summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorw0rp <devw0rp@gmail.com>2016-12-16 10:01:28 +0000
committerw0rp <devw0rp@gmail.com>2016-12-16 10:01:28 +0000
commit8cb9b2ba4eda0144dcdb2045c5d3036231e8faa3 (patch)
tree3ab4c59918d84ca44d219b8861e7fc990804841d
parent7e6d5292f7a0aac5331610b60438b9e8ed9d11d6 (diff)
downloadale-8cb9b2ba4eda0144dcdb2045c5d3036231e8faa3.zip
Make sign parsing testable, and add tests for it against various languages.
-rw-r--r--autoload/ale/sign.vim25
-rw-r--r--test/test_sign_parsing.vader8
2 files changed, 27 insertions, 6 deletions
diff --git a/autoload/ale/sign.vim b/autoload/ale/sign.vim
index 88a47aef..b5e9c075 100644
--- a/autoload/ale/sign.vim
+++ b/autoload/ale/sign.vim
@@ -27,19 +27,26 @@ execute 'sign define ALEWarningSign text=' . g:ale_sign_warning
\ . ' texthl=ALEWarningSign'
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 :
" line=4 id=1 name=ALEErrorSign
" строка=1 id=1000001 имя=ALEErrorSign
+ " 行=1 識別子=1000001 名前=ALEWarningSign
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 = []
- for l:line in split(l:output, "\n")
+ for l:line in a:line_list
let l:match = matchlist(l:line, l:pattern)
if len(l:match) > 0
@@ -50,6 +57,12 @@ function! ale#sign#FindCurrentSigns(buffer) abort
return l:id_list
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
" one sign appears per line. Error lines will take precedence.
" The loclist will have been previously sorted.
diff --git a/test/test_sign_parsing.vader b/test/test_sign_parsing.vader
new file mode 100644
index 00000000..a61de0d3
--- /dev/null
+++ b/test/test_sign_parsing.vader
@@ -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'])