diff options
| author | Kornel <kornel@geekhood.net> | 2024-01-30 16:08:57 +0000 |
|---|---|---|
| committer | Kornel <kornel@geekhood.net> | 2024-03-01 18:24:02 +0000 |
| commit | 78fb977d6b600865b7887245d24f6dca22a0099a (patch) | |
| tree | 88991f8cce8dc9f313eb04610043eae91dd8f920 /library/alloc/tests/vec.rs | |
| parent | f27a22c24a51ba734e4eb25c499320d819ebe236 (diff) | |
| download | rust-78fb977d6b600865b7887245d24f6dca22a0099a.tar.gz rust-78fb977d6b600865b7887245d24f6dca22a0099a.zip | |
try_with_capacity for Vec, VecDeque, String
#91913
Diffstat (limited to 'library/alloc/tests/vec.rs')
| -rw-r--r-- | library/alloc/tests/vec.rs | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/library/alloc/tests/vec.rs b/library/alloc/tests/vec.rs index 15ee4d65205..aa95b4e9770 100644 --- a/library/alloc/tests/vec.rs +++ b/library/alloc/tests/vec.rs @@ -1697,6 +1697,18 @@ fn test_reserve_exact() { #[test] #[cfg_attr(miri, ignore)] // Miri does not support signalling OOM #[cfg_attr(target_os = "android", ignore)] // Android used in CI has a broken dlmalloc +fn test_try_with_capacity() { + let mut vec: Vec<u32> = Vec::try_with_capacity(5).unwrap(); + assert_eq!(0, vec.len()); + assert!(vec.capacity() >= 5 && vec.capacity() <= isize::MAX as usize / 4); + assert!(vec.spare_capacity_mut().len() >= 5); + + assert!(Vec::<u16>::try_with_capacity(isize::MAX as usize + 1).is_err()); +} + +#[test] +#[cfg_attr(miri, ignore)] // Miri does not support signalling OOM +#[cfg_attr(target_os = "android", ignore)] // Android used in CI has a broken dlmalloc fn test_try_reserve() { // These are the interesting cases: // * exactly isize::MAX should never trigger a CapacityOverflow (can be OOM) |
