Clean up tests with setUp and tearDown functions

This commit is contained in:
Eric Freese 2016-03-15 09:05:55 -06:00
parent a28e72e84a
commit ba7109169d
4 changed files with 46 additions and 3 deletions

View File

@ -6,6 +6,17 @@ oneTimeSetUp() {
source_autosuggestions source_autosuggestions
} }
setUp() {
BUFFER=''
POSTDISPLAY=''
CURSOR=0
KEYMAP='main'
}
tearDown() {
restore _zsh_autosuggest_invoke_original_widget
}
testCursorAtEnd() { testCursorAtEnd() {
BUFFER='echo' BUFFER='echo'
POSTDISPLAY=' hello' POSTDISPLAY=' hello'
@ -128,6 +139,10 @@ testWidget() {
assertTrue \ assertTrue \
'highlight_apply was not called' \ 'highlight_apply was not called' \
'stub_called _zsh_autosuggest_highlight_apply' 'stub_called _zsh_autosuggest_highlight_apply'
restore _zsh_autosuggest_highlight_reset
restore _zsh_autosuggest_accept
restore _zsh_autosuggest_highlight_apply
} }
run_tests "$0" run_tests "$0"

View File

@ -6,6 +6,15 @@ oneTimeSetUp() {
source_autosuggestions source_autosuggestions
} }
setUp() {
BUFFER=''
POSTDISPLAY=''
}
tearDown() {
restore _zsh_autosuggest_invoke_original_widget
}
testClear() { testClear() {
BUFFER='ec' BUFFER='ec'
POSTDISPLAY='ho hello' POSTDISPLAY='ho hello'
@ -46,6 +55,10 @@ testWidget() {
assertTrue \ assertTrue \
'highlight_apply was not called' \ 'highlight_apply was not called' \
'stub_called _zsh_autosuggest_highlight_apply' 'stub_called _zsh_autosuggest_highlight_apply'
restore _zsh_autosuggest_highlight_reset
restore _zsh_autosuggest_clear
restore _zsh_autosuggest_highlight_apply
} }
run_tests "$0" run_tests "$0"

View File

@ -6,10 +6,17 @@ oneTimeSetUp() {
source_autosuggestions source_autosuggestions
} }
testModify() { setUp() {
BUFFER='' BUFFER=''
POSTDISPLAY='' POSTDISPLAY=''
}
tearDown() {
restore _zsh_autosuggest_invoke_original_widget
restore _zsh_autosuggest_suggestion
}
testModify() {
stub_and_eval \ stub_and_eval \
_zsh_autosuggest_invoke_original_widget \ _zsh_autosuggest_invoke_original_widget \
'BUFFER+="e"' 'BUFFER+="e"'
@ -34,8 +41,6 @@ testModify() {
'cho hello' \ 'cho hello' \
"$POSTDISPLAY" "$POSTDISPLAY"
restore _zsh_autosuggest_invoke_original_widget
restore _zsh_autosuggest_suggestion
} }
run_tests "$0" run_tests "$0"

View File

@ -6,6 +6,16 @@ oneTimeSetUp() {
source_autosuggestions source_autosuggestions
} }
setUp() {
BUFFER=''
POSTDISPLAY=''
CURSOR=0
}
tearDown() {
restore _zsh_autosuggest_invoke_original_widget
}
testCursorMovesOutOfBuffer() { testCursorMovesOutOfBuffer() {
BUFFER='ec' BUFFER='ec'
POSTDISPLAY='ho hello' POSTDISPLAY='ho hello'