diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-17 12:02:58 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-17 12:02:58 +0000 |
commit | 698f8c2f01ea549d77d7dc3338a12e04c11057b9 (patch) | |
tree | 173a775858bd501c378080a10dca74132f05bc50 /vendor/maplit/tests | |
parent | Initial commit. (diff) | |
download | rustc-698f8c2f01ea549d77d7dc3338a12e04c11057b9.tar.xz rustc-698f8c2f01ea549d77d7dc3338a12e04c11057b9.zip |
Adding upstream version 1.64.0+dfsg1.upstream/1.64.0+dfsg1
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'vendor/maplit/tests')
-rw-r--r-- | vendor/maplit/tests/tests.rs | 65 |
1 files changed, 65 insertions, 0 deletions
diff --git a/vendor/maplit/tests/tests.rs b/vendor/maplit/tests/tests.rs new file mode 100644 index 000000000..b7b8968fc --- /dev/null +++ b/vendor/maplit/tests/tests.rs @@ -0,0 +1,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); +} |