Add zsh-autosuggestion
[zsh.git] / .zsh / external / zsh-autosuggestions / test / widgets / modify_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 ZSH_AUTOSUGGEST_BUFFER_MAX_SIZE=''
13 }
14
15 tearDown() {
16 restore _zsh_autosuggest_invoke_original_widget
17 restore _zsh_autosuggest_suggestion
18 }
19
20 testModify() {
21 stub_and_eval \
22 _zsh_autosuggest_invoke_original_widget \
23 'BUFFER+="e"'
24
25 stub_and_echo \
26 _zsh_autosuggest_suggestion \
27 'echo hello'
28
29 _zsh_autosuggest_modify 'original-widget'
30
31 assertTrue \
32 'original widget not invoked' \
33 'stub_called _zsh_autosuggest_invoke_original_widget'
34
35 assertEquals \
36 'BUFFER was not modified' \
37 'e' \
38 "$BUFFER"
39
40 assertEquals \
41 'POSTDISPLAY does not contain suggestion' \
42 'cho hello' \
43 "$POSTDISPLAY"
44 }
45
46 testModifyBufferTooLarge() {
47
48 ZSH_AUTOSUGGEST_BUFFER_MAX_SIZE='20'
49
50 stub_and_eval \
51 _zsh_autosuggest_invoke_original_widget \
52 'BUFFER+="012345678901234567890"'
53
54 stub_and_echo \
55 _zsh_autosuggest_suggestion \
56 '012345678901234567890123456789'
57
58 _zsh_autosuggest_modify 'original-widget'
59
60 assertTrue \
61 'original widget not invoked' \
62 'stub_called _zsh_autosuggest_invoke_original_widget'
63
64 assertEquals \
65 'BUFFER was not modified' \
66 '012345678901234567890' \
67 "$BUFFER"
68
69 assertEquals \
70 'POSTDISPLAY does not contain suggestion' \
71 '' \
72 "$POSTDISPLAY"
73 }
74
75 testRetval() {
76 stub_and_eval \
77 _zsh_autosuggest_invoke_original_widget \
78 'return 1'
79
80 _zsh_autosuggest_widget_modify 'original-widget'
81
82 assertEquals \
83 'Did not return correct value from original widget' \
84 '1' \
85 "$?"
86 }
87
88 run_tests "$0"