1" Tests for ":highlight" and highlighting.
2
3source view_util.vim
4source screendump.vim
5source check.vim
6source script_util.vim
7source vim9.vim
8
9func ClearDict(d)
10  for k in keys(a:d)
11    call remove(a:d, k)
12  endfor
13endfunc
14
15func Test_highlight()
16  " basic test if ":highlight" doesn't crash
17  highlight
18  hi Search
19
20  " test setting colors.
21  " test clearing one color and all doesn't generate error or warning
22  silent! hi NewGroup term=bold cterm=italic ctermfg=DarkBlue ctermbg=Grey gui= guifg=#00ff00 guibg=Cyan
23  silent! hi Group2 term= cterm=
24  hi Group3 term=underline cterm=bold
25
26  let res = split(execute("hi NewGroup"), "\n")[0]
27  " filter ctermfg and ctermbg, the numbers depend on the terminal
28  let res = substitute(res, 'ctermfg=\d*', 'ctermfg=2', '')
29  let res = substitute(res, 'ctermbg=\d*', 'ctermbg=3', '')
30  call assert_equal("NewGroup       xxx term=bold cterm=italic ctermfg=2 ctermbg=3",
31				\ res)
32  call assert_equal("Group2         xxx cleared",
33				\ split(execute("hi Group2"), "\n")[0])
34  call assert_equal("Group3         xxx term=underline cterm=bold",
35				\ split(execute("hi Group3"), "\n")[0])
36
37  hi clear NewGroup
38  call assert_equal("NewGroup       xxx cleared",
39				\ split(execute("hi NewGroup"), "\n")[0])
40  call assert_equal("Group2         xxx cleared",
41				\ split(execute("hi Group2"), "\n")[0])
42  hi Group2 NONE
43  call assert_equal("Group2         xxx cleared",
44				\ split(execute("hi Group2"), "\n")[0])
45  hi clear
46  call assert_equal("Group3         xxx cleared",
47				\ split(execute("hi Group3"), "\n")[0])
48  call assert_fails("hi Crash term='asdf", "E475:")
49endfunc
50
51func HighlightArgs(name)
52  return 'hi ' . substitute(split(execute('hi ' . a:name), '\n')[0], '\<xxx\>', '', '')
53endfunc
54
55func IsColorable()
56  return has('gui_running') || str2nr(&t_Co) >= 8
57endfunc
58
59func HiCursorLine()
60  let hiCursorLine = HighlightArgs('CursorLine')
61  if has('gui_running')
62    let guibg = matchstr(hiCursorLine, 'guibg=\w\+')
63    let hi_ul = 'hi CursorLine gui=underline guibg=NONE'
64    let hi_bg = 'hi CursorLine gui=NONE ' . guibg
65  else
66    let hi_ul = 'hi CursorLine cterm=underline ctermbg=NONE'
67    let hi_bg = 'hi CursorLine cterm=NONE ctermbg=Gray'
68  endif
69  return [hiCursorLine, hi_ul, hi_bg]
70endfunc
71
72func Check_lcs_eol_attrs(attrs, row, col)
73  let save_lcs = &lcs
74  set list
75
76  call assert_equal(a:attrs, ScreenAttrs(a:row, a:col)[0])
77
78  set nolist
79  let &lcs = save_lcs
80endfunc
81
82func Test_highlight_eol_with_cursorline()
83  let [hiCursorLine, hi_ul, hi_bg] = HiCursorLine()
84
85  call NewWindow('topleft 5', 20)
86  call setline(1, 'abcd')
87  call matchadd('Search', '\n')
88
89  " expected:
90  " 'abcd      '
91  "  ^^^^ ^^^^^   no highlight
92  "      ^        'Search' highlight
93  let attrs0 = ScreenAttrs(1, 10)[0]
94  call assert_equal(repeat([attrs0[0]], 4), attrs0[0:3])
95  call assert_equal(repeat([attrs0[0]], 5), attrs0[5:9])
96  call assert_notequal(attrs0[0], attrs0[4])
97
98  setlocal cursorline
99
100  " underline
101  exe hi_ul
102
103  " expected:
104  " 'abcd      '
105  "  ^^^^         underline
106  "      ^        'Search' highlight with underline
107  "       ^^^^^   underline
108  let attrs = ScreenAttrs(1, 10)[0]
109  call assert_equal(repeat([attrs[0]], 4), attrs[0:3])
110  call assert_equal([attrs[4]] + repeat([attrs[5]], 5), attrs[4:9])
111  call assert_notequal(attrs[0], attrs[4])
112  call assert_notequal(attrs[4], attrs[5])
113  call assert_notequal(attrs0[0], attrs[0])
114  call assert_notequal(attrs0[4], attrs[4])
115  call Check_lcs_eol_attrs(attrs, 1, 10)
116
117  if IsColorable()
118    " bg-color
119    exe hi_bg
120
121    " expected:
122    " 'abcd      '
123    "  ^^^^         bg-color of 'CursorLine'
124    "      ^        'Search' highlight
125    "       ^^^^^   bg-color of 'CursorLine'
126    let attrs = ScreenAttrs(1, 10)[0]
127    call assert_equal(repeat([attrs[0]], 4), attrs[0:3])
128    call assert_equal(repeat([attrs[5]], 5), attrs[5:9])
129    call assert_equal(attrs0[4], attrs[4])
130    call assert_notequal(attrs[0], attrs[4])
131    call assert_notequal(attrs[4], attrs[5])
132    call assert_notequal(attrs0[0], attrs[0])
133    call assert_notequal(attrs0[5], attrs[5])
134    call Check_lcs_eol_attrs(attrs, 1, 10)
135  endif
136
137  call CloseWindow()
138  exe hiCursorLine
139endfunc
140
141func Test_highlight_eol_with_cursorline_vertsplit()
142  let [hiCursorLine, hi_ul, hi_bg] = HiCursorLine()
143
144  call NewWindow('topleft 5', 5)
145  call setline(1, 'abcd')
146  call matchadd('Search', '\n')
147
148  let expected = "abcd |abcd     "
149  let actual = ScreenLines(1, 15)[0]
150  call assert_equal(expected, actual)
151
152  " expected:
153  " 'abcd |abcd     '
154  "  ^^^^  ^^^^^^^^^   no highlight
155  "      ^             'Search' highlight
156  "       ^            'VertSplit' highlight
157  let attrs0 = ScreenAttrs(1, 15)[0]
158  call assert_equal(repeat([attrs0[0]], 4), attrs0[0:3])
159  call assert_equal(repeat([attrs0[0]], 9), attrs0[6:14])
160  call assert_notequal(attrs0[0], attrs0[4])
161  call assert_notequal(attrs0[0], attrs0[5])
162  call assert_notequal(attrs0[4], attrs0[5])
163
164  setlocal cursorline
165
166  " expected:
167  " 'abcd |abcd     '
168  "  ^^^^              underline
169  "      ^             'Search' highlight with underline
170  "       ^            'VertSplit' highlight
171  "        ^^^^^^^^^   no highlight
172
173  " underline
174  exe hi_ul
175
176  let actual = ScreenLines(1, 15)[0]
177  call assert_equal(expected, actual)
178
179  let attrs = ScreenAttrs(1, 15)[0]
180  call assert_equal(repeat([attrs[0]], 4), attrs[0:3])
181  call assert_equal(repeat([attrs[6]], 9), attrs[6:14])
182  call assert_equal(attrs0[5:14], attrs[5:14])
183  call assert_notequal(attrs[0], attrs[4])
184  call assert_notequal(attrs[0], attrs[5])
185  call assert_notequal(attrs[0], attrs[6])
186  call assert_notequal(attrs[4], attrs[5])
187  call assert_notequal(attrs[5], attrs[6])
188  call assert_notequal(attrs0[0], attrs[0])
189  call assert_notequal(attrs0[4], attrs[4])
190  call Check_lcs_eol_attrs(attrs, 1, 15)
191
192  if IsColorable()
193    " bg-color
194    exe hi_bg
195
196    let actual = ScreenLines(1, 15)[0]
197    call assert_equal(expected, actual)
198
199    let attrs = ScreenAttrs(1, 15)[0]
200    call assert_equal(repeat([attrs[0]], 4), attrs[0:3])
201    call assert_equal(repeat([attrs[6]], 9), attrs[6:14])
202    call assert_equal(attrs0[5:14], attrs[5:14])
203    call assert_notequal(attrs[0], attrs[4])
204    call assert_notequal(attrs[0], attrs[5])
205    call assert_notequal(attrs[0], attrs[6])
206    call assert_notequal(attrs[4], attrs[5])
207    call assert_notequal(attrs[5], attrs[6])
208    call assert_notequal(attrs0[0], attrs[0])
209    call assert_equal(attrs0[4], attrs[4])
210    call Check_lcs_eol_attrs(attrs, 1, 15)
211  endif
212
213  call CloseWindow()
214  exe hiCursorLine
215endfunc
216
217func Test_highlight_eol_with_cursorline_rightleft()
218  CheckFeature rightleft
219
220  let [hiCursorLine, hi_ul, hi_bg] = HiCursorLine()
221
222  call NewWindow('topleft 5', 10)
223  setlocal rightleft
224  call setline(1, 'abcd')
225  call matchadd('Search', '\n')
226  let attrs0 = ScreenAttrs(1, 10)[0]
227
228  setlocal cursorline
229
230  " underline
231  exe hi_ul
232
233  " expected:
234  " '      dcba'
235  "        ^^^^   underline
236  "       ^       'Search' highlight with underline
237  "  ^^^^^        underline
238  let attrs = ScreenAttrs(1, 10)[0]
239  call assert_equal(repeat([attrs[9]], 4), attrs[6:9])
240  call assert_equal(repeat([attrs[4]], 5) + [attrs[5]], attrs[0:5])
241  call assert_notequal(attrs[9], attrs[5])
242  call assert_notequal(attrs[4], attrs[5])
243  call assert_notequal(attrs0[9], attrs[9])
244  call assert_notequal(attrs0[5], attrs[5])
245  call Check_lcs_eol_attrs(attrs, 1, 10)
246
247  if IsColorable()
248    " bg-color
249    exe hi_bg
250
251    " expected:
252    " '      dcba'
253    "        ^^^^   bg-color of 'CursorLine'
254    "       ^       'Search' highlight
255    "  ^^^^^        bg-color of 'CursorLine'
256    let attrs = ScreenAttrs(1, 10)[0]
257    call assert_equal(repeat([attrs[9]], 4), attrs[6:9])
258    call assert_equal(repeat([attrs[4]], 5), attrs[0:4])
259    call assert_equal(attrs0[5], attrs[5])
260    call assert_notequal(attrs[9], attrs[5])
261    call assert_notequal(attrs[5], attrs[4])
262    call assert_notequal(attrs0[9], attrs[9])
263    call assert_notequal(attrs0[4], attrs[4])
264    call Check_lcs_eol_attrs(attrs, 1, 10)
265  endif
266
267  call CloseWindow()
268  exe hiCursorLine
269endfunc
270
271func Test_highlight_eol_with_cursorline_linewrap()
272  let [hiCursorLine, hi_ul, hi_bg] = HiCursorLine()
273
274  call NewWindow('topleft 5', 10)
275  call setline(1, [repeat('a', 51) . 'bcd', ''])
276  call matchadd('Search', '\n')
277
278  setlocal wrap
279  normal! gg$
280  let attrs0 = ScreenAttrs(5, 10)[0]
281  setlocal cursorline
282
283  " underline
284  exe hi_ul
285
286  " expected:
287  " 'abcd      '
288  "  ^^^^         underline
289  "      ^        'Search' highlight with underline
290  "       ^^^^^   underline
291  let attrs = ScreenAttrs(5, 10)[0]
292  call assert_equal(repeat([attrs[0]], 4), attrs[0:3])
293  call assert_equal([attrs[4]] + repeat([attrs[5]], 5), attrs[4:9])
294  call assert_notequal(attrs[0], attrs[4])
295  call assert_notequal(attrs[4], attrs[5])
296  call assert_notequal(attrs0[0], attrs[0])
297  call assert_notequal(attrs0[4], attrs[4])
298  call Check_lcs_eol_attrs(attrs, 5, 10)
299
300  if IsColorable()
301    " bg-color
302    exe hi_bg
303
304    " expected:
305    " 'abcd      '
306    "  ^^^^         bg-color of 'CursorLine'
307    "      ^        'Search' highlight
308    "       ^^^^^   bg-color of 'CursorLine'
309    let attrs = ScreenAttrs(5, 10)[0]
310    call assert_equal(repeat([attrs[0]], 4), attrs[0:3])
311    call assert_equal(repeat([attrs[5]], 5), attrs[5:9])
312    call assert_equal(attrs0[4], attrs[4])
313    call assert_notequal(attrs[0], attrs[4])
314    call assert_notequal(attrs[4], attrs[5])
315    call assert_notequal(attrs0[0], attrs[0])
316    call assert_notequal(attrs0[5], attrs[5])
317    call Check_lcs_eol_attrs(attrs, 5, 10)
318  endif
319
320  setlocal nocursorline nowrap
321  normal! gg$
322  let attrs0 = ScreenAttrs(1, 10)[0]
323  setlocal cursorline
324
325  " underline
326  exe hi_ul
327
328  " expected:
329  " 'aaabcd    '
330  "  ^^^^^^       underline
331  "        ^      'Search' highlight with underline
332  "         ^^^   underline
333  let attrs = ScreenAttrs(1, 10)[0]
334  call assert_equal(repeat([attrs[0]], 6), attrs[0:5])
335  call assert_equal([attrs[6]] + repeat([attrs[7]], 3), attrs[6:9])
336  call assert_notequal(attrs[0], attrs[6])
337  call assert_notequal(attrs[6], attrs[7])
338  call assert_notequal(attrs0[0], attrs[0])
339  call assert_notequal(attrs0[6], attrs[6])
340  call Check_lcs_eol_attrs(attrs, 1, 10)
341
342  if IsColorable()
343    " bg-color
344    exe hi_bg
345
346    " expected:
347    " 'aaabcd    '
348    "  ^^^^^^       bg-color of 'CursorLine'
349    "        ^      'Search' highlight
350    "         ^^^   bg-color of 'CursorLine'
351    let attrs = ScreenAttrs(1, 10)[0]
352    call assert_equal(repeat([attrs[0]], 6), attrs[0:5])
353    call assert_equal(repeat([attrs[7]], 3), attrs[7:9])
354    call assert_equal(attrs0[6], attrs[6])
355    call assert_notequal(attrs[0], attrs[6])
356    call assert_notequal(attrs[6], attrs[7])
357    call assert_notequal(attrs0[0], attrs[0])
358    call assert_notequal(attrs0[7], attrs[7])
359    call Check_lcs_eol_attrs(attrs, 1, 10)
360  endif
361
362  call CloseWindow()
363  exe hiCursorLine
364endfunc
365
366func Test_highlight_eol_with_cursorline_sign()
367  CheckFeature signs
368
369  let [hiCursorLine, hi_ul, hi_bg] = HiCursorLine()
370
371  call NewWindow('topleft 5', 10)
372  call setline(1, 'abcd')
373  call matchadd('Search', '\n')
374
375  sign define Sign text=>>
376  exe 'sign place 1 line=1 name=Sign buffer=' . bufnr('')
377  let attrs0 = ScreenAttrs(1, 10)[0]
378  setlocal cursorline
379
380  " underline
381  exe hi_ul
382
383  " expected:
384  " '>>abcd    '
385  "  ^^           sign
386  "    ^^^^       underline
387  "        ^      'Search' highlight with underline
388  "         ^^^   underline
389  let attrs = ScreenAttrs(1, 10)[0]
390  call assert_equal(repeat([attrs[2]], 4), attrs[2:5])
391  call assert_equal([attrs[6]] + repeat([attrs[7]], 3), attrs[6:9])
392  call assert_notequal(attrs[2], attrs[6])
393  call assert_notequal(attrs[6], attrs[7])
394  call assert_notequal(attrs0[2], attrs[2])
395  call assert_notequal(attrs0[6], attrs[6])
396  call Check_lcs_eol_attrs(attrs, 1, 10)
397
398  if IsColorable()
399    " bg-color
400    exe hi_bg
401
402    " expected:
403    " '>>abcd    '
404    "  ^^           sign
405    "    ^^^^       bg-color of 'CursorLine'
406    "        ^      'Search' highlight
407    "         ^^^   bg-color of 'CursorLine'
408    let attrs = ScreenAttrs(1, 10)[0]
409    call assert_equal(repeat([attrs[2]], 4), attrs[2:5])
410    call assert_equal(repeat([attrs[7]], 3), attrs[7:9])
411    call assert_equal(attrs0[6], attrs[6])
412    call assert_notequal(attrs[2], attrs[6])
413    call assert_notequal(attrs[6], attrs[7])
414    call assert_notequal(attrs0[2], attrs[2])
415    call assert_notequal(attrs0[7], attrs[7])
416    call Check_lcs_eol_attrs(attrs, 1, 10)
417  endif
418
419  sign unplace 1
420  call CloseWindow()
421  exe hiCursorLine
422endfunc
423
424func Test_highlight_eol_with_cursorline_breakindent()
425  CheckFeature linebreak
426
427  let [hiCursorLine, hi_ul, hi_bg] = HiCursorLine()
428
429  call NewWindow('topleft 5', 10)
430  set showbreak=xxx
431  setlocal breakindent breakindentopt=min:0,shift:1 showbreak=>
432  call setline(1, ' ' . repeat('a', 9) . 'bcd')
433  call matchadd('Search', '\n')
434  let attrs0 = ScreenAttrs(2, 10)[0]
435  setlocal cursorline
436
437  " underline
438  exe hi_ul
439
440  " expected:
441  " '  >bcd    '
442  "  ^^^          breakindent and showbreak
443  "     ^^^       underline
444  "        ^      'Search' highlight with underline
445  "         ^^^   underline
446  let attrs = ScreenAttrs(2, 10)[0]
447  call assert_equal(repeat([attrs[0]], 2), attrs[0:1])
448  call assert_equal(repeat([attrs[3]], 3), attrs[3:5])
449  call assert_equal([attrs[6]] + repeat([attrs[7]], 3), attrs[6:9])
450  call assert_equal(attrs0[0], attrs[0])
451  call assert_notequal(attrs[0], attrs[2])
452  call assert_notequal(attrs[2], attrs[3])
453  call assert_notequal(attrs[3], attrs[6])
454  call assert_notequal(attrs[6], attrs[7])
455  call assert_notequal(attrs0[2], attrs[2])
456  call assert_notequal(attrs0[3], attrs[3])
457  call assert_notequal(attrs0[6], attrs[6])
458  call Check_lcs_eol_attrs(attrs, 2, 10)
459
460  if IsColorable()
461    " bg-color
462    exe hi_bg
463
464    " expected:
465    " '  >bcd    '
466    "  ^^^          breakindent and showbreak
467    "     ^^^       bg-color of 'CursorLine'
468    "        ^      'Search' highlight
469    "         ^^^   bg-color of 'CursorLine'
470    let attrs = ScreenAttrs(2, 10)[0]
471    call assert_equal(repeat([attrs[0]], 2), attrs[0:1])
472    call assert_equal(repeat([attrs[3]], 3), attrs[3:5])
473    call assert_equal(repeat([attrs[7]], 3), attrs[7:9])
474    call assert_equal(attrs0[0], attrs[0])
475    call assert_equal(attrs0[6], attrs[6])
476    call assert_notequal(attrs[0], attrs[2])
477    call assert_notequal(attrs[2], attrs[3])
478    call assert_notequal(attrs[3], attrs[6])
479    call assert_notequal(attrs[6], attrs[7])
480    call assert_notequal(attrs0[2], attrs[2])
481    call assert_notequal(attrs0[3], attrs[3])
482    call assert_notequal(attrs0[7], attrs[7])
483    call Check_lcs_eol_attrs(attrs, 2, 10)
484  endif
485
486  call CloseWindow()
487  set showbreak=
488  setlocal showbreak=
489  exe hiCursorLine
490endfunc
491
492func Test_highlight_eol_on_diff()
493  call setline(1, ['abcd', ''])
494  call matchadd('Search', '\n')
495  let attrs0 = ScreenAttrs(1, 10)[0]
496
497  diffthis
498  botright new
499  diffthis
500
501  " expected:
502  " '  abcd    '
503  "  ^^           sign
504  "    ^^^^ ^^^   'DiffAdd' highlight
505  "        ^      'Search' highlight
506  let attrs = ScreenAttrs(1, 10)[0]
507  call assert_equal(repeat([attrs[0]], 2), attrs[0:1])
508  call assert_equal(repeat([attrs[2]], 4), attrs[2:5])
509  call assert_equal(repeat([attrs[2]], 3), attrs[7:9])
510  call assert_equal(attrs0[4], attrs[6])
511  call assert_notequal(attrs[0], attrs[2])
512  call assert_notequal(attrs[0], attrs[6])
513  call assert_notequal(attrs[2], attrs[6])
514  call Check_lcs_eol_attrs(attrs, 1, 10)
515
516  bwipe!
517  diffoff
518endfunc
519
520func Test_termguicolors()
521  CheckOption termguicolors
522  if has('vtp') && !has('vcon') && !has('gui_running')
523    " Win32: 'guicolors' doesn't work without virtual console.
524    call assert_fails('set termguicolors', 'E954:')
525    return
526  endif
527
528  " Basic test that setting 'termguicolors' works with one color.
529  set termguicolors
530  redraw
531  set t_Co=1
532  redraw
533  set t_Co=0
534  redraw
535endfunc
536
537func Test_cursorline_after_yank()
538  CheckScreendump
539
540  call writefile([
541	\ 'set cul rnu',
542	\ 'call setline(1, ["","1","2","3",""])',
543	\ ], 'Xtest_cursorline_yank')
544  let buf = RunVimInTerminal('-S Xtest_cursorline_yank', {'rows': 8})
545  call TermWait(buf)
546  call term_sendkeys(buf, "Gy3k")
547  call TermWait(buf)
548  call term_sendkeys(buf, "jj")
549
550  call VerifyScreenDump(buf, 'Test_cursorline_yank_01', {})
551
552  " clean up
553  call StopVimInTerminal(buf)
554  call delete('Xtest_cursorline_yank')
555endfunc
556
557" test for issue #4862
558func Test_put_before_cursorline()
559  new
560  only!
561  call setline(1, 'A')
562  redraw
563  let std_attr = screenattr(1, 1)
564  set cursorline
565  redraw
566  let cul_attr = screenattr(1, 1)
567  normal yyP
568  redraw
569  " Line 1 has cursor so it should be highlighted with CursorLine.
570  call assert_equal(cul_attr, screenattr(1, 1))
571  " And CursorLine highlighting from the second line should be gone.
572  call assert_equal(std_attr, screenattr(2, 1))
573  set nocursorline
574  bwipe!
575endfunc
576
577func Test_cursorline_with_visualmode()
578  CheckScreendump
579
580  call writefile([
581	\ 'set cul',
582	\ 'call setline(1, repeat(["abc"], 50))',
583	\ ], 'Xtest_cursorline_with_visualmode')
584  let buf = RunVimInTerminal('-S Xtest_cursorline_with_visualmode', {'rows': 12})
585  call TermWait(buf)
586  call term_sendkeys(buf, "V\<C-f>kkkjk")
587
588  call VerifyScreenDump(buf, 'Test_cursorline_with_visualmode_01', {})
589
590  " clean up
591  call StopVimInTerminal(buf)
592  call delete('Xtest_cursorline_with_visualmode')
593endfunc
594
595func Test_wincolor()
596  CheckScreendump
597  " make sure the width is enough for the test
598  set columns=80
599
600  let lines =<< trim END
601	set cursorline cursorcolumn rnu
602	call setline(1, ["","1111111111","22222222222","3 here 3","","the cat is out of the bag"])
603	set wincolor=Pmenu
604	hi CatLine guifg=green ctermfg=green
605	hi Reverse gui=reverse cterm=reverse
606	syn match CatLine /^the.*/
607	call prop_type_add("foo", {"highlight": "Reverse", "combine": 1})
608	call prop_add(6, 12, {"type": "foo", "end_col": 15})
609	/here
610  END
611  call writefile(lines, 'Xtest_wincolor')
612  let buf = RunVimInTerminal('-S Xtest_wincolor', {'rows': 8})
613  call TermWait(buf)
614  call term_sendkeys(buf, "2G5lvj")
615  call TermWait(buf)
616
617  call VerifyScreenDump(buf, 'Test_wincolor_01', {})
618
619  " clean up
620  call term_sendkeys(buf, "\<Esc>")
621  call StopVimInTerminal(buf)
622  call delete('Xtest_wincolor')
623endfunc
624
625func Test_wincolor_listchars()
626  CheckScreendump
627  CheckFeature conceal
628
629  let lines =<< trim END
630	call setline(1, ["one","\t\tsome random text enough long to show 'extends' and 'precedes' includingnbsps, preceding tabs and trailing spaces    ","three"])
631	set wincolor=Todo
632	set nowrap cole=1 cocu+=n
633	set list lcs=eol:$,tab:>-,space:.,trail:_,extends:>,precedes:<,conceal:*,nbsp:#
634	call matchadd('Conceal', 'text')
635	normal 2G5zl
636  END
637  call writefile(lines, 'Xtest_wincolorlcs')
638  let buf = RunVimInTerminal('-S Xtest_wincolorlcs', {'rows': 8})
639
640  call VerifyScreenDump(buf, 'Test_wincolor_lcs', {})
641
642  " clean up
643  call term_sendkeys(buf, "\<Esc>")
644  call StopVimInTerminal(buf)
645  call delete('Xtest_wincolorlcs')
646endfunc
647
648func Test_colorcolumn()
649  CheckScreendump
650
651  " check that setting 'colorcolumn' when entering a buffer works
652  let lines =<< trim END
653	split
654	edit X
655	call setline(1, ["1111111111","22222222222","3333333333"])
656	set nomodified
657	set colorcolumn=3,9
658	set number cursorline cursorlineopt=number
659	wincmd w
660	buf X
661  END
662  call writefile(lines, 'Xtest_colorcolumn')
663  let buf = RunVimInTerminal('-S Xtest_colorcolumn', {'rows': 10})
664  call term_sendkeys(buf, ":\<CR>")
665  call TermWait(buf)
666  call VerifyScreenDump(buf, 'Test_colorcolumn_1', {})
667
668  " clean up
669  call StopVimInTerminal(buf)
670  call delete('Xtest_colorcolumn')
671endfunc
672
673func Test_colorcolumn_bri()
674  CheckScreendump
675
676  " check 'colorcolumn' when 'breakindent' is set
677  let lines =<< trim END
678	call setline(1, 'The quick brown fox jumped over the lazy dogs')
679  END
680  call writefile(lines, 'Xtest_colorcolumn_bri')
681  let buf = RunVimInTerminal('-S Xtest_colorcolumn_bri', {'rows': 10,'columns': 40})
682  call term_sendkeys(buf, ":set co=40 linebreak bri briopt=shift:2 cc=40,41,43\<CR>")
683  call TermWait(buf)
684  call VerifyScreenDump(buf, 'Test_colorcolumn_2', {})
685
686  " clean up
687  call StopVimInTerminal(buf)
688  call delete('Xtest_colorcolumn_bri')
689endfunc
690
691func Test_colorcolumn_sbr()
692  CheckScreendump
693
694  " check 'colorcolumn' when 'showbreak' is set
695  let lines =<< trim END
696	call setline(1, 'The quick brown fox jumped over the lazy dogs')
697  END
698  call writefile(lines, 'Xtest_colorcolumn_srb')
699  let buf = RunVimInTerminal('-S Xtest_colorcolumn_srb', {'rows': 10,'columns': 40})
700  call term_sendkeys(buf, ":set co=40 showbreak=+++>\\  cc=40,41,43\<CR>")
701  call TermWait(buf)
702  call VerifyScreenDump(buf, 'Test_colorcolumn_3', {})
703
704  " clean up
705  call StopVimInTerminal(buf)
706  call delete('Xtest_colorcolumn_srb')
707endfunc
708
709" This test must come before the Test_cursorline test, as it appears this
710" defines the Normal highlighting group anyway.
711func Test_1_highlight_Normalgroup_exists()
712  let hlNormal = HighlightArgs('Normal')
713  if !has('gui_running')
714    call assert_match('hi Normal\s*clear', hlNormal)
715  elseif has('gui_gtk2') || has('gui_gnome') || has('gui_gtk3')
716    " expect is DEFAULT_FONT of gui_gtk_x11.c
717    call assert_match('hi Normal\s*font=Monospace 10', hlNormal)
718  elseif has('gui_motif') || has('gui_athena')
719    " expect is DEFAULT_FONT of gui_x11.c
720    call assert_match('hi Normal\s*font=7x13', hlNormal)
721  elseif has('win32')
722    " expect any font
723    call assert_match('hi Normal\s*font=.*', hlNormal)
724  endif
725endfunc
726
727" Do this test last, sometimes restoring the columns doesn't work
728func Test_z_no_space_before_xxx()
729  let l:org_columns = &columns
730  set columns=17
731  let l:hi_StatusLineTermNC = join(split(execute('hi StatusLineTermNC')))
732  call assert_match('StatusLineTermNC xxx', l:hi_StatusLineTermNC)
733  let &columns = l:org_columns
734endfunc
735
736" Test for :highlight command errors
737func Test_highlight_cmd_errors()
738  if has('gui_running')
739    " This test doesn't fail in the MS-Windows console version.
740    call assert_fails('hi Xcomment ctermbg=fg', 'E419:')
741    call assert_fails('hi Xcomment ctermfg=bg', 'E420:')
742    call assert_fails('hi Xcomment ctermfg=ul', 'E453:')
743  endif
744
745  " Try using a very long terminal code. Define a dummy terminal code for this
746  " test.
747  let &t_fo = "\<Esc>1;"
748  let c = repeat("t_fo,", 100) . "t_fo"
749  call assert_fails('exe "hi Xgroup1 start=" . c', 'E422:')
750  let &t_fo = ""
751endfunc
752
753" Test for 'highlight' option
754func Test_highlight_opt()
755  let save_hl = &highlight
756  call assert_fails('set highlight=j:b', 'E474:')
757  set highlight=f\ r
758  call assert_equal('f r', &highlight)
759  set highlight=fb
760  call assert_equal('fb', &highlight)
761  set highlight=fi
762  call assert_equal('fi', &highlight)
763  set highlight=f-
764  call assert_equal('f-', &highlight)
765  set highlight=fr
766  call assert_equal('fr', &highlight)
767  set highlight=fs
768  call assert_equal('fs', &highlight)
769  set highlight=fu
770  call assert_equal('fu', &highlight)
771  set highlight=fc
772  call assert_equal('fc', &highlight)
773  set highlight=ft
774  call assert_equal('ft', &highlight)
775  call assert_fails('set highlight=fr:Search', 'E474:')
776  set highlight=f:$#
777  call assert_match('W18:', v:statusmsg)
778  let &highlight = save_hl
779endfunc
780
781" Test for User group highlighting used in the statusline
782func Test_highlight_User()
783  CheckNotGui
784  hi User1 ctermfg=12
785  redraw!
786  call assert_equal('12', synIDattr(synIDtrans(hlID('User1')), 'fg'))
787  hi clear
788endfunc
789
790" Test for using RGB color values in a highlight group
791func Test_xxlast_highlight_RGB_color()
792  CheckCanRunGui
793  gui -f
794  hi MySearch guifg=#110000 guibg=#001100 guisp=#000011
795  call assert_equal('#110000', synIDattr(synIDtrans(hlID('MySearch')), 'fg#'))
796  call assert_equal('#001100', synIDattr(synIDtrans(hlID('MySearch')), 'bg#'))
797  call assert_equal('#000011', synIDattr(synIDtrans(hlID('MySearch')), 'sp#'))
798  hi clear
799endfunc
800
801" Test for using default highlighting group
802func Test_highlight_default()
803  highlight MySearch ctermfg=7
804  highlight default MySearch ctermfg=5
805  let hlSearch = HighlightArgs('MySearch')
806  call assert_match('ctermfg=7', hlSearch)
807
808  highlight default QFName ctermfg=3
809  call assert_match('ctermfg=3', HighlightArgs('QFName'))
810  hi clear
811endfunc
812
813" Test for 'ctermul in a highlight group
814func Test_highlight_ctermul()
815  CheckNotGui
816  call assert_notmatch('ctermul=', HighlightArgs('Normal'))
817  highlight Normal ctermul=3
818  call assert_match('ctermul=3', HighlightArgs('Normal'))
819  call assert_equal('3', synIDattr(synIDtrans(hlID('Normal')), 'ul'))
820  highlight Normal ctermul=NONE
821endfunc
822
823" Test for specifying 'start' and 'stop' in a highlight group
824func Test_highlight_start_stop()
825  hi HlGrp1 start=<Esc>[27h;<Esc>[<Space>r;
826  call assert_match("start=^[[27h;^[[ r;", HighlightArgs('HlGrp1'))
827  hi HlGrp1 start=NONE
828  call assert_notmatch("start=", HighlightArgs('HlGrp1'))
829  hi HlGrp2 stop=<Esc>[27h;<Esc>[<Space>r;
830  call assert_match("stop=^[[27h;^[[ r;", HighlightArgs('HlGrp2'))
831  hi HlGrp2 stop=NONE
832  call assert_notmatch("stop=", HighlightArgs('HlGrp2'))
833  hi clear
834endfunc
835
836" Test for setting various 'term' attributes
837func Test_highlight_term_attr()
838  hi HlGrp3 term=bold,underline,undercurl,strikethrough,reverse,italic,standout
839  call assert_equal('hi HlGrp3          term=bold,standout,underline,undercurl,italic,reverse,strikethrough', HighlightArgs('HlGrp3'))
840  hi HlGrp3 term=NONE
841  call assert_equal('hi HlGrp3          cleared', HighlightArgs('HlGrp3'))
842  hi clear
843endfunc
844
845func Test_highlight_clear_restores_links()
846  let aaa_id = hlID('aaa')
847  call assert_equal(aaa_id, 0)
848
849  " create default link aaa --> bbb
850  hi def link aaa bbb
851  let id_aaa = hlID('aaa')
852  let hl_aaa_bbb = HighlightArgs('aaa')
853
854  " try to redefine default link aaa --> ccc; check aaa --> bbb
855  hi def link aaa ccc
856  call assert_equal(HighlightArgs('aaa'), hl_aaa_bbb)
857
858  " clear aaa; check aaa --> bbb
859  hi clear aaa
860  call assert_equal(HighlightArgs('aaa'), hl_aaa_bbb)
861
862  " link aaa --> ccc; clear aaa; check aaa --> bbb
863  hi link aaa ccc
864  let id_ccc = hlID('ccc')
865  call assert_equal(synIDtrans(id_aaa), id_ccc)
866  hi clear aaa
867  call assert_equal(HighlightArgs('aaa'), hl_aaa_bbb)
868
869  " forcibly set default link aaa --> ddd
870  hi! def link aaa ddd
871  let id_ddd = hlID('ddd')
872  let hl_aaa_ddd = HighlightArgs('aaa')
873  call assert_equal(synIDtrans(id_aaa), id_ddd)
874
875  " link aaa --> eee; clear aaa; check aaa --> ddd
876  hi link aaa eee
877  let eee_id = hlID('eee')
878  call assert_equal(synIDtrans(id_aaa), eee_id)
879  hi clear aaa
880  call assert_equal(HighlightArgs('aaa'), hl_aaa_ddd)
881endfunc
882
883func Test_highlight_clear_restores_context()
884  func FuncContextDefault()
885    hi def link Context ContextDefault
886  endfun
887
888  func FuncContextRelink()
889    " Dummy line
890    hi link Context ContextRelink
891  endfunc
892
893  let scriptContextDefault = MakeScript("FuncContextDefault")
894  let scriptContextRelink = MakeScript("FuncContextRelink")
895  let patContextDefault = fnamemodify(scriptContextDefault, ':t') .. ' line 1'
896  let patContextRelink = fnamemodify(scriptContextRelink, ':t') .. ' line 2'
897
898  exec 'source ' .. scriptContextDefault
899  let hlContextDefault = execute("verbose hi Context")
900  call assert_match(patContextDefault, hlContextDefault)
901
902  exec 'source ' .. scriptContextRelink
903  let hlContextRelink = execute("verbose hi Context")
904  call assert_match(patContextRelink, hlContextRelink)
905
906  hi clear
907  let hlContextAfterClear = execute("verbose hi Context")
908  call assert_match(patContextDefault, hlContextAfterClear)
909
910  delfunc FuncContextDefault
911  delfunc FuncContextRelink
912  call delete(scriptContextDefault)
913  call delete(scriptContextRelink)
914endfunc
915
916func Test_highlight_default_colorscheme_restores_links()
917  hi link TestLink Identifier
918  hi TestHi ctermbg=red
919
920  let hlTestLinkPre = HighlightArgs('TestLink')
921  let hlTestHiPre = HighlightArgs('TestHi')
922
923  " Test colorscheme
924  hi clear
925  if exists('syntax_on')
926    syntax reset
927  endif
928  let g:colors_name = 'test'
929  hi link TestLink ErrorMsg
930  hi TestHi ctermbg=green
931
932  " Restore default highlighting
933  colorscheme default
934  " 'default' should work no matter if highlight group was cleared
935  hi def link TestLink Identifier
936  hi def TestHi ctermbg=red
937  let hlTestLinkPost = HighlightArgs('TestLink')
938  let hlTestHiPost = HighlightArgs('TestHi')
939  call assert_equal(hlTestLinkPre, hlTestLinkPost)
940  call assert_equal(hlTestHiPre, hlTestHiPost)
941  hi clear
942endfunc
943
944func Test_colornames_assignment_and_lookup()
945  CheckAnyOf Feature:gui_running Feature:termguicolors
946
947  " Ensure highlight command can find custom color.
948  let v:colornames['a redish white'] = '#ffeedd'
949  highlight Normal guifg='a redish white'
950  highlight clear
951  call ClearDict(v:colornames)
952endfunc
953
954func Test_colornames_default_list()
955  CheckAnyOf Feature:gui_running Feature:termguicolors
956
957  " Ensure default lists are loaded automatically and can be used for all gui fields.
958  call assert_equal(0, len(v:colornames))
959  highlight Normal guifg='rebecca purple' guibg='rebecca purple' guisp='rebecca purple'
960  call assert_notequal(0, len(v:colornames))
961  echo v:colornames['rebecca purple']
962  highlight clear
963  call ClearDict(v:colornames)
964endfunc
965
966func Test_colornames_overwrite_default()
967  CheckAnyOf Feature:gui_running Feature:termguicolors
968
969  " Ensure entries in v:colornames can be overwritten.
970  " Load default color scheme to trigger default color list loading.
971  colorscheme default
972  let old_rebecca_purple = v:colornames['rebecca purple']
973  highlight Normal guifg='rebecca purple' guibg='rebecca purple'
974  let v:colornames['rebecca purple'] = '#550099'
975  highlight Normal guifg='rebecca purple' guibg='rebecca purple'
976  let v:colornames['rebecca purple'] = old_rebecca_purple
977  highlight clear
978endfunc
979
980func Test_colornames_assignment_and_unassignment()
981  " No feature check is needed for this test because the v:colornames dict
982  " always exists with +eval. The feature checks are only required for
983  " commands that do color lookup.
984
985  " Ensure we cannot overwrite the v:colornames dict.
986  call assert_fails("let v:colornames = {}", 'E46:')
987
988  " Ensure we can delete entries from the v:colornames dict.
989  let v:colornames['x1'] = '#111111'
990  call assert_equal(v:colornames['x1'], '#111111')
991  unlet v:colornames['x1']
992  call assert_fails("echo v:colornames['x1']")
993endfunc
994
995" Test for the hlget() function
996func Test_hlget()
997  let lines =<< trim END
998    call assert_notequal([], filter(hlget(), 'v:val.name == "Visual"'))
999    call assert_equal([], hlget('SomeHLGroup'))
1000    highlight MyHLGroup term=standout cterm=reverse ctermfg=10 ctermbg=Black
1001    call assert_equal([{'id': hlID('MyHLGroup'), 'ctermfg': '10', 'name': 'MyHLGroup', 'term': {'standout': v:true}, 'ctermbg': '0', 'cterm': {'reverse': v:true}}], hlget('MyHLGroup'))
1002    highlight clear MyHLGroup
1003    call assert_equal(v:true, hlget('MyHLGroup')[0].cleared)
1004    highlight link MyHLGroup IncSearch
1005    call assert_equal('IncSearch', hlget('MyHLGroup')[0].linksto)
1006    highlight clear MyHLGroup
1007    call assert_equal([], hlget(test_null_string()))
1008    call assert_equal([], hlget(""))
1009  END
1010  call CheckLegacyAndVim9Success(lines)
1011
1012  " Test for resolving highlight group links
1013  let lines =<< trim END
1014    highlight hlgA term=bold
1015    VAR hlgAid = hlID('hlgA')
1016    highlight link hlgB hlgA
1017    VAR hlgBid = hlID('hlgB')
1018    highlight link hlgC hlgB
1019    VAR hlgCid = hlID('hlgC')
1020    call assert_equal('hlgA', hlget('hlgB')[0].linksto)
1021    call assert_equal('hlgB', hlget('hlgC')[0].linksto)
1022    call assert_equal([{'id': hlgAid, 'name': 'hlgA',
1023                      \ 'term': {'bold': v:true}}], hlget('hlgA'))
1024    call assert_equal([{'id': hlgBid, 'name': 'hlgB',
1025                      \ 'linksto': 'hlgA'}], hlget('hlgB'))
1026    call assert_equal([{'id': hlgCid, 'name': 'hlgC',
1027                      \ 'linksto': 'hlgB'}], hlget('hlgC'))
1028    call assert_equal([{'id': hlgAid, 'name': 'hlgA',
1029                      \ 'term': {'bold': v:true}}], hlget('hlgA', v:false))
1030    call assert_equal([{'id': hlgBid, 'name': 'hlgB',
1031                      \ 'linksto': 'hlgA'}], hlget('hlgB', 0))
1032    call assert_equal([{'id': hlgCid, 'name': 'hlgC',
1033                      \ 'linksto': 'hlgB'}], hlget('hlgC', v:false))
1034    call assert_equal([{'id': hlgAid, 'name': 'hlgA',
1035                      \ 'term': {'bold': v:true}}], hlget('hlgA', v:true))
1036    call assert_equal([{'id': hlgBid, 'name': 'hlgB',
1037                      \ 'term': {'bold': v:true}}], hlget('hlgB', 1))
1038    call assert_equal([{'id': hlgCid, 'name': 'hlgC',
1039                      \ 'term': {'bold': v:true}}], hlget('hlgC', v:true))
1040  END
1041  call CheckLegacyAndVim9Success(lines)
1042
1043  call assert_fails('call hlget([])', 'E1174:')
1044  call assert_fails('call hlget("abc", "xyz")', 'E1212:')
1045endfunc
1046
1047" Test for the hlset() function
1048func Test_hlset()
1049  let lines =<< trim END
1050    call assert_equal(0, hlset(test_null_list()))
1051    call assert_equal(0, hlset([]))
1052    call assert_fails('call hlset(["Search"])', 'E715:')
1053    call hlset(hlget())
1054    call hlset([{'name': 'NewHLGroup', 'cterm': {'reverse': v:true}, 'ctermfg': '10'}])
1055    call assert_equal({'reverse': v:true}, hlget('NewHLGroup')[0].cterm)
1056    call hlset([{'name': 'NewHLGroup', 'cterm': {'bold': v:true}}])
1057    call assert_equal({'bold': v:true}, hlget('NewHLGroup')[0].cterm)
1058    call hlset([{'name': 'NewHLGroup', 'cleared': v:true}])
1059    call assert_equal(v:true, hlget('NewHLGroup')[0].cleared)
1060    call hlset([{'name': 'NewHLGroup', 'linksto': 'Search'}])
1061    call assert_false(has_key(hlget('NewHLGroup')[0], 'cleared'))
1062    call assert_equal('Search', hlget('NewHLGroup')[0].linksto)
1063    call assert_fails("call hlset([{'name': [], 'ctermfg': '10'}])", 'E928:')
1064    call assert_fails("call hlset([{'name': 'NewHLGroup', 'cleared': []}])",
1065          \ 'E745:')
1066    call assert_fails("call hlset([{'name': 'NewHLGroup', 'cterm': 'Blue'}])",
1067          \ 'E715:')
1068    call assert_fails("call hlset([{'name': 'NewHLGroup', 'ctermbg': []}])",
1069          \ 'E928:')
1070    call assert_fails("call hlset([{'name': 'NewHLGroup', 'ctermfg': []}])",
1071          \ 'E928:')
1072    call assert_fails("call hlset([{'name': 'NewHLGroup', 'ctermul': []}])",
1073          \ 'E928:')
1074    if has('gui')
1075      call assert_fails("call hlset([{'name': 'NewHLGroup', 'font': []}])",
1076            \ 'E928:')
1077    endif
1078    call assert_fails("call hlset([{'name': 'NewHLGroup', 'gui': 'Cyan'}])",
1079          \ 'E715:')
1080    call assert_fails("call hlset([{'name': 'NewHLGroup', 'guibg': []}])",
1081          \ 'E928:')
1082    call assert_fails("call hlset([{'name': 'NewHLGroup', 'guifg': []}])",
1083          \ 'E928:')
1084    call assert_fails("call hlset([{'name': 'NewHLGroup', 'guisp': []}])",
1085          \ 'E928:')
1086    call assert_fails("call hlset([{'name': 'NewHLGroup', 'linksto': []}])",
1087          \ 'E928:')
1088    call assert_fails("call hlset([{'name': 'NewHLGroup', 'start': []}])",
1089          \ 'E928:')
1090    call assert_fails("call hlset([{'name': 'NewHLGroup', 'stop': []}])",
1091          \ 'E928:')
1092    call assert_fails("call hlset([{'name': 'NewHLGroup', 'term': 'Cyan'}])",
1093          \ 'E715:')
1094    call assert_equal('Search', hlget('NewHLGroup')[0].linksto)
1095    highlight clear NewHLGroup
1096  END
1097  call CheckLegacyAndVim9Success(lines)
1098
1099  " Test for clearing the 'term', 'cterm' and 'gui' attributes of a highlight
1100  " group.
1101  let lines =<< trim END
1102    highlight myhlg1 term=bold cterm=italic gui=standout
1103    VAR id = hlID('myhlg1')
1104    call hlset([{'name': 'myhlg1', 'term': {}}])
1105    call assert_equal([{'id': id, 'name': 'myhlg1',
1106                \ 'cterm': {'italic': v:true}, 'gui': {'standout': v:true}}],
1107                \ hlget('myhlg1'))
1108    call hlset([{'name': 'myhlg1', 'cterm': {}}])
1109    call assert_equal([{'id': id, 'name': 'myhlg1',
1110                \ 'gui': {'standout': v:true}}], hlget('myhlg1'))
1111    call hlset([{'name': 'myhlg1', 'gui': {}}])
1112    call assert_equal([{'id': id, 'name': 'myhlg1', 'cleared': v:true}],
1113                \ hlget('myhlg1'))
1114    highlight clear myhlg1
1115  END
1116  call CheckLegacyAndVim9Success(lines)
1117
1118  " Test for setting all the 'term', 'cterm' and 'gui' attributes of a
1119  " highlight group
1120  let lines =<< trim END
1121    VAR attr = {'bold': v:true, 'underline': v:true, 'undercurl': v:true,
1122                \ 'strikethrough': v:true, 'reverse': v:true, 'italic': v:true,
1123                \ 'standout': v:true, 'nocombine': v:true}
1124    call hlset([{'name': 'myhlg2', 'term': attr, 'cterm': attr, 'gui': attr}])
1125    VAR id2 = hlID('myhlg2')
1126    VAR expected = "myhlg2 xxx term=bold,standout,underline,undercurl,italic,reverse,nocombine,strikethrough cterm=bold,standout,underline,undercurl,italic,reverse,nocombine,strikethrough gui=bold,standout,underline,undercurl,italic,reverse,nocombine,strikethrough"
1127    VAR output = execute('highlight myhlg2')
1128    LET output = output->split("\n")->join()->substitute('\s\+', ' ', 'g')
1129    call assert_equal(expected, output)
1130    call assert_equal([{'id': id2, 'name': 'myhlg2', 'gui': attr,
1131                      \ 'term': attr, 'cterm': attr}], hlget('myhlg2'))
1132  END
1133  call CheckLegacyAndVim9Success(lines)
1134
1135  " Test for clearing some of the 'term', 'cterm' and 'gui' attributes of a
1136  " highlight group
1137  let lines =<< trim END
1138    VAR attr = {'bold': v:false, 'underline': v:true, 'strikethrough': v:true}
1139    call hlset([{'name': 'myhlg2', 'term': attr, 'cterm': attr, 'gui': attr}])
1140    VAR id2 = hlID('myhlg2')
1141    VAR expected = "myhlg2 xxx term=underline,strikethrough cterm=underline,strikethrough gui=underline,strikethrough"
1142    VAR output = execute('highlight myhlg2')
1143    LET output = output->split("\n")->join()->substitute('\s\+', ' ', 'g')
1144    call assert_equal(expected, output)
1145    LET attr = {'underline': v:true, 'strikethrough': v:true}
1146    call assert_equal([{'id': id2, 'name': 'myhlg2', 'gui': attr,
1147                      \ 'term': attr, 'cterm': attr}], hlget('myhlg2'))
1148  END
1149  call CheckLegacyAndVim9Success(lines)
1150
1151  " Test for clearing the attributes and link of a highlight group
1152  let lines =<< trim END
1153    highlight myhlg3 ctermbg=green guibg=green
1154    highlight! default link myhlg3 ErrorMsg
1155    VAR id3 = hlID('myhlg3')
1156    call hlset([{'name': 'myhlg3', 'cleared': v:true, 'linksto': 'NONE'}])
1157    call assert_equal([{'id': id3, 'name': 'myhlg3', 'cleared': v:true}],
1158                      \ hlget('myhlg3'))
1159    highlight clear hlg3
1160  END
1161  call CheckLegacyAndVim9Success(lines)
1162
1163  " Test for setting default attributes for a highlight group
1164  let lines =<< trim END
1165    call hlset([{'name': 'hlg4', 'ctermfg': '8'}])
1166    call hlset([{'name': 'hlg4', 'default': v:true, 'ctermfg': '9'}])
1167    VAR id4 = hlID('hlg4')
1168    call assert_equal([{'id': id4, 'name': 'hlg4', 'ctermfg': '8'}],
1169                    \ hlget('hlg4'))
1170    highlight clear hlg4
1171
1172    call hlset([{'name': 'hlg5', 'default': v:true, 'ctermbg': '2'}])
1173    call hlset([{'name': 'hlg5', 'ctermbg': '4'}])
1174    VAR id5 = hlID('hlg5')
1175    call assert_equal([{'id': id5, 'name': 'hlg5', 'ctermbg': '4'}],
1176                    \ hlget('hlg5'))
1177    highlight clear hlg5
1178
1179    call hlset([{'name': 'hlg6', 'linksto': 'Error'}])
1180    VAR id6 = hlID('hlg6')
1181    call hlset([{'name': 'hlg6', 'default': v:true, 'ctermbg': '2'}])
1182    call assert_equal([{'id': id6, 'name': 'hlg6', 'linksto': 'Error'}],
1183                    \ hlget('hlg6'))
1184    highlight clear hlg6
1185  END
1186  call CheckLegacyAndVim9Success(lines)
1187
1188  " Test for setting default links for a highlight group
1189  let lines =<< trim END
1190    call hlset([{'name': 'hlg7', 'ctermfg': '5'}])
1191    call hlset([{'name': 'hlg7', 'default': v:true, 'linksto': 'Search'}])
1192    VAR id7 = hlID('hlg7')
1193    call assert_equal([{'id': id7, 'name': 'hlg7', 'ctermfg': '5'}],
1194                    \ hlget('hlg7'))
1195    highlight clear hlg7
1196
1197    call hlset([{'name': 'hlg8', 'default': v:true, 'linksto': 'Search'}])
1198    VAR id8 = hlID('hlg8')
1199    call assert_equal([{'id': id8, 'name': 'hlg8', 'default': v:true,
1200                    \ 'linksto': 'Search'}], hlget('hlg8'))
1201    call hlset([{'name': 'hlg8', 'ctermbg': '2'}])
1202    call assert_equal([{'id': id8, 'name': 'hlg8', 'ctermbg': '2'}],
1203                    \ hlget('hlg8'))
1204    highlight clear hlg8
1205
1206    highlight default link hlg9 ErrorMsg
1207    VAR hlg_save = hlget('hlg9')
1208    LET hlg_save[0]['name'] = 'hlg9dup'
1209    call hlset(hlg_save)
1210    VAR id9 = hlID('hlg9dup')
1211    highlight clear hlg9dup
1212    call assert_equal([{'id': id9, 'name': 'hlg9dup', 'default': v:true,
1213                    \ 'linksto': 'ErrorMsg'}], hlget('hlg9dup'))
1214    highlight clear hlg9
1215  END
1216  call CheckLegacyAndVim9Success(lines)
1217
1218  " Test for force creating a link to a highlight group
1219  let lines =<< trim END
1220    call hlset([{'name': 'hlg10', 'ctermfg': '8'}])
1221    call hlset([{'name': 'hlg10', 'linksto': 'Search'}])
1222    VAR id10 = hlID('hlg10')
1223    call assert_equal([{'id': id10, 'name': 'hlg10', 'ctermfg': '8'}],
1224                    \ hlget('hlg10'))
1225    call hlset([{'name': 'hlg10', 'linksto': 'Search', 'force': v:true}])
1226    call assert_equal([{'id': id10, 'name': 'hlg10', 'ctermfg': '8',
1227                    \ 'linksto': 'Search'}], hlget('hlg10'))
1228    highlight clear hlg10
1229  END
1230  call CheckLegacyAndVim9Success(lines)
1231endfunc
1232
1233" vim: shiftwidth=2 sts=2 expandtab
1234