mirror of
https://github.com/airblade/vim-gitgutter.git
synced 2025-11-08 19:43:47 -05:00
Fix off-by-one error in LCS calculation
This commit is contained in:
@@ -135,11 +135,11 @@ function! s:lcs(s1, s2)
|
|||||||
|
|
||||||
for i in range(1, len(a:s1))
|
for i in range(1, len(a:s1))
|
||||||
for j in range(1, len(a:s2))
|
for j in range(1, len(a:s2))
|
||||||
if a:s1[i] ==# a:s2[j]
|
if a:s1[i-1] ==# a:s2[j-1]
|
||||||
let matrix[i][j] = 1 + matrix[i-1][j-1]
|
let matrix[i][j] = 1 + matrix[i-1][j-1]
|
||||||
if matrix[i][j] > maxlength
|
if matrix[i][j] > maxlength
|
||||||
let maxlength = matrix[i][j]
|
let maxlength = matrix[i][j]
|
||||||
let endindex = i
|
let endindex = i - 1
|
||||||
endif
|
endif
|
||||||
endif
|
endif
|
||||||
endfor
|
endfor
|
||||||
|
|||||||
@@ -1026,4 +1026,5 @@ function Test_lcs()
|
|||||||
call assert_equal('', gitgutter#diff_highlight#lcs('', 'foo'))
|
call assert_equal('', gitgutter#diff_highlight#lcs('', 'foo'))
|
||||||
call assert_equal('', gitgutter#diff_highlight#lcs('foo', ''))
|
call assert_equal('', gitgutter#diff_highlight#lcs('foo', ''))
|
||||||
call assert_equal('bar', gitgutter#diff_highlight#lcs('foobarbaz', 'bbart'))
|
call assert_equal('bar', gitgutter#diff_highlight#lcs('foobarbaz', 'bbart'))
|
||||||
|
call assert_equal('transaction', gitgutter#diff_highlight#lcs('transaction.unexplained_amount', 'amount(transaction)'))
|
||||||
endfunction
|
endfunction
|
||||||
|
|||||||
Reference in New Issue
Block a user