blob: b62266bb8aa65206b760c835e1b7cf4c11a5f74b [file] [log] [blame]
Bram Moolenaar42093c02016-07-30 16:16:54 +02001" Tests for diff mode
Bram Moolenaar6d91bcb2020-08-12 18:50:36 +02002
Bram Moolenaare828b762018-09-10 17:51:58 +02003source shared.vim
4source screendump.vim
Bram Moolenaar3c8ee622019-08-03 22:55:50 +02005source check.vim
zeertzjq9e7f1fc2024-03-16 09:40:22 +01006source view_util.vim
Bram Moolenaar42093c02016-07-30 16:16:54 +02007
8func Test_diff_fold_sync()
9 enew!
Bram Moolenaare8fa05b2018-09-16 15:48:06 +020010 let g:update_count = 0
11 au DiffUpdated * let g:update_count += 1
12
Bram Moolenaar42093c02016-07-30 16:16:54 +020013 let l = range(50)
14 call setline(1, l)
15 diffthis
16 let winone = win_getid()
17 new
18 let l[25] = 'diff'
19 call setline(1, l)
20 diffthis
21 let wintwo = win_getid()
22 " line 15 is inside the closed fold
23 call assert_equal(19, foldclosedend(10))
24 call win_gotoid(winone)
25 call assert_equal(19, foldclosedend(10))
26 " open the fold
27 normal zv
28 call assert_equal(-1, foldclosedend(10))
29 " fold in other window must have opened too
30 call win_gotoid(wintwo)
31 call assert_equal(-1, foldclosedend(10))
32
33 " cursor position is in sync
34 normal 23G
35 call win_gotoid(winone)
36 call assert_equal(23, getcurpos()[1])
37
Bram Moolenaarf65cc662022-06-26 18:17:50 +010038 " depending on how redraw is done DiffUpdated may be triggered once or twice
39 call assert_inrange(1, 2, g:update_count)
Bram Moolenaare8fa05b2018-09-16 15:48:06 +020040 au! DiffUpdated
41
Bram Moolenaar42093c02016-07-30 16:16:54 +020042 windo diffoff
43 close!
44 set nomodified
45endfunc
46
47func Test_vert_split()
Bram Moolenaare828b762018-09-10 17:51:58 +020048 set diffopt=filler
49 call Common_vert_split()
50 set diffopt&
51endfunc
52
53func Test_vert_split_internal()
54 set diffopt=internal,filler
55 call Common_vert_split()
56 set diffopt&
57endfunc
58
59func Common_vert_split()
Bram Moolenaar42093c02016-07-30 16:16:54 +020060 " Disable the title to avoid xterm keeping the wrong one.
61 set notitle noicon
62 new
63 let l = ['1 aa', '2 bb', '3 cc', '4 dd', '5 ee']
64 call setline(1, l)
65 w! Xtest
66 normal dd
67 $
68 put
69 normal kkrXoxxx
70 w! Xtest2
71 file Nop
72 normal ggoyyyjjjozzzz
73 set foldmethod=marker foldcolumn=4
74 call assert_equal(0, &diff)
75 call assert_equal('marker', &foldmethod)
76 call assert_equal(4, &foldcolumn)
77 call assert_equal(0, &scrollbind)
78 call assert_equal(0, &cursorbind)
79 call assert_equal(1, &wrap)
80
81 vert diffsplit Xtest
82 vert diffsplit Xtest2
83 call assert_equal(1, &diff)
84 call assert_equal('diff', &foldmethod)
85 call assert_equal(2, &foldcolumn)
86 call assert_equal(1, &scrollbind)
87 call assert_equal(1, &cursorbind)
88 call assert_equal(0, &wrap)
89
90 let diff_fdm = &fdm
91 let diff_fdc = &fdc
92 " repeat entering diff mode here to see if this saves the wrong settings
93 diffthis
94 " jump to second window for a moment to have filler line appear at start of
95 " first window
96 wincmd w
97 normal gg
98 wincmd p
99 normal gg
100 call assert_equal(2, winline())
101 normal j
102 call assert_equal(4, winline())
103 normal j
104 call assert_equal(5, winline())
105 normal j
106 call assert_equal(6, winline())
107 normal j
108 call assert_equal(8, winline())
109 normal j
110 call assert_equal(9, winline())
111
112 wincmd w
113 normal gg
114 call assert_equal(1, winline())
115 normal j
116 call assert_equal(2, winline())
117 normal j
118 call assert_equal(4, winline())
119 normal j
120 call assert_equal(5, winline())
121 normal j
122 call assert_equal(8, winline())
123
124 wincmd w
125 normal gg
126 call assert_equal(2, winline())
127 normal j
128 call assert_equal(3, winline())
129 normal j
130 call assert_equal(4, winline())
131 normal j
132 call assert_equal(5, winline())
133 normal j
134 call assert_equal(6, winline())
135 normal j
136 call assert_equal(7, winline())
137 normal j
138 call assert_equal(8, winline())
139
140 " Test diffoff
141 diffoff!
zeertzjq5fd6ab82022-08-17 12:09:45 +0100142 1wincmd w
Bram Moolenaar42093c02016-07-30 16:16:54 +0200143 let &diff = 1
144 let &fdm = diff_fdm
145 let &fdc = diff_fdc
146 4wincmd w
147 diffoff!
148 1wincmd w
149 call assert_equal(0, &diff)
150 call assert_equal('marker', &foldmethod)
151 call assert_equal(4, &foldcolumn)
152 call assert_equal(0, &scrollbind)
153 call assert_equal(0, &cursorbind)
154 call assert_equal(1, &wrap)
155
156 wincmd w
157 call assert_equal(0, &diff)
158 call assert_equal('marker', &foldmethod)
159 call assert_equal(4, &foldcolumn)
160 call assert_equal(0, &scrollbind)
161 call assert_equal(0, &cursorbind)
162 call assert_equal(1, &wrap)
163
164 wincmd w
165 call assert_equal(0, &diff)
166 call assert_equal('marker', &foldmethod)
167 call assert_equal(4, &foldcolumn)
168 call assert_equal(0, &scrollbind)
169 call assert_equal(0, &cursorbind)
170 call assert_equal(1, &wrap)
171
Bram Moolenaar623cf882016-07-30 16:36:01 +0200172 call delete('Xtest')
173 call delete('Xtest2')
Bram Moolenaar42093c02016-07-30 16:16:54 +0200174 windo bw!
175endfunc
176
177func Test_filler_lines()
178 " Test that diffing shows correct filler lines
179 enew!
180 put =range(4,10)
181 1d _
182 vnew
183 put =range(1,10)
184 1d _
185 windo diffthis
186 wincmd h
187 call assert_equal(1, line('w0'))
188 unlet! diff_fdm diff_fdc
Bram Moolenaar90d121f2016-07-30 19:11:25 +0200189 windo diffoff
190 bwipe!
191 enew!
192endfunc
Bram Moolenaar42093c02016-07-30 16:16:54 +0200193
Bram Moolenaar90d121f2016-07-30 19:11:25 +0200194func Test_diffget_diffput()
195 enew!
196 let l = range(50)
197 call setline(1, l)
198 call assert_fails('diffget', 'E99:')
199 diffthis
200 call assert_fails('diffget', 'E100:')
201 new
202 let l[10] = 'one'
203 let l[20] = 'two'
204 let l[30] = 'three'
205 let l[40] = 'four'
206 call setline(1, l)
207 diffthis
208 call assert_equal('one', getline(11))
209 11diffget
210 call assert_equal('10', getline(11))
211 21diffput
212 wincmd w
213 call assert_equal('two', getline(21))
214 normal 31Gdo
215 call assert_equal('three', getline(31))
216 call assert_equal('40', getline(41))
217 normal 41Gdp
218 wincmd w
219 call assert_equal('40', getline(41))
220 new
221 diffthis
222 call assert_fails('diffget', 'E101:')
223
224 windo diffoff
Bram Moolenaar79a213d2017-05-16 13:15:18 +0200225 %bwipe!
226endfunc
227
Bram Moolenaar5f57bdc2018-10-25 17:52:23 +0200228" Test putting two changes from one buffer to another
229func Test_diffput_two()
230 new a
231 let win_a = win_getid()
232 call setline(1, range(1, 10))
233 diffthis
234 new b
235 let win_b = win_getid()
236 call setline(1, range(1, 10))
237 8del
238 5del
239 diffthis
240 call win_gotoid(win_a)
241 %diffput
242 call win_gotoid(win_b)
243 call assert_equal(map(range(1, 10), 'string(v:val)'), getline(1, '$'))
244 bwipe! a
245 bwipe! b
246endfunc
247
Yegappan Lakshmanan30443242021-06-10 21:52:15 +0200248" Test for :diffget/:diffput with a range that is inside a diff chunk
249func Test_diffget_diffput_range()
250 call setline(1, range(1, 10))
251 new
252 call setline(1, range(11, 20))
253 windo diffthis
254 3,5diffget
255 call assert_equal(['13', '14', '15'], getline(3, 5))
256 call setline(1, range(1, 10))
257 4,8diffput
258 wincmd p
259 call assert_equal(['13', '4', '5', '6', '7', '8', '19'], getline(3, 9))
260 %bw!
261endfunc
262
263" Test for :diffget/:diffput with an empty buffer and a non-empty buffer
264func Test_diffget_diffput_empty_buffer()
265 %d _
266 new
267 call setline(1, 'one')
268 windo diffthis
269 diffget
270 call assert_equal(['one'], getline(1, '$'))
271 %d _
272 diffput
273 wincmd p
274 call assert_equal([''], getline(1, '$'))
275 %bw!
276endfunc
277
Bram Moolenaarefcc3292019-12-30 21:59:03 +0100278" :diffput and :diffget completes names of buffers which
Dominique Pelle923dce22021-11-21 11:36:04 +0000279" are in diff mode and which are different than current buffer.
Bram Moolenaarefcc3292019-12-30 21:59:03 +0100280" No completion when the current window is not in diff mode.
Bram Moolenaarae7dba82019-12-29 13:56:33 +0100281func Test_diffget_diffput_completion()
Bram Moolenaarefcc3292019-12-30 21:59:03 +0100282 e Xdiff1 | diffthis
283 botright new Xdiff2
284 botright new Xdiff3 | split | diffthis
285 botright new Xdiff4 | diffthis
Bram Moolenaarae7dba82019-12-29 13:56:33 +0100286
Bram Moolenaarefcc3292019-12-30 21:59:03 +0100287 wincmd t
288 call assert_equal('Xdiff1', bufname('%'))
Bram Moolenaarae7dba82019-12-29 13:56:33 +0100289 call feedkeys(":diffput \<C-A>\<C-B>\"\<CR>", 'tx')
Bram Moolenaarefcc3292019-12-30 21:59:03 +0100290 call assert_equal('"diffput Xdiff3 Xdiff4', @:)
Bram Moolenaarae7dba82019-12-29 13:56:33 +0100291 call feedkeys(":diffget \<C-A>\<C-B>\"\<CR>", 'tx')
Bram Moolenaarefcc3292019-12-30 21:59:03 +0100292 call assert_equal('"diffget Xdiff3 Xdiff4', @:)
293 call assert_equal(['Xdiff3', 'Xdiff4'], getcompletion('', 'diff_buffer'))
Bram Moolenaarae7dba82019-12-29 13:56:33 +0100294
Bram Moolenaarefcc3292019-12-30 21:59:03 +0100295 " Xdiff2 is not in diff mode, so no completion for :diffput, :diffget
296 wincmd j
297 call assert_equal('Xdiff2', bufname('%'))
Bram Moolenaarae7dba82019-12-29 13:56:33 +0100298 call feedkeys(":diffput \<C-A>\<C-B>\"\<CR>", 'tx')
299 call assert_equal('"diffput ', @:)
300 call feedkeys(":diffget \<C-A>\<C-B>\"\<CR>", 'tx')
301 call assert_equal('"diffget ', @:)
302 call assert_equal([], getcompletion('', 'diff_buffer'))
303
Bram Moolenaarefcc3292019-12-30 21:59:03 +0100304 " Xdiff3 is split in 2 windows, only the top one is in diff mode.
305 " So completion of :diffput :diffget only happens in the top window.
306 wincmd j
307 call assert_equal('Xdiff3', bufname('%'))
308 call assert_equal(1, &diff)
309 call feedkeys(":diffput \<C-A>\<C-B>\"\<CR>", 'tx')
310 call assert_equal('"diffput Xdiff1 Xdiff4', @:)
311 call feedkeys(":diffget \<C-A>\<C-B>\"\<CR>", 'tx')
312 call assert_equal('"diffget Xdiff1 Xdiff4', @:)
313 call assert_equal(['Xdiff1', 'Xdiff4'], getcompletion('', 'diff_buffer'))
314
315 wincmd j
316 call assert_equal('Xdiff3', bufname('%'))
317 call assert_equal(0, &diff)
318 call feedkeys(":diffput \<C-A>\<C-B>\"\<CR>", 'tx')
319 call assert_equal('"diffput ', @:)
320 call feedkeys(":diffget \<C-A>\<C-B>\"\<CR>", 'tx')
321 call assert_equal('"diffget ', @:)
322 call assert_equal([], getcompletion('', 'diff_buffer'))
323
324 wincmd j
325 call assert_equal('Xdiff4', bufname('%'))
326 call feedkeys(":diffput \<C-A>\<C-B>\"\<CR>", 'tx')
327 call assert_equal('"diffput Xdiff1 Xdiff3', @:)
328 call feedkeys(":diffget \<C-A>\<C-B>\"\<CR>", 'tx')
329 call assert_equal('"diffget Xdiff1 Xdiff3', @:)
330 call assert_equal(['Xdiff1', 'Xdiff3'], getcompletion('', 'diff_buffer'))
331
Bram Moolenaarae7dba82019-12-29 13:56:33 +0100332 %bwipe
333endfunc
334
Bram Moolenaar79a213d2017-05-16 13:15:18 +0200335func Test_dp_do_buffer()
336 e! one
337 let bn1=bufnr('%')
338 let l = range(60)
339 call setline(1, l)
340 diffthis
341
342 new two
343 let l[10] = 'one'
344 let l[20] = 'two'
345 let l[30] = 'three'
346 let l[40] = 'four'
347 let l[50] = 'five'
348 call setline(1, l)
349 diffthis
350
351 " dp and do with invalid buffer number.
352 11
353 call assert_fails('norm 99999dp', 'E102:')
354 call assert_fails('norm 99999do', 'E102:')
355 call assert_fails('diffput non_existing_buffer', 'E94:')
356 call assert_fails('diffget non_existing_buffer', 'E94:')
357
358 " dp and do with valid buffer number.
359 call assert_equal('one', getline('.'))
360 exe 'norm ' . bn1 . 'do'
361 call assert_equal('10', getline('.'))
362 21
363 call assert_equal('two', getline('.'))
Bram Moolenaar94722c52023-01-28 19:19:03 +0000364 diffget one
Bram Moolenaar79a213d2017-05-16 13:15:18 +0200365 call assert_equal('20', getline('.'))
366
367 31
368 exe 'norm ' . bn1 . 'dp'
369 41
370 diffput one
371 wincmd w
372 31
373 call assert_equal('three', getline('.'))
374 41
375 call assert_equal('four', getline('.'))
376
377 " dp and do with buffer number which is not in diff mode.
378 new not_in_diff_mode
379 let bn3=bufnr('%')
380 wincmd w
381 51
382 call assert_fails('exe "norm" . bn3 . "dp"', 'E103:')
383 call assert_fails('exe "norm" . bn3 . "do"', 'E103:')
384 call assert_fails('diffput not_in_diff_mode', 'E94:')
385 call assert_fails('diffget not_in_diff_mode', 'E94:')
386
387 windo diffoff
388 %bwipe!
Bram Moolenaar42093c02016-07-30 16:16:54 +0200389endfunc
Bram Moolenaare67d5462016-08-27 22:40:42 +0200390
Bram Moolenaardf77cef2018-10-07 17:46:42 +0200391func Test_do_lastline()
392 e! one
393 call setline(1, ['1','2','3','4','5','6'])
394 diffthis
395
396 new two
397 call setline(1, ['2','4','5'])
398 diffthis
399
400 1
401 norm dp]c
402 norm dp]c
403 wincmd w
404 call assert_equal(4, line('$'))
405 norm G
406 norm do
407 call assert_equal(3, line('$'))
408
409 windo diffoff
410 %bwipe!
411endfunc
412
Bram Moolenaare67d5462016-08-27 22:40:42 +0200413func Test_diffoff()
414 enew!
415 call setline(1, ['Two', 'Three'])
Bram Moolenaar79a213d2017-05-16 13:15:18 +0200416 redraw
Bram Moolenaare67d5462016-08-27 22:40:42 +0200417 let normattr = screenattr(1, 1)
418 diffthis
419 botright vert new
420 call setline(1, ['One', '', 'Two', 'Three'])
421 diffthis
422 redraw
Bram Moolenaar196b4662019-09-06 21:34:30 +0200423 call assert_notequal(normattr, 1->screenattr(1))
Bram Moolenaare67d5462016-08-27 22:40:42 +0200424 diffoff!
425 redraw
426 call assert_equal(normattr, screenattr(1, 1))
427 bwipe!
428 bwipe!
429endfunc
Bram Moolenaar025e3e02016-10-18 14:50:18 +0200430
Bram Moolenaare828b762018-09-10 17:51:58 +0200431func Common_icase_test()
432 edit one
Bram Moolenaarda22b8c2017-09-02 18:01:50 +0200433 call setline(1, ['One', 'Two', 'Three', 'Four', 'Fi#ve'])
Bram Moolenaar79a213d2017-05-16 13:15:18 +0200434 redraw
435 let normattr = screenattr(1, 1)
436 diffthis
437
438 botright vert new two
Bram Moolenaarda22b8c2017-09-02 18:01:50 +0200439 call setline(1, ['one', 'TWO', 'Three ', 'Four', 'fI=VE'])
Bram Moolenaar79a213d2017-05-16 13:15:18 +0200440 diffthis
441
442 redraw
443 call assert_equal(normattr, screenattr(1, 1))
444 call assert_equal(normattr, screenattr(2, 1))
445 call assert_notequal(normattr, screenattr(3, 1))
446 call assert_equal(normattr, screenattr(4, 1))
447
Bram Moolenaarda22b8c2017-09-02 18:01:50 +0200448 let dtextattr = screenattr(5, 3)
449 call assert_notequal(dtextattr, screenattr(5, 1))
450 call assert_notequal(dtextattr, screenattr(5, 5))
451
Bram Moolenaar79a213d2017-05-16 13:15:18 +0200452 diffoff!
453 %bwipe!
Bram Moolenaare828b762018-09-10 17:51:58 +0200454endfunc
455
456func Test_diffopt_icase()
457 set diffopt=icase,foldcolumn:0
458 call Common_icase_test()
Bram Moolenaar79a213d2017-05-16 13:15:18 +0200459 set diffopt&
460endfunc
461
Bram Moolenaare828b762018-09-10 17:51:58 +0200462func Test_diffopt_icase_internal()
463 set diffopt=icase,foldcolumn:0,internal
464 call Common_icase_test()
465 set diffopt&
466endfunc
Bram Moolenaar79a213d2017-05-16 13:15:18 +0200467
Bram Moolenaare828b762018-09-10 17:51:58 +0200468func Common_iwhite_test()
469 edit one
470 " Difference in trailing spaces and amount of spaces should be ignored,
Bram Moolenaar79a213d2017-05-16 13:15:18 +0200471 " but not other space differences.
Bram Moolenaare828b762018-09-10 17:51:58 +0200472 call setline(1, ["One \t", 'Two', 'Three', 'one two', 'one two', 'Four'])
Bram Moolenaar79a213d2017-05-16 13:15:18 +0200473 redraw
474 let normattr = screenattr(1, 1)
475 diffthis
476
477 botright vert new two
Bram Moolenaare828b762018-09-10 17:51:58 +0200478 call setline(1, ["One\t ", "Two\t ", 'Three', 'one two', 'onetwo', ' Four'])
Bram Moolenaar79a213d2017-05-16 13:15:18 +0200479 diffthis
480
481 redraw
482 call assert_equal(normattr, screenattr(1, 1))
483 call assert_equal(normattr, screenattr(2, 1))
484 call assert_equal(normattr, screenattr(3, 1))
Bram Moolenaare828b762018-09-10 17:51:58 +0200485 call assert_equal(normattr, screenattr(4, 1))
486 call assert_notequal(normattr, screenattr(5, 1))
487 call assert_notequal(normattr, screenattr(6, 1))
Bram Moolenaar79a213d2017-05-16 13:15:18 +0200488
489 diffoff!
490 %bwipe!
Bram Moolenaare828b762018-09-10 17:51:58 +0200491endfunc
492
493func Test_diffopt_iwhite()
494 set diffopt=iwhite,foldcolumn:0
495 call Common_iwhite_test()
496 set diffopt&
497endfunc
498
499func Test_diffopt_iwhite_internal()
500 set diffopt=internal,iwhite,foldcolumn:0
501 call Common_iwhite_test()
Bram Moolenaar79a213d2017-05-16 13:15:18 +0200502 set diffopt&
503endfunc
504
505func Test_diffopt_context()
506 enew!
507 call setline(1, ['1', '2', '3', '4', '5', '6', '7'])
508 diffthis
509 new
510 call setline(1, ['1', '2', '3', '4', '5x', '6', '7'])
511 diffthis
512
513 set diffopt=context:2
514 call assert_equal('+-- 2 lines: 1', foldtextresult(1))
Bram Moolenaare828b762018-09-10 17:51:58 +0200515 set diffopt=internal,context:2
516 call assert_equal('+-- 2 lines: 1', foldtextresult(1))
517
Bram Moolenaar79a213d2017-05-16 13:15:18 +0200518 set diffopt=context:1
519 call assert_equal('+-- 3 lines: 1', foldtextresult(1))
Bram Moolenaare828b762018-09-10 17:51:58 +0200520 set diffopt=internal,context:1
521 call assert_equal('+-- 3 lines: 1', foldtextresult(1))
Bram Moolenaar79a213d2017-05-16 13:15:18 +0200522
523 diffoff!
524 %bwipe!
525 set diffopt&
526endfunc
527
528func Test_diffopt_horizontal()
Bram Moolenaare828b762018-09-10 17:51:58 +0200529 set diffopt=internal,horizontal
Bram Moolenaar79a213d2017-05-16 13:15:18 +0200530 diffsplit
531
532 call assert_equal(&columns, winwidth(1))
533 call assert_equal(&columns, winwidth(2))
534 call assert_equal(&lines, winheight(1) + winheight(2) + 3)
535 call assert_inrange(0, 1, winheight(1) - winheight(2))
536
537 set diffopt&
538 diffoff!
539 %bwipe
540endfunc
541
542func Test_diffopt_vertical()
Bram Moolenaare828b762018-09-10 17:51:58 +0200543 set diffopt=internal,vertical
Bram Moolenaar79a213d2017-05-16 13:15:18 +0200544 diffsplit
545
546 call assert_equal(&lines - 2, winheight(1))
547 call assert_equal(&lines - 2, winheight(2))
548 call assert_equal(&columns, winwidth(1) + winwidth(2) + 1)
549 call assert_inrange(0, 1, winwidth(1) - winwidth(2))
550
551 set diffopt&
552 diffoff!
553 %bwipe
554endfunc
555
Bram Moolenaar97ce4192017-12-01 20:35:58 +0100556func Test_diffopt_hiddenoff()
Bram Moolenaare828b762018-09-10 17:51:58 +0200557 set diffopt=internal,filler,foldcolumn:0,hiddenoff
Bram Moolenaar97ce4192017-12-01 20:35:58 +0100558 e! one
559 call setline(1, ['Two', 'Three'])
560 redraw
561 let normattr = screenattr(1, 1)
562 diffthis
563 botright vert new two
564 call setline(1, ['One', 'Four'])
565 diffthis
566 redraw
567 call assert_notequal(normattr, screenattr(1, 1))
568 set hidden
569 close
570 redraw
571 " should not diffing with hidden buffer two while 'hiddenoff' is enabled
572 call assert_equal(normattr, screenattr(1, 1))
573
574 bwipe!
575 bwipe!
576 set hidden& diffopt&
577endfunc
578
Bram Moolenaar25ea0542017-02-03 23:16:28 +0100579func Test_diffoff_hidden()
Bram Moolenaare828b762018-09-10 17:51:58 +0200580 set diffopt=internal,filler,foldcolumn:0
Bram Moolenaar25ea0542017-02-03 23:16:28 +0100581 e! one
582 call setline(1, ['Two', 'Three'])
Bram Moolenaar79a213d2017-05-16 13:15:18 +0200583 redraw
Bram Moolenaar25ea0542017-02-03 23:16:28 +0100584 let normattr = screenattr(1, 1)
585 diffthis
586 botright vert new two
587 call setline(1, ['One', 'Four'])
588 diffthis
589 redraw
590 call assert_notequal(normattr, screenattr(1, 1))
591 set hidden
592 close
593 redraw
594 " diffing with hidden buffer two
595 call assert_notequal(normattr, screenattr(1, 1))
596 diffoff
597 redraw
598 call assert_equal(normattr, screenattr(1, 1))
599 diffthis
600 redraw
601 " still diffing with hidden buffer two
602 call assert_notequal(normattr, screenattr(1, 1))
603 diffoff!
604 redraw
605 call assert_equal(normattr, screenattr(1, 1))
606 diffthis
607 redraw
608 " no longer diffing with hidden buffer two
609 call assert_equal(normattr, screenattr(1, 1))
610
611 bwipe!
612 bwipe!
613 set hidden& diffopt&
614endfunc
615
Bram Moolenaar025e3e02016-10-18 14:50:18 +0200616func Test_setting_cursor()
617 new Xtest1
618 put =range(1,90)
619 wq
620 new Xtest2
621 put =range(1,100)
622 wq
Bram Moolenaar97fbc402017-09-26 19:41:46 +0200623
Bram Moolenaar025e3e02016-10-18 14:50:18 +0200624 tabe Xtest2
625 $
626 diffsp Xtest1
627 tabclose
628
629 call delete('Xtest1')
630 call delete('Xtest2')
631endfunc
Bram Moolenaaraeb661e2017-02-26 19:59:59 +0100632
633func Test_diff_move_to()
634 new
635 call setline(1, [1, 2, 3, 4, 5, 6, 7, 8, 9, 10])
636 diffthis
637 vnew
638 call setline(1, [1, '2x', 3, 4, 4, 5, '6x', 7, '8x', 9, '10x'])
639 diffthis
640 norm ]c
641 call assert_equal(2, line('.'))
642 norm 3]c
643 call assert_equal(9, line('.'))
644 norm 10]c
645 call assert_equal(11, line('.'))
646 norm [c
647 call assert_equal(9, line('.'))
648 norm 2[c
649 call assert_equal(5, line('.'))
650 norm 10[c
651 call assert_equal(2, line('.'))
652 %bwipe!
653endfunc
654
Bram Moolenaar79a213d2017-05-16 13:15:18 +0200655func Test_diffexpr()
Bram Moolenaaraeb313f2020-11-27 19:13:28 +0100656 CheckExecutable diff
Bram Moolenaar79a213d2017-05-16 13:15:18 +0200657
658 func DiffExpr()
Bram Moolenaar485b6272021-05-18 19:19:03 +0200659 " Prepend some text to check diff type detection
Bram Moolenaar3b8defd2018-09-13 13:03:11 +0200660 call writefile(['warning', ' message'], v:fname_out)
661 silent exe '!diff ' . v:fname_in . ' ' . v:fname_new . '>>' . v:fname_out
Bram Moolenaar79a213d2017-05-16 13:15:18 +0200662 endfunc
663 set diffexpr=DiffExpr()
664 set diffopt=foldcolumn:0
665
666 enew!
667 call setline(1, ['one', 'two', 'three'])
668 redraw
669 let normattr = screenattr(1, 1)
670 diffthis
671
672 botright vert new
673 call setline(1, ['one', 'two', 'three.'])
674 diffthis
675
676 redraw
677 call assert_equal(normattr, screenattr(1, 1))
678 call assert_equal(normattr, screenattr(2, 1))
679 call assert_notequal(normattr, screenattr(3, 1))
Yegappan Lakshmanan30443242021-06-10 21:52:15 +0200680 diffoff!
Bram Moolenaar79a213d2017-05-16 13:15:18 +0200681
Dominique Pelle923dce22021-11-21 11:36:04 +0000682 " Try using a non-existing function for 'diffexpr'.
Yegappan Lakshmanan30443242021-06-10 21:52:15 +0200683 set diffexpr=NewDiffFunc()
684 call assert_fails('windo diffthis', ['E117:', 'E97:'])
Bram Moolenaar79a213d2017-05-16 13:15:18 +0200685 diffoff!
Yegappan Lakshmanan8bb65f22021-12-26 10:51:39 +0000686
687 " Using a script-local function
688 func s:NewDiffExpr()
689 endfunc
690 set diffexpr=s:NewDiffExpr()
691 call assert_equal(expand('<SID>') .. 'NewDiffExpr()', &diffexpr)
692 set diffexpr=<SID>NewDiffExpr()
693 call assert_equal(expand('<SID>') .. 'NewDiffExpr()', &diffexpr)
694
Bram Moolenaar79a213d2017-05-16 13:15:18 +0200695 %bwipe!
696 set diffexpr& diffopt&
Yegappan Lakshmanan8bb65f22021-12-26 10:51:39 +0000697 delfunc DiffExpr
698 delfunc s:NewDiffExpr
Bram Moolenaar79a213d2017-05-16 13:15:18 +0200699endfunc
700
Bram Moolenaaraeb661e2017-02-26 19:59:59 +0100701func Test_diffpatch()
702 " The patch program on MS-Windows may fail or hang.
Bram Moolenaar6d91bcb2020-08-12 18:50:36 +0200703 CheckExecutable patch
704 CheckUnix
Bram Moolenaaraeb661e2017-02-26 19:59:59 +0100705 new
706 insert
707***************
708*** 1,3 ****
709 1
710! 2
711 3
712--- 1,4 ----
713 1
714! 2x
715 3
716+ 4
717.
Bram Moolenaar97fbc402017-09-26 19:41:46 +0200718 saveas! Xpatch
Bram Moolenaaraeb661e2017-02-26 19:59:59 +0100719 bwipe!
720 new
721 call assert_fails('diffpatch Xpatch', 'E816:')
Bram Moolenaar1ef73e32017-03-09 19:21:30 +0100722
Bram Moolenaara95ab322017-03-11 19:21:53 +0100723 for name in ['Xpatch', 'Xpatch$HOME', 'Xpa''tch']
Bram Moolenaar1ef73e32017-03-09 19:21:30 +0100724 call setline(1, ['1', '2', '3'])
725 if name != 'Xpatch'
726 call rename('Xpatch', name)
727 endif
728 exe 'diffpatch ' . escape(name, '$')
729 call assert_equal(['1', '2x', '3', '4'], getline(1, '$'))
730 if name != 'Xpatch'
731 call rename(name, 'Xpatch')
732 endif
733 bwipe!
734 endfor
735
Bram Moolenaaraeb661e2017-02-26 19:59:59 +0100736 call delete('Xpatch')
737 bwipe!
738endfunc
739
Bram Moolenaar23a971d2023-04-04 22:04:53 +0100740" FIXME: test fails, the Xresult file can't be read
741func No_Test_diffpatch_restricted()
742 let lines =<< trim END
743 call assert_fails('diffpatch NoSuchDiff', 'E145:')
744
745 call writefile(v:errors, 'Xresult')
746 qa!
747 END
748 call writefile(lines, 'Xrestricted', 'D')
749 if RunVim([], [], '-Z --clean -S Xrestricted')
750 call assert_equal([], readfile('Xresult'))
751 endif
752 call delete('Xresult')
753endfunc
754
Bram Moolenaaraeb661e2017-02-26 19:59:59 +0100755func Test_diff_too_many_buffers()
756 for i in range(1, 8)
757 exe "new Xtest" . i
758 diffthis
759 endfor
760 new Xtest9
761 call assert_fails('diffthis', 'E96:')
762 %bwipe!
763endfunc
764
765func Test_diff_nomodifiable()
766 new
767 call setline(1, [1, 2, 3, 4])
768 setl nomodifiable
769 diffthis
770 vnew
771 call setline(1, ['1x', 2, 3, 3, 4])
772 diffthis
773 call assert_fails('norm dp', 'E793:')
774 setl nomodifiable
775 call assert_fails('norm do', 'E21:')
776 %bwipe!
777endfunc
Bram Moolenaarf58a8472017-03-05 18:03:04 +0100778
Bram Moolenaar97fbc402017-09-26 19:41:46 +0200779func Test_diff_hlID()
780 new
781 call setline(1, [1, 2, 3])
782 diffthis
783 vnew
784 call setline(1, ['1x', 2, 'x', 3])
785 diffthis
786 redraw
787
Bram Moolenaara74e4942019-08-04 17:35:53 +0200788 call diff_hlID(-1, 1)->synIDattr("name")->assert_equal("")
Bram Moolenaar97fbc402017-09-26 19:41:46 +0200789
Bram Moolenaara74e4942019-08-04 17:35:53 +0200790 call diff_hlID(1, 1)->synIDattr("name")->assert_equal("DiffChange")
791 call diff_hlID(1, 2)->synIDattr("name")->assert_equal("DiffText")
792 call diff_hlID(2, 1)->synIDattr("name")->assert_equal("")
793 call diff_hlID(3, 1)->synIDattr("name")->assert_equal("DiffAdd")
Bram Moolenaar1a3a8912019-08-23 22:31:37 +0200794 eval 4->diff_hlID(1)->synIDattr("name")->assert_equal("")
Bram Moolenaar97fbc402017-09-26 19:41:46 +0200795
796 wincmd w
797 call assert_equal(synIDattr(diff_hlID(1, 1), "name"), "DiffChange")
798 call assert_equal(synIDattr(diff_hlID(2, 1), "name"), "")
799 call assert_equal(synIDattr(diff_hlID(3, 1), "name"), "")
800
801 %bwipe!
802endfunc
803
804func Test_diff_filler()
805 new
806 call setline(1, [1, 2, 3, 'x', 4])
807 diffthis
808 vnew
809 call setline(1, [1, 2, 'y', 'y', 3, 4])
810 diffthis
811 redraw
812
Bram Moolenaar1a3a8912019-08-23 22:31:37 +0200813 call assert_equal([0, 0, 0, 0, 0, 0, 0, 1, 0], map(range(-1, 7), 'v:val->diff_filler()'))
Bram Moolenaar97fbc402017-09-26 19:41:46 +0200814 wincmd w
815 call assert_equal([0, 0, 0, 0, 2, 0, 0, 0], map(range(-1, 6), 'diff_filler(v:val)'))
816
817 %bwipe!
818endfunc
819
Bram Moolenaarf58a8472017-03-05 18:03:04 +0100820func Test_diff_lastline()
821 enew!
822 only!
823 call setline(1, ['This is a ', 'line with five ', 'rows'])
824 diffthis
825 botright vert new
826 call setline(1, ['This is', 'a line with ', 'four rows'])
827 diffthis
828 1
829 call feedkeys("Je a\<CR>", 'tx')
830 call feedkeys("Je a\<CR>", 'tx')
831 let w1lines = winline()
832 wincmd w
833 $
834 let w2lines = winline()
835 call assert_equal(w2lines, w1lines)
836 bwipe!
837 bwipe!
838endfunc
Bram Moolenaare828b762018-09-10 17:51:58 +0200839
Bram Moolenaar785fc652018-09-15 19:17:38 +0200840func WriteDiffFiles(buf, list1, list2)
Bram Moolenaar61abe7d2022-08-30 21:46:08 +0100841 call writefile(a:list1, 'Xdifile1')
842 call writefile(a:list2, 'Xdifile2')
Bram Moolenaar785fc652018-09-15 19:17:38 +0200843 if a:buf
844 call term_sendkeys(a:buf, ":checktime\<CR>")
845 endif
Bram Moolenaare828b762018-09-10 17:51:58 +0200846endfunc
847
Yukihiro Nakadaira06fe70c2024-09-26 16:19:42 +0200848func WriteDiffFiles3(buf, list1, list2, list3)
849 call writefile(a:list1, 'Xdifile1')
850 call writefile(a:list2, 'Xdifile2')
851 call writefile(a:list3, 'Xdifile3')
852 if a:buf
853 call term_sendkeys(a:buf, ":checktime\<CR>")
854 endif
855endfunc
856
Bram Moolenaar785fc652018-09-15 19:17:38 +0200857" Verify a screendump with both the internal and external diff.
Bram Moolenaare828b762018-09-10 17:51:58 +0200858func VerifyBoth(buf, dumpfile, extra)
Bram Moolenaare828b762018-09-10 17:51:58 +0200859 " trailing : for leaving the cursor on the command line
Bram Moolenaar785fc652018-09-15 19:17:38 +0200860 for cmd in [":set diffopt=filler" . a:extra . "\<CR>:", ":set diffopt+=internal\<CR>:"]
Bram Moolenaare828b762018-09-10 17:51:58 +0200861 call term_sendkeys(a:buf, cmd)
862 if VerifyScreenDump(a:buf, a:dumpfile, {}, cmd =~ 'internal' ? 'internal' : 'external')
Bram Moolenaar485b6272021-05-18 19:19:03 +0200863 " don't let the next iteration overwrite the "failed" file.
864 return
Bram Moolenaare828b762018-09-10 17:51:58 +0200865 endif
866 endfor
Bram Moolenaar485b6272021-05-18 19:19:03 +0200867
868 " also test unified diff
869 call term_sendkeys(a:buf, ":call SetupUnified()\<CR>:")
glacambread5c1782021-05-24 14:20:53 +0200870 call term_sendkeys(a:buf, ":redraw!\<CR>:")
Bram Moolenaar485b6272021-05-18 19:19:03 +0200871 call VerifyScreenDump(a:buf, a:dumpfile, {}, 'unified')
872 call term_sendkeys(a:buf, ":call StopUnified()\<CR>:")
Bram Moolenaare828b762018-09-10 17:51:58 +0200873endfunc
874
Bram Moolenaar785fc652018-09-15 19:17:38 +0200875" Verify a screendump with the internal diff only.
876func VerifyInternal(buf, dumpfile, extra)
877 call term_sendkeys(a:buf, ":diffupdate!\<CR>")
878 " trailing : for leaving the cursor on the command line
879 call term_sendkeys(a:buf, ":set diffopt=internal,filler" . a:extra . "\<CR>:")
880 call VerifyScreenDump(a:buf, a:dumpfile, {})
881endfunc
882
Bram Moolenaare828b762018-09-10 17:51:58 +0200883func Test_diff_screen()
Yee Cheng Chin49f2ba62024-02-14 20:34:58 +0100884 if has('osxdarwin') && system('diff --version') =~ '^Apple diff'
885 throw 'Skipped: unified diff does not work properly on this macOS version'
rhysde93d5ca2024-02-01 21:22:14 +0100886 endif
887
Bram Moolenaarf08b0eb2021-10-16 13:00:14 +0100888 let g:test_is_flaky = 1
Bram Moolenaar3c8ee622019-08-03 22:55:50 +0200889 CheckScreendump
890 CheckFeature menu
891
Bram Moolenaar485b6272021-05-18 19:19:03 +0200892 let lines =<< trim END
893 func UnifiedDiffExpr()
894 " Prepend some text to check diff type detection
895 call writefile(['warning', ' message'], v:fname_out)
glacambread5c1782021-05-24 14:20:53 +0200896 silent exe '!diff -U0 ' .. v:fname_in .. ' ' .. v:fname_new .. '>>' .. v:fname_out
Bram Moolenaar485b6272021-05-18 19:19:03 +0200897 endfunc
898 func SetupUnified()
899 set diffexpr=UnifiedDiffExpr()
glacambread5c1782021-05-24 14:20:53 +0200900 diffupdate
Bram Moolenaar485b6272021-05-18 19:19:03 +0200901 endfunc
902 func StopUnified()
903 set diffexpr=
904 endfunc
905 END
Bram Moolenaar59173412022-09-20 22:01:33 +0100906 call writefile(lines, 'XdiffSetup', 'D')
Bram Moolenaar485b6272021-05-18 19:19:03 +0200907
Bram Moolenaare828b762018-09-10 17:51:58 +0200908 " clean up already existing swap files, just in case
Bram Moolenaar61abe7d2022-08-30 21:46:08 +0100909 call delete('.Xdifile1.swp')
910 call delete('.Xdifile2.swp')
Bram Moolenaare828b762018-09-10 17:51:58 +0200911
912 " Test 1: Add a line in beginning of file 2
Bram Moolenaar785fc652018-09-15 19:17:38 +0200913 call WriteDiffFiles(0, [1, 2, 3, 4, 5, 6, 7, 8, 9, 10], [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10])
Bram Moolenaar61abe7d2022-08-30 21:46:08 +0100914 let buf = RunVimInTerminal('-d -S XdiffSetup Xdifile1 Xdifile2', {})
Bram Moolenaar8ee4c012019-03-29 18:08:18 +0100915 " Set autoread mode, so that Vim won't complain once we re-write the test
Bram Moolenaare828b762018-09-10 17:51:58 +0200916 " files
Bram Moolenaar785fc652018-09-15 19:17:38 +0200917 call term_sendkeys(buf, ":set autoread\<CR>\<c-w>w:set autoread\<CR>\<c-w>w")
Bram Moolenaare828b762018-09-10 17:51:58 +0200918
919 call VerifyBoth(buf, 'Test_diff_01', '')
920
921 " Test 2: Add a line in beginning of file 1
Bram Moolenaar785fc652018-09-15 19:17:38 +0200922 call WriteDiffFiles(buf, [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10], [1, 2, 3, 4, 5, 6, 7, 8, 9, 10])
Bram Moolenaare828b762018-09-10 17:51:58 +0200923 call VerifyBoth(buf, 'Test_diff_02', '')
924
925 " Test 3: Add a line at the end of file 2
Bram Moolenaar785fc652018-09-15 19:17:38 +0200926 call WriteDiffFiles(buf, [1, 2, 3, 4, 5, 6, 7, 8, 9, 10], [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11])
Bram Moolenaare828b762018-09-10 17:51:58 +0200927 call VerifyBoth(buf, 'Test_diff_03', '')
928
929 " Test 4: Add a line at the end of file 1
Bram Moolenaar785fc652018-09-15 19:17:38 +0200930 call WriteDiffFiles(buf, [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11], [1, 2, 3, 4, 5, 6, 7, 8, 9, 10])
Bram Moolenaare828b762018-09-10 17:51:58 +0200931 call VerifyBoth(buf, 'Test_diff_04', '')
932
933 " Test 5: Add a line in the middle of file 2, remove on at the end of file 1
Bram Moolenaar785fc652018-09-15 19:17:38 +0200934 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])
Bram Moolenaare828b762018-09-10 17:51:58 +0200935 call VerifyBoth(buf, 'Test_diff_05', '')
936
937 " Test 6: Add a line in the middle of file 1, remove on at the end of file 2
Bram Moolenaar785fc652018-09-15 19:17:38 +0200938 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])
Bram Moolenaare828b762018-09-10 17:51:58 +0200939 call VerifyBoth(buf, 'Test_diff_06', '')
940
Bram Moolenaarb9ddda62019-02-19 23:00:50 +0100941 " Variants on test 6 with different context settings
942 call term_sendkeys(buf, ":set diffopt+=context:2\<cr>")
943 call VerifyScreenDump(buf, 'Test_diff_06.2', {})
944 call term_sendkeys(buf, ":set diffopt-=context:2\<cr>")
945 call term_sendkeys(buf, ":set diffopt+=context:1\<cr>")
946 call VerifyScreenDump(buf, 'Test_diff_06.1', {})
947 call term_sendkeys(buf, ":set diffopt-=context:1\<cr>")
948 call term_sendkeys(buf, ":set diffopt+=context:0\<cr>")
949 call VerifyScreenDump(buf, 'Test_diff_06.0', {})
950 call term_sendkeys(buf, ":set diffopt-=context:0\<cr>")
951
Bram Moolenaare828b762018-09-10 17:51:58 +0200952 " Test 7 - 9: Test normal/patience/histogram diff algorithm
Bram Moolenaar785fc652018-09-15 19:17:38 +0200953 call WriteDiffFiles(buf, ['#include <stdio.h>', '', '// Frobs foo heartily', 'int frobnitz(int foo)', '{',
Bram Moolenaare828b762018-09-10 17:51:58 +0200954 \ ' int i;', ' for(i = 0; i < 10; i++)', ' {', ' printf("Your answer is: ");',
955 \ ' printf("%d\n", foo);', ' }', '}', '', 'int fact(int n)', '{', ' if(n > 1)', ' {',
956 \ ' return fact(n-1) * n;', ' }', ' return 1;', '}', '', 'int main(int argc, char **argv)',
957 \ '{', ' frobnitz(fact(10));', '}'],
958 \ ['#include <stdio.h>', '', 'int fib(int n)', '{', ' if(n > 2)', ' {',
959 \ ' return fib(n-1) + fib(n-2);', ' }', ' return 1;', '}', '', '// Frobs foo heartily',
960 \ 'int frobnitz(int foo)', '{', ' int i;', ' for(i = 0; i < 10; i++)', ' {',
961 \ ' printf("%d\n", foo);', ' }', '}', '',
962 \ 'int main(int argc, char **argv)', '{', ' frobnitz(fib(10));', '}'])
963 call term_sendkeys(buf, ":diffupdate!\<cr>")
964 call term_sendkeys(buf, ":set diffopt+=internal\<cr>")
965 call VerifyScreenDump(buf, 'Test_diff_07', {})
966
967 call term_sendkeys(buf, ":set diffopt+=algorithm:patience\<cr>")
968 call VerifyScreenDump(buf, 'Test_diff_08', {})
969
970 call term_sendkeys(buf, ":set diffopt+=algorithm:histogram\<cr>")
971 call VerifyScreenDump(buf, 'Test_diff_09', {})
972
973 " Test 10-11: normal/indent-heuristic
974 call term_sendkeys(buf, ":set diffopt&vim\<cr>")
Bram Moolenaar785fc652018-09-15 19:17:38 +0200975 call WriteDiffFiles(buf, ['', ' def finalize(values)', '', ' values.each do |v|', ' v.finalize', ' end'],
Bram Moolenaare828b762018-09-10 17:51:58 +0200976 \ ['', ' def finalize(values)', '', ' values.each do |v|', ' v.prepare', ' end', '',
977 \ ' values.each do |v|', ' v.finalize', ' end'])
978 call term_sendkeys(buf, ":diffupdate!\<cr>")
979 call term_sendkeys(buf, ":set diffopt+=internal\<cr>")
980 call VerifyScreenDump(buf, 'Test_diff_10', {})
981
Bram Moolenaarb6fc7282018-12-04 22:24:16 +0100982 " Leave trailing : at commandline!
983 call term_sendkeys(buf, ":set diffopt+=indent-heuristic\<cr>:\<cr>")
984 call VerifyScreenDump(buf, 'Test_diff_11', {}, 'one')
985 " shouldn't matter, if indent-algorithm comes before or after the algorithm
986 call term_sendkeys(buf, ":set diffopt&\<cr>")
987 call term_sendkeys(buf, ":set diffopt+=indent-heuristic,algorithm:patience\<cr>:\<cr>")
988 call VerifyScreenDump(buf, 'Test_diff_11', {}, 'two')
989 call term_sendkeys(buf, ":set diffopt&\<cr>")
990 call term_sendkeys(buf, ":set diffopt+=algorithm:patience,indent-heuristic\<cr>:\<cr>")
991 call VerifyScreenDump(buf, 'Test_diff_11', {}, 'three')
Bram Moolenaare828b762018-09-10 17:51:58 +0200992
993 " Test 12: diff the same file
Bram Moolenaar785fc652018-09-15 19:17:38 +0200994 call WriteDiffFiles(buf, [1, 2, 3, 4, 5, 6, 7, 8, 9, 10], [1, 2, 3, 4, 5, 6, 7, 8, 9, 10])
Bram Moolenaare828b762018-09-10 17:51:58 +0200995 call VerifyBoth(buf, 'Test_diff_12', '')
996
997 " Test 13: diff an empty file
Bram Moolenaar785fc652018-09-15 19:17:38 +0200998 call WriteDiffFiles(buf, [], [])
Bram Moolenaare828b762018-09-10 17:51:58 +0200999 call VerifyBoth(buf, 'Test_diff_13', '')
1000
1001 " Test 14: test diffopt+=icase
Bram Moolenaar785fc652018-09-15 19:17:38 +02001002 call WriteDiffFiles(buf, ['a', 'b', 'cd'], ['A', 'b', 'cDe'])
Bram Moolenaare828b762018-09-10 17:51:58 +02001003 call VerifyBoth(buf, 'Test_diff_14', " diffopt+=filler diffopt+=icase")
1004
1005 " Test 15-16: test diffopt+=iwhite
Bram Moolenaar785fc652018-09-15 19:17:38 +02001006 call WriteDiffFiles(buf, ['int main()', '{', ' printf("Hello, World!");', ' return 0;', '}'],
Bram Moolenaare828b762018-09-10 17:51:58 +02001007 \ ['int main()', '{', ' if (0)', ' {', ' printf("Hello, World!");', ' return 0;', ' }', '}'])
1008 call term_sendkeys(buf, ":diffupdate!\<cr>")
1009 call term_sendkeys(buf, ":set diffopt&vim diffopt+=filler diffopt+=iwhite\<cr>")
1010 call VerifyScreenDump(buf, 'Test_diff_15', {})
1011 call term_sendkeys(buf, ":set diffopt+=internal\<cr>")
1012 call VerifyScreenDump(buf, 'Test_diff_16', {})
1013
Bram Moolenaar785fc652018-09-15 19:17:38 +02001014 " Test 17: test diffopt+=iblank
1015 call WriteDiffFiles(buf, ['a', ' ', 'cd', 'ef', 'xxx'], ['a', 'cd', '', 'ef', 'yyy'])
1016 call VerifyInternal(buf, 'Test_diff_17', " diffopt+=iblank")
1017
1018 " Test 18: test diffopt+=iblank,iwhite / iwhiteall / iwhiteeol
1019 call VerifyInternal(buf, 'Test_diff_18', " diffopt+=iblank,iwhite")
1020 call VerifyInternal(buf, 'Test_diff_18', " diffopt+=iblank,iwhiteall")
1021 call VerifyInternal(buf, 'Test_diff_18', " diffopt+=iblank,iwhiteeol")
1022
1023 " Test 19: test diffopt+=iwhiteeol
1024 call WriteDiffFiles(buf, ['a ', 'x', 'cd', 'ef', 'xx xx', 'foo', 'bar'], ['a', 'x', 'c d', ' ef', 'xx xx', 'foo', '', 'bar'])
1025 call VerifyInternal(buf, 'Test_diff_19', " diffopt+=iwhiteeol")
1026
Yukihiro Nakadairaf1694b42024-09-22 11:26:13 +02001027 " Test 20: test diffopt+=iwhiteall
Bram Moolenaar785fc652018-09-15 19:17:38 +02001028 call VerifyInternal(buf, 'Test_diff_20', " diffopt+=iwhiteall")
1029
Yukihiro Nakadairaf1694b42024-09-22 11:26:13 +02001030 " Test 21: Delete all lines
1031 call WriteDiffFiles(buf, [0], [])
1032 call VerifyBoth(buf, "Test_diff_21", "")
1033
1034 " Test 22: Add line to empty file
1035 call WriteDiffFiles(buf, [], [0])
1036 call VerifyBoth(buf, "Test_diff_22", "")
1037
Jonathon7c7a4e62025-01-12 09:58:00 +01001038 call WriteDiffFiles(buf, ['?a', '?b', '?c'], ['!b'])
1039 call VerifyInternal(buf, 'Test_diff_23', " diffopt+=linematch:30")
1040
1041 call WriteDiffFiles(buf, ['',
1042 \ 'common line',
1043 \ 'common line',
1044 \ '',
1045 \ 'DEFabc',
1046 \ 'xyz',
1047 \ 'xyz',
1048 \ 'xyz',
1049 \ 'DEFabc',
1050 \ 'DEFabc',
1051 \ 'DEFabc',
1052 \ 'common line',
1053 \ 'common line',
1054 \ 'DEF',
1055 \ 'common line',
1056 \ 'DEF',
1057 \ 'something' ],
1058 \ ['',
1059 \ 'common line',
1060 \ 'common line',
1061 \ '',
1062 \ 'ABCabc',
1063 \ 'ABCabc',
1064 \ 'ABCabc',
1065 \ 'ABCabc',
1066 \ 'common line',
1067 \ 'common line',
1068 \ 'common line',
1069 \ 'something'])
1070 call VerifyInternal(buf, 'Test_diff_24', " diffopt+=linematch:30")
1071
1072
Bram Moolenaare828b762018-09-10 17:51:58 +02001073 " clean up
1074 call StopVimInTerminal(buf)
Bram Moolenaar61abe7d2022-08-30 21:46:08 +01001075 call delete('Xdifile1')
1076 call delete('Xdifile2')
Bram Moolenaare828b762018-09-10 17:51:58 +02001077endfunc
1078
Bram Moolenaar04626c22021-09-01 16:02:07 +02001079func Test_diff_with_scroll_and_change()
1080 CheckScreendump
1081
1082 let lines =<< trim END
1083 call setline(1, range(1, 15))
1084 vnew
1085 call setline(1, range(9, 15))
1086 windo diffthis
1087 wincmd h
1088 exe "normal Gl5\<C-E>"
1089 END
Bram Moolenaar59173412022-09-20 22:01:33 +01001090 call writefile(lines, 'Xtest_scroll_change', 'D')
Bram Moolenaar04626c22021-09-01 16:02:07 +02001091 let buf = RunVimInTerminal('-S Xtest_scroll_change', {})
1092
1093 call VerifyScreenDump(buf, 'Test_diff_scroll_change_01', {})
1094
1095 call term_sendkeys(buf, "ax\<Esc>")
1096 call VerifyScreenDump(buf, 'Test_diff_scroll_change_02', {})
1097
Bram Moolenaar841c2252021-10-22 20:56:55 +01001098 call term_sendkeys(buf, "\<C-W>lay\<Esc>")
1099 call VerifyScreenDump(buf, 'Test_diff_scroll_change_03', {})
1100
Bram Moolenaar04626c22021-09-01 16:02:07 +02001101 " clean up
1102 call StopVimInTerminal(buf)
Bram Moolenaar04626c22021-09-01 16:02:07 +02001103endfunc
1104
Bram Moolenaar4a5abbd2018-10-02 18:26:10 +02001105func Test_diff_with_cursorline()
Bram Moolenaar3c8ee622019-08-03 22:55:50 +02001106 CheckScreendump
Bram Moolenaar4a5abbd2018-10-02 18:26:10 +02001107
1108 call writefile([
1109 \ 'hi CursorLine ctermbg=red ctermfg=white',
1110 \ 'set cursorline',
1111 \ 'call setline(1, ["foo","foo","foo","bar"])',
1112 \ 'vnew',
1113 \ 'call setline(1, ["bee","foo","foo","baz"])',
1114 \ 'windo diffthis',
1115 \ '2wincmd w',
Bram Moolenaar59173412022-09-20 22:01:33 +01001116 \ ], 'Xtest_diff_cursorline', 'D')
Bram Moolenaar4a5abbd2018-10-02 18:26:10 +02001117 let buf = RunVimInTerminal('-S Xtest_diff_cursorline', {})
1118
1119 call VerifyScreenDump(buf, 'Test_diff_with_cursorline_01', {})
1120 call term_sendkeys(buf, "j")
1121 call VerifyScreenDump(buf, 'Test_diff_with_cursorline_02', {})
1122 call term_sendkeys(buf, "j")
1123 call VerifyScreenDump(buf, 'Test_diff_with_cursorline_03', {})
1124
1125 " clean up
1126 call StopVimInTerminal(buf)
Bram Moolenaar4a5abbd2018-10-02 18:26:10 +02001127endfunc
Bram Moolenaarf7acf2b2018-11-01 21:14:53 +01001128
Bram Moolenaar127969c2022-03-06 19:54:13 +00001129func Test_diff_with_cursorline_number()
1130 CheckScreendump
1131
1132 let lines =<< trim END
1133 hi CursorLine ctermbg=red ctermfg=white
1134 hi CursorLineNr ctermbg=white ctermfg=black cterm=underline
1135 set cursorline number
1136 call setline(1, ["baz", "foo", "foo", "bar"])
1137 2
1138 vnew
1139 call setline(1, ["foo", "foo", "bar"])
1140 windo diffthis
1141 1wincmd w
1142 END
Bram Moolenaar59173412022-09-20 22:01:33 +01001143 call writefile(lines, 'Xtest_diff_cursorline_number', 'D')
Bram Moolenaar127969c2022-03-06 19:54:13 +00001144 let buf = RunVimInTerminal('-S Xtest_diff_cursorline_number', {})
1145
1146 call VerifyScreenDump(buf, 'Test_diff_with_cursorline_number_01', {})
1147 call term_sendkeys(buf, ":set cursorlineopt=number\r")
1148 call VerifyScreenDump(buf, 'Test_diff_with_cursorline_number_02', {})
1149
1150 " clean up
1151 call StopVimInTerminal(buf)
Bram Moolenaar127969c2022-03-06 19:54:13 +00001152endfunc
1153
zeertzjq4f33bc22021-08-05 17:57:02 +02001154func Test_diff_with_cursorline_breakindent()
1155 CheckScreendump
1156
zeertzjq588f20d2023-12-05 15:47:09 +01001157 let lines =<< trim END
1158 hi CursorLine ctermbg=red ctermfg=white
1159 set noequalalways wrap diffopt=followwrap cursorline breakindent
1160 50vnew
1161 call setline(1, [' ', ' ', ' ', ' '])
1162 exe "norm! 20Afoo\<Esc>j20Afoo\<Esc>j20Afoo\<Esc>j20Abar\<Esc>"
1163 vnew
1164 call setline(1, [' ', ' ', ' ', ' '])
1165 exe "norm! 20Abee\<Esc>j20Afoo\<Esc>j20Afoo\<Esc>j20Abaz\<Esc>"
1166 windo diffthis
1167 2wincmd w
1168 END
1169 call writefile(lines, 'Xtest_diff_cursorline_breakindent', 'D')
zeertzjq4f33bc22021-08-05 17:57:02 +02001170 let buf = RunVimInTerminal('-S Xtest_diff_cursorline_breakindent', {})
1171
1172 call term_sendkeys(buf, "gg0")
1173 call VerifyScreenDump(buf, 'Test_diff_with_cul_bri_01', {})
1174 call term_sendkeys(buf, "j")
1175 call VerifyScreenDump(buf, 'Test_diff_with_cul_bri_02', {})
1176 call term_sendkeys(buf, "j")
1177 call VerifyScreenDump(buf, 'Test_diff_with_cul_bri_03', {})
1178 call term_sendkeys(buf, "j")
1179 call VerifyScreenDump(buf, 'Test_diff_with_cul_bri_04', {})
1180
1181 " clean up
1182 call StopVimInTerminal(buf)
zeertzjq4f33bc22021-08-05 17:57:02 +02001183endfunc
1184
zeertzjq588f20d2023-12-05 15:47:09 +01001185func Test_diff_breakindent_after_filler()
1186 CheckScreendump
1187
1188 let lines =<< trim END
zeertzjqf0a9d652024-02-12 22:53:20 +01001189 set laststatus=0 diffopt+=followwrap breakindent breakindentopt=min:0
zeertzjq588f20d2023-12-05 15:47:09 +01001190 call setline(1, ['a', ' ' .. repeat('c', 50)])
1191 vnew
1192 call setline(1, ['a', 'b', ' ' .. repeat('c', 50)])
1193 windo diffthis
1194 norm! G$
1195 END
1196 call writefile(lines, 'Xtest_diff_breakindent_after_filler', 'D')
1197 let buf = RunVimInTerminal('-S Xtest_diff_breakindent_after_filler', #{rows: 8, cols: 45})
1198 call VerifyScreenDump(buf, 'Test_diff_breakindent_after_filler', {})
1199
1200 " clean up
1201 call StopVimInTerminal(buf)
1202endfunc
1203
Bram Moolenaar248fdb32019-09-15 19:31:28 +02001204func Test_diff_with_syntax()
1205 CheckScreendump
1206
1207 let lines =<< trim END
Bram Moolenaar94722c52023-01-28 19:19:03 +00001208 void doNothing() {
Bram Moolenaar248fdb32019-09-15 19:31:28 +02001209 int x = 0;
1210 char *s = "hello";
1211 return 5;
1212 }
1213 END
Bram Moolenaar59173412022-09-20 22:01:33 +01001214 call writefile(lines, 'Xprogram1.c', 'D')
Bram Moolenaar248fdb32019-09-15 19:31:28 +02001215 let lines =<< trim END
Bram Moolenaar94722c52023-01-28 19:19:03 +00001216 void doSomething() {
Bram Moolenaar248fdb32019-09-15 19:31:28 +02001217 int x = 0;
1218 char *s = "there";
1219 return 5;
1220 }
1221 END
Bram Moolenaar59173412022-09-20 22:01:33 +01001222 call writefile(lines, 'Xprogram2.c', 'D')
Bram Moolenaar248fdb32019-09-15 19:31:28 +02001223
1224 let lines =<< trim END
Bram Moolenaar94722c52023-01-28 19:19:03 +00001225 edit Xprogram1.c
Bram Moolenaar248fdb32019-09-15 19:31:28 +02001226 diffsplit Xprogram2.c
1227 END
Bram Moolenaar59173412022-09-20 22:01:33 +01001228 call writefile(lines, 'Xtest_diff_syntax', 'D')
Bram Moolenaar248fdb32019-09-15 19:31:28 +02001229 let buf = RunVimInTerminal('-S Xtest_diff_syntax', {})
1230
1231 call VerifyScreenDump(buf, 'Test_diff_syntax_1', {})
1232
1233 " clean up
1234 call StopVimInTerminal(buf)
Bram Moolenaar248fdb32019-09-15 19:31:28 +02001235endfunc
1236
Bram Moolenaarf7acf2b2018-11-01 21:14:53 +01001237func Test_diff_of_diff()
Bram Moolenaar3c8ee622019-08-03 22:55:50 +02001238 CheckScreendump
1239 CheckFeature rightleft
Bram Moolenaarf7acf2b2018-11-01 21:14:53 +01001240
1241 call writefile([
1242 \ 'call setline(1, ["aa","bb","cc","@@ -3,2 +5,7 @@","dd","ee","ff"])',
1243 \ 'vnew',
1244 \ 'call setline(1, ["aa","bb","cc"])',
1245 \ 'windo diffthis',
Bram Moolenaar8ee4c012019-03-29 18:08:18 +01001246 \ '1wincmd w',
1247 \ 'setlocal number',
Bram Moolenaar59173412022-09-20 22:01:33 +01001248 \ ], 'Xtest_diff_diff', 'D')
Bram Moolenaarf7acf2b2018-11-01 21:14:53 +01001249 let buf = RunVimInTerminal('-S Xtest_diff_diff', {})
1250
1251 call VerifyScreenDump(buf, 'Test_diff_of_diff_01', {})
1252
Bram Moolenaare73f9112019-03-29 18:29:54 +01001253 call term_sendkeys(buf, ":set rightleft\<cr>")
1254 call VerifyScreenDump(buf, 'Test_diff_of_diff_02', {})
1255
Bram Moolenaarf7acf2b2018-11-01 21:14:53 +01001256 " clean up
1257 call StopVimInTerminal(buf)
Bram Moolenaarf7acf2b2018-11-01 21:14:53 +01001258endfunc
Bram Moolenaarc8234772019-11-10 21:00:27 +01001259
1260func CloseoffSetup()
1261 enew
1262 call setline(1, ['one', 'two', 'three'])
1263 diffthis
1264 new
1265 call setline(1, ['one', 'tow', 'three'])
1266 diffthis
1267 call assert_equal(1, &diff)
Jonathonca307ef2025-01-17 13:37:35 +01001268 bw!
Bram Moolenaarc8234772019-11-10 21:00:27 +01001269endfunc
1270
1271func Test_diff_closeoff()
1272 " "closeoff" included by default: last diff win gets 'diff' reset'
1273 call CloseoffSetup()
1274 call assert_equal(0, &diff)
1275 enew!
1276
1277 " "closeoff" excluded: last diff win keeps 'diff' set'
1278 set diffopt-=closeoff
1279 call CloseoffSetup()
1280 call assert_equal(1, &diff)
1281 diffoff!
1282 enew!
1283endfunc
Bram Moolenaarf4a1d1c2019-11-16 13:50:25 +01001284
Bram Moolenaar4223d432021-02-10 13:18:17 +01001285func Test_diff_followwrap()
1286 new
1287 set diffopt+=followwrap
1288 set wrap
1289 diffthis
1290 call assert_equal(1, &wrap)
1291 diffoff
1292 set nowrap
1293 diffthis
1294 call assert_equal(0, &wrap)
1295 diffoff
1296 set diffopt&
1297 bwipe!
1298endfunc
1299
Bram Moolenaarf4a1d1c2019-11-16 13:50:25 +01001300func Test_diff_maintains_change_mark()
Sean Dewarccc16442021-12-29 16:44:48 +00001301 func DiffMaintainsChangeMark()
1302 enew!
1303 call setline(1, ['a', 'b', 'c', 'd'])
1304 diffthis
1305 new
1306 call setline(1, ['a', 'b', 'c', 'e'])
1307 " Set '[ and '] marks
1308 2,3yank
1309 call assert_equal([2, 3], [line("'["), line("']")])
1310 " Verify they aren't affected by the implicit diff
1311 diffthis
1312 call assert_equal([2, 3], [line("'["), line("']")])
1313 " Verify they aren't affected by an explicit diff
1314 diffupdate
1315 call assert_equal([2, 3], [line("'["), line("']")])
1316 bwipe!
1317 bwipe!
1318 endfunc
1319
1320 set diffopt-=internal
1321 call DiffMaintainsChangeMark()
1322 set diffopt+=internal
1323 call DiffMaintainsChangeMark()
Bram Moolenaard9b74a22022-01-16 15:00:08 +00001324
Sean Dewarccc16442021-12-29 16:44:48 +00001325 set diffopt&
Bram Moolenaard9b74a22022-01-16 15:00:08 +00001326 delfunc DiffMaintainsChangeMark
Bram Moolenaarf4a1d1c2019-11-16 13:50:25 +01001327endfunc
Bram Moolenaar8dfcce32020-03-18 19:32:26 +01001328
1329" Test for 'patchexpr'
1330func Test_patchexpr()
1331 let g:patch_args = []
1332 func TPatch()
1333 call add(g:patch_args, readfile(v:fname_in))
1334 call add(g:patch_args, readfile(v:fname_diff))
1335 call writefile(['output file'], v:fname_out)
1336 endfunc
1337 set patchexpr=TPatch()
1338
Bram Moolenaar59173412022-09-20 22:01:33 +01001339 call writefile(['input file'], 'Xinput', 'D')
1340 call writefile(['diff file'], 'Xdiff', 'D')
Bram Moolenaar8dfcce32020-03-18 19:32:26 +01001341 %bwipe!
1342 edit Xinput
1343 diffpatch Xdiff
1344 call assert_equal('output file', getline(1))
1345 call assert_equal('Xinput.new', bufname())
1346 call assert_equal(2, winnr('$'))
1347 call assert_true(&diff)
1348
Yegappan Lakshmanan8bb65f22021-12-26 10:51:39 +00001349 " Using a script-local function
1350 func s:NewPatchExpr()
1351 endfunc
1352 set patchexpr=s:NewPatchExpr()
1353 call assert_equal(expand('<SID>') .. 'NewPatchExpr()', &patchexpr)
1354 set patchexpr=<SID>NewPatchExpr()
1355 call assert_equal(expand('<SID>') .. 'NewPatchExpr()', &patchexpr)
1356
Bram Moolenaar8dfcce32020-03-18 19:32:26 +01001357 set patchexpr&
1358 delfunc TPatch
Yegappan Lakshmanan8bb65f22021-12-26 10:51:39 +00001359 delfunc s:NewPatchExpr
Bram Moolenaar8dfcce32020-03-18 19:32:26 +01001360 %bwipe!
1361endfunc
1362
Bram Moolenaar511feec2020-06-18 19:15:27 +02001363func Test_diff_rnu()
1364 CheckScreendump
1365
1366 let content =<< trim END
1367 call setline(1, ['a', 'a', 'a', 'y', 'b', 'b', 'b', 'b', 'b'])
1368 vnew
1369 call setline(1, ['a', 'a', 'a', 'x', 'x', 'x', 'b', 'b', 'b', 'b', 'b'])
1370 windo diffthis
1371 setlocal number rnu foldcolumn=0
1372 END
Bram Moolenaar59173412022-09-20 22:01:33 +01001373 call writefile(content, 'Xtest_diff_rnu', 'D')
Bram Moolenaar511feec2020-06-18 19:15:27 +02001374 let buf = RunVimInTerminal('-S Xtest_diff_rnu', {})
1375
1376 call VerifyScreenDump(buf, 'Test_diff_rnu_01', {})
1377
1378 call term_sendkeys(buf, "j")
1379 call VerifyScreenDump(buf, 'Test_diff_rnu_02', {})
1380 call term_sendkeys(buf, "j")
1381 call VerifyScreenDump(buf, 'Test_diff_rnu_03', {})
1382
1383 " clean up
1384 call StopVimInTerminal(buf)
Bram Moolenaar511feec2020-06-18 19:15:27 +02001385endfunc
1386
Bram Moolenaarfc838d62020-06-25 22:23:48 +02001387func Test_diff_multilineconceal()
1388 new
1389 diffthis
1390
1391 new
1392 call matchadd('Conceal', 'a\nb', 9, -1, {'conceal': 'Y'})
1393 set cole=2 cocu=n
1394 call setline(1, ["a", "b"])
1395 diffthis
1396 redraw
1397endfunc
1398
Bram Moolenaar8455c5e2020-07-14 21:22:30 +02001399func Test_diff_and_scroll()
1400 " this was causing an ml_get error
1401 set ls=2
Bram Moolenaar94722c52023-01-28 19:19:03 +00001402 for i in range(winheight(0) * 2)
1403 call setline(i, i < winheight(0) - 10 ? i : i + 10)
Bram Moolenaar8455c5e2020-07-14 21:22:30 +02001404 endfor
1405 vnew
Bram Moolenaar94722c52023-01-28 19:19:03 +00001406 for i in range(winheight(0)*2 + 10)
1407 call setline(i, i < winheight(0) - 10 ? 0 : i)
Bram Moolenaar8455c5e2020-07-14 21:22:30 +02001408 endfor
1409 diffthis
1410 wincmd p
1411 diffthis
1412 execute 'normal ' . winheight(0) . "\<C-d>"
1413
1414 bwipe!
1415 bwipe!
1416 set ls&
1417endfunc
1418
Bram Moolenaarfabc3ca2020-11-05 19:07:21 +01001419func Test_diff_filler_cursorcolumn()
1420 CheckScreendump
1421
1422 let content =<< trim END
1423 call setline(1, ['aa', 'bb', 'cc'])
1424 vnew
1425 call setline(1, ['aa', 'cc'])
1426 windo diffthis
1427 wincmd p
1428 setlocal cursorcolumn foldcolumn=0
1429 norm! gg0
1430 redraw!
1431 END
Bram Moolenaar59173412022-09-20 22:01:33 +01001432 call writefile(content, 'Xtest_diff_cuc', 'D')
Bram Moolenaarfabc3ca2020-11-05 19:07:21 +01001433 let buf = RunVimInTerminal('-S Xtest_diff_cuc', {})
1434
1435 call VerifyScreenDump(buf, 'Test_diff_cuc_01', {})
1436
1437 call term_sendkeys(buf, "l")
1438 call term_sendkeys(buf, "\<C-l>")
1439 call VerifyScreenDump(buf, 'Test_diff_cuc_02', {})
1440 call term_sendkeys(buf, "0j")
1441 call term_sendkeys(buf, "\<C-l>")
1442 call VerifyScreenDump(buf, 'Test_diff_cuc_03', {})
1443 call term_sendkeys(buf, "l")
1444 call term_sendkeys(buf, "\<C-l>")
1445 call VerifyScreenDump(buf, 'Test_diff_cuc_04', {})
1446
1447 " clean up
1448 call StopVimInTerminal(buf)
Bram Moolenaarfabc3ca2020-11-05 19:07:21 +01001449endfunc
1450
Yegappan Lakshmanan30443242021-06-10 21:52:15 +02001451" Test for adding/removing lines inside diff chunks, between diff chunks
1452" and before diff chunks
1453func Test_diff_modify_chunks()
1454 enew!
1455 let w2_id = win_getid()
1456 call setline(1, ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i'])
1457 new
1458 let w1_id = win_getid()
1459 call setline(1, ['a', '2', '3', 'd', 'e', 'f', '7', '8', 'i'])
1460 windo diffthis
1461
1462 " remove a line between two diff chunks and create a new diff chunk
1463 call win_gotoid(w2_id)
1464 5d
1465 call win_gotoid(w1_id)
1466 call diff_hlID(5, 1)->synIDattr('name')->assert_equal('DiffAdd')
1467
1468 " add a line between two diff chunks
1469 call win_gotoid(w2_id)
1470 normal! 4Goe
1471 call win_gotoid(w1_id)
1472 call diff_hlID(4, 1)->synIDattr('name')->assert_equal('')
1473 call diff_hlID(5, 1)->synIDattr('name')->assert_equal('')
1474
1475 " remove all the lines in a diff chunk.
1476 call win_gotoid(w2_id)
1477 7,8d
1478 call win_gotoid(w1_id)
1479 let hl = range(1, 9)->map({_, lnum -> diff_hlID(lnum, 1)->synIDattr('name')})
1480 call assert_equal(['', 'DiffText', 'DiffText', '', '', '', 'DiffAdd',
1481 \ 'DiffAdd', ''], hl)
1482
1483 " remove lines from one diff chunk to just before the next diff chunk
1484 call win_gotoid(w2_id)
1485 call setline(1, ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i'])
1486 2,6d
1487 call win_gotoid(w1_id)
1488 let hl = range(1, 9)->map({_, lnum -> diff_hlID(lnum, 1)->synIDattr('name')})
1489 call assert_equal(['', 'DiffText', 'DiffText', 'DiffAdd', 'DiffAdd',
1490 \ 'DiffAdd', 'DiffAdd', 'DiffAdd', ''], hl)
1491
1492 " remove lines just before the top of a diff chunk
1493 call win_gotoid(w2_id)
1494 call setline(1, ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i'])
1495 5,6d
1496 call win_gotoid(w1_id)
1497 let hl = range(1, 9)->map({_, lnum -> diff_hlID(lnum, 1)->synIDattr('name')})
1498 call assert_equal(['', 'DiffText', 'DiffText', '', 'DiffText', 'DiffText',
1499 \ 'DiffAdd', 'DiffAdd', ''], hl)
1500
1501 " remove line after the end of a diff chunk
1502 call win_gotoid(w2_id)
1503 call setline(1, ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i'])
1504 4d
1505 call win_gotoid(w1_id)
1506 let hl = range(1, 9)->map({_, lnum -> diff_hlID(lnum, 1)->synIDattr('name')})
1507 call assert_equal(['', 'DiffText', 'DiffText', 'DiffAdd', '', '', 'DiffText',
1508 \ 'DiffText', ''], hl)
1509
1510 " remove lines starting from the end of one diff chunk and ending inside
1511 " another diff chunk
1512 call win_gotoid(w2_id)
1513 call setline(1, ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i'])
1514 4,7d
1515 call win_gotoid(w1_id)
1516 let hl = range(1, 9)->map({_, lnum -> diff_hlID(lnum, 1)->synIDattr('name')})
1517 call assert_equal(['', 'DiffText', 'DiffText', 'DiffText', 'DiffAdd',
1518 \ 'DiffAdd', 'DiffAdd', 'DiffAdd', ''], hl)
1519
1520 " removing the only remaining diff chunk should make the files equal
1521 call win_gotoid(w2_id)
1522 call setline(1, ['a', '2', '3', 'x', 'd', 'e', 'f', 'x', '7', '8', 'i'])
1523 8d
1524 let hl = range(1, 10)->map({_, lnum -> diff_hlID(lnum, 1)->synIDattr('name')})
1525 call assert_equal(['', '', '', 'DiffAdd', '', '', '', '', '', ''], hl)
1526 call win_gotoid(w2_id)
1527 4d
1528 call win_gotoid(w1_id)
1529 let hl = range(1, 9)->map({_, lnum -> diff_hlID(lnum, 1)->synIDattr('name')})
1530 call assert_equal(['', '', '', '', '', '', '', '', ''], hl)
1531
1532 %bw!
1533endfunc
glacambread5c1782021-05-24 14:20:53 +02001534
Bram Moolenaar06f60952021-12-28 18:30:05 +00001535func Test_diff_binary()
1536 CheckScreendump
1537
1538 let content =<< trim END
1539 call setline(1, ['a', 'b', "c\n", 'd', 'e', 'f', 'g'])
1540 vnew
1541 call setline(1, ['A', 'b', 'c', 'd', 'E', 'f', 'g'])
1542 windo diffthis
1543 wincmd p
1544 norm! gg0
1545 redraw!
1546 END
Bram Moolenaar59173412022-09-20 22:01:33 +01001547 call writefile(content, 'Xtest_diff_bin', 'D')
Bram Moolenaar06f60952021-12-28 18:30:05 +00001548 let buf = RunVimInTerminal('-S Xtest_diff_bin', {})
1549
1550 " Test using internal diff
1551 call VerifyScreenDump(buf, 'Test_diff_bin_01', {})
1552
1553 " Test using internal diff and case folding
1554 call term_sendkeys(buf, ":set diffopt+=icase\<cr>")
1555 call term_sendkeys(buf, "\<C-l>")
1556 call VerifyScreenDump(buf, 'Test_diff_bin_02', {})
1557 " Test using external diff
1558 call term_sendkeys(buf, ":set diffopt=filler\<cr>")
1559 call term_sendkeys(buf, "\<C-l>")
1560 call VerifyScreenDump(buf, 'Test_diff_bin_03', {})
1561 " Test using external diff and case folding
1562 call term_sendkeys(buf, ":set diffopt=filler,icase\<cr>")
1563 call term_sendkeys(buf, "\<C-l>")
1564 call VerifyScreenDump(buf, 'Test_diff_bin_04', {})
1565
1566 " clean up
1567 call StopVimInTerminal(buf)
Bram Moolenaar06f60952021-12-28 18:30:05 +00001568 set diffopt&vim
1569endfunc
1570
Yegappan Lakshmananb0ad2d92022-01-27 13:16:59 +00001571" Test for using the 'zi' command to invert 'foldenable' in diff windows (test
1572" for the issue fixed by patch 6.2.317)
1573func Test_diff_foldinvert()
1574 %bw!
Bram Moolenaar61abe7d2022-08-30 21:46:08 +01001575 edit Xdoffile1
1576 new Xdoffile2
1577 new Xdoffile3
Yegappan Lakshmananb0ad2d92022-01-27 13:16:59 +00001578 windo diffthis
1579 " open a non-diff window
1580 botright new
1581 1wincmd w
1582 call assert_true(getwinvar(1, '&foldenable'))
1583 call assert_true(getwinvar(2, '&foldenable'))
1584 call assert_true(getwinvar(3, '&foldenable'))
1585 normal zi
1586 call assert_false(getwinvar(1, '&foldenable'))
1587 call assert_false(getwinvar(2, '&foldenable'))
1588 call assert_false(getwinvar(3, '&foldenable'))
1589 normal zi
1590 call assert_true(getwinvar(1, '&foldenable'))
1591 call assert_true(getwinvar(2, '&foldenable'))
1592 call assert_true(getwinvar(3, '&foldenable'))
1593
1594 " If the current window has 'noscrollbind', then 'zi' should not change
1595 " 'foldenable' in other windows.
1596 1wincmd w
1597 set noscrollbind
1598 normal zi
1599 call assert_false(getwinvar(1, '&foldenable'))
1600 call assert_true(getwinvar(2, '&foldenable'))
1601 call assert_true(getwinvar(3, '&foldenable'))
1602
1603 " 'zi' should not change the 'foldenable' for windows with 'noscrollbind'
1604 1wincmd w
1605 set scrollbind
1606 normal zi
1607 call setwinvar(2, '&scrollbind', v:false)
1608 normal zi
1609 call assert_false(getwinvar(1, '&foldenable'))
1610 call assert_true(getwinvar(2, '&foldenable'))
1611 call assert_false(getwinvar(3, '&foldenable'))
1612
1613 %bw!
1614 set scrollbind&
1615endfunc
1616
Bram Moolenaara315ce12022-06-24 12:38:57 +01001617" This was scrolling for 'cursorbind' but 'scrollbind' is more important
1618func Test_diff_scroll()
1619 CheckScreendump
1620
1621 let left =<< trim END
1622 line 1
1623 line 2
1624 line 3
1625 line 4
1626
1627 // Common block
1628 // one
1629 // containing
1630 // four lines
1631
1632 // Common block
1633 // two
1634 // containing
1635 // four lines
1636 END
Bram Moolenaar59173412022-09-20 22:01:33 +01001637 call writefile(left, 'Xleft', 'D')
Bram Moolenaara315ce12022-06-24 12:38:57 +01001638 let right =<< trim END
1639 line 1
1640 line 2
1641 line 3
1642 line 4
1643
1644 Lorem
1645 ipsum
1646 dolor
1647 sit
1648 amet,
1649 consectetur
1650 adipiscing
1651 elit.
1652 Etiam
1653 luctus
1654 lectus
1655 sodales,
1656 dictum
1657
1658 // Common block
1659 // one
1660 // containing
1661 // four lines
1662
1663 Vestibulum
1664 tincidunt
1665 aliquet
1666 nulla.
1667
1668 // Common block
1669 // two
1670 // containing
1671 // four lines
1672 END
Bram Moolenaar59173412022-09-20 22:01:33 +01001673 call writefile(right, 'Xright', 'D')
Bram Moolenaara315ce12022-06-24 12:38:57 +01001674 let buf = RunVimInTerminal('-d Xleft Xright', {'rows': 12})
1675 call term_sendkeys(buf, "\<C-W>\<C-W>jjjj")
1676 call VerifyScreenDump(buf, 'Test_diff_scroll_1', {})
1677 call term_sendkeys(buf, "j")
1678 call VerifyScreenDump(buf, 'Test_diff_scroll_2', {})
1679
1680 call StopVimInTerminal(buf)
Bram Moolenaara315ce12022-06-24 12:38:57 +01001681endfunc
1682
Bram Moolenaar38d867f2023-04-01 19:54:40 +01001683" This was scrolling too many lines.
1684func Test_diff_scroll_wrap_on()
1685 20new
1686 40vsplit
1687 call setline(1, map(range(1, 9), 'repeat(v:val, 200)'))
1688 setlocal number diff so=0
1689 redraw
1690 normal! jj
1691 call assert_equal(1, winsaveview().topline)
1692 normal! j
1693 call assert_equal(2, winsaveview().topline)
zeertzjq05834912023-10-04 20:12:37 +02001694
1695 bwipe!
1696 bwipe!
1697endfunc
1698
1699func Test_diff_scroll_many_filler()
1700 20new
1701 vnew
Luuk van Baalb9f5b952024-03-26 18:46:45 +01001702 call setline(1, range(1, 40))
zeertzjq05834912023-10-04 20:12:37 +02001703 diffthis
1704 setlocal scrolloff=0
1705 wincmd p
Luuk van Baalb9f5b952024-03-26 18:46:45 +01001706 call setline(1, range(1, 20)->reverse() + ['###']->repeat(41) + range(21, 40)->reverse())
zeertzjq05834912023-10-04 20:12:37 +02001707 diffthis
1708 setlocal scrolloff=0
1709 wincmd p
1710 redraw
1711
1712 " Note: need a redraw after each scroll, otherwise the test always passes.
Luuk van Baalb9f5b952024-03-26 18:46:45 +01001713 for _ in range(2)
1714 normal! G
1715 redraw
1716 call assert_equal(40, winsaveview().topline)
1717 call assert_equal(19, winsaveview().topfill)
1718 exe "normal! \<C-B>"
1719 redraw
1720 call assert_equal(22, winsaveview().topline)
1721 call assert_equal(0, winsaveview().topfill)
1722 exe "normal! \<C-B>"
1723 redraw
1724 call assert_equal(4, winsaveview().topline)
1725 call assert_equal(0, winsaveview().topfill)
1726 exe "normal! \<C-B>"
1727 redraw
1728 call assert_equal(1, winsaveview().topline)
1729 call assert_equal(0, winsaveview().topfill)
1730 set smoothscroll
1731 endfor
zeertzjq05834912023-10-04 20:12:37 +02001732
Luuk van Baalb9f5b952024-03-26 18:46:45 +01001733 set smoothscroll&
Luuk van Baalcb204e62024-04-02 20:49:45 +02001734 %bwipe!
Bram Moolenaar38d867f2023-04-01 19:54:40 +01001735endfunc
1736
Bram Moolenaarcd38bb42022-06-26 14:04:07 +01001737" This was trying to update diffs for a buffer being closed
1738func Test_diff_only()
1739 silent! lfile
1740 set diff
1741 lopen
1742 norm o
1743 silent! norm o
1744
1745 set nodiff
1746 %bwipe!
1747endfunc
1748
Bram Moolenaarc101abf2022-06-26 16:53:34 +01001749" This was causing invalid diff block values
1750" FIXME: somehow this causes a valgrind error when run directly but not when
1751" run as a test.
1752func Test_diff_manipulations()
1753 set diff
1754 split 0
1755 sil! norm R doobdeuR doobdeuR doobdeu
1756
1757 set nodiff
1758 %bwipe!
1759endfunc
1760
Bram Moolenaar4e677b92022-07-28 18:44:27 +01001761" This was causing the line number in the diff block to go below one.
1762" FIXME: somehow this causes a valgrind error when run directly but not when
1763" run as a test.
1764func Test_diff_put_and_undo()
1765 set diff
1766 next 0
1767 split 00
1768 sil! norm o0gguudpo0ggJuudp
1769
1770 bwipe!
1771 bwipe!
1772 set nodiff
1773endfunc
1774
Yegappan Lakshmananfa378352024-02-01 22:05:27 +01001775" Test for the diff() function
1776def Test_diff_func()
1777 # string is added/removed/modified at the beginning
Yegappan Lakshmanana0010a12024-02-12 20:21:26 +01001778 assert_equal("@@ -0,0 +1 @@\n+abc\n",
Yegappan Lakshmananfa378352024-02-01 22:05:27 +01001779 diff(['def'], ['abc', 'def'], {output: 'unified'}))
1780 assert_equal([{from_idx: 0, from_count: 0, to_idx: 0, to_count: 1}],
1781 diff(['def'], ['abc', 'def'], {output: 'indices'}))
Yegappan Lakshmanana0010a12024-02-12 20:21:26 +01001782 assert_equal("@@ -1 +0,0 @@\n-abc\n",
Yegappan Lakshmananfa378352024-02-01 22:05:27 +01001783 diff(['abc', 'def'], ['def'], {output: 'unified'}))
1784 assert_equal([{from_idx: 0, from_count: 1, to_idx: 0, to_count: 0}],
1785 diff(['abc', 'def'], ['def'], {output: 'indices'}))
Yegappan Lakshmanana0010a12024-02-12 20:21:26 +01001786 assert_equal("@@ -1 +1 @@\n-abc\n+abx\n",
Yegappan Lakshmananfa378352024-02-01 22:05:27 +01001787 diff(['abc', 'def'], ['abx', 'def'], {output: 'unified'}))
1788 assert_equal([{from_idx: 0, from_count: 1, to_idx: 0, to_count: 1}],
1789 diff(['abc', 'def'], ['abx', 'def'], {output: 'indices'}))
1790
1791 # string is added/removed/modified at the end
Yegappan Lakshmanana0010a12024-02-12 20:21:26 +01001792 assert_equal("@@ -1,0 +2 @@\n+def\n",
Yegappan Lakshmananfa378352024-02-01 22:05:27 +01001793 diff(['abc'], ['abc', 'def'], {output: 'unified'}))
1794 assert_equal([{from_idx: 1, from_count: 0, to_idx: 1, to_count: 1}],
1795 diff(['abc'], ['abc', 'def'], {output: 'indices'}))
Yegappan Lakshmanana0010a12024-02-12 20:21:26 +01001796 assert_equal("@@ -2 +1,0 @@\n-def\n",
Yegappan Lakshmananfa378352024-02-01 22:05:27 +01001797 diff(['abc', 'def'], ['abc'], {output: 'unified'}))
1798 assert_equal([{from_idx: 1, from_count: 1, to_idx: 1, to_count: 0}],
1799 diff(['abc', 'def'], ['abc'], {output: 'indices'}))
Yegappan Lakshmanana0010a12024-02-12 20:21:26 +01001800 assert_equal("@@ -2 +2 @@\n-def\n+xef\n",
Yegappan Lakshmananfa378352024-02-01 22:05:27 +01001801 diff(['abc', 'def'], ['abc', 'xef'], {output: 'unified'}))
1802 assert_equal([{from_idx: 1, from_count: 1, to_idx: 1, to_count: 1}],
1803 diff(['abc', 'def'], ['abc', 'xef'], {output: 'indices'}))
1804
1805 # string is added/removed/modified in the middle
Yegappan Lakshmanana0010a12024-02-12 20:21:26 +01001806 assert_equal("@@ -2,0 +3 @@\n+xxx\n",
Yegappan Lakshmananfa378352024-02-01 22:05:27 +01001807 diff(['111', '222', '333'], ['111', '222', 'xxx', '333'], {output: 'unified'}))
1808 assert_equal([{from_idx: 2, from_count: 0, to_idx: 2, to_count: 1}],
1809 diff(['111', '222', '333'], ['111', '222', 'xxx', '333'], {output: 'indices'}))
Yegappan Lakshmanana0010a12024-02-12 20:21:26 +01001810 assert_equal("@@ -3 +2,0 @@\n-333\n",
Yegappan Lakshmananfa378352024-02-01 22:05:27 +01001811 diff(['111', '222', '333', '444'], ['111', '222', '444'], {output: 'unified'}))
1812 assert_equal([{from_idx: 2, from_count: 1, to_idx: 2, to_count: 0}],
1813 diff(['111', '222', '333', '444'], ['111', '222', '444'], {output: 'indices'}))
Yegappan Lakshmanana0010a12024-02-12 20:21:26 +01001814 assert_equal("@@ -3 +3 @@\n-333\n+xxx\n",
Yegappan Lakshmananfa378352024-02-01 22:05:27 +01001815 diff(['111', '222', '333', '444'], ['111', '222', 'xxx', '444'], {output: 'unified'}))
1816 assert_equal([{from_idx: 2, from_count: 1, to_idx: 2, to_count: 1}],
1817 diff(['111', '222', '333', '444'], ['111', '222', 'xxx', '444'], {output: 'indices'}))
1818
1819 # new strings are added to an empty List
1820 assert_equal("@@ -0,0 +1,2 @@\n+abc\n+def\n",
1821 diff([], ['abc', 'def'], {output: 'unified'}))
1822 assert_equal([{from_idx: 0, from_count: 0, to_idx: 0, to_count: 2}],
1823 diff([], ['abc', 'def'], {output: 'indices'}))
1824
1825 # all the strings are removed from a List
1826 assert_equal("@@ -1,2 +0,0 @@\n-abc\n-def\n",
1827 diff(['abc', 'def'], [], {output: 'unified'}))
1828 assert_equal([{from_idx: 0, from_count: 2, to_idx: 0, to_count: 0}],
1829 diff(['abc', 'def'], [], {output: 'indices'}))
1830
1831 # First character is added/removed/different
1832 assert_equal("@@ -1 +1 @@\n-abc\n+bc\n",
1833 diff(['abc'], ['bc'], {output: 'unified'}))
1834 assert_equal([{from_idx: 0, from_count: 1, to_idx: 0, to_count: 1}],
1835 diff(['abc'], ['bc'], {output: 'indices'}))
1836 assert_equal("@@ -1 +1 @@\n-bc\n+abc\n",
1837 diff(['bc'], ['abc'], {output: 'unified'}))
1838 assert_equal([{from_idx: 0, from_count: 1, to_idx: 0, to_count: 1}],
1839 diff(['bc'], ['abc'], {output: 'indices'}))
1840 assert_equal("@@ -1 +1 @@\n-abc\n+xbc\n",
1841 diff(['abc'], ['xbc'], {output: 'unified'}))
1842 assert_equal([{from_idx: 0, from_count: 1, to_idx: 0, to_count: 1}],
1843 diff(['abc'], ['xbc'], {output: 'indices'}))
1844
1845 # Last character is added/removed/different
1846 assert_equal("@@ -1 +1 @@\n-abc\n+abcd\n",
1847 diff(['abc'], ['abcd'], {output: 'unified'}))
1848 assert_equal([{from_idx: 0, from_count: 1, to_idx: 0, to_count: 1}],
1849 diff(['abc'], ['abcd'], {output: 'indices'}))
1850 assert_equal("@@ -1 +1 @@\n-abcd\n+abc\n",
1851 diff(['abcd'], ['abc'], {output: 'unified'}))
1852 assert_equal([{from_idx: 0, from_count: 1, to_idx: 0, to_count: 1}],
1853 diff(['abcd'], ['abc'], {output: 'indices'}))
Yegappan Lakshmanana0010a12024-02-12 20:21:26 +01001854 var diff_unified: string = diff(['abc'], ['abx'], {output: 'unified'})
1855 assert_equal("@@ -1 +1 @@\n-abc\n+abx\n", diff_unified)
1856 var diff_indices: list<dict<number>> =
1857 diff(['abc'], ['abx'], {output: 'indices'})
Yegappan Lakshmananfa378352024-02-01 22:05:27 +01001858 assert_equal([{from_idx: 0, from_count: 1, to_idx: 0, to_count: 1}],
Yegappan Lakshmanana0010a12024-02-12 20:21:26 +01001859 diff_indices)
Yegappan Lakshmananfa378352024-02-01 22:05:27 +01001860
1861 # partial string modification at the start and at the end.
1862 var fromlist =<< trim END
1863 one two
1864 three four
1865 five six
1866 END
1867 var tolist =<< trim END
1868 one
1869 six
1870 END
1871 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'}))
1872 assert_equal([{from_idx: 0, from_count: 3, to_idx: 0, to_count: 2}],
1873 diff(fromlist, tolist, {output: 'indices'}))
1874
1875 # non-contiguous modifications
1876 fromlist =<< trim END
1877 one two
1878 three four
1879 five abc six
1880 END
1881 tolist =<< trim END
1882 one abc two
1883 three four
1884 five six
1885 END
Yegappan Lakshmanana0010a12024-02-12 20:21:26 +01001886 assert_equal("@@ -1 +1 @@\n-one two\n+one abc two\n@@ -3 +3 @@\n-five abc six\n+five six\n",
Yegappan Lakshmananfa378352024-02-01 22:05:27 +01001887 diff(fromlist, tolist, {output: 'unified'}))
Yegappan Lakshmanana0010a12024-02-12 20:21:26 +01001888 assert_equal([{'from_count': 1, 'to_idx': 0, 'to_count': 1, 'from_idx': 0},
1889 {'from_count': 1, 'to_idx': 2, 'to_count': 1, 'from_idx': 2}],
Yegappan Lakshmananfa378352024-02-01 22:05:27 +01001890 diff(fromlist, tolist, {output: 'indices'}))
1891
1892 # add/remove blank lines
Yegappan Lakshmanana0010a12024-02-12 20:21:26 +01001893 assert_equal("@@ -2,2 +1,0 @@\n-\n-\n",
Yegappan Lakshmananfa378352024-02-01 22:05:27 +01001894 diff(['one', '', '', 'two'], ['one', 'two'], {output: 'unified'}))
1895 assert_equal([{from_idx: 1, from_count: 2, to_idx: 1, to_count: 0}],
1896 diff(['one', '', '', 'two'], ['one', 'two'], {output: 'indices'}))
Yegappan Lakshmanana0010a12024-02-12 20:21:26 +01001897 assert_equal("@@ -1,0 +2,2 @@\n+\n+\n",
Yegappan Lakshmananfa378352024-02-01 22:05:27 +01001898 diff(['one', 'two'], ['one', '', '', 'two'], {output: 'unified'}))
1899 assert_equal([{'from_idx': 1, 'from_count': 0, 'to_idx': 1, 'to_count': 2}],
1900 diff(['one', 'two'], ['one', '', '', 'two'], {output: 'indices'}))
1901
1902 # diff ignoring case
1903 assert_equal('', diff(['abc', 'def'], ['ABC', 'DEF'], {icase: true, output: 'unified'}))
1904 assert_equal([], diff(['abc', 'def'], ['ABC', 'DEF'], {icase: true, output: 'indices'}))
1905
1906 # diff ignoring all whitespace changes except leading whitespace changes
1907 assert_equal('', diff(['abc def'], ['abc def '], {iwhite: true}))
1908 assert_equal("@@ -1 +1 @@\n- abc\n+ xxx\n", diff([' abc'], [' xxx'], {iwhite: v:true}))
1909 assert_equal("@@ -1 +1 @@\n- abc\n+ xxx\n", diff([' abc'], [' xxx'], {iwhite: v:false}))
1910 assert_equal("@@ -1 +1 @@\n-abc \n+xxx \n", diff(['abc '], ['xxx '], {iwhite: v:true}))
1911 assert_equal("@@ -1 +1 @@\n-abc \n+xxx \n", diff(['abc '], ['xxx '], {iwhite: v:false}))
1912
1913 # diff ignoring all whitespace changes
1914 assert_equal('', diff(['abc def'], [' abc def '], {iwhiteall: true}))
1915 assert_equal("@@ -1 +1 @@\n- abc \n+ xxx \n", diff([' abc '], [' xxx '], {iwhiteall: v:true}))
1916 assert_equal("@@ -1 +1 @@\n- abc \n+ xxx \n", diff([' abc '], [' xxx '], {iwhiteall: v:false}))
1917
1918 # diff ignoring trailing whitespace changes
1919 assert_equal('', diff(['abc'], ['abc '], {iwhiteeol: true}))
1920
1921 # diff ignoring blank lines
1922 assert_equal('', diff(['one', '', '', 'two'], ['one', 'two'], {iblank: true}))
1923 assert_equal('', diff(['one', 'two'], ['one', '', '', 'two'], {iblank: true}))
1924
1925 # same string
1926 assert_equal('', diff(['abc', 'def', 'ghi'], ['abc', 'def', 'ghi']))
1927 assert_equal('', diff([''], ['']))
1928 assert_equal('', diff([], []))
1929
1930 # different xdiff algorithms
1931 for algo in ['myers', 'minimal', 'patience', 'histogram']
1932 assert_equal("@@ -1 +1 @@\n- abc \n+ xxx \n",
1933 diff([' abc '], [' xxx '], {algorithm: algo, output: 'unified'}))
1934 assert_equal([{from_idx: 0, from_count: 1, to_idx: 0, to_count: 1}],
1935 diff([' abc '], [' xxx '], {algorithm: algo, output: 'indices'}))
1936 endfor
1937 assert_equal("@@ -1 +1 @@\n- abc \n+ xxx \n",
1938 diff([' abc '], [' xxx '], {indent-heuristic: true, output: 'unified'}))
1939 assert_equal([{from_idx: 0, from_count: 1, to_idx: 0, to_count: 1}],
1940 diff([' abc '], [' xxx '], {indent-heuristic: true, output: 'indices'}))
1941
1942 # identical strings
1943 assert_equal('', diff(['111', '222'], ['111', '222'], {output: 'unified'}))
1944 assert_equal([], diff(['111', '222'], ['111', '222'], {output: 'indices'}))
1945 assert_equal('', diff([], [], {output: 'unified'}))
1946 assert_equal([], diff([], [], {output: 'indices'}))
1947
Yegappan Lakshmananbe156a32024-02-11 17:08:29 +01001948 # If 'diffexpr' is set, it should not be used for diff()
1949 def MyDiffExpr()
1950 enddef
1951 var save_diffexpr = &diffexpr
1952 :set diffexpr=MyDiffExpr()
1953 assert_equal("@@ -1 +1 @@\n-abc\n+\n",
1954 diff(['abc'], [''], {output: 'unified'}))
1955 assert_equal([{'from_idx': 0, 'from_count': 1, 'to_idx': 0, 'to_count': 1}],
1956 diff(['abc'], [''], {output: 'indices'}))
1957 assert_equal('MyDiffExpr()', &diffexpr)
1958 &diffexpr = save_diffexpr
1959
1960 # try different values for unified diff 'context'
1961 assert_equal("@@ -0,0 +1 @@\n+x\n",
1962 diff(['a', 'b', 'c'], ['x', 'a', 'b', 'c']))
1963 assert_equal("@@ -0,0 +1 @@\n+x\n",
1964 diff(['a', 'b', 'c'], ['x', 'a', 'b', 'c'], {context: 0}))
1965 assert_equal("@@ -1 +1,2 @@\n+x\n a\n",
1966 diff(['a', 'b', 'c'], ['x', 'a', 'b', 'c'], {context: 1}))
1967 assert_equal("@@ -1,2 +1,3 @@\n+x\n a\n b\n",
1968 diff(['a', 'b', 'c'], ['x', 'a', 'b', 'c'], {context: 2}))
1969 assert_equal("@@ -1,3 +1,4 @@\n+x\n a\n b\n c\n",
1970 diff(['a', 'b', 'c'], ['x', 'a', 'b', 'c'], {context: 3}))
1971 assert_equal("@@ -1,3 +1,4 @@\n+x\n a\n b\n c\n",
1972 diff(['a', 'b', 'c'], ['x', 'a', 'b', 'c'], {context: 4}))
Yegappan Lakshmanana0010a12024-02-12 20:21:26 +01001973 assert_equal("@@ -0,0 +1 @@\n+x\n",
Yegappan Lakshmananbe156a32024-02-11 17:08:29 +01001974 diff(['a', 'b', 'c'], ['x', 'a', 'b', 'c'], {context: -1}))
1975
Yegappan Lakshmananfa378352024-02-01 22:05:27 +01001976 # Error cases
1977 assert_fails('call diff({}, ["a"])', 'E1211:')
1978 assert_fails('call diff(["a"], {})', 'E1211:')
1979 assert_fails('call diff(["a"], ["a"], [])', 'E1206:')
1980 assert_fails('call diff(["a"], ["a"], {output: "xyz"})', 'E106: Unsupported diff output format: xyz')
Yegappan Lakshmananbe156a32024-02-11 17:08:29 +01001981 assert_fails('call diff(["a"], ["a"], {context: []})', 'E745: Using a List as a Number')
Yegappan Lakshmananfa378352024-02-01 22:05:27 +01001982enddef
Bram Moolenaara315ce12022-06-24 12:38:57 +01001983
Yegappan Lakshmanana0010a12024-02-12 20:21:26 +01001984" Test for using the diff() function with 'diffexpr'
1985func Test_diffexpr_with_diff_func()
1986 CheckScreendump
1987
1988 let lines =<< trim END
1989 def DiffFuncExpr()
1990 var in: list<string> = readfile(v:fname_in)
1991 var new: list<string> = readfile(v:fname_new)
1992 var out: string = diff(in, new)
1993 writefile(split(out, "\n"), v:fname_out)
1994 enddef
1995 set diffexpr=DiffFuncExpr()
1996
1997 edit Xdifffunc1.txt
1998 diffthis
1999 vert split Xdifffunc2.txt
2000 diffthis
2001 END
2002 call writefile(lines, 'XsetupDiffFunc.vim', 'D')
2003
2004 call writefile(['zero', 'one', 'two', 'three'], 'Xdifffunc1.txt', 'D')
2005 call writefile(['one', 'twox', 'three', 'four'], 'Xdifffunc2.txt', 'D')
2006
2007 let buf = RunVimInTerminal('-S XsetupDiffFunc.vim', {'rows': 12})
2008 call VerifyScreenDump(buf, 'Test_difffunc_diffexpr_1', {})
2009 call StopVimInTerminal(buf)
2010endfunc
2011
zeertzjq9e7f1fc2024-03-16 09:40:22 +01002012func Test_diff_toggle_wrap_skipcol_leftcol()
2013 61vnew
2014 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.')
2015 30vnew
2016 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.')
2017 let win1 = win_getid()
2018 setlocal smoothscroll
2019 exe "normal! $\<C-E>"
2020 wincmd l
2021 let win2 = win_getid()
2022 setlocal smoothscroll
2023 exe "normal! $\<C-E>"
2024 call assert_equal([
2025 \ '<<<sadipscing elitr, sed diam |<<<tetur sadipscing elitr, sed|',
2026 \ 'nonumy eirmod tempor invidunt | diam nonumy eirmod tempor inv|',
2027 \ 'ut labore et dolore magna aliq|idunt ut labore et dolore magn|',
2028 \ 'uyam erat, sed diam voluptua. |a aliquyam erat, sed diam volu|',
2029 \ '~ |ptua. |',
2030 \ ], ScreenLines([1, 5], 62))
2031 call assert_equal({'col': 29, 'row': 4, 'endcol': 29, 'curscol': 29},
2032 \ screenpos(win1, line('.', win1), col('.', win1)))
2033 call assert_equal({'col': 36, 'row': 5, 'endcol': 36, 'curscol': 36},
2034 \ screenpos(win2, line('.', win2), col('.', win2)))
2035
2036 wincmd h
2037 diffthis
2038 wincmd l
2039 diffthis
2040 normal! 0
2041 call assert_equal([
2042 \ ' ipsum dolor sit amet, conset| Lorem ipsum dolor sit amet, |',
2043 \ '~ |~ |',
2044 \ ], ScreenLines([1, 2], 62))
2045 call assert_equal({'col': 3, 'row': 1, 'endcol': 3, 'curscol': 3},
2046 \ screenpos(win1, line('.', win1), col('.', win1)))
2047 call assert_equal({'col': 34, 'row': 1, 'endcol': 34, 'curscol': 34},
2048 \ screenpos(win2, line('.', win2), col('.', win2)))
2049
2050 normal! $
2051 call assert_equal([
2052 \ ' voluptua. | diam voluptua. |',
2053 \ '~ |~ |',
2054 \ ], ScreenLines([1, 2], 62))
2055 call assert_equal({'col': 11, 'row': 1, 'endcol': 11, 'curscol': 11},
2056 \ screenpos(win1, line('.', win1), col('.', win1)))
2057 call assert_equal({'col': 48, 'row': 1, 'endcol': 48, 'curscol': 48},
2058 \ screenpos(win2, line('.', win2), col('.', win2)))
2059
2060 diffoff!
2061 call assert_equal([
2062 \ 'ipsum dolor sit amet, consetet|Lorem ipsum dolor sit amet, co|',
2063 \ 'ur sadipscing elitr, sed diam |nsetetur sadipscing elitr, sed|',
2064 \ 'nonumy eirmod tempor invidunt | diam nonumy eirmod tempor inv|',
2065 \ 'ut labore et dolore magna aliq|idunt ut labore et dolore magn|',
2066 \ 'uyam erat, sed diam voluptua. |a aliquyam erat, sed diam volu|',
2067 \ '~ |ptua. |',
2068 \ ], ScreenLines([1, 6], 62))
2069 call assert_equal({'col': 29, 'row': 5, 'endcol': 29, 'curscol': 29},
2070 \ screenpos(win1, line('.', win1), col('.', win1)))
2071 call assert_equal({'col': 36, 'row': 6, 'endcol': 36, 'curscol': 36},
2072 \ screenpos(win2, line('.', win2), col('.', win2)))
2073
2074 bwipe!
2075 bwipe!
2076endfunc
2077
Luuk van Baal9148ba82024-04-08 22:27:41 +02002078" Ctrl-D reveals filler lines below the last line in the buffer.
2079func Test_diff_eob_halfpage()
Luuk van Baal08b0f632024-04-09 22:43:49 +02002080 new
Luuk van Baal9148ba82024-04-08 22:27:41 +02002081 call setline(1, ['']->repeat(10) + ['a'])
2082 diffthis
Luuk van Baal08b0f632024-04-09 22:43:49 +02002083 new
Luuk van Baal9148ba82024-04-08 22:27:41 +02002084 call setline(1, ['']->repeat(3) + ['a', 'b'])
2085 diffthis
Luuk van Baal08b0f632024-04-09 22:43:49 +02002086 resize 5
Luuk van Baal9148ba82024-04-08 22:27:41 +02002087 wincmd j
Luuk van Baal08b0f632024-04-09 22:43:49 +02002088 resize 5
2089 norm G
2090 call assert_equal(7, line('w0'))
2091 exe "norm! \<C-D>"
2092 call assert_equal(8, line('w0'))
Luuk van Baal9148ba82024-04-08 22:27:41 +02002093
2094 %bwipe!
2095endfunc
2096
Yukihiro Nakadaira06fe70c2024-09-26 16:19:42 +02002097func Test_diff_overlapped_diff_blocks_will_be_merged()
2098 CheckScreendump
2099
2100 let lines =<< trim END
2101 func DiffExprStub()
2102 let txt_in = readfile(v:fname_in)
2103 let txt_new = readfile(v:fname_new)
2104 if txt_in == ["line1"] && txt_new == ["line2"]
2105 call writefile(["1c1"], v:fname_out)
2106 elseif txt_in == readfile("Xdiin1") && txt_new == readfile("Xdinew1")
2107 call writefile(readfile("Xdiout1"), v:fname_out)
2108 elseif txt_in == readfile("Xdiin2") && txt_new == readfile("Xdinew2")
2109 call writefile(readfile("Xdiout2"), v:fname_out)
2110 endif
2111 endfunc
2112 END
2113 call writefile(lines, 'XdiffSetup', 'D')
2114
2115 call WriteDiffFiles(0, [], [])
2116 let buf = RunVimInTerminal('-d -S XdiffSetup Xdifile1 Xdifile2', {})
2117 call term_sendkeys(buf, ":set autoread\<CR>\<c-w>w:set autoread\<CR>\<c-w>w")
2118
2119 call WriteDiffFiles(buf, ["a", "b"], ["x", "x"])
2120 call writefile(["a", "b"], "Xdiin1")
2121 call writefile(["x", "x"], "Xdinew1")
2122 call writefile(["1c1", "2c2"], "Xdiout1")
2123 call term_sendkeys(buf, ":set diffexpr=DiffExprStub()\<CR>:")
2124 call VerifyBoth(buf, "Test_diff_overlapped_2.01", "")
2125 call term_sendkeys(buf, ":set diffexpr&\<CR>:")
2126
2127 call WriteDiffFiles(buf, ["a", "b", "c"], ["x", "c"])
2128 call writefile(["a", "b", "c"], "Xdiin1")
2129 call writefile(["x", "c"], "Xdinew1")
2130 call writefile(["1c1", "2d1"], "Xdiout1")
2131 call term_sendkeys(buf, ":set diffexpr=DiffExprStub()\<CR>:")
2132 call VerifyBoth(buf, "Test_diff_overlapped_2.02", "")
2133 call term_sendkeys(buf, ":set diffexpr&\<CR>:")
2134
2135 call WriteDiffFiles(buf, ["a", "c"], ["x", "x", "c"])
2136 call writefile(["a", "c"], "Xdiin1")
2137 call writefile(["x", "x", "c"], "Xdinew1")
2138 call writefile(["1c1", "1a2"], "Xdiout1")
2139 call term_sendkeys(buf, ":set diffexpr=DiffExprStub()\<CR>:")
2140 call VerifyBoth(buf, "Test_diff_overlapped_2.03", "")
2141 call term_sendkeys(buf, ":set diffexpr&\<CR>:")
2142
2143 call StopVimInTerminal(buf)
2144 wincmd c
2145
2146 call WriteDiffFiles3(0, [], [], [])
2147 let buf = RunVimInTerminal('-d -S XdiffSetup Xdifile1 Xdifile2 Xdifile3', {})
2148 call term_sendkeys(buf, ":set autoread\<CR>\<c-w>w:set autoread\<CR>\<c-w>w:set autoread\<CR>\<c-w>w")
2149
2150 call WriteDiffFiles3(buf, ["a", "b", "c"], ["a", "x", "c"], ["y", "b", "c"])
2151 call VerifyBoth(buf, "Test_diff_overlapped_3.01", "")
2152
2153 call WriteDiffFiles3(buf, ["a", "b", "c"], ["a", "x", "c"], ["a", "y", "c"])
2154 call VerifyBoth(buf, "Test_diff_overlapped_3.02", "")
2155
2156 call WriteDiffFiles3(buf, ["a", "b", "c"], ["a", "x", "c"], ["a", "b", "y"])
2157 call VerifyBoth(buf, "Test_diff_overlapped_3.03", "")
2158
2159 call WriteDiffFiles3(buf, ["a", "b", "c"], ["a", "x", "c"], ["y", "y", "c"])
2160 call VerifyBoth(buf, "Test_diff_overlapped_3.04", "")
2161
2162 call WriteDiffFiles3(buf, ["a", "b", "c"], ["a", "x", "c"], ["a", "y", "y"])
2163 call VerifyBoth(buf, "Test_diff_overlapped_3.05", "")
2164
2165 call WriteDiffFiles3(buf, ["a", "b", "c"], ["a", "x", "c"], ["y", "y", "y"])
2166 call VerifyBoth(buf, "Test_diff_overlapped_3.06", "")
2167
2168 call WriteDiffFiles3(buf, ["a", "b", "c"], ["a", "x", "x"], ["y", "y", "c"])
2169 call VerifyBoth(buf, "Test_diff_overlapped_3.07", "")
2170
2171 call WriteDiffFiles3(buf, ["a", "b", "c"], ["x", "x", "c"], ["a", "y", "y"])
2172 call VerifyBoth(buf, "Test_diff_overlapped_3.08", "")
2173
2174 call WriteDiffFiles3(buf, ["a", "b", "c", "d", "e"], ["a", "x", "c", "x", "e"], ["y", "y", "y", "d", "e"])
2175 call VerifyBoth(buf, "Test_diff_overlapped_3.09", "")
2176
2177 call WriteDiffFiles3(buf, ["a", "b", "c", "d", "e"], ["a", "x", "c", "x", "e"], ["y", "y", "y", "y", "e"])
2178 call VerifyBoth(buf, "Test_diff_overlapped_3.10", "")
2179
2180 call WriteDiffFiles3(buf, ["a", "b", "c", "d", "e"], ["a", "x", "c", "x", "e"], ["y", "y", "y", "y", "y"])
2181 call VerifyBoth(buf, "Test_diff_overlapped_3.11", "")
2182
2183 call WriteDiffFiles3(buf, ["a", "b", "c", "d", "e"], ["a", "x", "c", "x", "e"], ["a", "y", "y", "d", "e"])
2184 call VerifyBoth(buf, "Test_diff_overlapped_3.12", "")
2185
2186 call WriteDiffFiles3(buf, ["a", "b", "c", "d", "e"], ["a", "x", "c", "x", "e"], ["a", "y", "y", "y", "e"])
2187 call VerifyBoth(buf, "Test_diff_overlapped_3.13", "")
2188
2189 call WriteDiffFiles3(buf, ["a", "b", "c", "d", "e"], ["a", "x", "c", "x", "e"], ["a", "y", "y", "y", "y"])
2190 call VerifyBoth(buf, "Test_diff_overlapped_3.14", "")
2191
2192 call WriteDiffFiles3(buf, ["a", "b", "c", "d", "e"], ["a", "x", "c", "x", "e"], ["a", "b", "y", "d", "e"])
2193 call VerifyBoth(buf, "Test_diff_overlapped_3.15", "")
2194
2195 call WriteDiffFiles3(buf, ["a", "b", "c", "d", "e"], ["a", "x", "c", "x", "e"], ["a", "b", "y", "y", "e"])
2196 call VerifyBoth(buf, "Test_diff_overlapped_3.16", "")
2197
2198 call WriteDiffFiles3(buf, ["a", "b", "c", "d", "e"], ["a", "x", "c", "x", "e"], ["a", "b", "y", "y", "y"])
2199 call VerifyBoth(buf, "Test_diff_overlapped_3.17", "")
2200
2201 call WriteDiffFiles3(buf, ["a", "b"], ["x", "b"], ["y", "y"])
2202 call writefile(["a", "b"], "Xdiin1")
2203 call writefile(["x", "b"], "Xdinew1")
2204 call writefile(["1c1"], "Xdiout1")
2205 call writefile(["a", "b"], "Xdiin2")
2206 call writefile(["y", "y"], "Xdinew2")
2207 call writefile(["1c1", "2c2"], "Xdiout2")
2208 call term_sendkeys(buf, ":set diffexpr=DiffExprStub()\<CR>:")
2209 call VerifyInternal(buf, "Test_diff_overlapped_3.18", "")
2210 call term_sendkeys(buf, ":set diffexpr&\<CR>:")
2211
2212 call WriteDiffFiles3(buf, ["a", "b", "c", "d"], ["x", "b", "x", "d"], ["y", "y", "c", "d"])
2213 call writefile(["a", "b", "c", "d"], "Xdiin1")
2214 call writefile(["x", "b", "x", "d"], "Xdinew1")
2215 call writefile(["1c1", "3c3"], "Xdiout1")
2216 call writefile(["a", "b", "c", "d"], "Xdiin2")
2217 call writefile(["y", "y", "c", "d"], "Xdinew2")
2218 call writefile(["1c1", "2c2"], "Xdiout2")
2219 call term_sendkeys(buf, ":set diffexpr=DiffExprStub()\<CR>:")
2220 call VerifyInternal(buf, "Test_diff_overlapped_3.19", "")
2221 call term_sendkeys(buf, ":set diffexpr&\<CR>:")
2222
2223 call WriteDiffFiles3(buf, ["a", "b", "c", "d"], ["x", "b", "x", "d"], ["y", "y", "y", "d"])
2224 call writefile(["a", "b", "c", "d"], "Xdiin1")
2225 call writefile(["x", "b", "x", "d"], "Xdinew1")
2226 call writefile(["1c1", "3c3"], "Xdiout1")
2227 call writefile(["a", "b", "c", "d"], "Xdiin2")
2228 call writefile(["y", "y", "y", "d"], "Xdinew2")
2229 call writefile(["1c1", "2,3c2,3"], "Xdiout2")
2230 call term_sendkeys(buf, ":set diffexpr=DiffExprStub()\<CR>:")
2231 call VerifyInternal(buf, "Test_diff_overlapped_3.20", "")
2232 call term_sendkeys(buf, ":set diffexpr&\<CR>:")
2233
2234 call WriteDiffFiles3(buf, ["a", "b", "c", "d"], ["x", "b", "x", "d"], ["y", "y", "y", "y"])
2235 call writefile(["a", "b", "c", "d"], "Xdiin1")
2236 call writefile(["x", "b", "x", "d"], "Xdinew1")
2237 call writefile(["1c1", "3c3"], "Xdiout1")
2238 call writefile(["a", "b", "c", "d"], "Xdiin2")
2239 call writefile(["y", "y", "y", "y"], "Xdinew2")
2240 call writefile(["1c1", "2,4c2,4"], "Xdiout2")
2241 call term_sendkeys(buf, ":set diffexpr=DiffExprStub()\<CR>:")
2242 call VerifyInternal(buf, "Test_diff_overlapped_3.21", "")
2243 call term_sendkeys(buf, ":set diffexpr&\<CR>:")
2244
2245 call WriteDiffFiles3(buf, ["a", "b", "c"], ["a", "x", "c"], ["b", "c"])
2246 call VerifyBoth(buf, "Test_diff_overlapped_3.22", "")
2247
2248 call WriteDiffFiles3(buf, ["a", "b", "c"], ["a", "x", "c"], ["c"])
2249 call VerifyBoth(buf, "Test_diff_overlapped_3.23", "")
2250
2251 call WriteDiffFiles3(buf, ["a", "b", "c"], ["a", "x", "c"], [])
2252 call VerifyBoth(buf, "Test_diff_overlapped_3.24", "")
2253
2254 call WriteDiffFiles3(buf, ["a", "b", "c"], ["a", "x", "c"], ["a", "c"])
2255 call VerifyBoth(buf, "Test_diff_overlapped_3.25", "")
2256
2257 call WriteDiffFiles3(buf, ["a", "b", "c"], ["a", "x", "c"], ["a"])
2258 call VerifyBoth(buf, "Test_diff_overlapped_3.26", "")
2259
2260 call WriteDiffFiles3(buf, ["a", "b", "c"], ["a", "x", "c"], ["b"])
2261 call VerifyBoth(buf, "Test_diff_overlapped_3.27", "")
2262
2263 call WriteDiffFiles3(buf, ["a", "b", "c", "d", "e"], ["a", "x", "c", "x", "e"], ["d", "e"])
2264 call VerifyBoth(buf, "Test_diff_overlapped_3.28", "")
2265
2266 call WriteDiffFiles3(buf, ["a", "b", "c", "d", "e"], ["a", "x", "c", "x", "e"], ["e"])
2267 call VerifyBoth(buf, "Test_diff_overlapped_3.29", "")
2268
2269 call WriteDiffFiles3(buf, ["a", "b", "c", "d", "e"], ["a", "x", "c", "x", "e"], ["a", "d", "e"])
2270 call VerifyBoth(buf, "Test_diff_overlapped_3.30", "")
2271
2272 call WriteDiffFiles3(buf, ["a", "b", "c", "d", "e"], ["a", "x", "c", "x", "e"], ["a", "e"])
2273 call VerifyBoth(buf, "Test_diff_overlapped_3.31", "")
2274
2275 call WriteDiffFiles3(buf, ["a", "b", "c", "d", "e"], ["a", "x", "c", "x", "e"], ["a"])
2276 call VerifyBoth(buf, "Test_diff_overlapped_3.32", "")
2277
2278 call WriteDiffFiles3(buf, ["a", "b", "c", "d", "e"], ["a", "x", "c", "x", "e"], ["a", "b", "d", "e"])
2279 call VerifyBoth(buf, "Test_diff_overlapped_3.33", "")
2280
2281 call WriteDiffFiles3(buf, ["a", "b", "c", "d", "e"], ["a", "x", "c", "x", "e"], ["a", "b", "e"])
2282 call VerifyBoth(buf, "Test_diff_overlapped_3.34", "")
2283
2284 call WriteDiffFiles3(buf, ["a", "b", "c", "d", "e"], ["a", "x", "c", "x", "e"], ["a", "b"])
2285 call VerifyBoth(buf, "Test_diff_overlapped_3.35", "")
2286
2287 call WriteDiffFiles3(buf, ["a", "b", "c"], ["a", "x", "c"], ["a", "y", "b", "c"])
2288 call VerifyBoth(buf, "Test_diff_overlapped_3.36", "")
2289
2290 call WriteDiffFiles3(buf, ["a", "b", "c"], ["a", "x", "c"], ["a", "b", "y", "c"])
2291 call VerifyBoth(buf, "Test_diff_overlapped_3.37", "")
2292
Yukihiro Nakadaira01f65092025-01-15 18:36:43 +01002293 call WriteDiffFiles3(buf, ["a", "b", "c"], ["d", "e"], ["b", "f"])
2294 call VerifyBoth(buf, "Test_diff_overlapped_3.38", "")
2295
2296 call WriteDiffFiles3(buf, ["a", "b", "c"], ["d", "e"], ["b"])
2297 call VerifyBoth(buf, "Test_diff_overlapped_3.39", "")
2298
Yee Cheng Chinbc08ceb2025-03-02 22:05:37 +01002299 " File 3 overlaps twice, 2nd overlap completely within the existing block.
2300 call WriteDiffFiles3(buf, ["foo", "a", "b", "c", "bar"], ["foo", "w", "x", "y", "z", "bar"], ["foo", "1", "a", "b", "2", "bar"])
2301 call VerifyBoth(buf, "Test_diff_overlapped_3.40", "")
2302
2303 " File 3 overlaps twice, 2nd overlap extends beyond existing block on new
2304 " side. Make sure we don't over-extend the range and hit 'bar'.
2305 call WriteDiffFiles3(buf, ["foo", "a", "b", "c", "d", "bar"], ["foo", "w", "x", "y", "z", "u", "bar"], ["foo", "1", "a", "b", "2", "d", "bar"])
2306 call VerifyBoth(buf, "Test_diff_overlapped_3.41", "")
2307
2308 " Chained overlaps. File 3's 2nd overlap spans two diff blocks and is longer
2309 " than the 2nd one.
2310 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"])
2311 call VerifyBoth(buf, "Test_diff_overlapped_3.42", "")
2312
2313 " File 3 has 2 overlaps. An add and a delete. First overlap's expansion hits
2314 " the 2nd one. Make sure we adjust the diff block to have fewer lines.
2315 call WriteDiffFiles3(buf, ["foo", "a", "b", "bar"], ["foo", "x", "y", "bar"], ["foo", "1", "a", "bar"])
2316 call VerifyBoth(buf, "Test_diff_overlapped_3.43", "")
2317
2318 " File 3 has 2 overlaps. An add and another add. First overlap's expansion hits
2319 " the 2nd one. Make sure we adjust the diff block to have more lines.
2320 call WriteDiffFiles3(buf, ["foo", "a", "b", "c", "d", "bar"], ["foo", "w", "x", "y", "z", "u", "bar"], ["foo", "1", "a", "b", "3", "4", "d", "bar"])
2321 call VerifyBoth(buf, "Test_diff_overlapped_3.44", "")
2322
Yukihiro Nakadaira06fe70c2024-09-26 16:19:42 +02002323 call StopVimInTerminal(buf)
2324endfunc
2325
zeertzjq7c515282024-11-10 20:26:12 +01002326" switching windows in diff mode caused an unnecessary scroll
Christian Brabandt05a40e02024-10-29 20:29:04 +01002327func Test_diff_topline_noscroll()
2328 CheckScreendump
2329
2330 let content =<< trim END
2331 call setline(1, range(1,60))
2332 vnew
2333 call setline(1, range(1,10) + range(50,60))
2334 windo diffthis
2335 norm! G
2336 exe "norm! 30\<C-y>"
2337 END
2338 call writefile(content, 'Xcontent', 'D')
2339 let buf = RunVimInTerminal('-S Xcontent', {'rows': 20})
2340 call VerifyScreenDump(buf, 'Test_diff_topline_1', {})
2341 call term_sendkeys(buf, ":echo line('w0', 1001)\<cr>")
2342 call term_wait(buf)
2343 call VerifyScreenDump(buf, 'Test_diff_topline_2', {})
2344 call term_sendkeys(buf, "\<C-W>p")
2345 call term_wait(buf)
2346 call VerifyScreenDump(buf, 'Test_diff_topline_3', {})
2347 call term_sendkeys(buf, "\<C-W>p")
2348 call term_wait(buf)
2349 call VerifyScreenDump(buf, 'Test_diff_topline_4', {})
2350 call StopVimInTerminal(buf)
2351endfunc
2352
Jonathon7c7a4e62025-01-12 09:58:00 +01002353func Test_diffget_diffput_linematch()
2354 CheckScreendump
2355 call delete('.Xdifile1.swp')
2356 call delete('.Xdifile2.swp')
2357 call WriteDiffFiles(0, [], [])
2358 let buf = RunVimInTerminal('-d Xdifile1 Xdifile2', {})
2359 call term_sendkeys(buf, ":set autoread\<CR>\<c-w>w:set autoread\<CR>\<c-w>w")
2360
2361 " enable linematch
2362 call term_sendkeys(buf, ":set diffopt+=linematch:30\<CR>")
2363 call WriteDiffFiles(buf, ['',
2364 \ 'common line',
2365 \ 'common line',
2366 \ '',
2367 \ 'ABCabc',
2368 \ 'ABCabc',
2369 \ 'ABCabc',
2370 \ 'ABCabc',
2371 \ 'common line',
2372 \ 'common line',
2373 \ 'common line',
2374 \ 'something' ],
2375 \ ['',
2376 \ 'common line',
2377 \ 'common line',
2378 \ '',
2379 \ 'DEFabc',
2380 \ 'xyz',
2381 \ 'xyz',
2382 \ 'xyz',
2383 \ 'DEFabc',
2384 \ 'DEFabc',
2385 \ 'DEFabc',
2386 \ 'common line',
2387 \ 'common line',
2388 \ 'DEF',
2389 \ 'common line',
2390 \ 'DEF',
2391 \ 'something'])
2392 call VerifyScreenDump(buf, 'Test_diff_get_put_linematch_1', {})
2393
2394 " get from window 1 from line 5 to 9
2395 call term_sendkeys(buf, "1\<c-w>w")
2396 call term_sendkeys(buf, ":5,9diffget\<CR>")
2397 call VerifyScreenDump(buf, 'Test_diff_get_put_linematch_2', {})
2398
2399 " undo the last diffget
2400 call term_sendkeys(buf, "u")
2401
2402 " get from window 2 from line 5 to 10
2403 call term_sendkeys(buf, "2\<c-w>w")
2404 call term_sendkeys(buf, ":5,10diffget\<CR>")
2405 call VerifyScreenDump(buf, 'Test_diff_get_put_linematch_3', {})
2406
2407 " undo the last diffget
2408 call term_sendkeys(buf, "u")
2409
2410 " get all from window 2
2411 call term_sendkeys(buf, "2\<c-w>w")
2412 call term_sendkeys(buf, ":4,17diffget\<CR>")
2413 call VerifyScreenDump(buf, 'Test_diff_get_put_linematch_4', {})
2414
2415 " undo the last diffget
2416 call term_sendkeys(buf, "u")
2417
2418 " get all from window 1
2419 call term_sendkeys(buf, "1\<c-w>w")
2420 call term_sendkeys(buf, ":4,12diffget\<CR>")
2421 call VerifyScreenDump(buf, 'Test_diff_get_put_linematch_5', {})
2422
2423 " undo the last diffget
2424 call term_sendkeys(buf, "u")
2425
2426 " get from window 1 using do 1 line 5
2427 call term_sendkeys(buf, "1\<c-w>w")
2428 call term_sendkeys(buf, "5gg")
2429 call term_sendkeys(buf, ":diffget\<CR>")
2430 call VerifyScreenDump(buf, 'Test_diff_get_put_linematch_6', {})
2431
2432 " undo the last diffget
2433 call term_sendkeys(buf, "u")
2434
2435 " get from window 1 using do 2 line 6
2436 call term_sendkeys(buf, "1\<c-w>w")
2437 call term_sendkeys(buf, "6gg")
2438 call term_sendkeys(buf, ":diffget\<CR>")
2439 call VerifyScreenDump(buf, 'Test_diff_get_put_linematch_7', {})
2440
2441 " undo the last diffget
2442 call term_sendkeys(buf, "u")
2443
2444 " get from window 1 using do 2 line 7
2445 call term_sendkeys(buf, "1\<c-w>w")
2446 call term_sendkeys(buf, "7gg")
2447 call term_sendkeys(buf, ":diffget\<CR>")
2448 call VerifyScreenDump(buf, 'Test_diff_get_put_linematch_8', {})
2449
2450 " undo the last diffget
2451 call term_sendkeys(buf, "u")
2452
2453 " get from window 1 using do 2 line 11
2454 call term_sendkeys(buf, "1\<c-w>w")
2455 call term_sendkeys(buf, "11gg")
2456 call term_sendkeys(buf, ":diffget\<CR>")
2457 call VerifyScreenDump(buf, 'Test_diff_get_put_linematch_9', {})
2458
2459 " undo the last diffget
2460 call term_sendkeys(buf, "u")
2461
2462 " get from window 1 using do 2 line 12
2463 call term_sendkeys(buf, "1\<c-w>w")
2464 call term_sendkeys(buf, "12gg")
2465 call term_sendkeys(buf, ":diffget\<CR>")
2466 call VerifyScreenDump(buf, 'Test_diff_get_put_linematch_10', {})
2467
2468 " undo the last diffget
2469 call term_sendkeys(buf, "u")
2470
2471 " put from window 1 using dp 1 line 5
2472 call term_sendkeys(buf, "1\<c-w>w")
2473 call term_sendkeys(buf, "5gg")
2474 call term_sendkeys(buf, ":diffput\<CR>")
2475 call VerifyScreenDump(buf, 'Test_diff_get_put_linematch_11', {})
2476
2477 " undo the last diffput
2478 call term_sendkeys(buf, "2\<c-w>w")
2479 call term_sendkeys(buf, "u")
2480
2481 " put from window 1 using dp 2 line 6
2482 call term_sendkeys(buf, "1\<c-w>w")
2483 call term_sendkeys(buf, "6gg")
2484 call term_sendkeys(buf, ":diffput\<CR>")
2485 call VerifyScreenDump(buf, 'Test_diff_get_put_linematch_12', {})
2486
2487 " undo the last diffput
2488 call term_sendkeys(buf, "2\<c-w>w")
2489 call term_sendkeys(buf, "u")
2490
2491 " put from window 1 using dp 2 line 7
2492 call term_sendkeys(buf, "1\<c-w>w")
2493 call term_sendkeys(buf, "7gg")
2494 call term_sendkeys(buf, ":diffput\<CR>")
2495 call VerifyScreenDump(buf, 'Test_diff_get_put_linematch_13', {})
2496
2497 " undo the last diffput
2498 call term_sendkeys(buf, "2\<c-w>w")
2499 call term_sendkeys(buf, "u")
2500
2501 " put from window 1 using dp 2 line 11
2502 call term_sendkeys(buf, "1\<c-w>w")
2503 call term_sendkeys(buf, "11gg")
2504 call term_sendkeys(buf, ":diffput\<CR>")
2505 call VerifyScreenDump(buf, 'Test_diff_get_put_linematch_14', {})
2506
2507 " undo the last diffput
2508 call term_sendkeys(buf, "2\<c-w>w")
2509 call term_sendkeys(buf, "u")
2510
2511 " put from window 1 using dp 2 line 12
2512 call term_sendkeys(buf, "1\<c-w>w")
2513 call term_sendkeys(buf, "12gg")
2514 call term_sendkeys(buf, ":diffput\<CR>")
2515 call VerifyScreenDump(buf, 'Test_diff_get_put_linematch_15', {})
2516
2517 " undo the last diffput
2518 call term_sendkeys(buf, "2\<c-w>w")
2519 call term_sendkeys(buf, "u")
2520
2521 " put from window 2 using dp line 6
2522 call term_sendkeys(buf, "2\<c-w>w")
2523 call term_sendkeys(buf, "6gg")
2524 call term_sendkeys(buf, ":diffput\<CR>")
2525 call VerifyScreenDump(buf, 'Test_diff_get_put_linematch_16', {})
2526
2527 " undo the last diffput
2528 call term_sendkeys(buf, "1\<c-w>w")
2529 call term_sendkeys(buf, "u")
2530
2531 " put from window 2 using dp line 8
2532 call term_sendkeys(buf, "2\<c-w>w")
2533 call term_sendkeys(buf, "8gg")
2534 call term_sendkeys(buf, ":diffput\<CR>")
2535 call VerifyScreenDump(buf, 'Test_diff_get_put_linematch_17', {})
2536
2537 " undo the last diffput
2538 call term_sendkeys(buf, "1\<c-w>w")
2539 call term_sendkeys(buf, "u")
2540
2541 " put from window 2 using dp line 9
2542 call term_sendkeys(buf, "2\<c-w>w")
2543 call term_sendkeys(buf, "9gg")
2544 call term_sendkeys(buf, ":diffput\<CR>")
2545 call VerifyScreenDump(buf, 'Test_diff_get_put_linematch_18', {})
2546
2547 " undo the last diffput
2548 call term_sendkeys(buf, "1\<c-w>w")
2549 call term_sendkeys(buf, "u")
2550
2551 " put from window 2 using dp line 17
2552 call term_sendkeys(buf, "2\<c-w>w")
2553 call term_sendkeys(buf, "17gg")
2554 call term_sendkeys(buf, ":diffput\<CR>")
2555 call VerifyScreenDump(buf, 'Test_diff_get_put_linematch_19', {})
Jonathonca307ef2025-01-17 13:37:35 +01002556 " clean up
2557 call StopVimInTerminal(buf)
Jonathon7c7a4e62025-01-12 09:58:00 +01002558endfunc
2559
2560func Test_linematch_diff()
2561 CheckScreendump
2562 call delete('.Xdifile1.swp')
2563 call delete('.Xdifile2.swp')
2564 call WriteDiffFiles(0, [], [])
2565 let buf = RunVimInTerminal('-d Xdifile1 Xdifile2', {})
2566 call term_sendkeys(buf, ":set autoread\<CR>\<c-w>w:set autoread\<CR>\<c-w>w")
2567
2568 " enable linematch
2569 call term_sendkeys(buf, ":set diffopt+=linematch:30\<CR>")
2570 call WriteDiffFiles(buf, ['// abc d?',
2571 \ '// d?',
2572 \ '// d?' ],
2573 \ ['!',
2574 \ 'abc d!',
2575 \ 'd!'])
2576 call VerifyScreenDump(buf, 'Test_linematch_diff1', {})
Jonathonca307ef2025-01-17 13:37:35 +01002577 " clean up
2578 call StopVimInTerminal(buf)
Jonathon7c7a4e62025-01-12 09:58:00 +01002579endfunc
2580
2581func Test_linematch_diff_iwhite()
2582 CheckScreendump
2583 call delete('.Xdifile1.swp')
2584 call delete('.Xdifile2.swp')
2585 call WriteDiffFiles(0, [], [])
2586 let buf = RunVimInTerminal('-d Xdifile1 Xdifile2', {})
2587 call term_sendkeys(buf, ":set autoread\<CR>\<c-w>w:set autoread\<CR>\<c-w>w")
2588
2589 " setup a diff with 2 files and set linematch:30, with ignore white
2590 call term_sendkeys(buf, ":set diffopt+=linematch:30\<CR>")
2591 call WriteDiffFiles(buf, ['void testFunction () {',
2592 \ ' for (int i = 0; i < 10; i++) {',
2593 \ ' for (int j = 0; j < 10; j++) {',
2594 \ ' }',
2595 \ ' }',
2596 \ '}' ],
2597 \ ['void testFunction () {',
2598 \ ' // for (int j = 0; j < 10; i++) {',
2599 \ ' // }',
2600 \ '}'])
2601 call VerifyScreenDump(buf, 'Test_linematch_diff_iwhite1', {})
2602 call term_sendkeys(buf, ":set diffopt+=iwhiteall\<CR>")
2603 call VerifyScreenDump(buf, 'Test_linematch_diff_iwhite2', {})
Jonathonca307ef2025-01-17 13:37:35 +01002604 " clean up
2605 call StopVimInTerminal(buf)
Jonathon7c7a4e62025-01-12 09:58:00 +01002606endfunc
2607
2608func Test_linematch_diff_grouping()
2609 CheckScreendump
2610 call delete('.Xdifile1.swp')
2611 call delete('.Xdifile2.swp')
2612 call WriteDiffFiles(0, [], [])
2613 let buf = RunVimInTerminal('-d Xdifile1 Xdifile2', {})
2614 call term_sendkeys(buf, ":set autoread\<CR>\<c-w>w:set autoread\<CR>\<c-w>w")
2615
2616 " a diff that would result in multiple groups before grouping optimization
2617 call term_sendkeys(buf, ":set diffopt+=linematch:30\<CR>")
2618 call WriteDiffFiles(buf, ['!A',
2619 \ '!B',
2620 \ '!C' ],
2621 \ ['?Z',
2622 \ '?A',
2623 \ '?B',
2624 \ '?C',
2625 \ '?A',
2626 \ '?B',
2627 \ '?B',
2628 \ '?C'])
2629 call VerifyScreenDump(buf, 'Test_linematch_diff_grouping1', {})
2630 call WriteDiffFiles(buf, ['!A',
2631 \ '!B',
2632 \ '!C' ],
2633 \ ['?A',
2634 \ '?Z',
2635 \ '?B',
2636 \ '?C',
2637 \ '?A',
2638 \ '?B',
2639 \ '?C',
2640 \ '?C'])
2641 call VerifyScreenDump(buf, 'Test_linematch_diff_grouping2', {})
Jonathonca307ef2025-01-17 13:37:35 +01002642 " clean up
2643 call StopVimInTerminal(buf)
Jonathon7c7a4e62025-01-12 09:58:00 +01002644endfunc
2645
2646func Test_linematch_diff_scroll()
2647 CheckScreendump
2648 call delete('.Xdifile1.swp')
2649 call delete('.Xdifile2.swp')
2650 call WriteDiffFiles(0, [], [])
2651 let buf = RunVimInTerminal('-d Xdifile1 Xdifile2', {})
2652 call term_sendkeys(buf, ":set autoread\<CR>\<c-w>w:set autoread\<CR>\<c-w>w")
2653
2654 " a diff that would result in multiple groups before grouping optimization
2655 call term_sendkeys(buf, ":set diffopt+=linematch:30\<CR>")
2656 call WriteDiffFiles(buf, ['!A',
2657 \ '!B',
2658 \ '!C' ],
2659 \ ['?A',
2660 \ '?Z',
2661 \ '?B',
2662 \ '?C',
2663 \ '?A',
2664 \ '?B',
2665 \ '?C',
2666 \ '?C'])
2667 " scroll down to show calculation of top fill and scroll to correct line in
2668 " both windows
2669 call VerifyScreenDump(buf, 'Test_linematch_diff_grouping_scroll0', {})
2670 call term_sendkeys(buf, "3\<c-e>")
2671 call VerifyScreenDump(buf, 'Test_linematch_diff_grouping_scroll1', {})
2672 call term_sendkeys(buf, "3\<c-e>")
2673 call VerifyScreenDump(buf, 'Test_linematch_diff_grouping_scroll2', {})
Jonathonca307ef2025-01-17 13:37:35 +01002674 " clean up
2675 call StopVimInTerminal(buf)
Jonathon7c7a4e62025-01-12 09:58:00 +01002676endfunc
2677
Jonathon7c7a4e62025-01-12 09:58:00 +01002678func Test_linematch_line_limit_exceeded()
2679 CheckScreendump
2680 call delete('.Xdifile1.swp')
2681 call delete('.Xdifile2.swp')
2682 call WriteDiffFiles(0, [], [])
2683 let buf = RunVimInTerminal('-d Xdifile1 Xdifile2', {})
2684 call term_sendkeys(buf, ":set autoread\<CR>\<c-w>w:set autoread\<CR>\<c-w>w")
2685
2686 call term_sendkeys(buf, ":set diffopt+=linematch:10\<CR>")
2687 " a diff block will not be aligned with linematch because it's contents
2688 " exceed 10 lines
2689 call WriteDiffFiles(buf,
2690 \ ['common line',
2691 \ 'HIL',
2692 \ '',
2693 \ 'aABCabc',
2694 \ 'aABCabc',
2695 \ 'aABCabc',
2696 \ 'aABCabc',
2697 \ 'common line',
2698 \ 'HIL',
2699 \ 'common line',
2700 \ 'something'],
2701 \ ['common line',
2702 \ 'DEF',
2703 \ 'GHI',
2704 \ 'something',
2705 \ '',
2706 \ 'aDEFabc',
2707 \ 'xyz',
2708 \ 'xyz',
2709 \ 'xyz',
2710 \ 'aDEFabc',
2711 \ 'aDEFabc',
2712 \ 'aDEFabc',
2713 \ 'common line',
2714 \ 'DEF',
2715 \ 'GHI',
2716 \ 'something else',
2717 \ 'common line',
2718 \ 'something'])
2719 call VerifyScreenDump(buf, 'Test_linematch_line_limit_exceeded1', {})
2720 " after increasing the count to 30, the limit is not exceeded, and the
2721 " alignment algorithm will run on the largest diff block here
2722 call term_sendkeys(buf, ":set diffopt+=linematch:30\<CR>")
2723 call VerifyScreenDump(buf, 'Test_linematch_line_limit_exceeded2', {})
Jonathonca307ef2025-01-17 13:37:35 +01002724 " clean up
2725 call StopVimInTerminal(buf)
Jonathon7c7a4e62025-01-12 09:58:00 +01002726endfunc
2727
2728func Test_linematch_3diffs()
2729 CheckScreendump
2730 call delete('.Xdifile1.swp')
2731 call delete('.Xdifile2.swp')
2732 call delete('.Xdifile3.swp')
2733 call WriteDiffFiles3(0, [], [], [])
2734 let buf = RunVimInTerminal('-d Xdifile1 Xdifile2 Xdifile3', {})
2735 call term_sendkeys(buf, "1\<c-w>w:set autoread\<CR>")
2736 call term_sendkeys(buf, "2\<c-w>w:set autoread\<CR>")
2737 call term_sendkeys(buf, "3\<c-w>w:set autoread\<CR>")
2738 call term_sendkeys(buf, ":set diffopt+=linematch:30\<CR>")
2739 call WriteDiffFiles3(buf,
2740 \ ["",
2741 \ " common line",
2742 \ " AAA",
2743 \ " AAA",
2744 \ " AAA"],
2745 \ ["",
2746 \ " common line",
2747 \ " <<<<<<< HEAD",
2748 \ " AAA",
2749 \ " AAA",
2750 \ " AAA",
2751 \ " =======",
2752 \ " BBB",
2753 \ " BBB",
2754 \ " BBB",
2755 \ " >>>>>>> branch1"],
2756 \ ["",
2757 \ " common line",
2758 \ " BBB",
2759 \ " BBB",
2760 \ " BBB"])
2761 call VerifyScreenDump(buf, 'Test_linematch_3diffs1', {})
Jonathonca307ef2025-01-17 13:37:35 +01002762 " clean up
2763 call StopVimInTerminal(buf)
2764endfunc
Jonathon7c7a4e62025-01-12 09:58:00 +01002765
Jonathonca307ef2025-01-17 13:37:35 +01002766" this used to access invalid memory
2767func Test_linematch_3diffs_sanity_check()
2768 CheckScreendump
2769 call delete('.Xfile_linematch1.swp')
2770 call delete('.Xfile_linematch2.swp')
2771 call delete('.Xfile_linematch3.swp')
2772 let lines =<< trim END
2773 set diffopt+=linematch:60
2774 call feedkeys("Aq\<esc>")
2775 call feedkeys("GAklm\<esc>")
2776 call feedkeys("o")
2777 END
2778 call writefile(lines, 'Xlinematch_3diffs.vim', 'D')
2779 call writefile(['abcd', 'def', 'hij'], 'Xfile_linematch1', 'D')
2780 call writefile(['defq', 'hijk', 'nopq'], 'Xfile_linematch2', 'D')
2781 call writefile(['hijklm', 'nopqr', 'stuv'], 'Xfile_linematch3', 'D')
2782 call WriteDiffFiles3(0, [], [], [])
2783 let buf = RunVimInTerminal('-d -S Xlinematch_3diffs.vim Xfile_linematch1 Xfile_linematch2 Xfile_linematch3', {})
2784 call VerifyScreenDump(buf, 'Test_linematch_3diffs2', {})
2785
2786 " clean up
2787 call StopVimInTerminal(buf)
Jonathon7c7a4e62025-01-12 09:58:00 +01002788endfunc
Bram Moolenaar8dfcce32020-03-18 19:32:26 +01002789" vim: shiftwidth=2 sts=2 expandtab