robin/laufey
git clone https://git.robinwobin.dev/robin/laufey
f907614088
master
1local t =require ( 'test.testutil' ) 2local n =require ( 'test.functional.testnvim' )() 3local Screen =require ( 'test.functional.ui.screen' ) 4local tt =require ( 'test.functional.testterm' ) 5 6local describe , it , before_each =t . describe , t . it , t . before_each 7local clear , insert =n . clear , n . insert 8local command =n . command 9local api =n . api 10local testprg =n . testprg 11local skip =t . skip 12local is_os =t . is_os 13 14describe ( 'ext_hlstate detailed highlights' , function () 15local screen 16 17before_each ( function () 18clear () 19command ( 'syntax on' ) 20command ( 'hi VertSplit gui=reverse' ) 21screen =Screen . new ( 40 , 8 , { ext_hlstate =true } ) 22end ) 23 24it ( 'work with combined UI and syntax highlights' , function () 25insert ( [[ 26these are some lines 27with colorful text]] ) 28api . nvim_buf_add_highlight ( 0 , - 1 , 'String' , 0 , 10 , 14 ) 29api . nvim_buf_add_highlight ( 0 , - 1 , 'Statement' , 1 , 5 , - 1 ) 30command ( '/th co' ) 31 32screen : expect { 33grid =[[ 34these are {1:some} lines | 35^wi{2:th }{4:co}{3:lorful text} | 36{5:~ }|*5 37{8:search hit BOTTOM, continuing at TOP}{6: }| 38]] , 39attr_ids ={ 40[ 1 ] ={ 41{ foreground =Screen . colors . Magenta1 } , 42{ { kind ='syntax' , hi_name ='Constant' } } , 43} , 44[ 2 ] ={ 45{ background =Screen . colors . Yellow1 } , 46{ { kind ='ui' , ui_name ='Search' , hi_name ='Search' } } , 47} , 48[ 3 ] ={ 49{ foreground =Screen . colors . Brown , bold =true } , 50{ { kind ='syntax' , hi_name ='Statement' } } , 51} , 52[ 4 ] ={ 53{ background =Screen . colors . Yellow1 , bold =true , foreground =Screen . colors . Brown } , 54{ 3 , 2 } , 55} , 56[ 5 ] ={ 57{ foreground =Screen . colors . Blue , bold =true } , 58{ { kind ='ui' , ui_name ='EndOfBuffer' , hi_name ='NonText' } } , 59} , 60[ 6 ] ={ {} , { { kind ='ui' , ui_name ='MsgArea' , hi_name ='MsgArea' } } } , 61[ 7 ] ={ 62{ foreground =Screen . colors . Red1 } , 63{ { kind ='syntax' , hi_name ='WarningMsg' } } , 64} , 65[ 8 ] ={ { foreground =Screen . colors . Red1 } , { 6 , 7 } } , 66} , 67} 68end ) 69 70it ( 'work with cleared UI highlights' , function () 71screen : set_default_attr_ids ( { 72[ 1 ] ={ {} , { { hi_name ='Normal' , ui_name ='WinSeparator' , kind ='ui' } } } , 73[ 2 ] ={ 74{ bold =true , foreground =Screen . colors . Blue1 } , 75{ { hi_name ='NonText' , ui_name ='EndOfBuffer' , kind ='ui' } } , 76} , 77[ 3 ] ={ 78{ bold =true , reverse =true } , 79{ { hi_name ='StatusLine' , ui_name ='StatusLine' , kind ='ui' } } , 80} , 81[ 4 ] ={ 82{ reverse =true } , 83{ { hi_name ='StatusLineNC' , ui_name ='StatusLineNC' , kind ='ui' } } , 84} , 85[ 5 ] ={ {} , { { hi_name ='StatusLine' , ui_name ='StatusLine' , kind ='ui' } } } , 86[ 6 ] ={ {} , { { hi_name ='StatusLineNC' , ui_name ='StatusLineNC' , kind ='ui' } } } , 87[ 7 ] ={ {} , { { hi_name ='MsgArea' , ui_name ='MsgArea' , kind ='ui' } } } , 88} ) 89command ( 'hi clear WinSeparator' ) 90command ( 'vsplit' ) 91 92screen : expect ( [[ 93^ {1:│} | 94{2:~ }{1:│}{2:~ }|*5 95{3:[No Name] }{4:[No Name] }| 96{7: }| 97]] ) 98 99command ( 'hi clear StatusLine | hi clear StatuslineNC' ) 100screen : expect ( [[ 101^ {1:│} | 102{2:~ }{1:│}{2:~ }|*5 103{5:[No Name] }{6:[No Name] }| 104{7: }| 105]] ) 106 107-- redrawing is done even if visible highlights didn't change 108command ( 'wincmd w' ) 109screen : expect ( [[ 110{1:│}^ | 111{2:~ }{1:│}{2:~ }|*5 112{6:[No Name] }{5:[No Name] }| 113{7: }| 114]] ) 115end ) 116 117it ( 'work with window-local highlights' , function () 118screen : set_default_attr_ids ( { 119[ 1 ] ={ 120{ foreground =Screen . colors . Brown } , 121{ { hi_name ='LineNr' , ui_name ='LineNr' , kind ='ui' } } , 122} , 123[ 2 ] ={ 124{ bold =true , foreground =Screen . colors . Blue1 } , 125{ { hi_name ='NonText' , ui_name ='EndOfBuffer' , kind ='ui' } } , 126} , 127[ 3 ] ={ 128{ bold =true , reverse =true } , 129{ { hi_name ='StatusLine' , ui_name ='StatusLine' , kind ='ui' } } , 130} , 131[ 4 ] ={ 132{ reverse =true } , 133{ { hi_name ='StatusLineNC' , ui_name ='StatusLineNC' , kind ='ui' } } , 134} , 135[ 5 ] ={ 136{ background =Screen . colors . Red , foreground =Screen . colors . Grey100 } , 137{ { hi_name ='ErrorMsg' , ui_name ='LineNr' , kind ='ui' } } , 138} , 139[ 6 ] ={ 140{ bold =true , reverse =true } , 141{ { hi_name ='Normal' , ui_name ='Normal' , kind ='ui' } } , 142} , 143[ 7 ] ={ { foreground =Screen . colors . Brown , bold =true , reverse =true } , { 6 , 1 } } , 144[ 8 ] ={ { foreground =Screen . colors . Blue1 , bold =true , reverse =true } , { 6 , 14 } } , 145[ 9 ] ={ 146{ bold =true , foreground =Screen . colors . Brown } , 147{ { hi_name ='NormalNC' , ui_name ='NormalNC' , kind ='ui' } } , 148} , 149[ 10 ] ={ { bold =true , foreground =Screen . colors . Brown } , { 9 , 1 } } , 150[ 11 ] ={ { bold =true , foreground =Screen . colors . Blue1 } , { 9 , 14 } } , 151[ 12 ] ={ {} , { { hi_name ='MsgArea' , ui_name ='MsgArea' , kind ='ui' } } } , 152[ 13 ] ={ 153{ background =Screen . colors . Red1 , foreground =Screen . colors . Gray100 } , 154{ { ui_name ='LineNr' , kind ='ui' , hi_name ='LineNr' } } , 155} , 156[ 14 ] ={ 157{ bold =true , foreground =Screen . colors . Blue } , 158{ { ui_name ='EndOfBuffer' , kind ='ui' , hi_name ='EndOfBuffer' } } , 159} , 160} ) 161 162command ( 'set number' ) 163command ( 'split' ) 164-- NormalNC is not applied if not set, to avoid spurious redraws 165screen : expect ( [[ 166{1: 1 }^ | 167{2:~ }|*2 168{3:[No Name] }| 169{1: 1 } | 170{2:~ }| 171{4:[No Name] }| 172{12: }| 173]] ) 174 175command ( 'set winhl=LineNr:ErrorMsg' ) 176screen : expect { 177grid =[[ 178{13: 1 }^ | 179{14:~ }|*2 180{3:[No Name] }| 181{1: 1 } | 182{2:~ }| 183{4:[No Name] }| 184{12: }| 185]] , 186} 187 188command ( 'set winhl=Normal:MsgSeparator,NormalNC:Statement' ) 189screen : expect ( [[ 190{7: 1 }{6:^ }| 191{8:~ }|*2 192{3:[No Name] }| 193{1: 1 } | 194{2:~ }| 195{4:[No Name] }| 196{12: }| 197]] ) 198 199command ( 'wincmd w' ) 200screen : expect ( [[ 201{10: 1 }{9: }| 202{11:~ }|*2 203{4:[No Name] }| 204{1: 1 }^ | 205{2:~ }| 206{3:[No Name] }| 207{12: }| 208]] ) 209end ) 210 211it ( 'work with :terminal' , function () 212skip ( is_os ( 'win' )) 213 214screen : set_default_attr_ids ( { 215[ 1 ] ={ {} , { { hi_name ='TermCursorNC' , ui_name ='TermCursorNC' , kind ='ui' } } } , 216[ 2 ] ={ { foreground =tonumber ( '0x00ccff' ), fg_indexed =true } , { { kind ='term' } } } , 217[ 3 ] ={ 218{ bold =true , foreground =tonumber ( '0x00ccff' ), fg_indexed =true } , 219{ 220{ kind ='term' } , 221} , 222} , 223[ 4 ] ={ { foreground =tonumber ( '0x00ccff' ), fg_indexed =true } , { 2 , 1 } } , 224[ 5 ] ={ { foreground =tonumber ( '0x40ffff' ), fg_indexed =true } , { { kind ='term' } } } , 225[ 6 ] ={ { foreground =tonumber ( '0x40ffff' ), fg_indexed =true } , { 5 , 1 } } , 226[ 7 ] ={ {} , { { hi_name ='MsgArea' , ui_name ='MsgArea' , kind ='ui' } } } , 227} ) 228command (( "enew | call jobstart(['%s'],{'term':v:true})" ): format ( testprg ( 'tty-test' ))) 229screen : expect ( [[ 230^tty ready | 231|*6 232{7: }| 233]] ) 234 235tt . feed_data ( 'x ' ) 236tt . set_fg ( 45 ) 237tt . feed_data ( 'y ' ) 238tt . set_bold () 239tt . feed_data ( 'z\n' ) 240-- TODO(bfredl): check if this distinction makes sense 241if is_os ( 'win' ) then 242screen : expect ( [[ 243^tty ready | 244x {5:y z} | 245|*5 246{7: }| 247]] ) 248else 249screen : expect ( [[ 250^tty ready | 251x {2:y }{3:z} | 252|*5 253{7: }| 254]] ) 255end 256 257tt . feed_termcode ( '[A' ) 258tt . feed_termcode ( '[2C' ) 259if is_os ( 'win' ) then 260screen : expect ( [[ 261^tty ready | 262x {6:y}{5: z} | 263|*5 264{7: }| 265]] ) 266else 267screen : expect ( [[ 268^tty ready | 269x {2:y }{3:z} | 270|*5 271{7: }| 272]] ) 273end 274end ) 275 276it ( 'can use independent cterm and rgb colors' , function () 277-- tell test module to save all attributes (doesn't change nvim options) 278screen : set_rgb_cterm ( true ) 279 280screen : set_default_attr_ids ( { 281[ 1 ] ={ 282{ bold =true , foreground =Screen . colors . Blue1 } , 283{ foreground =12 } , 284{ { hi_name ='NonText' , ui_name ='EndOfBuffer' , kind ='ui' } } , 285} , 286[ 2 ] ={ 287{ reverse =true , foreground =Screen . colors . Red } , 288{ foreground =10 , italic =true } , 289{ { hi_name ='NonText' , ui_name ='EndOfBuffer' , kind ='ui' } } , 290} , 291[ 3 ] ={ {} , {} , { { hi_name ='MsgArea' , ui_name ='MsgArea' , kind ='ui' } } } , 292} ) 293screen : expect ( [[ 294^ | 295{1:~ }|*6 296{3: }| 297]] ) 298 299command ( 'hi NonText guifg=Red gui=reverse ctermfg=Green cterm=italic' ) 300screen : expect ( [[ 301^ | 302{2:~ }|*6 303{3: }| 304]] ) 305end ) 306 307it ( 'combines deleted extmark highlights' , function () 308insert ( [[ 309line1 310line2 311line3 312line4 313line5 314line6]] ) 315 316screen : expect { 317grid =[[ 318line1 | 319line2 | 320line3 | 321line4 | 322line5 | 323line^6 | 324{1:~ }| 325{2: }| 326]] , 327attr_ids ={ 328[ 1 ] ={ 329{ foreground =Screen . colors . Blue , bold =true } , 330{ { ui_name ='EndOfBuffer' , hi_name ='NonText' , kind ='ui' } } , 331} , 332[ 2 ] ={ {} , { { ui_name ='MsgArea' , hi_name ='MsgArea' , kind ='ui' } } } , 333} , 334} 335 336local ns =api . nvim_create_namespace ( 'test' ) 337 338local add_indicator =function ( line , col ) 339api . nvim_buf_set_extmark ( 0 , ns , line , col , { 340hl_mode ='combine' , 341priority =2 , 342right_gravity =false , 343virt_text ={ { '|' , 'Delimiter' } } , 344virt_text_win_col =0 , 345virt_text_pos ='overlay' , 346} ) 347end 348 349add_indicator ( 1 , 0 ) 350add_indicator ( 2 , 0 ) 351add_indicator ( 3 , 0 ) 352add_indicator ( 4 , 0 ) 353 354screen : expect { 355grid =[[ 356line1 | 357{1:|} line2 | 358{1:|} line3 | 359{1:|} line4 | 360{1:|} line5 | 361line^6 | 362{2:~ }| 363{3: }| 364]] , 365attr_ids ={ 366[ 1 ] ={ 367{ foreground =Screen . colors . SlateBlue } , 368{ { hi_name ='Special' , kind ='syntax' } } , 369} , 370[ 2 ] ={ 371{ bold =true , foreground =Screen . colors . Blue } , 372{ { ui_name ='EndOfBuffer' , kind ='ui' , hi_name ='NonText' } } , 373} , 374[ 3 ] ={ {} , { { ui_name ='MsgArea' , kind ='ui' , hi_name ='MsgArea' } } } , 375} , 376} 377 378n . feed ( '3ggV2jd' ) 379--screen:redraw_debug() 380screen : expect { 381grid =[[ 382line1 | 383{1:|} line2 | 384{2:^|}ine6 | 385{3:~ }|*4 386{4:3 fewer lines }| 387]] , 388attr_ids ={ 389[ 1 ] ={ 390{ foreground =Screen . colors . SlateBlue } , 391{ { kind ='syntax' , hi_name ='Special' } } , 392} , 393[ 2 ] ={ { foreground =Screen . colors . SlateBlue } , { 1 , 1 , 1 } } , 394[ 3 ] ={ 395{ bold =true , foreground =Screen . colors . Blue } , 396{ { kind ='ui' , ui_name ='EndOfBuffer' , hi_name ='NonText' } } , 397} , 398[ 4 ] ={ {} , { { kind ='ui' , ui_name ='MsgArea' , hi_name ='MsgArea' } } } , 399} , 400} 401end ) 402 403it ( 'removes deleted extmark highlights with invalidate' , function () 404insert ( [[ 405line1 406line2 407line3 408line4 409line5 410line6]] ) 411 412screen : expect { 413grid =[[ 414line1 | 415line2 | 416line3 | 417line4 | 418line5 | 419line^6 | 420{1:~ }| 421{2: }| 422]] , 423attr_ids ={ 424[ 1 ] ={ 425{ foreground =Screen . colors . Blue , bold =true } , 426{ { ui_name ='EndOfBuffer' , hi_name ='NonText' , kind ='ui' } } , 427} , 428[ 2 ] ={ {} , { { ui_name ='MsgArea' , hi_name ='MsgArea' , kind ='ui' } } } , 429} , 430} 431 432local ns =api . nvim_create_namespace ( 'test' ) 433 434local add_indicator =function ( line , col ) 435api . nvim_buf_set_extmark ( 0 , ns , line , col , { 436hl_mode ='combine' , 437priority =2 , 438right_gravity =false , 439virt_text ={ { '|' , 'Delimiter' } } , 440virt_text_win_col =0 , 441virt_text_pos ='overlay' , 442invalidate =true , 443} ) 444end 445 446add_indicator ( 1 , 0 ) 447add_indicator ( 2 , 0 ) 448add_indicator ( 3 , 0 ) 449add_indicator ( 4 , 0 ) 450 451screen : expect { 452grid =[[ 453line1 | 454{1:|} line2 | 455{1:|} line3 | 456{1:|} line4 | 457{1:|} line5 | 458line^6 | 459{2:~ }| 460{3: }| 461]] , 462attr_ids ={ 463[ 1 ] ={ 464{ foreground =Screen . colors . SlateBlue } , 465{ { hi_name ='Special' , kind ='syntax' } } , 466} , 467[ 2 ] ={ 468{ bold =true , foreground =Screen . colors . Blue } , 469{ { ui_name ='EndOfBuffer' , kind ='ui' , hi_name ='NonText' } } , 470} , 471[ 3 ] ={ {} , { { ui_name ='MsgArea' , kind ='ui' , hi_name ='MsgArea' } } } , 472} , 473} 474 475n . feed ( '3ggV2jd' ) 476--screen:redraw_debug() 477screen : expect { 478grid =[[ 479line1 | 480{1:|} line2 | 481^line6 | 482{2:~ }|*4 483{3:3 fewer lines }| 484]] , 485attr_ids ={ 486[ 1 ] ={ 487{ foreground =Screen . colors . SlateBlue } , 488{ { kind ='syntax' , hi_name ='Special' } } , 489} , 490[ 2 ] ={ 491{ foreground =Screen . colors . Blue , bold =true } , 492{ { kind ='ui' , ui_name ='EndOfBuffer' , hi_name ='NonText' } } , 493} , 494[ 3 ] ={ {} , { { kind ='ui' , ui_name ='MsgArea' , hi_name ='MsgArea' } } } , 495} , 496} 497end ) 498 499it ( 'does not hang when combining too many highlights' , function () 500local num_lines =500 501insert ( 'first line\n' ) 502for _ =1 , num_lines do 503api . nvim_paste ( ' line\n' , false , - 1 ) 504end 505insert ( 'last line' ) 506 507n . feed ( 'gg' ) 508screen : expect { 509grid =[[ 510^first line | 511line |*6 512{1: }| 513]] , 514attr_ids ={ 515[ 1 ] ={ {} , { { kind ='ui' , hi_name ='MsgArea' , ui_name ='MsgArea' } } } , 516} , 517} 518local ns =api . nvim_create_namespace ( 'test' ) 519 520local add_indicator =function ( line , col ) 521api . nvim_buf_set_extmark ( 0 , ns , line , col , { 522hl_mode ='combine' , 523priority =2 , 524right_gravity =false , 525virt_text ={ { '|' , 'Delimiter' } } , 526virt_text_win_col =0 , 527virt_text_pos ='overlay' , 528} ) 529end 530 531for i =1 , num_lines do 532add_indicator ( i , 0 ) 533end 534 535screen : expect { 536grid =[[ 537^first line | 538{1:|} line |*6 539{2: }| 540]] , 541attr_ids ={ 542[ 1 ] ={ 543{ foreground =Screen . colors . SlateBlue } , 544{ { kind ='syntax' , hi_name ='Special' } } , 545} , 546[ 2 ] ={ {} , { { kind ='ui' , ui_name ='MsgArea' , hi_name ='MsgArea' } } } , 547} , 548} 549 550n . feed ( string . format ( '3ggV%ijd' , num_lines - 2 )) 551--screen:redraw_debug(nil, nil, 100000) 552 553local expected_ids ={} 554for i =1 , num_lines - 1 do 555expected_ids [ i ] =1 556end 557screen : expect { 558grid =string . format ( 559[[ 560first line | 561{1:|} line | 562{2:^|}ast line | 563{3:~ }|*4 564{4:%-40s}| 565]] , 566tostring ( num_lines - 1 ) .. ' fewer lines' 567), 568attr_ids ={ 569[ 1 ] ={ 570{ foreground =Screen . colors . SlateBlue } , 571{ { kind ='syntax' , hi_name ='Special' } } , 572} , 573[ 2 ] ={ { foreground =Screen . colors . SlateBlue } , expected_ids } , 574[ 3 ] ={ 575{ foreground =Screen . colors . Blue , bold =true } , 576{ { kind ='ui' , hi_name ='NonText' , ui_name ='EndOfBuffer' } } , 577} , 578[ 4 ] ={ {} , { { kind ='ui' , hi_name ='MsgArea' , ui_name ='MsgArea' } } } , 579} , 580timeout =100000 , 581} 582end ) 583end )