test(complete): Verify space in completed value

This commit is contained in:
Ed Page 2024-09-04 09:42:52 -05:00
parent c3e5d16183
commit 5286385dac
8 changed files with 112 additions and 4 deletions

View file

@ -86,6 +86,7 @@ fn cli() -> clap::Command {
.long("choice")
.action(clap::ArgAction::Set)
.value_parser(clap::builder::PossibleValuesParser::new([
PossibleValue::new("another shell").help("something with a space"),
PossibleValue::new("bash").help("bash (shell)"),
PossibleValue::new("fish").help("fish shell"),
PossibleValue::new("zsh").help("zsh shell"),

View file

@ -728,7 +728,7 @@ _exhaustive() {
fi
case "${prev}" in
--choice)
COMPREPLY=($(compgen -W "bash fish zsh" -- "${cur}"))
COMPREPLY=($(compgen -W "another shell bash fish zsh" -- "${cur}"))
return 0
;;
*)

View file

@ -43,7 +43,7 @@ complete -c exhaustive -n "__fish_exhaustive_using_subcommand action" -l count -
complete -c exhaustive -n "__fish_exhaustive_using_subcommand action" -l global -d 'everywhere'
complete -c exhaustive -n "__fish_exhaustive_using_subcommand action" -s h -l help -d 'Print help'
complete -c exhaustive -n "__fish_exhaustive_using_subcommand action" -s V -l version -d 'Print version'
complete -c exhaustive -n "__fish_exhaustive_using_subcommand quote; and not __fish_seen_subcommand_from cmd-single-quotes cmd-double-quotes cmd-backticks cmd-backslash cmd-brackets cmd-expansions escape-help help" -l choice -r -f -a "{bash\t'bash (shell)',fish\t'fish shell',zsh\t'zsh shell'}"
complete -c exhaustive -n "__fish_exhaustive_using_subcommand quote; and not __fish_seen_subcommand_from cmd-single-quotes cmd-double-quotes cmd-backticks cmd-backslash cmd-brackets cmd-expansions escape-help help" -l choice -r -f -a "{another shell\t'something with a space',bash\t'bash (shell)',fish\t'fish shell',zsh\t'zsh shell'}"
complete -c exhaustive -n "__fish_exhaustive_using_subcommand quote; and not __fish_seen_subcommand_from cmd-single-quotes cmd-double-quotes cmd-backticks cmd-backslash cmd-brackets cmd-expansions escape-help help" -l single-quotes -d 'Can be \'always\', \'auto\', or \'never\''
complete -c exhaustive -n "__fish_exhaustive_using_subcommand quote; and not __fish_seen_subcommand_from cmd-single-quotes cmd-double-quotes cmd-backticks cmd-backslash cmd-brackets cmd-expansions escape-help help" -l double-quotes -d 'Can be "always", "auto", or "never"'
complete -c exhaustive -n "__fish_exhaustive_using_subcommand quote; and not __fish_seen_subcommand_from cmd-single-quotes cmd-double-quotes cmd-backticks cmd-backslash cmd-brackets cmd-expansions escape-help help" -l backticks -d 'For more information see `echo test`'

View file

@ -45,7 +45,8 @@ _arguments "${_arguments_options[@]}" : \
;;
(quote)
_arguments "${_arguments_options[@]}" : \
'--choice=[]: :((bash\:"bash (shell)"
'--choice=[]: :((another\ shell\:"something with a space"
bash\:"bash (shell)"
fish\:"fish shell"
zsh\:"zsh shell"))' \
'--single-quotes[Can be '\''always'\'', '\''auto'\'', or '\''never'\'']' \

View file

@ -303,3 +303,29 @@ fn complete_dynamic_env_option_value() {
let actual = runtime.complete(input, &term).unwrap();
assert_data_eq!(actual, expected);
}
#[test]
#[cfg(all(unix, feature = "unstable-dynamic"))]
fn complete_dynamic_env_quoted_value() {
if !common::has_command("bash") {
return;
}
let term = completest::Term::new();
let mut runtime =
common::load_runtime::<completest_pty::BashRuntimeBuilder>("dynamic-env", "exhaustive");
let input = "exhaustive quote --choice \t\t";
let expected = snapbox::str![[r#"
%
another shell bash fish zsh
"#]];
let actual = runtime.complete(input, &term).unwrap();
assert_data_eq!(actual, expected);
let input = "exhaustive quote --choice an\t";
let expected =
snapbox::str!["exhaustive quote --choice an % exhaustive quote --choice another shell "];
let actual = runtime.complete(input, &term).unwrap();
assert_data_eq!(actual, expected);
}

View file

@ -255,3 +255,33 @@ fn complete_dynamic_env_option_value() {
let actual = runtime.complete(input, &term).unwrap();
assert_data_eq!(actual, expected);
}
#[test]
#[cfg(all(unix, feature = "unstable-dynamic"))]
fn complete_dynamic_env_quoted_value() {
if !common::has_command("elvish") {
return;
}
let term = completest::Term::new();
let mut runtime =
common::load_runtime::<completest_pty::ElvishRuntimeBuilder>("dynamic-env", "exhaustive");
let input = "exhaustive quote --choice \t";
let expected = snapbox::str![[r#"
% exhaustive quote --choice 'another shell'
COMPLETING argument
another shell bash fish zsh
"#]];
let actual = runtime.complete(input, &term).unwrap();
assert_data_eq!(actual, expected);
let input = "exhaustive quote --choice an\t";
let expected = snapbox::str![[r#"
% exhaustive quote --choice 'another shell'
COMPLETING argument
another shell
"#]];
let actual = runtime.complete(input, &term).unwrap();
assert_data_eq!(actual, expected);
}

View file

@ -164,7 +164,7 @@ alias hint pacma
let actual = runtime.complete(input, &term).unwrap();
let expected = snapbox::str![[r#"
% exhaustive quote --choice
bash (bash (shell)) fish (fish shell) zsh (zsh shell)
another shell (something with a space) bash (bash (shell)) fish (fish shell) zsh (zsh shell)
"#]];
assert_data_eq!(actual, expected);
}
@ -262,3 +262,28 @@ fn complete_dynamic_env_option_value() {
let actual = runtime.complete(input, &term).unwrap();
assert_data_eq!(actual, expected);
}
#[test]
#[cfg(all(unix, feature = "unstable-dynamic"))]
fn complete_dynamic_env_quoted_value() {
if !common::has_command("fish") {
return;
}
let term = completest::Term::new();
let mut runtime =
common::load_runtime::<completest_pty::FishRuntimeBuilder>("dynamic-env", "exhaustive");
let input = "exhaustive quote --choice \t\t";
let expected = snapbox::str![[r#"
% exhaustive quote --choice another/ shell
another shell (something with a space) bash (bash (shell)) fish (fish shell) zsh (zsh shell)
"#]];
let actual = runtime.complete(input, &term).unwrap();
assert_data_eq!(actual, expected);
let input = "exhaustive quote --choice an\t";
let expected = snapbox::str!["% exhaustive quote --choice another/ shell "];
let actual = runtime.complete(input, &term).unwrap();
assert_data_eq!(actual, expected);
}

View file

@ -236,3 +236,28 @@ fn complete_dynamic_env_option_value() {
let actual = runtime.complete(input, &term).unwrap();
assert_data_eq!(actual, expected);
}
#[test]
#[cfg(all(unix, feature = "unstable-dynamic"))]
fn complete_dynamic_env_quoted_value() {
if !common::has_command("zsh") {
return;
}
let term = completest::Term::new();
let mut runtime =
common::load_runtime::<completest_pty::ZshRuntimeBuilder>("dynamic-env", "exhaustive");
let input = "exhaustive quote --choice \t\t";
let expected = snapbox::str![[r#"
% exhaustive quote --choice
another/ shell bash fish zsh
"#]];
let actual = runtime.complete(input, &term).unwrap();
assert_data_eq!(actual, expected);
let input = "exhaustive quote --choice an\t\t";
let expected = snapbox::str!["% exhaustive quote --choice another/ shell "];
let actual = runtime.complete(input, &term).unwrap();
assert_data_eq!(actual, expected);
}