Skip to content

Commit

Permalink
test(clap_complete): Add test case for multi-values comlpetion after …
Browse files Browse the repository at this point in the history
…flags
  • Loading branch information
shannmu committed Jul 30, 2024
1 parent 16fba4b commit 5d8c84b
Showing 1 changed file with 151 additions and 0 deletions.
151 changes: 151 additions & 0 deletions clap_complete/tests/testsuite/dynamic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -439,6 +439,157 @@ pos_c"
);
}

#[test]
fn suggest_argument_multi_values() {
let mut cmd = Command::new("dynamic")
.arg(
clap::Arg::new("certain-num")
.long("certain-num")
.short('Y')
.value_parser(["val1", "val2", "val3"])
.num_args(3),
)
.arg(
clap::Arg::new("uncertain-num")
.long("uncertain-num")
.short('N')
.value_parser(["val1", "val2", "val3"])
.num_args(1..=3),
);

assert_data_eq!(
complete!(cmd, "--certain-num [TAB]"),
snapbox::str![
"val1
val2
val3"
]
);

assert_data_eq!(
complete!(cmd, "--certain-num val1 [TAB]"),
snapbox::str![
"--certain-num
--uncertain-num
--help\tPrint help
-Y
-N
-h\tPrint help"
]
);

assert_data_eq!(
complete!(cmd, "--certain-num val1 val2 val3 [TAB]"),
snapbox::str![
"--certain-num
--uncertain-num
--help\tPrint help
-Y
-N
-h\tPrint help"
]
);

assert_data_eq!(
complete!(cmd, "--uncertain-num [TAB]"),
snapbox::str![
"val1
val2
val3"
]
);

assert_data_eq!(
complete!(cmd, "--uncertain-num val1 [TAB]"),
snapbox::str![
"--certain-num
--uncertain-num
--help\tPrint help
-Y
-N
-h\tPrint help"
]
);

assert_data_eq!(
complete!(cmd, "--uncertain-num val1 val2 val3 [TAB]"),
snapbox::str![
"--certain-num
--uncertain-num
--help\tPrint help
-Y
-N
-h\tPrint help"
]
);

assert_data_eq!(
complete!(cmd, "-Y [TAB]"),
snapbox::str![
"val1
val2
val3"
]
);

assert_data_eq!(
complete!(cmd, "-Y val1 [TAB]"),
snapbox::str![
"--certain-num
--uncertain-num
--help\tPrint help
-Y
-N
-h\tPrint help"
]
);

assert_data_eq!(
complete!(cmd, "-Y val1 val2 val3 [TAB]"),
snapbox::str![
"--certain-num
--uncertain-num
--help\tPrint help
-Y
-N
-h\tPrint help"
]
);

assert_data_eq!(
complete!(cmd, "-N [TAB]"),
snapbox::str![
"val1
val2
val3"
]
);

assert_data_eq!(
complete!(cmd, "-N val1 [TAB]"),
snapbox::str![
"--certain-num
--uncertain-num
--help\tPrint help
-Y
-N
-h\tPrint help"
]
);

assert_data_eq!(
complete!(cmd, "-N val1 val2 val3 [TAB]"),
snapbox::str![
"--certain-num
--uncertain-num
--help\tPrint help
-Y
-N
-h\tPrint help"
]
);
}

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 5d8c84b

Please sign in to comment.