Fix missing empty string when LCS at one end

This commit is contained in:
Andy Stewart
2019-09-24 18:38:12 +01:00
parent 3405ad72b6
commit f2ea4f7034
2 changed files with 10 additions and 2 deletions

View File

@@ -102,8 +102,8 @@ function! s:diff(rline, aline, rlinenr, alinenr, rprefix, aprefix, regions, whol
" two edits
let lcs = s:lcs(rtext, atext)
if len(lcs) > s:gap_between_regions
let redits = split(rtext, lcs)
let aedits = split(atext, lcs)
let redits = split(rtext, lcs, 1)
let aedits = split(atext, lcs, 1)
call s:diff(redits[0], aedits[0], a:rlinenr, a:alinenr, prefix+1, prefix+1, a:regions, 0)
call s:diff(redits[1], aedits[1], a:rlinenr, a:alinenr, prefix+1+len(redits[0])+len(lcs), prefix+1+len(aedits[0])+len(lcs), a:regions, 0)
return

View File

@@ -952,6 +952,7 @@ function Test_common_suffix()
endfunction
" Note the order of lists within the overall returned list does not matter.
function Test_diff_highlight()
" Ignores mismatched number of added and removed lines.
call assert_equal([], gitgutter#diff_highlight#process(['-foo']))
@@ -1022,6 +1023,13 @@ function Test_diff_highlight()
" two edits
let hunk = ['-The cat in the hat.', '+The ox in the box.']
call assert_equal([[1, '-', 6, 8], [2, '+', 6, 7], [1, '-', 17, 19], [2, '+', 16, 18]], gitgutter#diff_highlight#process(hunk))
" Requires s:gap_between_regions = 2 to pass.
" let hunk = ['-foo: bar.zap', '+foo: quux(bar)']
" call assert_equal([[2, '+', 7, 11], [1, '-', 10, 13], [2, '+', 15, 15]], gitgutter#diff_highlight#process(hunk))
let hunk = ['-gross_value: transaction.unexplained_amount', '+gross_value: amount(transaction)']
call assert_equal([[2, '+', 15, 21], [1, '-', 26, 44], [2, '+', 33, 33]], gitgutter#diff_highlight#process(hunk))
endfunction