1" Tests for diff mode
2source shared.vim
3source screendump.vim
4
5func Test_diff_fold_sync()
6  enew!
7  let l = range(50)
8  call setline(1, l)
9  diffthis
10  let winone = win_getid()
11  new
12  let l[25] = 'diff'
13  call setline(1, l)
14  diffthis
15  let wintwo = win_getid()
16  " line 15 is inside the closed fold
17  call assert_equal(19, foldclosedend(10))
18  call win_gotoid(winone)
19  call assert_equal(19, foldclosedend(10))
20  " open the fold
21  normal zv
22  call assert_equal(-1, foldclosedend(10))
23  " fold in other window must have opened too
24  call win_gotoid(wintwo)
25  call assert_equal(-1, foldclosedend(10))
26
27  " cursor position is in sync
28  normal 23G
29  call win_gotoid(winone)
30  call assert_equal(23, getcurpos()[1])
31
32  windo diffoff
33  close!
34  set nomodified
35endfunc
36
37func Test_vert_split()
38  set diffopt=filler
39  call Common_vert_split()
40  set diffopt&
41endfunc
42
43func Test_vert_split_internal()
44  set diffopt=internal,filler
45  call Common_vert_split()
46  set diffopt&
47endfunc
48
49func Common_vert_split()
50  " Disable the title to avoid xterm keeping the wrong one.
51  set notitle noicon
52  new
53  let l = ['1 aa', '2 bb', '3 cc', '4 dd', '5 ee']
54  call setline(1, l)
55  w! Xtest
56  normal dd
57  $
58  put
59  normal kkrXoxxx
60  w! Xtest2
61  file Nop
62  normal ggoyyyjjjozzzz
63  set foldmethod=marker foldcolumn=4
64  call assert_equal(0, &diff)
65  call assert_equal('marker', &foldmethod)
66  call assert_equal(4, &foldcolumn)
67  call assert_equal(0, &scrollbind)
68  call assert_equal(0, &cursorbind)
69  call assert_equal(1, &wrap)
70
71  vert diffsplit Xtest
72  vert diffsplit Xtest2
73  call assert_equal(1, &diff)
74  call assert_equal('diff', &foldmethod)
75  call assert_equal(2, &foldcolumn)
76  call assert_equal(1, &scrollbind)
77  call assert_equal(1, &cursorbind)
78  call assert_equal(0, &wrap)
79
80  let diff_fdm = &fdm
81  let diff_fdc = &fdc
82  " repeat entering diff mode here to see if this saves the wrong settings
83  diffthis
84  " jump to second window for a moment to have filler line appear at start of
85  " first window
86  wincmd w
87  normal gg
88  wincmd p
89  normal gg
90  call assert_equal(2, winline())
91  normal j
92  call assert_equal(4, winline())
93  normal j
94  call assert_equal(5, winline())
95  normal j
96  call assert_equal(6, winline())
97  normal j
98  call assert_equal(8, winline())
99  normal j
100  call assert_equal(9, winline())
101
102  wincmd w
103  normal gg
104  call assert_equal(1, winline())
105  normal j
106  call assert_equal(2, winline())
107  normal j
108  call assert_equal(4, winline())
109  normal j
110  call assert_equal(5, winline())
111  normal j
112  call assert_equal(8, winline())
113
114  wincmd w
115  normal gg
116  call assert_equal(2, winline())
117  normal j
118  call assert_equal(3, winline())
119  normal j
120  call assert_equal(4, winline())
121  normal j
122  call assert_equal(5, winline())
123  normal j
124  call assert_equal(6, winline())
125  normal j
126  call assert_equal(7, winline())
127  normal j
128  call assert_equal(8, winline())
129
130  " Test diffoff
131  diffoff!
132  1wincmd 2
133  let &diff = 1
134  let &fdm = diff_fdm
135  let &fdc = diff_fdc
136  4wincmd w
137  diffoff!
138  1wincmd w
139  call assert_equal(0, &diff)
140  call assert_equal('marker', &foldmethod)
141  call assert_equal(4, &foldcolumn)
142  call assert_equal(0, &scrollbind)
143  call assert_equal(0, &cursorbind)
144  call assert_equal(1, &wrap)
145
146  wincmd 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  call delete('Xtest')
163  call delete('Xtest2')
164  windo bw!
165endfunc
166
167func Test_filler_lines()
168  " Test that diffing shows correct filler lines
169  enew!
170  put =range(4,10)
171  1d _
172  vnew
173  put =range(1,10)
174  1d _
175  windo diffthis
176  wincmd h
177  call assert_equal(1, line('w0'))
178  unlet! diff_fdm diff_fdc
179  windo diffoff
180  bwipe!
181  enew!
182endfunc
183
184func Test_diffget_diffput()
185  enew!
186  let l = range(50)
187  call setline(1, l)
188  call assert_fails('diffget', 'E99:')
189  diffthis
190  call assert_fails('diffget', 'E100:')
191  new
192  let l[10] = 'one'
193  let l[20] = 'two'
194  let l[30] = 'three'
195  let l[40] = 'four'
196  call setline(1, l)
197  diffthis
198  call assert_equal('one', getline(11))
199  11diffget
200  call assert_equal('10', getline(11))
201  21diffput
202  wincmd w
203  call assert_equal('two', getline(21))
204  normal 31Gdo
205  call assert_equal('three', getline(31))
206  call assert_equal('40', getline(41))
207  normal 41Gdp
208  wincmd w
209  call assert_equal('40', getline(41))
210  new
211  diffthis
212  call assert_fails('diffget', 'E101:')
213
214  windo diffoff
215  %bwipe!
216endfunc
217
218func Test_dp_do_buffer()
219  e! one
220  let bn1=bufnr('%')
221  let l = range(60)
222  call setline(1, l)
223  diffthis
224
225  new two
226  let l[10] = 'one'
227  let l[20] = 'two'
228  let l[30] = 'three'
229  let l[40] = 'four'
230  let l[50] = 'five'
231  call setline(1, l)
232  diffthis
233
234  " dp and do with invalid buffer number.
235  11
236  call assert_fails('norm 99999dp', 'E102:')
237  call assert_fails('norm 99999do', 'E102:')
238  call assert_fails('diffput non_existing_buffer', 'E94:')
239  call assert_fails('diffget non_existing_buffer', 'E94:')
240
241  " dp and do with valid buffer number.
242  call assert_equal('one', getline('.'))
243  exe 'norm ' . bn1 . 'do'
244  call assert_equal('10', getline('.'))
245  21
246  call assert_equal('two', getline('.'))
247  diffget one
248  call assert_equal('20', getline('.'))
249
250  31
251  exe 'norm ' . bn1 . 'dp'
252  41
253  diffput one
254  wincmd w
255  31
256  call assert_equal('three', getline('.'))
257  41
258  call assert_equal('four', getline('.'))
259
260  " dp and do with buffer number which is not in diff mode.
261  new not_in_diff_mode
262  let bn3=bufnr('%')
263  wincmd w
264  51
265  call assert_fails('exe "norm" . bn3 . "dp"', 'E103:')
266  call assert_fails('exe "norm" . bn3 . "do"', 'E103:')
267  call assert_fails('diffput not_in_diff_mode', 'E94:')
268  call assert_fails('diffget not_in_diff_mode', 'E94:')
269
270  windo diffoff
271  %bwipe!
272endfunc
273
274func Test_diffoff()
275  enew!
276  call setline(1, ['Two', 'Three'])
277  redraw
278  let normattr = screenattr(1, 1)
279  diffthis
280  botright vert new
281  call setline(1, ['One', '', 'Two', 'Three'])
282  diffthis
283  redraw
284  call assert_notequal(normattr, screenattr(1, 1))
285  diffoff!
286  redraw
287  call assert_equal(normattr, screenattr(1, 1))
288  bwipe!
289  bwipe!
290endfunc
291
292func Common_icase_test()
293  edit one
294  call setline(1, ['One', 'Two', 'Three', 'Four', 'Fi#ve'])
295  redraw
296  let normattr = screenattr(1, 1)
297  diffthis
298
299  botright vert new two
300  call setline(1, ['one', 'TWO', 'Three ', 'Four', 'fI=VE'])
301  diffthis
302
303  redraw
304  call assert_equal(normattr, screenattr(1, 1))
305  call assert_equal(normattr, screenattr(2, 1))
306  call assert_notequal(normattr, screenattr(3, 1))
307  call assert_equal(normattr, screenattr(4, 1))
308
309  let dtextattr = screenattr(5, 3)
310  call assert_notequal(dtextattr, screenattr(5, 1))
311  call assert_notequal(dtextattr, screenattr(5, 5))
312
313  diffoff!
314  %bwipe!
315endfunc
316
317func Test_diffopt_icase()
318  set diffopt=icase,foldcolumn:0
319  call Common_icase_test()
320  set diffopt&
321endfunc
322
323func Test_diffopt_icase_internal()
324  set diffopt=icase,foldcolumn:0,internal
325  call Common_icase_test()
326  set diffopt&
327endfunc
328
329func Common_iwhite_test()
330  edit one
331  " Difference in trailing spaces and amount of spaces should be ignored,
332  " but not other space differences.
333  call setline(1, ["One \t", 'Two', 'Three', 'one two', 'one two', 'Four'])
334  redraw
335  let normattr = screenattr(1, 1)
336  diffthis
337
338  botright vert new two
339  call setline(1, ["One\t ", "Two\t ", 'Three', 'one   two', 'onetwo', ' Four'])
340  diffthis
341
342  redraw
343  call assert_equal(normattr, screenattr(1, 1))
344  call assert_equal(normattr, screenattr(2, 1))
345  call assert_equal(normattr, screenattr(3, 1))
346  call assert_equal(normattr, screenattr(4, 1))
347  call assert_notequal(normattr, screenattr(5, 1))
348  call assert_notequal(normattr, screenattr(6, 1))
349
350  diffoff!
351  %bwipe!
352endfunc
353
354func Test_diffopt_iwhite()
355  set diffopt=iwhite,foldcolumn:0
356  call Common_iwhite_test()
357  set diffopt&
358endfunc
359
360func Test_diffopt_iwhite_internal()
361  set diffopt=internal,iwhite,foldcolumn:0
362  call Common_iwhite_test()
363  set diffopt&
364endfunc
365
366func Test_diffopt_context()
367  enew!
368  call setline(1, ['1', '2', '3', '4', '5', '6', '7'])
369  diffthis
370  new
371  call setline(1, ['1', '2', '3', '4', '5x', '6', '7'])
372  diffthis
373
374  set diffopt=context:2
375  call assert_equal('+--  2 lines: 1', foldtextresult(1))
376  set diffopt=internal,context:2
377  call assert_equal('+--  2 lines: 1', foldtextresult(1))
378
379  set diffopt=context:1
380  call assert_equal('+--  3 lines: 1', foldtextresult(1))
381  set diffopt=internal,context:1
382  call assert_equal('+--  3 lines: 1', foldtextresult(1))
383
384  diffoff!
385  %bwipe!
386  set diffopt&
387endfunc
388
389func Test_diffopt_horizontal()
390  set diffopt=internal,horizontal
391  diffsplit
392
393  call assert_equal(&columns, winwidth(1))
394  call assert_equal(&columns, winwidth(2))
395  call assert_equal(&lines, winheight(1) + winheight(2) + 3)
396  call assert_inrange(0, 1, winheight(1) - winheight(2))
397
398  set diffopt&
399  diffoff!
400  %bwipe
401endfunc
402
403func Test_diffopt_vertical()
404  set diffopt=internal,vertical
405  diffsplit
406
407  call assert_equal(&lines - 2, winheight(1))
408  call assert_equal(&lines - 2, winheight(2))
409  call assert_equal(&columns, winwidth(1) + winwidth(2) + 1)
410  call assert_inrange(0, 1, winwidth(1) - winwidth(2))
411
412  set diffopt&
413  diffoff!
414  %bwipe
415endfunc
416
417func Test_diffopt_hiddenoff()
418  set diffopt=internal,filler,foldcolumn:0,hiddenoff
419  e! one
420  call setline(1, ['Two', 'Three'])
421  redraw
422  let normattr = screenattr(1, 1)
423  diffthis
424  botright vert new two
425  call setline(1, ['One', 'Four'])
426  diffthis
427  redraw
428  call assert_notequal(normattr, screenattr(1, 1))
429  set hidden
430  close
431  redraw
432  " should not diffing with hidden buffer two while 'hiddenoff' is enabled
433  call assert_equal(normattr, screenattr(1, 1))
434
435  bwipe!
436  bwipe!
437  set hidden& diffopt&
438endfunc
439
440func Test_diffoff_hidden()
441  set diffopt=internal,filler,foldcolumn:0
442  e! one
443  call setline(1, ['Two', 'Three'])
444  redraw
445  let normattr = screenattr(1, 1)
446  diffthis
447  botright vert new two
448  call setline(1, ['One', 'Four'])
449  diffthis
450  redraw
451  call assert_notequal(normattr, screenattr(1, 1))
452  set hidden
453  close
454  redraw
455  " diffing with hidden buffer two
456  call assert_notequal(normattr, screenattr(1, 1))
457  diffoff
458  redraw
459  call assert_equal(normattr, screenattr(1, 1))
460  diffthis
461  redraw
462  " still diffing with hidden buffer two
463  call assert_notequal(normattr, screenattr(1, 1))
464  diffoff!
465  redraw
466  call assert_equal(normattr, screenattr(1, 1))
467  diffthis
468  redraw
469  " no longer diffing with hidden buffer two
470  call assert_equal(normattr, screenattr(1, 1))
471
472  bwipe!
473  bwipe!
474  set hidden& diffopt&
475endfunc
476
477func Test_setting_cursor()
478  new Xtest1
479  put =range(1,90)
480  wq
481  new Xtest2
482  put =range(1,100)
483  wq
484
485  tabe Xtest2
486  $
487  diffsp Xtest1
488  tabclose
489
490  call delete('Xtest1')
491  call delete('Xtest2')
492endfunc
493
494func Test_diff_move_to()
495  new
496  call setline(1, [1, 2, 3, 4, 5, 6, 7, 8, 9, 10])
497  diffthis
498  vnew
499  call setline(1, [1, '2x', 3, 4, 4, 5, '6x', 7, '8x', 9, '10x'])
500  diffthis
501  norm ]c
502  call assert_equal(2, line('.'))
503  norm 3]c
504  call assert_equal(9, line('.'))
505  norm 10]c
506  call assert_equal(11, line('.'))
507  norm [c
508  call assert_equal(9, line('.'))
509  norm 2[c
510  call assert_equal(5, line('.'))
511  norm 10[c
512  call assert_equal(2, line('.'))
513  %bwipe!
514endfunc
515
516func Test_diffexpr()
517  if !executable('diff')
518    return
519  endif
520
521  func DiffExpr()
522    " Prepent some text to check diff type detection
523    call writefile(['warning', '  message'], v:fname_out)
524    silent exe '!diff ' . v:fname_in . ' ' . v:fname_new . '>>' . v:fname_out
525  endfunc
526  set diffexpr=DiffExpr()
527  set diffopt=foldcolumn:0
528
529  enew!
530  call setline(1, ['one', 'two', 'three'])
531  redraw
532  let normattr = screenattr(1, 1)
533  diffthis
534
535  botright vert new
536  call setline(1, ['one', 'two', 'three.'])
537  diffthis
538
539  redraw
540  call assert_equal(normattr, screenattr(1, 1))
541  call assert_equal(normattr, screenattr(2, 1))
542  call assert_notequal(normattr, screenattr(3, 1))
543
544  diffoff!
545  %bwipe!
546  set diffexpr& diffopt&
547endfunc
548
549func Test_diffpatch()
550  " The patch program on MS-Windows may fail or hang.
551  if !executable('patch') || !has('unix')
552    return
553  endif
554  new
555  insert
556***************
557*** 1,3 ****
558  1
559! 2
560  3
561--- 1,4 ----
562  1
563! 2x
564  3
565+ 4
566.
567  saveas! Xpatch
568  bwipe!
569  new
570  call assert_fails('diffpatch Xpatch', 'E816:')
571
572  for name in ['Xpatch', 'Xpatch$HOME', 'Xpa''tch']
573    call setline(1, ['1', '2', '3'])
574    if name != 'Xpatch'
575      call rename('Xpatch', name)
576    endif
577    exe 'diffpatch ' . escape(name, '$')
578    call assert_equal(['1', '2x', '3', '4'], getline(1, '$'))
579    if name != 'Xpatch'
580      call rename(name, 'Xpatch')
581    endif
582    bwipe!
583  endfor
584
585  call delete('Xpatch')
586  bwipe!
587endfunc
588
589func Test_diff_too_many_buffers()
590  for i in range(1, 8)
591    exe "new Xtest" . i
592    diffthis
593  endfor
594  new Xtest9
595  call assert_fails('diffthis', 'E96:')
596  %bwipe!
597endfunc
598
599func Test_diff_nomodifiable()
600  new
601  call setline(1, [1, 2, 3, 4])
602  setl nomodifiable
603  diffthis
604  vnew
605  call setline(1, ['1x', 2, 3, 3, 4])
606  diffthis
607  call assert_fails('norm dp', 'E793:')
608  setl nomodifiable
609  call assert_fails('norm do', 'E21:')
610  %bwipe!
611endfunc
612
613func Test_diff_hlID()
614  new
615  call setline(1, [1, 2, 3])
616  diffthis
617  vnew
618  call setline(1, ['1x', 2, 'x', 3])
619  diffthis
620  redraw
621
622  call assert_equal(synIDattr(diff_hlID(-1, 1), "name"), "")
623
624  call assert_equal(synIDattr(diff_hlID(1, 1), "name"), "DiffChange")
625  call assert_equal(synIDattr(diff_hlID(1, 2), "name"), "DiffText")
626  call assert_equal(synIDattr(diff_hlID(2, 1), "name"), "")
627  call assert_equal(synIDattr(diff_hlID(3, 1), "name"), "DiffAdd")
628  call assert_equal(synIDattr(diff_hlID(4, 1), "name"), "")
629
630  wincmd w
631  call assert_equal(synIDattr(diff_hlID(1, 1), "name"), "DiffChange")
632  call assert_equal(synIDattr(diff_hlID(2, 1), "name"), "")
633  call assert_equal(synIDattr(diff_hlID(3, 1), "name"), "")
634
635  %bwipe!
636endfunc
637
638func Test_diff_filler()
639  new
640  call setline(1, [1, 2, 3, 'x', 4])
641  diffthis
642  vnew
643  call setline(1, [1, 2, 'y', 'y', 3, 4])
644  diffthis
645  redraw
646
647  call assert_equal([0, 0, 0, 0, 0, 0, 0, 1, 0], map(range(-1, 7), 'diff_filler(v:val)'))
648  wincmd w
649  call assert_equal([0, 0, 0, 0, 2, 0, 0, 0], map(range(-1, 6), 'diff_filler(v:val)'))
650
651  %bwipe!
652endfunc
653
654func Test_diff_lastline()
655  enew!
656  only!
657  call setline(1, ['This is a ', 'line with five ', 'rows'])
658  diffthis
659  botright vert new
660  call setline(1, ['This is', 'a line with ', 'four rows'])
661  diffthis
662  1
663  call feedkeys("Je a\<CR>", 'tx')
664  call feedkeys("Je a\<CR>", 'tx')
665  let w1lines = winline()
666  wincmd w
667  $
668  let w2lines = winline()
669  call assert_equal(w2lines, w1lines)
670  bwipe!
671  bwipe!
672endfunc
673
674func WriteDiffFiles(list1, list2)
675  call writefile(a:list1, 'Xfile1')
676  call writefile(a:list2, 'Xfile2')
677endfunc
678
679" Verify a screendump with both the external and external diff.
680func VerifyBoth(buf, dumpfile, extra)
681  call term_sendkeys(a:buf, ":diffupdate!\<cr>")
682  " trailing : for leaving the cursor on the command line
683  for cmd in [":set diffopt=filler" . a:extra . "\<cr>:", ":set diffopt+=internal\<cr>:"]
684    call term_sendkeys(a:buf, cmd)
685    if VerifyScreenDump(a:buf, a:dumpfile, {}, cmd =~ 'internal' ? 'internal' : 'external')
686      break " don't let the next iteration overwrite the "failed" file.
687    endif
688  endfor
689endfunc
690
691func Test_diff_screen()
692  if !CanRunVimInTerminal() || !has('menu')
693    return
694  endif
695  " clean up already existing swap files, just in case
696  call delete('.Xfile1.swp')
697  call delete('.Xfile2.swp')
698
699  " Test 1: Add a line in beginning of file 2
700  call WriteDiffFiles([1, 2, 3, 4, 5, 6, 7, 8, 9, 10], [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10])
701  let buf = RunVimInTerminal('-d Xfile1 Xfile2', {})
702  " Set autoread mode, ,so that Vim won't complain once we re-write the test
703  " files
704  call term_sendkeys(buf, ":set autoread\<cr>\<c-w>w:set autoread\<cr>\<c-w>w")
705
706  call VerifyBoth(buf, 'Test_diff_01', '')
707
708  " Test 2: Add a line in beginning of file 1
709  call WriteDiffFiles([0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10], [1, 2, 3, 4, 5, 6, 7, 8, 9, 10])
710  call VerifyBoth(buf, 'Test_diff_02', '')
711
712  " Test 3: Add a line at the end of file 2
713  call WriteDiffFiles([1, 2, 3, 4, 5, 6, 7, 8, 9, 10], [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11])
714  call VerifyBoth(buf, 'Test_diff_03', '')
715
716  " Test 4: Add a line at the end of file 1
717  call WriteDiffFiles([1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11], [1, 2, 3, 4, 5, 6, 7, 8, 9, 10])
718  call VerifyBoth(buf, 'Test_diff_04', '')
719
720  " Test 5: Add a line in the middle of file 2, remove on at the end of file 1
721  call WriteDiffFiles([1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11], [1, 2, 3, 4, 4, 5, 6, 7, 8, 9, 10])
722  call VerifyBoth(buf, 'Test_diff_05', '')
723
724  " Test 6: Add a line in the middle of file 1, remove on at the end of file 2
725  call WriteDiffFiles([1, 2, 3, 4, 4, 5, 6, 7, 8, 9, 10], [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11])
726  call VerifyBoth(buf, 'Test_diff_06', '')
727
728  " Test 7 - 9: Test normal/patience/histogram diff algorithm
729  call WriteDiffFiles(['#include <stdio.h>', '', '// Frobs foo heartily', 'int frobnitz(int foo)', '{',
730      \ '    int i;', '    for(i = 0; i < 10; i++)', '    {', '        printf("Your answer is: ");',
731      \ '        printf("%d\n", foo);', '    }', '}', '', 'int fact(int n)', '{', '    if(n > 1)', '    {',
732      \ '        return fact(n-1) * n;', '    }', '    return 1;', '}', '', 'int main(int argc, char **argv)',
733      \ '{', '    frobnitz(fact(10));', '}'],
734      \ ['#include <stdio.h>', '', 'int fib(int n)', '{', '    if(n > 2)', '    {',
735      \ '        return fib(n-1) + fib(n-2);', '    }', '    return 1;', '}', '', '// Frobs foo heartily',
736      \ 'int frobnitz(int foo)', '{', '    int i;', '    for(i = 0; i < 10; i++)', '    {',
737      \ '        printf("%d\n", foo);', '    }', '}', '',
738      \ 'int main(int argc, char **argv)', '{', '    frobnitz(fib(10));', '}'])
739  call term_sendkeys(buf, ":diffupdate!\<cr>")
740  call term_sendkeys(buf, ":set diffopt+=internal\<cr>")
741  call VerifyScreenDump(buf, 'Test_diff_07', {})
742
743  call term_sendkeys(buf, ":set diffopt+=algorithm:patience\<cr>")
744  call VerifyScreenDump(buf, 'Test_diff_08', {})
745
746  call term_sendkeys(buf, ":set diffopt+=algorithm:histogram\<cr>")
747  call VerifyScreenDump(buf, 'Test_diff_09', {})
748
749  " Test 10-11: normal/indent-heuristic
750  call term_sendkeys(buf, ":set diffopt&vim\<cr>")
751  call WriteDiffFiles(['', '  def finalize(values)', '', '    values.each do |v|', '      v.finalize', '    end'],
752      \ ['', '  def finalize(values)', '', '    values.each do |v|', '      v.prepare', '    end', '',
753      \ '    values.each do |v|', '      v.finalize', '    end'])
754  call term_sendkeys(buf, ":diffupdate!\<cr>")
755  call term_sendkeys(buf, ":set diffopt+=internal\<cr>")
756  call VerifyScreenDump(buf, 'Test_diff_10', {})
757
758  call term_sendkeys(buf, ":set diffopt+=indent-heuristic\<cr>")
759  call VerifyScreenDump(buf, 'Test_diff_11', {})
760
761  " Test 12: diff the same file
762  call WriteDiffFiles([1, 2, 3, 4, 5, 6, 7, 8, 9, 10], [1, 2, 3, 4, 5, 6, 7, 8, 9, 10])
763  call VerifyBoth(buf, 'Test_diff_12', '')
764
765  " Test 13: diff an empty file
766  call WriteDiffFiles([], [])
767  call VerifyBoth(buf, 'Test_diff_13', '')
768
769  " Test 14: test diffopt+=icase
770  call WriteDiffFiles(['a', 'b', 'cd'], ['A', 'b', 'cDe'])
771  call VerifyBoth(buf, 'Test_diff_14', " diffopt+=filler diffopt+=icase")
772
773  " Test 15-16: test diffopt+=iwhite
774  call WriteDiffFiles(['int main()', '{', '   printf("Hello, World!");', '   return 0;', '}'],
775      \ ['int main()', '{', '   if (0)', '   {', '      printf("Hello, World!");', '      return 0;', '   }', '}'])
776  call term_sendkeys(buf, ":diffupdate!\<cr>")
777  call term_sendkeys(buf, ":set diffopt&vim diffopt+=filler diffopt+=iwhite\<cr>")
778  call VerifyScreenDump(buf, 'Test_diff_15', {})
779  call term_sendkeys(buf, ":set diffopt+=internal\<cr>")
780  call VerifyScreenDump(buf, 'Test_diff_16', {})
781
782  " clean up
783  call StopVimInTerminal(buf)
784  call delete('Xfile1')
785  call delete('Xfile2')
786endfunc
787
788