robin/laufey
git clone https://git.robinwobin.dev/robin/laufey
dab5fab948
master
1local n =require ( 'test.functional.testnvim' )() 2local t =require ( 'test.testutil' ) 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 feed =n . feed 9local feed_command =n . feed_command 10local exec =n . exec 11local api =n . api 12 13describe ( 'cmdline' , function () 14before_each ( clear ) 15 16-- oldtest: Test_cmdlineclear_tabenter() 17it ( 'is cleared when switching tabs' , function () 18local screen =Screen . new ( 30 , 10 ) 19 20feed_command ( [[call setline(1, range(30))]] ) 21screen : expect ( [[ 22^0 | 231 | 242 | 253 | 264 | 275 | 286 | 297 | 308 | 31:call setline(1, range(30)) | 32]] ) 33 34feed [[:tabnew<cr>]] 35screen : expect { 36grid =[[ 37{24: + [No Name] }{5: [No Name] }{2: }{24:X}| 38^ | 39{1:~ }|*7 40:tabnew | 41]] , 42} 43 44feed [[<C-w>-<C-w>-]] 45screen : expect { 46grid =[[ 47{24: + [No Name] }{5: [No Name] }{2: }{24:X}| 48^ | 49{1:~ }|*5 50|*3 51]] , 52} 53 54feed [[gt]] 55screen : expect { 56grid =[[ 57{5: + [No Name] }{24: [No Name] }{2: }{24:X}| 58^0 | 591 | 602 | 613 | 624 | 635 | 646 | 657 | 66| 67]] , 68} 69 70feed [[gt]] 71screen : expect ( [[ 72{24: + [No Name] }{5: [No Name] }{2: }{24:X}| 73^ | 74{1:~ }|*5 75|*3 76]] ) 77end ) 78 79-- oldtest: Test_verbose_option() 80it ( 'prints every executed Ex command if verbose >= 16' , function () 81local screen =Screen . new ( 60 , 12 ) 82exec ( [[ 83command DoSomething echo 'hello' |set ts=4 |let v = '123' |echo v 84call feedkeys("\r", 't') " for the hit-enter prompt 85set verbose=20 86]] ) 87feed_command ( 'DoSomething' ) 88screen : expect ( [[ 89| 90{1:~ }|*2 91{3: }| 92Executing: DoSomething | 93Executing: echo 'hello' |set ts=4 |let v = '123' |echo v | 94hello | 95Executing: set ts=4 |let v = '123' |echo v | 96Executing: let v = '123' |echo v | 97Executing: echo v | 98123 | 99{6:Press ENTER or type command to continue}^ | 100]] ) 101end ) 102 103-- oldtest: Test_cmdline_redraw_tabline() 104it ( 'tabline is redrawn on entering cmdline' , function () 105local screen =Screen . new ( 30 , 6 ) 106exec ( [[ 107set showtabline=2 108autocmd CmdlineEnter * set tabline=foo 109]] ) 110feed ( ':' ) 111screen : expect ( [[ 112{2:foo }| 113| 114{1:~ }|*3 115:^ | 116]] ) 117end ) 118 119-- oldtest: Test_wildmenu_with_input_func() 120it ( 'wildmenu works with input() function' , function () 121local screen =Screen . new ( 60 , 8 ) 122screen : add_extra_attr_ids ( { 123[ 100 ] ={ background =Screen . colors . Yellow , foreground =Screen . colors . Black } , 124} ) 125 126feed ( ":call input('Command? ', '', 'command')<CR>" ) 127screen : expect ( [[ 128| 129{1:~ }|*6 130Command? ^ | 131]] ) 132feed ( 'ech<Tab>' ) 133screen : expect ( [[ 134| 135{1:~ }|*5 136{100:echo}{3: echoerr echohl echomsg echon }| 137Command? echo^ | 138]] ) 139feed ( '<Space>' ) 140screen : expect ( [[ 141| 142{1:~ }|*6 143Command? echo ^ | 144]] ) 145feed ( 'bufn<Tab>' ) 146screen : expect ( [[ 147| 148{1:~ }|*5 149{100:bufname(}{3: bufnr( }| 150Command? echo bufname(^ | 151]] ) 152feed ( '<CR>' ) 153 154command ( 'set wildoptions+=pum' ) 155 156feed ( ":call input('Command? ', '', 'command')<CR>" ) 157screen : expect ( [[ 158| 159{1:~ }|*6 160Command? ^ | 161]] ) 162feed ( 'ech<Tab>' ) 163screen : expect ( [[ 164| 165{1:~ }| 166{1:~ }{12: echo }{1: }| 167{1:~ }{4: echoerr }{1: }| 168{1:~ }{4: echohl }{1: }| 169{1:~ }{4: echomsg }{1: }| 170{1:~ }{4: echon }{1: }| 171Command? echo^ | 172]] ) 173feed ( '<Space>' ) 174screen : expect ( [[ 175| 176{1:~ }|*6 177Command? echo ^ | 178]] ) 179feed ( 'bufn<Tab>' ) 180screen : expect ( [[ 181| 182{1:~ }|*4 183{1:~ }{12: bufname( }{1: }| 184{1:~ }{4: bufnr( }{1: }| 185Command? echo bufname(^ | 186]] ) 187feed ( '<CR>' ) 188end ) 189 190-- oldtest: Test_redraw_in_autocmd() 191it ( 'cmdline cursor position is correct after :redraw with cmdheight=2' , function () 192local screen =Screen . new ( 30 , 6 ) 193exec ( [[ 194set cmdheight=2 195autocmd CmdlineChanged * redraw 196]] ) 197feed ( ':for i in range(3)<CR>' ) 198screen : expect ( [[ 199| 200{1:~ }|*3 201:for i in range(3) | 202: ^ | 203]] ) 204feed ( ':let i =' ) 205-- Note: this may still be considered broken, ref #18140 206screen : expect ( [[ 207| 208{1:~ }|*3 209: :let i =^ | 210| 211]] ) 212end ) 213 214-- oldtest: Test_changing_cmdheight() 215it ( "changing 'cmdheight'" , function () 216local screen =Screen . new ( 60 , 8 ) 217exec ( [[ 218set cmdheight=1 laststatus=2 219func EchoOne() 220set laststatus=2 cmdheight=1 221echo 'foo' 222echo 'bar' 223set cmdheight=2 224endfunc 225func EchoTwo() 226set laststatus=2 227set cmdheight=5 228echo 'foo' 229echo 'bar' 230set cmdheight=1 231endfunc 232]] ) 233 234feed ( ':resize -3<CR>' ) 235screen : expect ( [[ 236^ | 237{1:~ }|*2 238{3:[No Name] }| 239|*4 240]] ) 241 242-- :resize now also changes 'cmdheight' accordingly 243feed ( ':set cmdheight+=1<CR>' ) 244screen : expect ( [[ 245^ | 246{1:~ }| 247{3:[No Name] }| 248|*5 249]] ) 250 251-- using more space moves the status line up 252feed ( ':set cmdheight+=1<CR>' ) 253screen : expect ( [[ 254^ | 255{3:[No Name] }| 256|*6 257]] ) 258 259-- reducing cmdheight moves status line down 260feed ( ':set cmdheight-=3<CR>' ) 261screen : expect ( [[ 262^ | 263{1:~ }|*3 264{3:[No Name] }| 265|*3 266]] ) 267 268-- reducing window size and then setting cmdheight 269feed ( ':resize -1<CR>' ) 270feed ( ':set cmdheight=1<CR>' ) 271screen : expect ( [[ 272^ | 273{1:~ }|*5 274{3:[No Name] }| 275| 276]] ) 277 278-- setting 'cmdheight' works after outputting two messages 279feed ( ':call EchoTwo()' ) 280screen : expect ( [[ 281| 282{1:~ }|*5 283{3:[No Name] }| 284:call EchoTwo()^ | 285]] ) 286feed ( '<CR>' ) 287screen : expect ( [[ 288^ | 289{1:~ }|*5 290{3:[No Name] }| 291| 292]] ) 293 294-- increasing 'cmdheight' doesn't clear the messages that need hit-enter 295feed ( ':call EchoOne()<CR>' ) 296screen : expect ( [[ 297| 298{1:~ }|*3 299{3: }| 300foo | 301bar | 302{6:Press ENTER or type command to continue}^ | 303]] ) 304 305-- window commands do not reduce 'cmdheight' to value lower than :set by user 306feed ( '<CR>:wincmd _<CR>' ) 307screen : expect ( [[ 308^ | 309{1:~ }|*4 310{3:[No Name] }| 311:wincmd _ | 312| 313]] ) 314end ) 315 316-- oldtest: Test_cmdheight_tabline() 317it ( "changing 'cmdheight' when there is a tabline" , function () 318local screen =Screen . new ( 60 , 8 ) 319api . nvim_set_option_value ( 'laststatus' , 2 , {} ) 320api . nvim_set_option_value ( 'showtabline' , 2 , {} ) 321api . nvim_set_option_value ( 'cmdheight' , 1 , {} ) 322screen : expect ( [[ 323{5: [No Name] }{2: }| 324^ | 325{1:~ }|*4 326{3:[No Name] }| 327| 328]] ) 329end ) 330 331-- oldtest: Test_wildmenu_with_pum_foldexpr() 332it ( 'pum when using &foldtext' , function () 333local screen =Screen . new ( 60 , 10 ) 334exec ( [[ 335call setline(1, ['folded one', 'folded two', 'some more text']) 336func MyFoldText() 337return 'foo' 338endfunc 339set foldtext=MyFoldText() wildoptions=pum 340normal ggzfj 341]] ) 342feed ( ':set<Tab>' ) 343screen : expect ( [[ 344{13:foo·························································}| 345some more text | 346{1:~ }|*3 347{12: set }{1: }| 348{4: setfiletype }{1: }| 349{4: setglobal }{1: }| 350{4: setlocal }{1: }| 351:set^ | 352]] ) 353feed ( '<Esc>' ) 354screen : expect ( [[ 355{13:^foo·························································}| 356some more text | 357{1:~ }|*7 358| 359]] ) 360end ) 361 362-- oldtest: Test_rulerformat_position() 363it ( "ruler has correct position with 'rulerformat' set" , function () 364local screen =Screen . new ( 20 , 3 ) 365api . nvim_set_option_value ( 'ruler' , true , {} ) 366api . nvim_set_option_value ( 'rulerformat' , 'longish' , {} ) 367api . nvim_set_option_value ( 'laststatus' , 0 , {} ) 368api . nvim_set_option_value ( 'winwidth' , 1 , {} ) 369feed [[<C-W>v<C-W>|<C-W>p]] 370screen : expect [[ 371│^ | 372{1:~ }│{1:~}| 373longish | 374]] 375end ) 376 377-- oldtest: Test_rulerformat_function() 378it ( "'rulerformat' can use %!" , function () 379local screen =Screen . new ( 40 , 2 ) 380exec ( [[ 381func TestRulerFn() 382return '10,20%=30%%' 383endfunc 384]] ) 385api . nvim_set_option_value ( 'ruler' , true , {} ) 386api . nvim_set_option_value ( 'rulerformat' , '%!TestRulerFn()' , {} ) 387screen : expect ( [[ 388^ | 38910,20 30%| 390]] ) 391end ) 392 393-- oldtest: Test_search_wildmenu_screendump() 394it ( 'wildmenu for search completion' , function () 395local screen =Screen . new ( 60 , 10 ) 396screen : add_extra_attr_ids ( { 397[ 100 ] ={ background =Screen . colors . Yellow , foreground =Screen . colors . Black } , 398} ) 399exec ( [[ 400set wildmenu wildcharm=<f5> wildoptions-=pum 401call setline(1, ['the', 'these', 'the', 'foobar', 'thethe', 'thethere']) 402]] ) 403 404-- Pattern has newline at EOF 405feed ( 'gg2j/e\\n<f5>' ) 406screen : expect ( [[ 407the | 408these | 409the | 410foobar | 411thethe | 412thethere | 413{1:~ }|*2 414{100:e\nfoobar}{3: e\nthethere e\nthese e\nthe }| 415/e\nfoobar^ | 416]] ) 417 418-- longest:full 419feed ( '<esc>' ) 420command ( 'set wim=longest,full' ) 421feed ( 'gg/t<f5>' ) 422screen : expect ( [[ 423the | 424these | 425the | 426foobar | 427thethe | 428thethere | 429{1:~ }|*3 430/the^ | 431]] ) 432 433-- list:full 434feed ( '<esc>' ) 435command ( 'set wim=list,full' ) 436feed ( 'gg/t<f5>' ) 437screen : expect ( [[ 438{10:t}he | 439{10:t}hese | 440{10:t}he | 441foobar | 442{10:t}he{10:t}he | 443{10:t}he{10:t}here | 444{3: }| 445/t | 446these the thethe thethere there | 447/t^ | 448]] ) 449 450-- noselect:full 451feed ( '<esc>' ) 452command ( 'set wim=noselect,full' ) 453feed ( 'gg/t<f5>' ) 454screen : expect ( [[ 455the | 456these | 457the | 458foobar | 459thethe | 460thethere | 461{1:~ }|*2 462{3:these the thethe thethere there }| 463/t^ | 464]] ) 465 466-- Multiline 467feed ( '<esc>gg/t.*\\n.*\\n.<tab>' ) 468screen : expect ( [[ 469the | 470these | 471the | 472foobar | 473thethe | 474thethere | 475{1:~ }|*2 476{3:t.*\n.*\n.oobar t.*\n.*\n.hethe t.*\n.*\n.he }| 477/t.*\n.*\n.^ | 478]] ) 479 480-- 'incsearch' is redrawn after accepting completion 481feed ( '<esc>' ) 482command ( 'set wim=full' ) 483command ( 'set incsearch hlsearch' ) 484feed ( '/th' ) 485screen : expect ( [[ 486{10:th}e | 487{2:th}ese | 488{10:th}e | 489foobar | 490{10:th}e{10:th}e | 491{10:th}e{10:th}ere | 492{1:~ }|*3 493/th^ | 494]] ) 495feed ( '<f5>' ) 496screen : expect ( [[ 497{10:th}e | 498{2:th}ese | 499{10:th}e | 500foobar | 501{10:th}e{10:th}e | 502{10:th}e{10:th}ere | 503{1:~ }|*2 504{100:these}{3: the thethe thethere there }| 505/these^ | 506]] ) 507feed ( '<c-n><c-y>' ) 508screen : expect ( [[ 509{10:the} | 510{2:the}se | 511{10:the} | 512foobar | 513{10:thethe} | 514{10:thethe}re | 515{1:~ }|*3 516/the^ | 517]] ) 518 519-- 'incsearch' highlight is restored after dismissing popup (Ctrl_E) 520feed ( '<esc>' ) 521command ( 'set wop=pum is nohls' ) 522feed ( 'gg/th<tab><c-e>' ) 523screen : expect ( [[ 524the | 525{2:th}ese | 526the | 527foobar | 528thethe | 529thethere | 530{1:~ }|*3 531/th^ | 532]] ) 533 534feed ( '<esc>' ) 535end ) 536 537-- oldtest: Test_search_wildmenu_iminsert() 538it ( 'search wildmenu pum with iminsert=1' , function () 539local screen =Screen . new ( 65 , 12 ) 540exec ( [[ 541set wop=pum imi=1 542setlocal iskeyword=!-~,192-255 543call setline(1, [ 544\ "global toggle global-local global/local glyphs toggles English", 545\ "accordingly. toggled accordingly single-byte", 546\ ]) 547call cursor(2, 42) 548]] ) 549feed ( '/gl<Tab>' ) 550screen : expect ( [[ 551{12: global }obal-local global/local glyphs toggles English | 552{4: gle }gled accordingly single-byte | 553{4: global-local }{1: }| 554{4: global/local }{1: }| 555{4: glyphs }{1: }| 556{4: gles }{1: }| 557{4: glish }{1: }| 558{4: gly. }{1: }| 559{4: gled }{1: }| 560{4: gly }{1: }| 561{4: gle-byte }{1: }| 562/global^ | 563]] ) 564end ) 565 566-- oldtest: Test_wildtrigger_update_screen() 567it ( 'pum by wildtrigger() avoids flicker' , function () 568local screen =Screen . new ( 40 , 10 ) 569exec ( [[ 570command! -nargs=* -complete=customlist,TestFn TestCmd echo 571func TestFn(cmdarg, b, c) 572if a:cmdarg == 'ax' 573return [] 574else 575return map(range(1, 5), 'printf("abc%d", v:val)') 576endif 577endfunc 578set wildmode=noselect,full 579set wildoptions=pum 580set wildmenu 581cnoremap <F8> <C-R>=wildtrigger()[-1]<CR> 582]] ) 583 584feed ( ':TestCmd a<F8>' ) 585local s1 =[[ 586| 587{1:~ }|*3 588{1:~ }{4: abc1 }{1: }| 589{1:~ }{4: abc2 }{1: }| 590{1:~ }{4: abc3 }{1: }| 591{1:~ }{4: abc4 }{1: }| 592{1:~ }{4: abc5 }{1: }| 593:TestCmd a^ | 594]] 595screen : expect ( s1 ) 596 597-- Typing a character when pum is open does not close the pum window 598-- This is needed to prevent pum window from flickering during 599-- ':h cmdline-autocompletion'. 600feed ( 'x' ) 601local s2 =[[ 602| 603{1:~ }|*3 604{1:~ }{4: abc1 }{1: }| 605{1:~ }{4: abc2 }{1: }| 606{1:~ }{4: abc3 }{1: }| 607{1:~ }{4: abc4 }{1: }| 608{1:~ }{4: abc5 }{1: }| 609:TestCmd ax^ | 610]] 611screen : expect ( s2 ) 612 613-- pum is closed when no completion candidates are available 614feed ( '<F8>' ) 615local s3 =[[ 616| 617{1:~ }|*8 618:TestCmd ax^ | 619]] 620screen : expect ( s3 ) 621 622feed ( '<BS><F8>' ) 623screen : expect ( s1 ) 624 625feed ( 'x' ) 626screen : expect ( s2 ) 627 628-- pum is closed when leaving cmdline mode 629feed ( '<Esc>' ) 630screen : expect ( [[ 631^ | 632{1:~ }|*8 633| 634]] ) 635 636feed ( ':TestCmd a<F8>' ) 637screen : expect ( s1 ) 638command ( 'redraw' ) 639screen : expect_unchanged () 640feed ( 'x' ) 641screen : expect ( s2 ) 642-- outdated pum is closed by :redraw #36808 643command ( 'redraw' ) 644screen : expect ( s3 ) 645end ) 646 647-- oldtest: Test_long_line_noselect() 648it ( "long line is shown properly with noselect in 'wildmode'" , function () 649local screen =Screen . new ( 60 , 8 ) 650exec ( [[ 651set wildmenu wildoptions=pum wildmode=noselect,full 652command -nargs=1 -complete=custom,Entries DoubleEntry echo 653func Entries(a, b, c) 654return 'loooooooooooooooong quite loooooooooooong, really loooooooooooong, probably too looooooooooooooooooooooooooong entry' 655endfunc 656]] ) 657 658feed ( ':DoubleEntry <Tab>' ) 659screen : expect ( [[ 660| 661{1:~ }|*5 662{1:~ }{4: loooooooooooooooong quite loooooooooooong, rea>}| 663:DoubleEntry ^ | 664]] ) 665 666feed ( '<C-N>' ) 667screen : expect ( [[ 668| 669{1:~ }|*3 670{3: }| 671:DoubleEntry loooooooooooooooong quite loooooooooooong, real| 672ly loooooooo{12: loooooooooooooooong quite loooooooooooong, rea>}| 673ong entry^ | 674]] ) 675 676feed ( '<C-N>' ) 677screen : expect ( [[ 678| 679{1:~ }|*3 680{3: }{4: loooooooooooooooong quite loooooooooooong, rea>}| 681:DoubleEntry ^ | 682|*2 683]] ) 684 685feed ( '<Esc>' ) 686end ) 687 688-- oldtest: Test_update_screen_after_wildtrigger() 689it ( 'pum is dismissed after wildtrigger() and whitespace' , function () 690local screen =Screen . new ( 40 , 10 ) 691exec ( [[ 692set wildmode=noselect:lastused,full wildmenu wildoptions=pum 693autocmd CmdlineChanged : if getcmdcompltype() != 'shellcmd' | call wildtrigger() | endif 694]] ) 695 696feed ( ':term' ) 697screen : expect ( [[ 698| 699{1:~ }|*7 700{4: terminal }{1: }| 701:term^ | 702]] ) 703feed ( ' ' ) 704screen : expect ( [[ 705| 706{1:~ }|*8 707:term ^ | 708]] ) 709feed ( 'foo' ) 710screen : expect ( [[ 711| 712{1:~ }|*8 713:term foo^ | 714]] ) 715end ) 716end )