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' ) 4 5local describe , it , before_each , after_each =t . describe , t . it , t . before_each , t . after_each 6local clear , feed , command =n . clear , n . feed , n . command 7local fn =n . fn 8local api =n . api 9local eq =t . eq 10local eval =n . eval 11local retry =t . retry 12local testprg =n . testprg 13local is_os =t . is_os 14 15describe ( "'wildmenu'" , function () 16local screen 17before_each ( function () 18clear () 19screen =Screen . new ( 25 , 5 ) 20screen : add_extra_attr_ids { 21[ 100 ] ={ background =Screen . colors . Yellow1 , foreground =Screen . colors . Black } , 22} 23end ) 24 25-- oldtest: Test_wildmenu_screendump() 26it ( 'works' , function () 27screen : add_extra_attr_ids { 28[ 100 ] ={ background =Screen . colors . Yellow1 , foreground =Screen . colors . Black } , 29} 30-- Test simple wildmenu 31feed ( ':sign <Tab>' ) 32screen : expect { 33grid =[[ 34| 35{1:~ }|*2 36{100:define}{3: jump list > }| 37:sign define^ | 38]] , 39} 40 41feed ( '<Tab>' ) 42screen : expect { 43grid =[[ 44| 45{1:~ }|*2 46{3:define }{100:jump}{3: list > }| 47:sign jump^ | 48]] , 49} 50 51feed ( '<Tab>' ) 52screen : expect { 53grid =[[ 54| 55{1:~ }|*2 56{3:define jump }{100:list}{3: > }| 57:sign list^ | 58]] , 59} 60 61-- Looped back to the original value 62feed ( '<Tab><Tab><Tab><Tab>' ) 63screen : expect { 64grid =[[ 65| 66{1:~ }|*2 67{3:define jump list > }| 68:sign ^ | 69]] , 70} 71 72-- Test that the wild menu is cleared properly 73feed ( '<Space>' ) 74screen : expect { 75grid =[[ 76| 77{1:~ }|*3 78:sign ^ | 79]] , 80} 81 82-- Test that a different wildchar still works 83feed ( '<Esc>' ) 84command ( 'set wildchar=<Esc>' ) 85feed ( ':sign <Esc>' ) 86screen : expect { 87grid =[[ 88| 89{1:~ }|*2 90{100:define}{3: jump list > }| 91:sign define^ | 92]] , 93} 94 95-- Double-<Esc> is a hard-coded method to escape while wildchar=<Esc>. Make 96-- sure clean up is properly done in edge case like this. 97feed ( '<Esc>' ) 98screen : expect { 99grid =[[ 100^ | 101{1:~ }|*3 102| 103]] , 104} 105end ) 106 107it ( 'C-E to cancel wildmenu completion restore original input' , function () 108feed ( ':sign <tab>' ) 109screen : expect ( [[ 110| 111{1:~ }|*2 112{100:define}{3: jump list > }| 113:sign define^ | 114]] ) 115feed ( '<C-E>' ) 116screen : expect ( [[ 117| 118{1:~ }|*3 119:sign ^ | 120]] ) 121end ) 122 123it ( 'C-Y to apply selection and end wildmenu completion' , function () 124feed ( ':sign <tab>' ) 125screen : expect ( [[ 126| 127{1:~ }|*2 128{100:define}{3: jump list > }| 129:sign define^ | 130]] ) 131feed ( '<tab><C-Y>' ) 132screen : expect ( [[ 133| 134{1:~ }|*3 135:sign jump^ | 136]] ) 137end ) 138 139it ( ':sign <tab> shows wildmenu completions' , function () 140command ( 'set wildmenu wildmode=full' ) 141feed ( ':sign <tab>' ) 142screen : expect ( [[ 143| 144{1:~ }|*2 145{100:define}{3: jump list > }| 146:sign define^ | 147]] ) 148end ) 149 150it ( ':sign <tab> <space> hides wildmenu #8453' , function () 151command ( 'set wildmode=full' ) 152-- only a regression if status-line open 153command ( 'set laststatus=2' ) 154command ( 'set wildmenu' ) 155feed ( ':sign <tab>' ) 156screen : expect ( [[ 157| 158{1:~ }|*2 159{100:define}{3: jump list > }| 160:sign define^ | 161]] ) 162feed ( '<space>' ) 163screen : expect ( [[ 164| 165{1:~ }|*2 166{3:[No Name] }| 167:sign define ^ | 168]] ) 169end ) 170 171it ( 'does not crash after cycling back to original text' , function () 172command ( 'set wildmode=full' ) 173feed ( ':j<Tab><Tab><Tab>' ) 174screen : expect ( [[ 175| 176{1:~ }|*2 177{3:join jumps }| 178:j^ | 179]] ) 180-- This would cause nvim to crash before #6650 181feed ( '<BS><Tab>' ) 182screen : expect ( [[ 183| 184{1:~ }|*2 185{100:!}{3: # & < = > @ > }| 186:!^ | 187]] ) 188end ) 189 190it ( 'is preserved during :terminal activity' , function () 191command ( 'set wildmenu wildmode=full' ) 192command ( 'set scrollback=4' ) 193feed (( ':terminal "%s" REP 5000 !terminal_output!<cr>' ): format ( testprg ( 'shell-test' ))) 194feed ( 'G' ) -- Follow :terminal output. 195feed ( [[:sign <Tab>]] ) -- Invoke wildmenu. 196screen : add_extra_attr_ids { 197[ 100 ] ={ foreground =Screen . colors . Black , background =Screen . colors . Yellow } , 198[ 101 ] ={ 199bold =true , 200foreground =Screen . colors . White , 201background =Screen . colors . DarkGreen , 202} , 203} 204-- NB: in earlier versions terminal output was redrawn during cmdline mode. 205-- For now just assert that the screen remains unchanged. 206screen : expect { any ='{100:define}{101: jump list > }|\n:sign define^ |' } 207screen : expect_unchanged () 208 209-- cmdline CTRL-D display should also be preserved. 210feed ( [[<C-U>]] ) 211feed ( [[sign <C-D>]] ) -- Invoke cmdline CTRL-D. 212screen : expect { 213grid =[[ 214:sign | 215define place | 216jump undefine | 217list unplace | 218:sign ^ | 219]] , 220} 221screen : expect_unchanged () 222 223-- Exiting cmdline should show the buffer. 224feed ( [[<C-\><C-N>]] ) 225screen : expect { any =[[!terminal_output!]] } 226end ) 227 228it ( 'ignores :redrawstatus called from a timer #7108' , function () 229command ( 'set wildmenu wildmode=full' ) 230command ( [[call timer_start(10, {->execute('redrawstatus')}, {'repeat':-1})]] ) 231feed ( [[<C-\><C-N>]] ) 232feed ( [[:sign <Tab>]] ) -- Invoke wildmenu. 233screen : expect { 234grid =[[ 235| 236{1:~ }|*2 237{100:define}{3: jump list > }| 238:sign define^ | 239]] , 240} 241screen : expect_unchanged () 242end ) 243 244it ( 'with laststatus=0, :vsplit, :term #2255' , function () 245if not is_os ( 'win' ) then 246command ( 'set shell=sh' ) -- Need a predictable "$" prompt. 247command ( 'let $PS1 = "$"' ) 248end 249command ( 'set laststatus=0' ) 250command ( 'vsplit' ) 251command ( 'term' ) 252 253-- Check for a shell prompt to verify that the terminal loaded. 254retry ( nil , nil , function () 255if is_os ( 'win' ) then 256eq ( 'Microsoft' , eval ( "matchstr(join(getline(1, '$')), 'Microsoft')" )) 257else 258eq ( '$' , eval ( [[matchstr(getline(1), '\$')]] )) 259end 260end ) 261 262feed ( [[<C-\><C-N>]] ) 263feed ( [[:<Tab>]] ) -- Invoke wildmenu. 264screen : add_extra_attr_ids { 265[ 100 ] ={ foreground =Screen . colors . Black , background =Screen . colors . Yellow } , 266[ 101 ] ={ 267bold =true , 268foreground =Screen . colors . White , 269background =Screen . colors . DarkGreen , 270} , 271} 272-- Check only the last 2 lines, because the shell output is 273-- system-dependent. 274screen : expect { any ='{100:!}{101: # & < = > @ > }|\n:!^' } 275-- Because this test verifies a _lack_ of activity, we must wait the full timeout. 276-- So make it reasonable. 277screen : expect_unchanged ( false , 1000 ) 278end ) 279 280it ( 'wildmode=list,full and messages interaction #10092' , function () 281-- Need more than 5 rows, else tabline is covered and will be redrawn. 282screen : try_resize ( 25 , 7 ) 283 284command ( 'set wildmenu wildmode=list,full' ) 285command ( 'set showtabline=2' ) 286feed ( ':set wildm<tab>' ) 287screen : expect ( [[ 288{5: [No Name] }{2: }| 289| 290{1:~ }| 291{3: }| 292:set wildm | 293wildmenu wildmode | 294:set wildm^ | 295]] ) 296feed ( '<tab>' ) -- trigger wildmode full 297screen : expect ( [[ 298{5: [No Name] }{2: }| 299| 300{3: }| 301:set wildm | 302wildmenu wildmode | 303{100:wildmenu}{3: wildmode }| 304:set wildmenu^ | 305]] ) 306feed ( '<Esc>' ) 307screen : expect ( [[ 308{5: [No Name] }{2: }| 309^ | 310{1:~ }|*4 311| 312]] ) 313end ) 314 315it ( 'wildmode=longest,list' , function () 316-- Need more than 5 rows, else tabline is covered and will be redrawn. 317screen : try_resize ( 25 , 7 ) 318 319command ( 'set wildmenu wildmode=longest,list' ) 320 321-- give wildmode-longest something to expand to 322feed ( ':sign u<tab>' ) 323screen : expect ( [[ 324| 325{1:~ }|*5 326:sign un^ | 327]] ) 328feed ( '<tab>' ) -- trigger wildmode list 329screen : expect ( [[ 330| 331{1:~ }|*2 332{3: }| 333:sign un | 334undefine unplace | 335:sign un^ | 336]] ) 337feed ( '<Esc>' ) 338screen : expect ( [[ 339^ | 340{1:~ }|*5 341| 342]] ) 343 344-- give wildmode-longest something it cannot expand, use list 345feed ( ':sign un<tab>' ) 346screen : expect ( [[ 347| 348{1:~ }|*2 349{3: }| 350:sign un | 351undefine unplace | 352:sign un^ | 353]] ) 354feed ( '<tab>' ) 355screen : expect_unchanged () 356feed ( '<Esc>' ) 357screen : expect ( [[ 358^ | 359{1:~ }|*5 360| 361]] ) 362end ) 363 364it ( 'wildmode=list,longest' , function () 365-- Need more than 5 rows, else tabline is covered and will be redrawn. 366screen : try_resize ( 25 , 7 ) 367 368command ( 'set wildmenu wildmode=list,longest' ) 369feed ( ':sign u<tab>' ) 370screen : expect ( [[ 371| 372{1:~ }|*2 373{3: }| 374:sign u | 375undefine unplace | 376:sign u^ | 377]] ) 378feed ( '<tab>' ) -- trigger wildmode longest 379screen : expect ( [[ 380| 381{1:~ }|*2 382{3: }| 383:sign u | 384undefine unplace | 385:sign un^ | 386]] ) 387feed ( '<Esc>' ) 388screen : expect ( [[ 389^ | 390{1:~ }|*5 391| 392]] ) 393end ) 394 395it ( 'multiple <C-D> renders correctly' , function () 396screen : try_resize ( 25 , 7 ) 397 398command ( 'set laststatus=2' ) 399feed ( ':set wildm' ) 400feed ( '<c-d>' ) 401screen : expect ( [[ 402| 403{1:~ }|*2 404{3: }| 405:set wildm | 406wildmenu wildmode | 407:set wildm^ | 408]] ) 409feed ( '<c-d>' ) 410screen : expect ( [[ 411| 412{3: }| 413:set wildm | 414wildmenu wildmode | 415:set wildm | 416wildmenu wildmode | 417:set wildm^ | 418]] ) 419feed ( '<Esc>' ) 420screen : expect ( [[ 421^ | 422{1:~ }|*4 423{3:[No Name] }| 424| 425]] ) 426end ) 427 428it ( "<C-D> doesn't make statuslines disappear with 'nowildmenu' #36053" , function () 429screen : try_resize ( 60 , 10 ) 430command ( 'set laststatus=2 nowildmenu' ) 431feed ( ':sign <C-D>' ) 432screen : expect ( [[ 433| 434{1:~ }|*5 435{3: }| 436:sign | 437define jump list place undefine unplace | 438:sign ^ | 439]] ) 440feed ( '<Esc>' ) 441screen : expect ( [[ 442^ | 443{1:~ }|*7 444{3:[No Name] }| 445| 446]] ) 447command ( 'mode' ) 448screen : expect_unchanged () 449feed ( 'ifoobar<Esc>' ) 450screen : expect ( [[ 451fooba^r | 452{1:~ }|*7 453{3:[No Name] [+] }| 454| 455]] ) 456end ) 457 458it ( 'works with c_CTRL_Z standard mapping' , function () 459screen : add_extra_attr_ids { 460[ 100 ] ={ background =Screen . colors . Yellow1 , foreground =Screen . colors . Black } , 461} 462 463-- Wildcharm? where we are going we aint't no need no wildcharm. 464eq ( 0 , api . nvim_get_option_value ( 'wildcharm' , {} )) 465-- Don't mess the defaults yet (neovim is about backwards compatibility) 466eq ( 9 , api . nvim_get_option_value ( 'wildchar' , {} )) 467-- Lol what is cnoremap? Some say it can define mappings. 468command 'set wildchar=0' 469eq ( 0 , api . nvim_get_option_value ( 'wildchar' , {} )) 470 471command 'cnoremap <f2> <c-z>' 472feed ( ':syntax <f2>' ) 473screen : expect { 474grid =[[ 475| 476{1:~ }|*2 477{100:case}{3: clear cluster > }| 478:syntax case^ | 479]] , 480} 481feed '<esc>' 482 483command 'set wildmode=longest:full,full' 484-- this will get cleaner once we have native lua expr mappings: 485command [[cnoremap <expr> <tab> luaeval("not rawset(_G, 'coin', not coin).coin") ? "<c-z>" : "c"]] 486 487feed ':syntax <tab>' 488screen : expect { 489grid =[[ 490| 491{1:~ }|*3 492:syntax c^ | 493]] , 494} 495 496feed '<tab>' 497screen : expect { 498grid =[[ 499| 500{1:~ }|*2 501{3:case clear cluster > }| 502:syntax c^ | 503]] , 504} 505 506feed '<tab>' 507screen : expect { 508grid =[[ 509| 510{1:~ }|*3 511:syntax cc^ | 512]] , 513} 514end ) 515end ) 516 517describe ( 'command line completion' , function () 518local screen 519before_each ( function () 520clear () 521screen =Screen . new ( 40 , 5 ) 522screen : add_extra_attr_ids { 523[ 100 ] ={ background =Screen . colors . Yellow1 , foreground =Screen . colors . Black } , 524} 525end ) 526after_each ( function () 527os . remove ( 'Xtest-functional-viml-compl-dir' ) 528end ) 529 530it ( 'lists directories with empty PATH' , function () 531local tmp =fn . tempname () 532command ( 'e ' .. tmp ) 533command ( 'cd %:h' ) 534command ( "call mkdir('Xtest-functional-viml-compl-dir')" ) 535command ( 'let $PATH=""' ) 536feed ( ':!<tab><bs>' ) 537screen : expect ( [[ 538| 539{1:~ }|*3 540:!Xtest-functional-viml-compl-dir^ | 541]] ) 542end ) 543 544it ( 'completes env var names #9681' , function () 545command ( 'let $XTEST_1 = "foo" | let $XTEST_2 = "bar"' ) 546command ( 'set wildmenu wildmode=full' ) 547feed ( ':!echo $XTEST_<tab>' ) 548screen : expect ( [[ 549| 550{1:~ }|*2 551{100:XTEST_1}{3: XTEST_2 }| 552:!echo $XTEST_1^ | 553]] ) 554end ) 555 556it ( 'completes (multibyte) env var names #9655' , function () 557clear ( { env ={ 558[ 'XTEST_1AaあB' ] ='foo' , 559[ 'XTEST_2' ] ='bar' , 560} } ) 561screen : attach () 562command ( 'set wildmenu wildmode=full' ) 563feed ( ':!echo $XTEST_<tab>' ) 564screen : expect ( [[ 565| 566{1:~ }|*2 567{100:XTEST_1AaあB}{3: XTEST_2 }| 568:!echo $XTEST_1AaあB^ | 569]] ) 570end ) 571 572it ( 'does not leak memory with <S-Tab> with wildmenu and only one match #19874' , function () 573api . nvim_set_option_value ( 'wildmenu' , true , {} ) 574api . nvim_set_option_value ( 'wildmode' , 'full' , {} ) 575api . nvim_set_option_value ( 'wildoptions' , 'pum' , {} ) 576 577feed ( ':sign unpla<S-Tab>' ) 578screen : expect ( [[ 579| 580{1:~ }|*3 581:sign unplace^ | 582]] ) 583 584feed ( '<Space>buff<Tab>' ) 585screen : expect ( [[ 586| 587{1:~ }|*3 588:sign unplace buffer=^ | 589]] ) 590end ) 591 592it ( 'does not show matches with <S-Tab> without wildmenu with wildmode=full' , function () 593api . nvim_set_option_value ( 'wildmenu' , false , {} ) 594api . nvim_set_option_value ( 'wildmode' , 'full' , {} ) 595 596feed ( ':sign <S-Tab>' ) 597screen : expect ( [[ 598| 599{1:~ }|*3 600:sign unplace^ | 601]] ) 602end ) 603 604it ( 'shows matches with <S-Tab> without wildmenu with wildmode=list' , function () 605api . nvim_set_option_value ( 'wildmenu' , false , {} ) 606api . nvim_set_option_value ( 'wildmode' , 'list' , {} ) 607 608feed ( ':sign <S-Tab>' ) 609screen : expect ( [[ 610{3: }| 611:sign define | 612define list undefine | 613jump place unplace | 614:sign unplace^ | 615]] ) 616end ) 617end ) 618 619describe ( 'ui/ext_wildmenu' , function () 620local screen 621 622before_each ( function () 623clear () 624screen =Screen . new ( 25 , 5 , { rgb =true , ext_wildmenu =true } ) 625end ) 626 627local function test_ext_wildmenu_sign_cmd () 628local expected ={ 629'define' , 630'jump' , 631'list' , 632'place' , 633'undefine' , 634'unplace' , 635} 636 637command ( 'set wildmode=full' ) 638command ( 'set wildmenu' ) 639feed ( ':sign <tab>' ) 640screen : expect { 641grid =[[ 642| 643{1:~ }|*3 644:sign define^ | 645]] , 646wildmenu_items =expected , 647wildmenu_pos =0 , 648} 649 650feed ( '<tab>' ) 651screen : expect { 652grid =[[ 653| 654{1:~ }|*3 655:sign jump^ | 656]] , 657wildmenu_items =expected , 658wildmenu_pos =1 , 659} 660 661feed ( '<left><left>' ) 662screen : expect { 663grid =[[ 664| 665{1:~ }|*3 666:sign ^ | 667]] , 668wildmenu_items =expected , 669wildmenu_pos =- 1 , 670} 671 672feed ( '<right>' ) 673screen : expect { 674grid =[[ 675| 676{1:~ }|*3 677:sign define^ | 678]] , 679wildmenu_items =expected , 680wildmenu_pos =0 , 681} 682 683feed ( 'a' ) 684screen : expect ( [[ 685| 686{1:~ }|*3 687:sign definea^ | 688]] ) 689 690feed ( '<Esc>' ) 691command ( 'set wildmode=longest,full' ) 692feed ( ':sign u<tab>' ) 693screen : expect ( [[ 694| 695{1:~ }|*3 696:sign un^ | 697]] ) 698 699feed ( '<tab>' ) 700local s_undefine_unplace_0 ={ 701grid =[[ 702| 703{1:~ }|*3 704:sign undefine^ | 705]] , 706wildmenu_items ={ 'undefine' , 'unplace' } , 707wildmenu_pos =0 , 708} 709screen : expect ( s_undefine_unplace_0 ) 710 711feed ( '<Esc>' ) 712screen : expect ( [[ 713^ | 714{1:~ }|*3 715| 716]] ) 717 718feed ( ':sign un<tab>' ) 719screen : expect ( s_undefine_unplace_0 ) 720end 721 722describe ( 'works with :sign <tab>' , function () 723it ( 'with wildoptions=pum' , function () 724command ( 'set wildoptions=pum' ) 725test_ext_wildmenu_sign_cmd () 726end ) 727 728it ( 'with wildoptions=' , function () 729command ( 'set wildoptions=' ) 730test_ext_wildmenu_sign_cmd () 731end ) 732end ) 733end )