1local helpers = require('test.functional.helpers')(after_each)
2local Screen = require('test.functional.ui.screen')
3
4local feed = helpers.feed
5local clear = helpers.clear
6local command = helpers.command
7local insert = helpers.insert
8local write_file = helpers.write_file
9local source = helpers.source
10
11describe('Diff mode screen', function()
12  local fname = 'Xtest-functional-diff-screen-1'
13  local fname_2 = fname .. '.2'
14  local screen
15
16  local reread = function()
17    feed(':e<cr><c-w>w:e<cr><c-w>w')
18  end
19
20  setup(function()
21    clear()
22    os.remove(fname)
23    os.remove(fname_2)
24  end)
25
26  teardown(function()
27    os.remove(fname)
28    os.remove(fname_2)
29  end)
30
31  before_each(function()
32    clear()
33    feed(':e ' .. fname_2 .. '<cr>')
34    feed(':vnew ' .. fname .. '<cr>')
35    feed(':diffthis<cr>')
36    feed('<c-w>w:diffthis<cr><c-w>w')
37
38    screen = Screen.new(40, 16)
39    screen:attach()
40    screen:set_default_attr_ids({
41      [1] = {foreground = Screen.colors.DarkBlue, background = Screen.colors.WebGray},
42      [2] = {background = Screen.colors.LightCyan1, bold = true, foreground = Screen.colors.Blue1},
43      [3] = {reverse = true},
44      [4] = {background = Screen.colors.LightBlue},
45      [5] = {foreground = Screen.colors.DarkBlue, background = Screen.colors.LightGrey},
46      [6] = {bold = true, foreground = Screen.colors.Blue1},
47      [7] = {bold = true, reverse = true},
48      [8] = {bold = true, background = Screen.colors.Red},
49      [9] = {background = Screen.colors.LightMagenta},
50    })
51  end)
52
53  it('Add a line in beginning of file 2', function()
54    write_file(fname, "1\n2\n3\n4\n5\n6\n7\n8\n9\n10\n", false)
55    write_file(fname_2, "0\n1\n2\n3\n4\n5\n6\n7\n8\n9\n10\n", false)
56    reread()
57
58    feed(':set diffopt=filler<cr>')
59    screen:expect([[
60      {1:  }{2:------------------}{3:│}{1:  }{4:0                }|
61      {1:  }^1                 {3:│}{1:  }1                |
62      {1:  }2                 {3:│}{1:  }2                |
63      {1:  }3                 {3:│}{1:  }3                |
64      {1:  }4                 {3:│}{1:  }4                |
65      {1:  }5                 {3:│}{1:  }5                |
66      {1:  }6                 {3:│}{1:  }6                |
67      {1:+ }{5:+--  4 lines: 7···}{3:│}{1:+ }{5:+--  4 lines: 7··}|
68      {6:~                   }{3:│}{6:~                  }|
69      {6:~                   }{3:│}{6:~                  }|
70      {6:~                   }{3:│}{6:~                  }|
71      {6:~                   }{3:│}{6:~                  }|
72      {6:~                   }{3:│}{6:~                  }|
73      {6:~                   }{3:│}{6:~                  }|
74      {7:<onal-diff-screen-1  }{3:<l-diff-screen-1.2 }|
75      :set diffopt=filler                     |
76    ]])
77
78    feed(':set diffopt+=internal<cr>')
79    screen:expect([[
80      {1:  }{2:------------------}{3:│}{1:  }{4:0                }|
81      {1:  }^1                 {3:│}{1:  }1                |
82      {1:  }2                 {3:│}{1:  }2                |
83      {1:  }3                 {3:│}{1:  }3                |
84      {1:  }4                 {3:│}{1:  }4                |
85      {1:  }5                 {3:│}{1:  }5                |
86      {1:  }6                 {3:│}{1:  }6                |
87      {1:+ }{5:+--  4 lines: 7···}{3:│}{1:+ }{5:+--  4 lines: 7··}|
88      {6:~                   }{3:│}{6:~                  }|
89      {6:~                   }{3:│}{6:~                  }|
90      {6:~                   }{3:│}{6:~                  }|
91      {6:~                   }{3:│}{6:~                  }|
92      {6:~                   }{3:│}{6:~                  }|
93      {6:~                   }{3:│}{6:~                  }|
94      {7:<onal-diff-screen-1  }{3:<l-diff-screen-1.2 }|
95      :set diffopt+=internal                  |
96    ]])
97  end)
98
99  it('Add a line in beginning of file 1', function()
100    write_file(fname, "0\n1\n2\n3\n4\n5\n6\n7\n8\n9\n10\n", false)
101    write_file(fname_2, "1\n2\n3\n4\n5\n6\n7\n8\n9\n10\n", false)
102    reread()
103
104    feed(":set diffopt=filler<cr>")
105    screen:expect([[
106      {1:  }{4:^0                 }{3:│}{1:  }{2:-----------------}|
107      {1:  }1                 {3:│}{1:  }1                |
108      {1:  }2                 {3:│}{1:  }2                |
109      {1:  }3                 {3:│}{1:  }3                |
110      {1:  }4                 {3:│}{1:  }4                |
111      {1:  }5                 {3:│}{1:  }5                |
112      {1:  }6                 {3:│}{1:  }6                |
113      {1:+ }{5:+--  4 lines: 7···}{3:│}{1:+ }{5:+--  4 lines: 7··}|
114      {6:~                   }{3:│}{6:~                  }|
115      {6:~                   }{3:│}{6:~                  }|
116      {6:~                   }{3:│}{6:~                  }|
117      {6:~                   }{3:│}{6:~                  }|
118      {6:~                   }{3:│}{6:~                  }|
119      {6:~                   }{3:│}{6:~                  }|
120      {7:<onal-diff-screen-1  }{3:<l-diff-screen-1.2 }|
121      :set diffopt=filler                     |
122    ]])
123
124    feed(":set diffopt+=internal<cr>")
125    screen:expect([[
126      {1:  }{4:^0                 }{3:│}{1:  }{2:-----------------}|
127      {1:  }1                 {3:│}{1:  }1                |
128      {1:  }2                 {3:│}{1:  }2                |
129      {1:  }3                 {3:│}{1:  }3                |
130      {1:  }4                 {3:│}{1:  }4                |
131      {1:  }5                 {3:│}{1:  }5                |
132      {1:  }6                 {3:│}{1:  }6                |
133      {1:+ }{5:+--  4 lines: 7···}{3:│}{1:+ }{5:+--  4 lines: 7··}|
134      {6:~                   }{3:│}{6:~                  }|
135      {6:~                   }{3:│}{6:~                  }|
136      {6:~                   }{3:│}{6:~                  }|
137      {6:~                   }{3:│}{6:~                  }|
138      {6:~                   }{3:│}{6:~                  }|
139      {6:~                   }{3:│}{6:~                  }|
140      {7:<onal-diff-screen-1  }{3:<l-diff-screen-1.2 }|
141      :set diffopt+=internal                  |
142    ]])
143  end)
144
145  it('Add a line at the end of file 2', function()
146    write_file(fname, "1\n2\n3\n4\n5\n6\n7\n8\n9\n10\n", false)
147    write_file(fname_2, "1\n2\n3\n4\n5\n6\n7\n8\n9\n10\n11\n", false)
148    reread()
149
150    feed(":set diffopt=filler<cr>")
151    screen:expect([[
152      {1:+ }{5:^+--  4 lines: 1···}{3:│}{1:+ }{5:+--  4 lines: 1··}|
153      {1:  }5                 {3:│}{1:  }5                |
154      {1:  }6                 {3:│}{1:  }6                |
155      {1:  }7                 {3:│}{1:  }7                |
156      {1:  }8                 {3:│}{1:  }8                |
157      {1:  }9                 {3:│}{1:  }9                |
158      {1:  }10                {3:│}{1:  }10               |
159      {1:  }{2:------------------}{3:│}{1:  }{4:11               }|
160      {6:~                   }{3:│}{6:~                  }|
161      {6:~                   }{3:│}{6:~                  }|
162      {6:~                   }{3:│}{6:~                  }|
163      {6:~                   }{3:│}{6:~                  }|
164      {6:~                   }{3:│}{6:~                  }|
165      {6:~                   }{3:│}{6:~                  }|
166      {7:<onal-diff-screen-1  }{3:<l-diff-screen-1.2 }|
167      :set diffopt=filler                     |
168    ]])
169
170    feed(":set diffopt+=internal<cr>")
171    screen:expect([[
172      {1:+ }{5:^+--  4 lines: 1···}{3:│}{1:+ }{5:+--  4 lines: 1··}|
173      {1:  }5                 {3:│}{1:  }5                |
174      {1:  }6                 {3:│}{1:  }6                |
175      {1:  }7                 {3:│}{1:  }7                |
176      {1:  }8                 {3:│}{1:  }8                |
177      {1:  }9                 {3:│}{1:  }9                |
178      {1:  }10                {3:│}{1:  }10               |
179      {1:  }{2:------------------}{3:│}{1:  }{4:11               }|
180      {6:~                   }{3:│}{6:~                  }|
181      {6:~                   }{3:│}{6:~                  }|
182      {6:~                   }{3:│}{6:~                  }|
183      {6:~                   }{3:│}{6:~                  }|
184      {6:~                   }{3:│}{6:~                  }|
185      {6:~                   }{3:│}{6:~                  }|
186      {7:<onal-diff-screen-1  }{3:<l-diff-screen-1.2 }|
187      :set diffopt+=internal                  |
188    ]])
189  end)
190
191  it('Add a line at the end of file 1', function()
192    write_file(fname, "1\n2\n3\n4\n5\n6\n7\n8\n9\n10\n11\n", false)
193    write_file(fname_2, "1\n2\n3\n4\n5\n6\n7\n8\n9\n10\n", false)
194    reread()
195
196    feed(":set diffopt=filler<cr>")
197    screen:expect([[
198      {1:+ }{5:^+--  4 lines: 1···}{3:│}{1:+ }{5:+--  4 lines: 1··}|
199      {1:  }5                 {3:│}{1:  }5                |
200      {1:  }6                 {3:│}{1:  }6                |
201      {1:  }7                 {3:│}{1:  }7                |
202      {1:  }8                 {3:│}{1:  }8                |
203      {1:  }9                 {3:│}{1:  }9                |
204      {1:  }10                {3:│}{1:  }10               |
205      {1:  }{4:11                }{3:│}{1:  }{2:-----------------}|
206      {6:~                   }{3:│}{6:~                  }|
207      {6:~                   }{3:│}{6:~                  }|
208      {6:~                   }{3:│}{6:~                  }|
209      {6:~                   }{3:│}{6:~                  }|
210      {6:~                   }{3:│}{6:~                  }|
211      {6:~                   }{3:│}{6:~                  }|
212      {7:<onal-diff-screen-1  }{3:<l-diff-screen-1.2 }|
213      :set diffopt=filler                     |
214    ]])
215
216    feed(":set diffopt+=internal<cr>")
217    screen:expect([[
218      {1:+ }{5:^+--  4 lines: 1···}{3:│}{1:+ }{5:+--  4 lines: 1··}|
219      {1:  }5                 {3:│}{1:  }5                |
220      {1:  }6                 {3:│}{1:  }6                |
221      {1:  }7                 {3:│}{1:  }7                |
222      {1:  }8                 {3:│}{1:  }8                |
223      {1:  }9                 {3:│}{1:  }9                |
224      {1:  }10                {3:│}{1:  }10               |
225      {1:  }{4:11                }{3:│}{1:  }{2:-----------------}|
226      {6:~                   }{3:│}{6:~                  }|
227      {6:~                   }{3:│}{6:~                  }|
228      {6:~                   }{3:│}{6:~                  }|
229      {6:~                   }{3:│}{6:~                  }|
230      {6:~                   }{3:│}{6:~                  }|
231      {6:~                   }{3:│}{6:~                  }|
232      {7:<onal-diff-screen-1  }{3:<l-diff-screen-1.2 }|
233      :set diffopt+=internal                  |
234    ]])
235  end)
236
237  it('Add a line in the middle of file 2, remove on at the end of file 1', function()
238    write_file(fname, "1\n2\n3\n4\n5\n6\n7\n8\n9\n10\n11\n", false)
239    write_file(fname_2, "1\n2\n3\n4\n4\n5\n6\n7\n8\n9\n10\n", false)
240    reread()
241
242    feed(':set diffopt=filler<cr>')
243    screen:expect([[
244      {1:  }^1                 {3:│}{1:  }1                |
245      {1:  }2                 {3:│}{1:  }2                |
246      {1:  }3                 {3:│}{1:  }3                |
247      {1:  }4                 {3:│}{1:  }4                |
248      {1:  }{2:------------------}{3:│}{1:  }{4:4                }|
249      {1:  }5                 {3:│}{1:  }5                |
250      {1:  }6                 {3:│}{1:  }6                |
251      {1:  }7                 {3:│}{1:  }7                |
252      {1:  }8                 {3:│}{1:  }8                |
253      {1:  }9                 {3:│}{1:  }9                |
254      {1:  }10                {3:│}{1:  }10               |
255      {1:  }{4:11                }{3:│}{1:  }{2:-----------------}|
256      {6:~                   }{3:│}{6:~                  }|
257      {6:~                   }{3:│}{6:~                  }|
258      {7:<onal-diff-screen-1  }{3:<l-diff-screen-1.2 }|
259      :set diffopt=filler                     |
260    ]])
261
262    feed(':set diffopt+=internal<cr>')
263    screen:expect([[
264      {1:  }^1                 {3:│}{1:  }1                |
265      {1:  }2                 {3:│}{1:  }2                |
266      {1:  }3                 {3:│}{1:  }3                |
267      {1:  }4                 {3:│}{1:  }4                |
268      {1:  }{2:------------------}{3:│}{1:  }{4:4                }|
269      {1:  }5                 {3:│}{1:  }5                |
270      {1:  }6                 {3:│}{1:  }6                |
271      {1:  }7                 {3:│}{1:  }7                |
272      {1:  }8                 {3:│}{1:  }8                |
273      {1:  }9                 {3:│}{1:  }9                |
274      {1:  }10                {3:│}{1:  }10               |
275      {1:  }{4:11                }{3:│}{1:  }{2:-----------------}|
276      {6:~                   }{3:│}{6:~                  }|
277      {6:~                   }{3:│}{6:~                  }|
278      {7:<onal-diff-screen-1  }{3:<l-diff-screen-1.2 }|
279      :set diffopt+=internal                  |
280    ]])
281  end)
282
283  it('Add a line in the middle of file 1, remove on at the end of file 2', function()
284    write_file(fname, "1\n2\n3\n4\n4\n5\n6\n7\n8\n9\n10\n", false)
285    write_file(fname_2, "1\n2\n3\n4\n5\n6\n7\n8\n9\n10\n11\n", false)
286    reread()
287
288    feed(':set diffopt=filler<cr>')
289    screen:expect([[
290      {1:  }^1                 {3:│}{1:  }1                |
291      {1:  }2                 {3:│}{1:  }2                |
292      {1:  }3                 {3:│}{1:  }3                |
293      {1:  }4                 {3:│}{1:  }4                |
294      {1:  }{4:4                 }{3:│}{1:  }{2:-----------------}|
295      {1:  }5                 {3:│}{1:  }5                |
296      {1:  }6                 {3:│}{1:  }6                |
297      {1:  }7                 {3:│}{1:  }7                |
298      {1:  }8                 {3:│}{1:  }8                |
299      {1:  }9                 {3:│}{1:  }9                |
300      {1:  }10                {3:│}{1:  }10               |
301      {1:  }{2:------------------}{3:│}{1:  }{4:11               }|
302      {6:~                   }{3:│}{6:~                  }|
303      {6:~                   }{3:│}{6:~                  }|
304      {7:<onal-diff-screen-1  }{3:<l-diff-screen-1.2 }|
305      :set diffopt=filler                     |
306    ]])
307
308    feed(':set diffopt+=internal<cr>')
309    screen:expect([[
310      {1:  }^1                 {3:│}{1:  }1                |
311      {1:  }2                 {3:│}{1:  }2                |
312      {1:  }3                 {3:│}{1:  }3                |
313      {1:  }4                 {3:│}{1:  }4                |
314      {1:  }{4:4                 }{3:│}{1:  }{2:-----------------}|
315      {1:  }5                 {3:│}{1:  }5                |
316      {1:  }6                 {3:│}{1:  }6                |
317      {1:  }7                 {3:│}{1:  }7                |
318      {1:  }8                 {3:│}{1:  }8                |
319      {1:  }9                 {3:│}{1:  }9                |
320      {1:  }10                {3:│}{1:  }10               |
321      {1:  }{2:------------------}{3:│}{1:  }{4:11               }|
322      {6:~                   }{3:│}{6:~                  }|
323      {6:~                   }{3:│}{6:~                  }|
324      {7:<onal-diff-screen-1  }{3:<l-diff-screen-1.2 }|
325      :set diffopt+=internal                  |
326    ]])
327  end)
328
329  describe('normal/patience/histogram diff algorithm', function()
330    setup(function()
331      local f1 = [[#include <stdio.h>
332
333// Frobs foo heartily
334int frobnitz(int foo)
335{
336    int i;
337    for(i = 0; i < 10; i++)
338    {
339        printf("Your answer is: ");
340        printf("%d\n", foo);
341    }
342}
343
344int fact(int n)
345{
346    if(n > 1)
347    {
348        return fact(n-1) * n;
349    }
350    return 1;
351}
352
353int main(int argc, char **argv)
354{
355    frobnitz(fact(10));
356}]]
357      write_file(fname, f1, false)
358      local f2 = [[#include <stdio.h>
359
360int fib(int n)
361{
362    if(n > 2)
363    {
364        return fib(n-1) + fib(n-2);
365    }
366    return 1;
367}
368
369// Frobs foo heartily
370int frobnitz(int foo)
371{
372    int i;
373    for(i = 0; i < 10; i++)
374    {
375        printf("%d\n", foo);
376    }
377}
378
379int main(int argc, char **argv)
380{
381    frobnitz(fib(10));
382}]]
383      write_file(fname_2, f2, false)
384    end)
385
386    it('diffopt=+algorithm:myers', function()
387      reread()
388      feed(':set diffopt=internal,filler<cr>')
389      screen:expect([[
390        {1:  }^#include <stdio.h>{3:│}{1:  }#include <stdio.h|
391        {1:  }                  {3:│}{1:  }                 |
392        {1:  }{8:// Frobs foo heart}{3:│}{1:  }{8:int fib(int n)}{9:   }|
393        {1:  }{4:int frobnitz(int f}{3:│}{1:  }{2:-----------------}|
394        {1:  }{                 {3:│}{1:  }{                |
395        {1:  }{9:    i}{8:nt i;}{9:        }{3:│}{1:  }{9:    i}{8:f(n > 2)}{9:    }|
396        {1:  }{4:    for(i = 0; i <}{3:│}{1:  }{2:-----------------}|
397        {1:  }    {             {3:│}{1:  }    {            |
398        {1:  }{9:        }{8:printf("Yo}{3:│}{1:  }{9:        }{8:return fi}|
399        {1:  }{4:        printf("%d}{3:│}{1:  }{2:-----------------}|
400        {1:  }    }             {3:│}{1:  }    }            |
401        {1:  }{2:------------------}{3:│}{1:  }{4:    return 1;    }|
402        {1:  }}                 {3:│}{1:  }}                |
403        {1:  }                  {3:│}{1:  }                 |
404        {7:<onal-diff-screen-1  }{3:<l-diff-screen-1.2 }|
405        :set diffopt=internal,filler            |
406      ]])
407
408      feed('G')
409      screen:expect([[
410        {1:  }{2:------------------}{3:│}{1:  }{4:int frobnitz(int }|
411        {1:  }{                 {3:│}{1:  }{                |
412        {1:  }{9:    i}{8:f(n > 1)}{9:     }{3:│}{1:  }{9:    i}{8:nt i;}{9:       }|
413        {1:  }{2:------------------}{3:│}{1:  }{4:    for(i = 0; i }|
414        {1:  }    {             {3:│}{1:  }    {            |
415        {1:  }{9:        }{8:return fac}{3:│}{1:  }{9:        }{8:printf("%}|
416        {1:  }    }             {3:│}{1:  }    }            |
417        {1:  }{4:    return 1;     }{3:│}{1:  }{2:-----------------}|
418        {1:  }}                 {3:│}{1:  }}                |
419        {1:  }                  {3:│}{1:  }                 |
420        {1:  }int main(int argc,{3:│}{1:  }int main(int argc|
421        {1:  }{                 {3:│}{1:  }{                |
422        {1:  }{9:    frobnitz(f}{8:act}{9:(}{3:│}{1:  }{9:    frobnitz(f}{8:ib}{9:(}|
423        {1:  }^}                 {3:│}{1:  }}                |
424        {7:<onal-diff-screen-1  }{3:<l-diff-screen-1.2 }|
425        :set diffopt=internal,filler            |
426      ]])
427    end)
428
429    it('diffopt+=algorithm:patience', function()
430      reread()
431      feed(':set diffopt=internal,filler,algorithm:patience<cr>')
432      screen:expect([[
433        {1:  }^#include <stdio.h>{3:│}{1:  }#include <stdio.h|
434        {1:  }                  {3:│}{1:  }                 |
435        {1:  }{2:------------------}{3:│}{1:  }{4:int fib(int n)   }|
436        {1:  }{2:------------------}{3:│}{1:  }{4:{                }|
437        {1:  }{2:------------------}{3:│}{1:  }{4:    if(n > 2)    }|
438        {1:  }{2:------------------}{3:│}{1:  }{4:    {            }|
439        {1:  }{2:------------------}{3:│}{1:  }{4:        return fi}|
440        {1:  }{2:------------------}{3:│}{1:  }{4:    }            }|
441        {1:  }{2:------------------}{3:│}{1:  }{4:    return 1;    }|
442        {1:  }{2:------------------}{3:│}{1:  }{4:}                }|
443        {1:  }{2:------------------}{3:│}{1:  }{4:                 }|
444        {1:  }// Frobs foo heart{3:│}{1:  }// Frobs foo hear|
445        {1:  }int frobnitz(int f{3:│}{1:  }int frobnitz(int |
446        {1:  }{                 {3:│}{1:  }{                |
447        {7:<onal-diff-screen-1  }{3:<l-diff-screen-1.2 }|
448                                                |
449      ]])
450
451      feed('G')
452      screen:expect([[
453        {1:  }                  {3:│}{1:  }                 |
454        {1:  }{4:int fact(int n)   }{3:│}{1:  }{2:-----------------}|
455        {1:  }{4:{                 }{3:│}{1:  }{2:-----------------}|
456        {1:  }{4:    if(n > 1)     }{3:│}{1:  }{2:-----------------}|
457        {1:  }{4:    {             }{3:│}{1:  }{2:-----------------}|
458        {1:  }{4:        return fac}{3:│}{1:  }{2:-----------------}|
459        {1:  }{4:    }             }{3:│}{1:  }{2:-----------------}|
460        {1:  }{4:    return 1;     }{3:│}{1:  }{2:-----------------}|
461        {1:  }{4:}                 }{3:│}{1:  }{2:-----------------}|
462        {1:  }{4:                  }{3:│}{1:  }{2:-----------------}|
463        {1:  }int main(int argc,{3:│}{1:  }int main(int argc|
464        {1:  }{                 {3:│}{1:  }{                |
465        {1:  }{9:    frobnitz(f}{8:act}{9:(}{3:│}{1:  }{9:    frobnitz(f}{8:ib}{9:(}|
466        {1:  }^}                 {3:│}{1:  }}                |
467        {7:<onal-diff-screen-1  }{3:<l-diff-screen-1.2 }|
468                                                |
469      ]])
470    end)
471
472    it('diffopt+=algorithm:histogram', function()
473      reread()
474      feed(':set diffopt=internal,filler,algorithm:histogram<cr>')
475      screen:expect([[
476        {1:  }^#include <stdio.h>{3:│}{1:  }#include <stdio.h|
477        {1:  }                  {3:│}{1:  }                 |
478        {1:  }{2:------------------}{3:│}{1:  }{4:int fib(int n)   }|
479        {1:  }{2:------------------}{3:│}{1:  }{4:{                }|
480        {1:  }{2:------------------}{3:│}{1:  }{4:    if(n > 2)    }|
481        {1:  }{2:------------------}{3:│}{1:  }{4:    {            }|
482        {1:  }{2:------------------}{3:│}{1:  }{4:        return fi}|
483        {1:  }{2:------------------}{3:│}{1:  }{4:    }            }|
484        {1:  }{2:------------------}{3:│}{1:  }{4:    return 1;    }|
485        {1:  }{2:------------------}{3:│}{1:  }{4:}                }|
486        {1:  }{2:------------------}{3:│}{1:  }{4:                 }|
487        {1:  }// Frobs foo heart{3:│}{1:  }// Frobs foo hear|
488        {1:  }int frobnitz(int f{3:│}{1:  }int frobnitz(int |
489        {1:  }{                 {3:│}{1:  }{                |
490        {7:<onal-diff-screen-1  }{3:<l-diff-screen-1.2 }|
491                                                |
492      ]])
493
494      feed('G')
495      screen:expect([[
496        {1:  }                  {3:│}{1:  }                 |
497        {1:  }{4:int fact(int n)   }{3:│}{1:  }{2:-----------------}|
498        {1:  }{4:{                 }{3:│}{1:  }{2:-----------------}|
499        {1:  }{4:    if(n > 1)     }{3:│}{1:  }{2:-----------------}|
500        {1:  }{4:    {             }{3:│}{1:  }{2:-----------------}|
501        {1:  }{4:        return fac}{3:│}{1:  }{2:-----------------}|
502        {1:  }{4:    }             }{3:│}{1:  }{2:-----------------}|
503        {1:  }{4:    return 1;     }{3:│}{1:  }{2:-----------------}|
504        {1:  }{4:}                 }{3:│}{1:  }{2:-----------------}|
505        {1:  }{4:                  }{3:│}{1:  }{2:-----------------}|
506        {1:  }int main(int argc,{3:│}{1:  }int main(int argc|
507        {1:  }{                 {3:│}{1:  }{                |
508        {1:  }{9:    frobnitz(f}{8:act}{9:(}{3:│}{1:  }{9:    frobnitz(f}{8:ib}{9:(}|
509        {1:  }^}                 {3:│}{1:  }}                |
510        {7:<onal-diff-screen-1  }{3:<l-diff-screen-1.2 }|
511                                                |
512      ]])
513    end)
514  end)
515
516  describe('diffopt+=indent-heuristic', function()
517    setup(function()
518      local f1 = [[
519  def finalize(values)
520
521    values.each do |v|
522      v.finalize
523    end]]
524      write_file(fname, f1, false)
525      local f2 = [[
526  def finalize(values)
527
528    values.each do |v|
529      v.prepare
530    end
531
532    values.each do |v|
533      v.finalize
534    end]]
535      write_file(fname_2, f2, false)
536      feed(':diffupdate!<cr>')
537    end)
538
539    it('internal', function()
540      reread()
541      feed(":set diffopt=internal,filler<cr>")
542      screen:expect([[
543        {1:  }^def finalize(value{3:│}{1:  }def finalize(valu|
544        {1:  }                  {3:│}{1:  }                 |
545        {1:  }  values.each do |{3:│}{1:  }  values.each do |
546        {1:  }{2:------------------}{3:│}{1:  }{4:    v.prepare    }|
547        {1:  }{2:------------------}{3:│}{1:  }{4:  end            }|
548        {1:  }{2:------------------}{3:│}{1:  }{4:                 }|
549        {1:  }{2:------------------}{3:│}{1:  }{4:  values.each do }|
550        {1:  }    v.finalize    {3:│}{1:  }    v.finalize   |
551        {1:  }  end             {3:│}{1:  }  end            |
552        {6:~                   }{3:│}{6:~                  }|
553        {6:~                   }{3:│}{6:~                  }|
554        {6:~                   }{3:│}{6:~                  }|
555        {6:~                   }{3:│}{6:~                  }|
556        {6:~                   }{3:│}{6:~                  }|
557        {7:<onal-diff-screen-1  }{3:<l-diff-screen-1.2 }|
558        :set diffopt=internal,filler            |
559      ]])
560    end)
561
562    it('indent-heuristic', function()
563      reread()
564      feed(':set diffopt=internal,filler,indent-heuristic<cr>')
565      screen:expect([[
566        {1:  }^def finalize(value{3:│}{1:  }def finalize(valu|
567        {1:  }                  {3:│}{1:  }                 |
568        {1:  }{2:------------------}{3:│}{1:  }{4:  values.each do }|
569        {1:  }{2:------------------}{3:│}{1:  }{4:    v.prepare    }|
570        {1:  }{2:------------------}{3:│}{1:  }{4:  end            }|
571        {1:  }{2:------------------}{3:│}{1:  }{4:                 }|
572        {1:  }  values.each do |{3:│}{1:  }  values.each do |
573        {1:  }    v.finalize    {3:│}{1:  }    v.finalize   |
574        {1:  }  end             {3:│}{1:  }  end            |
575        {6:~                   }{3:│}{6:~                  }|
576        {6:~                   }{3:│}{6:~                  }|
577        {6:~                   }{3:│}{6:~                  }|
578        {6:~                   }{3:│}{6:~                  }|
579        {6:~                   }{3:│}{6:~                  }|
580        {7:<onal-diff-screen-1  }{3:<l-diff-screen-1.2 }|
581                                                |
582      ]])
583    end)
584
585    it('indent-heuristic random order', function()
586      reread()
587      feed(':set diffopt=internal,filler,indent-heuristic,algorithm:patience<cr>')
588      feed(':<cr>')
589      screen:expect([[
590        {1:  }^def finalize(value{3:│}{1:  }def finalize(valu|
591        {1:  }                  {3:│}{1:  }                 |
592        {1:  }{2:------------------}{3:│}{1:  }{4:  values.each do }|
593        {1:  }{2:------------------}{3:│}{1:  }{4:    v.prepare    }|
594        {1:  }{2:------------------}{3:│}{1:  }{4:  end            }|
595        {1:  }{2:------------------}{3:│}{1:  }{4:                 }|
596        {1:  }  values.each do |{3:│}{1:  }  values.each do |
597        {1:  }    v.finalize    {3:│}{1:  }    v.finalize   |
598        {1:  }  end             {3:│}{1:  }  end            |
599        {6:~                   }{3:│}{6:~                  }|
600        {6:~                   }{3:│}{6:~                  }|
601        {6:~                   }{3:│}{6:~                  }|
602        {6:~                   }{3:│}{6:~                  }|
603        {6:~                   }{3:│}{6:~                  }|
604        {7:<onal-diff-screen-1  }{3:<l-diff-screen-1.2 }|
605        :                                       |
606      ]])
607    end)
608  end)
609
610  it('Diff the same file', function()
611    write_file(fname, "1\n2\n3\n4\n5\n6\n7\n8\n9\n10\n", false)
612    write_file(fname_2, "1\n2\n3\n4\n5\n6\n7\n8\n9\n10\n", false)
613    reread()
614
615    feed(':set diffopt=filler<cr>')
616    screen:expect([[
617      {1:+ }{5:^+-- 10 lines: 1···}{3:│}{1:+ }{5:+-- 10 lines: 1··}|
618      {6:~                   }{3:│}{6:~                  }|
619      {6:~                   }{3:│}{6:~                  }|
620      {6:~                   }{3:│}{6:~                  }|
621      {6:~                   }{3:│}{6:~                  }|
622      {6:~                   }{3:│}{6:~                  }|
623      {6:~                   }{3:│}{6:~                  }|
624      {6:~                   }{3:│}{6:~                  }|
625      {6:~                   }{3:│}{6:~                  }|
626      {6:~                   }{3:│}{6:~                  }|
627      {6:~                   }{3:│}{6:~                  }|
628      {6:~                   }{3:│}{6:~                  }|
629      {6:~                   }{3:│}{6:~                  }|
630      {6:~                   }{3:│}{6:~                  }|
631      {7:<onal-diff-screen-1  }{3:<l-diff-screen-1.2 }|
632      :set diffopt=filler                     |
633    ]])
634
635    feed(':set diffopt+=internal<cr>')
636    screen:expect([[
637      {1:+ }{5:^+-- 10 lines: 1···}{3:│}{1:+ }{5:+-- 10 lines: 1··}|
638      {6:~                   }{3:│}{6:~                  }|
639      {6:~                   }{3:│}{6:~                  }|
640      {6:~                   }{3:│}{6:~                  }|
641      {6:~                   }{3:│}{6:~                  }|
642      {6:~                   }{3:│}{6:~                  }|
643      {6:~                   }{3:│}{6:~                  }|
644      {6:~                   }{3:│}{6:~                  }|
645      {6:~                   }{3:│}{6:~                  }|
646      {6:~                   }{3:│}{6:~                  }|
647      {6:~                   }{3:│}{6:~                  }|
648      {6:~                   }{3:│}{6:~                  }|
649      {6:~                   }{3:│}{6:~                  }|
650      {6:~                   }{3:│}{6:~                  }|
651      {7:<onal-diff-screen-1  }{3:<l-diff-screen-1.2 }|
652      :set diffopt+=internal                  |
653    ]])
654  end)
655
656  it('Diff an empty file', function()
657    write_file(fname, "", false)
658    write_file(fname_2, "", false)
659    reread()
660
661    feed(':set diffopt=filler<cr>')
662    screen:expect([[
663      {1:- }^                  {3:│}{1:- }                 |
664      {6:~                   }{3:│}{6:~                  }|
665      {6:~                   }{3:│}{6:~                  }|
666      {6:~                   }{3:│}{6:~                  }|
667      {6:~                   }{3:│}{6:~                  }|
668      {6:~                   }{3:│}{6:~                  }|
669      {6:~                   }{3:│}{6:~                  }|
670      {6:~                   }{3:│}{6:~                  }|
671      {6:~                   }{3:│}{6:~                  }|
672      {6:~                   }{3:│}{6:~                  }|
673      {6:~                   }{3:│}{6:~                  }|
674      {6:~                   }{3:│}{6:~                  }|
675      {6:~                   }{3:│}{6:~                  }|
676      {6:~                   }{3:│}{6:~                  }|
677      {7:<onal-diff-screen-1  }{3:<l-diff-screen-1.2 }|
678      :set diffopt=filler                     |
679    ]])
680
681    feed(':set diffopt+=internal<cr>')
682    screen:expect([[
683      {1:- }^                  {3:│}{1:- }                 |
684      {6:~                   }{3:│}{6:~                  }|
685      {6:~                   }{3:│}{6:~                  }|
686      {6:~                   }{3:│}{6:~                  }|
687      {6:~                   }{3:│}{6:~                  }|
688      {6:~                   }{3:│}{6:~                  }|
689      {6:~                   }{3:│}{6:~                  }|
690      {6:~                   }{3:│}{6:~                  }|
691      {6:~                   }{3:│}{6:~                  }|
692      {6:~                   }{3:│}{6:~                  }|
693      {6:~                   }{3:│}{6:~                  }|
694      {6:~                   }{3:│}{6:~                  }|
695      {6:~                   }{3:│}{6:~                  }|
696      {6:~                   }{3:│}{6:~                  }|
697      {7:<onal-diff-screen-1  }{3:<l-diff-screen-1.2 }|
698      :set diffopt+=internal                  |
699    ]])
700  end)
701
702  it('diffopt+=icase', function()
703    write_file(fname, "a\nb\ncd\n", false)
704    write_file(fname_2, "A\nb\ncDe\n", false)
705    reread()
706
707    feed(':set diffopt=filler,icase<cr>')
708    screen:expect([[
709      {1:  }^a                 {3:│}{1:  }A                |
710      {1:  }b                 {3:│}{1:  }b                |
711      {1:  }{9:cd                }{3:│}{1:  }{9:cD}{8:e}{9:              }|
712      {6:~                   }{3:│}{6:~                  }|
713      {6:~                   }{3:│}{6:~                  }|
714      {6:~                   }{3:│}{6:~                  }|
715      {6:~                   }{3:│}{6:~                  }|
716      {6:~                   }{3:│}{6:~                  }|
717      {6:~                   }{3:│}{6:~                  }|
718      {6:~                   }{3:│}{6:~                  }|
719      {6:~                   }{3:│}{6:~                  }|
720      {6:~                   }{3:│}{6:~                  }|
721      {6:~                   }{3:│}{6:~                  }|
722      {6:~                   }{3:│}{6:~                  }|
723      {7:<onal-diff-screen-1  }{3:<l-diff-screen-1.2 }|
724      :set diffopt=filler,icase               |
725    ]])
726
727    feed(':set diffopt+=internal<cr>')
728    screen:expect([[
729      {1:  }^a                 {3:│}{1:  }A                |
730      {1:  }b                 {3:│}{1:  }b                |
731      {1:  }{9:cd                }{3:│}{1:  }{9:cD}{8:e}{9:              }|
732      {6:~                   }{3:│}{6:~                  }|
733      {6:~                   }{3:│}{6:~                  }|
734      {6:~                   }{3:│}{6:~                  }|
735      {6:~                   }{3:│}{6:~                  }|
736      {6:~                   }{3:│}{6:~                  }|
737      {6:~                   }{3:│}{6:~                  }|
738      {6:~                   }{3:│}{6:~                  }|
739      {6:~                   }{3:│}{6:~                  }|
740      {6:~                   }{3:│}{6:~                  }|
741      {6:~                   }{3:│}{6:~                  }|
742      {6:~                   }{3:│}{6:~                  }|
743      {7:<onal-diff-screen-1  }{3:<l-diff-screen-1.2 }|
744      :set diffopt+=internal                  |
745    ]])
746  end)
747
748  describe('diffopt+=iwhite', function()
749    setup(function()
750      local f1 = 'int main()\n{\n   printf("Hello, World!");\n   return 0;\n}\n'
751      write_file(fname, f1, false)
752      local f2 = 'int main()\n{\n   if (0)\n   {\n      printf("Hello, World!");\n      return 0;\n   }\n}\n'
753      write_file(fname_2, f2, false)
754      feed(':diffupdate!<cr>')
755    end)
756
757    it('external', function()
758      reread()
759      feed(':set diffopt=filler,iwhite<cr>')
760      screen:expect([[
761        {1:  }^int main()        {3:│}{1:  }int main()       |
762        {1:  }{                 {3:│}{1:  }{                |
763        {1:  }{2:------------------}{3:│}{1:  }{4:   if (0)        }|
764        {1:  }{2:------------------}{3:│}{1:  }{4:   {             }|
765        {1:  }   printf("Hello, {3:│}{1:  }      printf("Hel|
766        {1:  }   return 0;      {3:│}{1:  }      return 0;  |
767        {1:  }{2:------------------}{3:│}{1:  }{4:   }             }|
768        {1:  }}                 {3:│}{1:  }}                |
769        {6:~                   }{3:│}{6:~                  }|
770        {6:~                   }{3:│}{6:~                  }|
771        {6:~                   }{3:│}{6:~                  }|
772        {6:~                   }{3:│}{6:~                  }|
773        {6:~                   }{3:│}{6:~                  }|
774        {6:~                   }{3:│}{6:~                  }|
775        {7:<onal-diff-screen-1  }{3:<l-diff-screen-1.2 }|
776        :set diffopt=filler,iwhite              |
777      ]])
778    end)
779
780    it('internal', function()
781      reread()
782      feed(':set diffopt=filler,iwhite,internal<cr>')
783      screen:expect([[
784        {1:  }^int main()        {3:│}{1:  }int main()       |
785        {1:  }{                 {3:│}{1:  }{                |
786        {1:  }{2:------------------}{3:│}{1:  }{4:   if (0)        }|
787        {1:  }{2:------------------}{3:│}{1:  }{4:   {             }|
788        {1:  }   printf("Hello, {3:│}{1:  }      printf("Hel|
789        {1:  }   return 0;      {3:│}{1:  }      return 0;  |
790        {1:  }{2:------------------}{3:│}{1:  }{4:   }             }|
791        {1:  }}                 {3:│}{1:  }}                |
792        {6:~                   }{3:│}{6:~                  }|
793        {6:~                   }{3:│}{6:~                  }|
794        {6:~                   }{3:│}{6:~                  }|
795        {6:~                   }{3:│}{6:~                  }|
796        {6:~                   }{3:│}{6:~                  }|
797        {6:~                   }{3:│}{6:~                  }|
798        {7:<onal-diff-screen-1  }{3:<l-diff-screen-1.2 }|
799        :set diffopt=filler,iwhite,internal     |
800      ]])
801    end)
802  end)
803
804  describe('diffopt+=iblank', function()
805    setup(function()
806      write_file(fname, 'a\n\n \ncd\nef\nxxx\n', false)
807      write_file(fname_2, 'a\ncd\n\nef\nyyy\n', false)
808      feed(':diffupdate!<cr>')
809    end)
810
811    it('generic', function()
812      reread()
813      feed(':set diffopt=internal,filler,iblank<cr>')
814      screen:expect([[
815        {1:  }^a                 {3:│}{1:  }a                |
816        {1:  }{4:                  }{3:│}{1:  }{2:-----------------}|
817        {1:  }{4:                  }{3:│}{1:  }{2:-----------------}|
818        {1:  }cd                {3:│}{1:  }cd               |
819        {1:  }ef                {3:│}{1:  }                 |
820        {1:  }{8:xxx}{9:               }{3:│}{1:  }ef               |
821        {6:~                   }{3:│}{1:  }{8:yyy}{9:              }|
822        {6:~                   }{3:│}{6:~                  }|
823        {6:~                   }{3:│}{6:~                  }|
824        {6:~                   }{3:│}{6:~                  }|
825        {6:~                   }{3:│}{6:~                  }|
826        {6:~                   }{3:│}{6:~                  }|
827        {6:~                   }{3:│}{6:~                  }|
828        {6:~                   }{3:│}{6:~                  }|
829        {7:<onal-diff-screen-1  }{3:<l-diff-screen-1.2 }|
830        :set diffopt=internal,filler,iblank     |
831      ]])
832    end)
833
834    it('diffopt+=iwhite', function()
835      reread()
836      feed(':set diffopt=internal,filler,iblank,iwhite<cr>')
837      feed(':<cr>')
838      screen:expect([[
839        {1:  }^a                 {3:│}{1:  }a                |
840        {1:  }                  {3:│}{1:  }cd               |
841        {1:  }                  {3:│}{1:  }                 |
842        {1:  }cd                {3:│}{1:  }ef               |
843        {1:  }ef                {3:│}{1:  }{8:yyy}{9:              }|
844        {1:  }{8:xxx}{9:               }{3:│}{6:~                  }|
845        {6:~                   }{3:│}{6:~                  }|
846        {6:~                   }{3:│}{6:~                  }|
847        {6:~                   }{3:│}{6:~                  }|
848        {6:~                   }{3:│}{6:~                  }|
849        {6:~                   }{3:│}{6:~                  }|
850        {6:~                   }{3:│}{6:~                  }|
851        {6:~                   }{3:│}{6:~                  }|
852        {6:~                   }{3:│}{6:~                  }|
853        {7:<onal-diff-screen-1  }{3:<l-diff-screen-1.2 }|
854        :                                       |
855      ]])
856    end)
857
858    it('diffopt+=iwhiteall', function()
859      reread()
860      feed(':set diffopt=internal,filler,iblank,iwhiteall<cr>')
861      feed(':<cr>')
862      screen:expect([[
863        {1:  }^a                 {3:│}{1:  }a                |
864        {1:  }                  {3:│}{1:  }cd               |
865        {1:  }                  {3:│}{1:  }                 |
866        {1:  }cd                {3:│}{1:  }ef               |
867        {1:  }ef                {3:│}{1:  }{8:yyy}{9:              }|
868        {1:  }{8:xxx}{9:               }{3:│}{6:~                  }|
869        {6:~                   }{3:│}{6:~                  }|
870        {6:~                   }{3:│}{6:~                  }|
871        {6:~                   }{3:│}{6:~                  }|
872        {6:~                   }{3:│}{6:~                  }|
873        {6:~                   }{3:│}{6:~                  }|
874        {6:~                   }{3:│}{6:~                  }|
875        {6:~                   }{3:│}{6:~                  }|
876        {6:~                   }{3:│}{6:~                  }|
877        {7:<onal-diff-screen-1  }{3:<l-diff-screen-1.2 }|
878        :                                       |
879      ]])
880    end)
881
882    it('diffopt+=iwhiteeol', function()
883      reread()
884      feed(':set diffopt=internal,filler,iblank,iwhiteeol<cr>')
885      feed(':<cr>')
886      screen:expect([[
887        {1:  }^a                 {3:│}{1:  }a                |
888        {1:  }                  {3:│}{1:  }cd               |
889        {1:  }                  {3:│}{1:  }                 |
890        {1:  }cd                {3:│}{1:  }ef               |
891        {1:  }ef                {3:│}{1:  }{8:yyy}{9:              }|
892        {1:  }{8:xxx}{9:               }{3:│}{6:~                  }|
893        {6:~                   }{3:│}{6:~                  }|
894        {6:~                   }{3:│}{6:~                  }|
895        {6:~                   }{3:│}{6:~                  }|
896        {6:~                   }{3:│}{6:~                  }|
897        {6:~                   }{3:│}{6:~                  }|
898        {6:~                   }{3:│}{6:~                  }|
899        {6:~                   }{3:│}{6:~                  }|
900        {6:~                   }{3:│}{6:~                  }|
901        {7:<onal-diff-screen-1  }{3:<l-diff-screen-1.2 }|
902        :                                       |
903      ]])
904    end)
905  end)
906
907  describe('diffopt+=iwhite{eol,all}', function()
908    setup(function()
909      write_file(fname, 'a \nx\ncd\nef\nxx  xx\nfoo\nbar\n', false)
910      write_file(fname_2, 'a\nx\nc d\n ef\nxx xx\nfoo\n\nbar\n', false)
911      feed(':diffupdate!<cr>')
912    end)
913
914    it('diffopt+=iwhiteeol', function()
915      reread()
916      feed(':set diffopt=internal,filler,iwhiteeol<cr>')
917      feed(':<cr>')
918      screen:expect([[
919        {1:  }^a                 {3:│}{1:  }a                |
920        {1:  }x                 {3:│}{1:  }x                |
921        {1:  }{9:cd                }{3:│}{1:  }{9:c}{8: }{9:d              }|
922        {1:  }{9:ef                }{3:│}{1:  }{8: }{9:ef              }|
923        {1:  }{9:xx }{8: }{9:xx            }{3:│}{1:  }{9:xx xx            }|
924        {1:  }foo               {3:│}{1:  }foo              |
925        {1:  }{2:------------------}{3:│}{1:  }{4:                 }|
926        {1:  }bar               {3:│}{1:  }bar              |
927        {6:~                   }{3:│}{6:~                  }|
928        {6:~                   }{3:│}{6:~                  }|
929        {6:~                   }{3:│}{6:~                  }|
930        {6:~                   }{3:│}{6:~                  }|
931        {6:~                   }{3:│}{6:~                  }|
932        {6:~                   }{3:│}{6:~                  }|
933        {7:<onal-diff-screen-1  }{3:<l-diff-screen-1.2 }|
934        :                                       |
935      ]])
936    end)
937
938    it('diffopt+=iwhiteall', function()
939      reread()
940      feed(':set diffopt=internal,filler,iwhiteall<cr>')
941      feed(':<cr>')
942      screen:expect([[
943        {1:  }^a                 {3:│}{1:  }a                |
944        {1:  }x                 {3:│}{1:  }x                |
945        {1:  }cd                {3:│}{1:  }c d              |
946        {1:  }ef                {3:│}{1:  } ef              |
947        {1:  }xx  xx            {3:│}{1:  }xx xx            |
948        {1:  }foo               {3:│}{1:  }foo              |
949        {1:  }{2:------------------}{3:│}{1:  }{4:                 }|
950        {1:  }bar               {3:│}{1:  }bar              |
951        {6:~                   }{3:│}{6:~                  }|
952        {6:~                   }{3:│}{6:~                  }|
953        {6:~                   }{3:│}{6:~                  }|
954        {6:~                   }{3:│}{6:~                  }|
955        {6:~                   }{3:│}{6:~                  }|
956        {6:~                   }{3:│}{6:~                  }|
957        {7:<onal-diff-screen-1  }{3:<l-diff-screen-1.2 }|
958        :                                       |
959      ]])
960    end)
961  end)
962end)
963
964it('win_update redraws lines properly', function()
965  local screen
966  clear()
967  screen = Screen.new(50, 10)
968  screen:attach()
969  screen:set_default_attr_ids({
970    [1] = {bold = true, foreground = Screen.colors.Blue1},
971    [2] = {foreground = Screen.colors.Grey100, background = Screen.colors.Red},
972    [3] = {background = Screen.colors.Red, foreground = Screen.colors.Grey100, special = Screen.colors.Yellow},
973    [4] = {bold = true, foreground = Screen.colors.SeaGreen4},
974    [5] = {special = Screen.colors.Yellow},
975    [6] = {special = Screen.colors.Yellow, bold = true, foreground = Screen.colors.SeaGreen4},
976    [7] = {foreground = Screen.colors.Grey0, background = Screen.colors.Grey100},
977    [8] = {foreground = Screen.colors.Gray90, background = Screen.colors.Grey100},
978    [9] = {foreground = tonumber('0x00000c'), background = Screen.colors.Grey100},
979    [10] = {background = Screen.colors.Grey100, bold = true, foreground = tonumber('0xe5e5ff')},
980    [11] = {background = Screen.colors.Grey100, bold = true, foreground = tonumber('0x2b8452')},
981    [12] = {bold = true, reverse = true},
982    [13] = {foreground = Screen.colors.DarkBlue, background = Screen.colors.WebGray},
983    [14] = {reverse = true},
984    [15] = {background = Screen.colors.LightBlue},
985    [16] = {background = Screen.colors.LightCyan1, bold = true, foreground = Screen.colors.Blue1},
986    [17] = {bold = true, background = Screen.colors.Red},
987    [18] = {background = Screen.colors.LightMagenta},
988  })
989
990  insert([[
991  1
992
993
994  2
995  1a
996  ]])
997  command("vnew left")
998  insert([[
999  2
1000  2a
1001  2b
1002  ]])
1003  command("windo diffthis")
1004  command("windo 1")
1005  screen:expect{grid=[[
1006    {13:  }{16:-----------------------}{14:│}{13:  }{15:^1                     }|
1007    {13:  }{16:-----------------------}{14:│}{13:  }{15:                      }|
1008    {13:  }{16:-----------------------}{14:│}{13:  }{15:                      }|
1009    {13:  }2                      {14:│}{13:  }2                     |
1010    {13:  }{17:2}{18:a                     }{14:│}{13:  }{17:1}{18:a                    }|
1011    {13:  }{15:2b                     }{14:│}{13:  }{16:----------------------}|
1012    {13:  }                       {14:│}{13:  }                      |
1013    {1:~                        }{14:│}{1:~                       }|
1014    {14:left [+]                  }{12:[No Name] [+]           }|
1015                                                      |
1016  ]]}
1017  feed('<C-e>')
1018  feed('<C-e>')
1019  feed('<C-y>')
1020  feed('<C-y>')
1021  feed('<C-y>')
1022  screen:expect{grid=[[
1023    {13:  }{16:-----------------------}{14:│}{13:  }{15:1                     }|
1024    {13:  }{16:-----------------------}{14:│}{13:  }{15:                      }|
1025    {13:  }{16:-----------------------}{14:│}{13:  }{15:^                      }|
1026    {13:  }2                      {14:│}{13:  }2                     |
1027    {13:  }{17:2}{18:a                     }{14:│}{13:  }{17:1}{18:a                    }|
1028    {13:  }{15:2b                     }{14:│}{13:  }{16:----------------------}|
1029    {13:  }                       {14:│}{13:  }                      |
1030    {1:~                        }{14:│}{1:~                       }|
1031    {14:left [+]                  }{12:[No Name] [+]           }|
1032                                                      |
1033  ]]}
1034end)
1035
1036it('diff updates line numbers below filler lines', function()
1037  clear()
1038  local screen = Screen.new(40, 14)
1039  screen:attach()
1040  screen:set_default_attr_ids({
1041    [1] = {foreground = Screen.colors.DarkBlue, background = Screen.colors.WebGray},
1042    [2] = {background = Screen.colors.LightCyan1, bold = true, foreground = Screen.colors.Blue1},
1043    [3] = {reverse = true},
1044    [4] = {background = Screen.colors.LightBlue},
1045    [5] = {foreground = Screen.colors.DarkBlue, background = Screen.colors.LightGrey},
1046    [6] = {bold = true, foreground = Screen.colors.Blue1},
1047    [7] = {bold = true, reverse = true},
1048    [8] = {bold = true, background = Screen.colors.Red},
1049    [9] = {background = Screen.colors.LightMagenta},
1050    [10] = {bold = true, foreground = Screen.colors.Brown},
1051    [11] = {foreground = Screen.colors.Brown},
1052    [12] = {foreground = Screen.colors.Brown, bold = true, background = Screen.colors.Red};
1053    [13] = {background = Screen.colors.Gray90};
1054  })
1055  source([[
1056    call setline(1, ['a', 'a', 'a', 'y', 'b', 'b', 'b', 'b', 'b'])
1057    vnew
1058    call setline(1, ['a', 'a', 'a', 'x', 'x', 'x', 'b', 'b', 'b', 'b', 'b'])
1059    windo diffthis
1060    setlocal number rnu cursorline cursorlineopt=number foldcolumn=0
1061  ]])
1062  screen:expect([[
1063    {1:  }a                {3:│}{10:1   }^a               |
1064    {1:  }a                {3:│}{11:  1 }a               |
1065    {1:  }a                {3:│}{11:  2 }a               |
1066    {1:  }{8:x}{9:                }{3:│}{11:  3 }{8:y}{9:               }|
1067    {1:  }{4:x                }{3:│}{11:    }{2:----------------}|
1068    {1:  }{4:x                }{3:│}{11:    }{2:----------------}|
1069    {1:  }b                {3:│}{11:  4 }b               |
1070    {1:  }b                {3:│}{11:  5 }b               |
1071    {1:  }b                {3:│}{11:  6 }b               |
1072    {1:  }b                {3:│}{11:  7 }b               |
1073    {1:  }b                {3:│}{11:  8 }b               |
1074    {6:~                  }{3:│}{6:~                   }|
1075    {3:[No Name] [+]       }{7:[No Name] [+]       }|
1076                                            |
1077  ]])
1078  feed('j')
1079  screen:expect([[
1080    {1:  }a                {3:│}{11:  1 }a               |
1081    {1:  }a                {3:│}{10:2   }^a               |
1082    {1:  }a                {3:│}{11:  1 }a               |
1083    {1:  }{8:x}{9:                }{3:│}{11:  2 }{8:y}{9:               }|
1084    {1:  }{4:x                }{3:│}{11:    }{2:----------------}|
1085    {1:  }{4:x                }{3:│}{11:    }{2:----------------}|
1086    {1:  }b                {3:│}{11:  3 }b               |
1087    {1:  }b                {3:│}{11:  4 }b               |
1088    {1:  }b                {3:│}{11:  5 }b               |
1089    {1:  }b                {3:│}{11:  6 }b               |
1090    {1:  }b                {3:│}{11:  7 }b               |
1091    {6:~                  }{3:│}{6:~                   }|
1092    {3:[No Name] [+]       }{7:[No Name] [+]       }|
1093                                            |
1094  ]])
1095  feed('j')
1096  screen:expect([[
1097    {1:  }a                {3:│}{11:  2 }a               |
1098    {1:  }a                {3:│}{11:  1 }a               |
1099    {1:  }a                {3:│}{10:3   }^a               |
1100    {1:  }{8:x}{9:                }{3:│}{11:  1 }{8:y}{9:               }|
1101    {1:  }{4:x                }{3:│}{11:    }{2:----------------}|
1102    {1:  }{4:x                }{3:│}{11:    }{2:----------------}|
1103    {1:  }b                {3:│}{11:  2 }b               |
1104    {1:  }b                {3:│}{11:  3 }b               |
1105    {1:  }b                {3:│}{11:  4 }b               |
1106    {1:  }b                {3:│}{11:  5 }b               |
1107    {1:  }b                {3:│}{11:  6 }b               |
1108    {6:~                  }{3:│}{6:~                   }|
1109    {3:[No Name] [+]       }{7:[No Name] [+]       }|
1110                                            |
1111  ]])
1112  command("set signcolumn number tgc cursorline cursorlineopt=number,line")
1113  command("hi CursorLineNr guibg=red")
1114  screen:expect{grid=[[
1115    {1:  }a                {3:│}{11:  2 }a               |
1116    {1:  }a                {3:│}{11:  1 }a               |
1117    {1:  }a                {3:│}{12:3   }{13:^a               }|
1118    {1:  }{8:x}{9:                }{3:│}{11:  1 }{8:y}{9:               }|
1119    {1:  }{4:x                }{3:│}{11:    }{2:----------------}|
1120    {1:  }{4:x                }{3:│}{11:    }{2:----------------}|
1121    {1:  }b                {3:│}{11:  2 }b               |
1122    {1:  }b                {3:│}{11:  3 }b               |
1123    {1:  }b                {3:│}{11:  4 }b               |
1124    {1:  }b                {3:│}{11:  5 }b               |
1125    {1:  }b                {3:│}{11:  6 }b               |
1126    {6:~                  }{3:│}{6:~                   }|
1127    {3:[No Name] [+]       }{7:[No Name] [+]       }|
1128      signcolumn=auto                       |
1129  ]]}
1130end)
1131
1132it('Align the filler lines when changing text in diff mode', function()
1133  clear()
1134  local screen = Screen.new(40, 20)
1135  screen:attach()
1136  screen:set_default_attr_ids({
1137    [1] = {foreground = Screen.colors.DarkBlue, background = Screen.colors.Gray};
1138    [2] = {background = Screen.colors.LightCyan, foreground = Screen.colors.Blue1, bold = true};
1139    [3] = {reverse = true};
1140    [4] = {background = Screen.colors.LightBlue};
1141    [5] = {background = Screen.colors.LightMagenta};
1142    [6] = {background = Screen.colors.Red, bold = true};
1143    [7] = {foreground = Screen.colors.Blue1, bold = true};
1144    [8] = {reverse = true, bold = true};
1145  })
1146  source([[
1147    call setline(1, range(1, 15))
1148    vnew
1149    call setline(1, range(9, 15))
1150    windo diffthis
1151    wincmd h
1152    exe "normal Gl5\<C-E>"
1153  ]])
1154  screen:expect{grid=[[
1155    {1:  }{2:------------------}{3:│}{1:  }{4:6                }|
1156    {1:  }{2:------------------}{3:│}{1:  }{4:7                }|
1157    {1:  }{2:------------------}{3:│}{1:  }{4:8                }|
1158    {1:  }9                 {3:│}{1:  }9                |
1159    {1:  }10                {3:│}{1:  }10               |
1160    {1:  }11                {3:│}{1:  }11               |
1161    {1:  }12                {3:│}{1:  }12               |
1162    {1:  }13                {3:│}{1:  }13               |
1163    {1:  }14                {3:│}{1:  }14               |
1164    {1:- }1^5                {3:│}{1:- }15               |
1165    {7:~                   }{3:│}{7:~                  }|
1166    {7:~                   }{3:│}{7:~                  }|
1167    {7:~                   }{3:│}{7:~                  }|
1168    {7:~                   }{3:│}{7:~                  }|
1169    {7:~                   }{3:│}{7:~                  }|
1170    {7:~                   }{3:│}{7:~                  }|
1171    {7:~                   }{3:│}{7:~                  }|
1172    {7:~                   }{3:│}{7:~                  }|
1173    {8:[No Name] [+]        }{3:[No Name] [+]      }|
1174                                            |
1175  ]]}
1176  feed('ax<Esc>')
1177  screen:expect{grid=[[
1178    {1:  }{2:------------------}{3:│}{1:  }{4:6                }|
1179    {1:  }{2:------------------}{3:│}{1:  }{4:7                }|
1180    {1:  }{2:------------------}{3:│}{1:  }{4:8                }|
1181    {1:  }9                 {3:│}{1:  }9                |
1182    {1:  }10                {3:│}{1:  }10               |
1183    {1:  }11                {3:│}{1:  }11               |
1184    {1:  }12                {3:│}{1:  }12               |
1185    {1:  }13                {3:│}{1:  }13               |
1186    {1:  }14                {3:│}{1:  }14               |
1187    {1:  }{5:15}{6:^x}{5:               }{3:│}{1:  }{5:15               }|
1188    {7:~                   }{3:│}{7:~                  }|
1189    {7:~                   }{3:│}{7:~                  }|
1190    {7:~                   }{3:│}{7:~                  }|
1191    {7:~                   }{3:│}{7:~                  }|
1192    {7:~                   }{3:│}{7:~                  }|
1193    {7:~                   }{3:│}{7:~                  }|
1194    {7:~                   }{3:│}{7:~                  }|
1195    {7:~                   }{3:│}{7:~                  }|
1196    {8:[No Name] [+]        }{3:[No Name] [+]      }|
1197                                            |
1198  ]]}
1199  feed('<C-W>lay<Esc>')
1200  screen:expect{grid=[[
1201    {1:  }{2:-----------------}{3:│}{1:  }{4:6                 }|
1202    {1:  }{2:-----------------}{3:│}{1:  }{4:7                 }|
1203    {1:  }{2:-----------------}{3:│}{1:  }{4:8                 }|
1204    {1:  }9                {3:│}{1:  }9                 |
1205    {1:  }10               {3:│}{1:  }10                |
1206    {1:  }11               {3:│}{1:  }11                |
1207    {1:  }12               {3:│}{1:  }12                |
1208    {1:  }13               {3:│}{1:  }13                |
1209    {1:  }14               {3:│}{1:  }14                |
1210    {1:  }{5:15}{6:x}{5:              }{3:│}{1:  }{5:15}{6:^y}{5:               }|
1211    {7:~                  }{3:│}{7:~                   }|
1212    {7:~                  }{3:│}{7:~                   }|
1213    {7:~                  }{3:│}{7:~                   }|
1214    {7:~                  }{3:│}{7:~                   }|
1215    {7:~                  }{3:│}{7:~                   }|
1216    {7:~                  }{3:│}{7:~                   }|
1217    {7:~                  }{3:│}{7:~                   }|
1218    {7:~                  }{3:│}{7:~                   }|
1219    {3:[No Name] [+]       }{8:[No Name] [+]       }|
1220                                            |
1221  ]]}
1222end)
1223