mirror of
https://github.com/clap-rs/clap
synced 2024-12-14 14:52:33 +00:00
tests: adds tests to make sure args are preferred over matching subcommands when values are possible
This commit is contained in:
parent
03455b7751
commit
9435b2a589
2 changed files with 25 additions and 53 deletions
|
@ -25,30 +25,6 @@ fn option_long() {
|
|||
assert_eq!(m.values_of("option").unwrap().collect::<Vec<_>>(), ["val1", "val2", "val3"]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn with_subcmd() {
|
||||
let m = App::new("multiple_values")
|
||||
.arg(Arg::with_name("option")
|
||||
.long("option")
|
||||
.help("multiple options")
|
||||
.takes_value(true)
|
||||
.multiple(true))
|
||||
.subcommand(SubCommand::with_name("foo"))
|
||||
.get_matches_from_safe(vec![
|
||||
"",
|
||||
"--option", "val1",
|
||||
"val2", "foo"
|
||||
]);
|
||||
|
||||
assert!(m.is_ok());
|
||||
let m = m.unwrap();
|
||||
|
||||
assert!(m.is_present("option"));
|
||||
assert_eq!(m.occurrences_of("option"), 1);
|
||||
assert_eq!(m.values_of("option").unwrap().collect::<Vec<_>>(), ["val1", "val2"]);
|
||||
assert_eq!(m.subcommand_name(), Some("foo"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn option_short() {
|
||||
let m = App::new("multiple_values")
|
||||
|
@ -985,35 +961,6 @@ fn low_index_positional() {
|
|||
assert_eq!(m.value_of("target").unwrap(), "target");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn low_index_positional_with_subcmd() {
|
||||
let m = App::new("lip")
|
||||
.arg(Arg::with_name("files")
|
||||
.index(1)
|
||||
.required(true)
|
||||
.multiple(true))
|
||||
.arg(Arg::with_name("target")
|
||||
.index(2)
|
||||
.required(true))
|
||||
.subcommand(SubCommand::with_name("test").arg(Arg::with_name("other")))
|
||||
.get_matches_from_safe(vec![
|
||||
"lip",
|
||||
"file1", "file2",
|
||||
"file3", "target",
|
||||
"test"
|
||||
]);
|
||||
|
||||
assert!(m.is_ok(), "{:?}", m.unwrap_err().kind);
|
||||
let m = m.unwrap();
|
||||
|
||||
assert!(m.is_present("files"));
|
||||
assert_eq!(m.occurrences_of("files"), 3);
|
||||
assert!(m.is_present("target"));
|
||||
assert_eq!(m.occurrences_of("target"), 1);
|
||||
assert_eq!(m.values_of("files").unwrap().collect::<Vec<_>>(), ["file1", "file2", "file3"]);
|
||||
assert_eq!(m.value_of("target").unwrap(), "target");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn low_index_positional_in_subcmd() {
|
||||
let m = App::new("lip")
|
||||
|
|
|
@ -164,3 +164,28 @@ fn invisible_aliases_help_output() {
|
|||
.alias("invisible"));
|
||||
assert!(test::compare_output(app, "clap-test --help", INVISIBLE_ALIAS_HELP, false));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn issue_1031_args_with_same_name() {
|
||||
let res = App::new("prog")
|
||||
.arg(Arg::from_usage("--ui-path=<PATH>"))
|
||||
.subcommand(SubCommand::with_name("signer"))
|
||||
.get_matches_from_safe(vec!["prog", "--ui-path", "signer"]);
|
||||
|
||||
assert!(res.is_ok(), "{:?}", res.unwrap_err().kind);
|
||||
let m = res.unwrap();
|
||||
assert_eq!(m.value_of("ui-path"), Some("signer"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn issue_1031_args_with_same_name_no_more_vals() {
|
||||
let res = App::new("prog")
|
||||
.arg(Arg::from_usage("--ui-path=<PATH>"))
|
||||
.subcommand(SubCommand::with_name("signer"))
|
||||
.get_matches_from_safe(vec!["prog", "--ui-path", "value", "signer"]);
|
||||
|
||||
assert!(res.is_ok(), "{:?}", res.unwrap_err().kind);
|
||||
let m = res.unwrap();
|
||||
assert_eq!(m.value_of("ui-path"), Some("value"));
|
||||
assert_eq!(m.subcommand_name(), Some("signer"));
|
||||
}
|
Loading…
Reference in a new issue