mirror of
https://github.com/zsh-users/zsh-autosuggestions.git
synced 2024-12-23 10:21:15 +01:00
[Test] Add tests widgets
This commit is contained in:
parent
cf146b6696
commit
31452887d2
1 changed files with 204 additions and 0 deletions
204
script/test.zsh
204
script/test.zsh
|
@ -77,6 +77,210 @@ testHighlightReset() {
|
|||
"$_ZSH_AUTOSUGGEST_LAST_HIGHLIGHT"
|
||||
}
|
||||
|
||||
#--------------------------------------------------------------------#
|
||||
# Widgets #
|
||||
#--------------------------------------------------------------------#
|
||||
|
||||
testWidgetFunctionClear() {
|
||||
BUFFER="ec"
|
||||
POSTDISPLAY="ho hello"
|
||||
|
||||
_zsh_autosuggest_clear
|
||||
|
||||
assertEquals \
|
||||
"BUFFER was modified" \
|
||||
"ec" \
|
||||
"$BUFFER"
|
||||
|
||||
assertNull \
|
||||
"POSTDISPLAY was not cleared" \
|
||||
"$POSTDISPLAY"
|
||||
}
|
||||
|
||||
testWidgetFunctionModify() {
|
||||
BUFFER=""
|
||||
POSTDISPLAY=""
|
||||
|
||||
stub_and_eval \
|
||||
_zsh_autosuggest_invoke_original_widget \
|
||||
'BUFFER+="e"'
|
||||
|
||||
stub_and_echo \
|
||||
_zsh_autosuggest_suggestion \
|
||||
"echo hello"
|
||||
|
||||
_zsh_autosuggest_modify
|
||||
|
||||
assertTrue \
|
||||
"original widget not invoked" \
|
||||
"stub_called _zsh_autosuggest_invoke_original_widget"
|
||||
|
||||
assertEquals \
|
||||
"BUFFER was not modified" \
|
||||
"e" \
|
||||
"$BUFFER"
|
||||
|
||||
assertEquals \
|
||||
"POSTDISPLAY does not contain suggestion" \
|
||||
"cho hello" \
|
||||
"$POSTDISPLAY"
|
||||
|
||||
restore _zsh_autosuggest_invoke_original_widget
|
||||
restore _zsh_autosuggest_suggestion
|
||||
}
|
||||
|
||||
testWidgetFunctionAcceptCursorAtEnd() {
|
||||
BUFFER="echo"
|
||||
POSTDISPLAY=" hello"
|
||||
CURSOR=4
|
||||
|
||||
stub _zsh_autosuggest_invoke_original_widget
|
||||
|
||||
_zsh_autosuggest_accept
|
||||
|
||||
assertTrue \
|
||||
"original widget not invoked" \
|
||||
"stub_called _zsh_autosuggest_invoke_original_widget"
|
||||
|
||||
assertEquals \
|
||||
"BUFFER was not modified" \
|
||||
"echo hello" \
|
||||
"$BUFFER"
|
||||
|
||||
assertEquals \
|
||||
"POSTDISPLAY was not cleared" \
|
||||
"" \
|
||||
"$POSTDISPLAY"
|
||||
}
|
||||
|
||||
testWidgetFunctionAcceptCursorNotAtEnd() {
|
||||
BUFFER="echo"
|
||||
POSTDISPLAY=" hello"
|
||||
CURSOR=2
|
||||
|
||||
stub _zsh_autosuggest_invoke_original_widget
|
||||
|
||||
_zsh_autosuggest_accept
|
||||
|
||||
assertTrue \
|
||||
"original widget not invoked" \
|
||||
"stub_called _zsh_autosuggest_invoke_original_widget"
|
||||
|
||||
assertEquals \
|
||||
"BUFFER was modified" \
|
||||
"echo" \
|
||||
"$BUFFER"
|
||||
|
||||
assertEquals \
|
||||
"POSTDISPLAY was modified" \
|
||||
" hello" \
|
||||
"$POSTDISPLAY"
|
||||
}
|
||||
|
||||
testWidgetFunctionPartialAcceptCursorMovesOutOfBuffer() {
|
||||
BUFFER="ec"
|
||||
POSTDISPLAY="ho hello"
|
||||
CURSOR=1
|
||||
|
||||
stub_and_eval \
|
||||
_zsh_autosuggest_invoke_original_widget \
|
||||
'CURSOR=5; LBUFFER="echo "; RBUFFER="hello"'
|
||||
|
||||
_zsh_autosuggest_partial_accept
|
||||
|
||||
assertTrue \
|
||||
"original widget not invoked" \
|
||||
"stub_called _zsh_autosuggest_invoke_original_widget"
|
||||
|
||||
assertEquals \
|
||||
"BUFFER was not modified correctly" \
|
||||
"echo " \
|
||||
"$BUFFER"
|
||||
|
||||
assertEquals \
|
||||
"POSTDISPLAY was not modified correctly" \
|
||||
"hello" \
|
||||
"$POSTDISPLAY"
|
||||
}
|
||||
|
||||
testWidgetFunctionPartialAcceptCursorStaysInBuffer() {
|
||||
BUFFER="echo hello"
|
||||
POSTDISPLAY=" world"
|
||||
CURSOR=1
|
||||
|
||||
stub_and_eval \
|
||||
_zsh_autosuggest_invoke_original_widget \
|
||||
'CURSOR=5; LBUFFER="echo "; RBUFFER="hello"'
|
||||
|
||||
_zsh_autosuggest_partial_accept
|
||||
|
||||
assertTrue \
|
||||
"original widget not invoked" \
|
||||
"stub_called _zsh_autosuggest_invoke_original_widget"
|
||||
|
||||
assertEquals \
|
||||
"BUFFER was modified" \
|
||||
"echo hello" \
|
||||
"$BUFFER"
|
||||
|
||||
assertEquals \
|
||||
"POSTDISPLAY was modified" \
|
||||
" world" \
|
||||
"$POSTDISPLAY"
|
||||
}
|
||||
|
||||
testWidgetAccept() {
|
||||
stub _zsh_autosuggest_highlight_reset
|
||||
stub _zsh_autosuggest_accept
|
||||
stub _zsh_autosuggest_highlight_apply
|
||||
|
||||
# Call the function pointed to by the widget since we can't call
|
||||
# the widget itself when zle is not active
|
||||
${widgets[autosuggest-accept]#*:}
|
||||
|
||||
assertTrue \
|
||||
"autosuggest-accept widget does not exist" \
|
||||
"zle -l autosuggest-accept"
|
||||
|
||||
assertTrue \
|
||||
"highlight_reset was not called" \
|
||||
"stub_called _zsh_autosuggest_highlight_reset"
|
||||
|
||||
assertTrue \
|
||||
"widget function was not called" \
|
||||
"stub_called _zsh_autosuggest_accept"
|
||||
|
||||
assertTrue \
|
||||
"highlight_apply was not called" \
|
||||
"stub_called _zsh_autosuggest_highlight_apply"
|
||||
}
|
||||
|
||||
testWidgetClear() {
|
||||
stub _zsh_autosuggest_highlight_reset
|
||||
stub _zsh_autosuggest_clear
|
||||
stub _zsh_autosuggest_highlight_apply
|
||||
|
||||
# Call the function pointed to by the widget since we can't call
|
||||
# the widget itself when zle is not active
|
||||
${widgets[autosuggest-clear]#*:}
|
||||
|
||||
assertTrue \
|
||||
"autosuggest-clear widget does not exist" \
|
||||
"zle -l autosuggest-clear"
|
||||
|
||||
assertTrue \
|
||||
"highlight_reset was not called" \
|
||||
"stub_called _zsh_autosuggest_highlight_reset"
|
||||
|
||||
assertTrue \
|
||||
"widget function was not called" \
|
||||
"stub_called _zsh_autosuggest_clear"
|
||||
|
||||
assertTrue \
|
||||
"highlight_apply was not called" \
|
||||
"stub_called _zsh_autosuggest_highlight_apply"
|
||||
}
|
||||
|
||||
# For zsh compatibility
|
||||
setopt shwordsplit
|
||||
SHUNIT_PARENT=$0
|
||||
|
|
Loading…
Reference in a new issue