about summary refs log tree commit diff
path: root/src/liballoc
diff options
context:
space:
mode:
authorRalf Jung <post@ralfj.de>2020-03-30 11:57:31 +0200
committerRalf Jung <post@ralfj.de>2020-03-30 12:24:02 +0200
commit3411ade32ea8bb2e3f62140e8d47ad43c5a759ac (patch)
tree1d914c99607d7c61942fea49284b3e6685441a3f /src/liballoc
parent4393923168fee76aea78907250642ad5474b1315 (diff)
downloadrust-3411ade32ea8bb2e3f62140e8d47ad43c5a759ac.tar.gz
rust-3411ade32ea8bb2e3f62140e8d47ad43c5a759ac.zip
test more mutating vector methods
Diffstat (limited to 'src/liballoc')
-rw-r--r--src/liballoc/tests/vec.rs30
1 files changed, 30 insertions, 0 deletions
diff --git a/src/liballoc/tests/vec.rs b/src/liballoc/tests/vec.rs
index 831bc0346c2..d43bd11ebd3 100644
--- a/src/liballoc/tests/vec.rs
+++ b/src/liballoc/tests/vec.rs
@@ -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
@@ -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: