Skip to content

Commit

Permalink
test(clap_complete): Add test cases for delimiter_values support
Browse files Browse the repository at this point in the history
  • Loading branch information
shannmu authored and epage committed Aug 16, 2024
1 parent a3a4764 commit ccecab3
Showing 1 changed file with 108 additions and 0 deletions.
108 changes: 108 additions & 0 deletions clap_complete/tests/testsuite/dynamic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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())];
Expand Down

0 comments on commit ccecab3

Please sign in to comment.