From 6caa72776481067c7cb73e5497df162448e73440 Mon Sep 17 00:00:00 2001 From: Tom Kaitchuck Date: Sat, 10 Feb 2024 15:52:54 -0800 Subject: [PATCH] Add test for key ref invariance Signed-off-by: Tom Kaitchuck --- tests/map_tests.rs | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/tests/map_tests.rs b/tests/map_tests.rs index 8d798a0..bdf37d8 100644 --- a/tests/map_tests.rs +++ b/tests/map_tests.rs @@ -200,6 +200,32 @@ fn test_ahash_alias_set_construction() { set.insert(1); } + +#[cfg(feature = "std")] +#[test] +fn test_key_ref() { + let mut map = ahash::HashMap::default(); + map.insert(1, "test"); + assert_eq!(Some((1, "test")), map.remove_entry(&1)); + + let mut map = ahash::HashMap::default(); + map.insert(&1, "test"); + assert_eq!(Some((&1, "test")), map.remove_entry(&&1)); + + let mut m = ahash::HashSet::>::default(); + m.insert(Box::from("hello".to_string())); + assert!(m.contains(&"hello".to_string())); + + let mut m = ahash::HashSet::::default(); + m.insert("hello".to_string()); + assert!(m.contains("hello")); + + let mut m = ahash::HashSet::>::default(); + m.insert(Box::from(&b"hello"[..])); + assert!(m.contains(&b"hello"[..])); +} + + fn ahash_vec(b: &Vec) -> u64 { let mut total: u64 = 0; for item in b {