summaryrefslogtreecommitdiffstats
path: root/vendor/maplit/tests/tests.rs
blob: b7b8968fca1ff5cde3f18756def8c9012ff2619c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#[macro_use] extern crate maplit;

#[test]
#[allow(unused_parens)]
fn test_parse() {
    let mut m = hashmap!{};
    m.insert(1, 1);
    hashmap!{1 => 1};
    hashmap!{1 => 1,};
    hashmap!{1 + 1 => 1, 2 + 1 => 2};
    hashmap!{1 + 1 => 1, 2 + 1 => 2,};
    hashmap!{{1 + 2} => 1, (1 + 3) => {0 + 2}};
    let m = hashmap!{"a".to_string() => 1 + 2, "b".to_string() => 1 + 3};
    assert_eq!(m["a"], 3);
    assert_eq!(m["b"], 4);
    let m = hashmap!{"a".to_string() => 1 + 2, "b".to_string() => 1 + 3, };
    assert_eq!(m["a"], 3);
    assert_eq!(m["b"], 4);

    let mut s = hashset!{};
    s.insert(1);
    hashset!{1};
    hashset!{1,};
    hashset!{1, 2};
    hashset!{1, 2,};
    hashset!{1 + 1, 2 + 1};
    hashset!{1 + 1, 2 + 1,};
    hashset!{{1 + 1}, (2 + 1)};
}

#[test]
fn hashset() {
    let mut set = hashset!{};
    assert!(set.is_empty());
    set.insert(2);
    let set = hashset!{1};
    assert_eq!(set.len(), 1);
    let set = hashset!{2, 3};
    assert_eq!(set.len(), 2);
    // Test that we can use many elements without hitting the macro recursion limit
    let set = hashset!{1,
        2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,
        2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,
        2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,
        2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,
        2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,
        2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,
        2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,
        2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,
        2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,
        2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,
        2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,
        2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,
        2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,
        2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,
        2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,
        2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,
        2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,
        2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,
        2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,
        2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,
    };
    assert_eq!(set.len(), 10);
}