Add zsh-autosuggestion
[zsh.git] / .zsh / external / zsh-autosuggestions / test / highlight_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 testHighlightDefaultStyle() {
10 assertEquals \
11 'fg=8' \
12 "$ZSH_AUTOSUGGEST_HIGHLIGHT_STYLE"
13 }
14
15 testHighlightApplyWithSuggestion() {
16 local orig_style=ZSH_AUTOSUGGEST_HIGHLIGHT_STYLE
17 ZSH_AUTOSUGGEST_HIGHLIGHT_STYLE='fg=4'
18
19 BUFFER='ec'
20 POSTDISPLAY='ho hello'
21 region_highlight=('0 2 fg=1')
22
23 _zsh_autosuggest_highlight_apply
24
25 assertEquals \
26 'highlight did not use correct style' \
27 "0 2 fg=1 2 10 $ZSH_AUTOSUGGEST_HIGHLIGHT_STYLE" \
28 "$region_highlight"
29
30 assertEquals \
31 'higlight was not saved to be removed later' \
32 "2 10 $ZSH_AUTOSUGGEST_HIGHLIGHT_STYLE" \
33 "$_ZSH_AUTOSUGGEST_LAST_HIGHLIGHT"
34
35 ZSH_AUTOSUGGEST_HIGHLIGHT_STYLE=orig_style
36 }
37
38 testHighlightApplyWithoutSuggestion() {
39 BUFFER='echo hello'
40 POSTDISPLAY=''
41 region_highlight=('0 4 fg=1')
42
43 _zsh_autosuggest_highlight_apply
44
45 assertEquals \
46 'region_highlight was modified' \
47 '0 4 fg=1' \
48 "$region_highlight"
49
50 assertNull \
51 'last highlight region was not cleared' \
52 "$_ZSH_AUTOSUGGEST_LAST_HIGHLIGHT"
53 }
54
55 testHighlightReset() {
56 BUFFER='ec'
57 POSTDISPLAY='ho hello'
58 region_highlight=('0 1 fg=1' '2 10 fg=8' '1 2 fg=1')
59 _ZSH_AUTOSUGGEST_LAST_HIGHLIGHT='2 10 fg=8'
60
61 _zsh_autosuggest_highlight_reset
62
63 assertEquals \
64 'last highlight region was not removed' \
65 '0 1 fg=1 1 2 fg=1' \
66 "$region_highlight"
67
68 assertNull \
69 'last highlight variable was not cleared' \
70 "$_ZSH_AUTOSUGGEST_LAST_HIGHLIGHT"
71 }
72
73 run_tests "$0"