From f2ea4f703450cc27712e5f396e0bbe7bc1ff2be7 Mon Sep 17 00:00:00 2001 From: Andy Stewart Date: Tue, 24 Sep 2019 18:38:12 +0100 Subject: [PATCH] Fix missing empty string when LCS at one end --- autoload/gitgutter/diff_highlight.vim | 4 ++-- test/test_gitgutter.vim | 8 ++++++++ 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/autoload/gitgutter/diff_highlight.vim b/autoload/gitgutter/diff_highlight.vim index c2c48e1..03e20ff 100644 --- a/autoload/gitgutter/diff_highlight.vim +++ b/autoload/gitgutter/diff_highlight.vim @@ -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 diff --git a/test/test_gitgutter.vim b/test/test_gitgutter.vim index 20044bb..6e0a9e6 100644 --- a/test/test_gitgutter.vim +++ b/test/test_gitgutter.vim @@ -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