about summary refs log tree commit diff
path: root/compiler/rustc_data_structures/src/vec_map/tests.rs
diff options
context:
space:
mode:
authorSantiago Pastorino <spastorino@gmail.com>2021-06-04 10:05:27 -0300
committerSantiago Pastorino <spastorino@gmail.com>2021-06-07 19:03:51 -0300
commitaa7024b0c7034c75d36ebe9048d12480c8d0bae2 (patch)
tree34fbd1ddf09aebe94e742cea3480ddbb79e56d4c /compiler/rustc_data_structures/src/vec_map/tests.rs
parent022720bfccd46400e69def42f4647fe4059ad951 (diff)
downloadrust-aa7024b0c7034c75d36ebe9048d12480c8d0bae2.tar.gz
rust-aa7024b0c7034c75d36ebe9048d12480c8d0bae2.zip
Add VecMap to rustc_data_structures
Diffstat (limited to 'compiler/rustc_data_structures/src/vec_map/tests.rs')
-rw-r--r--compiler/rustc_data_structures/src/vec_map/tests.rs48
1 files changed, 48 insertions, 0 deletions
diff --git a/compiler/rustc_data_structures/src/vec_map/tests.rs b/compiler/rustc_data_structures/src/vec_map/tests.rs
new file mode 100644
index 00000000000..9083de85982
--- /dev/null
+++ b/compiler/rustc_data_structures/src/vec_map/tests.rs
@@ -0,0 +1,48 @@
+use super::*;
+
+impl<K, V> VecMap<K, V> {
+    fn into_vec(self) -> Vec<(K, V)> {
+        self.0.into()
+    }
+}
+
+#[test]
+fn test_from_iterator() {
+    assert_eq!(
+        std::iter::empty().collect::<VecMap<i32, bool>>().into_vec(),
+        Vec::<(i32, bool)>::new()
+    );
+    assert_eq!(std::iter::once((42, true)).collect::<VecMap<_, _>>().into_vec(), vec![(42, true)]);
+    assert_eq!(
+        vec![(1, true), (2, false)].into_iter().collect::<VecMap<_, _>>().into_vec(),
+        vec![(1, true), (2, false)]
+    );
+}
+
+#[test]
+fn test_into_iterator_owned() {
+    assert_eq!(VecMap::new().into_iter().collect::<Vec<(i32, bool)>>(), Vec::<(i32, bool)>::new());
+    assert_eq!(VecMap::from(vec![(1, true)]).into_iter().collect::<Vec<_>>(), vec![(1, true)]);
+    assert_eq!(
+        VecMap::from(vec![(1, true), (2, false)]).into_iter().collect::<Vec<_>>(),
+        vec![(1, true), (2, false)]
+    );
+}
+
+#[test]
+fn test_insert() {
+    let mut v = VecMap::new();
+    assert_eq!(v.insert(1, true), None);
+    assert_eq!(v.insert(2, false), None);
+    assert_eq!(v.clone().into_vec(), vec![(1, true), (2, false)]);
+    assert_eq!(v.insert(1, false), Some(true));
+    assert_eq!(v.into_vec(), vec![(1, false), (2, false)]);
+}
+
+#[test]
+fn test_get() {
+    let v = vec![(1, true), (2, false)].into_iter().collect::<VecMap<_, _>>();
+    assert_eq!(v.get(&1), Some(&true));
+    assert_eq!(v.get(&2), Some(&false));
+    assert_eq!(v.get(&3), None);
+}