blob: 03c6c798e05e79cdc09e419f44479187c0b07b01 [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
Bram Moolenaar42093c02016-07-30 16:16:54 +02006
7func Test_diff_fold_sync()
8 enew!
Bram Moolenaare8fa05b2018-09-16 15:48:06 +02009 let g:update_count = 0
10 au DiffUpdated * let g:update_count += 1
11
Bram Moolenaar42093c02016-07-30 16:16:54 +020012 let l = range(50)
13 call setline(1, l)
14 diffthis
15 let winone = win_getid()
16 new
17 let l[25] = 'diff'
18 call setline(1, l)
19 diffthis
20 let wintwo = win_getid()
21 " line 15 is inside the closed fold
22 call assert_equal(19, foldclosedend(10))
23 call win_gotoid(winone)
24 call assert_equal(19, foldclosedend(10))
25 " open the fold
26 normal zv
27 call assert_equal(-1, foldclosedend(10))
28 " fold in other window must have opened too
29 call win_gotoid(wintwo)
30 call assert_equal(-1, foldclosedend(10))
31
32 " cursor position is in sync
33 normal 23G
34 call win_gotoid(winone)
35 call assert_equal(23, getcurpos()[1])
36
Bram Moolenaare8fa05b2018-09-16 15:48:06 +020037 call assert_equal(1, g:update_count)
38 au! DiffUpdated
39
Bram Moolenaar42093c02016-07-30 16:16:54 +020040 windo diffoff
41 close!
42 set nomodified
43endfunc
44
45func Test_vert_split()
Bram Moolenaare828b762018-09-10 17:51:58 +020046 set diffopt=filler
47 call Common_vert_split()
48 set diffopt&
49endfunc
50
51func Test_vert_split_internal()
52 set diffopt=internal,filler
53 call Common_vert_split()
54 set diffopt&
55endfunc
56
57func Common_vert_split()
Bram Moolenaar42093c02016-07-30 16:16:54 +020058 " Disable the title to avoid xterm keeping the wrong one.
59 set notitle noicon
60 new
61 let l = ['1 aa', '2 bb', '3 cc', '4 dd', '5 ee']
62 call setline(1, l)
63 w! Xtest
64 normal dd
65 $
66 put
67 normal kkrXoxxx
68 w! Xtest2
69 file Nop
70 normal ggoyyyjjjozzzz
71 set foldmethod=marker foldcolumn=4
72 call assert_equal(0, &diff)
73 call assert_equal('marker', &foldmethod)
74 call assert_equal(4, &foldcolumn)
75 call assert_equal(0, &scrollbind)
76 call assert_equal(0, &cursorbind)
77 call assert_equal(1, &wrap)
78
79 vert diffsplit Xtest
80 vert diffsplit Xtest2
81 call assert_equal(1, &diff)
82 call assert_equal('diff', &foldmethod)
83 call assert_equal(2, &foldcolumn)
84 call assert_equal(1, &scrollbind)
85 call assert_equal(1, &cursorbind)
86 call assert_equal(0, &wrap)
87
88 let diff_fdm = &fdm
89 let diff_fdc = &fdc
90 " repeat entering diff mode here to see if this saves the wrong settings
91 diffthis
92 " jump to second window for a moment to have filler line appear at start of
93 " first window
94 wincmd w
95 normal gg
96 wincmd p
97 normal gg
98 call assert_equal(2, winline())
99 normal j
100 call assert_equal(4, winline())
101 normal j
102 call assert_equal(5, winline())
103 normal j
104 call assert_equal(6, winline())
105 normal j
106 call assert_equal(8, winline())
107 normal j
108 call assert_equal(9, winline())
109
110 wincmd w
111 normal gg
112 call assert_equal(1, winline())
113 normal j
114 call assert_equal(2, winline())
115 normal j
116 call assert_equal(4, winline())
117 normal j
118 call assert_equal(5, winline())
119 normal j
120 call assert_equal(8, winline())
121
122 wincmd w
123 normal gg
124 call assert_equal(2, winline())
125 normal j
126 call assert_equal(3, winline())
127 normal j
128 call assert_equal(4, winline())
129 normal j
130 call assert_equal(5, winline())
131 normal j
132 call assert_equal(6, winline())
133 normal j
134 call assert_equal(7, winline())
135 normal j
136 call assert_equal(8, winline())
137
138 " Test diffoff
139 diffoff!
140 1wincmd 2
141 let &diff = 1
142 let &fdm = diff_fdm
143 let &fdc = diff_fdc
144 4wincmd w
145 diffoff!
146 1wincmd w
147 call assert_equal(0, &diff)
148 call assert_equal('marker', &foldmethod)
149 call assert_equal(4, &foldcolumn)
150 call assert_equal(0, &scrollbind)
151 call assert_equal(0, &cursorbind)
152 call assert_equal(1, &wrap)
153
154 wincmd w
155 call assert_equal(0, &diff)
156 call assert_equal('marker', &foldmethod)
157 call assert_equal(4, &foldcolumn)
158 call assert_equal(0, &scrollbind)
159 call assert_equal(0, &cursorbind)
160 call assert_equal(1, &wrap)
161
162 wincmd w
163 call assert_equal(0, &diff)
164 call assert_equal('marker', &foldmethod)
165 call assert_equal(4, &foldcolumn)
166 call assert_equal(0, &scrollbind)
167 call assert_equal(0, &cursorbind)
168 call assert_equal(1, &wrap)
169
Bram Moolenaar623cf882016-07-30 16:36:01 +0200170 call delete('Xtest')
171 call delete('Xtest2')
Bram Moolenaar42093c02016-07-30 16:16:54 +0200172 windo bw!
173endfunc
174
175func Test_filler_lines()
176 " Test that diffing shows correct filler lines
177 enew!
178 put =range(4,10)
179 1d _
180 vnew
181 put =range(1,10)
182 1d _
183 windo diffthis
184 wincmd h
185 call assert_equal(1, line('w0'))
186 unlet! diff_fdm diff_fdc
Bram Moolenaar90d121f2016-07-30 19:11:25 +0200187 windo diffoff
188 bwipe!
189 enew!
190endfunc
Bram Moolenaar42093c02016-07-30 16:16:54 +0200191
Bram Moolenaar90d121f2016-07-30 19:11:25 +0200192func Test_diffget_diffput()
193 enew!
194 let l = range(50)
195 call setline(1, l)
196 call assert_fails('diffget', 'E99:')
197 diffthis
198 call assert_fails('diffget', 'E100:')
199 new
200 let l[10] = 'one'
201 let l[20] = 'two'
202 let l[30] = 'three'
203 let l[40] = 'four'
204 call setline(1, l)
205 diffthis
206 call assert_equal('one', getline(11))
207 11diffget
208 call assert_equal('10', getline(11))
209 21diffput
210 wincmd w
211 call assert_equal('two', getline(21))
212 normal 31Gdo
213 call assert_equal('three', getline(31))
214 call assert_equal('40', getline(41))
215 normal 41Gdp
216 wincmd w
217 call assert_equal('40', getline(41))
218 new
219 diffthis
220 call assert_fails('diffget', 'E101:')
221
222 windo diffoff
Bram Moolenaar79a213d2017-05-16 13:15:18 +0200223 %bwipe!
224endfunc
225
Bram Moolenaar5f57bdc2018-10-25 17:52:23 +0200226" Test putting two changes from one buffer to another
227func Test_diffput_two()
228 new a
229 let win_a = win_getid()
230 call setline(1, range(1, 10))
231 diffthis
232 new b
233 let win_b = win_getid()
234 call setline(1, range(1, 10))
235 8del
236 5del
237 diffthis
238 call win_gotoid(win_a)
239 %diffput
240 call win_gotoid(win_b)
241 call assert_equal(map(range(1, 10), 'string(v:val)'), getline(1, '$'))
242 bwipe! a
243 bwipe! b
244endfunc
245
Yegappan Lakshmanan30443242021-06-10 21:52:15 +0200246" Test for :diffget/:diffput with a range that is inside a diff chunk
247func Test_diffget_diffput_range()
248 call setline(1, range(1, 10))
249 new
250 call setline(1, range(11, 20))
251 windo diffthis
252 3,5diffget
253 call assert_equal(['13', '14', '15'], getline(3, 5))
254 call setline(1, range(1, 10))
255 4,8diffput
256 wincmd p
257 call assert_equal(['13', '4', '5', '6', '7', '8', '19'], getline(3, 9))
258 %bw!
259endfunc
260
261" Test for :diffget/:diffput with an empty buffer and a non-empty buffer
262func Test_diffget_diffput_empty_buffer()
263 %d _
264 new
265 call setline(1, 'one')
266 windo diffthis
267 diffget
268 call assert_equal(['one'], getline(1, '$'))
269 %d _
270 diffput
271 wincmd p
272 call assert_equal([''], getline(1, '$'))
273 %bw!
274endfunc
275
Bram Moolenaarefcc3292019-12-30 21:59:03 +0100276" :diffput and :diffget completes names of buffers which
Dominique Pelle923dce22021-11-21 11:36:04 +0000277" are in diff mode and which are different than current buffer.
Bram Moolenaarefcc3292019-12-30 21:59:03 +0100278" No completion when the current window is not in diff mode.
Bram Moolenaarae7dba82019-12-29 13:56:33 +0100279func Test_diffget_diffput_completion()
Bram Moolenaarefcc3292019-12-30 21:59:03 +0100280 e Xdiff1 | diffthis
281 botright new Xdiff2
282 botright new Xdiff3 | split | diffthis
283 botright new Xdiff4 | diffthis
Bram Moolenaarae7dba82019-12-29 13:56:33 +0100284
Bram Moolenaarefcc3292019-12-30 21:59:03 +0100285 wincmd t
286 call assert_equal('Xdiff1', bufname('%'))
Bram Moolenaarae7dba82019-12-29 13:56:33 +0100287 call feedkeys(":diffput \<C-A>\<C-B>\"\<CR>", 'tx')
Bram Moolenaarefcc3292019-12-30 21:59:03 +0100288 call assert_equal('"diffput Xdiff3 Xdiff4', @:)
Bram Moolenaarae7dba82019-12-29 13:56:33 +0100289 call feedkeys(":diffget \<C-A>\<C-B>\"\<CR>", 'tx')
Bram Moolenaarefcc3292019-12-30 21:59:03 +0100290 call assert_equal('"diffget Xdiff3 Xdiff4', @:)
291 call assert_equal(['Xdiff3', 'Xdiff4'], getcompletion('', 'diff_buffer'))
Bram Moolenaarae7dba82019-12-29 13:56:33 +0100292
Bram Moolenaarefcc3292019-12-30 21:59:03 +0100293 " Xdiff2 is not in diff mode, so no completion for :diffput, :diffget
294 wincmd j
295 call assert_equal('Xdiff2', bufname('%'))
Bram Moolenaarae7dba82019-12-29 13:56:33 +0100296 call feedkeys(":diffput \<C-A>\<C-B>\"\<CR>", 'tx')
297 call assert_equal('"diffput ', @:)
298 call feedkeys(":diffget \<C-A>\<C-B>\"\<CR>", 'tx')
299 call assert_equal('"diffget ', @:)
300 call assert_equal([], getcompletion('', 'diff_buffer'))
301
Bram Moolenaarefcc3292019-12-30 21:59:03 +0100302 " Xdiff3 is split in 2 windows, only the top one is in diff mode.
303 " So completion of :diffput :diffget only happens in the top window.
304 wincmd j
305 call assert_equal('Xdiff3', bufname('%'))
306 call assert_equal(1, &diff)
307 call feedkeys(":diffput \<C-A>\<C-B>\"\<CR>", 'tx')
308 call assert_equal('"diffput Xdiff1 Xdiff4', @:)
309 call feedkeys(":diffget \<C-A>\<C-B>\"\<CR>", 'tx')
310 call assert_equal('"diffget Xdiff1 Xdiff4', @:)
311 call assert_equal(['Xdiff1', 'Xdiff4'], getcompletion('', 'diff_buffer'))
312
313 wincmd j
314 call assert_equal('Xdiff3', bufname('%'))
315 call assert_equal(0, &diff)
316 call feedkeys(":diffput \<C-A>\<C-B>\"\<CR>", 'tx')
317 call assert_equal('"diffput ', @:)
318 call feedkeys(":diffget \<C-A>\<C-B>\"\<CR>", 'tx')
319 call assert_equal('"diffget ', @:)
320 call assert_equal([], getcompletion('', 'diff_buffer'))
321
322 wincmd j
323 call assert_equal('Xdiff4', bufname('%'))
324 call feedkeys(":diffput \<C-A>\<C-B>\"\<CR>", 'tx')
325 call assert_equal('"diffput Xdiff1 Xdiff3', @:)
326 call feedkeys(":diffget \<C-A>\<C-B>\"\<CR>", 'tx')
327 call assert_equal('"diffget Xdiff1 Xdiff3', @:)
328 call assert_equal(['Xdiff1', 'Xdiff3'], getcompletion('', 'diff_buffer'))
329
Bram Moolenaarae7dba82019-12-29 13:56:33 +0100330 %bwipe
331endfunc
332
Bram Moolenaar79a213d2017-05-16 13:15:18 +0200333func Test_dp_do_buffer()
334 e! one
335 let bn1=bufnr('%')
336 let l = range(60)
337 call setline(1, l)
338 diffthis
339
340 new two
341 let l[10] = 'one'
342 let l[20] = 'two'
343 let l[30] = 'three'
344 let l[40] = 'four'
345 let l[50] = 'five'
346 call setline(1, l)
347 diffthis
348
349 " dp and do with invalid buffer number.
350 11
351 call assert_fails('norm 99999dp', 'E102:')
352 call assert_fails('norm 99999do', 'E102:')
353 call assert_fails('diffput non_existing_buffer', 'E94:')
354 call assert_fails('diffget non_existing_buffer', 'E94:')
355
356 " dp and do with valid buffer number.
357 call assert_equal('one', getline('.'))
358 exe 'norm ' . bn1 . 'do'
359 call assert_equal('10', getline('.'))
360 21
361 call assert_equal('two', getline('.'))
Yegappan Lakshmanan30443242021-06-10 21:52:15 +0200362 diffget one
Bram Moolenaar79a213d2017-05-16 13:15:18 +0200363 call assert_equal('20', getline('.'))
364
365 31
366 exe 'norm ' . bn1 . 'dp'
367 41
368 diffput one
369 wincmd w
370 31
371 call assert_equal('three', getline('.'))
372 41
373 call assert_equal('four', getline('.'))
374
375 " dp and do with buffer number which is not in diff mode.
376 new not_in_diff_mode
377 let bn3=bufnr('%')
378 wincmd w
379 51
380 call assert_fails('exe "norm" . bn3 . "dp"', 'E103:')
381 call assert_fails('exe "norm" . bn3 . "do"', 'E103:')
382 call assert_fails('diffput not_in_diff_mode', 'E94:')
383 call assert_fails('diffget not_in_diff_mode', 'E94:')
384
385 windo diffoff
386 %bwipe!
Bram Moolenaar42093c02016-07-30 16:16:54 +0200387endfunc
Bram Moolenaare67d5462016-08-27 22:40:42 +0200388
Bram Moolenaardf77cef2018-10-07 17:46:42 +0200389func Test_do_lastline()
390 e! one
391 call setline(1, ['1','2','3','4','5','6'])
392 diffthis
393
394 new two
395 call setline(1, ['2','4','5'])
396 diffthis
397
398 1
399 norm dp]c
400 norm dp]c
401 wincmd w
402 call assert_equal(4, line('$'))
403 norm G
404 norm do
405 call assert_equal(3, line('$'))
406
407 windo diffoff
408 %bwipe!
409endfunc
410
Bram Moolenaare67d5462016-08-27 22:40:42 +0200411func Test_diffoff()
412 enew!
413 call setline(1, ['Two', 'Three'])
Bram Moolenaar79a213d2017-05-16 13:15:18 +0200414 redraw
Bram Moolenaare67d5462016-08-27 22:40:42 +0200415 let normattr = screenattr(1, 1)
416 diffthis
417 botright vert new
418 call setline(1, ['One', '', 'Two', 'Three'])
419 diffthis
420 redraw
Bram Moolenaar196b4662019-09-06 21:34:30 +0200421 call assert_notequal(normattr, 1->screenattr(1))
Bram Moolenaare67d5462016-08-27 22:40:42 +0200422 diffoff!
423 redraw
424 call assert_equal(normattr, screenattr(1, 1))
425 bwipe!
426 bwipe!
427endfunc
Bram Moolenaar025e3e02016-10-18 14:50:18 +0200428
Bram Moolenaare828b762018-09-10 17:51:58 +0200429func Common_icase_test()
430 edit one
Bram Moolenaarda22b8c2017-09-02 18:01:50 +0200431 call setline(1, ['One', 'Two', 'Three', 'Four', 'Fi#ve'])
Bram Moolenaar79a213d2017-05-16 13:15:18 +0200432 redraw
433 let normattr = screenattr(1, 1)
434 diffthis
435
436 botright vert new two
Bram Moolenaarda22b8c2017-09-02 18:01:50 +0200437 call setline(1, ['one', 'TWO', 'Three ', 'Four', 'fI=VE'])
Bram Moolenaar79a213d2017-05-16 13:15:18 +0200438 diffthis
439
440 redraw
441 call assert_equal(normattr, screenattr(1, 1))
442 call assert_equal(normattr, screenattr(2, 1))
443 call assert_notequal(normattr, screenattr(3, 1))
444 call assert_equal(normattr, screenattr(4, 1))
445
Bram Moolenaarda22b8c2017-09-02 18:01:50 +0200446 let dtextattr = screenattr(5, 3)
447 call assert_notequal(dtextattr, screenattr(5, 1))
448 call assert_notequal(dtextattr, screenattr(5, 5))
449
Bram Moolenaar79a213d2017-05-16 13:15:18 +0200450 diffoff!
451 %bwipe!
Bram Moolenaare828b762018-09-10 17:51:58 +0200452endfunc
453
454func Test_diffopt_icase()
455 set diffopt=icase,foldcolumn:0
456 call Common_icase_test()
Bram Moolenaar79a213d2017-05-16 13:15:18 +0200457 set diffopt&
458endfunc
459
Bram Moolenaare828b762018-09-10 17:51:58 +0200460func Test_diffopt_icase_internal()
461 set diffopt=icase,foldcolumn:0,internal
462 call Common_icase_test()
463 set diffopt&
464endfunc
Bram Moolenaar79a213d2017-05-16 13:15:18 +0200465
Bram Moolenaare828b762018-09-10 17:51:58 +0200466func Common_iwhite_test()
467 edit one
468 " Difference in trailing spaces and amount of spaces should be ignored,
Bram Moolenaar79a213d2017-05-16 13:15:18 +0200469 " but not other space differences.
Bram Moolenaare828b762018-09-10 17:51:58 +0200470 call setline(1, ["One \t", 'Two', 'Three', 'one two', 'one two', 'Four'])
Bram Moolenaar79a213d2017-05-16 13:15:18 +0200471 redraw
472 let normattr = screenattr(1, 1)
473 diffthis
474
475 botright vert new two
Bram Moolenaare828b762018-09-10 17:51:58 +0200476 call setline(1, ["One\t ", "Two\t ", 'Three', 'one two', 'onetwo', ' Four'])
Bram Moolenaar79a213d2017-05-16 13:15:18 +0200477 diffthis
478
479 redraw
480 call assert_equal(normattr, screenattr(1, 1))
481 call assert_equal(normattr, screenattr(2, 1))
482 call assert_equal(normattr, screenattr(3, 1))
Bram Moolenaare828b762018-09-10 17:51:58 +0200483 call assert_equal(normattr, screenattr(4, 1))
484 call assert_notequal(normattr, screenattr(5, 1))
485 call assert_notequal(normattr, screenattr(6, 1))
Bram Moolenaar79a213d2017-05-16 13:15:18 +0200486
487 diffoff!
488 %bwipe!
Bram Moolenaare828b762018-09-10 17:51:58 +0200489endfunc
490
491func Test_diffopt_iwhite()
492 set diffopt=iwhite,foldcolumn:0
493 call Common_iwhite_test()
494 set diffopt&
495endfunc
496
497func Test_diffopt_iwhite_internal()
498 set diffopt=internal,iwhite,foldcolumn:0
499 call Common_iwhite_test()
Bram Moolenaar79a213d2017-05-16 13:15:18 +0200500 set diffopt&
501endfunc
502
503func Test_diffopt_context()
504 enew!
505 call setline(1, ['1', '2', '3', '4', '5', '6', '7'])
506 diffthis
507 new
508 call setline(1, ['1', '2', '3', '4', '5x', '6', '7'])
509 diffthis
510
511 set diffopt=context:2
512 call assert_equal('+-- 2 lines: 1', foldtextresult(1))
Bram Moolenaare828b762018-09-10 17:51:58 +0200513 set diffopt=internal,context:2
514 call assert_equal('+-- 2 lines: 1', foldtextresult(1))
515
Bram Moolenaar79a213d2017-05-16 13:15:18 +0200516 set diffopt=context:1
517 call assert_equal('+-- 3 lines: 1', foldtextresult(1))
Bram Moolenaare828b762018-09-10 17:51:58 +0200518 set diffopt=internal,context:1
519 call assert_equal('+-- 3 lines: 1', foldtextresult(1))
Bram Moolenaar79a213d2017-05-16 13:15:18 +0200520
521 diffoff!
522 %bwipe!
523 set diffopt&
524endfunc
525
526func Test_diffopt_horizontal()
Bram Moolenaare828b762018-09-10 17:51:58 +0200527 set diffopt=internal,horizontal
Bram Moolenaar79a213d2017-05-16 13:15:18 +0200528 diffsplit
529
530 call assert_equal(&columns, winwidth(1))
531 call assert_equal(&columns, winwidth(2))
532 call assert_equal(&lines, winheight(1) + winheight(2) + 3)
533 call assert_inrange(0, 1, winheight(1) - winheight(2))
534
535 set diffopt&
536 diffoff!
537 %bwipe
538endfunc
539
540func Test_diffopt_vertical()
Bram Moolenaare828b762018-09-10 17:51:58 +0200541 set diffopt=internal,vertical
Bram Moolenaar79a213d2017-05-16 13:15:18 +0200542 diffsplit
543
544 call assert_equal(&lines - 2, winheight(1))
545 call assert_equal(&lines - 2, winheight(2))
546 call assert_equal(&columns, winwidth(1) + winwidth(2) + 1)
547 call assert_inrange(0, 1, winwidth(1) - winwidth(2))
548
549 set diffopt&
550 diffoff!
551 %bwipe
552endfunc
553
Bram Moolenaar97ce4192017-12-01 20:35:58 +0100554func Test_diffopt_hiddenoff()
Bram Moolenaare828b762018-09-10 17:51:58 +0200555 set diffopt=internal,filler,foldcolumn:0,hiddenoff
Bram Moolenaar97ce4192017-12-01 20:35:58 +0100556 e! one
557 call setline(1, ['Two', 'Three'])
558 redraw
559 let normattr = screenattr(1, 1)
560 diffthis
561 botright vert new two
562 call setline(1, ['One', 'Four'])
563 diffthis
564 redraw
565 call assert_notequal(normattr, screenattr(1, 1))
566 set hidden
567 close
568 redraw
569 " should not diffing with hidden buffer two while 'hiddenoff' is enabled
570 call assert_equal(normattr, screenattr(1, 1))
571
572 bwipe!
573 bwipe!
574 set hidden& diffopt&
575endfunc
576
Bram Moolenaar25ea0542017-02-03 23:16:28 +0100577func Test_diffoff_hidden()
Bram Moolenaare828b762018-09-10 17:51:58 +0200578 set diffopt=internal,filler,foldcolumn:0
Bram Moolenaar25ea0542017-02-03 23:16:28 +0100579 e! one
580 call setline(1, ['Two', 'Three'])
Bram Moolenaar79a213d2017-05-16 13:15:18 +0200581 redraw
Bram Moolenaar25ea0542017-02-03 23:16:28 +0100582 let normattr = screenattr(1, 1)
583 diffthis
584 botright vert new two
585 call setline(1, ['One', 'Four'])
586 diffthis
587 redraw
588 call assert_notequal(normattr, screenattr(1, 1))
589 set hidden
590 close
591 redraw
592 " diffing with hidden buffer two
593 call assert_notequal(normattr, screenattr(1, 1))
594 diffoff
595 redraw
596 call assert_equal(normattr, screenattr(1, 1))
597 diffthis
598 redraw
599 " still diffing with hidden buffer two
600 call assert_notequal(normattr, screenattr(1, 1))
601 diffoff!
602 redraw
603 call assert_equal(normattr, screenattr(1, 1))
604 diffthis
605 redraw
606 " no longer diffing with hidden buffer two
607 call assert_equal(normattr, screenattr(1, 1))
608
609 bwipe!
610 bwipe!
611 set hidden& diffopt&
612endfunc
613
Bram Moolenaar025e3e02016-10-18 14:50:18 +0200614func Test_setting_cursor()
615 new Xtest1
616 put =range(1,90)
617 wq
618 new Xtest2
619 put =range(1,100)
620 wq
Bram Moolenaar97fbc402017-09-26 19:41:46 +0200621
Bram Moolenaar025e3e02016-10-18 14:50:18 +0200622 tabe Xtest2
623 $
624 diffsp Xtest1
625 tabclose
626
627 call delete('Xtest1')
628 call delete('Xtest2')
629endfunc
Bram Moolenaaraeb661e2017-02-26 19:59:59 +0100630
631func Test_diff_move_to()
632 new
633 call setline(1, [1, 2, 3, 4, 5, 6, 7, 8, 9, 10])
634 diffthis
635 vnew
636 call setline(1, [1, '2x', 3, 4, 4, 5, '6x', 7, '8x', 9, '10x'])
637 diffthis
638 norm ]c
639 call assert_equal(2, line('.'))
640 norm 3]c
641 call assert_equal(9, line('.'))
642 norm 10]c
643 call assert_equal(11, line('.'))
644 norm [c
645 call assert_equal(9, line('.'))
646 norm 2[c
647 call assert_equal(5, line('.'))
648 norm 10[c
649 call assert_equal(2, line('.'))
650 %bwipe!
651endfunc
652
Bram Moolenaar79a213d2017-05-16 13:15:18 +0200653func Test_diffexpr()
Bram Moolenaaraeb313f2020-11-27 19:13:28 +0100654 CheckExecutable diff
Bram Moolenaar79a213d2017-05-16 13:15:18 +0200655
656 func DiffExpr()
Bram Moolenaar485b6272021-05-18 19:19:03 +0200657 " Prepend some text to check diff type detection
Bram Moolenaar3b8defd2018-09-13 13:03:11 +0200658 call writefile(['warning', ' message'], v:fname_out)
659 silent exe '!diff ' . v:fname_in . ' ' . v:fname_new . '>>' . v:fname_out
Bram Moolenaar79a213d2017-05-16 13:15:18 +0200660 endfunc
661 set diffexpr=DiffExpr()
662 set diffopt=foldcolumn:0
663
664 enew!
665 call setline(1, ['one', 'two', 'three'])
666 redraw
667 let normattr = screenattr(1, 1)
668 diffthis
669
670 botright vert new
671 call setline(1, ['one', 'two', 'three.'])
672 diffthis
673
674 redraw
675 call assert_equal(normattr, screenattr(1, 1))
676 call assert_equal(normattr, screenattr(2, 1))
677 call assert_notequal(normattr, screenattr(3, 1))
Yegappan Lakshmanan30443242021-06-10 21:52:15 +0200678 diffoff!
Bram Moolenaar79a213d2017-05-16 13:15:18 +0200679
Dominique Pelle923dce22021-11-21 11:36:04 +0000680 " Try using a non-existing function for 'diffexpr'.
Yegappan Lakshmanan30443242021-06-10 21:52:15 +0200681 set diffexpr=NewDiffFunc()
682 call assert_fails('windo diffthis', ['E117:', 'E97:'])
Bram Moolenaar79a213d2017-05-16 13:15:18 +0200683 diffoff!
Yegappan Lakshmanan8bb65f22021-12-26 10:51:39 +0000684
685 " Using a script-local function
686 func s:NewDiffExpr()
687 endfunc
688 set diffexpr=s:NewDiffExpr()
689 call assert_equal(expand('<SID>') .. 'NewDiffExpr()', &diffexpr)
690 set diffexpr=<SID>NewDiffExpr()
691 call assert_equal(expand('<SID>') .. 'NewDiffExpr()', &diffexpr)
692
Bram Moolenaar79a213d2017-05-16 13:15:18 +0200693 %bwipe!
694 set diffexpr& diffopt&
Yegappan Lakshmanan8bb65f22021-12-26 10:51:39 +0000695 delfunc DiffExpr
696 delfunc s:NewDiffExpr
Bram Moolenaar79a213d2017-05-16 13:15:18 +0200697endfunc
698
Bram Moolenaaraeb661e2017-02-26 19:59:59 +0100699func Test_diffpatch()
700 " The patch program on MS-Windows may fail or hang.
Bram Moolenaar6d91bcb2020-08-12 18:50:36 +0200701 CheckExecutable patch
702 CheckUnix
Bram Moolenaaraeb661e2017-02-26 19:59:59 +0100703 new
704 insert
705***************
706*** 1,3 ****
707 1
708! 2
709 3
710--- 1,4 ----
711 1
712! 2x
713 3
714+ 4
715.
Bram Moolenaar97fbc402017-09-26 19:41:46 +0200716 saveas! Xpatch
Bram Moolenaaraeb661e2017-02-26 19:59:59 +0100717 bwipe!
718 new
719 call assert_fails('diffpatch Xpatch', 'E816:')
Bram Moolenaar1ef73e32017-03-09 19:21:30 +0100720
Bram Moolenaara95ab322017-03-11 19:21:53 +0100721 for name in ['Xpatch', 'Xpatch$HOME', 'Xpa''tch']
Bram Moolenaar1ef73e32017-03-09 19:21:30 +0100722 call setline(1, ['1', '2', '3'])
723 if name != 'Xpatch'
724 call rename('Xpatch', name)
725 endif
726 exe 'diffpatch ' . escape(name, '$')
727 call assert_equal(['1', '2x', '3', '4'], getline(1, '$'))
728 if name != 'Xpatch'
729 call rename(name, 'Xpatch')
730 endif
731 bwipe!
732 endfor
733
Bram Moolenaaraeb661e2017-02-26 19:59:59 +0100734 call delete('Xpatch')
735 bwipe!
736endfunc
737
738func Test_diff_too_many_buffers()
739 for i in range(1, 8)
740 exe "new Xtest" . i
741 diffthis
742 endfor
743 new Xtest9
744 call assert_fails('diffthis', 'E96:')
745 %bwipe!
746endfunc
747
748func Test_diff_nomodifiable()
749 new
750 call setline(1, [1, 2, 3, 4])
751 setl nomodifiable
752 diffthis
753 vnew
754 call setline(1, ['1x', 2, 3, 3, 4])
755 diffthis
756 call assert_fails('norm dp', 'E793:')
757 setl nomodifiable
758 call assert_fails('norm do', 'E21:')
759 %bwipe!
760endfunc
Bram Moolenaarf58a8472017-03-05 18:03:04 +0100761
Bram Moolenaar97fbc402017-09-26 19:41:46 +0200762func Test_diff_hlID()
763 new
764 call setline(1, [1, 2, 3])
765 diffthis
766 vnew
767 call setline(1, ['1x', 2, 'x', 3])
768 diffthis
769 redraw
770
Bram Moolenaara74e4942019-08-04 17:35:53 +0200771 call diff_hlID(-1, 1)->synIDattr("name")->assert_equal("")
Bram Moolenaar97fbc402017-09-26 19:41:46 +0200772
Bram Moolenaara74e4942019-08-04 17:35:53 +0200773 call diff_hlID(1, 1)->synIDattr("name")->assert_equal("DiffChange")
774 call diff_hlID(1, 2)->synIDattr("name")->assert_equal("DiffText")
775 call diff_hlID(2, 1)->synIDattr("name")->assert_equal("")
776 call diff_hlID(3, 1)->synIDattr("name")->assert_equal("DiffAdd")
Bram Moolenaar1a3a8912019-08-23 22:31:37 +0200777 eval 4->diff_hlID(1)->synIDattr("name")->assert_equal("")
Bram Moolenaar97fbc402017-09-26 19:41:46 +0200778
779 wincmd w
780 call assert_equal(synIDattr(diff_hlID(1, 1), "name"), "DiffChange")
781 call assert_equal(synIDattr(diff_hlID(2, 1), "name"), "")
782 call assert_equal(synIDattr(diff_hlID(3, 1), "name"), "")
783
784 %bwipe!
785endfunc
786
787func Test_diff_filler()
788 new
789 call setline(1, [1, 2, 3, 'x', 4])
790 diffthis
791 vnew
792 call setline(1, [1, 2, 'y', 'y', 3, 4])
793 diffthis
794 redraw
795
Bram Moolenaar1a3a8912019-08-23 22:31:37 +0200796 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 +0200797 wincmd w
798 call assert_equal([0, 0, 0, 0, 2, 0, 0, 0], map(range(-1, 6), 'diff_filler(v:val)'))
799
800 %bwipe!
801endfunc
802
Bram Moolenaarf58a8472017-03-05 18:03:04 +0100803func Test_diff_lastline()
804 enew!
805 only!
806 call setline(1, ['This is a ', 'line with five ', 'rows'])
807 diffthis
808 botright vert new
809 call setline(1, ['This is', 'a line with ', 'four rows'])
810 diffthis
811 1
812 call feedkeys("Je a\<CR>", 'tx')
813 call feedkeys("Je a\<CR>", 'tx')
814 let w1lines = winline()
815 wincmd w
816 $
817 let w2lines = winline()
818 call assert_equal(w2lines, w1lines)
819 bwipe!
820 bwipe!
821endfunc
Bram Moolenaare828b762018-09-10 17:51:58 +0200822
Bram Moolenaar785fc652018-09-15 19:17:38 +0200823func WriteDiffFiles(buf, list1, list2)
Bram Moolenaare828b762018-09-10 17:51:58 +0200824 call writefile(a:list1, 'Xfile1')
825 call writefile(a:list2, 'Xfile2')
Bram Moolenaar785fc652018-09-15 19:17:38 +0200826 if a:buf
827 call term_sendkeys(a:buf, ":checktime\<CR>")
828 endif
Bram Moolenaare828b762018-09-10 17:51:58 +0200829endfunc
830
Bram Moolenaar785fc652018-09-15 19:17:38 +0200831" Verify a screendump with both the internal and external diff.
Bram Moolenaare828b762018-09-10 17:51:58 +0200832func VerifyBoth(buf, dumpfile, extra)
Bram Moolenaare828b762018-09-10 17:51:58 +0200833 " trailing : for leaving the cursor on the command line
Bram Moolenaar785fc652018-09-15 19:17:38 +0200834 for cmd in [":set diffopt=filler" . a:extra . "\<CR>:", ":set diffopt+=internal\<CR>:"]
Bram Moolenaare828b762018-09-10 17:51:58 +0200835 call term_sendkeys(a:buf, cmd)
836 if VerifyScreenDump(a:buf, a:dumpfile, {}, cmd =~ 'internal' ? 'internal' : 'external')
Bram Moolenaar485b6272021-05-18 19:19:03 +0200837 " don't let the next iteration overwrite the "failed" file.
838 return
Bram Moolenaare828b762018-09-10 17:51:58 +0200839 endif
840 endfor
Bram Moolenaar485b6272021-05-18 19:19:03 +0200841
842 " also test unified diff
843 call term_sendkeys(a:buf, ":call SetupUnified()\<CR>:")
glacambread5c1782021-05-24 14:20:53 +0200844 call term_sendkeys(a:buf, ":redraw!\<CR>:")
Bram Moolenaar485b6272021-05-18 19:19:03 +0200845 call VerifyScreenDump(a:buf, a:dumpfile, {}, 'unified')
846 call term_sendkeys(a:buf, ":call StopUnified()\<CR>:")
Bram Moolenaare828b762018-09-10 17:51:58 +0200847endfunc
848
Bram Moolenaar785fc652018-09-15 19:17:38 +0200849" Verify a screendump with the internal diff only.
850func VerifyInternal(buf, dumpfile, extra)
851 call term_sendkeys(a:buf, ":diffupdate!\<CR>")
852 " trailing : for leaving the cursor on the command line
853 call term_sendkeys(a:buf, ":set diffopt=internal,filler" . a:extra . "\<CR>:")
854 call VerifyScreenDump(a:buf, a:dumpfile, {})
855endfunc
856
Bram Moolenaare828b762018-09-10 17:51:58 +0200857func Test_diff_screen()
Bram Moolenaarf08b0eb2021-10-16 13:00:14 +0100858 let g:test_is_flaky = 1
Bram Moolenaar3c8ee622019-08-03 22:55:50 +0200859 CheckScreendump
860 CheckFeature menu
861
Bram Moolenaar485b6272021-05-18 19:19:03 +0200862 let lines =<< trim END
863 func UnifiedDiffExpr()
864 " Prepend some text to check diff type detection
865 call writefile(['warning', ' message'], v:fname_out)
glacambread5c1782021-05-24 14:20:53 +0200866 silent exe '!diff -U0 ' .. v:fname_in .. ' ' .. v:fname_new .. '>>' .. v:fname_out
Bram Moolenaar485b6272021-05-18 19:19:03 +0200867 endfunc
868 func SetupUnified()
869 set diffexpr=UnifiedDiffExpr()
glacambread5c1782021-05-24 14:20:53 +0200870 diffupdate
Bram Moolenaar485b6272021-05-18 19:19:03 +0200871 endfunc
872 func StopUnified()
873 set diffexpr=
874 endfunc
875 END
876 call writefile(lines, 'XdiffSetup')
877
Bram Moolenaare828b762018-09-10 17:51:58 +0200878 " clean up already existing swap files, just in case
879 call delete('.Xfile1.swp')
880 call delete('.Xfile2.swp')
881
882 " Test 1: Add a line in beginning of file 2
Bram Moolenaar785fc652018-09-15 19:17:38 +0200883 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 Moolenaar485b6272021-05-18 19:19:03 +0200884 let buf = RunVimInTerminal('-d -S XdiffSetup Xfile1 Xfile2', {})
Bram Moolenaar8ee4c012019-03-29 18:08:18 +0100885 " Set autoread mode, so that Vim won't complain once we re-write the test
Bram Moolenaare828b762018-09-10 17:51:58 +0200886 " files
Bram Moolenaar785fc652018-09-15 19:17:38 +0200887 call term_sendkeys(buf, ":set autoread\<CR>\<c-w>w:set autoread\<CR>\<c-w>w")
Bram Moolenaare828b762018-09-10 17:51:58 +0200888
889 call VerifyBoth(buf, 'Test_diff_01', '')
890
891 " Test 2: Add a line in beginning of file 1
Bram Moolenaar785fc652018-09-15 19:17:38 +0200892 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 +0200893 call VerifyBoth(buf, 'Test_diff_02', '')
894
895 " Test 3: Add a line at the end of file 2
Bram Moolenaar785fc652018-09-15 19:17:38 +0200896 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 +0200897 call VerifyBoth(buf, 'Test_diff_03', '')
898
899 " Test 4: Add a line at the end of file 1
Bram Moolenaar785fc652018-09-15 19:17:38 +0200900 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 +0200901 call VerifyBoth(buf, 'Test_diff_04', '')
902
903 " 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 +0200904 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 +0200905 call VerifyBoth(buf, 'Test_diff_05', '')
906
907 " 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 +0200908 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 +0200909 call VerifyBoth(buf, 'Test_diff_06', '')
910
Bram Moolenaarb9ddda62019-02-19 23:00:50 +0100911 " Variants on test 6 with different context settings
912 call term_sendkeys(buf, ":set diffopt+=context:2\<cr>")
913 call VerifyScreenDump(buf, 'Test_diff_06.2', {})
914 call term_sendkeys(buf, ":set diffopt-=context:2\<cr>")
915 call term_sendkeys(buf, ":set diffopt+=context:1\<cr>")
916 call VerifyScreenDump(buf, 'Test_diff_06.1', {})
917 call term_sendkeys(buf, ":set diffopt-=context:1\<cr>")
918 call term_sendkeys(buf, ":set diffopt+=context:0\<cr>")
919 call VerifyScreenDump(buf, 'Test_diff_06.0', {})
920 call term_sendkeys(buf, ":set diffopt-=context:0\<cr>")
921
Bram Moolenaare828b762018-09-10 17:51:58 +0200922 " Test 7 - 9: Test normal/patience/histogram diff algorithm
Bram Moolenaar785fc652018-09-15 19:17:38 +0200923 call WriteDiffFiles(buf, ['#include <stdio.h>', '', '// Frobs foo heartily', 'int frobnitz(int foo)', '{',
Bram Moolenaare828b762018-09-10 17:51:58 +0200924 \ ' int i;', ' for(i = 0; i < 10; i++)', ' {', ' printf("Your answer is: ");',
925 \ ' printf("%d\n", foo);', ' }', '}', '', 'int fact(int n)', '{', ' if(n > 1)', ' {',
926 \ ' return fact(n-1) * n;', ' }', ' return 1;', '}', '', 'int main(int argc, char **argv)',
927 \ '{', ' frobnitz(fact(10));', '}'],
928 \ ['#include <stdio.h>', '', 'int fib(int n)', '{', ' if(n > 2)', ' {',
929 \ ' return fib(n-1) + fib(n-2);', ' }', ' return 1;', '}', '', '// Frobs foo heartily',
930 \ 'int frobnitz(int foo)', '{', ' int i;', ' for(i = 0; i < 10; i++)', ' {',
931 \ ' printf("%d\n", foo);', ' }', '}', '',
932 \ 'int main(int argc, char **argv)', '{', ' frobnitz(fib(10));', '}'])
933 call term_sendkeys(buf, ":diffupdate!\<cr>")
934 call term_sendkeys(buf, ":set diffopt+=internal\<cr>")
935 call VerifyScreenDump(buf, 'Test_diff_07', {})
936
937 call term_sendkeys(buf, ":set diffopt+=algorithm:patience\<cr>")
938 call VerifyScreenDump(buf, 'Test_diff_08', {})
939
940 call term_sendkeys(buf, ":set diffopt+=algorithm:histogram\<cr>")
941 call VerifyScreenDump(buf, 'Test_diff_09', {})
942
943 " Test 10-11: normal/indent-heuristic
944 call term_sendkeys(buf, ":set diffopt&vim\<cr>")
Bram Moolenaar785fc652018-09-15 19:17:38 +0200945 call WriteDiffFiles(buf, ['', ' def finalize(values)', '', ' values.each do |v|', ' v.finalize', ' end'],
Bram Moolenaare828b762018-09-10 17:51:58 +0200946 \ ['', ' def finalize(values)', '', ' values.each do |v|', ' v.prepare', ' end', '',
947 \ ' values.each do |v|', ' v.finalize', ' end'])
948 call term_sendkeys(buf, ":diffupdate!\<cr>")
949 call term_sendkeys(buf, ":set diffopt+=internal\<cr>")
950 call VerifyScreenDump(buf, 'Test_diff_10', {})
951
Bram Moolenaarb6fc7282018-12-04 22:24:16 +0100952 " Leave trailing : at commandline!
953 call term_sendkeys(buf, ":set diffopt+=indent-heuristic\<cr>:\<cr>")
954 call VerifyScreenDump(buf, 'Test_diff_11', {}, 'one')
955 " shouldn't matter, if indent-algorithm comes before or after the algorithm
956 call term_sendkeys(buf, ":set diffopt&\<cr>")
957 call term_sendkeys(buf, ":set diffopt+=indent-heuristic,algorithm:patience\<cr>:\<cr>")
958 call VerifyScreenDump(buf, 'Test_diff_11', {}, 'two')
959 call term_sendkeys(buf, ":set diffopt&\<cr>")
960 call term_sendkeys(buf, ":set diffopt+=algorithm:patience,indent-heuristic\<cr>:\<cr>")
961 call VerifyScreenDump(buf, 'Test_diff_11', {}, 'three')
Bram Moolenaare828b762018-09-10 17:51:58 +0200962
963 " Test 12: diff the same file
Bram Moolenaar785fc652018-09-15 19:17:38 +0200964 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 +0200965 call VerifyBoth(buf, 'Test_diff_12', '')
966
967 " Test 13: diff an empty file
Bram Moolenaar785fc652018-09-15 19:17:38 +0200968 call WriteDiffFiles(buf, [], [])
Bram Moolenaare828b762018-09-10 17:51:58 +0200969 call VerifyBoth(buf, 'Test_diff_13', '')
970
971 " Test 14: test diffopt+=icase
Bram Moolenaar785fc652018-09-15 19:17:38 +0200972 call WriteDiffFiles(buf, ['a', 'b', 'cd'], ['A', 'b', 'cDe'])
Bram Moolenaare828b762018-09-10 17:51:58 +0200973 call VerifyBoth(buf, 'Test_diff_14', " diffopt+=filler diffopt+=icase")
974
975 " Test 15-16: test diffopt+=iwhite
Bram Moolenaar785fc652018-09-15 19:17:38 +0200976 call WriteDiffFiles(buf, ['int main()', '{', ' printf("Hello, World!");', ' return 0;', '}'],
Bram Moolenaare828b762018-09-10 17:51:58 +0200977 \ ['int main()', '{', ' if (0)', ' {', ' printf("Hello, World!");', ' return 0;', ' }', '}'])
978 call term_sendkeys(buf, ":diffupdate!\<cr>")
979 call term_sendkeys(buf, ":set diffopt&vim diffopt+=filler diffopt+=iwhite\<cr>")
980 call VerifyScreenDump(buf, 'Test_diff_15', {})
981 call term_sendkeys(buf, ":set diffopt+=internal\<cr>")
982 call VerifyScreenDump(buf, 'Test_diff_16', {})
983
Bram Moolenaar785fc652018-09-15 19:17:38 +0200984 " Test 17: test diffopt+=iblank
985 call WriteDiffFiles(buf, ['a', ' ', 'cd', 'ef', 'xxx'], ['a', 'cd', '', 'ef', 'yyy'])
986 call VerifyInternal(buf, 'Test_diff_17', " diffopt+=iblank")
987
988 " Test 18: test diffopt+=iblank,iwhite / iwhiteall / iwhiteeol
989 call VerifyInternal(buf, 'Test_diff_18', " diffopt+=iblank,iwhite")
990 call VerifyInternal(buf, 'Test_diff_18', " diffopt+=iblank,iwhiteall")
991 call VerifyInternal(buf, 'Test_diff_18', " diffopt+=iblank,iwhiteeol")
992
993 " Test 19: test diffopt+=iwhiteeol
994 call WriteDiffFiles(buf, ['a ', 'x', 'cd', 'ef', 'xx xx', 'foo', 'bar'], ['a', 'x', 'c d', ' ef', 'xx xx', 'foo', '', 'bar'])
995 call VerifyInternal(buf, 'Test_diff_19', " diffopt+=iwhiteeol")
996
997 " Test 19: test diffopt+=iwhiteall
998 call VerifyInternal(buf, 'Test_diff_20', " diffopt+=iwhiteall")
999
Bram Moolenaare828b762018-09-10 17:51:58 +02001000 " clean up
1001 call StopVimInTerminal(buf)
1002 call delete('Xfile1')
1003 call delete('Xfile2')
Bram Moolenaar485b6272021-05-18 19:19:03 +02001004 call delete('XdiffSetup')
Bram Moolenaare828b762018-09-10 17:51:58 +02001005endfunc
1006
Bram Moolenaar04626c22021-09-01 16:02:07 +02001007func Test_diff_with_scroll_and_change()
1008 CheckScreendump
1009
1010 let lines =<< trim END
1011 call setline(1, range(1, 15))
1012 vnew
1013 call setline(1, range(9, 15))
1014 windo diffthis
1015 wincmd h
1016 exe "normal Gl5\<C-E>"
1017 END
1018 call writefile(lines, 'Xtest_scroll_change')
1019 let buf = RunVimInTerminal('-S Xtest_scroll_change', {})
1020
1021 call VerifyScreenDump(buf, 'Test_diff_scroll_change_01', {})
1022
1023 call term_sendkeys(buf, "ax\<Esc>")
1024 call VerifyScreenDump(buf, 'Test_diff_scroll_change_02', {})
1025
Bram Moolenaar841c2252021-10-22 20:56:55 +01001026 call term_sendkeys(buf, "\<C-W>lay\<Esc>")
1027 call VerifyScreenDump(buf, 'Test_diff_scroll_change_03', {})
1028
Bram Moolenaar04626c22021-09-01 16:02:07 +02001029 " clean up
1030 call StopVimInTerminal(buf)
1031 call delete('Xtest_scroll_change')
1032endfunc
1033
Bram Moolenaar4a5abbd2018-10-02 18:26:10 +02001034func Test_diff_with_cursorline()
Bram Moolenaar3c8ee622019-08-03 22:55:50 +02001035 CheckScreendump
Bram Moolenaar4a5abbd2018-10-02 18:26:10 +02001036
1037 call writefile([
1038 \ 'hi CursorLine ctermbg=red ctermfg=white',
1039 \ 'set cursorline',
1040 \ 'call setline(1, ["foo","foo","foo","bar"])',
1041 \ 'vnew',
1042 \ 'call setline(1, ["bee","foo","foo","baz"])',
1043 \ 'windo diffthis',
1044 \ '2wincmd w',
1045 \ ], 'Xtest_diff_cursorline')
1046 let buf = RunVimInTerminal('-S Xtest_diff_cursorline', {})
1047
1048 call VerifyScreenDump(buf, 'Test_diff_with_cursorline_01', {})
1049 call term_sendkeys(buf, "j")
1050 call VerifyScreenDump(buf, 'Test_diff_with_cursorline_02', {})
1051 call term_sendkeys(buf, "j")
1052 call VerifyScreenDump(buf, 'Test_diff_with_cursorline_03', {})
1053
1054 " clean up
1055 call StopVimInTerminal(buf)
1056 call delete('Xtest_diff_cursorline')
1057endfunc
Bram Moolenaarf7acf2b2018-11-01 21:14:53 +01001058
Bram Moolenaar127969c2022-03-06 19:54:13 +00001059func Test_diff_with_cursorline_number()
1060 CheckScreendump
1061
1062 let lines =<< trim END
1063 hi CursorLine ctermbg=red ctermfg=white
1064 hi CursorLineNr ctermbg=white ctermfg=black cterm=underline
1065 set cursorline number
1066 call setline(1, ["baz", "foo", "foo", "bar"])
1067 2
1068 vnew
1069 call setline(1, ["foo", "foo", "bar"])
1070 windo diffthis
1071 1wincmd w
1072 END
1073 call writefile(lines, 'Xtest_diff_cursorline_number')
1074 let buf = RunVimInTerminal('-S Xtest_diff_cursorline_number', {})
1075
1076 call VerifyScreenDump(buf, 'Test_diff_with_cursorline_number_01', {})
1077 call term_sendkeys(buf, ":set cursorlineopt=number\r")
1078 call VerifyScreenDump(buf, 'Test_diff_with_cursorline_number_02', {})
1079
1080 " clean up
1081 call StopVimInTerminal(buf)
1082 call delete('Xtest_diff_cursorline_number')
1083endfunc
1084
zeertzjq4f33bc22021-08-05 17:57:02 +02001085func Test_diff_with_cursorline_breakindent()
1086 CheckScreendump
1087
1088 call writefile([
1089 \ 'hi CursorLine ctermbg=red ctermfg=white',
1090 \ 'set noequalalways wrap diffopt=followwrap cursorline breakindent',
1091 \ '50vnew',
1092 \ 'call setline(1, [" "," "," "," "])',
1093 \ 'exe "norm 20Afoo\<Esc>j20Afoo\<Esc>j20Afoo\<Esc>j20Abar\<Esc>"',
1094 \ 'vnew',
1095 \ 'call setline(1, [" "," "," "," "])',
1096 \ 'exe "norm 20Abee\<Esc>j20Afoo\<Esc>j20Afoo\<Esc>j20Abaz\<Esc>"',
1097 \ 'windo diffthis',
1098 \ '2wincmd w',
1099 \ ], 'Xtest_diff_cursorline_breakindent')
1100 let buf = RunVimInTerminal('-S Xtest_diff_cursorline_breakindent', {})
1101
1102 call term_sendkeys(buf, "gg0")
1103 call VerifyScreenDump(buf, 'Test_diff_with_cul_bri_01', {})
1104 call term_sendkeys(buf, "j")
1105 call VerifyScreenDump(buf, 'Test_diff_with_cul_bri_02', {})
1106 call term_sendkeys(buf, "j")
1107 call VerifyScreenDump(buf, 'Test_diff_with_cul_bri_03', {})
1108 call term_sendkeys(buf, "j")
1109 call VerifyScreenDump(buf, 'Test_diff_with_cul_bri_04', {})
1110
1111 " clean up
1112 call StopVimInTerminal(buf)
1113 call delete('Xtest_diff_cursorline_breakindent')
1114endfunc
1115
Bram Moolenaar248fdb32019-09-15 19:31:28 +02001116func Test_diff_with_syntax()
1117 CheckScreendump
1118
1119 let lines =<< trim END
1120 void doNothing() {
1121 int x = 0;
1122 char *s = "hello";
1123 return 5;
1124 }
1125 END
1126 call writefile(lines, 'Xprogram1.c')
1127 let lines =<< trim END
1128 void doSomething() {
1129 int x = 0;
1130 char *s = "there";
1131 return 5;
1132 }
1133 END
1134 call writefile(lines, 'Xprogram2.c')
1135
1136 let lines =<< trim END
1137 edit Xprogram1.c
1138 diffsplit Xprogram2.c
1139 END
1140 call writefile(lines, 'Xtest_diff_syntax')
1141 let buf = RunVimInTerminal('-S Xtest_diff_syntax', {})
1142
1143 call VerifyScreenDump(buf, 'Test_diff_syntax_1', {})
1144
1145 " clean up
1146 call StopVimInTerminal(buf)
1147 call delete('Xtest_diff_syntax')
1148 call delete('Xprogram1.c')
1149 call delete('Xprogram2.c')
1150endfunc
1151
Bram Moolenaarf7acf2b2018-11-01 21:14:53 +01001152func Test_diff_of_diff()
Bram Moolenaar3c8ee622019-08-03 22:55:50 +02001153 CheckScreendump
1154 CheckFeature rightleft
Bram Moolenaarf7acf2b2018-11-01 21:14:53 +01001155
1156 call writefile([
1157 \ 'call setline(1, ["aa","bb","cc","@@ -3,2 +5,7 @@","dd","ee","ff"])',
1158 \ 'vnew',
1159 \ 'call setline(1, ["aa","bb","cc"])',
1160 \ 'windo diffthis',
Bram Moolenaar8ee4c012019-03-29 18:08:18 +01001161 \ '1wincmd w',
1162 \ 'setlocal number',
Bram Moolenaarf7acf2b2018-11-01 21:14:53 +01001163 \ ], 'Xtest_diff_diff')
1164 let buf = RunVimInTerminal('-S Xtest_diff_diff', {})
1165
1166 call VerifyScreenDump(buf, 'Test_diff_of_diff_01', {})
1167
Bram Moolenaare73f9112019-03-29 18:29:54 +01001168 call term_sendkeys(buf, ":set rightleft\<cr>")
1169 call VerifyScreenDump(buf, 'Test_diff_of_diff_02', {})
1170
Bram Moolenaarf7acf2b2018-11-01 21:14:53 +01001171 " clean up
1172 call StopVimInTerminal(buf)
1173 call delete('Xtest_diff_diff')
1174endfunc
Bram Moolenaarc8234772019-11-10 21:00:27 +01001175
1176func CloseoffSetup()
1177 enew
1178 call setline(1, ['one', 'two', 'three'])
1179 diffthis
1180 new
1181 call setline(1, ['one', 'tow', 'three'])
1182 diffthis
1183 call assert_equal(1, &diff)
1184 only!
1185endfunc
1186
1187func Test_diff_closeoff()
1188 " "closeoff" included by default: last diff win gets 'diff' reset'
1189 call CloseoffSetup()
1190 call assert_equal(0, &diff)
1191 enew!
1192
1193 " "closeoff" excluded: last diff win keeps 'diff' set'
1194 set diffopt-=closeoff
1195 call CloseoffSetup()
1196 call assert_equal(1, &diff)
1197 diffoff!
1198 enew!
1199endfunc
Bram Moolenaarf4a1d1c2019-11-16 13:50:25 +01001200
Bram Moolenaar4223d432021-02-10 13:18:17 +01001201func Test_diff_followwrap()
1202 new
1203 set diffopt+=followwrap
1204 set wrap
1205 diffthis
1206 call assert_equal(1, &wrap)
1207 diffoff
1208 set nowrap
1209 diffthis
1210 call assert_equal(0, &wrap)
1211 diffoff
1212 set diffopt&
1213 bwipe!
1214endfunc
1215
Bram Moolenaarf4a1d1c2019-11-16 13:50:25 +01001216func Test_diff_maintains_change_mark()
Sean Dewarccc16442021-12-29 16:44:48 +00001217 func DiffMaintainsChangeMark()
1218 enew!
1219 call setline(1, ['a', 'b', 'c', 'd'])
1220 diffthis
1221 new
1222 call setline(1, ['a', 'b', 'c', 'e'])
1223 " Set '[ and '] marks
1224 2,3yank
1225 call assert_equal([2, 3], [line("'["), line("']")])
1226 " Verify they aren't affected by the implicit diff
1227 diffthis
1228 call assert_equal([2, 3], [line("'["), line("']")])
1229 " Verify they aren't affected by an explicit diff
1230 diffupdate
1231 call assert_equal([2, 3], [line("'["), line("']")])
1232 bwipe!
1233 bwipe!
1234 endfunc
1235
1236 set diffopt-=internal
1237 call DiffMaintainsChangeMark()
1238 set diffopt+=internal
1239 call DiffMaintainsChangeMark()
Bram Moolenaard9b74a22022-01-16 15:00:08 +00001240
Sean Dewarccc16442021-12-29 16:44:48 +00001241 set diffopt&
Bram Moolenaard9b74a22022-01-16 15:00:08 +00001242 delfunc DiffMaintainsChangeMark
Bram Moolenaarf4a1d1c2019-11-16 13:50:25 +01001243endfunc
Bram Moolenaar8dfcce32020-03-18 19:32:26 +01001244
1245" Test for 'patchexpr'
1246func Test_patchexpr()
1247 let g:patch_args = []
1248 func TPatch()
1249 call add(g:patch_args, readfile(v:fname_in))
1250 call add(g:patch_args, readfile(v:fname_diff))
1251 call writefile(['output file'], v:fname_out)
1252 endfunc
1253 set patchexpr=TPatch()
1254
1255 call writefile(['input file'], 'Xinput')
1256 call writefile(['diff file'], 'Xdiff')
1257 %bwipe!
1258 edit Xinput
1259 diffpatch Xdiff
1260 call assert_equal('output file', getline(1))
1261 call assert_equal('Xinput.new', bufname())
1262 call assert_equal(2, winnr('$'))
1263 call assert_true(&diff)
1264
Yegappan Lakshmanan8bb65f22021-12-26 10:51:39 +00001265 " Using a script-local function
1266 func s:NewPatchExpr()
1267 endfunc
1268 set patchexpr=s:NewPatchExpr()
1269 call assert_equal(expand('<SID>') .. 'NewPatchExpr()', &patchexpr)
1270 set patchexpr=<SID>NewPatchExpr()
1271 call assert_equal(expand('<SID>') .. 'NewPatchExpr()', &patchexpr)
1272
Bram Moolenaar8dfcce32020-03-18 19:32:26 +01001273 call delete('Xinput')
1274 call delete('Xdiff')
1275 set patchexpr&
1276 delfunc TPatch
Yegappan Lakshmanan8bb65f22021-12-26 10:51:39 +00001277 delfunc s:NewPatchExpr
Bram Moolenaar8dfcce32020-03-18 19:32:26 +01001278 %bwipe!
1279endfunc
1280
Bram Moolenaar511feec2020-06-18 19:15:27 +02001281func Test_diff_rnu()
1282 CheckScreendump
1283
1284 let content =<< trim END
1285 call setline(1, ['a', 'a', 'a', 'y', 'b', 'b', 'b', 'b', 'b'])
1286 vnew
1287 call setline(1, ['a', 'a', 'a', 'x', 'x', 'x', 'b', 'b', 'b', 'b', 'b'])
1288 windo diffthis
1289 setlocal number rnu foldcolumn=0
1290 END
1291 call writefile(content, 'Xtest_diff_rnu')
1292 let buf = RunVimInTerminal('-S Xtest_diff_rnu', {})
1293
1294 call VerifyScreenDump(buf, 'Test_diff_rnu_01', {})
1295
1296 call term_sendkeys(buf, "j")
1297 call VerifyScreenDump(buf, 'Test_diff_rnu_02', {})
1298 call term_sendkeys(buf, "j")
1299 call VerifyScreenDump(buf, 'Test_diff_rnu_03', {})
1300
1301 " clean up
1302 call StopVimInTerminal(buf)
1303 call delete('Xtest_diff_rnu')
1304endfunc
1305
Bram Moolenaarfc838d62020-06-25 22:23:48 +02001306func Test_diff_multilineconceal()
1307 new
1308 diffthis
1309
1310 new
1311 call matchadd('Conceal', 'a\nb', 9, -1, {'conceal': 'Y'})
1312 set cole=2 cocu=n
1313 call setline(1, ["a", "b"])
1314 diffthis
1315 redraw
1316endfunc
1317
Bram Moolenaar8455c5e2020-07-14 21:22:30 +02001318func Test_diff_and_scroll()
1319 " this was causing an ml_get error
1320 set ls=2
1321 for i in range(winheight(0) * 2)
1322 call setline(i, i < winheight(0) - 10 ? i : i + 10)
1323 endfor
1324 vnew
1325 for i in range(winheight(0)*2 + 10)
1326 call setline(i, i < winheight(0) - 10 ? 0 : i)
1327 endfor
1328 diffthis
1329 wincmd p
1330 diffthis
1331 execute 'normal ' . winheight(0) . "\<C-d>"
1332
1333 bwipe!
1334 bwipe!
1335 set ls&
1336endfunc
1337
Bram Moolenaarfabc3ca2020-11-05 19:07:21 +01001338func Test_diff_filler_cursorcolumn()
1339 CheckScreendump
1340
1341 let content =<< trim END
1342 call setline(1, ['aa', 'bb', 'cc'])
1343 vnew
1344 call setline(1, ['aa', 'cc'])
1345 windo diffthis
1346 wincmd p
1347 setlocal cursorcolumn foldcolumn=0
1348 norm! gg0
1349 redraw!
1350 END
1351 call writefile(content, 'Xtest_diff_cuc')
1352 let buf = RunVimInTerminal('-S Xtest_diff_cuc', {})
1353
1354 call VerifyScreenDump(buf, 'Test_diff_cuc_01', {})
1355
1356 call term_sendkeys(buf, "l")
1357 call term_sendkeys(buf, "\<C-l>")
1358 call VerifyScreenDump(buf, 'Test_diff_cuc_02', {})
1359 call term_sendkeys(buf, "0j")
1360 call term_sendkeys(buf, "\<C-l>")
1361 call VerifyScreenDump(buf, 'Test_diff_cuc_03', {})
1362 call term_sendkeys(buf, "l")
1363 call term_sendkeys(buf, "\<C-l>")
1364 call VerifyScreenDump(buf, 'Test_diff_cuc_04', {})
1365
1366 " clean up
1367 call StopVimInTerminal(buf)
1368 call delete('Xtest_diff_cuc')
1369endfunc
1370
Yegappan Lakshmanan30443242021-06-10 21:52:15 +02001371" Test for adding/removing lines inside diff chunks, between diff chunks
1372" and before diff chunks
1373func Test_diff_modify_chunks()
1374 enew!
1375 let w2_id = win_getid()
1376 call setline(1, ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i'])
1377 new
1378 let w1_id = win_getid()
1379 call setline(1, ['a', '2', '3', 'd', 'e', 'f', '7', '8', 'i'])
1380 windo diffthis
1381
1382 " remove a line between two diff chunks and create a new diff chunk
1383 call win_gotoid(w2_id)
1384 5d
1385 call win_gotoid(w1_id)
1386 call diff_hlID(5, 1)->synIDattr('name')->assert_equal('DiffAdd')
1387
1388 " add a line between two diff chunks
1389 call win_gotoid(w2_id)
1390 normal! 4Goe
1391 call win_gotoid(w1_id)
1392 call diff_hlID(4, 1)->synIDattr('name')->assert_equal('')
1393 call diff_hlID(5, 1)->synIDattr('name')->assert_equal('')
1394
1395 " remove all the lines in a diff chunk.
1396 call win_gotoid(w2_id)
1397 7,8d
1398 call win_gotoid(w1_id)
1399 let hl = range(1, 9)->map({_, lnum -> diff_hlID(lnum, 1)->synIDattr('name')})
1400 call assert_equal(['', 'DiffText', 'DiffText', '', '', '', 'DiffAdd',
1401 \ 'DiffAdd', ''], hl)
1402
1403 " remove lines from one diff chunk to just before the next diff chunk
1404 call win_gotoid(w2_id)
1405 call setline(1, ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i'])
1406 2,6d
1407 call win_gotoid(w1_id)
1408 let hl = range(1, 9)->map({_, lnum -> diff_hlID(lnum, 1)->synIDattr('name')})
1409 call assert_equal(['', 'DiffText', 'DiffText', 'DiffAdd', 'DiffAdd',
1410 \ 'DiffAdd', 'DiffAdd', 'DiffAdd', ''], hl)
1411
1412 " remove lines just before the top of a diff chunk
1413 call win_gotoid(w2_id)
1414 call setline(1, ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i'])
1415 5,6d
1416 call win_gotoid(w1_id)
1417 let hl = range(1, 9)->map({_, lnum -> diff_hlID(lnum, 1)->synIDattr('name')})
1418 call assert_equal(['', 'DiffText', 'DiffText', '', 'DiffText', 'DiffText',
1419 \ 'DiffAdd', 'DiffAdd', ''], hl)
1420
1421 " remove line after the end of a diff chunk
1422 call win_gotoid(w2_id)
1423 call setline(1, ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i'])
1424 4d
1425 call win_gotoid(w1_id)
1426 let hl = range(1, 9)->map({_, lnum -> diff_hlID(lnum, 1)->synIDattr('name')})
1427 call assert_equal(['', 'DiffText', 'DiffText', 'DiffAdd', '', '', 'DiffText',
1428 \ 'DiffText', ''], hl)
1429
1430 " remove lines starting from the end of one diff chunk and ending inside
1431 " another diff chunk
1432 call win_gotoid(w2_id)
1433 call setline(1, ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i'])
1434 4,7d
1435 call win_gotoid(w1_id)
1436 let hl = range(1, 9)->map({_, lnum -> diff_hlID(lnum, 1)->synIDattr('name')})
1437 call assert_equal(['', 'DiffText', 'DiffText', 'DiffText', 'DiffAdd',
1438 \ 'DiffAdd', 'DiffAdd', 'DiffAdd', ''], hl)
1439
1440 " removing the only remaining diff chunk should make the files equal
1441 call win_gotoid(w2_id)
1442 call setline(1, ['a', '2', '3', 'x', 'd', 'e', 'f', 'x', '7', '8', 'i'])
1443 8d
1444 let hl = range(1, 10)->map({_, lnum -> diff_hlID(lnum, 1)->synIDattr('name')})
1445 call assert_equal(['', '', '', 'DiffAdd', '', '', '', '', '', ''], hl)
1446 call win_gotoid(w2_id)
1447 4d
1448 call win_gotoid(w1_id)
1449 let hl = range(1, 9)->map({_, lnum -> diff_hlID(lnum, 1)->synIDattr('name')})
1450 call assert_equal(['', '', '', '', '', '', '', '', ''], hl)
1451
1452 %bw!
1453endfunc
glacambread5c1782021-05-24 14:20:53 +02001454
Bram Moolenaar06f60952021-12-28 18:30:05 +00001455func Test_diff_binary()
1456 CheckScreendump
1457
1458 let content =<< trim END
1459 call setline(1, ['a', 'b', "c\n", 'd', 'e', 'f', 'g'])
1460 vnew
1461 call setline(1, ['A', 'b', 'c', 'd', 'E', 'f', 'g'])
1462 windo diffthis
1463 wincmd p
1464 norm! gg0
1465 redraw!
1466 END
1467 call writefile(content, 'Xtest_diff_bin')
1468 let buf = RunVimInTerminal('-S Xtest_diff_bin', {})
1469
1470 " Test using internal diff
1471 call VerifyScreenDump(buf, 'Test_diff_bin_01', {})
1472
1473 " Test using internal diff and case folding
1474 call term_sendkeys(buf, ":set diffopt+=icase\<cr>")
1475 call term_sendkeys(buf, "\<C-l>")
1476 call VerifyScreenDump(buf, 'Test_diff_bin_02', {})
1477 " Test using external diff
1478 call term_sendkeys(buf, ":set diffopt=filler\<cr>")
1479 call term_sendkeys(buf, "\<C-l>")
1480 call VerifyScreenDump(buf, 'Test_diff_bin_03', {})
1481 " Test using external diff and case folding
1482 call term_sendkeys(buf, ":set diffopt=filler,icase\<cr>")
1483 call term_sendkeys(buf, "\<C-l>")
1484 call VerifyScreenDump(buf, 'Test_diff_bin_04', {})
1485
1486 " clean up
1487 call StopVimInTerminal(buf)
1488 call delete('Xtest_diff_bin')
1489 set diffopt&vim
1490endfunc
1491
Yegappan Lakshmananb0ad2d92022-01-27 13:16:59 +00001492" Test for using the 'zi' command to invert 'foldenable' in diff windows (test
1493" for the issue fixed by patch 6.2.317)
1494func Test_diff_foldinvert()
1495 %bw!
1496 edit Xfile1
1497 new Xfile2
1498 new Xfile3
1499 windo diffthis
1500 " open a non-diff window
1501 botright new
1502 1wincmd w
1503 call assert_true(getwinvar(1, '&foldenable'))
1504 call assert_true(getwinvar(2, '&foldenable'))
1505 call assert_true(getwinvar(3, '&foldenable'))
1506 normal zi
1507 call assert_false(getwinvar(1, '&foldenable'))
1508 call assert_false(getwinvar(2, '&foldenable'))
1509 call assert_false(getwinvar(3, '&foldenable'))
1510 normal zi
1511 call assert_true(getwinvar(1, '&foldenable'))
1512 call assert_true(getwinvar(2, '&foldenable'))
1513 call assert_true(getwinvar(3, '&foldenable'))
1514
1515 " If the current window has 'noscrollbind', then 'zi' should not change
1516 " 'foldenable' in other windows.
1517 1wincmd w
1518 set noscrollbind
1519 normal zi
1520 call assert_false(getwinvar(1, '&foldenable'))
1521 call assert_true(getwinvar(2, '&foldenable'))
1522 call assert_true(getwinvar(3, '&foldenable'))
1523
1524 " 'zi' should not change the 'foldenable' for windows with 'noscrollbind'
1525 1wincmd w
1526 set scrollbind
1527 normal zi
1528 call setwinvar(2, '&scrollbind', v:false)
1529 normal zi
1530 call assert_false(getwinvar(1, '&foldenable'))
1531 call assert_true(getwinvar(2, '&foldenable'))
1532 call assert_false(getwinvar(3, '&foldenable'))
1533
1534 %bw!
1535 set scrollbind&
1536endfunc
1537
Bram Moolenaara315ce12022-06-24 12:38:57 +01001538" This was scrolling for 'cursorbind' but 'scrollbind' is more important
1539func Test_diff_scroll()
1540 CheckScreendump
1541
1542 let left =<< trim END
1543 line 1
1544 line 2
1545 line 3
1546 line 4
1547
1548 // Common block
1549 // one
1550 // containing
1551 // four lines
1552
1553 // Common block
1554 // two
1555 // containing
1556 // four lines
1557 END
1558 call writefile(left, 'Xleft')
1559 let right =<< trim END
1560 line 1
1561 line 2
1562 line 3
1563 line 4
1564
1565 Lorem
1566 ipsum
1567 dolor
1568 sit
1569 amet,
1570 consectetur
1571 adipiscing
1572 elit.
1573 Etiam
1574 luctus
1575 lectus
1576 sodales,
1577 dictum
1578
1579 // Common block
1580 // one
1581 // containing
1582 // four lines
1583
1584 Vestibulum
1585 tincidunt
1586 aliquet
1587 nulla.
1588
1589 // Common block
1590 // two
1591 // containing
1592 // four lines
1593 END
1594 call writefile(right, 'Xright')
1595 let buf = RunVimInTerminal('-d Xleft Xright', {'rows': 12})
1596 call term_sendkeys(buf, "\<C-W>\<C-W>jjjj")
1597 call VerifyScreenDump(buf, 'Test_diff_scroll_1', {})
1598 call term_sendkeys(buf, "j")
1599 call VerifyScreenDump(buf, 'Test_diff_scroll_2', {})
1600
1601 call StopVimInTerminal(buf)
1602 call delete('Xleft')
1603 call delete('Xright')
1604endfunc
1605
1606
Bram Moolenaar8dfcce32020-03-18 19:32:26 +01001607" vim: shiftwidth=2 sts=2 expandtab