Skip to content

Commit fa9af6a

Browse files
committed
Added tests to drain an empty vec
Discovered this kind of issue in an unrelated library. The author copied the tests from here and AFAIK, there are no tests for this particular case. Signed-off-by: Hanif Bin Ariffin <[email protected]>
1 parent a118ee2 commit fa9af6a

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

library/alloc/tests/vec.rs

+11
Original file line numberDiff line numberDiff line change
@@ -609,6 +609,17 @@ fn test_move_items_zero_sized() {
609609
assert_eq!(vec2, [(), (), ()]);
610610
}
611611

612+
#[test]
613+
fn test_drain_empty_vec() {
614+
let mut vec: Vec<i32> = vec![];
615+
let mut vec2: Vec<i32> = vec![];
616+
for i in vec.drain(..) {
617+
vec2.push(i);
618+
}
619+
assert!(vec.is_empty());
620+
assert!(vec2.is_empty());
621+
}
622+
612623
#[test]
613624
fn test_drain_items() {
614625
let mut vec = vec![1, 2, 3];

0 commit comments

Comments
 (0)