Add zsh-autosuggestion
[zsh.git] / .zsh / external / zsh-autosuggestions / test / widgets / clear_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 setUp() {
10 BUFFER=''
11 POSTDISPLAY=''
12 }
13
14 tearDown() {
15 restore _zsh_autosuggest_invoke_original_widget
16 }
17
18 testClear() {
19 BUFFER='ec'
20 POSTDISPLAY='ho hello'
21
22 _zsh_autosuggest_clear 'original-widget'
23
24 assertEquals \
25 'BUFFER was modified' \
26 'ec' \
27 "$BUFFER"
28
29 assertNull \
30 'POSTDISPLAY was not cleared' \
31 "$POSTDISPLAY"
32 }
33
34 testRetval() {
35 stub_and_eval \
36 _zsh_autosuggest_invoke_original_widget \
37 'return 1'
38
39 _zsh_autosuggest_widget_clear 'original-widget'
40
41 assertEquals \
42 'Did not return correct value from original widget' \
43 '1' \
44 "$?"
45 }
46
47 testWidget() {
48 stub _zsh_autosuggest_highlight_reset
49 stub _zsh_autosuggest_clear
50 stub _zsh_autosuggest_highlight_apply
51
52 # Call the function pointed to by the widget since we can't call
53 # the widget itself when zle is not active
54 ${widgets[autosuggest-clear]#*:} 'original-widget'
55
56 assertTrue \
57 'autosuggest-clear widget does not exist' \
58 'zle -l autosuggest-clear'
59
60 assertTrue \
61 'highlight_reset was not called' \
62 'stub_called _zsh_autosuggest_highlight_reset'
63
64 assertTrue \
65 'widget function was not called' \
66 'stub_called _zsh_autosuggest_clear'
67
68 assertTrue \
69 'highlight_apply was not called' \
70 'stub_called _zsh_autosuggest_highlight_apply'
71
72 restore _zsh_autosuggest_highlight_reset
73 restore _zsh_autosuggest_clear
74 restore _zsh_autosuggest_highlight_apply
75 }
76
77 run_tests "$0"