From 5286385dacdcbe2693821671b1fbc567a082400d Mon Sep 17 00:00:00 2001 From: Ed Page Date: Wed, 4 Sep 2024 09:42:52 -0500 Subject: [PATCH] test(complete): Verify space in completed value --- clap_complete/examples/exhaustive.rs | 1 + .../home/static/exhaustive/bash/.bashrc | 2 +- .../fish/fish/completions/exhaustive.fish | 2 +- .../static/exhaustive/zsh/zsh/_exhaustive | 3 +- clap_complete/tests/testsuite/bash.rs | 26 ++++++++++++++++ clap_complete/tests/testsuite/elvish.rs | 30 +++++++++++++++++++ clap_complete/tests/testsuite/fish.rs | 27 ++++++++++++++++- clap_complete/tests/testsuite/zsh.rs | 25 ++++++++++++++++ 8 files changed, 112 insertions(+), 4 deletions(-) diff --git a/clap_complete/examples/exhaustive.rs b/clap_complete/examples/exhaustive.rs index cbe604ac..7079ed14 100644 --- a/clap_complete/examples/exhaustive.rs +++ b/clap_complete/examples/exhaustive.rs @@ -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"), diff --git a/clap_complete/tests/snapshots/home/static/exhaustive/bash/.bashrc b/clap_complete/tests/snapshots/home/static/exhaustive/bash/.bashrc index b8ce1da5..be558dec 100644 --- a/clap_complete/tests/snapshots/home/static/exhaustive/bash/.bashrc +++ b/clap_complete/tests/snapshots/home/static/exhaustive/bash/.bashrc @@ -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 ;; *) diff --git a/clap_complete/tests/snapshots/home/static/exhaustive/fish/fish/completions/exhaustive.fish b/clap_complete/tests/snapshots/home/static/exhaustive/fish/fish/completions/exhaustive.fish index dd17413c..82c56229 100644 --- a/clap_complete/tests/snapshots/home/static/exhaustive/fish/fish/completions/exhaustive.fish +++ b/clap_complete/tests/snapshots/home/static/exhaustive/fish/fish/completions/exhaustive.fish @@ -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`' diff --git a/clap_complete/tests/snapshots/home/static/exhaustive/zsh/zsh/_exhaustive b/clap_complete/tests/snapshots/home/static/exhaustive/zsh/zsh/_exhaustive index 4ceaca2d..52819144 100644 --- a/clap_complete/tests/snapshots/home/static/exhaustive/zsh/zsh/_exhaustive +++ b/clap_complete/tests/snapshots/home/static/exhaustive/zsh/zsh/_exhaustive @@ -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'\'']' \ diff --git a/clap_complete/tests/testsuite/bash.rs b/clap_complete/tests/testsuite/bash.rs index e0019d86..88dffe83 100644 --- a/clap_complete/tests/testsuite/bash.rs +++ b/clap_complete/tests/testsuite/bash.rs @@ -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::("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); +} diff --git a/clap_complete/tests/testsuite/elvish.rs b/clap_complete/tests/testsuite/elvish.rs index 9821f264..b0018a1b 100644 --- a/clap_complete/tests/testsuite/elvish.rs +++ b/clap_complete/tests/testsuite/elvish.rs @@ -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::("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); +} diff --git a/clap_complete/tests/testsuite/fish.rs b/clap_complete/tests/testsuite/fish.rs index 451b57fa..9dccb53c 100644 --- a/clap_complete/tests/testsuite/fish.rs +++ b/clap_complete/tests/testsuite/fish.rs @@ -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::("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); +} diff --git a/clap_complete/tests/testsuite/zsh.rs b/clap_complete/tests/testsuite/zsh.rs index 1d0e507c..4bc30a4d 100644 --- a/clap_complete/tests/testsuite/zsh.rs +++ b/clap_complete/tests/testsuite/zsh.rs @@ -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::("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); +}