robin/laufey

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

Justin M. KeyesMerge #40865 from justinmk/fixcif907614088

master
19.5 KiB583 linesraw
1local t = require('test.testutil')
2local n = require('test.functional.testnvim')()
3local Screen = require('test.functional.ui.screen')
4local tt = require('test.functional.testterm')
5
6local describe, it, before_each = t.describe, t.it, t.before_each
7local clear, insert = n.clear, n.insert
8local command = n.command
9local api = n.api
10local testprg = n.testprg
11local skip = t.skip
12local is_os = t.is_os
13
14describe('ext_hlstate detailed highlights', function()
15  local screen
16
17  before_each(function()
18    clear()
19    command('syntax on')
20    command('hi VertSplit gui=reverse')
21    screen = Screen.new(40, 8, { ext_hlstate = true })
22  end)
23
24  it('work with combined UI and syntax highlights', function()
25    insert([[
26      these are some lines
27      with colorful text]])
28    api.nvim_buf_add_highlight(0, -1, 'String', 0, 10, 14)
29    api.nvim_buf_add_highlight(0, -1, 'Statement', 1, 5, -1)
30    command('/th co')
31
32    screen:expect {
33      grid = [[
34      these are {1:some} lines                    |
35      ^wi{2:th }{4:co}{3:lorful text}                      |
36      {5:~                                       }|*5
37      {8:search hit BOTTOM, continuing at TOP}{6:    }|
38    ]],
39      attr_ids = {
40        [1] = {
41          { foreground = Screen.colors.Magenta1 },
42          { { kind = 'syntax', hi_name = 'Constant' } },
43        },
44        [2] = {
45          { background = Screen.colors.Yellow1 },
46          { { kind = 'ui', ui_name = 'Search', hi_name = 'Search' } },
47        },
48        [3] = {
49          { foreground = Screen.colors.Brown, bold = true },
50          { { kind = 'syntax', hi_name = 'Statement' } },
51        },
52        [4] = {
53          { background = Screen.colors.Yellow1, bold = true, foreground = Screen.colors.Brown },
54          { 3, 2 },
55        },
56        [5] = {
57          { foreground = Screen.colors.Blue, bold = true },
58          { { kind = 'ui', ui_name = 'EndOfBuffer', hi_name = 'NonText' } },
59        },
60        [6] = { {}, { { kind = 'ui', ui_name = 'MsgArea', hi_name = 'MsgArea' } } },
61        [7] = {
62          { foreground = Screen.colors.Red1 },
63          { { kind = 'syntax', hi_name = 'WarningMsg' } },
64        },
65        [8] = { { foreground = Screen.colors.Red1 }, { 6, 7 } },
66      },
67    }
68  end)
69
70  it('work with cleared UI highlights', function()
71    screen:set_default_attr_ids({
72      [1] = { {}, { { hi_name = 'Normal', ui_name = 'WinSeparator', kind = 'ui' } } },
73      [2] = {
74        { bold = true, foreground = Screen.colors.Blue1 },
75        { { hi_name = 'NonText', ui_name = 'EndOfBuffer', kind = 'ui' } },
76      },
77      [3] = {
78        { bold = true, reverse = true },
79        { { hi_name = 'StatusLine', ui_name = 'StatusLine', kind = 'ui' } },
80      },
81      [4] = {
82        { reverse = true },
83        { { hi_name = 'StatusLineNC', ui_name = 'StatusLineNC', kind = 'ui' } },
84      },
85      [5] = { {}, { { hi_name = 'StatusLine', ui_name = 'StatusLine', kind = 'ui' } } },
86      [6] = { {}, { { hi_name = 'StatusLineNC', ui_name = 'StatusLineNC', kind = 'ui' } } },
87      [7] = { {}, { { hi_name = 'MsgArea', ui_name = 'MsgArea', kind = 'ui' } } },
88    })
89    command('hi clear WinSeparator')
90    command('vsplit')
91
92    screen:expect([[
93      ^                    {1:│}                   |
94      {2:~                   }{1:│}{2:~                  }|*5
95      {3:[No Name]            }{4:[No Name]          }|
96      {7:                                        }|
97    ]])
98
99    command('hi clear StatusLine | hi clear StatuslineNC')
100    screen:expect([[
101      ^                    {1:│}                   |
102      {2:~                   }{1:│}{2:~                  }|*5
103      {5:[No Name]            }{6:[No Name]          }|
104      {7:                                        }|
105    ]])
106
107    -- redrawing is done even if visible highlights didn't change
108    command('wincmd w')
109    screen:expect([[
110                         {1:│}^                    |
111      {2:~                  }{1:│}{2:~                   }|*5
112      {6:[No Name]           }{5:[No Name]           }|
113      {7:                                        }|
114    ]])
115  end)
116
117  it('work with window-local highlights', function()
118    screen:set_default_attr_ids({
119      [1] = {
120        { foreground = Screen.colors.Brown },
121        { { hi_name = 'LineNr', ui_name = 'LineNr', kind = 'ui' } },
122      },
123      [2] = {
124        { bold = true, foreground = Screen.colors.Blue1 },
125        { { hi_name = 'NonText', ui_name = 'EndOfBuffer', kind = 'ui' } },
126      },
127      [3] = {
128        { bold = true, reverse = true },
129        { { hi_name = 'StatusLine', ui_name = 'StatusLine', kind = 'ui' } },
130      },
131      [4] = {
132        { reverse = true },
133        { { hi_name = 'StatusLineNC', ui_name = 'StatusLineNC', kind = 'ui' } },
134      },
135      [5] = {
136        { background = Screen.colors.Red, foreground = Screen.colors.Grey100 },
137        { { hi_name = 'ErrorMsg', ui_name = 'LineNr', kind = 'ui' } },
138      },
139      [6] = {
140        { bold = true, reverse = true },
141        { { hi_name = 'Normal', ui_name = 'Normal', kind = 'ui' } },
142      },
143      [7] = { { foreground = Screen.colors.Brown, bold = true, reverse = true }, { 6, 1 } },
144      [8] = { { foreground = Screen.colors.Blue1, bold = true, reverse = true }, { 6, 14 } },
145      [9] = {
146        { bold = true, foreground = Screen.colors.Brown },
147        { { hi_name = 'NormalNC', ui_name = 'NormalNC', kind = 'ui' } },
148      },
149      [10] = { { bold = true, foreground = Screen.colors.Brown }, { 9, 1 } },
150      [11] = { { bold = true, foreground = Screen.colors.Blue1 }, { 9, 14 } },
151      [12] = { {}, { { hi_name = 'MsgArea', ui_name = 'MsgArea', kind = 'ui' } } },
152      [13] = {
153        { background = Screen.colors.Red1, foreground = Screen.colors.Gray100 },
154        { { ui_name = 'LineNr', kind = 'ui', hi_name = 'LineNr' } },
155      },
156      [14] = {
157        { bold = true, foreground = Screen.colors.Blue },
158        { { ui_name = 'EndOfBuffer', kind = 'ui', hi_name = 'EndOfBuffer' } },
159      },
160    })
161
162    command('set number')
163    command('split')
164    -- NormalNC is not applied if not set, to avoid spurious redraws
165    screen:expect([[
166      {1:  1 }^                                    |
167      {2:~                                       }|*2
168      {3:[No Name]                               }|
169      {1:  1 }                                    |
170      {2:~                                       }|
171      {4:[No Name]                               }|
172      {12:                                        }|
173    ]])
174
175    command('set winhl=LineNr:ErrorMsg')
176    screen:expect {
177      grid = [[
178      {13:  1 }^                                    |
179      {14:~                                       }|*2
180      {3:[No Name]                               }|
181      {1:  1 }                                    |
182      {2:~                                       }|
183      {4:[No Name]                               }|
184      {12:                                        }|
185    ]],
186    }
187
188    command('set winhl=Normal:MsgSeparator,NormalNC:Statement')
189    screen:expect([[
190      {7:  1 }{6:^                                    }|
191      {8:~                                       }|*2
192      {3:[No Name]                               }|
193      {1:  1 }                                    |
194      {2:~                                       }|
195      {4:[No Name]                               }|
196      {12:                                        }|
197    ]])
198
199    command('wincmd w')
200    screen:expect([[
201      {10:  1 }{9:                                    }|
202      {11:~                                       }|*2
203      {4:[No Name]                               }|
204      {1:  1 }^                                    |
205      {2:~                                       }|
206      {3:[No Name]                               }|
207      {12:                                        }|
208    ]])
209  end)
210
211  it('work with :terminal', function()
212    skip(is_os('win'))
213
214    screen:set_default_attr_ids({
215      [1] = { {}, { { hi_name = 'TermCursorNC', ui_name = 'TermCursorNC', kind = 'ui' } } },
216      [2] = { { foreground = tonumber('0x00ccff'), fg_indexed = true }, { { kind = 'term' } } },
217      [3] = {
218        { bold = true, foreground = tonumber('0x00ccff'), fg_indexed = true },
219        {
220          { kind = 'term' },
221        },
222      },
223      [4] = { { foreground = tonumber('0x00ccff'), fg_indexed = true }, { 2, 1 } },
224      [5] = { { foreground = tonumber('0x40ffff'), fg_indexed = true }, { { kind = 'term' } } },
225      [6] = { { foreground = tonumber('0x40ffff'), fg_indexed = true }, { 5, 1 } },
226      [7] = { {}, { { hi_name = 'MsgArea', ui_name = 'MsgArea', kind = 'ui' } } },
227    })
228    command(("enew | call jobstart(['%s'],{'term':v:true})"):format(testprg('tty-test')))
229    screen:expect([[
230      ^tty ready                               |
231                                              |*6
232      {7:                                        }|
233    ]])
234
235    tt.feed_data('x ')
236    tt.set_fg(45)
237    tt.feed_data('y ')
238    tt.set_bold()
239    tt.feed_data('z\n')
240    -- TODO(bfredl): check if this distinction makes sense
241    if is_os('win') then
242      screen:expect([[
243        ^tty ready                               |
244        x {5:y z}                                   |
245                                                |*5
246        {7:                                        }|
247      ]])
248    else
249      screen:expect([[
250        ^tty ready                               |
251        x {2:y }{3:z}                                   |
252                                                |*5
253        {7:                                        }|
254      ]])
255    end
256
257    tt.feed_termcode('[A')
258    tt.feed_termcode('[2C')
259    if is_os('win') then
260      screen:expect([[
261        ^tty ready                               |
262        x {6:y}{5: z}                                   |
263                                                |*5
264        {7:                                        }|
265      ]])
266    else
267      screen:expect([[
268        ^tty ready                               |
269        x {2:y }{3:z}                                   |
270                                                |*5
271        {7:                                        }|
272      ]])
273    end
274  end)
275
276  it('can use independent cterm and rgb colors', function()
277    -- tell test module to save all attributes (doesn't change nvim options)
278    screen:set_rgb_cterm(true)
279
280    screen:set_default_attr_ids({
281      [1] = {
282        { bold = true, foreground = Screen.colors.Blue1 },
283        { foreground = 12 },
284        { { hi_name = 'NonText', ui_name = 'EndOfBuffer', kind = 'ui' } },
285      },
286      [2] = {
287        { reverse = true, foreground = Screen.colors.Red },
288        { foreground = 10, italic = true },
289        { { hi_name = 'NonText', ui_name = 'EndOfBuffer', kind = 'ui' } },
290      },
291      [3] = { {}, {}, { { hi_name = 'MsgArea', ui_name = 'MsgArea', kind = 'ui' } } },
292    })
293    screen:expect([[
294      ^                                        |
295      {1:~                                       }|*6
296      {3:                                        }|
297    ]])
298
299    command('hi NonText guifg=Red gui=reverse ctermfg=Green cterm=italic')
300    screen:expect([[
301      ^                                        |
302      {2:~                                       }|*6
303      {3:                                        }|
304    ]])
305  end)
306
307  it('combines deleted extmark highlights', function()
308    insert([[
309      line1
310        line2
311        line3
312        line4
313        line5
314      line6]])
315
316    screen:expect {
317      grid = [[
318      line1                                   |
319        line2                                 |
320        line3                                 |
321        line4                                 |
322        line5                                 |
323      line^6                                   |
324      {1:~                                       }|
325      {2:                                        }|
326    ]],
327      attr_ids = {
328        [1] = {
329          { foreground = Screen.colors.Blue, bold = true },
330          { { ui_name = 'EndOfBuffer', hi_name = 'NonText', kind = 'ui' } },
331        },
332        [2] = { {}, { { ui_name = 'MsgArea', hi_name = 'MsgArea', kind = 'ui' } } },
333      },
334    }
335
336    local ns = api.nvim_create_namespace('test')
337
338    local add_indicator = function(line, col)
339      api.nvim_buf_set_extmark(0, ns, line, col, {
340        hl_mode = 'combine',
341        priority = 2,
342        right_gravity = false,
343        virt_text = { { '|', 'Delimiter' } },
344        virt_text_win_col = 0,
345        virt_text_pos = 'overlay',
346      })
347    end
348
349    add_indicator(1, 0)
350    add_indicator(2, 0)
351    add_indicator(3, 0)
352    add_indicator(4, 0)
353
354    screen:expect {
355      grid = [[
356      line1                                   |
357      {1:|} line2                                 |
358      {1:|} line3                                 |
359      {1:|} line4                                 |
360      {1:|} line5                                 |
361      line^6                                   |
362      {2:~                                       }|
363      {3:                                        }|
364    ]],
365      attr_ids = {
366        [1] = {
367          { foreground = Screen.colors.SlateBlue },
368          { { hi_name = 'Special', kind = 'syntax' } },
369        },
370        [2] = {
371          { bold = true, foreground = Screen.colors.Blue },
372          { { ui_name = 'EndOfBuffer', kind = 'ui', hi_name = 'NonText' } },
373        },
374        [3] = { {}, { { ui_name = 'MsgArea', kind = 'ui', hi_name = 'MsgArea' } } },
375      },
376    }
377
378    n.feed('3ggV2jd')
379    --screen:redraw_debug()
380    screen:expect {
381      grid = [[
382      line1                                   |
383      {1:|} line2                                 |
384      {2:^|}ine6                                   |
385      {3:~                                       }|*4
386      {4:3 fewer lines                           }|
387    ]],
388      attr_ids = {
389        [1] = {
390          { foreground = Screen.colors.SlateBlue },
391          { { kind = 'syntax', hi_name = 'Special' } },
392        },
393        [2] = { { foreground = Screen.colors.SlateBlue }, { 1, 1, 1 } },
394        [3] = {
395          { bold = true, foreground = Screen.colors.Blue },
396          { { kind = 'ui', ui_name = 'EndOfBuffer', hi_name = 'NonText' } },
397        },
398        [4] = { {}, { { kind = 'ui', ui_name = 'MsgArea', hi_name = 'MsgArea' } } },
399      },
400    }
401  end)
402
403  it('removes deleted extmark highlights with invalidate', function()
404    insert([[
405      line1
406        line2
407        line3
408        line4
409        line5
410      line6]])
411
412    screen:expect {
413      grid = [[
414      line1                                   |
415        line2                                 |
416        line3                                 |
417        line4                                 |
418        line5                                 |
419      line^6                                   |
420      {1:~                                       }|
421      {2:                                        }|
422    ]],
423      attr_ids = {
424        [1] = {
425          { foreground = Screen.colors.Blue, bold = true },
426          { { ui_name = 'EndOfBuffer', hi_name = 'NonText', kind = 'ui' } },
427        },
428        [2] = { {}, { { ui_name = 'MsgArea', hi_name = 'MsgArea', kind = 'ui' } } },
429      },
430    }
431
432    local ns = api.nvim_create_namespace('test')
433
434    local add_indicator = function(line, col)
435      api.nvim_buf_set_extmark(0, ns, line, col, {
436        hl_mode = 'combine',
437        priority = 2,
438        right_gravity = false,
439        virt_text = { { '|', 'Delimiter' } },
440        virt_text_win_col = 0,
441        virt_text_pos = 'overlay',
442        invalidate = true,
443      })
444    end
445
446    add_indicator(1, 0)
447    add_indicator(2, 0)
448    add_indicator(3, 0)
449    add_indicator(4, 0)
450
451    screen:expect {
452      grid = [[
453      line1                                   |
454      {1:|} line2                                 |
455      {1:|} line3                                 |
456      {1:|} line4                                 |
457      {1:|} line5                                 |
458      line^6                                   |
459      {2:~                                       }|
460      {3:                                        }|
461    ]],
462      attr_ids = {
463        [1] = {
464          { foreground = Screen.colors.SlateBlue },
465          { { hi_name = 'Special', kind = 'syntax' } },
466        },
467        [2] = {
468          { bold = true, foreground = Screen.colors.Blue },
469          { { ui_name = 'EndOfBuffer', kind = 'ui', hi_name = 'NonText' } },
470        },
471        [3] = { {}, { { ui_name = 'MsgArea', kind = 'ui', hi_name = 'MsgArea' } } },
472      },
473    }
474
475    n.feed('3ggV2jd')
476    --screen:redraw_debug()
477    screen:expect {
478      grid = [[
479      line1                                   |
480      {1:|} line2                                 |
481      ^line6                                   |
482      {2:~                                       }|*4
483      {3:3 fewer lines                           }|
484    ]],
485      attr_ids = {
486        [1] = {
487          { foreground = Screen.colors.SlateBlue },
488          { { kind = 'syntax', hi_name = 'Special' } },
489        },
490        [2] = {
491          { foreground = Screen.colors.Blue, bold = true },
492          { { kind = 'ui', ui_name = 'EndOfBuffer', hi_name = 'NonText' } },
493        },
494        [3] = { {}, { { kind = 'ui', ui_name = 'MsgArea', hi_name = 'MsgArea' } } },
495      },
496    }
497  end)
498
499  it('does not hang when combining too many highlights', function()
500    local num_lines = 500
501    insert('first line\n')
502    for _ = 1, num_lines do
503      api.nvim_paste('  line\n', false, -1)
504    end
505    insert('last line')
506
507    n.feed('gg')
508    screen:expect {
509      grid = [[
510      ^first line                              |
511        line                                  |*6
512      {1:                                        }|
513    ]],
514      attr_ids = {
515        [1] = { {}, { { kind = 'ui', hi_name = 'MsgArea', ui_name = 'MsgArea' } } },
516      },
517    }
518    local ns = api.nvim_create_namespace('test')
519
520    local add_indicator = function(line, col)
521      api.nvim_buf_set_extmark(0, ns, line, col, {
522        hl_mode = 'combine',
523        priority = 2,
524        right_gravity = false,
525        virt_text = { { '|', 'Delimiter' } },
526        virt_text_win_col = 0,
527        virt_text_pos = 'overlay',
528      })
529    end
530
531    for i = 1, num_lines do
532      add_indicator(i, 0)
533    end
534
535    screen:expect {
536      grid = [[
537      ^first line                              |
538      {1:|} line                                  |*6
539      {2:                                        }|
540    ]],
541      attr_ids = {
542        [1] = {
543          { foreground = Screen.colors.SlateBlue },
544          { { kind = 'syntax', hi_name = 'Special' } },
545        },
546        [2] = { {}, { { kind = 'ui', ui_name = 'MsgArea', hi_name = 'MsgArea' } } },
547      },
548    }
549
550    n.feed(string.format('3ggV%ijd', num_lines - 2))
551    --screen:redraw_debug(nil, nil, 100000)
552
553    local expected_ids = {}
554    for i = 1, num_lines - 1 do
555      expected_ids[i] = 1
556    end
557    screen:expect {
558      grid = string.format(
559        [[
560        first line                              |
561        {1:|} line                                  |
562        {2:^|}ast line                               |
563        {3:~                                       }|*4
564        {4:%-40s}|
565    ]],
566        tostring(num_lines - 1) .. ' fewer lines'
567      ),
568      attr_ids = {
569        [1] = {
570          { foreground = Screen.colors.SlateBlue },
571          { { kind = 'syntax', hi_name = 'Special' } },
572        },
573        [2] = { { foreground = Screen.colors.SlateBlue }, expected_ids },
574        [3] = {
575          { foreground = Screen.colors.Blue, bold = true },
576          { { kind = 'ui', hi_name = 'NonText', ui_name = 'EndOfBuffer' } },
577        },
578        [4] = { {}, { { kind = 'ui', hi_name = 'MsgArea', ui_name = 'MsgArea' } } },
579      },
580      timeout = 100000,
581    }
582  end)
583end)