Skip to content

Commit

Permalink
test(complete): Show empty subcommand behavior
Browse files Browse the repository at this point in the history
  • Loading branch information
epage committed Dec 24, 2024
1 parent 8e246ef commit a1b866d
Show file tree
Hide file tree
Showing 4 changed files with 100 additions and 1 deletion.
22 changes: 22 additions & 0 deletions clap_complete/tests/testsuite/bash.rs
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,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 @@ -336,3 +341,20 @@ another shell bash fish zsh
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_subcommand() {
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);
}
31 changes: 30 additions & 1 deletion clap_complete/tests/testsuite/elvish.rs
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ fn register_completion() {
#[test]
#[cfg(unix)]
#[cfg(feature = "unstable-shell-tests")]
fn complete_static_toplevel() {
fn complete() {
if !common::has_command(CMD) {
return;
}
Expand All @@ -177,6 +177,14 @@ last last
pacman pacman
quote quote
value value
"#]];
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 @@ -293,3 +301,24 @@ another shell
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_subcommand() {
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\t";
let expected = snapbox::str![[r#"
no candidates
no candidates
% exhaustive empty
"#]];
let actual = runtime.complete(input, &term).unwrap();
assert_data_eq!(actual, expected);
}
26 changes: 26 additions & 0 deletions clap_complete/tests/testsuite/fish.rs
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,15 @@ alias global hint
let actual = runtime.complete(input, &term).unwrap();
assert_data_eq!(actual, expected);

let input = "exhaustive empty \t";
let expected = snapbox::str![[r#"
% exhaustive empty
Cargo.toml CONTRIBUTING.md LICENSE-APACHE README.md tests/
CHANGELOG.md examples/ LICENSE-MIT src/
"#]];
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 @@ -290,3 +299,20 @@ another shell (something with a space) bash (bash (shell)) fish (fish shell
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_subcommand() {
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\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 @@ -170,6 +170,11 @@ pacman action global alias value quote empty last --
"#]];
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 @@ -283,3 +288,20 @@ zsh -- zsh shell
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_subcommand() {
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\t";
let expected = snapbox::str!["% exhaustive empty "];
let actual = runtime.complete(input, &term).unwrap();
assert_data_eq!(actual, expected);
}

0 comments on commit a1b866d

Please sign in to comment.