More tests for completion

pull/1043/head
Nils Winkler 2017-09-15 08:10:16 +02:00
parent b37da4e1f0
commit cd578f8772
2 changed files with 24 additions and 4 deletions

View File

@ -2,7 +2,7 @@
_bash-it-comp-enable-disable() _bash-it-comp-enable-disable()
{ {
local enable_disable_args="alias plugin completion" local enable_disable_args="alias completion plugin"
COMPREPLY=( $(compgen -W "${enable_disable_args}" -- ${cur}) ) COMPREPLY=( $(compgen -W "${enable_disable_args}" -- ${cur}) )
} }

View File

@ -43,16 +43,25 @@ function local_teardown {
} }
function __check_completion () { function __check_completion () {
# Get the parameters as a single value
COMP_LINE=$*
# Get the parameters as an array # Get the parameters as an array
eval set -- "$@" eval set -- "$@"
COMP_WORDS=("$@") COMP_WORDS=("$@")
# Get the parameters as a single value
COMP_LINE=$*
# Index of the cursor in the line # Index of the cursor in the line
COMP_POINT=${#COMP_LINE} COMP_POINT=${#COMP_LINE}
# Get the last character of the line that was entered
COMP_LAST=$((${COMP_POINT} - 1))
# If the last character was a space...
if [[ ${COMP_LINE:$COMP_LAST} = ' ' ]]; then
# ...then add an empty array item
COMP_WORDS+=('')
fi
# Word index of the last word # Word index of the last word
COMP_CWORD=$(( ${#COMP_WORDS[@]} - 1 )) COMP_CWORD=$(( ${#COMP_WORDS[@]} - 1 ))
@ -68,6 +77,17 @@ function __check_completion () {
assert_line "0" "vagrant vault vim" assert_line "0" "vagrant vault vim"
} }
@test "completion bash-it: disable - show options" {
run __check_completion 'bash-it disable '
assert_line "0" "alias completion plugin"
}
@test "completion bash-it: disable - show options a" {
run __check_completion 'bash-it disable a'
assert_line "0" "alias"
}
@test "completion bash-it: disable - provide nothing when atom is not enabled" { @test "completion bash-it: disable - provide nothing when atom is not enabled" {
run __check_completion 'bash-it disable alias ato' run __check_completion 'bash-it disable alias ato'
assert_line "0" "" assert_line "0" ""