2017-02-15 21:36:16 +00:00
|
|
|
Before:
|
2017-08-13 21:27:01 +00:00
|
|
|
Save g:ale_buffer_info
|
|
|
|
|
|
|
|
let g:ale_buffer_info = {}
|
2017-02-15 21:36:16 +00:00
|
|
|
let g:expected_loclist = [{
|
|
|
|
\ 'bufnr': bufnr('%'),
|
|
|
|
\ 'lnum': 2,
|
|
|
|
\ 'vcol': 0,
|
|
|
|
\ 'col': 3,
|
|
|
|
\ 'text': 'foo bar',
|
|
|
|
\ 'type': 'E',
|
|
|
|
\ 'nr': -1,
|
|
|
|
\ 'pattern': '',
|
|
|
|
\ 'valid': 1,
|
|
|
|
\}]
|
|
|
|
let g:expected_groups = [
|
|
|
|
\ 'ALECleanupGroup',
|
|
|
|
\ 'ALECursorGroup',
|
|
|
|
\ 'ALEHighlightBufferGroup',
|
|
|
|
\ 'ALERunOnEnterGroup',
|
2017-03-27 21:40:25 +00:00
|
|
|
\ 'ALERunOnFiletypeChangeGroup',
|
2017-03-27 19:36:35 +00:00
|
|
|
\ 'ALERunOnSaveGroup',
|
2017-02-15 21:36:16 +00:00
|
|
|
\ 'ALERunOnTextChangedGroup',
|
|
|
|
\]
|
|
|
|
|
|
|
|
function! ToggleTestCallback(buffer, output)
|
|
|
|
return [{
|
|
|
|
\ 'bufnr': a:buffer,
|
|
|
|
\ 'lnum': 2,
|
|
|
|
\ 'vcol': 0,
|
|
|
|
\ 'col': 3,
|
2017-05-12 20:16:15 +00:00
|
|
|
\ 'text': 'foo bar',
|
2017-02-15 21:36:16 +00:00
|
|
|
\ 'type': 'E',
|
|
|
|
\ 'nr': -1,
|
|
|
|
\}]
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
function! ParseAuGroups()
|
|
|
|
redir => l:output
|
|
|
|
silent exec 'autocmd'
|
|
|
|
redir end
|
|
|
|
|
|
|
|
let l:results = []
|
|
|
|
|
|
|
|
for l:line in split(l:output, "\n")
|
|
|
|
let l:match = matchlist(l:line, '^ALE[a-zA-Z]\+Group')
|
|
|
|
|
2017-08-13 21:27:01 +00:00
|
|
|
" We don't care about some groups here.
|
2017-02-15 21:36:16 +00:00
|
|
|
if !empty(l:match)
|
2017-07-07 22:47:41 +00:00
|
|
|
\&& l:match[0] !=# 'ALECompletionGroup'
|
|
|
|
\&& l:match[0] !=# 'ALEBufferFixGroup'
|
2017-08-13 21:27:01 +00:00
|
|
|
\&& l:match[0] !=# 'ALEPatternOptionsGroup'
|
2017-02-15 21:36:16 +00:00
|
|
|
call add(l:results, l:match[0])
|
|
|
|
endif
|
|
|
|
endfor
|
|
|
|
|
|
|
|
call uniq(sort(l:results))
|
|
|
|
|
|
|
|
return l:results
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
call ale#linter#Define('foobar', {
|
|
|
|
\ 'name': 'testlinter',
|
|
|
|
\ 'callback': 'ToggleTestCallback',
|
|
|
|
\ 'executable': 'echo',
|
2017-05-12 20:16:15 +00:00
|
|
|
\ 'command': 'echo',
|
|
|
|
\ 'read_buffer': 0,
|
2017-02-15 21:36:16 +00:00
|
|
|
\})
|
|
|
|
|
|
|
|
After:
|
2017-08-13 21:27:01 +00:00
|
|
|
Restore
|
|
|
|
|
2017-02-15 21:36:16 +00:00
|
|
|
unlet! g:expected_loclist
|
|
|
|
unlet! g:expected_groups
|
|
|
|
|
|
|
|
call ale#linter#Reset()
|
|
|
|
|
|
|
|
" Toggle ALE back on if we fail when it's disabled.
|
|
|
|
if !g:ale_enabled
|
|
|
|
ALEToggle
|
|
|
|
endif
|
|
|
|
|
|
|
|
delfunction ToggleTestCallback
|
|
|
|
delfunction ParseAuGroups
|
|
|
|
|
|
|
|
Given foobar (Some imaginary filetype):
|
|
|
|
foo
|
|
|
|
bar
|
|
|
|
baz
|
|
|
|
|
|
|
|
Execute(ALEToggle should reset everything and then run again):
|
|
|
|
AssertEqual 'foobar', &filetype
|
|
|
|
|
|
|
|
call ale#Lint()
|
|
|
|
call ale#engine#WaitForJobs(2000)
|
|
|
|
|
|
|
|
" First check that everything is there...
|
|
|
|
AssertEqual g:expected_loclist, getloclist(0)
|
2017-03-14 23:04:25 +00:00
|
|
|
AssertEqual [[2, 1000001, 'ALEErrorSign']], ale#sign#FindCurrentSigns(bufnr('%'))
|
2017-02-15 21:36:16 +00:00
|
|
|
AssertEqual
|
|
|
|
\ [{'group': 'ALEError', 'pos1': [2, 3, 1]}],
|
|
|
|
\ map(getmatches(), '{''group'': v:val.group, ''pos1'': v:val.pos1}')
|
|
|
|
AssertEqual g:expected_groups, ParseAuGroups()
|
2017-07-07 22:47:41 +00:00
|
|
|
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
|
2017-02-15 21:36:16 +00:00
|
|
|
|
|
|
|
" Now Toggle ALE off.
|
|
|
|
ALEToggle
|
|
|
|
|
|
|
|
" Everything should be cleared.
|
2017-07-07 22:47:41 +00:00
|
|
|
Assert !has_key(g:ale_buffer_info, bufnr('')), 'The g:ale_buffer_info Dictionary was not removed'
|
|
|
|
AssertEqual [], getloclist(0), 'The loclist was not cleared'
|
|
|
|
AssertEqual [], ale#sign#FindCurrentSigns(bufnr('%')), 'The signs were not cleared'
|
|
|
|
AssertEqual [], getmatches(), 'The highlights were not cleared'
|
|
|
|
AssertEqual ['ALECleanupGroup', 'ALEHighlightBufferGroup'], ParseAuGroups()
|
2017-02-15 21:36:16 +00:00
|
|
|
|
|
|
|
" Toggle ALE on, everything should be set up and run again.
|
|
|
|
ALEToggle
|
|
|
|
call ale#engine#WaitForJobs(2000)
|
|
|
|
|
|
|
|
AssertEqual g:expected_loclist, getloclist(0)
|
2017-03-14 23:04:25 +00:00
|
|
|
AssertEqual [[2, 1000001, 'ALEErrorSign']], ale#sign#FindCurrentSigns(bufnr('%'))
|
2017-02-15 21:36:16 +00:00
|
|
|
AssertEqual
|
|
|
|
\ [{'group': 'ALEError', 'pos1': [2, 3, 1]}],
|
|
|
|
\ map(getmatches(), '{''group'': v:val.group, ''pos1'': v:val.pos1}')
|
|
|
|
AssertEqual g:expected_groups, ParseAuGroups()
|
2017-07-07 22:47:41 +00:00
|
|
|
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
|
2017-08-13 21:27:01 +00:00
|
|
|
|
|
|
|
Execute(ALEToggle should skip filename keys and preserve them):
|
|
|
|
AssertEqual 'foobar', &filetype
|
|
|
|
|
|
|
|
let g:ale_buffer_info['/foo/bar/baz.txt'] = {
|
|
|
|
\ 'job_list': [],
|
|
|
|
\ 'active_linter_list': [],
|
|
|
|
\ 'loclist': [],
|
|
|
|
\ 'temporary_file_list': [],
|
|
|
|
\ 'temporary_directory_list': [],
|
|
|
|
\ 'history': [],
|
|
|
|
\}
|
|
|
|
|
|
|
|
call ale#Lint()
|
|
|
|
call ale#engine#WaitForJobs(2000)
|
|
|
|
|
|
|
|
" Now Toggle ALE off.
|
|
|
|
ALEToggle
|
|
|
|
|
|
|
|
AssertEqual
|
|
|
|
\ {
|
|
|
|
\ 'job_list': [],
|
|
|
|
\ 'active_linter_list': [],
|
|
|
|
\ 'loclist': [],
|
|
|
|
\ 'temporary_file_list': [],
|
|
|
|
\ 'temporary_directory_list': [],
|
|
|
|
\ 'history': [],
|
|
|
|
\ },
|
|
|
|
\ get(g:ale_buffer_info, '/foo/bar/baz.txt', {})
|
|
|
|
|
|
|
|
" Toggle ALE on again.
|
|
|
|
ALEToggle
|
|
|
|
call ale#engine#WaitForJobs(2000)
|
|
|
|
|
|
|
|
AssertEqual
|
|
|
|
\ {
|
|
|
|
\ 'job_list': [],
|
|
|
|
\ 'active_linter_list': [],
|
|
|
|
\ 'loclist': [],
|
|
|
|
\ 'temporary_file_list': [],
|
|
|
|
\ 'temporary_directory_list': [],
|
|
|
|
\ 'history': [],
|
|
|
|
\ },
|
|
|
|
\ get(g:ale_buffer_info, '/foo/bar/baz.txt', {})
|