2016-07-30 16:16:54 +02:00
" Tests for diff mode
2020-08-12 18:50:36 +02:00
2018-09-10 17:51:58 +02:00
source shared .vim
source screendump .vim
2019-08-03 22:55:50 +02:00
source check .vim
2024-03-16 09:40:22 +01:00
source view_util .vim
2016-07-30 16:16:54 +02:00
func Test_diff_fold_sync ( )
enew !
2018-09-16 15:48:06 +02:00
let g :update_count = 0
au DiffUpdated * let g :update_count + = 1
2016-07-30 16:16:54 +02:00
let l = range ( 50 )
call setline ( 1 , l )
diffthis
let winone = win_getid ( )
new
let l [25 ] = 'diff'
call setline ( 1 , l )
diffthis
let wintwo = win_getid ( )
" line 15 is inside the closed fold
call assert_equal ( 19 , foldclosedend ( 10 ) )
call win_gotoid ( winone )
call assert_equal ( 19 , foldclosedend ( 10 ) )
" open the fold
normal zv
call assert_equal ( -1 , foldclosedend ( 10 ) )
" fold in other window must have opened too
call win_gotoid ( wintwo )
call assert_equal ( -1 , foldclosedend ( 10 ) )
" cursor position is in sync
normal 23 G
call win_gotoid ( winone )
call assert_equal ( 23 , getcurpos ( ) [1 ])
2022-06-26 18:17:50 +01:00
" depending on how redraw is done DiffUpdated may be triggered once or twice
call assert_inrange ( 1 , 2 , g :update_count )
2018-09-16 15:48:06 +02:00
au ! DiffUpdated
2016-07-30 16:16:54 +02:00
windo diffoff
close !
set nomodified
endfunc
func Test_vert_split ( )
2018-09-10 17:51:58 +02:00
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 ( )
2016-07-30 16:16:54 +02:00
" Disable the title to avoid xterm keeping the wrong one.
set notitle noicon
new
let l = ['1 aa' , '2 bb' , '3 cc' , '4 dd' , '5 ee' ]
call setline ( 1 , l )
w ! Xtest
normal dd
$
put
normal kkrXoxxx
w ! Xtest2
file Nop
normal ggoyyy jjjozzzz
set foldmethod = marker foldcolumn = 4
call assert_equal ( 0 , &diff )
call assert_equal ( 'marker' , &foldmethod )
call assert_equal ( 4 , &foldcolumn )
call assert_equal ( 0 , &scrollbind )
call assert_equal ( 0 , &cursorbind )
call assert_equal ( 1 , &wrap )
vert diffsplit Xtest
vert diffsplit Xtest2
call assert_equal ( 1 , &diff )
call assert_equal ( 'diff' , &foldmethod )
call assert_equal ( 2 , &foldcolumn )
call assert_equal ( 1 , &scrollbind )
call assert_equal ( 1 , &cursorbind )
call assert_equal ( 0 , &wrap )
let diff_fdm = &fdm
let diff_fdc = &fdc
" repeat entering diff mode here to see if this saves the wrong settings
diffthis
" jump to second window for a moment to have filler line appear at start of
" first window
wincmd w
normal gg
wincmd p
normal gg
call assert_equal ( 2 , winline ( ) )
normal j
call assert_equal ( 4 , winline ( ) )
normal j
call assert_equal ( 5 , winline ( ) )
normal j
call assert_equal ( 6 , winline ( ) )
normal j
call assert_equal ( 8 , winline ( ) )
normal j
call assert_equal ( 9 , winline ( ) )
wincmd w
normal gg
call assert_equal ( 1 , winline ( ) )
normal j
call assert_equal ( 2 , winline ( ) )
normal j
call assert_equal ( 4 , winline ( ) )
normal j
call assert_equal ( 5 , winline ( ) )
normal j
call assert_equal ( 8 , winline ( ) )
wincmd w
normal gg
call assert_equal ( 2 , winline ( ) )
normal j
call assert_equal ( 3 , winline ( ) )
normal j
call assert_equal ( 4 , winline ( ) )
normal j
call assert_equal ( 5 , winline ( ) )
normal j
call assert_equal ( 6 , winline ( ) )
normal j
call assert_equal ( 7 , winline ( ) )
normal j
call assert_equal ( 8 , winline ( ) )
" Test diffoff
diffoff !
2022-08-17 12:09:45 +01:00
1 wincmd w
2016-07-30 16:16:54 +02:00
let &diff = 1
let &fdm = diff_fdm
let &fdc = diff_fdc
4 wincmd w
diffoff !
1 wincmd w
call assert_equal ( 0 , &diff )
call assert_equal ( 'marker' , &foldmethod )
call assert_equal ( 4 , &foldcolumn )
call assert_equal ( 0 , &scrollbind )
call assert_equal ( 0 , &cursorbind )
call assert_equal ( 1 , &wrap )
wincmd w
call assert_equal ( 0 , &diff )
call assert_equal ( 'marker' , &foldmethod )
call assert_equal ( 4 , &foldcolumn )
call assert_equal ( 0 , &scrollbind )
call assert_equal ( 0 , &cursorbind )
call assert_equal ( 1 , &wrap )
wincmd w
call assert_equal ( 0 , &diff )
call assert_equal ( 'marker' , &foldmethod )
call assert_equal ( 4 , &foldcolumn )
call assert_equal ( 0 , &scrollbind )
call assert_equal ( 0 , &cursorbind )
call assert_equal ( 1 , &wrap )
2016-07-30 16:36:01 +02:00
call delete ( 'Xtest' )
call delete ( 'Xtest2' )
2016-07-30 16:16:54 +02:00
windo bw !
endfunc
func Test_filler_lines ( )
" Test that diffing shows correct filler lines
enew !
put = range ( 4 , 10 )
1 d _
vnew
put = range ( 1 , 10 )
1 d _
windo diffthis
wincmd h
call assert_equal ( 1 , line ( 'w0' ) )
unlet ! diff_fdm diff_fdc
2016-07-30 19:11:25 +02:00
windo diffoff
bwipe !
enew !
endfunc
2016-07-30 16:16:54 +02:00
2016-07-30 19:11:25 +02:00
func Test_diffget_diffput ( )
enew !
let l = range ( 50 )
call setline ( 1 , l )
call assert_fails ( 'diffget' , 'E99:' )
diffthis
call assert_fails ( 'diffget' , 'E100:' )
new
let l [10 ] = 'one'
let l [20 ] = 'two'
let l [30 ] = 'three'
let l [40 ] = 'four'
call setline ( 1 , l )
diffthis
call assert_equal ( 'one' , getline ( 11 ) )
11 diffget
call assert_equal ( '10' , getline ( 11 ) )
21 diffput
wincmd w
call assert_equal ( 'two' , getline ( 21 ) )
normal 31 Gdo
call assert_equal ( 'three' , getline ( 31 ) )
call assert_equal ( '40' , getline ( 41 ) )
normal 41 Gdp
wincmd w
call assert_equal ( '40' , getline ( 41 ) )
new
diffthis
call assert_fails ( 'diffget' , 'E101:' )
windo diffoff
2017-05-16 13:15:18 +02:00
%bwipe !
endfunc
2018-10-25 17:52:23 +02:00
" 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 ) )
8 del
5 del
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
2021-06-10 21:52:15 +02:00
" Test for :diffget/:diffput with a range that is inside a diff chunk
func Test_diffget_diffput_range ( )
call setline ( 1 , range ( 1 , 10 ) )
new
call setline ( 1 , range ( 11 , 20 ) )
windo diffthis
3 , 5 diffget
call assert_equal ( ['13' , '14' , '15' ], getline ( 3 , 5 ) )
call setline ( 1 , range ( 1 , 10 ) )
4 , 8 diffput
wincmd p
call assert_equal ( ['13' , '4' , '5' , '6' , '7' , '8' , '19' ], getline ( 3 , 9 ) )
%bw !
endfunc
" Test for :diffget/:diffput with an empty buffer and a non-empty buffer
func Test_diffget_diffput_empty_buffer ( )
%d _
new
call setline ( 1 , 'one' )
windo diffthis
diffget
call assert_equal ( ['one' ], getline ( 1 , '$' ) )
%d _
diffput
wincmd p
call assert_equal ( ['' ], getline ( 1 , '$' ) )
%bw !
endfunc
2019-12-30 21:59:03 +01:00
" :diffput and :diffget completes names of buffers which
2021-11-21 11:36:04 +00:00
" are in diff mode and which are different than current buffer.
2019-12-30 21:59:03 +01:00
" No completion when the current window is not in diff mode.
2019-12-29 13:56:33 +01:00
func Test_diffget_diffput_completion ( )
2019-12-30 21:59:03 +01:00
e Xdiff1 | diffthis
botright new Xdiff2
botright new Xdiff3 | split | diffthis
botright new Xdiff4 | diffthis
2019-12-29 13:56:33 +01:00
2019-12-30 21:59:03 +01:00
wincmd t
call assert_equal ( 'Xdiff1' , bufname ( '%' ) )
2019-12-29 13:56:33 +01:00
call feedkeys ( ":diffput \<C-A>\<C-B>\"\<CR>" , 'tx' )
2019-12-30 21:59:03 +01:00
call assert_equal ( '"diffput Xdiff3 Xdiff4' , @:)
2019-12-29 13:56:33 +01:00
call feedkeys ( ":diffget \<C-A>\<C-B>\"\<CR>" , 'tx' )
2019-12-30 21:59:03 +01:00
call assert_equal ( '"diffget Xdiff3 Xdiff4' , @:)
call assert_equal ( ['Xdiff3' , 'Xdiff4' ], getcompletion ( '' , 'diff_buffer' ) )
2019-12-29 13:56:33 +01:00
2019-12-30 21:59:03 +01:00
" Xdiff2 is not in diff mode, so no completion for :diffput, :diffget
wincmd j
call assert_equal ( 'Xdiff2' , bufname ( '%' ) )
2019-12-29 13:56:33 +01:00
call feedkeys ( ":diffput \<C-A>\<C-B>\"\<CR>" , 'tx' )
2019-12-30 21:59:03 +01:00
call assert_equal ( '"diffput ' , @:)
2019-12-29 13:56:33 +01:00
call feedkeys ( ":diffget \<C-A>\<C-B>\"\<CR>" , 'tx' )
2019-12-30 21:59:03 +01:00
call assert_equal ( '"diffget ' , @:)
call assert_equal ( [], getcompletion ( '' , 'diff_buffer' ) )
2019-12-29 13:56:33 +01:00
2019-12-30 21:59:03 +01:00
" Xdiff3 is split in 2 windows, only the top one is in diff mode.
" So completion of :diffput :diffget only happens in the top window.
wincmd j
call assert_equal ( 'Xdiff3' , bufname ( '%' ) )
call assert_equal ( 1 , &diff )
2019-12-29 13:56:33 +01:00
call feedkeys ( ":diffput \<C-A>\<C-B>\"\<CR>" , 'tx' )
2019-12-30 21:59:03 +01:00
call assert_equal ( '"diffput Xdiff1 Xdiff4' , @:)
2019-12-29 13:56:33 +01:00
call feedkeys ( ":diffget \<C-A>\<C-B>\"\<CR>" , 'tx' )
2019-12-30 21:59:03 +01:00
call assert_equal ( '"diffget Xdiff1 Xdiff4' , @:)
call assert_equal ( ['Xdiff1' , 'Xdiff4' ], getcompletion ( '' , 'diff_buffer' ) )
2019-12-29 13:56:33 +01:00
2019-12-30 21:59:03 +01:00
wincmd j
call assert_equal ( 'Xdiff3' , bufname ( '%' ) )
call assert_equal ( 0 , &diff )
2019-12-29 13:56:33 +01:00
call feedkeys ( ":diffput \<C-A>\<C-B>\"\<CR>" , 'tx' )
call assert_equal ( '"diffput ' , @:)
call feedkeys ( ":diffget \<C-A>\<C-B>\"\<CR>" , 'tx' )
call assert_equal ( '"diffget ' , @:)
call assert_equal ( [], getcompletion ( '' , 'diff_buffer' ) )
2019-12-30 21:59:03 +01:00
wincmd j
call assert_equal ( 'Xdiff4' , bufname ( '%' ) )
call feedkeys ( ":diffput \<C-A>\<C-B>\"\<CR>" , 'tx' )
call assert_equal ( '"diffput Xdiff1 Xdiff3' , @:)
call feedkeys ( ":diffget \<C-A>\<C-B>\"\<CR>" , 'tx' )
call assert_equal ( '"diffget Xdiff1 Xdiff3' , @:)
call assert_equal ( ['Xdiff1' , 'Xdiff3' ], getcompletion ( '' , 'diff_buffer' ) )
2019-12-29 13:56:33 +01:00
%bwipe
endfunc
2017-05-16 13:15:18 +02:00
func Test_dp_do_buffer ( )
e ! one
let bn1 = bufnr ( '%' )
let l = range ( 60 )
call setline ( 1 , l )
diffthis
new two
let l [10 ] = 'one'
let l [20 ] = 'two'
let l [30 ] = 'three'
let l [40 ] = 'four'
let l [50 ] = 'five'
call setline ( 1 , l )
diffthis
" dp and do with invalid buffer number.
11
call assert_fails ( 'norm 99999dp' , 'E102:' )
call assert_fails ( 'norm 99999do' , 'E102:' )
call assert_fails ( 'diffput non_existing_buffer' , 'E94:' )
call assert_fails ( 'diffget non_existing_buffer' , 'E94:' )
" dp and do with valid buffer number.
call assert_equal ( 'one' , getline ( '.' ) )
exe 'norm ' . bn1 . 'do'
call assert_equal ( '10' , getline ( '.' ) )
21
call assert_equal ( 'two' , getline ( '.' ) )
2023-01-28 19:19:03 +00:00
diffget one
2017-05-16 13:15:18 +02:00
call assert_equal ( '20' , getline ( '.' ) )
31
exe 'norm ' . bn1 . 'dp'
41
diffput one
wincmd w
31
call assert_equal ( 'three' , getline ( '.' ) )
41
call assert_equal ( 'four' , getline ( '.' ) )
" dp and do with buffer number which is not in diff mode.
new not_in_diff_mode
let bn3 = bufnr ( '%' )
wincmd w
51
call assert_fails ( 'exe "norm" . bn3 . "dp"' , 'E103:' )
call assert_fails ( 'exe "norm" . bn3 . "do"' , 'E103:' )
call assert_fails ( 'diffput not_in_diff_mode' , 'E94:' )
call assert_fails ( 'diffget not_in_diff_mode' , 'E94:' )
windo diffoff
%bwipe !
2016-07-30 16:16:54 +02:00
endfunc
2016-08-27 22:40:42 +02:00
2018-10-07 17:46:42 +02:00
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
2016-08-27 22:40:42 +02:00
func Test_diffoff ( )
enew !
call setline ( 1 , ['Two' , 'Three' ])
2017-05-16 13:15:18 +02:00
redraw
2016-08-27 22:40:42 +02:00
let normattr = screenattr ( 1 , 1 )
diffthis
botright vert new
call setline ( 1 , ['One' , '' , 'Two' , 'Three' ])
diffthis
redraw
2019-09-06 21:34:30 +02:00
call assert_notequal ( normattr , 1 - > screenattr ( 1 ) )
2016-08-27 22:40:42 +02:00
diffoff !
redraw
call assert_equal ( normattr , screenattr ( 1 , 1 ) )
bwipe !
bwipe !
endfunc
2016-10-18 14:50:18 +02:00
2018-09-10 17:51:58 +02:00
func Common_icase_test ( )
edit one
2017-09-02 18:01:50 +02:00
call setline ( 1 , ['One' , 'Two' , 'Three' , 'Four' , 'Fi#ve' ])
2017-05-16 13:15:18 +02:00
redraw
let normattr = screenattr ( 1 , 1 )
diffthis
botright vert new two
2017-09-02 18:01:50 +02:00
call setline ( 1 , ['one' , 'TWO' , 'Three ' , 'Four' , 'fI=VE' ])
2017-05-16 13:15:18 +02:00
diffthis
redraw
call assert_equal ( normattr , screenattr ( 1 , 1 ) )
call assert_equal ( normattr , screenattr ( 2 , 1 ) )
call assert_notequal ( normattr , screenattr ( 3 , 1 ) )
call assert_equal ( normattr , screenattr ( 4 , 1 ) )
2017-09-02 18:01:50 +02:00
let dtextattr = screenattr ( 5 , 3 )
call assert_notequal ( dtextattr , screenattr ( 5 , 1 ) )
call assert_notequal ( dtextattr , screenattr ( 5 , 5 ) )
2017-05-16 13:15:18 +02:00
diffoff !
%bwipe !
2018-09-10 17:51:58 +02:00
endfunc
func Test_diffopt_icase ( )
set diffopt = icase , foldcolumn :0
call Common_icase_test ( )
2017-05-16 13:15:18 +02:00
set diffopt &
endfunc
2018-09-10 17:51:58 +02:00
func Test_diffopt_icase_internal ( )
set diffopt = icase , foldcolumn :0 , internal
call Common_icase_test ( )
set diffopt &
endfunc
2017-05-16 13:15:18 +02:00
2018-09-10 17:51:58 +02:00
func Common_iwhite_test ( )
edit one
" Difference in trailing spaces and amount of spaces should be ignored,
2017-05-16 13:15:18 +02:00
" but not other space differences.
2018-09-10 17:51:58 +02:00
call setline ( 1 , ["One \t" , 'Two' , 'Three' , 'one two' , 'one two' , 'Four' ])
2017-05-16 13:15:18 +02:00
redraw
let normattr = screenattr ( 1 , 1 )
diffthis
botright vert new two
2018-09-10 17:51:58 +02:00
call setline ( 1 , ["One\t " , "Two\t " , 'Three' , 'one two' , 'onetwo' , ' Four' ])
2017-05-16 13:15:18 +02:00
diffthis
redraw
call assert_equal ( normattr , screenattr ( 1 , 1 ) )
call assert_equal ( normattr , screenattr ( 2 , 1 ) )
call assert_equal ( normattr , screenattr ( 3 , 1 ) )
2018-09-10 17:51:58 +02:00
call assert_equal ( normattr , screenattr ( 4 , 1 ) )
call assert_notequal ( normattr , screenattr ( 5 , 1 ) )
call assert_notequal ( normattr , screenattr ( 6 , 1 ) )
2017-05-16 13:15:18 +02:00
diffoff !
%bwipe !
2018-09-10 17:51:58 +02:00
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 ( )
2017-05-16 13:15:18 +02:00
set diffopt &
endfunc
func Test_diffopt_context ( )
enew !
call setline ( 1 , ['1' , '2' , '3' , '4' , '5' , '6' , '7' ])
diffthis
new
call setline ( 1 , ['1' , '2' , '3' , '4' , '5x' , '6' , '7' ])
diffthis
set diffopt = context :2
call assert_equal ( '+-- 2 lines: 1' , foldtextresult ( 1 ) )
2018-09-10 17:51:58 +02:00
set diffopt = internal , context :2
call assert_equal ( '+-- 2 lines: 1' , foldtextresult ( 1 ) )
2017-05-16 13:15:18 +02:00
set diffopt = context :1
call assert_equal ( '+-- 3 lines: 1' , foldtextresult ( 1 ) )
2018-09-10 17:51:58 +02:00
set diffopt = internal , context :1
call assert_equal ( '+-- 3 lines: 1' , foldtextresult ( 1 ) )
2017-05-16 13:15:18 +02:00
diffoff !
%bwipe !
set diffopt &
endfunc
func Test_diffopt_horizontal ( )
2018-09-10 17:51:58 +02:00
set diffopt = internal , horizontal
2017-05-16 13:15:18 +02:00
diffsplit
call assert_equal ( &columns , winwidth ( 1 ) )
call assert_equal ( &columns , winwidth ( 2 ) )
call assert_equal ( &lines , winheight ( 1 ) + winheight ( 2 ) + 3 )
call assert_inrange ( 0 , 1 , winheight ( 1 ) - winheight ( 2 ) )
set diffopt &
diffoff !
%bwipe
endfunc
func Test_diffopt_vertical ( )
2018-09-10 17:51:58 +02:00
set diffopt = internal , vertical
2017-05-16 13:15:18 +02:00
diffsplit
call assert_equal ( &lines - 2 , winheight ( 1 ) )
call assert_equal ( &lines - 2 , winheight ( 2 ) )
call assert_equal ( &columns , winwidth ( 1 ) + winwidth ( 2 ) + 1 )
call assert_inrange ( 0 , 1 , winwidth ( 1 ) - winwidth ( 2 ) )
set diffopt &
diffoff !
%bwipe
endfunc
2017-12-01 20:35:58 +01:00
func Test_diffopt_hiddenoff ( )
2018-09-10 17:51:58 +02:00
set diffopt = internal , filler , foldcolumn :0 , hiddenoff
2017-12-01 20:35:58 +01:00
e ! one
call setline ( 1 , ['Two' , 'Three' ])
redraw
let normattr = screenattr ( 1 , 1 )
diffthis
botright vert new two
call setline ( 1 , ['One' , 'Four' ])
diffthis
redraw
call assert_notequal ( normattr , screenattr ( 1 , 1 ) )
set hidden
close
redraw
" should not diffing with hidden buffer two while 'hiddenoff' is enabled
call assert_equal ( normattr , screenattr ( 1 , 1 ) )
bwipe !
bwipe !
set hidden & diffopt &
endfunc
2017-02-03 23:16:28 +01:00
func Test_diffoff_hidden ( )
2018-09-10 17:51:58 +02:00
set diffopt = internal , filler , foldcolumn :0
2017-02-03 23:16:28 +01:00
e ! one
call setline ( 1 , ['Two' , 'Three' ])
2017-05-16 13:15:18 +02:00
redraw
2017-02-03 23:16:28 +01:00
let normattr = screenattr ( 1 , 1 )
diffthis
botright vert new two
call setline ( 1 , ['One' , 'Four' ])
diffthis
redraw
call assert_notequal ( normattr , screenattr ( 1 , 1 ) )
set hidden
close
redraw
" diffing with hidden buffer two
call assert_notequal ( normattr , screenattr ( 1 , 1 ) )
diffoff
redraw
call assert_equal ( normattr , screenattr ( 1 , 1 ) )
diffthis
redraw
" still diffing with hidden buffer two
call assert_notequal ( normattr , screenattr ( 1 , 1 ) )
diffoff !
redraw
call assert_equal ( normattr , screenattr ( 1 , 1 ) )
diffthis
redraw
" no longer diffing with hidden buffer two
call assert_equal ( normattr , screenattr ( 1 , 1 ) )
bwipe !
bwipe !
set hidden & diffopt &
endfunc
2016-10-18 14:50:18 +02:00
func Test_setting_cursor ( )
new Xtest1
put = range ( 1 , 90 )
wq
new Xtest2
put = range ( 1 , 100 )
wq
2017-09-26 19:41:46 +02:00
2016-10-18 14:50:18 +02:00
tabe Xtest2
$
diffsp Xtest1
tabclose
call delete ( 'Xtest1' )
call delete ( 'Xtest2' )
endfunc
2017-02-26 19:59:59 +01:00
func Test_diff_move_to ( )
new
call setline ( 1 , [1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 , 10 ])
diffthis
vnew
call setline ( 1 , [1 , '2x' , 3 , 4 , 4 , 5 , '6x' , 7 , '8x' , 9 , '10x' ])
diffthis
norm ]c
call assert_equal ( 2 , line ( '.' ) )
norm 3 ]c
call assert_equal ( 9 , line ( '.' ) )
norm 10 ]c
call assert_equal ( 11 , line ( '.' ) )
norm [c
call assert_equal ( 9 , line ( '.' ) )
norm 2 [c
call assert_equal ( 5 , line ( '.' ) )
norm 10 [c
call assert_equal ( 2 , line ( '.' ) )
%bwipe !
endfunc
2017-05-16 13:15:18 +02:00
func Test_diffexpr ( )
2020-11-27 19:13:28 +01:00
CheckExecutable diff
2017-05-16 13:15:18 +02:00
func DiffExpr ( )
2021-05-18 19:19:03 +02:00
" Prepend some text to check diff type detection
2018-09-13 13:03:11 +02:00
call writefile ( ['warning' , ' message' ], v :fname_out )
silent exe '!diff ' . v :fname_in . ' ' . v :fname_new . '>>' . v :fname_out
2017-05-16 13:15:18 +02:00
endfunc
set diffexpr = DiffExpr ( )
set diffopt = foldcolumn :0
enew !
call setline ( 1 , ['one' , 'two' , 'three' ])
redraw
let normattr = screenattr ( 1 , 1 )
diffthis
botright vert new
call setline ( 1 , ['one' , 'two' , 'three.' ])
diffthis
redraw
call assert_equal ( normattr , screenattr ( 1 , 1 ) )
call assert_equal ( normattr , screenattr ( 2 , 1 ) )
call assert_notequal ( normattr , screenattr ( 3 , 1 ) )
2021-06-10 21:52:15 +02:00
diffoff !
2017-05-16 13:15:18 +02:00
2021-11-21 11:36:04 +00:00
" Try using a non-existing function for 'diffexpr'.
2021-06-10 21:52:15 +02:00
set diffexpr = NewDiffFunc ( )
call assert_fails ( 'windo diffthis' , ['E117:' , 'E97:' ])
2017-05-16 13:15:18 +02:00
diffoff !
2021-12-26 10:51:39 +00:00
" Using a script-local function
func s :NewDiffExpr ( )
endfunc
set diffexpr = s :NewDiffExpr ( )
call assert_equal ( expand ( '<SID>' ) .. 'NewDiffExpr()' , &diffexpr )
set diffexpr = < SID > NewDiffExpr ( )
call assert_equal ( expand ( '<SID>' ) .. 'NewDiffExpr()' , &diffexpr )
2017-05-16 13:15:18 +02:00
%bwipe !
set diffexpr & diffopt &
2021-12-26 10:51:39 +00:00
delfunc DiffExpr
delfunc s :NewDiffExpr
2017-05-16 13:15:18 +02:00
endfunc
2017-02-26 19:59:59 +01:00
func Test_diffpatch ( )
" The patch program on MS-Windows may fail or hang.
2020-08-12 18:50:36 +02:00
CheckExecutable patch
CheckUnix
2017-02-26 19:59:59 +01:00
new
insert
***************
*** 1 , 3 ****
1
! 2
3
- - - 1 , 4 - - - -
1
! 2 x
3
+ 4
.
2017-09-26 19:41:46 +02:00
saveas ! Xpatch
2017-02-26 19:59:59 +01:00
bwipe !
new
call assert_fails ( 'diffpatch Xpatch' , 'E816:' )
2017-03-09 19:21:30 +01:00
2017-03-11 19:21:53 +01:00
for name in ['Xpatch' , 'Xpatch$HOME' , 'Xpa''tch' ]
2017-03-09 19:21:30 +01:00
call setline ( 1 , ['1' , '2' , '3' ])
if name ! = 'Xpatch'
call rename ( 'Xpatch' , name )
endif
exe 'diffpatch ' . escape ( name , '$' )
call assert_equal ( ['1' , '2x' , '3' , '4' ], getline ( 1 , '$' ) )
if name ! = 'Xpatch'
call rename ( name , 'Xpatch' )
endif
bwipe !
endfor
2017-02-26 19:59:59 +01:00
call delete ( 'Xpatch' )
bwipe !
endfunc
2023-04-04 22:04:53 +01:00
" FIXME: test fails, the Xresult file can't be read
func No_Test_diffpatch_restricted ( )
let lines = < < trim END
call assert_fails ( 'diffpatch NoSuchDiff' , 'E145:' )
call writefile ( v :errors , 'Xresult' )
qa !
END
call writefile ( lines , 'Xrestricted' , 'D' )
if RunVim ( [], [], '-Z --clean -S Xrestricted' )
call assert_equal ( [], readfile ( 'Xresult' ) )
endif
call delete ( 'Xresult' )
endfunc
2017-02-26 19:59:59 +01:00
func Test_diff_too_many_buffers ( )
for i in range ( 1 , 8 )
exe "new Xtest" . i
diffthis
endfor
new Xtest9
call assert_fails ( 'diffthis' , 'E96:' )
%bwipe !
endfunc
func Test_diff_nomodifiable ( )
new
call setline ( 1 , [1 , 2 , 3 , 4 ])
setl nomodifiable
diffthis
vnew
call setline ( 1 , ['1x' , 2 , 3 , 3 , 4 ])
diffthis
call assert_fails ( 'norm dp' , 'E793:' )
setl nomodifiable
call assert_fails ( 'norm do' , 'E21:' )
%bwipe !
endfunc
2017-03-05 18:03:04 +01:00
2017-09-26 19:41:46 +02:00
func Test_diff_hlID ( )
new
call setline ( 1 , [1 , 2 , 3 ])
diffthis
vnew
call setline ( 1 , ['1x' , 2 , 'x' , 3 ])
diffthis
redraw
2019-08-04 17:35:53 +02:00
call diff_hlID ( -1 , 1 ) - > synIDattr ( "name" ) - > assert_equal ( "" )
2017-09-26 19:41:46 +02:00
2019-08-04 17:35:53 +02:00
call diff_hlID ( 1 , 1 ) - > synIDattr ( "name" ) - > assert_equal ( "DiffChange" )
call diff_hlID ( 1 , 2 ) - > synIDattr ( "name" ) - > assert_equal ( "DiffText" )
call diff_hlID ( 2 , 1 ) - > synIDattr ( "name" ) - > assert_equal ( "" )
call diff_hlID ( 3 , 1 ) - > synIDattr ( "name" ) - > assert_equal ( "DiffAdd" )
2019-08-23 22:31:37 +02:00
eval 4 - > diff_hlID ( 1 ) - > synIDattr ( "name" ) - > assert_equal ( "" )
2017-09-26 19:41:46 +02:00
wincmd w
call assert_equal ( synIDattr ( diff_hlID ( 1 , 1 ) , "name" ) , "DiffChange" )
call assert_equal ( synIDattr ( diff_hlID ( 2 , 1 ) , "name" ) , "" )
call assert_equal ( synIDattr ( diff_hlID ( 3 , 1 ) , "name" ) , "" )
%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
2019-08-23 22:31:37 +02:00
call assert_equal ( [0 , 0 , 0 , 0 , 0 , 0 , 0 , 1 , 0 ], map ( range ( -1 , 7 ) , 'v:val->diff_filler()' ) )
2017-09-26 19:41:46 +02:00
wincmd w
call assert_equal ( [0 , 0 , 0 , 0 , 2 , 0 , 0 , 0 ], map ( range ( -1 , 6 ) , 'diff_filler(v:val)' ) )
%bwipe !
endfunc
2017-03-05 18:03:04 +01:00
func Test_diff_lastline ( )
enew !
only !
call setline ( 1 , ['This is a ' , 'line with five ' , 'rows' ])
diffthis
botright vert new
call setline ( 1 , ['This is' , 'a line with ' , 'four rows' ])
diffthis
1
call feedkeys ( "Je a\<CR>" , 'tx' )
call feedkeys ( "Je a\<CR>" , 'tx' )
let w1lines = winline ( )
wincmd w
$
let w2lines = winline ( )
call assert_equal ( w2lines , w1lines )
bwipe !
bwipe !
endfunc
2018-09-10 17:51:58 +02:00
2018-09-15 19:17:38 +02:00
func WriteDiffFiles ( buf , list1 , list2 )
2022-08-30 21:46:08 +01:00
call writefile ( a :list1 , 'Xdifile1' )
call writefile ( a :list2 , 'Xdifile2' )
2018-09-15 19:17:38 +02:00
if a :buf
call term_sendkeys ( a :buf , ":checktime\<CR>" )
endif
2018-09-10 17:51:58 +02:00
endfunc
2024-09-26 16:19:42 +02:00
func WriteDiffFiles3 ( buf , list1 , list2 , list3 )
call writefile ( a :list1 , 'Xdifile1' )
call writefile ( a :list2 , 'Xdifile2' )
call writefile ( a :list3 , 'Xdifile3' )
if a :buf
call term_sendkeys ( a :buf , ":checktime\<CR>" )
endif
endfunc
2018-09-15 19:17:38 +02:00
" Verify a screendump with both the internal and external diff.
2018-09-10 17:51:58 +02:00
func VerifyBoth ( buf , dumpfile , extra )
" trailing : for leaving the cursor on the command line
2018-09-15 19:17:38 +02:00
for cmd in [":set diffopt=filler" . a :extra . "\<CR>:" , ":set diffopt+=internal\<CR>:" ]
2018-09-10 17:51:58 +02:00
call term_sendkeys ( a :buf , cmd )
if VerifyScreenDump ( a :buf , a :dumpfile , {}, cmd = ~ 'internal' ? 'internal' : 'external' )
2021-05-18 19:19:03 +02:00
" don't let the next iteration overwrite the "failed" file.
return
2018-09-10 17:51:58 +02:00
endif
endfor
2021-05-18 19:19:03 +02:00
" also test unified diff
call term_sendkeys ( a :buf , ":call SetupUnified()\<CR>:" )
2021-05-24 14:20:53 +02:00
call term_sendkeys ( a :buf , ":redraw!\<CR>:" )
2021-05-18 19:19:03 +02:00
call VerifyScreenDump ( a :buf , a :dumpfile , {}, 'unified' )
call term_sendkeys ( a :buf , ":call StopUnified()\<CR>:" )
2018-09-10 17:51:58 +02:00
endfunc
2018-09-15 19:17:38 +02:00
" Verify a screendump with the internal diff only.
func VerifyInternal ( buf , dumpfile , extra )
call term_sendkeys ( a :buf , ":diffupdate!\<CR>" )
" trailing : for leaving the cursor on the command line
call term_sendkeys ( a :buf , ":set diffopt=internal,filler" . a :extra . "\<CR>:" )
call VerifyScreenDump ( a :buf , a :dumpfile , {})
endfunc
2018-09-10 17:51:58 +02:00
func Test_diff_screen ( )
2024-02-14 20:34:58 +01:00
if has ( 'osxdarwin' ) && system ( 'diff --version' ) = ~ '^Apple diff'
throw 'Skipped: unified diff does not work properly on this macOS version'
2024-02-01 21:22:14 +01:00
endif
2021-10-16 13:00:14 +01:00
let g :test_is_flaky = 1
2019-08-03 22:55:50 +02:00
CheckScreendump
CheckFeature menu
2021-05-18 19:19:03 +02:00
let lines = < < trim END
func UnifiedDiffExpr ( )
" Prepend some text to check diff type detection
call writefile ( ['warning' , ' message' ], v :fname_out )
2021-05-24 14:20:53 +02:00
silent exe '!diff -U0 ' .. v :fname_in .. ' ' .. v :fname_new .. '>>' .. v :fname_out
2021-05-18 19:19:03 +02:00
endfunc
func SetupUnified ( )
set diffexpr = UnifiedDiffExpr ( )
2021-05-24 14:20:53 +02:00
diffupdate
2021-05-18 19:19:03 +02:00
endfunc
func StopUnified ( )
set diffexpr =
endfunc
END
2022-09-20 22:01:33 +01:00
call writefile ( lines , 'XdiffSetup' , 'D' )
2021-05-18 19:19:03 +02:00
2018-09-10 17:51:58 +02:00
" clean up already existing swap files, just in case
2022-08-30 21:46:08 +01:00
call delete ( '.Xdifile1.swp' )
call delete ( '.Xdifile2.swp' )
2018-09-10 17:51:58 +02:00
" Test 1: Add a line in beginning of file 2
2018-09-15 19:17:38 +02:00
call WriteDiffFiles ( 0 , [1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 , 10 ], [0 , 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 , 10 ])
2022-08-30 21:46:08 +01:00
let buf = RunVimInTerminal ( '-d -S XdiffSetup Xdifile1 Xdifile2' , {})
2019-03-29 18:08:18 +01:00
" Set autoread mode, so that Vim won't complain once we re-write the test
2018-09-10 17:51:58 +02:00
" files
2018-09-15 19:17:38 +02:00
call term_sendkeys ( buf , ":set autoread\<CR>\<c-w>w:set autoread\<CR>\<c-w>w" )
2018-09-10 17:51:58 +02:00
call VerifyBoth ( buf , 'Test_diff_01' , '' )
" Test 2: Add a line in beginning of file 1
2018-09-15 19:17:38 +02:00
call WriteDiffFiles ( buf , [0 , 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 , 10 ], [1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 , 10 ])
2018-09-10 17:51:58 +02:00
call VerifyBoth ( buf , 'Test_diff_02' , '' )
" Test 3: Add a line at the end of file 2
2018-09-15 19:17:38 +02:00
call WriteDiffFiles ( buf , [1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 , 10 ], [1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 , 10 , 11 ])
2018-09-10 17:51:58 +02:00
call VerifyBoth ( buf , 'Test_diff_03' , '' )
" Test 4: Add a line at the end of file 1
2018-09-15 19:17:38 +02:00
call WriteDiffFiles ( buf , [1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 , 10 , 11 ], [1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 , 10 ])
2018-09-10 17:51:58 +02:00
call VerifyBoth ( buf , 'Test_diff_04' , '' )
" Test 5: Add a line in the middle of file 2, remove on at the end of file 1
2018-09-15 19:17:38 +02:00
call WriteDiffFiles ( buf , [1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 , 10 , 11 ], [1 , 2 , 3 , 4 , 4 , 5 , 6 , 7 , 8 , 9 , 10 ])
2018-09-10 17:51:58 +02:00
call VerifyBoth ( buf , 'Test_diff_05' , '' )
" Test 6: Add a line in the middle of file 1, remove on at the end of file 2
2018-09-15 19:17:38 +02:00
call WriteDiffFiles ( buf , [1 , 2 , 3 , 4 , 4 , 5 , 6 , 7 , 8 , 9 , 10 ], [1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 , 10 , 11 ])
2018-09-10 17:51:58 +02:00
call VerifyBoth ( buf , 'Test_diff_06' , '' )
2019-02-19 23:00:50 +01:00
" Variants on test 6 with different context settings
call term_sendkeys ( buf , ":set diffopt+=context:2\<cr>" )
call VerifyScreenDump ( buf , 'Test_diff_06.2' , {})
call term_sendkeys ( buf , ":set diffopt-=context:2\<cr>" )
call term_sendkeys ( buf , ":set diffopt+=context:1\<cr>" )
call VerifyScreenDump ( buf , 'Test_diff_06.1' , {})
call term_sendkeys ( buf , ":set diffopt-=context:1\<cr>" )
call term_sendkeys ( buf , ":set diffopt+=context:0\<cr>" )
call VerifyScreenDump ( buf , 'Test_diff_06.0' , {})
call term_sendkeys ( buf , ":set diffopt-=context:0\<cr>" )
2018-09-10 17:51:58 +02:00
" Test 7 - 9: Test normal/patience/histogram diff algorithm
2018-09-15 19:17:38 +02:00
call WriteDiffFiles ( buf , ['#include <stdio.h>' , '' , '// Frobs foo heartily' , 'int frobnitz(int foo)' , '{' ,
2018-09-10 17:51:58 +02:00
\ ' int i;' , ' for(i = 0; i < 10; i++)' , ' {' , ' printf("Your answer is: ");' ,
\ ' printf("%d\n", foo);' , ' }' , '}' , '' , 'int fact(int n)' , '{' , ' if(n > 1)' , ' {' ,
\ ' return fact(n-1) * n;' , ' }' , ' return 1;' , '}' , '' , 'int main(int argc, char **argv)' ,
\ '{' , ' frobnitz(fact(10));' , '}' ],
\ ['#include <stdio.h>' , '' , 'int fib(int n)' , '{' , ' if(n > 2)' , ' {' ,
\ ' return fib(n-1) + fib(n-2);' , ' }' , ' return 1;' , '}' , '' , '// Frobs foo heartily' ,
\ 'int frobnitz(int foo)' , '{' , ' int i;' , ' for(i = 0; i < 10; i++)' , ' {' ,
\ ' printf("%d\n", foo);' , ' }' , '}' , '' ,
\ 'int main(int argc, char **argv)' , '{' , ' frobnitz(fib(10));' , '}' ])
call term_sendkeys ( buf , ":diffupdate!\<cr>" )
call term_sendkeys ( buf , ":set diffopt+=internal\<cr>" )
call VerifyScreenDump ( buf , 'Test_diff_07' , {})
call term_sendkeys ( buf , ":set diffopt+=algorithm:patience\<cr>" )
call VerifyScreenDump ( buf , 'Test_diff_08' , {})
call term_sendkeys ( buf , ":set diffopt+=algorithm:histogram\<cr>" )
call VerifyScreenDump ( buf , 'Test_diff_09' , {})
" Test 10-11: normal/indent-heuristic
call term_sendkeys ( buf , ":set diffopt&vim\<cr>" )
2018-09-15 19:17:38 +02:00
call WriteDiffFiles ( buf , ['' , ' def finalize(values)' , '' , ' values.each do |v|' , ' v.finalize' , ' end' ],
2018-09-10 17:51:58 +02:00
\ ['' , ' def finalize(values)' , '' , ' values.each do |v|' , ' v.prepare' , ' end' , '' ,
\ ' values.each do |v|' , ' v.finalize' , ' end' ])
call term_sendkeys ( buf , ":diffupdate!\<cr>" )
call term_sendkeys ( buf , ":set diffopt+=internal\<cr>" )
call VerifyScreenDump ( buf , 'Test_diff_10' , {})
2018-12-04 22:24:16 +01:00
" Leave trailing : at commandline!
call term_sendkeys ( buf , ":set diffopt+=indent-heuristic\<cr>:\<cr>" )
call VerifyScreenDump ( buf , 'Test_diff_11' , {}, 'one' )
" shouldn't matter, if indent-algorithm comes before or after the algorithm
call term_sendkeys ( buf , ":set diffopt&\<cr>" )
call term_sendkeys ( buf , ":set diffopt+=indent-heuristic,algorithm:patience\<cr>:\<cr>" )
call VerifyScreenDump ( buf , 'Test_diff_11' , {}, 'two' )
call term_sendkeys ( buf , ":set diffopt&\<cr>" )
call term_sendkeys ( buf , ":set diffopt+=algorithm:patience,indent-heuristic\<cr>:\<cr>" )
call VerifyScreenDump ( buf , 'Test_diff_11' , {}, 'three' )
2018-09-10 17:51:58 +02:00
" Test 12: diff the same file
2018-09-15 19:17:38 +02:00
call WriteDiffFiles ( buf , [1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 , 10 ], [1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 , 10 ])
2018-09-10 17:51:58 +02:00
call VerifyBoth ( buf , 'Test_diff_12' , '' )
" Test 13: diff an empty file
2018-09-15 19:17:38 +02:00
call WriteDiffFiles ( buf , [], [])
2018-09-10 17:51:58 +02:00
call VerifyBoth ( buf , 'Test_diff_13' , '' )
" Test 14: test diffopt+=icase
2018-09-15 19:17:38 +02:00
call WriteDiffFiles ( buf , ['a' , 'b' , 'cd' ], ['A' , 'b' , 'cDe' ])
2018-09-10 17:51:58 +02:00
call VerifyBoth ( buf , 'Test_diff_14' , " diffopt+=filler diffopt+=icase" )
" Test 15-16: test diffopt+=iwhite
2018-09-15 19:17:38 +02:00
call WriteDiffFiles ( buf , ['int main()' , '{' , ' printf("Hello, World!");' , ' return 0;' , '}' ],
2018-09-10 17:51:58 +02:00
\ ['int main()' , '{' , ' if (0)' , ' {' , ' printf("Hello, World!");' , ' return 0;' , ' }' , '}' ])
call term_sendkeys ( buf , ":diffupdate!\<cr>" )
call term_sendkeys ( buf , ":set diffopt&vim diffopt+=filler diffopt+=iwhite\<cr>" )
call VerifyScreenDump ( buf , 'Test_diff_15' , {})
call term_sendkeys ( buf , ":set diffopt+=internal\<cr>" )
call VerifyScreenDump ( buf , 'Test_diff_16' , {})
2018-09-15 19:17:38 +02:00
" Test 17: test diffopt+=iblank
call WriteDiffFiles ( buf , ['a' , ' ' , 'cd' , 'ef' , 'xxx' ], ['a' , 'cd' , '' , 'ef' , 'yyy' ])
call VerifyInternal ( buf , 'Test_diff_17' , " diffopt+=iblank" )
" Test 18: test diffopt+=iblank,iwhite / iwhiteall / iwhiteeol
call VerifyInternal ( buf , 'Test_diff_18' , " diffopt+=iblank,iwhite" )
call VerifyInternal ( buf , 'Test_diff_18' , " diffopt+=iblank,iwhiteall" )
call VerifyInternal ( buf , 'Test_diff_18' , " diffopt+=iblank,iwhiteeol" )
" Test 19: test diffopt+=iwhiteeol
call WriteDiffFiles ( buf , ['a ' , 'x' , 'cd' , 'ef' , 'xx xx' , 'foo' , 'bar' ], ['a' , 'x' , 'c d' , ' ef' , 'xx xx' , 'foo' , '' , 'bar' ])
call VerifyInternal ( buf , 'Test_diff_19' , " diffopt+=iwhiteeol" )
2024-09-22 11:26:13 +02:00
" Test 20: test diffopt+=iwhiteall
2018-09-15 19:17:38 +02:00
call VerifyInternal ( buf , 'Test_diff_20' , " diffopt+=iwhiteall" )
2024-09-22 11:26:13 +02:00
" Test 21: Delete all lines
call WriteDiffFiles ( buf , [0 ], [])
call VerifyBoth ( buf , "Test_diff_21" , "" )
" Test 22: Add line to empty file
call WriteDiffFiles ( buf , [], [0 ])
call VerifyBoth ( buf , "Test_diff_22" , "" )
2025-01-12 09:58:00 +01:00
call WriteDiffFiles ( buf , ['?a' , '?b' , '?c' ], ['!b' ])
call VerifyInternal ( buf , 'Test_diff_23' , " diffopt+=linematch:30" )
call WriteDiffFiles ( buf , ['' ,
\ 'common line' ,
\ 'common line' ,
\ '' ,
\ 'DEFabc' ,
\ 'xyz' ,
\ 'xyz' ,
\ 'xyz' ,
\ 'DEFabc' ,
\ 'DEFabc' ,
\ 'DEFabc' ,
\ 'common line' ,
\ 'common line' ,
\ 'DEF' ,
\ 'common line' ,
\ 'DEF' ,
\ 'something' ],
\ ['' ,
\ 'common line' ,
\ 'common line' ,
\ '' ,
\ 'ABCabc' ,
\ 'ABCabc' ,
\ 'ABCabc' ,
\ 'ABCabc' ,
\ 'common line' ,
\ 'common line' ,
\ 'common line' ,
\ 'something' ])
call VerifyInternal ( buf , 'Test_diff_24' , " diffopt+=linematch:30" )
2018-09-10 17:51:58 +02:00
" clean up
call StopVimInTerminal ( buf )
2022-08-30 21:46:08 +01:00
call delete ( 'Xdifile1' )
call delete ( 'Xdifile2' )
2018-09-10 17:51:58 +02:00
endfunc
2021-09-01 16:02:07 +02:00
func Test_diff_with_scroll_and_change ( )
CheckScreendump
let lines = < < trim END
call setline ( 1 , range ( 1 , 15 ) )
vnew
call setline ( 1 , range ( 9 , 15 ) )
windo diffthis
wincmd h
exe "normal Gl5\<C-E>"
END
2022-09-20 22:01:33 +01:00
call writefile ( lines , 'Xtest_scroll_change' , 'D' )
2021-09-01 16:02:07 +02:00
let buf = RunVimInTerminal ( '-S Xtest_scroll_change' , {})
call VerifyScreenDump ( buf , 'Test_diff_scroll_change_01' , {})
call term_sendkeys ( buf , "ax\<Esc>" )
call VerifyScreenDump ( buf , 'Test_diff_scroll_change_02' , {})
2021-10-22 20:56:55 +01:00
call term_sendkeys ( buf , "\<C-W>lay\<Esc>" )
call VerifyScreenDump ( buf , 'Test_diff_scroll_change_03' , {})
2021-09-01 16:02:07 +02:00
" clean up
call StopVimInTerminal ( buf )
endfunc
2018-10-02 18:26:10 +02:00
func Test_diff_with_cursorline ( )
2019-08-03 22:55:50 +02:00
CheckScreendump
2018-10-02 18:26:10 +02:00
call writefile ( [
\ 'hi CursorLine ctermbg=red ctermfg=white' ,
\ 'set cursorline' ,
\ 'call setline(1, ["foo","foo","foo","bar"])' ,
\ 'vnew' ,
\ 'call setline(1, ["bee","foo","foo","baz"])' ,
\ 'windo diffthis' ,
\ '2wincmd w' ,
2022-09-20 22:01:33 +01:00
\ ], 'Xtest_diff_cursorline' , 'D' )
2018-10-02 18:26:10 +02:00
let buf = RunVimInTerminal ( '-S Xtest_diff_cursorline' , {})
call VerifyScreenDump ( buf , 'Test_diff_with_cursorline_01' , {})
call term_sendkeys ( buf , "j" )
call VerifyScreenDump ( buf , 'Test_diff_with_cursorline_02' , {})
call term_sendkeys ( buf , "j" )
call VerifyScreenDump ( buf , 'Test_diff_with_cursorline_03' , {})
" clean up
call StopVimInTerminal ( buf )
endfunc
2018-11-01 21:14:53 +01:00
2022-03-06 19:54:13 +00:00
func Test_diff_with_cursorline_number ( )
CheckScreendump
let lines = < < trim END
hi CursorLine ctermbg = red ctermfg = white
hi CursorLineNr ctermbg = white ctermfg = black cterm = underline
set cursorline number
call setline ( 1 , ["baz" , "foo" , "foo" , "bar" ])
2
vnew
call setline ( 1 , ["foo" , "foo" , "bar" ])
windo diffthis
1 wincmd w
END
2022-09-20 22:01:33 +01:00
call writefile ( lines , 'Xtest_diff_cursorline_number' , 'D' )
2022-03-06 19:54:13 +00:00
let buf = RunVimInTerminal ( '-S Xtest_diff_cursorline_number' , {})
call VerifyScreenDump ( buf , 'Test_diff_with_cursorline_number_01' , {})
call term_sendkeys ( buf , ":set cursorlineopt=number\r" )
call VerifyScreenDump ( buf , 'Test_diff_with_cursorline_number_02' , {})
" clean up
call StopVimInTerminal ( buf )
endfunc
2021-08-05 17:57:02 +02:00
func Test_diff_with_cursorline_breakindent ( )
CheckScreendump
2023-12-05 15:47:09 +01:00
let lines = < < trim END
hi CursorLine ctermbg = red ctermfg = white
set noequalalways wrap diffopt = followwrap cursorline breakindent
50 vnew
call setline ( 1 , [' ' , ' ' , ' ' , ' ' ])
exe "norm! 20Afoo\<Esc>j20Afoo\<Esc>j20Afoo\<Esc>j20Abar\<Esc>"
vnew
call setline ( 1 , [' ' , ' ' , ' ' , ' ' ])
exe "norm! 20Abee\<Esc>j20Afoo\<Esc>j20Afoo\<Esc>j20Abaz\<Esc>"
windo diffthis
2 wincmd w
END
call writefile ( lines , 'Xtest_diff_cursorline_breakindent' , 'D' )
2021-08-05 17:57:02 +02:00
let buf = RunVimInTerminal ( '-S Xtest_diff_cursorline_breakindent' , {})
call term_sendkeys ( buf , "gg0" )
call VerifyScreenDump ( buf , 'Test_diff_with_cul_bri_01' , {})
call term_sendkeys ( buf , "j" )
call VerifyScreenDump ( buf , 'Test_diff_with_cul_bri_02' , {})
call term_sendkeys ( buf , "j" )
call VerifyScreenDump ( buf , 'Test_diff_with_cul_bri_03' , {})
call term_sendkeys ( buf , "j" )
call VerifyScreenDump ( buf , 'Test_diff_with_cul_bri_04' , {})
" clean up
call StopVimInTerminal ( buf )
endfunc
2023-12-05 15:47:09 +01:00
func Test_diff_breakindent_after_filler ( )
CheckScreendump
let lines = < < trim END
2024-02-12 22:53:20 +01:00
set laststatus = 0 diffopt + = followwrap breakindent breakindentopt = min :0
2023-12-05 15:47:09 +01:00
call setline ( 1 , ['a' , ' ' .. repeat ( 'c' , 50 ) ])
vnew
call setline ( 1 , ['a' , 'b' , ' ' .. repeat ( 'c' , 50 ) ])
windo diffthis
norm ! G $
END
call writefile ( lines , 'Xtest_diff_breakindent_after_filler' , 'D' )
let buf = RunVimInTerminal ( '-S Xtest_diff_breakindent_after_filler' , #{rows : 8 , cols : 45 })
call VerifyScreenDump ( buf , 'Test_diff_breakindent_after_filler' , {})
" clean up
call StopVimInTerminal ( buf )
endfunc
2019-09-15 19:31:28 +02:00
func Test_diff_with_syntax ( )
CheckScreendump
let lines = < < trim END
2023-01-28 19:19:03 +00:00
void doNothing ( ) {
2019-09-15 19:31:28 +02:00
int x = 0 ;
char *s = "hello" ;
return 5 ;
}
END
2022-09-20 22:01:33 +01:00
call writefile ( lines , 'Xprogram1.c' , 'D' )
2019-09-15 19:31:28 +02:00
let lines = < < trim END
2023-01-28 19:19:03 +00:00
void doSomething ( ) {
2019-09-15 19:31:28 +02:00
int x = 0 ;
char *s = "there" ;
return 5 ;
}
END
2022-09-20 22:01:33 +01:00
call writefile ( lines , 'Xprogram2.c' , 'D' )
2019-09-15 19:31:28 +02:00
let lines = < < trim END
2023-01-28 19:19:03 +00:00
edit Xprogram1 .c
2019-09-15 19:31:28 +02:00
diffsplit Xprogram2 .c
END
2022-09-20 22:01:33 +01:00
call writefile ( lines , 'Xtest_diff_syntax' , 'D' )
2019-09-15 19:31:28 +02:00
let buf = RunVimInTerminal ( '-S Xtest_diff_syntax' , {})
call VerifyScreenDump ( buf , 'Test_diff_syntax_1' , {})
" clean up
call StopVimInTerminal ( buf )
endfunc
2018-11-01 21:14:53 +01:00
func Test_diff_of_diff ( )
2019-08-03 22:55:50 +02:00
CheckScreendump
CheckFeature rightleft
2018-11-01 21:14:53 +01:00
call writefile ( [
\ 'call setline(1, ["aa","bb","cc","@@ -3,2 +5,7 @@","dd","ee","ff"])' ,
\ 'vnew' ,
\ 'call setline(1, ["aa","bb","cc"])' ,
\ 'windo diffthis' ,
2019-03-29 18:08:18 +01:00
\ '1wincmd w' ,
\ 'setlocal number' ,
2022-09-20 22:01:33 +01:00
\ ], 'Xtest_diff_diff' , 'D' )
2018-11-01 21:14:53 +01:00
let buf = RunVimInTerminal ( '-S Xtest_diff_diff' , {})
call VerifyScreenDump ( buf , 'Test_diff_of_diff_01' , {})
2019-03-29 18:29:54 +01:00
call term_sendkeys ( buf , ":set rightleft\<cr>" )
call VerifyScreenDump ( buf , 'Test_diff_of_diff_02' , {})
2018-11-01 21:14:53 +01:00
" clean up
call StopVimInTerminal ( buf )
endfunc
2019-11-10 21:00:27 +01:00
func CloseoffSetup ( )
enew
call setline ( 1 , ['one' , 'two' , 'three' ])
diffthis
new
call setline ( 1 , ['one' , 'tow' , 'three' ])
diffthis
call assert_equal ( 1 , &diff )
2025-01-17 13:37:35 +01:00
bw !
2019-11-10 21:00:27 +01:00
endfunc
func Test_diff_closeoff ( )
" "closeoff" included by default: last diff win gets 'diff' reset'
call CloseoffSetup ( )
call assert_equal ( 0 , &diff )
enew !
" "closeoff" excluded: last diff win keeps 'diff' set'
set diffopt - = closeoff
call CloseoffSetup ( )
call assert_equal ( 1 , &diff )
diffoff !
enew !
endfunc
2019-11-16 13:50:25 +01:00
2021-02-10 13:18:17 +01:00
func Test_diff_followwrap ( )
new
set diffopt + = followwrap
set wrap
diffthis
call assert_equal ( 1 , &wrap )
diffoff
set nowrap
diffthis
call assert_equal ( 0 , &wrap )
diffoff
set diffopt &
bwipe !
endfunc
2019-11-16 13:50:25 +01:00
func Test_diff_maintains_change_mark ( )
2021-12-29 16:44:48 +00:00
func DiffMaintainsChangeMark ( )
enew !
call setline ( 1 , ['a' , 'b' , 'c' , 'd' ])
diffthis
new
call setline ( 1 , ['a' , 'b' , 'c' , 'e' ])
" Set '[ and '] marks
2 , 3 yank
call assert_equal ( [2 , 3 ], [line ( "'[" ) , line ( "']" ) ])
" Verify they aren't affected by the implicit diff
diffthis
call assert_equal ( [2 , 3 ], [line ( "'[" ) , line ( "']" ) ])
" Verify they aren't affected by an explicit diff
diffupdate
call assert_equal ( [2 , 3 ], [line ( "'[" ) , line ( "']" ) ])
bwipe !
bwipe !
endfunc
set diffopt - = internal
call DiffMaintainsChangeMark ( )
set diffopt + = internal
call DiffMaintainsChangeMark ( )
2022-01-16 15:00:08 +00:00
2021-12-29 16:44:48 +00:00
set diffopt &
2022-01-16 15:00:08 +00:00
delfunc DiffMaintainsChangeMark
2019-11-16 13:50:25 +01:00
endfunc
2020-03-18 19:32:26 +01:00
" Test for 'patchexpr'
func Test_patchexpr ( )
let g :patch_args = []
func TPatch ( )
call add ( g :patch_args , readfile ( v :fname_in ) )
call add ( g :patch_args , readfile ( v :fname_diff ) )
call writefile ( ['output file' ], v :fname_out )
endfunc
set patchexpr = TPatch ( )
2022-09-20 22:01:33 +01:00
call writefile ( ['input file' ], 'Xinput' , 'D' )
call writefile ( ['diff file' ], 'Xdiff' , 'D' )
2020-03-18 19:32:26 +01:00
%bwipe !
edit Xinput
diffpatch Xdiff
call assert_equal ( 'output file' , getline ( 1 ) )
call assert_equal ( 'Xinput.new' , bufname ( ) )
call assert_equal ( 2 , winnr ( '$' ) )
call assert_true ( &diff )
2021-12-26 10:51:39 +00:00
" Using a script-local function
func s :NewPatchExpr ( )
endfunc
set patchexpr = s :NewPatchExpr ( )
call assert_equal ( expand ( '<SID>' ) .. 'NewPatchExpr()' , &patchexpr )
set patchexpr = < SID > NewPatchExpr ( )
call assert_equal ( expand ( '<SID>' ) .. 'NewPatchExpr()' , &patchexpr )
2020-03-18 19:32:26 +01:00
set patchexpr &
delfunc TPatch
2021-12-26 10:51:39 +00:00
delfunc s :NewPatchExpr
2020-03-18 19:32:26 +01:00
%bwipe !
endfunc
2020-06-18 19:15:27 +02:00
func Test_diff_rnu ( )
CheckScreendump
let content = < < trim END
call setline ( 1 , ['a' , 'a' , 'a' , 'y' , 'b' , 'b' , 'b' , 'b' , 'b' ])
vnew
call setline ( 1 , ['a' , 'a' , 'a' , 'x' , 'x' , 'x' , 'b' , 'b' , 'b' , 'b' , 'b' ])
windo diffthis
setlocal number rnu foldcolumn = 0
END
2022-09-20 22:01:33 +01:00
call writefile ( content , 'Xtest_diff_rnu' , 'D' )
2020-06-18 19:15:27 +02:00
let buf = RunVimInTerminal ( '-S Xtest_diff_rnu' , {})
call VerifyScreenDump ( buf , 'Test_diff_rnu_01' , {})
call term_sendkeys ( buf , "j" )
call VerifyScreenDump ( buf , 'Test_diff_rnu_02' , {})
call term_sendkeys ( buf , "j" )
call VerifyScreenDump ( buf , 'Test_diff_rnu_03' , {})
" clean up
call StopVimInTerminal ( buf )
endfunc
2020-06-25 22:23:48 +02:00
func Test_diff_multilineconceal ( )
new
diffthis
new
call matchadd ( 'Conceal' , 'a\nb' , 9 , -1 , {'conceal' : 'Y' })
set cole = 2 cocu = n
call setline ( 1 , ["a" , "b" ])
diffthis
redraw
endfunc
2020-07-14 21:22:30 +02:00
func Test_diff_and_scroll ( )
" this was causing an ml_get error
set ls = 2
2023-01-28 19:19:03 +00:00
for i in range ( winheight ( 0 ) * 2 )
call setline ( i , i < winheight ( 0 ) - 10 ? i : i + 10 )
2020-07-14 21:22:30 +02:00
endfor
vnew
2023-01-28 19:19:03 +00:00
for i in range ( winheight ( 0 ) *2 + 10 )
call setline ( i , i < winheight ( 0 ) - 10 ? 0 : i )
2020-07-14 21:22:30 +02:00
endfor
diffthis
wincmd p
diffthis
execute 'normal ' . winheight ( 0 ) . "\<C-d>"
bwipe !
bwipe !
set ls &
endfunc
2020-11-05 19:07:21 +01:00
func Test_diff_filler_cursorcolumn ( )
CheckScreendump
let content = < < trim END
call setline ( 1 , ['aa' , 'bb' , 'cc' ])
vnew
call setline ( 1 , ['aa' , 'cc' ])
windo diffthis
wincmd p
setlocal cursorcolumn foldcolumn = 0
norm ! gg0
redraw !
END
2022-09-20 22:01:33 +01:00
call writefile ( content , 'Xtest_diff_cuc' , 'D' )
2020-11-05 19:07:21 +01:00
let buf = RunVimInTerminal ( '-S Xtest_diff_cuc' , {})
call VerifyScreenDump ( buf , 'Test_diff_cuc_01' , {})
call term_sendkeys ( buf , "l" )
call term_sendkeys ( buf , "\<C-l>" )
call VerifyScreenDump ( buf , 'Test_diff_cuc_02' , {})
call term_sendkeys ( buf , "0j" )
call term_sendkeys ( buf , "\<C-l>" )
call VerifyScreenDump ( buf , 'Test_diff_cuc_03' , {})
call term_sendkeys ( buf , "l" )
call term_sendkeys ( buf , "\<C-l>" )
call VerifyScreenDump ( buf , 'Test_diff_cuc_04' , {})
" clean up
call StopVimInTerminal ( buf )
endfunc
2021-06-10 21:52:15 +02:00
" Test for adding/removing lines inside diff chunks, between diff chunks
" and before diff chunks
func Test_diff_modify_chunks ( )
enew !
let w2_id = win_getid ( )
call setline ( 1 , ['a' , 'b' , 'c' , 'd' , 'e' , 'f' , 'g' , 'h' , 'i' ])
new
let w1_id = win_getid ( )
call setline ( 1 , ['a' , '2' , '3' , 'd' , 'e' , 'f' , '7' , '8' , 'i' ])
windo diffthis
" remove a line between two diff chunks and create a new diff chunk
call win_gotoid ( w2_id )
5 d
call win_gotoid ( w1_id )
call diff_hlID ( 5 , 1 ) - > synIDattr ( 'name' ) - > assert_equal ( 'DiffAdd' )
" add a line between two diff chunks
call win_gotoid ( w2_id )
normal ! 4 Goe
call win_gotoid ( w1_id )
call diff_hlID ( 4 , 1 ) - > synIDattr ( 'name' ) - > assert_equal ( '' )
call diff_hlID ( 5 , 1 ) - > synIDattr ( 'name' ) - > assert_equal ( '' )
" remove all the lines in a diff chunk.
call win_gotoid ( w2_id )
7 , 8 d
call win_gotoid ( w1_id )
let hl = range ( 1 , 9 ) - > map ( {_ , lnum - > diff_hlID ( lnum , 1 ) - > synIDattr ( 'name' ) })
call assert_equal ( ['' , 'DiffText' , 'DiffText' , '' , '' , '' , 'DiffAdd' ,
\ 'DiffAdd' , '' ], hl )
" remove lines from one diff chunk to just before the next diff chunk
call win_gotoid ( w2_id )
call setline ( 1 , ['a' , 'b' , 'c' , 'd' , 'e' , 'f' , 'g' , 'h' , 'i' ])
2 , 6 d
call win_gotoid ( w1_id )
let hl = range ( 1 , 9 ) - > map ( {_ , lnum - > diff_hlID ( lnum , 1 ) - > synIDattr ( 'name' ) })
call assert_equal ( ['' , 'DiffText' , 'DiffText' , 'DiffAdd' , 'DiffAdd' ,
\ 'DiffAdd' , 'DiffAdd' , 'DiffAdd' , '' ], hl )
" remove lines just before the top of a diff chunk
call win_gotoid ( w2_id )
call setline ( 1 , ['a' , 'b' , 'c' , 'd' , 'e' , 'f' , 'g' , 'h' , 'i' ])
5 , 6 d
call win_gotoid ( w1_id )
let hl = range ( 1 , 9 ) - > map ( {_ , lnum - > diff_hlID ( lnum , 1 ) - > synIDattr ( 'name' ) })
call assert_equal ( ['' , 'DiffText' , 'DiffText' , '' , 'DiffText' , 'DiffText' ,
\ 'DiffAdd' , 'DiffAdd' , '' ], hl )
" remove line after the end of a diff chunk
call win_gotoid ( w2_id )
call setline ( 1 , ['a' , 'b' , 'c' , 'd' , 'e' , 'f' , 'g' , 'h' , 'i' ])
4 d
call win_gotoid ( w1_id )
let hl = range ( 1 , 9 ) - > map ( {_ , lnum - > diff_hlID ( lnum , 1 ) - > synIDattr ( 'name' ) })
call assert_equal ( ['' , 'DiffText' , 'DiffText' , 'DiffAdd' , '' , '' , 'DiffText' ,
\ 'DiffText' , '' ], hl )
" remove lines starting from the end of one diff chunk and ending inside
" another diff chunk
call win_gotoid ( w2_id )
call setline ( 1 , ['a' , 'b' , 'c' , 'd' , 'e' , 'f' , 'g' , 'h' , 'i' ])
4 , 7 d
call win_gotoid ( w1_id )
let hl = range ( 1 , 9 ) - > map ( {_ , lnum - > diff_hlID ( lnum , 1 ) - > synIDattr ( 'name' ) })
call assert_equal ( ['' , 'DiffText' , 'DiffText' , 'DiffText' , 'DiffAdd' ,
\ 'DiffAdd' , 'DiffAdd' , 'DiffAdd' , '' ], hl )
" removing the only remaining diff chunk should make the files equal
call win_gotoid ( w2_id )
call setline ( 1 , ['a' , '2' , '3' , 'x' , 'd' , 'e' , 'f' , 'x' , '7' , '8' , 'i' ])
8 d
let hl = range ( 1 , 10 ) - > map ( {_ , lnum - > diff_hlID ( lnum , 1 ) - > synIDattr ( 'name' ) })
call assert_equal ( ['' , '' , '' , 'DiffAdd' , '' , '' , '' , '' , '' , '' ], hl )
call win_gotoid ( w2_id )
4 d
call win_gotoid ( w1_id )
let hl = range ( 1 , 9 ) - > map ( {_ , lnum - > diff_hlID ( lnum , 1 ) - > synIDattr ( 'name' ) })
call assert_equal ( ['' , '' , '' , '' , '' , '' , '' , '' , '' ], hl )
%bw !
endfunc
2021-05-24 14:20:53 +02:00
2021-12-28 18:30:05 +00:00
func Test_diff_binary ( )
CheckScreendump
let content = < < trim END
call setline ( 1 , ['a' , 'b' , "c\n" , 'd' , 'e' , 'f' , 'g' ])
vnew
call setline ( 1 , ['A' , 'b' , 'c' , 'd' , 'E' , 'f' , 'g' ])
windo diffthis
wincmd p
norm ! gg0
redraw !
END
2022-09-20 22:01:33 +01:00
call writefile ( content , 'Xtest_diff_bin' , 'D' )
2021-12-28 18:30:05 +00:00
let buf = RunVimInTerminal ( '-S Xtest_diff_bin' , {})
" Test using internal diff
call VerifyScreenDump ( buf , 'Test_diff_bin_01' , {})
" Test using internal diff and case folding
call term_sendkeys ( buf , ":set diffopt+=icase\<cr>" )
call term_sendkeys ( buf , "\<C-l>" )
call VerifyScreenDump ( buf , 'Test_diff_bin_02' , {})
" Test using external diff
call term_sendkeys ( buf , ":set diffopt=filler\<cr>" )
call term_sendkeys ( buf , "\<C-l>" )
call VerifyScreenDump ( buf , 'Test_diff_bin_03' , {})
" Test using external diff and case folding
call term_sendkeys ( buf , ":set diffopt=filler,icase\<cr>" )
call term_sendkeys ( buf , "\<C-l>" )
call VerifyScreenDump ( buf , 'Test_diff_bin_04' , {})
" clean up
call StopVimInTerminal ( buf )
set diffopt &vim
endfunc
2022-01-27 13:16:59 +00:00
" Test for using the 'zi' command to invert 'foldenable' in diff windows (test
" for the issue fixed by patch 6.2.317)
func Test_diff_foldinvert ( )
%bw !
2022-08-30 21:46:08 +01:00
edit Xdoffile1
new Xdoffile2
new Xdoffile3
2022-01-27 13:16:59 +00:00
windo diffthis
" open a non-diff window
botright new
1 wincmd w
call assert_true ( getwinvar ( 1 , '&foldenable' ) )
call assert_true ( getwinvar ( 2 , '&foldenable' ) )
call assert_true ( getwinvar ( 3 , '&foldenable' ) )
normal zi
call assert_false ( getwinvar ( 1 , '&foldenable' ) )
call assert_false ( getwinvar ( 2 , '&foldenable' ) )
call assert_false ( getwinvar ( 3 , '&foldenable' ) )
normal zi
call assert_true ( getwinvar ( 1 , '&foldenable' ) )
call assert_true ( getwinvar ( 2 , '&foldenable' ) )
call assert_true ( getwinvar ( 3 , '&foldenable' ) )
" If the current window has 'noscrollbind', then 'zi' should not change
" 'foldenable' in other windows.
1 wincmd w
set noscrollbind
normal zi
call assert_false ( getwinvar ( 1 , '&foldenable' ) )
call assert_true ( getwinvar ( 2 , '&foldenable' ) )
call assert_true ( getwinvar ( 3 , '&foldenable' ) )
" 'zi' should not change the 'foldenable' for windows with 'noscrollbind'
1 wincmd w
set scrollbind
normal zi
call setwinvar ( 2 , '&scrollbind' , v :false )
normal zi
call assert_false ( getwinvar ( 1 , '&foldenable' ) )
call assert_true ( getwinvar ( 2 , '&foldenable' ) )
call assert_false ( getwinvar ( 3 , '&foldenable' ) )
%bw !
set scrollbind &
endfunc
2022-06-24 12:38:57 +01:00
" This was scrolling for 'cursorbind' but 'scrollbind' is more important
func Test_diff_scroll ( )
CheckScreendump
let left = < < trim END
line 1
line 2
line 3
line 4
// Common block
// one
// containing
// four lines
// Common block
// two
// containing
// four lines
END
2022-09-20 22:01:33 +01:00
call writefile ( left , 'Xleft' , 'D' )
2022-06-24 12:38:57 +01:00
let right = < < trim END
line 1
line 2
line 3
line 4
Lorem
ipsum
dolor
sit
amet ,
consectetur
adipiscing
elit .
Etiam
luctus
lectus
sodales ,
dictum
// Common block
// one
// containing
// four lines
Vestibulum
tincidunt
aliquet
nulla .
// Common block
// two
// containing
// four lines
END
2022-09-20 22:01:33 +01:00
call writefile ( right , 'Xright' , 'D' )
2022-06-24 12:38:57 +01:00
let buf = RunVimInTerminal ( '-d Xleft Xright' , {'rows' : 12 })
call term_sendkeys ( buf , "\<C-W>\<C-W>jjjj" )
call VerifyScreenDump ( buf , 'Test_diff_scroll_1' , {})
call term_sendkeys ( buf , "j" )
call VerifyScreenDump ( buf , 'Test_diff_scroll_2' , {})
call StopVimInTerminal ( buf )
endfunc
2023-04-01 19:54:40 +01:00
" This was scrolling too many lines.
func Test_diff_scroll_wrap_on ( )
20 new
40 vsplit
call setline ( 1 , map ( range ( 1 , 9 ) , 'repeat(v:val, 200)' ) )
setlocal number diff so = 0
redraw
normal ! jj
call assert_equal ( 1 , winsaveview ( ) .topline )
normal ! j
call assert_equal ( 2 , winsaveview ( ) .topline )
2023-10-04 20:12:37 +02:00
bwipe !
bwipe !
endfunc
func Test_diff_scroll_many_filler ( )
20 new
vnew
2024-03-26 18:46:45 +01:00
call setline ( 1 , range ( 1 , 40 ) )
2023-10-04 20:12:37 +02:00
diffthis
setlocal scrolloff = 0
wincmd p
2024-03-26 18:46:45 +01:00
call setline ( 1 , range ( 1 , 20 ) - > reverse ( ) + ['###' ]- > repeat ( 41 ) + range ( 21 , 40 ) - > reverse ( ) )
2023-10-04 20:12:37 +02:00
diffthis
setlocal scrolloff = 0
wincmd p
redraw
" Note: need a redraw after each scroll, otherwise the test always passes.
2024-03-26 18:46:45 +01:00
for _ in range ( 2 )
normal ! G
redraw
call assert_equal ( 40 , winsaveview ( ) .topline )
call assert_equal ( 19 , winsaveview ( ) .topfill )
exe "normal! \<C-B>"
redraw
call assert_equal ( 22 , winsaveview ( ) .topline )
call assert_equal ( 0 , winsaveview ( ) .topfill )
exe "normal! \<C-B>"
redraw
call assert_equal ( 4 , winsaveview ( ) .topline )
call assert_equal ( 0 , winsaveview ( ) .topfill )
exe "normal! \<C-B>"
redraw
call assert_equal ( 1 , winsaveview ( ) .topline )
call assert_equal ( 0 , winsaveview ( ) .topfill )
set smoothscroll
endfor
2023-10-04 20:12:37 +02:00
2024-03-26 18:46:45 +01:00
set smoothscroll &
2024-04-02 20:49:45 +02:00
%bwipe !
2023-04-01 19:54:40 +01:00
endfunc
2022-06-26 14:04:07 +01:00
" This was trying to update diffs for a buffer being closed
func Test_diff_only ( )
silent ! lfile
set diff
lopen
norm o
silent ! norm o
set nodiff
%bwipe !
endfunc
2022-06-26 16:53:34 +01:00
" This was causing invalid diff block values
" FIXME: somehow this causes a valgrind error when run directly but not when
" run as a test.
func Test_diff_manipulations ( )
set diff
split 0
sil ! norm R
doo bdeu R
doo bdeu R
doo bdeu
set nodiff
%bwipe !
endfunc
2022-07-28 18:44:27 +01:00
" This was causing the line number in the diff block to go below one.
" FIXME: somehow this causes a valgrind error when run directly but not when
" run as a test.
func Test_diff_put_and_undo ( )
set diff
next 0
split 00
sil ! norm o0 gguudpo0 ggJuudp
bwipe !
bwipe !
set nodiff
endfunc
2024-02-01 22:05:27 +01:00
" Test for the diff() function
def Test_diff_func ( )
# string is added /removed/ modified at the beginning
2024-02-12 20:21:26 +01:00
assert_equal ( "@@ -0,0 +1 @@\n+abc\n" ,
2024-02-01 22:05:27 +01:00
diff ( ['def' ], ['abc' , 'def' ], {output : 'unified' }) )
assert_equal ( [{from_idx : 0 , from_count : 0 , to_idx : 0 , to_count : 1 }],
diff ( ['def' ], ['abc' , 'def' ], {output : 'indices' }) )
2024-02-12 20:21:26 +01:00
assert_equal ( "@@ -1 +0,0 @@\n-abc\n" ,
2024-02-01 22:05:27 +01:00
diff ( ['abc' , 'def' ], ['def' ], {output : 'unified' }) )
assert_equal ( [{from_idx : 0 , from_count : 1 , to_idx : 0 , to_count : 0 }],
diff ( ['abc' , 'def' ], ['def' ], {output : 'indices' }) )
2024-02-12 20:21:26 +01:00
assert_equal ( "@@ -1 +1 @@\n-abc\n+abx\n" ,
2024-02-01 22:05:27 +01:00
diff ( ['abc' , 'def' ], ['abx' , 'def' ], {output : 'unified' }) )
assert_equal ( [{from_idx : 0 , from_count : 1 , to_idx : 0 , to_count : 1 }],
diff ( ['abc' , 'def' ], ['abx' , 'def' ], {output : 'indices' }) )
# string is added /removed/ modified at the end
2024-02-12 20:21:26 +01:00
assert_equal ( "@@ -1,0 +2 @@\n+def\n" ,
2024-02-01 22:05:27 +01:00
diff ( ['abc' ], ['abc' , 'def' ], {output : 'unified' }) )
assert_equal ( [{from_idx : 1 , from_count : 0 , to_idx : 1 , to_count : 1 }],
diff ( ['abc' ], ['abc' , 'def' ], {output : 'indices' }) )
2024-02-12 20:21:26 +01:00
assert_equal ( "@@ -2 +1,0 @@\n-def\n" ,
2024-02-01 22:05:27 +01:00
diff ( ['abc' , 'def' ], ['abc' ], {output : 'unified' }) )
assert_equal ( [{from_idx : 1 , from_count : 1 , to_idx : 1 , to_count : 0 }],
diff ( ['abc' , 'def' ], ['abc' ], {output : 'indices' }) )
2024-02-12 20:21:26 +01:00
assert_equal ( "@@ -2 +2 @@\n-def\n+xef\n" ,
2024-02-01 22:05:27 +01:00
diff ( ['abc' , 'def' ], ['abc' , 'xef' ], {output : 'unified' }) )
assert_equal ( [{from_idx : 1 , from_count : 1 , to_idx : 1 , to_count : 1 }],
diff ( ['abc' , 'def' ], ['abc' , 'xef' ], {output : 'indices' }) )
# string is added /removed/ modified in the middle
2024-02-12 20:21:26 +01:00
assert_equal ( "@@ -2,0 +3 @@\n+xxx\n" ,
2024-02-01 22:05:27 +01:00
diff ( ['111' , '222' , '333' ], ['111' , '222' , 'xxx' , '333' ], {output : 'unified' }) )
assert_equal ( [{from_idx : 2 , from_count : 0 , to_idx : 2 , to_count : 1 }],
diff ( ['111' , '222' , '333' ], ['111' , '222' , 'xxx' , '333' ], {output : 'indices' }) )
2024-02-12 20:21:26 +01:00
assert_equal ( "@@ -3 +2,0 @@\n-333\n" ,
2024-02-01 22:05:27 +01:00
diff ( ['111' , '222' , '333' , '444' ], ['111' , '222' , '444' ], {output : 'unified' }) )
assert_equal ( [{from_idx : 2 , from_count : 1 , to_idx : 2 , to_count : 0 }],
diff ( ['111' , '222' , '333' , '444' ], ['111' , '222' , '444' ], {output : 'indices' }) )
2024-02-12 20:21:26 +01:00
assert_equal ( "@@ -3 +3 @@\n-333\n+xxx\n" ,
2024-02-01 22:05:27 +01:00
diff ( ['111' , '222' , '333' , '444' ], ['111' , '222' , 'xxx' , '444' ], {output : 'unified' }) )
assert_equal ( [{from_idx : 2 , from_count : 1 , to_idx : 2 , to_count : 1 }],
diff ( ['111' , '222' , '333' , '444' ], ['111' , '222' , 'xxx' , '444' ], {output : 'indices' }) )
# new strings are added to an empty List
assert_equal ( "@@ -0,0 +1,2 @@\n+abc\n+def\n" ,
diff ( [], ['abc' , 'def' ], {output : 'unified' }) )
assert_equal ( [{from_idx : 0 , from_count : 0 , to_idx : 0 , to_count : 2 }],
diff ( [], ['abc' , 'def' ], {output : 'indices' }) )
# all the strings are removed from a List
assert_equal ( "@@ -1,2 +0,0 @@\n-abc\n-def\n" ,
diff ( ['abc' , 'def' ], [], {output : 'unified' }) )
assert_equal ( [{from_idx : 0 , from_count : 2 , to_idx : 0 , to_count : 0 }],
diff ( ['abc' , 'def' ], [], {output : 'indices' }) )
# First character is added /removed/ different
assert_equal ( "@@ -1 +1 @@\n-abc\n+bc\n" ,
diff ( ['abc' ], ['bc' ], {output : 'unified' }) )
assert_equal ( [{from_idx : 0 , from_count : 1 , to_idx : 0 , to_count : 1 }],
diff ( ['abc' ], ['bc' ], {output : 'indices' }) )
assert_equal ( "@@ -1 +1 @@\n-bc\n+abc\n" ,
diff ( ['bc' ], ['abc' ], {output : 'unified' }) )
assert_equal ( [{from_idx : 0 , from_count : 1 , to_idx : 0 , to_count : 1 }],
diff ( ['bc' ], ['abc' ], {output : 'indices' }) )
assert_equal ( "@@ -1 +1 @@\n-abc\n+xbc\n" ,
diff ( ['abc' ], ['xbc' ], {output : 'unified' }) )
assert_equal ( [{from_idx : 0 , from_count : 1 , to_idx : 0 , to_count : 1 }],
diff ( ['abc' ], ['xbc' ], {output : 'indices' }) )
# Last character is added /removed/ different
assert_equal ( "@@ -1 +1 @@\n-abc\n+abcd\n" ,
diff ( ['abc' ], ['abcd' ], {output : 'unified' }) )
assert_equal ( [{from_idx : 0 , from_count : 1 , to_idx : 0 , to_count : 1 }],
diff ( ['abc' ], ['abcd' ], {output : 'indices' }) )
assert_equal ( "@@ -1 +1 @@\n-abcd\n+abc\n" ,
diff ( ['abcd' ], ['abc' ], {output : 'unified' }) )
assert_equal ( [{from_idx : 0 , from_count : 1 , to_idx : 0 , to_count : 1 }],
diff ( ['abcd' ], ['abc' ], {output : 'indices' }) )
2024-02-12 20:21:26 +01:00
var diff_unified : string = diff ( ['abc' ], ['abx' ], {output : 'unified' })
assert_equal ( "@@ -1 +1 @@\n-abc\n+abx\n" , diff_unified )
var diff_indices : list < dict < number > > =
diff ( ['abc' ], ['abx' ], {output : 'indices' })
2024-02-01 22:05:27 +01:00
assert_equal ( [{from_idx : 0 , from_count : 1 , to_idx : 0 , to_count : 1 }],
2024-02-12 20:21:26 +01:00
diff_indices )
2024-02-01 22:05:27 +01:00
# partial string modification at the start and at the end .
var fromlist = < < trim END
one two
three four
five six
END
var tolist = < < trim END
one
six
END
assert_equal ( "@@ -1,3 +1,2 @@\n-one two\n-three four\n-five six\n+one\n+six\n" , diff ( fromlist , tolist , {output : 'unified' }) )
assert_equal ( [{from_idx : 0 , from_count : 3 , to_idx : 0 , to_count : 2 }],
diff ( fromlist , tolist , {output : 'indices' }) )
# non - contiguous modifications
fromlist = < < trim END
one two
three four
five abc six
END
tolist = < < trim END
one abc two
three four
five six
END
2024-02-12 20:21:26 +01:00
assert_equal ( "@@ -1 +1 @@\n-one two\n+one abc two\n@@ -3 +3 @@\n-five abc six\n+five six\n" ,
2024-02-01 22:05:27 +01:00
diff ( fromlist , tolist , {output : 'unified' }) )
2024-02-12 20:21:26 +01:00
assert_equal ( [{'from_count' : 1 , 'to_idx' : 0 , 'to_count' : 1 , 'from_idx' : 0 },
{'from_count' : 1 , 'to_idx' : 2 , 'to_count' : 1 , 'from_idx' : 2 }],
2024-02-01 22:05:27 +01:00
diff ( fromlist , tolist , {output : 'indices' }) )
# add /remove blank lines
2024-02-12 20:21:26 +01:00
assert_equal ( "@@ -2,2 +1,0 @@\n-\n-\n" ,
2024-02-01 22:05:27 +01:00
diff ( ['one' , '' , '' , 'two' ], ['one' , 'two' ], {output : 'unified' }) )
assert_equal ( [{from_idx : 1 , from_count : 2 , to_idx : 1 , to_count : 0 }],
diff ( ['one' , '' , '' , 'two' ], ['one' , 'two' ], {output : 'indices' }) )
2024-02-12 20:21:26 +01:00
assert_equal ( "@@ -1,0 +2,2 @@\n+\n+\n" ,
2024-02-01 22:05:27 +01:00
diff ( ['one' , 'two' ], ['one' , '' , '' , 'two' ], {output : 'unified' }) )
assert_equal ( [{'from_idx' : 1 , 'from_count' : 0 , 'to_idx' : 1 , 'to_count' : 2 }],
diff ( ['one' , 'two' ], ['one' , '' , '' , 'two' ], {output : 'indices' }) )
# diff ignoring case
assert_equal ( '' , diff ( ['abc' , 'def' ], ['ABC' , 'DEF' ], {icase : true , output : 'unified' }) )
assert_equal ( [], diff ( ['abc' , 'def' ], ['ABC' , 'DEF' ], {icase : true , output : 'indices' }) )
# diff ignoring all whitespace changes except leading whitespace changes
assert_equal ( '' , diff ( ['abc def' ], ['abc def ' ], {iwhite : true }) )
assert_equal ( "@@ -1 +1 @@\n- abc\n+ xxx\n" , diff ( [' abc' ], [' xxx' ], {iwhite : v :true }) )
assert_equal ( "@@ -1 +1 @@\n- abc\n+ xxx\n" , diff ( [' abc' ], [' xxx' ], {iwhite : v :false }) )
assert_equal ( "@@ -1 +1 @@\n-abc \n+xxx \n" , diff ( ['abc ' ], ['xxx ' ], {iwhite : v :true }) )
assert_equal ( "@@ -1 +1 @@\n-abc \n+xxx \n" , diff ( ['abc ' ], ['xxx ' ], {iwhite : v :false }) )
# diff ignoring all whitespace changes
assert_equal ( '' , diff ( ['abc def' ], [' abc def ' ], {iwhiteall : true }) )
assert_equal ( "@@ -1 +1 @@\n- abc \n+ xxx \n" , diff ( [' abc ' ], [' xxx ' ], {iwhiteall : v :true }) )
assert_equal ( "@@ -1 +1 @@\n- abc \n+ xxx \n" , diff ( [' abc ' ], [' xxx ' ], {iwhiteall : v :false }) )
# diff ignoring trailing whitespace changes
assert_equal ( '' , diff ( ['abc' ], ['abc ' ], {iwhiteeol : true }) )
# diff ignoring blank lines
assert_equal ( '' , diff ( ['one' , '' , '' , 'two' ], ['one' , 'two' ], {iblank : true }) )
assert_equal ( '' , diff ( ['one' , 'two' ], ['one' , '' , '' , 'two' ], {iblank : true }) )
# same string
assert_equal ( '' , diff ( ['abc' , 'def' , 'ghi' ], ['abc' , 'def' , 'ghi' ]) )
assert_equal ( '' , diff ( ['' ], ['' ]) )
assert_equal ( '' , diff ( [], []) )
# different xdiff algorithms
for algo in ['myers' , 'minimal' , 'patience' , 'histogram' ]
assert_equal ( "@@ -1 +1 @@\n- abc \n+ xxx \n" ,
diff ( [' abc ' ], [' xxx ' ], {algorithm : algo , output : 'unified' }) )
assert_equal ( [{from_idx : 0 , from_count : 1 , to_idx : 0 , to_count : 1 }],
diff ( [' abc ' ], [' xxx ' ], {algorithm : algo , output : 'indices' }) )
endfor
assert_equal ( "@@ -1 +1 @@\n- abc \n+ xxx \n" ,
diff ( [' abc ' ], [' xxx ' ], {indent - heuristic : true , output : 'unified' }) )
assert_equal ( [{from_idx : 0 , from_count : 1 , to_idx : 0 , to_count : 1 }],
diff ( [' abc ' ], [' xxx ' ], {indent - heuristic : true , output : 'indices' }) )
# identical strings
assert_equal ( '' , diff ( ['111' , '222' ], ['111' , '222' ], {output : 'unified' }) )
assert_equal ( [], diff ( ['111' , '222' ], ['111' , '222' ], {output : 'indices' }) )
assert_equal ( '' , diff ( [], [], {output : 'unified' }) )
assert_equal ( [], diff ( [], [], {output : 'indices' }) )
2024-02-11 17:08:29 +01:00
# If 'diffexpr' is set , it should not be used for diff ( )
def MyDiffExpr ( )
enddef
var save_diffexpr = &diffexpr
:set diffexpr = MyDiffExpr ( )
assert_equal ( "@@ -1 +1 @@\n-abc\n+\n" ,
diff ( ['abc' ], ['' ], {output : 'unified' }) )
assert_equal ( [{'from_idx' : 0 , 'from_count' : 1 , 'to_idx' : 0 , 'to_count' : 1 }],
diff ( ['abc' ], ['' ], {output : 'indices' }) )
assert_equal ( 'MyDiffExpr()' , &diffexpr )
&diffexpr = save_diffexpr
# try different values for unified diff 'context'
assert_equal ( "@@ -0,0 +1 @@\n+x\n" ,
diff ( ['a' , 'b' , 'c' ], ['x' , 'a' , 'b' , 'c' ]) )
assert_equal ( "@@ -0,0 +1 @@\n+x\n" ,
diff ( ['a' , 'b' , 'c' ], ['x' , 'a' , 'b' , 'c' ], {context : 0 }) )
assert_equal ( "@@ -1 +1,2 @@\n+x\n a\n" ,
diff ( ['a' , 'b' , 'c' ], ['x' , 'a' , 'b' , 'c' ], {context : 1 }) )
assert_equal ( "@@ -1,2 +1,3 @@\n+x\n a\n b\n" ,
diff ( ['a' , 'b' , 'c' ], ['x' , 'a' , 'b' , 'c' ], {context : 2 }) )
assert_equal ( "@@ -1,3 +1,4 @@\n+x\n a\n b\n c\n" ,
diff ( ['a' , 'b' , 'c' ], ['x' , 'a' , 'b' , 'c' ], {context : 3 }) )
assert_equal ( "@@ -1,3 +1,4 @@\n+x\n a\n b\n c\n" ,
diff ( ['a' , 'b' , 'c' ], ['x' , 'a' , 'b' , 'c' ], {context : 4 }) )
2024-02-12 20:21:26 +01:00
assert_equal ( "@@ -0,0 +1 @@\n+x\n" ,
2024-02-11 17:08:29 +01:00
diff ( ['a' , 'b' , 'c' ], ['x' , 'a' , 'b' , 'c' ], {context : -1 }) )
2024-02-01 22:05:27 +01:00
# Error cases
assert_fails ( 'call diff({}, ["a"])' , 'E1211:' )
assert_fails ( 'call diff(["a"], {})' , 'E1211:' )
assert_fails ( 'call diff(["a"], ["a"], [])' , 'E1206:' )
assert_fails ( 'call diff(["a"], ["a"], {output: "xyz"})' , 'E106: Unsupported diff output format: xyz' )
2024-02-11 17:08:29 +01:00
assert_fails ( 'call diff(["a"], ["a"], {context: []})' , 'E745: Using a List as a Number' )
2024-02-01 22:05:27 +01:00
enddef
2022-06-24 12:38:57 +01:00
2024-02-12 20:21:26 +01:00
" Test for using the diff() function with 'diffexpr'
func Test_diffexpr_with_diff_func ( )
CheckScreendump
let lines = < < trim END
def DiffFuncExpr ( )
var in : list < string > = readfile ( v :fname_in )
var new : list < string > = readfile ( v :fname_new )
var out : string = diff ( in , new )
writefile ( split ( out , "\n" ) , v :fname_out )
enddef
set diffexpr = DiffFuncExpr ( )
edit Xdifffunc1 .txt
diffthis
vert split Xdifffunc2 .txt
diffthis
END
call writefile ( lines , 'XsetupDiffFunc.vim' , 'D' )
call writefile ( ['zero' , 'one' , 'two' , 'three' ], 'Xdifffunc1.txt' , 'D' )
call writefile ( ['one' , 'twox' , 'three' , 'four' ], 'Xdifffunc2.txt' , 'D' )
let buf = RunVimInTerminal ( '-S XsetupDiffFunc.vim' , {'rows' : 12 })
call VerifyScreenDump ( buf , 'Test_difffunc_diffexpr_1' , {})
call StopVimInTerminal ( buf )
endfunc
2024-03-16 09:40:22 +01:00
func Test_diff_toggle_wrap_skipcol_leftcol ( )
61 vnew
call setline ( 1 , 'Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua.' )
30 vnew
call setline ( 1 , 'ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua.' )
let win1 = win_getid ( )
setlocal smoothscroll
exe "normal! $\<C-E>"
wincmd l
let win2 = win_getid ( )
setlocal smoothscroll
exe "normal! $\<C-E>"
call assert_equal ( [
\ '<<<sadipscing elitr, sed diam |<<<tetur sadipscing elitr, sed|' ,
\ 'nonumy eirmod tempor invidunt | diam nonumy eirmod tempor inv|' ,
\ 'ut labore et dolore magna aliq|idunt ut labore et dolore magn|' ,
\ 'uyam erat, sed diam voluptua. |a aliquyam erat, sed diam volu|' ,
\ '~ |ptua. |' ,
\ ], ScreenLines ( [1 , 5 ], 62 ) )
call assert_equal ( {'col' : 29 , 'row' : 4 , 'endcol' : 29 , 'curscol' : 29 },
\ screenpos ( win1 , line ( '.' , win1 ) , col ( '.' , win1 ) ) )
call assert_equal ( {'col' : 36 , 'row' : 5 , 'endcol' : 36 , 'curscol' : 36 },
\ screenpos ( win2 , line ( '.' , win2 ) , col ( '.' , win2 ) ) )
wincmd h
diffthis
wincmd l
diffthis
normal ! 0
call assert_equal ( [
\ ' ipsum dolor sit amet, conset| Lorem ipsum dolor sit amet, |' ,
\ '~ |~ |' ,
\ ], ScreenLines ( [1 , 2 ], 62 ) )
call assert_equal ( {'col' : 3 , 'row' : 1 , 'endcol' : 3 , 'curscol' : 3 },
\ screenpos ( win1 , line ( '.' , win1 ) , col ( '.' , win1 ) ) )
call assert_equal ( {'col' : 34 , 'row' : 1 , 'endcol' : 34 , 'curscol' : 34 },
\ screenpos ( win2 , line ( '.' , win2 ) , col ( '.' , win2 ) ) )
normal ! $
call assert_equal ( [
\ ' voluptua. | diam voluptua. |' ,
\ '~ |~ |' ,
\ ], ScreenLines ( [1 , 2 ], 62 ) )
call assert_equal ( {'col' : 11 , 'row' : 1 , 'endcol' : 11 , 'curscol' : 11 },
\ screenpos ( win1 , line ( '.' , win1 ) , col ( '.' , win1 ) ) )
call assert_equal ( {'col' : 48 , 'row' : 1 , 'endcol' : 48 , 'curscol' : 48 },
\ screenpos ( win2 , line ( '.' , win2 ) , col ( '.' , win2 ) ) )
diffoff !
call assert_equal ( [
\ 'ipsum dolor sit amet, consetet|Lorem ipsum dolor sit amet, co|' ,
\ 'ur sadipscing elitr, sed diam |nsetetur sadipscing elitr, sed|' ,
\ 'nonumy eirmod tempor invidunt | diam nonumy eirmod tempor inv|' ,
\ 'ut labore et dolore magna aliq|idunt ut labore et dolore magn|' ,
\ 'uyam erat, sed diam voluptua. |a aliquyam erat, sed diam volu|' ,
\ '~ |ptua. |' ,
\ ], ScreenLines ( [1 , 6 ], 62 ) )
call assert_equal ( {'col' : 29 , 'row' : 5 , 'endcol' : 29 , 'curscol' : 29 },
\ screenpos ( win1 , line ( '.' , win1 ) , col ( '.' , win1 ) ) )
call assert_equal ( {'col' : 36 , 'row' : 6 , 'endcol' : 36 , 'curscol' : 36 },
\ screenpos ( win2 , line ( '.' , win2 ) , col ( '.' , win2 ) ) )
bwipe !
bwipe !
endfunc
2024-04-08 22:27:41 +02:00
" Ctrl-D reveals filler lines below the last line in the buffer.
func Test_diff_eob_halfpage ( )
2024-04-09 22:43:49 +02:00
new
2024-04-08 22:27:41 +02:00
call setline ( 1 , ['' ]- > repeat ( 10 ) + ['a' ])
diffthis
2024-04-09 22:43:49 +02:00
new
2024-04-08 22:27:41 +02:00
call setline ( 1 , ['' ]- > repeat ( 3 ) + ['a' , 'b' ])
diffthis
2024-04-09 22:43:49 +02:00
resize 5
2024-04-08 22:27:41 +02:00
wincmd j
2024-04-09 22:43:49 +02:00
resize 5
norm G
call assert_equal ( 7 , line ( 'w0' ) )
exe "norm! \<C-D>"
call assert_equal ( 8 , line ( 'w0' ) )
2024-04-08 22:27:41 +02:00
%bwipe !
endfunc
2024-09-26 16:19:42 +02:00
func Test_diff_overlapped_diff_blocks_will_be_merged ( )
CheckScreendump
let lines = < < trim END
func DiffExprStub ( )
let txt_in = readfile ( v :fname_in )
let txt_new = readfile ( v :fname_new )
if txt_in = = ["line1" ] && txt_new = = ["line2" ]
call writefile ( ["1c1" ], v :fname_out )
elseif txt_in = = readfile ( "Xdiin1" ) && txt_new = = readfile ( "Xdinew1" )
call writefile ( readfile ( "Xdiout1" ) , v :fname_out )
elseif txt_in = = readfile ( "Xdiin2" ) && txt_new = = readfile ( "Xdinew2" )
call writefile ( readfile ( "Xdiout2" ) , v :fname_out )
endif
endfunc
END
call writefile ( lines , 'XdiffSetup' , 'D' )
call WriteDiffFiles ( 0 , [], [])
let buf = RunVimInTerminal ( '-d -S XdiffSetup Xdifile1 Xdifile2' , {})
call term_sendkeys ( buf , ":set autoread\<CR>\<c-w>w:set autoread\<CR>\<c-w>w" )
call WriteDiffFiles ( buf , ["a" , "b" ], ["x" , "x" ])
call writefile ( ["a" , "b" ], "Xdiin1" )
call writefile ( ["x" , "x" ], "Xdinew1" )
call writefile ( ["1c1" , "2c2" ], "Xdiout1" )
call term_sendkeys ( buf , ":set diffexpr=DiffExprStub()\<CR>:" )
call VerifyBoth ( buf , "Test_diff_overlapped_2.01" , "" )
call term_sendkeys ( buf , ":set diffexpr&\<CR>:" )
call WriteDiffFiles ( buf , ["a" , "b" , "c" ], ["x" , "c" ])
call writefile ( ["a" , "b" , "c" ], "Xdiin1" )
call writefile ( ["x" , "c" ], "Xdinew1" )
call writefile ( ["1c1" , "2d1" ], "Xdiout1" )
call term_sendkeys ( buf , ":set diffexpr=DiffExprStub()\<CR>:" )
call VerifyBoth ( buf , "Test_diff_overlapped_2.02" , "" )
call term_sendkeys ( buf , ":set diffexpr&\<CR>:" )
call WriteDiffFiles ( buf , ["a" , "c" ], ["x" , "x" , "c" ])
call writefile ( ["a" , "c" ], "Xdiin1" )
call writefile ( ["x" , "x" , "c" ], "Xdinew1" )
call writefile ( ["1c1" , "1a2" ], "Xdiout1" )
call term_sendkeys ( buf , ":set diffexpr=DiffExprStub()\<CR>:" )
call VerifyBoth ( buf , "Test_diff_overlapped_2.03" , "" )
call term_sendkeys ( buf , ":set diffexpr&\<CR>:" )
call StopVimInTerminal ( buf )
wincmd c
call WriteDiffFiles3 ( 0 , [], [], [])
let buf = RunVimInTerminal ( '-d -S XdiffSetup Xdifile1 Xdifile2 Xdifile3' , {})
call term_sendkeys ( buf , ":set autoread\<CR>\<c-w>w:set autoread\<CR>\<c-w>w:set autoread\<CR>\<c-w>w" )
call WriteDiffFiles3 ( buf , ["a" , "b" , "c" ], ["a" , "x" , "c" ], ["y" , "b" , "c" ])
call VerifyBoth ( buf , "Test_diff_overlapped_3.01" , "" )
call WriteDiffFiles3 ( buf , ["a" , "b" , "c" ], ["a" , "x" , "c" ], ["a" , "y" , "c" ])
call VerifyBoth ( buf , "Test_diff_overlapped_3.02" , "" )
call WriteDiffFiles3 ( buf , ["a" , "b" , "c" ], ["a" , "x" , "c" ], ["a" , "b" , "y" ])
call VerifyBoth ( buf , "Test_diff_overlapped_3.03" , "" )
call WriteDiffFiles3 ( buf , ["a" , "b" , "c" ], ["a" , "x" , "c" ], ["y" , "y" , "c" ])
call VerifyBoth ( buf , "Test_diff_overlapped_3.04" , "" )
call WriteDiffFiles3 ( buf , ["a" , "b" , "c" ], ["a" , "x" , "c" ], ["a" , "y" , "y" ])
call VerifyBoth ( buf , "Test_diff_overlapped_3.05" , "" )
call WriteDiffFiles3 ( buf , ["a" , "b" , "c" ], ["a" , "x" , "c" ], ["y" , "y" , "y" ])
call VerifyBoth ( buf , "Test_diff_overlapped_3.06" , "" )
call WriteDiffFiles3 ( buf , ["a" , "b" , "c" ], ["a" , "x" , "x" ], ["y" , "y" , "c" ])
call VerifyBoth ( buf , "Test_diff_overlapped_3.07" , "" )
call WriteDiffFiles3 ( buf , ["a" , "b" , "c" ], ["x" , "x" , "c" ], ["a" , "y" , "y" ])
call VerifyBoth ( buf , "Test_diff_overlapped_3.08" , "" )
call WriteDiffFiles3 ( buf , ["a" , "b" , "c" , "d" , "e" ], ["a" , "x" , "c" , "x" , "e" ], ["y" , "y" , "y" , "d" , "e" ])
call VerifyBoth ( buf , "Test_diff_overlapped_3.09" , "" )
call WriteDiffFiles3 ( buf , ["a" , "b" , "c" , "d" , "e" ], ["a" , "x" , "c" , "x" , "e" ], ["y" , "y" , "y" , "y" , "e" ])
call VerifyBoth ( buf , "Test_diff_overlapped_3.10" , "" )
call WriteDiffFiles3 ( buf , ["a" , "b" , "c" , "d" , "e" ], ["a" , "x" , "c" , "x" , "e" ], ["y" , "y" , "y" , "y" , "y" ])
call VerifyBoth ( buf , "Test_diff_overlapped_3.11" , "" )
call WriteDiffFiles3 ( buf , ["a" , "b" , "c" , "d" , "e" ], ["a" , "x" , "c" , "x" , "e" ], ["a" , "y" , "y" , "d" , "e" ])
call VerifyBoth ( buf , "Test_diff_overlapped_3.12" , "" )
call WriteDiffFiles3 ( buf , ["a" , "b" , "c" , "d" , "e" ], ["a" , "x" , "c" , "x" , "e" ], ["a" , "y" , "y" , "y" , "e" ])
call VerifyBoth ( buf , "Test_diff_overlapped_3.13" , "" )
call WriteDiffFiles3 ( buf , ["a" , "b" , "c" , "d" , "e" ], ["a" , "x" , "c" , "x" , "e" ], ["a" , "y" , "y" , "y" , "y" ])
call VerifyBoth ( buf , "Test_diff_overlapped_3.14" , "" )
call WriteDiffFiles3 ( buf , ["a" , "b" , "c" , "d" , "e" ], ["a" , "x" , "c" , "x" , "e" ], ["a" , "b" , "y" , "d" , "e" ])
call VerifyBoth ( buf , "Test_diff_overlapped_3.15" , "" )
call WriteDiffFiles3 ( buf , ["a" , "b" , "c" , "d" , "e" ], ["a" , "x" , "c" , "x" , "e" ], ["a" , "b" , "y" , "y" , "e" ])
call VerifyBoth ( buf , "Test_diff_overlapped_3.16" , "" )
call WriteDiffFiles3 ( buf , ["a" , "b" , "c" , "d" , "e" ], ["a" , "x" , "c" , "x" , "e" ], ["a" , "b" , "y" , "y" , "y" ])
call VerifyBoth ( buf , "Test_diff_overlapped_3.17" , "" )
call WriteDiffFiles3 ( buf , ["a" , "b" ], ["x" , "b" ], ["y" , "y" ])
call writefile ( ["a" , "b" ], "Xdiin1" )
call writefile ( ["x" , "b" ], "Xdinew1" )
call writefile ( ["1c1" ], "Xdiout1" )
call writefile ( ["a" , "b" ], "Xdiin2" )
call writefile ( ["y" , "y" ], "Xdinew2" )
call writefile ( ["1c1" , "2c2" ], "Xdiout2" )
call term_sendkeys ( buf , ":set diffexpr=DiffExprStub()\<CR>:" )
call VerifyInternal ( buf , "Test_diff_overlapped_3.18" , "" )
call term_sendkeys ( buf , ":set diffexpr&\<CR>:" )
call WriteDiffFiles3 ( buf , ["a" , "b" , "c" , "d" ], ["x" , "b" , "x" , "d" ], ["y" , "y" , "c" , "d" ])
call writefile ( ["a" , "b" , "c" , "d" ], "Xdiin1" )
call writefile ( ["x" , "b" , "x" , "d" ], "Xdinew1" )
call writefile ( ["1c1" , "3c3" ], "Xdiout1" )
call writefile ( ["a" , "b" , "c" , "d" ], "Xdiin2" )
call writefile ( ["y" , "y" , "c" , "d" ], "Xdinew2" )
call writefile ( ["1c1" , "2c2" ], "Xdiout2" )
call term_sendkeys ( buf , ":set diffexpr=DiffExprStub()\<CR>:" )
call VerifyInternal ( buf , "Test_diff_overlapped_3.19" , "" )
call term_sendkeys ( buf , ":set diffexpr&\<CR>:" )
call WriteDiffFiles3 ( buf , ["a" , "b" , "c" , "d" ], ["x" , "b" , "x" , "d" ], ["y" , "y" , "y" , "d" ])
call writefile ( ["a" , "b" , "c" , "d" ], "Xdiin1" )
call writefile ( ["x" , "b" , "x" , "d" ], "Xdinew1" )
call writefile ( ["1c1" , "3c3" ], "Xdiout1" )
call writefile ( ["a" , "b" , "c" , "d" ], "Xdiin2" )
call writefile ( ["y" , "y" , "y" , "d" ], "Xdinew2" )
call writefile ( ["1c1" , "2,3c2,3" ], "Xdiout2" )
call term_sendkeys ( buf , ":set diffexpr=DiffExprStub()\<CR>:" )
call VerifyInternal ( buf , "Test_diff_overlapped_3.20" , "" )
call term_sendkeys ( buf , ":set diffexpr&\<CR>:" )
call WriteDiffFiles3 ( buf , ["a" , "b" , "c" , "d" ], ["x" , "b" , "x" , "d" ], ["y" , "y" , "y" , "y" ])
call writefile ( ["a" , "b" , "c" , "d" ], "Xdiin1" )
call writefile ( ["x" , "b" , "x" , "d" ], "Xdinew1" )
call writefile ( ["1c1" , "3c3" ], "Xdiout1" )
call writefile ( ["a" , "b" , "c" , "d" ], "Xdiin2" )
call writefile ( ["y" , "y" , "y" , "y" ], "Xdinew2" )
call writefile ( ["1c1" , "2,4c2,4" ], "Xdiout2" )
call term_sendkeys ( buf , ":set diffexpr=DiffExprStub()\<CR>:" )
call VerifyInternal ( buf , "Test_diff_overlapped_3.21" , "" )
call term_sendkeys ( buf , ":set diffexpr&\<CR>:" )
call WriteDiffFiles3 ( buf , ["a" , "b" , "c" ], ["a" , "x" , "c" ], ["b" , "c" ])
call VerifyBoth ( buf , "Test_diff_overlapped_3.22" , "" )
call WriteDiffFiles3 ( buf , ["a" , "b" , "c" ], ["a" , "x" , "c" ], ["c" ])
call VerifyBoth ( buf , "Test_diff_overlapped_3.23" , "" )
call WriteDiffFiles3 ( buf , ["a" , "b" , "c" ], ["a" , "x" , "c" ], [])
call VerifyBoth ( buf , "Test_diff_overlapped_3.24" , "" )
call WriteDiffFiles3 ( buf , ["a" , "b" , "c" ], ["a" , "x" , "c" ], ["a" , "c" ])
call VerifyBoth ( buf , "Test_diff_overlapped_3.25" , "" )
call WriteDiffFiles3 ( buf , ["a" , "b" , "c" ], ["a" , "x" , "c" ], ["a" ])
call VerifyBoth ( buf , "Test_diff_overlapped_3.26" , "" )
call WriteDiffFiles3 ( buf , ["a" , "b" , "c" ], ["a" , "x" , "c" ], ["b" ])
call VerifyBoth ( buf , "Test_diff_overlapped_3.27" , "" )
call WriteDiffFiles3 ( buf , ["a" , "b" , "c" , "d" , "e" ], ["a" , "x" , "c" , "x" , "e" ], ["d" , "e" ])
call VerifyBoth ( buf , "Test_diff_overlapped_3.28" , "" )
call WriteDiffFiles3 ( buf , ["a" , "b" , "c" , "d" , "e" ], ["a" , "x" , "c" , "x" , "e" ], ["e" ])
call VerifyBoth ( buf , "Test_diff_overlapped_3.29" , "" )
call WriteDiffFiles3 ( buf , ["a" , "b" , "c" , "d" , "e" ], ["a" , "x" , "c" , "x" , "e" ], ["a" , "d" , "e" ])
call VerifyBoth ( buf , "Test_diff_overlapped_3.30" , "" )
call WriteDiffFiles3 ( buf , ["a" , "b" , "c" , "d" , "e" ], ["a" , "x" , "c" , "x" , "e" ], ["a" , "e" ])
call VerifyBoth ( buf , "Test_diff_overlapped_3.31" , "" )
call WriteDiffFiles3 ( buf , ["a" , "b" , "c" , "d" , "e" ], ["a" , "x" , "c" , "x" , "e" ], ["a" ])
call VerifyBoth ( buf , "Test_diff_overlapped_3.32" , "" )
call WriteDiffFiles3 ( buf , ["a" , "b" , "c" , "d" , "e" ], ["a" , "x" , "c" , "x" , "e" ], ["a" , "b" , "d" , "e" ])
call VerifyBoth ( buf , "Test_diff_overlapped_3.33" , "" )
call WriteDiffFiles3 ( buf , ["a" , "b" , "c" , "d" , "e" ], ["a" , "x" , "c" , "x" , "e" ], ["a" , "b" , "e" ])
call VerifyBoth ( buf , "Test_diff_overlapped_3.34" , "" )
call WriteDiffFiles3 ( buf , ["a" , "b" , "c" , "d" , "e" ], ["a" , "x" , "c" , "x" , "e" ], ["a" , "b" ])
call VerifyBoth ( buf , "Test_diff_overlapped_3.35" , "" )
call WriteDiffFiles3 ( buf , ["a" , "b" , "c" ], ["a" , "x" , "c" ], ["a" , "y" , "b" , "c" ])
call VerifyBoth ( buf , "Test_diff_overlapped_3.36" , "" )
call WriteDiffFiles3 ( buf , ["a" , "b" , "c" ], ["a" , "x" , "c" ], ["a" , "b" , "y" , "c" ])
call VerifyBoth ( buf , "Test_diff_overlapped_3.37" , "" )
2025-01-15 18:36:43 +01:00
call WriteDiffFiles3 ( buf , ["a" , "b" , "c" ], ["d" , "e" ], ["b" , "f" ])
call VerifyBoth ( buf , "Test_diff_overlapped_3.38" , "" )
call WriteDiffFiles3 ( buf , ["a" , "b" , "c" ], ["d" , "e" ], ["b" ])
call VerifyBoth ( buf , "Test_diff_overlapped_3.39" , "" )
2025-03-02 22:05:37 +01:00
" File 3 overlaps twice, 2nd overlap completely within the existing block.
call WriteDiffFiles3 ( buf , ["foo" , "a" , "b" , "c" , "bar" ], ["foo" , "w" , "x" , "y" , "z" , "bar" ], ["foo" , "1" , "a" , "b" , "2" , "bar" ])
call VerifyBoth ( buf , "Test_diff_overlapped_3.40" , "" )
" File 3 overlaps twice, 2nd overlap extends beyond existing block on new
" side. Make sure we don't over-extend the range and hit 'bar'.
call WriteDiffFiles3 ( buf , ["foo" , "a" , "b" , "c" , "d" , "bar" ], ["foo" , "w" , "x" , "y" , "z" , "u" , "bar" ], ["foo" , "1" , "a" , "b" , "2" , "d" , "bar" ])
call VerifyBoth ( buf , "Test_diff_overlapped_3.41" , "" )
" Chained overlaps. File 3's 2nd overlap spans two diff blocks and is longer
" than the 2nd one.
call WriteDiffFiles3 ( buf , ["foo" , "a" , "b" , "c" , "d" , "e" , "f" , "bar" ], ["foo" , "w" , "x" , "y" , "z" , "e" , "u" , "bar" ], ["foo" , "1" , "b" , "2" , "3" , "d" , "4" , "f" , "bar" ])
call VerifyBoth ( buf , "Test_diff_overlapped_3.42" , "" )
" File 3 has 2 overlaps. An add and a delete. First overlap's expansion hits
" the 2nd one. Make sure we adjust the diff block to have fewer lines.
call WriteDiffFiles3 ( buf , ["foo" , "a" , "b" , "bar" ], ["foo" , "x" , "y" , "bar" ], ["foo" , "1" , "a" , "bar" ])
call VerifyBoth ( buf , "Test_diff_overlapped_3.43" , "" )
" File 3 has 2 overlaps. An add and another add. First overlap's expansion hits
" the 2nd one. Make sure we adjust the diff block to have more lines.
call WriteDiffFiles3 ( buf , ["foo" , "a" , "b" , "c" , "d" , "bar" ], ["foo" , "w" , "x" , "y" , "z" , "u" , "bar" ], ["foo" , "1" , "a" , "b" , "3" , "4" , "d" , "bar" ])
call VerifyBoth ( buf , "Test_diff_overlapped_3.44" , "" )
2024-09-26 16:19:42 +02:00
call StopVimInTerminal ( buf )
endfunc
2024-11-10 20:26:12 +01:00
" switching windows in diff mode caused an unnecessary scroll
2024-10-29 20:29:04 +01:00
func Test_diff_topline_noscroll ( )
CheckScreendump
let content = < < trim END
call setline ( 1 , range ( 1 , 60 ) )
vnew
call setline ( 1 , range ( 1 , 10 ) + range ( 50 , 60 ) )
windo diffthis
norm ! G
exe "norm! 30\<C-y>"
END
call writefile ( content , 'Xcontent' , 'D' )
let buf = RunVimInTerminal ( '-S Xcontent' , {'rows' : 20 })
call VerifyScreenDump ( buf , 'Test_diff_topline_1' , {})
call term_sendkeys ( buf , ":echo line('w0', 1001)\<cr>" )
call term_wait ( buf )
call VerifyScreenDump ( buf , 'Test_diff_topline_2' , {})
call term_sendkeys ( buf , "\<C-W>p" )
call term_wait ( buf )
call VerifyScreenDump ( buf , 'Test_diff_topline_3' , {})
call term_sendkeys ( buf , "\<C-W>p" )
call term_wait ( buf )
call VerifyScreenDump ( buf , 'Test_diff_topline_4' , {})
call StopVimInTerminal ( buf )
endfunc
2025-01-12 09:58:00 +01:00
func Test_diffget_diffput_linematch ( )
CheckScreendump
call delete ( '.Xdifile1.swp' )
call delete ( '.Xdifile2.swp' )
call WriteDiffFiles ( 0 , [], [])
let buf = RunVimInTerminal ( '-d Xdifile1 Xdifile2' , {})
call term_sendkeys ( buf , ":set autoread\<CR>\<c-w>w:set autoread\<CR>\<c-w>w" )
" enable linematch
call term_sendkeys ( buf , ":set diffopt+=linematch:30\<CR>" )
call WriteDiffFiles ( buf , ['' ,
\ 'common line' ,
\ 'common line' ,
\ '' ,
\ 'ABCabc' ,
\ 'ABCabc' ,
\ 'ABCabc' ,
\ 'ABCabc' ,
\ 'common line' ,
\ 'common line' ,
\ 'common line' ,
\ 'something' ],
\ ['' ,
\ 'common line' ,
\ 'common line' ,
\ '' ,
\ 'DEFabc' ,
\ 'xyz' ,
\ 'xyz' ,
\ 'xyz' ,
\ 'DEFabc' ,
\ 'DEFabc' ,
\ 'DEFabc' ,
\ 'common line' ,
\ 'common line' ,
\ 'DEF' ,
\ 'common line' ,
\ 'DEF' ,
\ 'something' ])
call VerifyScreenDump ( buf , 'Test_diff_get_put_linematch_1' , {})
" get from window 1 from line 5 to 9
call term_sendkeys ( buf , "1\<c-w>w" )
call term_sendkeys ( buf , ":5,9diffget\<CR>" )
call VerifyScreenDump ( buf , 'Test_diff_get_put_linematch_2' , {})
" undo the last diffget
call term_sendkeys ( buf , "u" )
" get from window 2 from line 5 to 10
call term_sendkeys ( buf , "2\<c-w>w" )
call term_sendkeys ( buf , ":5,10diffget\<CR>" )
call VerifyScreenDump ( buf , 'Test_diff_get_put_linematch_3' , {})
" undo the last diffget
call term_sendkeys ( buf , "u" )
" get all from window 2
call term_sendkeys ( buf , "2\<c-w>w" )
call term_sendkeys ( buf , ":4,17diffget\<CR>" )
call VerifyScreenDump ( buf , 'Test_diff_get_put_linematch_4' , {})
" undo the last diffget
call term_sendkeys ( buf , "u" )
" get all from window 1
call term_sendkeys ( buf , "1\<c-w>w" )
call term_sendkeys ( buf , ":4,12diffget\<CR>" )
call VerifyScreenDump ( buf , 'Test_diff_get_put_linematch_5' , {})
" undo the last diffget
call term_sendkeys ( buf , "u" )
" get from window 1 using do 1 line 5
call term_sendkeys ( buf , "1\<c-w>w" )
call term_sendkeys ( buf , "5gg" )
call term_sendkeys ( buf , ":diffget\<CR>" )
call VerifyScreenDump ( buf , 'Test_diff_get_put_linematch_6' , {})
" undo the last diffget
call term_sendkeys ( buf , "u" )
" get from window 1 using do 2 line 6
call term_sendkeys ( buf , "1\<c-w>w" )
call term_sendkeys ( buf , "6gg" )
call term_sendkeys ( buf , ":diffget\<CR>" )
call VerifyScreenDump ( buf , 'Test_diff_get_put_linematch_7' , {})
" undo the last diffget
call term_sendkeys ( buf , "u" )
" get from window 1 using do 2 line 7
call term_sendkeys ( buf , "1\<c-w>w" )
call term_sendkeys ( buf , "7gg" )
call term_sendkeys ( buf , ":diffget\<CR>" )
call VerifyScreenDump ( buf , 'Test_diff_get_put_linematch_8' , {})
" undo the last diffget
call term_sendkeys ( buf , "u" )
" get from window 1 using do 2 line 11
call term_sendkeys ( buf , "1\<c-w>w" )
call term_sendkeys ( buf , "11gg" )
call term_sendkeys ( buf , ":diffget\<CR>" )
call VerifyScreenDump ( buf , 'Test_diff_get_put_linematch_9' , {})
" undo the last diffget
call term_sendkeys ( buf , "u" )
" get from window 1 using do 2 line 12
call term_sendkeys ( buf , "1\<c-w>w" )
call term_sendkeys ( buf , "12gg" )
call term_sendkeys ( buf , ":diffget\<CR>" )
call VerifyScreenDump ( buf , 'Test_diff_get_put_linematch_10' , {})
" undo the last diffget
call term_sendkeys ( buf , "u" )
" put from window 1 using dp 1 line 5
call term_sendkeys ( buf , "1\<c-w>w" )
call term_sendkeys ( buf , "5gg" )
call term_sendkeys ( buf , ":diffput\<CR>" )
call VerifyScreenDump ( buf , 'Test_diff_get_put_linematch_11' , {})
" undo the last diffput
call term_sendkeys ( buf , "2\<c-w>w" )
call term_sendkeys ( buf , "u" )
" put from window 1 using dp 2 line 6
call term_sendkeys ( buf , "1\<c-w>w" )
call term_sendkeys ( buf , "6gg" )
call term_sendkeys ( buf , ":diffput\<CR>" )
call VerifyScreenDump ( buf , 'Test_diff_get_put_linematch_12' , {})
" undo the last diffput
call term_sendkeys ( buf , "2\<c-w>w" )
call term_sendkeys ( buf , "u" )
" put from window 1 using dp 2 line 7
call term_sendkeys ( buf , "1\<c-w>w" )
call term_sendkeys ( buf , "7gg" )
call term_sendkeys ( buf , ":diffput\<CR>" )
call VerifyScreenDump ( buf , 'Test_diff_get_put_linematch_13' , {})
" undo the last diffput
call term_sendkeys ( buf , "2\<c-w>w" )
call term_sendkeys ( buf , "u" )
" put from window 1 using dp 2 line 11
call term_sendkeys ( buf , "1\<c-w>w" )
call term_sendkeys ( buf , "11gg" )
call term_sendkeys ( buf , ":diffput\<CR>" )
call VerifyScreenDump ( buf , 'Test_diff_get_put_linematch_14' , {})
" undo the last diffput
call term_sendkeys ( buf , "2\<c-w>w" )
call term_sendkeys ( buf , "u" )
" put from window 1 using dp 2 line 12
call term_sendkeys ( buf , "1\<c-w>w" )
call term_sendkeys ( buf , "12gg" )
call term_sendkeys ( buf , ":diffput\<CR>" )
call VerifyScreenDump ( buf , 'Test_diff_get_put_linematch_15' , {})
" undo the last diffput
call term_sendkeys ( buf , "2\<c-w>w" )
call term_sendkeys ( buf , "u" )
" put from window 2 using dp line 6
call term_sendkeys ( buf , "2\<c-w>w" )
call term_sendkeys ( buf , "6gg" )
call term_sendkeys ( buf , ":diffput\<CR>" )
call VerifyScreenDump ( buf , 'Test_diff_get_put_linematch_16' , {})
" undo the last diffput
call term_sendkeys ( buf , "1\<c-w>w" )
call term_sendkeys ( buf , "u" )
" put from window 2 using dp line 8
call term_sendkeys ( buf , "2\<c-w>w" )
call term_sendkeys ( buf , "8gg" )
call term_sendkeys ( buf , ":diffput\<CR>" )
call VerifyScreenDump ( buf , 'Test_diff_get_put_linematch_17' , {})
" undo the last diffput
call term_sendkeys ( buf , "1\<c-w>w" )
call term_sendkeys ( buf , "u" )
" put from window 2 using dp line 9
call term_sendkeys ( buf , "2\<c-w>w" )
call term_sendkeys ( buf , "9gg" )
call term_sendkeys ( buf , ":diffput\<CR>" )
call VerifyScreenDump ( buf , 'Test_diff_get_put_linematch_18' , {})
" undo the last diffput
call term_sendkeys ( buf , "1\<c-w>w" )
call term_sendkeys ( buf , "u" )
" put from window 2 using dp line 17
call term_sendkeys ( buf , "2\<c-w>w" )
call term_sendkeys ( buf , "17gg" )
call term_sendkeys ( buf , ":diffput\<CR>" )
call VerifyScreenDump ( buf , 'Test_diff_get_put_linematch_19' , {})
2025-01-17 13:37:35 +01:00
" clean up
call StopVimInTerminal ( buf )
2025-01-12 09:58:00 +01:00
endfunc
func Test_linematch_diff ( )
CheckScreendump
call delete ( '.Xdifile1.swp' )
call delete ( '.Xdifile2.swp' )
call WriteDiffFiles ( 0 , [], [])
let buf = RunVimInTerminal ( '-d Xdifile1 Xdifile2' , {})
call term_sendkeys ( buf , ":set autoread\<CR>\<c-w>w:set autoread\<CR>\<c-w>w" )
" enable linematch
call term_sendkeys ( buf , ":set diffopt+=linematch:30\<CR>" )
call WriteDiffFiles ( buf , ['// abc d?' ,
\ '// d?' ,
\ '// d?' ],
\ ['!' ,
\ 'abc d!' ,
\ 'd!' ])
call VerifyScreenDump ( buf , 'Test_linematch_diff1' , {})
2025-01-17 13:37:35 +01:00
" clean up
call StopVimInTerminal ( buf )
2025-01-12 09:58:00 +01:00
endfunc
func Test_linematch_diff_iwhite ( )
CheckScreendump
call delete ( '.Xdifile1.swp' )
call delete ( '.Xdifile2.swp' )
call WriteDiffFiles ( 0 , [], [])
let buf = RunVimInTerminal ( '-d Xdifile1 Xdifile2' , {})
call term_sendkeys ( buf , ":set autoread\<CR>\<c-w>w:set autoread\<CR>\<c-w>w" )
" setup a diff with 2 files and set linematch:30, with ignore white
call term_sendkeys ( buf , ":set diffopt+=linematch:30\<CR>" )
call WriteDiffFiles ( buf , ['void testFunction () {' ,
\ ' for (int i = 0; i < 10; i++) {' ,
\ ' for (int j = 0; j < 10; j++) {' ,
\ ' }' ,
\ ' }' ,
\ '}' ],
\ ['void testFunction () {' ,
\ ' // for (int j = 0; j < 10; i++) {' ,
\ ' // }' ,
\ '}' ])
call VerifyScreenDump ( buf , 'Test_linematch_diff_iwhite1' , {})
call term_sendkeys ( buf , ":set diffopt+=iwhiteall\<CR>" )
call VerifyScreenDump ( buf , 'Test_linematch_diff_iwhite2' , {})
2025-01-17 13:37:35 +01:00
" clean up
call StopVimInTerminal ( buf )
2025-01-12 09:58:00 +01:00
endfunc
func Test_linematch_diff_grouping ( )
CheckScreendump
call delete ( '.Xdifile1.swp' )
call delete ( '.Xdifile2.swp' )
call WriteDiffFiles ( 0 , [], [])
let buf = RunVimInTerminal ( '-d Xdifile1 Xdifile2' , {})
call term_sendkeys ( buf , ":set autoread\<CR>\<c-w>w:set autoread\<CR>\<c-w>w" )
" a diff that would result in multiple groups before grouping optimization
call term_sendkeys ( buf , ":set diffopt+=linematch:30\<CR>" )
call WriteDiffFiles ( buf , ['!A' ,
\ '!B' ,
\ '!C' ],
\ ['?Z' ,
\ '?A' ,
\ '?B' ,
\ '?C' ,
\ '?A' ,
\ '?B' ,
\ '?B' ,
\ '?C' ])
call VerifyScreenDump ( buf , 'Test_linematch_diff_grouping1' , {})
call WriteDiffFiles ( buf , ['!A' ,
\ '!B' ,
\ '!C' ],
\ ['?A' ,
\ '?Z' ,
\ '?B' ,
\ '?C' ,
\ '?A' ,
\ '?B' ,
\ '?C' ,
\ '?C' ])
call VerifyScreenDump ( buf , 'Test_linematch_diff_grouping2' , {})
2025-01-17 13:37:35 +01:00
" clean up
call StopVimInTerminal ( buf )
2025-01-12 09:58:00 +01:00
endfunc
func Test_linematch_diff_scroll ( )
CheckScreendump
call delete ( '.Xdifile1.swp' )
call delete ( '.Xdifile2.swp' )
call WriteDiffFiles ( 0 , [], [])
let buf = RunVimInTerminal ( '-d Xdifile1 Xdifile2' , {})
call term_sendkeys ( buf , ":set autoread\<CR>\<c-w>w:set autoread\<CR>\<c-w>w" )
" a diff that would result in multiple groups before grouping optimization
call term_sendkeys ( buf , ":set diffopt+=linematch:30\<CR>" )
call WriteDiffFiles ( buf , ['!A' ,
\ '!B' ,
\ '!C' ],
\ ['?A' ,
\ '?Z' ,
\ '?B' ,
\ '?C' ,
\ '?A' ,
\ '?B' ,
\ '?C' ,
\ '?C' ])
" scroll down to show calculation of top fill and scroll to correct line in
" both windows
call VerifyScreenDump ( buf , 'Test_linematch_diff_grouping_scroll0' , {})
call term_sendkeys ( buf , "3\<c-e>" )
call VerifyScreenDump ( buf , 'Test_linematch_diff_grouping_scroll1' , {})
call term_sendkeys ( buf , "3\<c-e>" )
call VerifyScreenDump ( buf , 'Test_linematch_diff_grouping_scroll2' , {})
2025-01-17 13:37:35 +01:00
" clean up
call StopVimInTerminal ( buf )
2025-01-12 09:58:00 +01:00
endfunc
func Test_linematch_line_limit_exceeded ( )
CheckScreendump
call delete ( '.Xdifile1.swp' )
call delete ( '.Xdifile2.swp' )
call WriteDiffFiles ( 0 , [], [])
let buf = RunVimInTerminal ( '-d Xdifile1 Xdifile2' , {})
call term_sendkeys ( buf , ":set autoread\<CR>\<c-w>w:set autoread\<CR>\<c-w>w" )
call term_sendkeys ( buf , ":set diffopt+=linematch:10\<CR>" )
" a diff block will not be aligned with linematch because it's contents
" exceed 10 lines
call WriteDiffFiles ( buf ,
\ ['common line' ,
\ 'HIL' ,
\ '' ,
\ 'aABCabc' ,
\ 'aABCabc' ,
\ 'aABCabc' ,
\ 'aABCabc' ,
\ 'common line' ,
\ 'HIL' ,
\ 'common line' ,
\ 'something' ],
\ ['common line' ,
\ 'DEF' ,
\ 'GHI' ,
\ 'something' ,
\ '' ,
\ 'aDEFabc' ,
\ 'xyz' ,
\ 'xyz' ,
\ 'xyz' ,
\ 'aDEFabc' ,
\ 'aDEFabc' ,
\ 'aDEFabc' ,
\ 'common line' ,
\ 'DEF' ,
\ 'GHI' ,
\ 'something else' ,
\ 'common line' ,
\ 'something' ])
call VerifyScreenDump ( buf , 'Test_linematch_line_limit_exceeded1' , {})
" after increasing the count to 30, the limit is not exceeded, and the
" alignment algorithm will run on the largest diff block here
call term_sendkeys ( buf , ":set diffopt+=linematch:30\<CR>" )
call VerifyScreenDump ( buf , 'Test_linematch_line_limit_exceeded2' , {})
2025-01-17 13:37:35 +01:00
" clean up
call StopVimInTerminal ( buf )
2025-01-12 09:58:00 +01:00
endfunc
func Test_linematch_3diffs ( )
CheckScreendump
call delete ( '.Xdifile1.swp' )
call delete ( '.Xdifile2.swp' )
call delete ( '.Xdifile3.swp' )
call WriteDiffFiles3 ( 0 , [], [], [])
let buf = RunVimInTerminal ( '-d Xdifile1 Xdifile2 Xdifile3' , {})
call term_sendkeys ( buf , "1\<c-w>w:set autoread\<CR>" )
call term_sendkeys ( buf , "2\<c-w>w:set autoread\<CR>" )
call term_sendkeys ( buf , "3\<c-w>w:set autoread\<CR>" )
call term_sendkeys ( buf , ":set diffopt+=linematch:30\<CR>" )
call WriteDiffFiles3 ( buf ,
\ ["" ,
\ " common line" ,
\ " AAA" ,
\ " AAA" ,
\ " AAA" ],
\ ["" ,
\ " common line" ,
\ " <<<<<<< HEAD" ,
\ " AAA" ,
\ " AAA" ,
\ " AAA" ,
\ " =======" ,
\ " BBB" ,
\ " BBB" ,
\ " BBB" ,
\ " >>>>>>> branch1" ],
\ ["" ,
\ " common line" ,
\ " BBB" ,
\ " BBB" ,
\ " BBB" ])
call VerifyScreenDump ( buf , 'Test_linematch_3diffs1' , {})
2025-01-17 13:37:35 +01:00
" clean up
call StopVimInTerminal ( buf )
endfunc
2025-01-12 09:58:00 +01:00
2025-01-17 13:37:35 +01:00
" this used to access invalid memory
func Test_linematch_3diffs_sanity_check ( )
CheckScreendump
call delete ( '.Xfile_linematch1.swp' )
call delete ( '.Xfile_linematch2.swp' )
call delete ( '.Xfile_linematch3.swp' )
let lines = < < trim END
set diffopt + = linematch :60
call feedkeys ( "Aq\<esc>" )
call feedkeys ( "GAklm\<esc>" )
call feedkeys ( "o" )
END
call writefile ( lines , 'Xlinematch_3diffs.vim' , 'D' )
call writefile ( ['abcd' , 'def' , 'hij' ], 'Xfile_linematch1' , 'D' )
call writefile ( ['defq' , 'hijk' , 'nopq' ], 'Xfile_linematch2' , 'D' )
call writefile ( ['hijklm' , 'nopqr' , 'stuv' ], 'Xfile_linematch3' , 'D' )
call WriteDiffFiles3 ( 0 , [], [], [])
let buf = RunVimInTerminal ( '-d -S Xlinematch_3diffs.vim Xfile_linematch1 Xfile_linematch2 Xfile_linematch3' , {})
call VerifyScreenDump ( buf , 'Test_linematch_3diffs2' , {})
" clean up
call StopVimInTerminal ( buf )
2025-01-12 09:58:00 +01:00
endfunc
2020-03-18 19:32:26 +01:00
" vim: shiftwidth=2 sts=2 expandtab