Add zsh-autosuggestion
[zsh.git] / .zsh / external / zsh-autosuggestions / test / strategies_test.zsh
1 #!/usr/bin/env zsh
2
3 source "${0:a:h}/test_helper.zsh"
4
5 oneTimeSetUp() {
6 source_autosuggestions
7 }
8
9 assertBackslashSuggestion() {
10 set_history <<-'EOF'
11 echo "hello\nworld"
12 EOF
13
14 assertSuggestion \
15 'echo "hello\' \
16 'echo "hello\nworld"'
17 }
18
19 assertDoubleBackslashSuggestion() {
20 set_history <<-'EOF'
21 echo "\\"
22 EOF
23
24 assertSuggestion \
25 'echo "\\' \
26 'echo "\\"'
27 }
28
29 assertTildeSuggestion() {
30 set_history <<-'EOF'
31 cd ~/something
32 EOF
33
34 assertSuggestion \
35 'cd' \
36 'cd ~/something'
37
38 assertSuggestion \
39 'cd ~' \
40 'cd ~/something'
41
42 assertSuggestion \
43 'cd ~/s' \
44 'cd ~/something'
45 }
46
47 assertTildeSuggestionWithExtendedGlob() {
48 setopt local_options extended_glob
49
50 assertTildeSuggestion
51 }
52
53 assertParenthesesSuggestion() {
54 set_history <<-'EOF'
55 echo "$(ls foo)"
56 EOF
57
58 assertSuggestion \
59 'echo "$(' \
60 'echo "$(ls foo)"'
61 }
62
63 assertSquareBracketsSuggestion() {
64 set_history <<-'EOF'
65 echo "$history[123]"
66 EOF
67
68 assertSuggestion \
69 'echo "$history[' \
70 'echo "$history[123]"'
71 }
72
73 assertHashSuggestion() {
74 set_history <<-'EOF'
75 echo "#yolo"
76 EOF
77
78 assertSuggestion \
79 'echo "#' \
80 'echo "#yolo"'
81 }
82
83 testSpecialCharsForAllStrategies() {
84 local strategies
85 strategies=(
86 "default"
87 "match_prev_cmd"
88 )
89
90 for s in $strategies; do
91 ZSH_AUTOSUGGEST_STRATEGY="$s"
92
93 assertBackslashSuggestion
94 assertDoubleBackslashSuggestion
95 assertTildeSuggestion
96 assertTildeSuggestionWithExtendedGlob
97 assertParenthesesSuggestion
98 assertSquareBracketsSuggestion
99 done
100 }
101
102 run_tests "$0"