Skip to content

Commit

Permalink
Rollup merge of #82050 - hbina:fix/added-test-to-drain-empty-vec, r=d…
Browse files Browse the repository at this point in the history
…tolnay

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.

cmazakas/minivec#19

Signed-off-by: Hanif Bin Ariffin <hanif.ariffin.4326@gmail.com>
  • Loading branch information
JohnTitor committed Feb 13, 2021
2 parents 2673026 + fa9af6a commit 0ca5fd7
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions library/alloc/tests/vec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -609,6 +609,17 @@ fn test_move_items_zero_sized() {
assert_eq!(vec2, [(), (), ()]);
}

#[test]
fn test_drain_empty_vec() {
let mut vec: Vec<i32> = vec![];
let mut vec2: Vec<i32> = vec![];
for i in vec.drain(..) {
vec2.push(i);
}
assert!(vec.is_empty());
assert!(vec2.is_empty());
}

#[test]
fn test_drain_items() {
let mut vec = vec![1, 2, 3];
Expand Down

0 comments on commit 0ca5fd7

Please sign in to comment.