Skip to content

Commit

Permalink
test(complete): Show empty option-value behavior
Browse files Browse the repository at this point in the history
  • Loading branch information
epage committed Dec 24, 2024
1 parent 3c14c63 commit cca5f32
Show file tree
Hide file tree
Showing 4 changed files with 94 additions and 0 deletions.
22 changes: 22 additions & 0 deletions clap_complete/tests/testsuite/bash.rs
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,11 @@ fn complete() {
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 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/"];
Expand Down Expand Up @@ -358,3 +363,20 @@ fn complete_dynamic_empty_subcommand() {
let actual = runtime.complete(input, &term).unwrap();
assert_data_eq!(actual, expected);
}

#[test]
#[cfg(all(unix, feature = "unstable-dynamic"))]
#[cfg(feature = "unstable-shell-tests")]
fn complete_dynamic_empty_option_value() {
if !common::has_command(CMD) {
return;
}

let term = completest::Term::new();
let mut runtime = common::load_runtime::<RuntimeBuilder>("dynamic-env", "exhaustive");

let input = "exhaustive --empty=\t";
let expected = snapbox::str!["exhaustive --empty= % exhaustive --empty="];
let actual = runtime.complete(input, &term).unwrap();
assert_data_eq!(actual, expected);
}
28 changes: 28 additions & 0 deletions clap_complete/tests/testsuite/elvish.rs
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,14 @@ value value
let expected = snapbox::str![[r#"
no candidates
% exhaustive empty
"#]];
let actual = runtime.complete(input, &term).unwrap();
assert_data_eq!(actual, expected);

let input = "exhaustive --empty=\t";
let expected = snapbox::str![[r#"
no candidates
% exhaustive --empty=
"#]];
let actual = runtime.complete(input, &term).unwrap();
assert_data_eq!(actual, expected);
Expand Down Expand Up @@ -323,3 +331,23 @@ no candidates
let actual = runtime.complete(input, &term).unwrap();
assert_data_eq!(actual, expected);
}

#[test]
#[cfg(all(unix, feature = "unstable-dynamic"))]
#[cfg(feature = "unstable-shell-tests")]
fn complete_dynamic_empty_option_value() {
if !common::has_command(CMD) {
return;
}

let term = completest::Term::new();
let mut runtime = common::load_runtime::<RuntimeBuilder>("dynamic-env", "exhaustive");

let input = "exhaustive --empty=\t";
let expected = snapbox::str![[r#"
no candidates
% exhaustive --empty=
"#]];
let actual = runtime.complete(input, &term).unwrap();
assert_data_eq!(actual, expected);
}
22 changes: 22 additions & 0 deletions clap_complete/tests/testsuite/fish.rs
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,11 @@ CHANGELOG.md examples/ LICENSE-MIT src/
let actual = runtime.complete(input, &term).unwrap();
assert_data_eq!(actual, expected);

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

let input = "exhaustive quote --choice \t";
let actual = runtime.complete(input, &term).unwrap();
let expected = snapbox::str![[r#"
Expand Down Expand Up @@ -317,3 +322,20 @@ fn complete_dynamic_empty_subcommand() {
let actual = runtime.complete(input, &term).unwrap();
assert_data_eq!(actual, expected);
}

#[test]
#[cfg(all(unix, feature = "unstable-dynamic"))]
#[cfg(feature = "unstable-shell-tests")]
fn complete_dynamic_empty_option_value() {
if !common::has_command(CMD) {
return;
}

let term = completest::Term::new();
let mut runtime = common::load_runtime::<RuntimeBuilder>("dynamic-env", "exhaustive");

let input = "exhaustive --empty=\t";
let expected = snapbox::str!["% exhaustive --empty="];
let actual = runtime.complete(input, &term).unwrap();
assert_data_eq!(actual, expected);
}
22 changes: 22 additions & 0 deletions clap_complete/tests/testsuite/zsh.rs
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,11 @@ pacman action global alias value quote empty last --
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="];
let actual = runtime.complete(input, &term).unwrap();
assert_data_eq!(actual, expected);
}

#[test]
Expand Down Expand Up @@ -306,3 +311,20 @@ fn complete_dynamic_empty_subcommand() {
let actual = runtime.complete(input, &term).unwrap();
assert_data_eq!(actual, expected);
}

#[test]
#[cfg(all(unix, feature = "unstable-dynamic"))]
#[cfg(feature = "unstable-shell-tests")]
fn complete_dynamic_empty_option_value() {
if !common::has_command(CMD) {
return;
}

let term = completest::Term::new();
let mut runtime = common::load_runtime::<RuntimeBuilder>("dynamic-env", "exhaustive");

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

0 comments on commit cca5f32

Please sign in to comment.