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