robin/laufey

git clone https://git.robinwobin.dev/robin/laufey

zeertzjqvim-patch:9.2.0892: highlight: wrong column highlighted with 'cursorcolumn' (#41110)a5103c0853

master
28.9 KiB987 linesraw
1" Tests for ":highlight" and highlighting.
2
3source view_util.vim
4source screendump.vim
5source check.vim
6source script_util.vim
7
8func 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 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 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:")
42
43  if has('gui_running')
44    call assert_fails('hi NotUsed guibg=none', 'E1361:')
45  endif
46endfunc
47
48func HighlightArgs(name)
49  return 'hi ' . substitute(split(execute('hi ' . a:name), '\n')[0], '\<xxx\>', '', '')
50endfunc
51
52func IsColorable()
53  return has('gui_running') || str2nr(&t_Co) >= 8
54endfunc
55
56func HiCursorLine()
57  let hiCursorLine = HighlightArgs('CursorLine')
58  if has('gui_running')
59    let guibg = matchstr(hiCursorLine, 'guibg=\w\+')
60    let hi_ul = 'hi CursorLine gui=underline guibg=NONE'
61    let hi_bg = 'hi CursorLine gui=NONE ' . guibg
62  else
63    let hi_ul = 'hi CursorLine cterm=underline ctermbg=NONE'
64    let hi_bg = 'hi CursorLine cterm=NONE ctermbg=Gray'
65  endif
66  return [hiCursorLine, hi_ul, hi_bg]
67endfunc
68
69func Check_lcs_eol_attrs(attrs, row, col)
70  let save_lcs = &lcs
71  set list
72
73  call assert_equal(a:attrs, ScreenAttrs(a:row, a:col)[0])
74
75  set nolist
76  let &lcs = save_lcs
77endfunc
78
79func Test_highlight_eol_with_cursorline()
80  let [hiCursorLine, hi_ul, hi_bg] = HiCursorLine()
81
82  call NewWindow('topleft 5', 20)
83  call setline(1, 'abcd')
84  call matchadd('Search', '\n')
85
86  " expected:
87  " 'abcd      '
88  "  ^^^^ ^^^^^   no highlight
89  "      ^        'Search' highlight
90  let attrs0 = ScreenAttrs(1, 10)[0]
91  call assert_equal(repeat([attrs0[0]], 4), attrs0[0:3])
92  call assert_equal(repeat([attrs0[0]], 5), attrs0[5:9])
93  call assert_notequal(attrs0[0], attrs0[4])
94
95  setlocal cursorline
96
97  " underline
98  exe hi_ul
99
100  " expected:
101  " 'abcd      '
102  "  ^^^^         underline
103  "      ^        'Search' highlight with underline
104  "       ^^^^^   underline
105  let attrs = ScreenAttrs(1, 10)[0]
106  call assert_equal(repeat([attrs[0]], 4), attrs[0:3])
107  call assert_equal([attrs[4]] + repeat([attrs[5]], 5), attrs[4:9])
108  call assert_notequal(attrs[0], attrs[4])
109  call assert_notequal(attrs[4], attrs[5])
110  call assert_notequal(attrs0[0], attrs[0])
111  call assert_notequal(attrs0[4], attrs[4])
112  call Check_lcs_eol_attrs(attrs, 1, 10)
113
114  if IsColorable()
115    " bg-color
116    exe hi_bg
117
118    " expected:
119    " 'abcd      '
120    "  ^^^^         bg-color of 'CursorLine'
121    "      ^        'Search' highlight
122    "       ^^^^^   bg-color of 'CursorLine'
123    let attrs = ScreenAttrs(1, 10)[0]
124    call assert_equal(repeat([attrs[0]], 4), attrs[0:3])
125    call assert_equal(repeat([attrs[5]], 5), attrs[5:9])
126    call assert_equal(attrs0[4], attrs[4])
127    call assert_notequal(attrs[0], attrs[4])
128    call assert_notequal(attrs[4], attrs[5])
129    call assert_notequal(attrs0[0], attrs[0])
130    call assert_notequal(attrs0[5], attrs[5])
131    call Check_lcs_eol_attrs(attrs, 1, 10)
132  endif
133
134  call CloseWindow()
135  exe hiCursorLine
136endfunc
137
138func Test_highlight_eol_with_cursorline_vertsplit()
139  let [hiCursorLine, hi_ul, hi_bg] = HiCursorLine()
140
141  call NewWindow('topleft 5', 5)
142  call setline(1, 'abcd')
143  call matchadd('Search', '\n')
144
145  let expected = "abcd |abcd     "
146  let actual = ScreenLines(1, 15)[0]
147  call assert_equal(expected, actual)
148
149  " expected:
150  " 'abcd |abcd     '
151  "  ^^^^  ^^^^^^^^^   no highlight
152  "      ^             'Search' highlight
153  "       ^            'WinSeparator' highlight
154  let attrs0 = ScreenAttrs(1, 15)[0]
155  call assert_equal(repeat([attrs0[0]], 4), attrs0[0:3])
156  call assert_equal(repeat([attrs0[0]], 9), attrs0[6:14])
157  call assert_notequal(attrs0[0], attrs0[4])
158  call assert_notequal(attrs0[0], attrs0[5])
159  call assert_notequal(attrs0[4], attrs0[5])
160
161  setlocal cursorline
162
163  " expected:
164  " 'abcd |abcd     '
165  "  ^^^^              underline
166  "      ^             'Search' highlight with underline
167  "       ^            'WinSeparator' highlight
168  "        ^^^^^^^^^   no highlight
169
170  " underline
171  exe hi_ul
172
173  let actual = ScreenLines(1, 15)[0]
174  call assert_equal(expected, actual)
175
176  let attrs = ScreenAttrs(1, 15)[0]
177  call assert_equal(repeat([attrs[0]], 4), attrs[0:3])
178  call assert_equal(repeat([attrs[6]], 9), attrs[6:14])
179  call assert_equal(attrs0[5:14], attrs[5:14])
180  call assert_notequal(attrs[0], attrs[4])
181  call assert_notequal(attrs[0], attrs[5])
182  call assert_notequal(attrs[0], attrs[6])
183  call assert_notequal(attrs[4], attrs[5])
184  call assert_notequal(attrs[5], attrs[6])
185  call assert_notequal(attrs0[0], attrs[0])
186  call assert_notequal(attrs0[4], attrs[4])
187  call Check_lcs_eol_attrs(attrs, 1, 15)
188
189  if IsColorable()
190    " bg-color
191    exe hi_bg
192
193    let actual = ScreenLines(1, 15)[0]
194    call assert_equal(expected, actual)
195
196    let attrs = ScreenAttrs(1, 15)[0]
197    call assert_equal(repeat([attrs[0]], 4), attrs[0:3])
198    call assert_equal(repeat([attrs[6]], 9), attrs[6:14])
199    call assert_equal(attrs0[5:14], attrs[5:14])
200    call assert_notequal(attrs[0], attrs[4])
201    call assert_notequal(attrs[0], attrs[5])
202    call assert_notequal(attrs[0], attrs[6])
203    call assert_notequal(attrs[4], attrs[5])
204    call assert_notequal(attrs[5], attrs[6])
205    call assert_notequal(attrs0[0], attrs[0])
206    call assert_equal(attrs0[4], attrs[4])
207    call Check_lcs_eol_attrs(attrs, 1, 15)
208  endif
209
210  call CloseWindow()
211  exe hiCursorLine
212endfunc
213
214func Test_highlight_eol_with_cursorline_rightleft()
215  if !has('rightleft')
216    return
217  endif
218
219  let [hiCursorLine, hi_ul, hi_bg] = HiCursorLine()
220
221  call NewWindow('topleft 5', 10)
222  setlocal rightleft
223  call setline(1, 'abcd')
224  call matchadd('Search', '\n')
225  let attrs0 = ScreenAttrs(1, 10)[0]
226
227  setlocal cursorline
228
229  " underline
230  exe hi_ul
231
232  " expected:
233  " '      dcba'
234  "        ^^^^   underline
235  "       ^       'Search' highlight with underline
236  "  ^^^^^        underline
237  let attrs = ScreenAttrs(1, 10)[0]
238  call assert_equal(repeat([attrs[9]], 4), attrs[6:9])
239  call assert_equal(repeat([attrs[4]], 5) + [attrs[5]], attrs[0:5])
240  call assert_notequal(attrs[9], attrs[5])
241  call assert_notequal(attrs[4], attrs[5])
242  call assert_notequal(attrs0[9], attrs[9])
243  call assert_notequal(attrs0[5], attrs[5])
244  call Check_lcs_eol_attrs(attrs, 1, 10)
245
246  if IsColorable()
247    " bg-color
248    exe hi_bg
249
250    " expected:
251    " '      dcba'
252    "        ^^^^   bg-color of 'CursorLine'
253    "       ^       'Search' highlight
254    "  ^^^^^        bg-color of 'CursorLine'
255    let attrs = ScreenAttrs(1, 10)[0]
256    call assert_equal(repeat([attrs[9]], 4), attrs[6:9])
257    call assert_equal(repeat([attrs[4]], 5), attrs[0:4])
258    call assert_equal(attrs0[5], attrs[5])
259    call assert_notequal(attrs[9], attrs[5])
260    call assert_notequal(attrs[5], attrs[4])
261    call assert_notequal(attrs0[9], attrs[9])
262    call assert_notequal(attrs0[4], attrs[4])
263    call Check_lcs_eol_attrs(attrs, 1, 10)
264  endif
265
266  call CloseWindow()
267  exe hiCursorLine
268endfunc
269
270func Test_highlight_eol_with_cursorline_linewrap()
271  let [hiCursorLine, hi_ul, hi_bg] = HiCursorLine()
272
273  call NewWindow('topleft 5', 10)
274  call setline(1, [repeat('a', 51) . 'bcd', ''])
275  call matchadd('Search', '\n')
276
277  setlocal wrap
278  normal! gg$
279  let attrs0 = ScreenAttrs(5, 10)[0]
280  setlocal cursorline
281
282  " underline
283  exe hi_ul
284
285  " expected:
286  " 'abcd      '
287  "  ^^^^         underline
288  "      ^        'Search' highlight with underline
289  "       ^^^^^   underline
290  let attrs = ScreenAttrs(5, 10)[0]
291  call assert_equal(repeat([attrs[0]], 4), attrs[0:3])
292  call assert_equal([attrs[4]] + repeat([attrs[5]], 5), attrs[4:9])
293  call assert_notequal(attrs[0], attrs[4])
294  call assert_notequal(attrs[4], attrs[5])
295  call assert_notequal(attrs0[0], attrs[0])
296  call assert_notequal(attrs0[4], attrs[4])
297  call Check_lcs_eol_attrs(attrs, 5, 10)
298
299  if IsColorable()
300    " bg-color
301    exe hi_bg
302
303    " expected:
304    " 'abcd      '
305    "  ^^^^         bg-color of 'CursorLine'
306    "      ^        'Search' highlight
307    "       ^^^^^   bg-color of 'CursorLine'
308    let attrs = ScreenAttrs(5, 10)[0]
309    call assert_equal(repeat([attrs[0]], 4), attrs[0:3])
310    call assert_equal(repeat([attrs[5]], 5), attrs[5:9])
311    call assert_equal(attrs0[4], attrs[4])
312    call assert_notequal(attrs[0], attrs[4])
313    call assert_notequal(attrs[4], attrs[5])
314    call assert_notequal(attrs0[0], attrs[0])
315    call assert_notequal(attrs0[5], attrs[5])
316    call Check_lcs_eol_attrs(attrs, 5, 10)
317  endif
318
319  setlocal nocursorline nowrap
320  normal! gg$
321  let attrs0 = ScreenAttrs(1, 10)[0]
322  setlocal cursorline
323
324  " underline
325  exe hi_ul
326
327  " expected:
328  " 'aaabcd    '
329  "  ^^^^^^       underline
330  "        ^      'Search' highlight with underline
331  "         ^^^   underline
332  let attrs = ScreenAttrs(1, 10)[0]
333  call assert_equal(repeat([attrs[0]], 6), attrs[0:5])
334  call assert_equal([attrs[6]] + repeat([attrs[7]], 3), attrs[6:9])
335  call assert_notequal(attrs[0], attrs[6])
336  call assert_notequal(attrs[6], attrs[7])
337  call assert_notequal(attrs0[0], attrs[0])
338  call assert_notequal(attrs0[6], attrs[6])
339  call Check_lcs_eol_attrs(attrs, 1, 10)
340
341  if IsColorable()
342    " bg-color
343    exe hi_bg
344
345    " expected:
346    " 'aaabcd    '
347    "  ^^^^^^       bg-color of 'CursorLine'
348    "        ^      'Search' highlight
349    "         ^^^   bg-color of 'CursorLine'
350    let attrs = ScreenAttrs(1, 10)[0]
351    call assert_equal(repeat([attrs[0]], 6), attrs[0:5])
352    call assert_equal(repeat([attrs[7]], 3), attrs[7:9])
353    call assert_equal(attrs0[6], attrs[6])
354    call assert_notequal(attrs[0], attrs[6])
355    call assert_notequal(attrs[6], attrs[7])
356    call assert_notequal(attrs0[0], attrs[0])
357    call assert_notequal(attrs0[7], attrs[7])
358    call Check_lcs_eol_attrs(attrs, 1, 10)
359  endif
360
361  call CloseWindow()
362  exe hiCursorLine
363endfunc
364
365func Test_highlight_eol_with_cursorline_sign()
366  if !has('signs')
367    return
368  endif
369
370  let [hiCursorLine, hi_ul, hi_bg] = HiCursorLine()
371
372  call NewWindow('topleft 5', 10)
373  call setline(1, 'abcd')
374  call matchadd('Search', '\n')
375
376  sign define Sign text=>>
377  exe 'sign place 1 line=1 name=Sign buffer=' . bufnr('')
378  let attrs0 = ScreenAttrs(1, 10)[0]
379  setlocal cursorline
380
381  " underline
382  exe hi_ul
383
384  " expected:
385  " '>>abcd    '
386  "  ^^           sign
387  "    ^^^^       underline
388  "        ^      'Search' highlight with underline
389  "         ^^^   underline
390  let attrs = ScreenAttrs(1, 10)[0]
391  call assert_equal(repeat([attrs[2]], 4), attrs[2:5])
392  call assert_equal([attrs[6]] + repeat([attrs[7]], 3), attrs[6:9])
393  call assert_notequal(attrs[2], attrs[6])
394  call assert_notequal(attrs[6], attrs[7])
395  call assert_notequal(attrs0[2], attrs[2])
396  call assert_notequal(attrs0[6], attrs[6])
397  call Check_lcs_eol_attrs(attrs, 1, 10)
398
399  if IsColorable()
400    " bg-color
401    exe hi_bg
402
403    " expected:
404    " '>>abcd    '
405    "  ^^           sign
406    "    ^^^^       bg-color of 'CursorLine'
407    "        ^      'Search' highlight
408    "         ^^^   bg-color of 'CursorLine'
409    let attrs = ScreenAttrs(1, 10)[0]
410    call assert_equal(repeat([attrs[2]], 4), attrs[2:5])
411    call assert_equal(repeat([attrs[7]], 3), attrs[7:9])
412    call assert_equal(attrs0[6], attrs[6])
413    call assert_notequal(attrs[2], attrs[6])
414    call assert_notequal(attrs[6], attrs[7])
415    call assert_notequal(attrs0[2], attrs[2])
416    call assert_notequal(attrs0[7], attrs[7])
417    call Check_lcs_eol_attrs(attrs, 1, 10)
418  endif
419
420  sign unplace 1
421  call CloseWindow()
422  exe hiCursorLine
423endfunc
424
425func Test_highlight_eol_with_cursorline_breakindent()
426  if !has('linebreak')
427    return
428  endif
429
430  let [hiCursorLine, hi_ul, hi_bg] = HiCursorLine()
431
432  call NewWindow('topleft 5', 10)
433  set showbreak=xxx
434  setlocal breakindent breakindentopt=min:0,shift:1 showbreak=>
435  call setline(1, ' ' . repeat('a', 9) . 'bcd')
436  call matchadd('Search', '\n')
437  let attrs0 = ScreenAttrs(2, 10)[0]
438  setlocal cursorline
439
440  " underline
441  exe hi_ul
442
443  " expected:
444  " '  >bcd    '
445  "  ^^^          breakindent and showbreak
446  "     ^^^       underline
447  "        ^      'Search' highlight with underline
448  "         ^^^   underline
449  let attrs = ScreenAttrs(2, 10)[0]
450  call assert_equal(repeat([attrs[0]], 2), attrs[0:1])
451  call assert_equal(repeat([attrs[3]], 3), attrs[3:5])
452  call assert_equal([attrs[6]] + repeat([attrs[7]], 3), attrs[6:9])
453  call assert_equal(attrs0[0], attrs[0])
454  call assert_notequal(attrs[0], attrs[2])
455  call assert_notequal(attrs[2], attrs[3])
456  call assert_notequal(attrs[3], attrs[6])
457  call assert_notequal(attrs[6], attrs[7])
458  call assert_notequal(attrs0[2], attrs[2])
459  call assert_notequal(attrs0[3], attrs[3])
460  call assert_notequal(attrs0[6], attrs[6])
461  call Check_lcs_eol_attrs(attrs, 2, 10)
462
463  if IsColorable()
464    " bg-color
465    exe hi_bg
466
467    " expected:
468    " '  >bcd    '
469    "  ^^^          breakindent and showbreak
470    "     ^^^       bg-color of 'CursorLine'
471    "        ^      'Search' highlight
472    "         ^^^   bg-color of 'CursorLine'
473    let attrs = ScreenAttrs(2, 10)[0]
474    call assert_equal(repeat([attrs[0]], 2), attrs[0:1])
475    call assert_equal(repeat([attrs[3]], 3), attrs[3:5])
476    call assert_equal(repeat([attrs[7]], 3), attrs[7:9])
477    call assert_equal(attrs0[0], attrs[0])
478    call assert_equal(attrs0[6], attrs[6])
479    call assert_notequal(attrs[0], attrs[2])
480    call assert_notequal(attrs[2], attrs[3])
481    call assert_notequal(attrs[3], attrs[6])
482    call assert_notequal(attrs[6], attrs[7])
483    call assert_notequal(attrs0[2], attrs[2])
484    call assert_notequal(attrs0[3], attrs[3])
485    call assert_notequal(attrs0[7], attrs[7])
486    call Check_lcs_eol_attrs(attrs, 2, 10)
487  endif
488
489  call CloseWindow()
490  set showbreak=
491  setlocal showbreak=
492  exe hiCursorLine
493endfunc
494
495func Test_highlight_eol_on_diff()
496  call setline(1, ['abcd', ''])
497  call matchadd('Search', '\n')
498  let attrs0 = ScreenAttrs(1, 10)[0]
499
500  diffthis
501  botright new
502  diffthis
503
504  " expected:
505  " '  abcd    '
506  "  ^^           sign
507  "    ^^^^ ^^^   'DiffAdd' highlight
508  "        ^      'Search' highlight
509  let attrs = ScreenAttrs(1, 10)[0]
510  call assert_equal(repeat([attrs[0]], 2), attrs[0:1])
511  call assert_equal(repeat([attrs[2]], 4), attrs[2:5])
512  call assert_equal(repeat([attrs[2]], 3), attrs[7:9])
513  call assert_equal(attrs0[4], attrs[6])
514  call assert_notequal(attrs[0], attrs[2])
515  call assert_notequal(attrs[0], attrs[6])
516  call assert_notequal(attrs[2], attrs[6])
517  call Check_lcs_eol_attrs(attrs, 1, 10)
518
519  bwipe!
520  diffoff
521endfunc
522
523func Test_termguicolors()
524  if !exists('+termguicolors')
525    return
526  endif
527  if has('vtp') && !has('vcon') && !has('gui_running')
528    " Win32: 'guicolors' doesn't work without virtual console.
529    call assert_fails('set termguicolors', 'E954:')
530    return
531  endif
532
533  " Basic test that setting 'termguicolors' works with one color.
534  set termguicolors
535  redraw
536  set t_Co=1
537  redraw
538  set t_Co=0
539  redraw
540endfunc
541
542func Test_cursorline_after_yank()
543  CheckScreendump
544
545  call writefile([
546	\ 'set cul rnu',
547	\ 'call setline(1, ["","1","2","3",""])',
548	\ ], 'Xtest_cursorline_yank', 'D')
549  let buf = RunVimInTerminal('-S Xtest_cursorline_yank', {'rows': 8})
550  call TermWait(buf)
551  call term_sendkeys(buf, "Gy3k")
552  call TermWait(buf)
553  call term_sendkeys(buf, "jj")
554
555  call VerifyScreenDump(buf, 'Test_cursorline_yank_01', {})
556
557  " clean up
558  call StopVimInTerminal(buf)
559endfunc
560
561" Test for issue #4862: pasting above 'cursorline' redraws properly.
562func Test_put_before_cursorline()
563  new
564  only!
565  call setline(1, ['A', 'B', 'C'])
566  call cursor(2, 1)
567  redraw
568  let std_attr = screenattr(2, 1)
569  set cursorline
570  redraw
571  let cul_attr = screenattr(2, 1)
572  normal yyP
573  redraw
574  " Line 2 has cursor so it should be highlighted with CursorLine.
575  call assert_equal(cul_attr, screenattr(2, 1))
576  " And CursorLine highlighting from line 3 should be gone.
577  call assert_equal(std_attr, screenattr(3, 1))
578  set nocursorline
579  bwipe!
580endfunc
581
582func Test_cursorline_with_visualmode()
583  CheckScreendump
584
585  call writefile([
586	\ 'set cul',
587	\ 'call setline(1, repeat(["abc"], 50))',
588	\ ], 'Xtest_cursorline_with_visualmode')
589  let buf = RunVimInTerminal('-S Xtest_cursorline_with_visualmode', {'rows': 12})
590  call TermWait(buf)
591  call term_sendkeys(buf, "V\<C-f>kkkjk")
592
593  call VerifyScreenDump(buf, 'Test_cursorline_with_visualmode_01', {})
594
595  " clean up
596  call StopVimInTerminal(buf)
597  call delete('Xtest_cursorline_with_visualmode')
598endfunc
599
600func Test_wincolor()
601  CheckScreendump
602  " make sure the width is enough for the test
603  set columns=80
604
605  let lines =<< trim END
606	set cursorline cursorcolumn rnu
607	call setline(1, ["","1111111111","22222222222","3 here 3","","the cat is out of the bag"])
608	set wincolor=Pmenu
609	hi CatLine guifg=green ctermfg=green
610	hi Reverse gui=reverse cterm=reverse
611	syn match CatLine /^the.*/
612	call prop_type_add("foo", {"highlight": "Reverse", "combine": 1})
613	call prop_add(6, 12, {"type": "foo", "end_col": 15})
614	/here
615  END
616  call writefile(lines, 'Xtest_wincolor')
617  let buf = RunVimInTerminal('-S Xtest_wincolor', {'rows': 8})
618  call TermWait(buf)
619  call term_sendkeys(buf, "2G5lvj")
620  call TermWait(buf)
621
622  call VerifyScreenDump(buf, 'Test_wincolor_01', {})
623
624  " clean up
625  call term_sendkeys(buf, "\<Esc>")
626  call StopVimInTerminal(buf)
627  call delete('Xtest_wincolor')
628endfunc
629
630func Test_wincolor_listchars()
631  CheckScreendump
632  CheckFeature conceal
633
634  let lines =<< trim END
635	call setline(1, ["one","\t\tsome random text enough long to show 'extends' and 'precedes' includingnbsps, preceding tabs and trailing spaces    ","three"])
636	set wincolor=Todo
637	set nowrap cole=1 cocu+=n
638	set list lcs=eol:$,tab:>-,space:.,trail:_,extends:>,precedes:<,conceal:*,nbsp:#
639	call matchadd('Conceal', 'text')
640	normal 2G5zl
641  END
642  call writefile(lines, 'Xtest_wincolorlcs')
643  let buf = RunVimInTerminal('-S Xtest_wincolorlcs', {'rows': 8})
644
645  call VerifyScreenDump(buf, 'Test_wincolor_lcs', {})
646
647  " clean up
648  call term_sendkeys(buf, "\<Esc>")
649  call StopVimInTerminal(buf)
650  call delete('Xtest_wincolorlcs')
651endfunc
652
653func Test_cursorcolumn_insert_on_tab()
654  CheckScreendump
655
656  let lines =<< trim END
657    call setline(1, ['123456789', "a\tb"])
658    set cursorcolumn
659    call cursor(2, 2)
660  END
661  call writefile(lines, 'Xcuc_insert_on_tab', 'D')
662
663  let buf = RunVimInTerminal('-S Xcuc_insert_on_tab', #{rows: 8})
664  call TermWait(buf)
665  call VerifyScreenDump(buf, 'Test_cursorcolumn_insert_on_tab_1', {})
666
667  call term_sendkeys(buf, 'i')
668  call TermWait(buf)
669  call VerifyScreenDump(buf, 'Test_cursorcolumn_insert_on_tab_2', {})
670
671  call term_sendkeys(buf, "\<C-O>")
672  call TermWait(buf)
673  call VerifyScreenDump(buf, 'Test_cursorcolumn_insert_on_tab_3', {})
674
675  call term_sendkeys(buf, 'i')
676  call TermWait(buf)
677  call VerifyScreenDump(buf, 'Test_cursorcolumn_insert_on_tab_2', {})
678
679  call StopVimInTerminal(buf)
680endfunc
681
682" The column highlighted with 'cursorcolumn' must be the column of the cursor,
683" also after a command that moved the cursor into virtual space and back.
684func Test_cursorcolumn_virtualedit()
685  CheckScreendump
686
687  let lines =<< trim END
688    set virtualedit=all
689    set cursorcolumn
690    call setline(1, ['', '', ''])
691    call cursor(3, 1)
692  END
693  call writefile(lines, 'Xcuc_virtualedit', 'D')
694
695  let buf = RunVimInTerminal('-S Xcuc_virtualedit', #{rows: 8})
696  call TermWait(buf)
697  call VerifyScreenDump(buf, 'Test_cursorcolumn_virtualedit_1', {})
698
699  call term_sendkeys(buf, "\<Del>")
700  call TermWait(buf)
701  call VerifyScreenDump(buf, 'Test_cursorcolumn_virtualedit_1', {})
702
703  call StopVimInTerminal(buf)
704endfunc
705
706func Test_cursorcolumn_callback()
707  CheckScreendump
708  CheckFeature timers
709
710  let lines =<< trim END
711      call setline(1, ['aaaaa', 'bbbbb', 'ccccc', 'ddddd'])
712      set cursorcolumn
713      call cursor(4, 5)
714
715      func Func(timer)
716        call cursor(1, 1)
717      endfunc
718
719      call timer_start(300, 'Func')
720  END
721  call writefile(lines, 'Xcuc_timer')
722
723  let buf = RunVimInTerminal('-S Xcuc_timer', #{rows: 8})
724  call TermWait(buf, 310)
725  call VerifyScreenDump(buf, 'Test_cursorcolumn_callback_1', {})
726
727  call StopVimInTerminal(buf)
728  call delete('Xcuc_timer')
729endfunc
730
731func Test_colorcolumn()
732  CheckScreendump
733
734  " check that setting 'colorcolumn' when entering a buffer works
735  let lines =<< trim END
736	split
737	edit X
738	call setline(1, ["1111111111","22222222222","3333333333"])
739	set nomodified
740	set colorcolumn=3,9
741	set number cursorline cursorlineopt=number
742	wincmd w
743	buf X
744  END
745  call writefile(lines, 'Xtest_colorcolumn')
746  let buf = RunVimInTerminal('-S Xtest_colorcolumn', {'rows': 10})
747  call term_sendkeys(buf, ":\<CR>")
748  call VerifyScreenDump(buf, 'Test_colorcolumn_1', {})
749
750  " clean up
751  call StopVimInTerminal(buf)
752  call delete('Xtest_colorcolumn')
753endfunc
754
755func Test_colorcolumn_bri()
756  CheckScreendump
757
758  " check 'colorcolumn' when 'breakindent' is set
759  let lines =<< trim END
760	call setline(1, 'The quick brown fox jumped over the lazy dogs')
761  END
762  call writefile(lines, 'Xtest_colorcolumn_bri')
763  let buf = RunVimInTerminal('-S Xtest_colorcolumn_bri', {'rows': 10,'columns': 40})
764  call term_sendkeys(buf, ":set co=40 linebreak bri briopt=shift:2 cc=40,41,43\<CR>")
765  call VerifyScreenDump(buf, 'Test_colorcolumn_2', {})
766
767  " clean up
768  call StopVimInTerminal(buf)
769  call delete('Xtest_colorcolumn_bri')
770endfunc
771
772func Test_colorcolumn_sbr()
773  CheckScreendump
774
775  " check 'colorcolumn' when 'showbreak' is set
776  let lines =<< trim END
777	call setline(1, 'The quick brown fox jumped over the lazy dogs')
778  END
779  call writefile(lines, 'Xtest_colorcolumn_sbr', 'D')
780  let buf = RunVimInTerminal('-S Xtest_colorcolumn_sbr', {'rows': 10,'columns': 40})
781  call term_sendkeys(buf, ":set co=40 showbreak=+++>\\  cc=40,41,43\<CR>")
782  call VerifyScreenDump(buf, 'Test_colorcolumn_3', {})
783
784  " clean up
785  call StopVimInTerminal(buf)
786endfunc
787
788func Test_visual_sbr()
789  CheckScreendump
790
791  " check Visual highlight when 'showbreak' is set
792  let lines =<< trim END
793      set showbreak=>
794      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.')
795      exe "normal! z1\<CR>"
796  END
797  call writefile(lines, 'Xtest_visual_sbr', 'D')
798  let buf = RunVimInTerminal('-S Xtest_visual_sbr', {'rows': 6,'columns': 60})
799
800  call term_sendkeys(buf, "v$")
801  call WaitForAssert({-> assert_match('VISUAL.*\d\+\s\+\d', term_getline(buf, 6))}, 1000)
802  call VerifyScreenDump(buf, 'Test_visual_sbr_1', {})
803
804  " clean up
805  call term_sendkeys(buf, "\<Esc>")
806  call StopVimInTerminal(buf)
807endfunc
808
809" This test must come before the Test_cursorline test, as it appears this
810" defines the Normal highlighting group anyway.
811func Test_1_highlight_Normalgroup_exists()
812  let hlNormal = HighlightArgs('Normal')
813  if !has('gui_running')
814    call assert_match('hi Normal\s*clear', hlNormal)
815  elseif has('gui_gtk2') || has('gui_gnome') || has('gui_gtk3')
816    " expect is DEFAULT_FONT of gui_gtk_x11.c (any size)
817    call assert_match('hi Normal\s*font=Monospace\>', hlNormal)
818  elseif has('gui_motif')
819    " expect is DEFAULT_FONT of gui_x11.c
820    call assert_match('hi Normal\s*font=7x13', hlNormal)
821  elseif has('win32')
822    " expect any font
823    call assert_match('hi Normal\s*font=.*', hlNormal)
824  endif
825endfunc
826
827" Do this test last, sometimes restoring the columns doesn't work
828func Test_z_no_space_before_xxx()
829  " Note: we need to create this highlight group in the test because it does not exist in Neovim
830  execute('hi StatusLineTermNC ctermfg=green')
831  let l:org_columns = &columns
832  set columns=17
833  let l:hi_StatusLineTermNC = join(split(execute('hi StatusLineTermNC')))
834  call assert_match('StatusLineTermNC xxx', l:hi_StatusLineTermNC)
835  let &columns = l:org_columns
836endfunc
837
838" Test for :highlight command errors
839func Test_highlight_cmd_errors()
840  if has('gui_running') || has('nvim')
841    hi! Normal ctermfg=NONE ctermbg=NONE
842    " This test doesn't fail in the MS-Windows console version.
843    call assert_fails('hi Xcomment ctermfg=fg', 'E419:')
844    call assert_fails('hi Xcomment ctermfg=bg', 'E420:')
845    call assert_fails('hi ' .. repeat('a', 201) .. ' ctermfg=black', 'E1249:')
846  endif
847
848  " Try using a very long terminal code. Define a dummy terminal code for this
849  " test.
850  let &t_fo = "\<Esc>1;"
851  let c = repeat("t_fo,", 100) . "t_fo"
852  " call assert_fails('exe "hi Xgroup1 start=" . c', 'E422:')
853  let &t_fo = ""
854endfunc
855
856" Test for User group highlighting used in the statusline
857func Test_highlight_User()
858  CheckNotGui
859  hi User1 ctermfg=12
860  redraw!
861  call assert_equal('12', synIDattr(synIDtrans(hlID('User1')), 'fg'))
862  hi clear
863endfunc
864
865" Test for MsgArea highlighting
866func Test_highlight_MsgArea()
867  CheckNotGui
868  hi MsgArea ctermfg=20
869  redraw!
870  call assert_equal('20', synIDattr(synIDtrans(hlID('MsgArea')), 'fg'))
871  hi clear
872endfunc
873
874" Test for using RGB color values in a highlight group
875func Test_xxlast_highlight_RGB_color()
876  CheckCanRunGui
877  gui -f
878  hi MySearch guifg=#110000 guibg=#001100 guisp=#000011
879  call assert_equal('#110000', synIDattr(synIDtrans(hlID('MySearch')), 'fg#'))
880  call assert_equal('#001100', synIDattr(synIDtrans(hlID('MySearch')), 'bg#'))
881  call assert_equal('#000011', synIDattr(synIDtrans(hlID('MySearch')), 'sp#'))
882  hi clear
883endfunc
884
885func Test_highlight_clear_restores_links()
886  let aaa_id = hlID('aaa')
887  call assert_equal(aaa_id, 0)
888
889  " create default link aaa --> bbb
890  hi def link aaa bbb
891  let id_aaa = hlID('aaa')
892  let hl_aaa_bbb = HighlightArgs('aaa')
893
894  " try to redefine default link aaa --> ccc; check aaa --> bbb
895  hi def link aaa ccc
896  call assert_equal(HighlightArgs('aaa'), hl_aaa_bbb)
897
898  " clear aaa; check aaa --> bbb
899  hi clear aaa
900  call assert_equal(HighlightArgs('aaa'), hl_aaa_bbb)
901
902  " link aaa --> ccc; clear aaa; check aaa --> bbb
903  hi link aaa ccc
904  let id_ccc = hlID('ccc')
905  call assert_equal(synIDtrans(id_aaa), id_ccc)
906  hi clear aaa
907  call assert_equal(HighlightArgs('aaa'), hl_aaa_bbb)
908
909  " forcibly set default link aaa --> ddd
910  hi! def link aaa ddd
911  let id_ddd = hlID('ddd')
912  let hl_aaa_ddd = HighlightArgs('aaa')
913  call assert_equal(synIDtrans(id_aaa), id_ddd)
914
915  " link aaa --> eee; clear aaa; check aaa --> ddd
916  hi link aaa eee
917  let eee_id = hlID('eee')
918  call assert_equal(synIDtrans(id_aaa), eee_id)
919  hi clear aaa
920  call assert_equal(HighlightArgs('aaa'), hl_aaa_ddd)
921endfunc
922
923func Test_highlight_clear_restores_context()
924  func FuncContextDefault()
925    hi def link Context ContextDefault
926  endfun
927
928  func FuncContextRelink()
929    " Dummy line
930    hi link Context ContextRelink
931  endfunc
932
933  let scriptContextDefault = MakeScript("FuncContextDefault")
934  let scriptContextRelink = MakeScript("FuncContextRelink")
935  let patContextDefault = fnamemodify(scriptContextDefault, ':t') .. ' line 1'
936  let patContextRelink = fnamemodify(scriptContextRelink, ':t') .. ' line 2'
937
938  exec 'source ' .. scriptContextDefault
939  let hlContextDefault = execute("verbose hi Context")
940  call assert_match(patContextDefault, hlContextDefault)
941
942  exec 'source ' .. scriptContextRelink
943  let hlContextRelink = execute("verbose hi Context")
944  call assert_match(patContextRelink, hlContextRelink)
945
946  hi clear
947  let hlContextAfterClear = execute("verbose hi Context")
948  call assert_match(patContextDefault, hlContextAfterClear)
949
950  delfunc FuncContextDefault
951  delfunc FuncContextRelink
952  call delete(scriptContextDefault)
953  call delete(scriptContextRelink)
954endfunc
955
956func Test_highlight_default_colorscheme_restores_links()
957  hi link TestLink Identifier
958  hi TestHi ctermbg=red
959
960  let hlTestLinkPre = HighlightArgs('TestLink')
961  let hlTestHiPre = HighlightArgs('TestHi')
962
963  " Test colorscheme
964  call assert_equal("\ndefault", execute('colorscheme'))
965  hi clear
966  if exists('syntax_on')
967    syntax reset
968  endif
969  let g:colors_name = 'test'
970  call assert_equal("\ntest", execute('colorscheme'))
971  hi link TestLink ErrorMsg
972  hi TestHi ctermbg=green
973
974  " Restore default highlighting
975  colorscheme default
976  " 'default' should work no matter if highlight group was cleared
977  call assert_equal("\ndefault", execute('colorscheme'))
978  hi def link TestLink Identifier
979  hi def TestHi ctermbg=red
980  let hlTestLinkPost = HighlightArgs('TestLink')
981  let hlTestHiPost = HighlightArgs('TestHi')
982  call assert_equal(hlTestLinkPre, hlTestLinkPost)
983  call assert_equal(hlTestHiPre, hlTestHiPost)
984  hi clear
985endfunc
986
987" vim: shiftwidth=2 sts=2 expandtab