blob: 3400052a7cd0bbc72fb6fe1d9d7ca2fa04a7dc4e [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
zeertzjq8c979602022-04-07 15:08:01 +0100613 call term_sendkeys(buf, "\<C-O>")
614 call TermWait(buf)
615 call VerifyScreenDump(buf, 'Test_cursorcolumn_insert_on_tab_3', {})
616
617 call term_sendkeys(buf, 'i')
618 call TermWait(buf)
619 call VerifyScreenDump(buf, 'Test_cursorcolumn_insert_on_tab_2', {})
620
Bram Moolenaar782c6742022-04-01 12:06:31 +0100621 call StopVimInTerminal(buf)
622 call delete('Xcuc_insert_on_tab')
623endfunc
624
zeertzjq3e559cd2022-03-27 19:26:55 +0100625func Test_cursorcolumn_callback()
626 CheckScreendump
627 CheckFeature timers
628
629 let lines =<< trim END
630 call setline(1, ['aaaaa', 'bbbbb', 'ccccc', 'ddddd'])
631 set cursorcolumn
632 call cursor(4, 5)
633
634 func Func(timer)
635 call cursor(1, 1)
636 endfunc
637
638 call timer_start(300, 'Func')
639 END
640 call writefile(lines, 'Xcuc_timer')
641
642 let buf = RunVimInTerminal('-S Xcuc_timer', #{rows: 8})
643 call TermWait(buf, 310)
644 call VerifyScreenDump(buf, 'Test_cursorcolumn_callback_1', {})
645
646 call StopVimInTerminal(buf)
647 call delete('Xcuc_timer')
648endfunc
649
Bram Moolenaar193ffd12019-05-25 22:57:30 +0200650func Test_wincolor()
Bram Moolenaar8c5a2782019-08-07 23:07:07 +0200651 CheckScreendump
Bram Moolenaar3180fe62020-02-02 13:47:06 +0100652 " make sure the width is enough for the test
653 set columns=80
Bram Moolenaar193ffd12019-05-25 22:57:30 +0200654
Bram Moolenaare7eb9272019-06-24 00:58:07 +0200655 let lines =<< trim END
656 set cursorline cursorcolumn rnu
Bram Moolenaar053f7122019-09-23 22:17:15 +0200657 call setline(1, ["","1111111111","22222222222","3 here 3","","the cat is out of the bag"])
Bram Moolenaare7eb9272019-06-24 00:58:07 +0200658 set wincolor=Pmenu
Bram Moolenaar053f7122019-09-23 22:17:15 +0200659 hi CatLine guifg=green ctermfg=green
660 hi Reverse gui=reverse cterm=reverse
661 syn match CatLine /^the.*/
662 call prop_type_add("foo", {"highlight": "Reverse", "combine": 1})
663 call prop_add(6, 12, {"type": "foo", "end_col": 15})
Bram Moolenaare7eb9272019-06-24 00:58:07 +0200664 /here
665 END
666 call writefile(lines, 'Xtest_wincolor')
Bram Moolenaar193ffd12019-05-25 22:57:30 +0200667 let buf = RunVimInTerminal('-S Xtest_wincolor', {'rows': 8})
Bram Moolenaar6a2c5a72020-04-08 21:50:25 +0200668 call TermWait(buf)
Bram Moolenaar193ffd12019-05-25 22:57:30 +0200669 call term_sendkeys(buf, "2G5lvj")
Bram Moolenaar6a2c5a72020-04-08 21:50:25 +0200670 call TermWait(buf)
Bram Moolenaar193ffd12019-05-25 22:57:30 +0200671
672 call VerifyScreenDump(buf, 'Test_wincolor_01', {})
673
674 " clean up
675 call term_sendkeys(buf, "\<Esc>")
676 call StopVimInTerminal(buf)
677 call delete('Xtest_wincolor')
678endfunc
679
Bram Moolenaar42e931b2019-12-04 19:08:50 +0100680func Test_wincolor_listchars()
681 CheckScreendump
Bram Moolenaar705724e2020-01-31 21:13:42 +0100682 CheckFeature conceal
Bram Moolenaar42e931b2019-12-04 19:08:50 +0100683
684 let lines =<< trim END
685 call setline(1, ["one","\t\tsome random text enough long to show 'extends' and 'precedes' includingnbsps, preceding tabs and trailing spaces ","three"])
686 set wincolor=Todo
687 set nowrap cole=1 cocu+=n
688 set list lcs=eol:$,tab:>-,space:.,trail:_,extends:>,precedes:<,conceal:*,nbsp:#
689 call matchadd('Conceal', 'text')
690 normal 2G5zl
691 END
692 call writefile(lines, 'Xtest_wincolorlcs')
693 let buf = RunVimInTerminal('-S Xtest_wincolorlcs', {'rows': 8})
694
695 call VerifyScreenDump(buf, 'Test_wincolor_lcs', {})
696
697 " clean up
698 call term_sendkeys(buf, "\<Esc>")
699 call StopVimInTerminal(buf)
700 call delete('Xtest_wincolorlcs')
701endfunc
702
Bram Moolenaar010ee962019-09-25 20:37:36 +0200703func Test_colorcolumn()
704 CheckScreendump
705
706 " check that setting 'colorcolumn' when entering a buffer works
707 let lines =<< trim END
708 split
709 edit X
710 call setline(1, ["1111111111","22222222222","3333333333"])
711 set nomodified
712 set colorcolumn=3,9
713 set number cursorline cursorlineopt=number
714 wincmd w
715 buf X
716 END
717 call writefile(lines, 'Xtest_colorcolumn')
718 let buf = RunVimInTerminal('-S Xtest_colorcolumn', {'rows': 10})
719 call term_sendkeys(buf, ":\<CR>")
Bram Moolenaar010ee962019-09-25 20:37:36 +0200720 call VerifyScreenDump(buf, 'Test_colorcolumn_1', {})
721
722 " clean up
723 call StopVimInTerminal(buf)
724 call delete('Xtest_colorcolumn')
725endfunc
726
Bram Moolenaarad5e5632020-09-15 20:52:26 +0200727func Test_colorcolumn_bri()
728 CheckScreendump
729
730 " check 'colorcolumn' when 'breakindent' is set
731 let lines =<< trim END
732 call setline(1, 'The quick brown fox jumped over the lazy dogs')
733 END
734 call writefile(lines, 'Xtest_colorcolumn_bri')
735 let buf = RunVimInTerminal('-S Xtest_colorcolumn_bri', {'rows': 10,'columns': 40})
736 call term_sendkeys(buf, ":set co=40 linebreak bri briopt=shift:2 cc=40,41,43\<CR>")
Bram Moolenaarad5e5632020-09-15 20:52:26 +0200737 call VerifyScreenDump(buf, 'Test_colorcolumn_2', {})
738
739 " clean up
740 call StopVimInTerminal(buf)
741 call delete('Xtest_colorcolumn_bri')
742endfunc
743
744func Test_colorcolumn_sbr()
745 CheckScreendump
746
747 " check 'colorcolumn' when 'showbreak' is set
748 let lines =<< trim END
749 call setline(1, 'The quick brown fox jumped over the lazy dogs')
750 END
751 call writefile(lines, 'Xtest_colorcolumn_srb')
752 let buf = RunVimInTerminal('-S Xtest_colorcolumn_srb', {'rows': 10,'columns': 40})
753 call term_sendkeys(buf, ":set co=40 showbreak=+++>\\ cc=40,41,43\<CR>")
Bram Moolenaarad5e5632020-09-15 20:52:26 +0200754 call VerifyScreenDump(buf, 'Test_colorcolumn_3', {})
755
756 " clean up
757 call StopVimInTerminal(buf)
758 call delete('Xtest_colorcolumn_srb')
759endfunc
760
Bram Moolenaar6b528fa2019-05-09 20:07:33 +0200761" This test must come before the Test_cursorline test, as it appears this
762" defines the Normal highlighting group anyway.
Bram Moolenaarf90b6e02019-05-09 19:26:38 +0200763func Test_1_highlight_Normalgroup_exists()
Bram Moolenaar435f9f02019-07-03 21:40:16 +0200764 let hlNormal = HighlightArgs('Normal')
765 if !has('gui_running')
Bram Moolenaar6b528fa2019-05-09 20:07:33 +0200766 call assert_match('hi Normal\s*clear', hlNormal)
Bram Moolenaar435f9f02019-07-03 21:40:16 +0200767 elseif has('gui_gtk2') || has('gui_gnome') || has('gui_gtk3')
768 " expect is DEFAULT_FONT of gui_gtk_x11.c
769 call assert_match('hi Normal\s*font=Monospace 10', hlNormal)
Bram Moolenaar0b962e52022-04-03 18:02:37 +0100770 elseif has('gui_motif')
Bram Moolenaar435f9f02019-07-03 21:40:16 +0200771 " expect is DEFAULT_FONT of gui_x11.c
772 call assert_match('hi Normal\s*font=7x13', hlNormal)
773 elseif has('win32')
774 " expect any font
775 call assert_match('hi Normal\s*font=.*', hlNormal)
Bram Moolenaar6b528fa2019-05-09 20:07:33 +0200776 endif
Bram Moolenaarf90b6e02019-05-09 19:26:38 +0200777endfunc
Bram Moolenaar548be7f2019-06-29 03:42:42 +0200778
Bram Moolenaar3180fe62020-02-02 13:47:06 +0100779" Do this test last, sometimes restoring the columns doesn't work
Bram Moolenaaree4e0c12020-04-06 21:35:05 +0200780func Test_z_no_space_before_xxx()
Bram Moolenaar548be7f2019-06-29 03:42:42 +0200781 let l:org_columns = &columns
782 set columns=17
783 let l:hi_StatusLineTermNC = join(split(execute('hi StatusLineTermNC')))
784 call assert_match('StatusLineTermNC xxx', l:hi_StatusLineTermNC)
785 let &columns = l:org_columns
Bram Moolenaaree4e0c12020-04-06 21:35:05 +0200786endfunc
787
788" Test for :highlight command errors
789func Test_highlight_cmd_errors()
790 if has('gui_running')
791 " This test doesn't fail in the MS-Windows console version.
Bram Moolenaar75e15672020-06-28 13:10:22 +0200792 call assert_fails('hi Xcomment ctermbg=fg', 'E419:')
Bram Moolenaaree4e0c12020-04-06 21:35:05 +0200793 call assert_fails('hi Xcomment ctermfg=bg', 'E420:')
Bram Moolenaar75e15672020-06-28 13:10:22 +0200794 call assert_fails('hi Xcomment ctermfg=ul', 'E453:')
erw7f7f7aaf2021-12-07 21:29:20 +0000795 call assert_fails('hi ' .. repeat('a', 201) .. ' ctermfg=black', 'E1249:')
Bram Moolenaaree4e0c12020-04-06 21:35:05 +0200796 endif
797
798 " Try using a very long terminal code. Define a dummy terminal code for this
799 " test.
800 let &t_fo = "\<Esc>1;"
801 let c = repeat("t_fo,", 100) . "t_fo"
802 call assert_fails('exe "hi Xgroup1 start=" . c', 'E422:')
803 let &t_fo = ""
804endfunc
805
Bram Moolenaar75e15672020-06-28 13:10:22 +0200806" Test for 'highlight' option
807func Test_highlight_opt()
808 let save_hl = &highlight
809 call assert_fails('set highlight=j:b', 'E474:')
810 set highlight=f\ r
811 call assert_equal('f r', &highlight)
812 set highlight=fb
813 call assert_equal('fb', &highlight)
814 set highlight=fi
815 call assert_equal('fi', &highlight)
816 set highlight=f-
817 call assert_equal('f-', &highlight)
818 set highlight=fr
819 call assert_equal('fr', &highlight)
820 set highlight=fs
821 call assert_equal('fs', &highlight)
822 set highlight=fu
823 call assert_equal('fu', &highlight)
824 set highlight=fc
825 call assert_equal('fc', &highlight)
826 set highlight=ft
827 call assert_equal('ft', &highlight)
828 call assert_fails('set highlight=fr:Search', 'E474:')
829 set highlight=f:$#
830 call assert_match('W18:', v:statusmsg)
831 let &highlight = save_hl
832endfunc
833
834" Test for User group highlighting used in the statusline
835func Test_highlight_User()
836 CheckNotGui
837 hi User1 ctermfg=12
838 redraw!
839 call assert_equal('12', synIDattr(synIDtrans(hlID('User1')), 'fg'))
840 hi clear
841endfunc
842
843" Test for using RGB color values in a highlight group
Bram Moolenaar09fbedc2021-01-19 17:22:58 +0100844func Test_xxlast_highlight_RGB_color()
845 CheckCanRunGui
846 gui -f
Bram Moolenaar75e15672020-06-28 13:10:22 +0200847 hi MySearch guifg=#110000 guibg=#001100 guisp=#000011
848 call assert_equal('#110000', synIDattr(synIDtrans(hlID('MySearch')), 'fg#'))
849 call assert_equal('#001100', synIDattr(synIDtrans(hlID('MySearch')), 'bg#'))
850 call assert_equal('#000011', synIDattr(synIDtrans(hlID('MySearch')), 'sp#'))
851 hi clear
852endfunc
853
Bram Moolenaarde8f0f42020-06-30 18:45:43 +0200854" Test for using default highlighting group
855func Test_highlight_default()
856 highlight MySearch ctermfg=7
857 highlight default MySearch ctermfg=5
858 let hlSearch = HighlightArgs('MySearch')
859 call assert_match('ctermfg=7', hlSearch)
860
861 highlight default QFName ctermfg=3
862 call assert_match('ctermfg=3', HighlightArgs('QFName'))
863 hi clear
864endfunc
865
866" Test for 'ctermul in a highlight group
867func Test_highlight_ctermul()
868 CheckNotGui
869 call assert_notmatch('ctermul=', HighlightArgs('Normal'))
870 highlight Normal ctermul=3
871 call assert_match('ctermul=3', HighlightArgs('Normal'))
Bram Moolenaar391c3622020-09-29 20:59:17 +0200872 call assert_equal('3', synIDattr(synIDtrans(hlID('Normal')), 'ul'))
Bram Moolenaarde8f0f42020-06-30 18:45:43 +0200873 highlight Normal ctermul=NONE
874endfunc
875
876" Test for specifying 'start' and 'stop' in a highlight group
877func Test_highlight_start_stop()
878 hi HlGrp1 start=<Esc>[27h;<Esc>[<Space>r;
879 call assert_match("start=^[[27h;^[[ r;", HighlightArgs('HlGrp1'))
880 hi HlGrp1 start=NONE
881 call assert_notmatch("start=", HighlightArgs('HlGrp1'))
882 hi HlGrp2 stop=<Esc>[27h;<Esc>[<Space>r;
883 call assert_match("stop=^[[27h;^[[ r;", HighlightArgs('HlGrp2'))
884 hi HlGrp2 stop=NONE
885 call assert_notmatch("stop=", HighlightArgs('HlGrp2'))
886 hi clear
887endfunc
888
889" Test for setting various 'term' attributes
890func Test_highlight_term_attr()
891 hi HlGrp3 term=bold,underline,undercurl,strikethrough,reverse,italic,standout
892 call assert_equal('hi HlGrp3 term=bold,standout,underline,undercurl,italic,reverse,strikethrough', HighlightArgs('HlGrp3'))
893 hi HlGrp3 term=NONE
894 call assert_equal('hi HlGrp3 cleared', HighlightArgs('HlGrp3'))
895 hi clear
896endfunc
897
Bram Moolenaar213da552020-09-17 19:59:26 +0200898func Test_highlight_clear_restores_links()
899 let aaa_id = hlID('aaa')
900 call assert_equal(aaa_id, 0)
901
902 " create default link aaa --> bbb
903 hi def link aaa bbb
904 let id_aaa = hlID('aaa')
905 let hl_aaa_bbb = HighlightArgs('aaa')
906
907 " try to redefine default link aaa --> ccc; check aaa --> bbb
908 hi def link aaa ccc
909 call assert_equal(HighlightArgs('aaa'), hl_aaa_bbb)
910
911 " clear aaa; check aaa --> bbb
912 hi clear aaa
913 call assert_equal(HighlightArgs('aaa'), hl_aaa_bbb)
914
915 " link aaa --> ccc; clear aaa; check aaa --> bbb
916 hi link aaa ccc
917 let id_ccc = hlID('ccc')
918 call assert_equal(synIDtrans(id_aaa), id_ccc)
919 hi clear aaa
920 call assert_equal(HighlightArgs('aaa'), hl_aaa_bbb)
921
922 " forcibly set default link aaa --> ddd
923 hi! def link aaa ddd
924 let id_ddd = hlID('ddd')
925 let hl_aaa_ddd = HighlightArgs('aaa')
926 call assert_equal(synIDtrans(id_aaa), id_ddd)
927
928 " link aaa --> eee; clear aaa; check aaa --> ddd
929 hi link aaa eee
930 let eee_id = hlID('eee')
931 call assert_equal(synIDtrans(id_aaa), eee_id)
932 hi clear aaa
933 call assert_equal(HighlightArgs('aaa'), hl_aaa_ddd)
934endfunc
935
Bram Moolenaare8df0102020-09-18 19:40:45 +0200936func Test_highlight_clear_restores_context()
937 func FuncContextDefault()
938 hi def link Context ContextDefault
939 endfun
940
941 func FuncContextRelink()
942 " Dummy line
943 hi link Context ContextRelink
944 endfunc
945
946 let scriptContextDefault = MakeScript("FuncContextDefault")
947 let scriptContextRelink = MakeScript("FuncContextRelink")
948 let patContextDefault = fnamemodify(scriptContextDefault, ':t') .. ' line 1'
949 let patContextRelink = fnamemodify(scriptContextRelink, ':t') .. ' line 2'
950
Bram Moolenaar2bbada82020-09-18 21:55:26 +0200951 exec 'source ' .. scriptContextDefault
Bram Moolenaare8df0102020-09-18 19:40:45 +0200952 let hlContextDefault = execute("verbose hi Context")
953 call assert_match(patContextDefault, hlContextDefault)
954
Bram Moolenaar2bbada82020-09-18 21:55:26 +0200955 exec 'source ' .. scriptContextRelink
Bram Moolenaare8df0102020-09-18 19:40:45 +0200956 let hlContextRelink = execute("verbose hi Context")
957 call assert_match(patContextRelink, hlContextRelink)
958
959 hi clear
960 let hlContextAfterClear = execute("verbose hi Context")
961 call assert_match(patContextDefault, hlContextAfterClear)
962
963 delfunc FuncContextDefault
964 delfunc FuncContextRelink
965 call delete(scriptContextDefault)
966 call delete(scriptContextRelink)
967endfunc
968
Bram Moolenaar213da552020-09-17 19:59:26 +0200969func Test_highlight_default_colorscheme_restores_links()
970 hi link TestLink Identifier
971 hi TestHi ctermbg=red
Bram Moolenaar05eb5b92020-09-16 15:43:21 +0200972
973 let hlTestLinkPre = HighlightArgs('TestLink')
974 let hlTestHiPre = HighlightArgs('TestHi')
975
976 " Test colorscheme
Dominique Pelle8bfa0eb2022-01-02 16:16:33 +0000977 call assert_equal("\ndefault", execute('colorscheme'))
Bram Moolenaar05eb5b92020-09-16 15:43:21 +0200978 hi clear
979 if exists('syntax_on')
980 syntax reset
981 endif
982 let g:colors_name = 'test'
Dominique Pelle8bfa0eb2022-01-02 16:16:33 +0000983 call assert_equal("\ntest", execute('colorscheme'))
Bram Moolenaar213da552020-09-17 19:59:26 +0200984 hi link TestLink ErrorMsg
985 hi TestHi ctermbg=green
Bram Moolenaar05eb5b92020-09-16 15:43:21 +0200986
987 " Restore default highlighting
988 colorscheme default
Bram Moolenaar05eb5b92020-09-16 15:43:21 +0200989 " 'default' should work no matter if highlight group was cleared
Dominique Pelle8bfa0eb2022-01-02 16:16:33 +0000990 call assert_equal("\ndefault", execute('colorscheme'))
Bram Moolenaar05eb5b92020-09-16 15:43:21 +0200991 hi def link TestLink Identifier
992 hi def TestHi ctermbg=red
Bram Moolenaar05eb5b92020-09-16 15:43:21 +0200993 let hlTestLinkPost = HighlightArgs('TestLink')
994 let hlTestHiPost = HighlightArgs('TestHi')
Bram Moolenaar05eb5b92020-09-16 15:43:21 +0200995 call assert_equal(hlTestLinkPre, hlTestLinkPost)
996 call assert_equal(hlTestHiPre, hlTestHiPost)
997 hi clear
998endfunc
999
Drew Vogele30d1022021-10-24 20:35:07 +01001000func Test_colornames_assignment_and_lookup()
Drew Vogela0fca172021-11-13 10:50:01 +00001001 CheckAnyOf Feature:gui_running Feature:termguicolors
1002
Drew Vogele30d1022021-10-24 20:35:07 +01001003 " Ensure highlight command can find custom color.
1004 let v:colornames['a redish white'] = '#ffeedd'
1005 highlight Normal guifg='a redish white'
1006 highlight clear
Drew Vogela0fca172021-11-13 10:50:01 +00001007 call ClearDict(v:colornames)
Drew Vogele30d1022021-10-24 20:35:07 +01001008endfunc
1009
1010func Test_colornames_default_list()
Drew Vogela0fca172021-11-13 10:50:01 +00001011 CheckAnyOf Feature:gui_running Feature:termguicolors
1012
Drew Vogele30d1022021-10-24 20:35:07 +01001013 " Ensure default lists are loaded automatically and can be used for all gui fields.
Drew Vogela0fca172021-11-13 10:50:01 +00001014 call assert_equal(0, len(v:colornames))
Drew Vogele30d1022021-10-24 20:35:07 +01001015 highlight Normal guifg='rebecca purple' guibg='rebecca purple' guisp='rebecca purple'
Drew Vogela0fca172021-11-13 10:50:01 +00001016 call assert_notequal(0, len(v:colornames))
1017 echo v:colornames['rebecca purple']
Drew Vogele30d1022021-10-24 20:35:07 +01001018 highlight clear
Drew Vogela0fca172021-11-13 10:50:01 +00001019 call ClearDict(v:colornames)
Drew Vogele30d1022021-10-24 20:35:07 +01001020endfunc
1021
1022func Test_colornames_overwrite_default()
Drew Vogela0fca172021-11-13 10:50:01 +00001023 CheckAnyOf Feature:gui_running Feature:termguicolors
1024
Drew Vogele30d1022021-10-24 20:35:07 +01001025 " Ensure entries in v:colornames can be overwritten.
1026 " Load default color scheme to trigger default color list loading.
1027 colorscheme default
1028 let old_rebecca_purple = v:colornames['rebecca purple']
1029 highlight Normal guifg='rebecca purple' guibg='rebecca purple'
1030 let v:colornames['rebecca purple'] = '#550099'
1031 highlight Normal guifg='rebecca purple' guibg='rebecca purple'
1032 let v:colornames['rebecca purple'] = old_rebecca_purple
1033 highlight clear
1034endfunc
1035
1036func Test_colornames_assignment_and_unassignment()
Drew Vogela0fca172021-11-13 10:50:01 +00001037 " No feature check is needed for this test because the v:colornames dict
1038 " always exists with +eval. The feature checks are only required for
1039 " commands that do color lookup.
1040
Drew Vogele30d1022021-10-24 20:35:07 +01001041 " Ensure we cannot overwrite the v:colornames dict.
1042 call assert_fails("let v:colornames = {}", 'E46:')
1043
1044 " Ensure we can delete entries from the v:colornames dict.
1045 let v:colornames['x1'] = '#111111'
1046 call assert_equal(v:colornames['x1'], '#111111')
1047 unlet v:colornames['x1']
1048 call assert_fails("echo v:colornames['x1']")
1049endfunc
1050
Yegappan Lakshmanand1a8d652021-11-03 21:56:45 +00001051" Test for the hlget() function
1052func Test_hlget()
1053 let lines =<< trim END
1054 call assert_notequal([], filter(hlget(), 'v:val.name == "Visual"'))
1055 call assert_equal([], hlget('SomeHLGroup'))
1056 highlight MyHLGroup term=standout cterm=reverse ctermfg=10 ctermbg=Black
1057 call assert_equal([{'id': hlID('MyHLGroup'), 'ctermfg': '10', 'name': 'MyHLGroup', 'term': {'standout': v:true}, 'ctermbg': '0', 'cterm': {'reverse': v:true}}], hlget('MyHLGroup'))
1058 highlight clear MyHLGroup
1059 call assert_equal(v:true, hlget('MyHLGroup')[0].cleared)
1060 highlight link MyHLGroup IncSearch
1061 call assert_equal('IncSearch', hlget('MyHLGroup')[0].linksto)
1062 highlight clear MyHLGroup
1063 call assert_equal([], hlget(test_null_string()))
1064 call assert_equal([], hlget(""))
1065 END
Bram Moolenaar62aec932022-01-29 21:45:34 +00001066 call v9.CheckLegacyAndVim9Success(lines)
Yegappan Lakshmanand1a8d652021-11-03 21:56:45 +00001067
1068 " Test for resolving highlight group links
1069 let lines =<< trim END
1070 highlight hlgA term=bold
1071 VAR hlgAid = hlID('hlgA')
1072 highlight link hlgB hlgA
1073 VAR hlgBid = hlID('hlgB')
1074 highlight link hlgC hlgB
1075 VAR hlgCid = hlID('hlgC')
1076 call assert_equal('hlgA', hlget('hlgB')[0].linksto)
1077 call assert_equal('hlgB', hlget('hlgC')[0].linksto)
1078 call assert_equal([{'id': hlgAid, 'name': 'hlgA',
1079 \ 'term': {'bold': v:true}}], hlget('hlgA'))
1080 call assert_equal([{'id': hlgBid, 'name': 'hlgB',
1081 \ 'linksto': 'hlgA'}], hlget('hlgB'))
1082 call assert_equal([{'id': hlgCid, 'name': 'hlgC',
1083 \ 'linksto': 'hlgB'}], hlget('hlgC'))
1084 call assert_equal([{'id': hlgAid, 'name': 'hlgA',
1085 \ 'term': {'bold': v:true}}], hlget('hlgA', v:false))
1086 call assert_equal([{'id': hlgBid, 'name': 'hlgB',
1087 \ 'linksto': 'hlgA'}], hlget('hlgB', 0))
1088 call assert_equal([{'id': hlgCid, 'name': 'hlgC',
1089 \ 'linksto': 'hlgB'}], hlget('hlgC', v:false))
1090 call assert_equal([{'id': hlgAid, 'name': 'hlgA',
1091 \ 'term': {'bold': v:true}}], hlget('hlgA', v:true))
1092 call assert_equal([{'id': hlgBid, 'name': 'hlgB',
1093 \ 'term': {'bold': v:true}}], hlget('hlgB', 1))
1094 call assert_equal([{'id': hlgCid, 'name': 'hlgC',
1095 \ 'term': {'bold': v:true}}], hlget('hlgC', v:true))
1096 END
Bram Moolenaar62aec932022-01-29 21:45:34 +00001097 call v9.CheckLegacyAndVim9Success(lines)
Yegappan Lakshmanand1a8d652021-11-03 21:56:45 +00001098
1099 call assert_fails('call hlget([])', 'E1174:')
1100 call assert_fails('call hlget("abc", "xyz")', 'E1212:')
1101endfunc
1102
1103" Test for the hlset() function
1104func Test_hlset()
1105 let lines =<< trim END
1106 call assert_equal(0, hlset(test_null_list()))
1107 call assert_equal(0, hlset([]))
1108 call assert_fails('call hlset(["Search"])', 'E715:')
1109 call hlset(hlget())
1110 call hlset([{'name': 'NewHLGroup', 'cterm': {'reverse': v:true}, 'ctermfg': '10'}])
1111 call assert_equal({'reverse': v:true}, hlget('NewHLGroup')[0].cterm)
1112 call hlset([{'name': 'NewHLGroup', 'cterm': {'bold': v:true}}])
1113 call assert_equal({'bold': v:true}, hlget('NewHLGroup')[0].cterm)
1114 call hlset([{'name': 'NewHLGroup', 'cleared': v:true}])
1115 call assert_equal(v:true, hlget('NewHLGroup')[0].cleared)
1116 call hlset([{'name': 'NewHLGroup', 'linksto': 'Search'}])
1117 call assert_false(has_key(hlget('NewHLGroup')[0], 'cleared'))
1118 call assert_equal('Search', hlget('NewHLGroup')[0].linksto)
1119 call assert_fails("call hlset([{'name': [], 'ctermfg': '10'}])", 'E928:')
1120 call assert_fails("call hlset([{'name': 'NewHLGroup', 'cleared': []}])",
1121 \ 'E745:')
1122 call assert_fails("call hlset([{'name': 'NewHLGroup', 'cterm': 'Blue'}])",
1123 \ 'E715:')
1124 call assert_fails("call hlset([{'name': 'NewHLGroup', 'ctermbg': []}])",
1125 \ 'E928:')
1126 call assert_fails("call hlset([{'name': 'NewHLGroup', 'ctermfg': []}])",
1127 \ 'E928:')
1128 call assert_fails("call hlset([{'name': 'NewHLGroup', 'ctermul': []}])",
1129 \ 'E928:')
1130 if has('gui')
1131 call assert_fails("call hlset([{'name': 'NewHLGroup', 'font': []}])",
1132 \ 'E928:')
1133 endif
1134 call assert_fails("call hlset([{'name': 'NewHLGroup', 'gui': 'Cyan'}])",
1135 \ 'E715:')
1136 call assert_fails("call hlset([{'name': 'NewHLGroup', 'guibg': []}])",
1137 \ 'E928:')
1138 call assert_fails("call hlset([{'name': 'NewHLGroup', 'guifg': []}])",
1139 \ 'E928:')
1140 call assert_fails("call hlset([{'name': 'NewHLGroup', 'guisp': []}])",
1141 \ 'E928:')
1142 call assert_fails("call hlset([{'name': 'NewHLGroup', 'linksto': []}])",
1143 \ 'E928:')
1144 call assert_fails("call hlset([{'name': 'NewHLGroup', 'start': []}])",
1145 \ 'E928:')
1146 call assert_fails("call hlset([{'name': 'NewHLGroup', 'stop': []}])",
1147 \ 'E928:')
1148 call assert_fails("call hlset([{'name': 'NewHLGroup', 'term': 'Cyan'}])",
1149 \ 'E715:')
1150 call assert_equal('Search', hlget('NewHLGroup')[0].linksto)
1151 highlight clear NewHLGroup
1152 END
Bram Moolenaar62aec932022-01-29 21:45:34 +00001153 call v9.CheckLegacyAndVim9Success(lines)
Yegappan Lakshmanand1a8d652021-11-03 21:56:45 +00001154
1155 " Test for clearing the 'term', 'cterm' and 'gui' attributes of a highlight
1156 " group.
1157 let lines =<< trim END
1158 highlight myhlg1 term=bold cterm=italic gui=standout
1159 VAR id = hlID('myhlg1')
1160 call hlset([{'name': 'myhlg1', 'term': {}}])
1161 call assert_equal([{'id': id, 'name': 'myhlg1',
1162 \ 'cterm': {'italic': v:true}, 'gui': {'standout': v:true}}],
1163 \ hlget('myhlg1'))
1164 call hlset([{'name': 'myhlg1', 'cterm': {}}])
1165 call assert_equal([{'id': id, 'name': 'myhlg1',
1166 \ 'gui': {'standout': v:true}}], hlget('myhlg1'))
1167 call hlset([{'name': 'myhlg1', 'gui': {}}])
1168 call assert_equal([{'id': id, 'name': 'myhlg1', 'cleared': v:true}],
1169 \ hlget('myhlg1'))
1170 highlight clear myhlg1
1171 END
Bram Moolenaar62aec932022-01-29 21:45:34 +00001172 call v9.CheckLegacyAndVim9Success(lines)
Yegappan Lakshmanand1a8d652021-11-03 21:56:45 +00001173
1174 " Test for setting all the 'term', 'cterm' and 'gui' attributes of a
1175 " highlight group
1176 let lines =<< trim END
1177 VAR attr = {'bold': v:true, 'underline': v:true, 'undercurl': v:true,
1178 \ 'strikethrough': v:true, 'reverse': v:true, 'italic': v:true,
1179 \ 'standout': v:true, 'nocombine': v:true}
1180 call hlset([{'name': 'myhlg2', 'term': attr, 'cterm': attr, 'gui': attr}])
1181 VAR id2 = hlID('myhlg2')
Yegappan Lakshmanan2a16dc62021-11-16 17:19:30 +00001182 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"
1183 VAR output = execute('highlight myhlg2')
1184 LET output = output->split("\n")->join()->substitute('\s\+', ' ', 'g')
1185 call assert_equal(expected, output)
Yegappan Lakshmanand1a8d652021-11-03 21:56:45 +00001186 call assert_equal([{'id': id2, 'name': 'myhlg2', 'gui': attr,
1187 \ 'term': attr, 'cterm': attr}], hlget('myhlg2'))
1188 END
Bram Moolenaar62aec932022-01-29 21:45:34 +00001189 call v9.CheckLegacyAndVim9Success(lines)
Yegappan Lakshmanand1a8d652021-11-03 21:56:45 +00001190
1191 " Test for clearing some of the 'term', 'cterm' and 'gui' attributes of a
1192 " highlight group
1193 let lines =<< trim END
1194 VAR attr = {'bold': v:false, 'underline': v:true, 'strikethrough': v:true}
1195 call hlset([{'name': 'myhlg2', 'term': attr, 'cterm': attr, 'gui': attr}])
1196 VAR id2 = hlID('myhlg2')
Yegappan Lakshmanan2a16dc62021-11-16 17:19:30 +00001197 VAR expected = "myhlg2 xxx term=underline,strikethrough cterm=underline,strikethrough gui=underline,strikethrough"
1198 VAR output = execute('highlight myhlg2')
1199 LET output = output->split("\n")->join()->substitute('\s\+', ' ', 'g')
1200 call assert_equal(expected, output)
Yegappan Lakshmanand1a8d652021-11-03 21:56:45 +00001201 LET attr = {'underline': v:true, 'strikethrough': v:true}
1202 call assert_equal([{'id': id2, 'name': 'myhlg2', 'gui': attr,
1203 \ 'term': attr, 'cterm': attr}], hlget('myhlg2'))
1204 END
Bram Moolenaar62aec932022-01-29 21:45:34 +00001205 call v9.CheckLegacyAndVim9Success(lines)
Dominique Pelle6a950a62021-11-13 18:44:37 +00001206
Yegappan Lakshmanan2a16dc62021-11-16 17:19:30 +00001207 " Test for clearing the attributes and link of a highlight group
1208 let lines =<< trim END
1209 highlight myhlg3 ctermbg=green guibg=green
1210 highlight! default link myhlg3 ErrorMsg
1211 VAR id3 = hlID('myhlg3')
1212 call hlset([{'name': 'myhlg3', 'cleared': v:true, 'linksto': 'NONE'}])
1213 call assert_equal([{'id': id3, 'name': 'myhlg3', 'cleared': v:true}],
1214 \ hlget('myhlg3'))
1215 highlight clear hlg3
1216 END
Bram Moolenaar62aec932022-01-29 21:45:34 +00001217 call v9.CheckLegacyAndVim9Success(lines)
Yegappan Lakshmanan2a16dc62021-11-16 17:19:30 +00001218
1219 " Test for setting default attributes for a highlight group
1220 let lines =<< trim END
1221 call hlset([{'name': 'hlg4', 'ctermfg': '8'}])
1222 call hlset([{'name': 'hlg4', 'default': v:true, 'ctermfg': '9'}])
1223 VAR id4 = hlID('hlg4')
1224 call assert_equal([{'id': id4, 'name': 'hlg4', 'ctermfg': '8'}],
1225 \ hlget('hlg4'))
1226 highlight clear hlg4
1227
1228 call hlset([{'name': 'hlg5', 'default': v:true, 'ctermbg': '2'}])
1229 call hlset([{'name': 'hlg5', 'ctermbg': '4'}])
1230 VAR id5 = hlID('hlg5')
1231 call assert_equal([{'id': id5, 'name': 'hlg5', 'ctermbg': '4'}],
1232 \ hlget('hlg5'))
1233 highlight clear hlg5
1234
1235 call hlset([{'name': 'hlg6', 'linksto': 'Error'}])
1236 VAR id6 = hlID('hlg6')
1237 call hlset([{'name': 'hlg6', 'default': v:true, 'ctermbg': '2'}])
1238 call assert_equal([{'id': id6, 'name': 'hlg6', 'linksto': 'Error'}],
1239 \ hlget('hlg6'))
1240 highlight clear hlg6
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 setting default links for a highlight group
1245 let lines =<< trim END
1246 call hlset([{'name': 'hlg7', 'ctermfg': '5'}])
1247 call hlset([{'name': 'hlg7', 'default': v:true, 'linksto': 'Search'}])
1248 VAR id7 = hlID('hlg7')
1249 call assert_equal([{'id': id7, 'name': 'hlg7', 'ctermfg': '5'}],
1250 \ hlget('hlg7'))
1251 highlight clear hlg7
1252
1253 call hlset([{'name': 'hlg8', 'default': v:true, 'linksto': 'Search'}])
1254 VAR id8 = hlID('hlg8')
1255 call assert_equal([{'id': id8, 'name': 'hlg8', 'default': v:true,
1256 \ 'linksto': 'Search'}], hlget('hlg8'))
1257 call hlset([{'name': 'hlg8', 'ctermbg': '2'}])
1258 call assert_equal([{'id': id8, 'name': 'hlg8', 'ctermbg': '2'}],
1259 \ hlget('hlg8'))
1260 highlight clear hlg8
1261
1262 highlight default link hlg9 ErrorMsg
1263 VAR hlg_save = hlget('hlg9')
1264 LET hlg_save[0]['name'] = 'hlg9dup'
1265 call hlset(hlg_save)
1266 VAR id9 = hlID('hlg9dup')
1267 highlight clear hlg9dup
1268 call assert_equal([{'id': id9, 'name': 'hlg9dup', 'default': v:true,
1269 \ 'linksto': 'ErrorMsg'}], hlget('hlg9dup'))
1270 highlight clear hlg9
1271 END
Bram Moolenaar62aec932022-01-29 21:45:34 +00001272 call v9.CheckLegacyAndVim9Success(lines)
Yegappan Lakshmanan2a16dc62021-11-16 17:19:30 +00001273
1274 " Test for force creating a link to a highlight group
1275 let lines =<< trim END
1276 call hlset([{'name': 'hlg10', 'ctermfg': '8'}])
1277 call hlset([{'name': 'hlg10', 'linksto': 'Search'}])
1278 VAR id10 = hlID('hlg10')
1279 call assert_equal([{'id': id10, 'name': 'hlg10', 'ctermfg': '8'}],
1280 \ hlget('hlg10'))
1281 call hlset([{'name': 'hlg10', 'linksto': 'Search', 'force': v:true}])
1282 call assert_equal([{'id': id10, 'name': 'hlg10', 'ctermfg': '8',
1283 \ 'linksto': 'Search'}], hlget('hlg10'))
1284 highlight clear hlg10
1285 END
Bram Moolenaar62aec932022-01-29 21:45:34 +00001286 call v9.CheckLegacyAndVim9Success(lines)
Yegappan Lakshmananbb277fd2021-11-24 20:28:31 +00001287
1288 " Test for empty values of attributes
1289 call hlset([{'name': 'hlg11', 'cterm': {}}])
1290 call hlset([{'name': 'hlg11', 'ctermfg': ''}])
1291 call hlset([{'name': 'hlg11', 'ctermbg': ''}])
1292 call hlset([{'name': 'hlg11', 'ctermul': ''}])
1293 call hlset([{'name': 'hlg11', 'font': ''}])
1294 call hlset([{'name': 'hlg11', 'gui': {}}])
1295 call hlset([{'name': 'hlg11', 'guifg': ''}])
1296 call hlset([{'name': 'hlg11', 'guibg': ''}])
1297 call hlset([{'name': 'hlg11', 'guisp': ''}])
1298 call hlset([{'name': 'hlg11', 'start': ''}])
1299 call hlset([{'name': 'hlg11', 'stop': ''}])
1300 call hlset([{'name': 'hlg11', 'term': {}}])
1301 call assert_true(hlget('hlg11')[0].cleared)
Yegappan Lakshmanand1a8d652021-11-03 21:56:45 +00001302endfunc
1303
Bram Moolenaaree4e0c12020-04-06 21:35:05 +02001304" vim: shiftwidth=2 sts=2 expandtab