Skip to content

Commit

Permalink
test more mutating vector methods
Browse files Browse the repository at this point in the history
  • Loading branch information
RalfJung committed Mar 30, 2020
1 parent 4393923 commit 3411ade
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions src/liballoc/tests/vec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1371,7 +1371,12 @@ fn test_stable_pointers() {
v.pop().unwrap();
assert_eq!(*v0, 13);

// Appending
v.append(&mut vec![27, 19]);
assert_eq!(*v0, 13);

// Extending
v.extend_from_slice(&[1, 2]);
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
Expand All @@ -1383,6 +1388,31 @@ fn test_stable_pointers() {
// Truncation
v.truncate(2);
assert_eq!(*v0, 13);

// Resizing
v.resize_with(v.len() + 10, || 42);
assert_eq!(*v0, 13);
v.resize_with(2, || panic!());
assert_eq!(*v0, 13);

// No-op reservation
v.reserve(32);
v.reserve_exact(32);
assert_eq!(*v0, 13);

// Partial draining
v.resize_with(10, || 42);
drop(v.drain(5..));
assert_eq!(*v0, 13);

// Splicing
v.resize_with(10, || 42);
drop(v.splice(5.., vec![1, 2, 3, 4, 5])); // empty tail after range
assert_eq!(*v0, 13);
drop(v.splice(5..8, vec![1])); // replacement is smaller than original range
assert_eq!(*v0, 13);
drop(v.splice(5..6, vec![1; 10].into_iter().filter(|_| true))); // lower bound not exact
assert_eq!(*v0, 13);
}

// https://github.com/rust-lang/rust/pull/49496 introduced specialization based on:
Expand Down

0 comments on commit 3411ade

Please sign in to comment.