robin/laufey
git clone https://git.robinwobin.dev/robin/laufey
e750f7c357
master
1" Test 'winfixbuf' 2 3source check.vim 4source shared.vim 5 6" Find the number of open windows in the current tab 7func s: get_windows_count () 8return tabpagewinnr ( tabpagenr (), '$' ) 9endfunc 10 11" Create some unnamed buffers. 12func s: make_buffers_list () 13enew 14file first 15let l: first = bufnr () 16 17enew 18file middle 19let l: middle = bufnr () 20 21enew 22file last 23let l: last = bufnr () 24 25set winfixbuf 26 27return [ l: first , l: last ] 28endfunc 29 30" Create some unnamed buffers and add them to an args list 31func s: make_args_list () 32let [ l: first , l: last ] = s: make_buffers_list () 33 34args ! first middle last 35 36return [ l: first , l: last ] 37endfunc 38 39" Create two buffers and then set the window to 'winfixbuf' 40func s: make_buffer_pairs (...) 41let l: reversed = get ( a: , 1 , 0 ) 42 43if l: reversed == 1 44enew 45file original 46 47set winfixbuf 48 49enew ! 50file other 51let l: other = bufnr () 52 53return l: other 54endif 55 56enew 57file other 58let l: other = bufnr () 59 60enew 61file current 62 63set winfixbuf 64 65return l: other 66endfunc 67 68" Create 3 quick buffers and set the window to 'winfixbuf' 69func s: make_buffer_trio () 70edit first 71let l: first = bufnr () 72edit second 73let l: second = bufnr () 74 75set winfixbuf 76 77edit ! third 78let l: third = bufnr () 79 80exe $ ":buffer! {l: second }" 81 82return [ l: first , l: second , l: third ] 83endfunc 84 85" Create a location list with at least 2 entries + a 'winfixbuf' window. 86func s: make_simple_location_list () 87enew 88file middle 89let l: middle = bufnr () 90call append ( 0 , [ "winfix search-term" , "another line" ]) 91 92enew ! 93file first 94let l: first = bufnr () 95call append ( 0 , "first search-term" ) 96 97enew ! 98file last 99let l: last = bufnr () 100call append ( 0 , "last search-term" ) 101 102call setloclist ( 103 \0 , 104 \[ 105 \{ 106 \"filename" : "first" , 107 \"bufnr" : l: first , 108 \"lnum" : 1 , 109 \}, 110 \{ 111 \"filename" : "middle" , 112 \"bufnr" : l: middle , 113 \"lnum" : 1 , 114 \}, 115 \{ 116 \"filename" : "middle" , 117 \"bufnr" : l: middle , 118 \"lnum" : 2 , 119 \}, 120 \{ 121 \"filename" : "last" , 122 \"bufnr" : l: last , 123 \"lnum" : 1 , 124 \}, 125 \] 126 \) 127 128set winfixbuf 129 130return [ l: first , l: middle , l: last ] 131endfunc 132 133" Create a quickfix with at least 2 entries that are in the current 'winfixbuf' window. 134func s: make_simple_quickfix () 135enew 136file current 137let l: current = bufnr () 138call append ( 0 , [ "winfix search-term" , "another line" ]) 139 140enew ! 141file first 142let l: first = bufnr () 143call append ( 0 , "first search-term" ) 144 145enew ! 146file last 147let l: last = bufnr () 148call append ( 0 , "last search-term" ) 149 150call setqflist ( 151 \[ 152 \{ 153 \"filename" : "first" , 154 \"bufnr" : l: first , 155 \"lnum" : 1 , 156 \}, 157 \{ 158 \"filename" : "current" , 159 \"bufnr" : l: current , 160 \"lnum" : 1 , 161 \}, 162 \{ 163 \"filename" : "current" , 164 \"bufnr" : l: current , 165 \"lnum" : 2 , 166 \}, 167 \{ 168 \"filename" : "last" , 169 \"bufnr" : l: last , 170 \"lnum" : 1 , 171 \}, 172 \] 173 \) 174 175set winfixbuf 176 177return [ l: current , l: last ] 178endfunc 179 180" Create a quickfix with at least 2 entries that are in the current 'winfixbuf' window. 181func s: make_quickfix_windows () 182let [ l: current , _ ] = s: make_simple_quickfix () 183exe $ "buffer! {l: current }" 184 185split 186let l: first_window = win_getid () 187exe "normal \<C-w>j" 188let l: winfix_window = win_getid () 189 190" Open the quickfix in a separate split and go to it 191copen 192let l: quickfix_window = win_getid () 193 194return [ l: first_window , l: winfix_window , l: quickfix_window ] 195endfunc 196 197" Revert all changes that occurred in any past test 198func s: reset_all_buffers () 199 %bwipeout ! 200set nowinfixbuf 201 202call setqflist ([]) 203call setloclist ( 0 , [], 'f' ) 204 205delmarks A-Z0-9 206endfunc 207 208" Find and set the first quickfix entry that points to `buffer` 209func s: set_quickfix_by_buffer ( buffer ) 210let l: index = 1 " quickfix indices start at 1 211for l: entry in getqflist () 212if l: entry [ "bufnr" ] == a: buffer 213exe $ "{l: index } cc" 214 215return 216endif 217 218let l: index += 1 219endfor 220 221echoerr $ 'No quickfix entry matching {a:buffer} could be found.' 222endfunc 223 224" Fail to call :Next on a 'winfixbuf' window unless :Next! is used. 225func Test_Next () 226call s: reset_all_buffers () 227 228let [ l: first , _ ] = s: make_args_list () 229next ! 230 231call assert_fails ( "Next" , "E1513:" ) 232call assert_notequal ( l: first , bufnr ()) 233 234Next ! 235call assert_equal ( l: first , bufnr ()) 236endfunc 237 238" Call :argdo and choose the next available 'nowinfixbuf' window. 239func Test_argdo_choose_available_window () 240call s: reset_all_buffers () 241 242let [ _ , l: last ] = s: make_args_list () 243 244" Make a split window that is 'nowinfixbuf' but make it the second-to-last 245" window so that :argdo will first try the 'winfixbuf' window, pass over it, 246" and prefer the other 'nowinfixbuf' window, instead. 247" 248" +-------------------+ 249" | 'nowinfixbuf' | 250" +-------------------+ 251" | 'winfixbuf' | <-- Cursor is here 252" +-------------------+ 253split 254let l: nowinfixbuf_window = win_getid () 255" Move to the 'winfixbuf' window now 256exe "normal \<C-w>j" 257let l: winfixbuf_window = win_getid () 258let l: expected_windows = s: get_windows_count () 259 260argdo echo'' 261call assert_equal ( l: nowinfixbuf_window , win_getid ()) 262call assert_equal ( l: last , bufnr ()) 263call assert_equal ( l: expected_windows , s: get_windows_count ()) 264endfunc 265 266" Call :argdo and create a new split window if all available windows are 'winfixbuf'. 267func Test_argdo_make_new_window () 268call s: reset_all_buffers () 269 270let [ l: first , l: last ] = s: make_args_list () 271let l: current = win_getid () 272let l: current_windows = s: get_windows_count () 273 274argdo echo'' 275call assert_notequal ( l: current , win_getid ()) 276call assert_equal ( l: last , bufnr ()) 277exe "normal \<C-w>j" 278call assert_equal ( l: first , bufnr ()) 279call assert_equal ( l: current_windows + 1 , s: get_windows_count ()) 280endfunc 281 282" Fail :argedit but :argedit! is allowed 283func Test_argedit () 284call s: reset_all_buffers () 285 286args ! first middle last 287enew 288file first 289let l: first = bufnr () 290 291enew 292file middle 293let l: middle = bufnr () 294 295enew 296file last 297let l: last = bufnr () 298 299set winfixbuf 300 301let l: current = bufnr () 302call assert_fails ( "argedit first middle last" , "E1513:" ) 303call assert_equal ( l: current , bufnr ()) 304 305argedit ! first middle last 306call assert_equal ( l: first , bufnr ()) 307endfunc 308 309" Fail :arglocal but :arglocal! is allowed 310func Test_arglocal () 311call s: reset_all_buffers () 312 313let l: other = s: make_buffer_pairs () 314let l: current = bufnr () 315argglobal ! other 316exe $ "buffer! {l: current }" 317 318call assert_fails ( "arglocal other" , "E1513:" ) 319call assert_equal ( l: current , bufnr ()) 320 321arglocal ! other 322call assert_equal ( l: other , bufnr ()) 323endfunc 324 325" Fail :argglobal but :argglobal! is allowed 326func Test_argglobal () 327call s: reset_all_buffers () 328 329let l: other = s: make_buffer_pairs () 330let l: current = bufnr () 331 332call assert_fails ( "argglobal other" , "E1513:" ) 333call assert_equal ( l: current , bufnr ()) 334 335argglobal ! other 336call assert_equal ( l: other , bufnr ()) 337endfunc 338 339" Fail :args but :args! is allowed 340func Test_args () 341call s: reset_all_buffers () 342 343let [ l: first , _ ] = s: make_buffers_list () 344let l: current = bufnr () 345 346call assert_fails ( "args first middle last" , "E1513:" ) 347call assert_equal ( l: current , bufnr ()) 348 349args ! first middle last 350call assert_equal ( l: first , bufnr ()) 351endfunc 352 353" Fail :bNext but :bNext! is allowed 354func Test_bNext () 355call s: reset_all_buffers () 356 357let l: other = s: make_buffer_pairs () 358call assert_fails ( "bNext" , "E1513:" ) 359let l: current = bufnr () 360 361call assert_equal ( l: current , bufnr ()) 362 363bNext ! 364call assert_equal ( l: other , bufnr ()) 365endfunc 366 367" Allow :badd because it doesn't actually change the current window's buffer 368func Test_badd () 369call s: reset_all_buffers () 370 371call s: make_buffer_pairs () 372let l: current = bufnr () 373 374badd other 375call assert_equal ( l: current , bufnr ()) 376endfunc 377 378" Allow :balt because it doesn't actually change the current window's buffer 379func Test_balt () 380call s: reset_all_buffers () 381 382call s: make_buffer_pairs () 383let l: current = bufnr () 384 385balt other 386call assert_equal ( l: current , bufnr ()) 387endfunc 388 389" Fail :bfirst but :bfirst! is allowed 390func Test_bfirst () 391call s: reset_all_buffers () 392 393let l: other = s: make_buffer_pairs () 394let l: current = bufnr () 395 396call assert_fails ( "bfirst" , "E1513:" ) 397call assert_equal ( l: current , bufnr ()) 398 399bfirst ! 400call assert_equal ( l: other , bufnr ()) 401endfunc 402 403" Fail :blast but :blast! is allowed 404func Test_blast () 405call s: reset_all_buffers () 406 407let l: other = s: make_buffer_pairs ( 1 ) 408bfirst ! 409let l: current = bufnr () 410 411call assert_fails ( "blast" , "E1513:" ) 412call assert_equal ( l: current , bufnr ()) 413 414blast ! 415call assert_equal ( l: other , bufnr ()) 416endfunc 417 418" Fail :bmodified but :bmodified! is allowed 419func Test_bmodified () 420call s: reset_all_buffers () 421 422let l: other = s: make_buffer_pairs () 423let l: current = bufnr () 424 425exe $ "buffer! {l: other }" 426set modified 427exe $ "buffer! {l: current }" 428 429call assert_fails ( "bmodified" , "E1513:" ) 430call assert_equal ( l: current , bufnr ()) 431 432bmodified ! 433call assert_equal ( l: other , bufnr ()) 434endfunc 435 436" Fail :bnext but :bnext! is allowed 437func Test_bnext () 438call s: reset_all_buffers () 439 440let l: other = s: make_buffer_pairs () 441let l: current = bufnr () 442 443call assert_fails ( "bnext" , "E1513:" ) 444call assert_equal ( l: current , bufnr ()) 445 446bnext ! 447call assert_equal ( l: other , bufnr ()) 448endfunc 449 450" Fail :bprevious but :bprevious! is allowed 451func Test_bprevious () 452call s: reset_all_buffers () 453 454let l: other = s: make_buffer_pairs () 455let l: current = bufnr () 456 457call assert_fails ( "bprevious" , "E1513:" ) 458call assert_equal ( l: current , bufnr ()) 459 460bprevious ! 461call assert_equal ( l: other , bufnr ()) 462endfunc 463 464" Fail :brewind but :brewind! is allowed 465func Test_brewind () 466call s: reset_all_buffers () 467 468let l: other = s: make_buffer_pairs () 469let l: current = bufnr () 470 471call assert_fails ( "brewind" , "E1513:" ) 472call assert_equal ( l: current , bufnr ()) 473 474brewind ! 475call assert_equal ( l: other , bufnr ()) 476endfunc 477 478" Fail :browse edit but :browse edit! is allowed 479func Test_browse_edit_fail () 480" A GUI dialog may stall the test. 481CheckNotGui 482 483call s: reset_all_buffers () 484 485let l: other = s: make_buffer_pairs () 486let l: current = bufnr () 487 488call assert_fails ( "browse edit other" , "E1513:" ) 489call assert_equal ( l: current , bufnr ()) 490 491try 492 browse edit! other 493call assert_equal ( l: other , bufnr ()) 494catch /^Vim\%((\a\+)\)\=:E338:/ 495" Ignore E338, which occurs if console Vim is built with +browse. 496" Console Vim without +browse will treat this as a regular :edit. 497endtry 498endfunc 499 500" Allow :browse w because it doesn't change the buffer in the current file 501func Test_browse_edit_pass () 502" A GUI dialog may stall the test. 503CheckNotGui 504 505call s: reset_all_buffers () 506 507let l: other = s: make_buffer_pairs () 508let l: current = bufnr () 509 510try 511 browse write other 512catch /^Vim\%((\a\+)\)\=:E338:/ 513" Ignore E338, which occurs if console Vim is built with +browse. 514" Console Vim without +browse will treat this as a regular :write. 515endtry 516 517call delete ( "other" ) 518endfunc 519 520" Call :bufdo and choose the next available 'nowinfixbuf' window. 521func Test_bufdo_choose_available_window () 522call s: reset_all_buffers () 523 524let l: other = s: make_buffer_pairs () 525 526" Make a split window that is 'nowinfixbuf' but make it the second-to-last 527" window so that :bufdo will first try the 'winfixbuf' window, pass over it, 528" and prefer the other 'nowinfixbuf' window, instead. 529" 530" +-------------------+ 531" | 'nowinfixbuf' | 532" +-------------------+ 533" | 'winfixbuf' | <-- Cursor is here 534" +-------------------+ 535split 536let l: nowinfixbuf_window = win_getid () 537" Move to the 'winfixbuf' window now 538exe "normal \<C-w>j" 539let l: winfixbuf_window = win_getid () 540 541let l: current = bufnr () 542let l: expected_windows = s: get_windows_count () 543 544call assert_notequal ( l: current , l: other ) 545 546bufdo echo'' 547call assert_equal ( l: nowinfixbuf_window , win_getid ()) 548call assert_notequal ( l: other , bufnr ()) 549call assert_equal ( l: expected_windows , s: get_windows_count ()) 550endfunc 551 552" Call :bufdo and create a new split window if all available windows are 'winfixbuf'. 553func Test_bufdo_make_new_window () 554call s: reset_all_buffers () 555 556let [ l: first , l: last ] = s: make_buffers_list () 557exe $ "buffer! {l: first }" 558let l: current = win_getid () 559let l: current_windows = s: get_windows_count () 560 561bufdo echo'' 562call assert_notequal ( l: current , win_getid ()) 563call assert_equal ( l: last , bufnr ()) 564exe "normal \<C-w>j" 565call assert_equal ( l: first , bufnr ()) 566call assert_equal ( l: current_windows + 1 , s: get_windows_count ()) 567endfunc 568 569" Fail :buffer but :buffer! is allowed 570func Test_buffer () 571call s: reset_all_buffers () 572 573let l: other = s: make_buffer_pairs () 574let l: current = bufnr () 575 576call assert_fails ( $ "buffer {l: other } ", "E1513:") 577call assert_equal ( l: current , bufnr ()) 578 579exe $ "buffer! {l: other }" 580call assert_equal ( l: other , bufnr ()) 581endfunc 582 583" Allow :buffer on a 'winfixbuf' window if there is no change in buffer 584func Test_buffer_same_buffer () 585call s: reset_all_buffers () 586 587call s: make_buffer_pairs () 588let l: current = bufnr () 589 590exe $ "buffer {l: current }" 591call assert_equal ( l: current , bufnr ()) 592 593exe $ "buffer! {l: current }" 594call assert_equal ( l: current , bufnr ()) 595endfunc 596 597" Allow :cNext but the 'nowinfixbuf' window is selected, instead 598func Test_cNext () 599CheckFeature quickfix 600call s: reset_all_buffers () 601 602let [ l: first_window , l: winfix_window , l: quickfix_window ] = s: make_quickfix_windows () 603 604" The call to `:cNext` succeeds but it selects the window with 'nowinfixbuf' instead 605call s: set_quickfix_by_buffer ( winbufnr ( l: winfix_window )) 606 607" Make sure the previous window has 'winfixbuf' so we can test that our 608" "skip 'winfixbuf' window" logic works. 609call win_gotoid ( l: winfix_window ) 610call win_gotoid ( l: quickfix_window ) 611 612cNext 613call assert_equal ( l: first_window , win_getid ()) 614endfunc 615 616" Allow :cNfile but the 'nowinfixbuf' window is selected, instead 617func Test_cNfile () 618CheckFeature quickfix 619call s: reset_all_buffers () 620 621let [ l: first_window , l: winfix_window , l: quickfix_window ] = s: make_quickfix_windows () 622 623" The call to `:cNfile` succeeds but it selects the window with 'nowinfixbuf' instead 624call s: set_quickfix_by_buffer ( winbufnr ( l: winfix_window )) 625cnext ! 626 627" Make sure the previous window has 'winfixbuf' so we can test that our 628" "skip 'winfixbuf' window" logic works. 629call win_gotoid ( l: winfix_window ) 630call win_gotoid ( l: quickfix_window ) 631 632cNfile 633call assert_equal ( l: first_window , win_getid ()) 634endfunc 635 636" Allow :caddexpr because it doesn't change the current buffer 637func Test_caddexpr () 638CheckFeature quickfix 639call s: reset_all_buffers () 640 641let l: file_path = tempname () 642call writefile ([ "Error - bad-thing-found" ], l: file_path , 'D' ) 643exe $ "edit {l: file_path }" 644let l: file_buffer = bufnr () 645let l: current = bufnr () 646 647edit first.unittest 648call append ( 0 , [ "some-search-term bad-thing-found" ]) 649 650edit ! other.unittest 651 652set winfixbuf 653 654exe $ "buffer! {l: file_buffer }" 655 656exe 'caddexpr expand("%") .. ":" .. line(".") .. ":" .. getline(".")' 657call assert_equal ( l: current , bufnr ()) 658endfunc 659 660" Fail :cbuffer but :cbuffer! is allowed 661func Test_cbuffer () 662CheckFeature quickfix 663call s: reset_all_buffers () 664 665let l: file_path = tempname () 666call writefile ([ "first.unittest:1:Error - bad-thing-found" ], l: file_path , 'D' ) 667exe $ "edit {l: file_path }" 668let l: file_buffer = bufnr () 669let l: current = bufnr () 670 671edit first.unittest 672call append ( 0 , [ "some-search-term bad-thing-found" ]) 673 674edit ! other.unittest 675 676set winfixbuf 677 678exe $ "buffer! {file_buffer}" 679 680call assert_fails ( $ "cbuffer {file_buffer}", "E1513: Cannot switch buffer. 'winfixbuf' is enabled") 681call assert_equal ( current , bufnr ()) 682 683exe $ "cbuffer! {file_buffer}" 684call assert_equal ( "first.unittest" , expand ( "%:t" )) 685endfunc 686 687" Allow :cc but the 'nowinfixbuf' window is selected, instead 688func Test_cc () 689CheckFeature quickfix 690call s: reset_all_buffers () 691 692let [ l: first_window , l: winfix_window , l: quickfix_window ] = s: make_quickfix_windows () 693 694" The call to `:cnext` succeeds but it selects the window with 'nowinfixbuf' instead 695call s: set_quickfix_by_buffer ( winbufnr ( l: winfix_window )) 696 697" Make sure the previous window has 'winfixbuf' so we can test that our 698" "skip 'winfixbuf' window" logic works. 699call win_gotoid ( l: winfix_window ) 700call win_gotoid ( l: quickfix_window ) 701" Go up one line in the quickfix window to an quickfix entry that doesn't 702" point to a winfixbuf buffer 703normal k 704" Attempt to make the previous window, winfixbuf buffer, to go to the 705" non-winfixbuf quickfix entry 706 .cc 707 708" Confirm that :.cc did not change the winfixbuf-enabled window 709call assert_equal ( l: first_window , win_getid ()) 710endfunc 711 712" Call :cdo and choose the next available 'nowinfixbuf' window. 713func Test_cdo_choose_available_window () 714CheckFeature quickfix 715call s: reset_all_buffers () 716 717let [ l: current , l: last ] = s: make_simple_quickfix () 718exe $ "buffer! {l: current }" 719 720" Make a split window that is 'nowinfixbuf' but make it the second-to-last 721" window so that :cdo will first try the 'winfixbuf' window, pass over it, 722" and prefer the other 'nowinfixbuf' window, instead. 723" 724" +-------------------+ 725" | 'nowinfixbuf' | 726" +-------------------+ 727" | 'winfixbuf' | <-- Cursor is here 728" +-------------------+ 729split 730let l: nowinfixbuf_window = win_getid () 731" Move to the 'winfixbuf' window now 732exe "normal \<C-w>j" 733let l: winfixbuf_window = win_getid () 734let l: expected_windows = s: get_windows_count () 735 736cdo echo'' 737 738call assert_equal ( l: nowinfixbuf_window , win_getid ()) 739call assert_equal ( l: last , bufnr ()) 740exe "normal \<C-w>j" 741call assert_equal ( l: current , bufnr ()) 742call assert_equal ( l: expected_windows , s: get_windows_count ()) 743endfunc 744 745" Call :cdo and create a new split window if all available windows are 'winfixbuf'. 746func Test_cdo_make_new_window () 747CheckFeature quickfix 748call s: reset_all_buffers () 749 750let [ l: current_buffer , l: last ] = s: make_simple_quickfix () 751exe $ "buffer! {l: current_buffer }" 752 753let l: current_window = win_getid () 754let l: current_windows = s: get_windows_count () 755 756cdo echo'' 757call assert_notequal ( l: current_window , win_getid ()) 758call assert_equal ( l: last , bufnr ()) 759exe "normal \<C-w>j" 760call assert_equal ( l: current_buffer , bufnr ()) 761call assert_equal ( l: current_windows + 1 , s: get_windows_count ()) 762endfunc 763 764" Fail :cexpr but :cexpr! is allowed 765func Test_cexpr () 766CheckFeature quickfix 767call s: reset_all_buffers () 768 769let file = tempname () 770let entry = $ '["{file}:1:bar"]' 771let current = bufnr () 772 773set winfixbuf 774 775call assert_fails ( $ "cexpr {entry}", "E1513: Cannot switch buffer. 'winfixbuf' is enabled") 776call assert_equal ( current , bufnr ()) 777 778exe $ "cexpr! {entry}" 779call assert_equal ( fnamemodify ( file , ":t" ), expand ( "%:t" )) 780endfunc 781 782" Call :cfdo and choose the next available 'nowinfixbuf' window. 783func Test_cfdo_choose_available_window () 784CheckFeature quickfix 785call s: reset_all_buffers () 786 787let [ l: current , l: last ] = s: make_simple_quickfix () 788exe $ "buffer! {l: current }" 789 790" Make a split window that is 'nowinfixbuf' but make it the second-to-last 791" window so that :cfdo will first try the 'winfixbuf' window, pass over it, 792" and prefer the other 'nowinfixbuf' window, instead. 793" 794" +-------------------+ 795" | 'nowinfixbuf' | 796" +-------------------+ 797" | 'winfixbuf' | <-- Cursor is here 798" +-------------------+ 799split 800let l: nowinfixbuf_window = win_getid () 801" Move to the 'winfixbuf' window now 802exe "normal \<C-w>j" 803let l: winfixbuf_window = win_getid () 804let l: expected_windows = s: get_windows_count () 805 806cfdo echo'' 807 808call assert_equal ( l: nowinfixbuf_window , win_getid ()) 809call assert_equal ( l: last , bufnr ()) 810exe "normal \<C-w>j" 811call assert_equal ( l: current , bufnr ()) 812call assert_equal ( l: expected_windows , s: get_windows_count ()) 813endfunc 814 815" Call :cfdo and create a new split window if all available windows are 'winfixbuf'. 816func Test_cfdo_make_new_window () 817CheckFeature quickfix 818call s: reset_all_buffers () 819 820let [ l: current_buffer , l: last ] = s: make_simple_quickfix () 821exe $ "buffer! {l: current_buffer }" 822 823let l: current_window = win_getid () 824let l: current_windows = s: get_windows_count () 825 826cfdo echo'' 827call assert_notequal ( l: current_window , win_getid ()) 828call assert_equal ( l: last , bufnr ()) 829exe "normal \<C-w>j" 830call assert_equal ( l: current_buffer , bufnr ()) 831call assert_equal ( l: current_windows + 1 , s: get_windows_count ()) 832endfunc 833 834" Fail :cfile but :cfile! is allowed 835func Test_cfile () 836CheckFeature quickfix 837call s: reset_all_buffers () 838 839edit first.unittest 840call append ( 0 , [ "some-search-term bad-thing-found" ]) 841write 842let first = bufnr () 843 844edit ! second.unittest 845call append ( 0 , [ "some-search-term" ]) 846write 847 848let file = tempname () 849call writefile ([ "first.unittest:1:Error - bad-thing-found was detected" ], file ) 850 851let current = bufnr () 852 853set winfixbuf 854 855call assert_fails ( $ ":cfile {file}", "E1513: Cannot switch buffer. 'winfixbuf' is enabled") 856call assert_equal ( current , bufnr ()) 857 858exe $ ":cfile! {file}" 859call assert_equal ( first , bufnr ()) 860 861call delete ( file ) 862call delete ( "first.unittest" ) 863call delete ( "second.unittest" ) 864endfunc 865 866" Allow :cfirst but the 'nowinfixbuf' window is selected, instead 867func Test_cfirst () 868CheckFeature quickfix 869call s: reset_all_buffers () 870 871let [ l: first_window , l: winfix_window , l: quickfix_window ] = s: make_quickfix_windows () 872 873" The call to `:cfirst` succeeds but it selects the window with 'nowinfixbuf' instead 874call s: set_quickfix_by_buffer ( winbufnr ( l: winfix_window )) 875 876" Make sure the previous window has 'winfixbuf' so we can test that our 877" "skip 'winfixbuf' window" logic works. 878call win_gotoid ( l: winfix_window ) 879call win_gotoid ( l: quickfix_window ) 880 881cfirst 882call assert_equal ( l: first_window , win_getid ()) 883endfunc 884 885" Allow :clast but the 'nowinfixbuf' window is selected, instead 886func Test_clast () 887CheckFeature quickfix 888call s: reset_all_buffers () 889 890let [ l: first_window , l: winfix_window , l: quickfix_window ] = s: make_quickfix_windows () 891 892" The call to `:clast` succeeds but it selects the window with 'nowinfixbuf' instead 893call s: set_quickfix_by_buffer ( winbufnr ( l: winfix_window )) 894 895" Make sure the previous window has 'winfixbuf' so we can test that our 896" "skip 'winfixbuf' window" logic works. 897call win_gotoid ( l: winfix_window ) 898call win_gotoid ( l: quickfix_window ) 899 900clast 901call assert_equal ( l: first_window , win_getid ()) 902endfunc 903 904" Allow :cnext but the 'nowinfixbuf' window is selected, instead 905" Make sure no new windows are created and previous windows are reused 906func Test_cnext () 907CheckFeature quickfix 908call s: reset_all_buffers () 909 910let [ l: first_window , l: winfix_window , l: quickfix_window ] = s: make_quickfix_windows () 911let l: expected = s: get_windows_count () 912 913" The call to `:cnext` succeeds but it selects the window with 'nowinfixbuf' instead 914call s: set_quickfix_by_buffer ( winbufnr ( l: winfix_window )) 915 916cnext ! 917call assert_equal ( l: expected , s: get_windows_count ()) 918 919" Make sure the previous window has 'winfixbuf' so we can test that our 920" "skip 'winfixbuf' window" logic works. 921call win_gotoid ( l: winfix_window ) 922call win_gotoid ( l: quickfix_window ) 923 924cnext 925call assert_equal ( l: first_window , win_getid ()) 926call assert_equal ( l: expected , s: get_windows_count ()) 927endfunc 928 929" Make sure :cnext creates a split window if no previous window exists 930func Test_cnext_no_previous_window () 931CheckFeature quickfix 932call s: reset_all_buffers () 933 934let [ l: current , _ ] = s: make_simple_quickfix () 935exe $ "buffer! {l: current }" 936 937let l: expected = s: get_windows_count () 938 939" Open the quickfix in a separate split and go to it 940copen 941 942call assert_equal ( l: expected + 1 , s: get_windows_count ()) 943endfunc 944 945" Allow :cnext and create a 'nowinfixbuf' window if none exists 946func Test_cnext_make_new_window () 947CheckFeature quickfix 948call s: reset_all_buffers () 949 950let [ l: current , _ ] = s: make_simple_quickfix () 951let l: current = win_getid () 952 953cfirst ! 954 955let l: windows = s: get_windows_count () 956let l: expected = l: windows + 1 " We're about to create a new split window 957 958cnext 959call assert_equal ( l: expected , s: get_windows_count ()) 960 961cnext ! 962call assert_equal ( l: expected , s: get_windows_count ()) 963endfunc 964 965" Allow :cprevious but the 'nowinfixbuf' window is selected, instead 966func Test_cprevious () 967CheckFeature quickfix 968call s: reset_all_buffers () 969 970let [ l: first_window , l: winfix_window , l: quickfix_window ] = s: make_quickfix_windows () 971 972" The call to `:cprevious` succeeds but it selects the window with 'nowinfixbuf' instead 973call s: set_quickfix_by_buffer ( winbufnr ( l: winfix_window )) 974 975" Make sure the previous window has 'winfixbuf' so we can test that our 976" "skip 'winfixbuf' window" logic works. 977call win_gotoid ( l: winfix_window ) 978call win_gotoid ( l: quickfix_window ) 979 980cprevious 981call assert_equal ( l: first_window , win_getid ()) 982endfunc 983 984" Allow :cnfile but the 'nowinfixbuf' window is selected, instead 985func Test_cnfile () 986CheckFeature quickfix 987call s: reset_all_buffers () 988 989let [ l: first_window , l: winfix_window , l: quickfix_window ] = s: make_quickfix_windows () 990 991" The call to `:cnfile` succeeds but it selects the window with 'nowinfixbuf' instead 992call s: set_quickfix_by_buffer ( winbufnr ( l: winfix_window )) 993cnext ! 994 995" Make sure the previous window has 'winfixbuf' so we can test that our 996" "skip 'winfixbuf' window" logic works. 997call win_gotoid ( l: winfix_window ) 998call win_gotoid ( l: quickfix_window ) 999 1000cnfile 1001call assert_equal ( l: first_window , win_getid ()) 1002endfunc 1003 1004" Allow :cpfile but the 'nowinfixbuf' window is selected, instead 1005func Test_cpfile () 1006CheckFeature quickfix 1007call s: reset_all_buffers () 1008 1009let [ l: first_window , l: winfix_window , l: quickfix_window ] = s: make_quickfix_windows () 1010 1011" The call to `:cpfile` succeeds but it selects the window with 'nowinfixbuf' instead 1012call s: set_quickfix_by_buffer ( winbufnr ( l: winfix_window )) 1013cnext ! 1014 1015" Make sure the previous window has 'winfixbuf' so we can test that our 1016" "skip 'winfixbuf' window" logic works. 1017call win_gotoid ( l: winfix_window ) 1018call win_gotoid ( l: quickfix_window ) 1019 1020cpfile 1021call assert_equal ( l: first_window , win_getid ()) 1022endfunc 1023 1024" Allow :crewind but the 'nowinfixbuf' window is selected, instead 1025func Test_crewind () 1026CheckFeature quickfix 1027call s: reset_all_buffers () 1028 1029let [ l: first_window , l: winfix_window , l: quickfix_window ] = s: make_quickfix_windows () 1030 1031" The call to `:crewind` succeeds but it selects the window with 'nowinfixbuf' instead 1032call s: set_quickfix_by_buffer ( winbufnr ( l: winfix_window )) 1033cnext ! 1034 1035" Make sure the previous window has 'winfixbuf' so we can test that our 1036" "skip 'winfixbuf' window" logic works. 1037call win_gotoid ( l: winfix_window ) 1038call win_gotoid ( l: quickfix_window ) 1039 1040crewind 1041call assert_equal ( l: first_window , win_getid ()) 1042endfunc 1043 1044" Allow <C-w>f because it opens in a new split 1045func Test_ctrl_w_f () 1046call s: reset_all_buffers () 1047 1048enew 1049let l: file_name = tempname () 1050call writefile ([], l: file_name ) 1051let l: file_buffer = bufnr () 1052 1053enew 1054file other 1055let l: other_buffer = bufnr () 1056 1057set winfixbuf 1058 1059call setline ( 1 , l: file_name ) 1060let l: current_windows = s: get_windows_count () 1061exe "normal \<C-w>f" 1062 1063call assert_equal ( l: current_windows + 1 , s: get_windows_count ()) 1064 1065call delete ( l: file_name ) 1066endfunc 1067 1068" Fail :djump but :djump! is allowed 1069func Test_djump () 1070call s: reset_all_buffers () 1071 1072let l: include_file = tempname () .. ".h" 1073call writefile ([ "min(1, 12);" , 1074 \$ '#include "{l: include_file } "' 1075 \ ], 1076 \ "main.c") 1077call writefile ([ "#define min(X, Y) ((X) < (Y) ? (X) : (Y))" ], l: include_file ) 1078edit main.c 1079 1080set winfixbuf 1081 1082let l: current = bufnr () 1083 1084call assert_fails ( "djump 1 /min/" , "E1513:" ) 1085call assert_equal ( l: current , bufnr ()) 1086 1087djump ! 1 /min/ 1088call assert_notequal ( l: current , bufnr ()) 1089 1090call delete ( "main.c" ) 1091call delete ( l: include_file ) 1092endfunc 1093 1094" Fail :drop but :drop! is allowed 1095func Test_drop () 1096call s: reset_all_buffers () 1097 1098let l: other = s: make_buffer_pairs () 1099let l: current = bufnr () 1100 1101call assert_fails ( "drop other" , "E1513:" ) 1102call assert_equal ( l: current , bufnr ()) 1103 1104drop ! other 1105call assert_equal ( l: other , bufnr ()) 1106endfunc 1107 1108" Fail :edit but :edit! is allowed 1109func Test_edit () 1110call s: reset_all_buffers () 1111 1112let l: other = s: make_buffer_pairs () 1113let l: current = bufnr () 1114 1115call assert_fails ( "edit other" , "E1513:" ) 1116call assert_equal ( l: current , bufnr ()) 1117 1118edit ! other 1119call assert_equal ( l: other , bufnr ()) 1120endfunc 1121 1122" Fail :e when selecting a buffer from a relative path if in a different folder 1123" 1124" In this tests there's 2 buffers 1125" 1126" foo - lives on disk, in some folder. e.g. /tmp/foo 1127" foo - an in-memory buffer that has not been saved to disk. If saved, it 1128" would live in a different folder, /other/foo. 1129" 1130" The 'winfixbuf' is looking at the in-memory buffer and trying to switch to 1131" the buffer on-disk (and fails, because it's a different buffer) 1132func Test_edit_different_buffer_on_disk_and_relative_path_to_disk () 1133call s: reset_all_buffers () 1134 1135let l: file_on_disk = tempname () 1136let l: directory_on_disk1 = fnamemodify ( l: file_on_disk , ":p:h" ) 1137let l: name = fnamemodify ( l: file_on_disk , ":t" ) 1138exe $ "edit {l: file_on_disk }" 1139write ! 1140 1141let l: directory_on_disk2 = l: directory_on_disk1 .. "_something_else" 1142 1143if ! isdirectory ( l: directory_on_disk2 ) 1144call mkdir ( l: directory_on_disk2 ) 1145endif 1146 1147exe $ "cd {l: directory_on_disk2 }" 1148exe $ "edit {l: name }" 1149 1150let l: current = bufnr () 1151 1152call assert_equal ( l: current , bufnr ()) 1153set winfixbuf 1154call assert_fails ( $ "edit {l: file_on_disk } ", "E1513:") 1155call assert_equal ( l: current , bufnr ()) 1156 1157call delete ( l: directory_on_disk1 ) 1158call delete ( l: directory_on_disk2 ) 1159endfunc 1160 1161" Fail :e when selecting a buffer from a relative path if in a different folder 1162" 1163" In this tests there's 2 buffers 1164" 1165" foo - lives on disk, in some folder. e.g. /tmp/foo 1166" foo - an in-memory buffer that has not been saved to disk. If saved, it 1167" would live in a different folder, /other/foo. 1168" 1169" The 'winfixbuf' is looking at the on-disk buffer and trying to switch to 1170" the in-memory buffer (and fails, because it's a different buffer) 1171func Test_edit_different_buffer_on_disk_and_relative_path_to_memory () 1172call s: reset_all_buffers () 1173 1174let l: file_on_disk = tempname () 1175let l: directory_on_disk1 = fnamemodify ( l: file_on_disk , ":p:h" ) 1176let l: name = fnamemodify ( l: file_on_disk , ":t" ) 1177exe $ "edit {l: file_on_disk }" 1178write ! 1179 1180let l: directory_on_disk2 = l: directory_on_disk1 .. "_something_else" 1181 1182if ! isdirectory ( l: directory_on_disk2 ) 1183call mkdir ( l: directory_on_disk2 ) 1184endif 1185 1186exe $ "cd {l: directory_on_disk2 }" 1187exe $ "edit {l: name }" 1188exe $ "cd {l: directory_on_disk1 }" 1189exe $ "edit {l: file_on_disk }" 1190exe $ "cd {l: directory_on_disk2 }" 1191 1192let l: current = bufnr () 1193 1194call assert_equal ( l: current , bufnr ()) 1195set winfixbuf 1196call assert_fails ( $ "edit {l: name } ", "E1513:") 1197call assert_equal ( l: current , bufnr ()) 1198 1199call delete ( l: directory_on_disk1 ) 1200call delete ( l: directory_on_disk2 ) 1201endfunc 1202 1203" Fail to call `:e first` if called from a starting, in-memory buffer 1204func Test_edit_first_buffer () 1205call s: reset_all_buffers () 1206 1207set winfixbuf 1208let l: current = bufnr () 1209 1210call assert_fails ( "edit first" , "E1513:" ) 1211call assert_equal ( l: current , bufnr ()) 1212 1213edit ! first 1214call assert_equal ( l: current , bufnr ()) 1215edit ! somewhere_else 1216call assert_notequal ( l: current , bufnr ()) 1217endfunc 1218 1219" Allow reloading a buffer using :e 1220func Test_edit_no_arguments () 1221call s: reset_all_buffers () 1222 1223let l: current = bufnr () 1224file some_buffer 1225 1226call assert_equal ( l: current , bufnr ()) 1227set winfixbuf 1228edit 1229call assert_equal ( l: current , bufnr ()) 1230endfunc 1231 1232" Allow :e selecting the current buffer 1233func Test_edit_same_buffer_in_memory () 1234call s: reset_all_buffers () 1235 1236let current = bufnr () 1237file same_buffer 1238 1239call assert_equal ( current , bufnr ()) 1240set winfixbuf 1241edit same_buffer 1242call assert_equal ( current , bufnr ()) 1243set nowinfixbuf 1244endfunc 1245 1246" Allow :e selecting the current buffer as a full path 1247func Test_edit_same_buffer_on_disk_absolute_path () 1248call s: reset_all_buffers () 1249 1250let file = tempname () 1251" file must exist for expansion of 8.3 paths to succeed 1252call writefile ([], file , 'D' ) 1253let file = fnamemodify ( file , ':p' ) 1254let current = bufnr () 1255exe $ "edit {file}" 1256write ! 1257 1258call assert_equal ( current , bufnr ()) 1259set winfixbuf 1260exe $ "edit {file}" 1261call assert_equal ( current , bufnr ()) 1262 1263set nowinfixbuf 1264endfunc 1265 1266" Fail :enew but :enew! is allowed 1267func Test_enew () 1268call s: reset_all_buffers () 1269 1270let l: other = s: make_buffer_pairs () 1271let l: current = bufnr () 1272 1273call assert_fails ( "enew" , "E1513:" ) 1274call assert_equal ( l: current , bufnr ()) 1275 1276enew ! 1277call assert_notequal ( l: other , bufnr ()) 1278call assert_notequal ( 3 , bufnr ()) 1279endfunc 1280 1281" Fail :ex but :ex! is allowed 1282func Test_ex () 1283call s: reset_all_buffers () 1284 1285let l: other = s: make_buffer_pairs () 1286let l: current = bufnr () 1287 1288call assert_fails ( "ex other" , "E1513:" ) 1289call assert_equal ( l: current , bufnr ()) 1290 1291ex ! other 1292call assert_equal ( l: other , bufnr ()) 1293endfunc 1294 1295" Fail :find but :find! is allowed 1296func Test_find () 1297call s: reset_all_buffers () 1298 1299let l: current = bufnr () 1300let l: file = tempname () 1301call writefile ([], l: file , 'D' ) 1302let l: file = fnamemodify ( l: file , ':p' ) " In case it's Windows 8.3-style. 1303let l: directory = fnamemodify ( l: file , ":p:h" ) 1304let l: name = fnamemodify ( l: file , ":p:t" ) 1305 1306let l: original_path = & path 1307exe $ "set path={l: directory }" 1308 1309set winfixbuf 1310 1311call assert_fails ( $ "exe 'find {l: name } '", "E1513:") 1312call assert_equal ( l: current , bufnr ()) 1313 1314exe $ "find! {l: name }" 1315call assert_equal ( l: file , expand ( "%:p" )) 1316 1317exe $ "set path={l: original_path }" 1318endfunc 1319 1320" Fail :first but :first! is allowed 1321func Test_first () 1322call s: reset_all_buffers () 1323 1324let [ l: first , _ ] = s: make_args_list () 1325next ! 1326 1327call assert_fails ( "first" , "E1513:" ) 1328call assert_notequal ( l: first , bufnr ()) 1329 1330first ! 1331call assert_equal ( l: first , bufnr ()) 1332endfunc 1333 1334" Fail :grep but :grep! is allowed 1335func Test_grep () 1336CheckFeature quickfix 1337call s: reset_all_buffers () 1338 1339edit first.unittest 1340call append ( 0 , [ "some-search-term" ]) 1341write 1342let l: first = bufnr () 1343 1344edit current.unittest 1345call append ( 0 , [ "some-search-term" ]) 1346write 1347let l: current = bufnr () 1348 1349edit ! last.unittest 1350call append ( 0 , [ "some-search-term" ]) 1351write 1352let l: last = bufnr () 1353 1354set winfixbuf 1355 1356buffer ! current.unittest 1357 1358call assert_fails ( "silent! grep some-search-term *.unittest" , "E1513:" ) 1359call assert_equal ( l: current , bufnr ()) 1360exe $ "edit ! {l: first }" 1361 1362silent ! grep ! some-search-term *.unittest 1363call assert_notequal ( l: first , bufnr ()) 1364 1365call delete ( "first.unittest" ) 1366call delete ( "current.unittest" ) 1367call delete ( "last.unittest" ) 1368endfunc 1369 1370" Fail :ijump but :ijump! is allowed 1371func Test_ijump () 1372call s: reset_all_buffers () 1373 1374let l: include_file = tempname () .. ".h" 1375call writefile ([ 1376 \$ '#include "{l: include_file } "' 1377 \ ], 1378 \ "main.c", 'D') 1379call writefile ([ "#define min(X, Y) ((X) < (Y) ? (X) : (Y))" ], l: include_file , 'D' ) 1380edit main.c 1381 1382set winfixbuf 1383 1384let l: current = bufnr () 1385 1386set define = ^\\s*#\\s*define 1387set include = ^\\s*#\\s*include 1388set path = .,/usr/include,, 1389 1390call assert_fails ( "ijump /min/" , "E1513:" ) 1391call assert_equal ( l: current , bufnr ()) 1392 1393set nowinfixbuf 1394 1395ijump ! /min/ 1396call assert_notequal ( l: current , bufnr ()) 1397 1398set define & 1399set include & 1400set path & 1401endfunc 1402 1403" Fail :lNext but :lNext! is allowed 1404func Test_lNext () 1405CheckFeature quickfix 1406call s: reset_all_buffers () 1407 1408let [ l: first , l: middle , _ ] = s: make_simple_location_list () 1409call assert_equal ( 1 , getloclist ( 0 , #{ idx : 0 }). idx ) 1410 1411lnext ! 1412call assert_equal ( 2 , getloclist ( 0 , #{ idx : 0 }). idx ) 1413call assert_equal ( l: middle , bufnr ()) 1414 1415call assert_fails ( "lNext" , "E1513:" ) 1416" Ensure the entry didn't change. 1417call assert_equal ( 2 , getloclist ( 0 , #{ idx : 0 }). idx ) 1418call assert_equal ( l: middle , bufnr ()) 1419 1420lnext ! 1421call assert_equal ( 3 , getloclist ( 0 , #{ idx : 0 }). idx ) 1422call assert_equal ( l: middle , bufnr ()) 1423 1424lNext ! 1425call assert_equal ( 2 , getloclist ( 0 , #{ idx : 0 }). idx ) 1426call assert_equal ( l: middle , bufnr ()) 1427 1428lNext ! 1429call assert_equal ( 1 , getloclist ( 0 , #{ idx : 0 }). idx ) 1430call assert_equal ( l: first , bufnr ()) 1431endfunc 1432 1433" Fail :lNfile but :lNfile! is allowed 1434func Test_lNfile () 1435CheckFeature quickfix 1436call s: reset_all_buffers () 1437 1438let [ l: first , l: current , _ ] = s: make_simple_location_list () 1439call assert_equal ( 1 , getloclist ( 0 , #{ idx : 0 }). idx ) 1440 1441lnext ! 1442call assert_equal ( 2 , getloclist ( 0 , #{ idx : 0 }). idx ) 1443call assert_equal ( l: current , bufnr ()) 1444 1445call assert_fails ( "lNfile" , "E1513:" ) 1446" Ensure the entry didn't change. 1447call assert_equal ( 2 , getloclist ( 0 , #{ idx : 0 }). idx ) 1448call assert_equal ( l: current , bufnr ()) 1449 1450lnext ! 1451call assert_equal ( 3 , getloclist ( 0 , #{ idx : 0 }). idx ) 1452call assert_equal ( l: current , bufnr ()) 1453 1454lNfile ! 1455call assert_equal ( 1 , getloclist ( 0 , #{ idx : 0 }). idx ) 1456call assert_equal ( l: first , bufnr ()) 1457endfunc 1458 1459" Allow :laddexpr because it doesn't change the current buffer 1460func Test_laddexpr () 1461CheckFeature quickfix 1462call s: reset_all_buffers () 1463 1464let l: file_path = tempname () 1465call writefile ([ "Error - bad-thing-found" ], l: file_path , 'D' ) 1466exe $ "edit {l: file_path }" 1467let l: file_buffer = bufnr () 1468let l: current = bufnr () 1469 1470edit first.unittest 1471call append ( 0 , [ "some-search-term bad-thing-found" ]) 1472 1473edit ! other.unittest 1474 1475set winfixbuf 1476 1477exe $ "buffer! {l: file_buffer }" 1478 1479exe 'laddexpr expand("%") .. ":" .. line(".") .. ":" .. getline(".")' 1480call assert_equal ( l: current , bufnr ()) 1481endfunc 1482 1483" Fail :last but :last! is allowed 1484func Test_last () 1485call s: reset_all_buffers () 1486 1487let [ _ , l: last ] = s: make_args_list () 1488next ! 1489 1490call assert_fails ( "last" , "E1513:" ) 1491call assert_notequal ( l: last , bufnr ()) 1492 1493last ! 1494call assert_equal ( l: last , bufnr ()) 1495endfunc 1496 1497" Fail :lbuffer but :lbuffer! is allowed 1498func Test_lbuffer () 1499CheckFeature quickfix 1500call s: reset_all_buffers () 1501 1502let l: file_path = tempname () 1503call writefile ([ "first.unittest:1:Error - bad-thing-found" ], l: file_path , 'D' ) 1504exe $ "edit {l: file_path }" 1505let l: file_buffer = bufnr () 1506let l: current = bufnr () 1507 1508edit first.unittest 1509call append ( 0 , [ "some-search-term bad-thing-found" ]) 1510 1511edit ! other.unittest 1512 1513set winfixbuf 1514 1515exe $ "buffer! {file_buffer}" 1516 1517call assert_fails ( $ "lbuffer {file_buffer}", "E1513: Cannot switch buffer. 'winfixbuf' is enabled") 1518call assert_equal ( current , bufnr ()) 1519 1520exe $ "lbuffer! {file_buffer}" 1521call assert_equal ( "first.unittest" , expand ( "%:t" )) 1522endfunc 1523 1524" Fail :ldo but :ldo! is allowed 1525func Test_ldo () 1526CheckFeature quickfix 1527call s: reset_all_buffers () 1528 1529let [ l: first , l: middle , l: last ] = s: make_simple_location_list () 1530lnext ! 1531 1532call assert_fails ( $ 'exe "ldo buffer {l: first } "', "E1513:") 1533call assert_equal ( l: middle , bufnr ()) 1534exe $ "ldo! buffer {l: first }" 1535call assert_notequal ( l: last , bufnr ()) 1536endfunc 1537 1538" Fail :lfdo but :lfdo! is allowed 1539func Test_lexpr () 1540CheckFeature quickfix 1541call s: reset_all_buffers () 1542 1543let file = tempname () 1544let entry = $ '["{file}:1:bar"]' 1545let current = bufnr () 1546 1547set winfixbuf 1548 1549call assert_fails ( $ "lexpr {entry}", "E1513: Cannot switch buffer. 'winfixbuf' is enabled") 1550call assert_equal ( current , bufnr ()) 1551 1552exe $ "lexpr! {entry}" 1553call assert_equal ( fnamemodify ( file , ":t" ), expand ( "%:t" )) 1554endfunc 1555 1556" Fail :lfdo but :lfdo! is allowed 1557func Test_lfdo () 1558CheckFeature quickfix 1559call s: reset_all_buffers () 1560 1561let [ first , middle , last ] = s: make_simple_location_list () 1562lnext ! 1563 1564call assert_fails ( 'exe "lfdo buffer ' .. first .. '"' , "E1513:" ) 1565call assert_equal ( middle , bufnr ()) 1566exe $ "lfdo! buffer {first}" 1567call assert_notequal ( last , bufnr ()) 1568endfunc 1569 1570" Fail :lfile but :lfile! is allowed 1571func Test_lfile () 1572CheckFeature quickfix 1573call s: reset_all_buffers () 1574 1575edit first.unittest 1576call append ( 0 , [ "some-search-term bad-thing-found" ]) 1577write 1578let l: first = bufnr () 1579 1580edit ! second.unittest 1581call append ( 0 , [ "some-search-term" ]) 1582write 1583 1584let l: file = tempname () 1585call writefile ([ "first.unittest:1:Error - bad-thing-found was detected" ], l: file , 'D' ) 1586 1587let l: current = bufnr () 1588 1589set winfixbuf 1590 1591call assert_fails ( $ ":lfile {l: file } ", "E1513: Cannot switch buffer. 'winfixbuf' is enabled") 1592call assert_equal ( l: current , bufnr ()) 1593 1594exe $ ":lfile! {l: file }" 1595call assert_equal ( l: first , bufnr ()) 1596 1597call delete ( "first.unittest" ) 1598call delete ( "second.unittest" ) 1599endfunc 1600 1601" Fail :ll but :ll! is allowed 1602func Test_ll () 1603CheckFeature quickfix 1604call s: reset_all_buffers () 1605 1606let [ l: first , l: middle , l: last ] = s: make_simple_location_list () 1607lopen 1608lfirst ! 1609exe "normal \<C-w>j" 1610normal j 1611 1612call assert_fails ( ".ll" , "E1513:" ) 1613exe "normal \<C-w>k" 1614call assert_equal ( l: first , bufnr ()) 1615exe "normal \<C-w>j" 1616 .ll ! 1617exe "normal \<C-w>k" 1618call assert_equal ( l: middle , bufnr ()) 1619endfunc 1620 1621" Fail :llast but :llast! is allowed 1622func Test_llast () 1623CheckFeature quickfix 1624call s: reset_all_buffers () 1625 1626let [ l: first , _ , l: last ] = s: make_simple_location_list () 1627lfirst ! 1628 1629call assert_fails ( "llast" , "E1513:" ) 1630call assert_equal ( l: first , bufnr ()) 1631 1632llast ! 1633call assert_equal ( l: last , bufnr ()) 1634endfunc 1635 1636" Fail :lnext but :lnext! is allowed 1637func Test_lnext () 1638CheckFeature quickfix 1639call s: reset_all_buffers () 1640 1641let [ l: first , l: middle , l: last ] = s: make_simple_location_list () 1642ll ! 1643 1644call assert_fails ( "lnext" , "E1513:" ) 1645call assert_equal ( l: first , bufnr ()) 1646 1647lnext ! 1648call assert_equal ( l: middle , bufnr ()) 1649endfunc 1650 1651" Fail :lnfile but :lnfile! is allowed 1652func Test_lnfile () 1653CheckFeature quickfix 1654call s: reset_all_buffers () 1655 1656let [ _ , l: current , l: last ] = s: make_simple_location_list () 1657call assert_equal ( 1 , getloclist ( 0 , #{ idx : 0 }). idx ) 1658 1659lnext ! 1660call assert_equal ( 2 , getloclist ( 0 , #{ idx : 0 }). idx ) 1661call assert_equal ( l: current , bufnr ()) 1662 1663call assert_fails ( "lnfile" , "E1513:" ) 1664" Ensure the entry didn't change. 1665call assert_equal ( 2 , getloclist ( 0 , #{ idx : 0 }). idx ) 1666call assert_equal ( l: current , bufnr ()) 1667 1668lnfile ! 1669call assert_equal ( 4 , getloclist ( 0 , #{ idx : 0 }). idx ) 1670call assert_equal ( l: last , bufnr ()) 1671endfunc 1672 1673" Fail :lpfile but :lpfile! is allowed 1674func Test_lpfile () 1675CheckFeature quickfix 1676call s: reset_all_buffers () 1677 1678let [ l: first , l: current , _ ] = s: make_simple_location_list () 1679lnext ! 1680 1681call assert_fails ( "lpfile" , "E1513:" ) 1682call assert_equal ( l: current , bufnr ()) 1683 1684lnext ! " Reset for the next test call 1685 1686lpfile ! 1687call assert_equal ( l: first , bufnr ()) 1688endfunc 1689 1690" Fail :lprevious but :lprevious! is allowed 1691func Test_lprevious () 1692CheckFeature quickfix 1693call s: reset_all_buffers () 1694 1695let [ l: first , l: middle , _ ] = s: make_simple_location_list () 1696call assert_equal ( 1 , getloclist ( 0 , #{ idx : 0 }). idx ) 1697 1698lnext ! 1699call assert_equal ( 2 , getloclist ( 0 , #{ idx : 0 }). idx ) 1700call assert_equal ( l: middle , bufnr ()) 1701 1702call assert_fails ( "lprevious" , "E1513:" ) 1703" Ensure the entry didn't change. 1704call assert_equal ( 2 , getloclist ( 0 , #{ idx : 0 }). idx ) 1705call assert_equal ( l: middle , bufnr ()) 1706 1707lprevious ! 1708call assert_equal ( 1 , getloclist ( 0 , #{ idx : 0 }). idx ) 1709call assert_equal ( l: first , bufnr ()) 1710endfunc 1711 1712" Fail :lrewind but :lrewind! is allowed 1713func Test_lrewind () 1714CheckFeature quickfix 1715call s: reset_all_buffers () 1716 1717let [ l: first , l: middle , _ ] = s: make_simple_location_list () 1718lnext ! 1719 1720call assert_fails ( "lrewind" , "E1513:" ) 1721call assert_equal ( l: middle , bufnr ()) 1722 1723lrewind ! 1724call assert_equal ( l: first , bufnr ()) 1725endfunc 1726 1727" Fail :ltag but :ltag! is allowed 1728func Test_ltag () 1729call s: reset_all_buffers () 1730 1731set tags = Xtags 1732call writefile ([ "!_TAG_FILE_ENCODING\tutf-8\t//" , 1733 \"one\tXfile\t1" , 1734 \"three\tXfile\t3" , 1735 \"two\tXfile\t2" ], 1736 \"Xtags" , 'D' ) 1737call writefile ([ "one" , "two" , "three" ], "Xfile" , 'D' ) 1738call writefile ([ "one" ], "Xother" , 'D' ) 1739edit Xother 1740exe "normal \<C-]>" 1741 1742set winfixbuf 1743 1744let l: current = bufnr () 1745 1746call assert_fails ( "ltag one" , "E1513:" ) 1747 1748ltag ! one 1749 1750set tags & 1751endfunc 1752 1753" Fail vim.cmd if we try to change buffers while 'winfixbuf' is set 1754func Test_lua_command () 1755" CheckFeature lua 1756call s: reset_all_buffers () 1757 1758enew 1759file first 1760let l: previous = bufnr () 1761 1762enew 1763file second 1764let l: current = bufnr () 1765 1766set winfixbuf 1767 1768call assert_fails ( $ 'lua vim.cmd("buffer " .. {l: previous } )') 1769call assert_equal ( l: current , bufnr ()) 1770 1771exe $ 'lua vim.cmd("buffer! " .. {l: previous })' 1772call assert_equal ( l: previous , bufnr ()) 1773endfunc 1774 1775" Fail :lvimgrep but :lvimgrep! is allowed 1776func Test_lvimgrep () 1777CheckFeature quickfix 1778call s: reset_all_buffers () 1779 1780edit first.unittest 1781call append ( 0 , [ "some-search-term" ]) 1782write 1783 1784edit winfix.unittest 1785call append ( 0 , [ "some-search-term" ]) 1786write 1787let l: current = bufnr () 1788 1789set winfixbuf 1790 1791edit ! last.unittest 1792call append ( 0 , [ "some-search-term" ]) 1793write 1794let l: last = bufnr () 1795 1796buffer ! winfix.unittest 1797 1798call assert_fails ( "lvimgrep /some-search-term/ *.unittest" , "E1513:" ) 1799call assert_equal ( l: current , bufnr ()) 1800 1801lvimgrep ! /some-search-term/ *.unittest 1802call assert_notequal ( l: current , bufnr ()) 1803 1804call delete ( "first.unittest" ) 1805call delete ( "winfix.unittest" ) 1806call delete ( "last.unittest" ) 1807endfunc 1808 1809" Fail :lvimgrepadd but :lvimgrepadd! is allowed 1810func Test_lvimgrepadd () 1811CheckFeature quickfix 1812call s: reset_all_buffers () 1813 1814edit first.unittest 1815call append ( 0 , [ "some-search-term" ]) 1816write 1817 1818edit winfix.unittest 1819call append ( 0 , [ "some-search-term" ]) 1820write 1821let l: current = bufnr () 1822 1823set winfixbuf 1824 1825edit ! last.unittest 1826call append ( 0 , [ "some-search-term" ]) 1827write 1828let l: last = bufnr () 1829 1830buffer ! winfix.unittest 1831 1832call assert_fails ( "lvimgrepadd /some-search-term/ *.unittest" , "E1513: Cannot switch buffer. 'winfixbuf' is enabled" ) 1833call assert_equal ( l: current , bufnr ()) 1834 1835lvimgrepadd ! /some-search-term/ *.unittest 1836call assert_notequal ( l: current , bufnr ()) 1837 1838call delete ( "first.unittest" ) 1839call delete ( "winfix.unittest" ) 1840call delete ( "last.unittest" ) 1841endfunc 1842 1843" Don't allow global marks to change the current 'winfixbuf' window 1844func Test_marks_mappings_fail () 1845call s: reset_all_buffers () 1846 1847let l: other = s: make_buffer_pairs () 1848let l: current = bufnr () 1849exe $ "buffer! {l: other }" 1850normal mA 1851exe $ "buffer! {l: current }" 1852normal mB 1853 1854call assert_fails ( "normal `A" , "E1513:" ) 1855call assert_equal ( l: current , bufnr ()) 1856 1857call assert_fails ( "normal 'A" , "E1513:" ) 1858call assert_equal ( l: current , bufnr ()) 1859 1860set nowinfixbuf 1861 1862normal `A 1863call assert_equal ( l: other , bufnr ()) 1864endfunc 1865 1866" Allow global marks in a 'winfixbuf' window if the jump is the same buffer 1867func Test_marks_mappings_pass_intra_move () 1868call s: reset_all_buffers () 1869 1870let l: current = bufnr () 1871call append ( 0 , [ "some line" , "another line" ]) 1872normal mA 1873normal j 1874normal mB 1875 1876set winfixbuf 1877 1878normal `A 1879call assert_equal ( l: current , bufnr ()) 1880endfunc 1881 1882" Fail :next but :next! is allowed 1883func Test_next () 1884call s: reset_all_buffers () 1885 1886let [ l: first , _ ] = s: make_args_list () 1887first ! 1888 1889call assert_fails ( "next" , "E1513:" ) 1890call assert_equal ( l: first , bufnr ()) 1891 1892next ! 1893call assert_notequal ( l: first , bufnr ()) 1894endfunc 1895 1896" Ensure :mksession saves 'winfixbuf' details 1897func Test_mksession () 1898CheckFeature mksession 1899call s: reset_all_buffers () 1900 1901set sessionoptions += options 1902set winfixbuf 1903 1904mksession test_winfixbuf_Test_mksession.vim 1905 1906call s: reset_all_buffers () 1907let l: winfixbuf = & winfixbuf 1908call assert_equal ( 0 , l: winfixbuf ) 1909 1910source test_winfixbuf_Test_mksession.vim 1911 1912let l: winfixbuf = & winfixbuf 1913call assert_equal ( 1 , l: winfixbuf ) 1914 1915set sessionoptions & 1916call delete ( "test_winfixbuf_Test_mksession.vim" ) 1917endfunc 1918 1919" Allow :next if the next index is the same as the current buffer 1920func Test_next_same_buffer () 1921call s: reset_all_buffers () 1922 1923enew 1924file foo 1925enew 1926file bar 1927enew 1928file fizz 1929enew 1930file buzz 1931args foo foo bar fizz buzz 1932 1933edit foo 1934set winfixbuf 1935let l: current = bufnr () 1936 1937" Allow :next because the args list is `[foo] foo bar fizz buzz 1938next 1939call assert_equal ( l: current , bufnr ()) 1940 1941" Fail :next because the args list is `foo [foo] bar fizz buzz 1942" and the next buffer would be bar, which is a different buffer 1943call assert_fails ( "next" , "E1513:" ) 1944call assert_equal ( l: current , bufnr ()) 1945endfunc 1946 1947" Fail to jump to a tag with g<C-]> if 'winfixbuf' is enabled 1948func Test_normal_g_ctrl_square_bracket_right () 1949call s: reset_all_buffers () 1950 1951set tags = Xtags 1952call writefile ([ "!_TAG_FILE_ENCODING\tutf-8\t//" , 1953 \"one\tXfile\t1" , 1954 \"three\tXfile\t3" , 1955 \"two\tXfile\t2" ], 1956 \"Xtags" , 'D' ) 1957call writefile ([ "one" , "two" , "three" ], "Xfile" , 'D' ) 1958call writefile ([ "one" ], "Xother" , 'D' ) 1959edit Xother 1960 1961set winfixbuf 1962 1963let l: current = bufnr () 1964 1965call assert_fails ( "normal g\<C-]>" , "E1513:" ) 1966call assert_equal ( l: current , bufnr ()) 1967 1968set tags & 1969endfunc 1970 1971" Fail to jump to a tag with g<RightMouse> if 'winfixbuf' is enabled 1972func Test_normal_g_rightmouse () 1973call s: reset_all_buffers () 1974set mouse = n 1975 1976set tags = Xtags 1977call writefile ([ "!_TAG_FILE_ENCODING\tutf-8\t//" , 1978 \"one\tXfile\t1" , 1979 \"three\tXfile\t3" , 1980 \"two\tXfile\t2" ], 1981 \"Xtags" , 'D' ) 1982call writefile ([ "one" , "two" , "three" ], "Xfile" , 'D' ) 1983call writefile ([ "one" ], "Xother" , 'D' ) 1984edit Xother 1985exe "normal \<C-]>" 1986 1987set winfixbuf 1988 1989let l: current = bufnr () 1990 1991call assert_fails ( "normal g\<RightMouse>" , "E1513:" ) 1992call assert_equal ( l: current , bufnr ()) 1993 1994set tags & 1995set mouse & 1996endfunc 1997 1998" Fail to jump to a tag with g] if 'winfixbuf' is enabled 1999func Test_normal_g_square_bracket_right () 2000call s: reset_all_buffers () 2001 2002set tags = Xtags 2003call writefile ([ "!_TAG_FILE_ENCODING\tutf-8\t//" , 2004 \"one\tXfile\t1" , 2005 \"three\tXfile\t3" , 2006 \"two\tXfile\t2" ], 2007 \"Xtags" , 'D' ) 2008call writefile ([ "one" , "two" , "three" ], "Xfile" , 'D' ) 2009call writefile ([ "one" ], "Xother" , 'D' ) 2010edit Xother 2011 2012set winfixbuf 2013 2014let l: current = bufnr () 2015 2016call assert_fails ( "normal g]" , "E1513:" ) 2017call assert_equal ( l: current , bufnr ()) 2018 2019set tags & 2020endfunc 2021 2022" Fail to jump to a tag with <C-RightMouse> if 'winfixbuf' is enabled 2023func Test_normal_ctrl_rightmouse () 2024call s: reset_all_buffers () 2025set mouse = n 2026 2027set tags = Xtags 2028call writefile ([ "!_TAG_FILE_ENCODING\tutf-8\t//" , 2029 \"one\tXfile\t1" , 2030 \"three\tXfile\t3" , 2031 \"two\tXfile\t2" ], 2032 \"Xtags" , 'D' ) 2033call writefile ([ "one" , "two" , "three" ], "Xfile" , 'D' ) 2034call writefile ([ "one" ], "Xother" , 'D' ) 2035edit Xother 2036exe "normal \<C-]>" 2037 2038set winfixbuf 2039 2040let l: current = bufnr () 2041 2042call assert_fails ( "normal \<C-RightMouse>" , "E1513:" ) 2043call assert_equal ( l: current , bufnr ()) 2044 2045set tags & 2046set mouse & 2047endfunc 2048 2049" Fail to jump to a tag with <C-t> if 'winfixbuf' is enabled 2050func Test_normal_ctrl_t () 2051call s: reset_all_buffers () 2052 2053set tags = Xtags 2054call writefile ([ "!_TAG_FILE_ENCODING\tutf-8\t//" , 2055 \"one\tXfile\t1" , 2056 \"three\tXfile\t3" , 2057 \"two\tXfile\t2" ], 2058 \"Xtags" , 'D' ) 2059call writefile ([ "one" , "two" , "three" ], "Xfile" , 'D' ) 2060call writefile ([ "one" ], "Xother" , 'D' ) 2061edit Xother 2062exe "normal \<C-]>" 2063 2064set winfixbuf 2065 2066let l: current = bufnr () 2067 2068call assert_fails ( "normal \<C-t>" , "E1513:" ) 2069call assert_equal ( l: current , bufnr ()) 2070 2071set tags & 2072endfunc 2073 2074" Disallow <C-^> in 'winfixbuf' windows 2075func Test_normal_ctrl_hat () 2076call s: reset_all_buffers () 2077clearjumps 2078 2079enew 2080file first 2081let l: first = bufnr () 2082 2083enew 2084file current 2085let l: current = bufnr () 2086 2087set winfixbuf 2088 2089call assert_fails ( "normal \<C-^>" , "E1513:" ) 2090call assert_equal ( l: current , bufnr ()) 2091endfunc 2092 2093" Allow <C-i> in 'winfixbuf' windows if the movement stays within the buffer 2094func Test_normal_ctrl_i_pass () 2095call s: reset_all_buffers () 2096clearjumps 2097 2098enew 2099file first 2100let l: first = bufnr () 2101 2102enew ! 2103file current 2104let l: current = bufnr () 2105" Add some lines so we can populate a jumplist" 2106call append ( 0 , [ "some line" , "another line" ]) 2107" Add an entry to the jump list 2108" Go up another line 2109normal m` 2110normal k 2111exe "normal \<C-o>" 2112 2113set winfixbuf 2114 2115let l: line = getcurpos ()[ 1 ] 2116exe "normal 1\<C-i>" 2117call assert_notequal ( l: line , getcurpos ()[ 1 ]) 2118endfunc 2119 2120" Disallow <C-o> in 'winfixbuf' windows if it would cause the buffer to switch 2121func Test_normal_ctrl_o_fail () 2122call s: reset_all_buffers () 2123clearjumps 2124 2125enew 2126file first 2127let l: first = bufnr () 2128 2129enew 2130file current 2131let l: current = bufnr () 2132 2133set winfixbuf 2134 2135call assert_fails ( "normal \<C-o>" , "E1513:" ) 2136call assert_equal ( l: current , bufnr ()) 2137endfunc 2138 2139" Allow <C-o> in 'winfixbuf' windows if the movement stays within the buffer 2140func Test_normal_ctrl_o_pass () 2141call s: reset_all_buffers () 2142clearjumps 2143 2144enew 2145file first 2146let l: first = bufnr () 2147 2148enew ! 2149file current 2150let l: current = bufnr () 2151" Add some lines so we can populate a jumplist 2152call append ( 0 , [ "some line" , "another line" ]) 2153" Add an entry to the jump list 2154" Go up another line 2155normal m` 2156normal k 2157 2158set winfixbuf 2159 2160exe "normal \<C-o>" 2161call assert_equal ( l: current , bufnr ()) 2162endfunc 2163 2164" Fail to jump to a tag with <C-]> if 'winfixbuf' is enabled 2165func Test_normal_ctrl_square_bracket_right () 2166call s: reset_all_buffers () 2167 2168set tags = Xtags 2169call writefile ([ "!_TAG_FILE_ENCODING\tutf-8\t//" , 2170 \"one\tXfile\t1" , 2171 \"three\tXfile\t3" , 2172 \"two\tXfile\t2" ], 2173 \"Xtags" , 'D' ) 2174call writefile ([ "one" , "two" , "three" ], "Xfile" , 'D' ) 2175call writefile ([ "one" ], "Xother" , 'D' ) 2176edit Xother 2177 2178set winfixbuf 2179 2180let l: current = bufnr () 2181 2182call assert_fails ( "normal \<C-]>" , "E1513:" ) 2183call assert_equal ( l: current , bufnr ()) 2184 2185set tags & 2186endfunc 2187 2188" Allow <C-w><C-]> with 'winfixbuf' enabled because it runs in a new, split window 2189func Test_normal_ctrl_w_ctrl_square_bracket_right () 2190call s: reset_all_buffers () 2191 2192set tags = Xtags 2193call writefile ([ "!_TAG_FILE_ENCODING\tutf-8\t//" , 2194 \"one\tXfile\t1" , 2195 \"three\tXfile\t3" , 2196 \"two\tXfile\t2" ], 2197 \"Xtags" , 'D' ) 2198call writefile ([ "one" , "two" , "three" ], "Xfile" , 'D' ) 2199call writefile ([ "one" ], "Xother" , 'D' ) 2200edit Xother 2201 2202set winfixbuf 2203 2204let l: current_windows = s: get_windows_count () 2205exe "normal \<C-w>\<C-]>" 2206call assert_equal ( l: current_windows + 1 , s: get_windows_count ()) 2207 2208set tags & 2209endfunc 2210 2211" Allow <C-w>g<C-]> with 'winfixbuf' enabled because it runs in a new, split window 2212func Test_normal_ctrl_w_g_ctrl_square_bracket_right () 2213call s: reset_all_buffers () 2214 2215set tags = Xtags 2216call writefile ([ "!_TAG_FILE_ENCODING\tutf-8\t//" , 2217 \"one\tXfile\t1" , 2218 \"three\tXfile\t3" , 2219 \"two\tXfile\t2" ], 2220 \"Xtags" , 'D' ) 2221call writefile ([ "one" , "two" , "three" ], "Xfile" , 'D' ) 2222call writefile ([ "one" ], "Xother" , 'D' ) 2223edit Xother 2224 2225set winfixbuf 2226 2227let l: current_windows = s: get_windows_count () 2228exe "normal \<C-w>g\<C-]>" 2229call assert_equal ( l: current_windows + 1 , s: get_windows_count ()) 2230 2231set tags & 2232endfunc 2233 2234" Fail to jump to a tag with <C-]> if 'winfixbuf' is enabled 2235func Test_normal_gt () 2236call s: reset_all_buffers () 2237 2238set tags = Xtags 2239call writefile ([ "!_TAG_FILE_ENCODING\tutf-8\t//" , 2240 \"one\tXfile\t1" , 2241 \"three\tXfile\t3" , 2242 \"two\tXfile\t2" ], 2243 \"Xtags" , 'D' ) 2244call writefile ([ "one" , "two" , "three" ], "Xfile" , 'D' ) 2245call writefile ([ "one" , "two" , "three" ], "Xother" , 'D' ) 2246edit Xother 2247 2248set winfixbuf 2249 2250let l: current = bufnr () 2251 2252call assert_fails ( "normal \<C-]>" , "E1513:" ) 2253call assert_equal ( l: current , bufnr ()) 2254 2255set tags & 2256endfunc 2257 2258" Prevent gF from switching a 'winfixbuf' window's buffer 2259func Test_normal_gF () 2260call s: reset_all_buffers () 2261 2262let l: file = tempname () 2263call append ( 0 , [ l: file ]) 2264call writefile ([], l: file , 'D' ) 2265" Place the cursor onto the line that has `l:file` 2266normal gg 2267" Prevent Vim from erroring with "No write since last change @ command 2268" line" when we try to call gF, later. 2269set hidden 2270 2271set winfixbuf 2272 2273let l: buffer = bufnr () 2274 2275call assert_fails ( "normal gF" , "E1513:" ) 2276call assert_equal ( l: buffer , bufnr ()) 2277 2278set nowinfixbuf 2279 2280normal gF 2281call assert_notequal ( l: buffer , bufnr ()) 2282 2283set nohidden 2284endfunc 2285 2286" Prevent gf from switching a 'winfixbuf' window's buffer 2287func Test_normal_gf () 2288call s: reset_all_buffers () 2289 2290let l: file = tempname () 2291call append ( 0 , [ l: file ]) 2292call writefile ([], l: file , 'D' ) 2293" Place the cursor onto the line that has `l:file` 2294normal gg 2295" Prevent Vim from erroring with "No write since last change @ command 2296" line" when we try to call gf, later. 2297set hidden 2298 2299set winfixbuf 2300 2301let l: buffer = bufnr () 2302 2303call assert_fails ( "normal gf" , "E1513:" ) 2304call assert_equal ( l: buffer , bufnr ()) 2305 2306set nowinfixbuf 2307 2308normal gf 2309call assert_notequal ( l: buffer , bufnr ()) 2310 2311set nohidden 2312endfunc 2313 2314" Fail "goto file under the cursor" (using [f, which is the same as `:normal gf`) 2315func Test_normal_square_bracket_left_f () 2316call s: reset_all_buffers () 2317 2318let l: file = tempname () 2319call append ( 0 , [ l: file ]) 2320call writefile ([], l: file , 'D' ) 2321" Place the cursor onto the line that has `l:file` 2322normal gg 2323" Prevent Vim from erroring with "No write since last change @ command 2324" line" when we try to call gf, later. 2325set hidden 2326 2327set winfixbuf 2328 2329let l: buffer = bufnr () 2330 2331call assert_fails ( "normal [f" , "E1513:" ) 2332call assert_equal ( l: buffer , bufnr ()) 2333 2334set nowinfixbuf 2335 2336normal [f 2337call assert_notequal ( l: buffer , bufnr ()) 2338 2339set nohidden 2340endfunc 2341 2342" Fail to go to a C macro with [<C-d> if 'winfixbuf' is enabled 2343func Test_normal_square_bracket_left_ctrl_d () 2344call s: reset_all_buffers () 2345 2346let l: include_file = tempname () .. ".h" 2347call writefile ([ "min(1, 12);" , 2348 \$ '#include "{l: include_file } "' 2349 \ ], 2350 \ "main.c", 'D') 2351call writefile ([ "#define min(X, Y) ((X) < (Y) ? (X) : (Y))" ], l: include_file , 'D' ) 2352edit main.c 2353normal ]\<C-d> 2354 2355set winfixbuf 2356 2357let l: current = bufnr () 2358 2359call assert_fails ( "normal [\<C-d>" , "E1513:" ) 2360call assert_equal ( l: current , bufnr ()) 2361 2362set nowinfixbuf 2363 2364exe "normal [\<C-d>" 2365call assert_notequal ( l: current , bufnr ()) 2366endfunc 2367 2368" Fail to go to a C macro with ]<C-d> if 'winfixbuf' is enabled 2369func Test_normal_square_bracket_right_ctrl_d () 2370call s: reset_all_buffers () 2371 2372let l: include_file = tempname () .. ".h" 2373call writefile ([ "min(1, 12);" , 2374 \$ '#include "{l: include_file } "' 2375 \ ], 2376 \ "main.c", 'D') 2377call writefile ([ "#define min(X, Y) ((X) < (Y) ? (X) : (Y))" ], l: include_file , 'D' ) 2378edit main.c 2379 2380set winfixbuf 2381 2382let l: current = bufnr () 2383 2384call assert_fails ( "normal ]\<C-d>" , "E1513:" ) 2385call assert_equal ( l: current , bufnr ()) 2386 2387set nowinfixbuf 2388 2389exe "normal ]\<C-d>" 2390call assert_notequal ( l: current , bufnr ()) 2391endfunc 2392 2393" Fail to go to a C macro with [<C-i> if 'winfixbuf' is enabled 2394func Test_normal_square_bracket_left_ctrl_i () 2395call s: reset_all_buffers () 2396 2397let l: include_file = tempname () .. ".h" 2398call writefile ([ $ '#include "{l: include_file } "', 2399 \ "min(1, 12);", 2400 \ ], 2401 \ "main.c", 'D') 2402call writefile ([ "#define min(X, Y) ((X) < (Y) ? (X) : (Y))" ], l: include_file , 'D' ) 2403edit main.c 2404" Move to the line with `min(1, 12);` on it" 2405normal j 2406 2407set define = ^\\s*#\\s*define 2408set include = ^\\s*#\\s*include 2409set path = .,/usr/include,, 2410 2411let l: current = bufnr () 2412 2413set winfixbuf 2414 2415call assert_fails ( "normal [\<C-i>" , "E1513:" ) 2416 2417set nowinfixbuf 2418 2419exe "normal [\<C-i>" 2420call assert_notequal ( l: current , bufnr ()) 2421 2422set define & 2423set include & 2424set path & 2425endfunc 2426 2427" Fail to go to a C macro with ]<C-i> if 'winfixbuf' is enabled 2428func Test_normal_square_bracket_right_ctrl_i () 2429call s: reset_all_buffers () 2430 2431let l: include_file = tempname () .. ".h" 2432call writefile ([ "min(1, 12);" , 2433 \$ '#include "{l: include_file } "' 2434 \ ], 2435 \ "main.c", 'D') 2436call writefile ([ "#define min(X, Y) ((X) < (Y) ? (X) : (Y))" ], l: include_file , 'D' ) 2437edit main.c 2438 2439set winfixbuf 2440 2441set define = ^\\s*#\\s*define 2442set include = ^\\s*#\\s*include 2443set path = .,/usr/include,, 2444 2445let l: current = bufnr () 2446 2447call assert_fails ( "normal ]\<C-i>" , "E1513:" ) 2448call assert_equal ( l: current , bufnr ()) 2449 2450set nowinfixbuf 2451 2452exe "normal ]\<C-i>" 2453call assert_notequal ( l: current , bufnr ()) 2454 2455set define & 2456set include & 2457set path & 2458endfunc 2459 2460" Fail "goto file under the cursor" (using ]f, which is the same as `:normal gf`) 2461func Test_normal_square_bracket_right_f () 2462call s: reset_all_buffers () 2463 2464let l: file = tempname () 2465call append ( 0 , [ l: file ]) 2466call writefile ([], l: file , 'D' ) 2467" Place the cursor onto the line that has `l:file` 2468normal gg 2469" Prevent Vim from erroring with "No write since last change @ command 2470" line" when we try to call gf, later. 2471set hidden 2472 2473set winfixbuf 2474 2475let l: buffer = bufnr () 2476 2477call assert_fails ( "normal ]f" , "E1513:" ) 2478call assert_equal ( l: buffer , bufnr ()) 2479 2480set nowinfixbuf 2481 2482normal ]f 2483call assert_notequal ( l: buffer , bufnr ()) 2484 2485set nohidden 2486endfunc 2487 2488" Fail to jump to a tag with v<C-]> if 'winfixbuf' is enabled 2489func Test_normal_v_ctrl_square_bracket_right () 2490call s: reset_all_buffers () 2491 2492set tags = Xtags 2493call writefile ([ "!_TAG_FILE_ENCODING\tutf-8\t//" , 2494 \"one\tXfile\t1" , 2495 \"three\tXfile\t3" , 2496 \"two\tXfile\t2" ], 2497 \"Xtags" , 'D' ) 2498call writefile ([ "one" , "two" , "three" ], "Xfile" , 'D' ) 2499call writefile ([ "one" ], "Xother" , 'D' ) 2500edit Xother 2501 2502set winfixbuf 2503 2504let l: current = bufnr () 2505 2506call assert_fails ( "normal v\<C-]>" , "E1513:" ) 2507call assert_equal ( l: current , bufnr ()) 2508 2509set tags & 2510endfunc 2511 2512" Fail to jump to a tag with vg<C-]> if 'winfixbuf' is enabled 2513func Test_normal_v_g_ctrl_square_bracket_right () 2514call s: reset_all_buffers () 2515 2516set tags = Xtags 2517call writefile ([ "!_TAG_FILE_ENCODING\tutf-8\t//" , 2518 \"one\tXfile\t1" , 2519 \"three\tXfile\t3" , 2520 \"two\tXfile\t2" ], 2521 \"Xtags" , 'D' ) 2522call writefile ([ "one" , "two" , "three" ], "Xfile" , 'D' ) 2523call writefile ([ "one" ], "Xother" , 'D' ) 2524edit Xother 2525 2526set winfixbuf 2527 2528let l: current = bufnr () 2529 2530call assert_fails ( "normal vg\<C-]>" , "E1513:" ) 2531call assert_equal ( l: current , bufnr ()) 2532 2533set tags & 2534endfunc 2535 2536" Allow :pedit because, unlike :edit, it uses a separate window 2537func Test_pedit () 2538call s: reset_all_buffers () 2539 2540let l: other = s: make_buffer_pairs () 2541 2542pedit other 2543 2544exe "normal \<C-w>w" 2545call assert_equal ( l: other , bufnr ()) 2546endfunc 2547 2548" Allow :pbuffer because, unlike :buffer, it uses a separate window 2549func Test_pbuffer () 2550call s: reset_all_buffers () 2551 2552let l: other = s: make_buffer_pairs () 2553 2554exe $ 'pbuffer {l: other }' 2555 2556exe "normal \<C-w>w" 2557call assert_equal ( l: other , bufnr ()) 2558endfunc 2559 2560" Fail :pop but :pop! is allowed 2561func Test_pop () 2562call s: reset_all_buffers () 2563 2564set tags = Xtags 2565call writefile ([ "!_TAG_FILE_ENCODING\tutf-8\t//" , 2566 \"thesame\tXfile\t1;\"\td\tfile:" , 2567 \"thesame\tXfile\t2;\"\td\tfile:" , 2568 \"thesame\tXfile\t3;\"\td\tfile:" , 2569 \], 2570 \"Xtags" , 'D' ) 2571call writefile ([ "thesame one" , "thesame two" , "thesame three" ], "Xfile" , 'D' ) 2572call writefile ([ "thesame one" ], "Xother" , 'D' ) 2573edit Xother 2574 2575tag thesame 2576 2577set winfixbuf 2578 2579let l: current = bufnr () 2580 2581call assert_fails ( "pop" , "E1513:" ) 2582call assert_equal ( l: current , bufnr ()) 2583 2584pop ! 2585call assert_notequal ( l: current , bufnr ()) 2586 2587set tags & 2588endfunc 2589 2590" Fail :previous but :previous! is allowed 2591func Test_previous () 2592call s: reset_all_buffers () 2593 2594let [ l: first , _ ] = s: make_args_list () 2595next ! 2596 2597call assert_fails ( "previous" , "E1513:" ) 2598call assert_notequal ( l: first , bufnr ()) 2599 2600previous ! 2601call assert_equal ( l: first , bufnr ()) 2602endfunc 2603 2604" Fail pyxdo if it changes a window with 'winfixbuf' is set 2605func Test_pythonx_pyxdo () 2606CheckFeature pythonx 2607call s: reset_all_buffers () 2608 2609enew 2610file first 2611let g: _previous_buffer = bufnr () 2612 2613enew 2614file second 2615 2616set winfixbuf 2617 2618pythonx << EOF 2619import vim 2620 2621def test_winfixbuf_Test_pythonx_pyxdo_set_buffer(): 2622buffer = vim.vars['_previous_buffer'] 2623vim .current.buffer = vim.buffers[buffer] 2624EOF 2625 2626try 2627pyxdo test_winfixbuf_Test_pythonx_pyxdo_set_buffer() 2628catch /pynvim\.api\.common\.NvimError: Vim:E1513:/ 2629let l: caught = 1 2630endtry 2631 2632call assert_equal ( 1 , l: caught ) 2633 2634unlet g: _previous_buffer 2635endfunc 2636 2637" Fail pyxfile if it changes a window with 'winfixbuf' is set 2638func Test_pythonx_pyxfile () 2639CheckFeature pythonx 2640call s: reset_all_buffers () 2641 2642enew 2643file first 2644let g: _previous_buffer = bufnr () 2645 2646enew 2647file second 2648 2649set winfixbuf 2650 2651call writefile ([ "import vim" , 2652 \"buffer = vim.vars['_previous_buffer']" , 2653 \"vim.current.buffer = vim.buffers[buffer]" , 2654 \], 2655 \"file.py" , 'D' ) 2656 2657try 2658pyxfile file.py 2659catch /pynvim\.api\.common\.NvimError: Vim:E1513:/ 2660let l: caught = 1 2661endtry 2662 2663call assert_equal ( 1 , l: caught ) 2664 2665unlet g: _previous_buffer 2666endfunc 2667 2668" Fail vim.current.buffer if 'winfixbuf' is set 2669func Test_pythonx_vim_current_buffer () 2670CheckFeature pythonx 2671call s: reset_all_buffers () 2672 2673enew 2674file first 2675let g: _previous_buffer = bufnr () 2676 2677enew 2678file second 2679 2680let l: caught = 0 2681 2682set winfixbuf 2683 2684try 2685pythonx << EOF 2686import vim 2687 2688buffer = vim.vars["_previous_buffer"] 2689vim .current.buffer = vim.buffers[buffer] 2690EOF 2691catch /pynvim\.api\.common\.NvimError: Vim:E1513:/ 2692let l: caught = 1 2693endtry 2694 2695call assert_equal ( 1 , l: caught ) 2696unlet g: _previous_buffer 2697endfunc 2698 2699" Ensure remapping to a disabled action still triggers failures 2700func Test_remap_key_fail () 2701call s: reset_all_buffers () 2702 2703enew 2704file first 2705let l: first = bufnr () 2706 2707enew 2708file current 2709let l: current = bufnr () 2710 2711set winfixbuf 2712 2713nnoremap g< C-^ > 2714 2715call assert_fails ( "normal g" , "E1513:" ) 2716call assert_equal ( l: current , bufnr ()) 2717 2718nunmap g 2719endfunc 2720 2721" Ensure remapping a disabled key to something valid does trigger any failures 2722func Test_remap_key_pass () 2723call s: reset_all_buffers () 2724 2725enew 2726file first 2727let l: first = bufnr () 2728 2729enew 2730file current 2731let l: current = bufnr () 2732 2733set winfixbuf 2734 2735call assert_fails ( "normal \<C-^>" , "E1513:" ) 2736call assert_equal ( l: current , bufnr ()) 2737 2738" Disallow <C-^> by default but allow it if the command does something else 2739nnoremap < C-^ > :echo "hello!" 2740 2741exe "normal \<C-^>" 2742call assert_equal ( l: current , bufnr ()) 2743 2744nunmap <C-^> 2745endfunc 2746 2747" Fail :rewind but :rewind! is allowed 2748func Test_rewind () 2749call s: reset_all_buffers () 2750 2751let [ l: first , _ ] = s: make_args_list () 2752next ! 2753 2754call assert_fails ( "rewind" , "E1513:" ) 2755call assert_notequal ( l: first , bufnr ()) 2756 2757rewind ! 2758call assert_equal ( l: first , bufnr ()) 2759endfunc 2760 2761" Allow :sblast because it opens the buffer in a new, split window 2762func Test_sblast () 2763call s: reset_all_buffers () 2764 2765let l: other = s: make_buffer_pairs ( 1 ) 2766bfirst ! 2767let l: current = bufnr () 2768 2769sblast 2770call assert_equal ( l: other , bufnr ()) 2771endfunc 2772 2773" Fail :sbprevious but :sbprevious! is allowed 2774func Test_sbprevious () 2775call s: reset_all_buffers () 2776 2777let l: other = s: make_buffer_pairs () 2778let l: current = bufnr () 2779 2780sbprevious 2781call assert_equal ( l: other , bufnr ()) 2782endfunc 2783 2784" Make sure 'winfixbuf' can be set using 'winfixbuf' or 'wfb' 2785func Test_short_option () 2786call s: reset_all_buffers () 2787 2788call s: make_buffer_pairs () 2789 2790set winfixbuf 2791call assert_fails ( "edit something_else" , "E1513:" ) 2792 2793set nowinfixbuf 2794set wfb 2795call assert_fails ( "edit another_place" , "E1513:" ) 2796 2797set nowfb 2798edit last_place 2799endfunc 2800 2801" Allow :snext because it makes a new window 2802func Test_snext () 2803call s: reset_all_buffers () 2804 2805let [ l: first , _ ] = s: make_args_list () 2806first ! 2807 2808let l: current_window = win_getid () 2809 2810snext 2811call assert_notequal ( l: current_window , win_getid ()) 2812call assert_notequal ( l: first , bufnr ()) 2813endfunc 2814 2815" Ensure the first has 'winfixbuf' and a new split window is 'nowinfixbuf' 2816func Test_split_window () 2817call s: reset_all_buffers () 2818 2819split 2820exe "normal \<C-w>j" 2821 2822set winfixbuf 2823 2824let l: winfix_window_1 = win_getid () 2825vsplit 2826let l: winfix_window_2 = win_getid () 2827 2828call assert_equal ( 1 , getwinvar ( l: winfix_window_1 , "&winfixbuf" )) 2829call assert_equal ( 0 , getwinvar ( l: winfix_window_2 , "&winfixbuf" )) 2830endfunc 2831 2832" Fail :tNext but :tNext! is allowed 2833func Test_tNext () 2834call s: reset_all_buffers () 2835 2836set tags = Xtags 2837call writefile ([ "!_TAG_FILE_ENCODING\tutf-8\t//" , 2838 \"thesame\tXfile\t1;\"\td\tfile:" , 2839 \"thesame\tXfile\t2;\"\td\tfile:" , 2840 \"thesame\tXfile\t3;\"\td\tfile:" , 2841 \], 2842 \"Xtags" , 'D' ) 2843call writefile ([ "thesame one" , "thesame two" , "thesame three" ], "Xfile" , 'D' ) 2844call writefile ([ "thesame one" ], "Xother" , 'D' ) 2845edit Xother 2846 2847tag thesame 2848exe "normal \<C-^>" 2849tnext ! 2850 2851set winfixbuf 2852 2853let l: current = bufnr () 2854 2855call assert_fails ( "tNext" , "E1513:" ) 2856call assert_equal ( l: current , bufnr ()) 2857 2858tNext ! 2859 2860set tags & 2861endfunc 2862 2863" Call :tabdo and stay in the 'winfixbuf' window: it only visits tabpages and 2864" doesn't change the current buffer, so it must not switch to another window 2865" even when a 'nowinfixbuf' window is available. 2866func Test_tabdo_stay_in_winfixbuf_window () 2867call s: reset_all_buffers () 2868 2869let [ l: first , _ ] = s: make_args_list () 2870 2871" +-------------------+ 2872" | 'nowinfixbuf' | 2873" +-------------------+ 2874" | 'winfixbuf' | <-- Cursor is here 2875" +-------------------+ 2876split 2877" Move to the 'winfixbuf' window now 2878exe "normal \<C-w>j" 2879let l: winfixbuf_window = win_getid () 2880 2881let l: expected_windows = s: get_windows_count () 2882tabdo echo'' 2883call assert_equal ( l: winfixbuf_window , win_getid ()) 2884call assert_equal ( l: first , bufnr ()) 2885call assert_equal ( l: expected_windows , s: get_windows_count ()) 2886endfunc 2887 2888" Call :tabdo and do not create a new window even when the only window is 2889" 'winfixbuf'. 2890func Test_tabdo_no_new_window () 2891call s: reset_all_buffers () 2892 2893let [ l: first , _ ] = s: make_buffers_list () 2894exe $ "buffer! {l: first }" 2895 2896let l: current = win_getid () 2897let l: current_windows = s: get_windows_count () 2898 2899tabdo echo'' 2900call assert_equal ( l: current , win_getid ()) 2901call assert_equal ( l: first , bufnr ()) 2902call assert_equal ( l: current_windows , s: get_windows_count ()) 2903endfunc 2904 2905" Fail :tag but :tag! is allowed 2906func Test_tag () 2907call s: reset_all_buffers () 2908 2909set tags = Xtags 2910call writefile ([ "!_TAG_FILE_ENCODING\tutf-8\t//" , 2911 \"one\tXfile\t1" , 2912 \"three\tXfile\t3" , 2913 \"two\tXfile\t2" ], 2914 \"Xtags" , 'D' ) 2915call writefile ([ "one" , "two" , "three" ], "Xfile" , 'D' ) 2916call writefile ([ "one" ], "Xother" , 'D' ) 2917edit Xother 2918 2919set winfixbuf 2920 2921let l: current = bufnr () 2922 2923call assert_fails ( "tag one" , "E1513:" ) 2924call assert_equal ( l: current , bufnr ()) 2925 2926tag ! one 2927call assert_notequal ( l: current , bufnr ()) 2928 2929set tags & 2930endfunc 2931 2932 2933" Fail :tfirst but :tfirst! is allowed 2934func Test_tfirst () 2935call s: reset_all_buffers () 2936 2937set tags = Xtags 2938call writefile ([ "!_TAG_FILE_ENCODING\tutf-8\t//" , 2939 \"one\tXfile\t1" , 2940 \"three\tXfile\t3" , 2941 \"two\tXfile\t2" ], 2942 \"Xtags" , 'D' ) 2943call writefile ([ "one" , "two" , "three" ], "Xfile" , 'D' ) 2944call writefile ([ "one" ], "Xother" , 'D' ) 2945tag one 2946edit Xother 2947 2948set winfixbuf 2949 2950let l: current = bufnr () 2951 2952call assert_fails ( "tfirst" , "E1513:" ) 2953call assert_equal ( l: current , bufnr ()) 2954 2955tfirst ! 2956call assert_notequal ( l: current , bufnr ()) 2957 2958set tags & 2959endfunc 2960 2961" Fail :tjump but :tjump! is allowed 2962func Test_tjump () 2963call s: reset_all_buffers () 2964 2965set tags = Xtags 2966call writefile ([ "!_TAG_FILE_ENCODING\tutf-8\t//" , 2967 \"one\tXfile\t1" , 2968 \"three\tXfile\t3" , 2969 \"two\tXfile\t2" ], 2970 \"Xtags" , 'D' ) 2971call writefile ([ "one" , "two" , "three" ], "Xfile" , 'D' ) 2972call writefile ([ "one" ], "Xother" , 'D' ) 2973edit Xother 2974 2975set winfixbuf 2976 2977let l: current = bufnr () 2978 2979call assert_fails ( "tjump one" , "E1513:" ) 2980call assert_equal ( l: current , bufnr ()) 2981 2982tjump ! one 2983call assert_notequal ( l: current , bufnr ()) 2984 2985set tags & 2986endfunc 2987 2988" Fail :tlast but :tlast! is allowed 2989func Test_tlast () 2990call s: reset_all_buffers () 2991 2992set tags = Xtags 2993call writefile ([ "!_TAG_FILE_ENCODING\tutf-8\t//" , 2994 \"one\tXfile\t1" , 2995 \"three\tXfile\t3" , 2996 \"two\tXfile\t2" ], 2997 \"Xtags" , 'D' ) 2998call writefile ([ "one" , "two" , "three" ], "Xfile" , 'D' ) 2999edit Xfile 3000tjump one 3001edit Xfile 3002 3003set winfixbuf 3004 3005let l: current = bufnr () 3006 3007call assert_fails ( "tlast" , "E1513:" ) 3008call assert_equal ( l: current , bufnr ()) 3009 3010tlast ! 3011call assert_equal ( l: current , bufnr ()) 3012 3013set tags & 3014endfunc 3015 3016" Fail :tnext but :tnext! is allowed 3017func Test_tnext () 3018call s: reset_all_buffers () 3019 3020set tags = Xtags 3021call writefile ([ "!_TAG_FILE_ENCODING\tutf-8\t//" , 3022 \"thesame\tXfile\t1;\"\td\tfile:" , 3023 \"thesame\tXfile\t2;\"\td\tfile:" , 3024 \"thesame\tXfile\t3;\"\td\tfile:" , 3025 \], 3026 \"Xtags" , 'D' ) 3027call writefile ([ "thesame one" , "thesame two" , "thesame three" ], "Xfile" , 'D' ) 3028call writefile ([ "thesame one" ], "Xother" , 'D' ) 3029edit Xother 3030 3031tag thesame 3032exe "normal \<C-^>" 3033 3034set winfixbuf 3035 3036let l: current = bufnr () 3037 3038call assert_fails ( "tnext" , "E1513:" ) 3039call assert_equal ( l: current , bufnr ()) 3040 3041tnext ! 3042call assert_notequal ( l: current , bufnr ()) 3043 3044set tags & 3045endfunc 3046 3047" Fail :tprevious but :tprevious! is allowed 3048func Test_tprevious () 3049call s: reset_all_buffers () 3050 3051set tags = Xtags 3052call writefile ([ "!_TAG_FILE_ENCODING\tutf-8\t//" , 3053 \"thesame\tXfile\t1;\"\td\tfile:" , 3054 \"thesame\tXfile\t2;\"\td\tfile:" , 3055 \"thesame\tXfile\t3;\"\td\tfile:" , 3056 \], 3057 \"Xtags" , 'D' ) 3058call writefile ([ "thesame one" , "thesame two" , "thesame three" ], "Xfile" , 'D' ) 3059call writefile ([ "thesame one" ], "Xother" , 'D' ) 3060edit Xother 3061 3062tag thesame 3063exe "normal \<C-^>" 3064tnext ! 3065 3066set winfixbuf 3067 3068let l: current = bufnr () 3069 3070call assert_fails ( "tprevious" , "E1513:" ) 3071call assert_equal ( l: current , bufnr ()) 3072 3073tprevious ! 3074 3075set tags & 3076endfunc 3077 3078" Fail :view but :view! is allowed 3079func Test_view () 3080call s: reset_all_buffers () 3081 3082let l: other = s: make_buffer_pairs () 3083let l: current = bufnr () 3084 3085call assert_fails ( "view other" , "E1513:" ) 3086call assert_equal ( l: current , bufnr ()) 3087 3088view ! other 3089call assert_equal ( l: other , bufnr ()) 3090endfunc 3091 3092" Fail :visual but :visual! is allowed 3093func Test_visual () 3094call s: reset_all_buffers () 3095 3096let l: other = s: make_buffer_pairs () 3097let l: current = bufnr () 3098 3099call assert_fails ( "visual other" , "E1513:" ) 3100call assert_equal ( l: current , bufnr ()) 3101 3102visual ! other 3103call assert_equal ( l: other , bufnr ()) 3104endfunc 3105 3106" Fail :vimgrep but :vimgrep! is allowed 3107func Test_vimgrep () 3108CheckFeature quickfix 3109call s: reset_all_buffers () 3110 3111edit first.unittest 3112call append ( 0 , [ "some-search-term" ]) 3113write 3114 3115edit winfix.unittest 3116call append ( 0 , [ "some-search-term" ]) 3117write 3118let l: current = bufnr () 3119 3120set winfixbuf 3121 3122edit ! last.unittest 3123call append ( 0 , [ "some-search-term" ]) 3124write 3125let l: last = bufnr () 3126 3127buffer ! winfix.unittest 3128 3129call assert_fails ( "vimgrep /some-search-term/ *.unittest" , "E1513: Cannot switch buffer. 'winfixbuf' is enabled" ) 3130call assert_equal ( l: current , bufnr ()) 3131 3132" Don't error and also do swap to the first match because ! was included 3133vimgrep ! /some-search-term/ *.unittest 3134call assert_notequal ( l: current , bufnr ()) 3135 3136call delete ( "first.unittest" ) 3137call delete ( "winfix.unittest" ) 3138call delete ( "last.unittest" ) 3139endfunc 3140 3141" Fail :vimgrepadd but ::vimgrepadd! is allowed 3142func Test_vimgrepadd () 3143CheckFeature quickfix 3144call s: reset_all_buffers () 3145 3146edit first.unittest 3147call append ( 0 , [ "some-search-term" ]) 3148write 3149 3150edit winfix.unittest 3151call append ( 0 , [ "some-search-term" ]) 3152write 3153let l: current = bufnr () 3154 3155set winfixbuf 3156 3157edit ! last.unittest 3158call append ( 0 , [ "some-search-term" ]) 3159write 3160let l: last = bufnr () 3161 3162buffer ! winfix.unittest 3163 3164call assert_fails ( "vimgrepadd /some-search-term/ *.unittest" , "E1513: Cannot switch buffer. 'winfixbuf' is enabled" ) 3165call assert_equal ( l: current , bufnr ()) 3166 3167vimgrepadd ! /some-search-term/ *.unittest 3168call assert_notequal ( l: current , bufnr ()) 3169call delete ( "first.unittest" ) 3170call delete ( "winfix.unittest" ) 3171call delete ( "last.unittest" ) 3172endfunc 3173 3174" Fail :wNext but :wNext! is allowed 3175func Test_wNext () 3176call s: reset_all_buffers () 3177 3178let [ l: first , _ ] = s: make_args_list () 3179next ! 3180 3181call assert_fails ( "wNext" , "E1513:" ) 3182call assert_notequal ( l: first , bufnr ()) 3183 3184wNext ! 3185call assert_equal ( l: first , bufnr ()) 3186 3187call delete ( "first" ) 3188call delete ( "middle" ) 3189call delete ( "last" ) 3190endfunc 3191 3192" Allow :windo unless `:windo foo` would change a 'winfixbuf' window's buffer 3193func Test_windo () 3194call s: reset_all_buffers () 3195 3196let l: current_window = win_getid () 3197let l: current_buffer = bufnr () 3198split 3199enew 3200file some_other_buffer 3201 3202set winfixbuf 3203 3204let l: current = win_getid () 3205 3206windo echo'' 3207call assert_equal ( l: current_window , win_getid ()) 3208 3209call assert_fails ( $ 'exe "windo buffer {l: current_buffer } "', "E1513:") 3210call assert_equal ( l: current_window , win_getid ()) 3211 3212exe $ "windo buffer! {l: current_buffer }" 3213call assert_equal ( l: current_window , win_getid ()) 3214endfunc 3215 3216" Call :windo and do not create a new window even when the only window is 3217" 'winfixbuf'. 3218func Test_windo_no_new_window () 3219call s: reset_all_buffers () 3220 3221let [ l: first , _ ] = s: make_buffers_list () 3222exe $ "buffer! {l: first }" 3223 3224let l: current = win_getid () 3225let l: current_windows = s: get_windows_count () 3226 3227windo echo'' 3228call assert_equal ( l: current , win_getid ()) 3229call assert_equal ( l: first , bufnr ()) 3230call assert_equal ( l: current_windows , s: get_windows_count ()) 3231endfunc 3232 3233" Fail :wnext but :wnext! is allowed 3234func Test_wnext () 3235call s: reset_all_buffers () 3236 3237let [ _ , l: last ] = s: make_args_list () 3238next ! 3239 3240call assert_fails ( "wnext" , "E1513:" ) 3241call assert_notequal ( l: last , bufnr ()) 3242 3243wnext ! 3244call assert_equal ( l: last , bufnr ()) 3245 3246call delete ( "first" ) 3247call delete ( "middle" ) 3248call delete ( "last" ) 3249endfunc 3250 3251" Fail :wprevious but :wprevious! is allowed 3252func Test_wprevious () 3253call s: reset_all_buffers () 3254 3255let [ l: first , _ ] = s: make_args_list () 3256next ! 3257 3258call assert_fails ( "wprevious" , "E1513:" ) 3259call assert_notequal ( l: first , bufnr ()) 3260 3261wprevious ! 3262call assert_equal ( l: first , bufnr ()) 3263 3264call delete ( "first" ) 3265call delete ( "middle" ) 3266call delete ( "last" ) 3267endfunc 3268 3269func Test_quickfix_switchbuf_invalid_prevwin () 3270call s: reset_all_buffers () 3271 3272call s: make_simple_quickfix () 3273call assert_equal ( 1 , getqflist (#{ idx : 0 }). idx ) 3274 3275set switchbuf = uselast 3276split 3277copen 3278exe winnr ( '#' ) 'quit' 3279call assert_equal ( 2 , winnr ( '$' )) 3280 3281cnext " Would've triggered a null pointer member access 3282call assert_equal ( 2 , getqflist (#{ idx : 0 }). idx ) 3283 3284set switchbuf & 3285endfunc 3286 3287func Test_listdo_goto_prevwin () 3288call s: reset_all_buffers () 3289call s: make_buffers_list () 3290 3291new 3292call assert_equal ( 0 , & winfixbuf ) 3293wincmd p 3294call assert_equal ( 1 , & winfixbuf ) 3295call assert_notequal ( bufnr (), bufnr ( '#' )) 3296 3297augroup ListDoGotoPrevwin 3298au ! 3299au BufLeave * let s: triggered = 1 3300 \|call assert_equal ( bufnr (), winbufnr ( winnr ())) 3301augroup END 3302" Should correctly switch to the window without 'winfixbuf', and curbuf should 3303" be consistent with curwin->w_buffer for autocommands. 3304bufdo " 3305call assert_equal ( 0 , & winfixbuf ) 3306call assert_equal ( 1 , s: triggered ) 3307unlet ! s: triggered 3308au ! ListDoGotoPrevwin 3309 3310set winfixbuf 3311wincmd p 3312call assert_equal ( 2 , winnr ( '$' )) 3313" Both curwin and prevwin have 'winfixbuf' set, so should split a new window 3314" without it set. 3315bufdo " 3316call assert_equal ( 0 , & winfixbuf ) 3317call assert_equal ( 3 , winnr ( '$' )) 3318 3319quit 3320call assert_equal ( 2 , winnr ( '$' )) 3321call assert_equal ( 1 , & winfixbuf ) 3322augroup ListDoGotoPrevwin 3323au ! 3324au WinEnter * ++once set winfixbuf 3325augroup END 3326" Same as before, but naughty autocommands set 'winfixbuf' for the new window. 3327" :bufdo should give up in this case. 3328call assert_fails ( 'bufdo "' , 'E1513:' ) 3329 3330au ! ListDoGotoPrevwin 3331augroup ! ListDoGotoPrevwin 3332endfunc 3333 3334func Test_quickfix_changed_split_failed () 3335call s: reset_all_buffers () 3336 3337call s: make_simple_quickfix () 3338call assert_equal ( 1 , winnr ( '$' )) 3339 3340" Quickfix code will open a split in an attempt to get a 'nowinfixbuf' window 3341" to switch buffers in. Interfere with things by setting 'winfixbuf' in it. 3342augroup QfChanged 3343au ! 3344au WinEnter * ++once call assert_equal ( 2 , winnr ( '$' )) 3345\| set winfixbuf | call setqflist ([], 'f' ) 3346augroup END 3347call assert_fails ( 'cnext' , [ 'E1513:' , 'E925:' ]) 3348" Check that the split was automatically closed. 3349call assert_equal ( 1 , winnr ( '$' )) 3350 3351au ! QfChanged 3352augroup ! QfChanged 3353endfunc 3354 3355func Test_bufdo_cnext_splitwin_fails () 3356call s: reset_all_buffers () 3357call s: make_simple_quickfix () 3358call assert_equal ( 1 , getqflist (#{ idx : 0 }). idx ) 3359" Make sure there is not enough room to 3360" split the winfixedbuf window 3361let & winheight =& lines 3362let & winminheight =& lines - 2 3363" Still want E1513, or it may not be clear why a split was attempted and why 3364" it failing caused the commands to abort. 3365call assert_fails ( ':bufdo echo 1' , [ 'E36:' , 'E1513:' ]) 3366call assert_fails ( ':cnext' , [ 'E36:' , 'E1513:' ]) 3367" Ensure the entry didn't change. 3368call assert_equal ( 1 , getqflist (#{ idx : 0 }). idx ) 3369set winminheight & vim winheight & vim 3370endfunc 3371 3372" Test that exiting with 'winfixbuf' and EXITFREE doesn't cause an error. 3373func Test_exitfree_no_error () 3374let lines =<< trim END 3375set winfixbuf 3376qall! 3377END 3378call writefile ( lines , 'Xwfb_exitfree' , 'D' ) 3379call assert_notmatch ( 'E1513:' , 3380"\ system(GetVimCommandClean() .. ' --not-a-term -X -S Xwfb_exitfree')) 3381\ system ( GetVimCommandClean () .. ' -X -S Xwfb_exitfree' )) 3382endfunc 3383 3384" vim: shiftwidth=2 sts=2 expandtab