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 =t . describe , t . it , t . before_each 6local clear =n . clear 7local command =n . command 8local exec =n . exec 9local feed =n . feed 10local api =n . api 11 12local expect_pos =function ( row , col ) 13return t . eq ( { row , col } , n . eval ( '[screenrow(), screencol()]' )) 14end 15 16describe ( 'Conceal' , function () 17before_each ( function () 18clear () 19command ( 'set nohlsearch' ) 20end ) 21 22-- oldtest: Test_conceal_two_windows() 23it ( 'works' , function () 24local screen =Screen . new ( 75 , 12 ) 25exec ( [[ 26let lines = ["one one one one one", "two |hidden| here", "three |hidden| three"] 27call setline(1, lines) 28syntax match test /|hidden|/ conceal 29set conceallevel=2 30set concealcursor= 31exe "normal /here\r" 32new 33call setline(1, lines) 34call setline(4, "Second window") 35syntax match test /|hidden|/ conceal 36set conceallevel=2 37set concealcursor=nc 38exe "normal /here\r" 39]] ) 40 41-- Check that cursor line is concealed 42screen : expect ( [[ 43one one one one one | 44two ^here | 45three three | 46Second window | 47{1:~ }| 48{3:[No Name] [+] }| 49one one one one one | 50two here | 51three three | 52{1:~ }| 53{2:[No Name] [+] }| 54/here | 55]] ) 56 57-- Check that with concealed text vertical cursor movement is correct. 58feed ( 'k' ) 59screen : expect ( [[ 60one one one o^ne one | 61two here | 62three three | 63Second window | 64{1:~ }| 65{3:[No Name] [+] }| 66one one one one one | 67two here | 68three three | 69{1:~ }| 70{2:[No Name] [+] }| 71/here | 72]] ) 73 74-- Check that with cursor line is not concealed 75feed ( 'j' ) 76command ( 'set concealcursor=' ) 77screen : expect ( [[ 78one one one one one | 79two |hidden| ^here | 80three three | 81Second window | 82{1:~ }| 83{3:[No Name] [+] }| 84one one one one one | 85two here | 86three three | 87{1:~ }| 88{2:[No Name] [+] }| 89/here | 90]] ) 91 92-- Check that with cursor line is not concealed when moving cursor down 93feed ( 'j' ) 94screen : expect ( [[ 95one one one one one | 96two here | 97three |hidden^| three | 98Second window | 99{1:~ }| 100{3:[No Name] [+] }| 101one one one one one | 102two here | 103three three | 104{1:~ }| 105{2:[No Name] [+] }| 106/here | 107]] ) 108 109-- Check that with cursor line is not concealed when switching windows 110feed ( '<C-W><C-W>' ) 111screen : expect ( [[ 112one one one one one | 113two here | 114three three | 115Second window | 116{1:~ }| 117{2:[No Name] [+] }| 118one one one one one | 119two |hidden| ^here | 120three three | 121{1:~ }| 122{3:[No Name] [+] }| 123/here | 124]] ) 125 126-- Check that with cursor line is only concealed in Normal mode 127command ( 'set concealcursor=n' ) 128screen : expect ( [[ 129one one one one one | 130two here | 131three three | 132Second window | 133{1:~ }| 134{2:[No Name] [+] }| 135one one one one one | 136two ^here | 137three three | 138{1:~ }| 139{3:[No Name] [+] }| 140/here | 141]] ) 142feed ( 'a' ) 143screen : expect ( [[ 144one one one one one | 145two here | 146three three | 147Second window | 148{1:~ }| 149{2:[No Name] [+] }| 150one one one one one | 151two |hidden| h^ere | 152three three | 153{1:~ }| 154{3:[No Name] [+] }| 155{5:-- INSERT --} | 156]] ) 157feed ( '<Esc>/e' ) 158screen : expect ( [[ 159one one one one one | 160two here | 161three three | 162Second window | 163{1:~ }| 164{2:[No Name] [+] }| 165one one one one one | 166two |hidden| h{2:e}re | 167three three | 168{1:~ }| 169{3:[No Name] [+] }| 170/e^ | 171]] ) 172feed ( '<Esc>v' ) 173screen : expect ( [[ 174one one one one one | 175two here | 176three three | 177Second window | 178{1:~ }| 179{2:[No Name] [+] }| 180one one one one one | 181two |hidden| {17:^h}ere | 182three three | 183{1:~ }| 184{3:[No Name] [+] }| 185{5:-- VISUAL --} | 186]] ) 187feed ( '<Esc>' ) 188 189-- Check that with cursor line is only concealed in Insert mode 190command ( 'set concealcursor=i' ) 191screen : expect ( [[ 192one one one one one | 193two here | 194three three | 195Second window | 196{1:~ }| 197{2:[No Name] [+] }| 198one one one one one | 199two |hidden| ^here | 200three three | 201{1:~ }| 202{3:[No Name] [+] }| 203| 204]] ) 205feed ( 'a' ) 206screen : expect ( [[ 207one one one one one | 208two here | 209three three | 210Second window | 211{1:~ }| 212{2:[No Name] [+] }| 213one one one one one | 214two h^ere | 215three three | 216{1:~ }| 217{3:[No Name] [+] }| 218{5:-- INSERT --} | 219]] ) 220feed ( '<Esc>/e' ) 221screen : expect ( [[ 222one one one one one | 223two here | 224three three | 225Second window | 226{1:~ }| 227{2:[No Name] [+] }| 228one one one one one | 229two |hidden| h{2:e}re | 230three three | 231{1:~ }| 232{3:[No Name] [+] }| 233/e^ | 234]] ) 235feed ( '<Esc>v' ) 236screen : expect ( [[ 237one one one one one | 238two here | 239three three | 240Second window | 241{1:~ }| 242{2:[No Name] [+] }| 243one one one one one | 244two |hidden| {17:^h}ere | 245three three | 246{1:~ }| 247{3:[No Name] [+] }| 248{5:-- VISUAL --} | 249]] ) 250feed ( '<Esc>' ) 251 252-- Check that with cursor line is only concealed in Visual mode 253command ( 'set concealcursor=v' ) 254screen : expect ( [[ 255one one one one one | 256two here | 257three three | 258Second window | 259{1:~ }| 260{2:[No Name] [+] }| 261one one one one one | 262two |hidden| ^here | 263three three | 264{1:~ }| 265{3:[No Name] [+] }| 266| 267]] ) 268feed ( 'a' ) 269screen : expect ( [[ 270one one one one one | 271two here | 272three three | 273Second window | 274{1:~ }| 275{2:[No Name] [+] }| 276one one one one one | 277two |hidden| h^ere | 278three three | 279{1:~ }| 280{3:[No Name] [+] }| 281{5:-- INSERT --} | 282]] ) 283feed ( '<Esc>/e' ) 284screen : expect ( [[ 285one one one one one | 286two here | 287three three | 288Second window | 289{1:~ }| 290{2:[No Name] [+] }| 291one one one one one | 292two |hidden| h{2:e}re | 293three three | 294{1:~ }| 295{3:[No Name] [+] }| 296/e^ | 297]] ) 298feed ( '<Esc>v' ) 299screen : expect ( [[ 300one one one one one | 301two here | 302three three | 303Second window | 304{1:~ }| 305{2:[No Name] [+] }| 306one one one one one | 307two {17:^h}ere | 308three three | 309{1:~ }| 310{3:[No Name] [+] }| 311{5:-- VISUAL --} | 312]] ) 313feed ( '<Esc>' ) 314 315-- Check moving the cursor while in insert mode. 316command ( 'set concealcursor=' ) 317feed ( 'a' ) 318screen : expect ( [[ 319one one one one one | 320two here | 321three three | 322Second window | 323{1:~ }| 324{2:[No Name] [+] }| 325one one one one one | 326two |hidden| h^ere | 327three three | 328{1:~ }| 329{3:[No Name] [+] }| 330{5:-- INSERT --} | 331]] ) 332feed ( '<Down>' ) 333screen : expect ( [[ 334one one one one one | 335two here | 336three three | 337Second window | 338{1:~ }| 339{2:[No Name] [+] }| 340one one one one one | 341two here | 342three |hidden|^ three | 343{1:~ }| 344{3:[No Name] [+] }| 345{5:-- INSERT --} | 346]] ) 347feed ( '<Esc>' ) 348 349-- Check the "o" command 350screen : expect ( [[ 351one one one one one | 352two here | 353three three | 354Second window | 355{1:~ }| 356{2:[No Name] [+] }| 357one one one one one | 358two here | 359three |hidden^| three | 360{1:~ }| 361{3:[No Name] [+] }| 362| 363]] ) 364feed ( 'o' ) 365screen : expect ( [[ 366one one one one one | 367two here | 368three three | 369Second window | 370{1:~ }| 371{2:[No Name] [+] }| 372one one one one one | 373two here | 374three three | 375^ | 376{3:[No Name] [+] }| 377{5:-- INSERT --} | 378]] ) 379feed ( '<Esc>' ) 380end ) 381 382-- oldtest: Test_conceal_with_cursorcolumn() 383it ( 'CursorColumn and ColorColumn on wrapped line' , function () 384local screen =Screen . new ( 40 , 10 ) 385screen : add_extra_attr_ids { 386[ 100 ] ={ background =Screen . colors . LightRed } , 387} 388-- Check that cursorcolumn and colorcolumn don't get broken in presence of 389-- wrapped lines containing concealed text 390-- luacheck: push ignore 613 (trailing whitespace in a string) 391exec ( [[ 392let lines = ["one one one |hidden| one one one one one one one one", 393\ "two two two two |hidden| here two two", 394\ "three |hidden| three three three three three three three three"] 395call setline(1, lines) 396set wrap linebreak 397let &showbreak = ' >>> ' 398syntax match test /|hidden|/ conceal 399set conceallevel=2 400set concealcursor= 401exe "normal /here\r" 402set cursorcolumn 403set colorcolumn=50 404]] ) 405-- luacheck: pop 406 407screen : expect ( [[ 408one one one one one one {21:o}ne | 409{1: >>> }one {100:o}ne one one | 410two two two two |hidden| ^here two two | 411three three three three {21:t}hree | 412{1: >>> }thre{100:e} three three three | 413{1:~ }|*4 414/here | 415]] ) 416 417-- move cursor to the end of line (the cursor jumps to the next screen line) 418feed ( '$' ) 419screen : expect ( [[ 420one one one one one one one | 421{1: >>> }one {100:o}ne one one | 422two two two two |hidden| here two tw^o | 423three three three three three | 424{1: >>> }thre{100:e} three three three | 425{1:~ }|*4 426/here | 427]] ) 428end ) 429 430-- oldtest: Test_conceal_wrapped_cursorline_wincolor() 431it ( 'CursorLine highlight on wrapped lines' , function () 432local screen =Screen . new ( 40 , 4 ) 433screen : add_extra_attr_ids { 434[ 100 ] ={ background =Screen . colors . WebGreen } , 435} 436exec ( [[ 437call setline(1, 'one one one |hidden| one one one one one one one one') 438syntax match test /|hidden|/ conceal 439set conceallevel=2 concealcursor=n cursorline 440normal! g$ 441hi! CursorLine guibg=Green 442]] ) 443screen : expect ( [[ 444{100:one one one one one one one on^e }| 445{100: one one one }| 446{1:~ }| 447| 448]] ) 449command ( 'hi! CursorLine guibg=NONE guifg=Red' ) 450screen : expect ( [[ 451{19:one one one one one one one on^e }| 452{19: one one one }| 453{1:~ }| 454| 455]] ) 456end ) 457 458-- oldtest: Test_conceal_wrapped_cursorline_wincolor_rightleft() 459it ( 'CursorLine highlight on wrapped lines with rightleft' , function () 460local screen =Screen . new ( 40 , 4 ) 461screen : add_extra_attr_ids { 462[ 100 ] ={ background =Screen . colors . WebGreen } , 463} 464exec ( [[ 465call setline(1, 'one one one |hidden| one one one one one one one one') 466syntax match test /|hidden|/ conceal 467set conceallevel=2 concealcursor=n cursorline rightleft 468normal! g$ 469hi! CursorLine guibg=Green 470]] ) 471screen : expect ( [[ 472{100: ^eno eno eno eno eno eno eno eno}| 473{100: eno eno eno }| 474{1: ~}| 475| 476]] ) 477command ( 'hi! CursorLine guibg=NONE guifg=Red' ) 478screen : expect ( [[ 479{19: ^eno eno eno eno eno eno eno eno}| 480{19: eno eno eno }| 481{1: ~}| 482| 483]] ) 484end ) 485 486-- oldtest: Test_conceal_resize_term() 487it ( 'resize editor' , function () 488local screen =Screen . new ( 75 , 6 ) 489exec ( [[ 490call setline(1, '`one` `two` `three` `four` `five`, the backticks should be concealed') 491setl cocu=n cole=3 492syn region CommentCodeSpan matchgroup=Comment start=/`/ end=/`/ concealends 493normal fb 494]] ) 495screen : expect ( [[ 496one two three four five, the ^backticks should be concealed | 497{1:~ }|*4 498| 499]] ) 500 501screen : try_resize ( 75 , 7 ) 502screen : expect ( [[ 503one two three four five, the ^backticks should be concealed | 504{1:~ }|*5 505| 506]] ) 507end ) 508 509-- oldtest: Test_conceal_linebreak() 510it ( 'with linebreak' , function () 511local screen =Screen . new ( 75 , 8 ) 512exec ( [[ 513let &wrap = v:true 514let &conceallevel = 2 515let &concealcursor = 'nc' 516let &linebreak = v:true 517let &showbreak = '+ ' 518let line = 'a`a`a`a`' 519\ .. 'a'->repeat(&columns - 15) 520\ .. ' b`b`' 521\ .. 'b'->repeat(&columns - 10) 522\ .. ' cccccc' 523eval ['x'->repeat(&columns), '', line]->setline(1) 524syntax region CodeSpan matchgroup=Delimiter start=/\z(`\+\)/ end=/\z1/ concealends 525]] ) 526screen : expect ( [[ 527^xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx| 528| 529aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa | 530{1:+ }bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb | 531{1:+ }cccccc | 532{1:~ }|*2 533| 534]] ) 535end ) 536 537-- Tests for correct display (cursor column position) with +conceal and tabulators. 538-- oldtest: Test_conceal_cursor_pos() 539it ( 'cursor and column position with conceal and tabulators' , function () 540exec ( [[ 541let l = ['start:', '.concealed. text', "|concealed|\ttext"] 542let l += ['', "\t.concealed.\ttext", "\t|concealed|\ttext", ''] 543let l += [".a.\t.b.\t.c.\t.d.", "|a|\t|b|\t|c|\t|d|"] 544call append(0, l) 545call cursor(1, 1) 546" Conceal settings. 547set conceallevel=2 548set concealcursor=nc 549syntax match test /|/ conceal 550]] ) 551feed ( 'ztj' ) 552expect_pos ( 2 , 1 ) 553-- We should end up in the same column when running these commands on the 554-- two lines. 555feed ( 'ft' ) 556expect_pos ( 2 , 17 ) 557feed ( '$' ) 558expect_pos ( 2 , 20 ) 559feed ( '0j' ) 560expect_pos ( 3 , 1 ) 561feed ( 'ft' ) 562expect_pos ( 3 , 17 ) 563feed ( '$' ) 564expect_pos ( 3 , 20 ) 565feed ( 'j0j' ) 566expect_pos ( 5 , 8 ) 567-- Same for next test block. 568feed ( 'ft' ) 569expect_pos ( 5 , 25 ) 570feed ( '$' ) 571expect_pos ( 5 , 28 ) 572feed ( '0j' ) 573expect_pos ( 6 , 8 ) 574feed ( 'ft' ) 575expect_pos ( 6 , 25 ) 576feed ( '$' ) 577expect_pos ( 6 , 28 ) 578feed ( '0j0j' ) 579expect_pos ( 8 , 1 ) 580-- And check W with multiple tabs and conceals in a line. 581feed ( 'W' ) 582expect_pos ( 8 , 9 ) 583feed ( 'W' ) 584expect_pos ( 8 , 17 ) 585feed ( 'W' ) 586expect_pos ( 8 , 25 ) 587feed ( '$' ) 588expect_pos ( 8 , 27 ) 589feed ( '0j' ) 590expect_pos ( 9 , 1 ) 591feed ( 'W' ) 592expect_pos ( 9 , 9 ) 593feed ( 'W' ) 594expect_pos ( 9 , 17 ) 595feed ( 'W' ) 596expect_pos ( 9 , 25 ) 597feed ( '$' ) 598expect_pos ( 9 , 26 ) 599command ( 'set lbr' ) 600feed ( '$' ) 601expect_pos ( 9 , 26 ) 602command ( 'set list listchars=tab:>-' ) 603feed ( '0' ) 604expect_pos ( 9 , 1 ) 605feed ( 'W' ) 606expect_pos ( 9 , 9 ) 607feed ( 'W' ) 608expect_pos ( 9 , 17 ) 609feed ( 'W' ) 610expect_pos ( 9 , 25 ) 611feed ( '$' ) 612expect_pos ( 9 , 26 ) 613end ) 614 615local function test_conceal_virtualedit_after_eol ( wrap ) 616local screen =Screen . new ( 60 , 3 ) 617api . nvim_set_option_value ( 'wrap' , wrap , {} ) 618exec ( [[ 619call setline(1, 'abcdefgh|hidden|ijklmnpop') 620syntax match test /|hidden|/ conceal 621set conceallevel=2 concealcursor=n virtualedit=all 622normal! $ 623]] ) 624screen : expect ( [[ 625abcdefghijklmnpo^p | 626{1:~ }| 627| 628]] ) 629feed ( 'l' ) 630screen : expect ( [[ 631abcdefghijklmnpop^ | 632{1:~ }| 633| 634]] ) 635feed ( 'l' ) 636screen : expect ( [[ 637abcdefghijklmnpop ^ | 638{1:~ }| 639| 640]] ) 641feed ( 'l' ) 642screen : expect ( [[ 643abcdefghijklmnpop ^ | 644{1:~ }| 645| 646]] ) 647feed ( 'rr' ) 648screen : expect ( [[ 649abcdefghijklmnpop ^r | 650{1:~ }| 651| 652]] ) 653end 654 655-- oldtest: Test_conceal_virtualedit_after_eol() 656describe ( 'cursor drawn at correct column with virtualedit' , function () 657it ( 'with wrapping' , function () 658test_conceal_virtualedit_after_eol ( true ) 659end ) 660it ( 'without wrapping' , function () 661test_conceal_virtualedit_after_eol ( false ) 662end ) 663end ) 664 665local function test_conceal_virtualedit_after_eol_rightleft ( wrap ) 666local screen =Screen . new ( 60 , 3 ) 667api . nvim_set_option_value ( 'wrap' , wrap , {} ) 668exec ( [[ 669call setline(1, 'abcdefgh|hidden|ijklmnpop') 670syntax match test /|hidden|/ conceal 671set conceallevel=2 concealcursor=n virtualedit=all rightleft 672normal! $ 673]] ) 674screen : expect ( [[ 675^popnmlkjihgfedcba| 676{1: ~}| 677| 678]] ) 679feed ( 'h' ) 680screen : expect ( [[ 681^ popnmlkjihgfedcba| 682{1: ~}| 683| 684]] ) 685feed ( 'h' ) 686screen : expect ( [[ 687^ popnmlkjihgfedcba| 688{1: ~}| 689| 690]] ) 691feed ( 'h' ) 692screen : expect ( [[ 693^ popnmlkjihgfedcba| 694{1: ~}| 695| 696]] ) 697feed ( 'rr' ) 698screen : expect ( [[ 699^r popnmlkjihgfedcba| 700{1: ~}| 701| 702]] ) 703end 704 705-- oldtest: Test_conceal_virtualedit_after_eol_rightleft() 706describe ( 'cursor drawn correctly with virtualedit and rightleft' , function () 707it ( 'with wrapping' , function () 708test_conceal_virtualedit_after_eol_rightleft ( true ) 709end ) 710it ( 'without wrapping' , function () 711test_conceal_virtualedit_after_eol_rightleft ( false ) 712end ) 713end ) 714 715local function test_conceal_double_width ( wrap ) 716local screen =Screen . new ( 60 , 4 ) 717screen : add_extra_attr_ids { 718[ 100 ] ={ background =Screen . colors . LightRed } , 719} 720api . nvim_set_option_value ( 'wrap' , wrap , {} ) 721exec ( [[ 722call setline(1, ['aaaaa口=口bbbbb口=口ccccc', 'foobar']) 723syntax match test /口=口/ conceal cchar=β 724set conceallevel=2 concealcursor=n colorcolumn=30 725normal! $ 726]] ) 727screen : expect ( [[ 728aaaaa{14:β}bbbbb{14:β}cccc^c {100: } | 729foobar {100: } | 730{1:~ }| 731| 732]] ) 733feed ( 'gM' ) 734screen : expect ( [[ 735aaaaa{14:β}bb^bbb{14:β}ccccc {100: } | 736foobar {100: } | 737{1:~ }| 738| 739]] ) 740command ( 'set conceallevel=3' ) 741screen : expect ( [[ 742aaaaabb^bbbccccc {100: } | 743foobar {100: } | 744{1:~ }| 745| 746]] ) 747feed ( '$' ) 748screen : expect ( [[ 749aaaaabbbbbcccc^c {100: } | 750foobar {100: } | 751{1:~ }| 752| 753]] ) 754end 755 756-- oldtest: Test_conceal_double_width() 757describe ( 'cursor drawn correctly when double-width chars are concealed' , function () 758it ( 'with wrapping' , function () 759test_conceal_double_width ( true ) 760end ) 761it ( 'without wrapping' , function () 762test_conceal_double_width ( false ) 763end ) 764end ) 765 766-- oldtest: Test_conceal_double_width_wrap() 767it ( 'line wraps correctly when double-width chars are concealed' , function () 768local screen =Screen . new ( 20 , 4 ) 769screen : add_extra_attr_ids { 770[ 100 ] ={ background =Screen . colors . LightRed } , 771} 772exec ( [[ 773call setline(1, 'aaaaaaaaaa口=口bbbbbbbbbb口=口cccccccccc') 774syntax match test /口=口/ conceal cchar=β 775set conceallevel=2 concealcursor=n 776normal! $ 777]] ) 778screen : expect ( [[ 779aaaaaaaaaa{14:β}bbbbb | 780bbbbb{14:β}ccccccccc^c | 781{1:~ }| 782| 783]] ) 784feed ( 'gM' ) 785screen : expect ( [[ 786aaaaaaaaaa{14:β}bbbbb | 787^bbbbb{14:β}cccccccccc | 788{1:~ }| 789| 790]] ) 791command ( 'set conceallevel=3' ) 792screen : expect ( [[ 793aaaaaaaaaabbbbb | 794^bbbbbcccccccccc | 795{1:~ }| 796| 797]] ) 798feed ( '$' ) 799screen : expect ( [[ 800aaaaaaaaaabbbbb | 801bbbbbccccccccc^c | 802{1:~ }| 803| 804]] ) 805end ) 806end )