robin/laufey
git clone https://git.robinwobin.dev/robin/laufey
aa1d8a2702
master
1local t =require ( 'test.testutil' ) 2local n =require ( 'test.functional.testnvim' )() 3local Screen =require ( 'test.functional.ui.screen' ) 4 5local describe , it , before_each , pending =t . describe , t . it , t . before_each , t . pending 6local clear , feed , insert =n . clear , n . feed , n . insert 7local command , neq =n . command , t . neq 8local api =n . api 9local eq =t . eq 10local pcall_err =t . pcall_err 11local set_virtual_text =api . nvim_buf_set_virtual_text 12 13describe ( 'Buffer highlighting' , function () 14local screen 15 16before_each ( function () 17clear () 18command ( 'syntax on' ) 19screen =Screen . new ( 40 , 8 ) 20screen : set_default_attr_ids ( { 21[ 1 ] ={ bold =true , foreground =Screen . colors . Blue } , 22[ 2 ] ={ foreground =Screen . colors . Fuchsia } , -- String 23[ 3 ] ={ foreground =Screen . colors . Brown , bold =true } , -- Statement 24[ 4 ] ={ foreground =Screen . colors . SlateBlue } , -- Special 25[ 5 ] ={ bold =true , foreground =Screen . colors . SlateBlue } , 26[ 6 ] ={ foreground =Screen . colors . DarkCyan } , -- Identifier 27[ 7 ] ={ bold =true } , 28[ 8 ] ={ underline =true , bold =true , foreground =Screen . colors . SlateBlue } , 29[ 9 ] ={ foreground =Screen . colors . SlateBlue , underline =true } , 30[ 10 ] ={ foreground =Screen . colors . Red } , 31[ 11 ] ={ foreground =Screen . colors . Grey100 , background =Screen . colors . Red } , 32[ 12 ] ={ foreground =Screen . colors . Blue1 } , 33[ 13 ] ={ foreground =Screen . colors . Black , background =Screen . colors . LightGrey } , 34[ 14 ] ={ background =Screen . colors . Gray90 } , 35[ 15 ] ={ background =Screen . colors . Gray90 , bold =true , foreground =Screen . colors . Brown } , 36[ 16 ] ={ foreground =Screen . colors . Magenta , background =Screen . colors . Gray90 } , 37[ 17 ] ={ foreground =Screen . colors . Magenta , background =Screen . colors . LightRed } , 38[ 18 ] ={ background =Screen . colors . LightRed } , 39[ 19 ] ={ foreground =Screen . colors . Blue1 , background =Screen . colors . LightRed } , 40[ 20 ] ={ underline =true , bold =true , foreground =Screen . colors . Cyan4 } , 41} ) 42end ) 43 44local add_highlight =api . nvim_buf_add_highlight 45local clear_namespace =api . nvim_buf_clear_namespace 46 47it ( 'works' , function () 48insert ( [[ 49these are some lines 50with colorful text]] ) 51feed ( '+' ) 52 53screen : expect ( [[ 54these are some lines | 55with colorful tex^t | 56{1:~ }|*5 57| 58]] ) 59 60add_highlight ( 0 , - 1 , 'String' , 0 , 10 , 14 ) 61add_highlight ( 0 , - 1 , 'Statement' , 1 , 5 , - 1 ) 62 63screen : expect ( [[ 64these are {2:some} lines | 65with {3:colorful tex^t} | 66{1:~ }|*5 67| 68]] ) 69 70feed ( 'ggo<esc>' ) 71screen : expect ( [[ 72these are {2:some} lines | 73^ | 74with {3:colorful text} | 75{1:~ }|*4 76| 77]] ) 78 79clear_namespace ( 0 , - 1 , 0 , - 1 ) 80screen : expect ( [[ 81these are some lines | 82^ | 83with colorful text | 84{1:~ }|*4 85| 86]] ) 87end ) 88 89describe ( 'support using multiple namespaces' , function () 90local id1 , id2 91before_each ( function () 92insert ( [[ 93a longer example 94in order to demonstrate 95combining highlights 96from different sources]] ) 97 98command ( 'hi ImportantWord gui=bold cterm=bold' ) 99id1 =add_highlight ( 0 , 0 , 'ImportantWord' , 0 , 2 , 8 ) 100add_highlight ( 0 , id1 , 'ImportantWord' , 1 , 12 , - 1 ) 101add_highlight ( 0 , id1 , 'ImportantWord' , 2 , 0 , 9 ) 102add_highlight ( 0 , id1 , 'ImportantWord' , 3 , 5 , 14 ) 103 104-- add_highlight can be called like this to get a new source 105-- without adding any highlight 106id2 =add_highlight ( 0 , 0 , '' , 0 , 0 , 0 ) 107neq ( id1 , id2 ) 108 109add_highlight ( 0 , id2 , 'Special' , 0 , 2 , 8 ) 110add_highlight ( 0 , id2 , 'Identifier' , 1 , 3 , 8 ) 111add_highlight ( 0 , id2 , 'Special' , 1 , 14 , 20 ) 112add_highlight ( 0 , id2 , 'Underlined' , 2 , 6 , 12 ) 113add_highlight ( 0 , id2 , 'Underlined' , 3 , 0 , 9 ) 114 115screen : expect ( [[ 116a {5:longer} example | 117in {6:order} to {7:de}{5:monstr}{7:ate} | 118{7:combin}{8:ing}{9: hi}ghlights | 119{9:from }{8:diff}{7:erent} source^s | 120{1:~ }|*3 121| 122]] ) 123end ) 124 125it ( 'and clearing the first added' , function () 126clear_namespace ( 0 , id1 , 0 , - 1 ) 127screen : expect ( [[ 128a {4:longer} example | 129in {6:order} to de{4:monstr}ate | 130combin{9:ing hi}ghlights | 131{9:from diff}erent source^s | 132{1:~ }|*3 133| 134]] ) 135end ) 136 137it ( 'and clearing using deprecated name' , function () 138api . nvim_buf_clear_highlight ( 0 , id1 , 0 , - 1 ) 139screen : expect ( [[ 140a {4:longer} example | 141in {6:order} to de{4:monstr}ate | 142combin{9:ing hi}ghlights | 143{9:from diff}erent source^s | 144{1:~ }|*3 145| 146]] ) 147end ) 148 149it ( 'and clearing the second added' , function () 150clear_namespace ( 0 , id2 , 0 , - 1 ) 151screen : expect ( [[ 152a {7:longer} example | 153in order to {7:demonstrate} | 154{7:combining} highlights | 155from {7:different} source^s | 156{1:~ }|*3 157| 158]] ) 159end ) 160 161it ( 'and clearing line ranges' , function () 162clear_namespace ( 0 , - 1 , 0 , 1 ) 163clear_namespace ( 0 , id1 , 1 , 2 ) 164clear_namespace ( 0 , id2 , 2 , - 1 ) 165screen : expect ( [[ 166a longer example | 167in {6:order} to de{4:monstr}ate | 168{7:combining} highlights | 169from {7:different} source^s | 170{1:~ }|*3 171| 172]] ) 173end ) 174 175it ( 'and renumbering lines' , function () 176feed ( '3Gddggo<esc>' ) 177screen : expect ( [[ 178a {5:longer} example | 179^ | 180in {6:order} to {7:de}{5:monstr}{7:ate} | 181{9:from }{8:diff}{7:erent} sources | 182{1:~ }|*3 183| 184]] ) 185 186-- TODO(bfedl): this behaves a bit weirdly due to the highlight on 187-- the deleted line wrapping around. we should invalidate 188-- highlights when they are completely inside deleted text 189command ( '3move 4' ) 190screen : expect { 191grid =[[ 192a {5:longer} example | 193| 194{8:from different sources} | 195{8:^in }{20:order}{8: to demonstrate} | 196{1:~ }|*3 197| 198]] , 199} 200--screen:expect([[ 201-- a {5:longer} example | 202-- | 203-- {9:from }{8:diff}{7:erent} sources | 204-- ^in {6:order} to {7:de}{5:monstr}{7:ate} | 205-- {1:~ }|*3 206-- | 207--]]) 208 209command ( 'undo' ) 210screen : expect { 211grid =[[ 212a {5:longer} example | 213^ | 214in {6:order} to {7:de}{5:monstr}{7:ate} | 215{9:from }{8:diff}{7:erent} sources | 216{1:~ }|*3 2171 change; before #4 {MATCH:.*}| 218]] , 219} 220 221command ( 'undo' ) 222screen : expect { 223grid =[[ 224^a {5:longer} example | 225in {6:order} to {7:de}{5:monstr}{7:ate} | 226{9:from }{8:diff}{7:erent} sources | 227{1:~ }|*4 2281 line less; before #3 {MATCH:.*}| 229]] , 230} 231 232command ( 'undo' ) 233screen : expect { 234grid =[[ 235a {5:longer} example | 236in {6:order} to {7:de}{5:monstr}{7:ate} | 237{7:^combin}{8:ing}{9: hi}ghlights | 238{9:from }{8:diff}{7:erent} sources | 239{1:~ }|*3 2401 more line; before #2 {MATCH:.*}| 241]] , 242} 243end ) 244 245it ( 'and moving lines around' , function () 246command ( '2move 3' ) 247screen : expect { 248grid =[[ 249a {5:longer} example | 250{7:combin}{8:ing}{9: hi}ghlights | 251^in {6:order} to {7:de}{5:monstr}{7:ate} | 252{9:from }{8:diff}{7:erent} sources | 253{1:~ }|*3 254| 255]] , 256} 257 258command ( '1,2move 4' ) 259screen : expect { 260grid =[[ 261in {6:order} to {7:de}{5:monstr}{7:ate} | 262{9:from }{8:diff}{7:erent} sources | 263a {5:longer} example | 264{7:^combin}{8:ing}{9: hi}ghlights | 265{1:~ }|*3 266| 267]] , 268} 269 270command ( 'undo' ) 271screen : expect { 272grid =[[ 273a {5:longer} example | 274{7:combin}{8:ing}{9: hi}ghlights | 275^in {6:order} to {7:de}{5:monstr}{7:ate} | 276{9:from }{8:diff}{7:erent} sources | 277{1:~ }|*3 2782 changes; before #3 {MATCH:.*}| 279]] , 280} 281 282command ( 'undo' ) 283screen : expect { 284grid =[[ 285a {5:longer} example | 286in {6:order} to {7:de}{5:monstr}{7:ate} | 287{7:combin}{8:ing}{9: hi}ghlights | 288{9:from }{8:diff}{7:erent} source^s | 289{1:~ }|*3 2901 change; before #2 {MATCH:.*}| 291]] , 292} 293end ) 294 295it ( 'and adjusting columns' , function () 296-- insert before 297feed ( 'ggiquite <esc>' ) 298screen : expect { 299grid =[[ 300quite^ a {5:longer} example | 301in {6:order} to {7:de}{5:monstr}{7:ate} | 302{7:combin}{8:ing}{9: hi}ghlights | 303{9:from }{8:diff}{7:erent} sources | 304{1:~ }|*3 305| 306]] , 307} 308 309feed ( 'u' ) 310screen : expect { 311grid =[[ 312^a {5:longer} example | 313in {6:order} to {7:de}{5:monstr}{7:ate} | 314{7:combin}{8:ing}{9: hi}ghlights | 315{9:from }{8:diff}{7:erent} sources | 316{1:~ }|*3 3171 change; before #2 {MATCH:.*}| 318]] , 319} 320 321-- change/insert in the middle 322feed ( '+fesAAAA' ) 323screen : expect { 324grid =[[ 325a {5:longer} example | 326in {6:ordAAAA^r} to {7:de}{5:monstr}{7:ate} | 327{7:combin}{8:ing}{9: hi}ghlights | 328{9:from }{8:diff}{7:erent} sources | 329{1:~ }|*3 330{7:-- INSERT --} | 331]] , 332} 333 334feed ( '<esc>tdD' ) 335screen : expect { 336grid =[[ 337a {5:longer} example | 338in {6:ordAAAAr} t^o | 339{7:combin}{8:ing}{9: hi}ghlights | 340{9:from }{8:diff}{7:erent} sources | 341{1:~ }|*3 342| 343]] , 344} 345 346feed ( 'u' ) 347screen : expect { 348grid =[[ 349a {5:longer} example | 350in {6:ordAAAAr} to^ {7:de}{5:monstr}{7:ate} | 351{7:combin}{8:ing}{9: hi}ghlights | 352{9:from }{8:diff}{7:erent} sources | 353{1:~ }|*3 3541 change; before #4 {MATCH:.*}| 355]] , 356} 357 358feed ( 'u' ) 359screen : expect { 360grid =[[ 361a {5:longer} example | 362in {6:ord^er} to {7:de}{5:monstr}{7:ate} | 363{7:combin}{8:ing}{9: hi}ghlights | 364{9:from }{8:diff}{7:erent} sources | 365{1:~ }|*3 3661 change; before #3 {MATCH:.*}| 367]] , 368} 369end ) 370 371it ( 'and joining lines' , function () 372feed ( 'ggJJJ' ) 373screen : expect { 374grid =[[ 375a {5:longer} example in {6:order} to {7:de}{5:monstr}{7:ate}| 376{7:combin}{8:ing}{9: hi}ghlights^ {9:from }{8:diff}{7:erent} sou| 377rces | 378{1:~ }|*4 379| 380]] , 381} 382 383feed ( 'uuu' ) 384screen : expect { 385grid =[[ 386^a {5:longer} example | 387in {6:order} to {7:de}{5:monstr}{7:ate} | 388{7:combin}{8:ing}{9: hi}ghlights | 389{9:from }{8:diff}{7:erent} sources | 390{1:~ }|*3 3911 more line; before #2 {MATCH:.*}| 392]] , 393} 394end ) 395 396it ( 'and splitting lines' , function () 397feed ( '2Gtti<cr>' ) 398screen : expect { 399grid =[[ 400a {5:longer} example | 401in {6:order} | 402^ to {7:de}{5:monstr}{7:ate} | 403{7:combin}{8:ing}{9: hi}ghlights | 404{9:from }{8:diff}{7:erent} sources | 405{1:~ }|*2 406{7:-- INSERT --} | 407]] , 408} 409 410feed ( '<esc>tsi<cr>' ) 411screen : expect { 412grid =[[ 413a {5:longer} example | 414in {6:order} | 415to {7:de}{5:mo} | 416{5:^nstr}{7:ate} | 417{7:combin}{8:ing}{9: hi}ghlights | 418{9:from }{8:diff}{7:erent} sources | 419{1:~ }| 420{7:-- INSERT --} | 421]] , 422} 423 424feed ( '<esc>u' ) 425screen : expect { 426grid =[[ 427a {5:longer} example | 428in {6:order} | 429to {7:de}{5:mo^nstr}{7:ate} | 430{7:combin}{8:ing}{9: hi}ghlights | 431{9:from }{8:diff}{7:erent} sources | 432{1:~ }|*2 4331 line less; before #3 {MATCH:.*}| 434]] , 435} 436 437feed ( '<esc>u' ) 438screen : expect { 439grid =[[ 440a {5:longer} example | 441in {6:order}^ to {7:de}{5:monstr}{7:ate} | 442{7:combin}{8:ing}{9: hi}ghlights | 443{9:from }{8:diff}{7:erent} sources | 444{1:~ }|*3 4451 line less; before #2 {MATCH:.*}| 446]] , 447} 448end ) 449end ) 450 451pending ( 'prioritizes latest added highlight' , function () 452insert ( [[ 453three overlapping colors]] ) 454add_highlight ( 0 , 0 , 'Identifier' , 0 , 6 , 17 ) 455add_highlight ( 0 , 0 , 'String' , 0 , 14 , 23 ) 456local id =add_highlight ( 0 , 0 , 'Special' , 0 , 0 , 9 ) 457 458screen : expect ( [[ 459{4:three ove}{6:rlapp}{2:ing color}^s | 460{1:~ }|*6 461| 462]] ) 463 464clear_namespace ( 0 , id , 0 , 1 ) 465screen : expect ( [[ 466three {6:overlapp}{2:ing color}^s | 467{1:~ }|*6 468| 469]] ) 470end ) 471 472it ( 'prioritizes earlier highlight groups (TEMP)' , function () 473insert ( [[ 474three overlapping colors]] ) 475add_highlight ( 0 , 0 , 'Identifier' , 0 , 6 , 17 ) 476add_highlight ( 0 , 0 , 'String' , 0 , 14 , 23 ) 477local id =add_highlight ( 0 , 0 , 'Special' , 0 , 0 , 9 ) 478 479screen : expect { 480grid =[[ 481{4:three }{6:overlapp}{2:ing color}^s | 482{1:~ }|*6 483| 484]] , 485} 486 487clear_namespace ( 0 , id , 0 , 1 ) 488screen : expect { 489grid =[[ 490three {6:overlapp}{2:ing color}^s | 491{1:~ }|*6 492| 493]] , 494} 495end ) 496 497it ( 'respects priority' , function () 498local id =api . nvim_create_namespace ( '' ) 499insert [[foobar]] 500 501api . nvim_buf_set_extmark ( 0 , id , 0 , 0 , { 502end_line =0 , 503end_col =5 , 504hl_group ='Statement' , 505priority =100 , 506} ) 507api . nvim_buf_set_extmark ( 0 , id , 0 , 0 , { 508end_line =0 , 509end_col =6 , 510hl_group ='String' , 511priority =1 , 512} ) 513 514screen : expect [[ 515{3:fooba}{2:^r} | 516{1:~ }|*6 517| 518]] 519 520clear_namespace ( 0 , id , 0 , - 1 ) 521screen : expect { 522grid =[[ 523fooba^r | 524{1:~ }|*6 525| 526]] , 527} 528 529api . nvim_buf_set_extmark ( 0 , id , 0 , 0 , { 530end_line =0 , 531end_col =6 , 532hl_group ='String' , 533priority =1 , 534} ) 535api . nvim_buf_set_extmark ( 0 , id , 0 , 0 , { 536end_line =0 , 537end_col =5 , 538hl_group ='Statement' , 539priority =100 , 540} ) 541 542screen : expect [[ 543{3:fooba}{2:^r} | 544{1:~ }|*6 545| 546]] 547end ) 548 549it ( 'works with multibyte text' , function () 550insert ( [[ 551Ta båten över sjön!]] ) 552add_highlight ( 0 , - 1 , 'Identifier' , 0 , 3 , 9 ) 553add_highlight ( 0 , - 1 , 'String' , 0 , 16 , 21 ) 554 555screen : expect ( [[ 556Ta {6:båten} över {2:sjön}^! | 557{1:~ }|*6 558| 559]] ) 560end ) 561 562it ( 'works with new syntax groups' , function () 563insert ( [[ 564fancy code in a new fancy language]] ) 565add_highlight ( 0 , - 1 , 'FancyLangItem' , 0 , 0 , 5 ) 566screen : expect ( [[ 567fancy code in a new fancy languag^e | 568{1:~ }|*6 569| 570]] ) 571 572command ( 'hi FancyLangItem guifg=red' ) 573screen : expect ( [[ 574{10:fancy} code in a new fancy languag^e | 575{1:~ }|*6 576| 577]] ) 578end ) 579 580describe ( 'virtual text decorations' , function () 581local id1 , id2 ---@type integer, integer 582before_each ( function () 583insert ( [[ 5841 + 2 5853 + 586x = 4]] ) 587feed ( 'O<esc>20A5, <esc>gg' ) 588screen : expect ( [[ 589^1 + 2 | 5903 + | 5915, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5| 592, 5, 5, 5, 5, 5, 5, | 593x = 4 | 594{1:~ }|*2 595| 596]] ) 597 598id1 =set_virtual_text ( 0 , 0 , 0 , { { '=' , 'Statement' } , { ' 3' , 'Number' } } , {} ) 599set_virtual_text ( 0 , id1 , 1 , { { 'ERROR:' , 'ErrorMsg' } , { ' invalid syntax' } } , {} ) 600id2 =set_virtual_text ( 0 , 0 , 2 , { 601{ 602'Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.' , 603} , 604} , {} ) 605neq ( id2 , id1 ) 606end ) 607 608it ( 'works' , function () 609screen : expect ( [[ 610^1 + 2 {3:=}{2: 3} | 6113 + {11:ERROR:} invalid syntax | 6125, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5| 613, 5, 5, 5, 5, 5, 5, Lorem ipsum dolor s| 614x = 4 | 615{1:~ }|*2 616| 617]] ) 618 619clear_namespace ( 0 , id1 , 0 , - 1 ) 620screen : expect ( [[ 621^1 + 2 | 6223 + | 6235, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5| 624, 5, 5, 5, 5, 5, 5, Lorem ipsum dolor s| 625x = 4 | 626{1:~ }|*2 627| 628]] ) 629 630-- Handles doublewidth chars, leaving a space if truncating 631-- in the middle of a char 632eq ( 633- 1 , 634set_virtual_text ( 6350 , 636- 1 , 6371 , 638{ { '暗x事zz速野谷質結育副住新覚丸活解終事' , 'Comment' } } , 639{} 640) 641) 642screen : expect ( [[ 643^1 + 2 | 6443 + {12:暗x事zz速野谷質結育副住新覚丸活解終 }| 6455, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5| 646, 5, 5, 5, 5, 5, 5, Lorem ipsum dolor s| 647x = 4 | 648{1:~ }|*2 649| 650]] ) 651 652feed ( '2Gx' ) 653screen : expect ( [[ 6541 + 2 | 655^ + {12:暗x事zz速野谷質結育副住新覚丸活解終事}| 6565, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5| 657, 5, 5, 5, 5, 5, 5, Lorem ipsum dolor s| 658x = 4 | 659{1:~ }|*2 660| 661]] ) 662 663feed ( '2Gdd' ) 664-- TODO(bfredl): currently decorations get moved from a deleted line 665-- to the next one. We might want to add "invalidation" when deleting 666-- over a decoration. 667screen : expect { 668grid =[[ 6691 + 2 | 670^5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5| 671, 5, 5, 5, 5, 5, 5, {12:暗x事zz速野谷質結育}| 672x = 4 | 673{1:~ }|*3 674| 675]] , 676} 677--screen:expect([[ 678-- 1 + 2 | 679-- ^5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5| 680-- , 5, 5, 5, 5, 5, 5, Lorem ipsum dolor s| 681-- x = 4 | 682-- {1:~ }|*3 683-- | 684--]]) 685end ) 686 687it ( 'validates contents' , function () 688-- this used to leak memory 689eq ( 690"Invalid 'chunk': expected Array, got String" , 691pcall_err ( set_virtual_text , 0 , id1 , 0 , { 'texty' } , {} ) 692) 693eq ( 694"Invalid 'chunk': expected Array, got String" , 695pcall_err ( set_virtual_text , 0 , id1 , 0 , { { 'very' } , 'texty' } , {} ) 696) 697end ) 698 699it ( 'can be retrieved' , function () 700local get_extmarks =api . nvim_buf_get_extmarks 701local line_count =api . nvim_buf_line_count 702 703local s1 ={ { 'Köttbullar' , 'Comment' } , { 'Kräuterbutter' } } 704local s2 ={ { 'こんにちは' , 'Comment' } } 705 706set_virtual_text ( 0 , id1 , 0 , s1 , {} ) 707eq ( { 708{ 7091 , 7100 , 7110 , 712{ 713ns_id =id1 , 714priority =0 , 715virt_text =s1 , 716-- other details 717right_gravity =true , 718virt_text_repeat_linebreak =false , 719virt_text_pos ='eol' , 720virt_text_hide =false , 721} , 722} , 723} , get_extmarks ( 0 , id1 , { 0 , 0 } , { 0 , - 1 } , { details =true } )) 724 725local lastline =line_count ( 0 ) 726set_virtual_text ( 0 , id1 , line_count ( 0 ), s2 , {} ) 727eq ( { 728{ 7293 , 730lastline , 7310 , 732{ 733ns_id =id1 , 734priority =0 , 735virt_text =s2 , 736-- other details 737right_gravity =true , 738virt_text_repeat_linebreak =false , 739virt_text_pos ='eol' , 740virt_text_hide =false , 741} , 742} , 743} , get_extmarks ( 0 , id1 , { lastline , 0 } , { lastline , - 1 } , { details =true } )) 744 745eq ( {} , get_extmarks ( 0 , id1 , { lastline + 9000 , 0 } , { lastline + 9000 , - 1 } , {} )) 746end ) 747 748it ( 'is not highlighted by visual selection' , function () 749feed ( 'ggVG' ) 750screen : expect ( [[ 751{13:1 + 2} {3:=}{2: 3} | 752{13:3 +} {11:ERROR:} invalid syntax | 753{13:5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5}| 754{13:, 5, 5, 5, 5, 5, 5, } Lorem ipsum dolor s| 755{13:^x = 4} | 756{1:~ }|*2 757{7:-- VISUAL LINE --} | 758]] ) 759 760feed ( '<esc>' ) 761screen : expect ( [[ 7621 + 2 {3:=}{2: 3} | 7633 + {11:ERROR:} invalid syntax | 7645, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5| 765, 5, 5, 5, 5, 5, 5, Lorem ipsum dolor s| 766^x = 4 | 767{1:~ }|*2 768| 769]] ) 770 771-- special case: empty line has extra eol highlight 772feed ( 'ggd$' ) 773screen : expect ( [[ 774^ {3:=}{2: 3} | 7753 + {11:ERROR:} invalid syntax | 7765, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5| 777, 5, 5, 5, 5, 5, 5, Lorem ipsum dolor s| 778x = 4 | 779{1:~ }|*2 780| 781]] ) 782 783feed ( 'jvk' ) 784screen : expect ( [[ 785{13:^ }{3:=}{2: 3} | 786{13:3} + {11:ERROR:} invalid syntax | 7875, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5| 788, 5, 5, 5, 5, 5, 5, Lorem ipsum dolor s| 789x = 4 | 790{1:~ }|*2 791{7:-- VISUAL --} | 792]] ) 793 794feed ( 'o' ) 795screen : expect ( [[ 796{13: }{3:=}{2: 3} | 797{13:^3} + {11:ERROR:} invalid syntax | 7985, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5| 799, 5, 5, 5, 5, 5, 5, Lorem ipsum dolor s| 800x = 4 | 801{1:~ }|*2 802{7:-- VISUAL --} | 803]] ) 804end ) 805 806it ( 'works with listchars' , function () 807command ( 'set list listchars+=eol:$' ) 808screen : expect ( [[ 809^1 + 2{1:$}{3:=}{2: 3} | 8103 +{1:$}{11:ERROR:} invalid syntax | 8115, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5| 812, 5, 5, 5, 5, 5, 5,{1:-$}Lorem ipsum dolor s| 813x = 4{1:$} | 814{1:~ }|*2 815| 816]] ) 817 818clear_namespace ( 0 , - 1 , 0 , - 1 ) 819screen : expect ( [[ 820^1 + 2{1:$} | 8213 +{1:$} | 8225, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5| 823, 5, 5, 5, 5, 5, 5,{1:-$} | 824x = 4{1:$} | 825{1:~ }|*2 826| 827]] ) 828end ) 829 830it ( 'works with cursorline' , function () 831command ( 'set cursorline' ) 832 833screen : expect { 834grid =[[ 835{14:^1 + 2 }{3:=}{2: 3}{14: }| 8363 + {11:ERROR:} invalid syntax | 8375, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5| 838, 5, 5, 5, 5, 5, 5, Lorem ipsum dolor s| 839x = 4 | 840{1:~ }|*2 841| 842]] , 843} 844 845feed ( 'j' ) 846screen : expect { 847grid =[[ 8481 + 2 {3:=}{2: 3} | 849{14:^3 + }{11:ERROR:} invalid syntax{14: }| 8505, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5| 851, 5, 5, 5, 5, 5, 5, Lorem ipsum dolor s| 852x = 4 | 853{1:~ }|*2 854| 855]] , 856} 857 858feed ( 'j' ) 859screen : expect { 860grid =[[ 8611 + 2 {3:=}{2: 3} | 8623 + {11:ERROR:} invalid syntax | 863{14:^5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5}| 864{14:, 5, 5, 5, 5, 5, 5, }Lorem ipsum dolor s| 865x = 4 | 866{1:~ }|*2 867| 868]] , 869} 870end ) 871 872it ( 'works with color column' , function () 873eq ( - 1 , set_virtual_text ( 0 , - 1 , 3 , { { '暗x事' , 'Comment' } } , {} )) 874screen : expect { 875grid =[[ 876^1 + 2 {3:=}{2: 3} | 8773 + {11:ERROR:} invalid syntax | 8785, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5| 879, 5, 5, 5, 5, 5, 5, Lorem ipsum dolor s| 880x = 4 {12:暗x事} | 881{1:~ }|*2 882| 883]] , 884} 885 886command ( 'set colorcolumn=9' ) 887screen : expect { 888grid =[[ 889^1 + 2 {3:=}{2: 3} | 8903 + {11:ERROR:} invalid syntax | 8915, 5, 5,{18: }5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5| 892, 5, 5, 5, 5, 5, 5, Lorem ipsum dolor s| 893x = 4 {12:暗x事} | 894{1:~ }|*2 895| 896]] , 897} 898end ) 899end ) 900 901it ( 'and virtual text use the same namespace counter' , function () 902local base =vim . iter ( api . nvim_get_namespaces ()): fold ( 0 , function ( acc , _ , v ) 903return math . max ( acc , v ) 904end ) 905 906eq ( base + 1 , add_highlight ( 0 , 0 , 'String' , 0 , 0 , - 1 )) 907eq ( base + 2 , set_virtual_text ( 0 , 0 , 0 , { { '= text' , 'Comment' } } , {} )) 908eq ( base + 3 , api . nvim_create_namespace ( 'my-ns' )) 909eq ( base + 4 , add_highlight ( 0 , 0 , 'String' , 0 , 0 , - 1 )) 910eq ( base + 5 , set_virtual_text ( 0 , 0 , 0 , { { '= text' , 'Comment' } } , {} )) 911eq ( base + 6 , api . nvim_create_namespace ( 'other-ns' )) 912end ) 913end )