Add zsh-autosuggestion
[zsh.git] / .zsh / external / zsh-autosuggestions / test / widgets / partial_accept_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 CURSOR=0
13 }
14
15 tearDown() {
16 restore _zsh_autosuggest_invoke_original_widget
17 }
18
19 testCursorMovesOutOfBuffer() {
20 BUFFER='ec'
21 POSTDISPLAY='ho hello'
22 CURSOR=1
23
24 stub_and_eval \
25 _zsh_autosuggest_invoke_original_widget \
26 'CURSOR=5; LBUFFER="echo "; RBUFFER="hello"'
27
28 _zsh_autosuggest_partial_accept 'original-widget'
29
30 assertTrue \
31 'original widget not invoked' \
32 'stub_called _zsh_autosuggest_invoke_original_widget'
33
34 assertEquals \
35 'BUFFER was not modified correctly' \
36 'echo ' \
37 "$BUFFER"
38
39 assertEquals \
40 'POSTDISPLAY was not modified correctly' \
41 'hello' \
42 "$POSTDISPLAY"
43 }
44
45 testCursorStaysInBuffer() {
46 BUFFER='echo hello'
47 POSTDISPLAY=' world'
48 CURSOR=1
49
50 stub_and_eval \
51 _zsh_autosuggest_invoke_original_widget \
52 'CURSOR=5; LBUFFER="echo "; RBUFFER="hello"'
53
54 _zsh_autosuggest_partial_accept 'original-widget'
55
56 assertTrue \
57 'original widget not invoked' \
58 'stub_called _zsh_autosuggest_invoke_original_widget'
59
60 assertEquals \
61 'BUFFER was modified' \
62 'echo hello' \
63 "$BUFFER"
64
65 assertEquals \
66 'POSTDISPLAY was modified' \
67 ' world' \
68 "$POSTDISPLAY"
69 }
70
71 testRetval() {
72 stub_and_eval \
73 _zsh_autosuggest_invoke_original_widget \
74 'return 1'
75
76 _zsh_autosuggest_widget_partial_accept 'original-widget'
77
78 assertEquals \
79 'Did not return correct value from original widget' \
80 '1' \
81 "$?"
82 }
83
84 run_tests "$0"