blob: 487eb8dc14795cf1de85a83da8502e658cbbc3ea [file] [log] [blame]
Bram Moolenaar0aa398f2017-09-30 21:23:55 +02001" Tests for ":highlight" and highlighting.
2
Bram Moolenaarc07ff5c2019-01-30 21:41:14 +01003source screendump.vim
Bram Moolenaare8df0102020-09-18 19:40:45 +02004source script_util.vim
Bram Moolenaar62aec932022-01-29 21:45:34 +00005import './vim9.vim' as v9
Bram Moolenaar0aa398f2017-09-30 21:23:55 +02006
Drew Vogela0fca172021-11-13 10:50:01 +00007func ClearDict(d)
8 for k in keys(a:d)
9 call remove(a:d, k)
10 endfor
11endfunc
12
Bram Moolenaar75373f32017-08-07 22:02:30 +020013func Test_highlight()
14 " basic test if ":highlight" doesn't crash
15 highlight
16 hi Search
17
18 " test setting colors.
19 " test clearing one color and all doesn't generate error or warning
20 silent! hi NewGroup term=bold cterm=italic ctermfg=DarkBlue ctermbg=Grey gui= guifg=#00ff00 guibg=Cyan
21 silent! hi Group2 term= cterm=
22 hi Group3 term=underline cterm=bold
23
24 let res = split(execute("hi NewGroup"), "\n")[0]
25 " filter ctermfg and ctermbg, the numbers depend on the terminal
26 let res = substitute(res, 'ctermfg=\d*', 'ctermfg=2', '')
27 let res = substitute(res, 'ctermbg=\d*', 'ctermbg=3', '')
28 call assert_equal("NewGroup xxx term=bold cterm=italic ctermfg=2 ctermbg=3",
29 \ res)
30 call assert_equal("Group2 xxx cleared",
31 \ split(execute("hi Group2"), "\n")[0])
32 call assert_equal("Group3 xxx term=underline cterm=bold",
33 \ split(execute("hi Group3"), "\n")[0])
34
35 hi clear NewGroup
36 call assert_equal("NewGroup xxx cleared",
37 \ split(execute("hi NewGroup"), "\n")[0])
38 call assert_equal("Group2 xxx cleared",
39 \ split(execute("hi Group2"), "\n")[0])
40 hi Group2 NONE
41 call assert_equal("Group2 xxx cleared",
42 \ split(execute("hi Group2"), "\n")[0])
43 hi clear
44 call assert_equal("Group3 xxx cleared",
45 \ split(execute("hi Group3"), "\n")[0])
46 call assert_fails("hi Crash term='asdf", "E475:")
Bram Moolenaar5b9f5722023-02-19 20:49:38 +000047
48 if has('gui_running')
49 call assert_fails('hi NotUsed guibg=none', 'E1361:')
50 endif
Bram Moolenaar75373f32017-08-07 22:02:30 +020051endfunc
Bram Moolenaar0aa398f2017-09-30 21:23:55 +020052
Bram Moolenaar1e115362019-01-09 23:01:02 +010053func HighlightArgs(name)
Bram Moolenaar0aa398f2017-09-30 21:23:55 +020054 return 'hi ' . substitute(split(execute('hi ' . a:name), '\n')[0], '\<xxx\>', '', '')
Bram Moolenaar1e115362019-01-09 23:01:02 +010055endfunc
Bram Moolenaar0aa398f2017-09-30 21:23:55 +020056
Bram Moolenaar1e115362019-01-09 23:01:02 +010057func IsColorable()
Bram Moolenaar0aa398f2017-09-30 21:23:55 +020058 return has('gui_running') || str2nr(&t_Co) >= 8
Bram Moolenaar1e115362019-01-09 23:01:02 +010059endfunc
Bram Moolenaar0aa398f2017-09-30 21:23:55 +020060
Bram Moolenaar1e115362019-01-09 23:01:02 +010061func HiCursorLine()
Bram Moolenaar0aa398f2017-09-30 21:23:55 +020062 let hiCursorLine = HighlightArgs('CursorLine')
63 if has('gui_running')
64 let guibg = matchstr(hiCursorLine, 'guibg=\w\+')
65 let hi_ul = 'hi CursorLine gui=underline guibg=NONE'
66 let hi_bg = 'hi CursorLine gui=NONE ' . guibg
67 else
68 let hi_ul = 'hi CursorLine cterm=underline ctermbg=NONE'
69 let hi_bg = 'hi CursorLine cterm=NONE ctermbg=Gray'
70 endif
71 return [hiCursorLine, hi_ul, hi_bg]
Bram Moolenaar1e115362019-01-09 23:01:02 +010072endfunc
Bram Moolenaar0aa398f2017-09-30 21:23:55 +020073
Bram Moolenaar1e115362019-01-09 23:01:02 +010074func Check_lcs_eol_attrs(attrs, row, col)
Bram Moolenaar5ece3e32017-10-01 14:35:02 +020075 let save_lcs = &lcs
76 set list
77
78 call assert_equal(a:attrs, ScreenAttrs(a:row, a:col)[0])
79
80 set nolist
81 let &lcs = save_lcs
Bram Moolenaar1e115362019-01-09 23:01:02 +010082endfunc
Bram Moolenaar5ece3e32017-10-01 14:35:02 +020083
Bram Moolenaar0aa398f2017-09-30 21:23:55 +020084func Test_highlight_eol_with_cursorline()
85 let [hiCursorLine, hi_ul, hi_bg] = HiCursorLine()
86
87 call NewWindow('topleft 5', 20)
88 call setline(1, 'abcd')
89 call matchadd('Search', '\n')
90
91 " expected:
92 " 'abcd '
93 " ^^^^ ^^^^^ no highlight
94 " ^ 'Search' highlight
95 let attrs0 = ScreenAttrs(1, 10)[0]
96 call assert_equal(repeat([attrs0[0]], 4), attrs0[0:3])
97 call assert_equal(repeat([attrs0[0]], 5), attrs0[5:9])
98 call assert_notequal(attrs0[0], attrs0[4])
99
100 setlocal cursorline
101
102 " underline
103 exe hi_ul
104
105 " expected:
106 " 'abcd '
107 " ^^^^ underline
Bram Moolenaar5ece3e32017-10-01 14:35:02 +0200108 " ^ 'Search' highlight with underline
109 " ^^^^^ underline
Bram Moolenaar0aa398f2017-09-30 21:23:55 +0200110 let attrs = ScreenAttrs(1, 10)[0]
111 call assert_equal(repeat([attrs[0]], 4), attrs[0:3])
112 call assert_equal([attrs[4]] + repeat([attrs[5]], 5), attrs[4:9])
113 call assert_notequal(attrs[0], attrs[4])
114 call assert_notequal(attrs[4], attrs[5])
115 call assert_notequal(attrs0[0], attrs[0])
116 call assert_notequal(attrs0[4], attrs[4])
Bram Moolenaar5ece3e32017-10-01 14:35:02 +0200117 call Check_lcs_eol_attrs(attrs, 1, 10)
Bram Moolenaar0aa398f2017-09-30 21:23:55 +0200118
119 if IsColorable()
120 " bg-color
121 exe hi_bg
122
123 " expected:
124 " 'abcd '
125 " ^^^^ bg-color of 'CursorLine'
126 " ^ 'Search' highlight
127 " ^^^^^ bg-color of 'CursorLine'
128 let attrs = ScreenAttrs(1, 10)[0]
129 call assert_equal(repeat([attrs[0]], 4), attrs[0:3])
130 call assert_equal(repeat([attrs[5]], 5), attrs[5:9])
131 call assert_equal(attrs0[4], attrs[4])
132 call assert_notequal(attrs[0], attrs[4])
133 call assert_notequal(attrs[4], attrs[5])
134 call assert_notequal(attrs0[0], attrs[0])
135 call assert_notequal(attrs0[5], attrs[5])
Bram Moolenaar5ece3e32017-10-01 14:35:02 +0200136 call Check_lcs_eol_attrs(attrs, 1, 10)
Bram Moolenaar0aa398f2017-09-30 21:23:55 +0200137 endif
138
139 call CloseWindow()
140 exe hiCursorLine
141endfunc
142
143func Test_highlight_eol_with_cursorline_vertsplit()
Bram Moolenaar0aa398f2017-09-30 21:23:55 +0200144 let [hiCursorLine, hi_ul, hi_bg] = HiCursorLine()
145
146 call NewWindow('topleft 5', 5)
147 call setline(1, 'abcd')
148 call matchadd('Search', '\n')
149
150 let expected = "abcd |abcd "
151 let actual = ScreenLines(1, 15)[0]
152 call assert_equal(expected, actual)
153
154 " expected:
155 " 'abcd |abcd '
156 " ^^^^ ^^^^^^^^^ no highlight
157 " ^ 'Search' highlight
158 " ^ 'VertSplit' highlight
159 let attrs0 = ScreenAttrs(1, 15)[0]
160 call assert_equal(repeat([attrs0[0]], 4), attrs0[0:3])
161 call assert_equal(repeat([attrs0[0]], 9), attrs0[6:14])
162 call assert_notequal(attrs0[0], attrs0[4])
163 call assert_notequal(attrs0[0], attrs0[5])
164 call assert_notequal(attrs0[4], attrs0[5])
165
166 setlocal cursorline
167
168 " expected:
169 " 'abcd |abcd '
170 " ^^^^ underline
171 " ^ 'Search' highlight with underline
172 " ^ 'VertSplit' highlight
173 " ^^^^^^^^^ no highlight
174
175 " underline
176 exe hi_ul
177
178 let actual = ScreenLines(1, 15)[0]
179 call assert_equal(expected, actual)
180
181 let attrs = ScreenAttrs(1, 15)[0]
182 call assert_equal(repeat([attrs[0]], 4), attrs[0:3])
183 call assert_equal(repeat([attrs[6]], 9), attrs[6:14])
184 call assert_equal(attrs0[5:14], attrs[5:14])
185 call assert_notequal(attrs[0], attrs[4])
186 call assert_notequal(attrs[0], attrs[5])
187 call assert_notequal(attrs[0], attrs[6])
188 call assert_notequal(attrs[4], attrs[5])
189 call assert_notequal(attrs[5], attrs[6])
190 call assert_notequal(attrs0[0], attrs[0])
191 call assert_notequal(attrs0[4], attrs[4])
Bram Moolenaar5ece3e32017-10-01 14:35:02 +0200192 call Check_lcs_eol_attrs(attrs, 1, 15)
Bram Moolenaar0aa398f2017-09-30 21:23:55 +0200193
194 if IsColorable()
195 " bg-color
196 exe hi_bg
197
198 let actual = ScreenLines(1, 15)[0]
199 call assert_equal(expected, actual)
200
201 let attrs = ScreenAttrs(1, 15)[0]
202 call assert_equal(repeat([attrs[0]], 4), attrs[0:3])
203 call assert_equal(repeat([attrs[6]], 9), attrs[6:14])
204 call assert_equal(attrs0[5:14], attrs[5:14])
205 call assert_notequal(attrs[0], attrs[4])
206 call assert_notequal(attrs[0], attrs[5])
207 call assert_notequal(attrs[0], attrs[6])
208 call assert_notequal(attrs[4], attrs[5])
209 call assert_notequal(attrs[5], attrs[6])
210 call assert_notequal(attrs0[0], attrs[0])
211 call assert_equal(attrs0[4], attrs[4])
Bram Moolenaar5ece3e32017-10-01 14:35:02 +0200212 call Check_lcs_eol_attrs(attrs, 1, 15)
Bram Moolenaar0aa398f2017-09-30 21:23:55 +0200213 endif
214
215 call CloseWindow()
216 exe hiCursorLine
217endfunc
218
219func Test_highlight_eol_with_cursorline_rightleft()
Bram Moolenaar6d91bcb2020-08-12 18:50:36 +0200220 CheckFeature rightleft
Bram Moolenaar0aa398f2017-09-30 21:23:55 +0200221
222 let [hiCursorLine, hi_ul, hi_bg] = HiCursorLine()
223
224 call NewWindow('topleft 5', 10)
225 setlocal rightleft
226 call setline(1, 'abcd')
227 call matchadd('Search', '\n')
228 let attrs0 = ScreenAttrs(1, 10)[0]
229
230 setlocal cursorline
231
232 " underline
233 exe hi_ul
234
235 " expected:
236 " ' dcba'
237 " ^^^^ underline
238 " ^ 'Search' highlight with underline
239 " ^^^^^ underline
240 let attrs = ScreenAttrs(1, 10)[0]
241 call assert_equal(repeat([attrs[9]], 4), attrs[6:9])
242 call assert_equal(repeat([attrs[4]], 5) + [attrs[5]], attrs[0:5])
243 call assert_notequal(attrs[9], attrs[5])
244 call assert_notequal(attrs[4], attrs[5])
245 call assert_notequal(attrs0[9], attrs[9])
246 call assert_notequal(attrs0[5], attrs[5])
Bram Moolenaar5ece3e32017-10-01 14:35:02 +0200247 call Check_lcs_eol_attrs(attrs, 1, 10)
Bram Moolenaar0aa398f2017-09-30 21:23:55 +0200248
249 if IsColorable()
250 " bg-color
251 exe hi_bg
252
253 " expected:
254 " ' dcba'
255 " ^^^^ bg-color of 'CursorLine'
256 " ^ 'Search' highlight
257 " ^^^^^ bg-color of 'CursorLine'
258 let attrs = ScreenAttrs(1, 10)[0]
259 call assert_equal(repeat([attrs[9]], 4), attrs[6:9])
260 call assert_equal(repeat([attrs[4]], 5), attrs[0:4])
261 call assert_equal(attrs0[5], attrs[5])
262 call assert_notequal(attrs[9], attrs[5])
263 call assert_notequal(attrs[5], attrs[4])
264 call assert_notequal(attrs0[9], attrs[9])
265 call assert_notequal(attrs0[4], attrs[4])
Bram Moolenaar5ece3e32017-10-01 14:35:02 +0200266 call Check_lcs_eol_attrs(attrs, 1, 10)
Bram Moolenaar0aa398f2017-09-30 21:23:55 +0200267 endif
268
269 call CloseWindow()
270 exe hiCursorLine
271endfunc
272
273func Test_highlight_eol_with_cursorline_linewrap()
274 let [hiCursorLine, hi_ul, hi_bg] = HiCursorLine()
275
276 call NewWindow('topleft 5', 10)
277 call setline(1, [repeat('a', 51) . 'bcd', ''])
278 call matchadd('Search', '\n')
279
280 setlocal wrap
281 normal! gg$
282 let attrs0 = ScreenAttrs(5, 10)[0]
283 setlocal cursorline
284
285 " underline
286 exe hi_ul
287
288 " expected:
289 " 'abcd '
290 " ^^^^ underline
291 " ^ 'Search' highlight with underline
292 " ^^^^^ underline
293 let attrs = ScreenAttrs(5, 10)[0]
294 call assert_equal(repeat([attrs[0]], 4), attrs[0:3])
295 call assert_equal([attrs[4]] + repeat([attrs[5]], 5), attrs[4:9])
296 call assert_notequal(attrs[0], attrs[4])
297 call assert_notequal(attrs[4], attrs[5])
298 call assert_notequal(attrs0[0], attrs[0])
299 call assert_notequal(attrs0[4], attrs[4])
Bram Moolenaar5ece3e32017-10-01 14:35:02 +0200300 call Check_lcs_eol_attrs(attrs, 5, 10)
Bram Moolenaar0aa398f2017-09-30 21:23:55 +0200301
302 if IsColorable()
303 " bg-color
304 exe hi_bg
305
306 " expected:
307 " 'abcd '
308 " ^^^^ bg-color of 'CursorLine'
309 " ^ 'Search' highlight
310 " ^^^^^ bg-color of 'CursorLine'
311 let attrs = ScreenAttrs(5, 10)[0]
312 call assert_equal(repeat([attrs[0]], 4), attrs[0:3])
313 call assert_equal(repeat([attrs[5]], 5), attrs[5:9])
314 call assert_equal(attrs0[4], attrs[4])
315 call assert_notequal(attrs[0], attrs[4])
316 call assert_notequal(attrs[4], attrs[5])
317 call assert_notequal(attrs0[0], attrs[0])
318 call assert_notequal(attrs0[5], attrs[5])
Bram Moolenaar5ece3e32017-10-01 14:35:02 +0200319 call Check_lcs_eol_attrs(attrs, 5, 10)
Bram Moolenaar0aa398f2017-09-30 21:23:55 +0200320 endif
321
322 setlocal nocursorline nowrap
323 normal! gg$
324 let attrs0 = ScreenAttrs(1, 10)[0]
325 setlocal cursorline
326
327 " underline
328 exe hi_ul
329
330 " expected:
331 " 'aaabcd '
332 " ^^^^^^ underline
333 " ^ 'Search' highlight with underline
334 " ^^^ underline
335 let attrs = ScreenAttrs(1, 10)[0]
336 call assert_equal(repeat([attrs[0]], 6), attrs[0:5])
337 call assert_equal([attrs[6]] + repeat([attrs[7]], 3), attrs[6:9])
338 call assert_notequal(attrs[0], attrs[6])
339 call assert_notequal(attrs[6], attrs[7])
340 call assert_notequal(attrs0[0], attrs[0])
341 call assert_notequal(attrs0[6], attrs[6])
Bram Moolenaar5ece3e32017-10-01 14:35:02 +0200342 call Check_lcs_eol_attrs(attrs, 1, 10)
Bram Moolenaar0aa398f2017-09-30 21:23:55 +0200343
344 if IsColorable()
345 " bg-color
346 exe hi_bg
347
348 " expected:
349 " 'aaabcd '
350 " ^^^^^^ bg-color of 'CursorLine'
351 " ^ 'Search' highlight
352 " ^^^ bg-color of 'CursorLine'
353 let attrs = ScreenAttrs(1, 10)[0]
354 call assert_equal(repeat([attrs[0]], 6), attrs[0:5])
355 call assert_equal(repeat([attrs[7]], 3), attrs[7:9])
356 call assert_equal(attrs0[6], attrs[6])
357 call assert_notequal(attrs[0], attrs[6])
358 call assert_notequal(attrs[6], attrs[7])
359 call assert_notequal(attrs0[0], attrs[0])
360 call assert_notequal(attrs0[7], attrs[7])
Bram Moolenaar5ece3e32017-10-01 14:35:02 +0200361 call Check_lcs_eol_attrs(attrs, 1, 10)
Bram Moolenaar0aa398f2017-09-30 21:23:55 +0200362 endif
363
364 call CloseWindow()
365 exe hiCursorLine
366endfunc
367
368func Test_highlight_eol_with_cursorline_sign()
Bram Moolenaar6d91bcb2020-08-12 18:50:36 +0200369 CheckFeature signs
Bram Moolenaar0aa398f2017-09-30 21:23:55 +0200370
371 let [hiCursorLine, hi_ul, hi_bg] = HiCursorLine()
372
373 call NewWindow('topleft 5', 10)
374 call setline(1, 'abcd')
375 call matchadd('Search', '\n')
376
377 sign define Sign text=>>
378 exe 'sign place 1 line=1 name=Sign buffer=' . bufnr('')
379 let attrs0 = ScreenAttrs(1, 10)[0]
380 setlocal cursorline
381
382 " underline
383 exe hi_ul
384
385 " expected:
386 " '>>abcd '
387 " ^^ sign
388 " ^^^^ underline
389 " ^ 'Search' highlight with underline
390 " ^^^ underline
391 let attrs = ScreenAttrs(1, 10)[0]
392 call assert_equal(repeat([attrs[2]], 4), attrs[2:5])
393 call assert_equal([attrs[6]] + repeat([attrs[7]], 3), attrs[6:9])
394 call assert_notequal(attrs[2], attrs[6])
395 call assert_notequal(attrs[6], attrs[7])
396 call assert_notequal(attrs0[2], attrs[2])
397 call assert_notequal(attrs0[6], attrs[6])
Bram Moolenaar5ece3e32017-10-01 14:35:02 +0200398 call Check_lcs_eol_attrs(attrs, 1, 10)
Bram Moolenaar0aa398f2017-09-30 21:23:55 +0200399
400 if IsColorable()
401 " bg-color
402 exe hi_bg
403
404 " expected:
405 " '>>abcd '
406 " ^^ sign
407 " ^^^^ bg-color of 'CursorLine'
408 " ^ 'Search' highlight
409 " ^^^ bg-color of 'CursorLine'
410 let attrs = ScreenAttrs(1, 10)[0]
411 call assert_equal(repeat([attrs[2]], 4), attrs[2:5])
412 call assert_equal(repeat([attrs[7]], 3), attrs[7:9])
413 call assert_equal(attrs0[6], attrs[6])
414 call assert_notequal(attrs[2], attrs[6])
415 call assert_notequal(attrs[6], attrs[7])
416 call assert_notequal(attrs0[2], attrs[2])
417 call assert_notequal(attrs0[7], attrs[7])
Bram Moolenaar5ece3e32017-10-01 14:35:02 +0200418 call Check_lcs_eol_attrs(attrs, 1, 10)
Bram Moolenaar0aa398f2017-09-30 21:23:55 +0200419 endif
420
421 sign unplace 1
422 call CloseWindow()
423 exe hiCursorLine
424endfunc
425
426func Test_highlight_eol_with_cursorline_breakindent()
Bram Moolenaar6d91bcb2020-08-12 18:50:36 +0200427 CheckFeature linebreak
Bram Moolenaar0aa398f2017-09-30 21:23:55 +0200428
429 let [hiCursorLine, hi_ul, hi_bg] = HiCursorLine()
430
431 call NewWindow('topleft 5', 10)
Bram Moolenaaree857022019-11-09 23:26:40 +0100432 set showbreak=xxx
Bram Moolenaar0aa398f2017-09-30 21:23:55 +0200433 setlocal breakindent breakindentopt=min:0,shift:1 showbreak=>
434 call setline(1, ' ' . repeat('a', 9) . 'bcd')
435 call matchadd('Search', '\n')
436 let attrs0 = ScreenAttrs(2, 10)[0]
437 setlocal cursorline
438
439 " underline
440 exe hi_ul
441
442 " expected:
443 " ' >bcd '
444 " ^^^ breakindent and showbreak
445 " ^^^ underline
446 " ^ 'Search' highlight with underline
447 " ^^^ underline
448 let attrs = ScreenAttrs(2, 10)[0]
449 call assert_equal(repeat([attrs[0]], 2), attrs[0:1])
450 call assert_equal(repeat([attrs[3]], 3), attrs[3:5])
451 call assert_equal([attrs[6]] + repeat([attrs[7]], 3), attrs[6:9])
452 call assert_equal(attrs0[0], attrs[0])
453 call assert_notequal(attrs[0], attrs[2])
454 call assert_notequal(attrs[2], attrs[3])
455 call assert_notequal(attrs[3], attrs[6])
456 call assert_notequal(attrs[6], attrs[7])
457 call assert_notequal(attrs0[2], attrs[2])
458 call assert_notequal(attrs0[3], attrs[3])
459 call assert_notequal(attrs0[6], attrs[6])
Bram Moolenaar5ece3e32017-10-01 14:35:02 +0200460 call Check_lcs_eol_attrs(attrs, 2, 10)
Bram Moolenaar0aa398f2017-09-30 21:23:55 +0200461
462 if IsColorable()
463 " bg-color
464 exe hi_bg
465
466 " expected:
467 " ' >bcd '
468 " ^^^ breakindent and showbreak
469 " ^^^ bg-color of 'CursorLine'
470 " ^ 'Search' highlight
471 " ^^^ bg-color of 'CursorLine'
472 let attrs = ScreenAttrs(2, 10)[0]
473 call assert_equal(repeat([attrs[0]], 2), attrs[0:1])
474 call assert_equal(repeat([attrs[3]], 3), attrs[3:5])
475 call assert_equal(repeat([attrs[7]], 3), attrs[7:9])
476 call assert_equal(attrs0[0], attrs[0])
477 call assert_equal(attrs0[6], attrs[6])
478 call assert_notequal(attrs[0], attrs[2])
479 call assert_notequal(attrs[2], attrs[3])
480 call assert_notequal(attrs[3], attrs[6])
481 call assert_notequal(attrs[6], attrs[7])
482 call assert_notequal(attrs0[2], attrs[2])
483 call assert_notequal(attrs0[3], attrs[3])
484 call assert_notequal(attrs0[7], attrs[7])
Bram Moolenaar5ece3e32017-10-01 14:35:02 +0200485 call Check_lcs_eol_attrs(attrs, 2, 10)
Bram Moolenaar0aa398f2017-09-30 21:23:55 +0200486 endif
487
488 call CloseWindow()
489 set showbreak=
Bram Moolenaaree857022019-11-09 23:26:40 +0100490 setlocal showbreak=
Bram Moolenaar0aa398f2017-09-30 21:23:55 +0200491 exe hiCursorLine
492endfunc
493
494func Test_highlight_eol_on_diff()
495 call setline(1, ['abcd', ''])
496 call matchadd('Search', '\n')
497 let attrs0 = ScreenAttrs(1, 10)[0]
498
499 diffthis
500 botright new
501 diffthis
502
503 " expected:
504 " ' abcd '
505 " ^^ sign
506 " ^^^^ ^^^ 'DiffAdd' highlight
507 " ^ 'Search' highlight
508 let attrs = ScreenAttrs(1, 10)[0]
509 call assert_equal(repeat([attrs[0]], 2), attrs[0:1])
510 call assert_equal(repeat([attrs[2]], 4), attrs[2:5])
511 call assert_equal(repeat([attrs[2]], 3), attrs[7:9])
512 call assert_equal(attrs0[4], attrs[6])
513 call assert_notequal(attrs[0], attrs[2])
514 call assert_notequal(attrs[0], attrs[6])
515 call assert_notequal(attrs[2], attrs[6])
Bram Moolenaar5ece3e32017-10-01 14:35:02 +0200516 call Check_lcs_eol_attrs(attrs, 1, 10)
Bram Moolenaar0aa398f2017-09-30 21:23:55 +0200517
518 bwipe!
519 diffoff
520endfunc
Bram Moolenaarf708ac52018-03-12 21:48:32 +0100521
522func Test_termguicolors()
Bram Moolenaar6d91bcb2020-08-12 18:50:36 +0200523 CheckOption termguicolors
Bram Moolenaar310c32e2019-11-29 23:15:25 +0100524 if has('vtp') && !has('vcon') && !has('gui_running')
Bram Moolenaarff1e8792018-03-12 22:16:37 +0100525 " Win32: 'guicolors' doesn't work without virtual console.
526 call assert_fails('set termguicolors', 'E954:')
527 return
528 endif
Bram Moolenaarf708ac52018-03-12 21:48:32 +0100529
530 " Basic test that setting 'termguicolors' works with one color.
531 set termguicolors
532 redraw
533 set t_Co=1
534 redraw
535 set t_Co=0
536 redraw
537endfunc
Bram Moolenaarc07ff5c2019-01-30 21:41:14 +0100538
539func Test_cursorline_after_yank()
Bram Moolenaar8c5a2782019-08-07 23:07:07 +0200540 CheckScreendump
Bram Moolenaarc07ff5c2019-01-30 21:41:14 +0100541
542 call writefile([
543 \ 'set cul rnu',
544 \ 'call setline(1, ["","1","2","3",""])',
Bram Moolenaar572a4432022-09-28 21:07:03 +0100545 \ ], 'Xtest_cursorline_yank', 'D')
Bram Moolenaarc07ff5c2019-01-30 21:41:14 +0100546 let buf = RunVimInTerminal('-S Xtest_cursorline_yank', {'rows': 8})
Bram Moolenaar6a2c5a72020-04-08 21:50:25 +0200547 call TermWait(buf)
Bram Moolenaarc07ff5c2019-01-30 21:41:14 +0100548 call term_sendkeys(buf, "Gy3k")
Bram Moolenaar6a2c5a72020-04-08 21:50:25 +0200549 call TermWait(buf)
Bram Moolenaarc07ff5c2019-01-30 21:41:14 +0100550 call term_sendkeys(buf, "jj")
551
552 call VerifyScreenDump(buf, 'Test_cursorline_yank_01', {})
553
554 " clean up
555 call StopVimInTerminal(buf)
Bram Moolenaarc07ff5c2019-01-30 21:41:14 +0100556endfunc
Bram Moolenaar8156ed32019-03-09 11:46:15 +0100557
zeertzjq7ce34c92024-02-08 11:34:55 +0100558" Test for issue #4862: pasting above 'cursorline' redraws properly.
Bram Moolenaarfca068b2019-09-08 14:07:47 +0200559func Test_put_before_cursorline()
560 new
561 only!
zeertzjq7ce34c92024-02-08 11:34:55 +0100562 call setline(1, ['A', 'B', 'C'])
563 call cursor(2, 1)
Bram Moolenaarfca068b2019-09-08 14:07:47 +0200564 redraw
zeertzjq7ce34c92024-02-08 11:34:55 +0100565 let std_attr = screenattr(2, 1)
Bram Moolenaarfca068b2019-09-08 14:07:47 +0200566 set cursorline
567 redraw
zeertzjq7ce34c92024-02-08 11:34:55 +0100568 let cul_attr = screenattr(2, 1)
Bram Moolenaarfca068b2019-09-08 14:07:47 +0200569 normal yyP
570 redraw
zeertzjq7ce34c92024-02-08 11:34:55 +0100571 " Line 2 has cursor so it should be highlighted with CursorLine.
572 call assert_equal(cul_attr, screenattr(2, 1))
573 " And CursorLine highlighting from line 3 should be gone.
574 call assert_equal(std_attr, screenattr(3, 1))
Bram Moolenaarfca068b2019-09-08 14:07:47 +0200575 set nocursorline
576 bwipe!
577endfunc
578
Bram Moolenaar8156ed32019-03-09 11:46:15 +0100579func Test_cursorline_with_visualmode()
Bram Moolenaar8c5a2782019-08-07 23:07:07 +0200580 CheckScreendump
Bram Moolenaar8156ed32019-03-09 11:46:15 +0100581
582 call writefile([
583 \ 'set cul',
584 \ 'call setline(1, repeat(["abc"], 50))',
Bram Moolenaar572a4432022-09-28 21:07:03 +0100585 \ ], 'Xtest_cursorline_with_visualmode', 'D')
Bram Moolenaar8156ed32019-03-09 11:46:15 +0100586 let buf = RunVimInTerminal('-S Xtest_cursorline_with_visualmode', {'rows': 12})
Bram Moolenaar6a2c5a72020-04-08 21:50:25 +0200587 call TermWait(buf)
Bram Moolenaar8156ed32019-03-09 11:46:15 +0100588 call term_sendkeys(buf, "V\<C-f>kkkjk")
589
590 call VerifyScreenDump(buf, 'Test_cursorline_with_visualmode_01', {})
591
592 " clean up
593 call StopVimInTerminal(buf)
Bram Moolenaar8156ed32019-03-09 11:46:15 +0100594endfunc
Bram Moolenaarf90b6e02019-05-09 19:26:38 +0200595
Bram Moolenaar782c6742022-04-01 12:06:31 +0100596func Test_cursorcolumn_insert_on_tab()
597 CheckScreendump
598
599 let lines =<< trim END
600 call setline(1, ['123456789', "a\tb"])
601 set cursorcolumn
602 call cursor(2, 2)
603 END
Bram Moolenaar572a4432022-09-28 21:07:03 +0100604 call writefile(lines, 'Xcuc_insert_on_tab', 'D')
Bram Moolenaar782c6742022-04-01 12:06:31 +0100605
606 let buf = RunVimInTerminal('-S Xcuc_insert_on_tab', #{rows: 8})
607 call TermWait(buf)
608 call VerifyScreenDump(buf, 'Test_cursorcolumn_insert_on_tab_1', {})
609
610 call term_sendkeys(buf, 'i')
611 call TermWait(buf)
612 call VerifyScreenDump(buf, 'Test_cursorcolumn_insert_on_tab_2', {})
613
zeertzjq8c979602022-04-07 15:08:01 +0100614 call term_sendkeys(buf, "\<C-O>")
615 call TermWait(buf)
616 call VerifyScreenDump(buf, 'Test_cursorcolumn_insert_on_tab_3', {})
617
618 call term_sendkeys(buf, 'i')
619 call TermWait(buf)
620 call VerifyScreenDump(buf, 'Test_cursorcolumn_insert_on_tab_2', {})
621
Bram Moolenaar782c6742022-04-01 12:06:31 +0100622 call StopVimInTerminal(buf)
Bram Moolenaar782c6742022-04-01 12:06:31 +0100623endfunc
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
Bram Moolenaar572a4432022-09-28 21:07:03 +0100640 call writefile(lines, 'Xcuc_timer', 'D')
zeertzjq3e559cd2022-03-27 19:26:55 +0100641
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)
zeertzjq3e559cd2022-03-27 19:26:55 +0100647endfunc
648
Bram Moolenaar193ffd12019-05-25 22:57:30 +0200649func Test_wincolor()
Bram Moolenaar8c5a2782019-08-07 23:07:07 +0200650 CheckScreendump
Bram Moolenaar3180fe62020-02-02 13:47:06 +0100651 " make sure the width is enough for the test
652 set columns=80
Bram Moolenaar193ffd12019-05-25 22:57:30 +0200653
Bram Moolenaare7eb9272019-06-24 00:58:07 +0200654 let lines =<< trim END
655 set cursorline cursorcolumn rnu
Bram Moolenaar053f7122019-09-23 22:17:15 +0200656 call setline(1, ["","1111111111","22222222222","3 here 3","","the cat is out of the bag"])
Bram Moolenaare7eb9272019-06-24 00:58:07 +0200657 set wincolor=Pmenu
Bram Moolenaar053f7122019-09-23 22:17:15 +0200658 hi CatLine guifg=green ctermfg=green
659 hi Reverse gui=reverse cterm=reverse
660 syn match CatLine /^the.*/
661 call prop_type_add("foo", {"highlight": "Reverse", "combine": 1})
662 call prop_add(6, 12, {"type": "foo", "end_col": 15})
Bram Moolenaare7eb9272019-06-24 00:58:07 +0200663 /here
664 END
Bram Moolenaar572a4432022-09-28 21:07:03 +0100665 call writefile(lines, 'Xtest_wincolor', 'D')
Bram Moolenaar193ffd12019-05-25 22:57:30 +0200666 let buf = RunVimInTerminal('-S Xtest_wincolor', {'rows': 8})
Bram Moolenaar6a2c5a72020-04-08 21:50:25 +0200667 call TermWait(buf)
Bram Moolenaar193ffd12019-05-25 22:57:30 +0200668 call term_sendkeys(buf, "2G5lvj")
Bram Moolenaar6a2c5a72020-04-08 21:50:25 +0200669 call TermWait(buf)
Bram Moolenaar193ffd12019-05-25 22:57:30 +0200670
671 call VerifyScreenDump(buf, 'Test_wincolor_01', {})
672
673 " clean up
674 call term_sendkeys(buf, "\<Esc>")
675 call StopVimInTerminal(buf)
Bram Moolenaar193ffd12019-05-25 22:57:30 +0200676endfunc
677
Bram Moolenaar42e931b2019-12-04 19:08:50 +0100678func Test_wincolor_listchars()
679 CheckScreendump
Bram Moolenaar705724e2020-01-31 21:13:42 +0100680 CheckFeature conceal
Bram Moolenaar42e931b2019-12-04 19:08:50 +0100681
682 let lines =<< trim END
683 call setline(1, ["one","\t\tsome random text enough long to show 'extends' and 'precedes' includingnbsps, preceding tabs and trailing spaces ","three"])
684 set wincolor=Todo
685 set nowrap cole=1 cocu+=n
686 set list lcs=eol:$,tab:>-,space:.,trail:_,extends:>,precedes:<,conceal:*,nbsp:#
687 call matchadd('Conceal', 'text')
688 normal 2G5zl
689 END
Bram Moolenaar572a4432022-09-28 21:07:03 +0100690 call writefile(lines, 'Xtest_wincolorlcs', 'D')
Bram Moolenaar42e931b2019-12-04 19:08:50 +0100691 let buf = RunVimInTerminal('-S Xtest_wincolorlcs', {'rows': 8})
692
693 call VerifyScreenDump(buf, 'Test_wincolor_lcs', {})
694
695 " clean up
696 call term_sendkeys(buf, "\<Esc>")
697 call StopVimInTerminal(buf)
Bram Moolenaar42e931b2019-12-04 19:08:50 +0100698endfunc
699
Bram Moolenaar010ee962019-09-25 20:37:36 +0200700func Test_colorcolumn()
701 CheckScreendump
702
703 " check that setting 'colorcolumn' when entering a buffer works
704 let lines =<< trim END
705 split
706 edit X
707 call setline(1, ["1111111111","22222222222","3333333333"])
708 set nomodified
709 set colorcolumn=3,9
710 set number cursorline cursorlineopt=number
711 wincmd w
712 buf X
713 END
Bram Moolenaar572a4432022-09-28 21:07:03 +0100714 call writefile(lines, 'Xtest_colorcolumn', 'D')
Bram Moolenaar010ee962019-09-25 20:37:36 +0200715 let buf = RunVimInTerminal('-S Xtest_colorcolumn', {'rows': 10})
716 call term_sendkeys(buf, ":\<CR>")
Bram Moolenaar010ee962019-09-25 20:37:36 +0200717 call VerifyScreenDump(buf, 'Test_colorcolumn_1', {})
718
719 " clean up
720 call StopVimInTerminal(buf)
Bram Moolenaar010ee962019-09-25 20:37:36 +0200721endfunc
722
Bram Moolenaarad5e5632020-09-15 20:52:26 +0200723func Test_colorcolumn_bri()
724 CheckScreendump
725
726 " check 'colorcolumn' when 'breakindent' is set
727 let lines =<< trim END
728 call setline(1, 'The quick brown fox jumped over the lazy dogs')
729 END
Bram Moolenaar572a4432022-09-28 21:07:03 +0100730 call writefile(lines, 'Xtest_colorcolumn_bri', 'D')
Bram Moolenaarad5e5632020-09-15 20:52:26 +0200731 let buf = RunVimInTerminal('-S Xtest_colorcolumn_bri', {'rows': 10,'columns': 40})
732 call term_sendkeys(buf, ":set co=40 linebreak bri briopt=shift:2 cc=40,41,43\<CR>")
Bram Moolenaarad5e5632020-09-15 20:52:26 +0200733 call VerifyScreenDump(buf, 'Test_colorcolumn_2', {})
734
735 " clean up
736 call StopVimInTerminal(buf)
Bram Moolenaarad5e5632020-09-15 20:52:26 +0200737endfunc
738
739func Test_colorcolumn_sbr()
740 CheckScreendump
741
742 " check 'colorcolumn' when 'showbreak' is set
743 let lines =<< trim END
744 call setline(1, 'The quick brown fox jumped over the lazy dogs')
745 END
zeertzjqfc305842023-08-19 13:27:03 +0200746 call writefile(lines, 'Xtest_colorcolumn_sbr', 'D')
747 let buf = RunVimInTerminal('-S Xtest_colorcolumn_sbr', {'rows': 10,'columns': 40})
Bram Moolenaarad5e5632020-09-15 20:52:26 +0200748 call term_sendkeys(buf, ":set co=40 showbreak=+++>\\ cc=40,41,43\<CR>")
Bram Moolenaarad5e5632020-09-15 20:52:26 +0200749 call VerifyScreenDump(buf, 'Test_colorcolumn_3', {})
750
751 " clean up
752 call StopVimInTerminal(buf)
Bram Moolenaarad5e5632020-09-15 20:52:26 +0200753endfunc
754
Bram Moolenaarf578ca22023-06-10 19:40:30 +0100755func Test_visual_sbr()
756 CheckScreendump
757
758 " check Visual highlight when 'showbreak' is set
759 let lines =<< trim END
760 set showbreak=>
761 call setline(1, 'Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet.')
762 exe "normal! z1\<CR>"
763 END
764 call writefile(lines, 'Xtest_visual_sbr', 'D')
765 let buf = RunVimInTerminal('-S Xtest_visual_sbr', {'rows': 6,'columns': 60})
766
767 call term_sendkeys(buf, "v$")
768 call VerifyScreenDump(buf, 'Test_visual_sbr_1', {})
769
770 " clean up
771 call term_sendkeys(buf, "\<Esc>")
772 call StopVimInTerminal(buf)
773endfunc
774
Bram Moolenaar6b528fa2019-05-09 20:07:33 +0200775" This test must come before the Test_cursorline test, as it appears this
776" defines the Normal highlighting group anyway.
Bram Moolenaarf90b6e02019-05-09 19:26:38 +0200777func Test_1_highlight_Normalgroup_exists()
Bram Moolenaar435f9f02019-07-03 21:40:16 +0200778 let hlNormal = HighlightArgs('Normal')
779 if !has('gui_running')
Bram Moolenaar6b528fa2019-05-09 20:07:33 +0200780 call assert_match('hi Normal\s*clear', hlNormal)
Bram Moolenaar435f9f02019-07-03 21:40:16 +0200781 elseif has('gui_gtk2') || has('gui_gnome') || has('gui_gtk3')
matveytad3b6a32024-12-08 10:26:51 +0100782 " expect is DEFAULT_FONT of gui_gtk_x11.c (any size)
783 call assert_match('hi Normal\s*font=Monospace\>', hlNormal)
Bram Moolenaar0b962e52022-04-03 18:02:37 +0100784 elseif has('gui_motif')
Bram Moolenaar435f9f02019-07-03 21:40:16 +0200785 " expect is DEFAULT_FONT of gui_x11.c
786 call assert_match('hi Normal\s*font=7x13', hlNormal)
787 elseif has('win32')
788 " expect any font
789 call assert_match('hi Normal\s*font=.*', hlNormal)
Bram Moolenaar6b528fa2019-05-09 20:07:33 +0200790 endif
Bram Moolenaarf90b6e02019-05-09 19:26:38 +0200791endfunc
Bram Moolenaar548be7f2019-06-29 03:42:42 +0200792
Bram Moolenaar3180fe62020-02-02 13:47:06 +0100793" Do this test last, sometimes restoring the columns doesn't work
Bram Moolenaaree4e0c12020-04-06 21:35:05 +0200794func Test_z_no_space_before_xxx()
Bram Moolenaar548be7f2019-06-29 03:42:42 +0200795 let l:org_columns = &columns
796 set columns=17
797 let l:hi_StatusLineTermNC = join(split(execute('hi StatusLineTermNC')))
798 call assert_match('StatusLineTermNC xxx', l:hi_StatusLineTermNC)
799 let &columns = l:org_columns
Bram Moolenaaree4e0c12020-04-06 21:35:05 +0200800endfunc
801
802" Test for :highlight command errors
803func Test_highlight_cmd_errors()
804 if has('gui_running')
805 " This test doesn't fail in the MS-Windows console version.
Bram Moolenaar75e15672020-06-28 13:10:22 +0200806 call assert_fails('hi Xcomment ctermbg=fg', 'E419:')
Bram Moolenaaree4e0c12020-04-06 21:35:05 +0200807 call assert_fails('hi Xcomment ctermfg=bg', 'E420:')
Bram Moolenaar75e15672020-06-28 13:10:22 +0200808 call assert_fails('hi Xcomment ctermfg=ul', 'E453:')
erw7f7f7aaf2021-12-07 21:29:20 +0000809 call assert_fails('hi ' .. repeat('a', 201) .. ' ctermfg=black', 'E1249:')
Bram Moolenaaree4e0c12020-04-06 21:35:05 +0200810 endif
811
812 " Try using a very long terminal code. Define a dummy terminal code for this
813 " test.
814 let &t_fo = "\<Esc>1;"
815 let c = repeat("t_fo,", 100) . "t_fo"
816 call assert_fails('exe "hi Xgroup1 start=" . c', 'E422:')
817 let &t_fo = ""
818endfunc
819
Bram Moolenaar75e15672020-06-28 13:10:22 +0200820" Test for 'highlight' option
821func Test_highlight_opt()
822 let save_hl = &highlight
823 call assert_fails('set highlight=j:b', 'E474:')
824 set highlight=f\ r
825 call assert_equal('f r', &highlight)
826 set highlight=fb
827 call assert_equal('fb', &highlight)
828 set highlight=fi
829 call assert_equal('fi', &highlight)
830 set highlight=f-
831 call assert_equal('f-', &highlight)
832 set highlight=fr
833 call assert_equal('fr', &highlight)
834 set highlight=fs
835 call assert_equal('fs', &highlight)
836 set highlight=fu
837 call assert_equal('fu', &highlight)
838 set highlight=fc
839 call assert_equal('fc', &highlight)
840 set highlight=ft
841 call assert_equal('ft', &highlight)
842 call assert_fails('set highlight=fr:Search', 'E474:')
843 set highlight=f:$#
844 call assert_match('W18:', v:statusmsg)
845 let &highlight = save_hl
846endfunc
847
848" Test for User group highlighting used in the statusline
849func Test_highlight_User()
850 CheckNotGui
851 hi User1 ctermfg=12
852 redraw!
853 call assert_equal('12', synIDattr(synIDtrans(hlID('User1')), 'fg'))
854 hi clear
855endfunc
856
Shougo Matsushitabe2b03c2024-04-08 22:11:50 +0200857" Test for MsgArea highlighting
858func Test_highlight_MsgArea()
859 CheckNotGui
860 hi MsgArea ctermfg=20
861 redraw!
862 call assert_equal('20', synIDattr(synIDtrans(hlID('MsgArea')), 'fg'))
863 hi clear
864endfunc
865
Bram Moolenaar75e15672020-06-28 13:10:22 +0200866" Test for using RGB color values in a highlight group
Bram Moolenaar09fbedc2021-01-19 17:22:58 +0100867func Test_xxlast_highlight_RGB_color()
868 CheckCanRunGui
869 gui -f
Bram Moolenaar75e15672020-06-28 13:10:22 +0200870 hi MySearch guifg=#110000 guibg=#001100 guisp=#000011
871 call assert_equal('#110000', synIDattr(synIDtrans(hlID('MySearch')), 'fg#'))
872 call assert_equal('#001100', synIDattr(synIDtrans(hlID('MySearch')), 'bg#'))
873 call assert_equal('#000011', synIDattr(synIDtrans(hlID('MySearch')), 'sp#'))
874 hi clear
875endfunc
876
Bram Moolenaarde8f0f42020-06-30 18:45:43 +0200877" Test for using default highlighting group
878func Test_highlight_default()
879 highlight MySearch ctermfg=7
880 highlight default MySearch ctermfg=5
881 let hlSearch = HighlightArgs('MySearch')
882 call assert_match('ctermfg=7', hlSearch)
883
884 highlight default QFName ctermfg=3
885 call assert_match('ctermfg=3', HighlightArgs('QFName'))
886 hi clear
887endfunc
888
Christian Brabandtee17b6f2023-09-09 11:23:50 +0200889" Test for 'ctermul' in a highlight group
Bram Moolenaarde8f0f42020-06-30 18:45:43 +0200890func Test_highlight_ctermul()
891 CheckNotGui
892 call assert_notmatch('ctermul=', HighlightArgs('Normal'))
893 highlight Normal ctermul=3
894 call assert_match('ctermul=3', HighlightArgs('Normal'))
Bram Moolenaar391c3622020-09-29 20:59:17 +0200895 call assert_equal('3', synIDattr(synIDtrans(hlID('Normal')), 'ul'))
Bram Moolenaarde8f0f42020-06-30 18:45:43 +0200896 highlight Normal ctermul=NONE
897endfunc
898
PMuncha606f3a2023-11-15 15:35:49 +0100899" Test for 'ctermfont' in a highlight group
900func Test_highlight_ctermfont()
901 CheckNotGui
902 call assert_notmatch('ctermfont=', HighlightArgs('Normal'))
903 highlight Normal ctermfont=3
904 call assert_match('ctermfont=3', HighlightArgs('Normal'))
905 call assert_equal('3', synIDattr(synIDtrans(hlID('Normal')), 'font'))
906 highlight Normal ctermfont=NONE
907endfunc
908
Bram Moolenaarde8f0f42020-06-30 18:45:43 +0200909" Test for specifying 'start' and 'stop' in a highlight group
910func Test_highlight_start_stop()
911 hi HlGrp1 start=<Esc>[27h;<Esc>[<Space>r;
912 call assert_match("start=^[[27h;^[[ r;", HighlightArgs('HlGrp1'))
913 hi HlGrp1 start=NONE
914 call assert_notmatch("start=", HighlightArgs('HlGrp1'))
915 hi HlGrp2 stop=<Esc>[27h;<Esc>[<Space>r;
916 call assert_match("stop=^[[27h;^[[ r;", HighlightArgs('HlGrp2'))
917 hi HlGrp2 stop=NONE
918 call assert_notmatch("stop=", HighlightArgs('HlGrp2'))
Yegappan Lakshmanan5284b232023-03-04 19:57:32 +0000919 set t_xy=^[foo;
920 set t_xz=^[bar;
921 hi HlGrp3 start=t_xy stop=t_xz
922 let d = hlget('HlGrp3')
923 call assert_equal('^[foo;', d[0].start)
924 call assert_equal('^[bar;', d[0].stop)
925 set t_xy= t_xz=
Bram Moolenaarde8f0f42020-06-30 18:45:43 +0200926 hi clear
927endfunc
928
929" Test for setting various 'term' attributes
930func Test_highlight_term_attr()
Bram Moolenaar84f54632022-06-29 18:39:11 +0100931 hi HlGrp3 term=bold,underline,undercurl,underdouble,underdotted,underdashed,strikethrough,reverse,italic,standout
932 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 +0200933 hi HlGrp3 term=NONE
934 call assert_equal('hi HlGrp3 cleared', HighlightArgs('HlGrp3'))
935 hi clear
936endfunc
937
Bram Moolenaar213da552020-09-17 19:59:26 +0200938func Test_highlight_clear_restores_links()
939 let aaa_id = hlID('aaa')
940 call assert_equal(aaa_id, 0)
941
942 " create default link aaa --> bbb
943 hi def link aaa bbb
944 let id_aaa = hlID('aaa')
945 let hl_aaa_bbb = HighlightArgs('aaa')
946
947 " try to redefine default link aaa --> ccc; check aaa --> bbb
948 hi def link aaa ccc
949 call assert_equal(HighlightArgs('aaa'), hl_aaa_bbb)
950
951 " clear aaa; check aaa --> bbb
952 hi clear aaa
953 call assert_equal(HighlightArgs('aaa'), hl_aaa_bbb)
954
955 " link aaa --> ccc; clear aaa; check aaa --> bbb
956 hi link aaa ccc
957 let id_ccc = hlID('ccc')
958 call assert_equal(synIDtrans(id_aaa), id_ccc)
959 hi clear aaa
960 call assert_equal(HighlightArgs('aaa'), hl_aaa_bbb)
961
962 " forcibly set default link aaa --> ddd
963 hi! def link aaa ddd
964 let id_ddd = hlID('ddd')
965 let hl_aaa_ddd = HighlightArgs('aaa')
966 call assert_equal(synIDtrans(id_aaa), id_ddd)
967
968 " link aaa --> eee; clear aaa; check aaa --> ddd
969 hi link aaa eee
970 let eee_id = hlID('eee')
971 call assert_equal(synIDtrans(id_aaa), eee_id)
972 hi clear aaa
973 call assert_equal(HighlightArgs('aaa'), hl_aaa_ddd)
974endfunc
975
Bram Moolenaare8df0102020-09-18 19:40:45 +0200976func Test_highlight_clear_restores_context()
977 func FuncContextDefault()
978 hi def link Context ContextDefault
979 endfun
980
981 func FuncContextRelink()
982 " Dummy line
983 hi link Context ContextRelink
984 endfunc
985
986 let scriptContextDefault = MakeScript("FuncContextDefault")
987 let scriptContextRelink = MakeScript("FuncContextRelink")
988 let patContextDefault = fnamemodify(scriptContextDefault, ':t') .. ' line 1'
989 let patContextRelink = fnamemodify(scriptContextRelink, ':t') .. ' line 2'
990
Bram Moolenaar2bbada82020-09-18 21:55:26 +0200991 exec 'source ' .. scriptContextDefault
Bram Moolenaare8df0102020-09-18 19:40:45 +0200992 let hlContextDefault = execute("verbose hi Context")
993 call assert_match(patContextDefault, hlContextDefault)
994
Bram Moolenaar2bbada82020-09-18 21:55:26 +0200995 exec 'source ' .. scriptContextRelink
Bram Moolenaare8df0102020-09-18 19:40:45 +0200996 let hlContextRelink = execute("verbose hi Context")
997 call assert_match(patContextRelink, hlContextRelink)
998
999 hi clear
1000 let hlContextAfterClear = execute("verbose hi Context")
1001 call assert_match(patContextDefault, hlContextAfterClear)
1002
1003 delfunc FuncContextDefault
1004 delfunc FuncContextRelink
1005 call delete(scriptContextDefault)
1006 call delete(scriptContextRelink)
1007endfunc
1008
Bram Moolenaar213da552020-09-17 19:59:26 +02001009func Test_highlight_default_colorscheme_restores_links()
1010 hi link TestLink Identifier
1011 hi TestHi ctermbg=red
Bram Moolenaar05eb5b92020-09-16 15:43:21 +02001012
1013 let hlTestLinkPre = HighlightArgs('TestLink')
1014 let hlTestHiPre = HighlightArgs('TestHi')
1015
1016 " Test colorscheme
Dominique Pelle8bfa0eb2022-01-02 16:16:33 +00001017 call assert_equal("\ndefault", execute('colorscheme'))
Bram Moolenaar05eb5b92020-09-16 15:43:21 +02001018 hi clear
1019 if exists('syntax_on')
1020 syntax reset
1021 endif
1022 let g:colors_name = 'test'
Dominique Pelle8bfa0eb2022-01-02 16:16:33 +00001023 call assert_equal("\ntest", execute('colorscheme'))
Bram Moolenaar213da552020-09-17 19:59:26 +02001024 hi link TestLink ErrorMsg
1025 hi TestHi ctermbg=green
Bram Moolenaar05eb5b92020-09-16 15:43:21 +02001026
1027 " Restore default highlighting
1028 colorscheme default
Bram Moolenaar05eb5b92020-09-16 15:43:21 +02001029 " 'default' should work no matter if highlight group was cleared
Dominique Pelle8bfa0eb2022-01-02 16:16:33 +00001030 call assert_equal("\ndefault", execute('colorscheme'))
Bram Moolenaar05eb5b92020-09-16 15:43:21 +02001031 hi def link TestLink Identifier
1032 hi def TestHi ctermbg=red
Bram Moolenaar05eb5b92020-09-16 15:43:21 +02001033 let hlTestLinkPost = HighlightArgs('TestLink')
1034 let hlTestHiPost = HighlightArgs('TestHi')
Bram Moolenaar05eb5b92020-09-16 15:43:21 +02001035 call assert_equal(hlTestLinkPre, hlTestLinkPost)
1036 call assert_equal(hlTestHiPre, hlTestHiPost)
1037 hi clear
1038endfunc
1039
Drew Vogele30d1022021-10-24 20:35:07 +01001040func Test_colornames_assignment_and_lookup()
Drew Vogela0fca172021-11-13 10:50:01 +00001041 CheckAnyOf Feature:gui_running Feature:termguicolors
1042
Drew Vogele30d1022021-10-24 20:35:07 +01001043 " Ensure highlight command can find custom color.
1044 let v:colornames['a redish white'] = '#ffeedd'
1045 highlight Normal guifg='a redish white'
1046 highlight clear
Drew Vogela0fca172021-11-13 10:50:01 +00001047 call ClearDict(v:colornames)
Drew Vogele30d1022021-10-24 20:35:07 +01001048endfunc
1049
1050func Test_colornames_default_list()
Drew Vogela0fca172021-11-13 10:50:01 +00001051 CheckAnyOf Feature:gui_running Feature:termguicolors
1052
Drew Vogele30d1022021-10-24 20:35:07 +01001053 " Ensure default lists are loaded automatically and can be used for all gui fields.
Drew Vogela0fca172021-11-13 10:50:01 +00001054 call assert_equal(0, len(v:colornames))
Drew Vogele30d1022021-10-24 20:35:07 +01001055 highlight Normal guifg='rebecca purple' guibg='rebecca purple' guisp='rebecca purple'
Drew Vogela0fca172021-11-13 10:50:01 +00001056 call assert_notequal(0, len(v:colornames))
1057 echo v:colornames['rebecca purple']
Drew Vogele30d1022021-10-24 20:35:07 +01001058 highlight clear
Drew Vogela0fca172021-11-13 10:50:01 +00001059 call ClearDict(v:colornames)
Drew Vogele30d1022021-10-24 20:35:07 +01001060endfunc
1061
1062func Test_colornames_overwrite_default()
Drew Vogela0fca172021-11-13 10:50:01 +00001063 CheckAnyOf Feature:gui_running Feature:termguicolors
1064
Drew Vogele30d1022021-10-24 20:35:07 +01001065 " Ensure entries in v:colornames can be overwritten.
1066 " Load default color scheme to trigger default color list loading.
1067 colorscheme default
1068 let old_rebecca_purple = v:colornames['rebecca purple']
1069 highlight Normal guifg='rebecca purple' guibg='rebecca purple'
1070 let v:colornames['rebecca purple'] = '#550099'
1071 highlight Normal guifg='rebecca purple' guibg='rebecca purple'
1072 let v:colornames['rebecca purple'] = old_rebecca_purple
1073 highlight clear
1074endfunc
1075
1076func Test_colornames_assignment_and_unassignment()
Drew Vogela0fca172021-11-13 10:50:01 +00001077 " No feature check is needed for this test because the v:colornames dict
1078 " always exists with +eval. The feature checks are only required for
1079 " commands that do color lookup.
1080
Drew Vogele30d1022021-10-24 20:35:07 +01001081 " Ensure we cannot overwrite the v:colornames dict.
1082 call assert_fails("let v:colornames = {}", 'E46:')
1083
1084 " Ensure we can delete entries from the v:colornames dict.
1085 let v:colornames['x1'] = '#111111'
1086 call assert_equal(v:colornames['x1'], '#111111')
1087 unlet v:colornames['x1']
1088 call assert_fails("echo v:colornames['x1']")
1089endfunc
1090
Yegappan Lakshmanand1a8d652021-11-03 21:56:45 +00001091" Test for the hlget() function
1092func Test_hlget()
1093 let lines =<< trim END
1094 call assert_notequal([], filter(hlget(), 'v:val.name == "Visual"'))
1095 call assert_equal([], hlget('SomeHLGroup'))
1096 highlight MyHLGroup term=standout cterm=reverse ctermfg=10 ctermbg=Black
1097 call assert_equal([{'id': hlID('MyHLGroup'), 'ctermfg': '10', 'name': 'MyHLGroup', 'term': {'standout': v:true}, 'ctermbg': '0', 'cterm': {'reverse': v:true}}], hlget('MyHLGroup'))
1098 highlight clear MyHLGroup
1099 call assert_equal(v:true, hlget('MyHLGroup')[0].cleared)
1100 highlight link MyHLGroup IncSearch
1101 call assert_equal('IncSearch', hlget('MyHLGroup')[0].linksto)
1102 highlight clear MyHLGroup
1103 call assert_equal([], hlget(test_null_string()))
1104 call assert_equal([], hlget(""))
1105 END
Bram Moolenaar62aec932022-01-29 21:45:34 +00001106 call v9.CheckLegacyAndVim9Success(lines)
Yegappan Lakshmanand1a8d652021-11-03 21:56:45 +00001107
1108 " Test for resolving highlight group links
1109 let lines =<< trim END
1110 highlight hlgA term=bold
1111 VAR hlgAid = hlID('hlgA')
1112 highlight link hlgB hlgA
1113 VAR hlgBid = hlID('hlgB')
1114 highlight link hlgC hlgB
1115 VAR hlgCid = hlID('hlgC')
1116 call assert_equal('hlgA', hlget('hlgB')[0].linksto)
1117 call assert_equal('hlgB', hlget('hlgC')[0].linksto)
1118 call assert_equal([{'id': hlgAid, 'name': 'hlgA',
1119 \ 'term': {'bold': v:true}}], hlget('hlgA'))
1120 call assert_equal([{'id': hlgBid, 'name': 'hlgB',
1121 \ 'linksto': 'hlgA'}], hlget('hlgB'))
1122 call assert_equal([{'id': hlgCid, 'name': 'hlgC',
1123 \ 'linksto': 'hlgB'}], hlget('hlgC'))
1124 call assert_equal([{'id': hlgAid, 'name': 'hlgA',
1125 \ 'term': {'bold': v:true}}], hlget('hlgA', v:false))
1126 call assert_equal([{'id': hlgBid, 'name': 'hlgB',
1127 \ 'linksto': 'hlgA'}], hlget('hlgB', 0))
1128 call assert_equal([{'id': hlgCid, 'name': 'hlgC',
1129 \ 'linksto': 'hlgB'}], hlget('hlgC', v:false))
1130 call assert_equal([{'id': hlgAid, 'name': 'hlgA',
1131 \ 'term': {'bold': v:true}}], hlget('hlgA', v:true))
1132 call assert_equal([{'id': hlgBid, 'name': 'hlgB',
1133 \ 'term': {'bold': v:true}}], hlget('hlgB', 1))
1134 call assert_equal([{'id': hlgCid, 'name': 'hlgC',
1135 \ 'term': {'bold': v:true}}], hlget('hlgC', v:true))
1136 END
Bram Moolenaar62aec932022-01-29 21:45:34 +00001137 call v9.CheckLegacyAndVim9Success(lines)
Yegappan Lakshmanand1a8d652021-11-03 21:56:45 +00001138
1139 call assert_fails('call hlget([])', 'E1174:')
1140 call assert_fails('call hlget("abc", "xyz")', 'E1212:')
1141endfunc
1142
1143" Test for the hlset() function
1144func Test_hlset()
Aliaksei Budaveic4eb1cb2025-06-08 15:52:42 +02001145 " FIXME: With GVim, _current_ test cases that are run before this one may
1146 " influence the result of calling "hlset(hlget())", depending on what
1147 " "&guifont" is set to. For example, introduce SetUp() as follows:
1148 "
1149 " if CanRunVimInTerminal() && has('gui_running') && has('gui_gtk')
1150 " def SetUp()
1151 " set guifont=Monospace\ 10
1152 " enddef
1153 " endif
1154 "
1155 " and see "E416: Missing equal sign: ... line 4" for this test case.
Yegappan Lakshmanand1a8d652021-11-03 21:56:45 +00001156 let lines =<< trim END
1157 call assert_equal(0, hlset(test_null_list()))
1158 call assert_equal(0, hlset([]))
1159 call assert_fails('call hlset(["Search"])', 'E715:')
1160 call hlset(hlget())
1161 call hlset([{'name': 'NewHLGroup', 'cterm': {'reverse': v:true}, 'ctermfg': '10'}])
1162 call assert_equal({'reverse': v:true}, hlget('NewHLGroup')[0].cterm)
1163 call hlset([{'name': 'NewHLGroup', 'cterm': {'bold': v:true}}])
1164 call assert_equal({'bold': v:true}, hlget('NewHLGroup')[0].cterm)
1165 call hlset([{'name': 'NewHLGroup', 'cleared': v:true}])
1166 call assert_equal(v:true, hlget('NewHLGroup')[0].cleared)
1167 call hlset([{'name': 'NewHLGroup', 'linksto': 'Search'}])
1168 call assert_false(has_key(hlget('NewHLGroup')[0], 'cleared'))
1169 call assert_equal('Search', hlget('NewHLGroup')[0].linksto)
1170 call assert_fails("call hlset([{'name': [], 'ctermfg': '10'}])", 'E928:')
1171 call assert_fails("call hlset([{'name': 'NewHLGroup', 'cleared': []}])",
1172 \ 'E745:')
1173 call assert_fails("call hlset([{'name': 'NewHLGroup', 'cterm': 'Blue'}])",
1174 \ 'E715:')
1175 call assert_fails("call hlset([{'name': 'NewHLGroup', 'ctermbg': []}])",
1176 \ 'E928:')
1177 call assert_fails("call hlset([{'name': 'NewHLGroup', 'ctermfg': []}])",
1178 \ 'E928:')
1179 call assert_fails("call hlset([{'name': 'NewHLGroup', 'ctermul': []}])",
1180 \ 'E928:')
1181 if has('gui')
1182 call assert_fails("call hlset([{'name': 'NewHLGroup', 'font': []}])",
1183 \ 'E928:')
1184 endif
1185 call assert_fails("call hlset([{'name': 'NewHLGroup', 'gui': 'Cyan'}])",
1186 \ 'E715:')
1187 call assert_fails("call hlset([{'name': 'NewHLGroup', 'guibg': []}])",
1188 \ 'E928:')
1189 call assert_fails("call hlset([{'name': 'NewHLGroup', 'guifg': []}])",
1190 \ 'E928:')
1191 call assert_fails("call hlset([{'name': 'NewHLGroup', 'guisp': []}])",
1192 \ 'E928:')
1193 call assert_fails("call hlset([{'name': 'NewHLGroup', 'linksto': []}])",
1194 \ 'E928:')
1195 call assert_fails("call hlset([{'name': 'NewHLGroup', 'start': []}])",
1196 \ 'E928:')
1197 call assert_fails("call hlset([{'name': 'NewHLGroup', 'stop': []}])",
1198 \ 'E928:')
1199 call assert_fails("call hlset([{'name': 'NewHLGroup', 'term': 'Cyan'}])",
1200 \ 'E715:')
1201 call assert_equal('Search', hlget('NewHLGroup')[0].linksto)
1202 highlight clear NewHLGroup
1203 END
Bram Moolenaar62aec932022-01-29 21:45:34 +00001204 call v9.CheckLegacyAndVim9Success(lines)
Yegappan Lakshmanand1a8d652021-11-03 21:56:45 +00001205
1206 " Test for clearing the 'term', 'cterm' and 'gui' attributes of a highlight
1207 " group.
1208 let lines =<< trim END
1209 highlight myhlg1 term=bold cterm=italic gui=standout
1210 VAR id = hlID('myhlg1')
1211 call hlset([{'name': 'myhlg1', 'term': {}}])
1212 call assert_equal([{'id': id, 'name': 'myhlg1',
1213 \ 'cterm': {'italic': v:true}, 'gui': {'standout': v:true}}],
1214 \ hlget('myhlg1'))
1215 call hlset([{'name': 'myhlg1', 'cterm': {}}])
1216 call assert_equal([{'id': id, 'name': 'myhlg1',
1217 \ 'gui': {'standout': v:true}}], hlget('myhlg1'))
1218 call hlset([{'name': 'myhlg1', 'gui': {}}])
1219 call assert_equal([{'id': id, 'name': 'myhlg1', 'cleared': v:true}],
1220 \ hlget('myhlg1'))
1221 highlight clear myhlg1
1222 END
Bram Moolenaar62aec932022-01-29 21:45:34 +00001223 call v9.CheckLegacyAndVim9Success(lines)
Yegappan Lakshmanand1a8d652021-11-03 21:56:45 +00001224
1225 " Test for setting all the 'term', 'cterm' and 'gui' attributes of a
1226 " highlight group
1227 let lines =<< trim END
Bram Moolenaar84f54632022-06-29 18:39:11 +01001228 VAR attr = {'bold': v:true, 'underline': v:true,
1229 \ 'undercurl': v:true, 'underdouble': v:true,
1230 \ 'underdotted': v:true, 'underdashed': v:true,
Yegappan Lakshmanand1a8d652021-11-03 21:56:45 +00001231 \ 'strikethrough': v:true, 'reverse': v:true, 'italic': v:true,
1232 \ 'standout': v:true, 'nocombine': v:true}
1233 call hlset([{'name': 'myhlg2', 'term': attr, 'cterm': attr, 'gui': attr}])
1234 VAR id2 = hlID('myhlg2')
Bram Moolenaar84f54632022-06-29 18:39:11 +01001235 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 +00001236 VAR output = execute('highlight myhlg2')
1237 LET output = output->split("\n")->join()->substitute('\s\+', ' ', 'g')
1238 call assert_equal(expected, output)
Yegappan Lakshmanand1a8d652021-11-03 21:56:45 +00001239 call assert_equal([{'id': id2, 'name': 'myhlg2', 'gui': attr,
1240 \ 'term': attr, 'cterm': attr}], hlget('myhlg2'))
1241 END
Bram Moolenaar62aec932022-01-29 21:45:34 +00001242 call v9.CheckLegacyAndVim9Success(lines)
Yegappan Lakshmanand1a8d652021-11-03 21:56:45 +00001243
1244 " Test for clearing some of the 'term', 'cterm' and 'gui' attributes of a
1245 " highlight group
1246 let lines =<< trim END
1247 VAR attr = {'bold': v:false, 'underline': v:true, 'strikethrough': v:true}
1248 call hlset([{'name': 'myhlg2', 'term': attr, 'cterm': attr, 'gui': attr}])
1249 VAR id2 = hlID('myhlg2')
Yegappan Lakshmanan2a16dc62021-11-16 17:19:30 +00001250 VAR expected = "myhlg2 xxx term=underline,strikethrough cterm=underline,strikethrough gui=underline,strikethrough"
1251 VAR output = execute('highlight myhlg2')
1252 LET output = output->split("\n")->join()->substitute('\s\+', ' ', 'g')
1253 call assert_equal(expected, output)
Yegappan Lakshmanand1a8d652021-11-03 21:56:45 +00001254 LET attr = {'underline': v:true, 'strikethrough': v:true}
1255 call assert_equal([{'id': id2, 'name': 'myhlg2', 'gui': attr,
1256 \ 'term': attr, 'cterm': attr}], hlget('myhlg2'))
1257 END
Bram Moolenaar62aec932022-01-29 21:45:34 +00001258 call v9.CheckLegacyAndVim9Success(lines)
Dominique Pelle6a950a62021-11-13 18:44:37 +00001259
Yegappan Lakshmanan2a16dc62021-11-16 17:19:30 +00001260 " Test for clearing the attributes and link of a highlight group
1261 let lines =<< trim END
1262 highlight myhlg3 ctermbg=green guibg=green
1263 highlight! default link myhlg3 ErrorMsg
1264 VAR id3 = hlID('myhlg3')
1265 call hlset([{'name': 'myhlg3', 'cleared': v:true, 'linksto': 'NONE'}])
1266 call assert_equal([{'id': id3, 'name': 'myhlg3', 'cleared': v:true}],
1267 \ hlget('myhlg3'))
1268 highlight clear hlg3
1269 END
Bram Moolenaar62aec932022-01-29 21:45:34 +00001270 call v9.CheckLegacyAndVim9Success(lines)
Yegappan Lakshmanan2a16dc62021-11-16 17:19:30 +00001271
1272 " Test for setting default attributes for a highlight group
1273 let lines =<< trim END
1274 call hlset([{'name': 'hlg4', 'ctermfg': '8'}])
1275 call hlset([{'name': 'hlg4', 'default': v:true, 'ctermfg': '9'}])
1276 VAR id4 = hlID('hlg4')
1277 call assert_equal([{'id': id4, 'name': 'hlg4', 'ctermfg': '8'}],
1278 \ hlget('hlg4'))
1279 highlight clear hlg4
1280
1281 call hlset([{'name': 'hlg5', 'default': v:true, 'ctermbg': '2'}])
1282 call hlset([{'name': 'hlg5', 'ctermbg': '4'}])
1283 VAR id5 = hlID('hlg5')
1284 call assert_equal([{'id': id5, 'name': 'hlg5', 'ctermbg': '4'}],
1285 \ hlget('hlg5'))
1286 highlight clear hlg5
1287
1288 call hlset([{'name': 'hlg6', 'linksto': 'Error'}])
1289 VAR id6 = hlID('hlg6')
1290 call hlset([{'name': 'hlg6', 'default': v:true, 'ctermbg': '2'}])
1291 call assert_equal([{'id': id6, 'name': 'hlg6', 'linksto': 'Error'}],
1292 \ hlget('hlg6'))
1293 highlight clear hlg6
1294 END
Bram Moolenaar62aec932022-01-29 21:45:34 +00001295 call v9.CheckLegacyAndVim9Success(lines)
Yegappan Lakshmanan2a16dc62021-11-16 17:19:30 +00001296
1297 " Test for setting default links for a highlight group
1298 let lines =<< trim END
1299 call hlset([{'name': 'hlg7', 'ctermfg': '5'}])
1300 call hlset([{'name': 'hlg7', 'default': v:true, 'linksto': 'Search'}])
1301 VAR id7 = hlID('hlg7')
1302 call assert_equal([{'id': id7, 'name': 'hlg7', 'ctermfg': '5'}],
1303 \ hlget('hlg7'))
1304 highlight clear hlg7
1305
1306 call hlset([{'name': 'hlg8', 'default': v:true, 'linksto': 'Search'}])
1307 VAR id8 = hlID('hlg8')
1308 call assert_equal([{'id': id8, 'name': 'hlg8', 'default': v:true,
1309 \ 'linksto': 'Search'}], hlget('hlg8'))
1310 call hlset([{'name': 'hlg8', 'ctermbg': '2'}])
1311 call assert_equal([{'id': id8, 'name': 'hlg8', 'ctermbg': '2'}],
1312 \ hlget('hlg8'))
1313 highlight clear hlg8
1314
1315 highlight default link hlg9 ErrorMsg
1316 VAR hlg_save = hlget('hlg9')
1317 LET hlg_save[0]['name'] = 'hlg9dup'
1318 call hlset(hlg_save)
1319 VAR id9 = hlID('hlg9dup')
1320 highlight clear hlg9dup
1321 call assert_equal([{'id': id9, 'name': 'hlg9dup', 'default': v:true,
1322 \ 'linksto': 'ErrorMsg'}], hlget('hlg9dup'))
1323 highlight clear hlg9
1324 END
Bram Moolenaar62aec932022-01-29 21:45:34 +00001325 call v9.CheckLegacyAndVim9Success(lines)
Yegappan Lakshmanan2a16dc62021-11-16 17:19:30 +00001326
1327 " Test for force creating a link to a highlight group
1328 let lines =<< trim END
1329 call hlset([{'name': 'hlg10', 'ctermfg': '8'}])
1330 call hlset([{'name': 'hlg10', 'linksto': 'Search'}])
1331 VAR id10 = hlID('hlg10')
1332 call assert_equal([{'id': id10, 'name': 'hlg10', 'ctermfg': '8'}],
1333 \ hlget('hlg10'))
1334 call hlset([{'name': 'hlg10', 'linksto': 'Search', 'force': v:true}])
1335 call assert_equal([{'id': id10, 'name': 'hlg10', 'ctermfg': '8',
1336 \ 'linksto': 'Search'}], hlget('hlg10'))
1337 highlight clear hlg10
1338 END
Bram Moolenaar62aec932022-01-29 21:45:34 +00001339 call v9.CheckLegacyAndVim9Success(lines)
Yegappan Lakshmananbb277fd2021-11-24 20:28:31 +00001340
1341 " Test for empty values of attributes
1342 call hlset([{'name': 'hlg11', 'cterm': {}}])
1343 call hlset([{'name': 'hlg11', 'ctermfg': ''}])
1344 call hlset([{'name': 'hlg11', 'ctermbg': ''}])
1345 call hlset([{'name': 'hlg11', 'ctermul': ''}])
PMuncha606f3a2023-11-15 15:35:49 +01001346 call hlset([{'name': 'hlg11', 'ctermfont': ''}])
Yegappan Lakshmananbb277fd2021-11-24 20:28:31 +00001347 call hlset([{'name': 'hlg11', 'font': ''}])
1348 call hlset([{'name': 'hlg11', 'gui': {}}])
1349 call hlset([{'name': 'hlg11', 'guifg': ''}])
1350 call hlset([{'name': 'hlg11', 'guibg': ''}])
1351 call hlset([{'name': 'hlg11', 'guisp': ''}])
1352 call hlset([{'name': 'hlg11', 'start': ''}])
1353 call hlset([{'name': 'hlg11', 'stop': ''}])
1354 call hlset([{'name': 'hlg11', 'term': {}}])
1355 call assert_true(hlget('hlg11')[0].cleared)
Yegappan Lakshmanand1a8d652021-11-03 21:56:45 +00001356endfunc
1357
Bram Moolenaaree4e0c12020-04-06 21:35:05 +02001358" vim: shiftwidth=2 sts=2 expandtab