Skip to content

Commit 45d4088

Browse files
author
asakh
committed
test(parser): Added test delete_id_without_returning
Related to [#5973](#5973)
1 parent 9ebef15 commit 45d4088

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed

clap_builder/src/parser/matches/arg_matches.rs

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2052,4 +2052,43 @@ mod tests {
20522052
let b = b_index.into_iter().zip(b_value).rev().collect::<Vec<_>>();
20532053
dbg!(b);
20542054
}
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+
}
20552094
}

0 commit comments

Comments
 (0)