mirror of
https://github.com/clap-rs/clap
synced 2024-11-10 06:44:16 +00:00
test(clap_complete): Add test case for multi-values of positional argument with num_args(N)
This commit is contained in:
parent
75a45e5aa0
commit
3f2466b2f6
1 changed files with 90 additions and 0 deletions
|
@ -590,6 +590,96 @@ val3
|
|||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn suggest_multi_positional() {
|
||||
let mut cmd = Command::new("dynamic")
|
||||
.arg(
|
||||
clap::Arg::new("positional")
|
||||
.value_parser(["pos_1, pos_2, pos_3"])
|
||||
.index(1),
|
||||
)
|
||||
.arg(
|
||||
clap::Arg::new("positional-2")
|
||||
.value_parser(["pos_a", "pos_b", "pos_c"])
|
||||
.index(2)
|
||||
.num_args(3),
|
||||
)
|
||||
.arg(
|
||||
clap::Arg::new("--format")
|
||||
.long("format")
|
||||
.short('F')
|
||||
.value_parser(["json", "yaml", "toml"]),
|
||||
);
|
||||
|
||||
assert_data_eq!(
|
||||
complete!(cmd, "pos_1 pos_a [TAB]"),
|
||||
snapbox::str![
|
||||
"--format
|
||||
--help\tPrint help
|
||||
-F
|
||||
-h\tPrint help"
|
||||
]
|
||||
);
|
||||
|
||||
assert_data_eq!(
|
||||
complete!(cmd, "pos_1 pos_a pos_b [TAB]"),
|
||||
snapbox::str![
|
||||
"--format
|
||||
--help\tPrint help
|
||||
-F
|
||||
-h\tPrint help"
|
||||
]
|
||||
);
|
||||
|
||||
assert_data_eq!(
|
||||
complete!(cmd, "--format json pos_1 [TAB]"),
|
||||
snapbox::str![
|
||||
"--format
|
||||
--help\tPrint help
|
||||
-F
|
||||
-h\tPrint help
|
||||
pos_a
|
||||
pos_b
|
||||
pos_c"
|
||||
]
|
||||
);
|
||||
|
||||
assert_data_eq!(
|
||||
complete!(cmd, "--format json pos_1 pos_a [TAB]"),
|
||||
snapbox::str![
|
||||
"--format
|
||||
--help\tPrint help
|
||||
-F
|
||||
-h\tPrint help"
|
||||
]
|
||||
);
|
||||
|
||||
assert_data_eq!(
|
||||
complete!(cmd, "--format json pos_1 pos_a pos_b pos_c [TAB]"),
|
||||
snapbox::str![
|
||||
"--format
|
||||
--help\tPrint help
|
||||
-F
|
||||
-h\tPrint help"
|
||||
]
|
||||
);
|
||||
|
||||
assert_data_eq!(
|
||||
complete!(cmd, "--format json -- pos_1 pos_a [TAB]"),
|
||||
snapbox::str![""]
|
||||
);
|
||||
|
||||
assert_data_eq!(
|
||||
complete!(cmd, "--format json -- pos_1 pos_a pos_b [TAB]"),
|
||||
snapbox::str![""]
|
||||
);
|
||||
|
||||
assert_data_eq!(
|
||||
complete!(cmd, "--format json -- pos_1 pos_a pos_b pos_c [TAB]"),
|
||||
snapbox::str![""]
|
||||
);
|
||||
}
|
||||
|
||||
fn complete(cmd: &mut Command, args: impl AsRef<str>, current_dir: Option<&Path>) -> String {
|
||||
let input = args.as_ref();
|
||||
let mut args = vec![std::ffi::OsString::from(cmd.get_name())];
|
||||
|
|
Loading…
Reference in a new issue