diff options
| author | Hanif Bin Ariffin <hanif.ariffin.4326@gmail.com> | 2021-02-13 11:18:36 +0800 |
|---|---|---|
| committer | Hanif Bin Ariffin <hanif.ariffin.4326@gmail.com> | 2021-02-13 11:18:36 +0800 |
| commit | fa9af6a9be72e80c7c86adf656bee5964cb2f6a2 (patch) | |
| tree | c6f88751aae5b2c6f6968752ff16919e2f65d46e | |
| parent | a118ee2c13cc96ceb27bd5030c1cca1052377604 (diff) | |
| download | rust-fa9af6a9be72e80c7c86adf656bee5964cb2f6a2.tar.gz rust-fa9af6a9be72e80c7c86adf656bee5964cb2f6a2.zip | |
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 <hanif.ariffin.4326@gmail.com>
| -rw-r--r-- | library/alloc/tests/vec.rs | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/library/alloc/tests/vec.rs b/library/alloc/tests/vec.rs index e3d74791dcf..2969da58d42 100644 --- a/library/alloc/tests/vec.rs +++ b/library/alloc/tests/vec.rs @@ -610,6 +610,17 @@ fn test_move_items_zero_sized() { } #[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]; let mut vec2 = vec![]; |
