blob: a8ef8028b75190b85552fd25500e18d6978f5c54 [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
Bram Moolenaar572a4432022-09-28 21:07:03 +0100747 call writefile(lines, 'Xtest_colorcolumn_srb', 'D')
Bram Moolenaarad5e5632020-09-15 20:52:26 +0200748 let buf = RunVimInTerminal('-S Xtest_colorcolumn_srb', {'rows': 10,'columns': 40})
749 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 Moolenaar6b528fa2019-05-09 20:07:33 +0200756" This test must come before the Test_cursorline test, as it appears this
757" defines the Normal highlighting group anyway.
Bram Moolenaarf90b6e02019-05-09 19:26:38 +0200758func Test_1_highlight_Normalgroup_exists()
Bram Moolenaar435f9f02019-07-03 21:40:16 +0200759 let hlNormal = HighlightArgs('Normal')
760 if !has('gui_running')
Bram Moolenaar6b528fa2019-05-09 20:07:33 +0200761 call assert_match('hi Normal\s*clear', hlNormal)
Bram Moolenaar435f9f02019-07-03 21:40:16 +0200762 elseif has('gui_gtk2') || has('gui_gnome') || has('gui_gtk3')
763 " expect is DEFAULT_FONT of gui_gtk_x11.c
764 call assert_match('hi Normal\s*font=Monospace 10', hlNormal)
Bram Moolenaar0b962e52022-04-03 18:02:37 +0100765 elseif has('gui_motif')
Bram Moolenaar435f9f02019-07-03 21:40:16 +0200766 " expect is DEFAULT_FONT of gui_x11.c
767 call assert_match('hi Normal\s*font=7x13', hlNormal)
768 elseif has('win32')
769 " expect any font
770 call assert_match('hi Normal\s*font=.*', hlNormal)
Bram Moolenaar6b528fa2019-05-09 20:07:33 +0200771 endif
Bram Moolenaarf90b6e02019-05-09 19:26:38 +0200772endfunc
Bram Moolenaar548be7f2019-06-29 03:42:42 +0200773
Bram Moolenaar3180fe62020-02-02 13:47:06 +0100774" Do this test last, sometimes restoring the columns doesn't work
Bram Moolenaaree4e0c12020-04-06 21:35:05 +0200775func Test_z_no_space_before_xxx()
Bram Moolenaar548be7f2019-06-29 03:42:42 +0200776 let l:org_columns = &columns
777 set columns=17
778 let l:hi_StatusLineTermNC = join(split(execute('hi StatusLineTermNC')))
779 call assert_match('StatusLineTermNC xxx', l:hi_StatusLineTermNC)
780 let &columns = l:org_columns
Bram Moolenaaree4e0c12020-04-06 21:35:05 +0200781endfunc
782
783" Test for :highlight command errors
784func Test_highlight_cmd_errors()
785 if has('gui_running')
786 " This test doesn't fail in the MS-Windows console version.
Bram Moolenaar75e15672020-06-28 13:10:22 +0200787 call assert_fails('hi Xcomment ctermbg=fg', 'E419:')
Bram Moolenaaree4e0c12020-04-06 21:35:05 +0200788 call assert_fails('hi Xcomment ctermfg=bg', 'E420:')
Bram Moolenaar75e15672020-06-28 13:10:22 +0200789 call assert_fails('hi Xcomment ctermfg=ul', 'E453:')
erw7f7f7aaf2021-12-07 21:29:20 +0000790 call assert_fails('hi ' .. repeat('a', 201) .. ' ctermfg=black', 'E1249:')
Bram Moolenaaree4e0c12020-04-06 21:35:05 +0200791 endif
792
793 " Try using a very long terminal code. Define a dummy terminal code for this
794 " test.
795 let &t_fo = "\<Esc>1;"
796 let c = repeat("t_fo,", 100) . "t_fo"
797 call assert_fails('exe "hi Xgroup1 start=" . c', 'E422:')
798 let &t_fo = ""
799endfunc
800
Bram Moolenaar75e15672020-06-28 13:10:22 +0200801" Test for 'highlight' option
802func Test_highlight_opt()
803 let save_hl = &highlight
804 call assert_fails('set highlight=j:b', 'E474:')
805 set highlight=f\ r
806 call assert_equal('f r', &highlight)
807 set highlight=fb
808 call assert_equal('fb', &highlight)
809 set highlight=fi
810 call assert_equal('fi', &highlight)
811 set highlight=f-
812 call assert_equal('f-', &highlight)
813 set highlight=fr
814 call assert_equal('fr', &highlight)
815 set highlight=fs
816 call assert_equal('fs', &highlight)
817 set highlight=fu
818 call assert_equal('fu', &highlight)
819 set highlight=fc
820 call assert_equal('fc', &highlight)
821 set highlight=ft
822 call assert_equal('ft', &highlight)
823 call assert_fails('set highlight=fr:Search', 'E474:')
824 set highlight=f:$#
825 call assert_match('W18:', v:statusmsg)
826 let &highlight = save_hl
827endfunc
828
829" Test for User group highlighting used in the statusline
830func Test_highlight_User()
831 CheckNotGui
832 hi User1 ctermfg=12
833 redraw!
834 call assert_equal('12', synIDattr(synIDtrans(hlID('User1')), 'fg'))
835 hi clear
836endfunc
837
838" Test for using RGB color values in a highlight group
Bram Moolenaar09fbedc2021-01-19 17:22:58 +0100839func Test_xxlast_highlight_RGB_color()
840 CheckCanRunGui
841 gui -f
Bram Moolenaar75e15672020-06-28 13:10:22 +0200842 hi MySearch guifg=#110000 guibg=#001100 guisp=#000011
843 call assert_equal('#110000', synIDattr(synIDtrans(hlID('MySearch')), 'fg#'))
844 call assert_equal('#001100', synIDattr(synIDtrans(hlID('MySearch')), 'bg#'))
845 call assert_equal('#000011', synIDattr(synIDtrans(hlID('MySearch')), 'sp#'))
846 hi clear
847endfunc
848
Bram Moolenaarde8f0f42020-06-30 18:45:43 +0200849" Test for using default highlighting group
850func Test_highlight_default()
851 highlight MySearch ctermfg=7
852 highlight default MySearch ctermfg=5
853 let hlSearch = HighlightArgs('MySearch')
854 call assert_match('ctermfg=7', hlSearch)
855
856 highlight default QFName ctermfg=3
857 call assert_match('ctermfg=3', HighlightArgs('QFName'))
858 hi clear
859endfunc
860
861" Test for 'ctermul in a highlight group
862func Test_highlight_ctermul()
863 CheckNotGui
864 call assert_notmatch('ctermul=', HighlightArgs('Normal'))
865 highlight Normal ctermul=3
866 call assert_match('ctermul=3', HighlightArgs('Normal'))
Bram Moolenaar391c3622020-09-29 20:59:17 +0200867 call assert_equal('3', synIDattr(synIDtrans(hlID('Normal')), 'ul'))
Bram Moolenaarde8f0f42020-06-30 18:45:43 +0200868 highlight Normal ctermul=NONE
869endfunc
870
871" Test for specifying 'start' and 'stop' in a highlight group
872func Test_highlight_start_stop()
873 hi HlGrp1 start=<Esc>[27h;<Esc>[<Space>r;
874 call assert_match("start=^[[27h;^[[ r;", HighlightArgs('HlGrp1'))
875 hi HlGrp1 start=NONE
876 call assert_notmatch("start=", HighlightArgs('HlGrp1'))
877 hi HlGrp2 stop=<Esc>[27h;<Esc>[<Space>r;
878 call assert_match("stop=^[[27h;^[[ r;", HighlightArgs('HlGrp2'))
879 hi HlGrp2 stop=NONE
880 call assert_notmatch("stop=", HighlightArgs('HlGrp2'))
Yegappan Lakshmanan5284b232023-03-04 19:57:32 +0000881 set t_xy=^[foo;
882 set t_xz=^[bar;
883 hi HlGrp3 start=t_xy stop=t_xz
884 let d = hlget('HlGrp3')
885 call assert_equal('^[foo;', d[0].start)
886 call assert_equal('^[bar;', d[0].stop)
887 set t_xy= t_xz=
Bram Moolenaarde8f0f42020-06-30 18:45:43 +0200888 hi clear
889endfunc
890
891" Test for setting various 'term' attributes
892func Test_highlight_term_attr()
Bram Moolenaar84f54632022-06-29 18:39:11 +0100893 hi HlGrp3 term=bold,underline,undercurl,underdouble,underdotted,underdashed,strikethrough,reverse,italic,standout
894 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 +0200895 hi HlGrp3 term=NONE
896 call assert_equal('hi HlGrp3 cleared', HighlightArgs('HlGrp3'))
897 hi clear
898endfunc
899
Bram Moolenaar213da552020-09-17 19:59:26 +0200900func Test_highlight_clear_restores_links()
901 let aaa_id = hlID('aaa')
902 call assert_equal(aaa_id, 0)
903
904 " create default link aaa --> bbb
905 hi def link aaa bbb
906 let id_aaa = hlID('aaa')
907 let hl_aaa_bbb = HighlightArgs('aaa')
908
909 " try to redefine default link aaa --> ccc; check aaa --> bbb
910 hi def link aaa ccc
911 call assert_equal(HighlightArgs('aaa'), hl_aaa_bbb)
912
913 " clear aaa; check aaa --> bbb
914 hi clear aaa
915 call assert_equal(HighlightArgs('aaa'), hl_aaa_bbb)
916
917 " link aaa --> ccc; clear aaa; check aaa --> bbb
918 hi link aaa ccc
919 let id_ccc = hlID('ccc')
920 call assert_equal(synIDtrans(id_aaa), id_ccc)
921 hi clear aaa
922 call assert_equal(HighlightArgs('aaa'), hl_aaa_bbb)
923
924 " forcibly set default link aaa --> ddd
925 hi! def link aaa ddd
926 let id_ddd = hlID('ddd')
927 let hl_aaa_ddd = HighlightArgs('aaa')
928 call assert_equal(synIDtrans(id_aaa), id_ddd)
929
930 " link aaa --> eee; clear aaa; check aaa --> ddd
931 hi link aaa eee
932 let eee_id = hlID('eee')
933 call assert_equal(synIDtrans(id_aaa), eee_id)
934 hi clear aaa
935 call assert_equal(HighlightArgs('aaa'), hl_aaa_ddd)
936endfunc
937
Bram Moolenaare8df0102020-09-18 19:40:45 +0200938func Test_highlight_clear_restores_context()
939 func FuncContextDefault()
940 hi def link Context ContextDefault
941 endfun
942
943 func FuncContextRelink()
944 " Dummy line
945 hi link Context ContextRelink
946 endfunc
947
948 let scriptContextDefault = MakeScript("FuncContextDefault")
949 let scriptContextRelink = MakeScript("FuncContextRelink")
950 let patContextDefault = fnamemodify(scriptContextDefault, ':t') .. ' line 1'
951 let patContextRelink = fnamemodify(scriptContextRelink, ':t') .. ' line 2'
952
Bram Moolenaar2bbada82020-09-18 21:55:26 +0200953 exec 'source ' .. scriptContextDefault
Bram Moolenaare8df0102020-09-18 19:40:45 +0200954 let hlContextDefault = execute("verbose hi Context")
955 call assert_match(patContextDefault, hlContextDefault)
956
Bram Moolenaar2bbada82020-09-18 21:55:26 +0200957 exec 'source ' .. scriptContextRelink
Bram Moolenaare8df0102020-09-18 19:40:45 +0200958 let hlContextRelink = execute("verbose hi Context")
959 call assert_match(patContextRelink, hlContextRelink)
960
961 hi clear
962 let hlContextAfterClear = execute("verbose hi Context")
963 call assert_match(patContextDefault, hlContextAfterClear)
964
965 delfunc FuncContextDefault
966 delfunc FuncContextRelink
967 call delete(scriptContextDefault)
968 call delete(scriptContextRelink)
969endfunc
970
Bram Moolenaar213da552020-09-17 19:59:26 +0200971func Test_highlight_default_colorscheme_restores_links()
972 hi link TestLink Identifier
973 hi TestHi ctermbg=red
Bram Moolenaar05eb5b92020-09-16 15:43:21 +0200974
975 let hlTestLinkPre = HighlightArgs('TestLink')
976 let hlTestHiPre = HighlightArgs('TestHi')
977
978 " Test colorscheme
Dominique Pelle8bfa0eb2022-01-02 16:16:33 +0000979 call assert_equal("\ndefault", execute('colorscheme'))
Bram Moolenaar05eb5b92020-09-16 15:43:21 +0200980 hi clear
981 if exists('syntax_on')
982 syntax reset
983 endif
984 let g:colors_name = 'test'
Dominique Pelle8bfa0eb2022-01-02 16:16:33 +0000985 call assert_equal("\ntest", execute('colorscheme'))
Bram Moolenaar213da552020-09-17 19:59:26 +0200986 hi link TestLink ErrorMsg
987 hi TestHi ctermbg=green
Bram Moolenaar05eb5b92020-09-16 15:43:21 +0200988
989 " Restore default highlighting
990 colorscheme default
Bram Moolenaar05eb5b92020-09-16 15:43:21 +0200991 " 'default' should work no matter if highlight group was cleared
Dominique Pelle8bfa0eb2022-01-02 16:16:33 +0000992 call assert_equal("\ndefault", execute('colorscheme'))
Bram Moolenaar05eb5b92020-09-16 15:43:21 +0200993 hi def link TestLink Identifier
994 hi def TestHi ctermbg=red
Bram Moolenaar05eb5b92020-09-16 15:43:21 +0200995 let hlTestLinkPost = HighlightArgs('TestLink')
996 let hlTestHiPost = HighlightArgs('TestHi')
Bram Moolenaar05eb5b92020-09-16 15:43:21 +0200997 call assert_equal(hlTestLinkPre, hlTestLinkPost)
998 call assert_equal(hlTestHiPre, hlTestHiPost)
999 hi clear
1000endfunc
1001
Drew Vogele30d1022021-10-24 20:35:07 +01001002func Test_colornames_assignment_and_lookup()
Drew Vogela0fca172021-11-13 10:50:01 +00001003 CheckAnyOf Feature:gui_running Feature:termguicolors
1004
Drew Vogele30d1022021-10-24 20:35:07 +01001005 " Ensure highlight command can find custom color.
1006 let v:colornames['a redish white'] = '#ffeedd'
1007 highlight Normal guifg='a redish white'
1008 highlight clear
Drew Vogela0fca172021-11-13 10:50:01 +00001009 call ClearDict(v:colornames)
Drew Vogele30d1022021-10-24 20:35:07 +01001010endfunc
1011
1012func Test_colornames_default_list()
Drew Vogela0fca172021-11-13 10:50:01 +00001013 CheckAnyOf Feature:gui_running Feature:termguicolors
1014
Drew Vogele30d1022021-10-24 20:35:07 +01001015 " Ensure default lists are loaded automatically and can be used for all gui fields.
Drew Vogela0fca172021-11-13 10:50:01 +00001016 call assert_equal(0, len(v:colornames))
Drew Vogele30d1022021-10-24 20:35:07 +01001017 highlight Normal guifg='rebecca purple' guibg='rebecca purple' guisp='rebecca purple'
Drew Vogela0fca172021-11-13 10:50:01 +00001018 call assert_notequal(0, len(v:colornames))
1019 echo v:colornames['rebecca purple']
Drew Vogele30d1022021-10-24 20:35:07 +01001020 highlight clear
Drew Vogela0fca172021-11-13 10:50:01 +00001021 call ClearDict(v:colornames)
Drew Vogele30d1022021-10-24 20:35:07 +01001022endfunc
1023
1024func Test_colornames_overwrite_default()
Drew Vogela0fca172021-11-13 10:50:01 +00001025 CheckAnyOf Feature:gui_running Feature:termguicolors
1026
Drew Vogele30d1022021-10-24 20:35:07 +01001027 " Ensure entries in v:colornames can be overwritten.
1028 " Load default color scheme to trigger default color list loading.
1029 colorscheme default
1030 let old_rebecca_purple = v:colornames['rebecca purple']
1031 highlight Normal guifg='rebecca purple' guibg='rebecca purple'
1032 let v:colornames['rebecca purple'] = '#550099'
1033 highlight Normal guifg='rebecca purple' guibg='rebecca purple'
1034 let v:colornames['rebecca purple'] = old_rebecca_purple
1035 highlight clear
1036endfunc
1037
1038func Test_colornames_assignment_and_unassignment()
Drew Vogela0fca172021-11-13 10:50:01 +00001039 " No feature check is needed for this test because the v:colornames dict
1040 " always exists with +eval. The feature checks are only required for
1041 " commands that do color lookup.
1042
Drew Vogele30d1022021-10-24 20:35:07 +01001043 " Ensure we cannot overwrite the v:colornames dict.
1044 call assert_fails("let v:colornames = {}", 'E46:')
1045
1046 " Ensure we can delete entries from the v:colornames dict.
1047 let v:colornames['x1'] = '#111111'
1048 call assert_equal(v:colornames['x1'], '#111111')
1049 unlet v:colornames['x1']
1050 call assert_fails("echo v:colornames['x1']")
1051endfunc
1052
Yegappan Lakshmanand1a8d652021-11-03 21:56:45 +00001053" Test for the hlget() function
1054func Test_hlget()
1055 let lines =<< trim END
1056 call assert_notequal([], filter(hlget(), 'v:val.name == "Visual"'))
1057 call assert_equal([], hlget('SomeHLGroup'))
1058 highlight MyHLGroup term=standout cterm=reverse ctermfg=10 ctermbg=Black
1059 call assert_equal([{'id': hlID('MyHLGroup'), 'ctermfg': '10', 'name': 'MyHLGroup', 'term': {'standout': v:true}, 'ctermbg': '0', 'cterm': {'reverse': v:true}}], hlget('MyHLGroup'))
1060 highlight clear MyHLGroup
1061 call assert_equal(v:true, hlget('MyHLGroup')[0].cleared)
1062 highlight link MyHLGroup IncSearch
1063 call assert_equal('IncSearch', hlget('MyHLGroup')[0].linksto)
1064 highlight clear MyHLGroup
1065 call assert_equal([], hlget(test_null_string()))
1066 call assert_equal([], hlget(""))
1067 END
Bram Moolenaar62aec932022-01-29 21:45:34 +00001068 call v9.CheckLegacyAndVim9Success(lines)
Yegappan Lakshmanand1a8d652021-11-03 21:56:45 +00001069
1070 " Test for resolving highlight group links
1071 let lines =<< trim END
1072 highlight hlgA term=bold
1073 VAR hlgAid = hlID('hlgA')
1074 highlight link hlgB hlgA
1075 VAR hlgBid = hlID('hlgB')
1076 highlight link hlgC hlgB
1077 VAR hlgCid = hlID('hlgC')
1078 call assert_equal('hlgA', hlget('hlgB')[0].linksto)
1079 call assert_equal('hlgB', hlget('hlgC')[0].linksto)
1080 call assert_equal([{'id': hlgAid, 'name': 'hlgA',
1081 \ 'term': {'bold': v:true}}], hlget('hlgA'))
1082 call assert_equal([{'id': hlgBid, 'name': 'hlgB',
1083 \ 'linksto': 'hlgA'}], hlget('hlgB'))
1084 call assert_equal([{'id': hlgCid, 'name': 'hlgC',
1085 \ 'linksto': 'hlgB'}], hlget('hlgC'))
1086 call assert_equal([{'id': hlgAid, 'name': 'hlgA',
1087 \ 'term': {'bold': v:true}}], hlget('hlgA', v:false))
1088 call assert_equal([{'id': hlgBid, 'name': 'hlgB',
1089 \ 'linksto': 'hlgA'}], hlget('hlgB', 0))
1090 call assert_equal([{'id': hlgCid, 'name': 'hlgC',
1091 \ 'linksto': 'hlgB'}], hlget('hlgC', v:false))
1092 call assert_equal([{'id': hlgAid, 'name': 'hlgA',
1093 \ 'term': {'bold': v:true}}], hlget('hlgA', v:true))
1094 call assert_equal([{'id': hlgBid, 'name': 'hlgB',
1095 \ 'term': {'bold': v:true}}], hlget('hlgB', 1))
1096 call assert_equal([{'id': hlgCid, 'name': 'hlgC',
1097 \ 'term': {'bold': v:true}}], hlget('hlgC', v:true))
1098 END
Bram Moolenaar62aec932022-01-29 21:45:34 +00001099 call v9.CheckLegacyAndVim9Success(lines)
Yegappan Lakshmanand1a8d652021-11-03 21:56:45 +00001100
1101 call assert_fails('call hlget([])', 'E1174:')
1102 call assert_fails('call hlget("abc", "xyz")', 'E1212:')
1103endfunc
1104
1105" Test for the hlset() function
1106func Test_hlset()
1107 let lines =<< trim END
1108 call assert_equal(0, hlset(test_null_list()))
1109 call assert_equal(0, hlset([]))
1110 call assert_fails('call hlset(["Search"])', 'E715:')
1111 call hlset(hlget())
1112 call hlset([{'name': 'NewHLGroup', 'cterm': {'reverse': v:true}, 'ctermfg': '10'}])
1113 call assert_equal({'reverse': v:true}, hlget('NewHLGroup')[0].cterm)
1114 call hlset([{'name': 'NewHLGroup', 'cterm': {'bold': v:true}}])
1115 call assert_equal({'bold': v:true}, hlget('NewHLGroup')[0].cterm)
1116 call hlset([{'name': 'NewHLGroup', 'cleared': v:true}])
1117 call assert_equal(v:true, hlget('NewHLGroup')[0].cleared)
1118 call hlset([{'name': 'NewHLGroup', 'linksto': 'Search'}])
1119 call assert_false(has_key(hlget('NewHLGroup')[0], 'cleared'))
1120 call assert_equal('Search', hlget('NewHLGroup')[0].linksto)
1121 call assert_fails("call hlset([{'name': [], 'ctermfg': '10'}])", 'E928:')
1122 call assert_fails("call hlset([{'name': 'NewHLGroup', 'cleared': []}])",
1123 \ 'E745:')
1124 call assert_fails("call hlset([{'name': 'NewHLGroup', 'cterm': 'Blue'}])",
1125 \ 'E715:')
1126 call assert_fails("call hlset([{'name': 'NewHLGroup', 'ctermbg': []}])",
1127 \ 'E928:')
1128 call assert_fails("call hlset([{'name': 'NewHLGroup', 'ctermfg': []}])",
1129 \ 'E928:')
1130 call assert_fails("call hlset([{'name': 'NewHLGroup', 'ctermul': []}])",
1131 \ 'E928:')
1132 if has('gui')
1133 call assert_fails("call hlset([{'name': 'NewHLGroup', 'font': []}])",
1134 \ 'E928:')
1135 endif
1136 call assert_fails("call hlset([{'name': 'NewHLGroup', 'gui': 'Cyan'}])",
1137 \ 'E715:')
1138 call assert_fails("call hlset([{'name': 'NewHLGroup', 'guibg': []}])",
1139 \ 'E928:')
1140 call assert_fails("call hlset([{'name': 'NewHLGroup', 'guifg': []}])",
1141 \ 'E928:')
1142 call assert_fails("call hlset([{'name': 'NewHLGroup', 'guisp': []}])",
1143 \ 'E928:')
1144 call assert_fails("call hlset([{'name': 'NewHLGroup', 'linksto': []}])",
1145 \ 'E928:')
1146 call assert_fails("call hlset([{'name': 'NewHLGroup', 'start': []}])",
1147 \ 'E928:')
1148 call assert_fails("call hlset([{'name': 'NewHLGroup', 'stop': []}])",
1149 \ 'E928:')
1150 call assert_fails("call hlset([{'name': 'NewHLGroup', 'term': 'Cyan'}])",
1151 \ 'E715:')
1152 call assert_equal('Search', hlget('NewHLGroup')[0].linksto)
1153 highlight clear NewHLGroup
1154 END
Bram Moolenaar62aec932022-01-29 21:45:34 +00001155 call v9.CheckLegacyAndVim9Success(lines)
Yegappan Lakshmanand1a8d652021-11-03 21:56:45 +00001156
1157 " Test for clearing the 'term', 'cterm' and 'gui' attributes of a highlight
1158 " group.
1159 let lines =<< trim END
1160 highlight myhlg1 term=bold cterm=italic gui=standout
1161 VAR id = hlID('myhlg1')
1162 call hlset([{'name': 'myhlg1', 'term': {}}])
1163 call assert_equal([{'id': id, 'name': 'myhlg1',
1164 \ 'cterm': {'italic': v:true}, 'gui': {'standout': v:true}}],
1165 \ hlget('myhlg1'))
1166 call hlset([{'name': 'myhlg1', 'cterm': {}}])
1167 call assert_equal([{'id': id, 'name': 'myhlg1',
1168 \ 'gui': {'standout': v:true}}], hlget('myhlg1'))
1169 call hlset([{'name': 'myhlg1', 'gui': {}}])
1170 call assert_equal([{'id': id, 'name': 'myhlg1', 'cleared': v:true}],
1171 \ hlget('myhlg1'))
1172 highlight clear myhlg1
1173 END
Bram Moolenaar62aec932022-01-29 21:45:34 +00001174 call v9.CheckLegacyAndVim9Success(lines)
Yegappan Lakshmanand1a8d652021-11-03 21:56:45 +00001175
1176 " Test for setting all the 'term', 'cterm' and 'gui' attributes of a
1177 " highlight group
1178 let lines =<< trim END
Bram Moolenaar84f54632022-06-29 18:39:11 +01001179 VAR attr = {'bold': v:true, 'underline': v:true,
1180 \ 'undercurl': v:true, 'underdouble': v:true,
1181 \ 'underdotted': v:true, 'underdashed': v:true,
Yegappan Lakshmanand1a8d652021-11-03 21:56:45 +00001182 \ 'strikethrough': v:true, 'reverse': v:true, 'italic': v:true,
1183 \ 'standout': v:true, 'nocombine': v:true}
1184 call hlset([{'name': 'myhlg2', 'term': attr, 'cterm': attr, 'gui': attr}])
1185 VAR id2 = hlID('myhlg2')
Bram Moolenaar84f54632022-06-29 18:39:11 +01001186 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 +00001187 VAR output = execute('highlight myhlg2')
1188 LET output = output->split("\n")->join()->substitute('\s\+', ' ', 'g')
1189 call assert_equal(expected, output)
Yegappan Lakshmanand1a8d652021-11-03 21:56:45 +00001190 call assert_equal([{'id': id2, 'name': 'myhlg2', 'gui': attr,
1191 \ 'term': attr, 'cterm': attr}], hlget('myhlg2'))
1192 END
Bram Moolenaar62aec932022-01-29 21:45:34 +00001193 call v9.CheckLegacyAndVim9Success(lines)
Yegappan Lakshmanand1a8d652021-11-03 21:56:45 +00001194
1195 " Test for clearing some of the 'term', 'cterm' and 'gui' attributes of a
1196 " highlight group
1197 let lines =<< trim END
1198 VAR attr = {'bold': v:false, 'underline': v:true, 'strikethrough': v:true}
1199 call hlset([{'name': 'myhlg2', 'term': attr, 'cterm': attr, 'gui': attr}])
1200 VAR id2 = hlID('myhlg2')
Yegappan Lakshmanan2a16dc62021-11-16 17:19:30 +00001201 VAR expected = "myhlg2 xxx term=underline,strikethrough cterm=underline,strikethrough gui=underline,strikethrough"
1202 VAR output = execute('highlight myhlg2')
1203 LET output = output->split("\n")->join()->substitute('\s\+', ' ', 'g')
1204 call assert_equal(expected, output)
Yegappan Lakshmanand1a8d652021-11-03 21:56:45 +00001205 LET attr = {'underline': v:true, 'strikethrough': v:true}
1206 call assert_equal([{'id': id2, 'name': 'myhlg2', 'gui': attr,
1207 \ 'term': attr, 'cterm': attr}], hlget('myhlg2'))
1208 END
Bram Moolenaar62aec932022-01-29 21:45:34 +00001209 call v9.CheckLegacyAndVim9Success(lines)
Dominique Pelle6a950a62021-11-13 18:44:37 +00001210
Yegappan Lakshmanan2a16dc62021-11-16 17:19:30 +00001211 " Test for clearing the attributes and link of a highlight group
1212 let lines =<< trim END
1213 highlight myhlg3 ctermbg=green guibg=green
1214 highlight! default link myhlg3 ErrorMsg
1215 VAR id3 = hlID('myhlg3')
1216 call hlset([{'name': 'myhlg3', 'cleared': v:true, 'linksto': 'NONE'}])
1217 call assert_equal([{'id': id3, 'name': 'myhlg3', 'cleared': v:true}],
1218 \ hlget('myhlg3'))
1219 highlight clear hlg3
1220 END
Bram Moolenaar62aec932022-01-29 21:45:34 +00001221 call v9.CheckLegacyAndVim9Success(lines)
Yegappan Lakshmanan2a16dc62021-11-16 17:19:30 +00001222
1223 " Test for setting default attributes for a highlight group
1224 let lines =<< trim END
1225 call hlset([{'name': 'hlg4', 'ctermfg': '8'}])
1226 call hlset([{'name': 'hlg4', 'default': v:true, 'ctermfg': '9'}])
1227 VAR id4 = hlID('hlg4')
1228 call assert_equal([{'id': id4, 'name': 'hlg4', 'ctermfg': '8'}],
1229 \ hlget('hlg4'))
1230 highlight clear hlg4
1231
1232 call hlset([{'name': 'hlg5', 'default': v:true, 'ctermbg': '2'}])
1233 call hlset([{'name': 'hlg5', 'ctermbg': '4'}])
1234 VAR id5 = hlID('hlg5')
1235 call assert_equal([{'id': id5, 'name': 'hlg5', 'ctermbg': '4'}],
1236 \ hlget('hlg5'))
1237 highlight clear hlg5
1238
1239 call hlset([{'name': 'hlg6', 'linksto': 'Error'}])
1240 VAR id6 = hlID('hlg6')
1241 call hlset([{'name': 'hlg6', 'default': v:true, 'ctermbg': '2'}])
1242 call assert_equal([{'id': id6, 'name': 'hlg6', 'linksto': 'Error'}],
1243 \ hlget('hlg6'))
1244 highlight clear hlg6
1245 END
Bram Moolenaar62aec932022-01-29 21:45:34 +00001246 call v9.CheckLegacyAndVim9Success(lines)
Yegappan Lakshmanan2a16dc62021-11-16 17:19:30 +00001247
1248 " Test for setting default links for a highlight group
1249 let lines =<< trim END
1250 call hlset([{'name': 'hlg7', 'ctermfg': '5'}])
1251 call hlset([{'name': 'hlg7', 'default': v:true, 'linksto': 'Search'}])
1252 VAR id7 = hlID('hlg7')
1253 call assert_equal([{'id': id7, 'name': 'hlg7', 'ctermfg': '5'}],
1254 \ hlget('hlg7'))
1255 highlight clear hlg7
1256
1257 call hlset([{'name': 'hlg8', 'default': v:true, 'linksto': 'Search'}])
1258 VAR id8 = hlID('hlg8')
1259 call assert_equal([{'id': id8, 'name': 'hlg8', 'default': v:true,
1260 \ 'linksto': 'Search'}], hlget('hlg8'))
1261 call hlset([{'name': 'hlg8', 'ctermbg': '2'}])
1262 call assert_equal([{'id': id8, 'name': 'hlg8', 'ctermbg': '2'}],
1263 \ hlget('hlg8'))
1264 highlight clear hlg8
1265
1266 highlight default link hlg9 ErrorMsg
1267 VAR hlg_save = hlget('hlg9')
1268 LET hlg_save[0]['name'] = 'hlg9dup'
1269 call hlset(hlg_save)
1270 VAR id9 = hlID('hlg9dup')
1271 highlight clear hlg9dup
1272 call assert_equal([{'id': id9, 'name': 'hlg9dup', 'default': v:true,
1273 \ 'linksto': 'ErrorMsg'}], hlget('hlg9dup'))
1274 highlight clear hlg9
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 force creating a link to a highlight group
1279 let lines =<< trim END
1280 call hlset([{'name': 'hlg10', 'ctermfg': '8'}])
1281 call hlset([{'name': 'hlg10', 'linksto': 'Search'}])
1282 VAR id10 = hlID('hlg10')
1283 call assert_equal([{'id': id10, 'name': 'hlg10', 'ctermfg': '8'}],
1284 \ hlget('hlg10'))
1285 call hlset([{'name': 'hlg10', 'linksto': 'Search', 'force': v:true}])
1286 call assert_equal([{'id': id10, 'name': 'hlg10', 'ctermfg': '8',
1287 \ 'linksto': 'Search'}], hlget('hlg10'))
1288 highlight clear hlg10
1289 END
Bram Moolenaar62aec932022-01-29 21:45:34 +00001290 call v9.CheckLegacyAndVim9Success(lines)
Yegappan Lakshmananbb277fd2021-11-24 20:28:31 +00001291
1292 " Test for empty values of attributes
1293 call hlset([{'name': 'hlg11', 'cterm': {}}])
1294 call hlset([{'name': 'hlg11', 'ctermfg': ''}])
1295 call hlset([{'name': 'hlg11', 'ctermbg': ''}])
1296 call hlset([{'name': 'hlg11', 'ctermul': ''}])
1297 call hlset([{'name': 'hlg11', 'font': ''}])
1298 call hlset([{'name': 'hlg11', 'gui': {}}])
1299 call hlset([{'name': 'hlg11', 'guifg': ''}])
1300 call hlset([{'name': 'hlg11', 'guibg': ''}])
1301 call hlset([{'name': 'hlg11', 'guisp': ''}])
1302 call hlset([{'name': 'hlg11', 'start': ''}])
1303 call hlset([{'name': 'hlg11', 'stop': ''}])
1304 call hlset([{'name': 'hlg11', 'term': {}}])
1305 call assert_true(hlget('hlg11')[0].cleared)
Yegappan Lakshmanand1a8d652021-11-03 21:56:45 +00001306endfunc
1307
Bram Moolenaaree4e0c12020-04-06 21:35:05 +02001308" vim: shiftwidth=2 sts=2 expandtab