summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorw0rp <devw0rp@gmail.com>2016-10-13 20:56:18 +0100
committerw0rp <devw0rp@gmail.com>2016-10-13 20:56:18 +0100
commitf506887b28b64879a8dd7c47ade57164c42e86df (patch)
treefdd23ddaa3171902b0c1c79ebff5e8f8b4848d29
parent5ca7cc14f314c0491a9e7f2100150d345955d4b7 (diff)
downloadale-f506887b28b64879a8dd7c47ade57164c42e86df.zip
Add a unit test for the loclist comparison function.
-rw-r--r--autoload/ale/engine.vim22
-rw-r--r--autoload/ale/util.vim20
-rw-r--r--test/test_loclist_sorting.vader21
3 files changed, 42 insertions, 21 deletions
diff --git a/autoload/ale/engine.vim b/autoload/ale/engine.vim
index 0ce5b84e..4f15c935 100644
--- a/autoload/ale/engine.vim
+++ b/autoload/ale/engine.vim
@@ -103,7 +103,7 @@ function! s:HandleExit(job) abort
" Sort the loclist again.
" We need a sorted list so we can run a binary search against it
" for efficient lookup of the messages in the cursor handler.
- call sort(g:ale_buffer_loclist_map[l:buffer], 's:LocItemCompare')
+ call sort(g:ale_buffer_loclist_map[l:buffer], 'ale#util#LocItemCompare')
if g:ale_set_loclist
call setloclist(0, g:ale_buffer_loclist_map[l:buffer])
@@ -149,26 +149,6 @@ function! s:FixLocList(buffer, loclist) abort
endfor
endfunction
-function! s:LocItemCompare(left, right) abort
- if a:left['lnum'] < a:right['lnum']
- return -1
- endif
-
- if a:left['lnum'] > a:right['lnum']
- return 1
- endif
-
- if a:left['col'] < a:right['col']
- return -1
- endif
-
- if a:left['col'] > a:right['col']
- return 1
- endif
-
- return 0
-endfunction
-
function! ale#engine#Invoke(buffer, linter) abort
if has_key(a:linter, 'job')
" Stop previous jobs for the same linter.
diff --git a/autoload/ale/util.vim b/autoload/ale/util.vim
index 4217ac49..17ce7c44 100644
--- a/autoload/ale/util.vim
+++ b/autoload/ale/util.vim
@@ -43,3 +43,23 @@ function! ale#util#GetFunction(string_or_ref) abort
return a:string_or_ref
endfunction
+
+function! ale#util#LocItemCompare(left, right) abort
+ if a:left['lnum'] < a:right['lnum']
+ return -1
+ endif
+
+ if a:left['lnum'] > a:right['lnum']
+ return 1
+ endif
+
+ if a:left['col'] < a:right['col']
+ return -1
+ endif
+
+ if a:left['col'] > a:right['col']
+ return 1
+ endif
+
+ return 0
+endfunction
diff --git a/test/test_loclist_sorting.vader b/test/test_loclist_sorting.vader
new file mode 100644
index 00000000..fe4bc688
--- /dev/null
+++ b/test/test_loclist_sorting.vader
@@ -0,0 +1,21 @@
+Before:
+ let g:loclist = [
+ \ {'lnum': 5, 'col': 5},
+ \ {'lnum': 5, 'col': 4},
+ \ {'lnum': 2, 'col': 10},
+ \ {'lnum': 3, 'col': 2},
+ \]
+
+Execute (Sort loclist with comparison function):
+ call sort(g:loclist, 'ale#util#LocItemCompare')
+
+Then (loclist item should be sorted):
+ AssertEqual g:loclist, [
+ \ {'lnum': 2, 'col': 10},
+ \ {'lnum': 3, 'col': 2},
+ \ {'lnum': 5, 'col': 4},
+ \ {'lnum': 5, 'col': 5},
+ \]
+
+After:
+ unlet g:loclist