Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions clap_complete/tests/testsuite/bash.rs
Original file line number Diff line number Diff line change
Expand Up @@ -219,18 +219,18 @@ fn complete() {
assert_data_eq!(actual, expected);

let input = "exhaustive empty \t";
let expected = snapbox::str!["exhaustive empty % exhaustive empty "];
let expected = snapbox::str!["exhaustive empty "];
let actual = runtime.complete(input, &term).unwrap();
assert_data_eq!(actual, expected);

let input = "exhaustive --empty=\t";
let expected = snapbox::str!["exhaustive --empty= % exhaustive --empty="];
let expected = snapbox::str!["exhaustive --empty="];
let actual = runtime.complete(input, &term).unwrap();
assert_data_eq!(actual, expected);

// Issue 5239 (https://github.com/clap-rs/clap/issues/5239)
let input = "exhaustive hint --file test\t";
let expected = snapbox::str!["exhaustive hint --file test % exhaustive hint --file tests/"];
let expected = snapbox::str!["exhaustive hint --file test"];
let actual = runtime.complete(input, &term).unwrap();
assert_data_eq!(actual, expected);

Expand Down Expand Up @@ -443,7 +443,7 @@ fn complete_dynamic_empty_subcommand() {
let mut runtime = common::load_runtime::<RuntimeBuilder>("dynamic-env", "exhaustive");

let input = "exhaustive empty \t";
let expected = snapbox::str!["exhaustive empty % exhaustive empty "];
let expected = snapbox::str!["exhaustive empty "];
let actual = runtime.complete(input, &term).unwrap();
assert_data_eq!(actual, expected);
}
Expand All @@ -460,7 +460,7 @@ fn complete_dynamic_empty_option_value() {
let mut runtime = common::load_runtime::<RuntimeBuilder>("dynamic-env", "exhaustive");

let input = "exhaustive --empty=\t";
let expected = snapbox::str!["exhaustive --empty= % exhaustive --empty="];
let expected = snapbox::str!["exhaustive --empty="];
let actual = runtime.complete(input, &term).unwrap();
assert_data_eq!(actual, expected);
}
Expand Down Expand Up @@ -532,7 +532,7 @@ fn complete_dynamic_dir_no_trailing_space() {
let mut runtime = common::load_runtime::<RuntimeBuilder>("dynamic-env", "exhaustive");

let input = "exhaustive hint --file test\t";
let expected = snapbox::str!["exhaustive hint --file test % exhaustive hint --file tests/"];
let expected = snapbox::str!["exhaustive hint --file test"];
let actual = runtime.complete(input, &term).unwrap();
assert_data_eq!(actual, expected);
}
73 changes: 73 additions & 0 deletions clap_complete/tests/testsuite/engine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1443,6 +1443,79 @@ pos-c
);
}

#[test]
fn suggest_delimiter_with_allow_hyphen() {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If this is extra tests for value_delimiter, why is it not next to that?

let mut cmd = Command::new("delimiter")
.arg(
clap::Arg::new("values")
.long("values")
.value_parser(["normal", "--special", "-s"])
.value_delimiter(',')
.allow_hyphen_values(true),
);

// Completing first value
assert_data_eq!(
complete!(cmd, "--values [TAB]"),
snapbox::str![[r#"
normal
--special
-s
"#]]
);

// Completing second value after delimiter
assert_data_eq!(
complete!(cmd, "--values normal,[TAB]"),
snapbox::str![[r#"
normal,normal
normal,--special
normal,-s
"#]]
);

// Completing with hyphen prefix after delimiter
assert_data_eq!(
complete!(cmd, "--values normal,--[TAB]"),
snapbox::str!["normal,--special"]
);
}

#[test]
fn suggest_delimiter_positional_multi() {
Comment on lines +1484 to +1485
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What in particular is the concern this is trying to address?

let mut cmd = Command::new("delimiter")
.arg(
clap::Arg::new("pos1")
.value_parser(["a", "b", "c"])
.value_delimiter(','),
)
.arg(
clap::Arg::new("pos2")
.value_parser(["x", "y", "z"])
.value_delimiter(','),
);

// First positional with delimiter
assert_data_eq!(
complete!(cmd, "a,[TAB]"),
snapbox::str![[r#"
a,a
a,b
a,c
"#]]
);

// Second positional
assert_data_eq!(
complete!(cmd, "a x,[TAB]"),
snapbox::str![[r#"
x,x
x,y
x,z
"#]]
);
}

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
Loading