diff options
| author | Ralf Jung <post@ralfj.de> | 2020-03-30 11:53:36 +0200 |
|---|---|---|
| committer | Ralf Jung <post@ralfj.de> | 2020-03-30 11:58:16 +0200 |
| commit | 4393923168fee76aea78907250642ad5474b1315 (patch) | |
| tree | afdc791d32a7b7a89653c86d4f379d4193cd80f1 /src/liballoc | |
| parent | fa6c8830740829d38f4ac7bfc8d8131ae44b9ade (diff) | |
| download | rust-4393923168fee76aea78907250642ad5474b1315.tar.gz rust-4393923168fee76aea78907250642ad5474b1315.zip | |
add some tests
Diffstat (limited to 'src/liballoc')
| -rw-r--r-- | src/liballoc/tests/vec.rs | 22 |
1 files changed, 18 insertions, 4 deletions
diff --git a/src/liballoc/tests/vec.rs b/src/liballoc/tests/vec.rs index 9c4ac52acac..831bc0346c2 100644 --- a/src/liballoc/tests/vec.rs +++ b/src/liballoc/tests/vec.rs @@ -1351,17 +1351,18 @@ fn test_try_reserve_exact() { } #[test] -fn test_stable_push_pop() { +fn test_stable_pointers() { // Test that, if we reserved enough space, adding and removing elements does not // invalidate references into the vector (such as `v0`). This test also // runs in Miri, which would detect such problems. - let mut v = Vec::with_capacity(10); + let mut v = Vec::with_capacity(128); v.push(13); - // laundering the lifetime -- we take care that `v` does not reallocate, so that's okay. + // Laundering the lifetime -- we take care that `v` does not reallocate, so that's okay. let v0 = unsafe { &*(&v[0] as *const _) }; - // Now do a bunch of things and occasionally use `v0` again to assert it is still valid. + + // Pushing/inserting and popping/removing v.push(1); v.push(2); v.insert(1, 1); @@ -1369,6 +1370,19 @@ fn test_stable_push_pop() { v.remove(1); v.pop().unwrap(); assert_eq!(*v0, 13); + + // Extending + v.extend(&[1, 2]); // `slice::Iter` (with `T: Copy`) specialization + v.extend(vec![2, 3]); // `vec::IntoIter` specialization + v.extend(std::iter::once(3)); // `TrustedLen` specialization + v.extend(std::iter::empty::<i32>()); // `TrustedLen` specialization with empty iterator + v.extend(std::iter::once(3).filter(|_| true)); // base case + v.extend(std::iter::once(&3)); // `cloned` specialization + assert_eq!(*v0, 13); + + // Truncation + v.truncate(2); + assert_eq!(*v0, 13); } // https://github.com/rust-lang/rust/pull/49496 introduced specialization based on: |
