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 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 43 44func HighlightArgs(name) 45 return 'hi ' . substitute(split(execute('hi ' . a:name), '\n')[0], '\<xxx\>', '', '') 46endfunc 47 48func IsColorable() 49 return has('gui_running') || str2nr(&t_Co) >= 8 50endfunc 51 52func HiCursorLine() 53 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] 63endfunc 64 65func Check_lcs_eol_attrs(attrs, row, col) 66 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 73endfunc 74 75func 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 99 " ^ 'Search' highlight with underline 100 " ^^^^^ underline 101 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]) 108 call Check_lcs_eol_attrs(attrs, 1, 10) 109 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]) 127 call Check_lcs_eol_attrs(attrs, 1, 10) 128 endif 129 130 call CloseWindow() 131 exe hiCursorLine 132endfunc 133 134func Test_highlight_eol_with_cursorline_vertsplit() 135 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]) 183 call Check_lcs_eol_attrs(attrs, 1, 15) 184 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]) 203 call Check_lcs_eol_attrs(attrs, 1, 15) 204 endif 205 206 call CloseWindow() 207 exe hiCursorLine 208endfunc 209 210func Test_highlight_eol_with_cursorline_rightleft() 211 CheckFeature rightleft 212 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]) 238 call Check_lcs_eol_attrs(attrs, 1, 10) 239 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]) 257 call Check_lcs_eol_attrs(attrs, 1, 10) 258 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]) 291 call Check_lcs_eol_attrs(attrs, 5, 10) 292 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]) 310 call Check_lcs_eol_attrs(attrs, 5, 10) 311 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]) 333 call Check_lcs_eol_attrs(attrs, 1, 10) 334 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]) 352 call Check_lcs_eol_attrs(attrs, 1, 10) 353 endif 354 355 call CloseWindow() 356 exe hiCursorLine 357endfunc 358 359func Test_highlight_eol_with_cursorline_sign() 360 CheckFeature signs 361 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]) 389 call Check_lcs_eol_attrs(attrs, 1, 10) 390 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]) 409 call Check_lcs_eol_attrs(attrs, 1, 10) 410 endif 411 412 sign unplace 1 413 call CloseWindow() 414 exe hiCursorLine 415endfunc 416 417func Test_highlight_eol_with_cursorline_breakindent() 418 CheckFeature linebreak 419 420 let [hiCursorLine, hi_ul, hi_bg] = HiCursorLine() 421 422 call NewWindow('topleft 5', 10) 423 set showbreak=xxx 424 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]) 451 call Check_lcs_eol_attrs(attrs, 2, 10) 452 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]) 476 call Check_lcs_eol_attrs(attrs, 2, 10) 477 endif 478 479 call CloseWindow() 480 set showbreak= 481 setlocal showbreak= 482 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]) 507 call Check_lcs_eol_attrs(attrs, 1, 10) 508 509 bwipe! 510 diffoff 511endfunc 512 513func Test_termguicolors() 514 CheckOption termguicolors 515 if has('vtp') && !has('vcon') && !has('gui_running') 516 " Win32: 'guicolors' doesn't work without virtual console. 517 call assert_fails('set termguicolors', 'E954:') 518 return 519 endif 520 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 529 530func Test_cursorline_after_yank() 531 CheckScreendump 532 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}) 538 call TermWait(buf) 539 call term_sendkeys(buf, "Gy3k") 540 call TermWait(buf) 541 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 549 550" 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 570func Test_cursorline_with_visualmode() 571 CheckScreendump 572 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}) 578 call TermWait(buf) 579 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 587 588func Test_wincolor() 589 CheckScreendump 590 " make sure the width is enough for the test 591 set columns=80 592 593 let lines =<< trim END 594 set cursorline cursorcolumn rnu 595 call setline(1, ["","1111111111","22222222222","3 here 3","","the cat is out of the bag"]) 596 set wincolor=Pmenu 597 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}) 602 /here 603 END 604 call writefile(lines, 'Xtest_wincolor') 605 let buf = RunVimInTerminal('-S Xtest_wincolor', {'rows': 8}) 606 call TermWait(buf) 607 call term_sendkeys(buf, "2G5lvj") 608 call TermWait(buf) 609 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 618func Test_wincolor_listchars() 619 CheckScreendump 620 CheckFeature conceal 621 622 let lines =<< trim END 623 call setline(1, ["one","\t\tsome random text enough long to show 'extends' and 'precedes' includingnbsps, 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 641func 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>") 658 call TermWait(buf) 659 call VerifyScreenDump(buf, 'Test_colorcolumn_1', {}) 660 661 " clean up 662 call StopVimInTerminal(buf) 663 call delete('Xtest_colorcolumn') 664endfunc 665 666func 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 702" This test must come before the Test_cursorline test, as it appears this 703" defines the Normal highlighting group anyway. 704func Test_1_highlight_Normalgroup_exists() 705 let hlNormal = HighlightArgs('Normal') 706 if !has('gui_running') 707 call assert_match('hi Normal\s*clear', hlNormal) 708 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) 717 endif 718endfunc 719 720" Do this test last, sometimes restoring the columns doesn't work 721func Test_z_no_space_before_xxx() 722 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 727endfunc 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. 733 call assert_fails('hi Xcomment ctermbg=fg', 'E419:') 734 call assert_fails('hi Xcomment ctermfg=bg', 'E420:') 735 call assert_fails('hi Xcomment ctermfg=ul', 'E453:') 736 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 746" 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_xxlast_highlight_RGB_color() 785 CheckCanRunGui 786 gui -f 787 hi MySearch guifg=#110000 guibg=#001100 guisp=#000011 788 call assert_equal('#110000', synIDattr(synIDtrans(hlID('MySearch')), 'fg#')) 789 call assert_equal('#001100', synIDattr(synIDtrans(hlID('MySearch')), 'bg#')) 790 call assert_equal('#000011', synIDattr(synIDtrans(hlID('MySearch')), 'sp#')) 791 hi clear 792endfunc 793 794" Test for using default highlighting group 795func Test_highlight_default() 796 highlight MySearch ctermfg=7 797 highlight default MySearch ctermfg=5 798 let hlSearch = HighlightArgs('MySearch') 799 call assert_match('ctermfg=7', hlSearch) 800 801 highlight default QFName ctermfg=3 802 call assert_match('ctermfg=3', HighlightArgs('QFName')) 803 hi clear 804endfunc 805 806" Test for 'ctermul in a highlight group 807func Test_highlight_ctermul() 808 CheckNotGui 809 call assert_notmatch('ctermul=', HighlightArgs('Normal')) 810 highlight Normal ctermul=3 811 call assert_match('ctermul=3', HighlightArgs('Normal')) 812 call assert_equal('3', synIDattr(synIDtrans(hlID('Normal')), 'ul')) 813 highlight Normal ctermul=NONE 814endfunc 815 816" Test for specifying 'start' and 'stop' in a highlight group 817func Test_highlight_start_stop() 818 hi HlGrp1 start=<Esc>[27h;<Esc>[<Space>r; 819 call assert_match("start=^[[27h;^[[ r;", HighlightArgs('HlGrp1')) 820 hi HlGrp1 start=NONE 821 call assert_notmatch("start=", HighlightArgs('HlGrp1')) 822 hi HlGrp2 stop=<Esc>[27h;<Esc>[<Space>r; 823 call assert_match("stop=^[[27h;^[[ r;", HighlightArgs('HlGrp2')) 824 hi HlGrp2 stop=NONE 825 call assert_notmatch("stop=", HighlightArgs('HlGrp2')) 826 hi clear 827endfunc 828 829" Test for setting various 'term' attributes 830func Test_highlight_term_attr() 831 hi HlGrp3 term=bold,underline,undercurl,strikethrough,reverse,italic,standout 832 call assert_equal('hi HlGrp3 term=bold,standout,underline,undercurl,italic,reverse,strikethrough', HighlightArgs('HlGrp3')) 833 hi HlGrp3 term=NONE 834 call assert_equal('hi HlGrp3 cleared', HighlightArgs('HlGrp3')) 835 hi clear 836endfunc 837 838func Test_highlight_clear_restores_links() 839 let aaa_id = hlID('aaa') 840 call assert_equal(aaa_id, 0) 841 842 " create default link aaa --> bbb 843 hi def link aaa bbb 844 let id_aaa = hlID('aaa') 845 let hl_aaa_bbb = HighlightArgs('aaa') 846 847 " try to redefine default link aaa --> ccc; check aaa --> bbb 848 hi def link aaa ccc 849 call assert_equal(HighlightArgs('aaa'), hl_aaa_bbb) 850 851 " clear aaa; check aaa --> bbb 852 hi clear aaa 853 call assert_equal(HighlightArgs('aaa'), hl_aaa_bbb) 854 855 " link aaa --> ccc; clear aaa; check aaa --> bbb 856 hi link aaa ccc 857 let id_ccc = hlID('ccc') 858 call assert_equal(synIDtrans(id_aaa), id_ccc) 859 hi clear aaa 860 call assert_equal(HighlightArgs('aaa'), hl_aaa_bbb) 861 862 " forcibly set default link aaa --> ddd 863 hi! def link aaa ddd 864 let id_ddd = hlID('ddd') 865 let hl_aaa_ddd = HighlightArgs('aaa') 866 call assert_equal(synIDtrans(id_aaa), id_ddd) 867 868 " link aaa --> eee; clear aaa; check aaa --> ddd 869 hi link aaa eee 870 let eee_id = hlID('eee') 871 call assert_equal(synIDtrans(id_aaa), eee_id) 872 hi clear aaa 873 call assert_equal(HighlightArgs('aaa'), hl_aaa_ddd) 874endfunc 875 876func Test_highlight_clear_restores_context() 877 func FuncContextDefault() 878 hi def link Context ContextDefault 879 endfun 880 881 func FuncContextRelink() 882 " Dummy line 883 hi link Context ContextRelink 884 endfunc 885 886 let scriptContextDefault = MakeScript("FuncContextDefault") 887 let scriptContextRelink = MakeScript("FuncContextRelink") 888 let patContextDefault = fnamemodify(scriptContextDefault, ':t') .. ' line 1' 889 let patContextRelink = fnamemodify(scriptContextRelink, ':t') .. ' line 2' 890 891 exec 'source ' .. scriptContextDefault 892 let hlContextDefault = execute("verbose hi Context") 893 call assert_match(patContextDefault, hlContextDefault) 894 895 exec 'source ' .. scriptContextRelink 896 let hlContextRelink = execute("verbose hi Context") 897 call assert_match(patContextRelink, hlContextRelink) 898 899 hi clear 900 let hlContextAfterClear = execute("verbose hi Context") 901 call assert_match(patContextDefault, hlContextAfterClear) 902 903 delfunc FuncContextDefault 904 delfunc FuncContextRelink 905 call delete(scriptContextDefault) 906 call delete(scriptContextRelink) 907endfunc 908 909func Test_highlight_default_colorscheme_restores_links() 910 hi link TestLink Identifier 911 hi TestHi ctermbg=red 912 913 let hlTestLinkPre = HighlightArgs('TestLink') 914 let hlTestHiPre = HighlightArgs('TestHi') 915 916 " Test colorscheme 917 hi clear 918 if exists('syntax_on') 919 syntax reset 920 endif 921 let g:colors_name = 'test' 922 hi link TestLink ErrorMsg 923 hi TestHi ctermbg=green 924 925 " Restore default highlighting 926 colorscheme default 927 " 'default' should work no matter if highlight group was cleared 928 hi def link TestLink Identifier 929 hi def TestHi ctermbg=red 930 let hlTestLinkPost = HighlightArgs('TestLink') 931 let hlTestHiPost = HighlightArgs('TestHi') 932 call assert_equal(hlTestLinkPre, hlTestLinkPost) 933 call assert_equal(hlTestHiPre, hlTestHiPost) 934 hi clear 935endfunc 936 937" vim: shiftwidth=2 sts=2 expandtab 938