blob: 26426e05cb508b95b39d42f346fe1ba89e80b66d [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",""])',
Bram Moolenaar572a4432022-09-28 21:07:03 +0100543 \ ], 'Xtest_cursorline_yank', 'D')
Bram Moolenaarc07ff5c2019-01-30 21:41:14 +0100544 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)
Bram Moolenaarc07ff5c2019-01-30 21:41:14 +0100554endfunc
Bram Moolenaar8156ed32019-03-09 11:46:15 +0100555
Bram Moolenaarfca068b2019-09-08 14:07:47 +0200556" test for issue #4862
557func Test_put_before_cursorline()
558 new
559 only!
560 call setline(1, 'A')
561 redraw
562 let std_attr = screenattr(1, 1)
563 set cursorline
564 redraw
565 let cul_attr = screenattr(1, 1)
566 normal yyP
567 redraw
568 " Line 1 has cursor so it should be highlighted with CursorLine.
569 call assert_equal(cul_attr, screenattr(1, 1))
570 " And CursorLine highlighting from the second line should be gone.
571 call assert_equal(std_attr, screenattr(2, 1))
572 set nocursorline
573 bwipe!
574endfunc
575
Bram Moolenaar8156ed32019-03-09 11:46:15 +0100576func Test_cursorline_with_visualmode()
Bram Moolenaar8c5a2782019-08-07 23:07:07 +0200577 CheckScreendump
Bram Moolenaar8156ed32019-03-09 11:46:15 +0100578
579 call writefile([
580 \ 'set cul',
581 \ 'call setline(1, repeat(["abc"], 50))',
Bram Moolenaar572a4432022-09-28 21:07:03 +0100582 \ ], 'Xtest_cursorline_with_visualmode', 'D')
Bram Moolenaar8156ed32019-03-09 11:46:15 +0100583 let buf = RunVimInTerminal('-S Xtest_cursorline_with_visualmode', {'rows': 12})
Bram Moolenaar6a2c5a72020-04-08 21:50:25 +0200584 call TermWait(buf)
Bram Moolenaar8156ed32019-03-09 11:46:15 +0100585 call term_sendkeys(buf, "V\<C-f>kkkjk")
586
587 call VerifyScreenDump(buf, 'Test_cursorline_with_visualmode_01', {})
588
589 " clean up
590 call StopVimInTerminal(buf)
Bram Moolenaar8156ed32019-03-09 11:46:15 +0100591endfunc
Bram Moolenaarf90b6e02019-05-09 19:26:38 +0200592
Bram Moolenaar782c6742022-04-01 12:06:31 +0100593func Test_cursorcolumn_insert_on_tab()
594 CheckScreendump
595
596 let lines =<< trim END
597 call setline(1, ['123456789', "a\tb"])
598 set cursorcolumn
599 call cursor(2, 2)
600 END
Bram Moolenaar572a4432022-09-28 21:07:03 +0100601 call writefile(lines, 'Xcuc_insert_on_tab', 'D')
Bram Moolenaar782c6742022-04-01 12:06:31 +0100602
603 let buf = RunVimInTerminal('-S Xcuc_insert_on_tab', #{rows: 8})
604 call TermWait(buf)
605 call VerifyScreenDump(buf, 'Test_cursorcolumn_insert_on_tab_1', {})
606
607 call term_sendkeys(buf, 'i')
608 call TermWait(buf)
609 call VerifyScreenDump(buf, 'Test_cursorcolumn_insert_on_tab_2', {})
610
zeertzjq8c979602022-04-07 15:08:01 +0100611 call term_sendkeys(buf, "\<C-O>")
612 call TermWait(buf)
613 call VerifyScreenDump(buf, 'Test_cursorcolumn_insert_on_tab_3', {})
614
615 call term_sendkeys(buf, 'i')
616 call TermWait(buf)
617 call VerifyScreenDump(buf, 'Test_cursorcolumn_insert_on_tab_2', {})
618
Bram Moolenaar782c6742022-04-01 12:06:31 +0100619 call StopVimInTerminal(buf)
Bram Moolenaar782c6742022-04-01 12:06:31 +0100620endfunc
621
zeertzjq3e559cd2022-03-27 19:26:55 +0100622func Test_cursorcolumn_callback()
623 CheckScreendump
624 CheckFeature timers
625
626 let lines =<< trim END
627 call setline(1, ['aaaaa', 'bbbbb', 'ccccc', 'ddddd'])
628 set cursorcolumn
629 call cursor(4, 5)
630
631 func Func(timer)
632 call cursor(1, 1)
633 endfunc
634
635 call timer_start(300, 'Func')
636 END
Bram Moolenaar572a4432022-09-28 21:07:03 +0100637 call writefile(lines, 'Xcuc_timer', 'D')
zeertzjq3e559cd2022-03-27 19:26:55 +0100638
639 let buf = RunVimInTerminal('-S Xcuc_timer', #{rows: 8})
640 call TermWait(buf, 310)
641 call VerifyScreenDump(buf, 'Test_cursorcolumn_callback_1', {})
642
643 call StopVimInTerminal(buf)
zeertzjq3e559cd2022-03-27 19:26:55 +0100644endfunc
645
Bram Moolenaar193ffd12019-05-25 22:57:30 +0200646func Test_wincolor()
Bram Moolenaar8c5a2782019-08-07 23:07:07 +0200647 CheckScreendump
Bram Moolenaar3180fe62020-02-02 13:47:06 +0100648 " make sure the width is enough for the test
649 set columns=80
Bram Moolenaar193ffd12019-05-25 22:57:30 +0200650
Bram Moolenaare7eb9272019-06-24 00:58:07 +0200651 let lines =<< trim END
652 set cursorline cursorcolumn rnu
Bram Moolenaar053f7122019-09-23 22:17:15 +0200653 call setline(1, ["","1111111111","22222222222","3 here 3","","the cat is out of the bag"])
Bram Moolenaare7eb9272019-06-24 00:58:07 +0200654 set wincolor=Pmenu
Bram Moolenaar053f7122019-09-23 22:17:15 +0200655 hi CatLine guifg=green ctermfg=green
656 hi Reverse gui=reverse cterm=reverse
657 syn match CatLine /^the.*/
658 call prop_type_add("foo", {"highlight": "Reverse", "combine": 1})
659 call prop_add(6, 12, {"type": "foo", "end_col": 15})
Bram Moolenaare7eb9272019-06-24 00:58:07 +0200660 /here
661 END
Bram Moolenaar572a4432022-09-28 21:07:03 +0100662 call writefile(lines, 'Xtest_wincolor', 'D')
Bram Moolenaar193ffd12019-05-25 22:57:30 +0200663 let buf = RunVimInTerminal('-S Xtest_wincolor', {'rows': 8})
Bram Moolenaar6a2c5a72020-04-08 21:50:25 +0200664 call TermWait(buf)
Bram Moolenaar193ffd12019-05-25 22:57:30 +0200665 call term_sendkeys(buf, "2G5lvj")
Bram Moolenaar6a2c5a72020-04-08 21:50:25 +0200666 call TermWait(buf)
Bram Moolenaar193ffd12019-05-25 22:57:30 +0200667
668 call VerifyScreenDump(buf, 'Test_wincolor_01', {})
669
670 " clean up
671 call term_sendkeys(buf, "\<Esc>")
672 call StopVimInTerminal(buf)
Bram Moolenaar193ffd12019-05-25 22:57:30 +0200673endfunc
674
Bram Moolenaar42e931b2019-12-04 19:08:50 +0100675func Test_wincolor_listchars()
676 CheckScreendump
Bram Moolenaar705724e2020-01-31 21:13:42 +0100677 CheckFeature conceal
Bram Moolenaar42e931b2019-12-04 19:08:50 +0100678
679 let lines =<< trim END
680 call setline(1, ["one","\t\tsome random text enough long to show 'extends' and 'precedes' includingnbsps, preceding tabs and trailing spaces ","three"])
681 set wincolor=Todo
682 set nowrap cole=1 cocu+=n
683 set list lcs=eol:$,tab:>-,space:.,trail:_,extends:>,precedes:<,conceal:*,nbsp:#
684 call matchadd('Conceal', 'text')
685 normal 2G5zl
686 END
Bram Moolenaar572a4432022-09-28 21:07:03 +0100687 call writefile(lines, 'Xtest_wincolorlcs', 'D')
Bram Moolenaar42e931b2019-12-04 19:08:50 +0100688 let buf = RunVimInTerminal('-S Xtest_wincolorlcs', {'rows': 8})
689
690 call VerifyScreenDump(buf, 'Test_wincolor_lcs', {})
691
692 " clean up
693 call term_sendkeys(buf, "\<Esc>")
694 call StopVimInTerminal(buf)
Bram Moolenaar42e931b2019-12-04 19:08:50 +0100695endfunc
696
Bram Moolenaar010ee962019-09-25 20:37:36 +0200697func Test_colorcolumn()
698 CheckScreendump
699
700 " check that setting 'colorcolumn' when entering a buffer works
701 let lines =<< trim END
702 split
703 edit X
704 call setline(1, ["1111111111","22222222222","3333333333"])
705 set nomodified
706 set colorcolumn=3,9
707 set number cursorline cursorlineopt=number
708 wincmd w
709 buf X
710 END
Bram Moolenaar572a4432022-09-28 21:07:03 +0100711 call writefile(lines, 'Xtest_colorcolumn', 'D')
Bram Moolenaar010ee962019-09-25 20:37:36 +0200712 let buf = RunVimInTerminal('-S Xtest_colorcolumn', {'rows': 10})
713 call term_sendkeys(buf, ":\<CR>")
Bram Moolenaar010ee962019-09-25 20:37:36 +0200714 call VerifyScreenDump(buf, 'Test_colorcolumn_1', {})
715
716 " clean up
717 call StopVimInTerminal(buf)
Bram Moolenaar010ee962019-09-25 20:37:36 +0200718endfunc
719
Bram Moolenaarad5e5632020-09-15 20:52:26 +0200720func Test_colorcolumn_bri()
721 CheckScreendump
722
723 " check 'colorcolumn' when 'breakindent' is set
724 let lines =<< trim END
725 call setline(1, 'The quick brown fox jumped over the lazy dogs')
726 END
Bram Moolenaar572a4432022-09-28 21:07:03 +0100727 call writefile(lines, 'Xtest_colorcolumn_bri', 'D')
Bram Moolenaarad5e5632020-09-15 20:52:26 +0200728 let buf = RunVimInTerminal('-S Xtest_colorcolumn_bri', {'rows': 10,'columns': 40})
729 call term_sendkeys(buf, ":set co=40 linebreak bri briopt=shift:2 cc=40,41,43\<CR>")
Bram Moolenaarad5e5632020-09-15 20:52:26 +0200730 call VerifyScreenDump(buf, 'Test_colorcolumn_2', {})
731
732 " clean up
733 call StopVimInTerminal(buf)
Bram Moolenaarad5e5632020-09-15 20:52:26 +0200734endfunc
735
736func Test_colorcolumn_sbr()
737 CheckScreendump
738
739 " check 'colorcolumn' when 'showbreak' is set
740 let lines =<< trim END
741 call setline(1, 'The quick brown fox jumped over the lazy dogs')
742 END
Bram Moolenaar572a4432022-09-28 21:07:03 +0100743 call writefile(lines, 'Xtest_colorcolumn_srb', 'D')
Bram Moolenaarad5e5632020-09-15 20:52:26 +0200744 let buf = RunVimInTerminal('-S Xtest_colorcolumn_srb', {'rows': 10,'columns': 40})
745 call term_sendkeys(buf, ":set co=40 showbreak=+++>\\ cc=40,41,43\<CR>")
Bram Moolenaarad5e5632020-09-15 20:52:26 +0200746 call VerifyScreenDump(buf, 'Test_colorcolumn_3', {})
747
748 " clean up
749 call StopVimInTerminal(buf)
Bram Moolenaarad5e5632020-09-15 20:52:26 +0200750endfunc
751
Bram Moolenaar6b528fa2019-05-09 20:07:33 +0200752" This test must come before the Test_cursorline test, as it appears this
753" defines the Normal highlighting group anyway.
Bram Moolenaarf90b6e02019-05-09 19:26:38 +0200754func Test_1_highlight_Normalgroup_exists()
Bram Moolenaar435f9f02019-07-03 21:40:16 +0200755 let hlNormal = HighlightArgs('Normal')
756 if !has('gui_running')
Bram Moolenaar6b528fa2019-05-09 20:07:33 +0200757 call assert_match('hi Normal\s*clear', hlNormal)
Bram Moolenaar435f9f02019-07-03 21:40:16 +0200758 elseif has('gui_gtk2') || has('gui_gnome') || has('gui_gtk3')
759 " expect is DEFAULT_FONT of gui_gtk_x11.c
760 call assert_match('hi Normal\s*font=Monospace 10', hlNormal)
Bram Moolenaar0b962e52022-04-03 18:02:37 +0100761 elseif has('gui_motif')
Bram Moolenaar435f9f02019-07-03 21:40:16 +0200762 " expect is DEFAULT_FONT of gui_x11.c
763 call assert_match('hi Normal\s*font=7x13', hlNormal)
764 elseif has('win32')
765 " expect any font
766 call assert_match('hi Normal\s*font=.*', hlNormal)
Bram Moolenaar6b528fa2019-05-09 20:07:33 +0200767 endif
Bram Moolenaarf90b6e02019-05-09 19:26:38 +0200768endfunc
Bram Moolenaar548be7f2019-06-29 03:42:42 +0200769
Bram Moolenaar3180fe62020-02-02 13:47:06 +0100770" Do this test last, sometimes restoring the columns doesn't work
Bram Moolenaaree4e0c12020-04-06 21:35:05 +0200771func Test_z_no_space_before_xxx()
Bram Moolenaar548be7f2019-06-29 03:42:42 +0200772 let l:org_columns = &columns
773 set columns=17
774 let l:hi_StatusLineTermNC = join(split(execute('hi StatusLineTermNC')))
775 call assert_match('StatusLineTermNC xxx', l:hi_StatusLineTermNC)
776 let &columns = l:org_columns
Bram Moolenaaree4e0c12020-04-06 21:35:05 +0200777endfunc
778
779" Test for :highlight command errors
780func Test_highlight_cmd_errors()
781 if has('gui_running')
782 " This test doesn't fail in the MS-Windows console version.
Bram Moolenaar75e15672020-06-28 13:10:22 +0200783 call assert_fails('hi Xcomment ctermbg=fg', 'E419:')
Bram Moolenaaree4e0c12020-04-06 21:35:05 +0200784 call assert_fails('hi Xcomment ctermfg=bg', 'E420:')
Bram Moolenaar75e15672020-06-28 13:10:22 +0200785 call assert_fails('hi Xcomment ctermfg=ul', 'E453:')
erw7f7f7aaf2021-12-07 21:29:20 +0000786 call assert_fails('hi ' .. repeat('a', 201) .. ' ctermfg=black', 'E1249:')
Bram Moolenaaree4e0c12020-04-06 21:35:05 +0200787 endif
788
789 " Try using a very long terminal code. Define a dummy terminal code for this
790 " test.
791 let &t_fo = "\<Esc>1;"
792 let c = repeat("t_fo,", 100) . "t_fo"
793 call assert_fails('exe "hi Xgroup1 start=" . c', 'E422:')
794 let &t_fo = ""
795endfunc
796
Bram Moolenaar75e15672020-06-28 13:10:22 +0200797" Test for 'highlight' option
798func Test_highlight_opt()
799 let save_hl = &highlight
800 call assert_fails('set highlight=j:b', 'E474:')
801 set highlight=f\ r
802 call assert_equal('f r', &highlight)
803 set highlight=fb
804 call assert_equal('fb', &highlight)
805 set highlight=fi
806 call assert_equal('fi', &highlight)
807 set highlight=f-
808 call assert_equal('f-', &highlight)
809 set highlight=fr
810 call assert_equal('fr', &highlight)
811 set highlight=fs
812 call assert_equal('fs', &highlight)
813 set highlight=fu
814 call assert_equal('fu', &highlight)
815 set highlight=fc
816 call assert_equal('fc', &highlight)
817 set highlight=ft
818 call assert_equal('ft', &highlight)
819 call assert_fails('set highlight=fr:Search', 'E474:')
820 set highlight=f:$#
821 call assert_match('W18:', v:statusmsg)
822 let &highlight = save_hl
823endfunc
824
825" Test for User group highlighting used in the statusline
826func Test_highlight_User()
827 CheckNotGui
828 hi User1 ctermfg=12
829 redraw!
830 call assert_equal('12', synIDattr(synIDtrans(hlID('User1')), 'fg'))
831 hi clear
832endfunc
833
834" Test for using RGB color values in a highlight group
Bram Moolenaar09fbedc2021-01-19 17:22:58 +0100835func Test_xxlast_highlight_RGB_color()
836 CheckCanRunGui
837 gui -f
Bram Moolenaar75e15672020-06-28 13:10:22 +0200838 hi MySearch guifg=#110000 guibg=#001100 guisp=#000011
839 call assert_equal('#110000', synIDattr(synIDtrans(hlID('MySearch')), 'fg#'))
840 call assert_equal('#001100', synIDattr(synIDtrans(hlID('MySearch')), 'bg#'))
841 call assert_equal('#000011', synIDattr(synIDtrans(hlID('MySearch')), 'sp#'))
842 hi clear
843endfunc
844
Bram Moolenaarde8f0f42020-06-30 18:45:43 +0200845" Test for using default highlighting group
846func Test_highlight_default()
847 highlight MySearch ctermfg=7
848 highlight default MySearch ctermfg=5
849 let hlSearch = HighlightArgs('MySearch')
850 call assert_match('ctermfg=7', hlSearch)
851
852 highlight default QFName ctermfg=3
853 call assert_match('ctermfg=3', HighlightArgs('QFName'))
854 hi clear
855endfunc
856
857" Test for 'ctermul in a highlight group
858func Test_highlight_ctermul()
859 CheckNotGui
860 call assert_notmatch('ctermul=', HighlightArgs('Normal'))
861 highlight Normal ctermul=3
862 call assert_match('ctermul=3', HighlightArgs('Normal'))
Bram Moolenaar391c3622020-09-29 20:59:17 +0200863 call assert_equal('3', synIDattr(synIDtrans(hlID('Normal')), 'ul'))
Bram Moolenaarde8f0f42020-06-30 18:45:43 +0200864 highlight Normal ctermul=NONE
865endfunc
866
867" Test for specifying 'start' and 'stop' in a highlight group
868func Test_highlight_start_stop()
869 hi HlGrp1 start=<Esc>[27h;<Esc>[<Space>r;
870 call assert_match("start=^[[27h;^[[ r;", HighlightArgs('HlGrp1'))
871 hi HlGrp1 start=NONE
872 call assert_notmatch("start=", HighlightArgs('HlGrp1'))
873 hi HlGrp2 stop=<Esc>[27h;<Esc>[<Space>r;
874 call assert_match("stop=^[[27h;^[[ r;", HighlightArgs('HlGrp2'))
875 hi HlGrp2 stop=NONE
876 call assert_notmatch("stop=", HighlightArgs('HlGrp2'))
877 hi clear
878endfunc
879
880" Test for setting various 'term' attributes
881func Test_highlight_term_attr()
Bram Moolenaar84f54632022-06-29 18:39:11 +0100882 hi HlGrp3 term=bold,underline,undercurl,underdouble,underdotted,underdashed,strikethrough,reverse,italic,standout
883 call assert_equal('hi HlGrp3 term=bold,standout,underline,undercurl,underdouble,underdotted,underdashed,italic,reverse,strikethrough', HighlightArgs('HlGrp3'))
Bram Moolenaarde8f0f42020-06-30 18:45:43 +0200884 hi HlGrp3 term=NONE
885 call assert_equal('hi HlGrp3 cleared', HighlightArgs('HlGrp3'))
886 hi clear
887endfunc
888
Bram Moolenaar213da552020-09-17 19:59:26 +0200889func Test_highlight_clear_restores_links()
890 let aaa_id = hlID('aaa')
891 call assert_equal(aaa_id, 0)
892
893 " create default link aaa --> bbb
894 hi def link aaa bbb
895 let id_aaa = hlID('aaa')
896 let hl_aaa_bbb = HighlightArgs('aaa')
897
898 " try to redefine default link aaa --> ccc; check aaa --> bbb
899 hi def link aaa ccc
900 call assert_equal(HighlightArgs('aaa'), hl_aaa_bbb)
901
902 " clear aaa; check aaa --> bbb
903 hi clear aaa
904 call assert_equal(HighlightArgs('aaa'), hl_aaa_bbb)
905
906 " link aaa --> ccc; clear aaa; check aaa --> bbb
907 hi link aaa ccc
908 let id_ccc = hlID('ccc')
909 call assert_equal(synIDtrans(id_aaa), id_ccc)
910 hi clear aaa
911 call assert_equal(HighlightArgs('aaa'), hl_aaa_bbb)
912
913 " forcibly set default link aaa --> ddd
914 hi! def link aaa ddd
915 let id_ddd = hlID('ddd')
916 let hl_aaa_ddd = HighlightArgs('aaa')
917 call assert_equal(synIDtrans(id_aaa), id_ddd)
918
919 " link aaa --> eee; clear aaa; check aaa --> ddd
920 hi link aaa eee
921 let eee_id = hlID('eee')
922 call assert_equal(synIDtrans(id_aaa), eee_id)
923 hi clear aaa
924 call assert_equal(HighlightArgs('aaa'), hl_aaa_ddd)
925endfunc
926
Bram Moolenaare8df0102020-09-18 19:40:45 +0200927func Test_highlight_clear_restores_context()
928 func FuncContextDefault()
929 hi def link Context ContextDefault
930 endfun
931
932 func FuncContextRelink()
933 " Dummy line
934 hi link Context ContextRelink
935 endfunc
936
937 let scriptContextDefault = MakeScript("FuncContextDefault")
938 let scriptContextRelink = MakeScript("FuncContextRelink")
939 let patContextDefault = fnamemodify(scriptContextDefault, ':t') .. ' line 1'
940 let patContextRelink = fnamemodify(scriptContextRelink, ':t') .. ' line 2'
941
Bram Moolenaar2bbada82020-09-18 21:55:26 +0200942 exec 'source ' .. scriptContextDefault
Bram Moolenaare8df0102020-09-18 19:40:45 +0200943 let hlContextDefault = execute("verbose hi Context")
944 call assert_match(patContextDefault, hlContextDefault)
945
Bram Moolenaar2bbada82020-09-18 21:55:26 +0200946 exec 'source ' .. scriptContextRelink
Bram Moolenaare8df0102020-09-18 19:40:45 +0200947 let hlContextRelink = execute("verbose hi Context")
948 call assert_match(patContextRelink, hlContextRelink)
949
950 hi clear
951 let hlContextAfterClear = execute("verbose hi Context")
952 call assert_match(patContextDefault, hlContextAfterClear)
953
954 delfunc FuncContextDefault
955 delfunc FuncContextRelink
956 call delete(scriptContextDefault)
957 call delete(scriptContextRelink)
958endfunc
959
Bram Moolenaar213da552020-09-17 19:59:26 +0200960func Test_highlight_default_colorscheme_restores_links()
961 hi link TestLink Identifier
962 hi TestHi ctermbg=red
Bram Moolenaar05eb5b92020-09-16 15:43:21 +0200963
964 let hlTestLinkPre = HighlightArgs('TestLink')
965 let hlTestHiPre = HighlightArgs('TestHi')
966
967 " Test colorscheme
Dominique Pelle8bfa0eb2022-01-02 16:16:33 +0000968 call assert_equal("\ndefault", execute('colorscheme'))
Bram Moolenaar05eb5b92020-09-16 15:43:21 +0200969 hi clear
970 if exists('syntax_on')
971 syntax reset
972 endif
973 let g:colors_name = 'test'
Dominique Pelle8bfa0eb2022-01-02 16:16:33 +0000974 call assert_equal("\ntest", execute('colorscheme'))
Bram Moolenaar213da552020-09-17 19:59:26 +0200975 hi link TestLink ErrorMsg
976 hi TestHi ctermbg=green
Bram Moolenaar05eb5b92020-09-16 15:43:21 +0200977
978 " Restore default highlighting
979 colorscheme default
Bram Moolenaar05eb5b92020-09-16 15:43:21 +0200980 " 'default' should work no matter if highlight group was cleared
Dominique Pelle8bfa0eb2022-01-02 16:16:33 +0000981 call assert_equal("\ndefault", execute('colorscheme'))
Bram Moolenaar05eb5b92020-09-16 15:43:21 +0200982 hi def link TestLink Identifier
983 hi def TestHi ctermbg=red
Bram Moolenaar05eb5b92020-09-16 15:43:21 +0200984 let hlTestLinkPost = HighlightArgs('TestLink')
985 let hlTestHiPost = HighlightArgs('TestHi')
Bram Moolenaar05eb5b92020-09-16 15:43:21 +0200986 call assert_equal(hlTestLinkPre, hlTestLinkPost)
987 call assert_equal(hlTestHiPre, hlTestHiPost)
988 hi clear
989endfunc
990
Drew Vogele30d1022021-10-24 20:35:07 +0100991func Test_colornames_assignment_and_lookup()
Drew Vogela0fca172021-11-13 10:50:01 +0000992 CheckAnyOf Feature:gui_running Feature:termguicolors
993
Drew Vogele30d1022021-10-24 20:35:07 +0100994 " Ensure highlight command can find custom color.
995 let v:colornames['a redish white'] = '#ffeedd'
996 highlight Normal guifg='a redish white'
997 highlight clear
Drew Vogela0fca172021-11-13 10:50:01 +0000998 call ClearDict(v:colornames)
Drew Vogele30d1022021-10-24 20:35:07 +0100999endfunc
1000
1001func Test_colornames_default_list()
Drew Vogela0fca172021-11-13 10:50:01 +00001002 CheckAnyOf Feature:gui_running Feature:termguicolors
1003
Drew Vogele30d1022021-10-24 20:35:07 +01001004 " Ensure default lists are loaded automatically and can be used for all gui fields.
Drew Vogela0fca172021-11-13 10:50:01 +00001005 call assert_equal(0, len(v:colornames))
Drew Vogele30d1022021-10-24 20:35:07 +01001006 highlight Normal guifg='rebecca purple' guibg='rebecca purple' guisp='rebecca purple'
Drew Vogela0fca172021-11-13 10:50:01 +00001007 call assert_notequal(0, len(v:colornames))
1008 echo v:colornames['rebecca purple']
Drew Vogele30d1022021-10-24 20:35:07 +01001009 highlight clear
Drew Vogela0fca172021-11-13 10:50:01 +00001010 call ClearDict(v:colornames)
Drew Vogele30d1022021-10-24 20:35:07 +01001011endfunc
1012
1013func Test_colornames_overwrite_default()
Drew Vogela0fca172021-11-13 10:50:01 +00001014 CheckAnyOf Feature:gui_running Feature:termguicolors
1015
Drew Vogele30d1022021-10-24 20:35:07 +01001016 " Ensure entries in v:colornames can be overwritten.
1017 " Load default color scheme to trigger default color list loading.
1018 colorscheme default
1019 let old_rebecca_purple = v:colornames['rebecca purple']
1020 highlight Normal guifg='rebecca purple' guibg='rebecca purple'
1021 let v:colornames['rebecca purple'] = '#550099'
1022 highlight Normal guifg='rebecca purple' guibg='rebecca purple'
1023 let v:colornames['rebecca purple'] = old_rebecca_purple
1024 highlight clear
1025endfunc
1026
1027func Test_colornames_assignment_and_unassignment()
Drew Vogela0fca172021-11-13 10:50:01 +00001028 " No feature check is needed for this test because the v:colornames dict
1029 " always exists with +eval. The feature checks are only required for
1030 " commands that do color lookup.
1031
Drew Vogele30d1022021-10-24 20:35:07 +01001032 " Ensure we cannot overwrite the v:colornames dict.
1033 call assert_fails("let v:colornames = {}", 'E46:')
1034
1035 " Ensure we can delete entries from the v:colornames dict.
1036 let v:colornames['x1'] = '#111111'
1037 call assert_equal(v:colornames['x1'], '#111111')
1038 unlet v:colornames['x1']
1039 call assert_fails("echo v:colornames['x1']")
1040endfunc
1041
Yegappan Lakshmanand1a8d652021-11-03 21:56:45 +00001042" Test for the hlget() function
1043func Test_hlget()
1044 let lines =<< trim END
1045 call assert_notequal([], filter(hlget(), 'v:val.name == "Visual"'))
1046 call assert_equal([], hlget('SomeHLGroup'))
1047 highlight MyHLGroup term=standout cterm=reverse ctermfg=10 ctermbg=Black
1048 call assert_equal([{'id': hlID('MyHLGroup'), 'ctermfg': '10', 'name': 'MyHLGroup', 'term': {'standout': v:true}, 'ctermbg': '0', 'cterm': {'reverse': v:true}}], hlget('MyHLGroup'))
1049 highlight clear MyHLGroup
1050 call assert_equal(v:true, hlget('MyHLGroup')[0].cleared)
1051 highlight link MyHLGroup IncSearch
1052 call assert_equal('IncSearch', hlget('MyHLGroup')[0].linksto)
1053 highlight clear MyHLGroup
1054 call assert_equal([], hlget(test_null_string()))
1055 call assert_equal([], hlget(""))
1056 END
Bram Moolenaar62aec932022-01-29 21:45:34 +00001057 call v9.CheckLegacyAndVim9Success(lines)
Yegappan Lakshmanand1a8d652021-11-03 21:56:45 +00001058
1059 " Test for resolving highlight group links
1060 let lines =<< trim END
1061 highlight hlgA term=bold
1062 VAR hlgAid = hlID('hlgA')
1063 highlight link hlgB hlgA
1064 VAR hlgBid = hlID('hlgB')
1065 highlight link hlgC hlgB
1066 VAR hlgCid = hlID('hlgC')
1067 call assert_equal('hlgA', hlget('hlgB')[0].linksto)
1068 call assert_equal('hlgB', hlget('hlgC')[0].linksto)
1069 call assert_equal([{'id': hlgAid, 'name': 'hlgA',
1070 \ 'term': {'bold': v:true}}], hlget('hlgA'))
1071 call assert_equal([{'id': hlgBid, 'name': 'hlgB',
1072 \ 'linksto': 'hlgA'}], hlget('hlgB'))
1073 call assert_equal([{'id': hlgCid, 'name': 'hlgC',
1074 \ 'linksto': 'hlgB'}], hlget('hlgC'))
1075 call assert_equal([{'id': hlgAid, 'name': 'hlgA',
1076 \ 'term': {'bold': v:true}}], hlget('hlgA', v:false))
1077 call assert_equal([{'id': hlgBid, 'name': 'hlgB',
1078 \ 'linksto': 'hlgA'}], hlget('hlgB', 0))
1079 call assert_equal([{'id': hlgCid, 'name': 'hlgC',
1080 \ 'linksto': 'hlgB'}], hlget('hlgC', v:false))
1081 call assert_equal([{'id': hlgAid, 'name': 'hlgA',
1082 \ 'term': {'bold': v:true}}], hlget('hlgA', v:true))
1083 call assert_equal([{'id': hlgBid, 'name': 'hlgB',
1084 \ 'term': {'bold': v:true}}], hlget('hlgB', 1))
1085 call assert_equal([{'id': hlgCid, 'name': 'hlgC',
1086 \ 'term': {'bold': v:true}}], hlget('hlgC', v:true))
1087 END
Bram Moolenaar62aec932022-01-29 21:45:34 +00001088 call v9.CheckLegacyAndVim9Success(lines)
Yegappan Lakshmanand1a8d652021-11-03 21:56:45 +00001089
1090 call assert_fails('call hlget([])', 'E1174:')
1091 call assert_fails('call hlget("abc", "xyz")', 'E1212:')
1092endfunc
1093
1094" Test for the hlset() function
1095func Test_hlset()
1096 let lines =<< trim END
1097 call assert_equal(0, hlset(test_null_list()))
1098 call assert_equal(0, hlset([]))
1099 call assert_fails('call hlset(["Search"])', 'E715:')
1100 call hlset(hlget())
1101 call hlset([{'name': 'NewHLGroup', 'cterm': {'reverse': v:true}, 'ctermfg': '10'}])
1102 call assert_equal({'reverse': v:true}, hlget('NewHLGroup')[0].cterm)
1103 call hlset([{'name': 'NewHLGroup', 'cterm': {'bold': v:true}}])
1104 call assert_equal({'bold': v:true}, hlget('NewHLGroup')[0].cterm)
1105 call hlset([{'name': 'NewHLGroup', 'cleared': v:true}])
1106 call assert_equal(v:true, hlget('NewHLGroup')[0].cleared)
1107 call hlset([{'name': 'NewHLGroup', 'linksto': 'Search'}])
1108 call assert_false(has_key(hlget('NewHLGroup')[0], 'cleared'))
1109 call assert_equal('Search', hlget('NewHLGroup')[0].linksto)
1110 call assert_fails("call hlset([{'name': [], 'ctermfg': '10'}])", 'E928:')
1111 call assert_fails("call hlset([{'name': 'NewHLGroup', 'cleared': []}])",
1112 \ 'E745:')
1113 call assert_fails("call hlset([{'name': 'NewHLGroup', 'cterm': 'Blue'}])",
1114 \ 'E715:')
1115 call assert_fails("call hlset([{'name': 'NewHLGroup', 'ctermbg': []}])",
1116 \ 'E928:')
1117 call assert_fails("call hlset([{'name': 'NewHLGroup', 'ctermfg': []}])",
1118 \ 'E928:')
1119 call assert_fails("call hlset([{'name': 'NewHLGroup', 'ctermul': []}])",
1120 \ 'E928:')
1121 if has('gui')
1122 call assert_fails("call hlset([{'name': 'NewHLGroup', 'font': []}])",
1123 \ 'E928:')
1124 endif
1125 call assert_fails("call hlset([{'name': 'NewHLGroup', 'gui': 'Cyan'}])",
1126 \ 'E715:')
1127 call assert_fails("call hlset([{'name': 'NewHLGroup', 'guibg': []}])",
1128 \ 'E928:')
1129 call assert_fails("call hlset([{'name': 'NewHLGroup', 'guifg': []}])",
1130 \ 'E928:')
1131 call assert_fails("call hlset([{'name': 'NewHLGroup', 'guisp': []}])",
1132 \ 'E928:')
1133 call assert_fails("call hlset([{'name': 'NewHLGroup', 'linksto': []}])",
1134 \ 'E928:')
1135 call assert_fails("call hlset([{'name': 'NewHLGroup', 'start': []}])",
1136 \ 'E928:')
1137 call assert_fails("call hlset([{'name': 'NewHLGroup', 'stop': []}])",
1138 \ 'E928:')
1139 call assert_fails("call hlset([{'name': 'NewHLGroup', 'term': 'Cyan'}])",
1140 \ 'E715:')
1141 call assert_equal('Search', hlget('NewHLGroup')[0].linksto)
1142 highlight clear NewHLGroup
1143 END
Bram Moolenaar62aec932022-01-29 21:45:34 +00001144 call v9.CheckLegacyAndVim9Success(lines)
Yegappan Lakshmanand1a8d652021-11-03 21:56:45 +00001145
1146 " Test for clearing the 'term', 'cterm' and 'gui' attributes of a highlight
1147 " group.
1148 let lines =<< trim END
1149 highlight myhlg1 term=bold cterm=italic gui=standout
1150 VAR id = hlID('myhlg1')
1151 call hlset([{'name': 'myhlg1', 'term': {}}])
1152 call assert_equal([{'id': id, 'name': 'myhlg1',
1153 \ 'cterm': {'italic': v:true}, 'gui': {'standout': v:true}}],
1154 \ hlget('myhlg1'))
1155 call hlset([{'name': 'myhlg1', 'cterm': {}}])
1156 call assert_equal([{'id': id, 'name': 'myhlg1',
1157 \ 'gui': {'standout': v:true}}], hlget('myhlg1'))
1158 call hlset([{'name': 'myhlg1', 'gui': {}}])
1159 call assert_equal([{'id': id, 'name': 'myhlg1', 'cleared': v:true}],
1160 \ hlget('myhlg1'))
1161 highlight clear myhlg1
1162 END
Bram Moolenaar62aec932022-01-29 21:45:34 +00001163 call v9.CheckLegacyAndVim9Success(lines)
Yegappan Lakshmanand1a8d652021-11-03 21:56:45 +00001164
1165 " Test for setting all the 'term', 'cterm' and 'gui' attributes of a
1166 " highlight group
1167 let lines =<< trim END
Bram Moolenaar84f54632022-06-29 18:39:11 +01001168 VAR attr = {'bold': v:true, 'underline': v:true,
1169 \ 'undercurl': v:true, 'underdouble': v:true,
1170 \ 'underdotted': v:true, 'underdashed': v:true,
Yegappan Lakshmanand1a8d652021-11-03 21:56:45 +00001171 \ 'strikethrough': v:true, 'reverse': v:true, 'italic': v:true,
1172 \ 'standout': v:true, 'nocombine': v:true}
1173 call hlset([{'name': 'myhlg2', 'term': attr, 'cterm': attr, 'gui': attr}])
1174 VAR id2 = hlID('myhlg2')
Bram Moolenaar84f54632022-06-29 18:39:11 +01001175 VAR expected = "myhlg2 xxx term=bold,standout,underline,undercurl,underdouble,underdotted,underdashed,italic,reverse,nocombine,strikethrough cterm=bold,standout,underline,undercurl,underdouble,underdotted,underdashed,italic,reverse,nocombine,strikethrough gui=bold,standout,underline,undercurl,underdouble,underdotted,underdashed,italic,reverse,nocombine,strikethrough"
Yegappan Lakshmanan2a16dc62021-11-16 17:19:30 +00001176 VAR output = execute('highlight myhlg2')
1177 LET output = output->split("\n")->join()->substitute('\s\+', ' ', 'g')
1178 call assert_equal(expected, output)
Yegappan Lakshmanand1a8d652021-11-03 21:56:45 +00001179 call assert_equal([{'id': id2, 'name': 'myhlg2', 'gui': attr,
1180 \ 'term': attr, 'cterm': attr}], hlget('myhlg2'))
1181 END
Bram Moolenaar62aec932022-01-29 21:45:34 +00001182 call v9.CheckLegacyAndVim9Success(lines)
Yegappan Lakshmanand1a8d652021-11-03 21:56:45 +00001183
1184 " Test for clearing some of the 'term', 'cterm' and 'gui' attributes of a
1185 " highlight group
1186 let lines =<< trim END
1187 VAR attr = {'bold': v:false, 'underline': v:true, 'strikethrough': v:true}
1188 call hlset([{'name': 'myhlg2', 'term': attr, 'cterm': attr, 'gui': attr}])
1189 VAR id2 = hlID('myhlg2')
Yegappan Lakshmanan2a16dc62021-11-16 17:19:30 +00001190 VAR expected = "myhlg2 xxx term=underline,strikethrough cterm=underline,strikethrough gui=underline,strikethrough"
1191 VAR output = execute('highlight myhlg2')
1192 LET output = output->split("\n")->join()->substitute('\s\+', ' ', 'g')
1193 call assert_equal(expected, output)
Yegappan Lakshmanand1a8d652021-11-03 21:56:45 +00001194 LET attr = {'underline': v:true, 'strikethrough': v:true}
1195 call assert_equal([{'id': id2, 'name': 'myhlg2', 'gui': attr,
1196 \ 'term': attr, 'cterm': attr}], hlget('myhlg2'))
1197 END
Bram Moolenaar62aec932022-01-29 21:45:34 +00001198 call v9.CheckLegacyAndVim9Success(lines)
Dominique Pelle6a950a62021-11-13 18:44:37 +00001199
Yegappan Lakshmanan2a16dc62021-11-16 17:19:30 +00001200 " Test for clearing the attributes and link of a highlight group
1201 let lines =<< trim END
1202 highlight myhlg3 ctermbg=green guibg=green
1203 highlight! default link myhlg3 ErrorMsg
1204 VAR id3 = hlID('myhlg3')
1205 call hlset([{'name': 'myhlg3', 'cleared': v:true, 'linksto': 'NONE'}])
1206 call assert_equal([{'id': id3, 'name': 'myhlg3', 'cleared': v:true}],
1207 \ hlget('myhlg3'))
1208 highlight clear hlg3
1209 END
Bram Moolenaar62aec932022-01-29 21:45:34 +00001210 call v9.CheckLegacyAndVim9Success(lines)
Yegappan Lakshmanan2a16dc62021-11-16 17:19:30 +00001211
1212 " Test for setting default attributes for a highlight group
1213 let lines =<< trim END
1214 call hlset([{'name': 'hlg4', 'ctermfg': '8'}])
1215 call hlset([{'name': 'hlg4', 'default': v:true, 'ctermfg': '9'}])
1216 VAR id4 = hlID('hlg4')
1217 call assert_equal([{'id': id4, 'name': 'hlg4', 'ctermfg': '8'}],
1218 \ hlget('hlg4'))
1219 highlight clear hlg4
1220
1221 call hlset([{'name': 'hlg5', 'default': v:true, 'ctermbg': '2'}])
1222 call hlset([{'name': 'hlg5', 'ctermbg': '4'}])
1223 VAR id5 = hlID('hlg5')
1224 call assert_equal([{'id': id5, 'name': 'hlg5', 'ctermbg': '4'}],
1225 \ hlget('hlg5'))
1226 highlight clear hlg5
1227
1228 call hlset([{'name': 'hlg6', 'linksto': 'Error'}])
1229 VAR id6 = hlID('hlg6')
1230 call hlset([{'name': 'hlg6', 'default': v:true, 'ctermbg': '2'}])
1231 call assert_equal([{'id': id6, 'name': 'hlg6', 'linksto': 'Error'}],
1232 \ hlget('hlg6'))
1233 highlight clear hlg6
1234 END
Bram Moolenaar62aec932022-01-29 21:45:34 +00001235 call v9.CheckLegacyAndVim9Success(lines)
Yegappan Lakshmanan2a16dc62021-11-16 17:19:30 +00001236
1237 " Test for setting default links for a highlight group
1238 let lines =<< trim END
1239 call hlset([{'name': 'hlg7', 'ctermfg': '5'}])
1240 call hlset([{'name': 'hlg7', 'default': v:true, 'linksto': 'Search'}])
1241 VAR id7 = hlID('hlg7')
1242 call assert_equal([{'id': id7, 'name': 'hlg7', 'ctermfg': '5'}],
1243 \ hlget('hlg7'))
1244 highlight clear hlg7
1245
1246 call hlset([{'name': 'hlg8', 'default': v:true, 'linksto': 'Search'}])
1247 VAR id8 = hlID('hlg8')
1248 call assert_equal([{'id': id8, 'name': 'hlg8', 'default': v:true,
1249 \ 'linksto': 'Search'}], hlget('hlg8'))
1250 call hlset([{'name': 'hlg8', 'ctermbg': '2'}])
1251 call assert_equal([{'id': id8, 'name': 'hlg8', 'ctermbg': '2'}],
1252 \ hlget('hlg8'))
1253 highlight clear hlg8
1254
1255 highlight default link hlg9 ErrorMsg
1256 VAR hlg_save = hlget('hlg9')
1257 LET hlg_save[0]['name'] = 'hlg9dup'
1258 call hlset(hlg_save)
1259 VAR id9 = hlID('hlg9dup')
1260 highlight clear hlg9dup
1261 call assert_equal([{'id': id9, 'name': 'hlg9dup', 'default': v:true,
1262 \ 'linksto': 'ErrorMsg'}], hlget('hlg9dup'))
1263 highlight clear hlg9
1264 END
Bram Moolenaar62aec932022-01-29 21:45:34 +00001265 call v9.CheckLegacyAndVim9Success(lines)
Yegappan Lakshmanan2a16dc62021-11-16 17:19:30 +00001266
1267 " Test for force creating a link to a highlight group
1268 let lines =<< trim END
1269 call hlset([{'name': 'hlg10', 'ctermfg': '8'}])
1270 call hlset([{'name': 'hlg10', 'linksto': 'Search'}])
1271 VAR id10 = hlID('hlg10')
1272 call assert_equal([{'id': id10, 'name': 'hlg10', 'ctermfg': '8'}],
1273 \ hlget('hlg10'))
1274 call hlset([{'name': 'hlg10', 'linksto': 'Search', 'force': v:true}])
1275 call assert_equal([{'id': id10, 'name': 'hlg10', 'ctermfg': '8',
1276 \ 'linksto': 'Search'}], hlget('hlg10'))
1277 highlight clear hlg10
1278 END
Bram Moolenaar62aec932022-01-29 21:45:34 +00001279 call v9.CheckLegacyAndVim9Success(lines)
Yegappan Lakshmananbb277fd2021-11-24 20:28:31 +00001280
1281 " Test for empty values of attributes
1282 call hlset([{'name': 'hlg11', 'cterm': {}}])
1283 call hlset([{'name': 'hlg11', 'ctermfg': ''}])
1284 call hlset([{'name': 'hlg11', 'ctermbg': ''}])
1285 call hlset([{'name': 'hlg11', 'ctermul': ''}])
1286 call hlset([{'name': 'hlg11', 'font': ''}])
1287 call hlset([{'name': 'hlg11', 'gui': {}}])
1288 call hlset([{'name': 'hlg11', 'guifg': ''}])
1289 call hlset([{'name': 'hlg11', 'guibg': ''}])
1290 call hlset([{'name': 'hlg11', 'guisp': ''}])
1291 call hlset([{'name': 'hlg11', 'start': ''}])
1292 call hlset([{'name': 'hlg11', 'stop': ''}])
1293 call hlset([{'name': 'hlg11', 'term': {}}])
1294 call assert_true(hlget('hlg11')[0].cleared)
Yegappan Lakshmanand1a8d652021-11-03 21:56:45 +00001295endfunc
1296
Bram Moolenaaree4e0c12020-04-06 21:35:05 +02001297" vim: shiftwidth=2 sts=2 expandtab