Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid using newline as a completion separator #17

Merged
merged 1 commit into from
May 17, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions tests/bash/comp-test-lib.bash
Original file line number Diff line number Diff line change
Expand Up @@ -188,10 +188,16 @@ _completionTests_complete() {
# to stderr.
eval $(_completionTests_findCompletionFunction ${COMP_WORDS[0]}) 2>&1

# Return the result of the completion.
# Return the result of the call to the completion function.
# We separate each completion with a space and not a newline; using newlines
# was preventing us from detecting empty completions as newlines are stripped
# automatically by the sub-shell call to this function.
result="$(printf "%s " "${COMPREPLY[@]}")"
# remove the last space we inserted ourselves
result="${result% }"
# We use printf instead of echo as the first completion could be -n which
# would be interpreted as an argument to echo
printf "%s\n" "${COMPREPLY[@]}"
printf "%s" "${result}"
}

_completionTests_exit() {
Expand Down
43 changes: 12 additions & 31 deletions tests/bash/comp-tests.bash
Original file line number Diff line number Diff line change
Expand Up @@ -232,38 +232,23 @@ EOF
COLUMNS=${COLUMNS-100}

# Test descriptions with ShellCompDirectiveDefault
_completionTests_verifyCompletion "testprog prefix default " "bear (an animal)
bearpaw (a dessert)
dog
unicorn (mythical)"
_completionTests_verifyCompletion "testprog prefix default b" "bear (an animal)
bearpaw (a dessert)"
_completionTests_verifyCompletion "testprog prefix default " "bear (an animal) bearpaw (a dessert) dog unicorn (mythical)"
_completionTests_verifyCompletion "testprog prefix default b" "bear (an animal) bearpaw (a dessert)"
_completionTests_verifyCompletion "testprog prefix default bearp" "bearpaw"

# Test descriptions with ShellCompDirectiveNoFileComp
_completionTests_verifyCompletion "testprog prefix nofile " "bear (an animal)
bearpaw (a dessert)
dog
unicorn (mythical)" nofile
_completionTests_verifyCompletion "testprog prefix nofile b" "bear (an animal)
bearpaw (a dessert)" nofile
_completionTests_verifyCompletion "testprog prefix nofile " "bear (an animal) bearpaw (a dessert) dog unicorn (mythical)" nofile
_completionTests_verifyCompletion "testprog prefix nofile b" "bear (an animal) bearpaw (a dessert)" nofile
_completionTests_verifyCompletion "testprog prefix nofile bearp" "bearpaw" nofile

# Test descriptions with ShellCompDirectiveNoSpace
_completionTests_verifyCompletion "testprog prefix nospace " "bear (an animal)
bearpaw (a dessert)
dog
unicorn (mythical)" nospace
_completionTests_verifyCompletion "testprog prefix nospace b" "bear (an animal)
bearpaw (a dessert)" nospace
_completionTests_verifyCompletion "testprog prefix nospace " "bear (an animal) bearpaw (a dessert) dog unicorn (mythical)" nospace
_completionTests_verifyCompletion "testprog prefix nospace b" "bear (an animal) bearpaw (a dessert)" nospace
_completionTests_verifyCompletion "testprog prefix nospace bearp" "bearpaw" nospace

# Test descriptions with completion of flag values
_completionTests_verifyCompletion "testprog --customComp " "firstComp (the first value)
secondComp (the second value)
forthComp" nofile
_completionTests_verifyCompletion "testprog --customComp f" "firstComp (the first value)
forthComp" nofile
_completionTests_verifyCompletion "testprog --customComp " "firstComp (the first value) secondComp (the second value) forthComp" nofile
_completionTests_verifyCompletion "testprog --customComp f" "firstComp (the first value) forthComp" nofile
_completionTests_verifyCompletion "testprog --customComp fi" "firstComp" nofile

# Measure speed of execution with descriptions
Expand All @@ -273,19 +258,15 @@ forthComp" nofile
# The types are: menu-complete/menu-complete-backward (COMP_TYPE == 37)
# and insert-completions (COMP_TYPE == 42)
COMP_TYPE=37
_completionTests_verifyCompletion "testprog prefix nospace b" "bear
bearpaw" nospace
_completionTests_verifyCompletion "testprog prefix nofile b" "bear
bearpaw" nofile
_completionTests_verifyCompletion "testprog prefix nospace b" "bear bearpaw" nospace
_completionTests_verifyCompletion "testprog prefix nofile b" "bear bearpaw" nofile

# Measure speed of execution with menu-complete with descriptions
_completionTests_timing "testprog manycomps " 0.2 "menu-complete with descs"

COMP_TYPE=42
_completionTests_verifyCompletion "testprog prefix nospace b" "bear
bearpaw" nospace
_completionTests_verifyCompletion "testprog prefix nofile b" "bear
bearpaw" nofile
_completionTests_verifyCompletion "testprog prefix nospace b" "bear bearpaw" nospace
_completionTests_verifyCompletion "testprog prefix nofile b" "bear bearpaw" nofile

# Measure speed of execution with insert-completions with descriptions
_completionTests_timing "testprog manycomps " 0.2 "insert-completions no descs"
Expand Down