Skip to content

Commit

Permalink
test(command): add file type completion test for zsh (#688)
Browse files Browse the repository at this point in the history
  • Loading branch information
c4spar committed Mar 25, 2024
1 parent a5cd35e commit fba0969
Show file tree
Hide file tree
Showing 2 changed files with 458 additions and 1 deletion.
399 changes: 399 additions & 0 deletions command/test/command/__snapshots__/completion_test.ts.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,399 @@
export const snapshot = {};

snapshot[`should handle file type completions in options > zsh 1`] = `
stdout:
\`#!/usr/bin/env zsh
# zsh completion support for completions-test v1.0.0
autoload -U is-at-least
# shellcheck disable=SC2154
(( \$+functions[__completions_test_complete] )) ||
function __completions_test_complete {
local name="\$1"; shift
local action="\$1"; shift
integer ret=1
local -a values
local expl lines
_tags "\$name"
while _tags; do
if _requested "\$name"; then
# shellcheck disable=SC2034
lines="\$(completions-test completions complete "\${action}" "\${@}")"
values=("\${(ps:\\\\n:)lines}")
if (( \${#values[@]} )); then
while _next_label "\$name" expl "\$action"; do
compadd -S '' "\${expl[@]}" "\${values[@]}"
done
fi
fi
done
}
# shellcheck disable=SC2154
(( \$+functions[_completions_test] )) ||
function _completions_test() {
local state
function _commands() {
local -a commands
# shellcheck disable=SC2034
commands=(
'foo:'
'bar:'
'beep:'
'boop:'
'completions:Generate shell completions.'
)
_describe 'command' commands
}
function _command_args() {
case "\${words[1]}" in
foo) _completions_test_foo ;;
bar) _completions_test_bar ;;
beep) _completions_test_beep ;;
boop) _completions_test_boop ;;
completions) _completions_test_completions ;;
esac
}
_arguments -w -s -S -C \\\\
'(- *)'{-h,--help}'[Show this help.]' \\\\
'(- *)'{-V,--version}'[Show the version number for this program.]' \\\\
'1:command:_commands' \\\\
'*::sub command:->command_args'
case "\$state" in
command_args) _command_args ;;
esac
}
# shellcheck disable=SC2154
(( \$+functions[_completions_test_foo] )) ||
function _completions_test_foo() {
_arguments -w -s -S -C \\\\
'(- *)'{-h,--help}'[Show this help.]' \\\\
'(-h --help -f --file1)'{-f,--file1}'[...]:path:_files'
}
# shellcheck disable=SC2154
(( \$+functions[_completions_test_bar] )) ||
function _completions_test_bar() {
_arguments -w -s -S -C \\\\
'(- *)'{-h,--help}'[Show this help.]' \\\\
'(-h --help -f --file2)'{-f,--file2}'[...]:name:->name-string:path:_files'
case "\$state" in
name-string) __completions_test_complete name string bar ;;
esac
}
# shellcheck disable=SC2154
(( \$+functions[_completions_test_beep] )) ||
function _completions_test_beep() {
_arguments -w -s -S -C \\\\
'(- *)'{-h,--help}'[Show this help.]' \\\\
'(-h --help -f --file3)'{-f,--file3}'[...]:path:_files'
}
# shellcheck disable=SC2154
(( \$+functions[_completions_test_boop] )) ||
function _completions_test_boop() {
_arguments -w -s -S -C \\\\
'(- *)'{-h,--help}'[Show this help.]' \\\\
'(-h --help -f --file4)'{-f,--file4}'[...]:name:->name-string:path:_files'
case "\$state" in
name-string) __completions_test_complete name string boop ;;
esac
}
# shellcheck disable=SC2154
(( \$+functions[_completions_test_completions] )) ||
function _completions_test_completions() {
function _commands() {
local -a commands
# shellcheck disable=SC2034
commands=(
'bash:Generate shell completions for bash.'
'fish:Generate shell completions for fish.'
'zsh:Generate shell completions for zsh.'
)
_describe 'command' commands
}
function _command_args() {
case "\${words[1]}" in
bash) _completions_test_completions_bash ;;
fish) _completions_test_completions_fish ;;
zsh) _completions_test_completions_zsh ;;
esac
}
_arguments -w -s -S -C \\\\
'(- *)'{-h,--help}'[Show this help.]' \\\\
'1:command:_commands' \\\\
'*::sub command:->command_args'
case "\$state" in
command_args) _command_args ;;
esac
}
# shellcheck disable=SC2154
(( \$+functions[_completions_test_completions_bash] )) ||
function _completions_test_completions_bash() {
_arguments -w -s -S -C \\\\
'(- *)'{-h,--help}'[Show this help.]' \\\\
'(-h --help -n --name)'{-n,--name}'[The name of the main command.]:command-name:->command-name-string'
case "\$state" in
command-name-string) __completions_test_complete command-name string completions bash ;;
esac
}
# shellcheck disable=SC2154
(( \$+functions[_completions_test_completions_fish] )) ||
function _completions_test_completions_fish() {
_arguments -w -s -S -C \\\\
'(- *)'{-h,--help}'[Show this help.]' \\\\
'(-h --help -n --name)'{-n,--name}'[The name of the main command.]:command-name:->command-name-string'
case "\$state" in
command-name-string) __completions_test_complete command-name string completions fish ;;
esac
}
# shellcheck disable=SC2154
(( \$+functions[_completions_test_completions_zsh] )) ||
function _completions_test_completions_zsh() {
_arguments -w -s -S -C \\\\
'(- *)'{-h,--help}'[Show this help.]' \\\\
'(-h --help -n --name)'{-n,--name}'[The name of the main command.]:command-name:->command-name-string'
case "\$state" in
command-name-string) __completions_test_complete command-name string completions zsh ;;
esac
}
# _completions_test "\${@}"
compdef _completions_test completions-test
\`
stderr:
""
`;

snapshot[`should generate file type completions in arguments > zsh 1`] = `
stdout:
\`#!/usr/bin/env zsh
# zsh completion support for completions-test v1.0.0
autoload -U is-at-least
# shellcheck disable=SC2154
(( \$+functions[__completions_test_complete] )) ||
function __completions_test_complete {
local name="\$1"; shift
local action="\$1"; shift
integer ret=1
local -a values
local expl lines
_tags "\$name"
while _tags; do
if _requested "\$name"; then
# shellcheck disable=SC2034
lines="\$(completions-test completions complete "\${action}" "\${@}")"
values=("\${(ps:\\\\n:)lines}")
if (( \${#values[@]} )); then
while _next_label "\$name" expl "\$action"; do
compadd -S '' "\${expl[@]}" "\${values[@]}"
done
fi
fi
done
}
# shellcheck disable=SC2154
(( \$+functions[_completions_test] )) ||
function _completions_test() {
local state
function _commands() {
local -a commands
# shellcheck disable=SC2034
commands=(
'foo:'
'bar:'
'beep:'
'boop:'
'completions:Generate shell completions.'
)
_describe 'command' commands
}
function _command_args() {
case "\${words[1]}" in
foo) _completions_test_foo ;;
bar) _completions_test_bar ;;
beep) _completions_test_beep ;;
boop) _completions_test_boop ;;
completions) _completions_test_completions ;;
esac
}
_arguments -w -s -S -C \\\\
'(- *)'{-h,--help}'[Show this help.]' \\\\
'(- *)'{-V,--version}'[Show the version number for this program.]' \\\\
'1:command:_commands' \\\\
'*::sub command:->command_args'
case "\$state" in
command_args) _command_args ;;
esac
}
# shellcheck disable=SC2154
(( \$+functions[_completions_test_foo] )) ||
function _completions_test_foo() {
function _commands() {
_files
}
_arguments -w -s -S -C \\\\
'(- *)'{-h,--help}'[Show this help.]' \\\\
'1:command:_commands'
}
# shellcheck disable=SC2154
(( \$+functions[_completions_test_bar] )) ||
function _completions_test_bar() {
function _commands() {
}
_arguments -w -s -S -C \\\\
'(- *)'{-h,--help}'[Show this help.]' \\\\
'1:command:_commands'\\\\
'2:path:_files'
}
# shellcheck disable=SC2154
(( \$+functions[_completions_test_beep] )) ||
function _completions_test_beep() {
function _commands() {
_files
}
_arguments -w -s -S -C \\\\
'(- *)'{-h,--help}'[Show this help.]' \\\\
'*:command:_commands'
}
# shellcheck disable=SC2154
(( \$+functions[_completions_test_boop] )) ||
function _completions_test_boop() {
function _commands() {
}
_arguments -w -s -S -C \\\\
'(- *)'{-h,--help}'[Show this help.]' \\\\
'1:command:_commands'\\\\
'2:path:_files'\\\\
'3:path:_files'\\\\
'4:path:_files'\\\\
'5:path:_files'\\\\
'6:path:_files'
}
# shellcheck disable=SC2154
(( \$+functions[_completions_test_completions] )) ||
function _completions_test_completions() {
function _commands() {
local -a commands
# shellcheck disable=SC2034
commands=(
'bash:Generate shell completions for bash.'
'fish:Generate shell completions for fish.'
'zsh:Generate shell completions for zsh.'
)
_describe 'command' commands
}
function _command_args() {
case "\${words[1]}" in
bash) _completions_test_completions_bash ;;
fish) _completions_test_completions_fish ;;
zsh) _completions_test_completions_zsh ;;
esac
}
_arguments -w -s -S -C \\\\
'(- *)'{-h,--help}'[Show this help.]' \\\\
'1:command:_commands' \\\\
'*::sub command:->command_args'
case "\$state" in
command_args) _command_args ;;
esac
}
# shellcheck disable=SC2154
(( \$+functions[_completions_test_completions_bash] )) ||
function _completions_test_completions_bash() {
_arguments -w -s -S -C \\\\
'(- *)'{-h,--help}'[Show this help.]' \\\\
'(-h --help -n --name)'{-n,--name}'[The name of the main command.]:command-name:->command-name-string'
case "\$state" in
command-name-string) __completions_test_complete command-name string completions bash ;;
esac
}
# shellcheck disable=SC2154
(( \$+functions[_completions_test_completions_fish] )) ||
function _completions_test_completions_fish() {
_arguments -w -s -S -C \\\\
'(- *)'{-h,--help}'[Show this help.]' \\\\
'(-h --help -n --name)'{-n,--name}'[The name of the main command.]:command-name:->command-name-string'
case "\$state" in
command-name-string) __completions_test_complete command-name string completions fish ;;
esac
}
# shellcheck disable=SC2154
(( \$+functions[_completions_test_completions_zsh] )) ||
function _completions_test_completions_zsh() {
_arguments -w -s -S -C \\\\
'(- *)'{-h,--help}'[Show this help.]' \\\\
'(-h --help -n --name)'{-n,--name}'[The name of the main command.]:command-name:->command-name-string'
case "\$state" in
command-name-string) __completions_test_complete command-name string completions zsh ;;
esac
}
# _completions_test "\${@}"
compdef _completions_test completions-test
\`
stderr:
""
`;
Loading

0 comments on commit fba0969

Please sign in to comment.