blob: b831878b40c5fac84a017374563e46d65027ccf7 [file] [log] [blame]
Bram Moolenaar0aa398f2017-09-30 21:23:55 +02001" Tests for ":highlight" and highlighting.
2
3source view_util.vim
Bram Moolenaarc07ff5c2019-01-30 21:41:14 +01004source screendump.vim
Bram Moolenaar8c5a2782019-08-07 23:07:07 +02005source check.vim
Bram Moolenaare8df0102020-09-18 19:40:45 +02006source script_util.vim
Bram Moolenaar62aec932022-01-29 21:45:34 +00007import './vim9.vim' as v9
Bram Moolenaar0aa398f2017-09-30 21:23:55 +02008
Drew Vogela0fca172021-11-13 10:50:01 +00009func ClearDict(d)
10 for k in keys(a:d)
11 call remove(a:d, k)
12 endfor
13endfunc
14
Bram Moolenaar75373f32017-08-07 22:02:30 +020015func 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:")
Bram Moolenaar5b9f5722023-02-19 20:49:38 +000049
50 if has('gui_running')
51 call assert_fails('hi NotUsed guibg=none', 'E1361:')
52 endif
Bram Moolenaar75373f32017-08-07 22:02:30 +020053endfunc
Bram Moolenaar0aa398f2017-09-30 21:23:55 +020054
Bram Moolenaar1e115362019-01-09 23:01:02 +010055func HighlightArgs(name)
Bram Moolenaar0aa398f2017-09-30 21:23:55 +020056 return 'hi ' . substitute(split(execute('hi ' . a:name), '\n')[0], '\<xxx\>', '', '')
Bram Moolenaar1e115362019-01-09 23:01:02 +010057endfunc
Bram Moolenaar0aa398f2017-09-30 21:23:55 +020058
Bram Moolenaar1e115362019-01-09 23:01:02 +010059func IsColorable()
Bram Moolenaar0aa398f2017-09-30 21:23:55 +020060 return has('gui_running') || str2nr(&t_Co) >= 8
Bram Moolenaar1e115362019-01-09 23:01:02 +010061endfunc
Bram Moolenaar0aa398f2017-09-30 21:23:55 +020062
Bram Moolenaar1e115362019-01-09 23:01:02 +010063func HiCursorLine()
Bram Moolenaar0aa398f2017-09-30 21:23:55 +020064 let hiCursorLine = HighlightArgs('CursorLine')
65 if has('gui_running')
66 let guibg = matchstr(hiCursorLine, 'guibg=\w\+')
67 let hi_ul = 'hi CursorLine gui=underline guibg=NONE'
68 let hi_bg = 'hi CursorLine gui=NONE ' . guibg
69 else
70 let hi_ul = 'hi CursorLine cterm=underline ctermbg=NONE'
71 let hi_bg = 'hi CursorLine cterm=NONE ctermbg=Gray'
72 endif
73 return [hiCursorLine, hi_ul, hi_bg]
Bram Moolenaar1e115362019-01-09 23:01:02 +010074endfunc
Bram Moolenaar0aa398f2017-09-30 21:23:55 +020075
Bram Moolenaar1e115362019-01-09 23:01:02 +010076func Check_lcs_eol_attrs(attrs, row, col)
Bram Moolenaar5ece3e32017-10-01 14:35:02 +020077 let save_lcs = &lcs
78 set list
79
80 call assert_equal(a:attrs, ScreenAttrs(a:row, a:col)[0])
81
82 set nolist
83 let &lcs = save_lcs
Bram Moolenaar1e115362019-01-09 23:01:02 +010084endfunc
Bram Moolenaar5ece3e32017-10-01 14:35:02 +020085
Bram Moolenaar0aa398f2017-09-30 21:23:55 +020086func Test_highlight_eol_with_cursorline()
87 let [hiCursorLine, hi_ul, hi_bg] = HiCursorLine()
88
89 call NewWindow('topleft 5', 20)
90 call setline(1, 'abcd')
91 call matchadd('Search', '\n')
92
93 " expected:
94 " 'abcd '
95 " ^^^^ ^^^^^ no highlight
96 " ^ 'Search' highlight
97 let attrs0 = ScreenAttrs(1, 10)[0]
98 call assert_equal(repeat([attrs0[0]], 4), attrs0[0:3])
99 call assert_equal(repeat([attrs0[0]], 5), attrs0[5:9])
100 call assert_notequal(attrs0[0], attrs0[4])
101
102 setlocal cursorline
103
104 " underline
105 exe hi_ul
106
107 " expected:
108 " 'abcd '
109 " ^^^^ underline
Bram Moolenaar5ece3e32017-10-01 14:35:02 +0200110 " ^ 'Search' highlight with underline
111 " ^^^^^ underline
Bram Moolenaar0aa398f2017-09-30 21:23:55 +0200112 let attrs = ScreenAttrs(1, 10)[0]
113 call assert_equal(repeat([attrs[0]], 4), attrs[0:3])
114 call assert_equal([attrs[4]] + repeat([attrs[5]], 5), attrs[4:9])
115 call assert_notequal(attrs[0], attrs[4])
116 call assert_notequal(attrs[4], attrs[5])
117 call assert_notequal(attrs0[0], attrs[0])
118 call assert_notequal(attrs0[4], attrs[4])
Bram Moolenaar5ece3e32017-10-01 14:35:02 +0200119 call Check_lcs_eol_attrs(attrs, 1, 10)
Bram Moolenaar0aa398f2017-09-30 21:23:55 +0200120
121 if IsColorable()
122 " bg-color
123 exe hi_bg
124
125 " expected:
126 " 'abcd '
127 " ^^^^ bg-color of 'CursorLine'
128 " ^ 'Search' highlight
129 " ^^^^^ bg-color of 'CursorLine'
130 let attrs = ScreenAttrs(1, 10)[0]
131 call assert_equal(repeat([attrs[0]], 4), attrs[0:3])
132 call assert_equal(repeat([attrs[5]], 5), attrs[5:9])
133 call assert_equal(attrs0[4], attrs[4])
134 call assert_notequal(attrs[0], attrs[4])
135 call assert_notequal(attrs[4], attrs[5])
136 call assert_notequal(attrs0[0], attrs[0])
137 call assert_notequal(attrs0[5], attrs[5])
Bram Moolenaar5ece3e32017-10-01 14:35:02 +0200138 call Check_lcs_eol_attrs(attrs, 1, 10)
Bram Moolenaar0aa398f2017-09-30 21:23:55 +0200139 endif
140
141 call CloseWindow()
142 exe hiCursorLine
143endfunc
144
145func Test_highlight_eol_with_cursorline_vertsplit()
Bram Moolenaar0aa398f2017-09-30 21:23:55 +0200146 let [hiCursorLine, hi_ul, hi_bg] = HiCursorLine()
147
148 call NewWindow('topleft 5', 5)
149 call setline(1, 'abcd')
150 call matchadd('Search', '\n')
151
152 let expected = "abcd |abcd "
153 let actual = ScreenLines(1, 15)[0]
154 call assert_equal(expected, actual)
155
156 " expected:
157 " 'abcd |abcd '
158 " ^^^^ ^^^^^^^^^ no highlight
159 " ^ 'Search' highlight
160 " ^ 'VertSplit' highlight
161 let attrs0 = ScreenAttrs(1, 15)[0]
162 call assert_equal(repeat([attrs0[0]], 4), attrs0[0:3])
163 call assert_equal(repeat([attrs0[0]], 9), attrs0[6:14])
164 call assert_notequal(attrs0[0], attrs0[4])
165 call assert_notequal(attrs0[0], attrs0[5])
166 call assert_notequal(attrs0[4], attrs0[5])
167
168 setlocal cursorline
169
170 " expected:
171 " 'abcd |abcd '
172 " ^^^^ underline
173 " ^ 'Search' highlight with underline
174 " ^ 'VertSplit' highlight
175 " ^^^^^^^^^ no highlight
176
177 " underline
178 exe hi_ul
179
180 let actual = ScreenLines(1, 15)[0]
181 call assert_equal(expected, actual)
182
183 let attrs = ScreenAttrs(1, 15)[0]
184 call assert_equal(repeat([attrs[0]], 4), attrs[0:3])
185 call assert_equal(repeat([attrs[6]], 9), attrs[6:14])
186 call assert_equal(attrs0[5:14], attrs[5:14])
187 call assert_notequal(attrs[0], attrs[4])
188 call assert_notequal(attrs[0], attrs[5])
189 call assert_notequal(attrs[0], attrs[6])
190 call assert_notequal(attrs[4], attrs[5])
191 call assert_notequal(attrs[5], attrs[6])
192 call assert_notequal(attrs0[0], attrs[0])
193 call assert_notequal(attrs0[4], attrs[4])
Bram Moolenaar5ece3e32017-10-01 14:35:02 +0200194 call Check_lcs_eol_attrs(attrs, 1, 15)
Bram Moolenaar0aa398f2017-09-30 21:23:55 +0200195
196 if IsColorable()
197 " bg-color
198 exe hi_bg
199
200 let actual = ScreenLines(1, 15)[0]
201 call assert_equal(expected, actual)
202
203 let attrs = ScreenAttrs(1, 15)[0]
204 call assert_equal(repeat([attrs[0]], 4), attrs[0:3])
205 call assert_equal(repeat([attrs[6]], 9), attrs[6:14])
206 call assert_equal(attrs0[5:14], attrs[5:14])
207 call assert_notequal(attrs[0], attrs[4])
208 call assert_notequal(attrs[0], attrs[5])
209 call assert_notequal(attrs[0], attrs[6])
210 call assert_notequal(attrs[4], attrs[5])
211 call assert_notequal(attrs[5], attrs[6])
212 call assert_notequal(attrs0[0], attrs[0])
213 call assert_equal(attrs0[4], attrs[4])
Bram Moolenaar5ece3e32017-10-01 14:35:02 +0200214 call Check_lcs_eol_attrs(attrs, 1, 15)
Bram Moolenaar0aa398f2017-09-30 21:23:55 +0200215 endif
216
217 call CloseWindow()
218 exe hiCursorLine
219endfunc
220
221func Test_highlight_eol_with_cursorline_rightleft()
Bram Moolenaar6d91bcb2020-08-12 18:50:36 +0200222 CheckFeature rightleft
Bram Moolenaar0aa398f2017-09-30 21:23:55 +0200223
224 let [hiCursorLine, hi_ul, hi_bg] = HiCursorLine()
225
226 call NewWindow('topleft 5', 10)
227 setlocal rightleft
228 call setline(1, 'abcd')
229 call matchadd('Search', '\n')
230 let attrs0 = ScreenAttrs(1, 10)[0]
231
232 setlocal cursorline
233
234 " underline
235 exe hi_ul
236
237 " expected:
238 " ' dcba'
239 " ^^^^ underline
240 " ^ 'Search' highlight with underline
241 " ^^^^^ underline
242 let attrs = ScreenAttrs(1, 10)[0]
243 call assert_equal(repeat([attrs[9]], 4), attrs[6:9])
244 call assert_equal(repeat([attrs[4]], 5) + [attrs[5]], attrs[0:5])
245 call assert_notequal(attrs[9], attrs[5])
246 call assert_notequal(attrs[4], attrs[5])
247 call assert_notequal(attrs0[9], attrs[9])
248 call assert_notequal(attrs0[5], attrs[5])
Bram Moolenaar5ece3e32017-10-01 14:35:02 +0200249 call Check_lcs_eol_attrs(attrs, 1, 10)
Bram Moolenaar0aa398f2017-09-30 21:23:55 +0200250
251 if IsColorable()
252 " bg-color
253 exe hi_bg
254
255 " expected:
256 " ' dcba'
257 " ^^^^ bg-color of 'CursorLine'
258 " ^ 'Search' highlight
259 " ^^^^^ bg-color of 'CursorLine'
260 let attrs = ScreenAttrs(1, 10)[0]
261 call assert_equal(repeat([attrs[9]], 4), attrs[6:9])
262 call assert_equal(repeat([attrs[4]], 5), attrs[0:4])
263 call assert_equal(attrs0[5], attrs[5])
264 call assert_notequal(attrs[9], attrs[5])
265 call assert_notequal(attrs[5], attrs[4])
266 call assert_notequal(attrs0[9], attrs[9])
267 call assert_notequal(attrs0[4], attrs[4])
Bram Moolenaar5ece3e32017-10-01 14:35:02 +0200268 call Check_lcs_eol_attrs(attrs, 1, 10)
Bram Moolenaar0aa398f2017-09-30 21:23:55 +0200269 endif
270
271 call CloseWindow()
272 exe hiCursorLine
273endfunc
274
275func Test_highlight_eol_with_cursorline_linewrap()
276 let [hiCursorLine, hi_ul, hi_bg] = HiCursorLine()
277
278 call NewWindow('topleft 5', 10)
279 call setline(1, [repeat('a', 51) . 'bcd', ''])
280 call matchadd('Search', '\n')
281
282 setlocal wrap
283 normal! gg$
284 let attrs0 = ScreenAttrs(5, 10)[0]
285 setlocal cursorline
286
287 " underline
288 exe hi_ul
289
290 " expected:
291 " 'abcd '
292 " ^^^^ underline
293 " ^ 'Search' highlight with underline
294 " ^^^^^ underline
295 let attrs = ScreenAttrs(5, 10)[0]
296 call assert_equal(repeat([attrs[0]], 4), attrs[0:3])
297 call assert_equal([attrs[4]] + repeat([attrs[5]], 5), attrs[4:9])
298 call assert_notequal(attrs[0], attrs[4])
299 call assert_notequal(attrs[4], attrs[5])
300 call assert_notequal(attrs0[0], attrs[0])
301 call assert_notequal(attrs0[4], attrs[4])
Bram Moolenaar5ece3e32017-10-01 14:35:02 +0200302 call Check_lcs_eol_attrs(attrs, 5, 10)
Bram Moolenaar0aa398f2017-09-30 21:23:55 +0200303
304 if IsColorable()
305 " bg-color
306 exe hi_bg
307
308 " expected:
309 " 'abcd '
310 " ^^^^ bg-color of 'CursorLine'
311 " ^ 'Search' highlight
312 " ^^^^^ bg-color of 'CursorLine'
313 let attrs = ScreenAttrs(5, 10)[0]
314 call assert_equal(repeat([attrs[0]], 4), attrs[0:3])
315 call assert_equal(repeat([attrs[5]], 5), attrs[5:9])
316 call assert_equal(attrs0[4], attrs[4])
317 call assert_notequal(attrs[0], attrs[4])
318 call assert_notequal(attrs[4], attrs[5])
319 call assert_notequal(attrs0[0], attrs[0])
320 call assert_notequal(attrs0[5], attrs[5])
Bram Moolenaar5ece3e32017-10-01 14:35:02 +0200321 call Check_lcs_eol_attrs(attrs, 5, 10)
Bram Moolenaar0aa398f2017-09-30 21:23:55 +0200322 endif
323
324 setlocal nocursorline nowrap
325 normal! gg$
326 let attrs0 = ScreenAttrs(1, 10)[0]
327 setlocal cursorline
328
329 " underline
330 exe hi_ul
331
332 " expected:
333 " 'aaabcd '
334 " ^^^^^^ underline
335 " ^ 'Search' highlight with underline
336 " ^^^ underline
337 let attrs = ScreenAttrs(1, 10)[0]
338 call assert_equal(repeat([attrs[0]], 6), attrs[0:5])
339 call assert_equal([attrs[6]] + repeat([attrs[7]], 3), attrs[6:9])
340 call assert_notequal(attrs[0], attrs[6])
341 call assert_notequal(attrs[6], attrs[7])
342 call assert_notequal(attrs0[0], attrs[0])
343 call assert_notequal(attrs0[6], attrs[6])
Bram Moolenaar5ece3e32017-10-01 14:35:02 +0200344 call Check_lcs_eol_attrs(attrs, 1, 10)
Bram Moolenaar0aa398f2017-09-30 21:23:55 +0200345
346 if IsColorable()
347 " bg-color
348 exe hi_bg
349
350 " expected:
351 " 'aaabcd '
352 " ^^^^^^ bg-color of 'CursorLine'
353 " ^ 'Search' highlight
354 " ^^^ bg-color of 'CursorLine'
355 let attrs = ScreenAttrs(1, 10)[0]
356 call assert_equal(repeat([attrs[0]], 6), attrs[0:5])
357 call assert_equal(repeat([attrs[7]], 3), attrs[7:9])
358 call assert_equal(attrs0[6], attrs[6])
359 call assert_notequal(attrs[0], attrs[6])
360 call assert_notequal(attrs[6], attrs[7])
361 call assert_notequal(attrs0[0], attrs[0])
362 call assert_notequal(attrs0[7], attrs[7])
Bram Moolenaar5ece3e32017-10-01 14:35:02 +0200363 call Check_lcs_eol_attrs(attrs, 1, 10)
Bram Moolenaar0aa398f2017-09-30 21:23:55 +0200364 endif
365
366 call CloseWindow()
367 exe hiCursorLine
368endfunc
369
370func Test_highlight_eol_with_cursorline_sign()
Bram Moolenaar6d91bcb2020-08-12 18:50:36 +0200371 CheckFeature signs
Bram Moolenaar0aa398f2017-09-30 21:23:55 +0200372
373 let [hiCursorLine, hi_ul, hi_bg] = HiCursorLine()
374
375 call NewWindow('topleft 5', 10)
376 call setline(1, 'abcd')
377 call matchadd('Search', '\n')
378
379 sign define Sign text=>>
380 exe 'sign place 1 line=1 name=Sign buffer=' . bufnr('')
381 let attrs0 = ScreenAttrs(1, 10)[0]
382 setlocal cursorline
383
384 " underline
385 exe hi_ul
386
387 " expected:
388 " '>>abcd '
389 " ^^ sign
390 " ^^^^ underline
391 " ^ 'Search' highlight with underline
392 " ^^^ underline
393 let attrs = ScreenAttrs(1, 10)[0]
394 call assert_equal(repeat([attrs[2]], 4), attrs[2:5])
395 call assert_equal([attrs[6]] + repeat([attrs[7]], 3), attrs[6:9])
396 call assert_notequal(attrs[2], attrs[6])
397 call assert_notequal(attrs[6], attrs[7])
398 call assert_notequal(attrs0[2], attrs[2])
399 call assert_notequal(attrs0[6], attrs[6])
Bram Moolenaar5ece3e32017-10-01 14:35:02 +0200400 call Check_lcs_eol_attrs(attrs, 1, 10)
Bram Moolenaar0aa398f2017-09-30 21:23:55 +0200401
402 if IsColorable()
403 " bg-color
404 exe hi_bg
405
406 " expected:
407 " '>>abcd '
408 " ^^ sign
409 " ^^^^ bg-color of 'CursorLine'
410 " ^ 'Search' highlight
411 " ^^^ bg-color of 'CursorLine'
412 let attrs = ScreenAttrs(1, 10)[0]
413 call assert_equal(repeat([attrs[2]], 4), attrs[2:5])
414 call assert_equal(repeat([attrs[7]], 3), attrs[7:9])
415 call assert_equal(attrs0[6], attrs[6])
416 call assert_notequal(attrs[2], attrs[6])
417 call assert_notequal(attrs[6], attrs[7])
418 call assert_notequal(attrs0[2], attrs[2])
419 call assert_notequal(attrs0[7], attrs[7])
Bram Moolenaar5ece3e32017-10-01 14:35:02 +0200420 call Check_lcs_eol_attrs(attrs, 1, 10)
Bram Moolenaar0aa398f2017-09-30 21:23:55 +0200421 endif
422
423 sign unplace 1
424 call CloseWindow()
425 exe hiCursorLine
426endfunc
427
428func Test_highlight_eol_with_cursorline_breakindent()
Bram Moolenaar6d91bcb2020-08-12 18:50:36 +0200429 CheckFeature linebreak
Bram Moolenaar0aa398f2017-09-30 21:23:55 +0200430
431 let [hiCursorLine, hi_ul, hi_bg] = HiCursorLine()
432
433 call NewWindow('topleft 5', 10)
Bram Moolenaaree857022019-11-09 23:26:40 +0100434 set showbreak=xxx
Bram Moolenaar0aa398f2017-09-30 21:23:55 +0200435 setlocal breakindent breakindentopt=min:0,shift:1 showbreak=>
436 call setline(1, ' ' . repeat('a', 9) . 'bcd')
437 call matchadd('Search', '\n')
438 let attrs0 = ScreenAttrs(2, 10)[0]
439 setlocal cursorline
440
441 " underline
442 exe hi_ul
443
444 " expected:
445 " ' >bcd '
446 " ^^^ breakindent and showbreak
447 " ^^^ underline
448 " ^ 'Search' highlight with underline
449 " ^^^ underline
450 let attrs = ScreenAttrs(2, 10)[0]
451 call assert_equal(repeat([attrs[0]], 2), attrs[0:1])
452 call assert_equal(repeat([attrs[3]], 3), attrs[3:5])
453 call assert_equal([attrs[6]] + repeat([attrs[7]], 3), attrs[6:9])
454 call assert_equal(attrs0[0], attrs[0])
455 call assert_notequal(attrs[0], attrs[2])
456 call assert_notequal(attrs[2], attrs[3])
457 call assert_notequal(attrs[3], attrs[6])
458 call assert_notequal(attrs[6], attrs[7])
459 call assert_notequal(attrs0[2], attrs[2])
460 call assert_notequal(attrs0[3], attrs[3])
461 call assert_notequal(attrs0[6], attrs[6])
Bram Moolenaar5ece3e32017-10-01 14:35:02 +0200462 call Check_lcs_eol_attrs(attrs, 2, 10)
Bram Moolenaar0aa398f2017-09-30 21:23:55 +0200463
464 if IsColorable()
465 " bg-color
466 exe hi_bg
467
468 " expected:
469 " ' >bcd '
470 " ^^^ breakindent and showbreak
471 " ^^^ bg-color of 'CursorLine'
472 " ^ 'Search' highlight
473 " ^^^ bg-color of 'CursorLine'
474 let attrs = ScreenAttrs(2, 10)[0]
475 call assert_equal(repeat([attrs[0]], 2), attrs[0:1])
476 call assert_equal(repeat([attrs[3]], 3), attrs[3:5])
477 call assert_equal(repeat([attrs[7]], 3), attrs[7:9])
478 call assert_equal(attrs0[0], attrs[0])
479 call assert_equal(attrs0[6], attrs[6])
480 call assert_notequal(attrs[0], attrs[2])
481 call assert_notequal(attrs[2], attrs[3])
482 call assert_notequal(attrs[3], attrs[6])
483 call assert_notequal(attrs[6], attrs[7])
484 call assert_notequal(attrs0[2], attrs[2])
485 call assert_notequal(attrs0[3], attrs[3])
486 call assert_notequal(attrs0[7], attrs[7])
Bram Moolenaar5ece3e32017-10-01 14:35:02 +0200487 call Check_lcs_eol_attrs(attrs, 2, 10)
Bram Moolenaar0aa398f2017-09-30 21:23:55 +0200488 endif
489
490 call CloseWindow()
491 set showbreak=
Bram Moolenaaree857022019-11-09 23:26:40 +0100492 setlocal showbreak=
Bram Moolenaar0aa398f2017-09-30 21:23:55 +0200493 exe hiCursorLine
494endfunc
495
496func Test_highlight_eol_on_diff()
497 call setline(1, ['abcd', ''])
498 call matchadd('Search', '\n')
499 let attrs0 = ScreenAttrs(1, 10)[0]
500
501 diffthis
502 botright new
503 diffthis
504
505 " expected:
506 " ' abcd '
507 " ^^ sign
508 " ^^^^ ^^^ 'DiffAdd' highlight
509 " ^ 'Search' highlight
510 let attrs = ScreenAttrs(1, 10)[0]
511 call assert_equal(repeat([attrs[0]], 2), attrs[0:1])
512 call assert_equal(repeat([attrs[2]], 4), attrs[2:5])
513 call assert_equal(repeat([attrs[2]], 3), attrs[7:9])
514 call assert_equal(attrs0[4], attrs[6])
515 call assert_notequal(attrs[0], attrs[2])
516 call assert_notequal(attrs[0], attrs[6])
517 call assert_notequal(attrs[2], attrs[6])
Bram Moolenaar5ece3e32017-10-01 14:35:02 +0200518 call Check_lcs_eol_attrs(attrs, 1, 10)
Bram Moolenaar0aa398f2017-09-30 21:23:55 +0200519
520 bwipe!
521 diffoff
522endfunc
Bram Moolenaarf708ac52018-03-12 21:48:32 +0100523
524func Test_termguicolors()
Bram Moolenaar6d91bcb2020-08-12 18:50:36 +0200525 CheckOption termguicolors
Bram Moolenaar310c32e2019-11-29 23:15:25 +0100526 if has('vtp') && !has('vcon') && !has('gui_running')
Bram Moolenaarff1e8792018-03-12 22:16:37 +0100527 " Win32: 'guicolors' doesn't work without virtual console.
528 call assert_fails('set termguicolors', 'E954:')
529 return
530 endif
Bram Moolenaarf708ac52018-03-12 21:48:32 +0100531
532 " Basic test that setting 'termguicolors' works with one color.
533 set termguicolors
534 redraw
535 set t_Co=1
536 redraw
537 set t_Co=0
538 redraw
539endfunc
Bram Moolenaarc07ff5c2019-01-30 21:41:14 +0100540
541func Test_cursorline_after_yank()
Bram Moolenaar8c5a2782019-08-07 23:07:07 +0200542 CheckScreendump
Bram Moolenaarc07ff5c2019-01-30 21:41:14 +0100543
544 call writefile([
545 \ 'set cul rnu',
546 \ 'call setline(1, ["","1","2","3",""])',
Bram Moolenaar572a4432022-09-28 21:07:03 +0100547 \ ], 'Xtest_cursorline_yank', 'D')
Bram Moolenaarc07ff5c2019-01-30 21:41:14 +0100548 let buf = RunVimInTerminal('-S Xtest_cursorline_yank', {'rows': 8})
Bram Moolenaar6a2c5a72020-04-08 21:50:25 +0200549 call TermWait(buf)
Bram Moolenaarc07ff5c2019-01-30 21:41:14 +0100550 call term_sendkeys(buf, "Gy3k")
Bram Moolenaar6a2c5a72020-04-08 21:50:25 +0200551 call TermWait(buf)
Bram Moolenaarc07ff5c2019-01-30 21:41:14 +0100552 call term_sendkeys(buf, "jj")
553
554 call VerifyScreenDump(buf, 'Test_cursorline_yank_01', {})
555
556 " clean up
557 call StopVimInTerminal(buf)
Bram Moolenaarc07ff5c2019-01-30 21:41:14 +0100558endfunc
Bram Moolenaar8156ed32019-03-09 11:46:15 +0100559
Bram Moolenaarfca068b2019-09-08 14:07:47 +0200560" test for issue #4862
561func Test_put_before_cursorline()
562 new
563 only!
564 call setline(1, 'A')
565 redraw
566 let std_attr = screenattr(1, 1)
567 set cursorline
568 redraw
569 let cul_attr = screenattr(1, 1)
570 normal yyP
571 redraw
572 " Line 1 has cursor so it should be highlighted with CursorLine.
573 call assert_equal(cul_attr, screenattr(1, 1))
574 " And CursorLine highlighting from the second line should be gone.
575 call assert_equal(std_attr, screenattr(2, 1))
576 set nocursorline
577 bwipe!
578endfunc
579
Bram Moolenaar8156ed32019-03-09 11:46:15 +0100580func Test_cursorline_with_visualmode()
Bram Moolenaar8c5a2782019-08-07 23:07:07 +0200581 CheckScreendump
Bram Moolenaar8156ed32019-03-09 11:46:15 +0100582
583 call writefile([
584 \ 'set cul',
585 \ 'call setline(1, repeat(["abc"], 50))',
Bram Moolenaar572a4432022-09-28 21:07:03 +0100586 \ ], 'Xtest_cursorline_with_visualmode', 'D')
Bram Moolenaar8156ed32019-03-09 11:46:15 +0100587 let buf = RunVimInTerminal('-S Xtest_cursorline_with_visualmode', {'rows': 12})
Bram Moolenaar6a2c5a72020-04-08 21:50:25 +0200588 call TermWait(buf)
Bram Moolenaar8156ed32019-03-09 11:46:15 +0100589 call term_sendkeys(buf, "V\<C-f>kkkjk")
590
591 call VerifyScreenDump(buf, 'Test_cursorline_with_visualmode_01', {})
592
593 " clean up
594 call StopVimInTerminal(buf)
Bram Moolenaar8156ed32019-03-09 11:46:15 +0100595endfunc
Bram Moolenaarf90b6e02019-05-09 19:26:38 +0200596
Bram Moolenaar782c6742022-04-01 12:06:31 +0100597func Test_cursorcolumn_insert_on_tab()
598 CheckScreendump
599
600 let lines =<< trim END
601 call setline(1, ['123456789', "a\tb"])
602 set cursorcolumn
603 call cursor(2, 2)
604 END
Bram Moolenaar572a4432022-09-28 21:07:03 +0100605 call writefile(lines, 'Xcuc_insert_on_tab', 'D')
Bram Moolenaar782c6742022-04-01 12:06:31 +0100606
607 let buf = RunVimInTerminal('-S Xcuc_insert_on_tab', #{rows: 8})
608 call TermWait(buf)
609 call VerifyScreenDump(buf, 'Test_cursorcolumn_insert_on_tab_1', {})
610
611 call term_sendkeys(buf, 'i')
612 call TermWait(buf)
613 call VerifyScreenDump(buf, 'Test_cursorcolumn_insert_on_tab_2', {})
614
zeertzjq8c979602022-04-07 15:08:01 +0100615 call term_sendkeys(buf, "\<C-O>")
616 call TermWait(buf)
617 call VerifyScreenDump(buf, 'Test_cursorcolumn_insert_on_tab_3', {})
618
619 call term_sendkeys(buf, 'i')
620 call TermWait(buf)
621 call VerifyScreenDump(buf, 'Test_cursorcolumn_insert_on_tab_2', {})
622
Bram Moolenaar782c6742022-04-01 12:06:31 +0100623 call StopVimInTerminal(buf)
Bram Moolenaar782c6742022-04-01 12:06:31 +0100624endfunc
625
zeertzjq3e559cd2022-03-27 19:26:55 +0100626func Test_cursorcolumn_callback()
627 CheckScreendump
628 CheckFeature timers
629
630 let lines =<< trim END
631 call setline(1, ['aaaaa', 'bbbbb', 'ccccc', 'ddddd'])
632 set cursorcolumn
633 call cursor(4, 5)
634
635 func Func(timer)
636 call cursor(1, 1)
637 endfunc
638
639 call timer_start(300, 'Func')
640 END
Bram Moolenaar572a4432022-09-28 21:07:03 +0100641 call writefile(lines, 'Xcuc_timer', 'D')
zeertzjq3e559cd2022-03-27 19:26:55 +0100642
643 let buf = RunVimInTerminal('-S Xcuc_timer', #{rows: 8})
644 call TermWait(buf, 310)
645 call VerifyScreenDump(buf, 'Test_cursorcolumn_callback_1', {})
646
647 call StopVimInTerminal(buf)
zeertzjq3e559cd2022-03-27 19:26:55 +0100648endfunc
649
Bram Moolenaar193ffd12019-05-25 22:57:30 +0200650func Test_wincolor()
Bram Moolenaar8c5a2782019-08-07 23:07:07 +0200651 CheckScreendump
Bram Moolenaar3180fe62020-02-02 13:47:06 +0100652 " make sure the width is enough for the test
653 set columns=80
Bram Moolenaar193ffd12019-05-25 22:57:30 +0200654
Bram Moolenaare7eb9272019-06-24 00:58:07 +0200655 let lines =<< trim END
656 set cursorline cursorcolumn rnu
Bram Moolenaar053f7122019-09-23 22:17:15 +0200657 call setline(1, ["","1111111111","22222222222","3 here 3","","the cat is out of the bag"])
Bram Moolenaare7eb9272019-06-24 00:58:07 +0200658 set wincolor=Pmenu
Bram Moolenaar053f7122019-09-23 22:17:15 +0200659 hi CatLine guifg=green ctermfg=green
660 hi Reverse gui=reverse cterm=reverse
661 syn match CatLine /^the.*/
662 call prop_type_add("foo", {"highlight": "Reverse", "combine": 1})
663 call prop_add(6, 12, {"type": "foo", "end_col": 15})
Bram Moolenaare7eb9272019-06-24 00:58:07 +0200664 /here
665 END
Bram Moolenaar572a4432022-09-28 21:07:03 +0100666 call writefile(lines, 'Xtest_wincolor', 'D')
Bram Moolenaar193ffd12019-05-25 22:57:30 +0200667 let buf = RunVimInTerminal('-S Xtest_wincolor', {'rows': 8})
Bram Moolenaar6a2c5a72020-04-08 21:50:25 +0200668 call TermWait(buf)
Bram Moolenaar193ffd12019-05-25 22:57:30 +0200669 call term_sendkeys(buf, "2G5lvj")
Bram Moolenaar6a2c5a72020-04-08 21:50:25 +0200670 call TermWait(buf)
Bram Moolenaar193ffd12019-05-25 22:57:30 +0200671
672 call VerifyScreenDump(buf, 'Test_wincolor_01', {})
673
674 " clean up
675 call term_sendkeys(buf, "\<Esc>")
676 call StopVimInTerminal(buf)
Bram Moolenaar193ffd12019-05-25 22:57:30 +0200677endfunc
678
Bram Moolenaar42e931b2019-12-04 19:08:50 +0100679func Test_wincolor_listchars()
680 CheckScreendump
Bram Moolenaar705724e2020-01-31 21:13:42 +0100681 CheckFeature conceal
Bram Moolenaar42e931b2019-12-04 19:08:50 +0100682
683 let lines =<< trim END
684 call setline(1, ["one","\t\tsome random text enough long to show 'extends' and 'precedes' includingnbsps, preceding tabs and trailing spaces ","three"])
685 set wincolor=Todo
686 set nowrap cole=1 cocu+=n
687 set list lcs=eol:$,tab:>-,space:.,trail:_,extends:>,precedes:<,conceal:*,nbsp:#
688 call matchadd('Conceal', 'text')
689 normal 2G5zl
690 END
Bram Moolenaar572a4432022-09-28 21:07:03 +0100691 call writefile(lines, 'Xtest_wincolorlcs', 'D')
Bram Moolenaar42e931b2019-12-04 19:08:50 +0100692 let buf = RunVimInTerminal('-S Xtest_wincolorlcs', {'rows': 8})
693
694 call VerifyScreenDump(buf, 'Test_wincolor_lcs', {})
695
696 " clean up
697 call term_sendkeys(buf, "\<Esc>")
698 call StopVimInTerminal(buf)
Bram Moolenaar42e931b2019-12-04 19:08:50 +0100699endfunc
700
Bram Moolenaar010ee962019-09-25 20:37:36 +0200701func Test_colorcolumn()
702 CheckScreendump
703
704 " check that setting 'colorcolumn' when entering a buffer works
705 let lines =<< trim END
706 split
707 edit X
708 call setline(1, ["1111111111","22222222222","3333333333"])
709 set nomodified
710 set colorcolumn=3,9
711 set number cursorline cursorlineopt=number
712 wincmd w
713 buf X
714 END
Bram Moolenaar572a4432022-09-28 21:07:03 +0100715 call writefile(lines, 'Xtest_colorcolumn', 'D')
Bram Moolenaar010ee962019-09-25 20:37:36 +0200716 let buf = RunVimInTerminal('-S Xtest_colorcolumn', {'rows': 10})
717 call term_sendkeys(buf, ":\<CR>")
Bram Moolenaar010ee962019-09-25 20:37:36 +0200718 call VerifyScreenDump(buf, 'Test_colorcolumn_1', {})
719
720 " clean up
721 call StopVimInTerminal(buf)
Bram Moolenaar010ee962019-09-25 20:37:36 +0200722endfunc
723
Bram Moolenaarad5e5632020-09-15 20:52:26 +0200724func Test_colorcolumn_bri()
725 CheckScreendump
726
727 " check 'colorcolumn' when 'breakindent' is set
728 let lines =<< trim END
729 call setline(1, 'The quick brown fox jumped over the lazy dogs')
730 END
Bram Moolenaar572a4432022-09-28 21:07:03 +0100731 call writefile(lines, 'Xtest_colorcolumn_bri', 'D')
Bram Moolenaarad5e5632020-09-15 20:52:26 +0200732 let buf = RunVimInTerminal('-S Xtest_colorcolumn_bri', {'rows': 10,'columns': 40})
733 call term_sendkeys(buf, ":set co=40 linebreak bri briopt=shift:2 cc=40,41,43\<CR>")
Bram Moolenaarad5e5632020-09-15 20:52:26 +0200734 call VerifyScreenDump(buf, 'Test_colorcolumn_2', {})
735
736 " clean up
737 call StopVimInTerminal(buf)
Bram Moolenaarad5e5632020-09-15 20:52:26 +0200738endfunc
739
740func Test_colorcolumn_sbr()
741 CheckScreendump
742
743 " check 'colorcolumn' when 'showbreak' is set
744 let lines =<< trim END
745 call setline(1, 'The quick brown fox jumped over the lazy dogs')
746 END
zeertzjqfc305842023-08-19 13:27:03 +0200747 call writefile(lines, 'Xtest_colorcolumn_sbr', 'D')
748 let buf = RunVimInTerminal('-S Xtest_colorcolumn_sbr', {'rows': 10,'columns': 40})
Bram Moolenaarad5e5632020-09-15 20:52:26 +0200749 call term_sendkeys(buf, ":set co=40 showbreak=+++>\\ cc=40,41,43\<CR>")
Bram Moolenaarad5e5632020-09-15 20:52:26 +0200750 call VerifyScreenDump(buf, 'Test_colorcolumn_3', {})
751
752 " clean up
753 call StopVimInTerminal(buf)
Bram Moolenaarad5e5632020-09-15 20:52:26 +0200754endfunc
755
Bram Moolenaarf578ca22023-06-10 19:40:30 +0100756func Test_visual_sbr()
757 CheckScreendump
758
759 " check Visual highlight when 'showbreak' is set
760 let lines =<< trim END
761 set showbreak=>
762 call setline(1, 'Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet.')
763 exe "normal! z1\<CR>"
764 END
765 call writefile(lines, 'Xtest_visual_sbr', 'D')
766 let buf = RunVimInTerminal('-S Xtest_visual_sbr', {'rows': 6,'columns': 60})
767
768 call term_sendkeys(buf, "v$")
769 call VerifyScreenDump(buf, 'Test_visual_sbr_1', {})
770
771 " clean up
772 call term_sendkeys(buf, "\<Esc>")
773 call StopVimInTerminal(buf)
774endfunc
775
Bram Moolenaar6b528fa2019-05-09 20:07:33 +0200776" This test must come before the Test_cursorline test, as it appears this
777" defines the Normal highlighting group anyway.
Bram Moolenaarf90b6e02019-05-09 19:26:38 +0200778func Test_1_highlight_Normalgroup_exists()
Bram Moolenaar435f9f02019-07-03 21:40:16 +0200779 let hlNormal = HighlightArgs('Normal')
780 if !has('gui_running')
Bram Moolenaar6b528fa2019-05-09 20:07:33 +0200781 call assert_match('hi Normal\s*clear', hlNormal)
Bram Moolenaar435f9f02019-07-03 21:40:16 +0200782 elseif has('gui_gtk2') || has('gui_gnome') || has('gui_gtk3')
783 " expect is DEFAULT_FONT of gui_gtk_x11.c
784 call assert_match('hi Normal\s*font=Monospace 10', hlNormal)
Bram Moolenaar0b962e52022-04-03 18:02:37 +0100785 elseif has('gui_motif')
Bram Moolenaar435f9f02019-07-03 21:40:16 +0200786 " expect is DEFAULT_FONT of gui_x11.c
787 call assert_match('hi Normal\s*font=7x13', hlNormal)
788 elseif has('win32')
789 " expect any font
790 call assert_match('hi Normal\s*font=.*', hlNormal)
Bram Moolenaar6b528fa2019-05-09 20:07:33 +0200791 endif
Bram Moolenaarf90b6e02019-05-09 19:26:38 +0200792endfunc
Bram Moolenaar548be7f2019-06-29 03:42:42 +0200793
Bram Moolenaar3180fe62020-02-02 13:47:06 +0100794" Do this test last, sometimes restoring the columns doesn't work
Bram Moolenaaree4e0c12020-04-06 21:35:05 +0200795func Test_z_no_space_before_xxx()
Bram Moolenaar548be7f2019-06-29 03:42:42 +0200796 let l:org_columns = &columns
797 set columns=17
798 let l:hi_StatusLineTermNC = join(split(execute('hi StatusLineTermNC')))
799 call assert_match('StatusLineTermNC xxx', l:hi_StatusLineTermNC)
800 let &columns = l:org_columns
Bram Moolenaaree4e0c12020-04-06 21:35:05 +0200801endfunc
802
803" Test for :highlight command errors
804func Test_highlight_cmd_errors()
805 if has('gui_running')
806 " This test doesn't fail in the MS-Windows console version.
Bram Moolenaar75e15672020-06-28 13:10:22 +0200807 call assert_fails('hi Xcomment ctermbg=fg', 'E419:')
Bram Moolenaaree4e0c12020-04-06 21:35:05 +0200808 call assert_fails('hi Xcomment ctermfg=bg', 'E420:')
Bram Moolenaar75e15672020-06-28 13:10:22 +0200809 call assert_fails('hi Xcomment ctermfg=ul', 'E453:')
erw7f7f7aaf2021-12-07 21:29:20 +0000810 call assert_fails('hi ' .. repeat('a', 201) .. ' ctermfg=black', 'E1249:')
Bram Moolenaaree4e0c12020-04-06 21:35:05 +0200811 endif
812
813 " Try using a very long terminal code. Define a dummy terminal code for this
814 " test.
815 let &t_fo = "\<Esc>1;"
816 let c = repeat("t_fo,", 100) . "t_fo"
817 call assert_fails('exe "hi Xgroup1 start=" . c', 'E422:')
818 let &t_fo = ""
819endfunc
820
Bram Moolenaar75e15672020-06-28 13:10:22 +0200821" Test for 'highlight' option
822func Test_highlight_opt()
823 let save_hl = &highlight
824 call assert_fails('set highlight=j:b', 'E474:')
825 set highlight=f\ r
826 call assert_equal('f r', &highlight)
827 set highlight=fb
828 call assert_equal('fb', &highlight)
829 set highlight=fi
830 call assert_equal('fi', &highlight)
831 set highlight=f-
832 call assert_equal('f-', &highlight)
833 set highlight=fr
834 call assert_equal('fr', &highlight)
835 set highlight=fs
836 call assert_equal('fs', &highlight)
837 set highlight=fu
838 call assert_equal('fu', &highlight)
839 set highlight=fc
840 call assert_equal('fc', &highlight)
841 set highlight=ft
842 call assert_equal('ft', &highlight)
843 call assert_fails('set highlight=fr:Search', 'E474:')
844 set highlight=f:$#
845 call assert_match('W18:', v:statusmsg)
846 let &highlight = save_hl
847endfunc
848
849" Test for User group highlighting used in the statusline
850func Test_highlight_User()
851 CheckNotGui
852 hi User1 ctermfg=12
853 redraw!
854 call assert_equal('12', synIDattr(synIDtrans(hlID('User1')), 'fg'))
855 hi clear
856endfunc
857
858" Test for using RGB color values in a highlight group
Bram Moolenaar09fbedc2021-01-19 17:22:58 +0100859func Test_xxlast_highlight_RGB_color()
860 CheckCanRunGui
861 gui -f
Bram Moolenaar75e15672020-06-28 13:10:22 +0200862 hi MySearch guifg=#110000 guibg=#001100 guisp=#000011
863 call assert_equal('#110000', synIDattr(synIDtrans(hlID('MySearch')), 'fg#'))
864 call assert_equal('#001100', synIDattr(synIDtrans(hlID('MySearch')), 'bg#'))
865 call assert_equal('#000011', synIDattr(synIDtrans(hlID('MySearch')), 'sp#'))
866 hi clear
867endfunc
868
Bram Moolenaarde8f0f42020-06-30 18:45:43 +0200869" Test for using default highlighting group
870func Test_highlight_default()
871 highlight MySearch ctermfg=7
872 highlight default MySearch ctermfg=5
873 let hlSearch = HighlightArgs('MySearch')
874 call assert_match('ctermfg=7', hlSearch)
875
876 highlight default QFName ctermfg=3
877 call assert_match('ctermfg=3', HighlightArgs('QFName'))
878 hi clear
879endfunc
880
Christian Brabandtee17b6f2023-09-09 11:23:50 +0200881" Test for 'ctermul' in a highlight group
Bram Moolenaarde8f0f42020-06-30 18:45:43 +0200882func Test_highlight_ctermul()
883 CheckNotGui
884 call assert_notmatch('ctermul=', HighlightArgs('Normal'))
885 highlight Normal ctermul=3
886 call assert_match('ctermul=3', HighlightArgs('Normal'))
Bram Moolenaar391c3622020-09-29 20:59:17 +0200887 call assert_equal('3', synIDattr(synIDtrans(hlID('Normal')), 'ul'))
Bram Moolenaarde8f0f42020-06-30 18:45:43 +0200888 highlight Normal ctermul=NONE
889endfunc
890
PMuncha606f3a2023-11-15 15:35:49 +0100891" Test for 'ctermfont' in a highlight group
892func Test_highlight_ctermfont()
893 CheckNotGui
894 call assert_notmatch('ctermfont=', HighlightArgs('Normal'))
895 highlight Normal ctermfont=3
896 call assert_match('ctermfont=3', HighlightArgs('Normal'))
897 call assert_equal('3', synIDattr(synIDtrans(hlID('Normal')), 'font'))
898 highlight Normal ctermfont=NONE
899endfunc
900
Bram Moolenaarde8f0f42020-06-30 18:45:43 +0200901" Test for specifying 'start' and 'stop' in a highlight group
902func Test_highlight_start_stop()
903 hi HlGrp1 start=<Esc>[27h;<Esc>[<Space>r;
904 call assert_match("start=^[[27h;^[[ r;", HighlightArgs('HlGrp1'))
905 hi HlGrp1 start=NONE
906 call assert_notmatch("start=", HighlightArgs('HlGrp1'))
907 hi HlGrp2 stop=<Esc>[27h;<Esc>[<Space>r;
908 call assert_match("stop=^[[27h;^[[ r;", HighlightArgs('HlGrp2'))
909 hi HlGrp2 stop=NONE
910 call assert_notmatch("stop=", HighlightArgs('HlGrp2'))
Yegappan Lakshmanan5284b232023-03-04 19:57:32 +0000911 set t_xy=^[foo;
912 set t_xz=^[bar;
913 hi HlGrp3 start=t_xy stop=t_xz
914 let d = hlget('HlGrp3')
915 call assert_equal('^[foo;', d[0].start)
916 call assert_equal('^[bar;', d[0].stop)
917 set t_xy= t_xz=
Bram Moolenaarde8f0f42020-06-30 18:45:43 +0200918 hi clear
919endfunc
920
921" Test for setting various 'term' attributes
922func Test_highlight_term_attr()
Bram Moolenaar84f54632022-06-29 18:39:11 +0100923 hi HlGrp3 term=bold,underline,undercurl,underdouble,underdotted,underdashed,strikethrough,reverse,italic,standout
924 call assert_equal('hi HlGrp3 term=bold,standout,underline,undercurl,underdouble,underdotted,underdashed,italic,reverse,strikethrough', HighlightArgs('HlGrp3'))
Bram Moolenaarde8f0f42020-06-30 18:45:43 +0200925 hi HlGrp3 term=NONE
926 call assert_equal('hi HlGrp3 cleared', HighlightArgs('HlGrp3'))
927 hi clear
928endfunc
929
Bram Moolenaar213da552020-09-17 19:59:26 +0200930func Test_highlight_clear_restores_links()
931 let aaa_id = hlID('aaa')
932 call assert_equal(aaa_id, 0)
933
934 " create default link aaa --> bbb
935 hi def link aaa bbb
936 let id_aaa = hlID('aaa')
937 let hl_aaa_bbb = HighlightArgs('aaa')
938
939 " try to redefine default link aaa --> ccc; check aaa --> bbb
940 hi def link aaa ccc
941 call assert_equal(HighlightArgs('aaa'), hl_aaa_bbb)
942
943 " clear aaa; check aaa --> bbb
944 hi clear aaa
945 call assert_equal(HighlightArgs('aaa'), hl_aaa_bbb)
946
947 " link aaa --> ccc; clear aaa; check aaa --> bbb
948 hi link aaa ccc
949 let id_ccc = hlID('ccc')
950 call assert_equal(synIDtrans(id_aaa), id_ccc)
951 hi clear aaa
952 call assert_equal(HighlightArgs('aaa'), hl_aaa_bbb)
953
954 " forcibly set default link aaa --> ddd
955 hi! def link aaa ddd
956 let id_ddd = hlID('ddd')
957 let hl_aaa_ddd = HighlightArgs('aaa')
958 call assert_equal(synIDtrans(id_aaa), id_ddd)
959
960 " link aaa --> eee; clear aaa; check aaa --> ddd
961 hi link aaa eee
962 let eee_id = hlID('eee')
963 call assert_equal(synIDtrans(id_aaa), eee_id)
964 hi clear aaa
965 call assert_equal(HighlightArgs('aaa'), hl_aaa_ddd)
966endfunc
967
Bram Moolenaare8df0102020-09-18 19:40:45 +0200968func Test_highlight_clear_restores_context()
969 func FuncContextDefault()
970 hi def link Context ContextDefault
971 endfun
972
973 func FuncContextRelink()
974 " Dummy line
975 hi link Context ContextRelink
976 endfunc
977
978 let scriptContextDefault = MakeScript("FuncContextDefault")
979 let scriptContextRelink = MakeScript("FuncContextRelink")
980 let patContextDefault = fnamemodify(scriptContextDefault, ':t') .. ' line 1'
981 let patContextRelink = fnamemodify(scriptContextRelink, ':t') .. ' line 2'
982
Bram Moolenaar2bbada82020-09-18 21:55:26 +0200983 exec 'source ' .. scriptContextDefault
Bram Moolenaare8df0102020-09-18 19:40:45 +0200984 let hlContextDefault = execute("verbose hi Context")
985 call assert_match(patContextDefault, hlContextDefault)
986
Bram Moolenaar2bbada82020-09-18 21:55:26 +0200987 exec 'source ' .. scriptContextRelink
Bram Moolenaare8df0102020-09-18 19:40:45 +0200988 let hlContextRelink = execute("verbose hi Context")
989 call assert_match(patContextRelink, hlContextRelink)
990
991 hi clear
992 let hlContextAfterClear = execute("verbose hi Context")
993 call assert_match(patContextDefault, hlContextAfterClear)
994
995 delfunc FuncContextDefault
996 delfunc FuncContextRelink
997 call delete(scriptContextDefault)
998 call delete(scriptContextRelink)
999endfunc
1000
Bram Moolenaar213da552020-09-17 19:59:26 +02001001func Test_highlight_default_colorscheme_restores_links()
1002 hi link TestLink Identifier
1003 hi TestHi ctermbg=red
Bram Moolenaar05eb5b92020-09-16 15:43:21 +02001004
1005 let hlTestLinkPre = HighlightArgs('TestLink')
1006 let hlTestHiPre = HighlightArgs('TestHi')
1007
1008 " Test colorscheme
Dominique Pelle8bfa0eb2022-01-02 16:16:33 +00001009 call assert_equal("\ndefault", execute('colorscheme'))
Bram Moolenaar05eb5b92020-09-16 15:43:21 +02001010 hi clear
1011 if exists('syntax_on')
1012 syntax reset
1013 endif
1014 let g:colors_name = 'test'
Dominique Pelle8bfa0eb2022-01-02 16:16:33 +00001015 call assert_equal("\ntest", execute('colorscheme'))
Bram Moolenaar213da552020-09-17 19:59:26 +02001016 hi link TestLink ErrorMsg
1017 hi TestHi ctermbg=green
Bram Moolenaar05eb5b92020-09-16 15:43:21 +02001018
1019 " Restore default highlighting
1020 colorscheme default
Bram Moolenaar05eb5b92020-09-16 15:43:21 +02001021 " 'default' should work no matter if highlight group was cleared
Dominique Pelle8bfa0eb2022-01-02 16:16:33 +00001022 call assert_equal("\ndefault", execute('colorscheme'))
Bram Moolenaar05eb5b92020-09-16 15:43:21 +02001023 hi def link TestLink Identifier
1024 hi def TestHi ctermbg=red
Bram Moolenaar05eb5b92020-09-16 15:43:21 +02001025 let hlTestLinkPost = HighlightArgs('TestLink')
1026 let hlTestHiPost = HighlightArgs('TestHi')
Bram Moolenaar05eb5b92020-09-16 15:43:21 +02001027 call assert_equal(hlTestLinkPre, hlTestLinkPost)
1028 call assert_equal(hlTestHiPre, hlTestHiPost)
1029 hi clear
1030endfunc
1031
Drew Vogele30d1022021-10-24 20:35:07 +01001032func Test_colornames_assignment_and_lookup()
Drew Vogela0fca172021-11-13 10:50:01 +00001033 CheckAnyOf Feature:gui_running Feature:termguicolors
1034
Drew Vogele30d1022021-10-24 20:35:07 +01001035 " Ensure highlight command can find custom color.
1036 let v:colornames['a redish white'] = '#ffeedd'
1037 highlight Normal guifg='a redish white'
1038 highlight clear
Drew Vogela0fca172021-11-13 10:50:01 +00001039 call ClearDict(v:colornames)
Drew Vogele30d1022021-10-24 20:35:07 +01001040endfunc
1041
1042func Test_colornames_default_list()
Drew Vogela0fca172021-11-13 10:50:01 +00001043 CheckAnyOf Feature:gui_running Feature:termguicolors
1044
Drew Vogele30d1022021-10-24 20:35:07 +01001045 " Ensure default lists are loaded automatically and can be used for all gui fields.
Drew Vogela0fca172021-11-13 10:50:01 +00001046 call assert_equal(0, len(v:colornames))
Drew Vogele30d1022021-10-24 20:35:07 +01001047 highlight Normal guifg='rebecca purple' guibg='rebecca purple' guisp='rebecca purple'
Drew Vogela0fca172021-11-13 10:50:01 +00001048 call assert_notequal(0, len(v:colornames))
1049 echo v:colornames['rebecca purple']
Drew Vogele30d1022021-10-24 20:35:07 +01001050 highlight clear
Drew Vogela0fca172021-11-13 10:50:01 +00001051 call ClearDict(v:colornames)
Drew Vogele30d1022021-10-24 20:35:07 +01001052endfunc
1053
1054func Test_colornames_overwrite_default()
Drew Vogela0fca172021-11-13 10:50:01 +00001055 CheckAnyOf Feature:gui_running Feature:termguicolors
1056
Drew Vogele30d1022021-10-24 20:35:07 +01001057 " Ensure entries in v:colornames can be overwritten.
1058 " Load default color scheme to trigger default color list loading.
1059 colorscheme default
1060 let old_rebecca_purple = v:colornames['rebecca purple']
1061 highlight Normal guifg='rebecca purple' guibg='rebecca purple'
1062 let v:colornames['rebecca purple'] = '#550099'
1063 highlight Normal guifg='rebecca purple' guibg='rebecca purple'
1064 let v:colornames['rebecca purple'] = old_rebecca_purple
1065 highlight clear
1066endfunc
1067
1068func Test_colornames_assignment_and_unassignment()
Drew Vogela0fca172021-11-13 10:50:01 +00001069 " No feature check is needed for this test because the v:colornames dict
1070 " always exists with +eval. The feature checks are only required for
1071 " commands that do color lookup.
1072
Drew Vogele30d1022021-10-24 20:35:07 +01001073 " Ensure we cannot overwrite the v:colornames dict.
1074 call assert_fails("let v:colornames = {}", 'E46:')
1075
1076 " Ensure we can delete entries from the v:colornames dict.
1077 let v:colornames['x1'] = '#111111'
1078 call assert_equal(v:colornames['x1'], '#111111')
1079 unlet v:colornames['x1']
1080 call assert_fails("echo v:colornames['x1']")
1081endfunc
1082
Yegappan Lakshmanand1a8d652021-11-03 21:56:45 +00001083" Test for the hlget() function
1084func Test_hlget()
1085 let lines =<< trim END
1086 call assert_notequal([], filter(hlget(), 'v:val.name == "Visual"'))
1087 call assert_equal([], hlget('SomeHLGroup'))
1088 highlight MyHLGroup term=standout cterm=reverse ctermfg=10 ctermbg=Black
1089 call assert_equal([{'id': hlID('MyHLGroup'), 'ctermfg': '10', 'name': 'MyHLGroup', 'term': {'standout': v:true}, 'ctermbg': '0', 'cterm': {'reverse': v:true}}], hlget('MyHLGroup'))
1090 highlight clear MyHLGroup
1091 call assert_equal(v:true, hlget('MyHLGroup')[0].cleared)
1092 highlight link MyHLGroup IncSearch
1093 call assert_equal('IncSearch', hlget('MyHLGroup')[0].linksto)
1094 highlight clear MyHLGroup
1095 call assert_equal([], hlget(test_null_string()))
1096 call assert_equal([], hlget(""))
1097 END
Bram Moolenaar62aec932022-01-29 21:45:34 +00001098 call v9.CheckLegacyAndVim9Success(lines)
Yegappan Lakshmanand1a8d652021-11-03 21:56:45 +00001099
1100 " Test for resolving highlight group links
1101 let lines =<< trim END
1102 highlight hlgA term=bold
1103 VAR hlgAid = hlID('hlgA')
1104 highlight link hlgB hlgA
1105 VAR hlgBid = hlID('hlgB')
1106 highlight link hlgC hlgB
1107 VAR hlgCid = hlID('hlgC')
1108 call assert_equal('hlgA', hlget('hlgB')[0].linksto)
1109 call assert_equal('hlgB', hlget('hlgC')[0].linksto)
1110 call assert_equal([{'id': hlgAid, 'name': 'hlgA',
1111 \ 'term': {'bold': v:true}}], hlget('hlgA'))
1112 call assert_equal([{'id': hlgBid, 'name': 'hlgB',
1113 \ 'linksto': 'hlgA'}], hlget('hlgB'))
1114 call assert_equal([{'id': hlgCid, 'name': 'hlgC',
1115 \ 'linksto': 'hlgB'}], hlget('hlgC'))
1116 call assert_equal([{'id': hlgAid, 'name': 'hlgA',
1117 \ 'term': {'bold': v:true}}], hlget('hlgA', v:false))
1118 call assert_equal([{'id': hlgBid, 'name': 'hlgB',
1119 \ 'linksto': 'hlgA'}], hlget('hlgB', 0))
1120 call assert_equal([{'id': hlgCid, 'name': 'hlgC',
1121 \ 'linksto': 'hlgB'}], hlget('hlgC', v:false))
1122 call assert_equal([{'id': hlgAid, 'name': 'hlgA',
1123 \ 'term': {'bold': v:true}}], hlget('hlgA', v:true))
1124 call assert_equal([{'id': hlgBid, 'name': 'hlgB',
1125 \ 'term': {'bold': v:true}}], hlget('hlgB', 1))
1126 call assert_equal([{'id': hlgCid, 'name': 'hlgC',
1127 \ 'term': {'bold': v:true}}], hlget('hlgC', v:true))
1128 END
Bram Moolenaar62aec932022-01-29 21:45:34 +00001129 call v9.CheckLegacyAndVim9Success(lines)
Yegappan Lakshmanand1a8d652021-11-03 21:56:45 +00001130
1131 call assert_fails('call hlget([])', 'E1174:')
1132 call assert_fails('call hlget("abc", "xyz")', 'E1212:')
1133endfunc
1134
1135" Test for the hlset() function
1136func Test_hlset()
1137 let lines =<< trim END
1138 call assert_equal(0, hlset(test_null_list()))
1139 call assert_equal(0, hlset([]))
1140 call assert_fails('call hlset(["Search"])', 'E715:')
1141 call hlset(hlget())
1142 call hlset([{'name': 'NewHLGroup', 'cterm': {'reverse': v:true}, 'ctermfg': '10'}])
1143 call assert_equal({'reverse': v:true}, hlget('NewHLGroup')[0].cterm)
1144 call hlset([{'name': 'NewHLGroup', 'cterm': {'bold': v:true}}])
1145 call assert_equal({'bold': v:true}, hlget('NewHLGroup')[0].cterm)
1146 call hlset([{'name': 'NewHLGroup', 'cleared': v:true}])
1147 call assert_equal(v:true, hlget('NewHLGroup')[0].cleared)
1148 call hlset([{'name': 'NewHLGroup', 'linksto': 'Search'}])
1149 call assert_false(has_key(hlget('NewHLGroup')[0], 'cleared'))
1150 call assert_equal('Search', hlget('NewHLGroup')[0].linksto)
1151 call assert_fails("call hlset([{'name': [], 'ctermfg': '10'}])", 'E928:')
1152 call assert_fails("call hlset([{'name': 'NewHLGroup', 'cleared': []}])",
1153 \ 'E745:')
1154 call assert_fails("call hlset([{'name': 'NewHLGroup', 'cterm': 'Blue'}])",
1155 \ 'E715:')
1156 call assert_fails("call hlset([{'name': 'NewHLGroup', 'ctermbg': []}])",
1157 \ 'E928:')
1158 call assert_fails("call hlset([{'name': 'NewHLGroup', 'ctermfg': []}])",
1159 \ 'E928:')
1160 call assert_fails("call hlset([{'name': 'NewHLGroup', 'ctermul': []}])",
1161 \ 'E928:')
1162 if has('gui')
1163 call assert_fails("call hlset([{'name': 'NewHLGroup', 'font': []}])",
1164 \ 'E928:')
1165 endif
1166 call assert_fails("call hlset([{'name': 'NewHLGroup', 'gui': 'Cyan'}])",
1167 \ 'E715:')
1168 call assert_fails("call hlset([{'name': 'NewHLGroup', 'guibg': []}])",
1169 \ 'E928:')
1170 call assert_fails("call hlset([{'name': 'NewHLGroup', 'guifg': []}])",
1171 \ 'E928:')
1172 call assert_fails("call hlset([{'name': 'NewHLGroup', 'guisp': []}])",
1173 \ 'E928:')
1174 call assert_fails("call hlset([{'name': 'NewHLGroup', 'linksto': []}])",
1175 \ 'E928:')
1176 call assert_fails("call hlset([{'name': 'NewHLGroup', 'start': []}])",
1177 \ 'E928:')
1178 call assert_fails("call hlset([{'name': 'NewHLGroup', 'stop': []}])",
1179 \ 'E928:')
1180 call assert_fails("call hlset([{'name': 'NewHLGroup', 'term': 'Cyan'}])",
1181 \ 'E715:')
1182 call assert_equal('Search', hlget('NewHLGroup')[0].linksto)
1183 highlight clear NewHLGroup
1184 END
Bram Moolenaar62aec932022-01-29 21:45:34 +00001185 call v9.CheckLegacyAndVim9Success(lines)
Yegappan Lakshmanand1a8d652021-11-03 21:56:45 +00001186
1187 " Test for clearing the 'term', 'cterm' and 'gui' attributes of a highlight
1188 " group.
1189 let lines =<< trim END
1190 highlight myhlg1 term=bold cterm=italic gui=standout
1191 VAR id = hlID('myhlg1')
1192 call hlset([{'name': 'myhlg1', 'term': {}}])
1193 call assert_equal([{'id': id, 'name': 'myhlg1',
1194 \ 'cterm': {'italic': v:true}, 'gui': {'standout': v:true}}],
1195 \ hlget('myhlg1'))
1196 call hlset([{'name': 'myhlg1', 'cterm': {}}])
1197 call assert_equal([{'id': id, 'name': 'myhlg1',
1198 \ 'gui': {'standout': v:true}}], hlget('myhlg1'))
1199 call hlset([{'name': 'myhlg1', 'gui': {}}])
1200 call assert_equal([{'id': id, 'name': 'myhlg1', 'cleared': v:true}],
1201 \ hlget('myhlg1'))
1202 highlight clear myhlg1
1203 END
Bram Moolenaar62aec932022-01-29 21:45:34 +00001204 call v9.CheckLegacyAndVim9Success(lines)
Yegappan Lakshmanand1a8d652021-11-03 21:56:45 +00001205
1206 " Test for setting all the 'term', 'cterm' and 'gui' attributes of a
1207 " highlight group
1208 let lines =<< trim END
Bram Moolenaar84f54632022-06-29 18:39:11 +01001209 VAR attr = {'bold': v:true, 'underline': v:true,
1210 \ 'undercurl': v:true, 'underdouble': v:true,
1211 \ 'underdotted': v:true, 'underdashed': v:true,
Yegappan Lakshmanand1a8d652021-11-03 21:56:45 +00001212 \ 'strikethrough': v:true, 'reverse': v:true, 'italic': v:true,
1213 \ 'standout': v:true, 'nocombine': v:true}
1214 call hlset([{'name': 'myhlg2', 'term': attr, 'cterm': attr, 'gui': attr}])
1215 VAR id2 = hlID('myhlg2')
Bram Moolenaar84f54632022-06-29 18:39:11 +01001216 VAR expected = "myhlg2 xxx term=bold,standout,underline,undercurl,underdouble,underdotted,underdashed,italic,reverse,nocombine,strikethrough cterm=bold,standout,underline,undercurl,underdouble,underdotted,underdashed,italic,reverse,nocombine,strikethrough gui=bold,standout,underline,undercurl,underdouble,underdotted,underdashed,italic,reverse,nocombine,strikethrough"
Yegappan Lakshmanan2a16dc62021-11-16 17:19:30 +00001217 VAR output = execute('highlight myhlg2')
1218 LET output = output->split("\n")->join()->substitute('\s\+', ' ', 'g')
1219 call assert_equal(expected, output)
Yegappan Lakshmanand1a8d652021-11-03 21:56:45 +00001220 call assert_equal([{'id': id2, 'name': 'myhlg2', 'gui': attr,
1221 \ 'term': attr, 'cterm': attr}], hlget('myhlg2'))
1222 END
Bram Moolenaar62aec932022-01-29 21:45:34 +00001223 call v9.CheckLegacyAndVim9Success(lines)
Yegappan Lakshmanand1a8d652021-11-03 21:56:45 +00001224
1225 " Test for clearing some of the 'term', 'cterm' and 'gui' attributes of a
1226 " highlight group
1227 let lines =<< trim END
1228 VAR attr = {'bold': v:false, 'underline': v:true, 'strikethrough': v:true}
1229 call hlset([{'name': 'myhlg2', 'term': attr, 'cterm': attr, 'gui': attr}])
1230 VAR id2 = hlID('myhlg2')
Yegappan Lakshmanan2a16dc62021-11-16 17:19:30 +00001231 VAR expected = "myhlg2 xxx term=underline,strikethrough cterm=underline,strikethrough gui=underline,strikethrough"
1232 VAR output = execute('highlight myhlg2')
1233 LET output = output->split("\n")->join()->substitute('\s\+', ' ', 'g')
1234 call assert_equal(expected, output)
Yegappan Lakshmanand1a8d652021-11-03 21:56:45 +00001235 LET attr = {'underline': v:true, 'strikethrough': v:true}
1236 call assert_equal([{'id': id2, 'name': 'myhlg2', 'gui': attr,
1237 \ 'term': attr, 'cterm': attr}], hlget('myhlg2'))
1238 END
Bram Moolenaar62aec932022-01-29 21:45:34 +00001239 call v9.CheckLegacyAndVim9Success(lines)
Dominique Pelle6a950a62021-11-13 18:44:37 +00001240
Yegappan Lakshmanan2a16dc62021-11-16 17:19:30 +00001241 " Test for clearing the attributes and link of a highlight group
1242 let lines =<< trim END
1243 highlight myhlg3 ctermbg=green guibg=green
1244 highlight! default link myhlg3 ErrorMsg
1245 VAR id3 = hlID('myhlg3')
1246 call hlset([{'name': 'myhlg3', 'cleared': v:true, 'linksto': 'NONE'}])
1247 call assert_equal([{'id': id3, 'name': 'myhlg3', 'cleared': v:true}],
1248 \ hlget('myhlg3'))
1249 highlight clear hlg3
1250 END
Bram Moolenaar62aec932022-01-29 21:45:34 +00001251 call v9.CheckLegacyAndVim9Success(lines)
Yegappan Lakshmanan2a16dc62021-11-16 17:19:30 +00001252
1253 " Test for setting default attributes for a highlight group
1254 let lines =<< trim END
1255 call hlset([{'name': 'hlg4', 'ctermfg': '8'}])
1256 call hlset([{'name': 'hlg4', 'default': v:true, 'ctermfg': '9'}])
1257 VAR id4 = hlID('hlg4')
1258 call assert_equal([{'id': id4, 'name': 'hlg4', 'ctermfg': '8'}],
1259 \ hlget('hlg4'))
1260 highlight clear hlg4
1261
1262 call hlset([{'name': 'hlg5', 'default': v:true, 'ctermbg': '2'}])
1263 call hlset([{'name': 'hlg5', 'ctermbg': '4'}])
1264 VAR id5 = hlID('hlg5')
1265 call assert_equal([{'id': id5, 'name': 'hlg5', 'ctermbg': '4'}],
1266 \ hlget('hlg5'))
1267 highlight clear hlg5
1268
1269 call hlset([{'name': 'hlg6', 'linksto': 'Error'}])
1270 VAR id6 = hlID('hlg6')
1271 call hlset([{'name': 'hlg6', 'default': v:true, 'ctermbg': '2'}])
1272 call assert_equal([{'id': id6, 'name': 'hlg6', 'linksto': 'Error'}],
1273 \ hlget('hlg6'))
1274 highlight clear hlg6
1275 END
Bram Moolenaar62aec932022-01-29 21:45:34 +00001276 call v9.CheckLegacyAndVim9Success(lines)
Yegappan Lakshmanan2a16dc62021-11-16 17:19:30 +00001277
1278 " Test for setting default links for a highlight group
1279 let lines =<< trim END
1280 call hlset([{'name': 'hlg7', 'ctermfg': '5'}])
1281 call hlset([{'name': 'hlg7', 'default': v:true, 'linksto': 'Search'}])
1282 VAR id7 = hlID('hlg7')
1283 call assert_equal([{'id': id7, 'name': 'hlg7', 'ctermfg': '5'}],
1284 \ hlget('hlg7'))
1285 highlight clear hlg7
1286
1287 call hlset([{'name': 'hlg8', 'default': v:true, 'linksto': 'Search'}])
1288 VAR id8 = hlID('hlg8')
1289 call assert_equal([{'id': id8, 'name': 'hlg8', 'default': v:true,
1290 \ 'linksto': 'Search'}], hlget('hlg8'))
1291 call hlset([{'name': 'hlg8', 'ctermbg': '2'}])
1292 call assert_equal([{'id': id8, 'name': 'hlg8', 'ctermbg': '2'}],
1293 \ hlget('hlg8'))
1294 highlight clear hlg8
1295
1296 highlight default link hlg9 ErrorMsg
1297 VAR hlg_save = hlget('hlg9')
1298 LET hlg_save[0]['name'] = 'hlg9dup'
1299 call hlset(hlg_save)
1300 VAR id9 = hlID('hlg9dup')
1301 highlight clear hlg9dup
1302 call assert_equal([{'id': id9, 'name': 'hlg9dup', 'default': v:true,
1303 \ 'linksto': 'ErrorMsg'}], hlget('hlg9dup'))
1304 highlight clear hlg9
1305 END
Bram Moolenaar62aec932022-01-29 21:45:34 +00001306 call v9.CheckLegacyAndVim9Success(lines)
Yegappan Lakshmanan2a16dc62021-11-16 17:19:30 +00001307
1308 " Test for force creating a link to a highlight group
1309 let lines =<< trim END
1310 call hlset([{'name': 'hlg10', 'ctermfg': '8'}])
1311 call hlset([{'name': 'hlg10', 'linksto': 'Search'}])
1312 VAR id10 = hlID('hlg10')
1313 call assert_equal([{'id': id10, 'name': 'hlg10', 'ctermfg': '8'}],
1314 \ hlget('hlg10'))
1315 call hlset([{'name': 'hlg10', 'linksto': 'Search', 'force': v:true}])
1316 call assert_equal([{'id': id10, 'name': 'hlg10', 'ctermfg': '8',
1317 \ 'linksto': 'Search'}], hlget('hlg10'))
1318 highlight clear hlg10
1319 END
Bram Moolenaar62aec932022-01-29 21:45:34 +00001320 call v9.CheckLegacyAndVim9Success(lines)
Yegappan Lakshmananbb277fd2021-11-24 20:28:31 +00001321
1322 " Test for empty values of attributes
1323 call hlset([{'name': 'hlg11', 'cterm': {}}])
1324 call hlset([{'name': 'hlg11', 'ctermfg': ''}])
1325 call hlset([{'name': 'hlg11', 'ctermbg': ''}])
1326 call hlset([{'name': 'hlg11', 'ctermul': ''}])
PMuncha606f3a2023-11-15 15:35:49 +01001327 call hlset([{'name': 'hlg11', 'ctermfont': ''}])
Yegappan Lakshmananbb277fd2021-11-24 20:28:31 +00001328 call hlset([{'name': 'hlg11', 'font': ''}])
1329 call hlset([{'name': 'hlg11', 'gui': {}}])
1330 call hlset([{'name': 'hlg11', 'guifg': ''}])
1331 call hlset([{'name': 'hlg11', 'guibg': ''}])
1332 call hlset([{'name': 'hlg11', 'guisp': ''}])
1333 call hlset([{'name': 'hlg11', 'start': ''}])
1334 call hlset([{'name': 'hlg11', 'stop': ''}])
1335 call hlset([{'name': 'hlg11', 'term': {}}])
1336 call assert_true(hlget('hlg11')[0].cleared)
Yegappan Lakshmanand1a8d652021-11-03 21:56:45 +00001337endfunc
1338
Bram Moolenaaree4e0c12020-04-06 21:35:05 +02001339" vim: shiftwidth=2 sts=2 expandtab