mirror of
https://github.com/clap-rs/clap
synced 2024-12-14 14:52:33 +00:00
Merge pull request #1136 from willmurphyscode/issue-1135
Test for Issue 1135
This commit is contained in:
commit
969c3adb41
2 changed files with 57 additions and 1 deletions
|
@ -67,7 +67,7 @@ impl<'n, 'e> AnyArg<'n, 'e> for FlagBuilder<'n, 'e> {
|
|||
self.b.requires.as_ref().map(|o| &o[..])
|
||||
}
|
||||
fn blacklist(&self) -> Option<&[&'e str]> { self.b.blacklist.as_ref().map(|o| &o[..]) }
|
||||
fn required_unless(&self) -> Option<&[&'e str]> { None }
|
||||
fn required_unless(&self) -> Option<&[&'e str]> { self.b.r_unless.as_ref().map(|o| &o[..]) }
|
||||
fn is_set(&self, s: ArgSettings) -> bool { self.b.settings.is_set(s) }
|
||||
fn has_switch(&self) -> bool { true }
|
||||
fn takes_value(&self) -> bool { false }
|
||||
|
|
|
@ -320,6 +320,62 @@ fn required_unless_one_2() {
|
|||
assert!(!m.is_present("cfg"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn required_unless_one_works_with_short() {
|
||||
// GitHub issue: https://github.com/kbknapp/clap-rs/issues/1135
|
||||
let res = App::new("unlessone")
|
||||
.arg(Arg::with_name("a").conflicts_with("b").short("a"))
|
||||
.arg(Arg::with_name("b").short("b"))
|
||||
.arg(
|
||||
Arg::with_name("x")
|
||||
.short("x")
|
||||
.required_unless_one(&["a", "b"])
|
||||
).get_matches_from_safe(vec!["unlessone", "-a"]);
|
||||
|
||||
assert!(res.is_ok());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn required_unless_one_works_with_short_err() {
|
||||
let res = App::new("unlessone")
|
||||
.arg(Arg::with_name("a").conflicts_with("b").short("a"))
|
||||
.arg(Arg::with_name("b").short("b"))
|
||||
.arg(
|
||||
Arg::with_name("x")
|
||||
.short("x")
|
||||
.required_unless_one(&["a", "b"])
|
||||
).get_matches_from_safe(vec!["unlessone"]);
|
||||
|
||||
assert!(!res.is_ok());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn required_unless_one_works_without() {
|
||||
let res = App::new("unlessone")
|
||||
.arg(Arg::with_name("a").conflicts_with("b").short("a"))
|
||||
.arg(Arg::with_name("b").short("b"))
|
||||
.arg(
|
||||
Arg::with_name("x")
|
||||
.required_unless_one(&["a", "b"])
|
||||
).get_matches_from_safe(vec!["unlessone", "-a"]);
|
||||
|
||||
assert!(res.is_ok());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn required_unless_one_works_with_long() {
|
||||
let res = App::new("unlessone")
|
||||
.arg(Arg::with_name("a").conflicts_with("b").short("a"))
|
||||
.arg(Arg::with_name("b").short("b"))
|
||||
.arg(
|
||||
Arg::with_name("x")
|
||||
.long("x_is_the_option")
|
||||
.required_unless_one(&["a", "b"])
|
||||
).get_matches_from_safe(vec!["unlessone", "-a"]);
|
||||
|
||||
assert!(res.is_ok());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn required_unless_one_1() {
|
||||
let res = App::new("unlessone")
|
||||
|
|
Loading…
Reference in a new issue