aboutsummaryrefslogtreecommitdiff
path: root/src/nvim/testdir/test_diffmode.vim
diff options
context:
space:
mode:
Diffstat (limited to 'src/nvim/testdir/test_diffmode.vim')
-rw-r--r--src/nvim/testdir/test_diffmode.vim157
1 files changed, 140 insertions, 17 deletions
diff --git a/src/nvim/testdir/test_diffmode.vim b/src/nvim/testdir/test_diffmode.vim
index afe289b262..ad3eec3274 100644
--- a/src/nvim/testdir/test_diffmode.vim
+++ b/src/nvim/testdir/test_diffmode.vim
@@ -2,6 +2,9 @@
func Test_diff_fold_sync()
enew!
+ let g:update_count = 0
+ au DiffUpdated * let g:update_count += 1
+
let l = range(50)
call setline(1, l)
diffthis
@@ -27,12 +30,27 @@ func Test_diff_fold_sync()
call win_gotoid(winone)
call assert_equal(23, getcurpos()[1])
+ call assert_equal(1, g:update_count)
+ au! DiffUpdated
+
windo diffoff
close!
set nomodified
endfunc
func Test_vert_split()
+ set diffopt=filler
+ call Common_vert_split()
+ set diffopt&
+endfunc
+
+func Test_vert_split_internal()
+ set diffopt=internal,filler
+ call Common_vert_split()
+ set diffopt&
+endfunc
+
+func Common_vert_split()
" Disable the title to avoid xterm keeping the wrong one.
set notitle noicon
new
@@ -201,6 +219,26 @@ func Test_diffget_diffput()
%bwipe!
endfunc
+" Test putting two changes from one buffer to another
+func Test_diffput_two()
+ new a
+ let win_a = win_getid()
+ call setline(1, range(1, 10))
+ diffthis
+ new b
+ let win_b = win_getid()
+ call setline(1, range(1, 10))
+ 8del
+ 5del
+ diffthis
+ call win_gotoid(win_a)
+ %diffput
+ call win_gotoid(win_b)
+ call assert_equal(map(range(1, 10), 'string(v:val)'), getline(1, '$'))
+ bwipe! a
+ bwipe! b
+endfunc
+
func Test_dp_do_buffer()
e! one
let bn1=bufnr('%')
@@ -257,6 +295,28 @@ func Test_dp_do_buffer()
%bwipe!
endfunc
+func Test_do_lastline()
+ e! one
+ call setline(1, ['1','2','3','4','5','6'])
+ diffthis
+
+ new two
+ call setline(1, ['2','4','5'])
+ diffthis
+
+ 1
+ norm dp]c
+ norm dp]c
+ wincmd w
+ call assert_equal(4, line('$'))
+ norm G
+ norm do
+ call assert_equal(3, line('$'))
+
+ windo diffoff
+ %bwipe!
+endfunc
+
func Test_diffoff()
enew!
call setline(1, ['Two', 'Three'])
@@ -275,10 +335,8 @@ func Test_diffoff()
bwipe!
endfunc
-func Test_diffopt_icase()
- set diffopt=icase,foldcolumn:0
-
- e one
+func Common_icase_test()
+ edit one
call setline(1, ['One', 'Two', 'Three', 'Four', 'Fi#ve'])
redraw
let normattr = screenattr(1, 1)
@@ -300,32 +358,54 @@ func Test_diffopt_icase()
diffoff!
%bwipe!
+endfunc
+
+func Test_diffopt_icase()
+ set diffopt=icase,foldcolumn:0
+ call Common_icase_test()
set diffopt&
endfunc
-func Test_diffopt_iwhite()
- set diffopt=iwhite,foldcolumn:0
+func Test_diffopt_icase_internal()
+ set diffopt=icase,foldcolumn:0,internal
+ call Common_icase_test()
+ set diffopt&
+endfunc
- e one
- " Difference in trailing spaces should be ignored,
+func Common_iwhite_test()
+ edit one
+ " Difference in trailing spaces and amount of spaces should be ignored,
" but not other space differences.
- call setline(1, ["One \t", 'Two', 'Three', 'Four'])
+ call setline(1, ["One \t", 'Two', 'Three', 'one two', 'one two', 'Four'])
redraw
let normattr = screenattr(1, 1)
diffthis
botright vert new two
- call setline(1, ["One\t ", "Two\t ", 'Three', ' Four'])
+ call setline(1, ["One\t ", "Two\t ", 'Three', 'one two', 'onetwo', ' Four'])
diffthis
redraw
call assert_equal(normattr, screenattr(1, 1))
call assert_equal(normattr, screenattr(2, 1))
call assert_equal(normattr, screenattr(3, 1))
- call assert_notequal(normattr, screenattr(4, 1))
+ call assert_equal(normattr, screenattr(4, 1))
+ call assert_notequal(normattr, screenattr(5, 1))
+ call assert_notequal(normattr, screenattr(6, 1))
diffoff!
%bwipe!
+endfunc
+
+func Test_diffopt_iwhite()
+ set diffopt=iwhite,foldcolumn:0
+ call Common_iwhite_test()
+ set diffopt&
+endfunc
+
+func Test_diffopt_iwhite_internal()
+ set diffopt=internal,iwhite,foldcolumn:0
+ call Common_iwhite_test()
set diffopt&
endfunc
@@ -339,8 +419,13 @@ func Test_diffopt_context()
set diffopt=context:2
call assert_equal('+-- 2 lines: 1', foldtextresult(1))
+ set diffopt=internal,context:2
+ call assert_equal('+-- 2 lines: 1', foldtextresult(1))
+
set diffopt=context:1
call assert_equal('+-- 3 lines: 1', foldtextresult(1))
+ set diffopt=internal,context:1
+ call assert_equal('+-- 3 lines: 1', foldtextresult(1))
diffoff!
%bwipe!
@@ -348,7 +433,7 @@ func Test_diffopt_context()
endfunc
func Test_diffopt_horizontal()
- set diffopt=horizontal
+ set diffopt=internal,horizontal
diffsplit
call assert_equal(&columns, winwidth(1))
@@ -362,7 +447,7 @@ func Test_diffopt_horizontal()
endfunc
func Test_diffopt_vertical()
- set diffopt=vertical
+ set diffopt=internal,vertical
diffsplit
call assert_equal(&lines - 2, winheight(1))
@@ -376,7 +461,7 @@ func Test_diffopt_vertical()
endfunc
func Test_diffopt_hiddenoff()
- set diffopt=filler,foldcolumn:0,hiddenoff
+ set diffopt=internal,filler,foldcolumn:0,hiddenoff
e! one
call setline(1, ['Two', 'Three'])
redraw
@@ -399,7 +484,7 @@ func Test_diffopt_hiddenoff()
endfunc
func Test_diffoff_hidden()
- set diffopt=filler,foldcolumn:0
+ set diffopt=internal,filler,foldcolumn:0
e! one
call setline(1, ['Two', 'Three'])
redraw
@@ -480,7 +565,9 @@ func Test_diffexpr()
endif
func DiffExpr()
- silent exe '!diff ' . v:fname_in . ' ' . v:fname_new . '>' . v:fname_out
+ " Prepend some text to check diff type detection
+ call writefile(['warning', ' message'], v:fname_out)
+ silent exe '!diff ' . v:fname_in . ' ' . v:fname_new . '>>' . v:fname_out
endfunc
set diffexpr=DiffExpr()
set diffopt=foldcolumn:0
@@ -523,7 +610,7 @@ func Test_diffpatch()
3
+ 4
.
- saveas Xpatch
+ saveas! Xpatch
bwipe!
new
call assert_fails('diffpatch Xpatch', 'E816:')
@@ -569,6 +656,22 @@ func Test_diff_nomodifiable()
%bwipe!
endfunc
+func Test_diff_filler()
+ new
+ call setline(1, [1, 2, 3, 'x', 4])
+ diffthis
+ vnew
+ call setline(1, [1, 2, 'y', 'y', 3, 4])
+ diffthis
+ redraw
+
+ call assert_equal([0, 0, 0, 0, 0, 0, 0, 1, 0], map(range(-1, 7), 'diff_filler(v:val)'))
+ wincmd w
+ call assert_equal([0, 0, 0, 0, 2, 0, 0, 0], map(range(-1, 6), 'diff_filler(v:val)'))
+
+ %bwipe!
+endfunc
+
func Test_diff_lastline()
enew!
only!
@@ -615,3 +718,23 @@ func Test_diff_with_cursorline()
call StopVimInTerminal(buf)
call delete('Xtest_diff_cursorline')
endfunc
+
+func Test_diff_of_diff()
+ if !CanRunVimInTerminal()
+ return
+ endif
+
+ call writefile([
+ \ 'call setline(1, ["aa","bb","cc","@@ -3,2 +5,7 @@","dd","ee","ff"])',
+ \ 'vnew',
+ \ 'call setline(1, ["aa","bb","cc"])',
+ \ 'windo diffthis',
+ \ ], 'Xtest_diff_diff')
+ let buf = RunVimInTerminal('-S Xtest_diff_diff', {})
+
+ call VerifyScreenDump(buf, 'Test_diff_of_diff_01', {})
+
+ " clean up
+ call StopVimInTerminal(buf)
+ call delete('Xtest_diff_diff')
+endfunc