From fa9af6a9be72e80c7c86adf656bee5964cb2f6a2 Mon Sep 17 00:00:00 2001 From: Hanif Bin Ariffin Date: Sat, 13 Feb 2021 11:18:36 +0800 Subject: [PATCH] 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 --- library/alloc/tests/vec.rs | 11 +++++++++++ 1 file changed, 11 insertions(+) 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 @@ -609,6 +609,17 @@ fn test_move_items_zero_sized() { assert_eq!(vec2, [(), (), ()]); } +#[test] +fn test_drain_empty_vec() { + let mut vec: Vec = vec![]; + let mut vec2: Vec = 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];