Merge pull request #1136 from willmurphyscode/issue-1135

Test for Issue 1135
This commit is contained in:
Kevin K 2018-01-22 14:08:50 -05:00 committed by GitHub
commit 969c3adb41
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 57 additions and 1 deletions

View file

@ -67,7 +67,7 @@ impl<'n, 'e> AnyArg<'n, 'e> for FlagBuilder<'n, 'e> {
self.b.requires.as_ref().map(|o| &o[..]) self.b.requires.as_ref().map(|o| &o[..])
} }
fn blacklist(&self) -> Option<&[&'e str]> { self.b.blacklist.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 is_set(&self, s: ArgSettings) -> bool { self.b.settings.is_set(s) }
fn has_switch(&self) -> bool { true } fn has_switch(&self) -> bool { true }
fn takes_value(&self) -> bool { false } fn takes_value(&self) -> bool { false }

View file

@ -320,6 +320,62 @@ fn required_unless_one_2() {
assert!(!m.is_present("cfg")); 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] #[test]
fn required_unless_one_1() { fn required_unless_one_1() {
let res = App::new("unlessone") let res = App::new("unlessone")