summaryrefslogtreecommitdiff
path: root/autoload
diff options
context:
space:
mode:
authorw0rp <devw0rp@gmail.com>2016-10-13 21:24:47 +0100
committerw0rp <devw0rp@gmail.com>2016-10-13 21:24:47 +0100
commita089fabb5c264026a26f7c63aa6f11c5fa9da30a (patch)
tree721ad6bfcdc5d6d2e01d263ec890c4412da6d2f9 /autoload
parentf506887b28b64879a8dd7c47ade57164c42e86df (diff)
downloadale-a089fabb5c264026a26f7c63aa6f11c5fa9da30a.zip
Add some unit tests for the BinarySearch function.
Diffstat (limited to 'autoload')
-rw-r--r--autoload/ale/cursor.vim37
-rw-r--r--autoload/ale/util.vim35
2 files changed, 36 insertions, 36 deletions
diff --git a/autoload/ale/cursor.vim b/autoload/ale/cursor.vim
index 0c5844e7..dfe886fc 100644
--- a/autoload/ale/cursor.vim
+++ b/autoload/ale/cursor.vim
@@ -18,41 +18,6 @@ function! s:GetMessage(linter, type, text) abort
return printf(l:msg, l:text)
endfunction
-" This function will perform a binary search to find a message from the
-" loclist to echo when the cursor moves.
-function! s:BinarySearch(loclist, line, column) abort
- let l:min = 0
- let l:max = len(a:loclist) - 1
- let l:last_column_match = -1
-
- while 1
- if l:max < l:min
- return l:last_column_match
- endif
-
- let l:mid = (l:min + l:max) / 2
- let l:obj = a:loclist[l:mid]
-
- " Binary search to get on the same line
- if a:loclist[l:mid]['lnum'] < a:line
- let l:min = l:mid + 1
- elseif a:loclist[l:mid]['lnum'] > a:line
- let l:max = l:mid - 1
- else
- let l:last_column_match = l:mid
-
- " Binary search to get the same column, or near it
- if a:loclist[l:mid]['col'] < a:column
- let l:min = l:mid + 1
- elseif a:loclist[l:mid]['col'] > a:column
- let l:max = l:mid - 1
- else
- return l:mid
- endif
- endif
- endwhile
-endfunction
-
function! ale#cursor#TruncatedEcho(message) abort
let l:message = a:message
" Change tabs to spaces.
@@ -87,7 +52,7 @@ function! ale#cursor#EchoCursorWarning(...) abort
let l:pos = getcurpos()
let l:loclist = g:ale_buffer_loclist_map[l:buffer]
- let l:index = s:BinarySearch(l:loclist, l:pos[1], l:pos[2])
+ let l:index = ale#util#BinarySearch(l:loclist, l:pos[1], l:pos[2])
if l:index >= 0
let l:loc = l:loclist[l:index]
diff --git a/autoload/ale/util.vim b/autoload/ale/util.vim
index 17ce7c44..c218f090 100644
--- a/autoload/ale/util.vim
+++ b/autoload/ale/util.vim
@@ -63,3 +63,38 @@ function! ale#util#LocItemCompare(left, right) abort
return 0
endfunction
+
+" This function will perform a binary search to find a message from the
+" loclist to echo when the cursor moves.
+function! ale#util#BinarySearch(loclist, line, column) abort
+ let l:min = 0
+ let l:max = len(a:loclist) - 1
+ let l:last_column_match = -1
+
+ while 1
+ if l:max < l:min
+ return l:last_column_match
+ endif
+
+ let l:mid = (l:min + l:max) / 2
+ let l:obj = a:loclist[l:mid]
+
+ " Binary search to get on the same line
+ if a:loclist[l:mid]['lnum'] < a:line
+ let l:min = l:mid + 1
+ elseif a:loclist[l:mid]['lnum'] > a:line
+ let l:max = l:mid - 1
+ else
+ let l:last_column_match = l:mid
+
+ " Binary search to get the same column, or near it
+ if a:loclist[l:mid]['col'] < a:column
+ let l:min = l:mid + 1
+ elseif a:loclist[l:mid]['col'] > a:column
+ let l:max = l:mid - 1
+ else
+ return l:mid
+ endif
+ endif
+ endwhile
+endfunction