mirror of
https://github.com/clap-rs/clap
synced 2024-12-13 14:22:34 +00:00
test(clap_complete): Add test cases for delimiter_values support
This commit is contained in:
parent
a3a476407b
commit
ccecab394b
1 changed files with 108 additions and 0 deletions
|
@ -615,6 +615,114 @@ pos_c
|
|||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn suggest_delimiter_values() {
|
||||
let mut cmd = Command::new("delimiter")
|
||||
.arg(
|
||||
clap::Arg::new("delimiter")
|
||||
.long("delimiter")
|
||||
.short('D')
|
||||
.value_parser([
|
||||
PossibleValue::new("comma"),
|
||||
PossibleValue::new("space"),
|
||||
PossibleValue::new("tab"),
|
||||
])
|
||||
.value_delimiter(','),
|
||||
)
|
||||
.arg(
|
||||
clap::Arg::new("pos")
|
||||
.index(1)
|
||||
.value_parser(["a_pos", "b_pos", "c_pos"])
|
||||
.value_delimiter(','),
|
||||
);
|
||||
|
||||
assert_data_eq!(
|
||||
complete!(cmd, "--delimiter [TAB]"),
|
||||
snapbox::str![
|
||||
"comma
|
||||
space
|
||||
tab"
|
||||
]
|
||||
);
|
||||
|
||||
assert_data_eq!(
|
||||
complete!(cmd, "--delimiter=[TAB]"),
|
||||
snapbox::str![
|
||||
"--delimiter=comma
|
||||
--delimiter=space
|
||||
--delimiter=tab"
|
||||
]
|
||||
);
|
||||
|
||||
assert_data_eq!(complete!(cmd, "--delimiter c[TAB]"), snapbox::str!["comma"]);
|
||||
|
||||
assert_data_eq!(
|
||||
complete!(cmd, "--delimiter=c[TAB]"),
|
||||
snapbox::str!["--delimiter=comma"]
|
||||
);
|
||||
|
||||
assert_data_eq!(complete!(cmd, "--delimiter comma,[TAB]"), snapbox::str![""]);
|
||||
|
||||
assert_data_eq!(complete!(cmd, "--delimiter=comma,[TAB]"), snapbox::str![""]);
|
||||
|
||||
assert_data_eq!(
|
||||
complete!(cmd, "--delimiter comma,s[TAB]"),
|
||||
snapbox::str![""]
|
||||
);
|
||||
|
||||
assert_data_eq!(
|
||||
complete!(cmd, "--delimiter=comma,s[TAB]"),
|
||||
snapbox::str![""]
|
||||
);
|
||||
|
||||
assert_data_eq!(
|
||||
complete!(cmd, "-D [TAB]"),
|
||||
snapbox::str![
|
||||
"comma
|
||||
space
|
||||
tab"
|
||||
]
|
||||
);
|
||||
|
||||
assert_data_eq!(
|
||||
complete!(cmd, "-D=[TAB]"),
|
||||
snapbox::str![
|
||||
"-D=comma
|
||||
-D=space
|
||||
-D=tab"
|
||||
]
|
||||
);
|
||||
|
||||
assert_data_eq!(complete!(cmd, "-D c[TAB]"), snapbox::str!["comma"]);
|
||||
|
||||
assert_data_eq!(complete!(cmd, "-D=c[TAB]"), snapbox::str!["-D=comma"]);
|
||||
|
||||
assert_data_eq!(complete!(cmd, "-D comma,[TAB]"), snapbox::str![""]);
|
||||
|
||||
assert_data_eq!(complete!(cmd, "-D=comma,[TAB]"), snapbox::str![""]);
|
||||
|
||||
assert_data_eq!(complete!(cmd, "-D comma,s[TAB]"), snapbox::str![""]);
|
||||
|
||||
assert_data_eq!(complete!(cmd, "-D=comma,s[TAB]"), snapbox::str![""]);
|
||||
|
||||
assert_data_eq!(
|
||||
complete!(cmd, "-- [TAB]"),
|
||||
snapbox::str![
|
||||
"--delimiter
|
||||
--help\tPrint help
|
||||
-D
|
||||
-h\tPrint help
|
||||
a_pos
|
||||
b_pos
|
||||
c_pos"
|
||||
]
|
||||
);
|
||||
|
||||
assert_data_eq!(complete!(cmd, " -- a_pos,[TAB]"), snapbox::str![""]);
|
||||
|
||||
assert_data_eq!(complete!(cmd, "-- a_pos,b[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