about summary refs log tree commit diff
path: root/library/alloctests/tests/vec.rs
diff options
context:
space:
mode:
Diffstat (limited to 'library/alloctests/tests/vec.rs')
-rw-r--r--library/alloctests/tests/vec.rs15
1 files changed, 15 insertions, 0 deletions
diff --git a/library/alloctests/tests/vec.rs b/library/alloctests/tests/vec.rs
index 33a34daccbf..ea334ab0f14 100644
--- a/library/alloctests/tests/vec.rs
+++ b/library/alloctests/tests/vec.rs
@@ -631,6 +631,21 @@ fn test_swap_remove_empty() {
 }
 
 #[test]
+fn test_try_remove() {
+    let mut vec = vec![1, 2, 3];
+    // We are attempting to remove vec[0] which contains 1
+    assert_eq!(vec.try_remove(0), Some(1));
+    // Now `vec` looks like: [2, 3]
+    // We will now try to remove vec[2] which does not exist
+    // This should return `None`
+    assert_eq!(vec.try_remove(2), None);
+
+    // We will try the same thing with an empty vector
+    let mut v: Vec<u8> = vec![];
+    assert!(v.try_remove(0).is_none());
+}
+
+#[test]
 fn test_move_items() {
     let vec = vec![1, 2, 3];
     let mut vec2 = vec![];