]> git.lizzy.rs Git - rust.git/commitdiff
test more mutating vector methods
authorRalf Jung <post@ralfj.de>
Mon, 30 Mar 2020 09:57:31 +0000 (11:57 +0200)
committerRalf Jung <post@ralfj.de>
Mon, 30 Mar 2020 10:24:02 +0000 (12:24 +0200)
src/liballoc/tests/vec.rs

index 831bc0346c217f42865bf2dacc22d93d861a5d4d..d43bd11ebd32542ac46620fb6b4ddeae9276411c 100644 (file)
@@ -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: