summaryrefslogtreecommitdiffstats
path: root/third_party/rust/hashbrown/tests
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 19:33:14 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 19:33:14 +0000
commit36d22d82aa202bb199967e9512281e9a53db42c9 (patch)
tree105e8c98ddea1c1e4784a60a5a6410fa416be2de /third_party/rust/hashbrown/tests
parentInitial commit. (diff)
downloadfirefox-esr-upstream.tar.xz
firefox-esr-upstream.zip
Adding upstream version 115.7.0esr.upstream/115.7.0esrupstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to '')
-rw-r--r--third_party/rust/hashbrown/tests/hasher.rs65
-rw-r--r--third_party/rust/hashbrown/tests/rayon.rs533
-rw-r--r--third_party/rust/hashbrown/tests/serde.rs65
-rw-r--r--third_party/rust/hashbrown/tests/set.rs34
4 files changed, 697 insertions, 0 deletions
diff --git a/third_party/rust/hashbrown/tests/hasher.rs b/third_party/rust/hashbrown/tests/hasher.rs
new file mode 100644
index 0000000000..e455e3d3c9
--- /dev/null
+++ b/third_party/rust/hashbrown/tests/hasher.rs
@@ -0,0 +1,65 @@
+//! Sanity check that alternate hashers work correctly.
+
+#![cfg(not(miri))] // FIXME: takes too long
+
+use hashbrown::HashSet;
+use std::hash::{BuildHasher, BuildHasherDefault, Hasher};
+
+fn check<S: BuildHasher + Default>() {
+ let range = 0..1_000;
+
+ let mut set = HashSet::<i32, S>::default();
+ set.extend(range.clone());
+
+ assert!(!set.contains(&i32::min_value()));
+ assert!(!set.contains(&(range.start - 1)));
+ for i in range.clone() {
+ assert!(set.contains(&i));
+ }
+ assert!(!set.contains(&range.end));
+ assert!(!set.contains(&i32::max_value()));
+}
+
+/// Use hashbrown's default hasher.
+#[test]
+fn default() {
+ check::<hashbrown::hash_map::DefaultHashBuilder>();
+}
+
+/// Use std's default hasher.
+#[test]
+fn random_state() {
+ check::<std::collections::hash_map::RandomState>();
+}
+
+/// Use a constant 0 hash.
+#[test]
+fn zero() {
+ #[derive(Default)]
+ struct ZeroHasher;
+
+ impl Hasher for ZeroHasher {
+ fn finish(&self) -> u64 {
+ 0
+ }
+ fn write(&mut self, _: &[u8]) {}
+ }
+
+ check::<BuildHasherDefault<ZeroHasher>>();
+}
+
+/// Use a constant maximum hash.
+#[test]
+fn max() {
+ #[derive(Default)]
+ struct MaxHasher;
+
+ impl Hasher for MaxHasher {
+ fn finish(&self) -> u64 {
+ u64::max_value()
+ }
+ fn write(&mut self, _: &[u8]) {}
+ }
+
+ check::<BuildHasherDefault<MaxHasher>>();
+}
diff --git a/third_party/rust/hashbrown/tests/rayon.rs b/third_party/rust/hashbrown/tests/rayon.rs
new file mode 100644
index 0000000000..8c603c5c41
--- /dev/null
+++ b/third_party/rust/hashbrown/tests/rayon.rs
@@ -0,0 +1,533 @@
+#![cfg(feature = "rayon")]
+
+#[macro_use]
+extern crate lazy_static;
+
+use hashbrown::{HashMap, HashSet};
+use rayon::iter::{
+ IntoParallelIterator, IntoParallelRefIterator, IntoParallelRefMutIterator, ParallelExtend,
+ ParallelIterator,
+};
+
+macro_rules! assert_eq3 {
+ ($e1:expr, $e2:expr, $e3:expr) => {{
+ assert_eq!($e1, $e2);
+ assert_eq!($e1, $e3);
+ assert_eq!($e2, $e3);
+ }};
+}
+
+lazy_static! {
+ static ref MAP_EMPTY: HashMap<char, u32> = HashMap::new();
+ static ref MAP: HashMap<char, u32> = {
+ let mut m = HashMap::new();
+ m.insert('b', 20);
+ m.insert('a', 10);
+ m.insert('c', 30);
+ m.insert('e', 50);
+ m.insert('f', 60);
+ m.insert('d', 40);
+ m
+ };
+}
+
+#[test]
+fn map_seq_par_equivalence_iter_empty() {
+ let vec_seq = MAP_EMPTY.iter().collect::<Vec<_>>();
+ let vec_par = MAP_EMPTY.par_iter().collect::<Vec<_>>();
+
+ assert_eq3!(vec_seq, vec_par, []);
+}
+
+#[test]
+fn map_seq_par_equivalence_iter() {
+ let mut vec_seq = MAP.iter().collect::<Vec<_>>();
+ let mut vec_par = MAP.par_iter().collect::<Vec<_>>();
+
+ assert_eq!(vec_seq, vec_par);
+
+ // Do not depend on the exact order of values
+ let expected_sorted = [
+ (&'a', &10),
+ (&'b', &20),
+ (&'c', &30),
+ (&'d', &40),
+ (&'e', &50),
+ (&'f', &60),
+ ];
+
+ vec_seq.sort_unstable();
+ vec_par.sort_unstable();
+
+ assert_eq3!(vec_seq, vec_par, expected_sorted);
+}
+
+#[test]
+fn map_seq_par_equivalence_keys_empty() {
+ let vec_seq = MAP_EMPTY.keys().collect::<Vec<&char>>();
+ let vec_par = MAP_EMPTY.par_keys().collect::<Vec<&char>>();
+
+ let expected: [&char; 0] = [];
+
+ assert_eq3!(vec_seq, vec_par, expected);
+}
+
+#[test]
+fn map_seq_par_equivalence_keys() {
+ let mut vec_seq = MAP.keys().collect::<Vec<_>>();
+ let mut vec_par = MAP.par_keys().collect::<Vec<_>>();
+
+ assert_eq!(vec_seq, vec_par);
+
+ // Do not depend on the exact order of values
+ let expected_sorted = [&'a', &'b', &'c', &'d', &'e', &'f'];
+
+ vec_seq.sort_unstable();
+ vec_par.sort_unstable();
+
+ assert_eq3!(vec_seq, vec_par, expected_sorted);
+}
+
+#[test]
+fn map_seq_par_equivalence_values_empty() {
+ let vec_seq = MAP_EMPTY.values().collect::<Vec<_>>();
+ let vec_par = MAP_EMPTY.par_values().collect::<Vec<_>>();
+
+ let expected: [&u32; 0] = [];
+
+ assert_eq3!(vec_seq, vec_par, expected);
+}
+
+#[test]
+fn map_seq_par_equivalence_values() {
+ let mut vec_seq = MAP.values().collect::<Vec<_>>();
+ let mut vec_par = MAP.par_values().collect::<Vec<_>>();
+
+ assert_eq!(vec_seq, vec_par);
+
+ // Do not depend on the exact order of values
+ let expected_sorted = [&10, &20, &30, &40, &50, &60];
+
+ vec_seq.sort_unstable();
+ vec_par.sort_unstable();
+
+ assert_eq3!(vec_seq, vec_par, expected_sorted);
+}
+
+#[test]
+fn map_seq_par_equivalence_iter_mut_empty() {
+ let mut map1 = MAP_EMPTY.clone();
+ let mut map2 = MAP_EMPTY.clone();
+
+ let vec_seq = map1.iter_mut().collect::<Vec<_>>();
+ let vec_par = map2.par_iter_mut().collect::<Vec<_>>();
+
+ assert_eq3!(vec_seq, vec_par, []);
+}
+
+#[test]
+fn map_seq_par_equivalence_iter_mut() {
+ let mut map1 = MAP.clone();
+ let mut map2 = MAP.clone();
+
+ let mut vec_seq = map1.iter_mut().collect::<Vec<_>>();
+ let mut vec_par = map2.par_iter_mut().collect::<Vec<_>>();
+
+ assert_eq!(vec_seq, vec_par);
+
+ // Do not depend on the exact order of values
+ let expected_sorted = [
+ (&'a', &mut 10),
+ (&'b', &mut 20),
+ (&'c', &mut 30),
+ (&'d', &mut 40),
+ (&'e', &mut 50),
+ (&'f', &mut 60),
+ ];
+
+ vec_seq.sort_unstable();
+ vec_par.sort_unstable();
+
+ assert_eq3!(vec_seq, vec_par, expected_sorted);
+}
+
+#[test]
+fn map_seq_par_equivalence_values_mut_empty() {
+ let mut map1 = MAP_EMPTY.clone();
+ let mut map2 = MAP_EMPTY.clone();
+
+ let vec_seq = map1.values_mut().collect::<Vec<_>>();
+ let vec_par = map2.par_values_mut().collect::<Vec<_>>();
+
+ let expected: [&u32; 0] = [];
+
+ assert_eq3!(vec_seq, vec_par, expected);
+}
+
+#[test]
+fn map_seq_par_equivalence_values_mut() {
+ let mut map1 = MAP.clone();
+ let mut map2 = MAP.clone();
+
+ let mut vec_seq = map1.values_mut().collect::<Vec<_>>();
+ let mut vec_par = map2.par_values_mut().collect::<Vec<_>>();
+
+ assert_eq!(vec_seq, vec_par);
+
+ // Do not depend on the exact order of values
+ let expected_sorted = [&mut 10, &mut 20, &mut 30, &mut 40, &mut 50, &mut 60];
+
+ vec_seq.sort_unstable();
+ vec_par.sort_unstable();
+
+ assert_eq3!(vec_seq, vec_par, expected_sorted);
+}
+
+#[test]
+fn map_seq_par_equivalence_into_iter_empty() {
+ let vec_seq = MAP_EMPTY.clone().into_iter().collect::<Vec<_>>();
+ let vec_par = MAP_EMPTY.clone().into_par_iter().collect::<Vec<_>>();
+
+ assert_eq3!(vec_seq, vec_par, []);
+}
+
+#[test]
+fn map_seq_par_equivalence_into_iter() {
+ let mut vec_seq = MAP.clone().into_iter().collect::<Vec<_>>();
+ let mut vec_par = MAP.clone().into_par_iter().collect::<Vec<_>>();
+
+ assert_eq!(vec_seq, vec_par);
+
+ // Do not depend on the exact order of values
+ let expected_sorted = [
+ ('a', 10),
+ ('b', 20),
+ ('c', 30),
+ ('d', 40),
+ ('e', 50),
+ ('f', 60),
+ ];
+
+ vec_seq.sort_unstable();
+ vec_par.sort_unstable();
+
+ assert_eq3!(vec_seq, vec_par, expected_sorted);
+}
+
+lazy_static! {
+ static ref MAP_VEC_EMPTY: Vec<(char, u32)> = vec![];
+ static ref MAP_VEC: Vec<(char, u32)> = vec![
+ ('b', 20),
+ ('a', 10),
+ ('c', 30),
+ ('e', 50),
+ ('f', 60),
+ ('d', 40),
+ ];
+}
+
+#[test]
+fn map_seq_par_equivalence_collect_empty() {
+ let map_expected = MAP_EMPTY.clone();
+ let map_seq = MAP_VEC_EMPTY.clone().into_iter().collect::<HashMap<_, _>>();
+ let map_par = MAP_VEC_EMPTY
+ .clone()
+ .into_par_iter()
+ .collect::<HashMap<_, _>>();
+
+ assert_eq!(map_seq, map_par);
+ assert_eq!(map_seq, map_expected);
+ assert_eq!(map_par, map_expected);
+}
+
+#[test]
+fn map_seq_par_equivalence_collect() {
+ let map_expected = MAP.clone();
+ let map_seq = MAP_VEC.clone().into_iter().collect::<HashMap<_, _>>();
+ let map_par = MAP_VEC.clone().into_par_iter().collect::<HashMap<_, _>>();
+
+ assert_eq!(map_seq, map_par);
+ assert_eq!(map_seq, map_expected);
+ assert_eq!(map_par, map_expected);
+}
+
+lazy_static! {
+ static ref MAP_EXISTING_EMPTY: HashMap<char, u32> = HashMap::new();
+ static ref MAP_EXISTING: HashMap<char, u32> = {
+ let mut m = HashMap::new();
+ m.insert('b', 20);
+ m.insert('a', 10);
+ m
+ };
+ static ref MAP_EXTENSION_EMPTY: Vec<(char, u32)> = vec![];
+ static ref MAP_EXTENSION: Vec<(char, u32)> = vec![('c', 30), ('e', 50), ('f', 60), ('d', 40),];
+}
+
+#[test]
+fn map_seq_par_equivalence_existing_empty_extend_empty() {
+ let expected = HashMap::new();
+ let mut map_seq = MAP_EXISTING_EMPTY.clone();
+ let mut map_par = MAP_EXISTING_EMPTY.clone();
+
+ map_seq.extend(MAP_EXTENSION_EMPTY.iter().copied());
+ map_par.par_extend(MAP_EXTENSION_EMPTY.par_iter().copied());
+
+ assert_eq3!(map_seq, map_par, expected);
+}
+
+#[test]
+fn map_seq_par_equivalence_existing_empty_extend() {
+ let expected = MAP_EXTENSION.iter().copied().collect::<HashMap<_, _>>();
+ let mut map_seq = MAP_EXISTING_EMPTY.clone();
+ let mut map_par = MAP_EXISTING_EMPTY.clone();
+
+ map_seq.extend(MAP_EXTENSION.iter().copied());
+ map_par.par_extend(MAP_EXTENSION.par_iter().copied());
+
+ assert_eq3!(map_seq, map_par, expected);
+}
+
+#[test]
+fn map_seq_par_equivalence_existing_extend_empty() {
+ let expected = MAP_EXISTING.clone();
+ let mut map_seq = MAP_EXISTING.clone();
+ let mut map_par = MAP_EXISTING.clone();
+
+ map_seq.extend(MAP_EXTENSION_EMPTY.iter().copied());
+ map_par.par_extend(MAP_EXTENSION_EMPTY.par_iter().copied());
+
+ assert_eq3!(map_seq, map_par, expected);
+}
+
+#[test]
+fn map_seq_par_equivalence_existing_extend() {
+ let expected = MAP.clone();
+ let mut map_seq = MAP_EXISTING.clone();
+ let mut map_par = MAP_EXISTING.clone();
+
+ map_seq.extend(MAP_EXTENSION.iter().copied());
+ map_par.par_extend(MAP_EXTENSION.par_iter().copied());
+
+ assert_eq3!(map_seq, map_par, expected);
+}
+
+lazy_static! {
+ static ref SET_EMPTY: HashSet<char> = HashSet::new();
+ static ref SET: HashSet<char> = {
+ let mut s = HashSet::new();
+ s.insert('b');
+ s.insert('a');
+ s.insert('c');
+ s.insert('e');
+ s.insert('f');
+ s.insert('d');
+ s
+ };
+}
+
+#[test]
+fn set_seq_par_equivalence_iter_empty() {
+ let vec_seq = SET_EMPTY.iter().collect::<Vec<_>>();
+ let vec_par = SET_EMPTY.par_iter().collect::<Vec<_>>();
+
+ let expected: [&char; 0] = [];
+
+ assert_eq3!(vec_seq, vec_par, expected);
+}
+
+#[test]
+fn set_seq_par_equivalence_iter() {
+ let mut vec_seq = SET.iter().collect::<Vec<_>>();
+ let mut vec_par = SET.par_iter().collect::<Vec<_>>();
+
+ assert_eq!(vec_seq, vec_par);
+
+ // Do not depend on the exact order of values
+ let expected_sorted = [&'a', &'b', &'c', &'d', &'e', &'f'];
+
+ vec_seq.sort_unstable();
+ vec_par.sort_unstable();
+
+ assert_eq3!(vec_seq, vec_par, expected_sorted);
+}
+
+#[test]
+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, []);
+}
+
+#[test]
+fn set_seq_par_equivalence_into_iter() {
+ let mut vec_seq = SET.clone().into_iter().collect::<Vec<_>>();
+ let mut vec_par = SET.clone().into_par_iter().collect::<Vec<_>>();
+
+ assert_eq!(vec_seq, vec_par);
+
+ // Do not depend on the exact order of values
+ let expected_sorted = ['a', 'b', 'c', 'd', 'e', 'f'];
+
+ vec_seq.sort_unstable();
+ vec_par.sort_unstable();
+
+ assert_eq3!(vec_seq, vec_par, expected_sorted);
+}
+
+lazy_static! {
+ static ref SET_VEC_EMPTY: Vec<char> = vec![];
+ static ref SET_VEC: Vec<char> = vec!['b', 'a', 'c', 'e', 'f', 'd',];
+}
+
+#[test]
+fn set_seq_par_equivalence_collect_empty() {
+ let set_expected = SET_EMPTY.clone();
+ let set_seq = SET_VEC_EMPTY.clone().into_iter().collect::<HashSet<_>>();
+ let set_par = SET_VEC_EMPTY
+ .clone()
+ .into_par_iter()
+ .collect::<HashSet<_>>();
+
+ assert_eq!(set_seq, set_par);
+ assert_eq!(set_seq, set_expected);
+ assert_eq!(set_par, set_expected);
+}
+
+#[test]
+fn set_seq_par_equivalence_collect() {
+ let set_expected = SET.clone();
+ let set_seq = SET_VEC.clone().into_iter().collect::<HashSet<_>>();
+ let set_par = SET_VEC.clone().into_par_iter().collect::<HashSet<_>>();
+
+ assert_eq!(set_seq, set_par);
+ assert_eq!(set_seq, set_expected);
+ assert_eq!(set_par, set_expected);
+}
+
+lazy_static! {
+ static ref SET_EXISTING_EMPTY: HashSet<char> = HashSet::new();
+ static ref SET_EXISTING: HashSet<char> = {
+ let mut s = HashSet::new();
+ s.insert('b');
+ s.insert('a');
+ s
+ };
+ static ref SET_EXTENSION_EMPTY: Vec<char> = vec![];
+ static ref SET_EXTENSION: Vec<char> = vec!['c', 'e', 'f', 'd',];
+}
+
+#[test]
+fn set_seq_par_equivalence_existing_empty_extend_empty() {
+ let expected = HashSet::new();
+ let mut set_seq = SET_EXISTING_EMPTY.clone();
+ let mut set_par = SET_EXISTING_EMPTY.clone();
+
+ set_seq.extend(SET_EXTENSION_EMPTY.iter().copied());
+ set_par.par_extend(SET_EXTENSION_EMPTY.par_iter().copied());
+
+ assert_eq3!(set_seq, set_par, expected);
+}
+
+#[test]
+fn set_seq_par_equivalence_existing_empty_extend() {
+ let expected = SET_EXTENSION.iter().copied().collect::<HashSet<_>>();
+ let mut set_seq = SET_EXISTING_EMPTY.clone();
+ let mut set_par = SET_EXISTING_EMPTY.clone();
+
+ set_seq.extend(SET_EXTENSION.iter().copied());
+ set_par.par_extend(SET_EXTENSION.par_iter().copied());
+
+ assert_eq3!(set_seq, set_par, expected);
+}
+
+#[test]
+fn set_seq_par_equivalence_existing_extend_empty() {
+ let expected = SET_EXISTING.clone();
+ let mut set_seq = SET_EXISTING.clone();
+ let mut set_par = SET_EXISTING.clone();
+
+ set_seq.extend(SET_EXTENSION_EMPTY.iter().copied());
+ set_par.par_extend(SET_EXTENSION_EMPTY.par_iter().copied());
+
+ assert_eq3!(set_seq, set_par, expected);
+}
+
+#[test]
+fn set_seq_par_equivalence_existing_extend() {
+ let expected = SET.clone();
+ let mut set_seq = SET_EXISTING.clone();
+ let mut set_par = SET_EXISTING.clone();
+
+ set_seq.extend(SET_EXTENSION.iter().copied());
+ set_par.par_extend(SET_EXTENSION.par_iter().copied());
+
+ assert_eq3!(set_seq, set_par, expected);
+}
+
+lazy_static! {
+ static ref SET_A: HashSet<char> = ['a', 'b', 'c', 'd'].iter().copied().collect();
+ static ref SET_B: HashSet<char> = ['a', 'b', 'e', 'f'].iter().copied().collect();
+ static ref SET_DIFF_AB: HashSet<char> = ['c', 'd'].iter().copied().collect();
+ static ref SET_DIFF_BA: HashSet<char> = ['e', 'f'].iter().copied().collect();
+ static ref SET_SYMM_DIFF_AB: HashSet<char> = ['c', 'd', 'e', 'f'].iter().copied().collect();
+ static ref SET_INTERSECTION_AB: HashSet<char> = ['a', 'b'].iter().copied().collect();
+ static ref SET_UNION_AB: HashSet<char> =
+ ['a', 'b', 'c', 'd', 'e', 'f'].iter().copied().collect();
+}
+
+#[test]
+fn set_seq_par_equivalence_difference() {
+ let diff_ab_seq = SET_A.difference(&*SET_B).copied().collect::<HashSet<_>>();
+ let diff_ab_par = SET_A
+ .par_difference(&*SET_B)
+ .copied()
+ .collect::<HashSet<_>>();
+
+ assert_eq3!(diff_ab_seq, diff_ab_par, *SET_DIFF_AB);
+
+ let diff_ba_seq = SET_B.difference(&*SET_A).copied().collect::<HashSet<_>>();
+ let diff_ba_par = SET_B
+ .par_difference(&*SET_A)
+ .copied()
+ .collect::<HashSet<_>>();
+
+ assert_eq3!(diff_ba_seq, diff_ba_par, *SET_DIFF_BA);
+}
+
+#[test]
+fn set_seq_par_equivalence_symmetric_difference() {
+ let symm_diff_ab_seq = SET_A
+ .symmetric_difference(&*SET_B)
+ .copied()
+ .collect::<HashSet<_>>();
+ let symm_diff_ab_par = SET_A
+ .par_symmetric_difference(&*SET_B)
+ .copied()
+ .collect::<HashSet<_>>();
+
+ assert_eq3!(symm_diff_ab_seq, symm_diff_ab_par, *SET_SYMM_DIFF_AB);
+}
+
+#[test]
+fn set_seq_par_equivalence_intersection() {
+ let intersection_ab_seq = SET_A.intersection(&*SET_B).copied().collect::<HashSet<_>>();
+ let intersection_ab_par = SET_A
+ .par_intersection(&*SET_B)
+ .copied()
+ .collect::<HashSet<_>>();
+
+ assert_eq3!(
+ intersection_ab_seq,
+ intersection_ab_par,
+ *SET_INTERSECTION_AB
+ );
+}
+
+#[test]
+fn set_seq_par_equivalence_union() {
+ let union_ab_seq = SET_A.union(&*SET_B).copied().collect::<HashSet<_>>();
+ let union_ab_par = SET_A.par_union(&*SET_B).copied().collect::<HashSet<_>>();
+
+ assert_eq3!(union_ab_seq, union_ab_par, *SET_UNION_AB);
+}
diff --git a/third_party/rust/hashbrown/tests/serde.rs b/third_party/rust/hashbrown/tests/serde.rs
new file mode 100644
index 0000000000..a642348b3b
--- /dev/null
+++ b/third_party/rust/hashbrown/tests/serde.rs
@@ -0,0 +1,65 @@
+#![cfg(feature = "serde")]
+
+use core::hash::BuildHasherDefault;
+use fnv::FnvHasher;
+use hashbrown::{HashMap, HashSet};
+use serde_test::{assert_tokens, Token};
+
+// We use FnvHash for this test because we rely on the ordering
+type FnvHashMap<K, V> = HashMap<K, V, BuildHasherDefault<FnvHasher>>;
+type FnvHashSet<T> = HashSet<T, BuildHasherDefault<FnvHasher>>;
+
+#[test]
+fn map_serde_tokens_empty() {
+ let map = FnvHashMap::<char, u32>::default();
+
+ assert_tokens(&map, &[Token::Map { len: Some(0) }, Token::MapEnd]);
+}
+
+#[test]
+fn map_serde_tokens() {
+ let mut map = FnvHashMap::default();
+ map.insert('b', 20);
+ map.insert('a', 10);
+ map.insert('c', 30);
+
+ assert_tokens(
+ &map,
+ &[
+ Token::Map { len: Some(3) },
+ Token::Char('a'),
+ Token::I32(10),
+ Token::Char('c'),
+ Token::I32(30),
+ Token::Char('b'),
+ Token::I32(20),
+ Token::MapEnd,
+ ],
+ );
+}
+
+#[test]
+fn set_serde_tokens_empty() {
+ let set = FnvHashSet::<u32>::default();
+
+ assert_tokens(&set, &[Token::Seq { len: Some(0) }, Token::SeqEnd]);
+}
+
+#[test]
+fn set_serde_tokens() {
+ let mut set = FnvHashSet::default();
+ set.insert(20);
+ set.insert(10);
+ set.insert(30);
+
+ assert_tokens(
+ &set,
+ &[
+ Token::Seq { len: Some(3) },
+ Token::I32(30),
+ Token::I32(20),
+ Token::I32(10),
+ Token::SeqEnd,
+ ],
+ );
+}
diff --git a/third_party/rust/hashbrown/tests/set.rs b/third_party/rust/hashbrown/tests/set.rs
new file mode 100644
index 0000000000..5ae1ec98ec
--- /dev/null
+++ b/third_party/rust/hashbrown/tests/set.rs
@@ -0,0 +1,34 @@
+#![cfg(not(miri))] // FIXME: takes too long
+
+use hashbrown::HashSet;
+use rand::{distributions::Alphanumeric, rngs::SmallRng, Rng, SeedableRng};
+use std::iter;
+
+#[test]
+fn test_hashset_insert_remove() {
+ let mut m: HashSet<Vec<char>> = HashSet::new();
+ let seed = u64::from_le_bytes(*b"testseed");
+
+ let rng = &mut SmallRng::seed_from_u64(seed);
+ let tx: Vec<Vec<char>> = iter::repeat_with(|| {
+ rng.sample_iter(&Alphanumeric)
+ .take(32)
+ .map(char::from)
+ .collect()
+ })
+ .take(4096)
+ .collect();
+
+ // more readable with explicit `true` / `false`
+ #[allow(clippy::bool_assert_comparison)]
+ for _ in 0..32 {
+ for x in &tx {
+ assert_eq!(m.contains(x), false);
+ assert_eq!(m.insert(x.clone()), true);
+ }
+ for (i, x) in tx.iter().enumerate() {
+ println!("removing {} {:?}", i, x);
+ assert_eq!(m.remove(x), true);
+ }
+ }
+}