1" Tests for ":highlight" and highlighting.
2
3source view_util.vim
4source screendump.vim
5source check.vim
6
7func Test_highlight()
8  " basic test if ":highlight" doesn't crash
9  highlight
10  hi Search
11
12  " test setting colors.
13  " test clearing one color and all doesn't generate error or warning
14  silent! hi NewGroup term=bold cterm=italic ctermfg=DarkBlue ctermbg=Grey gui= guifg=#00ff00 guibg=Cyan
15  silent! hi Group2 term= cterm=
16  hi Group3 term=underline cterm=bold
17
18  let res = split(execute("hi NewGroup"), "\n")[0]
19  " filter ctermfg and ctermbg, the numbers depend on the terminal
20  let res = substitute(res, 'ctermfg=\d*', 'ctermfg=2', '')
21  let res = substitute(res, 'ctermbg=\d*', 'ctermbg=3', '')
22  call assert_equal("NewGroup       xxx term=bold cterm=italic ctermfg=2 ctermbg=3",
23				\ res)
24  call assert_equal("Group2         xxx cleared",
25				\ split(execute("hi Group2"), "\n")[0])
26  call assert_equal("Group3         xxx term=underline cterm=bold",
27				\ split(execute("hi Group3"), "\n")[0])
28
29  hi clear NewGroup
30  call assert_equal("NewGroup       xxx cleared",
31				\ split(execute("hi NewGroup"), "\n")[0])
32  call assert_equal("Group2         xxx cleared",
33				\ split(execute("hi Group2"), "\n")[0])
34  hi Group2 NONE
35  call assert_equal("Group2         xxx cleared",
36				\ split(execute("hi Group2"), "\n")[0])
37  hi clear
38  call assert_equal("Group3         xxx cleared",
39				\ split(execute("hi Group3"), "\n")[0])
40  call assert_fails("hi Crash term='asdf", "E475:")
41endfunc
42
43func HighlightArgs(name)
44  return 'hi ' . substitute(split(execute('hi ' . a:name), '\n')[0], '\<xxx\>', '', '')
45endfunc
46
47func IsColorable()
48  return has('gui_running') || str2nr(&t_Co) >= 8
49endfunc
50
51func HiCursorLine()
52  let hiCursorLine = HighlightArgs('CursorLine')
53  if has('gui_running')
54    let guibg = matchstr(hiCursorLine, 'guibg=\w\+')
55    let hi_ul = 'hi CursorLine gui=underline guibg=NONE'
56    let hi_bg = 'hi CursorLine gui=NONE ' . guibg
57  else
58    let hi_ul = 'hi CursorLine cterm=underline ctermbg=NONE'
59    let hi_bg = 'hi CursorLine cterm=NONE ctermbg=Gray'
60  endif
61  return [hiCursorLine, hi_ul, hi_bg]
62endfunc
63
64func Check_lcs_eol_attrs(attrs, row, col)
65  let save_lcs = &lcs
66  set list
67
68  call assert_equal(a:attrs, ScreenAttrs(a:row, a:col)[0])
69
70  set nolist
71  let &lcs = save_lcs
72endfunc
73
74func Test_highlight_eol_with_cursorline()
75  let [hiCursorLine, hi_ul, hi_bg] = HiCursorLine()
76
77  call NewWindow('topleft 5', 20)
78  call setline(1, 'abcd')
79  call matchadd('Search', '\n')
80
81  " expected:
82  " 'abcd      '
83  "  ^^^^ ^^^^^   no highlight
84  "      ^        'Search' highlight
85  let attrs0 = ScreenAttrs(1, 10)[0]
86  call assert_equal(repeat([attrs0[0]], 4), attrs0[0:3])
87  call assert_equal(repeat([attrs0[0]], 5), attrs0[5:9])
88  call assert_notequal(attrs0[0], attrs0[4])
89
90  setlocal cursorline
91
92  " underline
93  exe hi_ul
94
95  " expected:
96  " 'abcd      '
97  "  ^^^^         underline
98  "      ^        'Search' highlight with underline
99  "       ^^^^^   underline
100  let attrs = ScreenAttrs(1, 10)[0]
101  call assert_equal(repeat([attrs[0]], 4), attrs[0:3])
102  call assert_equal([attrs[4]] + repeat([attrs[5]], 5), attrs[4:9])
103  call assert_notequal(attrs[0], attrs[4])
104  call assert_notequal(attrs[4], attrs[5])
105  call assert_notequal(attrs0[0], attrs[0])
106  call assert_notequal(attrs0[4], attrs[4])
107  call Check_lcs_eol_attrs(attrs, 1, 10)
108
109  if IsColorable()
110    " bg-color
111    exe hi_bg
112
113    " expected:
114    " 'abcd      '
115    "  ^^^^         bg-color of 'CursorLine'
116    "      ^        'Search' highlight
117    "       ^^^^^   bg-color of 'CursorLine'
118    let attrs = ScreenAttrs(1, 10)[0]
119    call assert_equal(repeat([attrs[0]], 4), attrs[0:3])
120    call assert_equal(repeat([attrs[5]], 5), attrs[5:9])
121    call assert_equal(attrs0[4], attrs[4])
122    call assert_notequal(attrs[0], attrs[4])
123    call assert_notequal(attrs[4], attrs[5])
124    call assert_notequal(attrs0[0], attrs[0])
125    call assert_notequal(attrs0[5], attrs[5])
126    call Check_lcs_eol_attrs(attrs, 1, 10)
127  endif
128
129  call CloseWindow()
130  exe hiCursorLine
131endfunc
132
133func Test_highlight_eol_with_cursorline_vertsplit()
134  let [hiCursorLine, hi_ul, hi_bg] = HiCursorLine()
135
136  call NewWindow('topleft 5', 5)
137  call setline(1, 'abcd')
138  call matchadd('Search', '\n')
139
140  let expected = "abcd |abcd     "
141  let actual = ScreenLines(1, 15)[0]
142  call assert_equal(expected, actual)
143
144  " expected:
145  " 'abcd |abcd     '
146  "  ^^^^  ^^^^^^^^^   no highlight
147  "      ^             'Search' highlight
148  "       ^            'VertSplit' highlight
149  let attrs0 = ScreenAttrs(1, 15)[0]
150  call assert_equal(repeat([attrs0[0]], 4), attrs0[0:3])
151  call assert_equal(repeat([attrs0[0]], 9), attrs0[6:14])
152  call assert_notequal(attrs0[0], attrs0[4])
153  call assert_notequal(attrs0[0], attrs0[5])
154  call assert_notequal(attrs0[4], attrs0[5])
155
156  setlocal cursorline
157
158  " expected:
159  " 'abcd |abcd     '
160  "  ^^^^              underline
161  "      ^             'Search' highlight with underline
162  "       ^            'VertSplit' highlight
163  "        ^^^^^^^^^   no highlight
164
165  " underline
166  exe hi_ul
167
168  let actual = ScreenLines(1, 15)[0]
169  call assert_equal(expected, actual)
170
171  let attrs = ScreenAttrs(1, 15)[0]
172  call assert_equal(repeat([attrs[0]], 4), attrs[0:3])
173  call assert_equal(repeat([attrs[6]], 9), attrs[6:14])
174  call assert_equal(attrs0[5:14], attrs[5:14])
175  call assert_notequal(attrs[0], attrs[4])
176  call assert_notequal(attrs[0], attrs[5])
177  call assert_notequal(attrs[0], attrs[6])
178  call assert_notequal(attrs[4], attrs[5])
179  call assert_notequal(attrs[5], attrs[6])
180  call assert_notequal(attrs0[0], attrs[0])
181  call assert_notequal(attrs0[4], attrs[4])
182  call Check_lcs_eol_attrs(attrs, 1, 15)
183
184  if IsColorable()
185    " bg-color
186    exe hi_bg
187
188    let actual = ScreenLines(1, 15)[0]
189    call assert_equal(expected, actual)
190
191    let attrs = ScreenAttrs(1, 15)[0]
192    call assert_equal(repeat([attrs[0]], 4), attrs[0:3])
193    call assert_equal(repeat([attrs[6]], 9), attrs[6:14])
194    call assert_equal(attrs0[5:14], attrs[5:14])
195    call assert_notequal(attrs[0], attrs[4])
196    call assert_notequal(attrs[0], attrs[5])
197    call assert_notequal(attrs[0], attrs[6])
198    call assert_notequal(attrs[4], attrs[5])
199    call assert_notequal(attrs[5], attrs[6])
200    call assert_notequal(attrs0[0], attrs[0])
201    call assert_equal(attrs0[4], attrs[4])
202    call Check_lcs_eol_attrs(attrs, 1, 15)
203  endif
204
205  call CloseWindow()
206  exe hiCursorLine
207endfunc
208
209func Test_highlight_eol_with_cursorline_rightleft()
210  CheckFeature rightleft
211
212  let [hiCursorLine, hi_ul, hi_bg] = HiCursorLine()
213
214  call NewWindow('topleft 5', 10)
215  setlocal rightleft
216  call setline(1, 'abcd')
217  call matchadd('Search', '\n')
218  let attrs0 = ScreenAttrs(1, 10)[0]
219
220  setlocal cursorline
221
222  " underline
223  exe hi_ul
224
225  " expected:
226  " '      dcba'
227  "        ^^^^   underline
228  "       ^       'Search' highlight with underline
229  "  ^^^^^        underline
230  let attrs = ScreenAttrs(1, 10)[0]
231  call assert_equal(repeat([attrs[9]], 4), attrs[6:9])
232  call assert_equal(repeat([attrs[4]], 5) + [attrs[5]], attrs[0:5])
233  call assert_notequal(attrs[9], attrs[5])
234  call assert_notequal(attrs[4], attrs[5])
235  call assert_notequal(attrs0[9], attrs[9])
236  call assert_notequal(attrs0[5], attrs[5])
237  call Check_lcs_eol_attrs(attrs, 1, 10)
238
239  if IsColorable()
240    " bg-color
241    exe hi_bg
242
243    " expected:
244    " '      dcba'
245    "        ^^^^   bg-color of 'CursorLine'
246    "       ^       'Search' highlight
247    "  ^^^^^        bg-color of 'CursorLine'
248    let attrs = ScreenAttrs(1, 10)[0]
249    call assert_equal(repeat([attrs[9]], 4), attrs[6:9])
250    call assert_equal(repeat([attrs[4]], 5), attrs[0:4])
251    call assert_equal(attrs0[5], attrs[5])
252    call assert_notequal(attrs[9], attrs[5])
253    call assert_notequal(attrs[5], attrs[4])
254    call assert_notequal(attrs0[9], attrs[9])
255    call assert_notequal(attrs0[4], attrs[4])
256    call Check_lcs_eol_attrs(attrs, 1, 10)
257  endif
258
259  call CloseWindow()
260  exe hiCursorLine
261endfunc
262
263func Test_highlight_eol_with_cursorline_linewrap()
264  let [hiCursorLine, hi_ul, hi_bg] = HiCursorLine()
265
266  call NewWindow('topleft 5', 10)
267  call setline(1, [repeat('a', 51) . 'bcd', ''])
268  call matchadd('Search', '\n')
269
270  setlocal wrap
271  normal! gg$
272  let attrs0 = ScreenAttrs(5, 10)[0]
273  setlocal cursorline
274
275  " underline
276  exe hi_ul
277
278  " expected:
279  " 'abcd      '
280  "  ^^^^         underline
281  "      ^        'Search' highlight with underline
282  "       ^^^^^   underline
283  let attrs = ScreenAttrs(5, 10)[0]
284  call assert_equal(repeat([attrs[0]], 4), attrs[0:3])
285  call assert_equal([attrs[4]] + repeat([attrs[5]], 5), attrs[4:9])
286  call assert_notequal(attrs[0], attrs[4])
287  call assert_notequal(attrs[4], attrs[5])
288  call assert_notequal(attrs0[0], attrs[0])
289  call assert_notequal(attrs0[4], attrs[4])
290  call Check_lcs_eol_attrs(attrs, 5, 10)
291
292  if IsColorable()
293    " bg-color
294    exe hi_bg
295
296    " expected:
297    " 'abcd      '
298    "  ^^^^         bg-color of 'CursorLine'
299    "      ^        'Search' highlight
300    "       ^^^^^   bg-color of 'CursorLine'
301    let attrs = ScreenAttrs(5, 10)[0]
302    call assert_equal(repeat([attrs[0]], 4), attrs[0:3])
303    call assert_equal(repeat([attrs[5]], 5), attrs[5:9])
304    call assert_equal(attrs0[4], attrs[4])
305    call assert_notequal(attrs[0], attrs[4])
306    call assert_notequal(attrs[4], attrs[5])
307    call assert_notequal(attrs0[0], attrs[0])
308    call assert_notequal(attrs0[5], attrs[5])
309    call Check_lcs_eol_attrs(attrs, 5, 10)
310  endif
311
312  setlocal nocursorline nowrap
313  normal! gg$
314  let attrs0 = ScreenAttrs(1, 10)[0]
315  setlocal cursorline
316
317  " underline
318  exe hi_ul
319
320  " expected:
321  " 'aaabcd    '
322  "  ^^^^^^       underline
323  "        ^      'Search' highlight with underline
324  "         ^^^   underline
325  let attrs = ScreenAttrs(1, 10)[0]
326  call assert_equal(repeat([attrs[0]], 6), attrs[0:5])
327  call assert_equal([attrs[6]] + repeat([attrs[7]], 3), attrs[6:9])
328  call assert_notequal(attrs[0], attrs[6])
329  call assert_notequal(attrs[6], attrs[7])
330  call assert_notequal(attrs0[0], attrs[0])
331  call assert_notequal(attrs0[6], attrs[6])
332  call Check_lcs_eol_attrs(attrs, 1, 10)
333
334  if IsColorable()
335    " bg-color
336    exe hi_bg
337
338    " expected:
339    " 'aaabcd    '
340    "  ^^^^^^       bg-color of 'CursorLine'
341    "        ^      'Search' highlight
342    "         ^^^   bg-color of 'CursorLine'
343    let attrs = ScreenAttrs(1, 10)[0]
344    call assert_equal(repeat([attrs[0]], 6), attrs[0:5])
345    call assert_equal(repeat([attrs[7]], 3), attrs[7:9])
346    call assert_equal(attrs0[6], attrs[6])
347    call assert_notequal(attrs[0], attrs[6])
348    call assert_notequal(attrs[6], attrs[7])
349    call assert_notequal(attrs0[0], attrs[0])
350    call assert_notequal(attrs0[7], attrs[7])
351    call Check_lcs_eol_attrs(attrs, 1, 10)
352  endif
353
354  call CloseWindow()
355  exe hiCursorLine
356endfunc
357
358func Test_highlight_eol_with_cursorline_sign()
359  CheckFeature signs
360
361  let [hiCursorLine, hi_ul, hi_bg] = HiCursorLine()
362
363  call NewWindow('topleft 5', 10)
364  call setline(1, 'abcd')
365  call matchadd('Search', '\n')
366
367  sign define Sign text=>>
368  exe 'sign place 1 line=1 name=Sign buffer=' . bufnr('')
369  let attrs0 = ScreenAttrs(1, 10)[0]
370  setlocal cursorline
371
372  " underline
373  exe hi_ul
374
375  " expected:
376  " '>>abcd    '
377  "  ^^           sign
378  "    ^^^^       underline
379  "        ^      'Search' highlight with underline
380  "         ^^^   underline
381  let attrs = ScreenAttrs(1, 10)[0]
382  call assert_equal(repeat([attrs[2]], 4), attrs[2:5])
383  call assert_equal([attrs[6]] + repeat([attrs[7]], 3), attrs[6:9])
384  call assert_notequal(attrs[2], attrs[6])
385  call assert_notequal(attrs[6], attrs[7])
386  call assert_notequal(attrs0[2], attrs[2])
387  call assert_notequal(attrs0[6], attrs[6])
388  call Check_lcs_eol_attrs(attrs, 1, 10)
389
390  if IsColorable()
391    " bg-color
392    exe hi_bg
393
394    " expected:
395    " '>>abcd    '
396    "  ^^           sign
397    "    ^^^^       bg-color of 'CursorLine'
398    "        ^      'Search' highlight
399    "         ^^^   bg-color of 'CursorLine'
400    let attrs = ScreenAttrs(1, 10)[0]
401    call assert_equal(repeat([attrs[2]], 4), attrs[2:5])
402    call assert_equal(repeat([attrs[7]], 3), attrs[7:9])
403    call assert_equal(attrs0[6], attrs[6])
404    call assert_notequal(attrs[2], attrs[6])
405    call assert_notequal(attrs[6], attrs[7])
406    call assert_notequal(attrs0[2], attrs[2])
407    call assert_notequal(attrs0[7], attrs[7])
408    call Check_lcs_eol_attrs(attrs, 1, 10)
409  endif
410
411  sign unplace 1
412  call CloseWindow()
413  exe hiCursorLine
414endfunc
415
416func Test_highlight_eol_with_cursorline_breakindent()
417  CheckFeature linebreak
418
419  let [hiCursorLine, hi_ul, hi_bg] = HiCursorLine()
420
421  call NewWindow('topleft 5', 10)
422  set showbreak=xxx
423  setlocal breakindent breakindentopt=min:0,shift:1 showbreak=>
424  call setline(1, ' ' . repeat('a', 9) . 'bcd')
425  call matchadd('Search', '\n')
426  let attrs0 = ScreenAttrs(2, 10)[0]
427  setlocal cursorline
428
429  " underline
430  exe hi_ul
431
432  " expected:
433  " '  >bcd    '
434  "  ^^^          breakindent and showbreak
435  "     ^^^       underline
436  "        ^      'Search' highlight with underline
437  "         ^^^   underline
438  let attrs = ScreenAttrs(2, 10)[0]
439  call assert_equal(repeat([attrs[0]], 2), attrs[0:1])
440  call assert_equal(repeat([attrs[3]], 3), attrs[3:5])
441  call assert_equal([attrs[6]] + repeat([attrs[7]], 3), attrs[6:9])
442  call assert_equal(attrs0[0], attrs[0])
443  call assert_notequal(attrs[0], attrs[2])
444  call assert_notequal(attrs[2], attrs[3])
445  call assert_notequal(attrs[3], attrs[6])
446  call assert_notequal(attrs[6], attrs[7])
447  call assert_notequal(attrs0[2], attrs[2])
448  call assert_notequal(attrs0[3], attrs[3])
449  call assert_notequal(attrs0[6], attrs[6])
450  call Check_lcs_eol_attrs(attrs, 2, 10)
451
452  if IsColorable()
453    " bg-color
454    exe hi_bg
455
456    " expected:
457    " '  >bcd    '
458    "  ^^^          breakindent and showbreak
459    "     ^^^       bg-color of 'CursorLine'
460    "        ^      'Search' highlight
461    "         ^^^   bg-color of 'CursorLine'
462    let attrs = ScreenAttrs(2, 10)[0]
463    call assert_equal(repeat([attrs[0]], 2), attrs[0:1])
464    call assert_equal(repeat([attrs[3]], 3), attrs[3:5])
465    call assert_equal(repeat([attrs[7]], 3), attrs[7:9])
466    call assert_equal(attrs0[0], attrs[0])
467    call assert_equal(attrs0[6], attrs[6])
468    call assert_notequal(attrs[0], attrs[2])
469    call assert_notequal(attrs[2], attrs[3])
470    call assert_notequal(attrs[3], attrs[6])
471    call assert_notequal(attrs[6], attrs[7])
472    call assert_notequal(attrs0[2], attrs[2])
473    call assert_notequal(attrs0[3], attrs[3])
474    call assert_notequal(attrs0[7], attrs[7])
475    call Check_lcs_eol_attrs(attrs, 2, 10)
476  endif
477
478  call CloseWindow()
479  set showbreak=
480  setlocal showbreak=
481  exe hiCursorLine
482endfunc
483
484func Test_highlight_eol_on_diff()
485  call setline(1, ['abcd', ''])
486  call matchadd('Search', '\n')
487  let attrs0 = ScreenAttrs(1, 10)[0]
488
489  diffthis
490  botright new
491  diffthis
492
493  " expected:
494  " '  abcd    '
495  "  ^^           sign
496  "    ^^^^ ^^^   'DiffAdd' highlight
497  "        ^      'Search' highlight
498  let attrs = ScreenAttrs(1, 10)[0]
499  call assert_equal(repeat([attrs[0]], 2), attrs[0:1])
500  call assert_equal(repeat([attrs[2]], 4), attrs[2:5])
501  call assert_equal(repeat([attrs[2]], 3), attrs[7:9])
502  call assert_equal(attrs0[4], attrs[6])
503  call assert_notequal(attrs[0], attrs[2])
504  call assert_notequal(attrs[0], attrs[6])
505  call assert_notequal(attrs[2], attrs[6])
506  call Check_lcs_eol_attrs(attrs, 1, 10)
507
508  bwipe!
509  diffoff
510endfunc
511
512func Test_termguicolors()
513  CheckOption termguicolors
514  if has('vtp') && !has('vcon') && !has('gui_running')
515    " Win32: 'guicolors' doesn't work without virtual console.
516    call assert_fails('set termguicolors', 'E954:')
517    return
518  endif
519
520  " Basic test that setting 'termguicolors' works with one color.
521  set termguicolors
522  redraw
523  set t_Co=1
524  redraw
525  set t_Co=0
526  redraw
527endfunc
528
529func Test_cursorline_after_yank()
530  CheckScreendump
531
532  call writefile([
533	\ 'set cul rnu',
534	\ 'call setline(1, ["","1","2","3",""])',
535	\ ], 'Xtest_cursorline_yank')
536  let buf = RunVimInTerminal('-S Xtest_cursorline_yank', {'rows': 8})
537  call TermWait(buf)
538  call term_sendkeys(buf, "Gy3k")
539  call TermWait(buf)
540  call term_sendkeys(buf, "jj")
541
542  call VerifyScreenDump(buf, 'Test_cursorline_yank_01', {})
543
544  " clean up
545  call StopVimInTerminal(buf)
546  call delete('Xtest_cursorline_yank')
547endfunc
548
549" test for issue #4862
550func Test_put_before_cursorline()
551  new
552  only!
553  call setline(1, 'A')
554  redraw
555  let std_attr = screenattr(1, 1)
556  set cursorline
557  redraw
558  let cul_attr = screenattr(1, 1)
559  normal yyP
560  redraw
561  " Line 1 has cursor so it should be highlighted with CursorLine.
562  call assert_equal(cul_attr, screenattr(1, 1))
563  " And CursorLine highlighting from the second line should be gone.
564  call assert_equal(std_attr, screenattr(2, 1))
565  set nocursorline
566  bwipe!
567endfunc
568
569func Test_cursorline_with_visualmode()
570  CheckScreendump
571
572  call writefile([
573	\ 'set cul',
574	\ 'call setline(1, repeat(["abc"], 50))',
575	\ ], 'Xtest_cursorline_with_visualmode')
576  let buf = RunVimInTerminal('-S Xtest_cursorline_with_visualmode', {'rows': 12})
577  call TermWait(buf)
578  call term_sendkeys(buf, "V\<C-f>kkkjk")
579
580  call VerifyScreenDump(buf, 'Test_cursorline_with_visualmode_01', {})
581
582  " clean up
583  call StopVimInTerminal(buf)
584  call delete('Xtest_cursorline_with_visualmode')
585endfunc
586
587func Test_wincolor()
588  CheckScreendump
589  " make sure the width is enough for the test
590  set columns=80
591
592  let lines =<< trim END
593	set cursorline cursorcolumn rnu
594	call setline(1, ["","1111111111","22222222222","3 here 3","","the cat is out of the bag"])
595	set wincolor=Pmenu
596	hi CatLine guifg=green ctermfg=green
597	hi Reverse gui=reverse cterm=reverse
598	syn match CatLine /^the.*/
599	call prop_type_add("foo", {"highlight": "Reverse", "combine": 1})
600	call prop_add(6, 12, {"type": "foo", "end_col": 15})
601	/here
602  END
603  call writefile(lines, 'Xtest_wincolor')
604  let buf = RunVimInTerminal('-S Xtest_wincolor', {'rows': 8})
605  call TermWait(buf)
606  call term_sendkeys(buf, "2G5lvj")
607  call TermWait(buf)
608
609  call VerifyScreenDump(buf, 'Test_wincolor_01', {})
610
611  " clean up
612  call term_sendkeys(buf, "\<Esc>")
613  call StopVimInTerminal(buf)
614  call delete('Xtest_wincolor')
615endfunc
616
617func Test_wincolor_listchars()
618  CheckScreendump
619  CheckFeature conceal
620
621  let lines =<< trim END
622	call setline(1, ["one","\t\tsome random text enough long to show 'extends' and 'precedes' includingnbsps, preceding tabs and trailing spaces    ","three"])
623	set wincolor=Todo
624	set nowrap cole=1 cocu+=n
625	set list lcs=eol:$,tab:>-,space:.,trail:_,extends:>,precedes:<,conceal:*,nbsp:#
626	call matchadd('Conceal', 'text')
627	normal 2G5zl
628  END
629  call writefile(lines, 'Xtest_wincolorlcs')
630  let buf = RunVimInTerminal('-S Xtest_wincolorlcs', {'rows': 8})
631
632  call VerifyScreenDump(buf, 'Test_wincolor_lcs', {})
633
634  " clean up
635  call term_sendkeys(buf, "\<Esc>")
636  call StopVimInTerminal(buf)
637  call delete('Xtest_wincolorlcs')
638endfunc
639
640func Test_colorcolumn()
641  CheckScreendump
642
643  " check that setting 'colorcolumn' when entering a buffer works
644  let lines =<< trim END
645	split
646	edit X
647	call setline(1, ["1111111111","22222222222","3333333333"])
648	set nomodified
649	set colorcolumn=3,9
650	set number cursorline cursorlineopt=number
651	wincmd w
652	buf X
653  END
654  call writefile(lines, 'Xtest_colorcolumn')
655  let buf = RunVimInTerminal('-S Xtest_colorcolumn', {'rows': 10})
656  call term_sendkeys(buf, ":\<CR>")
657  call TermWait(buf)
658  call VerifyScreenDump(buf, 'Test_colorcolumn_1', {})
659
660  " clean up
661  call StopVimInTerminal(buf)
662  call delete('Xtest_colorcolumn')
663endfunc
664
665" This test must come before the Test_cursorline test, as it appears this
666" defines the Normal highlighting group anyway.
667func Test_1_highlight_Normalgroup_exists()
668  let hlNormal = HighlightArgs('Normal')
669  if !has('gui_running')
670    call assert_match('hi Normal\s*clear', hlNormal)
671  elseif has('gui_gtk2') || has('gui_gnome') || has('gui_gtk3')
672    " expect is DEFAULT_FONT of gui_gtk_x11.c
673    call assert_match('hi Normal\s*font=Monospace 10', hlNormal)
674  elseif has('gui_motif') || has('gui_athena')
675    " expect is DEFAULT_FONT of gui_x11.c
676    call assert_match('hi Normal\s*font=7x13', hlNormal)
677  elseif has('win32')
678    " expect any font
679    call assert_match('hi Normal\s*font=.*', hlNormal)
680  endif
681endfunc
682
683" Do this test last, sometimes restoring the columns doesn't work
684func Test_z_no_space_before_xxx()
685  let l:org_columns = &columns
686  set columns=17
687  let l:hi_StatusLineTermNC = join(split(execute('hi StatusLineTermNC')))
688  call assert_match('StatusLineTermNC xxx', l:hi_StatusLineTermNC)
689  let &columns = l:org_columns
690endfunc
691
692" Test for :highlight command errors
693func Test_highlight_cmd_errors()
694  if has('gui_running')
695    " This test doesn't fail in the MS-Windows console version.
696    call assert_fails('hi Xcomment ctermbg=fg', 'E419:')
697    call assert_fails('hi Xcomment ctermfg=bg', 'E420:')
698    call assert_fails('hi Xcomment ctermfg=ul', 'E453:')
699  endif
700
701  " Try using a very long terminal code. Define a dummy terminal code for this
702  " test.
703  let &t_fo = "\<Esc>1;"
704  let c = repeat("t_fo,", 100) . "t_fo"
705  call assert_fails('exe "hi Xgroup1 start=" . c', 'E422:')
706  let &t_fo = ""
707endfunc
708
709" Test for 'highlight' option
710func Test_highlight_opt()
711  let save_hl = &highlight
712  call assert_fails('set highlight=j:b', 'E474:')
713  set highlight=f\ r
714  call assert_equal('f r', &highlight)
715  set highlight=fb
716  call assert_equal('fb', &highlight)
717  set highlight=fi
718  call assert_equal('fi', &highlight)
719  set highlight=f-
720  call assert_equal('f-', &highlight)
721  set highlight=fr
722  call assert_equal('fr', &highlight)
723  set highlight=fs
724  call assert_equal('fs', &highlight)
725  set highlight=fu
726  call assert_equal('fu', &highlight)
727  set highlight=fc
728  call assert_equal('fc', &highlight)
729  set highlight=ft
730  call assert_equal('ft', &highlight)
731  call assert_fails('set highlight=fr:Search', 'E474:')
732  set highlight=f:$#
733  call assert_match('W18:', v:statusmsg)
734  let &highlight = save_hl
735endfunc
736
737" Test for User group highlighting used in the statusline
738func Test_highlight_User()
739  CheckNotGui
740  hi User1 ctermfg=12
741  redraw!
742  call assert_equal('12', synIDattr(synIDtrans(hlID('User1')), 'fg'))
743  hi clear
744endfunc
745
746" Test for using RGB color values in a highlight group
747func Test_highlight_RGB_color()
748  CheckGui
749  hi MySearch guifg=#110000 guibg=#001100 guisp=#000011
750  call assert_equal('#110000', synIDattr(synIDtrans(hlID('MySearch')), 'fg#'))
751  call assert_equal('#001100', synIDattr(synIDtrans(hlID('MySearch')), 'bg#'))
752  call assert_equal('#000011', synIDattr(synIDtrans(hlID('MySearch')), 'sp#'))
753  hi clear
754endfunc
755
756" Test for using default highlighting group
757func Test_highlight_default()
758  highlight MySearch ctermfg=7
759  highlight default MySearch ctermfg=5
760  let hlSearch = HighlightArgs('MySearch')
761  call assert_match('ctermfg=7', hlSearch)
762
763  highlight default QFName ctermfg=3
764  call assert_match('ctermfg=3', HighlightArgs('QFName'))
765  hi clear
766endfunc
767
768" Test for 'ctermul in a highlight group
769func Test_highlight_ctermul()
770  CheckNotGui
771  call assert_notmatch('ctermul=', HighlightArgs('Normal'))
772  highlight Normal ctermul=3
773  call assert_match('ctermul=3', HighlightArgs('Normal'))
774  highlight Normal ctermul=NONE
775endfunc
776
777" Test for specifying 'start' and 'stop' in a highlight group
778func Test_highlight_start_stop()
779  hi HlGrp1 start=<Esc>[27h;<Esc>[<Space>r;
780  call assert_match("start=^[[27h;^[[ r;", HighlightArgs('HlGrp1'))
781  hi HlGrp1 start=NONE
782  call assert_notmatch("start=", HighlightArgs('HlGrp1'))
783  hi HlGrp2 stop=<Esc>[27h;<Esc>[<Space>r;
784  call assert_match("stop=^[[27h;^[[ r;", HighlightArgs('HlGrp2'))
785  hi HlGrp2 stop=NONE
786  call assert_notmatch("stop=", HighlightArgs('HlGrp2'))
787  hi clear
788endfunc
789
790" Test for setting various 'term' attributes
791func Test_highlight_term_attr()
792  hi HlGrp3 term=bold,underline,undercurl,strikethrough,reverse,italic,standout
793  call assert_equal('hi HlGrp3          term=bold,standout,underline,undercurl,italic,reverse,strikethrough', HighlightArgs('HlGrp3'))
794  hi HlGrp3 term=NONE
795  call assert_equal('hi HlGrp3          cleared', HighlightArgs('HlGrp3'))
796  hi clear
797endfunc
798
799" vim: shiftwidth=2 sts=2 expandtab
800