summaryrefslogtreecommitdiffstats
path: root/third_party/rust/hashbrown/tests
diff options
context:
space:
mode:
Diffstat (limited to 'third_party/rust/hashbrown/tests')
-rw-r--r--third_party/rust/hashbrown/tests/equivalent_trait.rs53
-rw-r--r--third_party/rust/hashbrown/tests/raw.rs11
-rw-r--r--third_party/rust/hashbrown/tests/rayon.rs4
-rw-r--r--third_party/rust/hashbrown/tests/set.rs2
4 files changed, 68 insertions, 2 deletions
diff --git a/third_party/rust/hashbrown/tests/equivalent_trait.rs b/third_party/rust/hashbrown/tests/equivalent_trait.rs
new file mode 100644
index 0000000000..713dddd53c
--- /dev/null
+++ b/third_party/rust/hashbrown/tests/equivalent_trait.rs
@@ -0,0 +1,53 @@
+use hashbrown::Equivalent;
+use hashbrown::HashMap;
+
+use std::hash::Hash;
+
+#[derive(Debug, Hash)]
+pub struct Pair<A, B>(pub A, pub B);
+
+impl<A, B, C, D> PartialEq<(A, B)> for Pair<C, D>
+where
+ C: PartialEq<A>,
+ D: PartialEq<B>,
+{
+ fn eq(&self, rhs: &(A, B)) -> bool {
+ self.0 == rhs.0 && self.1 == rhs.1
+ }
+}
+
+impl<A, B, X> Equivalent<X> for Pair<A, B>
+where
+ Pair<A, B>: PartialEq<X>,
+ A: Hash + Eq,
+ B: Hash + Eq,
+{
+ fn equivalent(&self, other: &X) -> bool {
+ *self == *other
+ }
+}
+
+#[test]
+fn test_lookup() {
+ let s = String::from;
+ let mut map = HashMap::new();
+ map.insert((s("a"), s("b")), 1);
+ map.insert((s("a"), s("x")), 2);
+
+ assert!(map.contains_key(&Pair("a", "b")));
+ assert!(!map.contains_key(&Pair("b", "a")));
+}
+
+#[test]
+fn test_string_str() {
+ let s = String::from;
+ let mut map = HashMap::new();
+ map.insert(s("a"), 1);
+ map.insert(s("b"), 2);
+ map.insert(s("x"), 3);
+ map.insert(s("y"), 4);
+
+ assert!(map.contains_key("a"));
+ assert!(!map.contains_key("z"));
+ assert_eq!(map.remove("b"), Some(2));
+}
diff --git a/third_party/rust/hashbrown/tests/raw.rs b/third_party/rust/hashbrown/tests/raw.rs
new file mode 100644
index 0000000000..858836e63b
--- /dev/null
+++ b/third_party/rust/hashbrown/tests/raw.rs
@@ -0,0 +1,11 @@
+#![cfg(feature = "raw")]
+
+use hashbrown::raw::RawTable;
+use std::mem;
+
+#[test]
+fn test_allocation_info() {
+ assert_eq!(RawTable::<()>::new().allocation_info().1.size(), 0);
+ assert_eq!(RawTable::<u32>::new().allocation_info().1.size(), 0);
+ assert!(RawTable::<u32>::with_capacity(1).allocation_info().1.size() > mem::size_of::<u32>());
+}
diff --git a/third_party/rust/hashbrown/tests/rayon.rs b/third_party/rust/hashbrown/tests/rayon.rs
index 8c603c5c41..d55e5a9804 100644
--- a/third_party/rust/hashbrown/tests/rayon.rs
+++ b/third_party/rust/hashbrown/tests/rayon.rs
@@ -356,7 +356,9 @@ fn set_seq_par_equivalence_into_iter_empty() {
let vec_seq = SET_EMPTY.clone().into_iter().collect::<Vec<_>>();
let vec_par = SET_EMPTY.clone().into_par_iter().collect::<Vec<_>>();
- assert_eq3!(vec_seq, vec_par, []);
+ // Work around type inference failure introduced by rend dev-dependency.
+ let empty: [char; 0] = [];
+ assert_eq3!(vec_seq, vec_par, empty);
}
#[test]
diff --git a/third_party/rust/hashbrown/tests/set.rs b/third_party/rust/hashbrown/tests/set.rs
index 5ae1ec98ec..86ec964766 100644
--- a/third_party/rust/hashbrown/tests/set.rs
+++ b/third_party/rust/hashbrown/tests/set.rs
@@ -27,7 +27,7 @@ fn test_hashset_insert_remove() {
assert_eq!(m.insert(x.clone()), true);
}
for (i, x) in tx.iter().enumerate() {
- println!("removing {} {:?}", i, x);
+ println!("removing {i} {x:?}");
assert_eq!(m.remove(x), true);
}
}