Skip to content

Commit 3411ade

Browse files
committed
test more mutating vector methods
1 parent 4393923 commit 3411ade

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

src/liballoc/tests/vec.rs

+30
Original file line numberDiff line numberDiff line change
@@ -1371,7 +1371,12 @@ fn test_stable_pointers() {
13711371
v.pop().unwrap();
13721372
assert_eq!(*v0, 13);
13731373

1374+
// Appending
1375+
v.append(&mut vec![27, 19]);
1376+
assert_eq!(*v0, 13);
1377+
13741378
// Extending
1379+
v.extend_from_slice(&[1, 2]);
13751380
v.extend(&[1, 2]); // `slice::Iter` (with `T: Copy`) specialization
13761381
v.extend(vec![2, 3]); // `vec::IntoIter` specialization
13771382
v.extend(std::iter::once(3)); // `TrustedLen` specialization
@@ -1383,6 +1388,31 @@ fn test_stable_pointers() {
13831388
// Truncation
13841389
v.truncate(2);
13851390
assert_eq!(*v0, 13);
1391+
1392+
// Resizing
1393+
v.resize_with(v.len() + 10, || 42);
1394+
assert_eq!(*v0, 13);
1395+
v.resize_with(2, || panic!());
1396+
assert_eq!(*v0, 13);
1397+
1398+
// No-op reservation
1399+
v.reserve(32);
1400+
v.reserve_exact(32);
1401+
assert_eq!(*v0, 13);
1402+
1403+
// Partial draining
1404+
v.resize_with(10, || 42);
1405+
drop(v.drain(5..));
1406+
assert_eq!(*v0, 13);
1407+
1408+
// Splicing
1409+
v.resize_with(10, || 42);
1410+
drop(v.splice(5.., vec![1, 2, 3, 4, 5])); // empty tail after range
1411+
assert_eq!(*v0, 13);
1412+
drop(v.splice(5..8, vec![1])); // replacement is smaller than original range
1413+
assert_eq!(*v0, 13);
1414+
drop(v.splice(5..6, vec![1; 10].into_iter().filter(|_| true))); // lower bound not exact
1415+
assert_eq!(*v0, 13);
13861416
}
13871417

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

0 commit comments

Comments
 (0)