blob: 9bc5f12455d63f7a27e93b1c38e0ad104b58b9e3 [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
zeertzjq7ce34c92024-02-08 11:34:55 +0100560" Test for issue #4862: pasting above 'cursorline' redraws properly.
Bram Moolenaarfca068b2019-09-08 14:07:47 +0200561func Test_put_before_cursorline()
562 new
563 only!
zeertzjq7ce34c92024-02-08 11:34:55 +0100564 call setline(1, ['A', 'B', 'C'])
565 call cursor(2, 1)
Bram Moolenaarfca068b2019-09-08 14:07:47 +0200566 redraw
zeertzjq7ce34c92024-02-08 11:34:55 +0100567 let std_attr = screenattr(2, 1)
Bram Moolenaarfca068b2019-09-08 14:07:47 +0200568 set cursorline
569 redraw
zeertzjq7ce34c92024-02-08 11:34:55 +0100570 let cul_attr = screenattr(2, 1)
Bram Moolenaarfca068b2019-09-08 14:07:47 +0200571 normal yyP
572 redraw
zeertzjq7ce34c92024-02-08 11:34:55 +0100573 " Line 2 has cursor so it should be highlighted with CursorLine.
574 call assert_equal(cul_attr, screenattr(2, 1))
575 " And CursorLine highlighting from line 3 should be gone.
576 call assert_equal(std_attr, screenattr(3, 1))
Bram Moolenaarfca068b2019-09-08 14:07:47 +0200577 set nocursorline
578 bwipe!
579endfunc
580
Bram Moolenaar8156ed32019-03-09 11:46:15 +0100581func Test_cursorline_with_visualmode()
Bram Moolenaar8c5a2782019-08-07 23:07:07 +0200582 CheckScreendump
Bram Moolenaar8156ed32019-03-09 11:46:15 +0100583
584 call writefile([
585 \ 'set cul',
586 \ 'call setline(1, repeat(["abc"], 50))',
Bram Moolenaar572a4432022-09-28 21:07:03 +0100587 \ ], 'Xtest_cursorline_with_visualmode', 'D')
Bram Moolenaar8156ed32019-03-09 11:46:15 +0100588 let buf = RunVimInTerminal('-S Xtest_cursorline_with_visualmode', {'rows': 12})
Bram Moolenaar6a2c5a72020-04-08 21:50:25 +0200589 call TermWait(buf)
Bram Moolenaar8156ed32019-03-09 11:46:15 +0100590 call term_sendkeys(buf, "V\<C-f>kkkjk")
591
592 call VerifyScreenDump(buf, 'Test_cursorline_with_visualmode_01', {})
593
594 " clean up
595 call StopVimInTerminal(buf)
Bram Moolenaar8156ed32019-03-09 11:46:15 +0100596endfunc
Bram Moolenaarf90b6e02019-05-09 19:26:38 +0200597
Bram Moolenaar782c6742022-04-01 12:06:31 +0100598func Test_cursorcolumn_insert_on_tab()
599 CheckScreendump
600
601 let lines =<< trim END
602 call setline(1, ['123456789', "a\tb"])
603 set cursorcolumn
604 call cursor(2, 2)
605 END
Bram Moolenaar572a4432022-09-28 21:07:03 +0100606 call writefile(lines, 'Xcuc_insert_on_tab', 'D')
Bram Moolenaar782c6742022-04-01 12:06:31 +0100607
608 let buf = RunVimInTerminal('-S Xcuc_insert_on_tab', #{rows: 8})
609 call TermWait(buf)
610 call VerifyScreenDump(buf, 'Test_cursorcolumn_insert_on_tab_1', {})
611
612 call term_sendkeys(buf, 'i')
613 call TermWait(buf)
614 call VerifyScreenDump(buf, 'Test_cursorcolumn_insert_on_tab_2', {})
615
zeertzjq8c979602022-04-07 15:08:01 +0100616 call term_sendkeys(buf, "\<C-O>")
617 call TermWait(buf)
618 call VerifyScreenDump(buf, 'Test_cursorcolumn_insert_on_tab_3', {})
619
620 call term_sendkeys(buf, 'i')
621 call TermWait(buf)
622 call VerifyScreenDump(buf, 'Test_cursorcolumn_insert_on_tab_2', {})
623
Bram Moolenaar782c6742022-04-01 12:06:31 +0100624 call StopVimInTerminal(buf)
Bram Moolenaar782c6742022-04-01 12:06:31 +0100625endfunc
626
zeertzjq3e559cd2022-03-27 19:26:55 +0100627func Test_cursorcolumn_callback()
628 CheckScreendump
629 CheckFeature timers
630
631 let lines =<< trim END
632 call setline(1, ['aaaaa', 'bbbbb', 'ccccc', 'ddddd'])
633 set cursorcolumn
634 call cursor(4, 5)
635
636 func Func(timer)
637 call cursor(1, 1)
638 endfunc
639
640 call timer_start(300, 'Func')
641 END
Bram Moolenaar572a4432022-09-28 21:07:03 +0100642 call writefile(lines, 'Xcuc_timer', 'D')
zeertzjq3e559cd2022-03-27 19:26:55 +0100643
644 let buf = RunVimInTerminal('-S Xcuc_timer', #{rows: 8})
645 call TermWait(buf, 310)
646 call VerifyScreenDump(buf, 'Test_cursorcolumn_callback_1', {})
647
648 call StopVimInTerminal(buf)
zeertzjq3e559cd2022-03-27 19:26:55 +0100649endfunc
650
Bram Moolenaar193ffd12019-05-25 22:57:30 +0200651func Test_wincolor()
Bram Moolenaar8c5a2782019-08-07 23:07:07 +0200652 CheckScreendump
Bram Moolenaar3180fe62020-02-02 13:47:06 +0100653 " make sure the width is enough for the test
654 set columns=80
Bram Moolenaar193ffd12019-05-25 22:57:30 +0200655
Bram Moolenaare7eb9272019-06-24 00:58:07 +0200656 let lines =<< trim END
657 set cursorline cursorcolumn rnu
Bram Moolenaar053f7122019-09-23 22:17:15 +0200658 call setline(1, ["","1111111111","22222222222","3 here 3","","the cat is out of the bag"])
Bram Moolenaare7eb9272019-06-24 00:58:07 +0200659 set wincolor=Pmenu
Bram Moolenaar053f7122019-09-23 22:17:15 +0200660 hi CatLine guifg=green ctermfg=green
661 hi Reverse gui=reverse cterm=reverse
662 syn match CatLine /^the.*/
663 call prop_type_add("foo", {"highlight": "Reverse", "combine": 1})
664 call prop_add(6, 12, {"type": "foo", "end_col": 15})
Bram Moolenaare7eb9272019-06-24 00:58:07 +0200665 /here
666 END
Bram Moolenaar572a4432022-09-28 21:07:03 +0100667 call writefile(lines, 'Xtest_wincolor', 'D')
Bram Moolenaar193ffd12019-05-25 22:57:30 +0200668 let buf = RunVimInTerminal('-S Xtest_wincolor', {'rows': 8})
Bram Moolenaar6a2c5a72020-04-08 21:50:25 +0200669 call TermWait(buf)
Bram Moolenaar193ffd12019-05-25 22:57:30 +0200670 call term_sendkeys(buf, "2G5lvj")
Bram Moolenaar6a2c5a72020-04-08 21:50:25 +0200671 call TermWait(buf)
Bram Moolenaar193ffd12019-05-25 22:57:30 +0200672
673 call VerifyScreenDump(buf, 'Test_wincolor_01', {})
674
675 " clean up
676 call term_sendkeys(buf, "\<Esc>")
677 call StopVimInTerminal(buf)
Bram Moolenaar193ffd12019-05-25 22:57:30 +0200678endfunc
679
Bram Moolenaar42e931b2019-12-04 19:08:50 +0100680func Test_wincolor_listchars()
681 CheckScreendump
Bram Moolenaar705724e2020-01-31 21:13:42 +0100682 CheckFeature conceal
Bram Moolenaar42e931b2019-12-04 19:08:50 +0100683
684 let lines =<< trim END
685 call setline(1, ["one","\t\tsome random text enough long to show 'extends' and 'precedes' includingnbsps, preceding tabs and trailing spaces ","three"])
686 set wincolor=Todo
687 set nowrap cole=1 cocu+=n
688 set list lcs=eol:$,tab:>-,space:.,trail:_,extends:>,precedes:<,conceal:*,nbsp:#
689 call matchadd('Conceal', 'text')
690 normal 2G5zl
691 END
Bram Moolenaar572a4432022-09-28 21:07:03 +0100692 call writefile(lines, 'Xtest_wincolorlcs', 'D')
Bram Moolenaar42e931b2019-12-04 19:08:50 +0100693 let buf = RunVimInTerminal('-S Xtest_wincolorlcs', {'rows': 8})
694
695 call VerifyScreenDump(buf, 'Test_wincolor_lcs', {})
696
697 " clean up
698 call term_sendkeys(buf, "\<Esc>")
699 call StopVimInTerminal(buf)
Bram Moolenaar42e931b2019-12-04 19:08:50 +0100700endfunc
701
Bram Moolenaar010ee962019-09-25 20:37:36 +0200702func Test_colorcolumn()
703 CheckScreendump
704
705 " check that setting 'colorcolumn' when entering a buffer works
706 let lines =<< trim END
707 split
708 edit X
709 call setline(1, ["1111111111","22222222222","3333333333"])
710 set nomodified
711 set colorcolumn=3,9
712 set number cursorline cursorlineopt=number
713 wincmd w
714 buf X
715 END
Bram Moolenaar572a4432022-09-28 21:07:03 +0100716 call writefile(lines, 'Xtest_colorcolumn', 'D')
Bram Moolenaar010ee962019-09-25 20:37:36 +0200717 let buf = RunVimInTerminal('-S Xtest_colorcolumn', {'rows': 10})
718 call term_sendkeys(buf, ":\<CR>")
Bram Moolenaar010ee962019-09-25 20:37:36 +0200719 call VerifyScreenDump(buf, 'Test_colorcolumn_1', {})
720
721 " clean up
722 call StopVimInTerminal(buf)
Bram Moolenaar010ee962019-09-25 20:37:36 +0200723endfunc
724
Bram Moolenaarad5e5632020-09-15 20:52:26 +0200725func Test_colorcolumn_bri()
726 CheckScreendump
727
728 " check 'colorcolumn' when 'breakindent' is set
729 let lines =<< trim END
730 call setline(1, 'The quick brown fox jumped over the lazy dogs')
731 END
Bram Moolenaar572a4432022-09-28 21:07:03 +0100732 call writefile(lines, 'Xtest_colorcolumn_bri', 'D')
Bram Moolenaarad5e5632020-09-15 20:52:26 +0200733 let buf = RunVimInTerminal('-S Xtest_colorcolumn_bri', {'rows': 10,'columns': 40})
734 call term_sendkeys(buf, ":set co=40 linebreak bri briopt=shift:2 cc=40,41,43\<CR>")
Bram Moolenaarad5e5632020-09-15 20:52:26 +0200735 call VerifyScreenDump(buf, 'Test_colorcolumn_2', {})
736
737 " clean up
738 call StopVimInTerminal(buf)
Bram Moolenaarad5e5632020-09-15 20:52:26 +0200739endfunc
740
741func Test_colorcolumn_sbr()
742 CheckScreendump
743
744 " check 'colorcolumn' when 'showbreak' is set
745 let lines =<< trim END
746 call setline(1, 'The quick brown fox jumped over the lazy dogs')
747 END
zeertzjqfc305842023-08-19 13:27:03 +0200748 call writefile(lines, 'Xtest_colorcolumn_sbr', 'D')
749 let buf = RunVimInTerminal('-S Xtest_colorcolumn_sbr', {'rows': 10,'columns': 40})
Bram Moolenaarad5e5632020-09-15 20:52:26 +0200750 call term_sendkeys(buf, ":set co=40 showbreak=+++>\\ cc=40,41,43\<CR>")
Bram Moolenaarad5e5632020-09-15 20:52:26 +0200751 call VerifyScreenDump(buf, 'Test_colorcolumn_3', {})
752
753 " clean up
754 call StopVimInTerminal(buf)
Bram Moolenaarad5e5632020-09-15 20:52:26 +0200755endfunc
756
Bram Moolenaarf578ca22023-06-10 19:40:30 +0100757func Test_visual_sbr()
758 CheckScreendump
759
760 " check Visual highlight when 'showbreak' is set
761 let lines =<< trim END
762 set showbreak=>
763 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.')
764 exe "normal! z1\<CR>"
765 END
766 call writefile(lines, 'Xtest_visual_sbr', 'D')
767 let buf = RunVimInTerminal('-S Xtest_visual_sbr', {'rows': 6,'columns': 60})
768
769 call term_sendkeys(buf, "v$")
770 call VerifyScreenDump(buf, 'Test_visual_sbr_1', {})
771
772 " clean up
773 call term_sendkeys(buf, "\<Esc>")
774 call StopVimInTerminal(buf)
775endfunc
776
Bram Moolenaar6b528fa2019-05-09 20:07:33 +0200777" This test must come before the Test_cursorline test, as it appears this
778" defines the Normal highlighting group anyway.
Bram Moolenaarf90b6e02019-05-09 19:26:38 +0200779func Test_1_highlight_Normalgroup_exists()
Bram Moolenaar435f9f02019-07-03 21:40:16 +0200780 let hlNormal = HighlightArgs('Normal')
781 if !has('gui_running')
Bram Moolenaar6b528fa2019-05-09 20:07:33 +0200782 call assert_match('hi Normal\s*clear', hlNormal)
Bram Moolenaar435f9f02019-07-03 21:40:16 +0200783 elseif has('gui_gtk2') || has('gui_gnome') || has('gui_gtk3')
784 " expect is DEFAULT_FONT of gui_gtk_x11.c
785 call assert_match('hi Normal\s*font=Monospace 10', hlNormal)
Bram Moolenaar0b962e52022-04-03 18:02:37 +0100786 elseif has('gui_motif')
Bram Moolenaar435f9f02019-07-03 21:40:16 +0200787 " expect is DEFAULT_FONT of gui_x11.c
788 call assert_match('hi Normal\s*font=7x13', hlNormal)
789 elseif has('win32')
790 " expect any font
791 call assert_match('hi Normal\s*font=.*', hlNormal)
Bram Moolenaar6b528fa2019-05-09 20:07:33 +0200792 endif
Bram Moolenaarf90b6e02019-05-09 19:26:38 +0200793endfunc
Bram Moolenaar548be7f2019-06-29 03:42:42 +0200794
Bram Moolenaar3180fe62020-02-02 13:47:06 +0100795" Do this test last, sometimes restoring the columns doesn't work
Bram Moolenaaree4e0c12020-04-06 21:35:05 +0200796func Test_z_no_space_before_xxx()
Bram Moolenaar548be7f2019-06-29 03:42:42 +0200797 let l:org_columns = &columns
798 set columns=17
799 let l:hi_StatusLineTermNC = join(split(execute('hi StatusLineTermNC')))
800 call assert_match('StatusLineTermNC xxx', l:hi_StatusLineTermNC)
801 let &columns = l:org_columns
Bram Moolenaaree4e0c12020-04-06 21:35:05 +0200802endfunc
803
804" Test for :highlight command errors
805func Test_highlight_cmd_errors()
806 if has('gui_running')
807 " This test doesn't fail in the MS-Windows console version.
Bram Moolenaar75e15672020-06-28 13:10:22 +0200808 call assert_fails('hi Xcomment ctermbg=fg', 'E419:')
Bram Moolenaaree4e0c12020-04-06 21:35:05 +0200809 call assert_fails('hi Xcomment ctermfg=bg', 'E420:')
Bram Moolenaar75e15672020-06-28 13:10:22 +0200810 call assert_fails('hi Xcomment ctermfg=ul', 'E453:')
erw7f7f7aaf2021-12-07 21:29:20 +0000811 call assert_fails('hi ' .. repeat('a', 201) .. ' ctermfg=black', 'E1249:')
Bram Moolenaaree4e0c12020-04-06 21:35:05 +0200812 endif
813
814 " Try using a very long terminal code. Define a dummy terminal code for this
815 " test.
816 let &t_fo = "\<Esc>1;"
817 let c = repeat("t_fo,", 100) . "t_fo"
818 call assert_fails('exe "hi Xgroup1 start=" . c', 'E422:')
819 let &t_fo = ""
820endfunc
821
Bram Moolenaar75e15672020-06-28 13:10:22 +0200822" Test for 'highlight' option
823func Test_highlight_opt()
824 let save_hl = &highlight
825 call assert_fails('set highlight=j:b', 'E474:')
826 set highlight=f\ r
827 call assert_equal('f r', &highlight)
828 set highlight=fb
829 call assert_equal('fb', &highlight)
830 set highlight=fi
831 call assert_equal('fi', &highlight)
832 set highlight=f-
833 call assert_equal('f-', &highlight)
834 set highlight=fr
835 call assert_equal('fr', &highlight)
836 set highlight=fs
837 call assert_equal('fs', &highlight)
838 set highlight=fu
839 call assert_equal('fu', &highlight)
840 set highlight=fc
841 call assert_equal('fc', &highlight)
842 set highlight=ft
843 call assert_equal('ft', &highlight)
844 call assert_fails('set highlight=fr:Search', 'E474:')
845 set highlight=f:$#
846 call assert_match('W18:', v:statusmsg)
847 let &highlight = save_hl
848endfunc
849
850" Test for User group highlighting used in the statusline
851func Test_highlight_User()
852 CheckNotGui
853 hi User1 ctermfg=12
854 redraw!
855 call assert_equal('12', synIDattr(synIDtrans(hlID('User1')), 'fg'))
856 hi clear
857endfunc
858
Shougo Matsushitabe2b03c2024-04-08 22:11:50 +0200859" Test for MsgArea highlighting
860func Test_highlight_MsgArea()
861 CheckNotGui
862 hi MsgArea ctermfg=20
863 redraw!
864 call assert_equal('20', synIDattr(synIDtrans(hlID('MsgArea')), 'fg'))
865 hi clear
866endfunc
867
Bram Moolenaar75e15672020-06-28 13:10:22 +0200868" Test for using RGB color values in a highlight group
Bram Moolenaar09fbedc2021-01-19 17:22:58 +0100869func Test_xxlast_highlight_RGB_color()
870 CheckCanRunGui
871 gui -f
Bram Moolenaar75e15672020-06-28 13:10:22 +0200872 hi MySearch guifg=#110000 guibg=#001100 guisp=#000011
873 call assert_equal('#110000', synIDattr(synIDtrans(hlID('MySearch')), 'fg#'))
874 call assert_equal('#001100', synIDattr(synIDtrans(hlID('MySearch')), 'bg#'))
875 call assert_equal('#000011', synIDattr(synIDtrans(hlID('MySearch')), 'sp#'))
876 hi clear
877endfunc
878
Bram Moolenaarde8f0f42020-06-30 18:45:43 +0200879" Test for using default highlighting group
880func Test_highlight_default()
881 highlight MySearch ctermfg=7
882 highlight default MySearch ctermfg=5
883 let hlSearch = HighlightArgs('MySearch')
884 call assert_match('ctermfg=7', hlSearch)
885
886 highlight default QFName ctermfg=3
887 call assert_match('ctermfg=3', HighlightArgs('QFName'))
888 hi clear
889endfunc
890
Christian Brabandtee17b6f2023-09-09 11:23:50 +0200891" Test for 'ctermul' in a highlight group
Bram Moolenaarde8f0f42020-06-30 18:45:43 +0200892func Test_highlight_ctermul()
893 CheckNotGui
894 call assert_notmatch('ctermul=', HighlightArgs('Normal'))
895 highlight Normal ctermul=3
896 call assert_match('ctermul=3', HighlightArgs('Normal'))
Bram Moolenaar391c3622020-09-29 20:59:17 +0200897 call assert_equal('3', synIDattr(synIDtrans(hlID('Normal')), 'ul'))
Bram Moolenaarde8f0f42020-06-30 18:45:43 +0200898 highlight Normal ctermul=NONE
899endfunc
900
PMuncha606f3a2023-11-15 15:35:49 +0100901" Test for 'ctermfont' in a highlight group
902func Test_highlight_ctermfont()
903 CheckNotGui
904 call assert_notmatch('ctermfont=', HighlightArgs('Normal'))
905 highlight Normal ctermfont=3
906 call assert_match('ctermfont=3', HighlightArgs('Normal'))
907 call assert_equal('3', synIDattr(synIDtrans(hlID('Normal')), 'font'))
908 highlight Normal ctermfont=NONE
909endfunc
910
Bram Moolenaarde8f0f42020-06-30 18:45:43 +0200911" Test for specifying 'start' and 'stop' in a highlight group
912func Test_highlight_start_stop()
913 hi HlGrp1 start=<Esc>[27h;<Esc>[<Space>r;
914 call assert_match("start=^[[27h;^[[ r;", HighlightArgs('HlGrp1'))
915 hi HlGrp1 start=NONE
916 call assert_notmatch("start=", HighlightArgs('HlGrp1'))
917 hi HlGrp2 stop=<Esc>[27h;<Esc>[<Space>r;
918 call assert_match("stop=^[[27h;^[[ r;", HighlightArgs('HlGrp2'))
919 hi HlGrp2 stop=NONE
920 call assert_notmatch("stop=", HighlightArgs('HlGrp2'))
Yegappan Lakshmanan5284b232023-03-04 19:57:32 +0000921 set t_xy=^[foo;
922 set t_xz=^[bar;
923 hi HlGrp3 start=t_xy stop=t_xz
924 let d = hlget('HlGrp3')
925 call assert_equal('^[foo;', d[0].start)
926 call assert_equal('^[bar;', d[0].stop)
927 set t_xy= t_xz=
Bram Moolenaarde8f0f42020-06-30 18:45:43 +0200928 hi clear
929endfunc
930
931" Test for setting various 'term' attributes
932func Test_highlight_term_attr()
Bram Moolenaar84f54632022-06-29 18:39:11 +0100933 hi HlGrp3 term=bold,underline,undercurl,underdouble,underdotted,underdashed,strikethrough,reverse,italic,standout
934 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 +0200935 hi HlGrp3 term=NONE
936 call assert_equal('hi HlGrp3 cleared', HighlightArgs('HlGrp3'))
937 hi clear
938endfunc
939
Bram Moolenaar213da552020-09-17 19:59:26 +0200940func Test_highlight_clear_restores_links()
941 let aaa_id = hlID('aaa')
942 call assert_equal(aaa_id, 0)
943
944 " create default link aaa --> bbb
945 hi def link aaa bbb
946 let id_aaa = hlID('aaa')
947 let hl_aaa_bbb = HighlightArgs('aaa')
948
949 " try to redefine default link aaa --> ccc; check aaa --> bbb
950 hi def link aaa ccc
951 call assert_equal(HighlightArgs('aaa'), hl_aaa_bbb)
952
953 " clear aaa; check aaa --> bbb
954 hi clear aaa
955 call assert_equal(HighlightArgs('aaa'), hl_aaa_bbb)
956
957 " link aaa --> ccc; clear aaa; check aaa --> bbb
958 hi link aaa ccc
959 let id_ccc = hlID('ccc')
960 call assert_equal(synIDtrans(id_aaa), id_ccc)
961 hi clear aaa
962 call assert_equal(HighlightArgs('aaa'), hl_aaa_bbb)
963
964 " forcibly set default link aaa --> ddd
965 hi! def link aaa ddd
966 let id_ddd = hlID('ddd')
967 let hl_aaa_ddd = HighlightArgs('aaa')
968 call assert_equal(synIDtrans(id_aaa), id_ddd)
969
970 " link aaa --> eee; clear aaa; check aaa --> ddd
971 hi link aaa eee
972 let eee_id = hlID('eee')
973 call assert_equal(synIDtrans(id_aaa), eee_id)
974 hi clear aaa
975 call assert_equal(HighlightArgs('aaa'), hl_aaa_ddd)
976endfunc
977
Bram Moolenaare8df0102020-09-18 19:40:45 +0200978func Test_highlight_clear_restores_context()
979 func FuncContextDefault()
980 hi def link Context ContextDefault
981 endfun
982
983 func FuncContextRelink()
984 " Dummy line
985 hi link Context ContextRelink
986 endfunc
987
988 let scriptContextDefault = MakeScript("FuncContextDefault")
989 let scriptContextRelink = MakeScript("FuncContextRelink")
990 let patContextDefault = fnamemodify(scriptContextDefault, ':t') .. ' line 1'
991 let patContextRelink = fnamemodify(scriptContextRelink, ':t') .. ' line 2'
992
Bram Moolenaar2bbada82020-09-18 21:55:26 +0200993 exec 'source ' .. scriptContextDefault
Bram Moolenaare8df0102020-09-18 19:40:45 +0200994 let hlContextDefault = execute("verbose hi Context")
995 call assert_match(patContextDefault, hlContextDefault)
996
Bram Moolenaar2bbada82020-09-18 21:55:26 +0200997 exec 'source ' .. scriptContextRelink
Bram Moolenaare8df0102020-09-18 19:40:45 +0200998 let hlContextRelink = execute("verbose hi Context")
999 call assert_match(patContextRelink, hlContextRelink)
1000
1001 hi clear
1002 let hlContextAfterClear = execute("verbose hi Context")
1003 call assert_match(patContextDefault, hlContextAfterClear)
1004
1005 delfunc FuncContextDefault
1006 delfunc FuncContextRelink
1007 call delete(scriptContextDefault)
1008 call delete(scriptContextRelink)
1009endfunc
1010
Bram Moolenaar213da552020-09-17 19:59:26 +02001011func Test_highlight_default_colorscheme_restores_links()
1012 hi link TestLink Identifier
1013 hi TestHi ctermbg=red
Bram Moolenaar05eb5b92020-09-16 15:43:21 +02001014
1015 let hlTestLinkPre = HighlightArgs('TestLink')
1016 let hlTestHiPre = HighlightArgs('TestHi')
1017
1018 " Test colorscheme
Dominique Pelle8bfa0eb2022-01-02 16:16:33 +00001019 call assert_equal("\ndefault", execute('colorscheme'))
Bram Moolenaar05eb5b92020-09-16 15:43:21 +02001020 hi clear
1021 if exists('syntax_on')
1022 syntax reset
1023 endif
1024 let g:colors_name = 'test'
Dominique Pelle8bfa0eb2022-01-02 16:16:33 +00001025 call assert_equal("\ntest", execute('colorscheme'))
Bram Moolenaar213da552020-09-17 19:59:26 +02001026 hi link TestLink ErrorMsg
1027 hi TestHi ctermbg=green
Bram Moolenaar05eb5b92020-09-16 15:43:21 +02001028
1029 " Restore default highlighting
1030 colorscheme default
Bram Moolenaar05eb5b92020-09-16 15:43:21 +02001031 " 'default' should work no matter if highlight group was cleared
Dominique Pelle8bfa0eb2022-01-02 16:16:33 +00001032 call assert_equal("\ndefault", execute('colorscheme'))
Bram Moolenaar05eb5b92020-09-16 15:43:21 +02001033 hi def link TestLink Identifier
1034 hi def TestHi ctermbg=red
Bram Moolenaar05eb5b92020-09-16 15:43:21 +02001035 let hlTestLinkPost = HighlightArgs('TestLink')
1036 let hlTestHiPost = HighlightArgs('TestHi')
Bram Moolenaar05eb5b92020-09-16 15:43:21 +02001037 call assert_equal(hlTestLinkPre, hlTestLinkPost)
1038 call assert_equal(hlTestHiPre, hlTestHiPost)
1039 hi clear
1040endfunc
1041
Drew Vogele30d1022021-10-24 20:35:07 +01001042func Test_colornames_assignment_and_lookup()
Drew Vogela0fca172021-11-13 10:50:01 +00001043 CheckAnyOf Feature:gui_running Feature:termguicolors
1044
Drew Vogele30d1022021-10-24 20:35:07 +01001045 " Ensure highlight command can find custom color.
1046 let v:colornames['a redish white'] = '#ffeedd'
1047 highlight Normal guifg='a redish white'
1048 highlight clear
Drew Vogela0fca172021-11-13 10:50:01 +00001049 call ClearDict(v:colornames)
Drew Vogele30d1022021-10-24 20:35:07 +01001050endfunc
1051
1052func Test_colornames_default_list()
Drew Vogela0fca172021-11-13 10:50:01 +00001053 CheckAnyOf Feature:gui_running Feature:termguicolors
1054
Drew Vogele30d1022021-10-24 20:35:07 +01001055 " Ensure default lists are loaded automatically and can be used for all gui fields.
Drew Vogela0fca172021-11-13 10:50:01 +00001056 call assert_equal(0, len(v:colornames))
Drew Vogele30d1022021-10-24 20:35:07 +01001057 highlight Normal guifg='rebecca purple' guibg='rebecca purple' guisp='rebecca purple'
Drew Vogela0fca172021-11-13 10:50:01 +00001058 call assert_notequal(0, len(v:colornames))
1059 echo v:colornames['rebecca purple']
Drew Vogele30d1022021-10-24 20:35:07 +01001060 highlight clear
Drew Vogela0fca172021-11-13 10:50:01 +00001061 call ClearDict(v:colornames)
Drew Vogele30d1022021-10-24 20:35:07 +01001062endfunc
1063
1064func Test_colornames_overwrite_default()
Drew Vogela0fca172021-11-13 10:50:01 +00001065 CheckAnyOf Feature:gui_running Feature:termguicolors
1066
Drew Vogele30d1022021-10-24 20:35:07 +01001067 " Ensure entries in v:colornames can be overwritten.
1068 " Load default color scheme to trigger default color list loading.
1069 colorscheme default
1070 let old_rebecca_purple = v:colornames['rebecca purple']
1071 highlight Normal guifg='rebecca purple' guibg='rebecca purple'
1072 let v:colornames['rebecca purple'] = '#550099'
1073 highlight Normal guifg='rebecca purple' guibg='rebecca purple'
1074 let v:colornames['rebecca purple'] = old_rebecca_purple
1075 highlight clear
1076endfunc
1077
1078func Test_colornames_assignment_and_unassignment()
Drew Vogela0fca172021-11-13 10:50:01 +00001079 " No feature check is needed for this test because the v:colornames dict
1080 " always exists with +eval. The feature checks are only required for
1081 " commands that do color lookup.
1082
Drew Vogele30d1022021-10-24 20:35:07 +01001083 " Ensure we cannot overwrite the v:colornames dict.
1084 call assert_fails("let v:colornames = {}", 'E46:')
1085
1086 " Ensure we can delete entries from the v:colornames dict.
1087 let v:colornames['x1'] = '#111111'
1088 call assert_equal(v:colornames['x1'], '#111111')
1089 unlet v:colornames['x1']
1090 call assert_fails("echo v:colornames['x1']")
1091endfunc
1092
Yegappan Lakshmanand1a8d652021-11-03 21:56:45 +00001093" Test for the hlget() function
1094func Test_hlget()
1095 let lines =<< trim END
1096 call assert_notequal([], filter(hlget(), 'v:val.name == "Visual"'))
1097 call assert_equal([], hlget('SomeHLGroup'))
1098 highlight MyHLGroup term=standout cterm=reverse ctermfg=10 ctermbg=Black
1099 call assert_equal([{'id': hlID('MyHLGroup'), 'ctermfg': '10', 'name': 'MyHLGroup', 'term': {'standout': v:true}, 'ctermbg': '0', 'cterm': {'reverse': v:true}}], hlget('MyHLGroup'))
1100 highlight clear MyHLGroup
1101 call assert_equal(v:true, hlget('MyHLGroup')[0].cleared)
1102 highlight link MyHLGroup IncSearch
1103 call assert_equal('IncSearch', hlget('MyHLGroup')[0].linksto)
1104 highlight clear MyHLGroup
1105 call assert_equal([], hlget(test_null_string()))
1106 call assert_equal([], hlget(""))
1107 END
Bram Moolenaar62aec932022-01-29 21:45:34 +00001108 call v9.CheckLegacyAndVim9Success(lines)
Yegappan Lakshmanand1a8d652021-11-03 21:56:45 +00001109
1110 " Test for resolving highlight group links
1111 let lines =<< trim END
1112 highlight hlgA term=bold
1113 VAR hlgAid = hlID('hlgA')
1114 highlight link hlgB hlgA
1115 VAR hlgBid = hlID('hlgB')
1116 highlight link hlgC hlgB
1117 VAR hlgCid = hlID('hlgC')
1118 call assert_equal('hlgA', hlget('hlgB')[0].linksto)
1119 call assert_equal('hlgB', hlget('hlgC')[0].linksto)
1120 call assert_equal([{'id': hlgAid, 'name': 'hlgA',
1121 \ 'term': {'bold': v:true}}], hlget('hlgA'))
1122 call assert_equal([{'id': hlgBid, 'name': 'hlgB',
1123 \ 'linksto': 'hlgA'}], hlget('hlgB'))
1124 call assert_equal([{'id': hlgCid, 'name': 'hlgC',
1125 \ 'linksto': 'hlgB'}], hlget('hlgC'))
1126 call assert_equal([{'id': hlgAid, 'name': 'hlgA',
1127 \ 'term': {'bold': v:true}}], hlget('hlgA', v:false))
1128 call assert_equal([{'id': hlgBid, 'name': 'hlgB',
1129 \ 'linksto': 'hlgA'}], hlget('hlgB', 0))
1130 call assert_equal([{'id': hlgCid, 'name': 'hlgC',
1131 \ 'linksto': 'hlgB'}], hlget('hlgC', v:false))
1132 call assert_equal([{'id': hlgAid, 'name': 'hlgA',
1133 \ 'term': {'bold': v:true}}], hlget('hlgA', v:true))
1134 call assert_equal([{'id': hlgBid, 'name': 'hlgB',
1135 \ 'term': {'bold': v:true}}], hlget('hlgB', 1))
1136 call assert_equal([{'id': hlgCid, 'name': 'hlgC',
1137 \ 'term': {'bold': v:true}}], hlget('hlgC', v:true))
1138 END
Bram Moolenaar62aec932022-01-29 21:45:34 +00001139 call v9.CheckLegacyAndVim9Success(lines)
Yegappan Lakshmanand1a8d652021-11-03 21:56:45 +00001140
1141 call assert_fails('call hlget([])', 'E1174:')
1142 call assert_fails('call hlget("abc", "xyz")', 'E1212:')
1143endfunc
1144
1145" Test for the hlset() function
1146func Test_hlset()
1147 let lines =<< trim END
1148 call assert_equal(0, hlset(test_null_list()))
1149 call assert_equal(0, hlset([]))
1150 call assert_fails('call hlset(["Search"])', 'E715:')
1151 call hlset(hlget())
1152 call hlset([{'name': 'NewHLGroup', 'cterm': {'reverse': v:true}, 'ctermfg': '10'}])
1153 call assert_equal({'reverse': v:true}, hlget('NewHLGroup')[0].cterm)
1154 call hlset([{'name': 'NewHLGroup', 'cterm': {'bold': v:true}}])
1155 call assert_equal({'bold': v:true}, hlget('NewHLGroup')[0].cterm)
1156 call hlset([{'name': 'NewHLGroup', 'cleared': v:true}])
1157 call assert_equal(v:true, hlget('NewHLGroup')[0].cleared)
1158 call hlset([{'name': 'NewHLGroup', 'linksto': 'Search'}])
1159 call assert_false(has_key(hlget('NewHLGroup')[0], 'cleared'))
1160 call assert_equal('Search', hlget('NewHLGroup')[0].linksto)
1161 call assert_fails("call hlset([{'name': [], 'ctermfg': '10'}])", 'E928:')
1162 call assert_fails("call hlset([{'name': 'NewHLGroup', 'cleared': []}])",
1163 \ 'E745:')
1164 call assert_fails("call hlset([{'name': 'NewHLGroup', 'cterm': 'Blue'}])",
1165 \ 'E715:')
1166 call assert_fails("call hlset([{'name': 'NewHLGroup', 'ctermbg': []}])",
1167 \ 'E928:')
1168 call assert_fails("call hlset([{'name': 'NewHLGroup', 'ctermfg': []}])",
1169 \ 'E928:')
1170 call assert_fails("call hlset([{'name': 'NewHLGroup', 'ctermul': []}])",
1171 \ 'E928:')
1172 if has('gui')
1173 call assert_fails("call hlset([{'name': 'NewHLGroup', 'font': []}])",
1174 \ 'E928:')
1175 endif
1176 call assert_fails("call hlset([{'name': 'NewHLGroup', 'gui': 'Cyan'}])",
1177 \ 'E715:')
1178 call assert_fails("call hlset([{'name': 'NewHLGroup', 'guibg': []}])",
1179 \ 'E928:')
1180 call assert_fails("call hlset([{'name': 'NewHLGroup', 'guifg': []}])",
1181 \ 'E928:')
1182 call assert_fails("call hlset([{'name': 'NewHLGroup', 'guisp': []}])",
1183 \ 'E928:')
1184 call assert_fails("call hlset([{'name': 'NewHLGroup', 'linksto': []}])",
1185 \ 'E928:')
1186 call assert_fails("call hlset([{'name': 'NewHLGroup', 'start': []}])",
1187 \ 'E928:')
1188 call assert_fails("call hlset([{'name': 'NewHLGroup', 'stop': []}])",
1189 \ 'E928:')
1190 call assert_fails("call hlset([{'name': 'NewHLGroup', 'term': 'Cyan'}])",
1191 \ 'E715:')
1192 call assert_equal('Search', hlget('NewHLGroup')[0].linksto)
1193 highlight clear NewHLGroup
1194 END
Bram Moolenaar62aec932022-01-29 21:45:34 +00001195 call v9.CheckLegacyAndVim9Success(lines)
Yegappan Lakshmanand1a8d652021-11-03 21:56:45 +00001196
1197 " Test for clearing the 'term', 'cterm' and 'gui' attributes of a highlight
1198 " group.
1199 let lines =<< trim END
1200 highlight myhlg1 term=bold cterm=italic gui=standout
1201 VAR id = hlID('myhlg1')
1202 call hlset([{'name': 'myhlg1', 'term': {}}])
1203 call assert_equal([{'id': id, 'name': 'myhlg1',
1204 \ 'cterm': {'italic': v:true}, 'gui': {'standout': v:true}}],
1205 \ hlget('myhlg1'))
1206 call hlset([{'name': 'myhlg1', 'cterm': {}}])
1207 call assert_equal([{'id': id, 'name': 'myhlg1',
1208 \ 'gui': {'standout': v:true}}], hlget('myhlg1'))
1209 call hlset([{'name': 'myhlg1', 'gui': {}}])
1210 call assert_equal([{'id': id, 'name': 'myhlg1', 'cleared': v:true}],
1211 \ hlget('myhlg1'))
1212 highlight clear myhlg1
1213 END
Bram Moolenaar62aec932022-01-29 21:45:34 +00001214 call v9.CheckLegacyAndVim9Success(lines)
Yegappan Lakshmanand1a8d652021-11-03 21:56:45 +00001215
1216 " Test for setting all the 'term', 'cterm' and 'gui' attributes of a
1217 " highlight group
1218 let lines =<< trim END
Bram Moolenaar84f54632022-06-29 18:39:11 +01001219 VAR attr = {'bold': v:true, 'underline': v:true,
1220 \ 'undercurl': v:true, 'underdouble': v:true,
1221 \ 'underdotted': v:true, 'underdashed': v:true,
Yegappan Lakshmanand1a8d652021-11-03 21:56:45 +00001222 \ 'strikethrough': v:true, 'reverse': v:true, 'italic': v:true,
1223 \ 'standout': v:true, 'nocombine': v:true}
1224 call hlset([{'name': 'myhlg2', 'term': attr, 'cterm': attr, 'gui': attr}])
1225 VAR id2 = hlID('myhlg2')
Bram Moolenaar84f54632022-06-29 18:39:11 +01001226 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 +00001227 VAR output = execute('highlight myhlg2')
1228 LET output = output->split("\n")->join()->substitute('\s\+', ' ', 'g')
1229 call assert_equal(expected, output)
Yegappan Lakshmanand1a8d652021-11-03 21:56:45 +00001230 call assert_equal([{'id': id2, 'name': 'myhlg2', 'gui': attr,
1231 \ 'term': attr, 'cterm': attr}], hlget('myhlg2'))
1232 END
Bram Moolenaar62aec932022-01-29 21:45:34 +00001233 call v9.CheckLegacyAndVim9Success(lines)
Yegappan Lakshmanand1a8d652021-11-03 21:56:45 +00001234
1235 " Test for clearing some of the 'term', 'cterm' and 'gui' attributes of a
1236 " highlight group
1237 let lines =<< trim END
1238 VAR attr = {'bold': v:false, 'underline': v:true, 'strikethrough': v:true}
1239 call hlset([{'name': 'myhlg2', 'term': attr, 'cterm': attr, 'gui': attr}])
1240 VAR id2 = hlID('myhlg2')
Yegappan Lakshmanan2a16dc62021-11-16 17:19:30 +00001241 VAR expected = "myhlg2 xxx term=underline,strikethrough cterm=underline,strikethrough gui=underline,strikethrough"
1242 VAR output = execute('highlight myhlg2')
1243 LET output = output->split("\n")->join()->substitute('\s\+', ' ', 'g')
1244 call assert_equal(expected, output)
Yegappan Lakshmanand1a8d652021-11-03 21:56:45 +00001245 LET attr = {'underline': v:true, 'strikethrough': v:true}
1246 call assert_equal([{'id': id2, 'name': 'myhlg2', 'gui': attr,
1247 \ 'term': attr, 'cterm': attr}], hlget('myhlg2'))
1248 END
Bram Moolenaar62aec932022-01-29 21:45:34 +00001249 call v9.CheckLegacyAndVim9Success(lines)
Dominique Pelle6a950a62021-11-13 18:44:37 +00001250
Yegappan Lakshmanan2a16dc62021-11-16 17:19:30 +00001251 " Test for clearing the attributes and link of a highlight group
1252 let lines =<< trim END
1253 highlight myhlg3 ctermbg=green guibg=green
1254 highlight! default link myhlg3 ErrorMsg
1255 VAR id3 = hlID('myhlg3')
1256 call hlset([{'name': 'myhlg3', 'cleared': v:true, 'linksto': 'NONE'}])
1257 call assert_equal([{'id': id3, 'name': 'myhlg3', 'cleared': v:true}],
1258 \ hlget('myhlg3'))
1259 highlight clear hlg3
1260 END
Bram Moolenaar62aec932022-01-29 21:45:34 +00001261 call v9.CheckLegacyAndVim9Success(lines)
Yegappan Lakshmanan2a16dc62021-11-16 17:19:30 +00001262
1263 " Test for setting default attributes for a highlight group
1264 let lines =<< trim END
1265 call hlset([{'name': 'hlg4', 'ctermfg': '8'}])
1266 call hlset([{'name': 'hlg4', 'default': v:true, 'ctermfg': '9'}])
1267 VAR id4 = hlID('hlg4')
1268 call assert_equal([{'id': id4, 'name': 'hlg4', 'ctermfg': '8'}],
1269 \ hlget('hlg4'))
1270 highlight clear hlg4
1271
1272 call hlset([{'name': 'hlg5', 'default': v:true, 'ctermbg': '2'}])
1273 call hlset([{'name': 'hlg5', 'ctermbg': '4'}])
1274 VAR id5 = hlID('hlg5')
1275 call assert_equal([{'id': id5, 'name': 'hlg5', 'ctermbg': '4'}],
1276 \ hlget('hlg5'))
1277 highlight clear hlg5
1278
1279 call hlset([{'name': 'hlg6', 'linksto': 'Error'}])
1280 VAR id6 = hlID('hlg6')
1281 call hlset([{'name': 'hlg6', 'default': v:true, 'ctermbg': '2'}])
1282 call assert_equal([{'id': id6, 'name': 'hlg6', 'linksto': 'Error'}],
1283 \ hlget('hlg6'))
1284 highlight clear hlg6
1285 END
Bram Moolenaar62aec932022-01-29 21:45:34 +00001286 call v9.CheckLegacyAndVim9Success(lines)
Yegappan Lakshmanan2a16dc62021-11-16 17:19:30 +00001287
1288 " Test for setting default links for a highlight group
1289 let lines =<< trim END
1290 call hlset([{'name': 'hlg7', 'ctermfg': '5'}])
1291 call hlset([{'name': 'hlg7', 'default': v:true, 'linksto': 'Search'}])
1292 VAR id7 = hlID('hlg7')
1293 call assert_equal([{'id': id7, 'name': 'hlg7', 'ctermfg': '5'}],
1294 \ hlget('hlg7'))
1295 highlight clear hlg7
1296
1297 call hlset([{'name': 'hlg8', 'default': v:true, 'linksto': 'Search'}])
1298 VAR id8 = hlID('hlg8')
1299 call assert_equal([{'id': id8, 'name': 'hlg8', 'default': v:true,
1300 \ 'linksto': 'Search'}], hlget('hlg8'))
1301 call hlset([{'name': 'hlg8', 'ctermbg': '2'}])
1302 call assert_equal([{'id': id8, 'name': 'hlg8', 'ctermbg': '2'}],
1303 \ hlget('hlg8'))
1304 highlight clear hlg8
1305
1306 highlight default link hlg9 ErrorMsg
1307 VAR hlg_save = hlget('hlg9')
1308 LET hlg_save[0]['name'] = 'hlg9dup'
1309 call hlset(hlg_save)
1310 VAR id9 = hlID('hlg9dup')
1311 highlight clear hlg9dup
1312 call assert_equal([{'id': id9, 'name': 'hlg9dup', 'default': v:true,
1313 \ 'linksto': 'ErrorMsg'}], hlget('hlg9dup'))
1314 highlight clear hlg9
1315 END
Bram Moolenaar62aec932022-01-29 21:45:34 +00001316 call v9.CheckLegacyAndVim9Success(lines)
Yegappan Lakshmanan2a16dc62021-11-16 17:19:30 +00001317
1318 " Test for force creating a link to a highlight group
1319 let lines =<< trim END
1320 call hlset([{'name': 'hlg10', 'ctermfg': '8'}])
1321 call hlset([{'name': 'hlg10', 'linksto': 'Search'}])
1322 VAR id10 = hlID('hlg10')
1323 call assert_equal([{'id': id10, 'name': 'hlg10', 'ctermfg': '8'}],
1324 \ hlget('hlg10'))
1325 call hlset([{'name': 'hlg10', 'linksto': 'Search', 'force': v:true}])
1326 call assert_equal([{'id': id10, 'name': 'hlg10', 'ctermfg': '8',
1327 \ 'linksto': 'Search'}], hlget('hlg10'))
1328 highlight clear hlg10
1329 END
Bram Moolenaar62aec932022-01-29 21:45:34 +00001330 call v9.CheckLegacyAndVim9Success(lines)
Yegappan Lakshmananbb277fd2021-11-24 20:28:31 +00001331
1332 " Test for empty values of attributes
1333 call hlset([{'name': 'hlg11', 'cterm': {}}])
1334 call hlset([{'name': 'hlg11', 'ctermfg': ''}])
1335 call hlset([{'name': 'hlg11', 'ctermbg': ''}])
1336 call hlset([{'name': 'hlg11', 'ctermul': ''}])
PMuncha606f3a2023-11-15 15:35:49 +01001337 call hlset([{'name': 'hlg11', 'ctermfont': ''}])
Yegappan Lakshmananbb277fd2021-11-24 20:28:31 +00001338 call hlset([{'name': 'hlg11', 'font': ''}])
1339 call hlset([{'name': 'hlg11', 'gui': {}}])
1340 call hlset([{'name': 'hlg11', 'guifg': ''}])
1341 call hlset([{'name': 'hlg11', 'guibg': ''}])
1342 call hlset([{'name': 'hlg11', 'guisp': ''}])
1343 call hlset([{'name': 'hlg11', 'start': ''}])
1344 call hlset([{'name': 'hlg11', 'stop': ''}])
1345 call hlset([{'name': 'hlg11', 'term': {}}])
1346 call assert_true(hlget('hlg11')[0].cleared)
Yegappan Lakshmanand1a8d652021-11-03 21:56:45 +00001347endfunc
1348
Bram Moolenaaree4e0c12020-04-06 21:35:05 +02001349" vim: shiftwidth=2 sts=2 expandtab