mirror of
https://github.com/clap-rs/clap
synced 2025-01-18 23:53:54 +00:00
test(parser): Ensure conditional requirements work with new Actions
This commit is contained in:
parent
4afd1aafe5
commit
2e9e556359
1 changed files with 30 additions and 0 deletions
|
@ -103,6 +103,36 @@ fn set_true_with_default_value_if_value() {
|
||||||
assert_eq!(*matches.get_one::<bool>("mammal").unwrap(), true);
|
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]
|
#[test]
|
||||||
fn set_false() {
|
fn set_false() {
|
||||||
let cmd = Command::new("test").arg(
|
let cmd = Command::new("test").arg(
|
||||||
|
|
Loading…
Reference in a new issue