Update HashMap::try_reserve test to version from hashbrown

This commit is contained in:
Amanieu d'Antras 2022-01-21 17:17:00 +00:00
parent 88149d13e3
commit 361a2f9a83

View File

@ -828,11 +828,21 @@ fn test_try_reserve() {
"usize::MAX should trigger an overflow!"
);
assert_matches!(
empty_bytes.try_reserve(MAX_USIZE / 8).map_err(|e| e.kind()),
Err(AllocError { .. }),
"usize::MAX / 8 should trigger an OOM!"
);
if let Err(AllocError { .. }) = empty_bytes.try_reserve(MAX_USIZE / 16).map_err(|e| e.kind()) {
} else {
// This may succeed if there is enough free memory. Attempt to
// allocate a few more hashmaps to ensure the allocation will fail.
let mut empty_bytes2: HashMap<u8, u8> = HashMap::new();
let _ = empty_bytes2.try_reserve(MAX_USIZE / 16);
let mut empty_bytes3: HashMap<u8, u8> = HashMap::new();
let _ = empty_bytes3.try_reserve(MAX_USIZE / 16);
let mut empty_bytes4: HashMap<u8, u8> = HashMap::new();
assert_matches!(
empty_bytes4.try_reserve(MAX_USIZE / 16).map_err(|e| e.kind()),
Err(AllocError { .. }),
"usize::MAX / 16 should trigger an OOM!"
);
}
}
#[test]