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.
4 Save g:ale_set_lists_synchronously
5 Save g:ale_run_synchronously
6 Save g:ale_pattern_options
7 Save g:ale_pattern_options_enabled
8 Save g:ale_set_balloons
10 let g:ale_set_signs = 1
11 let g:ale_set_lists_synchronously = 1
12 let g:ale_run_synchronously = 1
13 unlet! g:ale_run_synchronously_callbacks
14 let g:ale_pattern_options = {}
15 let g:ale_pattern_options_enabled = 1
16 let g:ale_set_balloons =
17 \ has('balloon_eval') && has('gui_running') ||
18 \ has('balloon_eval_term') && !has('gui_running')
22 let g:ale_buffer_info = {}
23 let g:expected_loclist = [{
24 \ 'bufnr': bufnr('%'),
34 let g:expected_groups = [
37 \ 'ALEHighlightBufferGroup',
39 let g:has_nvim_highlight = exists('*nvim_buf_add_highlight') && exists('*nvim_buf_clear_namespace')
41 function! ToggleTestCallback(buffer, output)
53 function! ParseAuGroups()
60 for l:line in split(l:output, "\n")
61 let l:match = matchlist(l:line, '^ALE[a-zA-Z]\+')
63 " We don't care about some groups here.
65 \&& l:match[0] !=# 'ALECompletionGroup'
66 \&& l:match[0] !=# 'ALEBufferFixGroup'
67 \&& l:match[0] !=# 'ALEPatternOptionsGroup'
68 call add(l:results, l:match[0])
72 call uniq(sort(l:results))
77 call ale#linter#Define('foobar', {
78 \ 'name': 'testlinter',
79 \ 'callback': 'ToggleTestCallback',
80 \ 'executable': has('win32') ? 'cmd' : 'echo',
90 unlet! g:ale_run_synchronously_callbacks
91 unlet! g:expected_loclist
92 unlet! g:expected_groups
95 unlet! g:has_nvim_highlight
97 call ale#linter#Reset()
99 " Toggle ALE back on if we fail when it's disabled.
104 delfunction ToggleTestCallback
105 delfunction ParseAuGroups
107 call setloclist(0, [])
108 call ale#sign#Clear()
111 Given foobar (Some imaginary filetype):
116 Execute(ALEToggle should reset everything and then run again):
117 AssertEqual 'foobar', &filetype
120 call ale#test#FlushJobs()
122 " First check that everything is there...
123 AssertEqual g:expected_loclist, ale#test#GetLoclistWithoutNewerKeys()
124 AssertEqual [0, [[2, 1000001, 'ALEErrorSign']]], ale#sign#FindCurrentSigns(bufnr('%'))
126 " Only check the legacy matches if not using the new NeoVIM API.
127 if !g:has_nvim_highlight
129 \ [{'group': 'ALEError', 'pos1': [2, 3, 1]}],
130 \ map(getmatches(), '{''group'': v:val.group, ''pos1'': v:val.pos1}')
133 AssertEqual g:expected_groups, ParseAuGroups()
134 AssertEqual [{'lnum': 2, 'bufnr': bufnr(''), 'col': 3, 'linter_name': 'testlinter', 'vcol': 0, 'nr': -1, 'type': 'E', 'text': 'foo bar', 'sign_id': 1000001}], g:ale_buffer_info[bufnr('')].loclist
136 " Now Toggle ALE off.
139 " Everything should be cleared.
140 Assert !has_key(g:ale_buffer_info, bufnr('')), 'The g:ale_buffer_info Dictionary was not removed'
141 AssertEqual [], ale#test#GetLoclistWithoutNewerKeys(), 'The loclist was not cleared'
142 AssertEqual [0, []], ale#sign#FindCurrentSigns(bufnr('%')), 'The signs were not cleared'
144 if !g:has_nvim_highlight
145 AssertEqual [], getmatches(), 'The highlights were not cleared'
148 AssertEqual g:expected_groups, ParseAuGroups()
150 " Toggle ALE on, everything should be set up and run again.
152 call ale#test#FlushJobs()
154 AssertEqual g:expected_loclist, ale#test#GetLoclistWithoutNewerKeys()
155 AssertEqual [0, [[2, 1000001, 'ALEErrorSign']]], ale#sign#FindCurrentSigns(bufnr('%'))
157 if !g:has_nvim_highlight
159 \ [{'group': 'ALEError', 'pos1': [2, 3, 1]}],
160 \ map(getmatches(), '{''group'': v:val.group, ''pos1'': v:val.pos1}')
163 AssertEqual g:expected_groups, ParseAuGroups()
164 AssertEqual [{'lnum': 2, 'bufnr': bufnr(''), 'col': 3, 'linter_name': 'testlinter', 'vcol': 0, 'nr': -1, 'type': 'E', 'text': 'foo bar', 'sign_id': 1000001}], g:ale_buffer_info[bufnr('')].loclist
166 Execute(ALEToggle should skip filename keys and preserve them):
167 AssertEqual 'foobar', &filetype
169 let g:ale_buffer_info['/foo/bar/baz.txt'] = {
171 \ 'active_linter_list': [],
173 \ 'temporary_file_list': [],
174 \ 'temporary_directory_list': [],
179 call ale#test#FlushJobs()
181 " Now Toggle ALE off.
187 \ 'active_linter_list': [],
189 \ 'temporary_file_list': [],
190 \ 'temporary_directory_list': [],
193 \ get(g:ale_buffer_info, '/foo/bar/baz.txt', {})
195 " Toggle ALE on again.
197 call ale#test#FlushJobs()
202 \ 'active_linter_list': [],
204 \ 'temporary_file_list': [],
205 \ 'temporary_directory_list': [],
208 \ get(g:ale_buffer_info, '/foo/bar/baz.txt', {})
210 Execute(ALEDisable should reset everything and stay disabled):
212 call ale#test#FlushJobs()
214 AssertEqual g:expected_loclist, ale#test#GetLoclistWithoutNewerKeys()
217 call ale#test#FlushJobs()
219 AssertEqual [], ale#test#GetLoclistWithoutNewerKeys()
220 AssertEqual 0, g:ale_enabled
223 call ale#test#FlushJobs()
225 AssertEqual [], ale#test#GetLoclistWithoutNewerKeys()
226 AssertEqual 0, g:ale_enabled
228 Execute(ALEEnable should enable ALE and lint again):
229 let g:ale_enabled = 0
232 call ale#test#FlushJobs()
234 AssertEqual g:expected_loclist, ale#test#GetLoclistWithoutNewerKeys()
235 AssertEqual 1, g:ale_enabled
237 Execute(ALEReset should reset everything for a buffer):
238 AssertEqual 'foobar', &filetype
241 call ale#test#FlushJobs()
243 " First check that everything is there...
244 AssertEqual g:expected_loclist, ale#test#GetLoclistWithoutNewerKeys()
245 AssertEqual [0, [[2, 1000001, 'ALEErrorSign']]], ale#sign#FindCurrentSigns(bufnr('%'))
247 if !g:has_nvim_highlight
249 \ [{'group': 'ALEError', 'pos1': [2, 3, 1]}],
250 \ map(getmatches(), '{''group'': v:val.group, ''pos1'': v:val.pos1}')
253 AssertEqual [{'lnum': 2, 'bufnr': bufnr(''), 'col': 3, 'linter_name': 'testlinter', 'vcol': 0, 'nr': -1, 'type': 'E', 'text': 'foo bar', 'sign_id': 1000001}], g:ale_buffer_info[bufnr('')].loclist
255 " Now Toggle ALE off.
257 call ale#test#FlushJobs()
259 " Everything should be cleared.
260 Assert !has_key(g:ale_buffer_info, bufnr('')), 'The g:ale_buffer_info Dictionary was not removed'
261 AssertEqual [], ale#test#GetLoclistWithoutNewerKeys(), 'The loclist was not cleared'
262 AssertEqual [0, []], ale#sign#FindCurrentSigns(bufnr('%')), 'The signs were not cleared'
264 if !g:has_nvim_highlight
265 AssertEqual [], getmatches(), 'The highlights were not cleared'
268 AssertEqual 1, g:ale_enabled
270 Execute(ALEToggleBuffer should reset everything and then run again):
271 AssertEqual 'foobar', &filetype
274 call ale#test#FlushJobs()
276 " First check that everything is there...
277 AssertEqual g:expected_loclist, ale#test#GetLoclistWithoutNewerKeys()
278 AssertEqual [0, [[2, 1000001, 'ALEErrorSign']]], ale#sign#FindCurrentSigns(bufnr('%'))
280 if !g:has_nvim_highlight
282 \ [{'group': 'ALEError', 'pos1': [2, 3, 1]}],
283 \ map(getmatches(), '{''group'': v:val.group, ''pos1'': v:val.pos1}')
286 AssertEqual [{'lnum': 2, 'bufnr': bufnr(''), 'col': 3, 'linter_name': 'testlinter', 'vcol': 0, 'nr': -1, 'type': 'E', 'text': 'foo bar', 'sign_id': 1000001}], g:ale_buffer_info[bufnr('')].loclist
288 " Now Toggle ALE off.
291 " Everything should be cleared.
292 Assert !has_key(g:ale_buffer_info, bufnr('')), 'The g:ale_buffer_info Dictionary was not removed'
293 AssertEqual [], ale#test#GetLoclistWithoutNewerKeys(), 'The loclist was not cleared'
294 AssertEqual [0, []], ale#sign#FindCurrentSigns(bufnr('%')), 'The signs were not cleared'
296 if !g:has_nvim_highlight
297 AssertEqual [], getmatches(), 'The highlights were not cleared'
300 " Toggle ALE on, everything should be set up and run again.
302 call ale#test#FlushJobs()
304 AssertEqual g:expected_loclist, ale#test#GetLoclistWithoutNewerKeys()
305 AssertEqual [0, [[2, 1000001, 'ALEErrorSign']]], ale#sign#FindCurrentSigns(bufnr('%'))
307 if !g:has_nvim_highlight
309 \ [{'group': 'ALEError', 'pos1': [2, 3, 1]}],
310 \ map(getmatches(), '{''group'': v:val.group, ''pos1'': v:val.pos1}')
313 AssertEqual g:expected_groups, ParseAuGroups()
314 AssertEqual [{'lnum': 2, 'bufnr': bufnr(''), 'col': 3, 'linter_name': 'testlinter', 'vcol': 0, 'nr': -1, 'type': 'E', 'text': 'foo bar', 'sign_id': 1000001}], g:ale_buffer_info[bufnr('')].loclist
316 Execute(ALEDisableBuffer should reset everything and stay disabled):
318 call ale#test#FlushJobs()
320 AssertEqual g:expected_loclist, ale#test#GetLoclistWithoutNewerKeys()
323 call ale#test#FlushJobs()
325 AssertEqual [], ale#test#GetLoclistWithoutNewerKeys()
326 AssertEqual 0, b:ale_enabled
328 Execute(ALEEnableBuffer should enable ALE and lint again):
329 let b:ale_enabled = 0
332 call ale#test#FlushJobs()
334 AssertEqual g:expected_loclist, ale#test#GetLoclistWithoutNewerKeys()
335 AssertEqual 1, b:ale_enabled
337 Execute(ALEEnableBuffer should complain when ALE is disabled globally):
338 let g:ale_enabled = 0
339 let b:ale_enabled = 0
345 AssertEqual [], ale#test#GetLoclistWithoutNewerKeys()
346 AssertEqual 0, b:ale_enabled
347 AssertEqual 0, g:ale_enabled
349 \ 'ALE cannot be enabled locally when disabled globally',
350 \ join(split(g:output))
352 Execute(ALEResetBuffer should reset everything for a buffer):
353 AssertEqual 'foobar', &filetype
356 call ale#test#FlushJobs()
358 " First check that everything is there...
359 AssertEqual g:expected_loclist, ale#test#GetLoclistWithoutNewerKeys()
360 AssertEqual [0, [[2, 1000001, 'ALEErrorSign']]], ale#sign#FindCurrentSigns(bufnr('%'))
362 if !g:has_nvim_highlight
364 \ [{'group': 'ALEError', 'pos1': [2, 3, 1]}],
365 \ map(getmatches(), '{''group'': v:val.group, ''pos1'': v:val.pos1}')
368 AssertEqual [{'lnum': 2, 'bufnr': bufnr(''), 'col': 3, 'linter_name': 'testlinter', 'vcol': 0, 'nr': -1, 'type': 'E', 'text': 'foo bar', 'sign_id': 1000001}], g:ale_buffer_info[bufnr('')].loclist
370 " Now Toggle ALE off.
372 call ale#test#FlushJobs()
374 " Everything should be cleared.
375 Assert !has_key(g:ale_buffer_info, bufnr('')), 'The g:ale_buffer_info Dictionary was not removed'
376 AssertEqual [], ale#test#GetLoclistWithoutNewerKeys(), 'The loclist was not cleared'
377 AssertEqual [0, []], ale#sign#FindCurrentSigns(bufnr('%')), 'The signs were not cleared'
379 if !g:has_nvim_highlight
380 AssertEqual [], getmatches(), 'The highlights were not cleared'
383 AssertEqual 1, g:ale_enabled
384 AssertEqual 1, get(b:, 'ale_enabled', 1)
386 Execute(Disabling ALE should disable balloons):
387 " These tests won't run in the console, but we can run them manually in GVim.
388 if has('balloon_eval') && has('gui_running')
389 \|| (has('balloon_eval_term') && !has('gui_running'))
390 call ale#linter#Reset()
392 " Enable balloons, so we can check the expr value.
393 call ale#balloon#Enable()
395 if has('balloon_eval') && has('gui_running')
396 AssertEqual 1, &ballooneval
398 AssertEqual 1, &balloonevalterm
401 AssertEqual 'ale#balloon#Expr()', &balloonexpr
406 " The balloon settings should be reset.
407 if has('balloon_eval') && has('gui_running')
408 AssertEqual 0, &ballooneval
410 AssertEqual 0, &balloonevalterm
413 AssertEqual '', &balloonexpr
416 Execute(Enabling ALE should enable balloons if the setting is on):
417 if has('balloon_eval') && has('gui_running')
418 \|| (has('balloon_eval_term') && !has('gui_running'))
419 call ale#linter#Reset()
420 call ale#balloon#Disable()
422 let g:ale_set_balloons = 0
425 if has('balloon_eval') && has('gui_running')
426 AssertEqual 0, &ballooneval
428 AssertEqual 0, &balloonevalterm
431 AssertEqual '', &balloonexpr
434 let g:ale_set_balloons = 1
437 if has('balloon_eval') && has('gui_running')
438 AssertEqual 1, &ballooneval
440 AssertEqual 1, &balloonevalterm
443 AssertEqual 'ale#balloon#Expr()', &balloonexpr