Skip to content

Commit 6d724cc

Browse files
committed
Fix warning; Made test external
1 parent 0caac69 commit 6d724cc

File tree

3 files changed

+43
-43
lines changed

3 files changed

+43
-43
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
target
2+
doc

src/lazy_static.rs

Lines changed: 2 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,6 @@ define uninitialized `static mut` values.
7070
7171
*/
7272

73-
#![crate_id = "lazy_static"]
7473
#![crate_type = "dylib"]
7574
#![license = "MIT"]
7675

@@ -82,8 +81,8 @@ macro_rules! lazy_static {
8281
$(
8382
#[allow(non_camel_case_types)]
8483
#[allow(dead_code)]
85-
struct $N {__unit__: ()}
86-
static $N: $N = $N {__unit__: ()};
84+
struct $N {__private_field: ()}
85+
static $N: $N = $N {__private_field: ()};
8786
impl Deref<$T> for $N {
8887
fn deref<'a>(&'a self) -> &'a $T {
8988
use std::sync::{Once, ONCE_INIT};
@@ -104,46 +103,6 @@ macro_rules! lazy_static {
104103
}
105104
}
106105
}
107-
108106
)*
109107
}
110108
}
111-
112-
#[cfg(test)]
113-
mod test {
114-
use std::collections::HashMap;
115-
116-
lazy_static! {
117-
static ref NUMBER: uint = times_two(3);
118-
static ref VEC: [Box<uint>, ..3] = [box 1, box 2, box 3];
119-
static ref OWNED_STRING: String = "hello".to_string();
120-
static ref HASHMAP: HashMap<uint, &'static str> = {
121-
let mut m = HashMap::new();
122-
m.insert(0u, "abc");
123-
m.insert(1, "def");
124-
m.insert(2, "ghi");
125-
m
126-
};
127-
static ref UNUSED: () = ();
128-
}
129-
130-
fn times_two(n: uint) -> uint {
131-
n * 2
132-
}
133-
134-
#[test]
135-
fn test_basic() {
136-
assert_eq!(OWNED_STRING.as_slice(), "hello");
137-
assert_eq!(*NUMBER, 6);
138-
assert!(HASHMAP.find(&1).is_some());
139-
assert!(HASHMAP.find(&3).is_none());
140-
assert_eq!(VEC.as_slice(), &[box 1, box 2, box 3]);
141-
}
142-
143-
#[test]
144-
fn test_repeat() {
145-
assert_eq!(*NUMBER, 6);
146-
assert_eq!(*NUMBER, 6);
147-
assert_eq!(*NUMBER, 6);
148-
}
149-
}

tests/test.rs

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
#![feature(phase)]
2+
3+
#[phase(plugin)]
4+
extern crate lazy_static;
5+
use std::collections::HashMap;
6+
7+
lazy_static! {
8+
static ref NUMBER: uint = times_two(3);
9+
static ref ARRAY_BOXES: [Box<uint>, ..3] = [box 1, box 2, box 3];
10+
static ref STRING: String = "hello".to_string();
11+
static ref HASHMAP: HashMap<uint, &'static str> = {
12+
let mut m = HashMap::new();
13+
m.insert(0u, "abc");
14+
m.insert(1, "def");
15+
m.insert(2, "ghi");
16+
m
17+
};
18+
static ref UNUSED: () = ();
19+
}
20+
21+
fn times_two(n: uint) -> uint {
22+
n * 2
23+
}
24+
25+
#[test]
26+
fn test_basic() {
27+
assert_eq!(STRING.as_slice(), "hello");
28+
assert_eq!(*NUMBER, 6);
29+
assert!(HASHMAP.find(&1).is_some());
30+
assert!(HASHMAP.find(&3).is_none());
31+
assert_eq!(ARRAY_BOXES.as_slice(), &[box 1, box 2, box 3]);
32+
}
33+
34+
#[test]
35+
fn test_repeat() {
36+
assert_eq!(*NUMBER, 6);
37+
assert_eq!(*NUMBER, 6);
38+
assert_eq!(*NUMBER, 6);
39+
}

0 commit comments

Comments
 (0)