mirror of
https://github.com/airblade/vim-gitgutter.git
synced 2025-11-08 11:33:48 -05:00
Handle edge case in common prefix calculation
This commit is contained in:
@@ -162,6 +162,9 @@ endif
|
||||
"
|
||||
function! s:common_prefix(a, b)
|
||||
let len = min([len(a:a), len(a:b)])
|
||||
if len == 0
|
||||
return -1
|
||||
endif
|
||||
for i in range(len)
|
||||
if a:a[i:i] != a:b[i:i]
|
||||
return i - 1
|
||||
|
||||
@@ -916,6 +916,9 @@ endfunction
|
||||
|
||||
|
||||
function Test_common_prefix()
|
||||
" zero length
|
||||
call assert_equal(-1, gitgutter#diff_highlight#common_prefix('', 'foo'))
|
||||
call assert_equal(-1, gitgutter#diff_highlight#common_prefix('foo', ''))
|
||||
" nothing in common
|
||||
call assert_equal(-1, gitgutter#diff_highlight#common_prefix('-abcde', '+pqrst'))
|
||||
call assert_equal(-1, gitgutter#diff_highlight#common_prefix('abcde', 'pqrst'))
|
||||
|
||||
Reference in New Issue
Block a user