@@ -2644,6 +2644,36 @@ fn test_vec_from_array_mut_ref() {
2644
2644
assert_eq ! ( Vec :: from( & mut [ 1 , 2 , 3 ] ) , vec![ 1 , 2 , 3 ] ) ;
2645
2645
}
2646
2646
2647
+ #[ test]
2648
+ fn test_pop_if ( ) {
2649
+ let mut v = vec ! [ 1 , 2 , 3 , 4 ] ;
2650
+ let pred = |x : & mut i32 | * x % 2 == 0 ;
2651
+
2652
+ assert_eq ! ( v. pop_if( pred) , Some ( 4 ) ) ;
2653
+ assert_eq ! ( v, [ 1 , 2 , 3 ] ) ;
2654
+
2655
+ assert_eq ! ( v. pop_if( pred) , None ) ;
2656
+ assert_eq ! ( v, [ 1 , 2 , 3 ] ) ;
2657
+ }
2658
+
2659
+ #[ test]
2660
+ fn test_pop_if_empty ( ) {
2661
+ let mut v = Vec :: < i32 > :: new ( ) ;
2662
+ assert_eq ! ( v. pop_if( |_| true ) , None ) ;
2663
+ assert ! ( v. is_empty( ) ) ;
2664
+ }
2665
+
2666
+ #[ test]
2667
+ fn test_pop_if_mutates ( ) {
2668
+ let mut v = vec ! [ 1 ] ;
2669
+ let pred = |x : & mut i32 | {
2670
+ * x += 1 ;
2671
+ false
2672
+ } ;
2673
+ assert_eq ! ( v. pop_if( pred) , None ) ;
2674
+ assert_eq ! ( v, [ 2 ] ) ;
2675
+ }
2676
+
2647
2677
/// This assortment of tests, in combination with miri, verifies we handle UB on fishy arguments
2648
2678
/// in the stdlib. Draining and extending the allocation are fairly well-tested earlier, but
2649
2679
/// `vec.insert(usize::MAX, val)` once slipped by!
0 commit comments