Skip to content

Commit

Permalink
tests: Add failing tests from clap-rs#1374
Browse files Browse the repository at this point in the history
  • Loading branch information
Elarnon committed Dec 3, 2018
1 parent 9399174 commit 29d6ac9
Showing 1 changed file with 58 additions and 0 deletions.
58 changes: 58 additions & 0 deletions tests/app_settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -827,6 +827,64 @@ fn aaos_opts() {
assert_eq!(m.value_of("opt"), Some("other"));
}

#[test]
fn aaos_opts_two_values() {
// opts with two values
let res = App::new("posix")
.setting(AppSettings::AllArgsOverrideSelf)
.arg(Arg::from("--opt [val1] [val2] 'some option'"))
.try_get_matches_from(vec![
"", "--opt", "some", "thing", "--opt", "other", "stuff",
]);
assert!(res.is_ok());
let m = res.unwrap();
assert!(m.is_present("opt"));
assert_eq!(m.occurrences_of("opt"), 1);
assert_eq!(
m.values_of("opt").unwrap().collect::<Vec<_>>(),
&["other", "stuff"]
);
}

#[test]
fn aaos_opts_two_values_delimiter() {
// opts with two values and a delimiter
let res = App::new("posix")
.setting(AppSettings::AllArgsOverrideSelf)
.arg(Arg::from("--opt [val1] [val2] 'some option'").require_delimiter(true))
.try_get_matches_from(vec!["", "--opt=some,thing", "--opt=other,stuff"]);
assert!(res.is_ok());
let m = res.unwrap();
assert!(m.is_present("opt"));
assert_eq!(m.occurrences_of("opt"), 1);
assert_eq!(
m.values_of("opt").unwrap().collect::<Vec<_>>(),
&["other", "stuff"]
);
}

#[test]
fn aaos_opts_min_value() {
// opts with min_value
let res = App::new("posix")
.setting(AppSettings::AllArgsOverrideSelf)
.arg(
Arg::from("--opt [val] 'some option'")
.require_delimiter(true)
.min_values(0),
)
.try_get_matches_from(vec!["", "--opt", "--opt=val1,val2"]);
assert!(res.is_ok());
let m = res.unwrap();
assert!(m.is_present("opt"));
assert_eq!(m.occurrences_of("opt"), 1);
assert_eq!(
m.values_of("opt").unwrap().collect::<Vec<_>>(),
&["val1", "val2"]
);
}


#[test]
fn aaos_opts_w_other_overrides() {
// opts with other overrides
Expand Down

0 comments on commit 29d6ac9

Please sign in to comment.