]> git.madduck.net Git - etc/vim.git/blob - .vim/bundle/ale/test/test_autocmd_commands.vader

madduck's git repository

Every one of the projects in this repository is available at the canonical URL git://git.madduck.net/madduck/pub/<projectpath> — see each project's metadata for the exact URL.

All patches and comments are welcome. Please squash your changes to logical commits before using git-format-patch and git-send-email to patches@git.madduck.net. If you'd read over the Git project's submission guidelines and adhered to them, I'd be especially grateful.

SSH access, as well as push access can be individually arranged.

If you use my repositories frequently, consider adding the following snippet to ~/.gitconfig and using the third clone URL listed for each project:

[url "git://git.madduck.net/madduck/"]
  insteadOf = madduck:

Do not set EDITOR/VISUAL for shell
[etc/vim.git] / .vim / bundle / ale / test / test_autocmd_commands.vader
1 Before:
2   function! CheckAutocmd(group)
3     call ale#events#Init()
4
5     redir => l:output
6       execute 'silent! autocmd ' . a:group
7     redir END
8
9     let l:matches = []
10     let l:header = ''
11     " Some event names have aliases, and NeoVim and Vim produce
12     " different output. The names are remapped to fix this.
13     let l:event_name_corrections = {
14     \ 'BufWrite': 'BufWritePre',
15     \ 'BufRead': 'BufReadPost',
16     \}
17
18     " autocmd commands are split across two lines in output, so we
19     " must merge the lines back into one simple line.
20     for l:line in split(l:output, "\n")
21       if l:line =~# '^ALE' && split(l:line)[0] ==# a:group
22         let l:header = split(l:line)[1]
23         let l:header = get(l:event_name_corrections, l:header, l:header)
24       elseif !empty(l:header)
25         " There's an extra line for buffer events, and we should only look
26         " for the one matching the current buffer.
27         if l:line =~# '<buffer=' . bufnr('') . '>'
28           let l:header .= ' <buffer>'
29         elseif l:line[:0] is# ' '
30           call add(l:matches, join(split(l:header . l:line)))
31         else
32           let l:header = ''
33         endif
34       endif
35     endfor
36
37     call sort(l:matches)
38
39     return l:matches
40   endfunction
41
42   Save g:ale_completion_enabled
43   Save g:ale_echo_cursor
44   Save g:ale_enabled
45   Save g:ale_fix_on_save
46   Save g:ale_lint_on_enter
47   Save g:ale_lint_on_filetype_changed
48   Save g:ale_lint_on_insert_leave
49   Save g:ale_lint_on_save
50   Save g:ale_lint_on_text_changed
51   Save g:ale_pattern_options_enabled
52   Save g:ale_hover_cursor
53   Save g:ale_close_preview_on_insert
54
55   " Turn everything on by default for these tests.
56   let g:ale_completion_enabled = 1
57   let g:ale_echo_cursor = 1
58   let g:ale_enabled = 1
59   let g:ale_fix_on_save = 1
60   let g:ale_lint_on_enter = 1
61   let g:ale_lint_on_filetype_changed = 1
62   let g:ale_lint_on_insert_leave = 1
63   let g:ale_lint_on_save = 1
64   let g:ale_lint_on_text_changed = 1
65   let g:ale_pattern_options_enabled = 1
66   let g:ale_hover_cursor = 1
67   let g:ale_close_preview_on_insert = 0
68
69 After:
70   delfunction CheckAutocmd
71   Restore
72
73   if g:ale_completion_enabled
74     call ale#completion#Enable()
75   else
76     call ale#completion#Disable()
77   endif
78
79   call ale#events#Init()
80
81 Execute (All events should be set up when everything is on):
82   let g:ale_echo_cursor = 1
83
84   " The InsertEnter event is only added when a mapping is not set.
85   AssertEqual
86   \ [
87   \   'BufEnter * call ale#events#ReadOrEnterEvent(str2nr(expand(''<abuf>'')))',
88   \   'BufReadPost * call ale#events#ReadOrEnterEvent(str2nr(expand(''<abuf>'')))',
89   \   'BufWinEnter * call ale#events#LintOnEnter(str2nr(expand(''<abuf>'')))',
90   \   'BufWritePost * call ale#events#SaveEvent(str2nr(expand(''<abuf>'')))',
91   \   'CursorHold * if exists(''*ale#engine#Cleanup'') | call ale#cursor#EchoCursorWarningWithDelay() | endif',
92   \   'CursorHold if exists(''*ale#lsp#Send'') | call ale#hover#ShowTruncatedMessageAtCursor() | endif',
93   \   'CursorMoved * if exists(''*ale#engine#Cleanup'') | call ale#cursor#EchoCursorWarningWithDelay() | endif',
94   \   'FileChangedShellPost * call ale#events#FileChangedEvent(str2nr(expand(''<abuf>'')))',
95   \   'FileType * call ale#events#FileTypeEvent( str2nr(expand(''<abuf>'')), expand(''<amatch>''))',
96   \ ] + (
97   \   maparg("\<C-c>", 'i') isnot# '<Esc>' && !exists('##ModeChanged')
98   \     ? [
99   \         'InsertEnter * call ale#events#InsertEnterEvent(str2nr(expand(''<abuf>'')))',
100   \         'InsertLeave * call ale#events#InsertLeaveEvent(str2nr(expand(''<abuf>'')))',
101   \       ]
102   \     : []
103   \ ) + (
104   \   exists('##ModeChanged')
105   \     ? ['ModeChanged i*:* call ale#events#InsertLeaveEvent(str2nr(expand(''<abuf>'')))']
106   \     : []
107   \ ) + [
108   \   'TextChanged * call ale#Queue(ale#Var(str2nr(expand(''<abuf>'')), ''lint_delay''))',
109   \   'TextChangedI * call ale#Queue(ale#Var(str2nr(expand(''<abuf>'')), ''lint_delay''))',
110   \ ],
111   \ CheckAutocmd('ALEEvents')
112
113 Execute (Only the required events should be bound even if various settings are off):
114   let g:ale_enabled = 1
115   let g:ale_completion_enabled = 0
116   let g:ale_echo_cursor = 0
117   let g:ale_fix_on_save = 0
118   let g:ale_lint_on_enter = 0
119   let g:ale_lint_on_filetype_changed = 0
120   let g:ale_lint_on_insert_leave = 0
121   let g:ale_lint_on_save = 0
122   let g:ale_lint_on_text_changed = 0
123   let g:ale_pattern_options_enabled = 0
124   let g:ale_hover_cursor = 0
125
126   AssertEqual
127   \ [
128   \   'BufEnter * call ale#events#ReadOrEnterEvent(str2nr(expand(''<abuf>'')))',
129   \   'BufReadPost * call ale#events#ReadOrEnterEvent(str2nr(expand(''<abuf>'')))',
130   \   'BufWritePost * call ale#events#SaveEvent(str2nr(expand(''<abuf>'')))',
131   \ ],
132   \ CheckAutocmd('ALEEvents')
133
134 Execute (The cursor hover event should be enabled with g:ale_hover_cursor = 1):
135   let g:ale_enabled = 1
136   let g:ale_completion_enabled = 0
137   let g:ale_echo_cursor = 0
138   let g:ale_fix_on_save = 0
139   let g:ale_lint_on_enter = 0
140   let g:ale_lint_on_filetype_changed = 0
141   let g:ale_lint_on_insert_leave = 0
142   let g:ale_lint_on_save = 0
143   let g:ale_lint_on_text_changed = 0
144   let g:ale_pattern_options_enabled = 0
145   let g:ale_hover_cursor = 1
146
147   AssertEqual
148   \ [
149   \   'BufEnter * call ale#events#ReadOrEnterEvent(str2nr(expand(''<abuf>'')))',
150   \   'BufReadPost * call ale#events#ReadOrEnterEvent(str2nr(expand(''<abuf>'')))',
151   \   'BufWritePost * call ale#events#SaveEvent(str2nr(expand(''<abuf>'')))',
152   \   'CursorHold * if exists(''*ale#lsp#Send'') | call ale#hover#ShowTruncatedMessageAtCursor() | endif',
153   \ ],
154   \ CheckAutocmd('ALEEvents')
155
156 Execute (g:ale_lint_on_text_changed = 1 bind both events):
157   let g:ale_lint_on_text_changed = 1
158
159   AssertEqual
160   \ [
161   \   'TextChanged * call ale#Queue(ale#Var(str2nr(expand(''<abuf>'')), ''lint_delay''))',
162   \   'TextChangedI * call ale#Queue(ale#Var(str2nr(expand(''<abuf>'')), ''lint_delay''))',
163   \ ],
164   \ filter(CheckAutocmd('ALEEvents'), 'v:val =~ ''^TextChanged''')
165
166 Execute (g:ale_lint_on_text_changed = 'always' should bind both events):
167   let g:ale_lint_on_text_changed = 'always'
168
169   AssertEqual
170   \ [
171   \   'TextChanged * call ale#Queue(ale#Var(str2nr(expand(''<abuf>'')), ''lint_delay''))',
172   \   'TextChangedI * call ale#Queue(ale#Var(str2nr(expand(''<abuf>'')), ''lint_delay''))',
173   \ ],
174   \ filter(CheckAutocmd('ALEEvents'), 'v:val =~ ''^TextChanged''')
175
176 Execute (g:ale_lint_on_text_changed = 'normal' should bind only TextChanged):
177   let g:ale_lint_on_text_changed = 'normal'
178
179   AssertEqual
180   \ [
181   \   'TextChanged * call ale#Queue(ale#Var(str2nr(expand(''<abuf>'')), ''lint_delay''))',
182   \ ],
183   \ filter(CheckAutocmd('ALEEvents'), 'v:val =~ ''^TextChanged''')
184
185 Execute (g:ale_lint_on_text_changed = 'insert' should bind only TextChangedI):
186   let g:ale_lint_on_text_changed = 'insert'
187
188   AssertEqual
189   \ [
190   \   'TextChangedI * call ale#Queue(ale#Var(str2nr(expand(''<abuf>'')), ''lint_delay''))',
191   \ ],
192   \ filter(CheckAutocmd('ALEEvents'), 'v:val =~ ''^TextChanged''')
193
194 Execute (g:ale_lint_on_insert_leave = 1 should bind InsertLeave or ModeChanged if available):
195   let g:ale_lint_on_insert_leave = 1
196   let g:ale_echo_cursor = 0
197
198   " CI at least should run this check.
199   " There isn't an easy way to save an restore a mapping during running the test.
200   if maparg("\<C-c>", 'i') isnot# '<Esc>' && !exists('##ModeChanged')
201     AssertEqual
202     \ [
203     \   'InsertEnter * call ale#events#InsertEnterEvent(str2nr(expand(''<abuf>'')))',
204     \ ],
205     \ filter(CheckAutocmd('ALEEvents'), 'v:val =~ ''^InsertEnter''')
206   else
207     " If the ModeChanged event is available, starting the timer in InsertEnter is not necessary.
208     AssertEqual
209     \ [
210     \ ],
211     \ filter(CheckAutocmd('ALEEvents'), 'v:val =~ ''^InsertEnter''')
212   endif
213
214   if !exists('##ModeChanged')
215     " If the ModeChanged event is not available, bind InsertLeave.
216     AssertEqual
217     \ [
218     \   'InsertLeave * call ale#events#InsertLeaveEvent(str2nr(expand(''<abuf>'')))',
219     \ ],
220     \ filter(CheckAutocmd('ALEEvents'), 'v:val =~ ''^InsertLeave''')
221   else
222     AssertEqual
223     \ [
224     \   'ModeChanged i*:* call ale#events#InsertLeaveEvent(str2nr(expand(''<abuf>'')))',
225     \ ],
226     \ filter(CheckAutocmd('ALEEvents'), 'v:val =~ ''^ModeChanged''')
227   endif
228
229 Execute (g:ale_lint_on_filetype_changed = 1 should bind the FileType event):
230   let g:ale_lint_on_filetype_changed = 1
231
232   AssertEqual
233   \ [
234   \   'FileType * call ale#events#FileTypeEvent( '
235   \     . 'str2nr(expand(''<abuf>'')), '
236   \     . 'expand(''<amatch>'')'
237   \     . ')',
238   \ ],
239   \ filter(CheckAutocmd('ALEEvents'), 'v:val =~ ''\v^FileType''')
240
241 Execute (ALECleanupGroup should include the right commands):
242   if exists('##VimSuspend')
243     AssertEqual [
244     \ 'BufDelete * if exists(''*ale#engine#Cleanup'') | call ale#engine#Cleanup(str2nr(expand(''<abuf>''))) | endif',
245     \ 'QuitPre * call ale#events#QuitEvent(str2nr(expand(''<abuf>'')))',
246     \ 'VimSuspend * if exists(''*ale#engine#CleanupEveryBuffer'') | call ale#engine#CleanupEveryBuffer() | endif',
247     \], CheckAutocmd('ALECleanupGroup')
248   else
249     AssertEqual [
250     \ 'BufDelete * if exists(''*ale#engine#Cleanup'') | call ale#engine#Cleanup(str2nr(expand(''<abuf>''))) | endif',
251     \ 'QuitPre * call ale#events#QuitEvent(str2nr(expand(''<abuf>'')))',
252     \], CheckAutocmd('ALECleanupGroup')
253   endif
254
255 Execute(ALECompletionActions should always be set up):
256   AssertEqual [
257   \ 'CompleteDone * call ale#completion#HandleUserData(v:completed_item)',
258   \], CheckAutocmd('ALECompletionActions')
259
260 Execute(Enabling completion should set up autocmd events correctly):
261   let g:ale_completion_enabled = 0
262   call ale#completion#Enable()
263
264   AssertEqual [
265   \ 'CompleteDone * call ale#completion#Done()',
266   \ 'TextChangedI * call ale#completion#Queue()',
267   \], CheckAutocmd('ALECompletionGroup')
268   AssertEqual 1, g:ale_completion_enabled
269
270 Execute(Disabling completion should remove autocmd events correctly):
271   let g:ale_completion_enabled = 1
272   call ale#completion#Enable()
273   call ale#completion#Disable()
274
275   AssertEqual [], CheckAutocmd('ALECompletionGroup')
276   AssertEqual 0, g:ale_completion_enabled
277
278 Execute(ALE should try to close the preview window on InsertEnter):
279   let g:ale_lint_on_insert_leave = 0
280   let g:ale_close_preview_on_insert = 1
281
282   AssertEqual
283   \ [
284   \   'InsertEnter * call ale#events#InsertEnterEvent(str2nr(expand(''<abuf>'')))',
285   \ ],
286   \ filter(CheckAutocmd('ALEEvents'), 'v:val =~ ''^InsertEnter''')