blob: feccf84b6cd331c6006881a2974eb0f0fb8e98ae [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'))
881 hi clear
882endfunc
883
884" Test for setting various 'term' attributes
885func Test_highlight_term_attr()
Bram Moolenaar84f54632022-06-29 18:39:11 +0100886 hi HlGrp3 term=bold,underline,undercurl,underdouble,underdotted,underdashed,strikethrough,reverse,italic,standout
887 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 +0200888 hi HlGrp3 term=NONE
889 call assert_equal('hi HlGrp3 cleared', HighlightArgs('HlGrp3'))
890 hi clear
891endfunc
892
Bram Moolenaar213da552020-09-17 19:59:26 +0200893func Test_highlight_clear_restores_links()
894 let aaa_id = hlID('aaa')
895 call assert_equal(aaa_id, 0)
896
897 " create default link aaa --> bbb
898 hi def link aaa bbb
899 let id_aaa = hlID('aaa')
900 let hl_aaa_bbb = HighlightArgs('aaa')
901
902 " try to redefine default link aaa --> ccc; check aaa --> bbb
903 hi def link aaa ccc
904 call assert_equal(HighlightArgs('aaa'), hl_aaa_bbb)
905
906 " clear aaa; check aaa --> bbb
907 hi clear aaa
908 call assert_equal(HighlightArgs('aaa'), hl_aaa_bbb)
909
910 " link aaa --> ccc; clear aaa; check aaa --> bbb
911 hi link aaa ccc
912 let id_ccc = hlID('ccc')
913 call assert_equal(synIDtrans(id_aaa), id_ccc)
914 hi clear aaa
915 call assert_equal(HighlightArgs('aaa'), hl_aaa_bbb)
916
917 " forcibly set default link aaa --> ddd
918 hi! def link aaa ddd
919 let id_ddd = hlID('ddd')
920 let hl_aaa_ddd = HighlightArgs('aaa')
921 call assert_equal(synIDtrans(id_aaa), id_ddd)
922
923 " link aaa --> eee; clear aaa; check aaa --> ddd
924 hi link aaa eee
925 let eee_id = hlID('eee')
926 call assert_equal(synIDtrans(id_aaa), eee_id)
927 hi clear aaa
928 call assert_equal(HighlightArgs('aaa'), hl_aaa_ddd)
929endfunc
930
Bram Moolenaare8df0102020-09-18 19:40:45 +0200931func Test_highlight_clear_restores_context()
932 func FuncContextDefault()
933 hi def link Context ContextDefault
934 endfun
935
936 func FuncContextRelink()
937 " Dummy line
938 hi link Context ContextRelink
939 endfunc
940
941 let scriptContextDefault = MakeScript("FuncContextDefault")
942 let scriptContextRelink = MakeScript("FuncContextRelink")
943 let patContextDefault = fnamemodify(scriptContextDefault, ':t') .. ' line 1'
944 let patContextRelink = fnamemodify(scriptContextRelink, ':t') .. ' line 2'
945
Bram Moolenaar2bbada82020-09-18 21:55:26 +0200946 exec 'source ' .. scriptContextDefault
Bram Moolenaare8df0102020-09-18 19:40:45 +0200947 let hlContextDefault = execute("verbose hi Context")
948 call assert_match(patContextDefault, hlContextDefault)
949
Bram Moolenaar2bbada82020-09-18 21:55:26 +0200950 exec 'source ' .. scriptContextRelink
Bram Moolenaare8df0102020-09-18 19:40:45 +0200951 let hlContextRelink = execute("verbose hi Context")
952 call assert_match(patContextRelink, hlContextRelink)
953
954 hi clear
955 let hlContextAfterClear = execute("verbose hi Context")
956 call assert_match(patContextDefault, hlContextAfterClear)
957
958 delfunc FuncContextDefault
959 delfunc FuncContextRelink
960 call delete(scriptContextDefault)
961 call delete(scriptContextRelink)
962endfunc
963
Bram Moolenaar213da552020-09-17 19:59:26 +0200964func Test_highlight_default_colorscheme_restores_links()
965 hi link TestLink Identifier
966 hi TestHi ctermbg=red
Bram Moolenaar05eb5b92020-09-16 15:43:21 +0200967
968 let hlTestLinkPre = HighlightArgs('TestLink')
969 let hlTestHiPre = HighlightArgs('TestHi')
970
971 " Test colorscheme
Dominique Pelle8bfa0eb2022-01-02 16:16:33 +0000972 call assert_equal("\ndefault", execute('colorscheme'))
Bram Moolenaar05eb5b92020-09-16 15:43:21 +0200973 hi clear
974 if exists('syntax_on')
975 syntax reset
976 endif
977 let g:colors_name = 'test'
Dominique Pelle8bfa0eb2022-01-02 16:16:33 +0000978 call assert_equal("\ntest", execute('colorscheme'))
Bram Moolenaar213da552020-09-17 19:59:26 +0200979 hi link TestLink ErrorMsg
980 hi TestHi ctermbg=green
Bram Moolenaar05eb5b92020-09-16 15:43:21 +0200981
982 " Restore default highlighting
983 colorscheme default
Bram Moolenaar05eb5b92020-09-16 15:43:21 +0200984 " 'default' should work no matter if highlight group was cleared
Dominique Pelle8bfa0eb2022-01-02 16:16:33 +0000985 call assert_equal("\ndefault", execute('colorscheme'))
Bram Moolenaar05eb5b92020-09-16 15:43:21 +0200986 hi def link TestLink Identifier
987 hi def TestHi ctermbg=red
Bram Moolenaar05eb5b92020-09-16 15:43:21 +0200988 let hlTestLinkPost = HighlightArgs('TestLink')
989 let hlTestHiPost = HighlightArgs('TestHi')
Bram Moolenaar05eb5b92020-09-16 15:43:21 +0200990 call assert_equal(hlTestLinkPre, hlTestLinkPost)
991 call assert_equal(hlTestHiPre, hlTestHiPost)
992 hi clear
993endfunc
994
Drew Vogele30d1022021-10-24 20:35:07 +0100995func Test_colornames_assignment_and_lookup()
Drew Vogela0fca172021-11-13 10:50:01 +0000996 CheckAnyOf Feature:gui_running Feature:termguicolors
997
Drew Vogele30d1022021-10-24 20:35:07 +0100998 " Ensure highlight command can find custom color.
999 let v:colornames['a redish white'] = '#ffeedd'
1000 highlight Normal guifg='a redish white'
1001 highlight clear
Drew Vogela0fca172021-11-13 10:50:01 +00001002 call ClearDict(v:colornames)
Drew Vogele30d1022021-10-24 20:35:07 +01001003endfunc
1004
1005func Test_colornames_default_list()
Drew Vogela0fca172021-11-13 10:50:01 +00001006 CheckAnyOf Feature:gui_running Feature:termguicolors
1007
Drew Vogele30d1022021-10-24 20:35:07 +01001008 " Ensure default lists are loaded automatically and can be used for all gui fields.
Drew Vogela0fca172021-11-13 10:50:01 +00001009 call assert_equal(0, len(v:colornames))
Drew Vogele30d1022021-10-24 20:35:07 +01001010 highlight Normal guifg='rebecca purple' guibg='rebecca purple' guisp='rebecca purple'
Drew Vogela0fca172021-11-13 10:50:01 +00001011 call assert_notequal(0, len(v:colornames))
1012 echo v:colornames['rebecca purple']
Drew Vogele30d1022021-10-24 20:35:07 +01001013 highlight clear
Drew Vogela0fca172021-11-13 10:50:01 +00001014 call ClearDict(v:colornames)
Drew Vogele30d1022021-10-24 20:35:07 +01001015endfunc
1016
1017func Test_colornames_overwrite_default()
Drew Vogela0fca172021-11-13 10:50:01 +00001018 CheckAnyOf Feature:gui_running Feature:termguicolors
1019
Drew Vogele30d1022021-10-24 20:35:07 +01001020 " Ensure entries in v:colornames can be overwritten.
1021 " Load default color scheme to trigger default color list loading.
1022 colorscheme default
1023 let old_rebecca_purple = v:colornames['rebecca purple']
1024 highlight Normal guifg='rebecca purple' guibg='rebecca purple'
1025 let v:colornames['rebecca purple'] = '#550099'
1026 highlight Normal guifg='rebecca purple' guibg='rebecca purple'
1027 let v:colornames['rebecca purple'] = old_rebecca_purple
1028 highlight clear
1029endfunc
1030
1031func Test_colornames_assignment_and_unassignment()
Drew Vogela0fca172021-11-13 10:50:01 +00001032 " No feature check is needed for this test because the v:colornames dict
1033 " always exists with +eval. The feature checks are only required for
1034 " commands that do color lookup.
1035
Drew Vogele30d1022021-10-24 20:35:07 +01001036 " Ensure we cannot overwrite the v:colornames dict.
1037 call assert_fails("let v:colornames = {}", 'E46:')
1038
1039 " Ensure we can delete entries from the v:colornames dict.
1040 let v:colornames['x1'] = '#111111'
1041 call assert_equal(v:colornames['x1'], '#111111')
1042 unlet v:colornames['x1']
1043 call assert_fails("echo v:colornames['x1']")
1044endfunc
1045
Yegappan Lakshmanand1a8d652021-11-03 21:56:45 +00001046" Test for the hlget() function
1047func Test_hlget()
1048 let lines =<< trim END
1049 call assert_notequal([], filter(hlget(), 'v:val.name == "Visual"'))
1050 call assert_equal([], hlget('SomeHLGroup'))
1051 highlight MyHLGroup term=standout cterm=reverse ctermfg=10 ctermbg=Black
1052 call assert_equal([{'id': hlID('MyHLGroup'), 'ctermfg': '10', 'name': 'MyHLGroup', 'term': {'standout': v:true}, 'ctermbg': '0', 'cterm': {'reverse': v:true}}], hlget('MyHLGroup'))
1053 highlight clear MyHLGroup
1054 call assert_equal(v:true, hlget('MyHLGroup')[0].cleared)
1055 highlight link MyHLGroup IncSearch
1056 call assert_equal('IncSearch', hlget('MyHLGroup')[0].linksto)
1057 highlight clear MyHLGroup
1058 call assert_equal([], hlget(test_null_string()))
1059 call assert_equal([], hlget(""))
1060 END
Bram Moolenaar62aec932022-01-29 21:45:34 +00001061 call v9.CheckLegacyAndVim9Success(lines)
Yegappan Lakshmanand1a8d652021-11-03 21:56:45 +00001062
1063 " Test for resolving highlight group links
1064 let lines =<< trim END
1065 highlight hlgA term=bold
1066 VAR hlgAid = hlID('hlgA')
1067 highlight link hlgB hlgA
1068 VAR hlgBid = hlID('hlgB')
1069 highlight link hlgC hlgB
1070 VAR hlgCid = hlID('hlgC')
1071 call assert_equal('hlgA', hlget('hlgB')[0].linksto)
1072 call assert_equal('hlgB', hlget('hlgC')[0].linksto)
1073 call assert_equal([{'id': hlgAid, 'name': 'hlgA',
1074 \ 'term': {'bold': v:true}}], hlget('hlgA'))
1075 call assert_equal([{'id': hlgBid, 'name': 'hlgB',
1076 \ 'linksto': 'hlgA'}], hlget('hlgB'))
1077 call assert_equal([{'id': hlgCid, 'name': 'hlgC',
1078 \ 'linksto': 'hlgB'}], hlget('hlgC'))
1079 call assert_equal([{'id': hlgAid, 'name': 'hlgA',
1080 \ 'term': {'bold': v:true}}], hlget('hlgA', v:false))
1081 call assert_equal([{'id': hlgBid, 'name': 'hlgB',
1082 \ 'linksto': 'hlgA'}], hlget('hlgB', 0))
1083 call assert_equal([{'id': hlgCid, 'name': 'hlgC',
1084 \ 'linksto': 'hlgB'}], hlget('hlgC', v:false))
1085 call assert_equal([{'id': hlgAid, 'name': 'hlgA',
1086 \ 'term': {'bold': v:true}}], hlget('hlgA', v:true))
1087 call assert_equal([{'id': hlgBid, 'name': 'hlgB',
1088 \ 'term': {'bold': v:true}}], hlget('hlgB', 1))
1089 call assert_equal([{'id': hlgCid, 'name': 'hlgC',
1090 \ 'term': {'bold': v:true}}], hlget('hlgC', v:true))
1091 END
Bram Moolenaar62aec932022-01-29 21:45:34 +00001092 call v9.CheckLegacyAndVim9Success(lines)
Yegappan Lakshmanand1a8d652021-11-03 21:56:45 +00001093
1094 call assert_fails('call hlget([])', 'E1174:')
1095 call assert_fails('call hlget("abc", "xyz")', 'E1212:')
1096endfunc
1097
1098" Test for the hlset() function
1099func Test_hlset()
1100 let lines =<< trim END
1101 call assert_equal(0, hlset(test_null_list()))
1102 call assert_equal(0, hlset([]))
1103 call assert_fails('call hlset(["Search"])', 'E715:')
1104 call hlset(hlget())
1105 call hlset([{'name': 'NewHLGroup', 'cterm': {'reverse': v:true}, 'ctermfg': '10'}])
1106 call assert_equal({'reverse': v:true}, hlget('NewHLGroup')[0].cterm)
1107 call hlset([{'name': 'NewHLGroup', 'cterm': {'bold': v:true}}])
1108 call assert_equal({'bold': v:true}, hlget('NewHLGroup')[0].cterm)
1109 call hlset([{'name': 'NewHLGroup', 'cleared': v:true}])
1110 call assert_equal(v:true, hlget('NewHLGroup')[0].cleared)
1111 call hlset([{'name': 'NewHLGroup', 'linksto': 'Search'}])
1112 call assert_false(has_key(hlget('NewHLGroup')[0], 'cleared'))
1113 call assert_equal('Search', hlget('NewHLGroup')[0].linksto)
1114 call assert_fails("call hlset([{'name': [], 'ctermfg': '10'}])", 'E928:')
1115 call assert_fails("call hlset([{'name': 'NewHLGroup', 'cleared': []}])",
1116 \ 'E745:')
1117 call assert_fails("call hlset([{'name': 'NewHLGroup', 'cterm': 'Blue'}])",
1118 \ 'E715:')
1119 call assert_fails("call hlset([{'name': 'NewHLGroup', 'ctermbg': []}])",
1120 \ 'E928:')
1121 call assert_fails("call hlset([{'name': 'NewHLGroup', 'ctermfg': []}])",
1122 \ 'E928:')
1123 call assert_fails("call hlset([{'name': 'NewHLGroup', 'ctermul': []}])",
1124 \ 'E928:')
1125 if has('gui')
1126 call assert_fails("call hlset([{'name': 'NewHLGroup', 'font': []}])",
1127 \ 'E928:')
1128 endif
1129 call assert_fails("call hlset([{'name': 'NewHLGroup', 'gui': 'Cyan'}])",
1130 \ 'E715:')
1131 call assert_fails("call hlset([{'name': 'NewHLGroup', 'guibg': []}])",
1132 \ 'E928:')
1133 call assert_fails("call hlset([{'name': 'NewHLGroup', 'guifg': []}])",
1134 \ 'E928:')
1135 call assert_fails("call hlset([{'name': 'NewHLGroup', 'guisp': []}])",
1136 \ 'E928:')
1137 call assert_fails("call hlset([{'name': 'NewHLGroup', 'linksto': []}])",
1138 \ 'E928:')
1139 call assert_fails("call hlset([{'name': 'NewHLGroup', 'start': []}])",
1140 \ 'E928:')
1141 call assert_fails("call hlset([{'name': 'NewHLGroup', 'stop': []}])",
1142 \ 'E928:')
1143 call assert_fails("call hlset([{'name': 'NewHLGroup', 'term': 'Cyan'}])",
1144 \ 'E715:')
1145 call assert_equal('Search', hlget('NewHLGroup')[0].linksto)
1146 highlight clear NewHLGroup
1147 END
Bram Moolenaar62aec932022-01-29 21:45:34 +00001148 call v9.CheckLegacyAndVim9Success(lines)
Yegappan Lakshmanand1a8d652021-11-03 21:56:45 +00001149
1150 " Test for clearing the 'term', 'cterm' and 'gui' attributes of a highlight
1151 " group.
1152 let lines =<< trim END
1153 highlight myhlg1 term=bold cterm=italic gui=standout
1154 VAR id = hlID('myhlg1')
1155 call hlset([{'name': 'myhlg1', 'term': {}}])
1156 call assert_equal([{'id': id, 'name': 'myhlg1',
1157 \ 'cterm': {'italic': v:true}, 'gui': {'standout': v:true}}],
1158 \ hlget('myhlg1'))
1159 call hlset([{'name': 'myhlg1', 'cterm': {}}])
1160 call assert_equal([{'id': id, 'name': 'myhlg1',
1161 \ 'gui': {'standout': v:true}}], hlget('myhlg1'))
1162 call hlset([{'name': 'myhlg1', 'gui': {}}])
1163 call assert_equal([{'id': id, 'name': 'myhlg1', 'cleared': v:true}],
1164 \ hlget('myhlg1'))
1165 highlight clear myhlg1
1166 END
Bram Moolenaar62aec932022-01-29 21:45:34 +00001167 call v9.CheckLegacyAndVim9Success(lines)
Yegappan Lakshmanand1a8d652021-11-03 21:56:45 +00001168
1169 " Test for setting all the 'term', 'cterm' and 'gui' attributes of a
1170 " highlight group
1171 let lines =<< trim END
Bram Moolenaar84f54632022-06-29 18:39:11 +01001172 VAR attr = {'bold': v:true, 'underline': v:true,
1173 \ 'undercurl': v:true, 'underdouble': v:true,
1174 \ 'underdotted': v:true, 'underdashed': v:true,
Yegappan Lakshmanand1a8d652021-11-03 21:56:45 +00001175 \ 'strikethrough': v:true, 'reverse': v:true, 'italic': v:true,
1176 \ 'standout': v:true, 'nocombine': v:true}
1177 call hlset([{'name': 'myhlg2', 'term': attr, 'cterm': attr, 'gui': attr}])
1178 VAR id2 = hlID('myhlg2')
Bram Moolenaar84f54632022-06-29 18:39:11 +01001179 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 +00001180 VAR output = execute('highlight myhlg2')
1181 LET output = output->split("\n")->join()->substitute('\s\+', ' ', 'g')
1182 call assert_equal(expected, output)
Yegappan Lakshmanand1a8d652021-11-03 21:56:45 +00001183 call assert_equal([{'id': id2, 'name': 'myhlg2', 'gui': attr,
1184 \ 'term': attr, 'cterm': attr}], hlget('myhlg2'))
1185 END
Bram Moolenaar62aec932022-01-29 21:45:34 +00001186 call v9.CheckLegacyAndVim9Success(lines)
Yegappan Lakshmanand1a8d652021-11-03 21:56:45 +00001187
1188 " Test for clearing some of the 'term', 'cterm' and 'gui' attributes of a
1189 " highlight group
1190 let lines =<< trim END
1191 VAR attr = {'bold': v:false, 'underline': v:true, 'strikethrough': v:true}
1192 call hlset([{'name': 'myhlg2', 'term': attr, 'cterm': attr, 'gui': attr}])
1193 VAR id2 = hlID('myhlg2')
Yegappan Lakshmanan2a16dc62021-11-16 17:19:30 +00001194 VAR expected = "myhlg2 xxx term=underline,strikethrough cterm=underline,strikethrough gui=underline,strikethrough"
1195 VAR output = execute('highlight myhlg2')
1196 LET output = output->split("\n")->join()->substitute('\s\+', ' ', 'g')
1197 call assert_equal(expected, output)
Yegappan Lakshmanand1a8d652021-11-03 21:56:45 +00001198 LET attr = {'underline': v:true, 'strikethrough': v:true}
1199 call assert_equal([{'id': id2, 'name': 'myhlg2', 'gui': attr,
1200 \ 'term': attr, 'cterm': attr}], hlget('myhlg2'))
1201 END
Bram Moolenaar62aec932022-01-29 21:45:34 +00001202 call v9.CheckLegacyAndVim9Success(lines)
Dominique Pelle6a950a62021-11-13 18:44:37 +00001203
Yegappan Lakshmanan2a16dc62021-11-16 17:19:30 +00001204 " Test for clearing the attributes and link of a highlight group
1205 let lines =<< trim END
1206 highlight myhlg3 ctermbg=green guibg=green
1207 highlight! default link myhlg3 ErrorMsg
1208 VAR id3 = hlID('myhlg3')
1209 call hlset([{'name': 'myhlg3', 'cleared': v:true, 'linksto': 'NONE'}])
1210 call assert_equal([{'id': id3, 'name': 'myhlg3', 'cleared': v:true}],
1211 \ hlget('myhlg3'))
1212 highlight clear hlg3
1213 END
Bram Moolenaar62aec932022-01-29 21:45:34 +00001214 call v9.CheckLegacyAndVim9Success(lines)
Yegappan Lakshmanan2a16dc62021-11-16 17:19:30 +00001215
1216 " Test for setting default attributes for a highlight group
1217 let lines =<< trim END
1218 call hlset([{'name': 'hlg4', 'ctermfg': '8'}])
1219 call hlset([{'name': 'hlg4', 'default': v:true, 'ctermfg': '9'}])
1220 VAR id4 = hlID('hlg4')
1221 call assert_equal([{'id': id4, 'name': 'hlg4', 'ctermfg': '8'}],
1222 \ hlget('hlg4'))
1223 highlight clear hlg4
1224
1225 call hlset([{'name': 'hlg5', 'default': v:true, 'ctermbg': '2'}])
1226 call hlset([{'name': 'hlg5', 'ctermbg': '4'}])
1227 VAR id5 = hlID('hlg5')
1228 call assert_equal([{'id': id5, 'name': 'hlg5', 'ctermbg': '4'}],
1229 \ hlget('hlg5'))
1230 highlight clear hlg5
1231
1232 call hlset([{'name': 'hlg6', 'linksto': 'Error'}])
1233 VAR id6 = hlID('hlg6')
1234 call hlset([{'name': 'hlg6', 'default': v:true, 'ctermbg': '2'}])
1235 call assert_equal([{'id': id6, 'name': 'hlg6', 'linksto': 'Error'}],
1236 \ hlget('hlg6'))
1237 highlight clear hlg6
1238 END
Bram Moolenaar62aec932022-01-29 21:45:34 +00001239 call v9.CheckLegacyAndVim9Success(lines)
Yegappan Lakshmanan2a16dc62021-11-16 17:19:30 +00001240
1241 " Test for setting default links for a highlight group
1242 let lines =<< trim END
1243 call hlset([{'name': 'hlg7', 'ctermfg': '5'}])
1244 call hlset([{'name': 'hlg7', 'default': v:true, 'linksto': 'Search'}])
1245 VAR id7 = hlID('hlg7')
1246 call assert_equal([{'id': id7, 'name': 'hlg7', 'ctermfg': '5'}],
1247 \ hlget('hlg7'))
1248 highlight clear hlg7
1249
1250 call hlset([{'name': 'hlg8', 'default': v:true, 'linksto': 'Search'}])
1251 VAR id8 = hlID('hlg8')
1252 call assert_equal([{'id': id8, 'name': 'hlg8', 'default': v:true,
1253 \ 'linksto': 'Search'}], hlget('hlg8'))
1254 call hlset([{'name': 'hlg8', 'ctermbg': '2'}])
1255 call assert_equal([{'id': id8, 'name': 'hlg8', 'ctermbg': '2'}],
1256 \ hlget('hlg8'))
1257 highlight clear hlg8
1258
1259 highlight default link hlg9 ErrorMsg
1260 VAR hlg_save = hlget('hlg9')
1261 LET hlg_save[0]['name'] = 'hlg9dup'
1262 call hlset(hlg_save)
1263 VAR id9 = hlID('hlg9dup')
1264 highlight clear hlg9dup
1265 call assert_equal([{'id': id9, 'name': 'hlg9dup', 'default': v:true,
1266 \ 'linksto': 'ErrorMsg'}], hlget('hlg9dup'))
1267 highlight clear hlg9
1268 END
Bram Moolenaar62aec932022-01-29 21:45:34 +00001269 call v9.CheckLegacyAndVim9Success(lines)
Yegappan Lakshmanan2a16dc62021-11-16 17:19:30 +00001270
1271 " Test for force creating a link to a highlight group
1272 let lines =<< trim END
1273 call hlset([{'name': 'hlg10', 'ctermfg': '8'}])
1274 call hlset([{'name': 'hlg10', 'linksto': 'Search'}])
1275 VAR id10 = hlID('hlg10')
1276 call assert_equal([{'id': id10, 'name': 'hlg10', 'ctermfg': '8'}],
1277 \ hlget('hlg10'))
1278 call hlset([{'name': 'hlg10', 'linksto': 'Search', 'force': v:true}])
1279 call assert_equal([{'id': id10, 'name': 'hlg10', 'ctermfg': '8',
1280 \ 'linksto': 'Search'}], hlget('hlg10'))
1281 highlight clear hlg10
1282 END
Bram Moolenaar62aec932022-01-29 21:45:34 +00001283 call v9.CheckLegacyAndVim9Success(lines)
Yegappan Lakshmananbb277fd2021-11-24 20:28:31 +00001284
1285 " Test for empty values of attributes
1286 call hlset([{'name': 'hlg11', 'cterm': {}}])
1287 call hlset([{'name': 'hlg11', 'ctermfg': ''}])
1288 call hlset([{'name': 'hlg11', 'ctermbg': ''}])
1289 call hlset([{'name': 'hlg11', 'ctermul': ''}])
1290 call hlset([{'name': 'hlg11', 'font': ''}])
1291 call hlset([{'name': 'hlg11', 'gui': {}}])
1292 call hlset([{'name': 'hlg11', 'guifg': ''}])
1293 call hlset([{'name': 'hlg11', 'guibg': ''}])
1294 call hlset([{'name': 'hlg11', 'guisp': ''}])
1295 call hlset([{'name': 'hlg11', 'start': ''}])
1296 call hlset([{'name': 'hlg11', 'stop': ''}])
1297 call hlset([{'name': 'hlg11', 'term': {}}])
1298 call assert_true(hlget('hlg11')[0].cleared)
Yegappan Lakshmanand1a8d652021-11-03 21:56:45 +00001299endfunc
1300
Bram Moolenaaree4e0c12020-04-06 21:35:05 +02001301" vim: shiftwidth=2 sts=2 expandtab