tests(Value Delimiters): updates tests to new value delimiter rules

This commit is contained in:
Kevin K 2016-09-10 18:18:43 -04:00
parent 3834063d10
commit 9881a4a23a
3 changed files with 31 additions and 5 deletions

View file

@ -223,7 +223,7 @@ fn delim_values_only_pos_follows() {
let m = r.unwrap();
assert!(m.is_present("arg"));
assert!(!m.is_present("f"));
assert_eq!(m.values_of("arg").unwrap().collect::<Vec<_>>(), &["-f", "-g", "x"]);
assert_eq!(m.values_of("arg").unwrap().collect::<Vec<_>>(), &["-f", "-g,x"]);
}
#[test]
@ -235,6 +235,31 @@ fn delim_values_trailingvararg() {
)
.get_matches_from(vec!["", "test", "--foo", "-Wl,-bar"]);
assert!(m.is_present("opt"));
assert_eq!(m.values_of("opt").unwrap().collect::<Vec<_>>(), &["test", "--foo", "-Wl,-bar"]);
}
#[test]
fn delim_values_only_pos_follows_with_delim() {
let r = App::new("onlypos")
.args(&[Arg::from_usage("-f [flag] 'some opt'"),
Arg::from_usage("[arg]... 'some arg'").use_delimiter(true)])
.get_matches_from_safe(vec!["", "--", "-f", "-g,x"]);
assert!(r.is_ok());
let m = r.unwrap();
assert!(m.is_present("arg"));
assert!(!m.is_present("f"));
assert_eq!(m.values_of("arg").unwrap().collect::<Vec<_>>(), &["-f", "-g", "x"]);
}
#[test]
fn delim_values_trailingvararg_with_delim() {
let m = App::new("positional")
.setting(AppSettings::TrailingVarArg)
.arg(
Arg::from_usage("[opt]... 'some pos'").use_delimiter(true),
)
.get_matches_from(vec!["", "test", "--foo", "-Wl,-bar"]);
assert!(m.is_present("opt"));
assert_eq!(m.values_of("opt").unwrap().collect::<Vec<_>>(), &["test", "--foo", "-Wl", "-bar"]);
}

View file

@ -5,7 +5,7 @@ use clap::{App, Arg};
#[test]
fn multiple_occurrences_of_flags_long() {
let m = App::new("multiple_occurrences")
let m = App::new("mo_flags_long")
.arg(Arg::from_usage("--multflag 'allowed multiple flag'")
.multiple(true))
.arg(Arg::from_usage("--flag 'disallowed multiple flag'"))
@ -23,7 +23,7 @@ fn multiple_occurrences_of_flags_long() {
#[test]
fn multiple_occurrences_of_flags_short() {
let m = App::new("multiple_occurrences")
let m = App::new("mo_flags_short")
.arg(Arg::from_usage("-m --multflag 'allowed multiple flag'")
.multiple(true))
.arg(Arg::from_usage("-f --flag 'disallowed multiple flag'"))
@ -41,7 +41,7 @@ fn multiple_occurrences_of_flags_short() {
#[test]
fn multiple_occurrences_of_flags_mixed() {
let m = App::new("multiple_occurrences")
let m = App::new("mo_flags_mixed")
.arg(Arg::from_usage("-m, --multflag1 'allowed multiple flag'")
.multiple(true))
.arg(Arg::from_usage("-n, --multflag2 'another allowed multiple flag'")
@ -67,7 +67,7 @@ fn multiple_occurrences_of_flags_mixed() {
#[test]
fn multiple_occurrences_of_flags_large_quantity() {
let args : Vec<&str> = vec![""].into_iter().chain(vec!["-m"; 1024].into_iter()).collect();
let m = App::new("multiple_occurrences")
let m = App::new("mo_flags_larg_qty")
.arg(Arg::from_usage("-m --multflag 'allowed multiple flag'")
.multiple(true))
.get_matches_from(args);

View file

@ -630,6 +630,7 @@ fn multiple_values_sep_positional() {
let m = App::new("multiple_values")
.arg(Arg::with_name("option")
.help("multiple options")
.use_delimiter(true)
.multiple(true))
.get_matches_from_safe(vec![
"",