From 125f48c7f2b2860f3294a2209d9c56b58fabe003 Mon Sep 17 00:00:00 2001 From: Eric Freese Date: Tue, 23 Feb 2016 10:33:40 -0700 Subject: [PATCH] Add test for execute widget --- script/test.zsh | 49 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) diff --git a/script/test.zsh b/script/test.zsh index 45f3dbc..ba563a6 100755 --- a/script/test.zsh +++ b/script/test.zsh @@ -177,6 +177,29 @@ testWidgetFunctionAcceptCursorNotAtEnd() { "$POSTDISPLAY" } +testWidgetFunctionExecute() { + BUFFER="ec" + POSTDISPLAY="ho hello" + + stub _zsh_autosuggest_invoke_original_widget + + _zsh_autosuggest_execute + + assertTrue \ + "accept-line not invoked" \ + "stub_called_with _zsh_autosuggest_invoke_original_widget 'accept-line'" + + assertEquals \ + "BUFFER was not modified" \ + "echo hello" \ + "$BUFFER" + + assertEquals \ + "POSTDISPLAY was not cleared" \ + "" \ + "$POSTDISPLAY" +} + testWidgetFunctionPartialAcceptCursorMovesOutOfBuffer() { BUFFER="ec" POSTDISPLAY="ho hello" @@ -281,6 +304,32 @@ testWidgetClear() { "stub_called _zsh_autosuggest_highlight_apply" } +testWidgetExecute() { + stub _zsh_autosuggest_highlight_reset + stub _zsh_autosuggest_execute + 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-execute]#*:} "original-widget" + + assertTrue \ + "autosuggest-execute widget does not exist" \ + "zle -l autosuggest-execute" + + assertTrue \ + "highlight_reset was not called" \ + "stub_called _zsh_autosuggest_highlight_reset" + + assertTrue \ + "widget function was not called" \ + "stub_called _zsh_autosuggest_execute" + + assertTrue \ + "highlight_apply was not called" \ + "stub_called _zsh_autosuggest_highlight_apply" +} + testEscapeCommandPrefix() { assertEquals \ "Did not escape single backslash" \