1 
2 #[macro_use] extern crate maplit;
3 
4 #[test]
5 #[allow(unused_parens)]
test_parse()6 fn test_parse() {
7     let mut m = hashmap!{};
8     m.insert(1, 1);
9     hashmap!{1 => 1};
10     hashmap!{1 => 1,};
11     hashmap!{1 + 1 => 1, 2 + 1 => 2};
12     hashmap!{1 + 1 => 1, 2 + 1 => 2,};
13     hashmap!{{1 + 2} => 1, (1 + 3) => {0 + 2}};
14     let m = hashmap!{"a".to_string() => 1 + 2, "b".to_string() => 1 + 3};
15     assert_eq!(m["a"], 3);
16     assert_eq!(m["b"], 4);
17     let m = hashmap!{"a".to_string() => 1 + 2, "b".to_string() => 1 + 3, };
18     assert_eq!(m["a"], 3);
19     assert_eq!(m["b"], 4);
20 
21     let mut s = hashset!{};
22     s.insert(1);
23     hashset!{1};
24     hashset!{1,};
25     hashset!{1, 2};
26     hashset!{1, 2,};
27     hashset!{1 + 1, 2 + 1};
28     hashset!{1 + 1, 2 + 1,};
29     hashset!{{1 + 1}, (2 + 1)};
30 }
31 
32 #[test]
hashset()33 fn hashset() {
34     let mut set = hashset!{};
35     assert!(set.is_empty());
36     set.insert(2);
37     let set = hashset!{1};
38     assert_eq!(set.len(), 1);
39     let set = hashset!{2, 3};
40     assert_eq!(set.len(), 2);
41     // Test that we can use many elements without hitting the macro recursion limit
42     let set = hashset!{1,
43         2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,
44         2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,
45         2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,
46         2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,
47         2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,
48         2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,
49         2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,
50         2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,
51         2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,
52         2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,
53         2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,
54         2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,
55         2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,
56         2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,
57         2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,
58         2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,
59         2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,
60         2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,
61         2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,
62         2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,
63     };
64     assert_eq!(set.len(), 10);
65 }
66