blob: 4b8cd86fafd0ca8a30a408f991355aae8cf6d5fe [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:")
49endfunc
Bram Moolenaar0aa398f2017-09-30 21:23:55 +020050
Bram Moolenaar1e115362019-01-09 23:01:02 +010051func HighlightArgs(name)
Bram Moolenaar0aa398f2017-09-30 21:23:55 +020052 return 'hi ' . substitute(split(execute('hi ' . a:name), '\n')[0], '\<xxx\>', '', '')
Bram Moolenaar1e115362019-01-09 23:01:02 +010053endfunc
Bram Moolenaar0aa398f2017-09-30 21:23:55 +020054
Bram Moolenaar1e115362019-01-09 23:01:02 +010055func IsColorable()
Bram Moolenaar0aa398f2017-09-30 21:23:55 +020056 return has('gui_running') || str2nr(&t_Co) >= 8
Bram Moolenaar1e115362019-01-09 23:01:02 +010057endfunc
Bram Moolenaar0aa398f2017-09-30 21:23:55 +020058
Bram Moolenaar1e115362019-01-09 23:01:02 +010059func HiCursorLine()
Bram Moolenaar0aa398f2017-09-30 21:23:55 +020060 let hiCursorLine = HighlightArgs('CursorLine')
61 if has('gui_running')
62 let guibg = matchstr(hiCursorLine, 'guibg=\w\+')
63 let hi_ul = 'hi CursorLine gui=underline guibg=NONE'
64 let hi_bg = 'hi CursorLine gui=NONE ' . guibg
65 else
66 let hi_ul = 'hi CursorLine cterm=underline ctermbg=NONE'
67 let hi_bg = 'hi CursorLine cterm=NONE ctermbg=Gray'
68 endif
69 return [hiCursorLine, hi_ul, hi_bg]
Bram Moolenaar1e115362019-01-09 23:01:02 +010070endfunc
Bram Moolenaar0aa398f2017-09-30 21:23:55 +020071
Bram Moolenaar1e115362019-01-09 23:01:02 +010072func Check_lcs_eol_attrs(attrs, row, col)
Bram Moolenaar5ece3e32017-10-01 14:35:02 +020073 let save_lcs = &lcs
74 set list
75
76 call assert_equal(a:attrs, ScreenAttrs(a:row, a:col)[0])
77
78 set nolist
79 let &lcs = save_lcs
Bram Moolenaar1e115362019-01-09 23:01:02 +010080endfunc
Bram Moolenaar5ece3e32017-10-01 14:35:02 +020081
Bram Moolenaar0aa398f2017-09-30 21:23:55 +020082func Test_highlight_eol_with_cursorline()
83 let [hiCursorLine, hi_ul, hi_bg] = HiCursorLine()
84
85 call NewWindow('topleft 5', 20)
86 call setline(1, 'abcd')
87 call matchadd('Search', '\n')
88
89 " expected:
90 " 'abcd '
91 " ^^^^ ^^^^^ no highlight
92 " ^ 'Search' highlight
93 let attrs0 = ScreenAttrs(1, 10)[0]
94 call assert_equal(repeat([attrs0[0]], 4), attrs0[0:3])
95 call assert_equal(repeat([attrs0[0]], 5), attrs0[5:9])
96 call assert_notequal(attrs0[0], attrs0[4])
97
98 setlocal cursorline
99
100 " underline
101 exe hi_ul
102
103 " expected:
104 " 'abcd '
105 " ^^^^ underline
Bram Moolenaar5ece3e32017-10-01 14:35:02 +0200106 " ^ 'Search' highlight with underline
107 " ^^^^^ underline
Bram Moolenaar0aa398f2017-09-30 21:23:55 +0200108 let attrs = ScreenAttrs(1, 10)[0]
109 call assert_equal(repeat([attrs[0]], 4), attrs[0:3])
110 call assert_equal([attrs[4]] + repeat([attrs[5]], 5), attrs[4:9])
111 call assert_notequal(attrs[0], attrs[4])
112 call assert_notequal(attrs[4], attrs[5])
113 call assert_notequal(attrs0[0], attrs[0])
114 call assert_notequal(attrs0[4], attrs[4])
Bram Moolenaar5ece3e32017-10-01 14:35:02 +0200115 call Check_lcs_eol_attrs(attrs, 1, 10)
Bram Moolenaar0aa398f2017-09-30 21:23:55 +0200116
117 if IsColorable()
118 " bg-color
119 exe hi_bg
120
121 " expected:
122 " 'abcd '
123 " ^^^^ bg-color of 'CursorLine'
124 " ^ 'Search' highlight
125 " ^^^^^ bg-color of 'CursorLine'
126 let attrs = ScreenAttrs(1, 10)[0]
127 call assert_equal(repeat([attrs[0]], 4), attrs[0:3])
128 call assert_equal(repeat([attrs[5]], 5), attrs[5:9])
129 call assert_equal(attrs0[4], attrs[4])
130 call assert_notequal(attrs[0], attrs[4])
131 call assert_notequal(attrs[4], attrs[5])
132 call assert_notequal(attrs0[0], attrs[0])
133 call assert_notequal(attrs0[5], attrs[5])
Bram Moolenaar5ece3e32017-10-01 14:35:02 +0200134 call Check_lcs_eol_attrs(attrs, 1, 10)
Bram Moolenaar0aa398f2017-09-30 21:23:55 +0200135 endif
136
137 call CloseWindow()
138 exe hiCursorLine
139endfunc
140
141func Test_highlight_eol_with_cursorline_vertsplit()
Bram Moolenaar0aa398f2017-09-30 21:23:55 +0200142 let [hiCursorLine, hi_ul, hi_bg] = HiCursorLine()
143
144 call NewWindow('topleft 5', 5)
145 call setline(1, 'abcd')
146 call matchadd('Search', '\n')
147
148 let expected = "abcd |abcd "
149 let actual = ScreenLines(1, 15)[0]
150 call assert_equal(expected, actual)
151
152 " expected:
153 " 'abcd |abcd '
154 " ^^^^ ^^^^^^^^^ no highlight
155 " ^ 'Search' highlight
156 " ^ 'VertSplit' highlight
157 let attrs0 = ScreenAttrs(1, 15)[0]
158 call assert_equal(repeat([attrs0[0]], 4), attrs0[0:3])
159 call assert_equal(repeat([attrs0[0]], 9), attrs0[6:14])
160 call assert_notequal(attrs0[0], attrs0[4])
161 call assert_notequal(attrs0[0], attrs0[5])
162 call assert_notequal(attrs0[4], attrs0[5])
163
164 setlocal cursorline
165
166 " expected:
167 " 'abcd |abcd '
168 " ^^^^ underline
169 " ^ 'Search' highlight with underline
170 " ^ 'VertSplit' highlight
171 " ^^^^^^^^^ no highlight
172
173 " underline
174 exe hi_ul
175
176 let actual = ScreenLines(1, 15)[0]
177 call assert_equal(expected, actual)
178
179 let attrs = ScreenAttrs(1, 15)[0]
180 call assert_equal(repeat([attrs[0]], 4), attrs[0:3])
181 call assert_equal(repeat([attrs[6]], 9), attrs[6:14])
182 call assert_equal(attrs0[5:14], attrs[5:14])
183 call assert_notequal(attrs[0], attrs[4])
184 call assert_notequal(attrs[0], attrs[5])
185 call assert_notequal(attrs[0], attrs[6])
186 call assert_notequal(attrs[4], attrs[5])
187 call assert_notequal(attrs[5], attrs[6])
188 call assert_notequal(attrs0[0], attrs[0])
189 call assert_notequal(attrs0[4], attrs[4])
Bram Moolenaar5ece3e32017-10-01 14:35:02 +0200190 call Check_lcs_eol_attrs(attrs, 1, 15)
Bram Moolenaar0aa398f2017-09-30 21:23:55 +0200191
192 if IsColorable()
193 " bg-color
194 exe hi_bg
195
196 let actual = ScreenLines(1, 15)[0]
197 call assert_equal(expected, actual)
198
199 let attrs = ScreenAttrs(1, 15)[0]
200 call assert_equal(repeat([attrs[0]], 4), attrs[0:3])
201 call assert_equal(repeat([attrs[6]], 9), attrs[6:14])
202 call assert_equal(attrs0[5:14], attrs[5:14])
203 call assert_notequal(attrs[0], attrs[4])
204 call assert_notequal(attrs[0], attrs[5])
205 call assert_notequal(attrs[0], attrs[6])
206 call assert_notequal(attrs[4], attrs[5])
207 call assert_notequal(attrs[5], attrs[6])
208 call assert_notequal(attrs0[0], attrs[0])
209 call assert_equal(attrs0[4], attrs[4])
Bram Moolenaar5ece3e32017-10-01 14:35:02 +0200210 call Check_lcs_eol_attrs(attrs, 1, 15)
Bram Moolenaar0aa398f2017-09-30 21:23:55 +0200211 endif
212
213 call CloseWindow()
214 exe hiCursorLine
215endfunc
216
217func Test_highlight_eol_with_cursorline_rightleft()
Bram Moolenaar6d91bcb2020-08-12 18:50:36 +0200218 CheckFeature rightleft
Bram Moolenaar0aa398f2017-09-30 21:23:55 +0200219
220 let [hiCursorLine, hi_ul, hi_bg] = HiCursorLine()
221
222 call NewWindow('topleft 5', 10)
223 setlocal rightleft
224 call setline(1, 'abcd')
225 call matchadd('Search', '\n')
226 let attrs0 = ScreenAttrs(1, 10)[0]
227
228 setlocal cursorline
229
230 " underline
231 exe hi_ul
232
233 " expected:
234 " ' dcba'
235 " ^^^^ underline
236 " ^ 'Search' highlight with underline
237 " ^^^^^ underline
238 let attrs = ScreenAttrs(1, 10)[0]
239 call assert_equal(repeat([attrs[9]], 4), attrs[6:9])
240 call assert_equal(repeat([attrs[4]], 5) + [attrs[5]], attrs[0:5])
241 call assert_notequal(attrs[9], attrs[5])
242 call assert_notequal(attrs[4], attrs[5])
243 call assert_notequal(attrs0[9], attrs[9])
244 call assert_notequal(attrs0[5], attrs[5])
Bram Moolenaar5ece3e32017-10-01 14:35:02 +0200245 call Check_lcs_eol_attrs(attrs, 1, 10)
Bram Moolenaar0aa398f2017-09-30 21:23:55 +0200246
247 if IsColorable()
248 " bg-color
249 exe hi_bg
250
251 " expected:
252 " ' dcba'
253 " ^^^^ bg-color of 'CursorLine'
254 " ^ 'Search' highlight
255 " ^^^^^ bg-color of 'CursorLine'
256 let attrs = ScreenAttrs(1, 10)[0]
257 call assert_equal(repeat([attrs[9]], 4), attrs[6:9])
258 call assert_equal(repeat([attrs[4]], 5), attrs[0:4])
259 call assert_equal(attrs0[5], attrs[5])
260 call assert_notequal(attrs[9], attrs[5])
261 call assert_notequal(attrs[5], attrs[4])
262 call assert_notequal(attrs0[9], attrs[9])
263 call assert_notequal(attrs0[4], attrs[4])
Bram Moolenaar5ece3e32017-10-01 14:35:02 +0200264 call Check_lcs_eol_attrs(attrs, 1, 10)
Bram Moolenaar0aa398f2017-09-30 21:23:55 +0200265 endif
266
267 call CloseWindow()
268 exe hiCursorLine
269endfunc
270
271func Test_highlight_eol_with_cursorline_linewrap()
272 let [hiCursorLine, hi_ul, hi_bg] = HiCursorLine()
273
274 call NewWindow('topleft 5', 10)
275 call setline(1, [repeat('a', 51) . 'bcd', ''])
276 call matchadd('Search', '\n')
277
278 setlocal wrap
279 normal! gg$
280 let attrs0 = ScreenAttrs(5, 10)[0]
281 setlocal cursorline
282
283 " underline
284 exe hi_ul
285
286 " expected:
287 " 'abcd '
288 " ^^^^ underline
289 " ^ 'Search' highlight with underline
290 " ^^^^^ underline
291 let attrs = ScreenAttrs(5, 10)[0]
292 call assert_equal(repeat([attrs[0]], 4), attrs[0:3])
293 call assert_equal([attrs[4]] + repeat([attrs[5]], 5), attrs[4:9])
294 call assert_notequal(attrs[0], attrs[4])
295 call assert_notequal(attrs[4], attrs[5])
296 call assert_notequal(attrs0[0], attrs[0])
297 call assert_notequal(attrs0[4], attrs[4])
Bram Moolenaar5ece3e32017-10-01 14:35:02 +0200298 call Check_lcs_eol_attrs(attrs, 5, 10)
Bram Moolenaar0aa398f2017-09-30 21:23:55 +0200299
300 if IsColorable()
301 " bg-color
302 exe hi_bg
303
304 " expected:
305 " 'abcd '
306 " ^^^^ bg-color of 'CursorLine'
307 " ^ 'Search' highlight
308 " ^^^^^ bg-color of 'CursorLine'
309 let attrs = ScreenAttrs(5, 10)[0]
310 call assert_equal(repeat([attrs[0]], 4), attrs[0:3])
311 call assert_equal(repeat([attrs[5]], 5), attrs[5:9])
312 call assert_equal(attrs0[4], attrs[4])
313 call assert_notequal(attrs[0], attrs[4])
314 call assert_notequal(attrs[4], attrs[5])
315 call assert_notequal(attrs0[0], attrs[0])
316 call assert_notequal(attrs0[5], attrs[5])
Bram Moolenaar5ece3e32017-10-01 14:35:02 +0200317 call Check_lcs_eol_attrs(attrs, 5, 10)
Bram Moolenaar0aa398f2017-09-30 21:23:55 +0200318 endif
319
320 setlocal nocursorline nowrap
321 normal! gg$
322 let attrs0 = ScreenAttrs(1, 10)[0]
323 setlocal cursorline
324
325 " underline
326 exe hi_ul
327
328 " expected:
329 " 'aaabcd '
330 " ^^^^^^ underline
331 " ^ 'Search' highlight with underline
332 " ^^^ underline
333 let attrs = ScreenAttrs(1, 10)[0]
334 call assert_equal(repeat([attrs[0]], 6), attrs[0:5])
335 call assert_equal([attrs[6]] + repeat([attrs[7]], 3), attrs[6:9])
336 call assert_notequal(attrs[0], attrs[6])
337 call assert_notequal(attrs[6], attrs[7])
338 call assert_notequal(attrs0[0], attrs[0])
339 call assert_notequal(attrs0[6], attrs[6])
Bram Moolenaar5ece3e32017-10-01 14:35:02 +0200340 call Check_lcs_eol_attrs(attrs, 1, 10)
Bram Moolenaar0aa398f2017-09-30 21:23:55 +0200341
342 if IsColorable()
343 " bg-color
344 exe hi_bg
345
346 " expected:
347 " 'aaabcd '
348 " ^^^^^^ bg-color of 'CursorLine'
349 " ^ 'Search' highlight
350 " ^^^ bg-color of 'CursorLine'
351 let attrs = ScreenAttrs(1, 10)[0]
352 call assert_equal(repeat([attrs[0]], 6), attrs[0:5])
353 call assert_equal(repeat([attrs[7]], 3), attrs[7:9])
354 call assert_equal(attrs0[6], attrs[6])
355 call assert_notequal(attrs[0], attrs[6])
356 call assert_notequal(attrs[6], attrs[7])
357 call assert_notequal(attrs0[0], attrs[0])
358 call assert_notequal(attrs0[7], attrs[7])
Bram Moolenaar5ece3e32017-10-01 14:35:02 +0200359 call Check_lcs_eol_attrs(attrs, 1, 10)
Bram Moolenaar0aa398f2017-09-30 21:23:55 +0200360 endif
361
362 call CloseWindow()
363 exe hiCursorLine
364endfunc
365
366func Test_highlight_eol_with_cursorline_sign()
Bram Moolenaar6d91bcb2020-08-12 18:50:36 +0200367 CheckFeature signs
Bram Moolenaar0aa398f2017-09-30 21:23:55 +0200368
369 let [hiCursorLine, hi_ul, hi_bg] = HiCursorLine()
370
371 call NewWindow('topleft 5', 10)
372 call setline(1, 'abcd')
373 call matchadd('Search', '\n')
374
375 sign define Sign text=>>
376 exe 'sign place 1 line=1 name=Sign buffer=' . bufnr('')
377 let attrs0 = ScreenAttrs(1, 10)[0]
378 setlocal cursorline
379
380 " underline
381 exe hi_ul
382
383 " expected:
384 " '>>abcd '
385 " ^^ sign
386 " ^^^^ underline
387 " ^ 'Search' highlight with underline
388 " ^^^ underline
389 let attrs = ScreenAttrs(1, 10)[0]
390 call assert_equal(repeat([attrs[2]], 4), attrs[2:5])
391 call assert_equal([attrs[6]] + repeat([attrs[7]], 3), attrs[6:9])
392 call assert_notequal(attrs[2], attrs[6])
393 call assert_notequal(attrs[6], attrs[7])
394 call assert_notequal(attrs0[2], attrs[2])
395 call assert_notequal(attrs0[6], attrs[6])
Bram Moolenaar5ece3e32017-10-01 14:35:02 +0200396 call Check_lcs_eol_attrs(attrs, 1, 10)
Bram Moolenaar0aa398f2017-09-30 21:23:55 +0200397
398 if IsColorable()
399 " bg-color
400 exe hi_bg
401
402 " expected:
403 " '>>abcd '
404 " ^^ sign
405 " ^^^^ bg-color of 'CursorLine'
406 " ^ 'Search' highlight
407 " ^^^ bg-color of 'CursorLine'
408 let attrs = ScreenAttrs(1, 10)[0]
409 call assert_equal(repeat([attrs[2]], 4), attrs[2:5])
410 call assert_equal(repeat([attrs[7]], 3), attrs[7:9])
411 call assert_equal(attrs0[6], attrs[6])
412 call assert_notequal(attrs[2], attrs[6])
413 call assert_notequal(attrs[6], attrs[7])
414 call assert_notequal(attrs0[2], attrs[2])
415 call assert_notequal(attrs0[7], attrs[7])
Bram Moolenaar5ece3e32017-10-01 14:35:02 +0200416 call Check_lcs_eol_attrs(attrs, 1, 10)
Bram Moolenaar0aa398f2017-09-30 21:23:55 +0200417 endif
418
419 sign unplace 1
420 call CloseWindow()
421 exe hiCursorLine
422endfunc
423
424func Test_highlight_eol_with_cursorline_breakindent()
Bram Moolenaar6d91bcb2020-08-12 18:50:36 +0200425 CheckFeature linebreak
Bram Moolenaar0aa398f2017-09-30 21:23:55 +0200426
427 let [hiCursorLine, hi_ul, hi_bg] = HiCursorLine()
428
429 call NewWindow('topleft 5', 10)
Bram Moolenaaree857022019-11-09 23:26:40 +0100430 set showbreak=xxx
Bram Moolenaar0aa398f2017-09-30 21:23:55 +0200431 setlocal breakindent breakindentopt=min:0,shift:1 showbreak=>
432 call setline(1, ' ' . repeat('a', 9) . 'bcd')
433 call matchadd('Search', '\n')
434 let attrs0 = ScreenAttrs(2, 10)[0]
435 setlocal cursorline
436
437 " underline
438 exe hi_ul
439
440 " expected:
441 " ' >bcd '
442 " ^^^ breakindent and showbreak
443 " ^^^ underline
444 " ^ 'Search' highlight with underline
445 " ^^^ underline
446 let attrs = ScreenAttrs(2, 10)[0]
447 call assert_equal(repeat([attrs[0]], 2), attrs[0:1])
448 call assert_equal(repeat([attrs[3]], 3), attrs[3:5])
449 call assert_equal([attrs[6]] + repeat([attrs[7]], 3), attrs[6:9])
450 call assert_equal(attrs0[0], attrs[0])
451 call assert_notequal(attrs[0], attrs[2])
452 call assert_notequal(attrs[2], attrs[3])
453 call assert_notequal(attrs[3], attrs[6])
454 call assert_notequal(attrs[6], attrs[7])
455 call assert_notequal(attrs0[2], attrs[2])
456 call assert_notequal(attrs0[3], attrs[3])
457 call assert_notequal(attrs0[6], attrs[6])
Bram Moolenaar5ece3e32017-10-01 14:35:02 +0200458 call Check_lcs_eol_attrs(attrs, 2, 10)
Bram Moolenaar0aa398f2017-09-30 21:23:55 +0200459
460 if IsColorable()
461 " bg-color
462 exe hi_bg
463
464 " expected:
465 " ' >bcd '
466 " ^^^ breakindent and showbreak
467 " ^^^ bg-color of 'CursorLine'
468 " ^ 'Search' highlight
469 " ^^^ bg-color of 'CursorLine'
470 let attrs = ScreenAttrs(2, 10)[0]
471 call assert_equal(repeat([attrs[0]], 2), attrs[0:1])
472 call assert_equal(repeat([attrs[3]], 3), attrs[3:5])
473 call assert_equal(repeat([attrs[7]], 3), attrs[7:9])
474 call assert_equal(attrs0[0], attrs[0])
475 call assert_equal(attrs0[6], attrs[6])
476 call assert_notequal(attrs[0], attrs[2])
477 call assert_notequal(attrs[2], attrs[3])
478 call assert_notequal(attrs[3], attrs[6])
479 call assert_notequal(attrs[6], attrs[7])
480 call assert_notequal(attrs0[2], attrs[2])
481 call assert_notequal(attrs0[3], attrs[3])
482 call assert_notequal(attrs0[7], attrs[7])
Bram Moolenaar5ece3e32017-10-01 14:35:02 +0200483 call Check_lcs_eol_attrs(attrs, 2, 10)
Bram Moolenaar0aa398f2017-09-30 21:23:55 +0200484 endif
485
486 call CloseWindow()
487 set showbreak=
Bram Moolenaaree857022019-11-09 23:26:40 +0100488 setlocal showbreak=
Bram Moolenaar0aa398f2017-09-30 21:23:55 +0200489 exe hiCursorLine
490endfunc
491
492func Test_highlight_eol_on_diff()
493 call setline(1, ['abcd', ''])
494 call matchadd('Search', '\n')
495 let attrs0 = ScreenAttrs(1, 10)[0]
496
497 diffthis
498 botright new
499 diffthis
500
501 " expected:
502 " ' abcd '
503 " ^^ sign
504 " ^^^^ ^^^ 'DiffAdd' highlight
505 " ^ 'Search' highlight
506 let attrs = ScreenAttrs(1, 10)[0]
507 call assert_equal(repeat([attrs[0]], 2), attrs[0:1])
508 call assert_equal(repeat([attrs[2]], 4), attrs[2:5])
509 call assert_equal(repeat([attrs[2]], 3), attrs[7:9])
510 call assert_equal(attrs0[4], attrs[6])
511 call assert_notequal(attrs[0], attrs[2])
512 call assert_notequal(attrs[0], attrs[6])
513 call assert_notequal(attrs[2], attrs[6])
Bram Moolenaar5ece3e32017-10-01 14:35:02 +0200514 call Check_lcs_eol_attrs(attrs, 1, 10)
Bram Moolenaar0aa398f2017-09-30 21:23:55 +0200515
516 bwipe!
517 diffoff
518endfunc
Bram Moolenaarf708ac52018-03-12 21:48:32 +0100519
520func Test_termguicolors()
Bram Moolenaar6d91bcb2020-08-12 18:50:36 +0200521 CheckOption termguicolors
Bram Moolenaar310c32e2019-11-29 23:15:25 +0100522 if has('vtp') && !has('vcon') && !has('gui_running')
Bram Moolenaarff1e8792018-03-12 22:16:37 +0100523 " Win32: 'guicolors' doesn't work without virtual console.
524 call assert_fails('set termguicolors', 'E954:')
525 return
526 endif
Bram Moolenaarf708ac52018-03-12 21:48:32 +0100527
528 " Basic test that setting 'termguicolors' works with one color.
529 set termguicolors
530 redraw
531 set t_Co=1
532 redraw
533 set t_Co=0
534 redraw
535endfunc
Bram Moolenaarc07ff5c2019-01-30 21:41:14 +0100536
537func Test_cursorline_after_yank()
Bram Moolenaar8c5a2782019-08-07 23:07:07 +0200538 CheckScreendump
Bram Moolenaarc07ff5c2019-01-30 21:41:14 +0100539
540 call writefile([
541 \ 'set cul rnu',
542 \ 'call setline(1, ["","1","2","3",""])',
543 \ ], 'Xtest_cursorline_yank')
544 let buf = RunVimInTerminal('-S Xtest_cursorline_yank', {'rows': 8})
Bram Moolenaar6a2c5a72020-04-08 21:50:25 +0200545 call TermWait(buf)
Bram Moolenaarc07ff5c2019-01-30 21:41:14 +0100546 call term_sendkeys(buf, "Gy3k")
Bram Moolenaar6a2c5a72020-04-08 21:50:25 +0200547 call TermWait(buf)
Bram Moolenaarc07ff5c2019-01-30 21:41:14 +0100548 call term_sendkeys(buf, "jj")
549
550 call VerifyScreenDump(buf, 'Test_cursorline_yank_01', {})
551
552 " clean up
553 call StopVimInTerminal(buf)
554 call delete('Xtest_cursorline_yank')
555endfunc
Bram Moolenaar8156ed32019-03-09 11:46:15 +0100556
Bram Moolenaarfca068b2019-09-08 14:07:47 +0200557" test for issue #4862
558func Test_put_before_cursorline()
559 new
560 only!
561 call setline(1, 'A')
562 redraw
563 let std_attr = screenattr(1, 1)
564 set cursorline
565 redraw
566 let cul_attr = screenattr(1, 1)
567 normal yyP
568 redraw
569 " Line 1 has cursor so it should be highlighted with CursorLine.
570 call assert_equal(cul_attr, screenattr(1, 1))
571 " And CursorLine highlighting from the second line should be gone.
572 call assert_equal(std_attr, screenattr(2, 1))
573 set nocursorline
574 bwipe!
575endfunc
576
Bram Moolenaar8156ed32019-03-09 11:46:15 +0100577func Test_cursorline_with_visualmode()
Bram Moolenaar8c5a2782019-08-07 23:07:07 +0200578 CheckScreendump
Bram Moolenaar8156ed32019-03-09 11:46:15 +0100579
580 call writefile([
581 \ 'set cul',
582 \ 'call setline(1, repeat(["abc"], 50))',
583 \ ], 'Xtest_cursorline_with_visualmode')
584 let buf = RunVimInTerminal('-S Xtest_cursorline_with_visualmode', {'rows': 12})
Bram Moolenaar6a2c5a72020-04-08 21:50:25 +0200585 call TermWait(buf)
Bram Moolenaar8156ed32019-03-09 11:46:15 +0100586 call term_sendkeys(buf, "V\<C-f>kkkjk")
587
588 call VerifyScreenDump(buf, 'Test_cursorline_with_visualmode_01', {})
589
590 " clean up
591 call StopVimInTerminal(buf)
592 call delete('Xtest_cursorline_with_visualmode')
593endfunc
Bram Moolenaarf90b6e02019-05-09 19:26:38 +0200594
Bram Moolenaar782c6742022-04-01 12:06:31 +0100595func Test_cursorcolumn_insert_on_tab()
596 CheckScreendump
597
598 let lines =<< trim END
599 call setline(1, ['123456789', "a\tb"])
600 set cursorcolumn
601 call cursor(2, 2)
602 END
603 call writefile(lines, 'Xcuc_insert_on_tab')
604
605 let buf = RunVimInTerminal('-S Xcuc_insert_on_tab', #{rows: 8})
606 call TermWait(buf)
607 call VerifyScreenDump(buf, 'Test_cursorcolumn_insert_on_tab_1', {})
608
609 call term_sendkeys(buf, 'i')
610 call TermWait(buf)
611 call VerifyScreenDump(buf, 'Test_cursorcolumn_insert_on_tab_2', {})
612
613 call StopVimInTerminal(buf)
614 call delete('Xcuc_insert_on_tab')
615endfunc
616
zeertzjq3e559cd2022-03-27 19:26:55 +0100617func Test_cursorcolumn_callback()
618 CheckScreendump
619 CheckFeature timers
620
621 let lines =<< trim END
622 call setline(1, ['aaaaa', 'bbbbb', 'ccccc', 'ddddd'])
623 set cursorcolumn
624 call cursor(4, 5)
625
626 func Func(timer)
627 call cursor(1, 1)
628 endfunc
629
630 call timer_start(300, 'Func')
631 END
632 call writefile(lines, 'Xcuc_timer')
633
634 let buf = RunVimInTerminal('-S Xcuc_timer', #{rows: 8})
635 call TermWait(buf, 310)
636 call VerifyScreenDump(buf, 'Test_cursorcolumn_callback_1', {})
637
638 call StopVimInTerminal(buf)
639 call delete('Xcuc_timer')
640endfunc
641
Bram Moolenaar193ffd12019-05-25 22:57:30 +0200642func Test_wincolor()
Bram Moolenaar8c5a2782019-08-07 23:07:07 +0200643 CheckScreendump
Bram Moolenaar3180fe62020-02-02 13:47:06 +0100644 " make sure the width is enough for the test
645 set columns=80
Bram Moolenaar193ffd12019-05-25 22:57:30 +0200646
Bram Moolenaare7eb9272019-06-24 00:58:07 +0200647 let lines =<< trim END
648 set cursorline cursorcolumn rnu
Bram Moolenaar053f7122019-09-23 22:17:15 +0200649 call setline(1, ["","1111111111","22222222222","3 here 3","","the cat is out of the bag"])
Bram Moolenaare7eb9272019-06-24 00:58:07 +0200650 set wincolor=Pmenu
Bram Moolenaar053f7122019-09-23 22:17:15 +0200651 hi CatLine guifg=green ctermfg=green
652 hi Reverse gui=reverse cterm=reverse
653 syn match CatLine /^the.*/
654 call prop_type_add("foo", {"highlight": "Reverse", "combine": 1})
655 call prop_add(6, 12, {"type": "foo", "end_col": 15})
Bram Moolenaare7eb9272019-06-24 00:58:07 +0200656 /here
657 END
658 call writefile(lines, 'Xtest_wincolor')
Bram Moolenaar193ffd12019-05-25 22:57:30 +0200659 let buf = RunVimInTerminal('-S Xtest_wincolor', {'rows': 8})
Bram Moolenaar6a2c5a72020-04-08 21:50:25 +0200660 call TermWait(buf)
Bram Moolenaar193ffd12019-05-25 22:57:30 +0200661 call term_sendkeys(buf, "2G5lvj")
Bram Moolenaar6a2c5a72020-04-08 21:50:25 +0200662 call TermWait(buf)
Bram Moolenaar193ffd12019-05-25 22:57:30 +0200663
664 call VerifyScreenDump(buf, 'Test_wincolor_01', {})
665
666 " clean up
667 call term_sendkeys(buf, "\<Esc>")
668 call StopVimInTerminal(buf)
669 call delete('Xtest_wincolor')
670endfunc
671
Bram Moolenaar42e931b2019-12-04 19:08:50 +0100672func Test_wincolor_listchars()
673 CheckScreendump
Bram Moolenaar705724e2020-01-31 21:13:42 +0100674 CheckFeature conceal
Bram Moolenaar42e931b2019-12-04 19:08:50 +0100675
676 let lines =<< trim END
677 call setline(1, ["one","\t\tsome random text enough long to show 'extends' and 'precedes' includingnbsps, preceding tabs and trailing spaces ","three"])
678 set wincolor=Todo
679 set nowrap cole=1 cocu+=n
680 set list lcs=eol:$,tab:>-,space:.,trail:_,extends:>,precedes:<,conceal:*,nbsp:#
681 call matchadd('Conceal', 'text')
682 normal 2G5zl
683 END
684 call writefile(lines, 'Xtest_wincolorlcs')
685 let buf = RunVimInTerminal('-S Xtest_wincolorlcs', {'rows': 8})
686
687 call VerifyScreenDump(buf, 'Test_wincolor_lcs', {})
688
689 " clean up
690 call term_sendkeys(buf, "\<Esc>")
691 call StopVimInTerminal(buf)
692 call delete('Xtest_wincolorlcs')
693endfunc
694
Bram Moolenaar010ee962019-09-25 20:37:36 +0200695func Test_colorcolumn()
696 CheckScreendump
697
698 " check that setting 'colorcolumn' when entering a buffer works
699 let lines =<< trim END
700 split
701 edit X
702 call setline(1, ["1111111111","22222222222","3333333333"])
703 set nomodified
704 set colorcolumn=3,9
705 set number cursorline cursorlineopt=number
706 wincmd w
707 buf X
708 END
709 call writefile(lines, 'Xtest_colorcolumn')
710 let buf = RunVimInTerminal('-S Xtest_colorcolumn', {'rows': 10})
711 call term_sendkeys(buf, ":\<CR>")
Bram Moolenaar010ee962019-09-25 20:37:36 +0200712 call VerifyScreenDump(buf, 'Test_colorcolumn_1', {})
713
714 " clean up
715 call StopVimInTerminal(buf)
716 call delete('Xtest_colorcolumn')
717endfunc
718
Bram Moolenaarad5e5632020-09-15 20:52:26 +0200719func Test_colorcolumn_bri()
720 CheckScreendump
721
722 " check 'colorcolumn' when 'breakindent' is set
723 let lines =<< trim END
724 call setline(1, 'The quick brown fox jumped over the lazy dogs')
725 END
726 call writefile(lines, 'Xtest_colorcolumn_bri')
727 let buf = RunVimInTerminal('-S Xtest_colorcolumn_bri', {'rows': 10,'columns': 40})
728 call term_sendkeys(buf, ":set co=40 linebreak bri briopt=shift:2 cc=40,41,43\<CR>")
Bram Moolenaarad5e5632020-09-15 20:52:26 +0200729 call VerifyScreenDump(buf, 'Test_colorcolumn_2', {})
730
731 " clean up
732 call StopVimInTerminal(buf)
733 call delete('Xtest_colorcolumn_bri')
734endfunc
735
736func Test_colorcolumn_sbr()
737 CheckScreendump
738
739 " check 'colorcolumn' when 'showbreak' is set
740 let lines =<< trim END
741 call setline(1, 'The quick brown fox jumped over the lazy dogs')
742 END
743 call writefile(lines, 'Xtest_colorcolumn_srb')
744 let buf = RunVimInTerminal('-S Xtest_colorcolumn_srb', {'rows': 10,'columns': 40})
745 call term_sendkeys(buf, ":set co=40 showbreak=+++>\\ cc=40,41,43\<CR>")
Bram Moolenaarad5e5632020-09-15 20:52:26 +0200746 call VerifyScreenDump(buf, 'Test_colorcolumn_3', {})
747
748 " clean up
749 call StopVimInTerminal(buf)
750 call delete('Xtest_colorcolumn_srb')
751endfunc
752
Bram Moolenaar6b528fa2019-05-09 20:07:33 +0200753" This test must come before the Test_cursorline test, as it appears this
754" defines the Normal highlighting group anyway.
Bram Moolenaarf90b6e02019-05-09 19:26:38 +0200755func Test_1_highlight_Normalgroup_exists()
Bram Moolenaar435f9f02019-07-03 21:40:16 +0200756 let hlNormal = HighlightArgs('Normal')
757 if !has('gui_running')
Bram Moolenaar6b528fa2019-05-09 20:07:33 +0200758 call assert_match('hi Normal\s*clear', hlNormal)
Bram Moolenaar435f9f02019-07-03 21:40:16 +0200759 elseif has('gui_gtk2') || has('gui_gnome') || has('gui_gtk3')
760 " expect is DEFAULT_FONT of gui_gtk_x11.c
761 call assert_match('hi Normal\s*font=Monospace 10', hlNormal)
762 elseif has('gui_motif') || has('gui_athena')
763 " expect is DEFAULT_FONT of gui_x11.c
764 call assert_match('hi Normal\s*font=7x13', hlNormal)
765 elseif has('win32')
766 " expect any font
767 call assert_match('hi Normal\s*font=.*', hlNormal)
Bram Moolenaar6b528fa2019-05-09 20:07:33 +0200768 endif
Bram Moolenaarf90b6e02019-05-09 19:26:38 +0200769endfunc
Bram Moolenaar548be7f2019-06-29 03:42:42 +0200770
Bram Moolenaar3180fe62020-02-02 13:47:06 +0100771" Do this test last, sometimes restoring the columns doesn't work
Bram Moolenaaree4e0c12020-04-06 21:35:05 +0200772func Test_z_no_space_before_xxx()
Bram Moolenaar548be7f2019-06-29 03:42:42 +0200773 let l:org_columns = &columns
774 set columns=17
775 let l:hi_StatusLineTermNC = join(split(execute('hi StatusLineTermNC')))
776 call assert_match('StatusLineTermNC xxx', l:hi_StatusLineTermNC)
777 let &columns = l:org_columns
Bram Moolenaaree4e0c12020-04-06 21:35:05 +0200778endfunc
779
780" Test for :highlight command errors
781func Test_highlight_cmd_errors()
782 if has('gui_running')
783 " This test doesn't fail in the MS-Windows console version.
Bram Moolenaar75e15672020-06-28 13:10:22 +0200784 call assert_fails('hi Xcomment ctermbg=fg', 'E419:')
Bram Moolenaaree4e0c12020-04-06 21:35:05 +0200785 call assert_fails('hi Xcomment ctermfg=bg', 'E420:')
Bram Moolenaar75e15672020-06-28 13:10:22 +0200786 call assert_fails('hi Xcomment ctermfg=ul', 'E453:')
erw7f7f7aaf2021-12-07 21:29:20 +0000787 call assert_fails('hi ' .. repeat('a', 201) .. ' ctermfg=black', 'E1249:')
Bram Moolenaaree4e0c12020-04-06 21:35:05 +0200788 endif
789
790 " Try using a very long terminal code. Define a dummy terminal code for this
791 " test.
792 let &t_fo = "\<Esc>1;"
793 let c = repeat("t_fo,", 100) . "t_fo"
794 call assert_fails('exe "hi Xgroup1 start=" . c', 'E422:')
795 let &t_fo = ""
796endfunc
797
Bram Moolenaar75e15672020-06-28 13:10:22 +0200798" Test for 'highlight' option
799func Test_highlight_opt()
800 let save_hl = &highlight
801 call assert_fails('set highlight=j:b', 'E474:')
802 set highlight=f\ r
803 call assert_equal('f r', &highlight)
804 set highlight=fb
805 call assert_equal('fb', &highlight)
806 set highlight=fi
807 call assert_equal('fi', &highlight)
808 set highlight=f-
809 call assert_equal('f-', &highlight)
810 set highlight=fr
811 call assert_equal('fr', &highlight)
812 set highlight=fs
813 call assert_equal('fs', &highlight)
814 set highlight=fu
815 call assert_equal('fu', &highlight)
816 set highlight=fc
817 call assert_equal('fc', &highlight)
818 set highlight=ft
819 call assert_equal('ft', &highlight)
820 call assert_fails('set highlight=fr:Search', 'E474:')
821 set highlight=f:$#
822 call assert_match('W18:', v:statusmsg)
823 let &highlight = save_hl
824endfunc
825
826" Test for User group highlighting used in the statusline
827func Test_highlight_User()
828 CheckNotGui
829 hi User1 ctermfg=12
830 redraw!
831 call assert_equal('12', synIDattr(synIDtrans(hlID('User1')), 'fg'))
832 hi clear
833endfunc
834
835" Test for using RGB color values in a highlight group
Bram Moolenaar09fbedc2021-01-19 17:22:58 +0100836func Test_xxlast_highlight_RGB_color()
837 CheckCanRunGui
838 gui -f
Bram Moolenaar75e15672020-06-28 13:10:22 +0200839 hi MySearch guifg=#110000 guibg=#001100 guisp=#000011
840 call assert_equal('#110000', synIDattr(synIDtrans(hlID('MySearch')), 'fg#'))
841 call assert_equal('#001100', synIDattr(synIDtrans(hlID('MySearch')), 'bg#'))
842 call assert_equal('#000011', synIDattr(synIDtrans(hlID('MySearch')), 'sp#'))
843 hi clear
844endfunc
845
Bram Moolenaarde8f0f42020-06-30 18:45:43 +0200846" Test for using default highlighting group
847func Test_highlight_default()
848 highlight MySearch ctermfg=7
849 highlight default MySearch ctermfg=5
850 let hlSearch = HighlightArgs('MySearch')
851 call assert_match('ctermfg=7', hlSearch)
852
853 highlight default QFName ctermfg=3
854 call assert_match('ctermfg=3', HighlightArgs('QFName'))
855 hi clear
856endfunc
857
858" Test for 'ctermul in a highlight group
859func Test_highlight_ctermul()
860 CheckNotGui
861 call assert_notmatch('ctermul=', HighlightArgs('Normal'))
862 highlight Normal ctermul=3
863 call assert_match('ctermul=3', HighlightArgs('Normal'))
Bram Moolenaar391c3622020-09-29 20:59:17 +0200864 call assert_equal('3', synIDattr(synIDtrans(hlID('Normal')), 'ul'))
Bram Moolenaarde8f0f42020-06-30 18:45:43 +0200865 highlight Normal ctermul=NONE
866endfunc
867
868" Test for specifying 'start' and 'stop' in a highlight group
869func Test_highlight_start_stop()
870 hi HlGrp1 start=<Esc>[27h;<Esc>[<Space>r;
871 call assert_match("start=^[[27h;^[[ r;", HighlightArgs('HlGrp1'))
872 hi HlGrp1 start=NONE
873 call assert_notmatch("start=", HighlightArgs('HlGrp1'))
874 hi HlGrp2 stop=<Esc>[27h;<Esc>[<Space>r;
875 call assert_match("stop=^[[27h;^[[ r;", HighlightArgs('HlGrp2'))
876 hi HlGrp2 stop=NONE
877 call assert_notmatch("stop=", HighlightArgs('HlGrp2'))
878 hi clear
879endfunc
880
881" Test for setting various 'term' attributes
882func Test_highlight_term_attr()
883 hi HlGrp3 term=bold,underline,undercurl,strikethrough,reverse,italic,standout
884 call assert_equal('hi HlGrp3 term=bold,standout,underline,undercurl,italic,reverse,strikethrough', HighlightArgs('HlGrp3'))
885 hi HlGrp3 term=NONE
886 call assert_equal('hi HlGrp3 cleared', HighlightArgs('HlGrp3'))
887 hi clear
888endfunc
889
Bram Moolenaar213da552020-09-17 19:59:26 +0200890func Test_highlight_clear_restores_links()
891 let aaa_id = hlID('aaa')
892 call assert_equal(aaa_id, 0)
893
894 " create default link aaa --> bbb
895 hi def link aaa bbb
896 let id_aaa = hlID('aaa')
897 let hl_aaa_bbb = HighlightArgs('aaa')
898
899 " try to redefine default link aaa --> ccc; check aaa --> bbb
900 hi def link aaa ccc
901 call assert_equal(HighlightArgs('aaa'), hl_aaa_bbb)
902
903 " clear aaa; check aaa --> bbb
904 hi clear aaa
905 call assert_equal(HighlightArgs('aaa'), hl_aaa_bbb)
906
907 " link aaa --> ccc; clear aaa; check aaa --> bbb
908 hi link aaa ccc
909 let id_ccc = hlID('ccc')
910 call assert_equal(synIDtrans(id_aaa), id_ccc)
911 hi clear aaa
912 call assert_equal(HighlightArgs('aaa'), hl_aaa_bbb)
913
914 " forcibly set default link aaa --> ddd
915 hi! def link aaa ddd
916 let id_ddd = hlID('ddd')
917 let hl_aaa_ddd = HighlightArgs('aaa')
918 call assert_equal(synIDtrans(id_aaa), id_ddd)
919
920 " link aaa --> eee; clear aaa; check aaa --> ddd
921 hi link aaa eee
922 let eee_id = hlID('eee')
923 call assert_equal(synIDtrans(id_aaa), eee_id)
924 hi clear aaa
925 call assert_equal(HighlightArgs('aaa'), hl_aaa_ddd)
926endfunc
927
Bram Moolenaare8df0102020-09-18 19:40:45 +0200928func Test_highlight_clear_restores_context()
929 func FuncContextDefault()
930 hi def link Context ContextDefault
931 endfun
932
933 func FuncContextRelink()
934 " Dummy line
935 hi link Context ContextRelink
936 endfunc
937
938 let scriptContextDefault = MakeScript("FuncContextDefault")
939 let scriptContextRelink = MakeScript("FuncContextRelink")
940 let patContextDefault = fnamemodify(scriptContextDefault, ':t') .. ' line 1'
941 let patContextRelink = fnamemodify(scriptContextRelink, ':t') .. ' line 2'
942
Bram Moolenaar2bbada82020-09-18 21:55:26 +0200943 exec 'source ' .. scriptContextDefault
Bram Moolenaare8df0102020-09-18 19:40:45 +0200944 let hlContextDefault = execute("verbose hi Context")
945 call assert_match(patContextDefault, hlContextDefault)
946
Bram Moolenaar2bbada82020-09-18 21:55:26 +0200947 exec 'source ' .. scriptContextRelink
Bram Moolenaare8df0102020-09-18 19:40:45 +0200948 let hlContextRelink = execute("verbose hi Context")
949 call assert_match(patContextRelink, hlContextRelink)
950
951 hi clear
952 let hlContextAfterClear = execute("verbose hi Context")
953 call assert_match(patContextDefault, hlContextAfterClear)
954
955 delfunc FuncContextDefault
956 delfunc FuncContextRelink
957 call delete(scriptContextDefault)
958 call delete(scriptContextRelink)
959endfunc
960
Bram Moolenaar213da552020-09-17 19:59:26 +0200961func Test_highlight_default_colorscheme_restores_links()
962 hi link TestLink Identifier
963 hi TestHi ctermbg=red
Bram Moolenaar05eb5b92020-09-16 15:43:21 +0200964
965 let hlTestLinkPre = HighlightArgs('TestLink')
966 let hlTestHiPre = HighlightArgs('TestHi')
967
968 " Test colorscheme
Dominique Pelle8bfa0eb2022-01-02 16:16:33 +0000969 call assert_equal("\ndefault", execute('colorscheme'))
Bram Moolenaar05eb5b92020-09-16 15:43:21 +0200970 hi clear
971 if exists('syntax_on')
972 syntax reset
973 endif
974 let g:colors_name = 'test'
Dominique Pelle8bfa0eb2022-01-02 16:16:33 +0000975 call assert_equal("\ntest", execute('colorscheme'))
Bram Moolenaar213da552020-09-17 19:59:26 +0200976 hi link TestLink ErrorMsg
977 hi TestHi ctermbg=green
Bram Moolenaar05eb5b92020-09-16 15:43:21 +0200978
979 " Restore default highlighting
980 colorscheme default
Bram Moolenaar05eb5b92020-09-16 15:43:21 +0200981 " 'default' should work no matter if highlight group was cleared
Dominique Pelle8bfa0eb2022-01-02 16:16:33 +0000982 call assert_equal("\ndefault", execute('colorscheme'))
Bram Moolenaar05eb5b92020-09-16 15:43:21 +0200983 hi def link TestLink Identifier
984 hi def TestHi ctermbg=red
Bram Moolenaar05eb5b92020-09-16 15:43:21 +0200985 let hlTestLinkPost = HighlightArgs('TestLink')
986 let hlTestHiPost = HighlightArgs('TestHi')
Bram Moolenaar05eb5b92020-09-16 15:43:21 +0200987 call assert_equal(hlTestLinkPre, hlTestLinkPost)
988 call assert_equal(hlTestHiPre, hlTestHiPost)
989 hi clear
990endfunc
991
Drew Vogele30d1022021-10-24 20:35:07 +0100992func Test_colornames_assignment_and_lookup()
Drew Vogela0fca172021-11-13 10:50:01 +0000993 CheckAnyOf Feature:gui_running Feature:termguicolors
994
Drew Vogele30d1022021-10-24 20:35:07 +0100995 " Ensure highlight command can find custom color.
996 let v:colornames['a redish white'] = '#ffeedd'
997 highlight Normal guifg='a redish white'
998 highlight clear
Drew Vogela0fca172021-11-13 10:50:01 +0000999 call ClearDict(v:colornames)
Drew Vogele30d1022021-10-24 20:35:07 +01001000endfunc
1001
1002func Test_colornames_default_list()
Drew Vogela0fca172021-11-13 10:50:01 +00001003 CheckAnyOf Feature:gui_running Feature:termguicolors
1004
Drew Vogele30d1022021-10-24 20:35:07 +01001005 " Ensure default lists are loaded automatically and can be used for all gui fields.
Drew Vogela0fca172021-11-13 10:50:01 +00001006 call assert_equal(0, len(v:colornames))
Drew Vogele30d1022021-10-24 20:35:07 +01001007 highlight Normal guifg='rebecca purple' guibg='rebecca purple' guisp='rebecca purple'
Drew Vogela0fca172021-11-13 10:50:01 +00001008 call assert_notequal(0, len(v:colornames))
1009 echo v:colornames['rebecca purple']
Drew Vogele30d1022021-10-24 20:35:07 +01001010 highlight clear
Drew Vogela0fca172021-11-13 10:50:01 +00001011 call ClearDict(v:colornames)
Drew Vogele30d1022021-10-24 20:35:07 +01001012endfunc
1013
1014func Test_colornames_overwrite_default()
Drew Vogela0fca172021-11-13 10:50:01 +00001015 CheckAnyOf Feature:gui_running Feature:termguicolors
1016
Drew Vogele30d1022021-10-24 20:35:07 +01001017 " Ensure entries in v:colornames can be overwritten.
1018 " Load default color scheme to trigger default color list loading.
1019 colorscheme default
1020 let old_rebecca_purple = v:colornames['rebecca purple']
1021 highlight Normal guifg='rebecca purple' guibg='rebecca purple'
1022 let v:colornames['rebecca purple'] = '#550099'
1023 highlight Normal guifg='rebecca purple' guibg='rebecca purple'
1024 let v:colornames['rebecca purple'] = old_rebecca_purple
1025 highlight clear
1026endfunc
1027
1028func Test_colornames_assignment_and_unassignment()
Drew Vogela0fca172021-11-13 10:50:01 +00001029 " No feature check is needed for this test because the v:colornames dict
1030 " always exists with +eval. The feature checks are only required for
1031 " commands that do color lookup.
1032
Drew Vogele30d1022021-10-24 20:35:07 +01001033 " Ensure we cannot overwrite the v:colornames dict.
1034 call assert_fails("let v:colornames = {}", 'E46:')
1035
1036 " Ensure we can delete entries from the v:colornames dict.
1037 let v:colornames['x1'] = '#111111'
1038 call assert_equal(v:colornames['x1'], '#111111')
1039 unlet v:colornames['x1']
1040 call assert_fails("echo v:colornames['x1']")
1041endfunc
1042
Yegappan Lakshmanand1a8d652021-11-03 21:56:45 +00001043" Test for the hlget() function
1044func Test_hlget()
1045 let lines =<< trim END
1046 call assert_notequal([], filter(hlget(), 'v:val.name == "Visual"'))
1047 call assert_equal([], hlget('SomeHLGroup'))
1048 highlight MyHLGroup term=standout cterm=reverse ctermfg=10 ctermbg=Black
1049 call assert_equal([{'id': hlID('MyHLGroup'), 'ctermfg': '10', 'name': 'MyHLGroup', 'term': {'standout': v:true}, 'ctermbg': '0', 'cterm': {'reverse': v:true}}], hlget('MyHLGroup'))
1050 highlight clear MyHLGroup
1051 call assert_equal(v:true, hlget('MyHLGroup')[0].cleared)
1052 highlight link MyHLGroup IncSearch
1053 call assert_equal('IncSearch', hlget('MyHLGroup')[0].linksto)
1054 highlight clear MyHLGroup
1055 call assert_equal([], hlget(test_null_string()))
1056 call assert_equal([], hlget(""))
1057 END
Bram Moolenaar62aec932022-01-29 21:45:34 +00001058 call v9.CheckLegacyAndVim9Success(lines)
Yegappan Lakshmanand1a8d652021-11-03 21:56:45 +00001059
1060 " Test for resolving highlight group links
1061 let lines =<< trim END
1062 highlight hlgA term=bold
1063 VAR hlgAid = hlID('hlgA')
1064 highlight link hlgB hlgA
1065 VAR hlgBid = hlID('hlgB')
1066 highlight link hlgC hlgB
1067 VAR hlgCid = hlID('hlgC')
1068 call assert_equal('hlgA', hlget('hlgB')[0].linksto)
1069 call assert_equal('hlgB', hlget('hlgC')[0].linksto)
1070 call assert_equal([{'id': hlgAid, 'name': 'hlgA',
1071 \ 'term': {'bold': v:true}}], hlget('hlgA'))
1072 call assert_equal([{'id': hlgBid, 'name': 'hlgB',
1073 \ 'linksto': 'hlgA'}], hlget('hlgB'))
1074 call assert_equal([{'id': hlgCid, 'name': 'hlgC',
1075 \ 'linksto': 'hlgB'}], hlget('hlgC'))
1076 call assert_equal([{'id': hlgAid, 'name': 'hlgA',
1077 \ 'term': {'bold': v:true}}], hlget('hlgA', v:false))
1078 call assert_equal([{'id': hlgBid, 'name': 'hlgB',
1079 \ 'linksto': 'hlgA'}], hlget('hlgB', 0))
1080 call assert_equal([{'id': hlgCid, 'name': 'hlgC',
1081 \ 'linksto': 'hlgB'}], hlget('hlgC', v:false))
1082 call assert_equal([{'id': hlgAid, 'name': 'hlgA',
1083 \ 'term': {'bold': v:true}}], hlget('hlgA', v:true))
1084 call assert_equal([{'id': hlgBid, 'name': 'hlgB',
1085 \ 'term': {'bold': v:true}}], hlget('hlgB', 1))
1086 call assert_equal([{'id': hlgCid, 'name': 'hlgC',
1087 \ 'term': {'bold': v:true}}], hlget('hlgC', v:true))
1088 END
Bram Moolenaar62aec932022-01-29 21:45:34 +00001089 call v9.CheckLegacyAndVim9Success(lines)
Yegappan Lakshmanand1a8d652021-11-03 21:56:45 +00001090
1091 call assert_fails('call hlget([])', 'E1174:')
1092 call assert_fails('call hlget("abc", "xyz")', 'E1212:')
1093endfunc
1094
1095" Test for the hlset() function
1096func Test_hlset()
1097 let lines =<< trim END
1098 call assert_equal(0, hlset(test_null_list()))
1099 call assert_equal(0, hlset([]))
1100 call assert_fails('call hlset(["Search"])', 'E715:')
1101 call hlset(hlget())
1102 call hlset([{'name': 'NewHLGroup', 'cterm': {'reverse': v:true}, 'ctermfg': '10'}])
1103 call assert_equal({'reverse': v:true}, hlget('NewHLGroup')[0].cterm)
1104 call hlset([{'name': 'NewHLGroup', 'cterm': {'bold': v:true}}])
1105 call assert_equal({'bold': v:true}, hlget('NewHLGroup')[0].cterm)
1106 call hlset([{'name': 'NewHLGroup', 'cleared': v:true}])
1107 call assert_equal(v:true, hlget('NewHLGroup')[0].cleared)
1108 call hlset([{'name': 'NewHLGroup', 'linksto': 'Search'}])
1109 call assert_false(has_key(hlget('NewHLGroup')[0], 'cleared'))
1110 call assert_equal('Search', hlget('NewHLGroup')[0].linksto)
1111 call assert_fails("call hlset([{'name': [], 'ctermfg': '10'}])", 'E928:')
1112 call assert_fails("call hlset([{'name': 'NewHLGroup', 'cleared': []}])",
1113 \ 'E745:')
1114 call assert_fails("call hlset([{'name': 'NewHLGroup', 'cterm': 'Blue'}])",
1115 \ 'E715:')
1116 call assert_fails("call hlset([{'name': 'NewHLGroup', 'ctermbg': []}])",
1117 \ 'E928:')
1118 call assert_fails("call hlset([{'name': 'NewHLGroup', 'ctermfg': []}])",
1119 \ 'E928:')
1120 call assert_fails("call hlset([{'name': 'NewHLGroup', 'ctermul': []}])",
1121 \ 'E928:')
1122 if has('gui')
1123 call assert_fails("call hlset([{'name': 'NewHLGroup', 'font': []}])",
1124 \ 'E928:')
1125 endif
1126 call assert_fails("call hlset([{'name': 'NewHLGroup', 'gui': 'Cyan'}])",
1127 \ 'E715:')
1128 call assert_fails("call hlset([{'name': 'NewHLGroup', 'guibg': []}])",
1129 \ 'E928:')
1130 call assert_fails("call hlset([{'name': 'NewHLGroup', 'guifg': []}])",
1131 \ 'E928:')
1132 call assert_fails("call hlset([{'name': 'NewHLGroup', 'guisp': []}])",
1133 \ 'E928:')
1134 call assert_fails("call hlset([{'name': 'NewHLGroup', 'linksto': []}])",
1135 \ 'E928:')
1136 call assert_fails("call hlset([{'name': 'NewHLGroup', 'start': []}])",
1137 \ 'E928:')
1138 call assert_fails("call hlset([{'name': 'NewHLGroup', 'stop': []}])",
1139 \ 'E928:')
1140 call assert_fails("call hlset([{'name': 'NewHLGroup', 'term': 'Cyan'}])",
1141 \ 'E715:')
1142 call assert_equal('Search', hlget('NewHLGroup')[0].linksto)
1143 highlight clear NewHLGroup
1144 END
Bram Moolenaar62aec932022-01-29 21:45:34 +00001145 call v9.CheckLegacyAndVim9Success(lines)
Yegappan Lakshmanand1a8d652021-11-03 21:56:45 +00001146
1147 " Test for clearing the 'term', 'cterm' and 'gui' attributes of a highlight
1148 " group.
1149 let lines =<< trim END
1150 highlight myhlg1 term=bold cterm=italic gui=standout
1151 VAR id = hlID('myhlg1')
1152 call hlset([{'name': 'myhlg1', 'term': {}}])
1153 call assert_equal([{'id': id, 'name': 'myhlg1',
1154 \ 'cterm': {'italic': v:true}, 'gui': {'standout': v:true}}],
1155 \ hlget('myhlg1'))
1156 call hlset([{'name': 'myhlg1', 'cterm': {}}])
1157 call assert_equal([{'id': id, 'name': 'myhlg1',
1158 \ 'gui': {'standout': v:true}}], hlget('myhlg1'))
1159 call hlset([{'name': 'myhlg1', 'gui': {}}])
1160 call assert_equal([{'id': id, 'name': 'myhlg1', 'cleared': v:true}],
1161 \ hlget('myhlg1'))
1162 highlight clear myhlg1
1163 END
Bram Moolenaar62aec932022-01-29 21:45:34 +00001164 call v9.CheckLegacyAndVim9Success(lines)
Yegappan Lakshmanand1a8d652021-11-03 21:56:45 +00001165
1166 " Test for setting all the 'term', 'cterm' and 'gui' attributes of a
1167 " highlight group
1168 let lines =<< trim END
1169 VAR attr = {'bold': v:true, 'underline': v:true, 'undercurl': v:true,
1170 \ 'strikethrough': v:true, 'reverse': v:true, 'italic': v:true,
1171 \ 'standout': v:true, 'nocombine': v:true}
1172 call hlset([{'name': 'myhlg2', 'term': attr, 'cterm': attr, 'gui': attr}])
1173 VAR id2 = hlID('myhlg2')
Yegappan Lakshmanan2a16dc62021-11-16 17:19:30 +00001174 VAR expected = "myhlg2 xxx term=bold,standout,underline,undercurl,italic,reverse,nocombine,strikethrough cterm=bold,standout,underline,undercurl,italic,reverse,nocombine,strikethrough gui=bold,standout,underline,undercurl,italic,reverse,nocombine,strikethrough"
1175 VAR output = execute('highlight myhlg2')
1176 LET output = output->split("\n")->join()->substitute('\s\+', ' ', 'g')
1177 call assert_equal(expected, output)
Yegappan Lakshmanand1a8d652021-11-03 21:56:45 +00001178 call assert_equal([{'id': id2, 'name': 'myhlg2', 'gui': attr,
1179 \ 'term': attr, 'cterm': attr}], hlget('myhlg2'))
1180 END
Bram Moolenaar62aec932022-01-29 21:45:34 +00001181 call v9.CheckLegacyAndVim9Success(lines)
Yegappan Lakshmanand1a8d652021-11-03 21:56:45 +00001182
1183 " Test for clearing some of the 'term', 'cterm' and 'gui' attributes of a
1184 " highlight group
1185 let lines =<< trim END
1186 VAR attr = {'bold': v:false, 'underline': v:true, 'strikethrough': v:true}
1187 call hlset([{'name': 'myhlg2', 'term': attr, 'cterm': attr, 'gui': attr}])
1188 VAR id2 = hlID('myhlg2')
Yegappan Lakshmanan2a16dc62021-11-16 17:19:30 +00001189 VAR expected = "myhlg2 xxx term=underline,strikethrough cterm=underline,strikethrough gui=underline,strikethrough"
1190 VAR output = execute('highlight myhlg2')
1191 LET output = output->split("\n")->join()->substitute('\s\+', ' ', 'g')
1192 call assert_equal(expected, output)
Yegappan Lakshmanand1a8d652021-11-03 21:56:45 +00001193 LET attr = {'underline': v:true, 'strikethrough': v:true}
1194 call assert_equal([{'id': id2, 'name': 'myhlg2', 'gui': attr,
1195 \ 'term': attr, 'cterm': attr}], hlget('myhlg2'))
1196 END
Bram Moolenaar62aec932022-01-29 21:45:34 +00001197 call v9.CheckLegacyAndVim9Success(lines)
Dominique Pelle6a950a62021-11-13 18:44:37 +00001198
Yegappan Lakshmanan2a16dc62021-11-16 17:19:30 +00001199 " Test for clearing the attributes and link of a highlight group
1200 let lines =<< trim END
1201 highlight myhlg3 ctermbg=green guibg=green
1202 highlight! default link myhlg3 ErrorMsg
1203 VAR id3 = hlID('myhlg3')
1204 call hlset([{'name': 'myhlg3', 'cleared': v:true, 'linksto': 'NONE'}])
1205 call assert_equal([{'id': id3, 'name': 'myhlg3', 'cleared': v:true}],
1206 \ hlget('myhlg3'))
1207 highlight clear hlg3
1208 END
Bram Moolenaar62aec932022-01-29 21:45:34 +00001209 call v9.CheckLegacyAndVim9Success(lines)
Yegappan Lakshmanan2a16dc62021-11-16 17:19:30 +00001210
1211 " Test for setting default attributes for a highlight group
1212 let lines =<< trim END
1213 call hlset([{'name': 'hlg4', 'ctermfg': '8'}])
1214 call hlset([{'name': 'hlg4', 'default': v:true, 'ctermfg': '9'}])
1215 VAR id4 = hlID('hlg4')
1216 call assert_equal([{'id': id4, 'name': 'hlg4', 'ctermfg': '8'}],
1217 \ hlget('hlg4'))
1218 highlight clear hlg4
1219
1220 call hlset([{'name': 'hlg5', 'default': v:true, 'ctermbg': '2'}])
1221 call hlset([{'name': 'hlg5', 'ctermbg': '4'}])
1222 VAR id5 = hlID('hlg5')
1223 call assert_equal([{'id': id5, 'name': 'hlg5', 'ctermbg': '4'}],
1224 \ hlget('hlg5'))
1225 highlight clear hlg5
1226
1227 call hlset([{'name': 'hlg6', 'linksto': 'Error'}])
1228 VAR id6 = hlID('hlg6')
1229 call hlset([{'name': 'hlg6', 'default': v:true, 'ctermbg': '2'}])
1230 call assert_equal([{'id': id6, 'name': 'hlg6', 'linksto': 'Error'}],
1231 \ hlget('hlg6'))
1232 highlight clear hlg6
1233 END
Bram Moolenaar62aec932022-01-29 21:45:34 +00001234 call v9.CheckLegacyAndVim9Success(lines)
Yegappan Lakshmanan2a16dc62021-11-16 17:19:30 +00001235
1236 " Test for setting default links for a highlight group
1237 let lines =<< trim END
1238 call hlset([{'name': 'hlg7', 'ctermfg': '5'}])
1239 call hlset([{'name': 'hlg7', 'default': v:true, 'linksto': 'Search'}])
1240 VAR id7 = hlID('hlg7')
1241 call assert_equal([{'id': id7, 'name': 'hlg7', 'ctermfg': '5'}],
1242 \ hlget('hlg7'))
1243 highlight clear hlg7
1244
1245 call hlset([{'name': 'hlg8', 'default': v:true, 'linksto': 'Search'}])
1246 VAR id8 = hlID('hlg8')
1247 call assert_equal([{'id': id8, 'name': 'hlg8', 'default': v:true,
1248 \ 'linksto': 'Search'}], hlget('hlg8'))
1249 call hlset([{'name': 'hlg8', 'ctermbg': '2'}])
1250 call assert_equal([{'id': id8, 'name': 'hlg8', 'ctermbg': '2'}],
1251 \ hlget('hlg8'))
1252 highlight clear hlg8
1253
1254 highlight default link hlg9 ErrorMsg
1255 VAR hlg_save = hlget('hlg9')
1256 LET hlg_save[0]['name'] = 'hlg9dup'
1257 call hlset(hlg_save)
1258 VAR id9 = hlID('hlg9dup')
1259 highlight clear hlg9dup
1260 call assert_equal([{'id': id9, 'name': 'hlg9dup', 'default': v:true,
1261 \ 'linksto': 'ErrorMsg'}], hlget('hlg9dup'))
1262 highlight clear hlg9
1263 END
Bram Moolenaar62aec932022-01-29 21:45:34 +00001264 call v9.CheckLegacyAndVim9Success(lines)
Yegappan Lakshmanan2a16dc62021-11-16 17:19:30 +00001265
1266 " Test for force creating a link to a highlight group
1267 let lines =<< trim END
1268 call hlset([{'name': 'hlg10', 'ctermfg': '8'}])
1269 call hlset([{'name': 'hlg10', 'linksto': 'Search'}])
1270 VAR id10 = hlID('hlg10')
1271 call assert_equal([{'id': id10, 'name': 'hlg10', 'ctermfg': '8'}],
1272 \ hlget('hlg10'))
1273 call hlset([{'name': 'hlg10', 'linksto': 'Search', 'force': v:true}])
1274 call assert_equal([{'id': id10, 'name': 'hlg10', 'ctermfg': '8',
1275 \ 'linksto': 'Search'}], hlget('hlg10'))
1276 highlight clear hlg10
1277 END
Bram Moolenaar62aec932022-01-29 21:45:34 +00001278 call v9.CheckLegacyAndVim9Success(lines)
Yegappan Lakshmananbb277fd2021-11-24 20:28:31 +00001279
1280 " Test for empty values of attributes
1281 call hlset([{'name': 'hlg11', 'cterm': {}}])
1282 call hlset([{'name': 'hlg11', 'ctermfg': ''}])
1283 call hlset([{'name': 'hlg11', 'ctermbg': ''}])
1284 call hlset([{'name': 'hlg11', 'ctermul': ''}])
1285 call hlset([{'name': 'hlg11', 'font': ''}])
1286 call hlset([{'name': 'hlg11', 'gui': {}}])
1287 call hlset([{'name': 'hlg11', 'guifg': ''}])
1288 call hlset([{'name': 'hlg11', 'guibg': ''}])
1289 call hlset([{'name': 'hlg11', 'guisp': ''}])
1290 call hlset([{'name': 'hlg11', 'start': ''}])
1291 call hlset([{'name': 'hlg11', 'stop': ''}])
1292 call hlset([{'name': 'hlg11', 'term': {}}])
1293 call assert_true(hlget('hlg11')[0].cleared)
Yegappan Lakshmanand1a8d652021-11-03 21:56:45 +00001294endfunc
1295
Bram Moolenaaree4e0c12020-04-06 21:35:05 +02001296" vim: shiftwidth=2 sts=2 expandtab