Make sign parsing testable, and add tests for it against various languages.

This commit is contained in:
w0rp 2016-12-16 10:01:28 +00:00
parent 7e6d5292f7
commit 8cb9b2ba4e
2 changed files with 27 additions and 6 deletions

View File

@ -27,19 +27,26 @@ execute 'sign define ALEWarningSign text=' . g:ale_sign_warning
\ . ' texthl=ALEWarningSign' \ . ' texthl=ALEWarningSign'
sign define ALEDummySign sign define ALEDummySign
function! ale#sign#FindCurrentSigns(buffer) abort " Read sign data for a buffer to a list of lines.
function! ale#sign#ReadSigns(buffer) abort
redir => l:output
silent exec 'sign place buffer=' . a:buffer
redir end
return split(l:output, "\n")
endfunction
" Given a list of lines for sign output, return a list of sign IDs
function! ale#sign#ParseSigns(line_list) abort
" Matches output like : " Matches output like :
" line=4 id=1 name=ALEErrorSign " line=4 id=1 name=ALEErrorSign
" строка=1 id=1000001 имя=ALEErrorSign " строка=1 id=1000001 имя=ALEErrorSign
" 行=1 識別子=1000001 名前=ALEWarningSign
let l:pattern = '^.*=\d* .*=\(\d\+\) .*=ALE\(Warning\|Error\|Dummy\)Sign' let l:pattern = '^.*=\d* .*=\(\d\+\) .*=ALE\(Warning\|Error\|Dummy\)Sign'
redir => l:output
silent exec 'sign place buffer=' . a:buffer
redir END
let l:id_list = [] let l:id_list = []
for l:line in split(l:output, "\n") for l:line in a:line_list
let l:match = matchlist(l:line, l:pattern) let l:match = matchlist(l:line, l:pattern)
if len(l:match) > 0 if len(l:match) > 0
@ -50,6 +57,12 @@ function! ale#sign#FindCurrentSigns(buffer) abort
return l:id_list return l:id_list
endfunction endfunction
function! ale#sign#FindCurrentSigns(buffer) abort
let l:line_list = ale#sign#ReadSigns(a:buffer)
return ale#sign#ParseSigns(l:line_list)
endfunction
" Given a loclist, combine the loclist into a list of signs such that only " Given a loclist, combine the loclist into a list of signs such that only
" one sign appears per line. Error lines will take precedence. " one sign appears per line. Error lines will take precedence.
" The loclist will have been previously sorted. " The loclist will have been previously sorted.

View File

@ -0,0 +1,8 @@
Execute (Parsing English signs should work):
AssertEqual [1000001], ale#sign#ParseSigns(['Signs for app.js:', ' line=9 id=1000001 name=ALEWarningSign'])
Execute (Parsing Russian signs should work):
AssertEqual [1000001], ale#sign#ParseSigns([' строка=1 id=1000001 имя=ALEErrorSign'])
Execute (Parsing Japanese signs should work):
AssertEqual [1000001], ale#sign#ParseSigns([' 行=1 識別子=1000001 名前=ALEWarningSign'])