From c5f57da2b8559a5e40dbc4151884999fced9319b Mon Sep 17 00:00:00 2001 From: Eric Freese Date: Fri, 22 Apr 2016 14:14:29 -0600 Subject: [PATCH] Pull duplicated test logic from strategies into single test file --- test/strategies/default_test.zsh | 58 ----------------- test/strategies/match_prev_cmd_test.zsh | 58 ----------------- test/strategies_test.zsh | 85 +++++++++++++++++++++++++ test/test_helper.zsh | 2 +- 4 files changed, 86 insertions(+), 117 deletions(-) create mode 100644 test/strategies_test.zsh diff --git a/test/strategies/default_test.zsh b/test/strategies/default_test.zsh index 723d0df..f5200e6 100755 --- a/test/strategies/default_test.zsh +++ b/test/strategies/default_test.zsh @@ -53,62 +53,4 @@ testMostRecentMatch() { 'cd quux' } -testBackslash() { - set_history <<-'EOF' - echo "hello\nworld" - EOF - - assertSuggestion \ - 'echo "hello\' \ - 'echo "hello\nworld"' -} - -testDoubleBackslash() { - set_history <<-'EOF' - echo "\\" - EOF - - assertSuggestion \ - 'echo "\\' \ - 'echo "\\"' -} - -testTilde() { - set_history <<-'EOF' - cd ~/something - EOF - - assertSuggestion \ - 'cd' \ - 'cd ~/something' - - assertSuggestion \ - 'cd ~' \ - 'cd ~/something' - - assertSuggestion \ - 'cd ~/s' \ - 'cd ~/something' -} - -testParentheses() { - set_history <<-'EOF' - echo "$(ls foo)" - EOF - - assertSuggestion \ - 'echo "$(' \ - 'echo "$(ls foo)"' -} - -testSquareBrackets() { - set_history <<-'EOF' - echo "$history[123]" - EOF - - assertSuggestion \ - 'echo "$history[' \ - 'echo "$history[123]"' -} - run_tests "$0" diff --git a/test/strategies/match_prev_cmd_test.zsh b/test/strategies/match_prev_cmd_test.zsh index 768bdc0..bf3fc64 100755 --- a/test/strategies/match_prev_cmd_test.zsh +++ b/test/strategies/match_prev_cmd_test.zsh @@ -55,64 +55,6 @@ testMostRecentMatch() { 'cd quux' } -testBackslash() { - set_history <<-'EOF' - echo "hello\nworld" - EOF - - assertSuggestion \ - 'echo "hello\' \ - 'echo "hello\nworld"' -} - -testDoubleBackslash() { - set_history <<-'EOF' - echo "\\" - EOF - - assertSuggestion \ - 'echo "\\' \ - 'echo "\\"' -} - -testTilde() { - set_history <<-'EOF' - cd ~/something - EOF - - assertSuggestion \ - 'cd' \ - 'cd ~/something' - - assertSuggestion \ - 'cd ~' \ - 'cd ~/something' - - assertSuggestion \ - 'cd ~/s' \ - 'cd ~/something' -} - -testParentheses() { - set_history <<-'EOF' - echo "$(ls foo)" - EOF - - assertSuggestion \ - 'echo "$(' \ - 'echo "$(ls foo)"' -} - -testSquareBrackets() { - set_history <<-'EOF' - echo "$history[123]" - EOF - - assertSuggestion \ - 'echo "$history[' \ - 'echo "$history[123]"' -} - testMatchMostRecentAfterPreviousCmd() { set_history <<-'EOF' echo what diff --git a/test/strategies_test.zsh b/test/strategies_test.zsh new file mode 100644 index 0000000..0e18585 --- /dev/null +++ b/test/strategies_test.zsh @@ -0,0 +1,85 @@ +#!/usr/bin/env zsh + +source "${0:a:h}/test_helper.zsh" + +oneTimeSetUp() { + source_autosuggestions +} + +assertBackslashSuggestion() { + set_history <<-'EOF' + echo "hello\nworld" + EOF + + assertSuggestion \ + 'echo "hello\' \ + 'echo "hello\nworld"' +} + +assertDoubleBackslashSuggestion() { + set_history <<-'EOF' + echo "\\" + EOF + + assertSuggestion \ + 'echo "\\' \ + 'echo "\\"' +} + +assertTildeSuggestion() { + set_history <<-'EOF' + cd ~/something + EOF + + assertSuggestion \ + 'cd' \ + 'cd ~/something' + + assertSuggestion \ + 'cd ~' \ + 'cd ~/something' + + assertSuggestion \ + 'cd ~/s' \ + 'cd ~/something' +} + +assertParenthesesSuggestion() { + set_history <<-'EOF' + echo "$(ls foo)" + EOF + + assertSuggestion \ + 'echo "$(' \ + 'echo "$(ls foo)"' +} + +assertSquareBracketsSuggestion() { + set_history <<-'EOF' + echo "$history[123]" + EOF + + assertSuggestion \ + 'echo "$history[' \ + 'echo "$history[123]"' +} + +testSpecialCharsForAllStrategies() { + local strategies + strategies=( + "default" + "match_prev_cmd" + ) + + for s in $strategies; do + ZSH_AUTOSUGGEST_STRATEGY="$s" + + assertBackslashSuggestion + assertDoubleBackslashSuggestion + assertTildeSuggestion + assertParenthesesSuggestion + assertSquareBracketsSuggestion + done +} + +run_tests "$0" diff --git a/test/test_helper.zsh b/test/test_helper.zsh index d4cc94c..7e7dbc0 100644 --- a/test/test_helper.zsh +++ b/test/test_helper.zsh @@ -54,7 +54,7 @@ assertSuggestion() { local expected_suggestion="$2" assertEquals \ - "Did not get correct suggestion for prefix:<$prefix>" \ + "Did not get correct suggestion for prefix:<$prefix> using strategy <$ZSH_AUTOSUGGEST_STRATEGY>" \ "$expected_suggestion" \ "$(_zsh_autosuggest_suggestion "$prefix")" }