blob: 8bd03e2da12aad646b9c1cfe73b893e5e5844742 [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 Moolenaar0aa398f2017-09-30 21:23:55 +02007
Bram Moolenaar75373f32017-08-07 22:02:30 +02008func Test_highlight()
9 " basic test if ":highlight" doesn't crash
10 highlight
11 hi Search
12
13 " test setting colors.
14 " test clearing one color and all doesn't generate error or warning
15 silent! hi NewGroup term=bold cterm=italic ctermfg=DarkBlue ctermbg=Grey gui= guifg=#00ff00 guibg=Cyan
16 silent! hi Group2 term= cterm=
17 hi Group3 term=underline cterm=bold
18
19 let res = split(execute("hi NewGroup"), "\n")[0]
20 " filter ctermfg and ctermbg, the numbers depend on the terminal
21 let res = substitute(res, 'ctermfg=\d*', 'ctermfg=2', '')
22 let res = substitute(res, 'ctermbg=\d*', 'ctermbg=3', '')
23 call assert_equal("NewGroup xxx term=bold cterm=italic ctermfg=2 ctermbg=3",
24 \ res)
25 call assert_equal("Group2 xxx cleared",
26 \ split(execute("hi Group2"), "\n")[0])
27 call assert_equal("Group3 xxx term=underline cterm=bold",
28 \ split(execute("hi Group3"), "\n")[0])
29
30 hi clear NewGroup
31 call assert_equal("NewGroup xxx cleared",
32 \ split(execute("hi NewGroup"), "\n")[0])
33 call assert_equal("Group2 xxx cleared",
34 \ split(execute("hi Group2"), "\n")[0])
35 hi Group2 NONE
36 call assert_equal("Group2 xxx cleared",
37 \ split(execute("hi Group2"), "\n")[0])
38 hi clear
39 call assert_equal("Group3 xxx cleared",
40 \ split(execute("hi Group3"), "\n")[0])
41 call assert_fails("hi Crash term='asdf", "E475:")
42endfunc
Bram Moolenaar0aa398f2017-09-30 21:23:55 +020043
Bram Moolenaar1e115362019-01-09 23:01:02 +010044func HighlightArgs(name)
Bram Moolenaar0aa398f2017-09-30 21:23:55 +020045 return 'hi ' . substitute(split(execute('hi ' . a:name), '\n')[0], '\<xxx\>', '', '')
Bram Moolenaar1e115362019-01-09 23:01:02 +010046endfunc
Bram Moolenaar0aa398f2017-09-30 21:23:55 +020047
Bram Moolenaar1e115362019-01-09 23:01:02 +010048func IsColorable()
Bram Moolenaar0aa398f2017-09-30 21:23:55 +020049 return has('gui_running') || str2nr(&t_Co) >= 8
Bram Moolenaar1e115362019-01-09 23:01:02 +010050endfunc
Bram Moolenaar0aa398f2017-09-30 21:23:55 +020051
Bram Moolenaar1e115362019-01-09 23:01:02 +010052func HiCursorLine()
Bram Moolenaar0aa398f2017-09-30 21:23:55 +020053 let hiCursorLine = HighlightArgs('CursorLine')
54 if has('gui_running')
55 let guibg = matchstr(hiCursorLine, 'guibg=\w\+')
56 let hi_ul = 'hi CursorLine gui=underline guibg=NONE'
57 let hi_bg = 'hi CursorLine gui=NONE ' . guibg
58 else
59 let hi_ul = 'hi CursorLine cterm=underline ctermbg=NONE'
60 let hi_bg = 'hi CursorLine cterm=NONE ctermbg=Gray'
61 endif
62 return [hiCursorLine, hi_ul, hi_bg]
Bram Moolenaar1e115362019-01-09 23:01:02 +010063endfunc
Bram Moolenaar0aa398f2017-09-30 21:23:55 +020064
Bram Moolenaar1e115362019-01-09 23:01:02 +010065func Check_lcs_eol_attrs(attrs, row, col)
Bram Moolenaar5ece3e32017-10-01 14:35:02 +020066 let save_lcs = &lcs
67 set list
68
69 call assert_equal(a:attrs, ScreenAttrs(a:row, a:col)[0])
70
71 set nolist
72 let &lcs = save_lcs
Bram Moolenaar1e115362019-01-09 23:01:02 +010073endfunc
Bram Moolenaar5ece3e32017-10-01 14:35:02 +020074
Bram Moolenaar0aa398f2017-09-30 21:23:55 +020075func Test_highlight_eol_with_cursorline()
76 let [hiCursorLine, hi_ul, hi_bg] = HiCursorLine()
77
78 call NewWindow('topleft 5', 20)
79 call setline(1, 'abcd')
80 call matchadd('Search', '\n')
81
82 " expected:
83 " 'abcd '
84 " ^^^^ ^^^^^ no highlight
85 " ^ 'Search' highlight
86 let attrs0 = ScreenAttrs(1, 10)[0]
87 call assert_equal(repeat([attrs0[0]], 4), attrs0[0:3])
88 call assert_equal(repeat([attrs0[0]], 5), attrs0[5:9])
89 call assert_notequal(attrs0[0], attrs0[4])
90
91 setlocal cursorline
92
93 " underline
94 exe hi_ul
95
96 " expected:
97 " 'abcd '
98 " ^^^^ underline
Bram Moolenaar5ece3e32017-10-01 14:35:02 +020099 " ^ 'Search' highlight with underline
100 " ^^^^^ underline
Bram Moolenaar0aa398f2017-09-30 21:23:55 +0200101 let attrs = ScreenAttrs(1, 10)[0]
102 call assert_equal(repeat([attrs[0]], 4), attrs[0:3])
103 call assert_equal([attrs[4]] + repeat([attrs[5]], 5), attrs[4:9])
104 call assert_notequal(attrs[0], attrs[4])
105 call assert_notequal(attrs[4], attrs[5])
106 call assert_notequal(attrs0[0], attrs[0])
107 call assert_notequal(attrs0[4], attrs[4])
Bram Moolenaar5ece3e32017-10-01 14:35:02 +0200108 call Check_lcs_eol_attrs(attrs, 1, 10)
Bram Moolenaar0aa398f2017-09-30 21:23:55 +0200109
110 if IsColorable()
111 " bg-color
112 exe hi_bg
113
114 " expected:
115 " 'abcd '
116 " ^^^^ bg-color of 'CursorLine'
117 " ^ 'Search' highlight
118 " ^^^^^ bg-color of 'CursorLine'
119 let attrs = ScreenAttrs(1, 10)[0]
120 call assert_equal(repeat([attrs[0]], 4), attrs[0:3])
121 call assert_equal(repeat([attrs[5]], 5), attrs[5:9])
122 call assert_equal(attrs0[4], attrs[4])
123 call assert_notequal(attrs[0], attrs[4])
124 call assert_notequal(attrs[4], attrs[5])
125 call assert_notequal(attrs0[0], attrs[0])
126 call assert_notequal(attrs0[5], attrs[5])
Bram Moolenaar5ece3e32017-10-01 14:35:02 +0200127 call Check_lcs_eol_attrs(attrs, 1, 10)
Bram Moolenaar0aa398f2017-09-30 21:23:55 +0200128 endif
129
130 call CloseWindow()
131 exe hiCursorLine
132endfunc
133
134func Test_highlight_eol_with_cursorline_vertsplit()
Bram Moolenaar0aa398f2017-09-30 21:23:55 +0200135 let [hiCursorLine, hi_ul, hi_bg] = HiCursorLine()
136
137 call NewWindow('topleft 5', 5)
138 call setline(1, 'abcd')
139 call matchadd('Search', '\n')
140
141 let expected = "abcd |abcd "
142 let actual = ScreenLines(1, 15)[0]
143 call assert_equal(expected, actual)
144
145 " expected:
146 " 'abcd |abcd '
147 " ^^^^ ^^^^^^^^^ no highlight
148 " ^ 'Search' highlight
149 " ^ 'VertSplit' highlight
150 let attrs0 = ScreenAttrs(1, 15)[0]
151 call assert_equal(repeat([attrs0[0]], 4), attrs0[0:3])
152 call assert_equal(repeat([attrs0[0]], 9), attrs0[6:14])
153 call assert_notequal(attrs0[0], attrs0[4])
154 call assert_notequal(attrs0[0], attrs0[5])
155 call assert_notequal(attrs0[4], attrs0[5])
156
157 setlocal cursorline
158
159 " expected:
160 " 'abcd |abcd '
161 " ^^^^ underline
162 " ^ 'Search' highlight with underline
163 " ^ 'VertSplit' highlight
164 " ^^^^^^^^^ no highlight
165
166 " underline
167 exe hi_ul
168
169 let actual = ScreenLines(1, 15)[0]
170 call assert_equal(expected, actual)
171
172 let attrs = ScreenAttrs(1, 15)[0]
173 call assert_equal(repeat([attrs[0]], 4), attrs[0:3])
174 call assert_equal(repeat([attrs[6]], 9), attrs[6:14])
175 call assert_equal(attrs0[5:14], attrs[5:14])
176 call assert_notequal(attrs[0], attrs[4])
177 call assert_notequal(attrs[0], attrs[5])
178 call assert_notequal(attrs[0], attrs[6])
179 call assert_notequal(attrs[4], attrs[5])
180 call assert_notequal(attrs[5], attrs[6])
181 call assert_notequal(attrs0[0], attrs[0])
182 call assert_notequal(attrs0[4], attrs[4])
Bram Moolenaar5ece3e32017-10-01 14:35:02 +0200183 call Check_lcs_eol_attrs(attrs, 1, 15)
Bram Moolenaar0aa398f2017-09-30 21:23:55 +0200184
185 if IsColorable()
186 " bg-color
187 exe hi_bg
188
189 let actual = ScreenLines(1, 15)[0]
190 call assert_equal(expected, actual)
191
192 let attrs = ScreenAttrs(1, 15)[0]
193 call assert_equal(repeat([attrs[0]], 4), attrs[0:3])
194 call assert_equal(repeat([attrs[6]], 9), attrs[6:14])
195 call assert_equal(attrs0[5:14], attrs[5:14])
196 call assert_notequal(attrs[0], attrs[4])
197 call assert_notequal(attrs[0], attrs[5])
198 call assert_notequal(attrs[0], attrs[6])
199 call assert_notequal(attrs[4], attrs[5])
200 call assert_notequal(attrs[5], attrs[6])
201 call assert_notequal(attrs0[0], attrs[0])
202 call assert_equal(attrs0[4], attrs[4])
Bram Moolenaar5ece3e32017-10-01 14:35:02 +0200203 call Check_lcs_eol_attrs(attrs, 1, 15)
Bram Moolenaar0aa398f2017-09-30 21:23:55 +0200204 endif
205
206 call CloseWindow()
207 exe hiCursorLine
208endfunc
209
210func Test_highlight_eol_with_cursorline_rightleft()
Bram Moolenaar6d91bcb2020-08-12 18:50:36 +0200211 CheckFeature rightleft
Bram Moolenaar0aa398f2017-09-30 21:23:55 +0200212
213 let [hiCursorLine, hi_ul, hi_bg] = HiCursorLine()
214
215 call NewWindow('topleft 5', 10)
216 setlocal rightleft
217 call setline(1, 'abcd')
218 call matchadd('Search', '\n')
219 let attrs0 = ScreenAttrs(1, 10)[0]
220
221 setlocal cursorline
222
223 " underline
224 exe hi_ul
225
226 " expected:
227 " ' dcba'
228 " ^^^^ underline
229 " ^ 'Search' highlight with underline
230 " ^^^^^ underline
231 let attrs = ScreenAttrs(1, 10)[0]
232 call assert_equal(repeat([attrs[9]], 4), attrs[6:9])
233 call assert_equal(repeat([attrs[4]], 5) + [attrs[5]], attrs[0:5])
234 call assert_notequal(attrs[9], attrs[5])
235 call assert_notequal(attrs[4], attrs[5])
236 call assert_notequal(attrs0[9], attrs[9])
237 call assert_notequal(attrs0[5], attrs[5])
Bram Moolenaar5ece3e32017-10-01 14:35:02 +0200238 call Check_lcs_eol_attrs(attrs, 1, 10)
Bram Moolenaar0aa398f2017-09-30 21:23:55 +0200239
240 if IsColorable()
241 " bg-color
242 exe hi_bg
243
244 " expected:
245 " ' dcba'
246 " ^^^^ bg-color of 'CursorLine'
247 " ^ 'Search' highlight
248 " ^^^^^ bg-color of 'CursorLine'
249 let attrs = ScreenAttrs(1, 10)[0]
250 call assert_equal(repeat([attrs[9]], 4), attrs[6:9])
251 call assert_equal(repeat([attrs[4]], 5), attrs[0:4])
252 call assert_equal(attrs0[5], attrs[5])
253 call assert_notequal(attrs[9], attrs[5])
254 call assert_notequal(attrs[5], attrs[4])
255 call assert_notequal(attrs0[9], attrs[9])
256 call assert_notequal(attrs0[4], attrs[4])
Bram Moolenaar5ece3e32017-10-01 14:35:02 +0200257 call Check_lcs_eol_attrs(attrs, 1, 10)
Bram Moolenaar0aa398f2017-09-30 21:23:55 +0200258 endif
259
260 call CloseWindow()
261 exe hiCursorLine
262endfunc
263
264func Test_highlight_eol_with_cursorline_linewrap()
265 let [hiCursorLine, hi_ul, hi_bg] = HiCursorLine()
266
267 call NewWindow('topleft 5', 10)
268 call setline(1, [repeat('a', 51) . 'bcd', ''])
269 call matchadd('Search', '\n')
270
271 setlocal wrap
272 normal! gg$
273 let attrs0 = ScreenAttrs(5, 10)[0]
274 setlocal cursorline
275
276 " underline
277 exe hi_ul
278
279 " expected:
280 " 'abcd '
281 " ^^^^ underline
282 " ^ 'Search' highlight with underline
283 " ^^^^^ underline
284 let attrs = ScreenAttrs(5, 10)[0]
285 call assert_equal(repeat([attrs[0]], 4), attrs[0:3])
286 call assert_equal([attrs[4]] + repeat([attrs[5]], 5), attrs[4:9])
287 call assert_notequal(attrs[0], attrs[4])
288 call assert_notequal(attrs[4], attrs[5])
289 call assert_notequal(attrs0[0], attrs[0])
290 call assert_notequal(attrs0[4], attrs[4])
Bram Moolenaar5ece3e32017-10-01 14:35:02 +0200291 call Check_lcs_eol_attrs(attrs, 5, 10)
Bram Moolenaar0aa398f2017-09-30 21:23:55 +0200292
293 if IsColorable()
294 " bg-color
295 exe hi_bg
296
297 " expected:
298 " 'abcd '
299 " ^^^^ bg-color of 'CursorLine'
300 " ^ 'Search' highlight
301 " ^^^^^ bg-color of 'CursorLine'
302 let attrs = ScreenAttrs(5, 10)[0]
303 call assert_equal(repeat([attrs[0]], 4), attrs[0:3])
304 call assert_equal(repeat([attrs[5]], 5), attrs[5:9])
305 call assert_equal(attrs0[4], attrs[4])
306 call assert_notequal(attrs[0], attrs[4])
307 call assert_notequal(attrs[4], attrs[5])
308 call assert_notequal(attrs0[0], attrs[0])
309 call assert_notequal(attrs0[5], attrs[5])
Bram Moolenaar5ece3e32017-10-01 14:35:02 +0200310 call Check_lcs_eol_attrs(attrs, 5, 10)
Bram Moolenaar0aa398f2017-09-30 21:23:55 +0200311 endif
312
313 setlocal nocursorline nowrap
314 normal! gg$
315 let attrs0 = ScreenAttrs(1, 10)[0]
316 setlocal cursorline
317
318 " underline
319 exe hi_ul
320
321 " expected:
322 " 'aaabcd '
323 " ^^^^^^ underline
324 " ^ 'Search' highlight with underline
325 " ^^^ underline
326 let attrs = ScreenAttrs(1, 10)[0]
327 call assert_equal(repeat([attrs[0]], 6), attrs[0:5])
328 call assert_equal([attrs[6]] + repeat([attrs[7]], 3), attrs[6:9])
329 call assert_notequal(attrs[0], attrs[6])
330 call assert_notequal(attrs[6], attrs[7])
331 call assert_notequal(attrs0[0], attrs[0])
332 call assert_notequal(attrs0[6], attrs[6])
Bram Moolenaar5ece3e32017-10-01 14:35:02 +0200333 call Check_lcs_eol_attrs(attrs, 1, 10)
Bram Moolenaar0aa398f2017-09-30 21:23:55 +0200334
335 if IsColorable()
336 " bg-color
337 exe hi_bg
338
339 " expected:
340 " 'aaabcd '
341 " ^^^^^^ bg-color of 'CursorLine'
342 " ^ 'Search' highlight
343 " ^^^ bg-color of 'CursorLine'
344 let attrs = ScreenAttrs(1, 10)[0]
345 call assert_equal(repeat([attrs[0]], 6), attrs[0:5])
346 call assert_equal(repeat([attrs[7]], 3), attrs[7:9])
347 call assert_equal(attrs0[6], attrs[6])
348 call assert_notequal(attrs[0], attrs[6])
349 call assert_notequal(attrs[6], attrs[7])
350 call assert_notequal(attrs0[0], attrs[0])
351 call assert_notequal(attrs0[7], attrs[7])
Bram Moolenaar5ece3e32017-10-01 14:35:02 +0200352 call Check_lcs_eol_attrs(attrs, 1, 10)
Bram Moolenaar0aa398f2017-09-30 21:23:55 +0200353 endif
354
355 call CloseWindow()
356 exe hiCursorLine
357endfunc
358
359func Test_highlight_eol_with_cursorline_sign()
Bram Moolenaar6d91bcb2020-08-12 18:50:36 +0200360 CheckFeature signs
Bram Moolenaar0aa398f2017-09-30 21:23:55 +0200361
362 let [hiCursorLine, hi_ul, hi_bg] = HiCursorLine()
363
364 call NewWindow('topleft 5', 10)
365 call setline(1, 'abcd')
366 call matchadd('Search', '\n')
367
368 sign define Sign text=>>
369 exe 'sign place 1 line=1 name=Sign buffer=' . bufnr('')
370 let attrs0 = ScreenAttrs(1, 10)[0]
371 setlocal cursorline
372
373 " underline
374 exe hi_ul
375
376 " expected:
377 " '>>abcd '
378 " ^^ sign
379 " ^^^^ underline
380 " ^ 'Search' highlight with underline
381 " ^^^ underline
382 let attrs = ScreenAttrs(1, 10)[0]
383 call assert_equal(repeat([attrs[2]], 4), attrs[2:5])
384 call assert_equal([attrs[6]] + repeat([attrs[7]], 3), attrs[6:9])
385 call assert_notequal(attrs[2], attrs[6])
386 call assert_notequal(attrs[6], attrs[7])
387 call assert_notequal(attrs0[2], attrs[2])
388 call assert_notequal(attrs0[6], attrs[6])
Bram Moolenaar5ece3e32017-10-01 14:35:02 +0200389 call Check_lcs_eol_attrs(attrs, 1, 10)
Bram Moolenaar0aa398f2017-09-30 21:23:55 +0200390
391 if IsColorable()
392 " bg-color
393 exe hi_bg
394
395 " expected:
396 " '>>abcd '
397 " ^^ sign
398 " ^^^^ bg-color of 'CursorLine'
399 " ^ 'Search' highlight
400 " ^^^ bg-color of 'CursorLine'
401 let attrs = ScreenAttrs(1, 10)[0]
402 call assert_equal(repeat([attrs[2]], 4), attrs[2:5])
403 call assert_equal(repeat([attrs[7]], 3), attrs[7:9])
404 call assert_equal(attrs0[6], attrs[6])
405 call assert_notequal(attrs[2], attrs[6])
406 call assert_notequal(attrs[6], attrs[7])
407 call assert_notequal(attrs0[2], attrs[2])
408 call assert_notequal(attrs0[7], attrs[7])
Bram Moolenaar5ece3e32017-10-01 14:35:02 +0200409 call Check_lcs_eol_attrs(attrs, 1, 10)
Bram Moolenaar0aa398f2017-09-30 21:23:55 +0200410 endif
411
412 sign unplace 1
413 call CloseWindow()
414 exe hiCursorLine
415endfunc
416
417func Test_highlight_eol_with_cursorline_breakindent()
Bram Moolenaar6d91bcb2020-08-12 18:50:36 +0200418 CheckFeature linebreak
Bram Moolenaar0aa398f2017-09-30 21:23:55 +0200419
420 let [hiCursorLine, hi_ul, hi_bg] = HiCursorLine()
421
422 call NewWindow('topleft 5', 10)
Bram Moolenaaree857022019-11-09 23:26:40 +0100423 set showbreak=xxx
Bram Moolenaar0aa398f2017-09-30 21:23:55 +0200424 setlocal breakindent breakindentopt=min:0,shift:1 showbreak=>
425 call setline(1, ' ' . repeat('a', 9) . 'bcd')
426 call matchadd('Search', '\n')
427 let attrs0 = ScreenAttrs(2, 10)[0]
428 setlocal cursorline
429
430 " underline
431 exe hi_ul
432
433 " expected:
434 " ' >bcd '
435 " ^^^ breakindent and showbreak
436 " ^^^ underline
437 " ^ 'Search' highlight with underline
438 " ^^^ underline
439 let attrs = ScreenAttrs(2, 10)[0]
440 call assert_equal(repeat([attrs[0]], 2), attrs[0:1])
441 call assert_equal(repeat([attrs[3]], 3), attrs[3:5])
442 call assert_equal([attrs[6]] + repeat([attrs[7]], 3), attrs[6:9])
443 call assert_equal(attrs0[0], attrs[0])
444 call assert_notequal(attrs[0], attrs[2])
445 call assert_notequal(attrs[2], attrs[3])
446 call assert_notequal(attrs[3], attrs[6])
447 call assert_notequal(attrs[6], attrs[7])
448 call assert_notequal(attrs0[2], attrs[2])
449 call assert_notequal(attrs0[3], attrs[3])
450 call assert_notequal(attrs0[6], attrs[6])
Bram Moolenaar5ece3e32017-10-01 14:35:02 +0200451 call Check_lcs_eol_attrs(attrs, 2, 10)
Bram Moolenaar0aa398f2017-09-30 21:23:55 +0200452
453 if IsColorable()
454 " bg-color
455 exe hi_bg
456
457 " expected:
458 " ' >bcd '
459 " ^^^ breakindent and showbreak
460 " ^^^ bg-color of 'CursorLine'
461 " ^ 'Search' highlight
462 " ^^^ bg-color of 'CursorLine'
463 let attrs = ScreenAttrs(2, 10)[0]
464 call assert_equal(repeat([attrs[0]], 2), attrs[0:1])
465 call assert_equal(repeat([attrs[3]], 3), attrs[3:5])
466 call assert_equal(repeat([attrs[7]], 3), attrs[7:9])
467 call assert_equal(attrs0[0], attrs[0])
468 call assert_equal(attrs0[6], attrs[6])
469 call assert_notequal(attrs[0], attrs[2])
470 call assert_notequal(attrs[2], attrs[3])
471 call assert_notequal(attrs[3], attrs[6])
472 call assert_notequal(attrs[6], attrs[7])
473 call assert_notequal(attrs0[2], attrs[2])
474 call assert_notequal(attrs0[3], attrs[3])
475 call assert_notequal(attrs0[7], attrs[7])
Bram Moolenaar5ece3e32017-10-01 14:35:02 +0200476 call Check_lcs_eol_attrs(attrs, 2, 10)
Bram Moolenaar0aa398f2017-09-30 21:23:55 +0200477 endif
478
479 call CloseWindow()
480 set showbreak=
Bram Moolenaaree857022019-11-09 23:26:40 +0100481 setlocal showbreak=
Bram Moolenaar0aa398f2017-09-30 21:23:55 +0200482 exe hiCursorLine
483endfunc
484
485func Test_highlight_eol_on_diff()
486 call setline(1, ['abcd', ''])
487 call matchadd('Search', '\n')
488 let attrs0 = ScreenAttrs(1, 10)[0]
489
490 diffthis
491 botright new
492 diffthis
493
494 " expected:
495 " ' abcd '
496 " ^^ sign
497 " ^^^^ ^^^ 'DiffAdd' highlight
498 " ^ 'Search' highlight
499 let attrs = ScreenAttrs(1, 10)[0]
500 call assert_equal(repeat([attrs[0]], 2), attrs[0:1])
501 call assert_equal(repeat([attrs[2]], 4), attrs[2:5])
502 call assert_equal(repeat([attrs[2]], 3), attrs[7:9])
503 call assert_equal(attrs0[4], attrs[6])
504 call assert_notequal(attrs[0], attrs[2])
505 call assert_notequal(attrs[0], attrs[6])
506 call assert_notequal(attrs[2], attrs[6])
Bram Moolenaar5ece3e32017-10-01 14:35:02 +0200507 call Check_lcs_eol_attrs(attrs, 1, 10)
Bram Moolenaar0aa398f2017-09-30 21:23:55 +0200508
509 bwipe!
510 diffoff
511endfunc
Bram Moolenaarf708ac52018-03-12 21:48:32 +0100512
513func Test_termguicolors()
Bram Moolenaar6d91bcb2020-08-12 18:50:36 +0200514 CheckOption termguicolors
Bram Moolenaar310c32e2019-11-29 23:15:25 +0100515 if has('vtp') && !has('vcon') && !has('gui_running')
Bram Moolenaarff1e8792018-03-12 22:16:37 +0100516 " Win32: 'guicolors' doesn't work without virtual console.
517 call assert_fails('set termguicolors', 'E954:')
518 return
519 endif
Bram Moolenaarf708ac52018-03-12 21:48:32 +0100520
521 " Basic test that setting 'termguicolors' works with one color.
522 set termguicolors
523 redraw
524 set t_Co=1
525 redraw
526 set t_Co=0
527 redraw
528endfunc
Bram Moolenaarc07ff5c2019-01-30 21:41:14 +0100529
530func Test_cursorline_after_yank()
Bram Moolenaar8c5a2782019-08-07 23:07:07 +0200531 CheckScreendump
Bram Moolenaarc07ff5c2019-01-30 21:41:14 +0100532
533 call writefile([
534 \ 'set cul rnu',
535 \ 'call setline(1, ["","1","2","3",""])',
536 \ ], 'Xtest_cursorline_yank')
537 let buf = RunVimInTerminal('-S Xtest_cursorline_yank', {'rows': 8})
Bram Moolenaar6a2c5a72020-04-08 21:50:25 +0200538 call TermWait(buf)
Bram Moolenaarc07ff5c2019-01-30 21:41:14 +0100539 call term_sendkeys(buf, "Gy3k")
Bram Moolenaar6a2c5a72020-04-08 21:50:25 +0200540 call TermWait(buf)
Bram Moolenaarc07ff5c2019-01-30 21:41:14 +0100541 call term_sendkeys(buf, "jj")
542
543 call VerifyScreenDump(buf, 'Test_cursorline_yank_01', {})
544
545 " clean up
546 call StopVimInTerminal(buf)
547 call delete('Xtest_cursorline_yank')
548endfunc
Bram Moolenaar8156ed32019-03-09 11:46:15 +0100549
Bram Moolenaarfca068b2019-09-08 14:07:47 +0200550" test for issue #4862
551func Test_put_before_cursorline()
552 new
553 only!
554 call setline(1, 'A')
555 redraw
556 let std_attr = screenattr(1, 1)
557 set cursorline
558 redraw
559 let cul_attr = screenattr(1, 1)
560 normal yyP
561 redraw
562 " Line 1 has cursor so it should be highlighted with CursorLine.
563 call assert_equal(cul_attr, screenattr(1, 1))
564 " And CursorLine highlighting from the second line should be gone.
565 call assert_equal(std_attr, screenattr(2, 1))
566 set nocursorline
567 bwipe!
568endfunc
569
Bram Moolenaar8156ed32019-03-09 11:46:15 +0100570func Test_cursorline_with_visualmode()
Bram Moolenaar8c5a2782019-08-07 23:07:07 +0200571 CheckScreendump
Bram Moolenaar8156ed32019-03-09 11:46:15 +0100572
573 call writefile([
574 \ 'set cul',
575 \ 'call setline(1, repeat(["abc"], 50))',
576 \ ], 'Xtest_cursorline_with_visualmode')
577 let buf = RunVimInTerminal('-S Xtest_cursorline_with_visualmode', {'rows': 12})
Bram Moolenaar6a2c5a72020-04-08 21:50:25 +0200578 call TermWait(buf)
Bram Moolenaar8156ed32019-03-09 11:46:15 +0100579 call term_sendkeys(buf, "V\<C-f>kkkjk")
580
581 call VerifyScreenDump(buf, 'Test_cursorline_with_visualmode_01', {})
582
583 " clean up
584 call StopVimInTerminal(buf)
585 call delete('Xtest_cursorline_with_visualmode')
586endfunc
Bram Moolenaarf90b6e02019-05-09 19:26:38 +0200587
Bram Moolenaar193ffd12019-05-25 22:57:30 +0200588func Test_wincolor()
Bram Moolenaar8c5a2782019-08-07 23:07:07 +0200589 CheckScreendump
Bram Moolenaar3180fe62020-02-02 13:47:06 +0100590 " make sure the width is enough for the test
591 set columns=80
Bram Moolenaar193ffd12019-05-25 22:57:30 +0200592
Bram Moolenaare7eb9272019-06-24 00:58:07 +0200593 let lines =<< trim END
594 set cursorline cursorcolumn rnu
Bram Moolenaar053f7122019-09-23 22:17:15 +0200595 call setline(1, ["","1111111111","22222222222","3 here 3","","the cat is out of the bag"])
Bram Moolenaare7eb9272019-06-24 00:58:07 +0200596 set wincolor=Pmenu
Bram Moolenaar053f7122019-09-23 22:17:15 +0200597 hi CatLine guifg=green ctermfg=green
598 hi Reverse gui=reverse cterm=reverse
599 syn match CatLine /^the.*/
600 call prop_type_add("foo", {"highlight": "Reverse", "combine": 1})
601 call prop_add(6, 12, {"type": "foo", "end_col": 15})
Bram Moolenaare7eb9272019-06-24 00:58:07 +0200602 /here
603 END
604 call writefile(lines, 'Xtest_wincolor')
Bram Moolenaar193ffd12019-05-25 22:57:30 +0200605 let buf = RunVimInTerminal('-S Xtest_wincolor', {'rows': 8})
Bram Moolenaar6a2c5a72020-04-08 21:50:25 +0200606 call TermWait(buf)
Bram Moolenaar193ffd12019-05-25 22:57:30 +0200607 call term_sendkeys(buf, "2G5lvj")
Bram Moolenaar6a2c5a72020-04-08 21:50:25 +0200608 call TermWait(buf)
Bram Moolenaar193ffd12019-05-25 22:57:30 +0200609
610 call VerifyScreenDump(buf, 'Test_wincolor_01', {})
611
612 " clean up
613 call term_sendkeys(buf, "\<Esc>")
614 call StopVimInTerminal(buf)
615 call delete('Xtest_wincolor')
616endfunc
617
Bram Moolenaar42e931b2019-12-04 19:08:50 +0100618func Test_wincolor_listchars()
619 CheckScreendump
Bram Moolenaar705724e2020-01-31 21:13:42 +0100620 CheckFeature conceal
Bram Moolenaar42e931b2019-12-04 19:08:50 +0100621
622 let lines =<< trim END
623 call setline(1, ["one","\t\tsome random text enough long to show 'extends' and 'precedes' includingnbsps, preceding tabs and trailing spaces ","three"])
624 set wincolor=Todo
625 set nowrap cole=1 cocu+=n
626 set list lcs=eol:$,tab:>-,space:.,trail:_,extends:>,precedes:<,conceal:*,nbsp:#
627 call matchadd('Conceal', 'text')
628 normal 2G5zl
629 END
630 call writefile(lines, 'Xtest_wincolorlcs')
631 let buf = RunVimInTerminal('-S Xtest_wincolorlcs', {'rows': 8})
632
633 call VerifyScreenDump(buf, 'Test_wincolor_lcs', {})
634
635 " clean up
636 call term_sendkeys(buf, "\<Esc>")
637 call StopVimInTerminal(buf)
638 call delete('Xtest_wincolorlcs')
639endfunc
640
Bram Moolenaar010ee962019-09-25 20:37:36 +0200641func Test_colorcolumn()
642 CheckScreendump
643
644 " check that setting 'colorcolumn' when entering a buffer works
645 let lines =<< trim END
646 split
647 edit X
648 call setline(1, ["1111111111","22222222222","3333333333"])
649 set nomodified
650 set colorcolumn=3,9
651 set number cursorline cursorlineopt=number
652 wincmd w
653 buf X
654 END
655 call writefile(lines, 'Xtest_colorcolumn')
656 let buf = RunVimInTerminal('-S Xtest_colorcolumn', {'rows': 10})
657 call term_sendkeys(buf, ":\<CR>")
Bram Moolenaar6a2c5a72020-04-08 21:50:25 +0200658 call TermWait(buf)
Bram Moolenaar010ee962019-09-25 20:37:36 +0200659 call VerifyScreenDump(buf, 'Test_colorcolumn_1', {})
660
661 " clean up
662 call StopVimInTerminal(buf)
663 call delete('Xtest_colorcolumn')
664endfunc
665
Bram Moolenaarad5e5632020-09-15 20:52:26 +0200666func Test_colorcolumn_bri()
667 CheckScreendump
668
669 " check 'colorcolumn' when 'breakindent' is set
670 let lines =<< trim END
671 call setline(1, 'The quick brown fox jumped over the lazy dogs')
672 END
673 call writefile(lines, 'Xtest_colorcolumn_bri')
674 let buf = RunVimInTerminal('-S Xtest_colorcolumn_bri', {'rows': 10,'columns': 40})
675 call term_sendkeys(buf, ":set co=40 linebreak bri briopt=shift:2 cc=40,41,43\<CR>")
676 call TermWait(buf)
677 call VerifyScreenDump(buf, 'Test_colorcolumn_2', {})
678
679 " clean up
680 call StopVimInTerminal(buf)
681 call delete('Xtest_colorcolumn_bri')
682endfunc
683
684func Test_colorcolumn_sbr()
685 CheckScreendump
686
687 " check 'colorcolumn' when 'showbreak' is set
688 let lines =<< trim END
689 call setline(1, 'The quick brown fox jumped over the lazy dogs')
690 END
691 call writefile(lines, 'Xtest_colorcolumn_srb')
692 let buf = RunVimInTerminal('-S Xtest_colorcolumn_srb', {'rows': 10,'columns': 40})
693 call term_sendkeys(buf, ":set co=40 showbreak=+++>\\ cc=40,41,43\<CR>")
694 call TermWait(buf)
695 call VerifyScreenDump(buf, 'Test_colorcolumn_3', {})
696
697 " clean up
698 call StopVimInTerminal(buf)
699 call delete('Xtest_colorcolumn_srb')
700endfunc
701
Bram Moolenaar6b528fa2019-05-09 20:07:33 +0200702" This test must come before the Test_cursorline test, as it appears this
703" defines the Normal highlighting group anyway.
Bram Moolenaarf90b6e02019-05-09 19:26:38 +0200704func Test_1_highlight_Normalgroup_exists()
Bram Moolenaar435f9f02019-07-03 21:40:16 +0200705 let hlNormal = HighlightArgs('Normal')
706 if !has('gui_running')
Bram Moolenaar6b528fa2019-05-09 20:07:33 +0200707 call assert_match('hi Normal\s*clear', hlNormal)
Bram Moolenaar435f9f02019-07-03 21:40:16 +0200708 elseif has('gui_gtk2') || has('gui_gnome') || has('gui_gtk3')
709 " expect is DEFAULT_FONT of gui_gtk_x11.c
710 call assert_match('hi Normal\s*font=Monospace 10', hlNormal)
711 elseif has('gui_motif') || has('gui_athena')
712 " expect is DEFAULT_FONT of gui_x11.c
713 call assert_match('hi Normal\s*font=7x13', hlNormal)
714 elseif has('win32')
715 " expect any font
716 call assert_match('hi Normal\s*font=.*', hlNormal)
Bram Moolenaar6b528fa2019-05-09 20:07:33 +0200717 endif
Bram Moolenaarf90b6e02019-05-09 19:26:38 +0200718endfunc
Bram Moolenaar548be7f2019-06-29 03:42:42 +0200719
Bram Moolenaar3180fe62020-02-02 13:47:06 +0100720" Do this test last, sometimes restoring the columns doesn't work
Bram Moolenaaree4e0c12020-04-06 21:35:05 +0200721func Test_z_no_space_before_xxx()
Bram Moolenaar548be7f2019-06-29 03:42:42 +0200722 let l:org_columns = &columns
723 set columns=17
724 let l:hi_StatusLineTermNC = join(split(execute('hi StatusLineTermNC')))
725 call assert_match('StatusLineTermNC xxx', l:hi_StatusLineTermNC)
726 let &columns = l:org_columns
Bram Moolenaaree4e0c12020-04-06 21:35:05 +0200727endfunc
728
729" Test for :highlight command errors
730func Test_highlight_cmd_errors()
731 if has('gui_running')
732 " This test doesn't fail in the MS-Windows console version.
Bram Moolenaar75e15672020-06-28 13:10:22 +0200733 call assert_fails('hi Xcomment ctermbg=fg', 'E419:')
Bram Moolenaaree4e0c12020-04-06 21:35:05 +0200734 call assert_fails('hi Xcomment ctermfg=bg', 'E420:')
Bram Moolenaar75e15672020-06-28 13:10:22 +0200735 call assert_fails('hi Xcomment ctermfg=ul', 'E453:')
Bram Moolenaaree4e0c12020-04-06 21:35:05 +0200736 endif
737
738 " Try using a very long terminal code. Define a dummy terminal code for this
739 " test.
740 let &t_fo = "\<Esc>1;"
741 let c = repeat("t_fo,", 100) . "t_fo"
742 call assert_fails('exe "hi Xgroup1 start=" . c', 'E422:')
743 let &t_fo = ""
744endfunc
745
Bram Moolenaar75e15672020-06-28 13:10:22 +0200746" Test for 'highlight' option
747func Test_highlight_opt()
748 let save_hl = &highlight
749 call assert_fails('set highlight=j:b', 'E474:')
750 set highlight=f\ r
751 call assert_equal('f r', &highlight)
752 set highlight=fb
753 call assert_equal('fb', &highlight)
754 set highlight=fi
755 call assert_equal('fi', &highlight)
756 set highlight=f-
757 call assert_equal('f-', &highlight)
758 set highlight=fr
759 call assert_equal('fr', &highlight)
760 set highlight=fs
761 call assert_equal('fs', &highlight)
762 set highlight=fu
763 call assert_equal('fu', &highlight)
764 set highlight=fc
765 call assert_equal('fc', &highlight)
766 set highlight=ft
767 call assert_equal('ft', &highlight)
768 call assert_fails('set highlight=fr:Search', 'E474:')
769 set highlight=f:$#
770 call assert_match('W18:', v:statusmsg)
771 let &highlight = save_hl
772endfunc
773
774" Test for User group highlighting used in the statusline
775func Test_highlight_User()
776 CheckNotGui
777 hi User1 ctermfg=12
778 redraw!
779 call assert_equal('12', synIDattr(synIDtrans(hlID('User1')), 'fg'))
780 hi clear
781endfunc
782
783" Test for using RGB color values in a highlight group
784func Test_highlight_RGB_color()
785 CheckGui
786 hi MySearch guifg=#110000 guibg=#001100 guisp=#000011
787 call assert_equal('#110000', synIDattr(synIDtrans(hlID('MySearch')), 'fg#'))
788 call assert_equal('#001100', synIDattr(synIDtrans(hlID('MySearch')), 'bg#'))
789 call assert_equal('#000011', synIDattr(synIDtrans(hlID('MySearch')), 'sp#'))
790 hi clear
791endfunc
792
Bram Moolenaarde8f0f42020-06-30 18:45:43 +0200793" Test for using default highlighting group
794func Test_highlight_default()
795 highlight MySearch ctermfg=7
796 highlight default MySearch ctermfg=5
797 let hlSearch = HighlightArgs('MySearch')
798 call assert_match('ctermfg=7', hlSearch)
799
800 highlight default QFName ctermfg=3
801 call assert_match('ctermfg=3', HighlightArgs('QFName'))
802 hi clear
803endfunc
804
805" Test for 'ctermul in a highlight group
806func Test_highlight_ctermul()
807 CheckNotGui
808 call assert_notmatch('ctermul=', HighlightArgs('Normal'))
809 highlight Normal ctermul=3
810 call assert_match('ctermul=3', HighlightArgs('Normal'))
Bram Moolenaar391c3622020-09-29 20:59:17 +0200811 call assert_equal('3', synIDattr(synIDtrans(hlID('Normal')), 'ul'))
Bram Moolenaarde8f0f42020-06-30 18:45:43 +0200812 highlight Normal ctermul=NONE
813endfunc
814
815" Test for specifying 'start' and 'stop' in a highlight group
816func Test_highlight_start_stop()
817 hi HlGrp1 start=<Esc>[27h;<Esc>[<Space>r;
818 call assert_match("start=^[[27h;^[[ r;", HighlightArgs('HlGrp1'))
819 hi HlGrp1 start=NONE
820 call assert_notmatch("start=", HighlightArgs('HlGrp1'))
821 hi HlGrp2 stop=<Esc>[27h;<Esc>[<Space>r;
822 call assert_match("stop=^[[27h;^[[ r;", HighlightArgs('HlGrp2'))
823 hi HlGrp2 stop=NONE
824 call assert_notmatch("stop=", HighlightArgs('HlGrp2'))
825 hi clear
826endfunc
827
828" Test for setting various 'term' attributes
829func Test_highlight_term_attr()
830 hi HlGrp3 term=bold,underline,undercurl,strikethrough,reverse,italic,standout
831 call assert_equal('hi HlGrp3 term=bold,standout,underline,undercurl,italic,reverse,strikethrough', HighlightArgs('HlGrp3'))
832 hi HlGrp3 term=NONE
833 call assert_equal('hi HlGrp3 cleared', HighlightArgs('HlGrp3'))
834 hi clear
835endfunc
836
Bram Moolenaar213da552020-09-17 19:59:26 +0200837func Test_highlight_clear_restores_links()
838 let aaa_id = hlID('aaa')
839 call assert_equal(aaa_id, 0)
840
841 " create default link aaa --> bbb
842 hi def link aaa bbb
843 let id_aaa = hlID('aaa')
844 let hl_aaa_bbb = HighlightArgs('aaa')
845
846 " try to redefine default link aaa --> ccc; check aaa --> bbb
847 hi def link aaa ccc
848 call assert_equal(HighlightArgs('aaa'), hl_aaa_bbb)
849
850 " clear aaa; check aaa --> bbb
851 hi clear aaa
852 call assert_equal(HighlightArgs('aaa'), hl_aaa_bbb)
853
854 " link aaa --> ccc; clear aaa; check aaa --> bbb
855 hi link aaa ccc
856 let id_ccc = hlID('ccc')
857 call assert_equal(synIDtrans(id_aaa), id_ccc)
858 hi clear aaa
859 call assert_equal(HighlightArgs('aaa'), hl_aaa_bbb)
860
861 " forcibly set default link aaa --> ddd
862 hi! def link aaa ddd
863 let id_ddd = hlID('ddd')
864 let hl_aaa_ddd = HighlightArgs('aaa')
865 call assert_equal(synIDtrans(id_aaa), id_ddd)
866
867 " link aaa --> eee; clear aaa; check aaa --> ddd
868 hi link aaa eee
869 let eee_id = hlID('eee')
870 call assert_equal(synIDtrans(id_aaa), eee_id)
871 hi clear aaa
872 call assert_equal(HighlightArgs('aaa'), hl_aaa_ddd)
873endfunc
874
Bram Moolenaare8df0102020-09-18 19:40:45 +0200875func Test_highlight_clear_restores_context()
876 func FuncContextDefault()
877 hi def link Context ContextDefault
878 endfun
879
880 func FuncContextRelink()
881 " Dummy line
882 hi link Context ContextRelink
883 endfunc
884
885 let scriptContextDefault = MakeScript("FuncContextDefault")
886 let scriptContextRelink = MakeScript("FuncContextRelink")
887 let patContextDefault = fnamemodify(scriptContextDefault, ':t') .. ' line 1'
888 let patContextRelink = fnamemodify(scriptContextRelink, ':t') .. ' line 2'
889
Bram Moolenaar2bbada82020-09-18 21:55:26 +0200890 exec 'source ' .. scriptContextDefault
Bram Moolenaare8df0102020-09-18 19:40:45 +0200891 let hlContextDefault = execute("verbose hi Context")
892 call assert_match(patContextDefault, hlContextDefault)
893
Bram Moolenaar2bbada82020-09-18 21:55:26 +0200894 exec 'source ' .. scriptContextRelink
Bram Moolenaare8df0102020-09-18 19:40:45 +0200895 let hlContextRelink = execute("verbose hi Context")
896 call assert_match(patContextRelink, hlContextRelink)
897
898 hi clear
899 let hlContextAfterClear = execute("verbose hi Context")
900 call assert_match(patContextDefault, hlContextAfterClear)
901
902 delfunc FuncContextDefault
903 delfunc FuncContextRelink
904 call delete(scriptContextDefault)
905 call delete(scriptContextRelink)
906endfunc
907
Bram Moolenaar213da552020-09-17 19:59:26 +0200908func Test_highlight_default_colorscheme_restores_links()
909 hi link TestLink Identifier
910 hi TestHi ctermbg=red
Bram Moolenaar05eb5b92020-09-16 15:43:21 +0200911
912 let hlTestLinkPre = HighlightArgs('TestLink')
913 let hlTestHiPre = HighlightArgs('TestHi')
914
915 " Test colorscheme
916 hi clear
917 if exists('syntax_on')
918 syntax reset
919 endif
920 let g:colors_name = 'test'
Bram Moolenaar213da552020-09-17 19:59:26 +0200921 hi link TestLink ErrorMsg
922 hi TestHi ctermbg=green
Bram Moolenaar05eb5b92020-09-16 15:43:21 +0200923
924 " Restore default highlighting
925 colorscheme default
Bram Moolenaar05eb5b92020-09-16 15:43:21 +0200926 " 'default' should work no matter if highlight group was cleared
927 hi def link TestLink Identifier
928 hi def TestHi ctermbg=red
Bram Moolenaar05eb5b92020-09-16 15:43:21 +0200929 let hlTestLinkPost = HighlightArgs('TestLink')
930 let hlTestHiPost = HighlightArgs('TestHi')
Bram Moolenaar05eb5b92020-09-16 15:43:21 +0200931 call assert_equal(hlTestLinkPre, hlTestLinkPost)
932 call assert_equal(hlTestHiPre, hlTestHiPost)
933 hi clear
934endfunc
935
Bram Moolenaaree4e0c12020-04-06 21:35:05 +0200936" vim: shiftwidth=2 sts=2 expandtab