mirror of
https://github.com/clap-rs/clap
synced 2024-12-13 22:32:33 +00:00
test(parser): Show conditional requireds and exclusive
This commit is contained in:
parent
5e3386bb40
commit
65e90cd31f
1 changed files with 120 additions and 0 deletions
|
@ -684,6 +684,126 @@ fn exclusive_with_required() {
|
|||
cmd.clone().try_get_matches_from(["bug", "--test"]).unwrap();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn exclusive_with_required_unless_present() {
|
||||
let cmd = Command::new("bug")
|
||||
.arg(
|
||||
Arg::new("exclusive")
|
||||
.long("exclusive")
|
||||
.action(ArgAction::SetTrue)
|
||||
.exclusive(true),
|
||||
)
|
||||
.arg(
|
||||
Arg::new("required")
|
||||
.long("required")
|
||||
.action(ArgAction::SetTrue)
|
||||
.required_unless_present("alternative"),
|
||||
)
|
||||
.arg(
|
||||
Arg::new("alternative")
|
||||
.long("alternative")
|
||||
.action(ArgAction::SetTrue),
|
||||
);
|
||||
|
||||
cmd.clone()
|
||||
.try_get_matches_from(["bug", "--required"])
|
||||
.unwrap();
|
||||
|
||||
cmd.clone()
|
||||
.try_get_matches_from(["bug", "--alternative"])
|
||||
.unwrap();
|
||||
|
||||
cmd.clone().try_get_matches_from(["bug"]).unwrap_err();
|
||||
|
||||
cmd.clone()
|
||||
.try_get_matches_from(["bug", "--exclusive", "--required"])
|
||||
.unwrap_err();
|
||||
|
||||
cmd.clone()
|
||||
.try_get_matches_from(["bug", "--exclusive"])
|
||||
.unwrap_err();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn exclusive_with_required_unless_present_any() {
|
||||
let cmd = Command::new("bug")
|
||||
.arg(
|
||||
Arg::new("exclusive")
|
||||
.long("exclusive")
|
||||
.action(ArgAction::SetTrue)
|
||||
.exclusive(true),
|
||||
)
|
||||
.arg(
|
||||
Arg::new("required")
|
||||
.long("required")
|
||||
.action(ArgAction::SetTrue)
|
||||
.required_unless_present_any(["alternative"]),
|
||||
)
|
||||
.arg(
|
||||
Arg::new("alternative")
|
||||
.long("alternative")
|
||||
.action(ArgAction::SetTrue),
|
||||
);
|
||||
|
||||
cmd.clone()
|
||||
.try_get_matches_from(["bug", "--required"])
|
||||
.unwrap();
|
||||
|
||||
cmd.clone()
|
||||
.try_get_matches_from(["bug", "--alternative"])
|
||||
.unwrap();
|
||||
|
||||
cmd.clone().try_get_matches_from(["bug"]).unwrap_err();
|
||||
|
||||
cmd.clone()
|
||||
.try_get_matches_from(["bug", "--exclusive", "--required"])
|
||||
.unwrap_err();
|
||||
|
||||
cmd.clone()
|
||||
.try_get_matches_from(["bug", "--exclusive"])
|
||||
.unwrap_err();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn exclusive_with_required_unless_present_all() {
|
||||
let cmd = Command::new("bug")
|
||||
.arg(
|
||||
Arg::new("exclusive")
|
||||
.long("exclusive")
|
||||
.action(ArgAction::SetTrue)
|
||||
.exclusive(true),
|
||||
)
|
||||
.arg(
|
||||
Arg::new("required")
|
||||
.long("required")
|
||||
.action(ArgAction::SetTrue)
|
||||
.required_unless_present_all(["alternative"]),
|
||||
)
|
||||
.arg(
|
||||
Arg::new("alternative")
|
||||
.long("alternative")
|
||||
.action(ArgAction::SetTrue),
|
||||
);
|
||||
|
||||
cmd.clone()
|
||||
.try_get_matches_from(["bug", "--required"])
|
||||
.unwrap();
|
||||
|
||||
cmd.clone()
|
||||
.try_get_matches_from(["bug", "--alternative"])
|
||||
.unwrap();
|
||||
|
||||
cmd.clone().try_get_matches_from(["bug"]).unwrap_err();
|
||||
|
||||
cmd.clone()
|
||||
.try_get_matches_from(["bug", "--exclusive", "--required"])
|
||||
.unwrap_err();
|
||||
|
||||
cmd.clone()
|
||||
.try_get_matches_from(["bug", "--exclusive"])
|
||||
.unwrap_err();
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[cfg(feature = "error-context")]
|
||||
fn option_conflicts_with_subcommand() {
|
||||
|
|
Loading…
Reference in a new issue