robin/laufey
git clone https://git.robinwobin.dev/robin/laufey
60b643a815
master
1" Test argument list commands 2 3source check.vim 4source shared.vim 5source term_util.vim 6 7func Reset_arglist () 8args a | %argd 9endfunc 10 11func Test_argidx () 12args a b c 13last 14call assert_equal ( 2 , argidx ()) 15 %argdelete 16call assert_equal ( 0 , argidx ()) 17" doing it again doesn't result in an error 18 %argdelete 19call assert_equal ( 0 , argidx ()) 20call assert_fails ( '2argdelete' , 'E16:' ) 21 22args a b c 23call assert_equal ( 0 , argidx ()) 24next 25call assert_equal ( 1 , argidx ()) 26next 27call assert_equal ( 2 , argidx ()) 281 argdelete 29call assert_equal ( 1 , argidx ()) 301 argdelete 31call assert_equal ( 0 , argidx ()) 321 argdelete 33call assert_equal ( 0 , argidx ()) 34endfunc 35 36func Test_argadd () 37call Reset_arglist () 38 39 %argdelete 40argadd a b c 41call assert_equal ( 0 , argidx ()) 42 43 %argdelete 44argadd a 45call assert_equal ( 0 , argidx ()) 46argadd b c d 47call assert_equal ( 0 , argidx ()) 48 49call Init_abc () 50argadd x 51call Assert_argc ([ 'a' , 'b' , 'x' , 'c' ]) 52call assert_equal ( 1 , argidx ()) 53 54call Init_abc () 550 argadd x 56call Assert_argc ([ 'x' , 'a' , 'b' , 'c' ]) 57call assert_equal ( 2 , argidx ()) 58 59call Init_abc () 601 argadd x 61call Assert_argc ([ 'a' , 'x' , 'b' , 'c' ]) 62call assert_equal ( 2 , argidx ()) 63 64call Init_abc () 65$ argadd x 66call Assert_argc ([ 'a' , 'b' , 'c' , 'x' ]) 67call assert_equal ( 1 , argidx ()) 68 69call Init_abc () 70$ argadd x 71+2 argadd y 72call Assert_argc ([ 'a' , 'b' , 'c' , 'x' , 'y' ]) 73call assert_equal ( 1 , argidx ()) 74 75 %argd 76edit d 77arga 78call assert_equal ( 1 , len ( argv ())) 79call assert_equal ( 'd' , get ( argv (), 0 , '' )) 80 81 %argd 82edit some\ file 83arga 84call assert_equal ( 1 , len ( argv ())) 85call assert_equal ( 'some file' , get ( argv (), 0 , '' )) 86 87 %argd 88new 89arga 90call assert_equal ( 0 , len ( argv ())) 91 92if has ( 'unix' ) 93call assert_fails ( 'argadd `Xdoes_not_exist`' , 'E479:' ) 94endif 95endfunc 96 97func Test_argadd_empty_curbuf () 98new 99let curbuf = bufnr ( '%' ) 100call writefile ([ 'test' , 'Xargadd' ], 'Xargadd' , 'D' ) 101" must not re-use the current buffer. 102argadd Xargadd 103call assert_equal ( curbuf , bufnr ( '%' )) 104call assert_equal ( '' , bufname ( '%' )) 105call assert_equal ( 1 , '$' ->line ()) 106rew 107call assert_notequal ( curbuf , '%' ->bufnr ()) 108call assert_equal ( 'Xargadd' , '%' ->bufname ()) 109call assert_equal ( 2 , line ( '$' )) 110 111 %argd 112bwipe ! 113endfunc 114 115func Init_abc () 116args a b c 117next 118endfunc 119 120func Assert_argc ( l ) 121call assert_equal ( len ( a: l ), argc ()) 122let i = 0 123while i < len ( a: l ) && i < argc () 124call assert_equal ( a: l [ i ], argv ( i )) 125let i += 1 126endwhile 127endfunc 128 129" Test for [count]argument and [count]argdelete commands 130" Ported from the test_argument_count.in test script 131func Test_argument () 132call Reset_arglist () 133 134let save_hidden = & hidden 135set hidden 136 137let g: buffers = [] 138augroup TEST 139au BufEnter * call add ( buffers , expand ( '%:t' )) 140augroup END 141 142argadd a b c d 143$ argu 144$ -argu 145 -argu 1461 argu 147+2 argu 148 149augroup TEST 150au ! 151augroup END 152 153call assert_equal ([ 'd' , 'c' , 'b' , 'a' , 'c' ], g: buffers ) 154 155call assert_equal ( "\na b [c] d " , execute ( ':args' )) 156 157 .argd 158call assert_equal ([ 'a' , 'b' , 'd' ], argv ()) 159 160 -argd 161call assert_equal ([ 'a' , 'd' ], argv ()) 162 163$ argd 164call assert_equal ([ 'a' ], argv ()) 165 1661 arga c 1671 arga b 168$ argu 169$ arga x 170call assert_equal ([ 'a' , 'b' , 'c' , 'x' ], argv ()) 171 1720 arga y 173call assert_equal ([ 'y' , 'a' , 'b' , 'c' , 'x' ], argv ()) 174 175 %argd 176call assert_equal ([], argv ()) 177 178arga a b c d e f 1792 , $ -argd 180call assert_equal ([ 'a' , 'f' ], argv ()) 181 182let & hidden = save_hidden 183 184let save_columns = & columns 185let & columns = 79 186try 187exe 'args ' .. join ( range ( 1 , 81 )) 188call assert_equal ( join ([ 189 \'' , 190 \'[1] 6 11 16 21 26 31 36 41 46 51 56 61 66 71 76 81 ' , 191 \'2 7 12 17 22 27 32 37 42 47 52 57 62 67 72 77 ' , 192 \'3 8 13 18 23 28 33 38 43 48 53 58 63 68 73 78 ' , 193 \'4 9 14 19 24 29 34 39 44 49 54 59 64 69 74 79 ' , 194 \'5 10 15 20 25 30 35 40 45 50 55 60 65 70 75 80 ' , 195 \], "\n" ), 196 \execute ( 'args' )) 197 198" No trailing newline with one item per row. 199let long_arg = repeat ( 'X' , 81 ) 200exe 'args ' .. long_arg 201call assert_equal ( "\n[" . long_arg . ']' , execute ( 'args' )) 202finally 203let & columns = save_columns 204endtry 205 206" Setting argument list should fail when the current buffer has unsaved 207" changes 208 %argd 209enew ! 210set modified 211call assert_fails ( 'args x y z' , 'E37:' ) 212args ! x y z 213call assert_equal ([ 'x' , 'y' , 'z' ], argv ()) 214call assert_equal ( 'x' , expand ( '%:t' )) 215 216last |enew |argu 217call assert_equal ( 'z' , expand ( '%:t' )) 218 219 %argdelete 220call assert_fails ( 'argument' , 'E163:' ) 221endfunc 222 223func Test_list_arguments () 224" Clean the argument list 225arga a | %argd 226 227" four args half the screen width makes two lines with two columns 228let aarg = repeat ( 'a' , & columns / 2 - 4 ) 229let barg = repeat ( 'b' , & columns / 2 - 4 ) 230let carg = repeat ( 'c' , & columns / 2 - 4 ) 231let darg = repeat ( 'd' , & columns / 2 - 4 ) 232exe 'argadd ' aarg barg carg darg 233 234redir => result 235args 236redir END 237call assert_match ( '\[' . aarg . '] \+' . carg . '\n' . barg . ' \+' . darg , trim ( result )) 238 239" if one arg is longer than half the screen make one column 240exe 'argdel' aarg 241let aarg = repeat ( 'a' , & columns / 2 + 2 ) 242exe '0argadd' aarg 243redir => result 244args 245redir END 246call assert_match ( aarg . '\n\[' . barg . ']\n' . carg . '\n' . darg , trim ( result )) 247 248 %argdelete 249endfunc 250 251func Test_args_with_quote () 252" Only on Unix can a file name include a double quote. 253if has ( 'unix' ) 254args \"foobar 255call assert_equal ( '"foobar' , argv ( 0 )) 256 %argdelete 257endif 258endfunc 259 260" Test for 0argadd and 0argedit 261" Ported from the test_argument_0count.in test script 262func Test_zero_argadd () 263call Reset_arglist () 264 265arga a b c d 2662 argu 2670 arga added 268call assert_equal ([ 'added' , 'a' , 'b' , 'c' , 'd' ], argv ()) 269 2702 argu 271arga third 272call assert_equal ([ 'added' , 'a' , 'third' , 'b' , 'c' , 'd' ], argv ()) 273 274 %argd 275arga a b c d 2762 argu 2770 arge edited 278call assert_equal ([ 'edited' , 'a' , 'b' , 'c' , 'd' ], argv ()) 279 2802 argu 281arga third 282call assert_equal ([ 'edited' , 'a' , 'third' , 'b' , 'c' , 'd' ], argv ()) 283 2842 argu 285argedit file\ with\ spaces another file 286call assert_equal ([ 'edited' , 'a' , 'file with spaces' , 'another' , 'file' , 'third' , 'b' , 'c' , 'd' ], argv ()) 287call assert_equal ( 'file with spaces' , expand ( '%' )) 288endfunc 289 290" Test for argc() 291func Test_argc () 292call Reset_arglist () 293call assert_equal ( 0 , argc ()) 294argadd a b 295call assert_equal ( 2 , argc ()) 296endfunc 297 298" Test for arglistid() 299func Test_arglistid () 300call Reset_arglist () 301arga a b 302call assert_equal ( 0 , arglistid ()) 303split 304arglocal 305call assert_equal ( 1 , arglistid ()) 306tabnew |tabfirst 307call assert_equal ( 0 , arglistid ( 2 )) 308call assert_equal ( 1 , arglistid ( 1 , 1 )) 309call assert_equal ( 0 , arglistid ( 2 , 1 )) 310call assert_equal ( 1 , arglistid ( 1 , 2 )) 311tabonly |only |enew ! 312argglobal 313call assert_equal ( 0 , arglistid ()) 314endfunc 315 316" Tests for argv() and argc() 317func Test_argv () 318call Reset_arglist () 319call assert_equal ([], argv ()) 320call assert_equal ( "" , argv ( 2 )) 321call assert_equal ( 0 , argc ()) 322argadd a b c d 323call assert_equal ( 4 , argc ()) 324call assert_equal ( 'c' , argv ( 2 )) 325 326let w1_id = win_getid () 327split 328let w2_id = win_getid () 329arglocal 330args e f g 331tabnew 332let w3_id = win_getid () 333split 334let w4_id = win_getid () 335argglobal 336tabfirst 337call assert_equal ( 4 , argc ( w1_id )) 338call assert_equal ( 'b' , argv ( 1 , w1_id )) 339call assert_equal ([ 'a' , 'b' , 'c' , 'd' ], argv ( -1 , w1_id )) 340 341call assert_equal ( 3 , argc ( w2_id )) 342call assert_equal ( 'f' , argv ( 1 , w2_id )) 343call assert_equal ([ 'e' , 'f' , 'g' ], argv ( -1 , w2_id )) 344 345call assert_equal ( 3 , argc ( w3_id )) 346call assert_equal ( 'e' , argv ( 0 , w3_id )) 347call assert_equal ([ 'e' , 'f' , 'g' ], argv ( -1 , w3_id )) 348 349call assert_equal ( 4 , argc ( w4_id )) 350call assert_equal ( 'c' , argv ( 2 , w4_id )) 351call assert_equal ([ 'a' , 'b' , 'c' , 'd' ], argv ( -1 , w4_id )) 352 353call assert_equal ( 4 , argc ( -1 )) 354call assert_equal ( 3 , argc ()) 355call assert_equal ( 'd' , argv ( 3 , -1 )) 356call assert_equal ([ 'a' , 'b' , 'c' , 'd' ], argv ( -1 , -1 )) 357tabonly |only |enew ! 358" Negative test cases 359call assert_equal ( -1 , argc ( 100 )) 360call assert_equal ( '' , argv ( 1 , 100 )) 361call assert_equal ([], argv ( -1 , 100 )) 362call assert_equal ( '' , argv ( 10 , -1 )) 363 %argdelete 364endfunc 365 366" Test for the :argedit command 367func Test_argedit () 368call Reset_arglist () 369argedit a 370call assert_equal ([ 'a' ], argv ()) 371call assert_equal ( 'a' , expand ( '%:t' )) 372argedit b 373call assert_equal ([ 'a' , 'b' ], argv ()) 374call assert_equal ( 'b' , expand ( '%:t' )) 375argedit a 376call assert_equal ([ 'a' , 'b' , 'a' ], argv ()) 377call assert_equal ( 'a' , expand ( '%:t' )) 378" When file name case is ignored, an existing buffer with only case 379" difference is re-used. 380argedit C D 381call assert_equal ( 'C' , expand ( '%:t' )) 382call assert_equal ([ 'a' , 'b' , 'a' , 'C' , 'D' ], argv ()) 383argedit c 384if has ( 'fname_case' ) 385call assert_equal ([ 'a' , 'b' , 'a' , 'C' , 'c' , 'D' ], argv ()) 386else 387call assert_equal ([ 'a' , 'b' , 'a' , 'C' , 'C' , 'D' ], argv ()) 388endif 3890 argedit x 390if has ( 'fname_case' ) 391call assert_equal ([ 'x' , 'a' , 'b' , 'a' , 'C' , 'c' , 'D' ], argv ()) 392else 393call assert_equal ([ 'x' , 'a' , 'b' , 'a' , 'C' , 'C' , 'D' ], argv ()) 394endif 395enew ! |set modified 396call assert_fails ( 'argedit y' , 'E37:' ) 397argedit ! y 398if has ( 'fname_case' ) 399call assert_equal ([ 'x' , 'y' , 'y' , 'a' , 'b' , 'a' , 'C' , 'c' , 'D' ], argv ()) 400else 401call assert_equal ([ 'x' , 'y' , 'y' , 'a' , 'b' , 'a' , 'C' , 'C' , 'D' ], argv ()) 402endif 403 %argd 404bwipe ! C 405bwipe ! D 406 407" :argedit reuses the current buffer if it is empty 408 %argd 409" make sure to use a new buffer number for x when it is loaded 410bw ! x 411new 412let a = bufnr () 413argedit x 414call assert_equal ( a , bufnr ()) 415call assert_equal ( 'x' , bufname ()) 416 %argd 417bw ! x 418endfunc 419 420" Test for the :argdedupe command 421func Test_argdedupe () 422call Reset_arglist () 423argdedupe 424call assert_equal ([], argv ()) 425 426args a a a aa b b a b aa 427argdedupe 428call assert_equal ([ 'a' , 'aa' , 'b' ], argv ()) 429 430args a b c 431argdedupe 432call assert_equal ([ 'a' , 'b' , 'c' ], argv ()) 433 434args a 435argdedupe 436call assert_equal ([ 'a' ], argv ()) 437 438args a A b B 439argdedupe 440if has ( 'fname_case' ) 441call assert_equal ([ 'a' , 'A' , 'b' , 'B' ], argv ()) 442else 443call assert_equal ([ 'a' , 'b' ], argv ()) 444endif 445 446args a b a c a b 447last 448argdedupe 449next 450call assert_equal ( 'c' , expand ( '%:t' )) 451 452args a ./a 453argdedupe 454call assert_equal ([ 'a' ], argv ()) 455 456 %argd 457endfunc 458 459" Test for the :argdelete command 460func Test_argdelete () 461call Reset_arglist () 462args aa a aaa b bb 463argdelete a* 464call assert_equal ([ 'b' , 'bb' ], argv ()) 465call assert_equal ( 0 , argidx ()) 466call assert_equal ( 'aa' , expand ( '%:t' )) 467last 468call assert_equal ( 1 , argidx ()) 469call assert_equal ( 'bb' , expand ( '%:t' )) 470argdelete % 471call assert_equal ([ 'b' ], argv ()) 472call assert_equal ( 0 , argidx ()) 473call assert_equal ( 'bb' , expand ( '%:t' )) 474 475call assert_fails ( '1,100argdelete' , 'E16:' ) 476call assert_fails ( 'argdel /\)/' , 'E55:' ) 477call assert_fails ( '1argdel 1' , 'E474:' ) 478 479call Reset_arglist () 480args aa a aaa b bb 4814 argument 482call assert_equal ( 3 , argidx ()) 483call assert_equal ( 'b' , expand ( '%:t' )) 484argdelete aa* 485call assert_equal ([ 'a' , 'b' , 'bb' ], argv ()) 486call assert_equal ( 1 , argidx ()) 487call assert_equal ( 'b' , expand ( '%:t' )) 4882 argdelete 489call assert_equal ([ 'a' , 'bb' ], argv ()) 490call assert_equal ( 1 , argidx ()) 491call assert_equal ( 'b' , expand ( '%:t' )) 492 %argdelete 493call assert_equal ([], argv ()) 494call assert_equal ( 0 , argidx ()) 495call assert_equal ( 'b' , expand ( '%:t' )) 496" :%argdelete when the arglist is already empty should not error 497 %argdelete 498 499call Reset_arglist () 500args a b c d 501next 502argdel 503call Assert_argc ([ 'a' , 'c' , 'd' ]) 504 %argdel 505 506call assert_fails ( 'argdel does_not_exist' , 'E480:' ) 507endfunc 508 509func Test_argdelete_completion () 510args foo bar 511 512call feedkeys ( ":argdelete \<C-A>\<C-B>\"\<CR>" , 'tx' ) 513call assert_equal ( '"argdelete bar foo' , @:) 514 515call feedkeys ( ":argdelete x \<C-A>\<C-B>\"\<CR>" , 'tx' ) 516call assert_equal ( '"argdelete x bar foo' , @:) 517 518 %argd 519endfunc 520 521" Tests for the :next, :prev, :first, :last, :rewind commands 522func Test_argpos () 523call Reset_arglist () 524args a b c d 525last 526call assert_equal ( 3 , argidx ()) 527call assert_fails ( 'next' , 'E165:' ) 528prev 529call assert_equal ( 2 , argidx ()) 530Next 531call assert_equal ( 1 , argidx ()) 532first 533call assert_equal ( 0 , argidx ()) 534call assert_fails ( 'prev' , 'E164:' ) 5353 next 536call assert_equal ( 3 , argidx ()) 537rewind 538call assert_equal ( 0 , argidx ()) 539 %argd 540endfunc 541 542" Test for autocommand that redefines the argument list, when doing ":all". 543func Test_arglist_autocmd () 544autocmd BufReadPost Xxx2 next Xxx2 Xxx1 545call writefile ([ 'test file Xxx1' ], 'Xxx1' , 'D' ) 546call writefile ([ 'test file Xxx2' ], 'Xxx2' , 'D' ) 547call writefile ([ 'test file Xxx3' ], 'Xxx3' , 'D' ) 548 549new 550" redefine arglist; go to Xxx1 551next ! Xxx1 Xxx2 Xxx3 552" open window for all args; Reading Xxx2 will try to change the arglist and 553" that will fail 554call assert_fails ( "all" , "E1156:" ) 555call assert_equal ( 'test file Xxx1' , getline ( 1 )) 556wincmd w 557call assert_equal ( 'test file Xxx2' , getline ( 1 )) 558wincmd w 559call assert_equal ( 'test file Xxx3' , getline ( 1 )) 560 561autocmd ! BufReadPost Xxx2 562enew ! |only 563argdelete Xxx* 564bwipe ! Xxx1 Xxx2 Xxx3 565endfunc 566 567func Test_arg_all_expand () 568call writefile ([ 'test file Xxx1' ], 'Xx x' , 'D' ) 569next notexist Xx\ x runtest.vim 570call assert_equal ( 'notexist Xx\ x runtest.vim' , expand ( '##' )) 571endfunc 572 573func Test_large_arg () 574" Argument longer or equal to the number of columns used to cause 575" access to invalid memory. 576exe 'argadd ' . repeat ( 'x' , & columns ) 577args 578endfunc 579 580func Test_argdo () 581next ! Xa.c Xb.c Xc.c 582new 583 584let g: bufenter = 0 585let g: bufleave = 0 586autocmd BufEnter * let g: bufenter += 1 587autocmd BufLeave * let g: bufleave += 1 588 589let l = [] 590argdo call add(l, expand('%')) 591call assert_equal ([ 'Xa.c' , 'Xb.c' , 'Xc.c' ], l ) 592call assert_equal ( 3 , g: bufenter ) 593call assert_equal ( 3 , g: bufleave ) 594 595let g: bufenter = 0 596let g: bufleave = 0 597 598set eventignore = BufEnter,BufLeave 599let l = [] 600argdo call add(l, expand('%')) 601call assert_equal ([ 'Xa.c' , 'Xb.c' , 'Xc.c' ], l ) 602call assert_equal ( 0 , g: bufenter ) 603call assert_equal ( 0 , g: bufleave ) 604call assert_equal ( 'BufEnter,BufLeave' , & eventignore ) 605set eventignore & 606 607autocmd ! BufEnter 608autocmd ! BufLeave 609unlet g: bufenter 610unlet g: bufleave 611bwipe Xa.c Xb.c Xc.c 612endfunc 613 614" Test for quitting Vim with unedited files in the argument list 615func Test_quit_with_arglist () 616CheckRunVimInTerminal 617let buf = RunVimInTerminal ( '' , { 'rows' : 6 }) 618call term_sendkeys ( buf , ":set nomore\n" ) 619call term_sendkeys ( buf , ":args a b c\n" ) 620call term_sendkeys ( buf , ":quit\n" ) 621call TermWait ( buf ) 622call WaitForAssert ({ ->assert_match ( '^E173:' , term_getline ( buf , 6 ))}) 623call StopVimInTerminal ( buf ) 624 625" Try :confirm quit with unedited files in arglist 626let buf = RunVimInTerminal ( '' , { 'rows' : 6 }) 627call term_sendkeys ( buf , ":set nomore\n" ) 628call term_sendkeys ( buf , ":args a b c\n" ) 629call term_sendkeys ( buf , ":confirm quit\n" ) 630call TermWait ( buf ) 631call WaitForAssert ({ ->assert_match ( '^\[Y\]es, (N)o: *$' , 632 \term_getline ( buf , 6 ))}) 633call term_sendkeys ( buf , "N" ) 634call TermWait ( buf ) 635call term_sendkeys ( buf , ":confirm quit\n" ) 636call WaitForAssert ({ ->assert_match ( '^\[Y\]es, (N)o: *$' , 637 \term_getline ( buf , 6 ))}) 638call term_sendkeys ( buf , "Y" ) 639call TermWait ( buf ) 640call WaitForAssert ({ ->assert_equal ( "finished" , term_getstatus ( buf ))}) 641only ! 642" When this test fails, swap files are left behind which breaks subsequent 643" tests 644call delete ( '.a.swp' ) 645call delete ( '.b.swp' ) 646call delete ( '.c.swp' ) 647endfunc 648 649" Test for ":all" not working when in the cmdline window 650func Test_all_not_allowed_from_cmdwin () 651throw 'Skipped: Nvim supports cmdwin freedom #40312' 652au BufEnter * all 653next x 654" Use try/catch here, somehow assert_fails() doesn't work on MS-Windows 655" console. 656let caught = 'no' 657try 658exe ":norm! 7q?apat\<CR>" 659catch /E11:/ 660let caught = 'yes' 661endtry 662call assert_equal ( 'yes' , caught ) 663au ! BufEnter 664endfunc 665 666func Test_clear_arglist_in_all () 667n 0 00 000 0000 00000 000000 668au WinNew 0 n 0 669call assert_fails ( "all" , "E1156:" ) 670au ! * 671endfunc 672 673" Test for the :all command 674func Test_all_command () 675 %argdelete 676 677" :all command should not close windows with files in the argument list, 678" but can rearrange the windows. 679args Xargnew1 Xargnew2 680 %bw ! 681edit Xargold1 682split Xargnew1 683let Xargnew1_winid = win_getid () 684split Xargold2 685split Xargnew2 686let Xargnew2_winid = win_getid () 687split Xargold3 688all 689call assert_equal ( 2 , winnr ( '$' )) 690call assert_equal ([ Xargnew1_winid , Xargnew2_winid ], 691 \[ win_getid ( 1 ), win_getid ( 2 )]) 692call assert_equal ([ bufnr ( 'Xargnew1' ), bufnr ( 'Xargnew2' )], 693 \[ winbufnr ( 1 ), winbufnr ( 2 )]) 694 695" :all command should close windows for files which are not in the 696" argument list in the current tab page. 697 %bw ! 698edit Xargold1 699split Xargold2 700tabedit Xargold3 701split Xargold4 702tabedit Xargold5 703tabfirst 704all 705call assert_equal ( 3 , tabpagenr ( '$' )) 706call assert_equal ([ bufnr ( 'Xargnew1' ), bufnr ( 'Xargnew2' )], tabpagebuflist ( 1 )) 707call assert_equal ([ bufnr ( 'Xargold4' ), bufnr ( 'Xargold3' )], tabpagebuflist ( 2 )) 708call assert_equal ([ bufnr ( 'Xargold5' )], tabpagebuflist ( 3 )) 709 710" :tab all command should close windows for files which are not in the 711" argument list across all the tab pages. 712 %bw ! 713edit Xargold1 714split Xargold2 715tabedit Xargold3 716split Xargold4 717tabedit Xargold5 718tabfirst 719args Xargnew1 Xargnew2 720tab all 721call assert_equal ( 2 , tabpagenr ( '$' )) 722call assert_equal ([ bufnr ( 'Xargnew1' )], tabpagebuflist ( 1 )) 723call assert_equal ([ bufnr ( 'Xargnew2' )], tabpagebuflist ( 2 )) 724 725" If a count is specified, then :all should open only that many windows. 726 %bw ! 727args Xargnew1 Xargnew2 Xargnew3 Xargnew4 Xargnew5 728all 3 729call assert_equal ( 3 , winnr ( '$' )) 730call assert_equal ([ bufnr ( 'Xargnew1' ), bufnr ( 'Xargnew2' ), bufnr ( 'Xargnew3' )], 731 \[ winbufnr ( 1 ), winbufnr ( 2 ), winbufnr ( 3 )]) 732 733" The :all command should not open more than 'tabpagemax' tab pages. 734" If there are more files, then they should be opened in the last tab page. 735 %bw ! 736set tabpagemax = 3 737tab all 738call assert_equal ( 3 , tabpagenr ( '$' )) 739call assert_equal ([ bufnr ( 'Xargnew1' )], tabpagebuflist ( 1 )) 740call assert_equal ([ bufnr ( 'Xargnew2' )], tabpagebuflist ( 2 )) 741call assert_equal ([ bufnr ( 'Xargnew3' ), bufnr ( 'Xargnew4' ), bufnr ( 'Xargnew5' )], 742 \tabpagebuflist ( 3 )) 743set tabpagemax & 744 745" Without the 'hidden' option, modified buffers should not be closed. 746args Xargnew1 Xargnew2 747 %bw ! 748edit Xargtemp1 749call setline ( 1 , 'temp buffer 1' ) 750split Xargtemp2 751call setline ( 1 , 'temp buffer 2' ) 752all 753call assert_equal ( 4 , winnr ( '$' )) 754call assert_equal ([ bufnr ( 'Xargtemp2' ), bufnr ( 'Xargtemp1' ), bufnr ( 'Xargnew1' ), 755 \bufnr ( 'Xargnew2' )], 756 \[ winbufnr ( 1 ), winbufnr ( 2 ), winbufnr ( 3 ), winbufnr ( 4 )]) 757 758" With the 'hidden' option set, both modified and unmodified buffers in 759" closed windows should be hidden. 760set hidden 761all 762call assert_equal ( 2 , winnr ( '$' )) 763call assert_equal ([ bufnr ( 'Xargnew1' ), bufnr ( 'Xargnew2' )], 764 \[ winbufnr ( 1 ), winbufnr ( 2 )]) 765call assert_equal ([ 1 , 1 , 0 , 0 ], [ getbufinfo ( 'Xargtemp1' )[ 0 ]. hidden , 766 \getbufinfo ( 'Xargtemp2' )[ 0 ]. hidden , 767 \getbufinfo ( 'Xargnew1' )[ 0 ]. hidden , 768 \getbufinfo ( 'Xargnew2' )[ 0 ]. hidden ]) 769set nohidden 770 771" When 'winheight' is set to a large value, :all should open only one 772" window. 773args Xargnew1 Xargnew2 Xargnew3 Xargnew4 Xargnew5 774 %bw ! 775set winheight = 9999 776call assert_fails ( 'all' , 'E36:' ) 777call assert_equal ([ 1 , bufnr ( 'Xargnew1' )], [ winnr ( '$' ), winbufnr ( 1 )]) 778set winheight & 779 780" When 'winwidth' is set to a large value, :vert all should open only one 781" window. 782 %bw ! 783set winwidth = 9999 784call assert_fails ( 'vert all' , 'E36:' ) 785call assert_equal ([ 1 , bufnr ( 'Xargnew1' )], [ winnr ( '$' ), winbufnr ( 1 )]) 786set winwidth & 787 788" empty argument list tests 789 %bw ! 790 %argdelete 791call assert_equal ( '' , execute ( 'args' )) 792all 793call assert_equal ( 1 , winnr ( '$' )) 794 795 %argdelete 796 %bw ! 797endfunc 798 799" Test for deleting buffer when creating an arglist. This was accessing freed 800" memory 801func Test_crash_arglist_uaf () 802"%argdelete 803new one 804au BufAdd XUAFlocal : bw 805arglocal XUAFlocal 806au ! BufAdd 807bw ! XUAFlocal 808 809au BufAdd XUAFlocal2 : bw 810new two 811new three 812arglocal 813argadd XUAFlocal2 Xfoobar 814bw ! XUAFlocal2 815bw ! two 816 817au ! BufAdd 818endfunc 819 820" This was using freed memory again 821func Test_crash_arglist_uaf2 () 822new 823au BufAdd XUAFlocal : bw 824arglocal XUAFlocal 825redraw ! 826put ='abc' 8272 # 828au ! BufAdd 829endfunc 830 831func Test_arglist_w_locked_unlock () 832au BufAdd * split 833 834args a 835call assert_equal ( 2 , winnr ( '$' )) 836wincmd p 837quit 838call assert_equal ( 1 , winnr ( '$' )) 839 840argedit b 841call assert_equal ( 2 , winnr ( '$' )) 842wincmd p 843quit 844call assert_equal ( 1 , winnr ( '$' )) 845 846 %argd 847 %bw ! 848au ! BufAdd 849endfunc 850 851" vim: shiftwidth=2 sts=2 expandtab