@@ -2052,4 +2052,43 @@ mod tests {
2052
2052
let b = b_index. into_iter ( ) . zip ( b_value) . rev ( ) . collect :: < Vec < _ > > ( ) ;
2053
2053
dbg ! ( b) ;
2054
2054
}
2055
+
2056
+ #[ test]
2057
+ fn delete_id_without_returning ( ) {
2058
+ let mut matches = crate :: Command :: new ( "myprog" )
2059
+ . arg ( crate :: Arg :: new ( "a" ) . short ( 'a' ) . action ( ArgAction :: Append ) )
2060
+ . arg ( crate :: Arg :: new ( "b" ) . short ( 'b' ) . action ( ArgAction :: Append ) )
2061
+ . arg ( crate :: Arg :: new ( "c" ) . short ( 'c' ) . action ( ArgAction :: Append ) )
2062
+ . try_get_matches_from ( vec ! [ "myprog" , "-b1" , "-a1" , "-b2" ] )
2063
+ . unwrap ( ) ;
2064
+ let matches_ids_count = matches. ids ( ) . count ( ) ;
2065
+ assert_eq ! ( matches_ids_count, 2 ) ;
2066
+
2067
+ let _ = matches
2068
+ . try_remove_occurrences :: < bool > ( "d" )
2069
+ . expect_err ( "should fail due to there is no arg 'd'" ) ;
2070
+
2071
+ let values = matches. try_remove_occurrences :: < bool > ( "c" ) . expect (
2072
+ "doesn't fail because there is no matches for 'c' argument thus nothing to downcast" ,
2073
+ ) ;
2074
+ assert ! ( values. is_none( ) ) ;
2075
+ let matches_ids_count = matches. ids ( ) . count ( ) ;
2076
+ assert_eq ! ( matches_ids_count, 2 ) ;
2077
+
2078
+ let _ = matches
2079
+ . try_remove_occurrences :: < ( ) > ( "b" )
2080
+ . expect_err ( "should fail due to impossible downcasting to ()" ) ;
2081
+ let matches_ids_count = matches. ids ( ) . count ( ) ;
2082
+ assert_eq ! ( matches_ids_count, 2 ) ;
2083
+
2084
+ trait Remover : Any + Sync + Debug + ' static {
2085
+ fn _noop ( & self ) ;
2086
+ }
2087
+
2088
+ let _ = matches
2089
+ . try_remove_occurrences :: < & dyn Remover > ( "a" )
2090
+ . expect_err ( "should fail due to impossible downcasting to &dyn Remover" ) ;
2091
+ let matches_ids_count = matches. ids ( ) . count ( ) ;
2092
+ assert_eq ! ( matches_ids_count, 2 ) ;
2093
+ }
2055
2094
}
0 commit comments