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