robin/laufey

git clone https://git.robinwobin.dev/robin/laufey

Justin M. KeyesMerge #40865 from justinmk/fixcif907614088

master
154.2 KiB3430 linesraw
1local t = require('test.testutil')
2local n = require('test.functional.testnvim')()
3local Screen = require('test.functional.ui.screen')
4
5local describe, it, before_each, after_each, setup, teardown, finally =
6  t.describe, t.it, t.before_each, t.after_each, t.setup, t.teardown, t.finally
7local feed = n.feed
8local clear = n.clear
9local command = n.command
10local insert = n.insert
11local write_file = t.write_file
12local dedent = t.dedent
13local exec = n.exec
14local eq = t.eq
15local api = n.api
16
17local function WriteDiffFiles(text1, text2)
18  write_file('Xdifile1', text1)
19  write_file('Xdifile2', text2)
20  command('checktime')
21end
22
23local function WriteDiffFiles3(text1, text2, text3)
24  write_file('Xdifile1', text1)
25  write_file('Xdifile2', text2)
26  write_file('Xdifile3', text3)
27  command('checktime')
28end
29
30before_each(clear)
31
32describe('Diff mode screen', function()
33  local fname = 'Xtest-functional-diff-screen-1'
34  local fname_2 = fname .. '.2'
35  local screen
36
37  local reread = function()
38    feed(':e<cr><c-w>w:e<cr><c-w>w')
39  end
40
41  setup(function()
42    os.remove(fname)
43    os.remove(fname_2)
44  end)
45
46  teardown(function()
47    os.remove(fname)
48    os.remove(fname_2)
49  end)
50
51  before_each(function()
52    feed(':e ' .. fname_2 .. '<cr>')
53    feed(':vnew ' .. fname .. '<cr>')
54    feed(':diffthis<cr>')
55    feed('<c-w>w:diffthis<cr><c-w>w')
56
57    screen = Screen.new(40, 16)
58  end)
59
60  it('Add a line in beginning of file 2', function()
61    write_file(fname, '1\n2\n3\n4\n5\n6\n7\n8\n9\n10\n', false)
62    write_file(fname_2, '0\n1\n2\n3\n4\n5\n6\n7\n8\n9\n10\n', false)
63    reread()
64
65    feed(':set diffopt=filler<cr>')
66    screen:expect([[
67      {7:  }{23:------------------}│{7:  }{22:0                }|
68      {7:  }^1                 │{7:  }1                |
69      {7:  }2                 │{7:  }2                |
70      {7:  }3                 │{7:  }3                |
71      {7:  }4                 │{7:  }4                |
72      {7:  }5                 │{7:  }5                |
73      {7:  }6                 │{7:  }6                |
74      {7:+ }{13:+--  4 lines: 7···}│{7:+ }{13:+--  4 lines: 7··}|
75      {1:~                   }│{1:~                  }|*6
76      {3:<onal-diff-screen-1  }{2:<l-diff-screen-1.2 }|
77      :set diffopt=filler                     |
78    ]])
79
80    feed(':set diffopt+=internal<cr>')
81    screen:expect([[
82      {7:  }{23:------------------}│{7:  }{22:0                }|
83      {7:  }^1                 │{7:  }1                |
84      {7:  }2                 │{7:  }2                |
85      {7:  }3                 │{7:  }3                |
86      {7:  }4                 │{7:  }4                |
87      {7:  }5                 │{7:  }5                |
88      {7:  }6                 │{7:  }6                |
89      {7:+ }{13:+--  4 lines: 7···}│{7:+ }{13:+--  4 lines: 7··}|
90      {1:~                   }│{1:~                  }|*6
91      {3:<onal-diff-screen-1  }{2:<l-diff-screen-1.2 }|
92      :set diffopt+=internal                  |
93    ]])
94  end)
95
96  it('Add a line in beginning of file 1', function()
97    write_file(fname, '0\n1\n2\n3\n4\n5\n6\n7\n8\n9\n10\n', false)
98    write_file(fname_2, '1\n2\n3\n4\n5\n6\n7\n8\n9\n10\n', false)
99    reread()
100
101    feed(':set diffopt=filler<cr>')
102    screen:expect([[
103      {7:  }{22:^0                 }│{7:  }{23:-----------------}|
104      {7:  }1                 │{7:  }1                |
105      {7:  }2                 │{7:  }2                |
106      {7:  }3                 │{7:  }3                |
107      {7:  }4                 │{7:  }4                |
108      {7:  }5                 │{7:  }5                |
109      {7:  }6                 │{7:  }6                |
110      {7:+ }{13:+--  4 lines: 7···}│{7:+ }{13:+--  4 lines: 7··}|
111      {1:~                   }│{1:~                  }|*6
112      {3:<onal-diff-screen-1  }{2:<l-diff-screen-1.2 }|
113      :set diffopt=filler                     |
114    ]])
115
116    feed(':set diffopt+=internal<cr>')
117    screen:expect([[
118      {7:  }{22:^0                 }│{7:  }{23:-----------------}|
119      {7:  }1                 │{7:  }1                |
120      {7:  }2                 │{7:  }2                |
121      {7:  }3                 │{7:  }3                |
122      {7:  }4                 │{7:  }4                |
123      {7:  }5                 │{7:  }5                |
124      {7:  }6                 │{7:  }6                |
125      {7:+ }{13:+--  4 lines: 7···}│{7:+ }{13:+--  4 lines: 7··}|
126      {1:~                   }│{1:~                  }|*6
127      {3:<onal-diff-screen-1  }{2:<l-diff-screen-1.2 }|
128      :set diffopt+=internal                  |
129    ]])
130  end)
131
132  it('Add a line at the end of file 2', function()
133    write_file(fname, '1\n2\n3\n4\n5\n6\n7\n8\n9\n10\n', false)
134    write_file(fname_2, '1\n2\n3\n4\n5\n6\n7\n8\n9\n10\n11\n', false)
135    reread()
136
137    feed(':set diffopt=filler<cr>')
138    screen:expect([[
139      {7:+ }{13:^+--  4 lines: 1···}│{7:+ }{13:+--  4 lines: 1··}|
140      {7:  }5                 │{7:  }5                |
141      {7:  }6                 │{7:  }6                |
142      {7:  }7                 │{7:  }7                |
143      {7:  }8                 │{7:  }8                |
144      {7:  }9                 │{7:  }9                |
145      {7:  }10                │{7:  }10               |
146      {7:  }{23:------------------}│{7:  }{22:11               }|
147      {1:~                   }│{1:~                  }|*6
148      {3:<onal-diff-screen-1  }{2:<l-diff-screen-1.2 }|
149      :set diffopt=filler                     |
150    ]])
151
152    feed(':set diffopt+=internal<cr>')
153    screen:expect([[
154      {7:+ }{13:^+--  4 lines: 1···}│{7:+ }{13:+--  4 lines: 1··}|
155      {7:  }5                 │{7:  }5                |
156      {7:  }6                 │{7:  }6                |
157      {7:  }7                 │{7:  }7                |
158      {7:  }8                 │{7:  }8                |
159      {7:  }9                 │{7:  }9                |
160      {7:  }10                │{7:  }10               |
161      {7:  }{23:------------------}│{7:  }{22:11               }|
162      {1:~                   }│{1:~                  }|*6
163      {3:<onal-diff-screen-1  }{2:<l-diff-screen-1.2 }|
164      :set diffopt+=internal                  |
165    ]])
166
167    screen:try_resize(40, 9)
168    screen:expect([[
169      {7:+ }{13:^+--  4 lines: 1···}│{7:+ }{13:+--  4 lines: 1··}|
170      {7:  }5                 │{7:  }5                |
171      {7:  }6                 │{7:  }6                |
172      {7:  }7                 │{7:  }7                |
173      {7:  }8                 │{7:  }8                |
174      {7:  }9                 │{7:  }9                |
175      {7:  }10                │{7:  }10               |
176      {3:<onal-diff-screen-1  }{2:<l-diff-screen-1.2 }|
177                                              |
178    ]])
179  end)
180
181  it('Add a line at the end of file 1', function()
182    write_file(fname, '1\n2\n3\n4\n5\n6\n7\n8\n9\n10\n11\n', false)
183    write_file(fname_2, '1\n2\n3\n4\n5\n6\n7\n8\n9\n10\n', false)
184    reread()
185
186    feed(':set diffopt=filler<cr>')
187    screen:expect([[
188      {7:+ }{13:^+--  4 lines: 1···}│{7:+ }{13:+--  4 lines: 1··}|
189      {7:  }5                 │{7:  }5                |
190      {7:  }6                 │{7:  }6                |
191      {7:  }7                 │{7:  }7                |
192      {7:  }8                 │{7:  }8                |
193      {7:  }9                 │{7:  }9                |
194      {7:  }10                │{7:  }10               |
195      {7:  }{22:11                }│{7:  }{23:-----------------}|
196      {1:~                   }│{1:~                  }|*6
197      {3:<onal-diff-screen-1  }{2:<l-diff-screen-1.2 }|
198      :set diffopt=filler                     |
199    ]])
200
201    feed(':set diffopt+=internal<cr>')
202    screen:expect([[
203      {7:+ }{13:^+--  4 lines: 1···}│{7:+ }{13:+--  4 lines: 1··}|
204      {7:  }5                 │{7:  }5                |
205      {7:  }6                 │{7:  }6                |
206      {7:  }7                 │{7:  }7                |
207      {7:  }8                 │{7:  }8                |
208      {7:  }9                 │{7:  }9                |
209      {7:  }10                │{7:  }10               |
210      {7:  }{22:11                }│{7:  }{23:-----------------}|
211      {1:~                   }│{1:~                  }|*6
212      {3:<onal-diff-screen-1  }{2:<l-diff-screen-1.2 }|
213      :set diffopt+=internal                  |
214    ]])
215
216    screen:try_resize(40, 9)
217    screen:expect([[
218      {7:+ }{13:^+--  4 lines: 1···}│{7:+ }{13:+--  4 lines: 1··}|
219      {7:  }5                 │{7:  }5                |
220      {7:  }6                 │{7:  }6                |
221      {7:  }7                 │{7:  }7                |
222      {7:  }8                 │{7:  }8                |
223      {7:  }9                 │{7:  }9                |
224      {7:  }10                │{7:  }10               |
225      {3:<onal-diff-screen-1  }{2:<l-diff-screen-1.2 }|
226                                              |
227    ]])
228  end)
229
230  it('Add a line in the middle of file 2, remove on at the end of file 1', function()
231    write_file(fname, '1\n2\n3\n4\n5\n6\n7\n8\n9\n10\n11\n', false)
232    write_file(fname_2, '1\n2\n3\n4\n4\n5\n6\n7\n8\n9\n10\n', false)
233    reread()
234
235    feed(':set diffopt=filler<cr>')
236    screen:expect([[
237      {7:  }^1                 │{7:  }1                |
238      {7:  }2                 │{7:  }2                |
239      {7:  }3                 │{7:  }3                |
240      {7:  }4                 │{7:  }4                |
241      {7:  }{23:------------------}│{7:  }{22:4                }|
242      {7:  }5                 │{7:  }5                |
243      {7:  }6                 │{7:  }6                |
244      {7:  }7                 │{7:  }7                |
245      {7:  }8                 │{7:  }8                |
246      {7:  }9                 │{7:  }9                |
247      {7:  }10                │{7:  }10               |
248      {7:  }{22:11                }│{7:  }{23:-----------------}|
249      {1:~                   }│{1:~                  }|*2
250      {3:<onal-diff-screen-1  }{2:<l-diff-screen-1.2 }|
251      :set diffopt=filler                     |
252    ]])
253
254    feed(':set diffopt+=internal<cr>')
255    screen:expect([[
256      {7:  }^1                 │{7:  }1                |
257      {7:  }2                 │{7:  }2                |
258      {7:  }3                 │{7:  }3                |
259      {7:  }4                 │{7:  }4                |
260      {7:  }{23:------------------}│{7:  }{22:4                }|
261      {7:  }5                 │{7:  }5                |
262      {7:  }6                 │{7:  }6                |
263      {7:  }7                 │{7:  }7                |
264      {7:  }8                 │{7:  }8                |
265      {7:  }9                 │{7:  }9                |
266      {7:  }10                │{7:  }10               |
267      {7:  }{22:11                }│{7:  }{23:-----------------}|
268      {1:~                   }│{1:~                  }|*2
269      {3:<onal-diff-screen-1  }{2:<l-diff-screen-1.2 }|
270      :set diffopt+=internal                  |
271    ]])
272  end)
273
274  it('Add a line in the middle of file 1, remove on at the end of file 2', function()
275    write_file(fname, '1\n2\n3\n4\n4\n5\n6\n7\n8\n9\n10\n', false)
276    write_file(fname_2, '1\n2\n3\n4\n5\n6\n7\n8\n9\n10\n11\n', false)
277    reread()
278
279    feed(':set diffopt=filler<cr>')
280    screen:expect([[
281      {7:  }^1                 │{7:  }1                |
282      {7:  }2                 │{7:  }2                |
283      {7:  }3                 │{7:  }3                |
284      {7:  }4                 │{7:  }4                |
285      {7:  }{22:4                 }│{7:  }{23:-----------------}|
286      {7:  }5                 │{7:  }5                |
287      {7:  }6                 │{7:  }6                |
288      {7:  }7                 │{7:  }7                |
289      {7:  }8                 │{7:  }8                |
290      {7:  }9                 │{7:  }9                |
291      {7:  }10                │{7:  }10               |
292      {7:  }{23:------------------}│{7:  }{22:11               }|
293      {1:~                   }│{1:~                  }|*2
294      {3:<onal-diff-screen-1  }{2:<l-diff-screen-1.2 }|
295      :set diffopt=filler                     |
296    ]])
297
298    feed(':set diffopt+=internal<cr>')
299    screen:expect([[
300      {7:  }^1                 │{7:  }1                |
301      {7:  }2                 │{7:  }2                |
302      {7:  }3                 │{7:  }3                |
303      {7:  }4                 │{7:  }4                |
304      {7:  }{22:4                 }│{7:  }{23:-----------------}|
305      {7:  }5                 │{7:  }5                |
306      {7:  }6                 │{7:  }6                |
307      {7:  }7                 │{7:  }7                |
308      {7:  }8                 │{7:  }8                |
309      {7:  }9                 │{7:  }9                |
310      {7:  }10                │{7:  }10               |
311      {7:  }{23:------------------}│{7:  }{22:11               }|
312      {1:~                   }│{1:~                  }|*2
313      {3:<onal-diff-screen-1  }{2:<l-diff-screen-1.2 }|
314      :set diffopt+=internal                  |
315    ]])
316  end)
317
318  describe('normal/patience/histogram diff algorithm', function()
319    setup(function()
320      local f1 = [[#include <stdio.h>
321
322// Frobs foo heartily
323int frobnitz(int foo)
324{
325    int i;
326    for(i = 0; i < 10; i++)
327    {
328        printf("Your answer is: ");
329        printf("%d\n", foo);
330    }
331}
332
333int fact(int n)
334{
335    if(n > 1)
336    {
337        return fact(n-1) * n;
338    }
339    return 1;
340}
341
342int main(int argc, char **argv)
343{
344    frobnitz(fact(10));
345}]]
346      write_file(fname, f1, false)
347      local f2 = [[#include <stdio.h>
348
349int fib(int n)
350{
351    if(n > 2)
352    {
353        return fib(n-1) + fib(n-2);
354    }
355    return 1;
356}
357
358// Frobs foo heartily
359int frobnitz(int foo)
360{
361    int i;
362    for(i = 0; i < 10; i++)
363    {
364        printf("%d\n", foo);
365    }
366}
367
368int main(int argc, char **argv)
369{
370    frobnitz(fib(10));
371}]]
372      write_file(fname_2, f2, false)
373    end)
374
375    it('diffopt=+algorithm:myers', function()
376      reread()
377      feed(':set diffopt=internal,filler<cr>')
378      screen:expect([[
379        {7:  }^#include <stdio.h>│{7:  }#include <stdio.h|
380        {7:  }                  │{7:  }                 |
381        {7:  }{27:// Frobs foo heart}│{7:  }{27:int fib(int n)}{4:   }|
382        {7:  }{22:int frobnitz(int f}│{7:  }{23:-----------------}|
383        {7:  }{                 │{7:  }{                |
384        {7:  }{4:    i}{27:nt i;}{4:        }│{7:  }{4:    i}{27:f(n > 2)}{4:    }|
385        {7:  }{22:    for(i = 0; i <}│{7:  }{23:-----------------}|
386        {7:  }    {             │{7:  }    {            |
387        {7:  }{4:        }{27:printf("Yo}│{7:  }{4:        }{27:return fi}|
388        {7:  }{22:        printf("%d}│{7:  }{23:-----------------}|
389        {7:  }    }             │{7:  }    }            |
390        {7:  }{23:------------------}│{7:  }{22:    return 1;    }|
391        {7:  }}                 │{7:  }}                |
392        {7:  }                  │{7:  }                 |
393        {3:<onal-diff-screen-1  }{2:<l-diff-screen-1.2 }|
394        :set diffopt=internal,filler            |
395      ]])
396
397      feed('G')
398      screen:expect([[
399        {7:  }{23:------------------}│{7:  }{22:int frobnitz(int }|
400        {7:  }{                 │{7:  }{                |
401        {7:  }{4:    i}{27:f(n > 1)}{4:     }│{7:  }{4:    i}{27:nt i;}{4:       }|
402        {7:  }{23:------------------}│{7:  }{22:    for(i = 0; i }|
403        {7:  }    {             │{7:  }    {            |
404        {7:  }{4:        }{27:return fac}│{7:  }{4:        }{27:printf("%}|
405        {7:  }    }             │{7:  }    }            |
406        {7:  }{22:    return 1;     }│{7:  }{23:-----------------}|
407        {7:  }}                 │{7:  }}                |
408        {7:  }                  │{7:  }                 |
409        {7:  }int main(int argc,│{7:  }int main(int argc|
410        {7:  }{                 │{7:  }{                |
411        {7:  }{4:    frobnitz(f}{27:act}{4:(}│{7:  }{4:    frobnitz(f}{27:ib}{4:(}|
412        {7:  }^}                 │{7:  }}                |
413        {3:<onal-diff-screen-1  }{2:<l-diff-screen-1.2 }|
414        :set diffopt=internal,filler            |
415      ]])
416    end)
417
418    it('diffopt+=algorithm:patience', function()
419      reread()
420      feed(':set diffopt=internal,filler,algorithm:patience<cr>')
421      screen:expect([[
422        {7:  }^#include <stdio.h>│{7:  }#include <stdio.h|
423        {7:  }                  │{7:  }                 |
424        {7:  }{23:------------------}│{7:  }{22:int fib(int n)   }|
425        {7:  }{23:------------------}│{7:  }{22:{                }|
426        {7:  }{23:------------------}│{7:  }{22:    if(n > 2)    }|
427        {7:  }{23:------------------}│{7:  }{22:    {            }|
428        {7:  }{23:------------------}│{7:  }{22:        return fi}|
429        {7:  }{23:------------------}│{7:  }{22:    }            }|
430        {7:  }{23:------------------}│{7:  }{22:    return 1;    }|
431        {7:  }{23:------------------}│{7:  }{22:}                }|
432        {7:  }{23:------------------}│{7:  }{22:                 }|
433        {7:  }// Frobs foo heart│{7:  }// Frobs foo hear|
434        {7:  }int frobnitz(int f│{7:  }int frobnitz(int |
435        {7:  }{                 │{7:  }{                |
436        {3:<onal-diff-screen-1  }{2:<l-diff-screen-1.2 }|
437                                                |
438      ]])
439
440      feed('G')
441      screen:expect([[
442        {7:  }                  │{7:  }                 |
443        {7:  }{22:int fact(int n)   }│{7:  }{23:-----------------}|
444        {7:  }{22:{                 }│{7:  }{23:-----------------}|
445        {7:  }{22:    if(n > 1)     }│{7:  }{23:-----------------}|
446        {7:  }{22:    {             }│{7:  }{23:-----------------}|
447        {7:  }{22:        return fac}│{7:  }{23:-----------------}|
448        {7:  }{22:    }             }│{7:  }{23:-----------------}|
449        {7:  }{22:    return 1;     }│{7:  }{23:-----------------}|
450        {7:  }{22:}                 }│{7:  }{23:-----------------}|
451        {7:  }{22:                  }│{7:  }{23:-----------------}|
452        {7:  }int main(int argc,│{7:  }int main(int argc|
453        {7:  }{                 │{7:  }{                |
454        {7:  }{4:    frobnitz(f}{27:act}{4:(}│{7:  }{4:    frobnitz(f}{27:ib}{4:(}|
455        {7:  }^}                 │{7:  }}                |
456        {3:<onal-diff-screen-1  }{2:<l-diff-screen-1.2 }|
457                                                |
458      ]])
459    end)
460
461    it('diffopt+=algorithm:histogram', function()
462      reread()
463      feed(':set diffopt=internal,filler,algorithm:histogram<cr>')
464      screen:expect([[
465        {7:  }^#include <stdio.h>│{7:  }#include <stdio.h|
466        {7:  }                  │{7:  }                 |
467        {7:  }{23:------------------}│{7:  }{22:int fib(int n)   }|
468        {7:  }{23:------------------}│{7:  }{22:{                }|
469        {7:  }{23:------------------}│{7:  }{22:    if(n > 2)    }|
470        {7:  }{23:------------------}│{7:  }{22:    {            }|
471        {7:  }{23:------------------}│{7:  }{22:        return fi}|
472        {7:  }{23:------------------}│{7:  }{22:    }            }|
473        {7:  }{23:------------------}│{7:  }{22:    return 1;    }|
474        {7:  }{23:------------------}│{7:  }{22:}                }|
475        {7:  }{23:------------------}│{7:  }{22:                 }|
476        {7:  }// Frobs foo heart│{7:  }// Frobs foo hear|
477        {7:  }int frobnitz(int f│{7:  }int frobnitz(int |
478        {7:  }{                 │{7:  }{                |
479        {3:<onal-diff-screen-1  }{2:<l-diff-screen-1.2 }|
480                                                |
481      ]])
482
483      feed('G')
484      screen:expect([[
485        {7:  }                  │{7:  }                 |
486        {7:  }{22:int fact(int n)   }│{7:  }{23:-----------------}|
487        {7:  }{22:{                 }│{7:  }{23:-----------------}|
488        {7:  }{22:    if(n > 1)     }│{7:  }{23:-----------------}|
489        {7:  }{22:    {             }│{7:  }{23:-----------------}|
490        {7:  }{22:        return fac}│{7:  }{23:-----------------}|
491        {7:  }{22:    }             }│{7:  }{23:-----------------}|
492        {7:  }{22:    return 1;     }│{7:  }{23:-----------------}|
493        {7:  }{22:}                 }│{7:  }{23:-----------------}|
494        {7:  }{22:                  }│{7:  }{23:-----------------}|
495        {7:  }int main(int argc,│{7:  }int main(int argc|
496        {7:  }{                 │{7:  }{                |
497        {7:  }{4:    frobnitz(f}{27:act}{4:(}│{7:  }{4:    frobnitz(f}{27:ib}{4:(}|
498        {7:  }^}                 │{7:  }}                |
499        {3:<onal-diff-screen-1  }{2:<l-diff-screen-1.2 }|
500                                                |
501      ]])
502    end)
503  end)
504
505  describe('diffopt+=indent-heuristic', function()
506    setup(function()
507      local f1 = [[
508  def finalize(values)
509
510    values.each do |v|
511      v.finalize
512    end]]
513      write_file(fname, f1, false)
514      local f2 = [[
515  def finalize(values)
516
517    values.each do |v|
518      v.prepare
519    end
520
521    values.each do |v|
522      v.finalize
523    end]]
524      write_file(fname_2, f2, false)
525      feed(':diffupdate!<cr>')
526    end)
527
528    it('internal', function()
529      reread()
530      feed(':set diffopt=internal,filler<cr>')
531      screen:expect([[
532        {7:  }^def finalize(value│{7:  }def finalize(valu|
533        {7:  }                  │{7:  }                 |
534        {7:  }  values.each do |│{7:  }  values.each do |
535        {7:  }{23:------------------}│{7:  }{22:    v.prepare    }|
536        {7:  }{23:------------------}│{7:  }{22:  end            }|
537        {7:  }{23:------------------}│{7:  }{22:                 }|
538        {7:  }{23:------------------}│{7:  }{22:  values.each do }|
539        {7:  }    v.finalize    │{7:  }    v.finalize   |
540        {7:  }  end             │{7:  }  end            |
541        {1:~                   }│{1:~                  }|*5
542        {3:<onal-diff-screen-1  }{2:<l-diff-screen-1.2 }|
543        :set diffopt=internal,filler            |
544      ]])
545    end)
546
547    it('indent-heuristic', function()
548      reread()
549      feed(':set diffopt=internal,filler,indent-heuristic<cr>')
550      screen:expect([[
551        {7:  }^def finalize(value│{7:  }def finalize(valu|
552        {7:  }                  │{7:  }                 |
553        {7:  }{23:------------------}│{7:  }{22:  values.each do }|
554        {7:  }{23:------------------}│{7:  }{22:    v.prepare    }|
555        {7:  }{23:------------------}│{7:  }{22:  end            }|
556        {7:  }{23:------------------}│{7:  }{22:                 }|
557        {7:  }  values.each do |│{7:  }  values.each do |
558        {7:  }    v.finalize    │{7:  }    v.finalize   |
559        {7:  }  end             │{7:  }  end            |
560        {1:~                   }│{1:~                  }|*5
561        {3:<onal-diff-screen-1  }{2:<l-diff-screen-1.2 }|
562                                                |
563      ]])
564    end)
565
566    it('indent-heuristic random order', function()
567      reread()
568      feed(':set diffopt=internal,filler,indent-heuristic,algorithm:patience<cr>')
569      feed(':<cr>')
570      screen:expect([[
571        {7:  }^def finalize(value│{7:  }def finalize(valu|
572        {7:  }                  │{7:  }                 |
573        {7:  }{23:------------------}│{7:  }{22:  values.each do }|
574        {7:  }{23:------------------}│{7:  }{22:    v.prepare    }|
575        {7:  }{23:------------------}│{7:  }{22:  end            }|
576        {7:  }{23:------------------}│{7:  }{22:                 }|
577        {7:  }  values.each do |│{7:  }  values.each do |
578        {7:  }    v.finalize    │{7:  }    v.finalize   |
579        {7:  }  end             │{7:  }  end            |
580        {1:~                   }│{1:~                  }|*5
581        {3:<onal-diff-screen-1  }{2:<l-diff-screen-1.2 }|
582        :                                       |
583      ]])
584    end)
585  end)
586
587  it('Diff the same file', function()
588    write_file(fname, '1\n2\n3\n4\n5\n6\n7\n8\n9\n10\n', false)
589    write_file(fname_2, '1\n2\n3\n4\n5\n6\n7\n8\n9\n10\n', false)
590    reread()
591
592    feed(':set diffopt=filler<cr>')
593    screen:expect([[
594      {7:+ }{13:^+-- 10 lines: 1···}│{7:+ }{13:+-- 10 lines: 1··}|
595      {1:~                   }│{1:~                  }|*13
596      {3:<onal-diff-screen-1  }{2:<l-diff-screen-1.2 }|
597      :set diffopt=filler                     |
598    ]])
599
600    feed(':set diffopt+=internal<cr>')
601    screen:expect([[
602      {7:+ }{13:^+-- 10 lines: 1···}│{7:+ }{13:+-- 10 lines: 1··}|
603      {1:~                   }│{1:~                  }|*13
604      {3:<onal-diff-screen-1  }{2:<l-diff-screen-1.2 }|
605      :set diffopt+=internal                  |
606    ]])
607  end)
608
609  it('Diff an empty file', function()
610    write_file(fname, '', false)
611    write_file(fname_2, '', false)
612    reread()
613
614    feed(':set diffopt=filler<cr>')
615    screen:expect([[
616      {7:- }^                  │{7:- }                 |
617      {1:~                   }│{1:~                  }|*13
618      {3:<onal-diff-screen-1  }{2:<l-diff-screen-1.2 }|
619      :set diffopt=filler                     |
620    ]])
621
622    feed(':set diffopt+=internal<cr>')
623    screen:expect([[
624      {7:- }^                  │{7:- }                 |
625      {1:~                   }│{1:~                  }|*13
626      {3:<onal-diff-screen-1  }{2:<l-diff-screen-1.2 }|
627      :set diffopt+=internal                  |
628    ]])
629  end)
630
631  it('Diff empty and non-empty file', function()
632    write_file(fname, '', false)
633    write_file(fname_2, 'foo\nbar\nbaz', false)
634    reread()
635
636    feed(':set diffopt=filler<cr>')
637    screen:expect([[
638      {7:  }{23:------------------}│{7:  }{22:foo              }|
639      {7:  }{23:------------------}│{7:  }{22:bar              }|
640      {7:  }{23:------------------}│{7:  }{22:baz              }|
641      {7:  }^                  │{1:~                  }|
642      {1:~                   }│{1:~                  }|*10
643      {3:<onal-diff-screen-1  }{2:<l-diff-screen-1.2 }|
644      :set diffopt=filler                     |
645    ]])
646
647    feed(':set diffopt+=internal<cr>')
648    screen:expect([[
649      {7:  }{23:------------------}│{7:  }{22:foo              }|
650      {7:  }{23:------------------}│{7:  }{22:bar              }|
651      {7:  }{23:------------------}│{7:  }{22:baz              }|
652      {7:  }^                  │{1:~                  }|
653      {1:~                   }│{1:~                  }|*10
654      {3:<onal-diff-screen-1  }{2:<l-diff-screen-1.2 }|
655      :set diffopt+=internal                  |
656    ]])
657  end)
658
659  it('diffopt+=icase', function()
660    write_file(fname, 'a\nb\ncd\n', false)
661    write_file(fname_2, 'A\nb\ncDe\n', false)
662    reread()
663
664    feed(':set diffopt=filler,icase<cr>')
665    screen:expect([[
666      {7:  }^a                 │{7:  }A                |
667      {7:  }b                 │{7:  }b                |
668      {7:  }{4:cd                }│{7:  }{4:cD}{27:e}{4:              }|
669      {1:~                   }│{1:~                  }|*11
670      {3:<onal-diff-screen-1  }{2:<l-diff-screen-1.2 }|
671      :set diffopt=filler,icase               |
672    ]])
673
674    feed(':set diffopt+=internal<cr>')
675    screen:expect([[
676      {7:  }^a                 │{7:  }A                |
677      {7:  }b                 │{7:  }b                |
678      {7:  }{4:cd                }│{7:  }{4:cD}{27:e}{4:              }|
679      {1:~                   }│{1:~                  }|*11
680      {3:<onal-diff-screen-1  }{2:<l-diff-screen-1.2 }|
681      :set diffopt+=internal                  |
682    ]])
683  end)
684
685  describe('diffopt+=iwhite', function()
686    setup(function()
687      local f1 = 'int main()\n{\n   printf("Hello, World!");\n   return 0;\n}\n'
688      write_file(fname, f1, false)
689      local f2 =
690        'int main()\n{\n   if (0)\n   {\n      printf("Hello, World!");\n      return 0;\n   }\n}\n'
691      write_file(fname_2, f2, false)
692      feed(':diffupdate!<cr>')
693    end)
694
695    it('external', function()
696      reread()
697      feed(':set diffopt=filler,iwhite<cr>')
698      screen:expect([[
699        {7:  }^int main()        │{7:  }int main()       |
700        {7:  }{                 │{7:  }{                |
701        {7:  }{23:------------------}│{7:  }{22:   if (0)        }|
702        {7:  }{23:------------------}│{7:  }{22:   {             }|
703        {7:  }   printf("Hello, │{7:  }      printf("Hel|
704        {7:  }   return 0;      │{7:  }      return 0;  |
705        {7:  }{23:------------------}│{7:  }{22:   }             }|
706        {7:  }}                 │{7:  }}                |
707        {1:~                   }│{1:~                  }|*6
708        {3:<onal-diff-screen-1  }{2:<l-diff-screen-1.2 }|
709        :set diffopt=filler,iwhite              |
710      ]])
711    end)
712
713    it('internal', function()
714      reread()
715      feed(':set diffopt=filler,iwhite,internal<cr>')
716      screen:expect([[
717        {7:  }^int main()        │{7:  }int main()       |
718        {7:  }{                 │{7:  }{                |
719        {7:  }{23:------------------}│{7:  }{22:   if (0)        }|
720        {7:  }{23:------------------}│{7:  }{22:   {             }|
721        {7:  }   printf("Hello, │{7:  }      printf("Hel|
722        {7:  }   return 0;      │{7:  }      return 0;  |
723        {7:  }{23:------------------}│{7:  }{22:   }             }|
724        {7:  }}                 │{7:  }}                |
725        {1:~                   }│{1:~                  }|*6
726        {3:<onal-diff-screen-1  }{2:<l-diff-screen-1.2 }|
727        :set diffopt=filler,iwhite,internal     |
728      ]])
729    end)
730  end)
731
732  describe('diffopt+=iblank', function()
733    setup(function()
734      write_file(fname, 'a\n\n \ncd\nef\nxxx\n', false)
735      write_file(fname_2, 'a\ncd\n\nef\nyyy\n', false)
736      feed(':diffupdate!<cr>')
737    end)
738
739    it('generic', function()
740      reread()
741      feed(':set diffopt=internal,filler,iblank<cr>')
742      screen:expect([[
743        {7:  }^a                 │{7:  }a                |
744        {7:  }{22:                  }│{7:  }{23:-----------------}|*2
745        {7:  }cd                │{7:  }cd               |
746        {7:  }ef                │{7:  }                 |
747        {7:  }{27:xxx}{4:               }│{7:  }ef               |
748        {1:~                   }│{7:  }{27:yyy}{4:              }|
749        {1:~                   }│{1:~                  }|*7
750        {3:<onal-diff-screen-1  }{2:<l-diff-screen-1.2 }|
751        :set diffopt=internal,filler,iblank     |
752      ]])
753    end)
754
755    it('diffopt+=iwhite', function()
756      reread()
757      feed(':set diffopt=internal,filler,iblank,iwhite<cr>')
758      feed(':<cr>')
759      screen:expect([[
760        {7:  }^a                 │{7:  }a                |
761        {7:  }                  │{7:  }cd               |
762        {7:  }                  │{7:  }                 |
763        {7:  }cd                │{7:  }ef               |
764        {7:  }ef                │{7:  }{27:yyy}{4:              }|
765        {7:  }{27:xxx}{4:               }│{1:~                  }|
766        {1:~                   }│{1:~                  }|*8
767        {3:<onal-diff-screen-1  }{2:<l-diff-screen-1.2 }|
768        :                                       |
769      ]])
770    end)
771
772    it('diffopt+=iwhiteall', function()
773      reread()
774      feed(':set diffopt=internal,filler,iblank,iwhiteall<cr>')
775      feed(':<cr>')
776      screen:expect([[
777        {7:  }^a                 │{7:  }a                |
778        {7:  }                  │{7:  }cd               |
779        {7:  }                  │{7:  }                 |
780        {7:  }cd                │{7:  }ef               |
781        {7:  }ef                │{7:  }{27:yyy}{4:              }|
782        {7:  }{27:xxx}{4:               }│{1:~                  }|
783        {1:~                   }│{1:~                  }|*8
784        {3:<onal-diff-screen-1  }{2:<l-diff-screen-1.2 }|
785        :                                       |
786      ]])
787    end)
788
789    it('diffopt+=iwhiteeol', function()
790      reread()
791      feed(':set diffopt=internal,filler,iblank,iwhiteeol<cr>')
792      feed(':<cr>')
793      screen:expect([[
794        {7:  }^a                 │{7:  }a                |
795        {7:  }                  │{7:  }cd               |
796        {7:  }                  │{7:  }                 |
797        {7:  }cd                │{7:  }ef               |
798        {7:  }ef                │{7:  }{27:yyy}{4:              }|
799        {7:  }{27:xxx}{4:               }│{1:~                  }|
800        {1:~                   }│{1:~                  }|*8
801        {3:<onal-diff-screen-1  }{2:<l-diff-screen-1.2 }|
802        :                                       |
803      ]])
804    end)
805  end)
806
807  describe('diffopt+=iwhite{eol,all}', function()
808    setup(function()
809      write_file(fname, 'a \nx\ncd\nef\nxx  xx\nfoo\nbar\n', false)
810      write_file(fname_2, 'a\nx\nc d\n ef\nxx xx\nfoo\n\nbar\n', false)
811      feed(':diffupdate!<cr>')
812    end)
813
814    it('diffopt+=iwhiteeol', function()
815      reread()
816      feed(':set diffopt=internal,filler,iwhiteeol<cr>')
817      feed(':<cr>')
818      screen:expect([[
819        {7:  }^a                 │{7:  }a                |
820        {7:  }x                 │{7:  }x                |
821        {7:  }{4:cd                }│{7:  }{4:c}{27: }{4:d              }|
822        {7:  }{4:ef                }│{7:  }{27: }{4:ef              }|
823        {7:  }{4:xx }{27: }{4:xx            }│{7:  }{4:xx xx            }|
824        {7:  }foo               │{7:  }foo              |
825        {7:  }{23:------------------}│{7:  }{22:                 }|
826        {7:  }bar               │{7:  }bar              |
827        {1:~                   }│{1:~                  }|*6
828        {3:<onal-diff-screen-1  }{2:<l-diff-screen-1.2 }|
829        :                                       |
830      ]])
831    end)
832
833    it('diffopt+=iwhiteall', function()
834      reread()
835      feed(':set diffopt=internal,filler,iwhiteall<cr>')
836      feed(':<cr>')
837      screen:expect([[
838        {7:  }^a                 │{7:  }a                |
839        {7:  }x                 │{7:  }x                |
840        {7:  }cd                │{7:  }c d              |
841        {7:  }ef                │{7:  } ef              |
842        {7:  }xx  xx            │{7:  }xx xx            |
843        {7:  }foo               │{7:  }foo              |
844        {7:  }{23:------------------}│{7:  }{22:                 }|
845        {7:  }bar               │{7:  }bar              |
846        {1:~                   }│{1:~                  }|*6
847        {3:<onal-diff-screen-1  }{2:<l-diff-screen-1.2 }|
848        :                                       |
849      ]])
850    end)
851  end)
852
853  -- oldtest: Test_diff_scroll()
854  -- This was scrolling for 'cursorbind' but 'scrollbind' is more important
855  it('scrolling works correctly vim-patch:8.2.5155', function()
856    screen:try_resize(40, 12)
857    write_file(
858      fname,
859      dedent([[
860      line 1
861      line 2
862      line 3
863      line 4
864
865      // Common block
866      // one
867      // containing
868      // four lines
869
870      // Common block
871      // two
872      // containing
873      // four lines]]),
874      false
875    )
876    write_file(
877      fname_2,
878      dedent([[
879      line 1
880      line 2
881      line 3
882      line 4
883
884      Lorem
885      ipsum
886      dolor
887      sit
888      amet,
889      consectetur
890      adipiscing
891      elit.
892      Etiam
893      luctus
894      lectus
895      sodales,
896      dictum
897
898      // Common block
899      // one
900      // containing
901      // four lines
902
903      Vestibulum
904      tincidunt
905      aliquet
906      nulla.
907
908      // Common block
909      // two
910      // containing
911      // four lines]]),
912      false
913    )
914    reread()
915
916    feed('<C-W><C-W>jjjj')
917    screen:expect([[
918      {7:  }line 1           │{7:  }line 1            |
919      {7:  }line 2           │{7:  }line 2            |
920      {7:  }line 3           │{7:  }line 3            |
921      {7:  }line 4           │{7:  }line 4            |
922      {7:  }                 │{7:  }^                  |
923      {7:  }{23:-----------------}│{7:  }{22:Lorem             }|
924      {7:  }{23:-----------------}│{7:  }{22:ipsum             }|
925      {7:  }{23:-----------------}│{7:  }{22:dolor             }|
926      {7:  }{23:-----------------}│{7:  }{22:sit               }|
927      {7:  }{23:-----------------}│{7:  }{22:amet,             }|
928      {2:<nal-diff-screen-1  }{3:<al-diff-screen-1.2 }|
929      :e                                      |
930    ]])
931    feed('j')
932    screen:expect([[
933      {7:  }line 1           │{7:  }line 1            |
934      {7:  }line 2           │{7:  }line 2            |
935      {7:  }line 3           │{7:  }line 3            |
936      {7:  }line 4           │{7:  }line 4            |
937      {7:  }                 │{7:  }                  |
938      {7:  }{23:-----------------}│{7:  }{22:^Lorem             }|
939      {7:  }{23:-----------------}│{7:  }{22:ipsum             }|
940      {7:  }{23:-----------------}│{7:  }{22:dolor             }|
941      {7:  }{23:-----------------}│{7:  }{22:sit               }|
942      {7:  }{23:-----------------}│{7:  }{22:amet,             }|
943      {2:<nal-diff-screen-1  }{3:<al-diff-screen-1.2 }|
944      :e                                      |
945    ]])
946  end)
947
948  describe('line matching diff algorithm', function()
949    setup(function()
950      local f1 = [[if __name__ == "__main__":
951    import sys
952    app = QWidgets.QApplication(sys.args)
953    MainWindow = QtWidgets.QMainWindow()
954    ui = UI_MainWindow()
955    ui.setupUI(MainWindow)
956    MainWindow.show()
957    sys.exit(app.exec_())]]
958      write_file(fname, f1, false)
959      local f2 = [[if __name__ == "__main__":
960    import sys
961    comment these things
962    #app = QWidgets.QApplication(sys.args)
963    #MainWindow = QtWidgets.QMainWindow()
964    add a completely different line here
965    #ui = UI_MainWindow()
966    add another new line
967    ui.setupUI(MainWindow)
968    MainWindow.show()
969    sys.exit(app.exec_())]]
970      write_file(fname_2, f2, false)
971    end)
972
973    it('diffopt+=linematch:20', function()
974      reread()
975      feed(':set diffopt=internal,filler<cr>')
976      screen:expect([[
977  {7:  }^if __name__ == "__│{7:  }if __name__ == "_|
978  {7:  }    import sys    │{7:  }    import sys   |
979  {7:  }{4:    }{27:app = QWidgets}│{7:  }{4:    }{27:comment these}|
980  {7:  }{4:    }{27:MainWindow = Q}│{7:  }{4:    }{27:#app = QWidge}|
981  {7:  }{4:    }{27:ui = UI_}{4:MainWi}│{7:  }{4:    }{27:#MainWindow =}|
982  {7:  }{23:------------------}│{7:  }{22:    add a complet}|
983  {7:  }{23:------------------}│{7:  }{22:    #ui = UI_Main}|
984  {7:  }{23:------------------}│{7:  }{22:    add another n}|
985  {7:  }    ui.setupUI(Mai│{7:  }    ui.setupUI(Ma|
986  {7:  }    MainWindow.sho│{7:  }    MainWindow.sh|
987  {7:  }    sys.exit(app.e│{7:  }    sys.exit(app.|
988  {1:~                   }│{1:~                  }|*3
989  {3:<onal-diff-screen-1  }{2:<l-diff-screen-1.2 }|
990  :set diffopt=internal,filler            |
991      ]])
992
993      feed('G')
994      feed(':set diffopt+=linematch:20<cr>')
995      screen:expect([[
996        {7:  }if __name__ == "__│{7:  }if __name__ == "_|
997        {7:  }    import sys    │{7:  }    import sys   |
998        {7:  }{23:------------------}│{7:  }{22:    comment these}|
999        {7:  }{4:    app = QWidgets}│{7:  }{4:    }{27:#}{4:app = QWidge}|
1000        {7:  }{4:    MainWindow = Q}│{7:  }{4:    }{27:#}{4:MainWindow =}|
1001        {7:  }{23:------------------}│{7:  }{22:    add a complet}|
1002        {7:  }{4:    ui = UI_MainWi}│{7:  }{4:    }{27:#}{4:ui = UI_Main}|
1003        {7:  }{23:------------------}│{7:  }{22:    add another n}|
1004        {7:  }    ui.setupUI(Mai│{7:  }    ui.setupUI(Ma|
1005        {7:  }    MainWindow.sho│{7:  }    MainWindow.sh|
1006        {7:  }    ^sys.exit(app.e│{7:  }    sys.exit(app.|
1007        {1:~                   }│{1:~                  }|*3
1008        {3:<onal-diff-screen-1  }{2:<l-diff-screen-1.2 }|
1009        :set diffopt+=linematch:20              |
1010      ]])
1011    end)
1012  end)
1013
1014  describe('line matching diff algorithm with icase', function()
1015    setup(function()
1016      local f1 = [[DDD
1017_aa]]
1018      write_file(fname, f1, false)
1019      local f2 = [[DDD
1020AAA
1021ccca]]
1022      write_file(fname_2, f2, false)
1023    end)
1024    it('diffopt+=linematch:20,icase', function()
1025      reread()
1026      feed(':set diffopt=internal,filler,linematch:20<cr>')
1027      screen:expect([[
1028        {7:  }^DDD               │{7:  }DDD              |
1029        {7:  }{23:------------------}│{7:  }{22:AAA              }|
1030        {7:  }{27:_a}{4:a               }│{7:  }{27:ccc}{4:a             }|
1031        {1:~                   }│{1:~                  }|*11
1032        {3:<onal-diff-screen-1  }{2:<l-diff-screen-1.2 }|
1033                                                |
1034      ]])
1035      feed(':set diffopt+=icase<cr>')
1036      screen:expect([[
1037        {7:  }^DDD               │{7:  }DDD              |
1038        {7:  }{27:_}{4:aa               }│{7:  }{27:A}{4:AA              }|
1039        {7:  }{23:------------------}│{7:  }{22:ccca             }|
1040        {1:~                   }│{1:~                  }|*11
1041        {3:<onal-diff-screen-1  }{2:<l-diff-screen-1.2 }|
1042        :set diffopt+=icase                     |
1043      ]])
1044    end)
1045  end)
1046
1047  describe('line matching diff algorithm with iwhiteall', function()
1048    setup(function()
1049      local f1 = [[BB
1050   AAA]]
1051      write_file(fname, f1, false)
1052      local f2 = [[BB
1053   AAB
1054AAAB]]
1055      write_file(fname_2, f2, false)
1056    end)
1057    it('diffopt+=linematch:20,iwhiteall', function()
1058      reread()
1059      feed(':set diffopt=internal,filler,linematch:20<cr>')
1060      screen:expect {
1061        grid = [[
1062        {7:  }^BB                │{7:  }BB               |
1063        {7:  }{4:   AA}{27:A}{4:            }│{7:  }{4:   AA}{27:B}{4:           }|
1064        {7:  }{23:------------------}│{7:  }{22:AAAB             }|
1065        {1:~                   }│{1:~                  }|*11
1066        {3:<onal-diff-screen-1  }{2:<l-diff-screen-1.2 }|
1067                                                |
1068      ]],
1069      }
1070      feed(':set diffopt+=iwhiteall<cr>')
1071      screen:expect {
1072        grid = [[
1073        {7:  }^BB                │{7:  }BB               |
1074        {7:  }{23:------------------}│{7:  }{22:   AAB           }|
1075        {7:  }{4:   AAA            }│{7:  }{4:AAA}{27:B}{4:             }|
1076        {1:~                   }│{1:~                  }|*11
1077        {3:<onal-diff-screen-1  }{2:<l-diff-screen-1.2 }|
1078        :set diffopt+=iwhiteall                 |
1079      ]],
1080      }
1081    end)
1082  end)
1083
1084  it('redraws with a change to non-current buffer', function()
1085    write_file(fname, 'aaa\nbbb\nccc\n\nxx', false)
1086    write_file(fname_2, 'aaa\nbbb\nccc\n\nyy', false)
1087    reread()
1088    local buf = api.nvim_get_current_buf()
1089    command('botright new')
1090    screen:expect {
1091      grid = [[
1092      {7:  }aaa               │{7:  }aaa              |
1093      {7:  }bbb               │{7:  }bbb              |
1094      {7:  }ccc               │{7:  }ccc              |
1095      {7:  }                  │{7:  }                 |
1096      {7:  }{27:xx}{4:                }│{7:  }{27:yy}{4:               }|
1097      {1:~                   }│{1:~                  }|
1098      {2:<onal-diff-screen-1  <l-diff-screen-1.2 }|
1099      ^                                        |
1100      {1:~                                       }|*6
1101      {3:[No Name]                               }|
1102      :e                                      |
1103    ]],
1104    }
1105
1106    api.nvim_buf_set_lines(buf, 1, 2, true, { 'BBB' })
1107    screen:expect {
1108      grid = [[
1109      {7:  }aaa               │{7:  }aaa              |
1110      {7:  }{27:BBB}{4:               }│{7:  }{27:bbb}{4:              }|
1111      {7:  }ccc               │{7:  }ccc              |
1112      {7:  }                  │{7:  }                 |
1113      {7:  }{27:xx}{4:                }│{7:  }{27:yy}{4:               }|
1114      {1:~                   }│{1:~                  }|
1115      {2:<-diff-screen-1 [+]  <l-diff-screen-1.2 }|
1116      ^                                        |
1117      {1:~                                       }|*6
1118      {3:[No Name]                               }|
1119      :e                                      |
1120    ]],
1121    }
1122  end)
1123
1124  it('redraws with a change current buffer in another window', function()
1125    write_file(fname, 'aaa\nbbb\nccc\n\nxx', false)
1126    write_file(fname_2, 'aaa\nbbb\nccc\n\nyy', false)
1127    reread()
1128    local buf = api.nvim_get_current_buf()
1129    command('botright split | diffoff')
1130    screen:expect {
1131      grid = [[
1132      {7:  }aaa               │{7:  }aaa              |
1133      {7:  }bbb               │{7:  }bbb              |
1134      {7:  }ccc               │{7:  }ccc              |
1135      {7:  }                  │{7:  }                 |
1136      {7:  }{27:xx}{4:                }│{7:  }{27:yy}{4:               }|
1137      {1:~                   }│{1:~                  }|
1138      {2:<onal-diff-screen-1  <l-diff-screen-1.2 }|
1139      ^aaa                                     |
1140      bbb                                     |
1141      ccc                                     |
1142                                              |
1143      xx                                      |
1144      {1:~                                       }|*2
1145      {3:Xtest-functional-diff-screen-1          }|
1146      :e                                      |
1147    ]],
1148    }
1149
1150    api.nvim_buf_set_lines(buf, 1, 2, true, { 'BBB' })
1151    screen:expect {
1152      grid = [[
1153      {7:  }aaa               │{7:  }aaa              |
1154      {7:  }{27:BBB}{4:               }│{7:  }{27:bbb}{4:              }|
1155      {7:  }ccc               │{7:  }ccc              |
1156      {7:  }                  │{7:  }                 |
1157      {7:  }{27:xx}{4:                }│{7:  }{27:yy}{4:               }|
1158      {1:~                   }│{1:~                  }|
1159      {2:<-diff-screen-1 [+]  <l-diff-screen-1.2 }|
1160      ^aaa                                     |
1161      BBB                                     |
1162      ccc                                     |
1163                                              |
1164      xx                                      |
1165      {1:~                                       }|*2
1166      {3:Xtest-functional-diff-screen-1 [+]      }|
1167      :e                                      |
1168    ]],
1169    }
1170  end)
1171end)
1172
1173it('win_update redraws lines properly', function()
1174  local screen
1175  screen = Screen.new(50, 10)
1176  screen:set_default_attr_ids({
1177    [1] = { bold = true, foreground = Screen.colors.Blue1 },
1178    [2] = { foreground = Screen.colors.Grey100, background = Screen.colors.Red },
1179    [3] = {
1180      background = Screen.colors.Red,
1181      foreground = Screen.colors.Grey100,
1182      special = Screen.colors.Yellow,
1183    },
1184    [4] = { bold = true, foreground = Screen.colors.SeaGreen4 },
1185    [5] = { special = Screen.colors.Yellow },
1186    [6] = { special = Screen.colors.Yellow, bold = true, foreground = Screen.colors.SeaGreen4 },
1187    [7] = { foreground = Screen.colors.Grey0, background = Screen.colors.Grey100 },
1188    [8] = { foreground = Screen.colors.Gray90, background = Screen.colors.Grey100 },
1189    [9] = { foreground = tonumber('0x00000c'), background = Screen.colors.Grey100 },
1190    [10] = { background = Screen.colors.Grey100, bold = true, foreground = tonumber('0xe5e5ff') },
1191    [11] = { background = Screen.colors.Grey100, bold = true, foreground = tonumber('0x2b8452') },
1192    [12] = { bold = true, reverse = true },
1193    [13] = { foreground = Screen.colors.DarkBlue, background = Screen.colors.WebGray },
1194    [14] = { reverse = true },
1195    [15] = { background = Screen.colors.LightBlue },
1196    [16] = { background = Screen.colors.LightCyan1, bold = true, foreground = Screen.colors.Blue1 },
1197    [17] = { bold = true, background = Screen.colors.Red },
1198    [18] = { background = Screen.colors.LightMagenta },
1199  })
1200
1201  insert([[
1202  1
1203
1204
1205  2
1206  1a
1207  ]])
1208  command('vnew left')
1209  insert([[
1210  2
1211  2a
1212  2b
1213  ]])
1214  command('windo diffthis')
1215  command('windo 1')
1216  screen:expect {
1217    grid = [[
1218    {13:  }{16:-----------------------}│{13:  }{15:^1                     }|
1219    {13:  }{16:-----------------------}│{13:  }{15:                      }|*2
1220    {13:  }2                      │{13:  }2                     |
1221    {13:  }{17:2}{18:a                     }│{13:  }{17:1}{18:a                    }|
1222    {13:  }{15:2b                     }│{13:  }{16:----------------------}|
1223    {13:  }                       │{13:  }                      |
1224    {1:~                        }│{1:~                       }|
1225    {14:left [+]                  }{12:[No Name] [+]           }|
1226                                                      |
1227  ]],
1228  }
1229  feed('<C-e>')
1230  feed('<C-e>')
1231  feed('<C-y>')
1232  feed('<C-y>')
1233  feed('<C-y>')
1234  screen:expect {
1235    grid = [[
1236    {13:  }{16:-----------------------}│{13:  }{15:1                     }|
1237    {13:  }{16:-----------------------}│{13:  }{15:                      }|
1238    {13:  }{16:-----------------------}│{13:  }{15:^                      }|
1239    {13:  }2                      │{13:  }2                     |
1240    {13:  }{17:2}{18:a                     }│{13:  }{17:1}{18:a                    }|
1241    {13:  }{15:2b                     }│{13:  }{16:----------------------}|
1242    {13:  }                       │{13:  }                      |
1243    {1:~                        }│{1:~                       }|
1244    {14:left [+]                  }{12:[No Name] [+]           }|
1245                                                      |
1246  ]],
1247  }
1248end)
1249
1250-- oldtest: Test_diff_rnu()
1251it('diff updates line numbers below filler lines', function()
1252  local screen = Screen.new(40, 14)
1253  exec([[
1254    set diffopt=internal,filler
1255    call setline(1, ['a', 'a', 'a', 'y', 'b', 'b', 'b', 'b', 'b'])
1256    vnew
1257    call setline(1, ['a', 'a', 'a', 'x', 'x', 'x', 'b', 'b', 'b', 'b', 'b'])
1258    windo diffthis
1259    setlocal number rnu cursorline cursorlineopt=number foldcolumn=0
1260  ]])
1261  screen:expect([[
1262    {7:  }a                │{15:1   }^a               |
1263    {7:  }a                │{8:  1 }a               |
1264    {7:  }a                │{8:  2 }a               |
1265    {7:  }{27:x}{4:                }│{8:  3 }{27:y}{4:               }|
1266    {7:  }{22:x                }│{8:    }{23:----------------}|*2
1267    {7:  }b                │{8:  4 }b               |
1268    {7:  }b                │{8:  5 }b               |
1269    {7:  }b                │{8:  6 }b               |
1270    {7:  }b                │{8:  7 }b               |
1271    {7:  }b                │{8:  8 }b               |
1272    {1:~                  }│{1:~                   }|
1273    {2:[No Name] [+]       }{3:[No Name] [+]       }|
1274                                            |
1275  ]])
1276  feed('j')
1277  screen:expect([[
1278    {7:  }a                │{8:  1 }a               |
1279    {7:  }a                │{15:2   }^a               |
1280    {7:  }a                │{8:  1 }a               |
1281    {7:  }{27:x}{4:                }│{8:  2 }{27:y}{4:               }|
1282    {7:  }{22:x                }│{8:    }{23:----------------}|*2
1283    {7:  }b                │{8:  3 }b               |
1284    {7:  }b                │{8:  4 }b               |
1285    {7:  }b                │{8:  5 }b               |
1286    {7:  }b                │{8:  6 }b               |
1287    {7:  }b                │{8:  7 }b               |
1288    {1:~                  }│{1:~                   }|
1289    {2:[No Name] [+]       }{3:[No Name] [+]       }|
1290                                            |
1291  ]])
1292  feed('j')
1293  screen:expect([[
1294    {7:  }a                │{8:  2 }a               |
1295    {7:  }a                │{8:  1 }a               |
1296    {7:  }a                │{15:3   }^a               |
1297    {7:  }{27:x}{4:                }│{8:  1 }{27:y}{4:               }|
1298    {7:  }{22:x                }│{8:    }{23:----------------}|*2
1299    {7:  }b                │{8:  2 }b               |
1300    {7:  }b                │{8:  3 }b               |
1301    {7:  }b                │{8:  4 }b               |
1302    {7:  }b                │{8:  5 }b               |
1303    {7:  }b                │{8:  6 }b               |
1304    {1:~                  }│{1:~                   }|
1305    {2:[No Name] [+]       }{3:[No Name] [+]       }|
1306                                            |
1307  ]])
1308end)
1309
1310-- oldtest: Test_diff_with_scroll_and_change()
1311it('Align the filler lines when changing text in diff mode', function()
1312  local screen = Screen.new(40, 20)
1313  exec([[
1314    call setline(1, range(1, 15))
1315    vnew
1316    call setline(1, range(9, 15))
1317    windo diffthis
1318    wincmd h
1319    exe "normal Gl5\<C-E>"
1320  ]])
1321  screen:expect {
1322    grid = [[
1323    {7:  }{23:------------------}│{7:  }{22:6                }|
1324    {7:  }{23:------------------}│{7:  }{22:7                }|
1325    {7:  }{23:------------------}│{7:  }{22:8                }|
1326    {7:  }9                 │{7:  }9                |
1327    {7:  }10                │{7:  }10               |
1328    {7:  }11                │{7:  }11               |
1329    {7:  }12                │{7:  }12               |
1330    {7:  }13                │{7:  }13               |
1331    {7:  }14                │{7:  }14               |
1332    {7:- }1^5                │{7:- }15               |
1333    {1:~                   }│{1:~                  }|*8
1334    {3:[No Name] [+]        }{2:[No Name] [+]      }|
1335                                            |
1336  ]],
1337  }
1338  feed('ax<Esc>')
1339  screen:expect {
1340    grid = [[
1341    {7:  }{23:------------------}│{7:  }{22:6                }|
1342    {7:  }{23:------------------}│{7:  }{22:7                }|
1343    {7:  }{23:------------------}│{7:  }{22:8                }|
1344    {7:  }9                 │{7:  }9                |
1345    {7:  }10                │{7:  }10               |
1346    {7:  }11                │{7:  }11               |
1347    {7:  }12                │{7:  }12               |
1348    {7:  }13                │{7:  }13               |
1349    {7:  }14                │{7:  }14               |
1350    {7:  }{4:15}{27:^x}{4:               }│{7:  }{4:15               }|
1351    {1:~                   }│{1:~                  }|*8
1352    {3:[No Name] [+]        }{2:[No Name] [+]      }|
1353                                            |
1354  ]],
1355  }
1356  feed('<C-W>lay<Esc>')
1357  screen:expect {
1358    grid = [[
1359    {7:  }{23:-----------------}│{7:  }{22:6                 }|
1360    {7:  }{23:-----------------}│{7:  }{22:7                 }|
1361    {7:  }{23:-----------------}│{7:  }{22:8                 }|
1362    {7:  }9                │{7:  }9                 |
1363    {7:  }10               │{7:  }10                |
1364    {7:  }11               │{7:  }11                |
1365    {7:  }12               │{7:  }12                |
1366    {7:  }13               │{7:  }13                |
1367    {7:  }14               │{7:  }14                |
1368    {7:  }{4:15}{27:x}{4:              }│{7:  }{4:15}{27:^y}{4:               }|
1369    {1:~                  }│{1:~                   }|*8
1370    {2:[No Name] [+]       }{3:[No Name] [+]       }|
1371                                            |
1372  ]],
1373  }
1374end)
1375
1376it("diff mode doesn't restore invalid 'foldcolumn' value #21647", function()
1377  local screen = Screen.new(60, 6)
1378  eq('0', api.nvim_get_option_value('foldcolumn', {}))
1379  command('diffsplit | bd')
1380  screen:expect([[
1381    ^                                                            |
1382    {1:~                                                           }|*4
1383                                                                |
1384  ]])
1385  eq('0', api.nvim_get_option_value('foldcolumn', {}))
1386end)
1387
1388it("'relativenumber' doesn't draw beyond end of window in diff mode #29403", function()
1389  local screen = Screen.new(60, 12)
1390  command('set diffopt=internal,filler,closeoff')
1391  command('set relativenumber')
1392  feed('10aa<CR><Esc>gg')
1393  command('vnew')
1394  feed('ab<CR><Esc>gg')
1395  command('windo diffthis')
1396  command('wincmd |')
1397  screen:expect([[
1398    {8: }│{7:  }{8:  0 }{27:^a}{4:                                                   }|
1399    {8: }│{7:  }{8:  1 }{22:a                                                   }|
1400    {8: }│{7:  }{8:  2 }{22:a                                                   }|
1401    {8: }│{7:  }{8:  3 }{22:a                                                   }|
1402    {8: }│{7:  }{8:  4 }{22:a                                                   }|
1403    {8: }│{7:  }{8:  5 }{22:a                                                   }|
1404    {8: }│{7:  }{8:  6 }{22:a                                                   }|
1405    {8: }│{7:  }{8:  7 }{22:a                                                   }|
1406    {8: }│{7:  }{8:  8 }{22:a                                                   }|
1407    {8: }│{7:  }{8:  9 }{22:a                                                   }|
1408    {2:< }{3:[No Name] [+]                                             }|
1409                                                                |
1410  ]])
1411  feed('j')
1412  screen:expect([[
1413    {8: }│{7:  }{8:  1 }{27:a}{4:                                                   }|
1414    {8: }│{7:  }{8:  0 }{22:^a                                                   }|
1415    {8: }│{7:  }{8:  1 }{22:a                                                   }|
1416    {8: }│{7:  }{8:  2 }{22:a                                                   }|
1417    {8: }│{7:  }{8:  3 }{22:a                                                   }|
1418    {8: }│{7:  }{8:  4 }{22:a                                                   }|
1419    {8: }│{7:  }{8:  5 }{22:a                                                   }|
1420    {8: }│{7:  }{8:  6 }{22:a                                                   }|
1421    {8: }│{7:  }{8:  7 }{22:a                                                   }|
1422    {8: }│{7:  }{8:  8 }{22:a                                                   }|
1423    {2:< }{3:[No Name] [+]                                             }|
1424                                                                |
1425  ]])
1426end)
1427
1428-- oldtest: Test_diff_binary()
1429it('diff mode works properly if file contains NUL bytes vim-patch:8.2.3925', function()
1430  local screen = Screen.new(40, 20)
1431  screen:add_extra_attr_ids {
1432    [100] = { foreground = Screen.colors.Blue, bold = true, background = Screen.colors.Red },
1433  }
1434  exec([[
1435    call setline(1, ['a', 'b', "c\n", 'd', 'e', 'f', 'g'])
1436    vnew
1437    call setline(1, ['A', 'b', 'c', 'd', 'E', 'f', 'g'])
1438    windo diffthis
1439    wincmd p
1440    norm! gg0
1441    redraw!
1442  ]])
1443
1444  -- Test using internal diff
1445  screen:expect([[
1446    {7:  }{27:^A}{4:                 }│{7:  }{27:a}{4:                }|
1447    {7:  }b                 │{7:  }b                |
1448    {7:  }{4:c                 }│{7:  }{4:c}{100:^@}{4:              }|
1449    {7:  }d                 │{7:  }d                |
1450    {7:  }{27:E}{4:                 }│{7:  }{27:e}{4:                }|
1451    {7:  }f                 │{7:  }f                |
1452    {7:  }g                 │{7:  }g                |
1453    {1:~                   }│{1:~                  }|*11
1454    {3:[No Name] [+]        }{2:[No Name] [+]      }|
1455                                            |
1456  ]])
1457
1458  -- Test using internal diff and case folding
1459  command('set diffopt+=icase')
1460  feed('<C-L>')
1461  screen:expect([[
1462    {7:  }^A                 │{7:  }a                |
1463    {7:  }b                 │{7:  }b                |
1464    {7:  }{4:c                 }│{7:  }{4:c}{100:^@}{4:              }|
1465    {7:  }d                 │{7:  }d                |
1466    {7:  }E                 │{7:  }e                |
1467    {7:  }f                 │{7:  }f                |
1468    {7:  }g                 │{7:  }g                |
1469    {1:~                   }│{1:~                  }|*11
1470    {3:[No Name] [+]        }{2:[No Name] [+]      }|
1471                                            |
1472  ]])
1473
1474  -- Test using external diff
1475  command('set diffopt=filler')
1476  feed('<C-L>')
1477  screen:expect([[
1478    {7:  }{27:^A}{4:                 }│{7:  }{27:a}{4:                }|
1479    {7:  }b                 │{7:  }b                |
1480    {7:  }{4:c                 }│{7:  }{4:c}{100:^@}{4:              }|
1481    {7:  }d                 │{7:  }d                |
1482    {7:  }{27:E}{4:                 }│{7:  }{27:e}{4:                }|
1483    {7:  }f                 │{7:  }f                |
1484    {7:  }g                 │{7:  }g                |
1485    {1:~                   }│{1:~                  }|*11
1486    {3:[No Name] [+]        }{2:[No Name] [+]      }|
1487                                            |
1488  ]])
1489
1490  -- Test using external diff and case folding
1491  command('set diffopt+=filler,icase')
1492  feed('<C-L>')
1493  screen:expect([[
1494    {7:  }^A                 │{7:  }a                |
1495    {7:  }b                 │{7:  }b                |
1496    {7:  }{4:c                 }│{7:  }{4:c}{100:^@}{4:              }|
1497    {7:  }d                 │{7:  }d                |
1498    {7:  }E                 │{7:  }e                |
1499    {7:  }f                 │{7:  }f                |
1500    {7:  }g                 │{7:  }g                |
1501    {1:~                   }│{1:~                  }|*11
1502    {3:[No Name] [+]        }{2:[No Name] [+]      }|
1503                                            |
1504  ]])
1505end)
1506
1507-- oldtest: Test_diff_breakindent_after_filler()
1508it("diff mode draws 'breakindent' correctly after filler lines", function()
1509  local screen = Screen.new(45, 8)
1510  exec([[
1511    set laststatus=0 diffopt+=followwrap breakindent breakindentopt=min:0
1512    call setline(1, ['a', '  ' .. repeat('c', 50)])
1513    vnew
1514    call setline(1, ['a', 'b', '  ' .. repeat('c', 50)])
1515    windo diffthis
1516    norm! G$
1517  ]])
1518  screen:expect([[
1519    {7:  }a                   │{7:  }a                   |
1520    {7:  }{22:b                   }│{7:  }{23:--------------------}|
1521    {7:  }  cccccccccccccccccc│{7:  }  cccccccccccccccccc|*2
1522    {7:  }  cccccccccccccc    │{7:  }  ccccccccccccc^c    |
1523    {1:~                     }│{1:~                     }|*2
1524                                                 |
1525  ]])
1526end)
1527
1528-- oldtest: Test_diff_overlapped_diff_blocks_will_be_merged()
1529it('diff mode overlapped diff blocks will be merged', function()
1530  write_file('Xdifile1', '')
1531  write_file('Xdifile2', '')
1532  write_file('Xdifile3', '')
1533
1534  finally(function()
1535    os.remove('Xdifile1')
1536    os.remove('Xdifile2')
1537    os.remove('Xdifile3')
1538    os.remove('Xdiin1')
1539    os.remove('Xdinew1')
1540    os.remove('Xdiout1')
1541    os.remove('Xdiin2')
1542    os.remove('Xdinew2')
1543    os.remove('Xdiout2')
1544  end)
1545
1546  exec([[
1547    func DiffExprStub()
1548      let txt_in = readfile(v:fname_in)
1549      let txt_new = readfile(v:fname_new)
1550      if txt_in == ["line1"] && txt_new == ["line2"]
1551        call writefile(["1c1"], v:fname_out)
1552      elseif txt_in == readfile("Xdiin1") && txt_new == readfile("Xdinew1")
1553        call writefile(readfile("Xdiout1"), v:fname_out)
1554      elseif txt_in == readfile("Xdiin2") && txt_new == readfile("Xdinew2")
1555        call writefile(readfile("Xdiout2"), v:fname_out)
1556      endif
1557    endfunc
1558  ]])
1559
1560  local screen = Screen.new(35, 20)
1561  command('set winwidth=10 diffopt=filler,internal')
1562  command('args Xdifile1 Xdifile2 | vert all | windo diffthis')
1563
1564  WriteDiffFiles('a\nb', 'x\nx')
1565  write_file('Xdiin1', 'a\nb')
1566  write_file('Xdinew1', 'x\nx')
1567  write_file('Xdiout1', '1c1\n2c2')
1568  command('set diffexpr=DiffExprStub()')
1569  screen:expect([[
1570    {7:  }{27:a}{4:              }│{7:  }{27:^x}{4:              }|
1571    {7:  }{27:b}{4:              }│{7:  }{27:x}{4:              }|
1572    {1:~                }│{1:~                }|*16
1573    {2:Xdifile1          }{3:Xdifile2         }|
1574                                       |
1575  ]])
1576  command('set diffexpr&')
1577
1578  WriteDiffFiles('a\nb\nc', 'x\nc')
1579  write_file('Xdiin1', 'a\nb\nc')
1580  write_file('Xdinew1', 'x\nc')
1581  write_file('Xdiout1', '1c1\n2c1')
1582  command('set diffexpr=DiffExprStub()')
1583  screen:expect([[
1584    {7:  }{27:a}{4:              }│{7:  }{27:^x}{4:              }|
1585    {7:  }{22:b              }│{7:  }{23:---------------}|
1586    {7:  }c              │{7:  }c              |
1587    {1:~                }│{1:~                }|*15
1588    {2:Xdifile1          }{3:Xdifile2         }|
1589                                       |
1590  ]])
1591  command('set diffexpr&')
1592
1593  WriteDiffFiles('a\nc', 'x\nx\nc')
1594  write_file('Xdiin1', 'a\nc')
1595  write_file('Xdinew1', 'x\nx\nc')
1596  write_file('Xdiout1', '1c1\n1a2')
1597  command('set diffexpr=DiffExprStub()')
1598  screen:expect([[
1599    {7:  }{27:a}{4:              }│{7:  }{27:^x}{4:              }|
1600    {7:  }{23:---------------}│{7:  }{22:x              }|
1601    {7:  }c              │{7:  }c              |
1602    {1:~                }│{1:~                }|*15
1603    {2:Xdifile1          }{3:Xdifile2         }|
1604                                       |
1605  ]])
1606  command('set diffexpr&')
1607
1608  command('args Xdifile1 Xdifile2 Xdifile3 | vert all | windo diffthis')
1609
1610  WriteDiffFiles3('a\nb\nc', 'a\nx\nc', 'y\nb\nc')
1611  screen:expect([[
1612    {7:  }{27:a}{4:        }│{7:  }{27:a}{4:        }│{7:  }{27:^y}{4:        }|
1613    {7:  }{27:b}{4:        }│{7:  }{27:x}{4:        }│{7:  }{27:b}{4:        }|
1614    {7:  }c        │{7:  }c        │{7:  }c        |
1615    {1:~          }│{1:~          }│{1:~          }|*15
1616    {2:Xdifile1    Xdifile2    }{3:Xdifile3   }|
1617                                       |
1618  ]])
1619
1620  WriteDiffFiles3('a\nb\nc', 'a\nx\nc', 'a\ny\nc')
1621  screen:expect([[
1622    {7:  }a        │{7:  }a        │{7:  }^a        |
1623    {7:  }{27:b}{4:        }│{7:  }{27:x}{4:        }│{7:  }{27:y}{4:        }|
1624    {7:  }c        │{7:  }c        │{7:  }c        |
1625    {1:~          }│{1:~          }│{1:~          }|*15
1626    {2:Xdifile1    Xdifile2    }{3:Xdifile3   }|
1627                                       |
1628  ]])
1629
1630  WriteDiffFiles3('a\nb\nc', 'a\nx\nc', 'a\nb\ny')
1631  screen:expect([[
1632    {7:  }a        │{7:  }a        │{7:  }^a        |
1633    {7:  }{27:b}{4:        }│{7:  }{27:x}{4:        }│{7:  }{27:b}{4:        }|
1634    {7:  }{27:c}{4:        }│{7:  }{27:c}{4:        }│{7:  }{27:y}{4:        }|
1635    {1:~          }│{1:~          }│{1:~          }|*15
1636    {2:Xdifile1    Xdifile2    }{3:Xdifile3   }|
1637                                       |
1638  ]])
1639
1640  WriteDiffFiles3('a\nb\nc', 'a\nx\nc', 'y\ny\nc')
1641  screen:expect([[
1642    {7:  }{27:a}{4:        }│{7:  }{27:a}{4:        }│{7:  }{27:^y}{4:        }|
1643    {7:  }{27:b}{4:        }│{7:  }{27:x}{4:        }│{7:  }{27:y}{4:        }|
1644    {7:  }c        │{7:  }c        │{7:  }c        |
1645    {1:~          }│{1:~          }│{1:~          }|*15
1646    {2:Xdifile1    Xdifile2    }{3:Xdifile3   }|
1647                                       |
1648  ]])
1649
1650  WriteDiffFiles3('a\nb\nc', 'a\nx\nc', 'a\ny\ny')
1651  screen:expect([[
1652    {7:  }a        │{7:  }a        │{7:  }^a        |
1653    {7:  }{27:b}{4:        }│{7:  }{27:x}{4:        }│{7:  }{27:y}{4:        }|
1654    {7:  }{27:c}{4:        }│{7:  }{27:c}{4:        }│{7:  }{27:y}{4:        }|
1655    {1:~          }│{1:~          }│{1:~          }|*15
1656    {2:Xdifile1    Xdifile2    }{3:Xdifile3   }|
1657                                       |
1658  ]])
1659
1660  WriteDiffFiles3('a\nb\nc', 'a\nx\nc', 'y\ny\ny')
1661  screen:expect([[
1662    {7:  }{27:a}{4:        }│{7:  }{27:a}{4:        }│{7:  }{27:^y}{4:        }|
1663    {7:  }{27:b}{4:        }│{7:  }{27:x}{4:        }│{7:  }{27:y}{4:        }|
1664    {7:  }{27:c}{4:        }│{7:  }{27:c}{4:        }│{7:  }{27:y}{4:        }|
1665    {1:~          }│{1:~          }│{1:~          }|*15
1666    {2:Xdifile1    Xdifile2    }{3:Xdifile3   }|
1667                                       |
1668  ]])
1669
1670  WriteDiffFiles3('a\nb\nc', 'a\nx\nx', 'y\ny\nc')
1671  screen:expect([[
1672    {7:  }{27:a}{4:        }│{7:  }{27:a}{4:        }│{7:  }{27:^y}{4:        }|
1673    {7:  }{27:b}{4:        }│{7:  }{27:x}{4:        }│{7:  }{27:y}{4:        }|
1674    {7:  }{27:c}{4:        }│{7:  }{27:x}{4:        }│{7:  }{27:c}{4:        }|
1675    {1:~          }│{1:~          }│{1:~          }|*15
1676    {2:Xdifile1    Xdifile2    }{3:Xdifile3   }|
1677                                       |
1678  ]])
1679
1680  WriteDiffFiles3('a\nb\nc', 'x\nx\nc', 'a\ny\ny')
1681  screen:expect([[
1682    {7:  }{27:a}{4:        }│{7:  }{27:x}{4:        }│{7:  }{27:^a}{4:        }|
1683    {7:  }{27:b}{4:        }│{7:  }{27:x}{4:        }│{7:  }{27:y}{4:        }|
1684    {7:  }{27:c}{4:        }│{7:  }{27:c}{4:        }│{7:  }{27:y}{4:        }|
1685    {1:~          }│{1:~          }│{1:~          }|*15
1686    {2:Xdifile1    Xdifile2    }{3:Xdifile3   }|
1687                                       |
1688  ]])
1689
1690  WriteDiffFiles3('a\nb\nc\nd\ne', 'a\nx\nc\nx\ne', 'y\ny\ny\nd\ne')
1691  screen:expect([[
1692    {7:  }{27:a}{4:        }│{7:  }{27:a}{4:        }│{7:  }{27:^y}{4:        }|
1693    {7:  }{27:b}{4:        }│{7:  }{27:x}{4:        }│{7:  }{27:y}{4:        }|
1694    {7:  }{27:c}{4:        }│{7:  }{27:c}{4:        }│{7:  }{27:y}{4:        }|
1695    {7:  }{27:d}{4:        }│{7:  }{27:x}{4:        }│{7:  }{27:d}{4:        }|
1696    {7:  }e        │{7:  }e        │{7:  }e        |
1697    {1:~          }│{1:~          }│{1:~          }|*13
1698    {2:Xdifile1    Xdifile2    }{3:Xdifile3   }|
1699                                       |
1700  ]])
1701
1702  WriteDiffFiles3('a\nb\nc\nd\ne', 'a\nx\nc\nx\ne', 'y\ny\ny\ny\ne')
1703  screen:expect([[
1704    {7:  }{27:a}{4:        }│{7:  }{27:a}{4:        }│{7:  }{27:^y}{4:        }|
1705    {7:  }{27:b}{4:        }│{7:  }{27:x}{4:        }│{7:  }{27:y}{4:        }|
1706    {7:  }{27:c}{4:        }│{7:  }{27:c}{4:        }│{7:  }{27:y}{4:        }|
1707    {7:  }{27:d}{4:        }│{7:  }{27:x}{4:        }│{7:  }{27:y}{4:        }|
1708    {7:  }e        │{7:  }e        │{7:  }e        |
1709    {1:~          }│{1:~          }│{1:~          }|*13
1710    {2:Xdifile1    Xdifile2    }{3:Xdifile3   }|
1711                                       |
1712  ]])
1713
1714  WriteDiffFiles3('a\nb\nc\nd\ne', 'a\nx\nc\nx\ne', 'y\ny\ny\ny\ny')
1715  screen:expect([[
1716    {7:  }{27:a}{4:        }│{7:  }{27:a}{4:        }│{7:  }{27:^y}{4:        }|
1717    {7:  }{27:b}{4:        }│{7:  }{27:x}{4:        }│{7:  }{27:y}{4:        }|
1718    {7:  }{27:c}{4:        }│{7:  }{27:c}{4:        }│{7:  }{27:y}{4:        }|
1719    {7:  }{27:d}{4:        }│{7:  }{27:x}{4:        }│{7:  }{27:y}{4:        }|
1720    {7:  }{27:e}{4:        }│{7:  }{27:e}{4:        }│{7:  }{27:y}{4:        }|
1721    {1:~          }│{1:~          }│{1:~          }|*13
1722    {2:Xdifile1    Xdifile2    }{3:Xdifile3   }|
1723                                       |
1724  ]])
1725
1726  WriteDiffFiles3('a\nb\nc\nd\ne', 'a\nx\nc\nx\ne', 'a\ny\ny\nd\ne')
1727  screen:expect([[
1728    {7:  }a        │{7:  }a        │{7:  }^a        |
1729    {7:  }{27:b}{4:        }│{7:  }{27:x}{4:        }│{7:  }{27:y}{4:        }|
1730    {7:  }{27:c}{4:        }│{7:  }{27:c}{4:        }│{7:  }{27:y}{4:        }|
1731    {7:  }{27:d}{4:        }│{7:  }{27:x}{4:        }│{7:  }{27:d}{4:        }|
1732    {7:  }e        │{7:  }e        │{7:  }e        |
1733    {1:~          }│{1:~          }│{1:~          }|*13
1734    {2:Xdifile1    Xdifile2    }{3:Xdifile3   }|
1735                                       |
1736  ]])
1737
1738  WriteDiffFiles3('a\nb\nc\nd\ne', 'a\nx\nc\nx\ne', 'a\ny\ny\ny\ne')
1739  screen:expect([[
1740    {7:  }a        │{7:  }a        │{7:  }^a        |
1741    {7:  }{27:b}{4:        }│{7:  }{27:x}{4:        }│{7:  }{27:y}{4:        }|
1742    {7:  }{27:c}{4:        }│{7:  }{27:c}{4:        }│{7:  }{27:y}{4:        }|
1743    {7:  }{27:d}{4:        }│{7:  }{27:x}{4:        }│{7:  }{27:y}{4:        }|
1744    {7:  }e        │{7:  }e        │{7:  }e        |
1745    {1:~          }│{1:~          }│{1:~          }|*13
1746    {2:Xdifile1    Xdifile2    }{3:Xdifile3   }|
1747                                       |
1748  ]])
1749
1750  WriteDiffFiles3('a\nb\nc\nd\ne', 'a\nx\nc\nx\ne', 'a\ny\ny\ny\ny')
1751  screen:expect([[
1752    {7:  }a        │{7:  }a        │{7:  }^a        |
1753    {7:  }{27:b}{4:        }│{7:  }{27:x}{4:        }│{7:  }{27:y}{4:        }|
1754    {7:  }{27:c}{4:        }│{7:  }{27:c}{4:        }│{7:  }{27:y}{4:        }|
1755    {7:  }{27:d}{4:        }│{7:  }{27:x}{4:        }│{7:  }{27:y}{4:        }|
1756    {7:  }{27:e}{4:        }│{7:  }{27:e}{4:        }│{7:  }{27:y}{4:        }|
1757    {1:~          }│{1:~          }│{1:~          }|*13
1758    {2:Xdifile1    Xdifile2    }{3:Xdifile3   }|
1759                                       |
1760  ]])
1761
1762  WriteDiffFiles3('a\nb\nc\nd\ne', 'a\nx\nc\nx\ne', 'a\nb\ny\nd\ne')
1763  screen:expect([[
1764    {7:  }a        │{7:  }a        │{7:  }^a        |
1765    {7:  }{27:b}{4:        }│{7:  }{27:x}{4:        }│{7:  }{27:b}{4:        }|
1766    {7:  }{27:c}{4:        }│{7:  }{27:c}{4:        }│{7:  }{27:y}{4:        }|
1767    {7:  }{27:d}{4:        }│{7:  }{27:x}{4:        }│{7:  }{27:d}{4:        }|
1768    {7:  }e        │{7:  }e        │{7:  }e        |
1769    {1:~          }│{1:~          }│{1:~          }|*13
1770    {2:Xdifile1    Xdifile2    }{3:Xdifile3   }|
1771                                       |
1772  ]])
1773
1774  WriteDiffFiles3('a\nb\nc\nd\ne', 'a\nx\nc\nx\ne', 'a\nb\ny\ny\ne')
1775  screen:expect([[
1776    {7:  }a        │{7:  }a        │{7:  }^a        |
1777    {7:  }{27:b}{4:        }│{7:  }{27:x}{4:        }│{7:  }{27:b}{4:        }|
1778    {7:  }{27:c}{4:        }│{7:  }{27:c}{4:        }│{7:  }{27:y}{4:        }|
1779    {7:  }{27:d}{4:        }│{7:  }{27:x}{4:        }│{7:  }{27:y}{4:        }|
1780    {7:  }e        │{7:  }e        │{7:  }e        |
1781    {1:~          }│{1:~          }│{1:~          }|*13
1782    {2:Xdifile1    Xdifile2    }{3:Xdifile3   }|
1783                                       |
1784  ]])
1785
1786  WriteDiffFiles3('a\nb\nc\nd\ne', 'a\nx\nc\nx\ne', 'a\nb\ny\ny\ny')
1787  screen:expect([[
1788    {7:  }a        │{7:  }a        │{7:  }^a        |
1789    {7:  }{27:b}{4:        }│{7:  }{27:x}{4:        }│{7:  }{27:b}{4:        }|
1790    {7:  }{27:c}{4:        }│{7:  }{27:c}{4:        }│{7:  }{27:y}{4:        }|
1791    {7:  }{27:d}{4:        }│{7:  }{27:x}{4:        }│{7:  }{27:y}{4:        }|
1792    {7:  }{27:e}{4:        }│{7:  }{27:e}{4:        }│{7:  }{27:y}{4:        }|
1793    {1:~          }│{1:~          }│{1:~          }|*13
1794    {2:Xdifile1    Xdifile2    }{3:Xdifile3   }|
1795                                       |
1796  ]])
1797
1798  WriteDiffFiles3('a\nb', 'x\nb', 'y\ny')
1799  write_file('Xdiin1', 'a\nb')
1800  write_file('Xdinew1', 'x\nb')
1801  write_file('Xdiout1', '1c1')
1802  write_file('Xdiin2', 'a\nb')
1803  write_file('Xdinew2', 'y\ny')
1804  write_file('Xdiout2', '1c1\n2c2')
1805  command('set diffexpr=DiffExprStub()')
1806  screen:expect([[
1807    {7:  }{27:a}{4:        }│{7:  }{27:x}{4:        }│{7:  }{27:^y}{4:        }|
1808    {7:  }{27:b}{4:        }│{7:  }{27:b}{4:        }│{7:  }{27:y}{4:        }|
1809    {1:~          }│{1:~          }│{1:~          }|*16
1810    {2:Xdifile1    Xdifile2    }{3:Xdifile3   }|
1811                                       |
1812  ]])
1813  command('set diffexpr&')
1814
1815  WriteDiffFiles3('a\nb\nc\nd', 'x\nb\nx\nd', 'y\ny\nc\nd')
1816  write_file('Xdiin1', 'a\nb\nc\nd')
1817  write_file('Xdinew1', 'x\nb\nx\nd')
1818  write_file('Xdiout1', '1c1\n3c3')
1819  write_file('Xdiin2', 'a\nb\nc\nd')
1820  write_file('Xdinew2', 'y\ny\nc\nd')
1821  write_file('Xdiout2', '1c1\n2c2')
1822  command('set diffexpr=DiffExprStub()')
1823  screen:expect([[
1824    {7:  }{27:a}{4:        }│{7:  }{27:x}{4:        }│{7:  }{27:^y}{4:        }|
1825    {7:  }{27:b}{4:        }│{7:  }{27:b}{4:        }│{7:  }{27:y}{4:        }|
1826    {7:  }{27:c}{4:        }│{7:  }{27:x}{4:        }│{7:  }{27:c}{4:        }|
1827    {7:  }d        │{7:  }d        │{7:  }d        |
1828    {1:~          }│{1:~          }│{1:~          }|*14
1829    {2:Xdifile1    Xdifile2    }{3:Xdifile3   }|
1830                                       |
1831  ]])
1832  command('set diffexpr&')
1833
1834  WriteDiffFiles3('a\nb\nc\nd', 'x\nb\nx\nd', 'y\ny\ny\nd')
1835  write_file('Xdiin1', 'a\nb\nc\nd')
1836  write_file('Xdinew1', 'x\nb\nx\nd')
1837  write_file('Xdiout1', '1c1\n3c3')
1838  write_file('Xdiin2', 'a\nb\nc\nd')
1839  write_file('Xdinew2', 'y\ny\ny\nd')
1840  write_file('Xdiout2', '1c1\n2,3c2,3')
1841  command('set diffexpr=DiffExprStub()')
1842  screen:expect([[
1843    {7:  }{27:a}{4:        }│{7:  }{27:x}{4:        }│{7:  }{27:^y}{4:        }|
1844    {7:  }{27:b}{4:        }│{7:  }{27:b}{4:        }│{7:  }{27:y}{4:        }|
1845    {7:  }{27:c}{4:        }│{7:  }{27:x}{4:        }│{7:  }{27:y}{4:        }|
1846    {7:  }d        │{7:  }d        │{7:  }d        |
1847    {1:~          }│{1:~          }│{1:~          }|*14
1848    {2:Xdifile1    Xdifile2    }{3:Xdifile3   }|
1849                                       |
1850  ]])
1851  command('set diffexpr&')
1852
1853  WriteDiffFiles3('a\nb\nc\nd', 'x\nb\nx\nd', 'y\ny\ny\ny')
1854  write_file('Xdiin1', 'a\nb\nc\nd')
1855  write_file('Xdinew1', 'x\nb\nx\nd')
1856  write_file('Xdiout1', '1c1\n3c3')
1857  write_file('Xdiin2', 'a\nb\nc\nd')
1858  write_file('Xdinew2', 'y\ny\ny\ny')
1859  write_file('Xdiout2', '1c1\n2,4c2,4')
1860  command('set diffexpr=DiffExprStub()')
1861  screen:expect([[
1862    {7:  }{27:a}{4:        }│{7:  }{27:x}{4:        }│{7:  }{27:^y}{4:        }|
1863    {7:  }{27:b}{4:        }│{7:  }{27:b}{4:        }│{7:  }{27:y}{4:        }|
1864    {7:  }{27:c}{4:        }│{7:  }{27:x}{4:        }│{7:  }{27:y}{4:        }|
1865    {7:  }{27:d}{4:        }│{7:  }{27:d}{4:        }│{7:  }{27:y}{4:        }|
1866    {1:~          }│{1:~          }│{1:~          }|*14
1867    {2:Xdifile1    Xdifile2    }{3:Xdifile3   }|
1868                                       |
1869  ]])
1870  command('set diffexpr&')
1871
1872  WriteDiffFiles3('a\nb\nc', 'a\nx\nc', 'b\nc')
1873  screen:expect([[
1874    {7:  }{27:a}{4:        }│{7:  }{27:a}{4:        }│{7:  }{27:^b}{4:        }|
1875    {7:  }{27:b}{4:        }│{7:  }{27:x}{4:        }│{7:  }{23:---------}|
1876    {7:  }c        │{7:  }c        │{7:  }c        |
1877    {1:~          }│{1:~          }│{1:~          }|*15
1878    {2:Xdifile1    Xdifile2    }{3:Xdifile3   }|
1879                                       |
1880  ]])
1881
1882  WriteDiffFiles3('a\nb\nc', 'a\nx\nc', 'c')
1883  screen:expect([[
1884    {7:  }{4:a        }│{7:  }{4:a        }│{7:  }{23:---------}|
1885    {7:  }{27:b}{4:        }│{7:  }{27:x}{4:        }│{7:  }{23:---------}|
1886    {7:  }c        │{7:  }c        │{7:  }^c        |
1887    {1:~          }│{1:~          }│{1:~          }|*15
1888    {2:Xdifile1    Xdifile2    }{3:Xdifile3   }|
1889                                       |
1890  ]])
1891
1892  WriteDiffFiles3('a\nb\nc', 'a\nx\nc', '')
1893  screen:expect([[
1894    {7:  }{4:a        }│{7:  }{4:a        }│{7:  }{23:---------}|
1895    {7:  }{27:b}{4:        }│{7:  }{27:x}{4:        }│{7:  }{23:---------}|
1896    {7:  }{4:c        }│{7:  }{4:c        }│{7:  }{23:---------}|
1897    {1:~          }│{1:~          }│{7:  }^         |
1898    {1:~          }│{1:~          }│{1:~          }|*14
1899    {2:Xdifile1    Xdifile2    }{3:Xdifile3   }|
1900                                       |
1901  ]])
1902
1903  WriteDiffFiles3('a\nb\nc', 'a\nx\nc', 'a\nc')
1904  screen:expect([[
1905    {7:  }a        │{7:  }a        │{7:  }^a        |
1906    {7:  }{27:b}{4:        }│{7:  }{27:x}{4:        }│{7:  }{23:---------}|
1907    {7:  }c        │{7:  }c        │{7:  }c        |
1908    {1:~          }│{1:~          }│{1:~          }|*15
1909    {2:Xdifile1    Xdifile2    }{3:Xdifile3   }|
1910                                       |
1911  ]])
1912
1913  WriteDiffFiles3('a\nb\nc', 'a\nx\nc', 'a')
1914  screen:expect([[
1915    {7:  }a        │{7:  }a        │{7:  }^a        |
1916    {7:  }{27:b}{4:        }│{7:  }{27:x}{4:        }│{7:  }{23:---------}|
1917    {7:  }{4:c        }│{7:  }{4:c        }│{7:  }{23:---------}|
1918    {1:~          }│{1:~          }│{1:~          }|*15
1919    {2:Xdifile1    Xdifile2    }{3:Xdifile3   }|
1920                                       |
1921  ]])
1922
1923  WriteDiffFiles3('a\nb\nc', 'a\nx\nc', 'b')
1924  screen:expect([[
1925    {7:  }{27:a}{4:        }│{7:  }{27:a}{4:        }│{7:  }{27:^b}{4:        }|
1926    {7:  }{27:b}{4:        }│{7:  }{27:x}{4:        }│{7:  }{23:---------}|
1927    {7:  }{4:c        }│{7:  }{4:c        }│{7:  }{23:---------}|
1928    {1:~          }│{1:~          }│{1:~          }|*15
1929    {2:Xdifile1    Xdifile2    }{3:Xdifile3   }|
1930                                       |
1931  ]])
1932
1933  WriteDiffFiles3('a\nb\nc\nd\ne', 'a\nx\nc\nx\ne', 'd\ne')
1934  screen:expect([[
1935    {7:  }{27:a}{4:        }│{7:  }{27:a}{4:        }│{7:  }{27:^d}{4:        }|
1936    {7:  }{27:b}{4:        }│{7:  }{27:x}{4:        }│{7:  }{23:---------}|
1937    {7:  }{4:c        }│{7:  }{4:c        }│{7:  }{23:---------}|
1938    {7:  }{27:d}{4:        }│{7:  }{27:x}{4:        }│{7:  }{23:---------}|
1939    {7:  }e        │{7:  }e        │{7:  }e        |
1940    {1:~          }│{1:~          }│{1:~          }|*13
1941    {2:Xdifile1    Xdifile2    }{3:Xdifile3   }|
1942                                       |
1943  ]])
1944
1945  WriteDiffFiles3('a\nb\nc\nd\ne', 'a\nx\nc\nx\ne', 'e')
1946  screen:expect([[
1947    {7:  }{4:a        }│{7:  }{4:a        }│{7:  }{23:---------}|
1948    {7:  }{27:b}{4:        }│{7:  }{27:x}{4:        }│{7:  }{23:---------}|
1949    {7:  }{4:c        }│{7:  }{4:c        }│{7:  }{23:---------}|
1950    {7:  }{27:d}{4:        }│{7:  }{27:x}{4:        }│{7:  }{23:---------}|
1951    {7:  }e        │{7:  }e        │{7:  }^e        |
1952    {1:~          }│{1:~          }│{1:~          }|*13
1953    {2:Xdifile1    Xdifile2    }{3:Xdifile3   }|
1954                                       |
1955  ]])
1956
1957  WriteDiffFiles3('a\nb\nc\nd\ne', 'a\nx\nc\nx\ne', 'a\nd\ne')
1958  screen:expect([[
1959    {7:  }a        │{7:  }a        │{7:  }^a        |
1960    {7:  }{27:b}{4:        }│{7:  }{27:x}{4:        }│{7:  }{27:d}{4:        }|
1961    {7:  }{4:c        }│{7:  }{4:c        }│{7:  }{23:---------}|
1962    {7:  }{27:d}{4:        }│{7:  }{27:x}{4:        }│{7:  }{23:---------}|
1963    {7:  }e        │{7:  }e        │{7:  }e        |
1964    {1:~          }│{1:~          }│{1:~          }|*13
1965    {2:Xdifile1    Xdifile2    }{3:Xdifile3   }|
1966                                       |
1967  ]])
1968
1969  WriteDiffFiles3('a\nb\nc\nd\ne', 'a\nx\nc\nx\ne', 'a\ne')
1970  screen:expect([[
1971    {7:  }a        │{7:  }a        │{7:  }^a        |
1972    {7:  }{27:b}{4:        }│{7:  }{27:x}{4:        }│{7:  }{23:---------}|
1973    {7:  }{4:c        }│{7:  }{4:c        }│{7:  }{23:---------}|
1974    {7:  }{27:d}{4:        }│{7:  }{27:x}{4:        }│{7:  }{23:---------}|
1975    {7:  }e        │{7:  }e        │{7:  }e        |
1976    {1:~          }│{1:~          }│{1:~          }|*13
1977    {2:Xdifile1    Xdifile2    }{3:Xdifile3   }|
1978                                       |
1979  ]])
1980
1981  WriteDiffFiles3('a\nb\nc\nd\ne', 'a\nx\nc\nx\ne', 'a')
1982  screen:expect([[
1983    {7:  }a        │{7:  }a        │{7:  }^a        |
1984    {7:  }{27:b}{4:        }│{7:  }{27:x}{4:        }│{7:  }{23:---------}|
1985    {7:  }{4:c        }│{7:  }{4:c        }│{7:  }{23:---------}|
1986    {7:  }{27:d}{4:        }│{7:  }{27:x}{4:        }│{7:  }{23:---------}|
1987    {7:  }{4:e        }│{7:  }{4:e        }│{7:  }{23:---------}|
1988    {1:~          }│{1:~          }│{1:~          }|*13
1989    {2:Xdifile1    Xdifile2    }{3:Xdifile3   }|
1990                                       |
1991  ]])
1992
1993  WriteDiffFiles3('a\nb\nc\nd\ne', 'a\nx\nc\nx\ne', 'a\nb\nd\ne')
1994  screen:expect([[
1995    {7:  }a        │{7:  }a        │{7:  }^a        |
1996    {7:  }{27:b}{4:        }│{7:  }{27:x}{4:        }│{7:  }{27:b}{4:        }|
1997    {7:  }{27:c}{4:        }│{7:  }{27:c}{4:        }│{7:  }{27:d}{4:        }|
1998    {7:  }{27:d}{4:        }│{7:  }{27:x}{4:        }│{7:  }{23:---------}|
1999    {7:  }e        │{7:  }e        │{7:  }e        |
2000    {1:~          }│{1:~          }│{1:~          }|*13
2001    {2:Xdifile1    Xdifile2    }{3:Xdifile3   }|
2002                                       |
2003  ]])
2004
2005  WriteDiffFiles3('a\nb\nc\nd\ne', 'a\nx\nc\nx\ne', 'a\nb\ne')
2006  screen:expect([[
2007    {7:  }a        │{7:  }a        │{7:  }^a        |
2008    {7:  }{27:b}{4:        }│{7:  }{27:x}{4:        }│{7:  }{27:b}{4:        }|
2009    {7:  }{4:c        }│{7:  }{4:c        }│{7:  }{23:---------}|
2010    {7:  }{27:d}{4:        }│{7:  }{27:x}{4:        }│{7:  }{23:---------}|
2011    {7:  }e        │{7:  }e        │{7:  }e        |
2012    {1:~          }│{1:~          }│{1:~          }|*13
2013    {2:Xdifile1    Xdifile2    }{3:Xdifile3   }|
2014                                       |
2015  ]])
2016
2017  WriteDiffFiles3('a\nb\nc\nd\ne', 'a\nx\nc\nx\ne', 'a\nb')
2018  screen:expect([[
2019    {7:  }a        │{7:  }a        │{7:  }^a        |
2020    {7:  }{27:b}{4:        }│{7:  }{27:x}{4:        }│{7:  }{27:b}{4:        }|
2021    {7:  }{4:c        }│{7:  }{4:c        }│{7:  }{23:---------}|
2022    {7:  }{27:d}{4:        }│{7:  }{27:x}{4:        }│{7:  }{23:---------}|
2023    {7:  }{4:e        }│{7:  }{4:e        }│{7:  }{23:---------}|
2024    {1:~          }│{1:~          }│{1:~          }|*13
2025    {2:Xdifile1    Xdifile2    }{3:Xdifile3   }|
2026                                       |
2027  ]])
2028
2029  WriteDiffFiles3('a\nb\nc', 'a\nx\nc', 'a\ny\nb\nc')
2030  screen:expect([[
2031    {7:  }a        │{7:  }a        │{7:  }^a        |
2032    {7:  }{27:b}{4:        }│{7:  }{27:x}{4:        }│{7:  }{27:y}{4:        }|
2033    {7:  }{23:---------}│{7:  }{23:---------}│{7:  }{22:b        }|
2034    {7:  }c        │{7:  }c        │{7:  }c        |
2035    {1:~          }│{1:~          }│{1:~          }|*14
2036    {2:Xdifile1    Xdifile2    }{3:Xdifile3   }|
2037                                       |
2038  ]])
2039
2040  WriteDiffFiles3('a\nb\nc', 'a\nx\nc', 'a\nb\ny\nc')
2041  screen:expect([[
2042    {7:  }a        │{7:  }a        │{7:  }^a        |
2043    {7:  }{27:b}{4:        }│{7:  }{27:x}{4:        }│{7:  }{27:b}{4:        }|
2044    {7:  }{23:---------}│{7:  }{23:---------}│{7:  }{22:y        }|
2045    {7:  }c        │{7:  }c        │{7:  }c        |
2046    {1:~          }│{1:~          }│{1:~          }|*14
2047    {2:Xdifile1    Xdifile2    }{3:Xdifile3   }|
2048                                       |
2049  ]])
2050
2051  WriteDiffFiles3('a\nb\nc', 'd\ne', 'b\nf')
2052  screen:expect([[
2053    {7:  }{27:a}{4:        }│{7:  }{27:d}{4:        }│{7:  }{27:^b}{4:        }|
2054    {7:  }{27:b}{4:        }│{7:  }{27:e}{4:        }│{7:  }{27:f}{4:        }|
2055    {7:  }{22:c        }│{7:  }{23:---------}│{7:  }{23:---------}|
2056    {1:~          }│{1:~          }│{1:~          }|*15
2057    {2:Xdifile1    Xdifile2    }{3:Xdifile3   }|
2058                                       |
2059  ]])
2060
2061  WriteDiffFiles3('a\nb\nc', 'd\ne', 'b')
2062  screen:expect([[
2063    {7:  }{27:a}{4:        }│{7:  }{27:d}{4:        }│{7:  }{27:^b}{4:        }|
2064    {7:  }{27:b}{4:        }│{7:  }{27:e}{4:        }│{7:  }{23:---------}|
2065    {7:  }{22:c        }│{7:  }{23:---------}│{7:  }{23:---------}|
2066    {1:~          }│{1:~          }│{1:~          }|*15
2067    {2:Xdifile1    Xdifile2    }{3:Xdifile3   }|
2068                                       |
2069  ]])
2070
2071  -- File 3 overlaps twice, 2nd overlap completely within the existing block.
2072  WriteDiffFiles3('foo\na\nb\nc\nbar', 'foo\nw\nx\ny\nz\nbar', 'foo\n1\na\nb\n2\nbar')
2073  screen:expect([[
2074    {7:  }foo      │{7:  }foo      │{7:  }^foo      |
2075    {7:  }{27:a}{4:        }│{7:  }{27:w}{4:        }│{7:  }{27:1}{4:        }|
2076    {7:  }{27:b}{4:        }│{7:  }{27:x}{4:        }│{7:  }{27:a}{4:        }|
2077    {7:  }{27:c}{4:        }│{7:  }{27:y}{4:        }│{7:  }{27:b}{4:        }|
2078    {7:  }{23:---------}│{7:  }{27:z}{4:        }│{7:  }{27:2}{4:        }|
2079    {7:  }bar      │{7:  }bar      │{7:  }bar      |
2080    {1:~          }│{1:~          }│{1:~          }|*12
2081    {2:Xdifile1    Xdifile2    }{3:Xdifile3   }|
2082                                       |
2083  ]])
2084
2085  -- File 3 overlaps twice, 2nd overlap extends beyond existing block on new
2086  -- side. Make sure we don't over-extend the range and hit 'bar'.
2087  WriteDiffFiles3('foo\na\nb\nc\nd\nbar', 'foo\nw\nx\ny\nz\nu\nbar', 'foo\n1\na\nb\n2\nd\nbar')
2088  screen:expect([[
2089    {7:  }foo      │{7:  }foo      │{7:  }^foo      |
2090    {7:  }{27:a}{4:        }│{7:  }{27:w}{4:        }│{7:  }{27:1}{4:        }|
2091    {7:  }{27:b}{4:        }│{7:  }{27:x}{4:        }│{7:  }{27:a}{4:        }|
2092    {7:  }{27:c}{4:        }│{7:  }{27:y}{4:        }│{7:  }{27:b}{4:        }|
2093    {7:  }{27:d}{4:        }│{7:  }{27:z}{4:        }│{7:  }{27:2}{4:        }|
2094    {7:  }{23:---------}│{7:  }{27:u}{4:        }│{7:  }{27:d}{4:        }|
2095    {7:  }bar      │{7:  }bar      │{7:  }bar      |
2096    {1:~          }│{1:~          }│{1:~          }|*11
2097    {2:Xdifile1    Xdifile2    }{3:Xdifile3   }|
2098                                       |
2099  ]])
2100
2101  -- Chained overlaps. File 3's 2nd overlap spans two diff blocks and is longer
2102  -- than the 2nd one.
2103  WriteDiffFiles3(
2104    'foo\na\nb\nc\nd\ne\nf\nbar',
2105    'foo\nw\nx\ny\nz\ne\nu\nbar',
2106    'foo\n1\nb\n2\n3\nd\n4\nf\nbar'
2107  )
2108  screen:expect([[
2109    {7:  }foo      │{7:  }foo      │{7:  }^foo      |
2110    {7:  }{27:a}{4:        }│{7:  }{27:w}{4:        }│{7:  }{27:1}{4:        }|
2111    {7:  }{27:b}{4:        }│{7:  }{27:x}{4:        }│{7:  }{27:b}{4:        }|
2112    {7:  }{27:c}{4:        }│{7:  }{27:y}{4:        }│{7:  }{27:2}{4:        }|
2113    {7:  }{27:d}{4:        }│{7:  }{27:z}{4:        }│{7:  }{27:3}{4:        }|
2114    {7:  }{27:e}{4:        }│{7:  }{27:e}{4:        }│{7:  }{27:d}{4:        }|
2115    {7:  }{27:f}{4:        }│{7:  }{27:u}{4:        }│{7:  }{27:4}{4:        }|
2116    {7:  }{23:---------}│{7:  }{23:---------}│{7:  }{22:f        }|
2117    {7:  }bar      │{7:  }bar      │{7:  }bar      |
2118    {1:~          }│{1:~          }│{1:~          }|*9
2119    {2:Xdifile1    Xdifile2    }{3:Xdifile3   }|
2120                                       |
2121  ]])
2122
2123  -- File 3 has 2 overlaps. An add and a delete. First overlap's expansion hits
2124  -- the 2nd one. Make sure we adjust the diff block to have fewer lines.
2125  WriteDiffFiles3('foo\na\nb\nbar', 'foo\nx\ny\nbar', 'foo\n1\na\nbar')
2126  screen:expect([[
2127    {7:  }foo      │{7:  }foo      │{7:  }^foo      |
2128    {7:  }{27:a}{4:        }│{7:  }{27:x}{4:        }│{7:  }{27:1}{4:        }|
2129    {7:  }{27:b}{4:        }│{7:  }{27:y}{4:        }│{7:  }{27:a}{4:        }|
2130    {7:  }bar      │{7:  }bar      │{7:  }bar      |
2131    {1:~          }│{1:~          }│{1:~          }|*14
2132    {2:Xdifile1    Xdifile2    }{3:Xdifile3   }|
2133                                       |
2134  ]])
2135
2136  -- File 3 has 2 overlaps. An add and another add. First overlap's expansion hits
2137  -- the 2nd one. Make sure we adjust the diff block to have more lines.
2138  WriteDiffFiles3('foo\na\nb\nc\nd\nbar', 'foo\nw\nx\ny\nz\nu\nbar', 'foo\n1\na\nb\n3\n4\nd\nbar')
2139  screen:expect([[
2140    {7:  }foo      │{7:  }foo      │{7:  }^foo      |
2141    {7:  }{27:a}{4:        }│{7:  }{27:w}{4:        }│{7:  }{27:1}{4:        }|
2142    {7:  }{27:b}{4:        }│{7:  }{27:x}{4:        }│{7:  }{27:a}{4:        }|
2143    {7:  }{27:c}{4:        }│{7:  }{27:y}{4:        }│{7:  }{27:b}{4:        }|
2144    {7:  }{27:d}{4:        }│{7:  }{27:z}{4:        }│{7:  }{27:3}{4:        }|
2145    {7:  }{23:---------}│{7:  }{27:u}{4:        }│{7:  }{27:4}{4:        }|
2146    {7:  }{23:---------}│{7:  }{23:---------}│{7:  }{22:d        }|
2147    {7:  }bar      │{7:  }bar      │{7:  }bar      |
2148    {1:~          }│{1:~          }│{1:~          }|*10
2149    {2:Xdifile1    Xdifile2    }{3:Xdifile3   }|
2150                                       |
2151  ]])
2152end)
2153
2154-- oldtest: Test_diff_topline_noscroll()
2155it('diff mode does not scroll with line("w0")', function()
2156  local screen = Screen.new(45, 20)
2157  exec([[
2158    set scrolloff=5
2159    call setline(1, range(1,60))
2160    vnew
2161    call setline(1, range(1,10) + range(50,60))
2162    windo diffthis
2163    norm! G
2164    exe "norm! 30\<C-y>"
2165  ]])
2166  screen:expect([[
2167    {7:  }9                   │{7:  }9                   |
2168    {7:  }10                  │{7:  }10                  |
2169    {7:  }{23:--------------------}│{7:  }{22:11                  }|
2170    {7:  }{23:--------------------}│{7:  }{22:12                  }|
2171    {7:  }{23:--------------------}│{7:  }{22:13                  }|
2172    {7:  }{23:--------------------}│{7:  }{22:14                  }|
2173    {7:  }{23:--------------------}│{7:  }{22:15                  }|
2174    {7:  }{23:--------------------}│{7:  }{22:16                  }|
2175    {7:  }{23:--------------------}│{7:  }{22:17                  }|
2176    {7:  }{23:--------------------}│{7:  }{22:18                  }|
2177    {7:  }{23:--------------------}│{7:  }{22:19                  }|
2178    {7:  }{23:--------------------}│{7:  }{22:20                  }|
2179    {7:  }{23:--------------------}│{7:  }{22:^21                  }|
2180    {7:  }{23:--------------------}│{7:  }{22:22                  }|
2181    {7:  }{23:--------------------}│{7:  }{22:23                  }|
2182    {7:  }{23:--------------------}│{7:  }{22:24                  }|
2183    {7:  }{23:--------------------}│{7:  }{22:25                  }|
2184    {7:  }{23:--------------------}│{7:  }{22:26                  }|
2185    {2:[No Name] [+]          }{3:[No Name] [+]         }|
2186                                                 |
2187  ]])
2188  command([[echo line('w0', 1001)]])
2189  screen:expect([[
2190    {7:  }9                   │{7:  }9                   |
2191    {7:  }10                  │{7:  }10                  |
2192    {7:  }{23:--------------------}│{7:  }{22:11                  }|
2193    {7:  }{23:--------------------}│{7:  }{22:12                  }|
2194    {7:  }{23:--------------------}│{7:  }{22:13                  }|
2195    {7:  }{23:--------------------}│{7:  }{22:14                  }|
2196    {7:  }{23:--------------------}│{7:  }{22:15                  }|
2197    {7:  }{23:--------------------}│{7:  }{22:16                  }|
2198    {7:  }{23:--------------------}│{7:  }{22:17                  }|
2199    {7:  }{23:--------------------}│{7:  }{22:18                  }|
2200    {7:  }{23:--------------------}│{7:  }{22:19                  }|
2201    {7:  }{23:--------------------}│{7:  }{22:20                  }|
2202    {7:  }{23:--------------------}│{7:  }{22:^21                  }|
2203    {7:  }{23:--------------------}│{7:  }{22:22                  }|
2204    {7:  }{23:--------------------}│{7:  }{22:23                  }|
2205    {7:  }{23:--------------------}│{7:  }{22:24                  }|
2206    {7:  }{23:--------------------}│{7:  }{22:25                  }|
2207    {7:  }{23:--------------------}│{7:  }{22:26                  }|
2208    {2:[No Name] [+]          }{3:[No Name] [+]         }|
2209    9                                            |
2210  ]])
2211  feed('<C-W>p')
2212  screen:expect([[
2213    {7:  }{23:--------------------}│{7:  }{22:39                  }|
2214    {7:  }{23:--------------------}│{7:  }{22:40                  }|
2215    {7:  }{23:--------------------}│{7:  }{22:41                  }|
2216    {7:  }{23:--------------------}│{7:  }{22:42                  }|
2217    {7:  }{23:--------------------}│{7:  }{22:43                  }|
2218    {7:  }{23:--------------------}│{7:  }{22:44                  }|
2219    {7:  }{23:--------------------}│{7:  }{22:45                  }|
2220    {7:  }{23:--------------------}│{7:  }{22:46                  }|
2221    {7:  }{23:--------------------}│{7:  }{22:47                  }|
2222    {7:  }{23:--------------------}│{7:  }{22:48                  }|
2223    {7:  }{23:--------------------}│{7:  }{22:49                  }|
2224    {7:  }^50                  │{7:  }50                  |
2225    {7:  }51                  │{7:  }51                  |
2226    {7:  }52                  │{7:  }52                  |
2227    {7:  }53                  │{7:  }53                  |
2228    {7:  }54                  │{7:  }54                  |
2229    {7:  }55                  │{7:  }55                  |
2230    {7:+ }{13:+--  5 lines: 56····}│{7:+ }{13:+--  5 lines: 56····}|
2231    {3:[No Name] [+]          }{2:[No Name] [+]         }|
2232    9                                            |
2233  ]])
2234  feed('<C-W>p')
2235  screen:expect([[
2236    {7:  }{23:--------------------}│{7:  }{22:39                  }|
2237    {7:  }{23:--------------------}│{7:  }{22:40                  }|
2238    {7:  }{23:--------------------}│{7:  }{22:41                  }|
2239    {7:  }{23:--------------------}│{7:  }{22:42                  }|
2240    {7:  }{23:--------------------}│{7:  }{22:43                  }|
2241    {7:  }{23:--------------------}│{7:  }{22:^44                  }|
2242    {7:  }{23:--------------------}│{7:  }{22:45                  }|
2243    {7:  }{23:--------------------}│{7:  }{22:46                  }|
2244    {7:  }{23:--------------------}│{7:  }{22:47                  }|
2245    {7:  }{23:--------------------}│{7:  }{22:48                  }|
2246    {7:  }{23:--------------------}│{7:  }{22:49                  }|
2247    {7:  }50                  │{7:  }50                  |
2248    {7:  }51                  │{7:  }51                  |
2249    {7:  }52                  │{7:  }52                  |
2250    {7:  }53                  │{7:  }53                  |
2251    {7:  }54                  │{7:  }54                  |
2252    {7:  }55                  │{7:  }55                  |
2253    {7:+ }{13:+--  5 lines: 56····}│{7:+ }{13:+--  5 lines: 56····}|
2254    {2:[No Name] [+]          }{3:[No Name] [+]         }|
2255    9                                            |
2256  ]])
2257end)
2258
2259-- oldtest: Test_diff_inline()
2260it('diff mode inline highlighting', function()
2261  write_file('Xdifile1', '')
2262  write_file('Xdifile2', '')
2263  finally(function()
2264    os.remove('Xdifile1')
2265    os.remove('Xdifile2')
2266  end)
2267
2268  local screen = Screen.new(37, 20)
2269  screen:add_extra_attr_ids({
2270    [100] = { background = Screen.colors.Blue1 },
2271    [101] = { bold = true, background = Screen.colors.Red, foreground = Screen.colors.Blue1 },
2272    [102] = { background = Screen.colors.LightMagenta, foreground = Screen.colors.Blue1 },
2273    [103] = { bold = true, background = Screen.colors.Blue1, foreground = Screen.colors.Blue1 },
2274    [104] = { bold = true, background = Screen.colors.LightBlue, foreground = Screen.colors.Blue1 },
2275  })
2276  command('set winwidth=10')
2277  command('args Xdifile1 Xdifile2 | vert all | windo diffthis | 1wincmd w')
2278
2279  WriteDiffFiles('abcdef ghi jk n\nx\ny', 'aBcef gHi lm n\ny\nz')
2280  command('set diffopt=internal,filler')
2281  local s1 = [[
2282    {7:  }{4:^a}{27:bcdef ghi jk}{4: n }│{7:  }{4:a}{27:Bcef gHi lm}{4: n  }|
2283    {7:  }{22:x               }│{7:  }{23:----------------}|
2284    {7:  }y               │{7:  }y               |
2285    {7:  }{23:----------------}│{7:  }{22:z               }|
2286    {1:~                 }│{1:~                 }|*14
2287    {3:Xdifile1           }{2:Xdifile2          }|
2288                                         |
2289  ]]
2290  screen:expect(s1)
2291  command('set diffopt=internal,filler diffopt+=inline:none')
2292  local s2 = [[
2293    {7:  }{4:^abcdef ghi jk n }│{7:  }{4:aBcef gHi lm n  }|
2294    {7:  }{22:x               }│{7:  }{23:----------------}|
2295    {7:  }y               │{7:  }y               |
2296    {7:  }{23:----------------}│{7:  }{22:z               }|
2297    {1:~                 }│{1:~                 }|*14
2298    {3:Xdifile1           }{2:Xdifile2          }|
2299                                         |
2300  ]]
2301  screen:expect(s2)
2302
2303  -- inline:simple is the same as default
2304  command('set diffopt=internal,filler diffopt+=inline:simple')
2305  screen:expect(s1)
2306
2307  command('set diffopt=internal,filler diffopt+=inline:char')
2308  local s3 = [[
2309    {7:  }{4:^a}{27:b}{4:c}{27:d}{4:ef g}{27:h}{4:i }{27:jk}{4: n }│{7:  }{4:a}{27:B}{4:cef g}{27:H}{4:i }{27:lm}{4: n  }|
2310    {7:  }{22:x               }│{7:  }{23:----------------}|
2311    {7:  }y               │{7:  }y               |
2312    {7:  }{23:----------------}│{7:  }{22:z               }|
2313    {1:~                 }│{1:~                 }|*14
2314    {3:Xdifile1           }{2:Xdifile2          }|
2315                                         |
2316  ]]
2317  screen:expect(s3)
2318
2319  command('set diffopt=internal,filler diffopt+=inline:word')
2320  screen:expect([[
2321    {7:  }{27:^abcdef ghi jk}{4: n }│{7:  }{27:aBcef gHi lm}{4: n  }|
2322    {7:  }{22:x               }│{7:  }{23:----------------}|
2323    {7:  }y               │{7:  }y               |
2324    {7:  }{23:----------------}│{7:  }{22:z               }|
2325    {1:~                 }│{1:~                 }|*14
2326    {3:Xdifile1           }{2:Xdifile2          }|
2327                                         |
2328  ]])
2329
2330  -- multiple inline values will the last one
2331  command('set diffopt=internal,filler diffopt+=inline:none,inline:char,inline:simple')
2332  screen:expect(s1)
2333  command('set diffopt=internal,filler diffopt+=inline:simple,inline:word,inline:none')
2334  screen:expect(s2)
2335  command('set diffopt=internal,filler diffopt+=inline:simple,inline:word,inline:char')
2336  screen:expect(s3)
2337
2338  -- DiffTextAdd highlight
2339  command('hi DiffTextAdd guibg=blue')
2340  command('set diffopt=internal,filler diffopt+=inline:char')
2341  screen:expect([[
2342    {7:  }{4:^a}{27:b}{4:c}{100:d}{4:ef g}{27:h}{4:i }{27:jk}{4: n }│{7:  }{4:a}{27:B}{4:cef g}{27:H}{4:i }{27:lm}{4: n  }|
2343    {7:  }{22:x               }│{7:  }{23:----------------}|
2344    {7:  }y               │{7:  }y               |
2345    {7:  }{23:----------------}│{7:  }{22:z               }|
2346    {1:~                 }│{1:~                 }|*14
2347    {3:Xdifile1           }{2:Xdifile2          }|
2348                                         |
2349  ]])
2350
2351  -- Live update in insert mode
2352  feed('isometext')
2353  screen:expect([[
2354    {7:  }{27:sometext^abcd}{4:ef g}│{7:  }{27:aBc}{4:ef g}{27:H}{4:i }{27:lm}{4: n  }|
2355    {7:  }{22:x               }│{7:  }{23:----------------}|
2356    {7:  }y               │{7:  }y               |
2357    {7:  }{23:----------------}│{7:  }{22:z               }|
2358    {1:~                 }│{1:~                 }|*14
2359    {3:Xdifile1 [+]       }{2:Xdifile2          }|
2360    {5:-- INSERT --}                         |
2361  ]])
2362  feed('<Esc>')
2363  command('silent! undo')
2364
2365  -- icase simple scenarios
2366  command('set diffopt=internal,filler diffopt+=inline:simple,icase')
2367  screen:expect([[
2368    {7:  }{4:^abc}{27:def ghi jk}{4: n }│{7:  }{4:aBc}{27:ef gHi lm}{4: n  }|
2369    {7:  }{22:x               }│{7:  }{23:----------------}|
2370    {7:  }y               │{7:  }y               |
2371    {7:  }{23:----------------}│{7:  }{22:z               }|
2372    {1:~                 }│{1:~                 }|*14
2373    {3:Xdifile1           }{2:Xdifile2          }|
2374                                         |
2375  ]])
2376  command('set diffopt=internal,filler diffopt+=inline:char,icase')
2377  screen:expect([[
2378    {7:  }{4:^abc}{100:d}{4:ef ghi }{27:jk}{4: n }│{7:  }{4:aBcef gHi }{27:lm}{4: n  }|
2379    {7:  }{22:x               }│{7:  }{23:----------------}|
2380    {7:  }y               │{7:  }y               |
2381    {7:  }{23:----------------}│{7:  }{22:z               }|
2382    {1:~                 }│{1:~                 }|*14
2383    {3:Xdifile1           }{2:Xdifile2          }|
2384                                         |
2385  ]])
2386  command('set diffopt=internal,filler diffopt+=inline:word,icase')
2387  screen:expect([[
2388    {7:  }{27:^abcdef}{4: ghi }{27:jk}{4: n }│{7:  }{27:aBcef}{4: gHi }{27:lm}{4: n  }|
2389    {7:  }{22:x               }│{7:  }{23:----------------}|
2390    {7:  }y               │{7:  }y               |
2391    {7:  }{23:----------------}│{7:  }{22:z               }|
2392    {1:~                 }│{1:~                 }|*14
2393    {3:Xdifile1           }{2:Xdifile2          }|
2394                                         |
2395  ]])
2396
2397  screen:try_resize(45, 20)
2398  command('wincmd =')
2399  -- diff algorithms should affect highlight
2400  WriteDiffFiles('apples and oranges', 'oranges and apples')
2401  command('set diffopt=internal,filler diffopt+=inline:char')
2402  screen:expect([[
2403    {7:  }{27:^appl}{4:es and }{27:orang}{4:es  }│{7:  }{27:orang}{4:es and }{27:appl}{4:es  }|
2404    {1:~                     }│{1:~                     }|*17
2405    {3:Xdifile1               }{2:Xdifile2              }|
2406                                                 |
2407  ]])
2408  command('set diffopt=internal,filler diffopt+=inline:char,algorithm:patience')
2409  screen:expect([[
2410    {7:  }{100:^apples and }{4:oranges  }│{7:  }{4:oranges}{100: and apples}{4:  }|
2411    {1:~                     }│{1:~                     }|*17
2412    {3:Xdifile1               }{2:Xdifile2              }|
2413                                                 |
2414  ]])
2415
2416  screen:try_resize(65, 20)
2417  command('wincmd =')
2418  -- icase: composing chars and Unicode fold case edge cases
2419  WriteDiffFiles(
2420    '1 - sigma in 6σ and Ὀδυσσεύς\n1 - angstrom in åå\n1 - composing: ii⃗I⃗',
2421    '2 - Sigma in 6Σ and ὈΔΥΣΣΕΎΣ\n2 - Angstrom in ÅÅ\n2 - Composing: i⃗I⃗I⃗'
2422  )
2423  command('set diffopt=internal,filler diffopt+=inline:char')
2424  screen:expect([[
2425    {7:  }{27:^1}{4: - }{27:s}{4:igma in 6}{27:σ}{4: and Ὀ}{27:δυσσεύς}{4:  }│{7:  }{27:2}{4: - }{27:S}{4:igma in 6}{27:Σ}{4: and Ὀ}{27:ΔΥΣΣΕΎΣ}{4:  }|
2426    {7:  }{27:1}{4: - }{27:a}{4:ngstrom in }{27:åå}{4:            }│{7:  }{27:2}{4: - }{27:A}{4:ngstrom in }{27:ÅÅ}{4:            }|
2427    {7:  }{27:1}{4: - }{27:c}{4:omposing: }{100:i}{4:i⃗I⃗            }│{7:  }{27:2}{4: - }{27:C}{4:omposing: i⃗I⃗}{100:I⃗}{4:            }|
2428    {1:~                               }│{1:~                               }|*15
2429    {3:Xdifile1                         }{2:Xdifile2                        }|
2430                                                                     |
2431  ]])
2432  command('set diffopt=internal,filler diffopt+=inline:char,icase')
2433  screen:expect([[
2434    {7:  }{27:^1}{4: - sigma in 6σ and Ὀδυσσεύς  }│{7:  }{27:2}{4: - Sigma in 6Σ and ὈΔΥΣΣΕΎΣ  }|
2435    {7:  }{27:1}{4: - angstrom in åå            }│{7:  }{27:2}{4: - Angstrom in ÅÅ            }|
2436    {7:  }{27:1}{4: - composing: }{27:i}{4:i⃗I⃗            }│{7:  }{27:2}{4: - Composing: }{27:i⃗}{4:I⃗I⃗            }|
2437    {1:~                               }│{1:~                               }|*15
2438    {3:Xdifile1                         }{2:Xdifile2                        }|
2439                                                                     |
2440  ]])
2441
2442  screen:try_resize(35, 20)
2443  command('wincmd =')
2444  -- wide chars
2445  WriteDiffFiles('abc😅xde一\nf🚀g', 'abcy😢de\n二f🚀g')
2446  command('set diffopt=internal,filler diffopt+=inline:char,icase')
2447  screen:expect([[
2448    {7:  }{4:^abc}{27:😅x}{4:de}{100:一}{4:     }│{7:  }{4:abc}{27:y😢}{4:de       }|
2449    {7:  }{4:f🚀g           }│{7:  }{100:二}{4:f🚀g         }|
2450    {1:~                }│{1:~                }|*16
2451    {3:Xdifile1          }{2:Xdifile2         }|
2452                                       |
2453  ]])
2454
2455  -- NUL char
2456  WriteDiffFiles('1\00034\0005\0006', '1234\0005\n6')
2457  command('set diffopt=internal,filler diffopt+=inline:char')
2458  screen:expect([[
2459    {7:  }{4:^1}{101:^@}{4:34}{102:^@}{4:5}{101:^@}{4:6    }│{7:  }{4:1}{27:2}{4:34}{102:^@}{4:5        }|
2460    {7:  }{23:---------------}│{7:  }{4:6              }|
2461    {1:~                }│{1:~                }|*16
2462    {3:Xdifile1          }{2:Xdifile2         }|
2463                                       |
2464  ]])
2465
2466  -- word diff: always use first buffer's iskeyword and ignore others' for consistency
2467  WriteDiffFiles('foo+bar test', 'foo+baz test')
2468  command('set diffopt=internal,filler diffopt+=inline:word')
2469  local sw1 = [[
2470    {7:  }{4:^foo+}{27:bar}{4: test   }│{7:  }{4:foo+}{27:baz}{4: test   }|
2471    {1:~                }│{1:~                }|*17
2472    {3:Xdifile1          }{2:Xdifile2         }|
2473                                       |
2474  ]]
2475  screen:expect(sw1)
2476
2477  command('set iskeyword+=+ | diffupdate')
2478  screen:expect([[
2479    {7:  }{27:^foo+bar}{4: test   }│{7:  }{27:foo+baz}{4: test   }|
2480    {1:~                }│{1:~                }|*17
2481    {3:Xdifile1          }{2:Xdifile2         }|
2482                                       |
2483  ]])
2484
2485  command('set iskeyword& | wincmd w')
2486  command('set iskeyword+=+ | wincmd w | diffupdate')
2487  -- Use the previous screen as 2nd buffer's iskeyword does not matter
2488  screen:expect(sw1)
2489
2490  command('windo set iskeyword& | 1wincmd w')
2491
2492  screen:try_resize(75, 20)
2493  command('wincmd =')
2494  -- word diff: test handling of multi-byte characters. Only alphanumeric chars
2495  -- (e.g. Greek alphabet, but not CJK/emoji) count as words.
2496  WriteDiffFiles(
2497    '🚀⛵️一二三ひらがなΔέλτα Δelta foobar',
2498    '🚀🛸一二四ひらなδέλτα δelta foobar'
2499  )
2500  command('set diffopt=internal,filler diffopt+=inline:word')
2501  screen:expect([[
2502    {7:  }{4:^🚀}{27:⛵️}{4:一二}{27:三}{4:ひら}{27:がなΔέλτα Δelta}{4: fooba}│{7:  }{4:🚀}{27:🛸}{4:一二}{27:四}{4:ひら}{27:なδέλτα δelta}{4: foobar }|
2503    {1:~                                    }│{1:~                                    }|*17
2504    {3:Xdifile1                              }{2:Xdifile2                             }|
2505                                                                               |
2506  ]])
2507
2508  screen:try_resize(69, 20)
2509  command('wincmd =')
2510  -- char diff: should slide highlight to whitespace boundary if possible for
2511  -- better readability (by using forced indent-heuristics). A wrong result
2512  -- would be if the highlight is "Bar, prefix". It should be "prefixBar, "
2513  -- instead.
2514  WriteDiffFiles('prefixFoo, prefixEnd', 'prefixFoo, prefixBar, prefixEnd')
2515  command('set diffopt=internal,filler diffopt+=inline:char')
2516  screen:expect([[
2517    {7:  }{4:^prefixFoo, prefixEnd            }│{7:  }{4:prefixFoo, }{100:prefixBar, }{4:prefixEnd }|
2518    {1:~                                 }│{1:~                                 }|*17
2519    {3:Xdifile1                           }{2:Xdifile2                          }|
2520                                                                         |
2521  ]])
2522
2523  screen:try_resize(39, 20)
2524  command('wincmd =')
2525  -- char diff: small gaps between inline diff blocks will be merged during refine step
2526  -- - first segment: test that we iteratively merge small gaps after we merged
2527  --   adjacent blocks, but only with limited number (set to 4) of iterations.
2528  -- - second and third segments: show that we need a large enough adjacent block to
2529  --   trigger a merge.
2530  -- - fourth segment: small gaps are not merged when adjacent large block is
2531  --   on a different line.
2532  WriteDiffFiles(
2533    'abcdefghijklmno\nanchor1\n'
2534      .. 'abcdefghijklmno\nanchor2\n'
2535      .. 'abcdefghijklmno\nanchor3\n'
2536      .. 'test\nmultiline',
2537    'a?c?e?g?i?k???o\nanchor1\n'
2538      .. 'a??de?????klmno\nanchor2\n'
2539      .. 'a??de??????lmno\nanchor3\n'
2540      .. 't?s?\n??????i?e'
2541  )
2542  command('set diffopt=internal,filler diffopt+=inline:char')
2543  screen:expect([[
2544    {7:  }{4:^a}{27:b}{4:c}{27:defghijklmn}{4:o  }│{7:  }{4:a}{27:?}{4:c}{27:?e?g?i?k???}{4:o  }|
2545    {7:  }anchor1          │{7:  }anchor1          |
2546    {7:  }{4:a}{27:bc}{4:de}{27:fghij}{4:klmno  }│{7:  }{4:a}{27:??}{4:de}{27:?????}{4:klmno  }|
2547    {7:  }anchor2          │{7:  }anchor2          |
2548    {7:  }{4:a}{27:bcdefghijk}{4:lmno  }│{7:  }{4:a}{27:??de??????}{4:lmno  }|
2549    {7:  }anchor3          │{7:  }anchor3          |
2550    {7:  }{4:t}{27:e}{4:s}{27:t}{4:             }│{7:  }{4:t}{27:?}{4:s}{27:?}{4:             }|
2551    {7:  }{27:multilin}{4:e        }│{7:  }{27:??????i?}{4:e        }|
2552    {1:~                  }│{1:~                  }|*10
2553    {3:Xdifile1            }{2:Xdifile2           }|
2554                                           |
2555  ]])
2556
2557  screen:try_resize(49, 20)
2558  command('wincmd =')
2559  -- Test multi-line blocks and whitespace
2560  WriteDiffFiles(
2561    'this   is   \nsometest text foo\nbaz abc def \none\nword another word\nadditional line',
2562    'this is some test\ntexts\nfoo bar abX Yef     \noneword another word'
2563  )
2564  command('set diffopt=internal,filler diffopt+=inline:char,iwhite')
2565  screen:expect([[
2566    {7:  }{4:^this   is             }│{7:  }{4:this is some}{100: }{4:test     }|
2567    {7:  }{4:sometest text foo     }│{7:  }{4:text}{100:s}{4:                 }|
2568    {7:  }{4:ba}{27:z}{4: ab}{27:c}{4: }{27:d}{4:ef           }│{7:  }{4:foo ba}{27:r}{4: ab}{27:X}{4: }{27:Y}{4:ef       }|
2569    {7:  }{4:one                   }│{7:  }{4:oneword another word  }|
2570    {7:  }{4:word another word     }│{7:  }{23:----------------------}|
2571    {7:  }{22:additional line       }│{7:  }{23:----------------------}|
2572    {1:~                       }│{1:~                       }|*12
2573    {3:Xdifile1                 }{2:Xdifile2                }|
2574                                                     |
2575  ]])
2576  command('set diffopt=internal,filler diffopt+=inline:word,iwhite')
2577  screen:expect([[
2578    {7:  }{4:^this   is             }│{7:  }{4:this is }{27:some test}{4:     }|
2579    {7:  }{27:sometest text foo}{4:     }│{7:  }{27:texts}{4:                 }|
2580    {7:  }{27:baz abc def}{4:           }│{7:  }{27:foo bar abX}{4: }{27:Yef}{4:       }|
2581    {7:  }{27:one}{4:                   }│{7:  }{27:oneword}{4: another word  }|
2582    {7:  }{27:word}{4: another word     }│{7:  }{23:----------------------}|
2583    {7:  }{22:additional line       }│{7:  }{23:----------------------}|
2584    {1:~                       }│{1:~                       }|*12
2585    {3:Xdifile1                 }{2:Xdifile2                }|
2586                                                     |
2587  ]])
2588  command('set diffopt=internal,filler diffopt+=inline:char,iwhiteeol')
2589  screen:expect([[
2590    {7:  }{4:^this }{100:  }{4:is             }│{7:  }{4:this is some}{100: }{4:test     }|
2591    {7:  }{4:sometest text foo     }│{7:  }{4:text}{100:s}{4:                 }|
2592    {7:  }{4:ba}{27:z}{4: ab}{27:c}{4: }{27:d}{4:ef           }│{7:  }{4:foo ba}{27:r}{4: ab}{27:X}{4: }{27:Y}{4:ef       }|
2593    {7:  }{4:one                   }│{7:  }{4:oneword another word  }|
2594    {7:  }{4:word another word     }│{7:  }{23:----------------------}|
2595    {7:  }{22:additional line       }│{7:  }{23:----------------------}|
2596    {1:~                       }│{1:~                       }|*12
2597    {3:Xdifile1                 }{2:Xdifile2                }|
2598                                                     |
2599  ]])
2600  command('set diffopt=internal,filler diffopt+=inline:word,iwhiteeol')
2601  screen:expect([[
2602    {7:  }{4:^this }{100:  }{4:is             }│{7:  }{4:this is }{27:some test}{4:     }|
2603    {7:  }{27:sometest text}{4: foo     }│{7:  }{27:texts}{4:                 }|
2604    {7:  }{27:baz abc def}{4:           }│{7:  }{4:foo }{27:bar abX Yef}{4:       }|
2605    {7:  }{27:one}{4:                   }│{7:  }{27:oneword}{4: another word  }|
2606    {7:  }{27:word}{4: another word     }│{7:  }{23:----------------------}|
2607    {7:  }{22:additional line       }│{7:  }{23:----------------------}|
2608    {1:~                       }│{1:~                       }|*12
2609    {3:Xdifile1                 }{2:Xdifile2                }|
2610                                                     |
2611  ]])
2612  command('set diffopt=internal,filler diffopt+=inline:char,iwhiteall')
2613  screen:expect([[
2614    {7:  }{4:^this   is             }│{7:  }{4:this is some test     }|
2615    {7:  }{4:sometest text foo     }│{7:  }{4:text}{100:s}{4:                 }|
2616    {7:  }{4:ba}{27:z}{4: ab}{27:c d}{4:ef           }│{7:  }{4:foo ba}{27:r}{4: ab}{27:X Y}{4:ef       }|
2617    {7:  }{4:one                   }│{7:  }{4:oneword another word  }|
2618    {7:  }{4:word another word     }│{7:  }{23:----------------------}|
2619    {7:  }{22:additional line       }│{7:  }{23:----------------------}|
2620    {1:~                       }│{1:~                       }|*12
2621    {3:Xdifile1                 }{2:Xdifile2                }|
2622                                                     |
2623  ]])
2624  command('set diffopt=internal,filler diffopt+=inline:word,iwhiteall')
2625  screen:expect([[
2626    {7:  }{4:^this   is             }│{7:  }{4:this is }{27:some test}{4:     }|
2627    {7:  }{27:sometest text}{4: foo     }│{7:  }{27:texts}{4:                 }|
2628    {7:  }{27:baz abc def }{4:          }│{7:  }{4:foo }{27:bar abX Yef     }{4:  }|
2629    {7:  }{27:one}{4:                   }│{7:  }{27:oneword}{4: another word  }|
2630    {7:  }{27:word}{4: another word     }│{7:  }{23:----------------------}|
2631    {7:  }{22:additional line       }│{7:  }{23:----------------------}|
2632    {1:~                       }│{1:~                       }|*12
2633    {3:Xdifile1                 }{2:Xdifile2                }|
2634                                                     |
2635  ]])
2636
2637  -- newline should be highlighted too when 'list' is set
2638  command('windo set list listchars=eol:$')
2639  command('set diffopt=internal,filler diffopt+=inline:char')
2640  screen:expect([[
2641    {7:  }{4:this }{100:  }{4:is }{100:  }{103:$}{4:         }│{7:  }{4:^this is some}{100: }{4:test}{101:$}{4:    }|
2642    {7:  }{4:sometest}{27: }{4:text}{27: }{4:foo}{101:$}{4:    }│{7:  }{4:text}{27:s}{101:$}{4:                }|
2643    {7:  }{4:ba}{27:z}{4: ab}{27:c}{4: }{27:d}{4:ef }{11:$}{4:         }│{7:  }{4:foo}{27: }{4:ba}{27:r}{4: ab}{27:X}{4: }{27:Y}{4:ef }{100:    }{11:$}{4: }|
2644    {7:  }{4:one}{103:$}{4:                  }│{7:  }{4:oneword another word}{11:$}{4: }|
2645    {7:  }{4:word another word}{11:$}{4:    }│{7:  }{23:----------------------}|
2646    {7:  }{22:additional line}{104:$}{22:      }│{7:  }{23:----------------------}|
2647    {1:~                       }│{1:~                       }|*12
2648    {2:Xdifile1                 }{3:Xdifile2                }|
2649                                                     |
2650  ]])
2651  command('set diffopt=internal,filler diffopt+=inline:char,iwhite')
2652  screen:expect([[
2653    {7:  }{4:this   is   }{11:$}{4:         }│{7:  }{4:^this is some}{100: }{4:test}{11:$}{4:    }|
2654    {7:  }{4:sometest text foo}{11:$}{4:    }│{7:  }{4:text}{100:s}{11:$}{4:                }|
2655    {7:  }{4:ba}{27:z}{4: ab}{27:c}{4: }{27:d}{4:ef }{11:$}{4:         }│{7:  }{4:foo ba}{27:r}{4: ab}{27:X}{4: }{27:Y}{4:ef     }{11:$}{4: }|
2656    {7:  }{4:one}{103:$}{4:                  }│{7:  }{4:oneword another word}{11:$}{4: }|
2657    {7:  }{4:word another word}{11:$}{4:    }│{7:  }{23:----------------------}|
2658    {7:  }{22:additional line}{104:$}{22:      }│{7:  }{23:----------------------}|
2659    {1:~                       }│{1:~                       }|*12
2660    {2:Xdifile1                 }{3:Xdifile2                }|
2661                                                     |
2662  ]])
2663  command('set diffopt=internal,filler diffopt+=inline:char,iwhiteeol')
2664  screen:expect([[
2665    {7:  }{4:this }{100:  }{4:is   }{11:$}{4:         }│{7:  }{4:^this is some}{100: }{4:test}{11:$}{4:    }|
2666    {7:  }{4:sometest text foo}{11:$}{4:    }│{7:  }{4:text}{100:s}{11:$}{4:                }|
2667    {7:  }{4:ba}{27:z}{4: ab}{27:c}{4: }{27:d}{4:ef }{11:$}{4:         }│{7:  }{4:foo ba}{27:r}{4: ab}{27:X}{4: }{27:Y}{4:ef     }{11:$}{4: }|
2668    {7:  }{4:one}{103:$}{4:                  }│{7:  }{4:oneword another word}{11:$}{4: }|
2669    {7:  }{4:word another word}{11:$}{4:    }│{7:  }{23:----------------------}|
2670    {7:  }{22:additional line}{104:$}{22:      }│{7:  }{23:----------------------}|
2671    {1:~                       }│{1:~                       }|*12
2672    {2:Xdifile1                 }{3:Xdifile2                }|
2673                                                     |
2674  ]])
2675  command('set diffopt=internal,filler diffopt+=inline:char,iwhiteall')
2676  screen:expect([[
2677    {7:  }{4:this   is   }{11:$}{4:         }│{7:  }{4:^this is some test}{11:$}{4:    }|
2678    {7:  }{4:sometest text foo}{11:$}{4:    }│{7:  }{4:text}{100:s}{11:$}{4:                }|
2679    {7:  }{4:ba}{27:z}{4: ab}{27:c d}{4:ef }{11:$}{4:         }│{7:  }{4:foo ba}{27:r}{4: ab}{27:X Y}{4:ef     }{11:$}{4: }|
2680    {7:  }{4:one}{11:$}{4:                  }│{7:  }{4:oneword another word}{11:$}{4: }|
2681    {7:  }{4:word another word}{11:$}{4:    }│{7:  }{23:----------------------}|
2682    {7:  }{22:additional line}{104:$}{22:      }│{7:  }{23:----------------------}|
2683    {1:~                       }│{1:~                       }|*12
2684    {2:Xdifile1                 }{3:Xdifile2                }|
2685                                                     |
2686  ]])
2687  command('windo set nolist')
2688end)
2689
2690-- oldtest: Test_diff_inline_multibuffer()
2691it('diff mode inline highlighting with 3 buffers', function()
2692  write_file('Xdifile1', '')
2693  write_file('Xdifile2', '')
2694  write_file('Xdifile3', '')
2695  finally(function()
2696    os.remove('Xdifile1')
2697    os.remove('Xdifile2')
2698    os.remove('Xdifile3')
2699  end)
2700
2701  local screen = Screen.new(75, 20)
2702  screen:add_extra_attr_ids({
2703    [100] = { background = Screen.colors.Blue1 },
2704  })
2705  command('args Xdifile1 Xdifile2 Xdifile3 | vert all | windo diffthis | 1wincmd w')
2706  command('wincmd =')
2707  command('hi DiffTextAdd guibg=Blue')
2708
2709  WriteDiffFiles3(
2710    'That is buffer1.\nanchor\nSome random text\nanchor',
2711    'This is buffer2.\nanchor\nSome text\nanchor\nbuffer2/3',
2712    'This is buffer3. Last.\nanchor\nSome more\ntext here.\nanchor\nonly in buffer2/3\nnot in buffer1'
2713  )
2714  command('set diffopt=internal,filler diffopt+=inline:char')
2715  local s1 = [[
2716    {7:  }{4:^Th}{27:at}{4: is buffer}{27:1}{4:.       }│{7:  }{4:Th}{27:is}{4: is buffer}{27:2}{4:.      }│{7:  }{4:Th}{27:is}{4: is buffer}{27:3. Last}{4:.}|
2717    {7:  }anchor                 │{7:  }anchor                │{7:  }anchor                |
2718    {7:  }{4:Some }{27:random }{4:text       }│{7:  }{4:Some text             }│{7:  }{4:Some }{27:more}{4:             }|
2719    {7:  }{23:-----------------------}│{7:  }{23:----------------------}│{7:  }{4:text}{100: here.}{4:            }|
2720    {7:  }anchor                 │{7:  }anchor                │{7:  }anchor                |
2721    {7:  }{23:-----------------------}│{7:  }{4:buffer2/3             }│{7:  }{100:only in }{4:buffer2/3     }|
2722    {7:  }{23:-----------------------}│{7:  }{23:----------------------}│{7:  }{22:not in buffer1        }|
2723    {1:~                        }│{1:~                       }│{1:~                       }|*11
2724    {3:Xdifile1                  }{2:Xdifile2                 Xdifile3                }|
2725                                                                               |
2726  ]]
2727  screen:expect(s1)
2728
2729  -- Close one of the buffers and make sure it updates correctly
2730  command('diffoff')
2731  screen:expect([[
2732    ^That is buffer1.         │{7:  }{4:This is buffer}{27:2}{4:.      }│{7:  }{4:This is buffer}{27:3. Last}{4:.}|
2733    anchor                   │{7:  }anchor                │{7:  }anchor                |
2734    Some random text         │{7:  }{4:Some text             }│{7:  }{4:Some }{100:more}{4:             }|
2735    anchor                   │{7:  }{23:----------------------}│{7:  }{4:text}{100: here.}{4:            }|
2736    {1:~                        }│{7:  }anchor                │{7:  }anchor                |
2737    {1:~                        }│{7:  }{4:buffer2/3             }│{7:  }{100:only in }{4:buffer2/3     }|
2738    {1:~                        }│{7:  }{23:----------------------}│{7:  }{22:not in buffer1        }|
2739    {1:~                        }│{1:~                       }│{1:~                       }|*11
2740    {3:Xdifile1                  }{2:Xdifile2                 Xdifile3                }|
2741                                                                               |
2742  ]])
2743
2744  -- Update text in the non-diff buffer and nothing should be changed
2745  feed('isometext')
2746  screen:expect([[
2747    sometext^That is buffer1. │{7:  }{4:This is buffer}{27:2}{4:.      }│{7:  }{4:This is buffer}{27:3. Last}{4:.}|
2748    anchor                   │{7:  }anchor                │{7:  }anchor                |
2749    Some random text         │{7:  }{4:Some text             }│{7:  }{4:Some }{100:more}{4:             }|
2750    anchor                   │{7:  }{23:----------------------}│{7:  }{4:text}{100: here.}{4:            }|
2751    {1:~                        }│{7:  }anchor                │{7:  }anchor                |
2752    {1:~                        }│{7:  }{4:buffer2/3             }│{7:  }{100:only in }{4:buffer2/3     }|
2753    {1:~                        }│{7:  }{23:----------------------}│{7:  }{22:not in buffer1        }|
2754    {1:~                        }│{1:~                       }│{1:~                       }|*11
2755    {3:Xdifile1 [+]              }{2:Xdifile2                 Xdifile3                }|
2756    {5:-- INSERT --}                                                               |
2757  ]])
2758  feed('<Esc>')
2759  command('silent! undo')
2760
2761  command('diffthis')
2762  screen:expect(s1)
2763
2764  -- Test that removing first buffer from diff will in turn use the next
2765  -- earliest buffer's iskeyword during word diff.
2766  WriteDiffFiles3('This+is=a-setence', 'This+is=another-setence', 'That+is=a-setence')
2767  command('set iskeyword+=+ | 2wincmd w | set iskeyword+=- | 1wincmd w')
2768  command('set diffopt=internal,filler diffopt+=inline:word')
2769  local s4 = [[
2770    {7:  }{27:^This+is=a}{4:-setence      }│{7:  }{27:This+is=another}{4:-setenc}│{7:  }{27:That+is=a}{4:-setence     }|
2771    {1:~                        }│{1:~                       }│{1:~                       }|*17
2772    {3:Xdifile1                  }{2:Xdifile2                 Xdifile3                }|
2773                                                                               |
2774  ]]
2775  screen:expect(s4)
2776  command('diffoff')
2777  screen:expect([[
2778    ^This+is=a-setence        │{7:  }{27:This}{4:+is=}{27:another-setenc}│{7:  }{27:That}{4:+is=}{27:a-setence}{4:     }|
2779    {1:~                        }│{1:~                       }│{1:~                       }|*17
2780    {3:Xdifile1                  }{2:Xdifile2                 Xdifile3                }|
2781                                                                               |
2782  ]])
2783  command('diffthis')
2784  screen:expect(s4)
2785
2786  -- Test multi-buffer char diff refinement, and that removing a buffer from
2787  -- diff will update the others properly.
2788  WriteDiffFiles3('abcdefghijkYmYYY', 'aXXdXXghijklmnop', 'abcdefghijkYmYop')
2789  command('set diffopt=internal,filler diffopt+=inline:char')
2790  local s6 = [[
2791    {7:  }{4:^a}{27:bcdef}{4:ghijk}{27:YmYYY}{4:       }│{7:  }{4:a}{27:XXdXX}{4:ghijk}{27:lmnop}{4:      }│{7:  }{4:a}{27:bcdef}{4:ghijk}{27:YmYop}{4:      }|
2792    {1:~                        }│{1:~                       }│{1:~                       }|*17
2793    {3:Xdifile1                  }{2:Xdifile2                 Xdifile3                }|
2794                                                                               |
2795  ]]
2796  screen:expect(s6)
2797  command('diffoff')
2798  screen:expect([[
2799    ^abcdefghijkYmYYY         │{7:  }{4:a}{27:XXdXX}{4:ghijk}{27:l}{4:m}{27:n}{4:op      }│{7:  }{4:a}{27:bcdef}{4:ghijk}{27:Y}{4:m}{27:Y}{4:op      }|
2800    {1:~                        }│{1:~                       }│{1:~                       }|*17
2801    {3:Xdifile1                  }{2:Xdifile2                 Xdifile3                }|
2802                                                                               |
2803  ]])
2804  command('diffthis')
2805  screen:expect(s6)
2806end)
2807
2808-- oldtest: Test_diff_inline_multibuffer_empty_block()
2809it('diff mode inline highlighting with multi-buffer and empty block', function()
2810  write_file('Xdifile1', 'anchor1\n1234567890abcde\nanchor2')
2811  write_file('Xdifile2', 'anchor1\n1234567--0abc-e\nanchor2')
2812  write_file('Xdifile3', 'anchor1\nanchor2')
2813  write_file('Xdifile4', 'anchor1\n1???????90abcd?\nanchor2')
2814  finally(function()
2815    os.remove('Xdifile1')
2816    os.remove('Xdifile2')
2817    os.remove('Xdifile3')
2818    os.remove('Xdifile4')
2819  end)
2820  local screen = Screen.new(83, 20)
2821  command('args Xdifile1 Xdifile2 Xdifile3 Xdifile4 | vert all | windo diffthis')
2822  command('1wincmd w | set diffopt=filler,internal,inline:char')
2823  screen:expect([[
2824    {7:  }^anchor1           │{7:  }anchor1           │{7:  }anchor1           │{7:  }anchor1           |
2825    {7:  }{4:1}{27:23456789}{4:0abc}{27:de}{4:   }│{7:  }{4:1}{27:234567--}{4:0abc}{27:-e}{4:   }│{7:  }{23:------------------}│{7:  }{4:1}{27:???????9}{4:0abc}{27:d?}{4:   }|
2826    {7:  }anchor2           │{7:  }anchor2           │{7:  }anchor2           │{7:  }anchor2           |
2827    {1:~                   }│{1:~                   }│{1:~                   }│{1:~                   }|*15
2828    {3:Xdifile1             }{2:Xdifile2             Xdifile3             Xdifile4            }|
2829                                                                                       |
2830  ]])
2831  n.assert_alive()
2832end)
2833
2834it('diff mode algorithm:histogram and inline:char with long lines #34329', function()
2835  local screen = Screen.new(55, 20)
2836  exec([[
2837    set diffopt=internal,filler,closeoff,algorithm:histogram,inline:char
2838    cd test/functional/fixtures/diff/
2839    args inline_char_file1 inline_char_file2
2840    vert all | windo diffthis | 1wincmd w
2841  ]])
2842  screen:expect([[
2843    {7:  }{27:^aaaa,aaaaaaaa,aaaaaaaaaa,}│{7:  }{27:bbbb,bbbbbbbb,bbbbbbbbbb,}|
2844    {7:  }{27:aaaaaaa-aaaaaaaaa-aaaaaa-}│{7:  }{27:bbbbbbb-bbbbbbbbb-bbbbbb-}|*11
2845    {1:~                          }│{1:~                          }|*6
2846    {3:inline_char_file1           }{2:inline_char_file2          }|
2847                                                           |
2848  ]])
2849  n.assert_alive()
2850  feed('G$')
2851  screen:expect([[
2852    {7:  }{4:                         }│{7:  }{4:                         }|
2853    {7:  }{27:aa,aa,aa,aa,aa,a,a}{4:"      }│{7:  }{27:,bb,bb,bb,bb,bb,b,b}{4:"     }|
2854    {7:  }{27:,aa,aa,aa,aa,aa,a}{4:"       }│{7:  }{27:b,bb,bb,bb,bb,bb,bb,b}{4:"   }|
2855    {7:  }{27:,aa,aa,aa,aa,aa}{4:"         }│{7:  }{27:bb,bb,bb,bb,bb,bb,bb,bb}{4:" }|
2856    {7:  }{27:a,aa,aa,aa,aa}{4:"           }│{7:  }{27:,bb,b,bb,bb,bb}{4:"          }|
2857    {7:  }{27:aa,aa,aa,aa,aa}{4:"          }│{7:  }{27:,bb,bb}{4:"                  }|
2858    {7:  }{27:a,a,a}{4:"                   }│{7:  }{27:b,b,b,b,b}{4:"               }|
2859    {7:  }{27:a,a,a,a,a}{4:"               }│{7:  }{27:,b,b,b,b,b}{4:"              }|
2860    {7:  }{27:aa,a,a,a,a,a,a}{4:"          }│{7:  }{27:b,b,b,b,b,b}{4:"             }|
2861    {7:  }{27:,aa,aa,a,a,a,a,a}{4:"        }│{7:  }{27:bb,b,b,b,b,b}{4:"            }|
2862    {7:  }{27:aa,aa,aa,aa,a,a,a,a}{4:"     }│{7:  }{27:bb,bb,bb,b,b,b,b}{4:"        }|
2863    {7:  }{27:,aa,aa,a,a,a}{4:^"            }│{7:  }{27:bb,bb,bb,bb,b,b,b}{4:"       }|
2864    {1:~                          }│{1:~                          }|*6
2865    {3:inline_char_file1           }{2:inline_char_file2          }|
2866                                                           |
2867  ]])
2868end)
2869
2870-- oldtest: Test_linematch_diff()
2871it([["linematch" in 'diffopt' implies "filler"]], function()
2872  local screen = Screen.new(55, 20)
2873  command('set diffopt=internal,filler,closeoff,inline:simple,linematch:30')
2874
2875  write_file('Xdifile1', '')
2876  write_file('Xdifile2', '')
2877  finally(function()
2878    os.remove('Xdifile1')
2879    os.remove('Xdifile2')
2880  end)
2881
2882  WriteDiffFiles('// d?\n// d?', '!\nabc d!\nd!')
2883  command('args Xdifile1 Xdifile2 | vert all | windo diffthis | 1wincmd w')
2884  screen:expect([[
2885    {7:  }{23:-------------------------}│{7:  }{22:!                        }|
2886    {7:  }{27:^// d?}{4:                    }│{7:  }{27:abc d!}{4:                   }|
2887    {7:  }{27:// d?}{4:                    }│{7:  }{27:d!}{4:                       }|
2888    {1:~                          }│{1:~                          }|*15
2889    {3:Xdifile1                    }{2:Xdifile2                   }|
2890                                                           |
2891  ]])
2892
2893  -- test that filler is always implicitly set by linematch
2894  command('set diffopt-=filler')
2895  screen:expect_unchanged()
2896end)
2897
2898describe("'diffanchors'", function()
2899  local screen
2900
2901  before_each(function()
2902    screen = Screen.new(32, 20)
2903    command('set winwidth=10 nohlsearch shortmess+=s')
2904  end)
2905
2906  after_each(function()
2907    os.remove('Xdifile1')
2908    os.remove('Xdifile2')
2909    os.remove('Xdifile3')
2910  end)
2911
2912  it('works', function()
2913    WriteDiffFiles3(
2914      'anchorA1\n1\n2\n3\n100\n101\n102\nanchorB\n103\n104\n105',
2915      '100\n101\n102\nanchorB\n103\n104\n105\nanchorA2\n1\n2\n3',
2916      '100\nanchorB\n103\nanchorA3\n1\n2\n3'
2917    )
2918    command('args Xdifile1 Xdifile2 Xdifile3 | vert all | windo diffthis | 1wincmd w')
2919
2920    -- Simple diff without any anchors
2921    command('set diffopt=filler,internal')
2922    local s0 = [[
2923      {7:  }{22:^anchorA1}│{7:  }{23:--------}│{7:  }{23:--------}|
2924      {7:  }{22:1       }│{7:  }{23:--------}│{7:  }{23:--------}|
2925      {7:  }{22:2       }│{7:  }{23:--------}│{7:  }{23:--------}|
2926      {7:  }{22:3       }│{7:  }{23:--------}│{7:  }{23:--------}|
2927      {7:  }100     │{7:  }100     │{7:  }100     |
2928      {7:  }{22:101     }│{7:  }{22:101     }│{7:  }{23:--------}|
2929      {7:  }{22:102     }│{7:  }{22:102     }│{7:  }{23:--------}|
2930      {7:  }anchorB │{7:  }anchorB │{7:  }anchorB |
2931      {7:  }103     │{7:  }103     │{7:  }103     |
2932      {7:  }{27:104}{4:     }│{7:  }{27:104}{4:     }│{7:  }{27:anchorA3}|
2933      {7:  }{4:1}{27:05}{4:     }│{7:  }{4:1}{27:05}{4:     }│{7:  }{4:1       }|
2934      {7:  }{23:--------}│{7:  }{27:anchorA}{4:2}│{7:  }{4:2       }|
2935      {7:  }{23:--------}│{7:  }{27:1}{4:       }│{7:  }{27:3}{4:       }|
2936      {7:  }{23:--------}│{7:  }{22:2       }│{7:  }{23:--------}|
2937      {7:  }{23:--------}│{7:  }{22:3       }│{7:  }{23:--------}|
2938      {1:~         }│{1:~         }│{1:~         }|*3
2939      {3:Xdifile1   }{2:Xdifile2   Xdifile3  }|
2940                                      |
2941    ]]
2942    screen:expect(s0)
2943
2944    -- Setting diffopt+=anchor or diffanchors without the other won't do anything
2945    command('set diffopt=filler,internal diffopt+=anchor')
2946    screen:expect_unchanged()
2947    command('set diffopt=filler,internal dia=1/anchorA/')
2948    screen:expect_unchanged()
2949
2950    -- Use a single anchor by specifying a pattern. Test both internal and
2951    -- external diff to make sure both paths work.
2952    command('set diffopt=filler dia=1/anchorA/ diffopt+=anchor')
2953    local s1 = [[
2954      {7:  }{23:--------}│{7:  }{4:100     }│{7:  }{4:100     }|
2955      {7:  }{23:--------}│{7:  }{27:101}{4:     }│{7:  }{27:anchorB}{4: }|
2956      {7:  }{23:--------}│{7:  }{4:10}{27:2}{4:     }│{7:  }{4:10}{27:3}{4:     }|
2957      {7:  }{23:--------}│{7:  }{22:anchorB }│{7:  }{23:--------}|
2958      {7:  }{23:--------}│{7:  }{22:103     }│{7:  }{23:--------}|
2959      {7:  }{23:--------}│{7:  }{22:104     }│{7:  }{23:--------}|
2960      {7:  }{23:--------}│{7:  }{22:105     }│{7:  }{23:--------}|
2961      {7:  }{4:^anchorA}{27:1}│{7:  }{4:anchorA}{27:2}│{7:  }{4:anchorA}{27:3}|
2962      {7:  }1       │{7:  }1       │{7:  }1       |
2963      {7:  }2       │{7:  }2       │{7:  }2       |
2964      {7:  }3       │{7:  }3       │{7:  }3       |
2965      {7:  }{22:100     }│{7:  }{23:--------}│{7:  }{23:--------}|
2966      {7:  }{22:101     }│{7:  }{23:--------}│{7:  }{23:--------}|
2967      {7:  }{22:102     }│{7:  }{23:--------}│{7:  }{23:--------}|
2968      {7:  }{22:anchorB }│{7:  }{23:--------}│{7:  }{23:--------}|
2969      {7:  }{22:103     }│{7:  }{23:--------}│{7:  }{23:--------}|
2970      {7:  }{22:104     }│{7:  }{23:--------}│{7:  }{23:--------}|
2971      {7:  }{22:105     }│{7:  }{23:--------}│{7:  }{23:--------}|
2972      {3:Xdifile1   }{2:Xdifile2   Xdifile3  }|
2973                                      |
2974    ]]
2975    screen:expect(s1)
2976    command('set diffopt+=internal')
2977    screen:expect_unchanged()
2978
2979    -- Use 2 anchors. They should be sorted by line number, so in file 2/3
2980    -- anchorB is used before anchorA.
2981    command('set diffopt=filler dia=1/anchorA/,1/anchorB/ diffopt+=anchor')
2982    local s2 = [[
2983      {7:  }{23:--------}│{7:  }{4:100     }│{7:  }{4:100     }|
2984      {7:  }{23:--------}│{7:  }{22:101     }│{7:  }{23:--------}|
2985      {7:  }{23:--------}│{7:  }{22:102     }│{7:  }{23:--------}|
2986      {7:  }{4:^anchor}{27:A1}│{7:  }{4:anchor}{27:B}{4: }│{7:  }{4:anchor}{27:B}{4: }|
2987      {7:  }{4:1       }│{7:  }{4:1}{27:03}{4:     }│{7:  }{4:1}{27:03}{4:     }|
2988      {7:  }{27:2}{4:       }│{7:  }{27:104}{4:     }│{7:  }{23:--------}|
2989      {7:  }{27:3}{4:       }│{7:  }{27:105}{4:     }│{7:  }{23:--------}|
2990      {7:  }{22:100     }│{7:  }{23:--------}│{7:  }{23:--------}|
2991      {7:  }{22:101     }│{7:  }{23:--------}│{7:  }{23:--------}|
2992      {7:  }{22:102     }│{7:  }{23:--------}│{7:  }{23:--------}|
2993      {7:  }{4:anchor}{27:B}{4: }│{7:  }{4:anchor}{27:A2}│{7:  }{4:anchor}{27:A3}|
2994      {7:  }{4:1}{27:03}{4:     }│{7:  }{4:1       }│{7:  }{4:1       }|
2995      {7:  }{27:104}{4:     }│{7:  }{27:2}{4:       }│{7:  }{27:2}{4:       }|
2996      {7:  }{27:105}{4:     }│{7:  }{27:3}{4:       }│{7:  }{27:3}{4:       }|
2997      {1:~         }│{1:~         }│{1:~         }|*4
2998      {3:Xdifile1   }{2:Xdifile2   Xdifile3  }|
2999                                      |
3000    ]]
3001    screen:expect(s2)
3002    command('set diffopt+=internal')
3003    screen:expect_unchanged()
3004
3005    -- Set marks and specify addresses using marks and repeat the test
3006    command('2wincmd w | 1/anchorA/mark a')
3007    command('1/anchorB/mark b')
3008    command('3wincmd w | 1/anchorA/mark a')
3009    command('1/anchorB/mark b')
3010    command('1wincmd w | 1/anchorA/mark a')
3011    command('1/anchorB/mark b')
3012
3013    command("set diffopt=filler,internal dia='a diffopt+=anchor")
3014    screen:expect(s1)
3015    command("set diffopt=filler,internal dia='a,'b diffopt+=anchor")
3016    screen:expect(s2)
3017
3018    -- Update marks to point somewhere else. When we first set the mark the diff
3019    -- won't be updated until we manually invoke :diffupdate.
3020    command("set diffopt=filler,internal dia='a diffopt+=anchor")
3021    screen:expect(s1)
3022    command('1wincmd w | 1/anchorB/mark a')
3023    screen:expect_unchanged()
3024    command('diffupdate')
3025    screen:expect([[
3026      {7:  }{22:^anchorA1}│{7:  }{23:--------}│{7:  }{23:--------}|
3027      {7:  }{22:1       }│{7:  }{23:--------}│{7:  }{23:--------}|
3028      {7:  }{22:2       }│{7:  }{23:--------}│{7:  }{23:--------}|
3029      {7:  }{22:3       }│{7:  }{23:--------}│{7:  }{23:--------}|
3030      {7:  }100     │{7:  }100     │{7:  }100     |
3031      {7:  }{27:101}{4:     }│{7:  }{27:101}{4:     }│{7:  }{27:anchorB}{4: }|
3032      {7:  }{4:10}{27:2}{4:     }│{7:  }{4:10}{27:2}{4:     }│{7:  }{4:10}{27:3}{4:     }|
3033      {7:  }{23:--------}│{7:  }{22:anchorB }│{7:  }{23:--------}|
3034      {7:  }{23:--------}│{7:  }{22:103     }│{7:  }{23:--------}|
3035      {7:  }{23:--------}│{7:  }{22:104     }│{7:  }{23:--------}|
3036      {7:  }{23:--------}│{7:  }{22:105     }│{7:  }{23:--------}|
3037      {7:  }{4:anchor}{27:B}{4: }│{7:  }{4:anchor}{27:A2}│{7:  }{4:anchor}{27:A3}|
3038      {7:  }{4:1}{27:03}{4:     }│{7:  }{4:1       }│{7:  }{4:1       }|
3039      {7:  }{27:104}{4:     }│{7:  }{27:2}{4:       }│{7:  }{27:2}{4:       }|
3040      {7:  }{27:105}{4:     }│{7:  }{27:3}{4:       }│{7:  }{27:3}{4:       }|
3041      {1:~         }│{1:~         }│{1:~         }|*3
3042      {3:Xdifile1   }{2:Xdifile2   Xdifile3  }|
3043                                      |
3044    ]])
3045
3046    -- Use local diff anchors with line numbers, and repeat the same test
3047    command('2wincmd w | setlocal dia=8')
3048    command('3wincmd w | setlocal dia=4')
3049    command('1wincmd w | setlocal dia=1')
3050    command('set diffopt=filler,internal diffopt+=anchor')
3051    screen:expect(s1)
3052    command('2wincmd w | setlocal dia=8,4')
3053    command('3wincmd w | setlocal dia=4,2')
3054    command('1wincmd w | setlocal dia=1,8')
3055    command('set diffopt=filler,internal diffopt+=anchor')
3056    screen:expect(s2)
3057
3058    -- Test multiple diff anchors on the same line in file 1.
3059    command('1wincmd w | setlocal dia=1,1')
3060    command('set diffopt=filler,internal diffopt+=anchor')
3061    screen:expect([[
3062      {7:  }{23:--------}│{7:  }{4:100     }│{7:  }{4:100     }|
3063      {7:  }{23:--------}│{7:  }{22:101     }│{7:  }{23:--------}|
3064      {7:  }{23:--------}│{7:  }{22:102     }│{7:  }{23:--------}|
3065      {7:  }{23:--------}│{7:  }{4:anchorB }│{7:  }{4:anchorB }|
3066      {7:  }{23:--------}│{7:  }{4:103     }│{7:  }{4:103     }|
3067      {7:  }{23:--------}│{7:  }{22:104     }│{7:  }{23:--------}|
3068      {7:  }{23:--------}│{7:  }{22:105     }│{7:  }{23:--------}|
3069      {7:  }{4:^anchorA}{27:1}│{7:  }{4:anchorA}{27:2}│{7:  }{4:anchorA}{27:3}|
3070      {7:  }1       │{7:  }1       │{7:  }1       |
3071      {7:  }2       │{7:  }2       │{7:  }2       |
3072      {7:  }3       │{7:  }3       │{7:  }3       |
3073      {7:  }{22:100     }│{7:  }{23:--------}│{7:  }{23:--------}|
3074      {7:  }{22:101     }│{7:  }{23:--------}│{7:  }{23:--------}|
3075      {7:  }{22:102     }│{7:  }{23:--------}│{7:  }{23:--------}|
3076      {7:  }{22:anchorB }│{7:  }{23:--------}│{7:  }{23:--------}|
3077      {7:  }{22:103     }│{7:  }{23:--------}│{7:  }{23:--------}|
3078      {7:  }{22:104     }│{7:  }{23:--------}│{7:  }{23:--------}|
3079      {7:  }{22:105     }│{7:  }{23:--------}│{7:  }{23:--------}|
3080      {3:Xdifile1   }{2:Xdifile2   Xdifile3  }|
3081                                      |
3082    ]])
3083
3084    -- Test that if one file has fewer diff anchors than others. Vim should only
3085    -- use the minimum in this case.
3086    command('1wincmd w | setlocal dia=8')
3087    command('set diffopt=filler,internal diffopt+=anchor')
3088    screen:expect([[
3089      {7:  }{22:^anchorA1}│{7:  }{23:--------}│{7:  }{23:--------}|
3090      {7:  }{22:1       }│{7:  }{23:--------}│{7:  }{23:--------}|
3091      {7:  }{22:2       }│{7:  }{23:--------}│{7:  }{23:--------}|
3092      {7:  }{22:3       }│{7:  }{23:--------}│{7:  }{23:--------}|
3093      {7:  }100     │{7:  }100     │{7:  }100     |
3094      {7:  }{22:101     }│{7:  }{22:101     }│{7:  }{23:--------}|
3095      {7:  }{22:102     }│{7:  }{22:102     }│{7:  }{23:--------}|
3096      {7:  }anchorB │{7:  }anchorB │{7:  }anchorB |
3097      {7:  }103     │{7:  }103     │{7:  }103     |
3098      {7:  }{27:104}{4:     }│{7:  }{27:104}{4:     }│{7:  }{27:anchorA3}|
3099      {7:  }{4:1}{27:05}{4:     }│{7:  }{4:1}{27:05}{4:     }│{7:  }{4:1       }|
3100      {7:  }{23:--------}│{7:  }{27:anchorA}{4:2}│{7:  }{4:2       }|
3101      {7:  }{23:--------}│{7:  }{27:1}{4:       }│{7:  }{27:3}{4:       }|
3102      {7:  }{23:--------}│{7:  }{22:2       }│{7:  }{23:--------}|
3103      {7:  }{23:--------}│{7:  }{22:3       }│{7:  }{23:--------}|
3104      {1:~         }│{1:~         }│{1:~         }|*3
3105      {3:Xdifile1   }{2:Xdifile2   Xdifile3  }|
3106                                      |
3107    ]])
3108
3109    -- $+1 should anchor everything past the last line
3110    command('1wincmd w | setlocal dia=$+1')
3111    command('set diffopt=filler,internal diffopt+=anchor')
3112    screen:expect([[
3113      {7:  }{22:^anchorA1}│{7:  }{23:--------}│{7:  }{23:--------}|
3114      {7:  }{22:1       }│{7:  }{23:--------}│{7:  }{23:--------}|
3115      {7:  }{22:2       }│{7:  }{23:--------}│{7:  }{23:--------}|
3116      {7:  }{22:3       }│{7:  }{23:--------}│{7:  }{23:--------}|
3117      {7:  }100     │{7:  }100     │{7:  }100     |
3118      {7:  }{4:101     }│{7:  }{4:101     }│{7:  }{23:--------}|
3119      {7:  }{4:102     }│{7:  }{4:102     }│{7:  }{23:--------}|
3120      {7:  }{22:anchorB }│{7:  }{23:--------}│{7:  }{23:--------}|
3121      {7:  }{22:103     }│{7:  }{23:--------}│{7:  }{23:--------}|
3122      {7:  }{22:104     }│{7:  }{23:--------}│{7:  }{23:--------}|
3123      {7:  }{22:105     }│{7:  }{23:--------}│{7:  }{23:--------}|
3124      {7:  }{23:--------}│{7:  }{4:anchorB }│{7:  }{4:anchorB }|
3125      {7:  }{23:--------}│{7:  }{4:103     }│{7:  }{4:103     }|
3126      {7:  }{23:--------}│{7:  }{27:104}{4:     }│{7:  }{27:anchorA3}|
3127      {7:  }{23:--------}│{7:  }{4:1}{27:05}{4:     }│{7:  }{4:1       }|
3128      {7:  }{23:--------}│{7:  }{27:anchorA}{4:2}│{7:  }{4:2       }|
3129      {7:  }{23:--------}│{7:  }{27:1}{4:       }│{7:  }{27:3}{4:       }|
3130      {7:  }{23:--------}│{7:  }{22:2       }│{7:  }{23:--------}|
3131      {3:Xdifile1   }{2:Xdifile2   Xdifile3  }|
3132                                      |
3133    ]])
3134
3135    -- Sorting of diff anchors should work with multiple anchors
3136    command('1wincmd w | setlocal dia=1,10,8,2')
3137    command('2wincmd w | setlocal dia=1,2,3,4')
3138    command('3wincmd w | setlocal dia=4,3,2,1')
3139    command('set diffopt=filler,internal diffopt+=anchor')
3140    screen:expect([[
3141      {7:  }{27:anchorA1}│{7:  }{27:100}{4:     }│{7:  }{27:^100}{4:     }|
3142      {7:  }{27:1}{4:       }│{7:  }{27:101}{4:     }│{7:  }{27:anchorB}{4: }|
3143      {7:  }{22:2       }│{7:  }{23:--------}│{7:  }{23:--------}|
3144      {7:  }{22:3       }│{7:  }{23:--------}│{7:  }{23:--------}|
3145      {7:  }{22:100     }│{7:  }{23:--------}│{7:  }{23:--------}|
3146      {7:  }{22:101     }│{7:  }{23:--------}│{7:  }{23:--------}|
3147      {7:  }{22:102     }│{7:  }{23:--------}│{7:  }{23:--------}|
3148      {7:  }{27:anchorB}{4: }│{7:  }{27:102}{4:     }│{7:  }{27:103}{4:     }|
3149      {7:  }{22:103     }│{7:  }{23:--------}│{7:  }{23:--------}|
3150      {7:  }{27:104}{4:     }│{7:  }{27:anchorB}{4: }│{7:  }{27:anchorA3}|
3151      {7:  }{4:1}{27:05}{4:     }│{7:  }{4:1}{27:03}{4:     }│{7:  }{4:1       }|
3152      {7:  }{23:--------}│{7:  }{27:104}{4:     }│{7:  }{27:2}{4:       }|
3153      {7:  }{23:--------}│{7:  }{27:105}{4:     }│{7:  }{27:3}{4:       }|
3154      {7:  }{23:--------}│{7:  }{22:anchorA2}│{7:  }{23:--------}|
3155      {7:  }{23:--------}│{7:  }{22:1       }│{7:  }{23:--------}|
3156      {7:  }{23:--------}│{7:  }{22:2       }│{7:  }{23:--------}|
3157      {7:  }{23:--------}│{7:  }{22:3       }│{7:  }{23:--------}|
3158      {1:~         }│{1:~         }│{1:~         }|
3159      {2:Xdifile1   Xdifile2   }{3:Xdifile3  }|
3160                                      |
3161    ]])
3162
3163    -- Intentionally set an invalid anchor with wrong line number. Should fall
3164    -- back to treat it as if no anchors are used at all.
3165    command('1wincmd w | setlocal dia=1,10,8,2,1000 | silent! diffupdate')
3166    screen:expect(s0)
3167  end)
3168
3169  -- oldtest: Test_diffanchors_scrollbind_topline()
3170  it('scrollbind works with adjacent diff blocks', function()
3171    WriteDiffFiles('anchor1\ndiff1a\nanchor2', 'anchor1\ndiff2a\nanchor2')
3172    command('args Xdifile1 Xdifile2 | vert all | windo diffthis | 1wincmd w')
3173
3174    command('1wincmd w | setlocal dia=2')
3175    command('2wincmd w | setlocal dia=3')
3176
3177    command('set diffopt=filler,internal diffopt+=anchor')
3178    screen:expect([[
3179      {7:  }anchor1      │{7:  }^anchor1       |
3180      {7:  }{23:-------------}│{7:  }{22:diff2a        }|
3181      {7:  }{22:diff1a       }│{7:  }{23:--------------}|
3182      {7:  }anchor2      │{7:  }anchor2       |
3183      {1:~              }│{1:~               }|*14
3184      {2:Xdifile1        }{3:Xdifile2        }|
3185                                      |
3186    ]])
3187    feed('<C-E>')
3188    screen:expect([[
3189      {7:  }{23:-------------}│{7:  }{22:^diff2a        }|
3190      {7:  }{22:diff1a       }│{7:  }{23:--------------}|
3191      {7:  }anchor2      │{7:  }anchor2       |
3192      {1:~              }│{1:~               }|*15
3193      {2:Xdifile1        }{3:Xdifile2        }|
3194                                      |
3195    ]])
3196    feed('<C-E>')
3197    screen:expect([[
3198      {7:  }{22:diff1a       }│{7:  }{23:--------------}|
3199      {7:  }anchor2      │{7:  }^anchor2       |
3200      {1:~              }│{1:~               }|*16
3201      {2:Xdifile1        }{3:Xdifile2        }|
3202                                      |
3203    ]])
3204    feed('<C-E>')
3205    screen:expect([[
3206      {7:  }anchor2      │{7:  }^anchor2       |
3207      {1:~              }│{1:~               }|*17
3208      {2:Xdifile1        }{3:Xdifile2        }|
3209                                      |
3210    ]])
3211
3212    -- Also test no-filler
3213    feed('gg')
3214    command('set diffopt=filler,internal diffopt+=anchor diffopt-=filler')
3215    screen:expect([[
3216      {7:  }anchor1      │{7:  }^anchor1       |
3217      {7:  }{22:diff1a       }│{7:  }{22:diff2a        }|
3218      {7:  }anchor2      │{7:  }anchor2       |
3219      {1:~              }│{1:~               }|*15
3220      {2:Xdifile1        }{3:Xdifile2        }|
3221                                      |
3222    ]])
3223    feed('<C-E>')
3224    screen:expect([[
3225      {7:  }{22:diff1a       }│{7:  }{22:^diff2a        }|
3226      {7:  }anchor2      │{7:  }anchor2       |
3227      {1:~              }│{1:~               }|*16
3228      {2:Xdifile1        }{3:Xdifile2        }|
3229                                      |
3230    ]])
3231    feed('<C-E>')
3232    screen:expect([[
3233      {7:  }anchor2      │{7:  }^anchor2       |
3234      {1:~              }│{1:~               }|*17
3235      {2:Xdifile1        }{3:Xdifile2        }|
3236                                      |
3237    ]])
3238  end)
3239
3240  -- oldtest: Test_diffanchors_scrollbind_topline2()
3241  it('scrollbind works with 3 files and overlapping diff blocks', function()
3242    WriteDiffFiles3(
3243      'anchor1',
3244      'diff2a\ndiff2b\ndiff2c\ndiff2d\nanchor2',
3245      'diff3a\ndiff3c\ndiff3d\nanchor3\ndiff3e'
3246    )
3247    command('args Xdifile1 Xdifile2 Xdifile3 | vert all | windo diffthis | 1wincmd w')
3248
3249    command('1wincmd w | setlocal dia=1,1,2')
3250    command('2wincmd w | setlocal dia=3,5,6')
3251    command('3wincmd w | setlocal dia=2,4,5')
3252
3253    command('set diffopt=filler,internal diffopt+=anchor')
3254    screen:expect([[
3255      {7:  }{23:--------}│{7:  }{4:diff}{27:2}{4:a  }│{7:  }{4:^diff}{27:3}{4:a  }|
3256      {7:  }{23:--------}│{7:  }{22:diff2b  }│{7:  }{23:--------}|
3257      {7:  }{23:--------}│{7:  }{4:diff}{27:2}{4:c  }│{7:  }{4:diff}{27:3}{4:c  }|
3258      {7:  }{23:--------}│{7:  }{4:diff}{27:2}{4:d  }│{7:  }{4:diff}{27:3}{4:d  }|
3259      {7:  }{4:anchor}{27:1}{4: }│{7:  }{4:anchor}{27:2}{4: }│{7:  }{4:anchor}{27:3}{4: }|
3260      {7:  }{23:--------}│{7:  }{23:--------}│{7:  }{22:diff3e  }|
3261      {1:~         }│{1:~         }│{1:~         }|*12
3262      {2:Xdifile1   Xdifile2   }{3:Xdifile3  }|
3263                                      |
3264    ]])
3265    command('1wincmd w')
3266    feed('<C-E>')
3267    screen:expect([[
3268      {7:  }{23:--------}│{7:  }{22:diff2b  }│{7:  }{23:--------}|
3269      {7:  }{23:--------}│{7:  }{4:diff}{27:2}{4:c  }│{7:  }{4:diff}{27:3}{4:c  }|
3270      {7:  }{23:--------}│{7:  }{4:diff}{27:2}{4:d  }│{7:  }{4:diff}{27:3}{4:d  }|
3271      {7:  }{4:^anchor}{27:1}{4: }│{7:  }{4:anchor}{27:2}{4: }│{7:  }{4:anchor}{27:3}{4: }|
3272      {7:  }{23:--------}│{7:  }{23:--------}│{7:  }{22:diff3e  }|
3273      {1:~         }│{1:~         }│{1:~         }|*13
3274      {3:Xdifile1   }{2:Xdifile2   Xdifile3  }|
3275                                      |
3276    ]])
3277    feed('<C-E>')
3278    screen:expect([[
3279      {7:  }{23:--------}│{7:  }{4:diff}{27:2}{4:c  }│{7:  }{4:diff}{27:3}{4:c  }|
3280      {7:  }{23:--------}│{7:  }{4:diff}{27:2}{4:d  }│{7:  }{4:diff}{27:3}{4:d  }|
3281      {7:  }{4:^anchor}{27:1}{4: }│{7:  }{4:anchor}{27:2}{4: }│{7:  }{4:anchor}{27:3}{4: }|
3282      {7:  }{23:--------}│{7:  }{23:--------}│{7:  }{22:diff3e  }|
3283      {1:~         }│{1:~         }│{1:~         }|*14
3284      {3:Xdifile1   }{2:Xdifile2   Xdifile3  }|
3285                                      |
3286    ]])
3287    feed('<C-E>')
3288    screen:expect([[
3289      {7:  }{23:--------}│{7:  }{4:diff}{27:2}{4:d  }│{7:  }{4:diff}{27:3}{4:d  }|
3290      {7:  }{4:^anchor}{27:1}{4: }│{7:  }{4:anchor}{27:2}{4: }│{7:  }{4:anchor}{27:3}{4: }|
3291      {7:  }{23:--------}│{7:  }{23:--------}│{7:  }{22:diff3e  }|
3292      {1:~         }│{1:~         }│{1:~         }|*15
3293      {3:Xdifile1   }{2:Xdifile2   Xdifile3  }|
3294                                      |
3295    ]])
3296    feed('<C-E>')
3297    screen:expect([[
3298      {7:  }{4:^anchor}{27:1}{4: }│{7:  }{4:anchor}{27:2}{4: }│{7:  }{4:anchor}{27:3}{4: }|
3299      {7:  }{23:--------}│{7:  }{23:--------}│{7:  }{22:diff3e  }|
3300      {1:~         }│{1:~         }│{1:~         }|*16
3301      {3:Xdifile1   }{2:Xdifile2   Xdifile3  }|
3302                                      |
3303    ]])
3304
3305    -- Also test no-filler
3306    command('3wincmd w')
3307    feed('gg')
3308    command('set diffopt=filler,internal diffopt+=anchor diffopt-=filler')
3309    screen:expect([[
3310      {7:  }{4:anchor}{27:1}{4: }│{7:  }{4:diff}{27:2}{4:a  }│{7:  }{4:^diff}{27:3}{4:a  }|
3311      {1:~         }│{7:  }{22:diff2b  }│{7:  }{4:diff}{27:3}{4:c  }|
3312      {1:~         }│{7:  }{4:diff}{27:2}{4:c  }│{7:  }{4:diff}{27:3}{4:d  }|
3313      {1:~         }│{7:  }{4:diff}{27:2}{4:d  }│{7:  }{4:anchor}{27:3}{4: }|
3314      {1:~         }│{7:  }{4:anchor}{27:2}{4: }│{7:  }{22:diff3e  }|
3315      {1:~         }│{1:~         }│{1:~         }|*13
3316      {2:Xdifile1   Xdifile2   }{3:Xdifile3  }|
3317                                      |
3318    ]])
3319    feed('<C-E>')
3320    screen:expect([[
3321      {7:  }{4:anchor}{27:1}{4: }│{7:  }{4:diff}{27:2}{4:c  }│{7:  }{4:^diff}{27:3}{4:c  }|
3322      {1:~         }│{7:  }{4:diff}{27:2}{4:d  }│{7:  }{4:diff}{27:3}{4:d  }|
3323      {1:~         }│{7:  }{4:anchor}{27:2}{4: }│{7:  }{4:anchor}{27:3}{4: }|
3324      {1:~         }│{1:~         }│{7:  }{22:diff3e  }|
3325      {1:~         }│{1:~         }│{1:~         }|*14
3326      {2:Xdifile1   Xdifile2   }{3:Xdifile3  }|
3327                                      |
3328    ]])
3329    feed('<C-E>')
3330    screen:expect([[
3331      {7:  }{4:anchor}{27:1}{4: }│{7:  }{4:diff}{27:2}{4:d  }│{7:  }{4:^diff}{27:3}{4:d  }|
3332      {1:~         }│{7:  }{4:anchor}{27:2}{4: }│{7:  }{4:anchor}{27:3}{4: }|
3333      {1:~         }│{1:~         }│{7:  }{22:diff3e  }|
3334      {1:~         }│{1:~         }│{1:~         }|*15
3335      {2:Xdifile1   Xdifile2   }{3:Xdifile3  }|
3336                                      |
3337    ]])
3338    feed('<C-E>')
3339    screen:expect([[
3340      {7:  }{4:anchor}{27:1}{4: }│{7:  }{4:anchor}{27:2}{4: }│{7:  }{4:^anchor}{27:3}{4: }|
3341      {1:~         }│{1:~         }│{7:  }{22:diff3e  }|
3342      {1:~         }│{1:~         }│{1:~         }|*16
3343      {2:Xdifile1   Xdifile2   }{3:Xdifile3  }|
3344                                      |
3345    ]])
3346    feed('<C-E>')
3347    screen:expect([[
3348      {7:  }{4:anchor}{27:1}{4: }│{7:  }{4:anchor}{27:2}{4: }│{7:  }{22:^diff3e  }|
3349      {1:~         }│{1:~         }│{1:~         }|*17
3350      {2:Xdifile1   Xdifile2   }{3:Xdifile3  }|
3351                                      |
3352    ]])
3353  end)
3354end)
3355
3356-- oldtest: Test_diffexpr_wipe_buffers()
3357it(':%bwipe does not crash when using diffexpr', function()
3358  local screen = Screen.new(70, 20)
3359  exec([[
3360    func DiffFuncExpr()
3361      let in = readblob(v:fname_in)
3362      let new = readblob(v:fname_new)
3363      let out = v:lua.vim.text.diff(in, new)
3364      call writefile(split(out, "\n"), v:fname_out)
3365    endfunc
3366
3367    new
3368    vnew
3369    set diffexpr=DiffFuncExpr()
3370    wincmd l
3371    new
3372    call setline(1,range(20))
3373    windo diffthis
3374    wincmd w
3375    hide
3376    %bw!
3377  ]])
3378  screen:expect([[
3379    ^                                                                      |
3380    {1:~                                                                     }|*18
3381    4 buffers wiped out                                                   |
3382  ]])
3383end)
3384
3385-- oldtest: Test_diffput_to_empty_buf()
3386it(':diffput to empty buffer redraws properly', function()
3387  local screen = Screen.new(75, 20)
3388  exec([[
3389    set ruler
3390    call setline(1, ['foo', 'bar', 'baz'])
3391    rightbelow vnew
3392    windo diffthis
3393    windo set cursorline nofoldenable
3394    wincmd t
3395  ]])
3396  screen:add_extra_attr_ids({
3397    [100] = { underline = true, background = Screen.colors.LightBlue },
3398  })
3399  screen:expect([[
3400    {7:  }{100:^foo                                }│{7:  }{23:-----------------------------------}|
3401    {7:  }{22:bar                                }│{7:  }{23:-----------------------------------}|
3402    {7:  }{22:baz                                }│{7:  }{23:-----------------------------------}|
3403    {1:~                                    }│{7:  }{21:                                   }|
3404    {1:~                                    }│{1:~                                    }|*14
3405    {3:[No Name] [+]      1,1            All }{2:[No Name]          0,0-1          All}|
3406                                                                               |
3407  ]])
3408  feed('0') -- Trigger an initial 'cursorbind' check.
3409  screen:expect_unchanged()
3410  command('diffput')
3411  screen:expect([[
3412    {7:  }{21:^foo                                }│{7:  }foo                                |
3413    {7:  }bar                                │{7:  }bar                                |
3414    {7:  }baz                                │{7:  }{21:baz                                }|
3415    {1:~                                    }│{1:~                                    }|*15
3416    {3:[No Name] [+]      1,1            All }{2:[No Name] [+]      3,1            All}|
3417                                                                               |
3418  ]])
3419  command(':redraw!')
3420  screen:expect_unchanged()
3421  feed('j')
3422  screen:expect([[
3423    {7:  }foo                                │{7:  }foo                                |
3424    {7:  }{21:^bar                                }│{7:  }{21:bar                                }|
3425    {7:  }baz                                │{7:  }baz                                |
3426    {1:~                                    }│{1:~                                    }|*15
3427    {3:[No Name] [+]      2,1            All }{2:[No Name] [+]      2,1            All}|
3428                                                                               |
3429  ]])
3430end)