From ba7109169da89be4f39a6c8359652ba0a17c5dde Mon Sep 17 00:00:00 2001 From: Eric Freese Date: Tue, 15 Mar 2016 09:05:55 -0600 Subject: [PATCH] Clean up tests with setUp and tearDown functions --- test/widgets/accept_test.zsh | 15 +++++++++++++++ test/widgets/clear_test.zsh | 13 +++++++++++++ test/widgets/modify_test.zsh | 11 ++++++++--- test/widgets/partial_accept_test.zsh | 10 ++++++++++ 4 files changed, 46 insertions(+), 3 deletions(-) diff --git a/test/widgets/accept_test.zsh b/test/widgets/accept_test.zsh index 48bcf3c..a4150c5 100644 --- a/test/widgets/accept_test.zsh +++ b/test/widgets/accept_test.zsh @@ -6,6 +6,17 @@ oneTimeSetUp() { source_autosuggestions } +setUp() { + BUFFER='' + POSTDISPLAY='' + CURSOR=0 + KEYMAP='main' +} + +tearDown() { + restore _zsh_autosuggest_invoke_original_widget +} + testCursorAtEnd() { BUFFER='echo' POSTDISPLAY=' hello' @@ -128,6 +139,10 @@ testWidget() { assertTrue \ 'highlight_apply was not called' \ 'stub_called _zsh_autosuggest_highlight_apply' + + restore _zsh_autosuggest_highlight_reset + restore _zsh_autosuggest_accept + restore _zsh_autosuggest_highlight_apply } run_tests "$0" diff --git a/test/widgets/clear_test.zsh b/test/widgets/clear_test.zsh index e9f3a54..3665cf5 100644 --- a/test/widgets/clear_test.zsh +++ b/test/widgets/clear_test.zsh @@ -6,6 +6,15 @@ oneTimeSetUp() { source_autosuggestions } +setUp() { + BUFFER='' + POSTDISPLAY='' +} + +tearDown() { + restore _zsh_autosuggest_invoke_original_widget +} + testClear() { BUFFER='ec' POSTDISPLAY='ho hello' @@ -46,6 +55,10 @@ testWidget() { assertTrue \ 'highlight_apply was not called' \ 'stub_called _zsh_autosuggest_highlight_apply' + + restore _zsh_autosuggest_highlight_reset + restore _zsh_autosuggest_clear + restore _zsh_autosuggest_highlight_apply } run_tests "$0" diff --git a/test/widgets/modify_test.zsh b/test/widgets/modify_test.zsh index d0646a2..afe32c0 100644 --- a/test/widgets/modify_test.zsh +++ b/test/widgets/modify_test.zsh @@ -6,10 +6,17 @@ oneTimeSetUp() { source_autosuggestions } -testModify() { +setUp() { BUFFER='' POSTDISPLAY='' +} +tearDown() { + restore _zsh_autosuggest_invoke_original_widget + restore _zsh_autosuggest_suggestion +} + +testModify() { stub_and_eval \ _zsh_autosuggest_invoke_original_widget \ 'BUFFER+="e"' @@ -34,8 +41,6 @@ testModify() { 'cho hello' \ "$POSTDISPLAY" - restore _zsh_autosuggest_invoke_original_widget - restore _zsh_autosuggest_suggestion } run_tests "$0" diff --git a/test/widgets/partial_accept_test.zsh b/test/widgets/partial_accept_test.zsh index b137943..ad33079 100644 --- a/test/widgets/partial_accept_test.zsh +++ b/test/widgets/partial_accept_test.zsh @@ -6,6 +6,16 @@ oneTimeSetUp() { source_autosuggestions } +setUp() { + BUFFER='' + POSTDISPLAY='' + CURSOR=0 +} + +tearDown() { + restore _zsh_autosuggest_invoke_original_widget +} + testCursorMovesOutOfBuffer() { BUFFER='ec' POSTDISPLAY='ho hello'