Skip to content

Commit

Permalink
test(parser): Ensure conditional requirements work with new Actions
Browse files Browse the repository at this point in the history
  • Loading branch information
epage committed Jun 1, 2022
1 parent 9464ce4 commit 7a2fb34
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions tests/builder/action.rs
Expand Up @@ -103,6 +103,36 @@ fn set_true_with_default_value_if_value() {
assert_eq!(*matches.get_one::<bool>("mammal").unwrap(), true);
}

#[test]
fn set_true_with_required_if_eq() {
let cmd = Command::new("test")
.arg(
Arg::new("mammal")
.long("mammal")
.action(ArgAction::SetTrue)
.required_if_eq("dog", "true"),
)
.arg(Arg::new("dog").long("dog").action(ArgAction::SetTrue));

let matches = cmd
.clone()
.try_get_matches_from(["test", "--mammal"])
.unwrap();
assert_eq!(matches.get_one::<u64>("dog"), None);
assert_eq!(*matches.get_one::<bool>("mammal").unwrap(), true);

cmd.clone()
.try_get_matches_from(["test", "--dog"])
.unwrap_err();

let matches = cmd
.clone()
.try_get_matches_from(["test", "--dog", "--mammal"])
.unwrap();
assert_eq!(*matches.get_one::<bool>("dog").unwrap(), true);
assert_eq!(*matches.get_one::<bool>("mammal").unwrap(), true);
}

#[test]
fn set_false() {
let cmd = Command::new("test").arg(
Expand Down

0 comments on commit 7a2fb34

Please sign in to comment.