robin/laufey

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

robinmerge: 1dc9728daa1d8a2702

master
96.4 KiB2802 linesraw
1local t = require('test.testutil')
2local n = require('test.functional.testnvim')()
3local Screen = require('test.functional.ui.screen')
4local os = require('os')
5
6local describe, it, before_each, after_each = t.describe, t.it, t.before_each, t.after_each
7local clear, feed, insert = n.clear, n.feed, n.insert
8local command, exec = n.command, n.exec
9local eval = n.eval
10local feed_command, eq = n.feed_command, t.eq
11local fn = n.fn
12local api = n.api
13local exec_lua = n.exec_lua
14
15describe('colorscheme compatibility', function()
16  before_each(function()
17    clear()
18  end)
19
20  it('&t_Co exists and is set to 256 by default', function()
21    eq(1, fn.exists('&t_Co'))
22    eq(1, fn.exists('+t_Co'))
23    eq('256', eval('&t_Co'))
24  end)
25end)
26
27describe('highlight: `:syntax manual`', function()
28  -- When using manual syntax highlighting, it should be preserved even when
29  -- switching buffers... bug did only occur without :set hidden
30  -- Ref: vim patch 7.4.1236
31  local screen
32
33  before_each(function()
34    clear()
35    screen = Screen.new(20, 5)
36    -- syntax highlight for vimscript's "echo"
37  end)
38
39  after_each(function()
40    os.remove('Xtest-functional-ui-highlight.tmp.vim')
41  end)
42
43  it("works with buffer switch and 'hidden'", function()
44    command('e tmp1.vim')
45    command('e Xtest-functional-ui-highlight.tmp.vim')
46    command('filetype on')
47    command('syntax manual')
48    command('set ft=vim')
49    command('set syntax=ON')
50    feed('iecho 1<esc>0')
51
52    command('set hidden')
53    command('w')
54    command('bn')
55    feed_command('bp')
56    screen:expect([[
57      {15:^echo} {26:1}              |
58      {1:~                   }|*3
59      :bp                 |
60    ]])
61  end)
62
63  it("works with buffer switch and 'nohidden'", function()
64    command('e tmp1.vim')
65    command('e Xtest-functional-ui-highlight.tmp.vim')
66    command('filetype on')
67    command('syntax manual')
68    command('set filetype=vim fileformat=unix')
69    command('set syntax=ON')
70    feed('iecho 1<esc>0')
71
72    command('set nohidden')
73    command('w')
74    command('silent bn')
75    eq('tmp1.vim', eval("fnamemodify(bufname('%'), ':t')"))
76    feed_command('silent bp')
77    eq('Xtest-functional-ui-highlight.tmp.vim', eval("fnamemodify(bufname('%'), ':t')"))
78    screen:expect([[
79      {15:^echo} {26:1}              |
80      {1:~                   }|*3
81      :silent bp          |
82    ]])
83  end)
84end)
85
86describe('highlight defaults', function()
87  local screen
88
89  before_each(function()
90    clear()
91    screen = Screen.new()
92    screen:add_extra_attr_ids {
93      [100] = { foreground = Screen.colors.Red, background = Screen.colors.WebGreen },
94      [101] = { italic = true },
95    }
96  end)
97
98  it('window status bar', function()
99    feed_command('sp', 'vsp', 'vsp')
100    screen:expect([[
101      ^                    │                │               |
102      {1:~                   }│{1:~               }│{1:~              }|*5
103      {3:[No Name]            }{2:[No Name]        [No Name]      }|
104                                                           |
105      {1:~                                                    }|*4
106      {2:[No Name]                                            }|
107      :vsp                                                 |
108    ]])
109    -- navigate to verify that the attributes are properly moved
110    feed('<c-w>j')
111    screen:expect([[
112                          │                │               |
113      {1:~                   }│{1:~               }│{1:~              }|*5
114      {2:[No Name]            [No Name]        [No Name]      }|
115      ^                                                     |
116      {1:~                                                    }|*4
117      {3:[No Name]                                            }|
118      :vsp                                                 |
119    ]])
120    -- note that when moving to a window with small width nvim will increase
121    -- the width of the new active window at the expense of a inactive window
122    -- (upstream vim has the same behavior)
123    feed('<c-w>k<c-w>l')
124    screen:expect([[
125                          │^                    │           |
126      {1:~                   }│{1:~                   }│{1:~          }|*5
127      {2:[No Name]            }{3:[No Name]            }{2:[No Name]  }|
128                                                           |
129      {1:~                                                    }|*4
130      {2:[No Name]                                            }|
131      :vsp                                                 |
132    ]])
133    feed('<c-w>l')
134    screen:expect([[
135                          │           │^                    |
136      {1:~                   }│{1:~          }│{1:~                   }|*5
137      {2:[No Name]            [No Name]   }{3:[No Name]           }|
138                                                           |
139      {1:~                                                    }|*4
140      {2:[No Name]                                            }|
141      :vsp                                                 |
142    ]])
143    feed('<c-w>h<c-w>h')
144    screen:expect([[
145      ^                    │                    │           |
146      {1:~                   }│{1:~                   }│{1:~          }|*5
147      {3:[No Name]            }{2:[No Name]            [No Name]  }|
148                                                           |
149      {1:~                                                    }|*4
150      {2:[No Name]                                            }|
151      :vsp                                                 |
152    ]])
153  end)
154
155  it('insert mode text', function()
156    feed('i')
157    screen:try_resize(53, 4)
158    screen:expect([[
159      ^                                                     |
160      {1:~                                                    }|*2
161      {5:-- INSERT --}                                         |
162    ]])
163  end)
164
165  it('end of file markers', function()
166    screen:try_resize(53, 4)
167    screen:expect([[
168      ^                                                     |
169      {1:~                                                    }|*2
170                                                           |
171    ]])
172  end)
173
174  it('"wait return" text', function()
175    screen:try_resize(53, 4)
176    feed(':ls<cr>')
177    screen:expect([[
178      {3:                                                     }|
179      :ls                                                  |
180        1 %a   "[No Name]"                    line 1       |
181      {6:Press ENTER or type command to continue}^              |
182    ]])
183    feed('<cr>') --  skip the "Press ENTER..." state or tests will hang
184  end)
185
186  it('can be cleared and linked to other highlight groups', function()
187    screen:try_resize(53, 4)
188    feed_command('highlight clear ModeMsg')
189    feed('i')
190    screen:expect([[
191      ^                                                     |
192      {1:~                                                    }|*2
193      -- INSERT --                                         |
194    ]])
195    feed('<esc>')
196    feed_command('highlight CustomHLGroup guifg=red guibg=green')
197    feed_command('highlight link ModeMsg CustomHLGroup')
198    feed('i')
199    screen:expect([[
200      ^                                                     |
201      {1:~                                                    }|*2
202      {100:-- INSERT --}                                         |
203    ]])
204  end)
205
206  it('can be cleared by assigning NONE', function()
207    screen:try_resize(53, 4)
208    feed_command('syn keyword TmpKeyword neovim')
209    feed_command('hi link TmpKeyword ErrorMsg')
210    insert('neovim')
211    screen:expect([[
212      {9:neovi^m}                                               |
213      {1:~                                                    }|*2
214                                                           |
215    ]])
216    feed_command(
217      'hi ErrorMsg term=NONE cterm=NONE ctermfg=NONE ctermbg=NONE'
218        .. ' gui=NONE guifg=NONE guibg=NONE guisp=NONE'
219    )
220    screen:expect([[
221      neovi^m                                               |
222      {1:~                                                    }|*2
223                                                           |
224    ]])
225  end)
226
227  it('linking updates window highlight immediately #16552', function()
228    screen:try_resize(53, 4)
229    screen:expect([[
230      ^                                                     |
231      {1:~                                                    }|*2
232                                                           |
233    ]])
234    feed_command('hi NonTextAlt guifg=Red')
235    feed_command('hi! link NonText NonTextAlt')
236    screen:expect([[
237      ^                                                     |
238      {19:~                                                    }|*2
239      :hi! link NonText NonTextAlt                         |
240    ]])
241  end)
242
243  it('Cursor after `:hi clear|syntax reset` #6508', function()
244    command('highlight clear|syntax reset')
245    eq(
246      'cterm=reverse guifg=bg guibg=fg',
247      eval([[matchstr(execute('hi Cursor'), '\v(gui|cterm).*$')]])
248    )
249  end)
250
251  it('Whitespace highlight', function()
252    screen:try_resize(53, 4)
253    feed_command('highlight NonText gui=NONE guifg=#FF0000')
254    feed_command('set listchars=space:.,tab:>-,trail:*,eol:¬ list')
255    insert('   ne \t o\tv  im  ')
256    screen:expect([[
257      ne{19:.>----.}o{19:>-----}v{19:..}im{19:*^*¬}                             |
258      {19:~                                                    }|*2
259                                                           |
260    ]])
261    feed_command('highlight Whitespace gui=NONE guifg=#0000FF')
262    screen:expect([[
263      ne{18:.>----.}o{18:>-----}v{18:..}im{18:*^*}{19:¬}                             |
264      {19:~                                                    }|*2
265      :highlight Whitespace gui=NONE guifg=#0000FF         |
266    ]])
267  end)
268
269  it('are sent to UIs', function()
270    screen:try_resize(53, 4)
271
272    screen:expect {
273      grid = [[
274      ^                                                     |
275      {1:~                                                    }|*2
276                                                           |
277    ]],
278      hl_groups = { EndOfBuffer = 1, MsgSeparator = 3 },
279    }
280
281    command('highlight EndOfBuffer gui=italic')
282    screen:expect {
283      grid = [[
284      ^                                                     |
285      {101:~                                                    }|*2
286                                                           |
287    ]],
288      hl_groups = { EndOfBuffer = 101, MsgSeparator = 3 },
289    }
290
291    command('highlight clear EndOfBuffer')
292    screen:expect {
293      grid = [[
294      ^                                                     |
295      {1:~                                                    }|*2
296                                                           |
297    ]],
298      hl_groups = { EndOfBuffer = 1, MsgSeparator = 3 },
299    }
300  end)
301end)
302
303describe('highlight', function()
304  before_each(clear)
305
306  it('Visual', function()
307    local screen = Screen.new(45, 5)
308    insert([[
309      line1 foo bar
310    abcdefghijklmnopqrs
311    ABCDEFGHIJKLMNOPQRS
312    ]])
313    feed('gg')
314    command('vsplit')
315
316    -- Visual highlighting does not depend on 'guicursor'.
317    command('set guicursor=a:block-blinkon0')
318    feed('V')
319    screen:expect([[
320      {17:  ^line1 foo bar}       │{17:  line1 foo bar}       |
321      abcdefghijklmnopqrs   │abcdefghijklmnopqrs   |
322      ABCDEFGHIJKLMNOPQRS   │ABCDEFGHIJKLMNOPQRS   |
323      {3:[No Name] [+]          }{2:[No Name] [+]         }|
324      {5:-- VISUAL LINE --}                            |
325    ]])
326
327    feed('<Esc>$vhhh')
328    screen:expect([[
329        line1 foo{17:^ bar}       │  line1 foo{17: bar}       |
330      abcdefghijklmnopqrs   │abcdefghijklmnopqrs   |
331      ABCDEFGHIJKLMNOPQRS   │ABCDEFGHIJKLMNOPQRS   |
332      {3:[No Name] [+]          }{2:[No Name] [+]         }|
333      {5:-- VISUAL --}                                 |
334    ]])
335
336    -- Non-blinking block cursor with blinkon0 does not affect Visual highlighting either. #8983
337    command('set guicursor=a:block-blinkon175')
338    screen:expect([[
339        line1 foo{17:^ bar}       │  line1 foo{17: bar}       |
340      abcdefghijklmnopqrs   │abcdefghijklmnopqrs   |
341      ABCDEFGHIJKLMNOPQRS   │ABCDEFGHIJKLMNOPQRS   |
342      {3:[No Name] [+]          }{2:[No Name] [+]         }|
343      {5:-- VISUAL --}                                 |
344    ]])
345
346    command('set selection=exclusive')
347    screen:expect([[
348        line1 foo{17:^ ba}r       │  line1 foo{17: ba}r       |
349      abcdefghijklmnopqrs   │abcdefghijklmnopqrs   |
350      ABCDEFGHIJKLMNOPQRS   │ABCDEFGHIJKLMNOPQRS   |
351      {3:[No Name] [+]          }{2:[No Name] [+]         }|
352      {5:-- VISUAL --}                                 |
353    ]])
354
355    feed('o')
356    screen:expect([[
357        line1 foo{17: ba}^r       │  line1 foo{17: ba}r       |
358      abcdefghijklmnopqrs   │abcdefghijklmnopqrs   |
359      ABCDEFGHIJKLMNOPQRS   │ABCDEFGHIJKLMNOPQRS   |
360      {3:[No Name] [+]          }{2:[No Name] [+]         }|
361      {5:-- VISUAL --}                                 |
362    ]])
363
364    feed('V')
365    screen:expect([[
366      {17:  line1 foo ba^r}       │{17:  line1 foo bar}       |
367      abcdefghijklmnopqrs   │abcdefghijklmnopqrs   |
368      ABCDEFGHIJKLMNOPQRS   │ABCDEFGHIJKLMNOPQRS   |
369      {3:[No Name] [+]          }{2:[No Name] [+]         }|
370      {5:-- VISUAL LINE --}                            |
371    ]])
372
373    command('set cursorcolumn')
374    feed('<C-V>')
375    screen:expect([[
376        line1 foo{17: ba}^r       │  line1 foo{17: ba}r       |
377      abcdefghijklmn{21:o}pqrs   │abcdefghijklmnopqrs   |
378      ABCDEFGHIJKLMN{21:O}PQRS   │ABCDEFGHIJKLMNOPQRS   |
379      {3:[No Name] [+]          }{2:[No Name] [+]         }|
380      {5:-- VISUAL BLOCK --}                           |
381    ]])
382
383    command('set selection&')
384    screen:expect([[
385        line1 foo{17: ba^r}       │  line1 foo{17: bar}       |
386      abcdefghijklmn{21:o}pqrs   │abcdefghijklmnopqrs   |
387      ABCDEFGHIJKLMN{21:O}PQRS   │ABCDEFGHIJKLMNOPQRS   |
388      {3:[No Name] [+]          }{2:[No Name] [+]         }|
389      {5:-- VISUAL BLOCK --}                           |
390    ]])
391
392    feed('^')
393    screen:expect([[
394        {17:^line1 foo }bar       │  {17:line1 foo }bar       |
395      ab{21:c}defghijklmnopqrs   │abcdefghijklmnopqrs   |
396      AB{21:C}DEFGHIJKLMNOPQRS   │ABCDEFGHIJKLMNOPQRS   |
397      {3:[No Name] [+]          }{2:[No Name] [+]         }|
398      {5:-- VISUAL BLOCK --}                           |
399    ]])
400
401    feed('2j')
402    screen:expect([[
403        {17:line1 foo }bar       │  {17:line1 foo }bar       |
404      ab{17:cdefghijkl}mnopqrs   │ab{17:cdefghijkl}mnopqrs   |
405      AB{17:^CDEFGHIJKL}MNOPQRS   │AB{17:CDEFGHIJKL}MNOPQRS   |
406      {3:[No Name] [+]          }{2:[No Name] [+]         }|
407      {5:-- VISUAL BLOCK --}                           |
408    ]])
409
410    command('set nocursorcolumn')
411    feed('O')
412    screen:expect([[
413        {17:line1 foo }bar       │  {17:line1 foo }bar       |
414      ab{17:cdefghijkl}mnopqrs   │ab{17:cdefghijkl}mnopqrs   |
415      AB{17:CDEFGHIJK^L}MNOPQRS   │AB{17:CDEFGHIJKL}MNOPQRS   |
416      {3:[No Name] [+]          }{2:[No Name] [+]         }|
417      {5:-- VISUAL BLOCK --}                           |
418    ]])
419
420    command('set selection=exclusive')
421    screen:expect([[
422        {17:line1 foo} bar       │  {17:line1 foo} bar       |
423      ab{17:cdefghijk}lmnopqrs   │ab{17:cdefghijk}lmnopqrs   |
424      AB{17:CDEFGHIJK}^LMNOPQRS   │AB{17:CDEFGHIJK}LMNOPQRS   |
425      {3:[No Name] [+]          }{2:[No Name] [+]         }|
426      {5:-- VISUAL BLOCK --}                           |
427    ]])
428  end)
429
430  it('blockwise Visual highlight with virtualedit=block #34235', function()
431    local screen = Screen.new(45, 5)
432    command('set virtualedit=block')
433    insert('foobar\nfoo')
434    feed('0<C-V>k$')
435    screen:expect([[
436      {17:foobar^ }                                      |
437      {17:foo    }                                      |
438      {1:~                                            }|*2
439      {5:-- VISUAL BLOCK --}                           |
440    ]])
441    feed('10l')
442    screen:expect([[
443      {17:foobar          ^ }                            |
444      {17:foo              }                            |
445      {1:~                                            }|*2
446      {5:-- VISUAL BLOCK --}                           |
447    ]])
448  end)
449
450  it("is updated with H/L and 'scrolloff' #36059", function()
451    local screen = Screen.new(40, 10)
452    exec([[
453      call setline(1, map(range(1, 100), "'line ' .. v:val"))
454      set scrolloff=2 nostartofline
455      call cursor(50, 1)
456    ]])
457    feed('z<CR>V')
458    screen:expect([[
459      line 48                                 |
460      line 49                                 |
461      {17:^line 50}                                 |
462      line 51                                 |
463      line 52                                 |
464      line 53                                 |
465      line 54                                 |
466      line 55                                 |
467      line 56                                 |
468      {5:-- VISUAL LINE --}                       |
469    ]])
470    feed('L')
471    screen:expect([[
472      line 48                                 |
473      line 49                                 |
474      {17:line 50}                                 |
475      {17:line 51}                                 |
476      {17:line 52}                                 |
477      {17:line 53}                                 |
478      {17:^line 54}                                 |
479      line 55                                 |
480      line 56                                 |
481      {5:-- VISUAL LINE --}                       |
482    ]])
483    feed('<Esc>V')
484    screen:expect([[
485      line 48                                 |
486      line 49                                 |
487      line 50                                 |
488      line 51                                 |
489      line 52                                 |
490      line 53                                 |
491      {17:^line 54}                                 |
492      line 55                                 |
493      line 56                                 |
494      {5:-- VISUAL LINE --}                       |
495    ]])
496    feed('H')
497    screen:expect([[
498      line 48                                 |
499      line 49                                 |
500      {17:^line 50}                                 |
501      {17:line 51}                                 |
502      {17:line 52}                                 |
503      {17:line 53}                                 |
504      {17:line 54}                                 |
505      line 55                                 |
506      line 56                                 |
507      {5:-- VISUAL LINE --}                       |
508    ]])
509  end)
510
511  it('cterm=standout gui=standout', function()
512    local screen = Screen.new(20, 5)
513    screen:add_extra_attr_ids {
514      [100] = {
515        foreground = Screen.colors.Blue1,
516        bold = true,
517        background = Screen.colors.Grey90,
518        underline = true,
519        standout = true,
520      },
521      [101] = { underline = true, standout = true, background = Screen.colors.Grey90 },
522    }
523    feed_command('hi CursorLine cterm=standout,underline gui=standout,underline')
524    feed_command('set cursorline')
525    feed_command('set listchars=space:.,eol:¬,tab:>-,extends:>,precedes:<,trail:* list')
526    feed('i\t abcd <cr>\t abcd <cr><esc>k')
527    screen:expect([[
528    {1:>-------.}abcd{1:*¬}     |
529    {100:^>-------.}{101:abcd}{100:*¬}{101:     }|
530    {1:¬}                   |
531    {1:~                   }|
532                        |
533    ]])
534  end)
535
536  it('strikethrough', function()
537    local screen = Screen.new(25, 6)
538    feed_command('syntax on')
539    feed_command('syn keyword TmpKeyword foo')
540    feed_command('hi! Awesome cterm=strikethrough gui=strikethrough')
541    feed_command('hi link TmpKeyword Awesome')
542    insert([[
543      foo
544      foo bar
545      foobarfoobar
546      ]])
547    screen:expect(
548      [[
549      {1:foo}                      |
550      {1:foo} bar                  |
551      foobarfoobar             |
552      ^                         |
553      {2:~                        }|
554                               |
555    ]],
556      {
557        [1] = { strikethrough = true },
558        [2] = { bold = true, foreground = Screen.colors.Blue1 },
559      }
560    )
561  end)
562
563  it('nocombine', function()
564    local screen = Screen.new(25, 6)
565    screen:add_extra_attr_ids {
566      [100] = { underline = true, reverse = true, foreground = Screen.colors.SlateBlue },
567      [101] = {
568        foreground = Screen.colors.SlateBlue,
569        reverse = true,
570        background = Screen.colors.Yellow,
571      },
572    }
573    feed_command('syntax on')
574    feed_command('hi! Underlined cterm=underline gui=underline')
575    feed_command('syn keyword Underlined foobar')
576    feed_command('hi Search cterm=inverse,nocombine gui=inverse,nocombine')
577    insert([[
578      foobar
579      foobar
580      ]])
581    screen:expect {
582      grid = [[
583      {28:foobar}                   |*2
584      ^                         |
585      {1:~                        }|*2
586                               |
587    ]],
588    }
589
590    feed('/foo')
591    screen:expect {
592      grid = [[
593      {100:foo}{28:bar}                   |
594      {101:foo}{28:bar}                   |
595                               |
596      {1:~                        }|*2
597      /foo^                     |
598    ]],
599    }
600    feed('<cr>')
601    screen:expect {
602      grid = [[
603      {101:^foo}{28:bar}                   |
604      {101:foo}{28:bar}                   |
605                               |
606      {1:~                        }|*2
607      {19:search hit...uing at TOP} |
608    ]],
609    }
610  end)
611
612  it('guisp (special/undercurl)', function()
613    local screen = Screen.new(25, 10)
614    feed_command('syntax on')
615    feed_command('syn keyword TmpKeyword neovim')
616    feed_command('syn keyword TmpKeyword1 special')
617    feed_command('syn keyword TmpKeyword2 specialwithbg')
618    feed_command('syn keyword TmpKeyword3 specialwithfg')
619    feed_command('hi! Awesome guifg=red guibg=yellow guisp=red')
620    feed_command('hi! Awesome1 guisp=red')
621    feed_command('hi! Awesome2 guibg=yellow guisp=red')
622    feed_command('hi! Awesome3 guifg=red guisp=red')
623    feed_command('hi link TmpKeyword Awesome')
624    feed_command('hi link TmpKeyword1 Awesome1')
625    feed_command('hi link TmpKeyword2 Awesome2')
626    feed_command('hi link TmpKeyword3 Awesome3')
627    insert([[
628      neovim
629      awesome neovim
630      wordcontainingneovim
631      special
632      specialwithbg
633      specialwithfg
634      ]])
635    feed('Go<tab>neovim tabbed')
636    screen:expect(
637      [[
638      {1:neovim}                   |
639      awesome {1:neovim}           |
640      wordcontainingneovim     |
641      {2:special}                  |
642      {3:specialwithbg}            |
643      {4:specialwithfg}            |
644                               |
645              {1:neovim} tabbed^    |
646      {0:~                        }|
647      {5:-- INSERT --}             |
648    ]],
649      {
650        [0] = { bold = true, foreground = Screen.colors.Blue },
651        [1] = {
652          background = Screen.colors.Yellow,
653          foreground = Screen.colors.Red,
654          special = Screen.colors.Red,
655        },
656        [2] = { special = Screen.colors.Red },
657        [3] = { special = Screen.colors.Red, background = Screen.colors.Yellow },
658        [4] = { foreground = Screen.colors.Red, special = Screen.colors.Red },
659        [5] = { bold = true },
660      }
661    )
662  end)
663
664  it("'diff', syntax and extmark #23722", function()
665    local screen = Screen.new(25, 10)
666    exec([[
667      new
668      call setline(1, ['', '01234 6789'])
669      windo diffthis
670      wincmd w
671      syn match WarningMsg "^.*$"
672      call nvim_buf_add_highlight(0, -1, 'ErrorMsg', 1, 2, 8)
673    ]])
674    screen:expect(
675      [[
676      {1:  }{5:^                       }|
677      {1:  }{2:01}{3:234 67}{2:89}{5:             }|
678      {4:~                        }|*2
679      {7:[No Name] [+]            }|
680      {1:  }{6:-----------------------}|*2
681      {1:  }                       |
682      {8:[No Name]                }|
683                               |
684    ]],
685      {
686        [0] = { Screen.colors.WebGray, foreground = Screen.colors.DarkBlue },
687        [1] = { background = Screen.colors.Grey, foreground = Screen.colors.Blue4 },
688        [2] = { foreground = Screen.colors.Red, background = Screen.colors.LightBlue },
689        [3] = { foreground = Screen.colors.Grey100, background = Screen.colors.LightBlue },
690        [4] = { bold = true, foreground = Screen.colors.Blue },
691        [5] = { background = Screen.colors.LightBlue },
692        [6] = {
693          bold = true,
694          background = Screen.colors.LightCyan,
695          foreground = Screen.colors.Blue1,
696        },
697        [7] = { reverse = true, bold = true },
698        [8] = { reverse = true },
699      }
700    )
701  end)
702end)
703
704describe("'listchars' highlight", function()
705  local screen
706
707  before_each(function()
708    clear()
709    screen = Screen.new(20, 5)
710  end)
711
712  it("'cursorline' and 'cursorcolumn'", function()
713    feed_command('highlight clear ModeMsg')
714    feed_command('set cursorline')
715    feed('i')
716    screen:expect([[
717      {21:^                    }|
718      {1:~                   }|*3
719      -- INSERT --        |
720    ]])
721    feed('abcdefg<cr>kkasdf')
722    screen:expect([[
723      abcdefg             |
724      {21:kkasdf^              }|
725      {1:~                   }|*2
726      -- INSERT --        |
727    ]])
728    feed('<esc>')
729    screen:expect([[
730      abcdefg             |
731      {21:kkasd^f              }|
732      {1:~                   }|*2
733                          |
734    ]])
735    feed_command('set nocursorline')
736    screen:expect([[
737      abcdefg             |
738      kkasd^f              |
739      {1:~                   }|*2
740      :set nocursorline   |
741    ]])
742    feed('k')
743    screen:expect([[
744      abcde^fg             |
745      kkasdf              |
746      {1:~                   }|*2
747      :set nocursorline   |
748    ]])
749    feed('jjji<cr><cr><cr><esc>')
750    screen:expect([[
751      kkasd               |
752                          |*2
753      ^f                   |
754                          |
755    ]])
756    feed_command('set cursorline')
757    feed_command('set cursorcolumn')
758    feed('kkiabcdefghijk<esc>hh')
759    screen:expect([[
760      kkasd   {21: }           |
761      {21:abcdefgh^ijk         }|
762              {21: }           |
763      f       {21: }           |
764                          |
765    ]])
766    feed('khh')
767    screen:expect([[
768      {21:kk^asd               }|
769      ab{21:c}defghijk         |
770        {21: }                 |
771      f {21: }                 |
772                          |
773    ]])
774  end)
775
776  it("'cursorline' and with 'listchars' option", function()
777    screen:add_extra_attr_ids {
778      [100] = { foreground = Screen.colors.Red, background = Screen.colors.Grey90 },
779      [101] = { foreground = Screen.colors.Blue1, bold = true, background = Screen.colors.Grey90 },
780    }
781    feed_command('highlight clear ModeMsg')
782    feed_command('highlight Whitespace guifg=#FF0000')
783    feed_command('set cursorline')
784    feed_command('set tabstop=8')
785    feed_command('set listchars=space:.,eol:¬,tab:>-,extends:>,precedes:<,trail:* list')
786    feed('i\t abcd <cr>\t abcd <cr><esc>k')
787    screen:expect([[
788      {19:>-------.}abcd{19:*}{1:¬}     |
789      {100:^>-------.}{21:abcd}{100:*}{101:¬}{21:     }|
790      {1:¬}                   |
791      {1:~                   }|
792                          |
793    ]])
794    feed('k')
795    screen:expect([[
796      {100:^>-------.}{21:abcd}{100:*}{101:¬}{21:     }|
797      {19:>-------.}abcd{19:*}{1:¬}     |
798      {1:¬}                   |
799      {1:~                   }|
800                          |
801    ]])
802    feed_command('set nocursorline')
803    screen:expect([[
804      {19:^>-------.}abcd{19:*}{1:¬}     |
805      {19:>-------.}abcd{19:*}{1:¬}     |
806      {1:¬}                   |
807      {1:~                   }|
808      :set nocursorline   |
809    ]])
810    feed_command('set nowrap')
811    feed('ALorem ipsum dolor sit amet<ESC>0')
812    screen:expect([[
813      {19:^>-------.}abcd{19:.}Lorem{1:>}|
814      {19:>-------.}abcd{19:*}{1:¬}     |
815      {1:¬}                   |
816      {1:~                   }|
817                          |
818    ]])
819    feed_command('set cursorline')
820    screen:expect([[
821      {100:^>-------.}{21:abcd}{100:.}{21:Lorem}{101:>}|
822      {19:>-------.}abcd{19:*}{1:¬}     |
823      {1:¬}                   |
824      {1:~                   }|
825      :set cursorline     |
826    ]])
827    feed('$')
828    screen:expect([[
829      {101:<}{21:r}{100:.}{21:sit}{100:.}{21:ame^t}{101:¬}{21:        }|
830      {1:<}                   |*2
831      {1:~                   }|
832      :set cursorline     |
833    ]])
834    feed('G')
835    screen:expect([[
836      {19:>-------.}abcd{19:.}Lorem{1:>}|
837      {19:>-------.}abcd{19:*}{1:¬}     |
838      {101:^¬}{21:                   }|
839      {1:~                   }|
840      :set cursorline     |
841    ]])
842  end)
843
844  it("'listchar' with wrap", function()
845    feed_command('set wrap')
846    feed_command('set listchars=eol:¬,precedes:< list')
847    feed('90ia<esc>')
848    screen:expect([[
849      {1:<}aaaaaaaaaaaaaaaaaaa|
850      aaaaaaaaaaaaaaaaaaaa|*2
851      aaaaaaaaa^a{1:¬}         |
852                          |
853    ]])
854    feed('0')
855    screen:expect([[
856      ^aaaaaaaaaaaaaaaaaaaa|
857      aaaaaaaaaaaaaaaaaaaa|*3
858                          |
859    ]])
860  end)
861
862  it("'listchar' in visual mode", function()
863    screen:add_extra_attr_ids {
864      [100] = {
865        foreground = Screen.colors.Blue1,
866        bold = true,
867        background = Screen.colors.LightGray,
868      },
869      [101] = { foreground = Screen.colors.Red, background = Screen.colors.Grey90 },
870      [102] = { foreground = Screen.colors.Blue1, bold = true, background = Screen.colors.Grey90 },
871      [103] = { foreground = Screen.colors.Red, background = Screen.colors.LightGray },
872    }
873    command('highlight clear ModeMsg')
874    command('highlight Whitespace guifg=#FF0000')
875    command('set cursorline')
876    command('set tabstop=8')
877    command('set nowrap')
878    command('set listchars=space:.,eol:¬,tab:>-,extends:>,precedes:<,trail:* list')
879    feed('i\t abcd <cr>\t abcd Lorem ipsum dolor sit amet<cr><esc>kkk0')
880    screen:expect([[
881      {101:^>-------.}{21:abcd}{101:*}{102:¬}{21:     }|
882      {19:>-------.}abcd{19:.}Lorem{1:>}|
883      {1:¬}                   |
884      {1:~                   }|
885                          |
886    ]])
887    feed('lllvj')
888    screen:expect([[
889      {19:>-------.}a{17:bcd}{103:*}{100:¬}     |
890      {103:>-------.}{17:a^b}cd{19:.}Lorem{1:>}|
891      {1:¬}                   |
892      {1:~                   }|
893      -- VISUAL --        |
894    ]])
895    feed('<esc>V')
896    screen:expect([[
897      {19:>-------.}abcd{19:*}{1:¬}     |
898      {103:>-------.}{17:a^bcd}{103:.}{17:Lorem}{1:>}|
899      {1:¬}                   |
900      {1:~                   }|
901      -- VISUAL LINE --   |
902    ]])
903    feed('<esc>$')
904    screen:expect([[
905      {1:<}                   |
906      {102:<}{21:r}{101:.}{21:sit}{101:.}{21:ame^t}{102:¬}{21:        }|
907      {1:<}                   |
908      {1:~                   }|
909                          |
910    ]])
911  end)
912
913  it("'cursorline' with :match", function()
914    screen:add_extra_attr_ids {
915      [100] = { foreground = Screen.colors.Lime, background = Screen.colors.Red },
916    }
917    feed_command('highlight clear ModeMsg')
918    feed_command('highlight Whitespace guifg=#FF0000')
919    feed_command('highlight Error guifg=#00FF00')
920    feed_command('set nowrap')
921    feed('ia \t bc \t  <esc>')
922    screen:expect([[
923      a        bc      ^   |
924      {1:~                   }|*3
925                          |
926    ]])
927    feed_command('set listchars=space:.,eol:¬,tab:>-,extends:>,precedes:<,trail:* list')
928    screen:expect([[
929      a{19:.>-----.}bc{19:*>---*^*}{1:¬} |
930      {1:~                   }|*3
931                          |
932    ]])
933    feed_command('match Error /\\s\\+$/')
934    screen:expect([[
935      a{19:.>-----.}bc{100:*>---*^*}{1:¬} |
936      {1:~                   }|*3
937                          |
938    ]])
939  end)
940end)
941
942describe('CursorLine and CursorLineNr highlights', function()
943  before_each(clear)
944
945  it('overridden by Error, ColorColumn if fg not set', function()
946    local screen = Screen.new(50, 5)
947    screen:add_extra_attr_ids {
948      [100] = { background = Screen.colors.LightRed },
949      [101] = { foreground = Screen.colors.SlateBlue, background = Screen.colors.Grey90 },
950    }
951
952    command('filetype on')
953    command('syntax on')
954    command('set cursorline ft=json')
955    feed('i{<cr>"a" : abc // 10;<cr>}<cr><esc>')
956    screen:expect([[
957      {16:{}                                                 |
958      "{15:a}" : {9:abc} {9:// 10;}                                  |
959      {16:}}                                                 |
960      {21:^                                                  }|
961                                                        |
962    ]])
963
964    command('set colorcolumn=3')
965    feed('i  <esc>')
966    screen:expect([[
967      {16:{} {100: }                                               |
968      "{15:a}{100:"} : {9:abc} {9:// 10;}                                  |
969      {16:}} {100: }                                               |
970      {21: ^ }{100: }{21:                                               }|
971                                                        |
972    ]])
973  end)
974
975  it("overridden by NonText in 'showbreak' characters", function()
976    local screen = Screen.new(20, 5)
977    screen:add_extra_attr_ids {
978      [100] = { foreground = Screen.colors.Yellow1 },
979      [101] = { foreground = Screen.colors.Yellow1, background = Screen.colors.Blue },
980      [102] = { foreground = Screen.colors.Grey0, background = Screen.colors.Grey100 },
981      [103] = { foreground = Screen.colors.Yellow1, background = Screen.colors.Grey100 },
982    }
983
984    feed_command('set wrap cursorline')
985    feed_command('set showbreak=>>>')
986    feed_command('highlight clear NonText')
987    feed_command('highlight clear CursorLine')
988    feed_command('highlight NonText guifg=Yellow guibg=Blue gui=NONE')
989    feed_command('highlight CursorLine guifg=Black guibg=White gui=NONE')
990
991    feed('30iø<esc>o<esc>30ia<esc>')
992    screen:expect([[
993      øøøøøøøøøøøøøøøøøøøø|
994      {101:>>>}øøøøøøøøøø       |
995      {102:aaaaaaaaaaaaaaaaaaaa}|
996      {101:>>>}{102:aaaaaaaaa^a       }|
997                          |
998    ]])
999    feed('k')
1000    screen:expect([[
1001      {102:øøøøøøøøøøøøøøøøøøøø}|
1002      {101:>>>}{102:øøøøøøøøø^ø       }|
1003      aaaaaaaaaaaaaaaaaaaa|
1004      {101:>>>}aaaaaaaaaa       |
1005                          |
1006    ]])
1007    feed_command('highlight NonText guibg=NONE')
1008    screen:expect([[
1009      {102:øøøøøøøøøøøøøøøøøøøø}|
1010      {103:>>>}{102:øøøøøøøøø^ø       }|
1011      aaaaaaaaaaaaaaaaaaaa|
1012      {100:>>>}aaaaaaaaaa       |
1013                          |
1014    ]])
1015    feed_command('set nocursorline')
1016    screen:expect([[
1017      øøøøøøøøøøøøøøøøøøøø|
1018      {100:>>>}øøøøøøøøø^ø       |
1019      aaaaaaaaaaaaaaaaaaaa|
1020      {100:>>>}aaaaaaaaaa       |
1021      :set nocursorline   |
1022    ]])
1023  end)
1024
1025  it("'cursorlineopt' screenline", function()
1026    local screen = Screen.new(20, 5)
1027    screen:add_extra_attr_ids {
1028      [100] = { foreground = Screen.colors.Yellow },
1029      [101] = { foreground = Screen.colors.Red, background = Screen.colors.WebGreen },
1030      [102] = { foreground = Screen.colors.Black, background = Screen.colors.Grey100 },
1031      [103] = { foreground = Screen.colors.WebGreen, background = Screen.colors.Red },
1032    }
1033
1034    command('set wrap cursorline cursorlineopt=screenline')
1035    command('set showbreak=>>>')
1036    command('highlight clear NonText')
1037    command('highlight clear CursorLine')
1038    command('highlight NonText guifg=Yellow gui=NONE')
1039    command('highlight LineNr guifg=Red guibg=Green gui=NONE')
1040    command('highlight CursorLine guifg=Black guibg=White gui=NONE')
1041    command('highlight CursorLineNr guifg=Green guibg=Red gui=NONE')
1042
1043    feed('30iø<esc>o<esc>30ia<esc>')
1044
1045    -- CursorLine should not apply to 'showbreak' when 'cursorlineopt' contains "screenline"
1046    screen:expect([[
1047      øøøøøøøøøøøøøøøøøøøø|
1048      {100:>>>}øøøøøøøøøø       |
1049      aaaaaaaaaaaaaaaaaaaa|
1050      {100:>>>}{102:aaaaaaaaa^a       }|
1051                          |
1052    ]])
1053    feed('gk')
1054    screen:expect([[
1055      øøøøøøøøøøøøøøøøøøøø|
1056      {100:>>>}øøøøøøøøøø       |
1057      {102:aaaaaaaaaaaa^aaaaaaaa}|
1058      {100:>>>}aaaaaaaaaa       |
1059                          |
1060    ]])
1061    feed('k')
1062    screen:expect([[
1063      {102:øøøøøøøøøøøø^øøøøøøøø}|
1064      {100:>>>}øøøøøøøøøø       |
1065      aaaaaaaaaaaaaaaaaaaa|
1066      {100:>>>}aaaaaaaaaa       |
1067                          |
1068    ]])
1069
1070    -- CursorLineNr should not apply to line number when 'cursorlineopt' does not contain "number"
1071    command('set relativenumber numberwidth=2')
1072    screen:expect([[
1073      {101:0 }{102:øøøøøøøøøøøø^øøøøøø}|
1074      {101:  }{100:>>>}øøøøøøøøøøøø   |
1075      {101:1 }aaaaaaaaaaaaaaaaaa|
1076      {101:  }{100:>>>}aaaaaaaaaaaa   |
1077                          |
1078    ]])
1079
1080    -- CursorLineNr should apply to line number when 'cursorlineopt' contains "number"
1081    command('set cursorlineopt+=number')
1082    screen:expect([[
1083      {103:0 }{102:øøøøøøøøøøøø^øøøøøø}|
1084      {101:  }{100:>>>}øøøøøøøøøøøø   |
1085      {101:1 }aaaaaaaaaaaaaaaaaa|
1086      {101:  }{100:>>>}aaaaaaaaaaaa   |
1087                          |
1088    ]])
1089    feed('gj')
1090    screen:expect([[
1091      {103:0 }øøøøøøøøøøøøøøøøøø|
1092      {101:  }{100:>>>}{102:øøøøøøøøø^øøø   }|
1093      {101:1 }aaaaaaaaaaaaaaaaaa|
1094      {101:  }{100:>>>}aaaaaaaaaaaa   |
1095                          |
1096    ]])
1097    feed('gj')
1098    screen:expect([[
1099      {101:1 }øøøøøøøøøøøøøøøøøø|
1100      {101:  }{100:>>>}øøøøøøøøøøøø   |
1101      {103:0 }{102:aaaaaaaaaaaa^aaaaaa}|
1102      {101:  }{100:>>>}aaaaaaaaaaaa   |
1103                          |
1104    ]])
1105    feed('gj')
1106    screen:expect([[
1107      {101:1 }øøøøøøøøøøøøøøøøøø|
1108      {101:  }{100:>>>}øøøøøøøøøøøø   |
1109      {103:0 }aaaaaaaaaaaaaaaaaa|
1110      {101:  }{100:>>>}{102:aaaaaaaaa^aaa   }|
1111                          |
1112    ]])
1113
1114    -- updated in Insert mode
1115    feed('I')
1116    screen:expect([[
1117      {101:1 }øøøøøøøøøøøøøøøøøø|
1118      {101:  }{100:>>>}øøøøøøøøøøøø   |
1119      {103:0 }{102:^aaaaaaaaaaaaaaaaaa}|
1120      {101:  }{100:>>>}aaaaaaaaaaaa   |
1121      {5:-- INSERT --}        |
1122    ]])
1123
1124    feed('<Esc>gg')
1125    screen:expect([[
1126      {103:0 }{102:^øøøøøøøøøøøøøøøøøø}|
1127      {101:  }{100:>>>}øøøøøøøøøøøø   |
1128      {101:1 }aaaaaaaaaaaaaaaaaa|
1129      {101:  }{100:>>>}aaaaaaaaaaaa   |
1130                          |
1131    ]])
1132  end)
1133
1134  -- oldtest: Test_cursorline_screenline_resize()
1135  it("'cursorlineopt' screenline is updated on window resize", function()
1136    local screen = Screen.new(75, 8)
1137    exec([[
1138      50vnew
1139      call setline(1, repeat('xyz ', 30))
1140      setlocal number cursorline cursorlineopt=screenline
1141      normal! $
1142    ]])
1143    screen:expect([[
1144      {8:  1 }xyz xyz xyz xyz xyz xyz xyz xyz xyz xyz xyz xy│                        |
1145      {8:    }z xyz xyz xyz xyz xyz xyz xyz xyz xyz xyz xyz │{1:~                       }|
1146      {8:    }{21:xyz xyz xyz xyz xyz xyz xyz^                   }│{1:~                       }|
1147      {1:~                                                 }│{1:~                       }|*3
1148      {3:[No Name] [+]                                      }{2:[No Name]               }|
1149                                                                                 |
1150    ]])
1151    command('vertical resize -4')
1152    screen:expect([[
1153      {8:  1 }xyz xyz xyz xyz xyz xyz xyz xyz xyz xyz xy│                            |
1154      {8:    }z xyz xyz xyz xyz xyz xyz xyz xyz xyz xyz │{1:~                           }|
1155      {8:    }{21:xyz xyz xyz xyz xyz xyz xyz xyz xyz^       }│{1:~                           }|
1156      {1:~                                             }│{1:~                           }|*3
1157      {3:[No Name] [+]                                  }{2:[No Name]                   }|
1158                                                                                 |
1159    ]])
1160    command('set cpoptions+=n')
1161    screen:expect([[
1162      {8:  1 }xyz xyz xyz xyz xyz xyz xyz xyz xyz xyz xy│                            |
1163      z xyz xyz xyz xyz xyz xyz xyz xyz xyz xyz xyz │{1:~                           }|
1164      {21:xyz xyz xyz xyz xyz xyz xyz xyz^               }│{1:~                           }|
1165      {1:~                                             }│{1:~                           }|*3
1166      {3:[No Name] [+]                                  }{2:[No Name]                   }|
1167                                                                                 |
1168    ]])
1169  end)
1170
1171  -- oldtest: Test_cursorline_screenline_update()
1172  it("'cursorlineopt' screenline is updated on various movements", function()
1173    local screen = Screen.new(75, 8)
1174    exec([[
1175      func TestRetab()
1176        let w = winwidth(0)
1177        call cursor([1, w + 1, 0, w + 1])
1178        call line('w0')
1179        retab 8
1180      endfunc
1181
1182      call setline(1, repeat('xyz ', 30))
1183      set cursorline cursorlineopt=screenline tabstop=8
1184      inoremap <F2> <Cmd>call cursor(1, 1)<CR>
1185      inoremap <F3> <Cmd>call TestRetab()<CR>
1186    ]])
1187
1188    feed('A')
1189    screen:expect([[
1190      xyz xyz xyz xyz xyz xyz xyz xyz xyz xyz xyz xyz xyz xyz xyz xyz xyz xyz xyz|
1191      {21: xyz xyz xyz xyz xyz xyz xyz xyz xyz xyz xyz ^                              }|
1192      {1:~                                                                          }|*5
1193      {5:-- INSERT --}                                                               |
1194    ]])
1195    feed('<F2>')
1196    screen:expect([[
1197      {21:^xyz xyz xyz xyz xyz xyz xyz xyz xyz xyz xyz xyz xyz xyz xyz xyz xyz xyz xyz}|
1198       xyz xyz xyz xyz xyz xyz xyz xyz xyz xyz xyz                               |
1199      {1:~                                                                          }|*5
1200      {5:-- INSERT --}                                                               |
1201    ]])
1202    feed('<F3>')
1203    screen:expect([[
1204      xyz xyz xyz xyz xyz xyz xyz xyz xyz xyz xyz xyz xyz xyz xyz xyz xyz xyz xyz|
1205      {21:^ xyz xyz xyz xyz xyz xyz xyz xyz xyz xyz xyz                               }|
1206      {1:~                                                                          }|*5
1207      {5:-- INSERT --}                                                               |
1208    ]])
1209    feed('<Esc>')
1210  end)
1211
1212  -- oldtest: Test_cursorline_after_yank()
1213  it('always updated. vim-patch:8.1.0849', function()
1214    local screen = Screen.new(50, 5)
1215    screen:add_extra_attr_ids {
1216      [100] = { background = Screen.colors.LightRed },
1217      [101] = { foreground = Screen.colors.SlateBlue, background = Screen.colors.Grey90 },
1218    }
1219    command('set cursorline relativenumber')
1220    command('call setline(1, ["","1","2","3",""])')
1221    feed('Gy3k')
1222    screen:expect([[
1223      {15:  0 }{21:^1                                             }|
1224      {8:  1 }2                                             |
1225      {8:  2 }3                                             |
1226      {8:  3 }                                              |
1227      4 lines yanked                                    |
1228    ]])
1229    feed('jj')
1230    screen:expect([[
1231      {8:  2 }1                                             |
1232      {8:  1 }2                                             |
1233      {15:  0 }{21:^3                                             }|
1234      {8:  1 }                                              |
1235      4 lines yanked                                    |
1236    ]])
1237  end)
1238
1239  -- oldtest: Test_cursorline_with_visualmode()
1240  it('with visual area. vim-patch:8.1.1001', function()
1241    local screen = Screen.new(50, 5)
1242    screen:add_extra_attr_ids {
1243      [100] = { foreground = Screen.colors.SlateBlue, background = Screen.colors.Grey90 },
1244      [101] = { background = Screen.colors.LightRed },
1245    }
1246    command('set cursorline')
1247    command('call setline(1, repeat(["abc"], 50))')
1248    feed('V<C-f>zbkkjk')
1249    screen:expect([[
1250      {17:abc}                                               |
1251      {17:^abc}                                               |
1252      abc                                               |*2
1253      {5:-- VISUAL LINE --}                                 |
1254    ]])
1255  end)
1256
1257  -- oldtest: Test_cursorline_callback()
1258  it('is updated if cursor is moved up from timer vim-patch:8.2.4591', function()
1259    local screen = Screen.new(50, 8)
1260    exec([[
1261      call setline(1, ['aaaaa', 'bbbbb', 'ccccc', 'ddddd'])
1262      set cursorline
1263      call cursor(4, 1)
1264
1265      func Func(timer)
1266        call cursor(2, 1)
1267      endfunc
1268    ]])
1269    screen:expect([[
1270      aaaaa                                             |
1271      bbbbb                                             |
1272      ccccc                                             |
1273      {21:^ddddd                                             }|
1274      {1:~                                                 }|*3
1275                                                        |
1276    ]])
1277    command([[call timer_start(300, 'Func')]])
1278    screen:expect_unchanged(false, 100)
1279    screen:expect([[
1280      aaaaa                                             |
1281      {21:^bbbbb                                             }|
1282      ccccc                                             |
1283      ddddd                                             |
1284      {1:~                                                 }|*3
1285                                                        |
1286    ]])
1287  end)
1288
1289  it('with split windows in diff mode', function()
1290    local screen = Screen.new(50, 12)
1291    screen:add_extra_attr_ids {
1292      [100] = { background = Screen.colors.Plum1, underline = true },
1293      [101] = { background = Screen.colors.Red1, bold = true, underline = true },
1294    }
1295
1296    command('hi CursorLine ctermbg=red ctermfg=white guibg=red guifg=white')
1297    command('set cursorline')
1298    feed('iline 1 some text<cr>line 2 more text<cr>extra line!<cr>extra line!<cr>last line ...<cr>')
1299    feed('<esc>gg')
1300    command('vsplit')
1301    command('enew')
1302    feed(
1303      'iline 1 some text<cr>line 2 moRe text!<cr>extra line!<cr>extra line!<cr>extra line!<cr>last line ...<cr>'
1304    )
1305    feed('<esc>gg')
1306    command('windo diffthis')
1307    screen:expect([[
1308      {7:  }{9:line 1 some text       }│{7:  }{9:^line 1 some text      }|
1309      {7:  }{4:line 2 mo}{27:R}{4:e text}{27:!}{4:      }│{7:  }{4:line 2 mo}{27:r}{4:e text      }|
1310      {7:  }{22:extra line!            }│{7:  }{23:----------------------}|
1311      {7:  }extra line!            │{7:  }extra line!           |*2
1312      {7:  }last line ...          │{7:  }last line ...         |
1313      {7:  }                       │{7:  }                      |
1314      {1:~                        }│{1:~                       }|*3
1315      {2:[No Name] [+]             }{3:[No Name] [+]           }|
1316                                                        |
1317    ]])
1318    feed('jjjjj')
1319    screen:expect([[
1320      {7:  }line 1 some text       │{7:  }line 1 some text      |
1321      {7:  }{4:line 2 mo}{27:R}{4:e text}{27:!}{4:      }│{7:  }{4:line 2 mo}{27:r}{4:e text      }|
1322      {7:  }{22:extra line!            }│{7:  }{23:----------------------}|
1323      {7:  }extra line!            │{7:  }extra line!           |*2
1324      {7:  }last line ...          │{7:  }last line ...         |
1325      {7:  }{9:                       }│{7:  }{9:^                      }|
1326      {1:~                        }│{1:~                       }|*3
1327      {2:[No Name] [+]             }{3:[No Name] [+]           }|
1328                                                        |
1329    ]])
1330
1331    -- CursorLine with fg=NONE is "low-priority".
1332    -- Rendered as underline in a diff-line. #9028
1333    command('hi CursorLine ctermbg=red ctermfg=NONE guibg=red guifg=NONE')
1334    feed('kkkk')
1335    screen:expect([[
1336      {7:  }line 1 some text       │{7:  }line 1 some text      |
1337      {7:  }{100:line 2 mo}{101:R}{100:e text}{101:!}{100:      }│{7:  }{100:^line 2 mo}{101:r}{100:e text      }|
1338      {7:  }{22:extra line!            }│{7:  }{23:----------------------}|
1339      {7:  }extra line!            │{7:  }extra line!           |*2
1340      {7:  }last line ...          │{7:  }last line ...         |
1341      {7:  }                       │{7:  }                      |
1342      {1:~                        }│{1:~                       }|*3
1343      {2:[No Name] [+]             }{3:[No Name] [+]           }|
1344                                                        |
1345    ]])
1346  end)
1347
1348  -- oldtest: Test_diff_with_cursorline_number()
1349  it('CursorLineNr shows correctly just below filler lines', function()
1350    local screen = Screen.new(50, 12)
1351    screen:add_extra_attr_ids {
1352      [100] = { foreground = Screen.colors.Black, bold = true, background = Screen.colors.Grey100 },
1353    }
1354
1355    command('hi CursorLine guibg=red guifg=white')
1356    command('hi CursorLineNr guibg=white guifg=black gui=bold')
1357    command('set cursorline number')
1358    command('call setline(1, ["baz", "foo", "foo", "bar"])')
1359    feed('2gg0')
1360    command('vnew')
1361    command('call setline(1, ["foo", "foo", "bar"])')
1362    command('windo diffthis')
1363    command('1wincmd w')
1364    screen:expect([[
1365      {7:  }{8:    }{23:-------------------}│{7:  }{8:  1 }{22:baz               }|
1366      {7:  }{100:  1 }{9:^foo                }│{7:  }{100:  2 }{9:foo               }|
1367      {7:  }{8:  2 }foo                │{7:  }{8:  3 }foo               |
1368      {7:  }{8:  3 }bar                │{7:  }{8:  4 }bar               |
1369      {1:~                        }│{1:~                       }|*6
1370      {3:[No Name] [+]             }{2:[No Name] [+]           }|
1371                                                        |
1372    ]])
1373    command('set cursorlineopt=number')
1374    screen:expect([[
1375      {7:  }{8:    }{23:-------------------}│{7:  }{8:  1 }{22:baz               }|
1376      {7:  }{100:  1 }^foo                │{7:  }{100:  2 }{9:foo               }|
1377      {7:  }{8:  2 }foo                │{7:  }{8:  3 }foo               |
1378      {7:  }{8:  3 }bar                │{7:  }{8:  4 }bar               |
1379      {1:~                        }│{1:~                       }|*6
1380      {3:[No Name] [+]             }{2:[No Name] [+]           }|
1381                                                        |
1382    ]])
1383  end)
1384
1385  it('CursorLine overlays hl group linked to Normal', function()
1386    local screen = Screen.new(50, 12)
1387    screen:add_extra_attr_ids({
1388      [101] = { background = Screen.colors.Grey90, foreground = Screen.colors.Grey100 },
1389      [102] = { background = Screen.colors.DarkGray, foreground = Screen.colors.WebGreen },
1390    })
1391    command('hi Normal guibg=black guifg=white')
1392    command('hi def link Test Normal')
1393    feed('ifoo bar<ESC>')
1394    feed(':call matchadd("Test", "bar")<cr>')
1395    command('set cursorline')
1396    screen:expect([[
1397      {21:foo }{101:ba^r}{21:                                           }|
1398      {1:~                                                 }|*10
1399      :call matchadd("Test", "bar")                     |
1400    ]])
1401    api.nvim_buf_set_lines(0, 0, -1, false, { 'aaaaa', 'bbbbb' })
1402    command('hi AAA guifg=Green guibg=DarkGrey ctermfg=Green ctermbg=DarkGrey')
1403    fn.matchadd('AAA', 'aaaaa')
1404    command('setlocal winhighlight=Normal:NormalFloat')
1405    screen:expect([[
1406      {102:aaaa^a}{21:                                             }|
1407      {4:bbbbb                                             }|
1408      {11:~                                                 }|*9
1409      :call matchadd("Test", "bar")                     |
1410    ]])
1411  end)
1412end)
1413
1414describe('CursorColumn highlight', function()
1415  local screen
1416  before_each(function()
1417    clear()
1418    screen = Screen.new(50, 8)
1419    screen:add_extra_attr_ids {
1420      [100] = { background = Screen.colors.Blue1 },
1421    }
1422  end)
1423
1424  it('is updated when pressing "i" on a TAB character', function()
1425    exec([[
1426      call setline(1, ['123456789', "a\tb"])
1427      set cursorcolumn
1428      call cursor(2, 2)
1429    ]])
1430    screen:expect([[
1431      1234567{21:8}9                                         |
1432      a      ^ b                                         |
1433      {1:~                                                 }|*5
1434                                                        |
1435    ]])
1436    feed('i')
1437    screen:expect([[
1438      1{21:2}3456789                                         |
1439      a^       b                                         |
1440      {1:~                                                 }|*5
1441      {5:-- INSERT --}                                      |
1442    ]])
1443    feed('<C-O>')
1444    screen:expect([[
1445      1234567{21:8}9                                         |
1446      a      ^ b                                         |
1447      {1:~                                                 }|*5
1448      {5:-- (insert) --}                                    |
1449    ]])
1450    feed('i')
1451    screen:expect([[
1452      1{21:2}3456789                                         |
1453      a^       b                                         |
1454      {1:~                                                 }|*5
1455      {5:-- INSERT --}                                      |
1456    ]])
1457  end)
1458
1459  -- oldtest: Test_cursorcolumn_virtualedit()
1460  it('is correct with operator on empty line and virtualedit', function()
1461    exec([[
1462      set virtualedit=all
1463      set cursorcolumn
1464      call setline(1, ['', '', ''])
1465      call cursor(3, 1)
1466    ]])
1467    screen:expect([[
1468      {21: }                                                 |*2
1469      ^                                                  |
1470      {1:~                                                 }|*4
1471                                                        |
1472    ]])
1473    feed('<Del>')
1474    screen:expect_unchanged()
1475  end)
1476
1477  -- oldtest: Test_cursorcolumn_callback()
1478  it('is updated if cursor is moved from timer', function()
1479    exec([[
1480      call setline(1, ['aaaaa', 'bbbbb', 'ccccc', 'ddddd'])
1481      set cursorcolumn
1482      call cursor(4, 5)
1483
1484      func Func(timer)
1485        call cursor(1, 1)
1486      endfunc
1487    ]])
1488    screen:expect([[
1489      aaaa{21:a}                                             |
1490      bbbb{21:b}                                             |
1491      cccc{21:c}                                             |
1492      dddd^d                                             |
1493      {1:~                                                 }|*3
1494                                                        |
1495    ]])
1496    command([[call timer_start(300, 'Func')]])
1497    screen:expect_unchanged(false, 100)
1498    screen:expect([[
1499      ^aaaaa                                             |
1500      {21:b}bbbb                                             |
1501      {21:c}cccc                                             |
1502      {21:d}dddd                                             |
1503      {1:~                                                 }|*3
1504                                                        |
1505    ]])
1506  end)
1507
1508  it('is not shown on current line with virtualedit', function()
1509    exec([[
1510      hi! CursorColumn guibg=Red
1511      hi! CursorLine guibg=Blue
1512      set virtualedit=all cursorline cursorcolumn
1513    ]])
1514    insert('line 1\nline 2\nline 3')
1515    feed('k')
1516    screen:expect([[
1517      line {30:1}                                            |
1518      {100:line ^2                                            }|
1519      line {30:3}                                            |
1520      {1:~                                                 }|*4
1521                                                        |
1522    ]])
1523    feed('l')
1524    screen:expect([[
1525      line 1{30: }                                           |
1526      {100:line 2^                                            }|
1527      line 3{30: }                                           |
1528      {1:~                                                 }|*4
1529                                                        |
1530    ]])
1531    feed('l')
1532    screen:expect([[
1533      line 1 {30: }                                          |
1534      {100:line 2 ^                                           }|
1535      line 3 {30: }                                          |
1536      {1:~                                                 }|*4
1537                                                        |
1538    ]])
1539    feed('l')
1540    screen:expect([[
1541      line 1  {30: }                                         |
1542      {100:line 2  ^                                          }|
1543      line 3  {30: }                                         |
1544      {1:~                                                 }|*4
1545                                                        |
1546    ]])
1547  end)
1548
1549  it('is updated with completion active #39153', function()
1550    command('set autocomplete cursorcolumn')
1551    feed('iasdf<CR>')
1552    screen:expect([[
1553      {21:a}sdf                                              |
1554      ^                                                  |
1555      {1:~                                                 }|*5
1556      {5:-- INSERT --}                                      |
1557    ]])
1558    feed('a')
1559    screen:expect([[
1560      a{21:s}df                                              |
1561      a^                                                 |
1562      {4:asdf           }{1:                                   }|
1563      {1:~                                                 }|*4
1564      {5:-- INSERT --}                                      |
1565    ]])
1566    feed('s')
1567    screen:expect([[
1568      as{21:d}f                                              |
1569      as^                                                |
1570      {4:asdf           }{1:                                   }|
1571      {1:~                                                 }|*4
1572      {5:-- INSERT --}                                      |
1573    ]])
1574    feed('d')
1575    screen:expect([[
1576      asd{21:f}                                              |
1577      asd^                                               |
1578      {4:asdf           }{1:                                   }|
1579      {1:~                                                 }|*4
1580      {5:-- INSERT --}                                      |
1581    ]])
1582    feed('f')
1583    screen:expect([[
1584      asdf{21: }                                             |
1585      asdf^                                              |
1586      {4:asdf           }{1:                                   }|
1587      {1:~                                                 }|*4
1588      {5:-- INSERT --}                                      |
1589    ]])
1590    feed('g')
1591    screen:expect([[
1592      asdf {21: }                                            |
1593      asdfg^                                             |
1594      {1:~                                                 }|*5
1595      {5:-- INSERT --}                                      |
1596    ]])
1597    feed(' ')
1598    screen:expect([[
1599      asdf  {21: }                                           |
1600      asdfg ^                                            |
1601      {1:~                                                 }|*5
1602      {5:-- INSERT --}                                      |
1603    ]])
1604    feed('<BS>')
1605    screen:expect([[
1606      asdf {21: }                                            |
1607      asdfg^                                             |
1608      {1:~                                                 }|*5
1609      {5:-- INSERT --}                                      |
1610    ]])
1611    feed('<BS>')
1612    screen:expect([[
1613      asdf{21: }                                             |
1614      asdf^                                              |
1615      {4:asdf           }{1:                                   }|
1616      {1:~                                                 }|*4
1617      {5:-- INSERT --}                                      |
1618    ]])
1619    feed('<BS>')
1620    screen:expect([[
1621      asd{21:f}                                              |
1622      asd^                                               |
1623      {4:asdf           }{1:                                   }|
1624      {1:~                                                 }|*4
1625      {5:-- INSERT --}                                      |
1626    ]])
1627    feed('h')
1628    screen:expect([[
1629      asdf{21: }                                             |
1630      asdh^                                              |
1631      {1:~                                                 }|*5
1632      {5:-- INSERT --}                                      |
1633    ]])
1634    feed('<Esc>')
1635    screen:expect([[
1636      asd{21:f}                                              |
1637      asd^h                                              |
1638      {1:~                                                 }|*5
1639                                                        |
1640    ]])
1641  end)
1642end)
1643
1644describe('ColorColumn highlight', function()
1645  local screen
1646
1647  before_each(function()
1648    clear()
1649    screen = Screen.new(40, 15)
1650    screen:add_extra_attr_ids {
1651      [100] = { foreground = Screen.colors.Red, background = Screen.colors.Grey90 },
1652      [101] = { background = Screen.colors.LightRed },
1653      [102] = { foreground = Screen.colors.Blue1, bold = true, background = Screen.colors.LightRed },
1654    }
1655  end)
1656
1657  -- oldtest: Test_colorcolumn()
1658  it('when entering a buffer vim-patch:8.1.2073', function()
1659    exec([[
1660      set nohidden
1661      split
1662      edit X
1663      call setline(1, ["1111111111","22222222222","3333333333"])
1664      set nomodified
1665      set colorcolumn=3,9
1666      set number cursorline cursorlineopt=number
1667      wincmd w
1668      buf X
1669    ]])
1670    screen:expect([[
1671      {15:  1 }11{101:1}11111{101:1}1                          |
1672      {8:  2 }22{101:2}22222{101:2}22                         |
1673      {8:  3 }33{101:3}33333{101:3}3                          |
1674      {1:~                                       }|*3
1675      {2:X                                       }|
1676      {15:  1 }^11{101:1}11111{101:1}1                          |
1677      {8:  2 }22{101:2}22222{101:2}22                         |
1678      {8:  3 }33{101:3}33333{101:3}3                          |
1679      {1:~                                       }|*3
1680      {3:X                                       }|
1681                                              |
1682    ]])
1683  end)
1684
1685  -- oldtest: Test_colorcolumn_bri()
1686  it("in 'breakindent' vim-patch:8.2.1689", function()
1687    exec([[
1688      call setline(1, 'The quick brown fox jumped over the lazy dogs')
1689      set co=40 linebreak bri briopt=shift:2 cc=40,41,43
1690    ]])
1691    screen:expect([[
1692      ^The quick brown fox jumped over the    {101: }|
1693      {101: } {101:l}azy dogs                             |
1694      {1:~                                       }|*12
1695                                              |
1696    ]])
1697  end)
1698
1699  -- oldtest: Test_colorcolumn_sbr()
1700  it("in 'showbreak' vim-patch:8.2.1689", function()
1701    exec([[
1702      call setline(1, 'The quick brown fox jumped over the lazy dogs')
1703      set co=40 showbreak=+++>\\  cc=40,41,43
1704    ]])
1705    screen:expect([[
1706      ^The quick brown fox jumped over the laz{101:y}|
1707      {102:+}{1:+}{102:+}{1:>\} dogs                              |
1708      {1:~                                       }|*12
1709                                              |
1710    ]])
1711  end)
1712
1713  it('is combined with low-priority CursorLine highlight #23016', function()
1714    screen:try_resize(40, 2)
1715    command('set colorcolumn=30 cursorline')
1716    screen:expect([[
1717      {21:^                             }{101: }{21:          }|
1718                                              |
1719    ]])
1720    command('hi clear ColorColumn')
1721    screen:expect([[
1722      {21:^                                        }|
1723                                              |
1724    ]])
1725    command('hi ColorColumn guifg=Red')
1726    screen:expect([[
1727      {21:^                             }{100: }{21:          }|
1728                                              |
1729    ]])
1730  end)
1731end)
1732
1733describe('MsgSeparator highlight and msgsep fillchar', function()
1734  local screen
1735  before_each(function()
1736    clear()
1737    screen = Screen.new(50, 5)
1738    screen:set_default_attr_ids({
1739      [1] = { bold = true, foreground = Screen.colors.Blue },
1740      [2] = { bold = true, reverse = true },
1741      [3] = { bold = true, foreground = Screen.colors.SeaGreen4 },
1742      [4] = { background = Screen.colors.Cyan, bold = true, reverse = true },
1743      [5] = { bold = true, background = Screen.colors.Magenta },
1744      [6] = { background = Screen.colors.WebGray },
1745      [7] = {
1746        background = Screen.colors.WebGray,
1747        bold = true,
1748        foreground = Screen.colors.SeaGreen4,
1749      },
1750      [8] = { foreground = Screen.colors.Grey0, background = Screen.colors.Gray60 },
1751      [9] = { foreground = Screen.colors.Grey40, background = Screen.colors.Gray60 },
1752      [10] = { foreground = tonumber('0x000019'), background = Screen.colors.Gray60 },
1753      [11] = { background = Screen.colors.Gray60, bold = true, foreground = tonumber('0x666699') },
1754      [12] = { background = Screen.colors.Gray60, bold = true, foreground = tonumber('0x297d4e') },
1755      [13] = { background = tonumber('0xff4cff'), bold = true, foreground = tonumber('0xb200ff') },
1756    })
1757  end)
1758
1759  it('works', function()
1760    -- defaults
1761    feed_command('ls')
1762    screen:expect([[
1763                                                        |
1764      {2:                                                  }|
1765      :ls                                               |
1766        1 %a   "[No Name]"                    line 1    |
1767      {3:Press ENTER or type command to continue}^           |
1768    ]])
1769    feed('<cr>')
1770
1771    feed_command('set fillchars+=msgsep:-')
1772    feed_command('ls')
1773    screen:expect([[
1774                                                        |
1775      {2:--------------------------------------------------}|
1776      :ls                                               |
1777        1 %a   "[No Name]"                    line 1    |
1778      {3:Press ENTER or type command to continue}^           |
1779    ]])
1780
1781    -- linked to StatusLine per default
1782    feed_command('hi StatusLine guibg=Cyan')
1783    feed_command('ls')
1784    screen:expect([[
1785                                                        |
1786      {4:--------------------------------------------------}|
1787      :ls                                               |
1788        1 %a   "[No Name]"                    line 1    |
1789      {3:Press ENTER or type command to continue}^           |
1790    ]])
1791
1792    -- but can be unlinked
1793    feed_command('hi clear MsgSeparator')
1794    feed_command('hi MsgSeparator guibg=Magenta gui=bold')
1795    feed_command('ls')
1796    screen:expect([[
1797                                                        |
1798      {5:--------------------------------------------------}|
1799      :ls                                               |
1800        1 %a   "[No Name]"                    line 1    |
1801      {3:Press ENTER or type command to continue}^           |
1802    ]])
1803  end)
1804
1805  it('and MsgArea', function()
1806    feed_command('hi MsgArea guibg=Gray')
1807    screen:expect {
1808      grid = [[
1809      ^                                                  |
1810      {1:~                                                 }|*3
1811      {6:                                                  }|
1812    ]],
1813    }
1814    feed(':ls')
1815    screen:expect {
1816      grid = [[
1817                                                        |
1818      {1:~                                                 }|*3
1819      {6::ls^                                               }|
1820    ]],
1821    }
1822    feed(':<cr>')
1823    screen:expect {
1824      grid = [[
1825                                                        |
1826      {2:                                                  }|
1827      {6::ls:                                              }|
1828      {6:  1 %a   "[No Name]"                    line 1    }|
1829      {7:Press ENTER or type command to continue}{6:^           }|
1830    ]],
1831    }
1832
1833    -- support madness^Wblending of message "overlay"
1834    feed_command('hi MsgArea blend=20')
1835    feed_command('hi clear MsgSeparator')
1836    feed_command('hi MsgSeparator blend=30 guibg=Magenta')
1837    screen:expect {
1838      grid = [[
1839      ^                                                  |
1840      {1:~                                                 }|*3
1841      {8::hi}{9: }{8:MsgSeparator}{9: }{8:blend=30}{9: }{8:guibg=Magenta}{9:           }|
1842    ]],
1843    }
1844    feed(':ls')
1845    screen:expect {
1846      grid = [[
1847                                                        |
1848      {1:~                                                 }|*3
1849      {8::ls}{9:^                                               }|
1850    ]],
1851    }
1852    feed('<cr>')
1853    screen:expect {
1854      grid = [[
1855                                                        |
1856      {13:~                                                 }|
1857      {10::ls}{11:                                               }|
1858      {11:~ }{10:1}{11: }{10:%a}{11:   }{10:"[No}{11: }{10:Name]"}{11:                    }{10:line}{11: }{10:1}{11:    }|
1859      {12:Press}{9: }{12:ENTER}{9: }{12:or}{9: }{12:type}{9: }{12:command}{9: }{12:to}{9: }{12:continue}{9:^           }|
1860    ]],
1861    }
1862  end)
1863end)
1864
1865describe("'winhighlight' highlight", function()
1866  local screen
1867
1868  before_each(function()
1869    clear()
1870    screen = Screen.new(20, 8)
1871    screen:set_default_attr_ids {
1872      [0] = { bold = true, foreground = Screen.colors.Blue },
1873      [1] = { background = Screen.colors.DarkBlue },
1874      [2] = { background = Screen.colors.DarkBlue, bold = true, foreground = Screen.colors.Blue1 },
1875      [3] = { bold = true, reverse = true },
1876      [4] = { reverse = true },
1877      [5] = { background = Screen.colors.DarkGreen },
1878      [6] = { background = Screen.colors.DarkGreen, bold = true, foreground = Screen.colors.Blue1 },
1879      [7] = { background = Screen.colors.DarkMagenta },
1880      [8] = {
1881        background = Screen.colors.DarkMagenta,
1882        bold = true,
1883        foreground = Screen.colors.Blue1,
1884      },
1885      [9] = { foreground = Screen.colors.Brown },
1886      [10] = { foreground = Screen.colors.Brown, background = Screen.colors.DarkBlue },
1887      [11] = { background = Screen.colors.DarkBlue, bold = true, reverse = true },
1888      [12] = { background = Screen.colors.DarkGreen, reverse = true },
1889      [13] = { background = Screen.colors.Magenta4, reverse = true },
1890      [14] = { background = Screen.colors.DarkBlue, reverse = true },
1891      [15] = { foreground = Screen.colors.Grey100, background = Screen.colors.Red },
1892      [16] = { foreground = Screen.colors.Blue1 },
1893      [17] = { background = Screen.colors.LightRed },
1894      [18] = { background = Screen.colors.Gray90 },
1895      [19] = { foreground = Screen.colors.LightGrey, background = Screen.colors.DarkGray },
1896      [20] = { background = Screen.colors.LightGrey, underline = true },
1897      [21] = { bold = true },
1898      [22] = { bold = true, foreground = Screen.colors.SeaGreen4 },
1899      [23] = { background = Screen.colors.LightMagenta },
1900      [24] = { background = Screen.colors.WebGray },
1901      [25] = { bold = true, foreground = Screen.colors.Green1 },
1902      [26] = { background = Screen.colors.Red },
1903      [27] = { background = Screen.colors.DarkBlue, bold = true, foreground = Screen.colors.Green1 },
1904      [28] = { bold = true, foreground = Screen.colors.Brown },
1905      [29] = { foreground = Screen.colors.Blue1, background = Screen.colors.Red, bold = true },
1906      [30] = { background = tonumber('0xff8800') },
1907      [31] = { background = tonumber('0xff8800'), bold = true, foreground = Screen.colors.Blue },
1908      [32] = { bold = true, reverse = true, background = Screen.colors.DarkGreen },
1909    }
1910    command('hi Background1 guibg=DarkBlue')
1911    command('hi Background2 guibg=DarkGreen')
1912  end)
1913
1914  it('works for background color', function()
1915    insert('aa')
1916    command('split')
1917    command('set winhl=Normal:Background1')
1918    screen:expect([[
1919      {1:a^a                  }|
1920      {2:~                   }|*2
1921      {3:[No Name] [+]       }|
1922      aa                  |
1923      {0:~                   }|
1924      {4:[No Name] [+]       }|
1925                          |
1926    ]])
1927
1928    command('enew')
1929    screen:expect([[
1930      {1:^                    }|
1931      {2:~                   }|*2
1932      {3:[No Name]           }|
1933      aa                  |
1934      {0:~                   }|
1935      {4:[No Name] [+]       }|
1936                          |
1937    ]])
1938  end)
1939
1940  it('works for background color in rightleft window #22640', function()
1941    -- Use a wide screen to also check that this doesn't overflow linebuf_attr.
1942    screen:try_resize(80, 6)
1943    insert('aa')
1944    command('setlocal rightleft')
1945    command('setlocal winhl=Normal:Background1')
1946    screen:expect([[
1947      {1:                                                                              ^aa}|
1948      {2:                                                                               ~}|*4
1949                                                                                      |
1950    ]])
1951    command('botright vsplit')
1952    screen:expect([[
1953      {1:                                     aa│                                      ^aa}|
1954      {2:                                      ~}{1:│}{2:                                       ~}|*3
1955      {4:[No Name] [+]                           }{3:[No Name] [+]                           }|
1956                                                                                      |
1957    ]])
1958  end)
1959
1960  it('handles undefined groups', function()
1961    command('set winhl=Normal:Background1')
1962    screen:expect([[
1963      {1:^                    }|
1964      {2:~                   }|*6
1965                          |
1966    ]])
1967
1968    command('set winhl=xxx:yyy')
1969    eq('xxx:yyy', eval('&winhl'))
1970    screen:expect {
1971      grid = [[
1972      ^                    |
1973      {0:~                   }|*6
1974                          |
1975    ]],
1976    }
1977  end)
1978
1979  it('can be changed to define different groups', function()
1980    command('set winhl=EndOfBuffer:Background1')
1981    screen:expect {
1982      grid = [[
1983      ^                    |
1984      {1:~                   }|*6
1985                          |
1986    ]],
1987    }
1988
1989    command('set winhl=Normal:ErrorMsg')
1990    screen:expect {
1991      grid = [[
1992      {15:^                    }|
1993      {29:~                   }|*6
1994                          |
1995    ]],
1996    }
1997  end)
1998
1999  it('works local to the window', function()
2000    insert('aa')
2001    command('split')
2002    command('setlocal winhl=Normal:Background1')
2003    screen:expect([[
2004      {1:a^a                  }|
2005      {2:~                   }|*2
2006      {3:[No Name] [+]       }|
2007      aa                  |
2008      {0:~                   }|
2009      {4:[No Name] [+]       }|
2010                          |
2011    ]])
2012
2013    command('enew')
2014    screen:expect([[
2015      ^                    |
2016      {0:~                   }|*2
2017      {3:[No Name]           }|
2018      aa                  |
2019      {0:~                   }|
2020      {4:[No Name] [+]       }|
2021                          |
2022    ]])
2023
2024    command('bnext')
2025    screen:expect([[
2026      {1:^aa                  }|
2027      {2:~                   }|*2
2028      {3:[No Name] [+]       }|
2029      aa                  |
2030      {0:~                   }|
2031      {4:[No Name] [+]       }|
2032                          |
2033    ]])
2034  end)
2035
2036  it('for inactive window background works', function()
2037    command('set winhl=Normal:Background1,NormalNC:Background2')
2038    -- tests global value is copied across split
2039    command('split')
2040    screen:expect([[
2041      {1:^                    }|
2042      {2:~                   }|*2
2043      {3:[No Name]           }|
2044      {5:                    }|
2045      {6:~                   }|
2046      {4:[No Name]           }|
2047                          |
2048    ]])
2049
2050    feed('<c-w><c-w>')
2051    screen:expect([[
2052      {5:                    }|
2053      {6:~                   }|*2
2054      {4:[No Name]           }|
2055      {1:^                    }|
2056      {2:~                   }|
2057      {3:[No Name]           }|
2058                          |
2059    ]])
2060
2061    feed('<c-w><c-w>')
2062    screen:expect([[
2063      {1:^                    }|
2064      {2:~                   }|*2
2065      {3:[No Name]           }|
2066      {5:                    }|
2067      {6:~                   }|
2068      {4:[No Name]           }|
2069                          |
2070    ]])
2071  end)
2072
2073  it('works with NormalNC', function()
2074    command('hi NormalNC guibg=DarkMagenta')
2075    -- tests global value is copied across split
2076    command('split')
2077    screen:expect([[
2078      ^                    |
2079      {0:~                   }|*2
2080      {3:[No Name]           }|
2081      {7:                    }|
2082      {8:~                   }|
2083      {4:[No Name]           }|
2084                          |
2085    ]])
2086
2087    command('wincmd w')
2088    screen:expect([[
2089      {7:                    }|
2090      {8:~                   }|*2
2091      {4:[No Name]           }|
2092      ^                    |
2093      {0:~                   }|
2094      {3:[No Name]           }|
2095                          |
2096    ]])
2097
2098    -- winbg=Normal:... overrides global NormalNC
2099    command('set winhl=Normal:Background1')
2100    screen:expect([[
2101      {7:                    }|
2102      {8:~                   }|*2
2103      {4:[No Name]           }|
2104      {1:^                    }|
2105      {2:~                   }|
2106      {3:[No Name]           }|
2107                          |
2108    ]])
2109
2110    command('wincmd w')
2111    screen:expect([[
2112      ^                    |
2113      {0:~                   }|*2
2114      {3:[No Name]           }|
2115      {1:                    }|
2116      {2:~                   }|
2117      {4:[No Name]           }|
2118                          |
2119    ]])
2120
2121    command('wincmd w')
2122    command('set winhl=Normal:Background1,NormalNC:Background2')
2123    screen:expect([[
2124      {7:                    }|
2125      {8:~                   }|*2
2126      {4:[No Name]           }|
2127      {1:^                    }|
2128      {2:~                   }|
2129      {3:[No Name]           }|
2130                          |
2131    ]])
2132
2133    command('wincmd w')
2134    screen:expect([[
2135      ^                    |
2136      {0:~                   }|*2
2137      {3:[No Name]           }|
2138      {5:                    }|
2139      {6:~                   }|
2140      {4:[No Name]           }|
2141                          |
2142    ]])
2143  end)
2144
2145  it('updates background to changed linked group', function()
2146    command('split')
2147    command('setlocal winhl=Normal:FancyGroup') -- does not yet exist
2148    screen:expect {
2149      grid = [[
2150      ^                    |
2151      {0:~                   }|*2
2152      {3:[No Name]           }|
2153                          |
2154      {0:~                   }|
2155      {4:[No Name]           }|
2156                          |
2157    ]],
2158    }
2159
2160    command('hi FancyGroup guibg=#FF8800') -- nice orange
2161    screen:expect {
2162      grid = [[
2163      {30:^                    }|
2164      {31:~                   }|*2
2165      {3:[No Name]           }|
2166                          |
2167      {0:~                   }|
2168      {4:[No Name]           }|
2169                          |
2170    ]],
2171    }
2172  end)
2173
2174  it('background applies also to non-text', function()
2175    command('set sidescroll=0')
2176    insert('Lorem ipsum dolor sit amet ')
2177    command('set shiftwidth=2')
2178    feed('>>')
2179    command('set number')
2180    command('set breakindent')
2181    command('set briopt=shift:5,min:0')
2182    command('set list')
2183    command('set showbreak=↪')
2184    screen:expect([[
2185      {9:  1 }  ^Lorem ipsum do|
2186      {9:    }       {0:↪}lor sit |
2187      {9:    }       {0:↪}amet{0:-}   |
2188      {0:~                   }|*4
2189                          |
2190    ]])
2191
2192    command('set winhl=Normal:Background1')
2193    screen:expect([[
2194      {10:  1 }{1:  ^Lorem ipsum do}|
2195      {10:    }{1:       }{2:↪}{1:lor sit }|
2196      {10:    }{1:       }{2:↪}{1:amet}{2:-}{1:   }|
2197      {2:~                   }|*4
2198                          |
2199    ]])
2200
2201    command('set nowrap')
2202    command('set listchars+=extends:❯,precedes:❮')
2203    feed('3w')
2204    screen:expect([[
2205      {10:  1 }{2:❮}{1: dolor ^sit ame}{2:❯}|
2206      {2:~                   }|*6
2207                          |
2208    ]])
2209  end)
2210
2211  it("background doesn't override syntax background", function()
2212    command('syntax on')
2213    command('syntax keyword Foobar foobar')
2214    command('syntax keyword Article the')
2215    command('hi Foobar guibg=#FF0000')
2216    command('hi Article guifg=#00FF00 gui=bold')
2217    insert('the foobar was foobar')
2218    screen:expect([[
2219      {25:the} {26:foobar} was {26:fooba}|
2220      {26:^r}                   |
2221      {0:~                   }|*5
2222                          |
2223    ]])
2224
2225    -- winhl=Normal:Group with background doesn't override syntax background,
2226    -- but does combine with syntax foreground.
2227    command('set winhl=Normal:Background1')
2228    screen:expect([[
2229      {27:the}{1: }{26:foobar}{1: was }{26:fooba}|
2230      {26:^r}{1:                   }|
2231      {2:~                   }|*5
2232                          |
2233    ]])
2234  end)
2235
2236  it('can override NonText, Conceal and EndOfBuffer', function()
2237    api.nvim_buf_set_lines(0, 0, -1, true, { 'raa\000' })
2238    command('call matchaddpos("Conceal", [[1,2]], 0, -1, {"conceal": "#"})')
2239    command('set cole=2 cocu=nvic')
2240    command('split')
2241    command('call matchaddpos("Conceal", [[1,2]], 0, -1, {"conceal": "#"})')
2242    command('set winhl=SpecialKey:ErrorMsg,EndOfBuffer:Background1,' .. 'Conceal:Background2')
2243
2244    screen:expect([[
2245      ^r{5:#}a{15:^@}               |
2246      {1:~                   }|*2
2247      {3:[No Name] [+]       }|
2248      r{19:#}a{16:^@}               |
2249      {0:~                   }|
2250      {4:[No Name] [+]       }|
2251                          |
2252    ]])
2253  end)
2254
2255  it('can override LineNr, CursorColumn and ColorColumn', function()
2256    insert('very text\nmore text')
2257    command('set number')
2258    command('set colorcolumn=2')
2259    command('set cursorcolumn')
2260    feed('k')
2261
2262    command('split')
2263    command('set winhl=LineNr:Background1,CursorColumn:Background2,' .. 'ColorColumn:ErrorMsg')
2264    screen:expect([[
2265      {1:  1 }v{15:e}ry tex^t       |
2266      {1:  2 }m{15:o}re tex{5:t}       |
2267      {0:~                   }|
2268      {3:[No Name] [+]       }|
2269      {9:  1 }v{17:e}ry text       |
2270      {9:  2 }m{17:o}re tex{18:t}       |
2271      {4:[No Name] [+]       }|
2272                          |
2273    ]])
2274  end)
2275
2276  it('can override Tabline', function()
2277    command('tabnew')
2278    command('set winhl=TabLine:Background1,TabLineSel:ErrorMsg')
2279
2280    screen:expect([[
2281      {20: No Name] }{15: No Name]}{20:X}|
2282      ^                    |
2283      {0:~                   }|*5
2284                          |
2285    ]])
2286    command('tabnext')
2287    screen:expect([[
2288      {21: No Name] }{1: No Name]}{20:X}|
2289      ^                    |
2290      {0:~                   }|*5
2291                          |
2292    ]])
2293  end)
2294
2295  it('can override popupmenu', function()
2296    insert('word wording wordy')
2297    command('split')
2298    command(
2299      'set winhl=Pmenu:Background1,PmenuSel:Background2,' .. 'PmenuSbar:ErrorMsg,PmenuThumb:Normal'
2300    )
2301    screen:expect([[
2302      word wording word^y  |
2303      {0:~                   }|*2
2304      {3:[No Name] [+]       }|
2305      word wording wordy  |
2306      {0:~                   }|
2307      {4:[No Name] [+]       }|
2308                          |
2309    ]])
2310
2311    feed('oword<c-x><c-p>')
2312    screen:expect([[
2313      word wording wordy  |
2314      wordy^               |
2315      {1:word           }{0:     }|
2316      {1:wording        }{3:     }|
2317      {5:wordy          }rdy  |
2318      wordy               |
2319      {4:[No Name] [+]       }|
2320      {21:-- }{22:match 1 of 3}     |
2321    ]])
2322
2323    feed('<esc>u<c-w><c-w>oword<c-x><c-p>')
2324    screen:expect([[
2325      word wording wordy  |
2326      wordy               |
2327      {23:word           }{0:     }|
2328      {23:wording        }{4:     }|
2329      {24:wordy          }rdy  |
2330      wordy^               |
2331      {3:[No Name] [+]       }|
2332      {21:-- }{22:match 1 of 3}     |
2333    ]])
2334  end)
2335
2336  it('can override CursorLine and CursorLineNr', function()
2337    -- CursorLine used to be parsed as CursorLineNr, because strncmp
2338    command('set cursorline number')
2339    command('split')
2340    command('set winhl=CursorLine:Background1')
2341    screen:expect {
2342      grid = [[
2343      {28:  1 }{1:^                }|
2344      {0:~                   }|*2
2345      {3:[No Name]           }|
2346      {28:  1 }{18:                }|
2347      {0:~                   }|
2348      {4:[No Name]           }|
2349                          |
2350    ]],
2351    }
2352
2353    command('set winhl=CursorLineNr:Background2,CursorLine:Background1')
2354    screen:expect {
2355      grid = [[
2356      {5:  1 }{1:^                }|
2357      {0:~                   }|*2
2358      {3:[No Name]           }|
2359      {28:  1 }{18:                }|
2360      {0:~                   }|
2361      {4:[No Name]           }|
2362                          |
2363    ]],
2364    }
2365
2366    feed('<c-w>w')
2367    screen:expect {
2368      grid = [[
2369      {5:  1 }{1:                }|
2370      {0:~                   }|*2
2371      {4:[No Name]           }|
2372      {28:  1 }{18:^                }|
2373      {0:~                   }|
2374      {3:[No Name]           }|
2375                          |
2376    ]],
2377    }
2378  end)
2379
2380  it('can override StatusLine and StatusLineNC', function()
2381    command('set winhighlight=StatusLine:Background1,StatusLineNC:Background2')
2382    command('split')
2383    screen:expect([[
2384      ^                    |
2385      {0:~                   }|*2
2386      {1:[No Name]           }|
2387                          |
2388      {0:~                   }|
2389      {5:[No Name]           }|
2390                          |
2391    ]])
2392  end)
2393
2394  it('can override WinBar and WinBarNC #19345', function()
2395    command('setlocal winbar=foobar')
2396    command('set winhighlight=WinBar:Background1,WinBarNC:Background2')
2397    command('split')
2398    screen:expect([[
2399      {1:foobar              }|
2400      ^                    |
2401      {0:~                   }|
2402      {3:[No Name]           }|
2403      {5:foobar              }|
2404                          |
2405      {4:[No Name]           }|
2406                          |
2407    ]])
2408  end)
2409
2410  it('can override syntax groups', function()
2411    command('syntax on')
2412    command('syntax keyword Foobar foobar')
2413    command('syntax keyword Article the')
2414    command('hi Foobar guibg=#FF0000')
2415    command('hi Article guifg=#00FF00 gui=bold')
2416    insert('the foobar was foobar')
2417    screen:expect([[
2418      {25:the} {26:foobar} was {26:fooba}|
2419      {26:^r}                   |
2420      {0:~                   }|*5
2421                          |
2422    ]])
2423
2424    command('split')
2425    command('set winhl=Foobar:Background1,Article:ErrorMsg')
2426    screen:expect {
2427      grid = [[
2428      {15:the} {1:foobar} was {1:fooba}|
2429      {1:^r}                   |
2430      {0:~                   }|
2431      {3:[No Name] [+]       }|
2432      {25:the} {26:foobar} was {26:fooba}|
2433      {26:r}                   |
2434      {4:[No Name] [+]       }|
2435                          |
2436    ]],
2437    }
2438  end)
2439
2440  it('can be disabled in newly opened window #19823', function()
2441    command('split | set winhl=Normal:ErrorMsg | set winhl=')
2442    screen:expect {
2443      grid = [[
2444      ^                    |
2445      {0:~                   }|*2
2446      {3:[No Name]           }|
2447                          |
2448      {0:~                   }|
2449      {4:[No Name]           }|
2450                          |
2451    ]],
2452    }
2453
2454    n.assert_alive()
2455  end)
2456
2457  it('can redraw statusline on cursor movement', function()
2458    screen:try_resize(40, 8)
2459    exec [[
2460      set statusline=%f%=%#Background1#%l,%c%V\ %P
2461      split
2462    ]]
2463    insert [[
2464      some text
2465      more text]]
2466    screen:expect {
2467      grid = [[
2468      some text                               |
2469      more tex^t                               |
2470      {0:~                                       }|
2471      {3:[No Name]                        }{11:2,9 All}|
2472      some text                               |
2473      more text                               |
2474      {4:[No Name]                        }{14:1,1 All}|
2475                                              |
2476    ]],
2477    }
2478
2479    command 'set winhl=Background1:Background2'
2480    screen:expect {
2481      grid = [[
2482      some text                               |
2483      more tex^t                               |
2484      {0:~                                       }|
2485      {3:[No Name]                        }{32:2,9 All}|
2486      some text                               |
2487      more text                               |
2488      {4:[No Name]                        }{14:1,1 All}|
2489                                              |
2490    ]],
2491    }
2492
2493    feed 'k'
2494    screen:expect {
2495      grid = [[
2496      some tex^t                               |
2497      more text                               |
2498      {0:~                                       }|
2499      {3:[No Name]                        }{32:1,9 All}|
2500      some text                               |
2501      more text                               |
2502      {4:[No Name]                        }{14:1,1 All}|
2503                                              |
2504    ]],
2505    }
2506  end)
2507
2508  it('can link to empty highlight group', function()
2509    command 'hi NormalNC guibg=Red' -- czerwone time
2510    command 'set winhl=NormalNC:Normal'
2511    command 'split'
2512
2513    screen:expect {
2514      grid = [[
2515      ^                    |
2516      {0:~                   }|*2
2517      {3:[No Name]           }|
2518                          |
2519      {0:~                   }|
2520      {4:[No Name]           }|
2521                          |
2522    ]],
2523    }
2524  end)
2525end)
2526
2527describe('highlight namespaces', function()
2528  local screen
2529  local ns1, ns2
2530
2531  before_each(function()
2532    clear()
2533    screen = Screen.new(25, 10)
2534    screen:set_default_attr_ids {
2535      [1] = { foreground = Screen.colors.Blue, bold = true },
2536      [2] = { background = Screen.colors.DarkGrey },
2537      [3] = {
2538        italic = true,
2539        foreground = Screen.colors.DarkCyan,
2540        background = Screen.colors.DarkOrange4,
2541      },
2542      [4] = { background = Screen.colors.Magenta4 },
2543      [5] = { background = Screen.colors.Magenta4, foreground = Screen.colors.Crimson },
2544      [6] = { bold = true, reverse = true },
2545      [7] = { reverse = true },
2546      [8] = { foreground = Screen.colors.Gray20 },
2547      [9] = { foreground = Screen.colors.Blue },
2548      [10] = { bold = true, foreground = Screen.colors.SeaGreen },
2549    }
2550
2551    ns1 = api.nvim_create_namespace 'grungy'
2552    ns2 = api.nvim_create_namespace 'ultrared'
2553
2554    api.nvim_set_hl(ns1, 'Normal', { bg = 'DarkGrey' })
2555    api.nvim_set_hl(ns1, 'NonText', { bg = 'DarkOrange4', fg = 'DarkCyan', italic = true })
2556    api.nvim_set_hl(ns2, 'Normal', { bg = 'DarkMagenta' })
2557    api.nvim_set_hl(ns2, 'NonText', { fg = 'Crimson' })
2558  end)
2559
2560  it('can be used globally', function()
2561    screen:expect {
2562      grid = [[
2563      ^                         |
2564      {1:~                        }|*8
2565                               |
2566    ]],
2567    }
2568
2569    api.nvim_set_hl_ns(ns1)
2570    screen:expect {
2571      grid = [[
2572      {2:^                         }|
2573      {3:~                        }|*8
2574                               |
2575    ]],
2576    }
2577
2578    api.nvim_set_hl_ns(ns2)
2579    screen:expect {
2580      grid = [[
2581      {4:^                         }|
2582      {5:~                        }|*8
2583                               |
2584    ]],
2585    }
2586
2587    api.nvim_set_hl_ns(0)
2588    screen:expect {
2589      grid = [[
2590      ^                         |
2591      {1:~                        }|*8
2592                               |
2593    ]],
2594    }
2595  end)
2596
2597  it('can be used per window', function()
2598    local win1 = api.nvim_get_current_win()
2599    command 'split'
2600    local win2 = api.nvim_get_current_win()
2601    command 'split'
2602
2603    api.nvim_win_set_hl_ns(win1, ns1)
2604    api.nvim_win_set_hl_ns(win2, ns2)
2605
2606    screen:expect {
2607      grid = [[
2608      ^                         |
2609      {1:~                        }|
2610      {6:[No Name]                }|
2611      {4:                         }|
2612      {5:~                        }|
2613      {7:[No Name]                }|
2614      {2:                         }|
2615      {3:~                        }|
2616      {7:[No Name]                }|
2617                               |
2618    ]],
2619    }
2620  end)
2621
2622  it('redraws correctly when ns=0', function()
2623    screen:expect {
2624      grid = [[
2625      ^                         |
2626      {1:~                        }|*8
2627                               |
2628    ]],
2629    }
2630
2631    api.nvim_set_hl(0, 'EndOfBuffer', { fg = '#333333' })
2632    screen:expect {
2633      grid = [[
2634      ^                         |
2635      {8:~                        }|*8
2636                               |
2637    ]],
2638    }
2639  end)
2640
2641  it('winhl does not accept invalid value #24586', function()
2642    command('set winhl=Normal:Visual')
2643    for _, cmd in ipairs({
2644      [[set winhl='Normal:Wrong']],
2645      [[set winhl=Normal:Wrong']],
2646      [[set winhl='Normal:Wrong]],
2647    }) do
2648      local res = exec_lua(
2649        [[
2650          local _, msg = pcall(vim.api.nvim_command, ...)
2651          return { msg, vim.wo.winhl }
2652        ]],
2653        cmd
2654      )
2655      eq({
2656        'Vim(set):E5248: Invalid character in group name',
2657        'Normal:Visual',
2658      }, res)
2659    end
2660  end)
2661
2662  it('Normal in set_hl #25474', function()
2663    command('highlight Ignore guifg=bg ctermfg=White')
2664    api.nvim_set_hl(0, 'Normal', { bg = '#333333' })
2665    command('highlight Ignore')
2666    screen:expect {
2667      grid = [[
2668                               |
2669      {1:~                        }|*2
2670      {6:                         }|
2671                               |
2672      Ignore         {8:xxx} {9:ctermf}|
2673      {9:g=}15               {9:guifg=}|
2674      bg                       |
2675      {10:Press ENTER or type comma}|
2676      {10:nd to continue}^           |
2677    ]],
2678    }
2679  end)
2680end)
2681
2682describe('synIDattr()', function()
2683  before_each(function()
2684    clear()
2685    command('highlight Normal ctermfg=252 guifg=#ff0000 guibg=Black')
2686    -- Salmon #fa8072 Maroon #800000
2687    command(
2688      'highlight Keyword ctermfg=79 guifg=Salmon guisp=Maroon cterm=strikethrough gui=strikethrough'
2689    )
2690  end)
2691
2692  it('returns cterm-color if RGB-capable UI is _not_ attached', function()
2693    eq('252', eval('synIDattr(hlID("Normal"),  "fg")'))
2694    eq('252', eval('synIDattr(hlID("Normal"),  "fg#")'))
2695    eq('', eval('synIDattr(hlID("Normal"),  "bg")'))
2696    eq('', eval('synIDattr(hlID("Normal"),  "bg#")'))
2697    eq('79', eval('synIDattr(hlID("Keyword"), "fg")'))
2698    eq('79', eval('synIDattr(hlID("Keyword"), "fg#")'))
2699    eq('', eval('synIDattr(hlID("Keyword"), "sp")'))
2700    eq('', eval('synIDattr(hlID("Keyword"), "sp#")'))
2701  end)
2702
2703  it('returns gui-color if "gui" arg is passed', function()
2704    eq('Black', eval('synIDattr(hlID("Normal"),  "bg", "gui")'))
2705    eq('Maroon', eval('synIDattr(hlID("Keyword"), "sp", "gui")'))
2706  end)
2707
2708  it('returns gui-color if RGB-capable UI is attached', function()
2709    local _ = Screen.new(50, 7, { rgb = true })
2710    eq('#ff0000', eval('synIDattr(hlID("Normal"),  "fg")'))
2711    eq('Black', eval('synIDattr(hlID("Normal"),  "bg")'))
2712    eq('Salmon', eval('synIDattr(hlID("Keyword"), "fg")'))
2713    eq('Maroon', eval('synIDattr(hlID("Keyword"), "sp")'))
2714  end)
2715
2716  it('returns #RRGGBB value for fg#/bg#/sp#', function()
2717    local _ = Screen.new(50, 7, { rgb = true })
2718    eq('#ff0000', eval('synIDattr(hlID("Normal"),  "fg#")'))
2719    eq('#000000', eval('synIDattr(hlID("Normal"),  "bg#")'))
2720    eq('#fa8072', eval('synIDattr(hlID("Keyword"), "fg#")'))
2721    eq('#800000', eval('synIDattr(hlID("Keyword"), "sp#")'))
2722  end)
2723
2724  it('returns color number if non-RGB GUI', function()
2725    local _ = Screen.new(50, 7, { rgb = false })
2726    eq('252', eval('synIDattr(hlID("Normal"), "fg")'))
2727    eq('79', eval('synIDattr(hlID("Keyword"), "fg")'))
2728  end)
2729
2730  it('returns "1" if group has given highlight attribute', function()
2731    local hl_attrs = {
2732      'underline',
2733      'undercurl',
2734      'underdouble',
2735      'underdotted',
2736      'underdashed',
2737      'strikethrough',
2738    }
2739    for _, hl_attr in ipairs(hl_attrs) do
2740      local context = 'using ' .. hl_attr .. ' attr'
2741      command('highlight Keyword cterm=' .. hl_attr .. ' gui=' .. hl_attr)
2742      eq('', eval('synIDattr(hlID("Normal"), "' .. hl_attr .. '")'), context)
2743      eq('1', eval('synIDattr(hlID("Keyword"), "' .. hl_attr .. '")'), context)
2744      eq('1', eval('synIDattr(hlID("Keyword"), "' .. hl_attr .. '", "gui")'), context)
2745    end
2746  end)
2747end)
2748
2749describe('fg/bg special colors', function()
2750  before_each(function()
2751    clear()
2752    command('highlight Normal ctermfg=145 ctermbg=16 guifg=#ff0000 guibg=Black')
2753    command('highlight Visual ctermfg=bg ctermbg=fg guifg=bg guibg=fg guisp=bg')
2754  end)
2755
2756  it('resolve to "Normal" values', function()
2757    eq(eval('synIDattr(hlID("Normal"), "bg")'), eval('synIDattr(hlID("Visual"), "fg")'))
2758    eq(eval('synIDattr(hlID("Normal"), "bg#")'), eval('synIDattr(hlID("Visual"), "fg#")'))
2759    eq(eval('synIDattr(hlID("Normal"), "fg")'), eval('synIDattr(hlID("Visual"), "bg")'))
2760    eq(eval('synIDattr(hlID("Normal"), "fg#")'), eval('synIDattr(hlID("Visual"), "bg#")'))
2761    eq('bg', eval('synIDattr(hlID("Visual"), "fg", "gui")'))
2762    eq('bg', eval('synIDattr(hlID("Visual"), "fg#", "gui")'))
2763    eq('fg', eval('synIDattr(hlID("Visual"), "bg", "gui")'))
2764    eq('fg', eval('synIDattr(hlID("Visual"), "bg#", "gui")'))
2765    eq('bg', eval('synIDattr(hlID("Visual"), "sp", "gui")'))
2766    eq('bg', eval('synIDattr(hlID("Visual"), "sp#", "gui")'))
2767  end)
2768
2769  it('resolve to "Normal" values in RGB-capable UI', function()
2770    local _ = Screen.new(50, 7, { rgb = true })
2771    eq('bg', eval('synIDattr(hlID("Visual"), "fg")'))
2772    eq(eval('synIDattr(hlID("Normal"), "bg#")'), eval('synIDattr(hlID("Visual"), "fg#")'))
2773    eq('fg', eval('synIDattr(hlID("Visual"), "bg")'))
2774    eq(eval('synIDattr(hlID("Normal"), "fg#")'), eval('synIDattr(hlID("Visual"), "bg#")'))
2775    eq('bg', eval('synIDattr(hlID("Visual"), "sp")'))
2776    eq(eval('synIDattr(hlID("Normal"), "bg#")'), eval('synIDattr(hlID("Visual"), "sp#")'))
2777  end)
2778
2779  it('resolve after the "Normal" group is modified', function()
2780    local _ = Screen.new(50, 7, { rgb = true })
2781    local new_guibg = '#282c34'
2782    local new_guifg = '#abb2bf'
2783    command('highlight Normal guifg=' .. new_guifg .. ' guibg=' .. new_guibg)
2784    eq(new_guibg, eval('synIDattr(hlID("Visual"), "fg#")'))
2785    eq(new_guifg, eval('synIDattr(hlID("Visual"), "bg#")'))
2786    eq(new_guibg, eval('synIDattr(hlID("Visual"), "sp#")'))
2787  end)
2788
2789  it('changed highlight is reflected in messages before redraw #17832', function()
2790    local screen = Screen.new(50, 7, { rgb = true })
2791    command('set termguicolors')
2792    -- :echomsg in the same request, before the next redraw.
2793    command('call nvim_set_hl(0, "MsgArea", {"fg": "Red"}) | echomsg "foo"')
2794    screen:expect({
2795      grid = [[
2796        ^                                                  |
2797        {1:~                                                 }|*5
2798        {19:foo                                               }|
2799      ]],
2800    })
2801  end)
2802end)