blob: b07ba1174a446d4e6198b277e532710f16ff4946 [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
zeertzjq3e559cd2022-03-27 19:26:55 +0100595func Test_cursorcolumn_callback()
596 CheckScreendump
597 CheckFeature timers
598
599 let lines =<< trim END
600 call setline(1, ['aaaaa', 'bbbbb', 'ccccc', 'ddddd'])
601 set cursorcolumn
602 call cursor(4, 5)
603
604 func Func(timer)
605 call cursor(1, 1)
606 endfunc
607
608 call timer_start(300, 'Func')
609 END
610 call writefile(lines, 'Xcuc_timer')
611
612 let buf = RunVimInTerminal('-S Xcuc_timer', #{rows: 8})
613 call TermWait(buf, 310)
614 call VerifyScreenDump(buf, 'Test_cursorcolumn_callback_1', {})
615
616 call StopVimInTerminal(buf)
617 call delete('Xcuc_timer')
618endfunc
619
Bram Moolenaar193ffd12019-05-25 22:57:30 +0200620func Test_wincolor()
Bram Moolenaar8c5a2782019-08-07 23:07:07 +0200621 CheckScreendump
Bram Moolenaar3180fe62020-02-02 13:47:06 +0100622 " make sure the width is enough for the test
623 set columns=80
Bram Moolenaar193ffd12019-05-25 22:57:30 +0200624
Bram Moolenaare7eb9272019-06-24 00:58:07 +0200625 let lines =<< trim END
626 set cursorline cursorcolumn rnu
Bram Moolenaar053f7122019-09-23 22:17:15 +0200627 call setline(1, ["","1111111111","22222222222","3 here 3","","the cat is out of the bag"])
Bram Moolenaare7eb9272019-06-24 00:58:07 +0200628 set wincolor=Pmenu
Bram Moolenaar053f7122019-09-23 22:17:15 +0200629 hi CatLine guifg=green ctermfg=green
630 hi Reverse gui=reverse cterm=reverse
631 syn match CatLine /^the.*/
632 call prop_type_add("foo", {"highlight": "Reverse", "combine": 1})
633 call prop_add(6, 12, {"type": "foo", "end_col": 15})
Bram Moolenaare7eb9272019-06-24 00:58:07 +0200634 /here
635 END
636 call writefile(lines, 'Xtest_wincolor')
Bram Moolenaar193ffd12019-05-25 22:57:30 +0200637 let buf = RunVimInTerminal('-S Xtest_wincolor', {'rows': 8})
Bram Moolenaar6a2c5a72020-04-08 21:50:25 +0200638 call TermWait(buf)
Bram Moolenaar193ffd12019-05-25 22:57:30 +0200639 call term_sendkeys(buf, "2G5lvj")
Bram Moolenaar6a2c5a72020-04-08 21:50:25 +0200640 call TermWait(buf)
Bram Moolenaar193ffd12019-05-25 22:57:30 +0200641
642 call VerifyScreenDump(buf, 'Test_wincolor_01', {})
643
644 " clean up
645 call term_sendkeys(buf, "\<Esc>")
646 call StopVimInTerminal(buf)
647 call delete('Xtest_wincolor')
648endfunc
649
Bram Moolenaar42e931b2019-12-04 19:08:50 +0100650func Test_wincolor_listchars()
651 CheckScreendump
Bram Moolenaar705724e2020-01-31 21:13:42 +0100652 CheckFeature conceal
Bram Moolenaar42e931b2019-12-04 19:08:50 +0100653
654 let lines =<< trim END
655 call setline(1, ["one","\t\tsome random text enough long to show 'extends' and 'precedes' includingnbsps, preceding tabs and trailing spaces ","three"])
656 set wincolor=Todo
657 set nowrap cole=1 cocu+=n
658 set list lcs=eol:$,tab:>-,space:.,trail:_,extends:>,precedes:<,conceal:*,nbsp:#
659 call matchadd('Conceal', 'text')
660 normal 2G5zl
661 END
662 call writefile(lines, 'Xtest_wincolorlcs')
663 let buf = RunVimInTerminal('-S Xtest_wincolorlcs', {'rows': 8})
664
665 call VerifyScreenDump(buf, 'Test_wincolor_lcs', {})
666
667 " clean up
668 call term_sendkeys(buf, "\<Esc>")
669 call StopVimInTerminal(buf)
670 call delete('Xtest_wincolorlcs')
671endfunc
672
Bram Moolenaar010ee962019-09-25 20:37:36 +0200673func Test_colorcolumn()
674 CheckScreendump
675
676 " check that setting 'colorcolumn' when entering a buffer works
677 let lines =<< trim END
678 split
679 edit X
680 call setline(1, ["1111111111","22222222222","3333333333"])
681 set nomodified
682 set colorcolumn=3,9
683 set number cursorline cursorlineopt=number
684 wincmd w
685 buf X
686 END
687 call writefile(lines, 'Xtest_colorcolumn')
688 let buf = RunVimInTerminal('-S Xtest_colorcolumn', {'rows': 10})
689 call term_sendkeys(buf, ":\<CR>")
Bram Moolenaar010ee962019-09-25 20:37:36 +0200690 call VerifyScreenDump(buf, 'Test_colorcolumn_1', {})
691
692 " clean up
693 call StopVimInTerminal(buf)
694 call delete('Xtest_colorcolumn')
695endfunc
696
Bram Moolenaarad5e5632020-09-15 20:52:26 +0200697func Test_colorcolumn_bri()
698 CheckScreendump
699
700 " check 'colorcolumn' when 'breakindent' is set
701 let lines =<< trim END
702 call setline(1, 'The quick brown fox jumped over the lazy dogs')
703 END
704 call writefile(lines, 'Xtest_colorcolumn_bri')
705 let buf = RunVimInTerminal('-S Xtest_colorcolumn_bri', {'rows': 10,'columns': 40})
706 call term_sendkeys(buf, ":set co=40 linebreak bri briopt=shift:2 cc=40,41,43\<CR>")
Bram Moolenaarad5e5632020-09-15 20:52:26 +0200707 call VerifyScreenDump(buf, 'Test_colorcolumn_2', {})
708
709 " clean up
710 call StopVimInTerminal(buf)
711 call delete('Xtest_colorcolumn_bri')
712endfunc
713
714func Test_colorcolumn_sbr()
715 CheckScreendump
716
717 " check 'colorcolumn' when 'showbreak' is set
718 let lines =<< trim END
719 call setline(1, 'The quick brown fox jumped over the lazy dogs')
720 END
721 call writefile(lines, 'Xtest_colorcolumn_srb')
722 let buf = RunVimInTerminal('-S Xtest_colorcolumn_srb', {'rows': 10,'columns': 40})
723 call term_sendkeys(buf, ":set co=40 showbreak=+++>\\ cc=40,41,43\<CR>")
Bram Moolenaarad5e5632020-09-15 20:52:26 +0200724 call VerifyScreenDump(buf, 'Test_colorcolumn_3', {})
725
726 " clean up
727 call StopVimInTerminal(buf)
728 call delete('Xtest_colorcolumn_srb')
729endfunc
730
Bram Moolenaar6b528fa2019-05-09 20:07:33 +0200731" This test must come before the Test_cursorline test, as it appears this
732" defines the Normal highlighting group anyway.
Bram Moolenaarf90b6e02019-05-09 19:26:38 +0200733func Test_1_highlight_Normalgroup_exists()
Bram Moolenaar435f9f02019-07-03 21:40:16 +0200734 let hlNormal = HighlightArgs('Normal')
735 if !has('gui_running')
Bram Moolenaar6b528fa2019-05-09 20:07:33 +0200736 call assert_match('hi Normal\s*clear', hlNormal)
Bram Moolenaar435f9f02019-07-03 21:40:16 +0200737 elseif has('gui_gtk2') || has('gui_gnome') || has('gui_gtk3')
738 " expect is DEFAULT_FONT of gui_gtk_x11.c
739 call assert_match('hi Normal\s*font=Monospace 10', hlNormal)
740 elseif has('gui_motif') || has('gui_athena')
741 " expect is DEFAULT_FONT of gui_x11.c
742 call assert_match('hi Normal\s*font=7x13', hlNormal)
743 elseif has('win32')
744 " expect any font
745 call assert_match('hi Normal\s*font=.*', hlNormal)
Bram Moolenaar6b528fa2019-05-09 20:07:33 +0200746 endif
Bram Moolenaarf90b6e02019-05-09 19:26:38 +0200747endfunc
Bram Moolenaar548be7f2019-06-29 03:42:42 +0200748
Bram Moolenaar3180fe62020-02-02 13:47:06 +0100749" Do this test last, sometimes restoring the columns doesn't work
Bram Moolenaaree4e0c12020-04-06 21:35:05 +0200750func Test_z_no_space_before_xxx()
Bram Moolenaar548be7f2019-06-29 03:42:42 +0200751 let l:org_columns = &columns
752 set columns=17
753 let l:hi_StatusLineTermNC = join(split(execute('hi StatusLineTermNC')))
754 call assert_match('StatusLineTermNC xxx', l:hi_StatusLineTermNC)
755 let &columns = l:org_columns
Bram Moolenaaree4e0c12020-04-06 21:35:05 +0200756endfunc
757
758" Test for :highlight command errors
759func Test_highlight_cmd_errors()
760 if has('gui_running')
761 " This test doesn't fail in the MS-Windows console version.
Bram Moolenaar75e15672020-06-28 13:10:22 +0200762 call assert_fails('hi Xcomment ctermbg=fg', 'E419:')
Bram Moolenaaree4e0c12020-04-06 21:35:05 +0200763 call assert_fails('hi Xcomment ctermfg=bg', 'E420:')
Bram Moolenaar75e15672020-06-28 13:10:22 +0200764 call assert_fails('hi Xcomment ctermfg=ul', 'E453:')
erw7f7f7aaf2021-12-07 21:29:20 +0000765 call assert_fails('hi ' .. repeat('a', 201) .. ' ctermfg=black', 'E1249:')
Bram Moolenaaree4e0c12020-04-06 21:35:05 +0200766 endif
767
768 " Try using a very long terminal code. Define a dummy terminal code for this
769 " test.
770 let &t_fo = "\<Esc>1;"
771 let c = repeat("t_fo,", 100) . "t_fo"
772 call assert_fails('exe "hi Xgroup1 start=" . c', 'E422:')
773 let &t_fo = ""
774endfunc
775
Bram Moolenaar75e15672020-06-28 13:10:22 +0200776" Test for 'highlight' option
777func Test_highlight_opt()
778 let save_hl = &highlight
779 call assert_fails('set highlight=j:b', 'E474:')
780 set highlight=f\ r
781 call assert_equal('f r', &highlight)
782 set highlight=fb
783 call assert_equal('fb', &highlight)
784 set highlight=fi
785 call assert_equal('fi', &highlight)
786 set highlight=f-
787 call assert_equal('f-', &highlight)
788 set highlight=fr
789 call assert_equal('fr', &highlight)
790 set highlight=fs
791 call assert_equal('fs', &highlight)
792 set highlight=fu
793 call assert_equal('fu', &highlight)
794 set highlight=fc
795 call assert_equal('fc', &highlight)
796 set highlight=ft
797 call assert_equal('ft', &highlight)
798 call assert_fails('set highlight=fr:Search', 'E474:')
799 set highlight=f:$#
800 call assert_match('W18:', v:statusmsg)
801 let &highlight = save_hl
802endfunc
803
804" Test for User group highlighting used in the statusline
805func Test_highlight_User()
806 CheckNotGui
807 hi User1 ctermfg=12
808 redraw!
809 call assert_equal('12', synIDattr(synIDtrans(hlID('User1')), 'fg'))
810 hi clear
811endfunc
812
813" Test for using RGB color values in a highlight group
Bram Moolenaar09fbedc2021-01-19 17:22:58 +0100814func Test_xxlast_highlight_RGB_color()
815 CheckCanRunGui
816 gui -f
Bram Moolenaar75e15672020-06-28 13:10:22 +0200817 hi MySearch guifg=#110000 guibg=#001100 guisp=#000011
818 call assert_equal('#110000', synIDattr(synIDtrans(hlID('MySearch')), 'fg#'))
819 call assert_equal('#001100', synIDattr(synIDtrans(hlID('MySearch')), 'bg#'))
820 call assert_equal('#000011', synIDattr(synIDtrans(hlID('MySearch')), 'sp#'))
821 hi clear
822endfunc
823
Bram Moolenaarde8f0f42020-06-30 18:45:43 +0200824" Test for using default highlighting group
825func Test_highlight_default()
826 highlight MySearch ctermfg=7
827 highlight default MySearch ctermfg=5
828 let hlSearch = HighlightArgs('MySearch')
829 call assert_match('ctermfg=7', hlSearch)
830
831 highlight default QFName ctermfg=3
832 call assert_match('ctermfg=3', HighlightArgs('QFName'))
833 hi clear
834endfunc
835
836" Test for 'ctermul in a highlight group
837func Test_highlight_ctermul()
838 CheckNotGui
839 call assert_notmatch('ctermul=', HighlightArgs('Normal'))
840 highlight Normal ctermul=3
841 call assert_match('ctermul=3', HighlightArgs('Normal'))
Bram Moolenaar391c3622020-09-29 20:59:17 +0200842 call assert_equal('3', synIDattr(synIDtrans(hlID('Normal')), 'ul'))
Bram Moolenaarde8f0f42020-06-30 18:45:43 +0200843 highlight Normal ctermul=NONE
844endfunc
845
846" Test for specifying 'start' and 'stop' in a highlight group
847func Test_highlight_start_stop()
848 hi HlGrp1 start=<Esc>[27h;<Esc>[<Space>r;
849 call assert_match("start=^[[27h;^[[ r;", HighlightArgs('HlGrp1'))
850 hi HlGrp1 start=NONE
851 call assert_notmatch("start=", HighlightArgs('HlGrp1'))
852 hi HlGrp2 stop=<Esc>[27h;<Esc>[<Space>r;
853 call assert_match("stop=^[[27h;^[[ r;", HighlightArgs('HlGrp2'))
854 hi HlGrp2 stop=NONE
855 call assert_notmatch("stop=", HighlightArgs('HlGrp2'))
856 hi clear
857endfunc
858
859" Test for setting various 'term' attributes
860func Test_highlight_term_attr()
861 hi HlGrp3 term=bold,underline,undercurl,strikethrough,reverse,italic,standout
862 call assert_equal('hi HlGrp3 term=bold,standout,underline,undercurl,italic,reverse,strikethrough', HighlightArgs('HlGrp3'))
863 hi HlGrp3 term=NONE
864 call assert_equal('hi HlGrp3 cleared', HighlightArgs('HlGrp3'))
865 hi clear
866endfunc
867
Bram Moolenaar213da552020-09-17 19:59:26 +0200868func Test_highlight_clear_restores_links()
869 let aaa_id = hlID('aaa')
870 call assert_equal(aaa_id, 0)
871
872 " create default link aaa --> bbb
873 hi def link aaa bbb
874 let id_aaa = hlID('aaa')
875 let hl_aaa_bbb = HighlightArgs('aaa')
876
877 " try to redefine default link aaa --> ccc; check aaa --> bbb
878 hi def link aaa ccc
879 call assert_equal(HighlightArgs('aaa'), hl_aaa_bbb)
880
881 " clear aaa; check aaa --> bbb
882 hi clear aaa
883 call assert_equal(HighlightArgs('aaa'), hl_aaa_bbb)
884
885 " link aaa --> ccc; clear aaa; check aaa --> bbb
886 hi link aaa ccc
887 let id_ccc = hlID('ccc')
888 call assert_equal(synIDtrans(id_aaa), id_ccc)
889 hi clear aaa
890 call assert_equal(HighlightArgs('aaa'), hl_aaa_bbb)
891
892 " forcibly set default link aaa --> ddd
893 hi! def link aaa ddd
894 let id_ddd = hlID('ddd')
895 let hl_aaa_ddd = HighlightArgs('aaa')
896 call assert_equal(synIDtrans(id_aaa), id_ddd)
897
898 " link aaa --> eee; clear aaa; check aaa --> ddd
899 hi link aaa eee
900 let eee_id = hlID('eee')
901 call assert_equal(synIDtrans(id_aaa), eee_id)
902 hi clear aaa
903 call assert_equal(HighlightArgs('aaa'), hl_aaa_ddd)
904endfunc
905
Bram Moolenaare8df0102020-09-18 19:40:45 +0200906func Test_highlight_clear_restores_context()
907 func FuncContextDefault()
908 hi def link Context ContextDefault
909 endfun
910
911 func FuncContextRelink()
912 " Dummy line
913 hi link Context ContextRelink
914 endfunc
915
916 let scriptContextDefault = MakeScript("FuncContextDefault")
917 let scriptContextRelink = MakeScript("FuncContextRelink")
918 let patContextDefault = fnamemodify(scriptContextDefault, ':t') .. ' line 1'
919 let patContextRelink = fnamemodify(scriptContextRelink, ':t') .. ' line 2'
920
Bram Moolenaar2bbada82020-09-18 21:55:26 +0200921 exec 'source ' .. scriptContextDefault
Bram Moolenaare8df0102020-09-18 19:40:45 +0200922 let hlContextDefault = execute("verbose hi Context")
923 call assert_match(patContextDefault, hlContextDefault)
924
Bram Moolenaar2bbada82020-09-18 21:55:26 +0200925 exec 'source ' .. scriptContextRelink
Bram Moolenaare8df0102020-09-18 19:40:45 +0200926 let hlContextRelink = execute("verbose hi Context")
927 call assert_match(patContextRelink, hlContextRelink)
928
929 hi clear
930 let hlContextAfterClear = execute("verbose hi Context")
931 call assert_match(patContextDefault, hlContextAfterClear)
932
933 delfunc FuncContextDefault
934 delfunc FuncContextRelink
935 call delete(scriptContextDefault)
936 call delete(scriptContextRelink)
937endfunc
938
Bram Moolenaar213da552020-09-17 19:59:26 +0200939func Test_highlight_default_colorscheme_restores_links()
940 hi link TestLink Identifier
941 hi TestHi ctermbg=red
Bram Moolenaar05eb5b92020-09-16 15:43:21 +0200942
943 let hlTestLinkPre = HighlightArgs('TestLink')
944 let hlTestHiPre = HighlightArgs('TestHi')
945
946 " Test colorscheme
Dominique Pelle8bfa0eb2022-01-02 16:16:33 +0000947 call assert_equal("\ndefault", execute('colorscheme'))
Bram Moolenaar05eb5b92020-09-16 15:43:21 +0200948 hi clear
949 if exists('syntax_on')
950 syntax reset
951 endif
952 let g:colors_name = 'test'
Dominique Pelle8bfa0eb2022-01-02 16:16:33 +0000953 call assert_equal("\ntest", execute('colorscheme'))
Bram Moolenaar213da552020-09-17 19:59:26 +0200954 hi link TestLink ErrorMsg
955 hi TestHi ctermbg=green
Bram Moolenaar05eb5b92020-09-16 15:43:21 +0200956
957 " Restore default highlighting
958 colorscheme default
Bram Moolenaar05eb5b92020-09-16 15:43:21 +0200959 " 'default' should work no matter if highlight group was cleared
Dominique Pelle8bfa0eb2022-01-02 16:16:33 +0000960 call assert_equal("\ndefault", execute('colorscheme'))
Bram Moolenaar05eb5b92020-09-16 15:43:21 +0200961 hi def link TestLink Identifier
962 hi def TestHi ctermbg=red
Bram Moolenaar05eb5b92020-09-16 15:43:21 +0200963 let hlTestLinkPost = HighlightArgs('TestLink')
964 let hlTestHiPost = HighlightArgs('TestHi')
Bram Moolenaar05eb5b92020-09-16 15:43:21 +0200965 call assert_equal(hlTestLinkPre, hlTestLinkPost)
966 call assert_equal(hlTestHiPre, hlTestHiPost)
967 hi clear
968endfunc
969
Drew Vogele30d1022021-10-24 20:35:07 +0100970func Test_colornames_assignment_and_lookup()
Drew Vogela0fca172021-11-13 10:50:01 +0000971 CheckAnyOf Feature:gui_running Feature:termguicolors
972
Drew Vogele30d1022021-10-24 20:35:07 +0100973 " Ensure highlight command can find custom color.
974 let v:colornames['a redish white'] = '#ffeedd'
975 highlight Normal guifg='a redish white'
976 highlight clear
Drew Vogela0fca172021-11-13 10:50:01 +0000977 call ClearDict(v:colornames)
Drew Vogele30d1022021-10-24 20:35:07 +0100978endfunc
979
980func Test_colornames_default_list()
Drew Vogela0fca172021-11-13 10:50:01 +0000981 CheckAnyOf Feature:gui_running Feature:termguicolors
982
Drew Vogele30d1022021-10-24 20:35:07 +0100983 " Ensure default lists are loaded automatically and can be used for all gui fields.
Drew Vogela0fca172021-11-13 10:50:01 +0000984 call assert_equal(0, len(v:colornames))
Drew Vogele30d1022021-10-24 20:35:07 +0100985 highlight Normal guifg='rebecca purple' guibg='rebecca purple' guisp='rebecca purple'
Drew Vogela0fca172021-11-13 10:50:01 +0000986 call assert_notequal(0, len(v:colornames))
987 echo v:colornames['rebecca purple']
Drew Vogele30d1022021-10-24 20:35:07 +0100988 highlight clear
Drew Vogela0fca172021-11-13 10:50:01 +0000989 call ClearDict(v:colornames)
Drew Vogele30d1022021-10-24 20:35:07 +0100990endfunc
991
992func Test_colornames_overwrite_default()
Drew Vogela0fca172021-11-13 10:50:01 +0000993 CheckAnyOf Feature:gui_running Feature:termguicolors
994
Drew Vogele30d1022021-10-24 20:35:07 +0100995 " Ensure entries in v:colornames can be overwritten.
996 " Load default color scheme to trigger default color list loading.
997 colorscheme default
998 let old_rebecca_purple = v:colornames['rebecca purple']
999 highlight Normal guifg='rebecca purple' guibg='rebecca purple'
1000 let v:colornames['rebecca purple'] = '#550099'
1001 highlight Normal guifg='rebecca purple' guibg='rebecca purple'
1002 let v:colornames['rebecca purple'] = old_rebecca_purple
1003 highlight clear
1004endfunc
1005
1006func Test_colornames_assignment_and_unassignment()
Drew Vogela0fca172021-11-13 10:50:01 +00001007 " No feature check is needed for this test because the v:colornames dict
1008 " always exists with +eval. The feature checks are only required for
1009 " commands that do color lookup.
1010
Drew Vogele30d1022021-10-24 20:35:07 +01001011 " Ensure we cannot overwrite the v:colornames dict.
1012 call assert_fails("let v:colornames = {}", 'E46:')
1013
1014 " Ensure we can delete entries from the v:colornames dict.
1015 let v:colornames['x1'] = '#111111'
1016 call assert_equal(v:colornames['x1'], '#111111')
1017 unlet v:colornames['x1']
1018 call assert_fails("echo v:colornames['x1']")
1019endfunc
1020
Yegappan Lakshmanand1a8d652021-11-03 21:56:45 +00001021" Test for the hlget() function
1022func Test_hlget()
1023 let lines =<< trim END
1024 call assert_notequal([], filter(hlget(), 'v:val.name == "Visual"'))
1025 call assert_equal([], hlget('SomeHLGroup'))
1026 highlight MyHLGroup term=standout cterm=reverse ctermfg=10 ctermbg=Black
1027 call assert_equal([{'id': hlID('MyHLGroup'), 'ctermfg': '10', 'name': 'MyHLGroup', 'term': {'standout': v:true}, 'ctermbg': '0', 'cterm': {'reverse': v:true}}], hlget('MyHLGroup'))
1028 highlight clear MyHLGroup
1029 call assert_equal(v:true, hlget('MyHLGroup')[0].cleared)
1030 highlight link MyHLGroup IncSearch
1031 call assert_equal('IncSearch', hlget('MyHLGroup')[0].linksto)
1032 highlight clear MyHLGroup
1033 call assert_equal([], hlget(test_null_string()))
1034 call assert_equal([], hlget(""))
1035 END
Bram Moolenaar62aec932022-01-29 21:45:34 +00001036 call v9.CheckLegacyAndVim9Success(lines)
Yegappan Lakshmanand1a8d652021-11-03 21:56:45 +00001037
1038 " Test for resolving highlight group links
1039 let lines =<< trim END
1040 highlight hlgA term=bold
1041 VAR hlgAid = hlID('hlgA')
1042 highlight link hlgB hlgA
1043 VAR hlgBid = hlID('hlgB')
1044 highlight link hlgC hlgB
1045 VAR hlgCid = hlID('hlgC')
1046 call assert_equal('hlgA', hlget('hlgB')[0].linksto)
1047 call assert_equal('hlgB', hlget('hlgC')[0].linksto)
1048 call assert_equal([{'id': hlgAid, 'name': 'hlgA',
1049 \ 'term': {'bold': v:true}}], hlget('hlgA'))
1050 call assert_equal([{'id': hlgBid, 'name': 'hlgB',
1051 \ 'linksto': 'hlgA'}], hlget('hlgB'))
1052 call assert_equal([{'id': hlgCid, 'name': 'hlgC',
1053 \ 'linksto': 'hlgB'}], hlget('hlgC'))
1054 call assert_equal([{'id': hlgAid, 'name': 'hlgA',
1055 \ 'term': {'bold': v:true}}], hlget('hlgA', v:false))
1056 call assert_equal([{'id': hlgBid, 'name': 'hlgB',
1057 \ 'linksto': 'hlgA'}], hlget('hlgB', 0))
1058 call assert_equal([{'id': hlgCid, 'name': 'hlgC',
1059 \ 'linksto': 'hlgB'}], hlget('hlgC', v:false))
1060 call assert_equal([{'id': hlgAid, 'name': 'hlgA',
1061 \ 'term': {'bold': v:true}}], hlget('hlgA', v:true))
1062 call assert_equal([{'id': hlgBid, 'name': 'hlgB',
1063 \ 'term': {'bold': v:true}}], hlget('hlgB', 1))
1064 call assert_equal([{'id': hlgCid, 'name': 'hlgC',
1065 \ 'term': {'bold': v:true}}], hlget('hlgC', v:true))
1066 END
Bram Moolenaar62aec932022-01-29 21:45:34 +00001067 call v9.CheckLegacyAndVim9Success(lines)
Yegappan Lakshmanand1a8d652021-11-03 21:56:45 +00001068
1069 call assert_fails('call hlget([])', 'E1174:')
1070 call assert_fails('call hlget("abc", "xyz")', 'E1212:')
1071endfunc
1072
1073" Test for the hlset() function
1074func Test_hlset()
1075 let lines =<< trim END
1076 call assert_equal(0, hlset(test_null_list()))
1077 call assert_equal(0, hlset([]))
1078 call assert_fails('call hlset(["Search"])', 'E715:')
1079 call hlset(hlget())
1080 call hlset([{'name': 'NewHLGroup', 'cterm': {'reverse': v:true}, 'ctermfg': '10'}])
1081 call assert_equal({'reverse': v:true}, hlget('NewHLGroup')[0].cterm)
1082 call hlset([{'name': 'NewHLGroup', 'cterm': {'bold': v:true}}])
1083 call assert_equal({'bold': v:true}, hlget('NewHLGroup')[0].cterm)
1084 call hlset([{'name': 'NewHLGroup', 'cleared': v:true}])
1085 call assert_equal(v:true, hlget('NewHLGroup')[0].cleared)
1086 call hlset([{'name': 'NewHLGroup', 'linksto': 'Search'}])
1087 call assert_false(has_key(hlget('NewHLGroup')[0], 'cleared'))
1088 call assert_equal('Search', hlget('NewHLGroup')[0].linksto)
1089 call assert_fails("call hlset([{'name': [], 'ctermfg': '10'}])", 'E928:')
1090 call assert_fails("call hlset([{'name': 'NewHLGroup', 'cleared': []}])",
1091 \ 'E745:')
1092 call assert_fails("call hlset([{'name': 'NewHLGroup', 'cterm': 'Blue'}])",
1093 \ 'E715:')
1094 call assert_fails("call hlset([{'name': 'NewHLGroup', 'ctermbg': []}])",
1095 \ 'E928:')
1096 call assert_fails("call hlset([{'name': 'NewHLGroup', 'ctermfg': []}])",
1097 \ 'E928:')
1098 call assert_fails("call hlset([{'name': 'NewHLGroup', 'ctermul': []}])",
1099 \ 'E928:')
1100 if has('gui')
1101 call assert_fails("call hlset([{'name': 'NewHLGroup', 'font': []}])",
1102 \ 'E928:')
1103 endif
1104 call assert_fails("call hlset([{'name': 'NewHLGroup', 'gui': 'Cyan'}])",
1105 \ 'E715:')
1106 call assert_fails("call hlset([{'name': 'NewHLGroup', 'guibg': []}])",
1107 \ 'E928:')
1108 call assert_fails("call hlset([{'name': 'NewHLGroup', 'guifg': []}])",
1109 \ 'E928:')
1110 call assert_fails("call hlset([{'name': 'NewHLGroup', 'guisp': []}])",
1111 \ 'E928:')
1112 call assert_fails("call hlset([{'name': 'NewHLGroup', 'linksto': []}])",
1113 \ 'E928:')
1114 call assert_fails("call hlset([{'name': 'NewHLGroup', 'start': []}])",
1115 \ 'E928:')
1116 call assert_fails("call hlset([{'name': 'NewHLGroup', 'stop': []}])",
1117 \ 'E928:')
1118 call assert_fails("call hlset([{'name': 'NewHLGroup', 'term': 'Cyan'}])",
1119 \ 'E715:')
1120 call assert_equal('Search', hlget('NewHLGroup')[0].linksto)
1121 highlight clear NewHLGroup
1122 END
Bram Moolenaar62aec932022-01-29 21:45:34 +00001123 call v9.CheckLegacyAndVim9Success(lines)
Yegappan Lakshmanand1a8d652021-11-03 21:56:45 +00001124
1125 " Test for clearing the 'term', 'cterm' and 'gui' attributes of a highlight
1126 " group.
1127 let lines =<< trim END
1128 highlight myhlg1 term=bold cterm=italic gui=standout
1129 VAR id = hlID('myhlg1')
1130 call hlset([{'name': 'myhlg1', 'term': {}}])
1131 call assert_equal([{'id': id, 'name': 'myhlg1',
1132 \ 'cterm': {'italic': v:true}, 'gui': {'standout': v:true}}],
1133 \ hlget('myhlg1'))
1134 call hlset([{'name': 'myhlg1', 'cterm': {}}])
1135 call assert_equal([{'id': id, 'name': 'myhlg1',
1136 \ 'gui': {'standout': v:true}}], hlget('myhlg1'))
1137 call hlset([{'name': 'myhlg1', 'gui': {}}])
1138 call assert_equal([{'id': id, 'name': 'myhlg1', 'cleared': v:true}],
1139 \ hlget('myhlg1'))
1140 highlight clear myhlg1
1141 END
Bram Moolenaar62aec932022-01-29 21:45:34 +00001142 call v9.CheckLegacyAndVim9Success(lines)
Yegappan Lakshmanand1a8d652021-11-03 21:56:45 +00001143
1144 " Test for setting all the 'term', 'cterm' and 'gui' attributes of a
1145 " highlight group
1146 let lines =<< trim END
1147 VAR attr = {'bold': v:true, 'underline': v:true, 'undercurl': v:true,
1148 \ 'strikethrough': v:true, 'reverse': v:true, 'italic': v:true,
1149 \ 'standout': v:true, 'nocombine': v:true}
1150 call hlset([{'name': 'myhlg2', 'term': attr, 'cterm': attr, 'gui': attr}])
1151 VAR id2 = hlID('myhlg2')
Yegappan Lakshmanan2a16dc62021-11-16 17:19:30 +00001152 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"
1153 VAR output = execute('highlight myhlg2')
1154 LET output = output->split("\n")->join()->substitute('\s\+', ' ', 'g')
1155 call assert_equal(expected, output)
Yegappan Lakshmanand1a8d652021-11-03 21:56:45 +00001156 call assert_equal([{'id': id2, 'name': 'myhlg2', 'gui': attr,
1157 \ 'term': attr, 'cterm': attr}], hlget('myhlg2'))
1158 END
Bram Moolenaar62aec932022-01-29 21:45:34 +00001159 call v9.CheckLegacyAndVim9Success(lines)
Yegappan Lakshmanand1a8d652021-11-03 21:56:45 +00001160
1161 " Test for clearing some of the 'term', 'cterm' and 'gui' attributes of a
1162 " highlight group
1163 let lines =<< trim END
1164 VAR attr = {'bold': v:false, 'underline': v:true, 'strikethrough': v:true}
1165 call hlset([{'name': 'myhlg2', 'term': attr, 'cterm': attr, 'gui': attr}])
1166 VAR id2 = hlID('myhlg2')
Yegappan Lakshmanan2a16dc62021-11-16 17:19:30 +00001167 VAR expected = "myhlg2 xxx term=underline,strikethrough cterm=underline,strikethrough gui=underline,strikethrough"
1168 VAR output = execute('highlight myhlg2')
1169 LET output = output->split("\n")->join()->substitute('\s\+', ' ', 'g')
1170 call assert_equal(expected, output)
Yegappan Lakshmanand1a8d652021-11-03 21:56:45 +00001171 LET attr = {'underline': v:true, 'strikethrough': v:true}
1172 call assert_equal([{'id': id2, 'name': 'myhlg2', 'gui': attr,
1173 \ 'term': attr, 'cterm': attr}], hlget('myhlg2'))
1174 END
Bram Moolenaar62aec932022-01-29 21:45:34 +00001175 call v9.CheckLegacyAndVim9Success(lines)
Dominique Pelle6a950a62021-11-13 18:44:37 +00001176
Yegappan Lakshmanan2a16dc62021-11-16 17:19:30 +00001177 " Test for clearing the attributes and link of a highlight group
1178 let lines =<< trim END
1179 highlight myhlg3 ctermbg=green guibg=green
1180 highlight! default link myhlg3 ErrorMsg
1181 VAR id3 = hlID('myhlg3')
1182 call hlset([{'name': 'myhlg3', 'cleared': v:true, 'linksto': 'NONE'}])
1183 call assert_equal([{'id': id3, 'name': 'myhlg3', 'cleared': v:true}],
1184 \ hlget('myhlg3'))
1185 highlight clear hlg3
1186 END
Bram Moolenaar62aec932022-01-29 21:45:34 +00001187 call v9.CheckLegacyAndVim9Success(lines)
Yegappan Lakshmanan2a16dc62021-11-16 17:19:30 +00001188
1189 " Test for setting default attributes for a highlight group
1190 let lines =<< trim END
1191 call hlset([{'name': 'hlg4', 'ctermfg': '8'}])
1192 call hlset([{'name': 'hlg4', 'default': v:true, 'ctermfg': '9'}])
1193 VAR id4 = hlID('hlg4')
1194 call assert_equal([{'id': id4, 'name': 'hlg4', 'ctermfg': '8'}],
1195 \ hlget('hlg4'))
1196 highlight clear hlg4
1197
1198 call hlset([{'name': 'hlg5', 'default': v:true, 'ctermbg': '2'}])
1199 call hlset([{'name': 'hlg5', 'ctermbg': '4'}])
1200 VAR id5 = hlID('hlg5')
1201 call assert_equal([{'id': id5, 'name': 'hlg5', 'ctermbg': '4'}],
1202 \ hlget('hlg5'))
1203 highlight clear hlg5
1204
1205 call hlset([{'name': 'hlg6', 'linksto': 'Error'}])
1206 VAR id6 = hlID('hlg6')
1207 call hlset([{'name': 'hlg6', 'default': v:true, 'ctermbg': '2'}])
1208 call assert_equal([{'id': id6, 'name': 'hlg6', 'linksto': 'Error'}],
1209 \ hlget('hlg6'))
1210 highlight clear hlg6
1211 END
Bram Moolenaar62aec932022-01-29 21:45:34 +00001212 call v9.CheckLegacyAndVim9Success(lines)
Yegappan Lakshmanan2a16dc62021-11-16 17:19:30 +00001213
1214 " Test for setting default links for a highlight group
1215 let lines =<< trim END
1216 call hlset([{'name': 'hlg7', 'ctermfg': '5'}])
1217 call hlset([{'name': 'hlg7', 'default': v:true, 'linksto': 'Search'}])
1218 VAR id7 = hlID('hlg7')
1219 call assert_equal([{'id': id7, 'name': 'hlg7', 'ctermfg': '5'}],
1220 \ hlget('hlg7'))
1221 highlight clear hlg7
1222
1223 call hlset([{'name': 'hlg8', 'default': v:true, 'linksto': 'Search'}])
1224 VAR id8 = hlID('hlg8')
1225 call assert_equal([{'id': id8, 'name': 'hlg8', 'default': v:true,
1226 \ 'linksto': 'Search'}], hlget('hlg8'))
1227 call hlset([{'name': 'hlg8', 'ctermbg': '2'}])
1228 call assert_equal([{'id': id8, 'name': 'hlg8', 'ctermbg': '2'}],
1229 \ hlget('hlg8'))
1230 highlight clear hlg8
1231
1232 highlight default link hlg9 ErrorMsg
1233 VAR hlg_save = hlget('hlg9')
1234 LET hlg_save[0]['name'] = 'hlg9dup'
1235 call hlset(hlg_save)
1236 VAR id9 = hlID('hlg9dup')
1237 highlight clear hlg9dup
1238 call assert_equal([{'id': id9, 'name': 'hlg9dup', 'default': v:true,
1239 \ 'linksto': 'ErrorMsg'}], hlget('hlg9dup'))
1240 highlight clear hlg9
1241 END
Bram Moolenaar62aec932022-01-29 21:45:34 +00001242 call v9.CheckLegacyAndVim9Success(lines)
Yegappan Lakshmanan2a16dc62021-11-16 17:19:30 +00001243
1244 " Test for force creating a link to a highlight group
1245 let lines =<< trim END
1246 call hlset([{'name': 'hlg10', 'ctermfg': '8'}])
1247 call hlset([{'name': 'hlg10', 'linksto': 'Search'}])
1248 VAR id10 = hlID('hlg10')
1249 call assert_equal([{'id': id10, 'name': 'hlg10', 'ctermfg': '8'}],
1250 \ hlget('hlg10'))
1251 call hlset([{'name': 'hlg10', 'linksto': 'Search', 'force': v:true}])
1252 call assert_equal([{'id': id10, 'name': 'hlg10', 'ctermfg': '8',
1253 \ 'linksto': 'Search'}], hlget('hlg10'))
1254 highlight clear hlg10
1255 END
Bram Moolenaar62aec932022-01-29 21:45:34 +00001256 call v9.CheckLegacyAndVim9Success(lines)
Yegappan Lakshmananbb277fd2021-11-24 20:28:31 +00001257
1258 " Test for empty values of attributes
1259 call hlset([{'name': 'hlg11', 'cterm': {}}])
1260 call hlset([{'name': 'hlg11', 'ctermfg': ''}])
1261 call hlset([{'name': 'hlg11', 'ctermbg': ''}])
1262 call hlset([{'name': 'hlg11', 'ctermul': ''}])
1263 call hlset([{'name': 'hlg11', 'font': ''}])
1264 call hlset([{'name': 'hlg11', 'gui': {}}])
1265 call hlset([{'name': 'hlg11', 'guifg': ''}])
1266 call hlset([{'name': 'hlg11', 'guibg': ''}])
1267 call hlset([{'name': 'hlg11', 'guisp': ''}])
1268 call hlset([{'name': 'hlg11', 'start': ''}])
1269 call hlset([{'name': 'hlg11', 'stop': ''}])
1270 call hlset([{'name': 'hlg11', 'term': {}}])
1271 call assert_true(hlget('hlg11')[0].cleared)
Yegappan Lakshmanand1a8d652021-11-03 21:56:45 +00001272endfunc
1273
Bram Moolenaaree4e0c12020-04-06 21:35:05 +02001274" vim: shiftwidth=2 sts=2 expandtab