Fix tests so they work with new NeoVim highlight code

This commit is contained in:
w0rp 2019-09-01 13:31:09 +01:00
parent 7d7ddf22d3
commit 67ee2b9586
No known key found for this signature in database
GPG Key ID: 0FC1ECAA8C81CD83
2 changed files with 196 additions and 80 deletions

View File

@ -36,6 +36,7 @@ Before:
\ 'ALEEvents',
\ 'ALEHighlightBufferGroup',
\]
let g:has_nvim_highlight = exists('*nvim_buf_add_highlight') && exists('*nvim_buf_clear_namespace')
function! ToggleTestCallback(buffer, output)
return [{
@ -91,6 +92,7 @@ After:
unlet! g:expected_groups
unlet! b:ale_enabled
unlet! g:output
unlet! g:has_nvim_highlight
call ale#linter#Reset()
@ -120,9 +122,14 @@ Execute(ALEToggle should reset everything and then run again):
" First check that everything is there...
AssertEqual g:expected_loclist, ale#test#GetLoclistWithoutModule()
AssertEqual [0, [[2, 1000001, 'ALEErrorSign']]], ale#sign#FindCurrentSigns(bufnr('%'))
AssertEqual
\ [{'group': 'ALEError', 'pos1': [2, 3, 1]}],
\ map(getmatches(), '{''group'': v:val.group, ''pos1'': v:val.pos1}')
" Only check the legacy matches if not using the new NeoVIM API.
if !g:has_nvim_highlight
AssertEqual
\ [{'group': 'ALEError', 'pos1': [2, 3, 1]}],
\ map(getmatches(), '{''group'': v:val.group, ''pos1'': v:val.pos1}')
endif
AssertEqual g:expected_groups, ParseAuGroups()
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
@ -133,7 +140,11 @@ Execute(ALEToggle should reset everything and then run again):
Assert !has_key(g:ale_buffer_info, bufnr('')), 'The g:ale_buffer_info Dictionary was not removed'
AssertEqual [], ale#test#GetLoclistWithoutModule(), 'The loclist was not cleared'
AssertEqual [0, []], ale#sign#FindCurrentSigns(bufnr('%')), 'The signs were not cleared'
AssertEqual [], getmatches(), 'The highlights were not cleared'
if !g:has_nvim_highlight
AssertEqual [], getmatches(), 'The highlights were not cleared'
endif
AssertEqual g:expected_groups, ParseAuGroups()
" Toggle ALE on, everything should be set up and run again.
@ -142,9 +153,13 @@ Execute(ALEToggle should reset everything and then run again):
AssertEqual g:expected_loclist, ale#test#GetLoclistWithoutModule()
AssertEqual [0, [[2, 1000001, 'ALEErrorSign']]], ale#sign#FindCurrentSigns(bufnr('%'))
AssertEqual
\ [{'group': 'ALEError', 'pos1': [2, 3, 1]}],
\ map(getmatches(), '{''group'': v:val.group, ''pos1'': v:val.pos1}')
if !g:has_nvim_highlight
AssertEqual
\ [{'group': 'ALEError', 'pos1': [2, 3, 1]}],
\ map(getmatches(), '{''group'': v:val.group, ''pos1'': v:val.pos1}')
endif
AssertEqual g:expected_groups, ParseAuGroups()
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
@ -228,9 +243,13 @@ Execute(ALEReset should reset everything for a buffer):
" First check that everything is there...
AssertEqual g:expected_loclist, ale#test#GetLoclistWithoutModule()
AssertEqual [0, [[2, 1000001, 'ALEErrorSign']]], ale#sign#FindCurrentSigns(bufnr('%'))
AssertEqual
\ [{'group': 'ALEError', 'pos1': [2, 3, 1]}],
\ map(getmatches(), '{''group'': v:val.group, ''pos1'': v:val.pos1}')
if !g:has_nvim_highlight
AssertEqual
\ [{'group': 'ALEError', 'pos1': [2, 3, 1]}],
\ map(getmatches(), '{''group'': v:val.group, ''pos1'': v:val.pos1}')
endif
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
" Now Toggle ALE off.
@ -241,7 +260,10 @@ Execute(ALEReset should reset everything for a buffer):
Assert !has_key(g:ale_buffer_info, bufnr('')), 'The g:ale_buffer_info Dictionary was not removed'
AssertEqual [], ale#test#GetLoclistWithoutModule(), 'The loclist was not cleared'
AssertEqual [0, []], ale#sign#FindCurrentSigns(bufnr('%')), 'The signs were not cleared'
AssertEqual [], getmatches(), 'The highlights were not cleared'
if !g:has_nvim_highlight
AssertEqual [], getmatches(), 'The highlights were not cleared'
endif
AssertEqual 1, g:ale_enabled
@ -254,9 +276,13 @@ Execute(ALEToggleBuffer should reset everything and then run again):
" First check that everything is there...
AssertEqual g:expected_loclist, ale#test#GetLoclistWithoutModule()
AssertEqual [0, [[2, 1000001, 'ALEErrorSign']]], ale#sign#FindCurrentSigns(bufnr('%'))
AssertEqual
\ [{'group': 'ALEError', 'pos1': [2, 3, 1]}],
\ map(getmatches(), '{''group'': v:val.group, ''pos1'': v:val.pos1}')
if !g:has_nvim_highlight
AssertEqual
\ [{'group': 'ALEError', 'pos1': [2, 3, 1]}],
\ map(getmatches(), '{''group'': v:val.group, ''pos1'': v:val.pos1}')
endif
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
" Now Toggle ALE off.
@ -266,7 +292,10 @@ Execute(ALEToggleBuffer should reset everything and then run again):
Assert !has_key(g:ale_buffer_info, bufnr('')), 'The g:ale_buffer_info Dictionary was not removed'
AssertEqual [], ale#test#GetLoclistWithoutModule(), 'The loclist was not cleared'
AssertEqual [0, []], ale#sign#FindCurrentSigns(bufnr('%')), 'The signs were not cleared'
AssertEqual [], getmatches(), 'The highlights were not cleared'
if !g:has_nvim_highlight
AssertEqual [], getmatches(), 'The highlights were not cleared'
endif
" Toggle ALE on, everything should be set up and run again.
ALEToggleBuffer
@ -274,9 +303,13 @@ Execute(ALEToggleBuffer should reset everything and then run again):
AssertEqual g:expected_loclist, ale#test#GetLoclistWithoutModule()
AssertEqual [0, [[2, 1000001, 'ALEErrorSign']]], ale#sign#FindCurrentSigns(bufnr('%'))
AssertEqual
\ [{'group': 'ALEError', 'pos1': [2, 3, 1]}],
\ map(getmatches(), '{''group'': v:val.group, ''pos1'': v:val.pos1}')
if !g:has_nvim_highlight
AssertEqual
\ [{'group': 'ALEError', 'pos1': [2, 3, 1]}],
\ map(getmatches(), '{''group'': v:val.group, ''pos1'': v:val.pos1}')
endif
AssertEqual g:expected_groups, ParseAuGroups()
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
@ -325,9 +358,13 @@ Execute(ALEResetBuffer should reset everything for a buffer):
" First check that everything is there...
AssertEqual g:expected_loclist, ale#test#GetLoclistWithoutModule()
AssertEqual [0, [[2, 1000001, 'ALEErrorSign']]], ale#sign#FindCurrentSigns(bufnr('%'))
AssertEqual
\ [{'group': 'ALEError', 'pos1': [2, 3, 1]}],
\ map(getmatches(), '{''group'': v:val.group, ''pos1'': v:val.pos1}')
if !g:has_nvim_highlight
AssertEqual
\ [{'group': 'ALEError', 'pos1': [2, 3, 1]}],
\ map(getmatches(), '{''group'': v:val.group, ''pos1'': v:val.pos1}')
endif
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
" Now Toggle ALE off.
@ -338,7 +375,10 @@ Execute(ALEResetBuffer should reset everything for a buffer):
Assert !has_key(g:ale_buffer_info, bufnr('')), 'The g:ale_buffer_info Dictionary was not removed'
AssertEqual [], ale#test#GetLoclistWithoutModule(), 'The loclist was not cleared'
AssertEqual [0, []], ale#sign#FindCurrentSigns(bufnr('%')), 'The signs were not cleared'
AssertEqual [], getmatches(), 'The highlights were not cleared'
if !g:has_nvim_highlight
AssertEqual [], getmatches(), 'The highlights were not cleared'
endif
AssertEqual 1, g:ale_enabled
AssertEqual 1, get(b:, 'ale_enabled', 1)

View File

@ -146,9 +146,12 @@ Execute(Highlights set by ALE should be removed when buffer cleanup is done):
\ {'bufnr': bufnr('%'), 'type': 'E', 'lnum': 3, 'col': 2},
\])
AssertEqual
\ [{'group': 'ALEError', 'priority': 10, 'pos1': [3, 2, 1]}],
\ GetMatchesWithoutIDs()
if !g:has_nvim_highlight
" This check doesn't work with the new API, for some reason.
AssertEqual
\ [{'group': 'ALEError', 'priority': 10, 'pos1': [3, 2, 1]}],
\ GetMatchesWithoutIDs()
endif
call ale#engine#Cleanup(bufnr('%'))
@ -189,31 +192,53 @@ Execute(Only ALE highlights should be restored when buffers are restored):
call matchaddpos('SomeOtherGroup', [[1, 1, 1]])
" We should have both highlights.
AssertEqual
\ [
\ {'group': 'ALEError', 'priority': 10, 'pos1': [3, 2, 1]},
\ {'group': 'SomeOtherGroup', 'priority': 10, 'pos1': [1, 1, 1]},
\ ],
\ GetMatchesWithoutIDs()
if g:has_nvim_highlight
" When the newer NeoVim API is used, we don't have to worry about
" other highlights, namespacing is available.
AssertEqual
\ [
\ {'group': 'ALEError', 'priority': 10, 'pos1': [3, 2, 1]},
\ ],
\ GetMatchesWithoutIDs()
else
AssertEqual
\ [
\ {'group': 'ALEError', 'priority': 10, 'pos1': [3, 2, 1]},
\ {'group': 'SomeOtherGroup', 'priority': 10, 'pos1': [1, 1, 1]},
\ ],
\ sort(GetMatchesWithoutIDs(), {m1, m2 -> m1.group < m2.group ? -1 : 1})
endif
call ale#highlight#BufferHidden(bufnr('%'))
" We should remove our highlight, but not the other one.
AssertEqual
\ [
\ {'group': 'SomeOtherGroup', 'priority': 10, 'pos1': [1, 1, 1]}
\ ],
\ GetMatchesWithoutIDs()
if g:has_nvim_highlight
AssertEqual [], GetMatchesWithoutIDs()
else
AssertEqual
\ [
\ {'group': 'SomeOtherGroup', 'priority': 10, 'pos1': [1, 1, 1]}
\ ],
\ GetMatchesWithoutIDs()
endif
call ale#highlight#UpdateHighlights()
" Our highlight should apper again.
AssertEqual
\ [
\ {'group': 'SomeOtherGroup', 'priority': 10, 'pos1': [1, 1, 1]},
\ {'group': 'ALEError', 'priority': 10, 'pos1': [3, 2, 1]},
\ ],
\ GetMatchesWithoutIDs()
if g:has_nvim_highlight
AssertEqual
\ [
\ {'group': 'ALEError', 'priority': 10, 'pos1': [3, 2, 1]},
\ ],
\ GetMatchesWithoutIDs()
else
AssertEqual
\ [
\ {'group': 'ALEError', 'priority': 10, 'pos1': [3, 2, 1]},
\ {'group': 'SomeOtherGroup', 'priority': 10, 'pos1': [1, 1, 1]},
\ ],
\ sort(GetMatchesWithoutIDs(), {m1, m2 -> m1.group < m2.group ? -1 : 1})
endif
Execute(Higlight end columns should set an appropriate size):
call ale#highlight#SetHighlights(bufnr('%'), [
@ -260,32 +285,67 @@ Execute(Highlighting should support errors spanning many lines):
call ale#highlight#SetHighlights(bufnr(''), g:items)
" We should set 2 highlights for the item, as we can only add 8 at a time.
AssertEqual
\ [
\ {
\ 'group': 'ALEError', 'priority': 10, 'pos1': [1, 1, 1073741824],
\ 'pos2': [2], 'pos3': [3], 'pos4': [4], 'pos5': [5], 'pos6': [6],
\ 'pos7': [7], 'pos8': [8],
\ },
\ {
\ 'group': 'ALEError', 'priority': 10,
\ 'pos1': [9], 'pos2': [10, 1, 3]
\ },
\ ],
\ GetMatchesWithoutIDs()
if g:has_nvim_highlight
" The newer NeoVim highlight API produces different output.
AssertEqual
\ [
\ {'group': 'ALEError', 'priority': 10, 'pos1': [1, 1, 1073741824]},
\ {'group': 'ALEError', 'priority': 10, 'pos1': [2, 1, 1073741824]},
\ {'group': 'ALEError', 'priority': 10, 'pos1': [3, 1, 1073741824]},
\ {'group': 'ALEError', 'priority': 10, 'pos1': [4, 1, 1073741824]},
\ {'group': 'ALEError', 'priority': 10, 'pos1': [5, 1, 1073741824]},
\ {'group': 'ALEError', 'priority': 10, 'pos1': [6, 1, 1073741824]},
\ {'group': 'ALEError', 'priority': 10, 'pos1': [7, 1, 1073741824]},
\ {'group': 'ALEError', 'priority': 10, 'pos1': [8, 1, 1073741824]},
\ {'group': 'ALEError', 'priority': 10, 'pos1': [9, 1, 1073741824]},
\ {'group': 'ALEError', 'priority': 10, 'pos1': [10, 1, 3]},
\ ],
\ GetMatchesWithoutIDs()
else
" We should set 2 highlights for the item, as we can only add 8 at a time.
AssertEqual
\ [
\ {
\ 'group': 'ALEError', 'priority': 10, 'pos1': [1, 1, 1073741824],
\ 'pos2': [2], 'pos3': [3], 'pos4': [4], 'pos5': [5], 'pos6': [6],
\ 'pos7': [7], 'pos8': [8],
\ },
\ {
\ 'group': 'ALEError', 'priority': 10,
\ 'pos1': [9], 'pos2': [10, 1, 3]
\ },
\ ],
\ GetMatchesWithoutIDs()
endif
Execute(Highlights should always be cleared when the buffer highlight list is empty):
" Add our highlights and something else.
call matchaddpos('ALEError', [[1, 1, 1]])
call matchaddpos('SomeOtherGroup', [[1, 1, 1]])
if g:has_nvim_highlight
" The newer API uses namespacing. We'll emulate it here.
call ale#highlight#nvim_buf_add_highlight(
\ bufnr(''),
\ 1,
\ 'ALEError',
\ 0,
\ 0,
\ 1,
\)
AssertEqual
\ [{'group': 'ALEError', 'priority': 10, 'pos1': [1, 1, 1]}],
\ GetMatchesWithoutIDs()
else
" Add our highlights and something else.
call matchaddpos('ALEError', [[1, 1, 1]])
call matchaddpos('SomeOtherGroup', [[1, 1, 1]])
AssertEqual
\ [
\ {'group': 'ALEError', 'priority': 10, 'pos1': [1, 1, 1]},
\ {'group': 'SomeOtherGroup', 'priority': 10, 'pos1': [1, 1, 1]},
\ ],
\ GetMatchesWithoutIDs()
endif
AssertEqual
\ [
\ {'group': 'ALEError', 'priority': 10, 'pos1': [1, 1, 1]},
\ {'group': 'SomeOtherGroup', 'priority': 10, 'pos1': [1, 1, 1]},
\ ],
\ GetMatchesWithoutIDs()
" Set the List we use for holding highlights for buffers.
let b:ale_highlight_items = []
@ -295,11 +355,13 @@ Execute(Highlights should always be cleared when the buffer highlight list is em
call ale#highlight#UpdateHighlights()
" Check that we remove our highlights.
AssertEqual
\ [
\ {'group': 'SomeOtherGroup', 'priority': 10, 'pos1': [1, 1, 1]},
\ ],
\ GetMatchesWithoutIDs()
if g:has_nvim_highlight
AssertEqual [], GetMatchesWithoutIDs()
else
AssertEqual
\ [{'group': 'SomeOtherGroup', 'priority': 10, 'pos1': [1, 1, 1]}],
\ GetMatchesWithoutIDs()
endif
Execute(Highlights should be cleared when ALE is disabled):
let g:ale_enabled = 1
@ -335,16 +397,30 @@ Execute(Line highlights should be set when signs are disabled):
\ {'bufnr': bufnr(''), 'type': 'I', 'lnum': 3, 'col': 1},
\])
AssertEqual
\ [
\ {'group': 'ALEError', 'priority': 10, 'pos1': [1, 1, 1]},
\ {'group': 'ALEWarning', 'priority': 10, 'pos1': [2, 1, 1]},
\ {'group': 'ALEInfo', 'priority': 10, 'pos1': [3, 1, 1]},
\ {'group': 'aleerrorline', 'priority': 10, 'pos1': [1]},
\ {'group': 'ALEWarningLine', 'priority': 10, 'pos1': [2]},
\ {'group': 'ALEInfoLine', 'priority': 10, 'pos1': [3]},
\ ],
\ GetMatchesWithoutIDs()
if g:has_nvim_highlight
" The output is different with the newer NeoVIM highlight API.
AssertEqual
\ [
\ {'group': 'ALEError', 'priority': 10, 'pos1': [1, 1, 1]},
\ {'group': 'ALEErrorLine', 'priority': 10, 'pos1': [1, 1, 1073741824]},
\ {'group': 'ALEWarning', 'priority': 10, 'pos1': [2, 1, 1]},
\ {'group': 'ALEWarningLine', 'priority': 10, 'pos1': [2, 1, 1073741824]},
\ {'group': 'ALEInfo', 'priority': 10, 'pos1': [3, 1, 1]},
\ {'group': 'ALEInfoLine', 'priority': 10, 'pos1': [3, 1, 1073741824]}
\ ],
\ GetMatchesWithoutIDs()
else
AssertEqual
\ [
\ {'group': 'ALEError', 'priority': 10, 'pos1': [1, 1, 1]},
\ {'group': 'ALEWarning', 'priority': 10, 'pos1': [2, 1, 1]},
\ {'group': 'ALEInfo', 'priority': 10, 'pos1': [3, 1, 1]},
\ {'group': 'aleerrorline', 'priority': 10, 'pos1': [1]},
\ {'group': 'ALEWarningLine', 'priority': 10, 'pos1': [2]},
\ {'group': 'ALEInfoLine', 'priority': 10, 'pos1': [3]},
\ ],
\ GetMatchesWithoutIDs()
endif
" All of the highlights should be removed.
call ale#highlight#RemoveHighlights()