robin/laufey
git clone https://git.robinwobin.dev/robin/laufey
4836ecad1f
master
1" Test for the quickfix feature. 2 3source check.vim 4source vim9.vim 5CheckFeature quickfix 6 7source screendump.vim 8 9set encoding = utf-8 10 11func s: setup_commands ( cchar ) 12if a: cchar == 'c' 13command ! -nargs = * -bang Xlist <mods>clist<bang> <args> 14command ! -nargs = * Xgetexpr <mods>cgetexpr <args> 15command ! -nargs = * Xaddexpr <mods>caddexpr <args> 16command ! -nargs = * -count Xolder <mods><count>colder <args> 17command ! -nargs = * Xnewer <mods>cnewer <args> 18command ! -nargs = * Xopen <mods> copen <args> 19command ! -nargs = * Xwindow <mods>cwindow <args> 20command ! -nargs = * Xbottom <mods>cbottom <args> 21command ! -nargs = * Xclose <mods>cclose <args> 22command ! -nargs = * -bang Xfile <mods>cfile<bang> <args> 23command ! -nargs = * Xgetfile <mods>cgetfile <args> 24command ! -nargs = * Xaddfile <mods>caddfile <args> 25command ! -nargs = * -bang Xbuffer <mods>cbuffer<bang> <args> 26command ! -nargs = * Xgetbuffer <mods>cgetbuffer <args> 27command ! -nargs = * Xaddbuffer <mods>caddbuffer <args> 28command ! -nargs = * Xrewind <mods>crewind <args> 29command ! -count -nargs = * -bang Xnext <mods><count>cnext<bang> <args> 30command ! -count -nargs = * -bang Xprev <mods><count>cprev<bang> <args> 31command ! -nargs = * -bang Xfirst <mods>cfirst<bang> <args> 32command ! -nargs = * -bang Xlast <mods>clast<bang> <args> 33command ! -count -nargs = * -bang Xnfile <mods><count>cnfile<bang> <args> 34command ! -nargs = * -bang Xpfile <mods>cpfile<bang> <args> 35command ! -nargs = * Xexpr <mods>cexpr <args> 36command ! -count = 999 -nargs = * Xvimgrep <mods> <count>vimgrep <args> 37command ! -nargs = * Xvimgrepadd <mods> vimgrepadd <args> 38command ! -nargs = * Xgrep <mods> grep <args> 39command ! -nargs = * Xgrepadd <mods> grepadd <args> 40command ! -nargs = * Xhelpgrep helpgrep <args> 41command ! -nargs = 0 -count Xcc <count>cc 42command ! -count = 1 -nargs = 0 Xbelow <mods><count>cbelow 43command ! -count = 1 -nargs = 0 Xabove <mods><count>cabove 44command ! -count = 1 -nargs = 0 Xbefore <mods><count>cbefore 45command ! -count = 1 -nargs = 0 Xafter <mods><count>cafter 46command ! -nargs = 1 Xsethist <mods>set chistory=<args> 47command ! -nargs = 0 Xsethistdefault <mods>set chistory& 48let g: Xgetlist = function ( 'getqflist' ) 49let g: Xsetlist = function ( 'setqflist' ) 50call setqflist ([], 'f' ) 51else 52command ! -nargs = * -bang Xlist <mods>llist<bang> <args> 53command ! -nargs = * Xgetexpr <mods>lgetexpr <args> 54command ! -nargs = * Xaddexpr <mods>laddexpr <args> 55command ! -nargs = * -count Xolder <mods><count>lolder <args> 56command ! -nargs = * Xnewer <mods>lnewer <args> 57command ! -nargs = * Xopen <mods> lopen <args> 58command ! -nargs = * Xwindow <mods>lwindow <args> 59command ! -nargs = * Xbottom <mods>lbottom <args> 60command ! -nargs = * Xclose <mods>lclose <args> 61command ! -nargs = * -bang Xfile <mods>lfile<bang> <args> 62command ! -nargs = * Xgetfile <mods>lgetfile <args> 63command ! -nargs = * Xaddfile <mods>laddfile <args> 64command ! -nargs = * -bang Xbuffer <mods>lbuffer<bang> <args> 65command ! -nargs = * Xgetbuffer <mods>lgetbuffer <args> 66command ! -nargs = * Xaddbuffer <mods>laddbuffer <args> 67command ! -nargs = * Xrewind <mods>lrewind <args> 68command ! -count -nargs = * -bang Xnext <mods><count>lnext<bang> <args> 69command ! -count -nargs = * -bang Xprev <mods><count>lprev<bang> <args> 70command ! -nargs = * -bang Xfirst <mods>lfirst<bang> <args> 71command ! -nargs = * -bang Xlast <mods>llast<bang> <args> 72command ! -count -nargs = * -bang Xnfile <mods><count>lnfile<bang> <args> 73command ! -nargs = * -bang Xpfile <mods>lpfile<bang> <args> 74command ! -nargs = * Xexpr <mods>lexpr <args> 75command ! -count = 999 -nargs = * Xvimgrep <mods> <count>lvimgrep <args> 76command ! -nargs = * Xvimgrepadd <mods> lvimgrepadd <args> 77command ! -nargs = * Xgrep <mods> lgrep <args> 78command ! -nargs = * Xgrepadd <mods> lgrepadd <args> 79command ! -nargs = * Xhelpgrep lhelpgrep <args> 80command ! -nargs = 0 -count Xcc <count>ll 81command ! -count = 1 -nargs = 0 Xbelow <mods><count>lbelow 82command ! -count = 1 -nargs = 0 Xabove <mods><count>labove 83command ! -count = 1 -nargs = 0 Xbefore <mods><count>lbefore 84command ! -count = 1 -nargs = 0 Xafter <mods><count>lafter 85command ! -nargs = 1 Xsethist <mods>set lhistory=<args> 86command ! -nargs = 1 Xsetlocalhist <mods>setlocal lhistory=<args> 87command ! -nargs = 0 Xsethistdefault <mods>set lhistory& 88let g: Xgetlist = function ( 'getloclist' , [ 0 ]) 89let g: Xsetlist = function ( 'setloclist' , [ 0 ]) 90call setloclist ( 0 , [], 'f' ) 91endif 92endfunc 93 94" This must be run before any error lists are created. 95func Test_AA_cc_no_errors () 96call assert_fails ( 'cc' , 'E42:' ) 97call assert_fails ( 'll' , 'E42:' ) 98endfunc 99 100" Tests for the :clist and :llist commands 101func XlistTests ( cchar ) 102call s: setup_commands ( a: cchar ) 103 104if a: cchar == 'l' 105call assert_fails ( 'llist' , 'E776:' ) 106endif 107" With an empty list, command should return error 108Xgetexpr [] 109silent ! Xlist 110call assert_true ( v: errmsg ==# 'E42: No Errors' ) 111 112" Populate the list and then try 113let lines =<< trim END 114non-error 1 115Xtestfile1:1:3:Line1 116non-error 2 117Xtestfile2:2:2:Line2 118non-error| 3 119Xtestfile3:3:1:Line3 120END 121Xgetexpr lines 122 123" List only valid entries 124let l = split ( execute ( 'Xlist' , '' ), "\n" ) 125call assert_equal ([ ' 2 Xtestfile1:1 col 3: Line1' , 126 \' 4 Xtestfile2:2 col 2: Line2' , 127 \' 6 Xtestfile3:3 col 1: Line3' ], l ) 128 129" List all the entries 130let l = split ( execute ( 'Xlist!' , '' ), "\n" ) 131call assert_equal ([ ' 1: non-error 1' , ' 2 Xtestfile1:1 col 3: Line1' , 132 \' 3: non-error 2' , ' 4 Xtestfile2:2 col 2: Line2' , 133 \' 5: non-error| 3' , ' 6 Xtestfile3:3 col 1: Line3' ], l ) 134 135" List a range of errors 136let l = split ( execute ( 'Xlist 3,6' , '' ), "\n" ) 137call assert_equal ([ ' 4 Xtestfile2:2 col 2: Line2' , 138 \' 6 Xtestfile3:3 col 1: Line3' ], l ) 139 140let l = split ( execute ( 'Xlist! 3,4' , '' ), "\n" ) 141call assert_equal ([ ' 3: non-error 2' , ' 4 Xtestfile2:2 col 2: Line2' ], l ) 142 143let l = split ( execute ( 'Xlist -6,-4' , '' ), "\n" ) 144call assert_equal ([ ' 2 Xtestfile1:1 col 3: Line1' ], l ) 145 146let l = split ( execute ( 'Xlist! -5,-3' , '' ), "\n" ) 147call assert_equal ([ ' 2 Xtestfile1:1 col 3: Line1' , 148 \' 3: non-error 2' , ' 4 Xtestfile2:2 col 2: Line2' ], l ) 149 150" Test for '+' 151let l = split ( execute ( 'Xlist! +2' , '' ), "\n" ) 152call assert_equal ([ ' 2 Xtestfile1:1 col 3: Line1' , 153 \' 3: non-error 2' , ' 4 Xtestfile2:2 col 2: Line2' ], l ) 154 155" Ranged entries 156call g: Xsetlist ([{ 'lnum' : 10 , 'text' : 'Line1' }, 157 \{ 'lnum' : 20 , 'col' : 10 , 'text' : 'Line2' }, 158 \{ 'lnum' : 30 , 'col' : 15 , 'end_col' : 20 , 'text' : 'Line3' }, 159 \{ 'lnum' : 40 , 'end_lnum' : 45 , 'text' : 'Line4' }, 160 \{ 'lnum' : 50 , 'end_lnum' : 55 , 'col' : 15 , 'text' : 'Line5' }, 161 \{ 'lnum' : 60 , 'end_lnum' : 65 , 'col' : 25 , 'end_col' : 35 , 'text' : 'Line6' }]) 162let l = split ( execute ( 'Xlist' , "" ), "\n" ) 163call assert_equal ([ ' 1:10: Line1' , 164 \' 2:20 col 10: Line2' , 165 \' 3:30 col 15-20: Line3' , 166 \' 4:40-45: Line4' , 167 \' 5:50-55 col 15: Line5' , 168 \' 6:60-65 col 25-35: Line6' ], l ) 169 170" Different types of errors 171call g: Xsetlist ([{ 'lnum' : 10 , 'col' : 5 , 'type' : 'W' , 'text' : 'Warning' , 'nr' : 11 }, 172 \{ 'lnum' : 20 , 'col' : 10 , 'type' : 'e' , 'text' : 'Error' , 'nr' : 22 }, 173 \{ 'lnum' : 30 , 'col' : 15 , 'type' : 'i' , 'text' : 'Info' , 'nr' : 33 }, 174 \{ 'lnum' : 40 , 'col' : 20 , 'type' : 'x' , 'text' : 'Other' , 'nr' : 44 }, 175 \{ 'lnum' : 50 , 'col' : 25 , 'type' : "\<C-A>" , 'text' : 'one' , 'nr' : 55 }, 176 \{ 'lnum' : 0 , 'type' : 'e' , 'text' : 'Check type field is output even when lnum==0. ("error" was not output by v9.0.0736.)' , 'nr' : 66 }]) 177let l = split ( execute ( 'Xlist' , "" ), "\n" ) 178call assert_equal ([ ' 1:10 col 5 warning 11: Warning' , 179 \' 2:20 col 10 error 22: Error' , 180 \' 3:30 col 15 info 33: Info' , 181 \' 4:40 col 20 x 44: Other' , 182 \' 5:50 col 25 55: one' , 183 \' 6 error 66: Check type field is output even when lnum==0. ("error" was not output by v9.0.0736.)' ], l ) 184 185" Test for module names, one needs to explicitly set `'valid':v:true` so 186call g: Xsetlist ([ 187 \{ 'lnum' : 10 , 'col' : 5 , 'type' : 'W' , 'module' : 'Data.Text' , 'text' : 'ModuleWarning' , 'nr' : 11 , 'valid' : v: true }, 188 \{ 'lnum' : 20 , 'col' : 10 , 'type' : 'W' , 'module' : 'Data.Text' , 'filename' : 'Data/Text.hs' , 'text' : 'ModuleWarning' , 'nr' : 22 , 'valid' : v: true }, 189 \{ 'lnum' : 30 , 'col' : 15 , 'type' : 'W' , 'filename' : 'Data/Text.hs' , 'text' : 'FileWarning' , 'nr' : 33 , 'valid' : v: true }]) 190let l = split ( execute ( 'Xlist' , "" ), "\n" ) 191call assert_equal ([ ' 1 Data.Text:10 col 5 warning 11: ModuleWarning' , 192 \' 2 Data.Text:20 col 10 warning 22: ModuleWarning' , 193 \' 3 Data/Text.hs:30 col 15 warning 33: FileWarning' ], l ) 194 195" Very long line should be displayed. 196let text = 'Line' .. repeat ( '1234567890' , 130 ) 197let lines = [ 'Xtestfile9:2:9:' .. text ] 198Xgetexpr lines 199 200let l = split ( execute ( 'Xlist' , '' ), "\n" ) 201call assert_equal ([ ' 1 Xtestfile9:2 col 9: ' .. text ] , l ) 202 203" For help entries in the quickfix list, only the filename without directory 204" should be displayed 205Xhelpgrep setqflist() 206let l = split ( execute ( 'Xlist 1' , '' ), "\n" ) 207call assert_match ( '^ 1 [^\\/]\{-}:' , l [ 0 ]) 208 209" Error cases 210call assert_fails ( 'Xlist abc' , 'E488:' ) 211endfunc 212 213func Test_clist () 214call XlistTests ( 'c' ) 215call XlistTests ( 'l' ) 216endfunc 217 218" Tests for the :colder, :cnewer, :lolder and :lnewer commands 219" Note that this test assumes that a quickfix/location list is 220" already set by the caller. 221func XageTests ( cchar ) 222call s: setup_commands ( a: cchar ) 223 224if a: cchar == 'l' 225" No location list for the current window 226call assert_fails ( 'lolder' , 'E776:' ) 227call assert_fails ( 'lnewer' , 'E776:' ) 228endif 229 230let list = [{ 'bufnr' : bufnr ( '%' ), 'lnum' : 1 }] 231call g: Xsetlist ( list ) 232 233" Jumping to a non existent list should return error 234silent ! Xolder 99 235call assert_true ( v: errmsg ==# 'E380: At bottom of quickfix stack' ) 236 237silent ! Xnewer 99 238call assert_true ( v: errmsg ==# 'E381: At top of quickfix stack' ) 239 240" Add three quickfix/location lists 241Xgetexpr ['Xtestfile1:1:3:Line1'] 242Xgetexpr ['Xtestfile2:2:2:Line2'] 243Xgetexpr ['Xtestfile3:3:1:Line3'] 244 245" Go back two lists 246Xolder 247let l = g: Xgetlist () 248call assert_equal ( 'Line2' , l [ 0 ]. text ) 249 250" Go forward two lists 251Xnewer 252let l = g: Xgetlist () 253call assert_equal ( 'Line3' , l [ 0 ]. text ) 254 255" Test for the optional count argument 256Xolder 2 257let l = g: Xgetlist () 258call assert_equal ( 'Line1' , l [ 0 ]. text ) 259 260Xnewer 2 261let l = g: Xgetlist () 262call assert_equal ( 'Line3' , l [ 0 ]. text ) 263endfunc 264 265func Test_cage () 266call XageTests ( 'c' ) 267call XageTests ( 'l' ) 268endfunc 269 270" Tests for the :cwindow, :lwindow :cclose, :lclose, :copen and :lopen 271" commands 272func XwindowTests ( cchar ) 273call s: setup_commands ( a: cchar ) 274 275" Opening the location list window without any errors should fail 276if a: cchar == 'l' 277call assert_fails ( 'lopen' , 'E776:' ) 278call assert_fails ( 'lwindow' , 'E776:' ) 279endif 280 281" Create a list with no valid entries 282Xgetexpr ['non-error 1','non-error 2' ,'non-error 3' ] 283 284" Quickfix/Location window should not open with no valid errors 285Xwindow 286call assert_true ( winnr ( '$' ) == 1 ) 287 288" Create a list with valid entries 289let lines =<< trim END 290Xtestfile1:1:3:Line1 291Xtestfile2:2:2:Line2 292Xtestfile3:3:1:Line3 293END 294Xgetexpr lines 295 296" Open the window 297Xwindow 298call assert_true ( winnr ( '$' ) == 2 && winnr () == 2 && 299 \getline ( '.' ) ==# 'Xtestfile1|1 col 3| Line1' ) 300redraw ! 301 302" Close the window 303Xclose 304call assert_true ( winnr ( '$' ) == 1 ) 305 306" Create a list with no valid entries 307Xgetexpr ['non-error 1','non-error 2' ,'non-error 3' ] 308 309" Open the window 310Xopen 5 311call assert_true ( winnr ( '$' ) == 2 && getline ( '.' ) ==# '|| non-error 1' 312 \&& winheight ( 0 ) == 5 ) 313 314" Opening the window again, should move the cursor to that window 315wincmd t 316Xopen 7 317call assert_true ( winnr ( '$' ) == 2 && winnr () == 2 && 318 \winheight ( 0 ) == 7 && 319 \getline ( '.' ) ==# '|| non-error 1' ) 320 321" :cnext in quickfix window should move to the next entry 322Xnext 323call assert_equal ( 2 , g: Xgetlist ({ 'idx' : 0 }). idx ) 324 325" Calling cwindow should close the quickfix window with no valid errors 326Xwindow 327call assert_true ( winnr ( '$' ) == 1 ) 328 329" Specifying the width should adjust the width for a vertically split 330" quickfix window. 331vert Xopen 332call assert_equal ( 10 , winwidth ( 0 )) 333vert Xopen 12 334call assert_equal ( 12 , winwidth ( 0 )) 335Xclose 336 337" Horizontally or vertically splitting the quickfix window should create a 338" normal window/buffer 339Xopen 340wincmd s 341call assert_equal ( 0 , getwininfo ( win_getid ())[ 0 ]. quickfix ) 342call assert_equal ( 0 , getwininfo ( win_getid ())[ 0 ]. loclist ) 343call assert_notequal ( 'quickfix' , & buftype ) 344close 345Xopen 346wincmd v 347call assert_equal ( 0 , getwininfo ( win_getid ())[ 0 ]. quickfix ) 348call assert_equal ( 0 , getwininfo ( win_getid ())[ 0 ]. loclist ) 349call assert_notequal ( 'quickfix' , & buftype ) 350close 351Xopen 352Xclose 353 354if a: cchar == 'c' 355" Opening the quickfix window in multiple tab pages should reuse the 356" quickfix buffer 357let lines =<< trim END 358Xtestfile1:1:3:Line1 359Xtestfile2:2:2:Line2 360Xtestfile3:3:1:Line3 361END 362Xgetexpr lines 363Xopen 364let qfbufnum = bufnr ( '%' ) 365tabnew 366Xopen 367call assert_equal ( qfbufnum , bufnr ( '%' )) 368new |only |tabonly 369endif 370endfunc 371 372func Test_cwindow () 373call XwindowTests ( 'c' ) 374call XwindowTests ( 'l' ) 375endfunc 376 377func Test_copenHeight () 378copen 379wincmd H 380let height = winheight ( 0 ) 381copen 10 382call assert_equal ( height , winheight ( 0 )) 383quit 384endfunc 385 386func Test_copenHeight_tabline () 387set tabline = fooshowtabline = 2 388copen 389wincmd H 390let height = winheight ( 0 ) 391copen 10 392call assert_equal ( height , winheight ( 0 )) 393quit 394set tabline & showtabline & 395endfunc 396 397" Tests for the :cfile, :lfile, :caddfile, :laddfile, :cgetfile and :lgetfile 398" commands. 399func XfileTests ( cchar ) 400call s: setup_commands ( a: cchar ) 401 402let lines =<< trim END 403Xtestfile1:700:10:Line 700 404Xtestfile2:800:15:Line 800 405END 406call writefile ( lines , 'Xqftestfile1' ) 407 408enew ! 409Xfile Xqftestfile1 410let l = g: Xgetlist () 411call assert_true ( len ( l ) == 2 && 412 \l [ 0 ]. lnum == 700 && l [ 0 ]. col == 10 && l [ 0 ]. text ==# 'Line 700' && 413 \l [ 1 ]. lnum == 800 && l [ 1 ]. col == 15 && l [ 1 ]. text ==# 'Line 800' ) 414 415" Test with a non existent file 416call assert_fails ( 'Xfile non_existent_file' , 'E40' ) 417 418" Run cfile/lfile from a modified buffer 419enew ! 420silent ! put ='Quickfix' 421silent ! Xfile Xqftestfile1 422call assert_true ( v: errmsg ==# 'E37: No write since last change (add ! to override)' ) 423 424call writefile ([ 'Xtestfile3:900:30:Line 900' ], 'Xqftestfile1' ) 425Xaddfile Xqftestfile1 426let l = g: Xgetlist () 427call assert_true ( len ( l ) == 3 && 428 \l [ 2 ]. lnum == 900 && l [ 2 ]. col == 30 && l [ 2 ]. text ==# 'Line 900' ) 429 430let lines =<< trim END 431Xtestfile1:222:77:Line 222 432Xtestfile2:333:88:Line 333 433END 434call writefile ( lines , 'Xqftestfile1' ) 435 436enew ! 437Xgetfile Xqftestfile1 438let l = g: Xgetlist () 439call assert_true ( len ( l ) == 2 && 440 \l [ 0 ]. lnum == 222 && l [ 0 ]. col == 77 && l [ 0 ]. text ==# 'Line 222' && 441 \l [ 1 ]. lnum == 333 && l [ 1 ]. col == 88 && l [ 1 ]. text ==# 'Line 333' ) 442 443" Test for a file with a long line and without a newline at the end 444let text = repeat ( 'x' , 1024 ) 445let t = 'a.txt:18:' . text 446call writefile ([ t ], 'Xqftestfile1' , 'b' ) 447silent ! Xfile Xqftestfile1 448call assert_equal ( text , g: Xgetlist ()[ 0 ]. text ) 449 450call delete ( 'Xqftestfile1' ) 451endfunc 452 453func Test_cfile () 454call XfileTests ( 'c' ) 455call XfileTests ( 'l' ) 456endfunc 457 458" Tests for the :cbuffer, :lbuffer, :caddbuffer, :laddbuffer, :cgetbuffer and 459" :lgetbuffer commands. 460func XbufferTests ( cchar ) 461call s: setup_commands ( a: cchar ) 462 463enew ! 464let lines =<< trim END 465Xtestfile7:700:10:Line 700 466Xtestfile8:800:15:Line 800 467END 468silent ! call setline ( 1 , lines ) 469Xbuffer ! 470let l = g: Xgetlist () 471call assert_true ( len ( l ) == 2 && 472 \l [ 0 ]. lnum == 700 && l [ 0 ]. col == 10 && l [ 0 ]. text ==# 'Line 700' && 473 \l [ 1 ]. lnum == 800 && l [ 1 ]. col == 15 && l [ 1 ]. text ==# 'Line 800' ) 474 475enew ! 476let lines =<< trim END 477Xtestfile9:900:55:Line 900 478Xtestfile10:950:66:Line 950 479END 480silent ! call setline ( 1 , lines ) 481Xgetbuffer 482let l = g: Xgetlist () 483call assert_true ( len ( l ) == 2 && 484 \l [ 0 ]. lnum == 900 && l [ 0 ]. col == 55 && l [ 0 ]. text ==# 'Line 900' && 485 \l [ 1 ]. lnum == 950 && l [ 1 ]. col == 66 && l [ 1 ]. text ==# 'Line 950' ) 486 487enew ! 488let lines =<< trim END 489Xtestfile11:700:20:Line 700 490Xtestfile12:750:25:Line 750 491END 492silent ! call setline ( 1 , lines ) 493Xaddbuffer 494let l = g: Xgetlist () 495call assert_true ( len ( l ) == 4 && 496 \l [ 1 ]. lnum == 950 && l [ 1 ]. col == 66 && l [ 1 ]. text ==# 'Line 950' && 497 \l [ 2 ]. lnum == 700 && l [ 2 ]. col == 20 && l [ 2 ]. text ==# 'Line 700' && 498 \l [ 3 ]. lnum == 750 && l [ 3 ]. col == 25 && l [ 3 ]. text ==# 'Line 750' ) 499enew ! 500 501" Check for invalid buffer 502call assert_fails ( 'Xbuffer 199' , 'E474:' ) 503 504" Check for unloaded buffer 505edit Xtestfile1 506let bnr = bufnr ( '%' ) 507enew ! 508call assert_fails ( 'Xbuffer ' . bnr , 'E681:' ) 509 510" Check for invalid range 511" Using Xbuffer will not run the range check in the cbuffer/lbuffer 512" commands. So directly call the commands. 513if ( a: cchar == 'c' ) 514call assert_fails ( '900,999cbuffer' , 'E16:' ) 515else 516call assert_fails ( '900,999lbuffer' , 'E16:' ) 517endif 518endfunc 519 520func Test_cbuffer () 521call XbufferTests ( 'c' ) 522call XbufferTests ( 'l' ) 523endfunc 524 525func XexprTests ( cchar ) 526call s: setup_commands ( a: cchar ) 527 528call assert_fails ( 'Xexpr 10' , 'E777:' ) 529endfunc 530 531func Test_cexpr () 532call XexprTests ( 'c' ) 533call XexprTests ( 'l' ) 534endfunc 535 536" Tests for :cnext, :cprev, :cfirst, :clast commands 537func Xtest_browse ( cchar ) 538call s: setup_commands ( a: cchar ) 539 540call g: Xsetlist ([], 'f' ) 541" Jumping to first or next location list entry without any error should 542" result in failure 543if a: cchar == 'c' 544let err = 'E42:' 545let cmd = '$cc' 546else 547let err = 'E776:' 548let cmd = '$ll' 549endif 550call assert_fails ( 'Xnext' , err ) 551call assert_fails ( 'Xprev' , err ) 552call assert_fails ( 'Xnfile' , err ) 553call assert_fails ( 'Xpfile' , err ) 554call assert_fails ( cmd , err ) 555 556Xexpr '' 557call assert_fails ( cmd , 'E42:' ) 558 559call s: create_test_file ( 'Xqftestfile1' ) 560call s: create_test_file ( 'Xqftestfile2' ) 561 562let lines =<< trim END 563Xqftestfile1:5:Line5 564Xqftestfile1:6:Line6 565Xqftestfile2:10:Line10 566Xqftestfile2:11:Line11 567RegularLine1 568RegularLine2 569END 570Xgetexpr lines 571 572Xfirst 573call assert_fails ( '-5Xcc' , 'E16:' ) 574call assert_fails ( 'Xprev' , 'E553' ) 575call assert_fails ( 'Xpfile' , 'E553' ) 576Xnfile 577call assert_equal ( 'Xqftestfile2' , @%) 578call assert_equal ( 10 , line ( '.' )) 579Xpfile 580call assert_equal ( 'Xqftestfile1' , @%) 581call assert_equal ( 6 , line ( '.' )) 5825 Xcc 583call assert_equal ( 5 , g: Xgetlist ({ 'idx' : 0 }). idx ) 5842 Xcc 585call assert_equal ( 2 , g: Xgetlist ({ 'idx' : 0 }). idx ) 586if a: cchar == 'c' 587cc 588else 589ll 590endif 591call assert_equal ( 2 , g: Xgetlist ({ 'idx' : 0 }). idx ) 59210 Xcc 593call assert_equal ( 6 , g: Xgetlist ({ 'idx' : 0 }). idx ) 594Xlast 595Xprev 596call assert_equal ( 'Xqftestfile2' , @%) 597call assert_equal ( 11 , line ( '.' )) 598call assert_fails ( 'Xnext' , 'E553' ) 599call assert_fails ( 'Xnfile' , 'E553' ) 600" To process the range using quickfix list entries, directly use the 601" quickfix commands (don't use the user defined commands) 602if a: cchar == 'c' 603$ cc 604else 605$ ll 606endif 607call assert_equal ( 6 , g: Xgetlist ({ 'idx' : 0 }). idx ) 608Xrewind 609call assert_equal ( 'Xqftestfile1' , @%) 610call assert_equal ( 5 , line ( '.' )) 611 61210 Xnext 613call assert_equal ( 'Xqftestfile2' , @%) 614call assert_equal ( 11 , line ( '.' )) 61510 Xprev 616call assert_equal ( 'Xqftestfile1' , @%) 617call assert_equal ( 5 , line ( '.' )) 618 619" Jumping to an error from the error window using cc command 620let lines =<< trim END 621Xqftestfile1:5:Line5 622Xqftestfile1:6:Line6 623Xqftestfile2:10:Line10 624Xqftestfile2:11:Line11 625END 626Xgetexpr lines 627Xopen 62810 Xcc 629call assert_equal ( 11 , line ( '.' )) 630call assert_equal ( 'Xqftestfile2' , @%) 631Xopen 632call cursor ( 2 , 1 ) 633if a: cchar == 'c' 634 .cc 635else 636 .ll 637endif 638call assert_equal ( 6 , line ( '.' )) 639call assert_equal ( 'Xqftestfile1' , @%) 640 641" Jumping to an error from the error window (when only the error window is 642" present) 643Xopen |only 644Xlast 1 645call assert_equal ( 5 , line ( '.' )) 646call assert_equal ( 'Xqftestfile1' , @%) 647 648Xexpr "" 649call assert_fails ( 'Xnext' , 'E42:' ) 650 651call delete ( 'Xqftestfile1' ) 652call delete ( 'Xqftestfile2' ) 653 654" Should be able to use next/prev with invalid entries 655Xexpr "" 656call assert_equal ( 0 , g: Xgetlist ({ 'idx' : 0 }). idx ) 657call assert_equal ( 0 , g: Xgetlist ({ 'size' : 0 }). size ) 658Xaddexpr ['foo','bar' ,'baz' ,'quux' ,'sh|moo' ] 659call assert_equal ( 5 , g: Xgetlist ({ 'size' : 0 }). size ) 660Xlast 661call assert_equal ( 5 , g: Xgetlist ({ 'idx' : 0 }). idx ) 662Xfirst 663call assert_equal ( 1 , g: Xgetlist ({ 'idx' : 0 }). idx ) 6642 Xnext 665call assert_equal ( 3 , g: Xgetlist ({ 'idx' : 0 }). idx ) 666endfunc 667 668func Test_browse () 669call Xtest_browse ( 'c' ) 670call Xtest_browse ( 'l' ) 671endfunc 672 673" Test for memory allocation failures 674func Xnomem_tests ( cchar ) 675call s: setup_commands ( a: cchar ) 676 677call test_alloc_fail ( GetAllocId ( 'qf_dirname_start' ), 0 , 0 ) 678call assert_fails ( 'Xvimgrep vim runtest.vim' , 'E342:' ) 679 680call test_alloc_fail ( GetAllocId ( 'qf_dirname_now' ), 0 , 0 ) 681call assert_fails ( 'Xvimgrep vim runtest.vim' , 'E342:' ) 682 683call test_alloc_fail ( GetAllocId ( 'qf_namebuf' ), 0 , 0 ) 684call assert_fails ( 'Xfile runtest.vim' , 'E342:' ) 685 686call test_alloc_fail ( GetAllocId ( 'qf_errmsg' ), 0 , 0 ) 687call assert_fails ( 'Xfile runtest.vim' , 'E342:' ) 688 689call test_alloc_fail ( GetAllocId ( 'qf_pattern' ), 0 , 0 ) 690call assert_fails ( 'Xfile runtest.vim' , 'E342:' ) 691 692call test_alloc_fail ( GetAllocId ( 'qf_efm_fmtstr' ), 0 , 0 ) 693set efm = %f 694call assert_fails ( 'Xexpr ["Xfile1"]' , 'E342:' ) 695set efm & 696 697call test_alloc_fail ( GetAllocId ( 'qf_efm_fmtpart' ), 0 , 0 ) 698set efm = %f:%l:%m,%f-%l-%m 699call assert_fails ( 'Xaddexpr ["Xfile2", "Xfile3"]' , 'E342:' ) 700set efm & 701 702call test_alloc_fail ( GetAllocId ( 'qf_title' ), 0 , 0 ) 703call assert_fails ( 'Xexpr ""' , 'E342:' ) 704call assert_equal ( '' , g: Xgetlist ({ 'all' : 1 }). title ) 705 706call test_alloc_fail ( GetAllocId ( 'qf_mef_name' ), 0 , 0 ) 707set makeef = Xtmp##.err 708call assert_fails ( 'Xgrep needle haystack' , 'E342:' ) 709set makeef & 710 711call test_alloc_fail ( GetAllocId ( 'qf_qfline' ), 0 , 0 ) 712call assert_fails ( 'Xexpr "Xfile1:10:Line10"' , 'E342:' ) 713 714if a: cchar == 'l' 715for id in [ 'qf_qfline' , 'qf_qfinfo' ] 716lgetexpr ["Xfile1:10:L10","Xfile2:20:L20" ] 717call test_alloc_fail ( GetAllocId ( id ), 0 , 0 ) 718call assert_fails ( 'new' , 'E342:' ) 719call assert_equal ( 2 , winnr ( '$' )) 720call assert_equal ([], getloclist ( 0 )) 721 %bw ! 722endfor 723endif 724 725call test_alloc_fail ( GetAllocId ( 'qf_qfline' ), 0 , 0 ) 726try 727call assert_fails ( 'Xvimgrep vim runtest.vim' , 'E342:' ) 728catch /^Vim:Interrupt$/ 729endtry 730 731call test_alloc_fail ( GetAllocId ( 'qf_qfline' ), 0 , 0 ) 732try 733call assert_fails ( 'Xvimgrep /vim/f runtest.vim' , 'E342:' ) 734catch /^Vim:Interrupt$/ 735endtry 736 737let l = getqflist ({ "lines" : [ "Xfile1:10:L10" ]}) 738call test_alloc_fail ( GetAllocId ( 'qf_qfline' ), 0 , 0 ) 739call assert_fails ( 'call g:Xsetlist(l.items)' , 'E342:' ) 740 741call test_alloc_fail ( GetAllocId ( 'qf_qfline' ), 0 , 0 ) 742try 743call assert_fails ( 'Xhelpgrep quickfix' , 'E342:' ) 744catch /^Vim:Interrupt$/ 745endtry 746 747call test_alloc_fail ( GetAllocId ( 'qf_qfinfo' ), 0 , 0 ) 748call assert_fails ( 'let l = g:Xgetlist({"lines": ["Xfile1:10:L10"]})' , 'E342:' ) 749call assert_equal (#{ items : []}, l ) 750 751if a: cchar == 'l' 752call setqflist ([], 'f' ) 753call setloclist ( 0 , [], 'f' ) 754call test_alloc_fail ( GetAllocId ( 'qf_qfinfo' ), 0 , 0 ) 755call assert_fails ( 'lhelpgrep quickfix' , 'E342:' ) 756call assert_equal ([], getloclist ( 0 )) 757 758call test_alloc_fail ( GetAllocId ( 'qf_qfinfo' ), 0 , 0 ) 759call assert_fails ( 'lvimgrep vim runtest.vim' , 'E342:' ) 760 761let l = getqflist ({ "lines" : [ "Xfile1:10:L10" ]}) 762call test_alloc_fail ( GetAllocId ( 'qf_qfinfo' ), 0 , 0 ) 763call assert_fails ( 'call setloclist(0, l.items)' , 'E342:' ) 764 765call test_alloc_fail ( GetAllocId ( 'qf_qfinfo' ), 0 , 0 ) 766call assert_fails ( 'lbuffer' , 'E342:' ) 767 768call test_alloc_fail ( GetAllocId ( 'qf_qfinfo' ), 0 , 0 ) 769call assert_fails ( 'lexpr ["Xfile1:10:L10", "Xfile2:20:L20"]' , 'E342:' ) 770 771call test_alloc_fail ( GetAllocId ( 'qf_qfinfo' ), 0 , 0 ) 772call assert_fails ( 'lfile runtest.vim' , 'E342:' ) 773endif 774 775call test_alloc_fail ( GetAllocId ( 'qf_dirstack' ), 0 , 0 ) 776set efm = %DEntering\ dir\ %f,%f:%l:%m 777call assert_fails ( 'Xexpr ["Entering dir abc", "abc.txt:1:Hello world"]' , 'E342:' ) 778set efm & 779 780call test_alloc_fail ( GetAllocId ( 'qf_dirstack' ), 0 , 0 ) 781set efm = %+P[%f],(%l)%m 782call assert_fails ( 'Xexpr ["[runtest.vim]", "(1)Hello"]' , 'E342:' ) 783set efm & 784 785call test_alloc_fail ( GetAllocId ( 'qf_multiline_pfx' ), 0 , 0 ) 786set efm = %EError,%Cline\ %l,%Z%m 787call assert_fails ( 'Xexpr ["Error", "line 1", "msg"]' , 'E342:' ) 788set efm & 789 790call test_alloc_fail ( GetAllocId ( 'qf_makecmd' ), 0 , 0 ) 791call assert_fails ( 'Xgrep vim runtest.vim' , 'E342:' ) 792 793call test_alloc_fail ( GetAllocId ( 'qf_linebuf' ), 0 , 0 ) 794call assert_fails ( 'Xexpr repeat("a", 8192)' , 'E342:' ) 795 796call test_alloc_fail ( GetAllocId ( 'qf_linebuf' ), 0 , 0 ) 797call assert_fails ( 'Xexpr [repeat("a", 8192)]' , 'E342:' ) 798 799new 800call setline ( 1 , repeat ( 'a' , 8192 )) 801call test_alloc_fail ( GetAllocId ( 'qf_linebuf' ), 0 , 0 ) 802call assert_fails ( 'Xbuffer' , 'E342:' ) 803 %bw ! 804 805call writefile ([ repeat ( 'a' , 8192 )], 'Xtest' ) 806call test_alloc_fail ( GetAllocId ( 'qf_linebuf' ), 0 , 0 ) 807call assert_fails ( 'Xfile Xtest' , 'E342:' ) 808call delete ( 'Xtest' ) 809endfunc 810 811func Test_nomem () 812throw 'Skipped: Nvim does not support test_alloc_fail()' 813call Xnomem_tests ( 'c' ) 814call Xnomem_tests ( 'l' ) 815endfunc 816 817func s: test_xhelpgrep ( cchar ) 818call s: setup_commands ( a: cchar ) 819Xhelpgrep quickfix 820Xopen 821if a: cchar == 'c' 822let title_text = ':helpgrep quickfix' 823else 824let title_text = ':lhelpgrep quickfix' 825endif 826call assert_true ( w: quickfix_title =~ title_text , w: quickfix_title ) 827 828" Jumping to a help topic should open the help window 829only 830Xnext 831call assert_true ( & buftype == 'help' ) 832call assert_true ( winnr ( '$' ) == 2 ) 833" Jumping to the next match should reuse the help window 834Xnext 835call assert_true ( & buftype == 'help' ) 836call assert_true ( winnr () == 1 ) 837call assert_true ( winnr ( '$' ) == 2 ) 838" Jumping to the next match from the quickfix window should reuse the help 839" window 840Xopen 841Xnext 842call assert_true ( & buftype == 'help' ) 843call assert_true ( winnr () == 1 ) 844call assert_true ( winnr ( '$' ) == 2 ) 845call assert_match ( '|\d\+ col \d\+-\d\+|' , getbufline ( winbufnr ( 2 ), 1 )[ 0 ]) 846 847" This wipes out the buffer, make sure that doesn't cause trouble. 848Xclose 849 850" When the current window is vertically split, jumping to a help match 851" should open the help window at the top. 852only |enew 853let w1 = win_getid () 854vert new 855let w2 = win_getid () 856Xnext 857let w3 = win_getid () 858call assert_true ( & buftype == 'help' ) 859call assert_true ( winnr () == 1 ) 860" See jump_to_help_window() for details 861let w2_width = winwidth ( w2 ) 862if w2_width != & columns && w2_width < 80 863call assert_equal ([ 'col' , [[ 'leaf' , w3 ], 864 \[ 'row' , [[ 'leaf' , w2 ], [ 'leaf' , w1 ]]]]], winlayout ()) 865else 866call assert_equal ([ 'row' , [[ 'col' , [[ 'leaf' , w3 ], [ 'leaf' , w2 ]]], 867 \[ 'leaf' , w1 ]]] , winlayout ()) 868endif 869 870new |only 871set buftype = help 872set modified 873call assert_fails ( 'Xnext' , 'E37:' ) 874set nomodified 875new |only 876 877if a: cchar == 'l' 878" When a help window is present, running :lhelpgrep should reuse the 879" help window and not the current window 880new |only 881call g: Xsetlist ([], 'f' ) 882help index.txt 883wincmd w 884lhelpgrep quickfix 885call assert_equal ( 1 , winnr ()) 886call assert_notequal ([], getloclist ( 1 )) 887call assert_equal ([], getloclist ( 2 )) 888endif 889 890new |only 891 892" Search for non existing help string 893call assert_fails ( 'Xhelpgrep a1b2c3' , 'E480:' ) 894" Invalid regular expression 895call assert_fails ( 'Xhelpgrep \@<!' , 'E866:' ) 896endfunc 897 898func Test_helpgrep () 899call s: test_xhelpgrep ( 'c' ) 900helpclose 901call s: test_xhelpgrep ( 'l' ) 902endfunc 903 904" When running the :helpgrep command, if an autocmd modifies the 'cpoptions' 905" value, then Vim crashes. (issue fixed by 7.2b-004 and 8.2.4453) 906func Test_helpgrep_restore_cpo_aucmd () 907let save_cpo = & cpo 908augroup QF_Test 909au ! 910autocmd BufNew * set cpo = acd 911augroup END 912 913helpgrep quickfix 914call assert_equal ( 'acd' , & cpo ) 915 %bw ! 916 917set cpo & vim 918augroup QF_Test 919au ! 920autocmd BufReadPost * set cpo = 921augroup END 922 923helpgrep buffer 924call assert_equal ( '' , & cpo ) 925 926augroup QF_Test 927au ! 928augroup END 929 %bw ! 930let & cpo = save_cpo 931endfunc 932 933func Test_errortitle () 934augroup QfBufWinEnter 935au ! 936au BufWinEnter * : let g: a = get ( w:, 'quickfix_title' , 'NONE' ) 937augroup END 938copen 939let a = [{ 'lnum' : 308 , 'bufnr' : bufnr ( '' ), 'col' : 58 , 'valid' : 1 , 'vcol' : 0 , 'nr' : 0 , 'type' : '' , 'pattern' : '' , 'text' : ' au BufWinEnter * :let g:a=get(w:, ''quickfix_title'', ''NONE'')' }] 940call setqflist ( a ) 941call assert_equal ( ':setqflist()' , g: a ) 942augroup QfBufWinEnter 943au ! 944augroup END 945augroup ! QfBufWinEnter 946endfunc 947 948func Test_vimgreptitle () 949augroup QfBufWinEnter 950au ! 951au BufWinEnter * : let g: a = get ( w:, 'quickfix_title' , 'NONE' ) 952augroup END 953try 954vimgrep /pattern/j file 955catch /E480/ 956endtry 957copen 958call assert_equal ( ': vimgrep /pattern/j file' , g: a ) 959augroup QfBufWinEnter 960au ! 961augroup END 962augroup ! QfBufWinEnter 963endfunc 964 965func Test_bufwinenter_once () 966augroup QfBufWinEnter 967au ! 968au BufWinEnter * let g: got_afile ..= 'got ' .. expand ( '<afile>' ) 969augroup END 970let g: got_afile = '' 971copen 972call assert_equal ( 'got quickfix' , g: got_afile ) 973 974cclose 975unlet g: got_afile 976augroup QfBufWinEnter 977au ! 978augroup END 979augroup ! QfBufWinEnter 980endfunc 981 982func XqfTitleTests ( cchar ) 983call s: setup_commands ( a: cchar ) 984 985Xgetexpr ['file:1:1:message'] 986let l = g: Xgetlist () 987if a: cchar == 'c' 988call setqflist ( l , 'r' ) 989else 990call setloclist ( 0 , l , 'r' ) 991endif 992 993Xopen 994if a: cchar == 'c' 995let title = ':setqflist()' 996else 997let title = ':setloclist()' 998endif 999call assert_equal ( title , w: quickfix_title ) 1000Xclose 1001endfunc 1002 1003" Tests for quickfix window's title 1004func Test_qf_title () 1005call XqfTitleTests ( 'c' ) 1006call XqfTitleTests ( 'l' ) 1007endfunc 1008 1009" Tests for 'errorformat' 1010func Test_efm () 1011let save_efm = & efm 1012set efm = %EEEE%m,%WWWW%m,%+CCCC%.%#,%-GGGG%.%# 1013cgetexpr ['WWWW','EEEE' ,'CCCC' ] 1014let l = strtrans ( string ( map ( getqflist (), '[v:val.text, v:val.valid]' ))) 1015call assert_equal ( "[['W', 1], ['E^@CCCC', 1]]" , l ) 1016cgetexpr ['WWWW','GGGG' ,'EEEE' ,'CCCC' ] 1017let l = strtrans ( string ( map ( getqflist (), '[v:val.text, v:val.valid]' ))) 1018call assert_equal ( "[['W', 1], ['E^@CCCC', 1]]" , l ) 1019cgetexpr ['WWWW','GGGG' ,'ZZZZ' ,'EEEE' ,'CCCC' ,'YYYY' ] 1020let l = strtrans ( string ( map ( getqflist (), '[v:val.text, v:val.valid]' ))) 1021call assert_equal ( "[['W', 1], ['ZZZZ', 0], ['E^@CCCC', 1], ['YYYY', 0]]" , l ) 1022let & efm = save_efm 1023endfunc 1024 1025" This will test for problems in quickfix: 1026" A. incorrectly copying location lists which caused the location list to show 1027" a different name than the file that was actually being displayed. 1028" B. not reusing the window for which the location list window is opened but 1029" instead creating new windows. 1030" C. make sure that the location list window is not reused instead of the 1031" window it belongs to. 1032" 1033" Set up the test environment: 1034func ReadTestProtocol ( name ) 1035let base = substitute ( a: name , '\v^test://(.*)%(\.[^.]+)?' , '\1' , '' ) 1036let word = substitute ( base , '\v(.*)\..*' , '\1' , '' ) 1037 1038setl modifiable 1039setl noreadonly 1040setl noswapfile 1041setl bufhidden = delete 1042 %del _ 1043" For problem 2: 1044" 'buftype' has to be set to reproduce the constant opening of new windows 1045setl buftype = nofile 1046 1047call setline ( 1 , word ) 1048 1049setl nomodified 1050setl nomodifiable 1051setl readonly 1052exe 'doautocmd BufRead ' . substitute ( a: name , '\v^test://(.*)' , '\1' , '' ) 1053endfunc 1054 1055func Test_locationlist () 1056enew 1057 1058augroup testgroup 1059au ! 1060autocmd BufReadCmd test:// * call ReadTestProtocol ( expand ( "<amatch>" )) 1061augroup END 1062 1063let words = [ "foo" , "bar" , "baz" , "quux" , "shmoo" , "spam" , "eggs" ] 1064 1065let qflist = [] 1066for word in words 1067call add ( qflist , { 'filename' : 'test://' . word . '.txt' , 'text' : 'file ' . word . '.txt' , }) 1068" NOTE: problem 1: 1069" intentionally not setting 'lnum' so that the quickfix entries are not 1070" valid 1071eval qflist ->setloclist ( 0 , ' ' ) 1072endfor 1073 1074" Test A 1075lrewind 1076enew 1077lopen 10784 lnext 1079vert split 1080wincmd L 1081lopen 1082wincmd p 1083lnext 1084let fileName = expand ( "%" ) 1085wincmd p 1086let locationListFileName = substitute ( getline ( line ( '.' )), '\([^|]*\)|.*' , '\1' , '' ) 1087let fileName = substitute ( fileName , '\\' , '/' , 'g' ) 1088let locationListFileName = substitute ( locationListFileName , '\\' , '/' , 'g' ) 1089call assert_equal ( "test://bar.txt" , fileName ) 1090call assert_equal ( "test://bar.txt" , locationListFileName ) 1091 1092wincmd n |only 1093 1094" Test B: 1095lrewind 1096lopen 10972 1098exe "normal \<CR>" 1099wincmd p 11003 1101exe "normal \<CR>" 1102wincmd p 11034 1104exe "normal \<CR>" 1105call assert_equal ( 2 , winnr ( '$' )) 1106wincmd n |only 1107 1108" Test C: 1109lrewind 1110lopen 1111" Let's move the location list window to the top to check whether it (the 1112" first window found) will be reused when we try to open new windows: 1113wincmd K 11142 1115exe "normal \<CR>" 1116wincmd p 11173 1118exe "normal \<CR>" 1119wincmd p 11204 1121exe "normal \<CR>" 11221 wincmd w 1123call assert_equal ( 'quickfix' , & buftype ) 11242 wincmd w 1125let bufferName = expand ( "%" ) 1126let bufferName = substitute ( bufferName , '\\' , '/' , 'g' ) 1127call assert_equal ( 'test://quux.txt' , bufferName ) 1128 1129wincmd n |only 1130 1131augroup ! testgroup 1132endfunc 1133 1134func Test_locationlist_curwin_was_closed () 1135augroup testgroup 1136au ! 1137autocmd BufReadCmd test_curwin.txt call R ( expand ( "<amatch>" )) 1138augroup END 1139 1140func ! R ( n ) 1141quit 1142endfunc 1143 1144new 1145let q = [] 1146call add ( q , { 'filename' : 'test_curwin.txt' }) 1147call setloclist ( 0 , q ) 1148call assert_fails ( 'lrewind' , 'E924:' ) 1149 1150augroup ! testgroup 1151delfunc R 1152endfunc 1153 1154func Test_locationlist_cross_tab_jump () 1155call writefile ([ 'loclistfoo' ], 'loclistfoo' ) 1156call writefile ([ 'loclistbar' ], 'loclistbar' ) 1157set switchbuf = usetab 1158 1159edit loclistfoo 1160tabedit loclistbar 1161silent lgrep loclistfoo loclist* 1162call assert_equal ( 1 , tabpagenr ()) 1163 1164enew |only |tabonly 1165set switchbuf & vim 1166call delete ( 'loclistfoo' ) 1167call delete ( 'loclistbar' ) 1168endfunc 1169 1170" More tests for 'errorformat' 1171func Test_efm1 () 1172" The 'errorformat' setting is different on non-Unix systems. 1173" This test works only on Unix-like systems. 1174CheckUnix 1175 1176let l =<< trim [DATA] 1177"Xtestfile", line 4.12: 1506-045 (S) Undeclared identifier fd_set. 1178"Xtestfile", line 6 col 19; this is an error 1179gcc -c -DHAVE_CONFIsing-prototypes -I/usr/X11R6/include version.c 1180Xtestfile:9: parse error before `asd' 1181make: *** [src/vim/testdir/Makefile:100: test_quickfix] Error 1 1182in file "Xtestfile" linenr 10: there is an error 1183 11842 returned 1185"Xtestfile", line 11 col 1; this is an error 1186"Xtestfile", line 12 col 2; this is another error 1187"Xtestfile", line 14:10; this is an error in column 10 1188=Xtestfile=, line 15:10; this is another error, but in vcol 10 this time 1189"Xtestfile", linenr 16: yet another problem 1190Error in "Xtestfile" at line 17: 1191x should be a dot 1192xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 17 1193^ 1194Error in "Xtestfile" at line 18: 1195x should be a dot 1196xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 18 1197.............^ 1198Error in "Xtestfile" at line 19: 1199x should be a dot 1200xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 19 1201--------------^ 1202Error in "Xtestfile" at line 20: 1203x should be a dot 1204xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 20 1205^ 1206 1207Does anyone know what is the problem and how to correction it? 1208"Xtestfile", line 21 col 9: What is the title of the quickfix window? 1209"Xtestfile", line 22 col 9: What is the title of the quickfix window? 1210[DATA] 1211 1212call writefile ( l , 'Xerrorfile1' ) 1213call writefile ( l [: -2 ], 'Xerrorfile2' ) 1214 1215let m =<< [DATA] 1216xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 2 1217xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 3 1218xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 4 1219xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 5 1220xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 6 1221xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 7 1222xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 8 1223xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 9 1224xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 10 1225xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 11 1226xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 12 1227xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 13 1228xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 14 1229xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 15 1230xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 16 1231xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 17 1232xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 18 1233xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 19 1234xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 20 1235xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 21 1236xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 22 1237[DATA] 1238call writefile ( m , 'Xtestfile' ) 1239 1240let save_efm = & efm 1241set efm += =%f=\\,\ line\ %l%*\\D%v%*[^\ ]\ %m 1242set efm ^=%AError\ in\ \"%f\"\ at\ line\ %l:,%Z%p^,%C%m 1243 1244exe 'cf Xerrorfile2' 1245clast 1246copen 1247call assert_equal ( ':cf Xerrorfile2' , w: quickfix_title ) 1248wincmd p 1249 1250exe 'cf Xerrorfile1' 1251call assert_equal ([ 4 , 12 ], [ line ( '.' ), col ( '.' )]) 1252cn 1253call assert_equal ([ 6 , 19 ], [ line ( '.' ), col ( '.' )]) 1254cn 1255call assert_equal ([ 9 , 2 ], [ line ( '.' ), col ( '.' )]) 1256cn 1257call assert_equal ([ 10 , 2 ], [ line ( '.' ), col ( '.' )]) 1258cn 1259call assert_equal ([ 11 , 1 ], [ line ( '.' ), col ( '.' )]) 1260cn 1261call assert_equal ([ 12 , 2 ], [ line ( '.' ), col ( '.' )]) 1262cn 1263call assert_equal ([ 14 , 10 ], [ line ( '.' ), col ( '.' )]) 1264cn 1265call assert_equal ([ 15 , 3 , 10 ], [ line ( '.' ), col ( '.' ), virtcol ( '.' )]) 1266cn 1267call assert_equal ([ 16 , 2 ], [ line ( '.' ), col ( '.' )]) 1268cn 1269call assert_equal ([ 17 , 6 ], [ line ( '.' ), col ( '.' )]) 1270cn 1271call assert_equal ([ 18 , 7 ], [ line ( '.' ), col ( '.' )]) 1272cn 1273call assert_equal ([ 19 , 8 ], [ line ( '.' ), col ( '.' )]) 1274cn 1275call assert_equal ([ 20 , 9 ], [ line ( '.' ), col ( '.' )]) 1276clast 1277cprev 1278cprev 1279wincmd w 1280call assert_equal ( ':cf Xerrorfile1' , w: quickfix_title ) 1281wincmd p 1282 1283let & efm = save_efm 1284call delete ( 'Xerrorfile1' ) 1285call delete ( 'Xerrorfile2' ) 1286call delete ( 'Xtestfile' ) 1287endfunc 1288 1289" Test for quickfix directory stack support 1290func s: dir_stack_tests ( cchar ) 1291call s: setup_commands ( a: cchar ) 1292 1293let save_efm =& efm 1294set efm = %DEntering\ dir\ '%f',%f:%l:%m,%XLeaving\ dir\ '%f' 1295 1296let lines =<< trim END 1297Entering dir 'dir1/a' 1298habits2.txt:1:Nine Healthy Habits 1299Entering dir 'b' 1300habits3.txt:2:0 Hours of television 1301habits2.txt:7:5 Small meals 1302Entering dir 'dir1/c' 1303habits4.txt:3:1 Hour of exercise 1304Leaving dir 'dir1/c' 1305Leaving dir 'dir1/a' 1306habits1.txt:4:2 Liters of water 1307Entering dir 'dir2' 1308habits5.txt:5:3 Cups of hot green tea 1309Leaving dir 'dir2' 1310END 1311 1312Xexpr "" 1313for l in lines 1314Xaddexpr l 1315endfor 1316 1317let qf = g: Xgetlist () 1318 1319call assert_equal ( 'dir1/a/habits2.txt' , bufname ( qf [ 1 ]. bufnr )) 1320call assert_equal ( 1 , qf [ 1 ]. lnum ) 1321call assert_equal ( 'dir1/a/b/habits3.txt' , bufname ( qf [ 3 ]. bufnr )) 1322call assert_equal ( 2 , qf [ 3 ]. lnum ) 1323call assert_equal ( 'dir1/a/habits2.txt' , bufname ( qf [ 4 ]. bufnr )) 1324call assert_equal ( 7 , qf [ 4 ]. lnum ) 1325call assert_equal ( 'dir1/c/habits4.txt' , bufname ( qf [ 6 ]. bufnr )) 1326call assert_equal ( 3 , qf [ 6 ]. lnum ) 1327call assert_equal ( 'habits1.txt' , bufname ( qf [ 9 ]. bufnr )) 1328call assert_equal ( 4 , qf [ 9 ]. lnum ) 1329call assert_equal ( 'dir2/habits5.txt' , bufname ( qf [ 11 ]. bufnr )) 1330call assert_equal ( 5 , qf [ 11 ]. lnum ) 1331 1332let & efm = save_efm 1333endfunc 1334 1335" Tests for %D and %X errorformat options 1336func Test_efm_dirstack () 1337" Create the directory stack and files 1338call mkdir ( 'dir1' ) 1339call mkdir ( 'dir1/a' ) 1340call mkdir ( 'dir1/a/b' ) 1341call mkdir ( 'dir1/c' ) 1342call mkdir ( 'dir2' ) 1343 1344let lines =<< trim END 1345Nine Healthy Habits 13460 Hours of television 13471 Hour of exercise 13482 Liters of water 13493 Cups of hot green tea 13504 Short mental breaks 13515 Small meals 13526 AM wake up time 13537 Minutes of laughter 13548 Hours of sleep (at least) 13559 PM end of the day and off to bed 1356END 1357call writefile ( lines , 'habits1.txt' ) 1358call writefile ( lines , 'dir1/a/habits2.txt' ) 1359call writefile ( lines , 'dir1/a/b/habits3.txt' ) 1360call writefile ( lines , 'dir1/c/habits4.txt' ) 1361call writefile ( lines , 'dir2/habits5.txt' ) 1362 1363call s: dir_stack_tests ( 'c' ) 1364call s: dir_stack_tests ( 'l' ) 1365 1366call delete ( 'dir1' , 'rf' ) 1367call delete ( 'dir2' , 'rf' ) 1368call delete ( 'habits1.txt' ) 1369endfunc 1370 1371" Test for resync after continuing an ignored message 1372func Xefm_ignore_continuations ( cchar ) 1373call s: setup_commands ( a: cchar ) 1374 1375let save_efm = & efm 1376 1377let & efm = 1378 \'%Eerror %m %l,' . 1379 \'%-Wignored %m %l,' . 1380 \'%+Cmore ignored %m %l,' . 1381 \'%Zignored end' 1382let lines =<< trim END 1383ignored warning 1 1384more ignored continuation 2 1385ignored end 1386error resync 4 1387END 1388Xgetexpr lines 1389let l = map ( g: Xgetlist (), '[v:val.text, v:val.valid, v:val.lnum, v:val.type]' ) 1390call assert_equal ([[ 'resync' , 1 , 4 , 'E' ]], l ) 1391 1392let & efm = save_efm 1393endfunc 1394 1395func Test_efm_ignore_continuations () 1396call Xefm_ignore_continuations ( 'c' ) 1397call Xefm_ignore_continuations ( 'l' ) 1398endfunc 1399 1400" Tests for invalid error format specifies 1401func Xinvalid_efm_Tests ( cchar ) 1402call s: setup_commands ( a: cchar ) 1403 1404let save_efm = & efm 1405 1406set efm = %f:%l:%m,%f:%f:%l:%m 1407call assert_fails ( 'Xexpr "abc.txt:1:Hello world"' , 'E372:' ) 1408 1409set efm = %f:%l:%m,%f:%l:%r:%m 1410call assert_fails ( 'Xexpr "abc.txt:1:Hello world"' , 'E373:' ) 1411 1412set efm = %f:%l:%m,%O:%f:%l:%m 1413call assert_fails ( 'Xexpr "abc.txt:1:Hello world"' , 'E373:' ) 1414 1415set efm = %f:%l:%m,%f:%l:%*[^a-z 1416call assert_fails ( 'Xexpr "abc.txt:1:Hello world"' , 'E374:' ) 1417 1418set efm = %f:%l:%m,%f:%l:%*c 1419call assert_fails ( 'Xexpr "abc.txt:1:Hello world"' , 'E375:' ) 1420 1421set efm = %f:%l:%m,%L%M%N 1422call assert_fails ( 'Xexpr "abc.txt:1:Hello world"' , 'E376:' ) 1423 1424set efm = %f:%l:%m,%f:%l:%m:%R 1425call assert_fails ( 'Xexpr "abc.txt:1:Hello world"' , 'E377:' ) 1426 1427" Invalid regular expression 1428set efm = %\\%%k 1429call assert_fails ( 'Xexpr "abc.txt:1:Hello world"' , 'E867:' ) 1430 1431set efm = 1432call assert_fails ( 'Xexpr "abc.txt:1:Hello world"' , 'E378:' ) 1433 1434" Empty directory name. When there is an error in parsing new entries, make 1435" sure the previous quickfix list is made the current list. 1436set efm & 1437cexpr ["one","two" ] 1438let qf_id = getqflist (#{ id : 0 }). id 1439set efm = %DEntering\ dir\ abc,%f:%l:%m 1440call assert_fails ( 'Xexpr ["Entering dir abc", "abc.txt:1:Hello world"]' , 'E379:' ) 1441call assert_equal ( qf_id , getqflist (#{ id : 0 }). id ) 1442 1443let & efm = save_efm 1444endfunc 1445 1446func Test_invalid_efm () 1447call Xinvalid_efm_Tests ( 'c' ) 1448call Xinvalid_efm_Tests ( 'l' ) 1449endfunc 1450 1451" TODO: 1452" Add tests for the following formats in 'errorformat' 1453" %r %O 1454func Test_efm2 () 1455let save_efm = & efm 1456 1457" Test for %s format in efm 1458set efm = %f:%s 1459cexpr 'Xtestfile:Line search text' 1460let l = getqflist () 1461call assert_equal ( '^\VLine search text\$' , l [ 0 ]. pattern ) 1462call assert_equal ( 0 , l [ 0 ]. lnum ) 1463 1464let l = split ( execute ( 'clist' , '' ), "\n" ) 1465call assert_equal ([ ' 1 Xtestfile:^\VLine search text\$: ' ], l ) 1466 1467" Test for a long line 1468cexpr 'Xtestfile:' . repeat('a', 1026) 1469let l = getqflist () 1470call assert_equal ( '^\V' . repeat ( 'a' , 1019 ) . '\$' , l [ 0 ]. pattern ) 1471 1472" Test for %P, %Q and %t format specifiers 1473let lines =<< trim [DATA] 1474[Xtestfile1] 1475(1,17) error: ';' missing 1476(21,2) warning: variable 'z' not defined 1477(67,3) error: end of file found before string ended 1478-- 1479 1480[Xtestfile2] 1481-- 1482 1483[Xtestfile3] 1484NEW compiler v1.1 1485(2,2) warning: variable 'x' not defined 1486(67,3) warning: 's' already defined 1487-- 1488[DATA] 1489 1490set efm = %+P[%f]%r,(%l\\,%c)%*[\ ]%t%*[^:]:\ %m,%+Q--%r 1491" To exercise the push/pop file functionality in quickfix, the test files 1492" need to be created. 1493call writefile ([ 'Line1' ], 'Xtestfile1' ) 1494call writefile ([ 'Line2' ], 'Xtestfile2' ) 1495call writefile ([ 'Line3' ], 'Xtestfile3' ) 1496cexpr "" 1497for l in lines 1498caddexpr l 1499endfor 1500let l = getqflist () 1501call assert_equal ( 12 , len ( l )) 1502call assert_equal ( 21 , l [ 2 ]. lnum ) 1503call assert_equal ( 2 , l [ 2 ]. col ) 1504call assert_equal ( 'w' , l [ 2 ]. type ) 1505call assert_equal ( 'e' , l [ 3 ]. type ) 1506call delete ( 'Xtestfile1' ) 1507call delete ( 'Xtestfile2' ) 1508call delete ( 'Xtestfile3' ) 1509 1510" Test for %P, %Q with non-existing files 1511cexpr lines 1512let l = getqflist () 1513call assert_equal ( 14 , len ( l )) 1514call assert_equal ( '[Xtestfile1]' , l [ 0 ]. text ) 1515call assert_equal ( '[Xtestfile2]' , l [ 6 ]. text ) 1516call assert_equal ( '[Xtestfile3]' , l [ 9 ]. text ) 1517 1518" Tests for %E, %C and %Z format specifiers 1519let lines =<< trim [DATA] 1520Error 275 1521line 42 1522column 3 1523' ' expected after '--' 1524[DATA] 1525 1526set efm = %EError\ %n,%Cline\ %l,%Ccolumn\ %c,%Z%m 1527cgetexpr lines 1528let l = getqflist () 1529call assert_equal ( 275 , l [ 0 ]. nr ) 1530call assert_equal ( 42 , l [ 0 ]. lnum ) 1531call assert_equal ( 3 , l [ 0 ]. col ) 1532call assert_equal ( 'E' , l [ 0 ]. type ) 1533call assert_equal ( "\n' ' expected after '--'" , l [ 0 ]. text ) 1534 1535" Test for %> 1536let lines =<< trim [DATA] 1537Error in line 147 of foo.c: 1538unknown variable 'i' 1539[DATA] 1540 1541set efm = unknown\ variable\ %m,%E%>Error\ in\ line\ %l\ of\ %f:,%Z%m 1542cgetexpr lines 1543let l = getqflist () 1544call assert_equal ( 147 , l [ 0 ]. lnum ) 1545call assert_equal ( 'E' , l [ 0 ]. type ) 1546call assert_equal ( "\nunknown variable 'i'" , l [ 0 ]. text ) 1547 1548" Test for %A, %C and other formats 1549let lines =<< trim [DATA] 1550============================================================== 1551FAIL: testGetTypeIdCachesResult (dbfacadeTest.DjsDBFacadeTest) 1552-------------------------------------------------------------- 1553Traceback (most recent call last): 1554File "unittests/dbfacadeTest.py", line 89, in testFoo 1555self.assertEquals(34, dtid) 1556File "/usr/lib/python2.2/unittest.py", line 286, in 1557failUnlessEqual 1558raise self.failureException, \\ 1559W:AssertionError: 34 != 33 1560 1561-------------------------------------------------------------- 1562Ran 27 tests in 0.063s 1563[DATA] 1564 1565set efm = %C\ %.%#,%A\ \ File\ \"%f\"\\,\ line\ %l%.%#,%Z%[%^\ ]%\\@=%t:%m 1566cgetexpr lines 1567let l = getqflist () 1568call assert_equal ( 8 , len ( l )) 1569call assert_equal ( 89 , l [ 4 ]. lnum ) 1570call assert_equal ( 1 , l [ 4 ]. valid ) 1571call assert_equal ( 'unittests/dbfacadeTest.py' , bufname ( l [ 4 ]. bufnr )) 1572call assert_equal ( 'W' , l [ 4 ]. type ) 1573 1574" Test for %o 1575set efm = %f(%o):%l\ %m 1576cgetexpr ['Xotestfile(Language.PureScript.Types):20 Error'] 1577call writefile ([ 'Line1' ], 'Xotestfile' ) 1578let l = getqflist () 1579call assert_equal ( 1 , len ( l ), string ( l )) 1580call assert_equal ( 'Language.PureScript.Types' , l [ 0 ]. module ) 1581copen 1582call assert_equal ( 'Language.PureScript.Types|20| Error' , getline ( 1 )) 1583call feedkeys ( "\<CR>" , 'xn' ) 1584call assert_equal ( 'Xotestfile' , expand ( '%:t' )) 1585cclose 1586bd 1587call delete ( "Xotestfile" ) 1588 1589" Test for a long module name 1590cexpr 'Xtest(' . repeat('m', 1026) .'):15 message' 1591let l = getqflist () 1592" call assert_equal(repeat('m', 1024), l[0].module) 1593call assert_equal ( repeat ( 'm' , 1023 ), l [ 0 ]. module ) 1594call assert_equal ( 15 , l [ 0 ]. lnum ) 1595call assert_equal ( 'message' , l [ 0 ]. text ) 1596 1597" The following sequence of commands used to crash Vim 1598set efm = %W%m 1599cgetexpr ['msg1'] 1600let l = getqflist () 1601call assert_equal ( 1 , len ( l ), string ( l )) 1602call assert_equal ( 'msg1' , l [ 0 ]. text ) 1603set efm = %C%m 1604lexpr 'msg2' 1605let l = getloclist ( 0 ) 1606call assert_equal ( 1 , len ( l ), string ( l )) 1607call assert_equal ( 'msg2' , l [ 0 ]. text ) 1608lopen 1609call setqflist ([], 'r' ) 1610caddbuf 1611let l = getqflist () 1612call assert_equal ( 1 , len ( l ), string ( l )) 1613call assert_equal ( '|| msg2' , l [ 0 ]. text ) 1614 1615" When matching error lines, case should be ignored. Test for this. 1616set noignorecase 1617let l = getqflist ({ 'lines' : [ 'Xtest:FOO10:Line 20' ], 'efm' : '%f:foo%l:%m' }) 1618call assert_equal ( 10 , l . items [ 0 ]. lnum ) 1619call assert_equal ( 'Line 20' , l . items [ 0 ]. text ) 1620set ignorecase & 1621 1622new |only 1623let & efm = save_efm 1624endfunc 1625 1626" Test for '%t' (error type) field in 'efm' 1627func Test_efm_error_type () 1628let save_efm = & efm 1629 1630" error type 1631set efm = %f:%l:%t:%m 1632let lines =<< trim END 1633Xfile1:10:E:msg1 1634Xfile1:20:W:msg2 1635Xfile1:30:I:msg3 1636Xfile1:40:N:msg4 1637Xfile1:50:R:msg5 1638END 1639cexpr lines 1640let output = split ( execute ( 'clist' ), "\n" ) 1641call assert_equal ([ 1642 \' 1 Xfile1:10 error: msg1' , 1643 \' 2 Xfile1:20 warning: msg2' , 1644 \' 3 Xfile1:30 info: msg3' , 1645 \' 4 Xfile1:40 note: msg4' , 1646 \' 5 Xfile1:50 R: msg5' ], output ) 1647 1648" error type and a error number 1649set efm = %f:%l:%t:%n:%m 1650let lines =<< trim END 1651Xfile1:10:E:2:msg1 1652Xfile1:20:W:4:msg2 1653Xfile1:30:I:6:msg3 1654Xfile1:40:N:8:msg4 1655Xfile1:50:R:3:msg5 1656END 1657cexpr lines 1658let output = split ( execute ( 'clist' ), "\n" ) 1659call assert_equal ([ 1660 \' 1 Xfile1:10 error 2: msg1' , 1661 \' 2 Xfile1:20 warning 4: msg2' , 1662 \' 3 Xfile1:30 info 6: msg3' , 1663 \' 4 Xfile1:40 note 8: msg4' , 1664 \' 5 Xfile1:50 R 3: msg5' ], output ) 1665let & efm = save_efm 1666endfunc 1667 1668" Test for end_lnum ('%e') and end_col ('%k') fields in 'efm' 1669func Test_efm_end_lnum_col () 1670let save_efm = & efm 1671 1672" single line 1673set efm = %f:%l-%e:%c-%k:%t:%m 1674cexpr ["Xfile1:10-20:1-2:E:msg1","Xfile1:20-30:2-3:W:msg2" ,] 1675let output = split ( execute ( 'clist' ), "\n" ) 1676call assert_equal ([ 1677 \' 1 Xfile1:10-20 col 1-2 error: msg1' , 1678 \' 2 Xfile1:20-30 col 2-3 warning: msg2' ], output ) 1679 1680" multiple lines 1681set efm = %A%n)%m,%Z%f:%l-%e:%c-%k 1682let lines =<< trim END 16831)msg1 1684Xfile1:14-24:1-2 16852)msg2 1686Xfile1:24-34:3-4 1687END 1688cexpr lines 1689let output = split ( execute ( 'clist' ), "\n" ) 1690call assert_equal ([ 1691 \' 1 Xfile1:14-24 col 1-2 error 1: msg1' , 1692 \' 2 Xfile1:24-34 col 3-4 error 2: msg2' ], output ) 1693let & efm = save_efm 1694endfunc 1695 1696func XquickfixChangedByAutocmd ( cchar ) 1697call s: setup_commands ( a: cchar ) 1698if a: cchar == 'c' 1699let ErrorNr = 'E925' 1700func ! ReadFunc () 1701colder 1702cgetexpr [] 1703endfunc 1704else 1705let ErrorNr = 'E926' 1706func ! ReadFunc () 1707lolder 1708lgetexpr [] 1709endfunc 1710endif 1711 1712augroup QF_Test 1713au ! 1714autocmd BufReadCmd test_changed.txt call ReadFunc () 1715augroup END 1716 1717new |only 1718let words = [ "a" , "b" ] 1719let qflist = [] 1720for word in words 1721call add ( qflist , { 'filename' : 'test_changed.txt' }) 1722call g: Xsetlist ( qflist , ' ' ) 1723endfor 1724call assert_fails ( 'Xrewind' , ErrorNr . ':' ) 1725 1726augroup QF_Test 1727au ! 1728augroup END 1729 1730if a: cchar == 'c' 1731cexpr ["Xtest1:1:Line"] 1732cwindow 1733only 1734augroup QF_Test 1735au ! 1736autocmd WinEnter * call setqflist ([], 'f' ) 1737augroup END 1738call assert_fails ( 'exe "normal \<CR>"' , 'E925:' ) 1739augroup QF_Test 1740au ! 1741augroup END 1742endif 1743 %bw ! 1744endfunc 1745 1746func Test_quickfix_was_changed_by_autocmd () 1747call XquickfixChangedByAutocmd ( 'c' ) 1748call XquickfixChangedByAutocmd ( 'l' ) 1749endfunc 1750 1751func Test_setloclist_in_autocommand () 1752call writefile ([ 'test1' , 'test2' ], 'Xfile' ) 1753edit Xfile 1754let s: bufnr = bufnr () 1755call setloclist ( 1 , 1756 \[{ 'bufnr' : s: bufnr , 'lnum' : 1 , 'text' : 'test1' }, 1757 \{ 'bufnr' : s: bufnr , 'lnum' : 2 , 'text' : 'test2' }]) 1758 1759augroup Test_LocList 1760au ! 1761autocmd BufEnter * call setloclist ( 1 , 1762 \[{ 'bufnr' : s: bufnr , 'lnum' : 1 , 'text' : 'test1' }, 1763 \{ 'bufnr' : s: bufnr , 'lnum' : 2 , 'text' : 'test2' }], 'r' ) 1764augroup END 1765 1766lopen 1767call assert_fails ( 'exe "normal j\<CR>"' , 'E926:' ) 1768 1769augroup Test_LocList 1770au ! 1771augroup END 1772call delete ( 'Xfile' ) 1773endfunc 1774 1775func Test_caddbuffer_to_empty () 1776helpgr quickfix 1777call setqflist ([], 'r' ) 1778cad 1779try 1780cn 1781catch 1782" number of matches is unknown 1783call assert_true ( v: exception =~ 'E553:' ) 1784endtry 1785quit ! 1786endfunc 1787 1788func Test_cgetexpr_works () 1789" this must not crash Vim 1790cgetexpr [$x] 1791lgetexpr [$x] 1792endfunc 1793 1794" Tests for the setqflist() and setloclist() functions 1795func SetXlistTests ( cchar , bnum ) 1796call s: setup_commands ( a: cchar ) 1797 1798call g: Xsetlist ([{ 'bufnr' : a: bnum , 'lnum' : 1 }, 1799 \{ 'bufnr' : a: bnum , 'lnum' : 2 , 'end_lnum' : 3 , 'col' : 4 , 'end_col' : 5 , 'user_data' : { '6' : [ 7 , 8 ]}}]) 1800let l = g: Xgetlist () 1801call assert_equal ( 2 , len ( l )) 1802call assert_equal ( 2 , l [ 1 ]. lnum ) 1803call assert_equal ( 3 , l [ 1 ]. end_lnum ) 1804call assert_equal ( 4 , l [ 1 ]. col ) 1805call assert_equal ( 5 , l [ 1 ]. end_col ) 1806call assert_equal ({ '6' : [ 7 , 8 ]}, l [ 1 ]. user_data ) 1807 1808" Test that user_data is garbage collected 1809call g: Xsetlist ([{ 'user_data' : [ 'high' , 5 ]}, 1810 \{ 'user_data' : { 'this' : [ 7 , 'eight' ], 'is' : [ 'a' , 'dictionary' ]}}]) 1811call test_garbagecollect_now () 1812let l = g: Xgetlist () 1813call assert_equal ( 2 , len ( l )) 1814call assert_equal ([ 'high' , 5 ], l [ 0 ]. user_data ) 1815call assert_equal ({ 'this' : [ 7 , 'eight' ], 'is' : [ 'a' , 'dictionary' ]}, l [ 1 ]. user_data ) 1816 1817Xnext 1818call g: Xsetlist ([{ 'bufnr' : a: bnum , 'lnum' : 3 }], 'a' ) 1819let l = g: Xgetlist () 1820call assert_equal ( 3 , len ( l )) 1821Xnext 1822call assert_equal ( 3 , line ( '.' )) 1823 1824" Appending entries to the list should not change the cursor position 1825" in the quickfix window 1826Xwindow 18271 1828call g: Xsetlist ([{ 'bufnr' : a: bnum , 'lnum' : 4 }, 1829 \{ 'bufnr' : a: bnum , 'lnum' : 5 }], 'a' ) 1830call assert_equal ( 1 , line ( '.' )) 1831close 1832 1833call g: Xsetlist ([{ 'bufnr' : a: bnum , 'lnum' : 3 }, 1834 \{ 'bufnr' : a: bnum , 'lnum' : 4 }, 1835 \{ 'bufnr' : a: bnum , 'lnum' : 5 }], 'r' ) 1836let l = g: Xgetlist () 1837call assert_equal ( 3 , len ( l )) 1838call assert_equal ( 5 , l [ 2 ]. lnum ) 1839 1840call g: Xsetlist ([]) 1841let l = g: Xgetlist () 1842call assert_equal ( 0 , len ( l )) 1843 1844" Tests for setting the 'valid' flag 1845call g: Xsetlist ([{ 'bufnr' : a: bnum , 'lnum' : 4 , 'valid' : 0 }]) 1846Xwindow 1847call assert_equal ( 1 , winnr ( '$' )) 1848let l = g: Xgetlist () 1849call g: Xsetlist ( l ) 1850call assert_equal ( 0 , g: Xgetlist ()[ 0 ]. valid ) 1851" Adding a non-valid entry should not mark the list as having valid entries 1852call g: Xsetlist ([{ 'bufnr' : a: bnum , 'lnum' : 5 , 'valid' : 0 }], 'a' ) 1853Xwindow 1854call assert_equal ( 1 , winnr ( '$' )) 1855 1856" :cnext/:cprev should still work even with invalid entries in the list 1857let l = [{ 'bufnr' : a: bnum , 'lnum' : 1 , 'text' : '1' , 'valid' : 0 }, 1858 \{ 'bufnr' : a: bnum , 'lnum' : 2 , 'text' : '2' , 'valid' : 0 }] 1859call g: Xsetlist ( l ) 1860Xnext 1861call assert_equal ( 2 , g: Xgetlist ({ 'idx' : 0 }). idx ) 1862Xprev 1863call assert_equal ( 1 , g: Xgetlist ({ 'idx' : 0 }). idx ) 1864" :cnext/:cprev should still work after appending invalid entries to an 1865" empty list 1866call g: Xsetlist ([]) 1867call g: Xsetlist ( l , 'a' ) 1868Xnext 1869call assert_equal ( 2 , g: Xgetlist ({ 'idx' : 0 }). idx ) 1870Xprev 1871call assert_equal ( 1 , g: Xgetlist ({ 'idx' : 0 }). idx ) 1872 1873call g: Xsetlist ([{ 'text' : 'Text1' , 'valid' : 1 }]) 1874Xwindow 1875call assert_equal ( 2 , winnr ( '$' )) 1876Xclose 1877let save_efm = & efm 1878set efm = %m 1879Xgetexpr 'TestMessage' 1880let l = g: Xgetlist () 1881call g: Xsetlist ( l ) 1882call assert_equal ( 1 , g: Xgetlist ()[ 0 ]. valid ) 1883let & efm = save_efm 1884 1885" Error cases: 1886" Refer to a non-existing buffer and pass a non-dictionary type 1887call assert_fails ( "call g:Xsetlist([{'bufnr':998, 'lnum':4}," . 1888 \" {'bufnr':999, 'lnum':5}])" , 'E92:' ) 1889call g: Xsetlist ([[ 1 , 2 , 3 ]]) 1890call assert_equal ( 0 , len ( g: Xgetlist ())) 1891call assert_fails ( 'call g:Xsetlist([], [])' , 'E928:' ) 1892call g: Xsetlist ([ v: _null_dict ]) 1893call assert_equal ([], g: Xgetlist ()) 1894endfunc 1895 1896func Test_setqflist () 1897new Xtestfile |only 1898let bnum = bufnr ( '%' ) 1899call setline ( 1 , range ( 1 , 5 )) 1900 1901call SetXlistTests ( 'c' , bnum ) 1902call SetXlistTests ( 'l' , bnum ) 1903 1904enew ! 1905call delete ( 'Xtestfile' ) 1906endfunc 1907 1908func Xlist_empty_middle ( cchar ) 1909call s: setup_commands ( a: cchar ) 1910 1911" create three quickfix lists 1912let @/= 'Test_' 1913Xvimgrep // test_quickfix.vim 1914let testlen = len ( g: Xgetlist ()) 1915call assert_true ( testlen > 0 ) 1916Xvimgrep empty test_quickfix.vim 1917call assert_true ( len ( g: Xgetlist ()) > 0 ) 1918Xvimgrep matches test_quickfix.vim 1919let matchlen = len ( g: Xgetlist ()) 1920call assert_true ( matchlen > 0 ) 1921Xolder 1922" make the middle list empty 1923call g: Xsetlist ([], 'r' ) 1924call assert_true ( len ( g: Xgetlist ()) == 0 ) 1925Xolder 1926call assert_equal ( testlen , len ( g: Xgetlist ())) 1927Xnewer 1928Xnewer 1929call assert_equal ( matchlen , len ( g: Xgetlist ())) 1930endfunc 1931 1932func Test_setqflist_empty_middle () 1933call Xlist_empty_middle ( 'c' ) 1934call Xlist_empty_middle ( 'l' ) 1935endfunc 1936 1937func Xlist_empty_older ( cchar ) 1938call s: setup_commands ( a: cchar ) 1939 1940" create three quickfix lists 1941Xvimgrep one test_quickfix.vim 1942let onelen = len ( g: Xgetlist ()) 1943call assert_true ( onelen > 0 ) 1944Xvimgrep two test_quickfix.vim 1945let twolen = len ( g: Xgetlist ()) 1946call assert_true ( twolen > 0 ) 1947Xvimgrep three test_quickfix.vim 1948let threelen = len ( g: Xgetlist ()) 1949call assert_true ( threelen > 0 ) 1950Xolder 2 1951" make the first list empty, check the others didn't change 1952call g: Xsetlist ([], 'r' ) 1953call assert_true ( len ( g: Xgetlist ()) == 0 ) 1954Xnewer 1955call assert_equal ( twolen , len ( g: Xgetlist ())) 1956Xnewer 1957call assert_equal ( threelen , len ( g: Xgetlist ())) 1958endfunc 1959 1960func Test_setqflist_empty_older () 1961call Xlist_empty_older ( 'c' ) 1962call Xlist_empty_older ( 'l' ) 1963endfunc 1964 1965func XquickfixSetListWithAct ( cchar ) 1966call s: setup_commands ( a: cchar ) 1967 1968let list1 = [{ 'filename' : 'fnameA' , 'text' : 'A' }, 1969 \{ 'filename' : 'fnameB' , 'text' : 'B' }] 1970let list2 = [{ 'filename' : 'fnameC' , 'text' : 'C' }, 1971 \{ 'filename' : 'fnameD' , 'text' : 'D' }, 1972 \{ 'filename' : 'fnameE' , 'text' : 'E' }] 1973 1974" {action} is unspecified. Same as specifying ' '. 1975new |only 1976silent ! Xnewer 99 1977call g: Xsetlist ( list1 ) 1978call g: Xsetlist ( list2 ) 1979let li = g: Xgetlist () 1980call assert_equal ( 3 , len ( li )) 1981call assert_equal ( 'C' , li [ 0 ][ 'text' ]) 1982call assert_equal ( 'D' , li [ 1 ][ 'text' ]) 1983call assert_equal ( 'E' , li [ 2 ][ 'text' ]) 1984silent ! Xolder 1985let li = g: Xgetlist () 1986call assert_equal ( 2 , len ( li )) 1987call assert_equal ( 'A' , li [ 0 ][ 'text' ]) 1988call assert_equal ( 'B' , li [ 1 ][ 'text' ]) 1989 1990" {action} is specified ' '. 1991new |only 1992silent ! Xnewer 99 1993call g: Xsetlist ( list1 ) 1994call g: Xsetlist ( list2 , ' ' ) 1995let li = g: Xgetlist () 1996call assert_equal ( 3 , len ( li )) 1997call assert_equal ( 'C' , li [ 0 ][ 'text' ]) 1998call assert_equal ( 'D' , li [ 1 ][ 'text' ]) 1999call assert_equal ( 'E' , li [ 2 ][ 'text' ]) 2000silent ! Xolder 2001let li = g: Xgetlist () 2002call assert_equal ( 2 , len ( li )) 2003call assert_equal ( 'A' , li [ 0 ][ 'text' ]) 2004call assert_equal ( 'B' , li [ 1 ][ 'text' ]) 2005 2006" {action} is specified 'a'. 2007new |only 2008silent ! Xnewer 99 2009call g: Xsetlist ( list1 ) 2010call g: Xsetlist ( list2 , 'a' ) 2011let li = g: Xgetlist () 2012call assert_equal ( 5 , len ( li )) 2013call assert_equal ( 'A' , li [ 0 ][ 'text' ]) 2014call assert_equal ( 'B' , li [ 1 ][ 'text' ]) 2015call assert_equal ( 'C' , li [ 2 ][ 'text' ]) 2016call assert_equal ( 'D' , li [ 3 ][ 'text' ]) 2017call assert_equal ( 'E' , li [ 4 ][ 'text' ]) 2018 2019" {action} is specified 'r'. 2020new |only 2021silent ! Xnewer 99 2022call g: Xsetlist ( list1 ) 2023call g: Xsetlist ( list2 , 'r' ) 2024let li = g: Xgetlist () 2025call assert_equal ( 3 , len ( li )) 2026call assert_equal ( 'C' , li [ 0 ][ 'text' ]) 2027call assert_equal ( 'D' , li [ 1 ][ 'text' ]) 2028call assert_equal ( 'E' , li [ 2 ][ 'text' ]) 2029 2030" Test for wrong value. 2031new |only 2032call assert_fails ( "call g:Xsetlist(0)" , 'E714:' ) 2033call assert_fails ( "call g:Xsetlist(list1, '')" , 'E927:' ) 2034call assert_fails ( "call g:Xsetlist(list1, 'aa')" , 'E927:' ) 2035call assert_fails ( "call g:Xsetlist(list1, ' a')" , 'E927:' ) 2036call assert_fails ( "call g:Xsetlist(list1, 0)" , 'E928:' ) 2037endfunc 2038 2039func Test_setqflist_invalid_nr () 2040" The following command used to crash Vim 2041eval [] ->setqflist ( ' ' , { 'nr' : $ XXX_DOES_NOT_EXIST }) 2042endfunc 2043 2044func Test_setqflist_user_sets_buftype () 2045call setqflist ([{ 'text' : 'foo' }, { 'text' : 'bar' }]) 2046set buftype = quickfix 2047call setqflist ([], 'a' ) 2048enew 2049endfunc 2050 2051func Test_quickfix_set_list_with_act () 2052call XquickfixSetListWithAct ( 'c' ) 2053call XquickfixSetListWithAct ( 'l' ) 2054endfunc 2055 2056func XLongLinesTests ( cchar ) 2057let l = g: Xgetlist () 2058 2059call assert_equal ( 4 , len ( l )) 2060call assert_equal ( 1 , l [ 0 ]. lnum ) 2061call assert_equal ( 1 , l [ 0 ]. col ) 2062call assert_equal ( 1975 , len ( l [ 0 ]. text )) 2063call assert_equal ( 2 , l [ 1 ]. lnum ) 2064call assert_equal ( 1 , l [ 1 ]. col ) 2065call assert_equal ( 4070 , len ( l [ 1 ]. text )) 2066call assert_equal ( 3 , l [ 2 ]. lnum ) 2067call assert_equal ( 1 , l [ 2 ]. col ) 2068call assert_equal ( 4070 , len ( l [ 2 ]. text )) 2069call assert_equal ( 4 , l [ 3 ]. lnum ) 2070call assert_equal ( 1 , l [ 3 ]. col ) 2071call assert_equal ( 10 , len ( l [ 3 ]. text )) 2072 2073call g: Xsetlist ([], 'r' ) 2074endfunc 2075 2076func s: long_lines_tests ( cchar ) 2077call s: setup_commands ( a: cchar ) 2078 2079let testfile = 'samples/quickfix.txt' 2080 2081" file 2082exe 'Xgetfile' testfile 2083call XLongLinesTests ( a: cchar ) 2084 2085" list 2086Xexpr readfile(testfile) 2087call XLongLinesTests ( a: cchar ) 2088 2089" string 2090Xexpr join(readfile(testfile),"\n" ) 2091call XLongLinesTests ( a: cchar ) 2092 2093" buffer 2094exe 'edit' testfile 2095exe 'Xbuffer' bufnr ( '%' ) 2096call XLongLinesTests ( a: cchar ) 2097endfunc 2098 2099func Test_long_lines () 2100call s: long_lines_tests ( 'c' ) 2101call s: long_lines_tests ( 'l' ) 2102endfunc 2103 2104func Test_cgetfile_on_long_lines () 2105" Problematic values if the line is longer than 4096 bytes. Then 1024 bytes 2106" are read at a time. 2107for len in [ 4078 , 4079 , 4080 , 5102 , 5103 , 5104 , 6126 , 6127 , 6128 , 7150 , 7151 , 7152 ] 2108let lines =<< trim END 2109/tmp/file1:1:1:aaa 2110/tmp/file2:1:1:%s 2111/tmp/file3:1:1:bbb 2112/tmp/file4:1:1:ccc 2113END 2114let lines [ 1 ] = substitute ( lines [ 1 ], '%s' , repeat ( 'x' , len ), '' ) 2115call writefile ( lines , 'Xcqetfile.txt' ) 2116cgetfile Xcqetfile.txt 2117call assert_equal ( 4 , getqflist (#{ size : v: true }). size , 'with length ' .. len ) 2118endfor 2119call delete ( 'Xcqetfile.txt' ) 2120endfunc 2121 2122func s: create_test_file ( filename ) 2123let l = [] 2124for i in range ( 1 , 20 ) 2125call add ( l , 'Line' . i ) 2126endfor 2127call writefile ( l , a: filename ) 2128endfunc 2129 2130func Test_switchbuf () 2131call s: create_test_file ( 'Xqftestfile1' ) 2132call s: create_test_file ( 'Xqftestfile2' ) 2133call s: create_test_file ( 'Xqftestfile3' ) 2134 2135new |only 2136edit Xqftestfile1 2137let file1_winid = win_getid () 2138new Xqftestfile2 2139let file2_winid = win_getid () 2140let lines =<< trim END 2141Xqftestfile1:5:Line5 2142Xqftestfile1:6:Line6 2143Xqftestfile2:10:Line10 2144Xqftestfile2:11:Line11 2145Xqftestfile3:15:Line15 2146Xqftestfile3:16:Line16 2147END 2148cgetexpr lines 2149 2150new 2151let winid = win_getid () 2152cfirst |cnext 2153call assert_equal ( winid , win_getid ()) 21542 cnext 2155call assert_equal ( winid , win_getid ()) 21562 cnext 2157call assert_equal ( winid , win_getid ()) 2158 2159" Test for 'switchbuf' set to search for files in windows in the current 2160" tabpage and jump to an existing window (if present) 2161set switchbuf = useopen 2162enew 2163cfirst |cnext 2164call assert_equal ( file1_winid , win_getid ()) 21652 cnext 2166call assert_equal ( file2_winid , win_getid ()) 21672 cnext 2168call assert_equal ( file2_winid , win_getid ()) 2169 2170" Test for 'switchbuf' set to search for files in tabpages and jump to an 2171" existing tabpage (if present) 2172enew |only 2173set switchbuf = usetab 2174tabedit Xqftestfile1 2175tabedit Xqftestfile2 2176tabedit Xqftestfile3 2177tabfirst 2178cfirst |cnext 2179call assert_equal ( 2 , tabpagenr ()) 21802 cnext 2181call assert_equal ( 3 , tabpagenr ()) 21826 cnext 2183call assert_equal ( 4 , tabpagenr ()) 21842 cpfile 2185call assert_equal ( 2 , tabpagenr ()) 21862 cnfile 2187call assert_equal ( 4 , tabpagenr ()) 2188tabfirst |tabonly |enew 2189 2190" Test for 'switchbuf' set to open a new window for every file 2191set switchbuf = split 2192cfirst |cnext 2193call assert_equal ( 1 , winnr ( '$' )) 2194cnext |cnext 2195call assert_equal ( 2 , winnr ( '$' )) 2196cnext |cnext 2197call assert_equal ( 3 , winnr ( '$' )) 2198 2199" Test for 'switchbuf' set to open a new tabpage for every file 2200set switchbuf = newtab 2201enew |only 2202cfirst |cnext 2203call assert_equal ( 1 , tabpagenr ( '$' )) 2204cnext |cnext 2205call assert_equal ( 2 , tabpagenr ( '$' )) 2206cnext |cnext 2207call assert_equal ( 3 , tabpagenr ( '$' )) 2208tabfirst |enew |tabonly |only 2209 2210set switchbuf = uselast 2211split 2212let last_winid = win_getid () 2213copen 2214exe "normal 1G\<CR>" 2215call assert_equal ( last_winid , win_getid ()) 2216enew |only 2217 2218" With an empty 'switchbuf', jumping to a quickfix entry should open the 2219" file in an existing window (if present) 2220set switchbuf = 2221edit Xqftestfile1 2222let file1_winid = win_getid () 2223new Xqftestfile2 2224let file2_winid = win_getid () 2225copen 2226exe "normal 1G\<CR>" 2227call assert_equal ( file1_winid , win_getid ()) 2228copen 2229exe "normal 3G\<CR>" 2230call assert_equal ( file2_winid , win_getid ()) 2231copen |only 2232exe "normal 5G\<CR>" 2233call assert_equal ( 2 , winnr ( '$' )) 2234call assert_equal ( 1 , bufwinnr ( 'Xqftestfile3' )) 2235 2236" If only quickfix window is open in the current tabpage, jumping to an 2237" entry with 'switchbuf' set to 'usetab' should search in other tabpages. 2238enew |only 2239set switchbuf = usetab 2240tabedit Xqftestfile1 2241tabedit Xqftestfile2 2242tabedit Xqftestfile3 2243tabfirst 2244copen |only 2245clast 2246call assert_equal ( 4 , tabpagenr ()) 2247tabfirst |tabonly |enew |only 2248 2249" Jumping to a file that is not present in any of the tabpages and the 2250" current tabpage doesn't have any usable windows, should open it in a new 2251" window in the current tabpage. 2252copen |only 2253cfirst 2254call assert_equal ( 1 , tabpagenr ()) 2255call assert_equal ( 'Xqftestfile1' , @%) 2256 2257" If opening a file changes 'switchbuf', then the new value should be 2258" retained. 2259set modeline & vim 2260call writefile ([ "vim: switchbuf=split" ], 'Xqftestfile1' ) 2261enew |only 2262set switchbuf & vim 2263cexpr "Xqftestfile1:1:10" 2264call assert_equal ( 'split' , & switchbuf ) 2265call writefile ([ "vim: switchbuf=usetab" ], 'Xqftestfile1' ) 2266enew |only 2267set switchbuf = useopen 2268cexpr "Xqftestfile1:1:10" 2269call assert_equal ( 'usetab' , & switchbuf ) 2270call writefile ([ "vim: switchbuf&vim" ], 'Xqftestfile1' ) 2271enew |only 2272set switchbuf = useopen 2273cexpr "Xqftestfile1:1:10" 2274call assert_equal ( 'uselast' , & switchbuf ) 2275 2276call delete ( 'Xqftestfile1' ) 2277call delete ( 'Xqftestfile2' ) 2278call delete ( 'Xqftestfile3' ) 2279set switchbuf & vim 2280 2281enew |only 2282endfunc 2283 2284func Xadjust_qflnum ( cchar ) 2285call s: setup_commands ( a: cchar ) 2286 2287enew |only 2288 2289let fname = 'Xqftestfile' . a: cchar 2290call s: create_test_file ( fname ) 2291exe 'edit ' . fname 2292 2293Xgetexpr [fname .':5:Line5' , 2294 \ fname .':10:Line10' , 2295 \ fname .':15:Line15' , 2296 \ fname .':20:Line20' ] 2297 22986 , 14 delete 2299call append ( 6 , [ 'Buffer' , 'Window' ]) 2300 2301let l = g: Xgetlist () 2302call assert_equal ( 5 , l [ 0 ]. lnum ) 2303call assert_equal ( 6 , l [ 2 ]. lnum ) 2304call assert_equal ( 13 , l [ 3 ]. lnum ) 2305 2306" If a file doesn't have any quickfix entries, then deleting lines in the 2307" file should not update the quickfix list 2308call g: Xsetlist ([], 'f' ) 23091 , 2 delete 2310call assert_equal ([], g: Xgetlist ()) 2311 2312enew ! 2313call delete ( fname ) 2314endfunc 2315 2316func Test_adjust_lnum () 2317call setloclist ( 0 , []) 2318call Xadjust_qflnum ( 'c' ) 2319call setqflist ([]) 2320call Xadjust_qflnum ( 'l' ) 2321endfunc 2322 2323func Xqf_undo_after_delete ( cchar ) 2324call s: setup_commands ( a: cchar ) 2325 2326enew |only 2327 2328let fname = 'Xqfundofile' . a: cchar 2329call s: create_test_file ( fname ) 2330exe 'edit ' . fname 2331 2332Xgetexpr [fname .':5:Line5' , 2333 \ fname .':10:Line10' , 2334 \ fname .':15:Line15' ] 2335 2336" Delete the line of the second error and undo the deletion. 233710 delete 2338let l = g: Xgetlist () 2339call assert_equal ( 5 , l [ 0 ]. lnum ) 2340call assert_equal ( 10 , l [ 1 ]. lnum ) 2341call assert_equal ( 14 , l [ 2 ]. lnum ) 2342 2343undo 2344call assert_equal ( 'Line10' , getline ( 10 )) 2345let l = g: Xgetlist () 2346call assert_equal ( 5 , l [ 0 ]. lnum ) 2347call assert_equal ( 10 , l [ 1 ]. lnum ) 2348call assert_equal ( 15 , l [ 2 ]. lnum ) 2349 2350" Redo and undo again to make sure the line number does not drift. 2351redo 2352call assert_equal ( 14 , g: Xgetlist ()[ 2 ]. lnum ) 2353undo 2354let l = g: Xgetlist () 2355call assert_equal ( 10 , l [ 1 ]. lnum ) 2356call assert_equal ( 15 , l [ 2 ]. lnum ) 2357 2358call g: Xsetlist ([], 'f' ) 2359enew ! 2360call delete ( fname ) 2361endfunc 2362 2363func Test_qf_undo_after_delete () 2364call setloclist ( 0 , []) 2365call Xqf_undo_after_delete ( 'c' ) 2366call setqflist ([]) 2367call Xqf_undo_after_delete ( 'l' ) 2368endfunc 2369 2370" Tests for the :grep/:lgrep and :grepadd/:lgrepadd commands 2371func s: test_xgrep ( cchar ) 2372call s: setup_commands ( a: cchar ) 2373 2374" The following lines are used for the grep test. Don't remove. 2375" Grep_Test_Text: Match 1 2376" Grep_Test_Text: Match 2 2377" GrepAdd_Test_Text: Match 1 2378" GrepAdd_Test_Text: Match 2 2379enew ! |only 2380set makeef & vim 2381silent Xgrep Grep_Test_Text: test_quickfix.vim 2382call assert_true ( len ( g: Xgetlist ()) == 5 ) 2383Xopen 2384call assert_true ( w: quickfix_title =~ '^:grep' ) 2385Xclose 2386enew 2387set makeef = Temp_File_## 2388silent Xgrepadd GrepAdd_Test_Text: test_quickfix.vim 2389call assert_true ( len ( g: Xgetlist ()) == 9 ) 2390 2391" Try with 'grepprg' set to 'internal' 2392set grepprg = internal 2393silent Xgrep Grep_Test_Text: test_quickfix.vim 2394silent Xgrepadd GrepAdd_Test_Text: test_quickfix.vim 2395call assert_true ( len ( g: Xgetlist ()) == 9 ) 2396set grepprg & vim 2397 2398call writefile ([ 'Vim' ], 'XtestTempFile' ) 2399set makeef = XtestTempFile 2400silent Xgrep Grep_Test_Text: test_quickfix.vim 2401call assert_equal ( 5 , len ( g: Xgetlist ())) 2402call assert_false ( filereadable ( 'XtestTempFile' )) 2403set makeef & vim 2404endfunc 2405 2406func Test_grep () 2407" The grepprg may not be set on non-Unix systems 2408CheckUnix 2409 2410call s: test_xgrep ( 'c' ) 2411call s: test_xgrep ( 'l' ) 2412endfunc 2413 2414func Test_local_grepformat () 2415let save_grepformat = & grepformat 2416set grepformat = %f:%l:%m 2417" The following line are used for the local grep test. Don't remove. 2418" UNIQUEPREFIX:2:3: Local grepformat test 2419new 2420setlocal grepformat = UNIQUEPREFIX:%c:%n:%m 2421call assert_equal ( 'UNIQUEPREFIX:%c:%n:%m' , & l: grepformat ) 2422call assert_equal ( '%f:%l:%m' , & g: grepformat ) 2423 2424set grepprg = internal 2425silent grep "^[[:space:]]*\" UNIQUEPREFIX:" test_quickfix.vim 2426call assert_equal ( 1 , len ( getqflist ())) 2427set grepprg & vim 2428 2429bwipe ! 2430let & grepformat = save_grepformat 2431endfunc 2432 2433func Test_two_windows () 2434" Use one 'errorformat' for two windows. Add an expression to each of them, 2435" make sure they each keep their own state. 2436set efm = %DEntering\ dir\ '%f',%f:%l:%m,%XLeaving\ dir\ '%f' 2437call mkdir ( 'Xone/a' , 'p' ) 2438call mkdir ( 'Xtwo/a' , 'p' ) 2439let lines = [ '1' , '2' , 'one one one' , '4' , 'two two two' , '6' , '7' ] 2440call writefile ( lines , 'Xone/a/one.txt' ) 2441call writefile ( lines , 'Xtwo/a/two.txt' ) 2442 2443new one 2444let one_id = win_getid () 2445lexpr "" 2446new two 2447let two_id = win_getid () 2448lexpr "" 2449 2450laddexpr "Entering dir 'Xtwo/a'" 2451call win_gotoid ( one_id ) 2452laddexpr "Entering dir 'Xone/a'" 2453call win_gotoid ( two_id ) 2454laddexpr 'two.txt:5:two two two' 2455call win_gotoid ( one_id ) 2456laddexpr 'one.txt:3:one one one' 2457 2458let loc_one = getloclist ( one_id ) 2459call assert_equal ( 'Xone/a/one.txt' , bufname ( loc_one [ 1 ]. bufnr )) 2460call assert_equal ( 3 , loc_one [ 1 ]. lnum ) 2461 2462let loc_two = getloclist ( two_id ) 2463call assert_equal ( 'Xtwo/a/two.txt' , bufname ( loc_two [ 1 ]. bufnr )) 2464call assert_equal ( 5 , loc_two [ 1 ]. lnum ) 2465 2466call win_gotoid ( one_id ) 2467bwipe ! 2468call win_gotoid ( two_id ) 2469bwipe ! 2470call delete ( 'Xone' , 'rf' ) 2471call delete ( 'Xtwo' , 'rf' ) 2472endfunc 2473 2474func XbottomTests ( cchar ) 2475call s: setup_commands ( a: cchar ) 2476 2477" Calling lbottom without any errors should fail 2478if a: cchar == 'l' 2479call assert_fails ( 'lbottom' , 'E776:' ) 2480endif 2481 2482call g: Xsetlist ([{ 'filename' : 'foo' , 'lnum' : 42 }]) 2483Xopen 2484let wid = win_getid () 2485call assert_equal ( 1 , line ( '.' )) 2486wincmd w 2487call g: Xsetlist ([{ 'filename' : 'var' , 'lnum' : 24 }], 'a' ) 2488Xbottom 2489call win_gotoid ( wid ) 2490call assert_equal ( 2 , line ( '.' )) 2491Xclose 2492endfunc 2493 2494" Tests for the :cbottom and :lbottom commands 2495func Test_cbottom () 2496call XbottomTests ( 'c' ) 2497call XbottomTests ( 'l' ) 2498endfunc 2499 2500func HistoryTest ( cchar ) 2501call s: setup_commands ( a: cchar ) 2502 2503" clear all lists after the first one, then replace the first one. 2504call g: Xsetlist ([]) 2505call assert_fails ( 'Xolder 99' , 'E380:' ) 2506let entry = { 'filename' : 'foo' , 'lnum' : 42 } 2507call g: Xsetlist ([ entry ], 'r' ) 2508call g: Xsetlist ([ entry , entry ]) 2509call g: Xsetlist ([ entry , entry , entry ]) 2510let res = split ( execute ( a: cchar . 'hist' ), "\n" ) 2511call assert_equal ( 3 , len ( res )) 2512let common = 'errors :set' . ( a: cchar == 'c' ? 'qf' : 'loc' ) . 'list()' 2513call assert_equal ( ' error list 1 of 3; 1 ' . common , res [ 0 ]) 2514call assert_equal ( ' error list 2 of 3; 2 ' . common , res [ 1 ]) 2515call assert_equal ( '> error list 3 of 3; 3 ' . common , res [ 2 ]) 2516 2517" Test for changing the quickfix lists 2518call assert_equal ( 3 , g: Xgetlist ({ 'nr' : 0 }). nr ) 2519exe '1' . a: cchar . 'hist' 2520call assert_equal ( 1 , g: Xgetlist ({ 'nr' : 0 }). nr ) 2521exe '3' . a: cchar . 'hist' 2522call assert_equal ( 3 , g: Xgetlist ({ 'nr' : 0 }). nr ) 2523call assert_fails ( '-2' . a: cchar . 'hist' , 'E16:' ) 2524call assert_fails ( '4' . a: cchar . 'hist' , 'E16:' ) 2525 2526call g: Xsetlist ([], 'f' ) 2527let l = split ( execute ( a: cchar . 'hist' ), "\n" ) 2528call assert_equal ( 'No entries' , l [ 0 ]) 2529if a: cchar == 'c' 2530call assert_fails ( '4chist' , 'E16:' ) 2531else 2532call assert_fails ( '4lhist' , 'E776:' ) 2533endif 2534 2535" An empty list should still show the stack history 2536call g: Xsetlist ([]) 2537let res = split ( execute ( a: cchar . 'hist' ), "\n" ) 2538call assert_equal ( '> error list 1 of 1; 0 ' . common , res [ 0 ]) 2539 2540call g: Xsetlist ([], 'f' ) 2541endfunc 2542 2543func Test_history () 2544call HistoryTest ( 'c' ) 2545call HistoryTest ( 'l' ) 2546endfunc 2547 2548func Test_duplicate_buf () 2549" make sure we can get the highest buffer number 2550edit DoesNotExist 2551edit DoesNotExist2 2552let last_buffer = bufnr ( "$" ) 2553 2554" make sure only one buffer is created 2555call writefile ([ 'this one' , 'that one' ], 'Xgrepthis' ) 2556vimgrep one Xgrepthis 2557vimgrep one Xgrepthis 2558call assert_equal ( last_buffer + 1 , bufnr ( "$" )) 2559 2560call delete ( 'Xgrepthis' ) 2561endfunc 2562 2563" Quickfix/Location list set/get properties tests 2564func Xproperty_tests ( cchar ) 2565call s: setup_commands ( a: cchar ) 2566 2567" Error cases 2568call assert_fails ( 'call g:Xgetlist(99)' , 'E715:' ) 2569call assert_fails ( 'call g:Xsetlist(99)' , 'E714:' ) 2570call assert_fails ( 'call g:Xsetlist([], "a", [])' , 'E715:' ) 2571 2572" Set and get the title 2573call g: Xsetlist ([]) 2574Xopen 2575wincmd p 2576call g: Xsetlist ([{ 'filename' : 'foo' , 'lnum' : 27 }]) 2577let s = g: Xsetlist ([], 'a' , { 'title' : 'Sample' }) 2578call assert_equal ( 0 , s ) 2579let d = g: Xgetlist ({ "title" : 1 }) 2580call assert_equal ( 'Sample' , d . title ) 2581" Try setting title to a non-string value 2582call assert_equal ( -1 , g: Xsetlist ([], 'a' , { 'title' : [ 'Test' ]})) 2583call assert_equal ( 'Sample' , g: Xgetlist ({ "title" : 1 }). title ) 2584 2585Xopen 2586call assert_equal ( 'Sample' , w: quickfix_title ) 2587Xclose 2588 2589" Tests for action argument 2590silent ! Xolder 999 2591let qfnr = g: Xgetlist ({ 'all' : 1 }). nr 2592call g: Xsetlist ([], 'r' , { 'title' : 'N1' }) 2593call assert_equal ( 'N1' , g: Xgetlist ({ 'all' : 1 }). title ) 2594call g: Xsetlist ([], ' ' , { 'title' : 'N2' }) 2595call assert_equal ( qfnr + 1 , g: Xgetlist ({ 'all' : 1 }). nr ) 2596 2597let res = g: Xgetlist ({ 'nr' : 0 }) 2598call assert_equal ( qfnr + 1 , res . nr ) 2599call assert_equal ([ 'nr' ], keys ( res )) 2600 2601call g: Xsetlist ([], ' ' , { 'title' : 'N3' }) 2602call assert_equal ( 'N2' , g: Xgetlist ({ 'nr' : 2 , 'title' : 1 }). title ) 2603 2604" Changing the title of an earlier quickfix list 2605call g: Xsetlist ([], 'r' , { 'title' : 'NewTitle' , 'nr' : 2 }) 2606call assert_equal ( 'NewTitle' , g: Xgetlist ({ 'nr' : 2 , 'title' : 1 }). title ) 2607 2608" Changing the title of an invalid quickfix list 2609call assert_equal ( -1 , g: Xsetlist ([], ' ' , 2610 \{ 'title' : 'SomeTitle' , 'nr' : 99 })) 2611call assert_equal ( -1 , g: Xsetlist ([], ' ' , 2612 \{ 'title' : 'SomeTitle' , 'nr' : 'abc' })) 2613 2614if a: cchar == 'c' 2615copen 2616call assert_equal ({ 'winid' : win_getid ()}, getqflist ({ 'winid' : 1 })) 2617cclose 2618endif 2619 2620" Invalid arguments 2621call assert_fails ( 'call g:Xgetlist([])' , 'E715' ) 2622call assert_fails ( 'call g:Xsetlist([], "a", [])' , 'E715' ) 2623let s = g: Xsetlist ([], 'a' , { 'abc' : 1 }) 2624call assert_equal ( -1 , s ) 2625 2626call assert_equal ({}, g: Xgetlist ({ 'abc' : 1 })) 2627call assert_equal ( '' , g: Xgetlist ({ 'nr' : 99 , 'title' : 1 }). title ) 2628call assert_equal ( '' , g: Xgetlist ({ 'nr' :[], 'title' : 1 }). title ) 2629 2630if a: cchar == 'l' 2631call assert_equal ({}, getloclist ( 99 , { 'title' : 1 })) 2632endif 2633 2634" Context related tests 2635let s = g: Xsetlist ([], 'a' , { 'context' :[ 1 , 2 , 3 ]}) 2636call assert_equal ( 0 , s ) 2637call test_garbagecollect_now () 2638let d = g: Xgetlist ({ 'context' : 1 }) 2639call assert_equal ([ 1 , 2 , 3 ], d . context ) 2640call g: Xsetlist ([], 'a' , { 'context' :{ 'color' : 'green' }}) 2641let d = g: Xgetlist ({ 'context' : 1 }) 2642call assert_equal ({ 'color' : 'green' }, d . context ) 2643call g: Xsetlist ([], 'a' , { 'context' : "Context info" }) 2644let d = g: Xgetlist ({ 'context' : 1 }) 2645call assert_equal ( "Context info" , d . context ) 2646call g: Xsetlist ([], 'a' , { 'context' : 246 }) 2647let d = g: Xgetlist ({ 'context' : 1 }) 2648call assert_equal ( 246 , d . context ) 2649" set other Vim data types as context 2650call g: Xsetlist ([], 'a' , { 'context' : v: _null_blob }) 2651if has ( 'channel' ) 2652call g: Xsetlist ([], 'a' , { 'context' : test_null_channel ()}) 2653endif 2654if has ( 'job' ) 2655call g: Xsetlist ([], 'a' , { 'context' : test_null_job ()}) 2656endif 2657" Nvim doesn't have null functions 2658" call g:Xsetlist([], 'a', {'context' : test_null_function()}) 2659" Nvim doesn't have null partials 2660" call g:Xsetlist([], 'a', {'context' : test_null_partial()}) 2661call g: Xsetlist ([], 'a' , { 'context' : '' }) 2662call test_garbagecollect_now () 2663if a: cchar == 'l' 2664" Test for copying context across two different location lists 2665new |only 2666let w1_id = win_getid () 2667let l = [ 1 ] 2668call setloclist ( 0 , [], 'a' , { 'context' : l }) 2669new 2670let w2_id = win_getid () 2671call add ( l , 2 ) 2672call assert_equal ([ 1 , 2 ], getloclist ( w1_id , { 'context' : 1 }). context ) 2673call assert_equal ([ 1 , 2 ], getloclist ( w2_id , { 'context' : 1 }). context ) 2674unlet ! l 2675call assert_equal ([ 1 , 2 ], getloclist ( w2_id , { 'context' : 1 }). context ) 2676only 2677call setloclist ( 0 , [], 'f' ) 2678call assert_equal ( '' , getloclist ( 0 , { 'context' : 1 }). context ) 2679endif 2680 2681" Test for changing the context of previous quickfix lists 2682call g: Xsetlist ([], 'f' ) 2683Xexpr "One" 2684Xexpr "Two" 2685Xexpr "Three" 2686call g: Xsetlist ([], 'r' , { 'context' : [ 1 ], 'nr' : 1 }) 2687call g: Xsetlist ([], 'a' , { 'context' : [ 2 ], 'nr' : 2 }) 2688" Also, check for setting the context using quickfix list number zero. 2689call g: Xsetlist ([], 'r' , { 'context' : [ 3 ], 'nr' : 0 }) 2690call test_garbagecollect_now () 2691let l = g: Xgetlist ({ 'nr' : 1 , 'context' : 1 }) 2692call assert_equal ([ 1 ], l . context ) 2693let l = g: Xgetlist ({ 'nr' : 2 , 'context' : 1 }) 2694call assert_equal ([ 2 ], l . context ) 2695let l = g: Xgetlist ({ 'nr' : 3 , 'context' : 1 }) 2696call assert_equal ([ 3 ], l . context ) 2697 2698" Test for changing the context through reference and for garbage 2699" collection of quickfix context 2700let l = [ "red" ] 2701call g: Xsetlist ([], ' ' , { 'context' : l }) 2702call add ( l , "blue" ) 2703let x = g: Xgetlist ({ 'context' : 1 }) 2704call add ( x . context , "green" ) 2705call assert_equal ([ "red" , "blue" , "green" ], l ) 2706call assert_equal ([ "red" , "blue" , "green" ], x . context ) 2707unlet l 2708call test_garbagecollect_now () 2709let m = g: Xgetlist ({ 'context' : 1 }) 2710call assert_equal ([ "red" , "blue" , "green" ], m . context ) 2711 2712" Test for setting/getting items 2713Xexpr "" 2714let qfprev = g: Xgetlist ({ 'nr' : 0 }) 2715let s = g: Xsetlist ([], ' ' , { 'title' : 'Green' , 2716 \'items' : [{ 'filename' : 'F1' , 'lnum' : 10 }]}) 2717call assert_equal ( 0 , s ) 2718let qfcur = g: Xgetlist ({ 'nr' : 0 }) 2719call assert_true ( qfcur . nr == qfprev . nr + 1 ) 2720let l = g: Xgetlist ({ 'items' : 1 }) 2721call assert_equal ( 'F1' , bufname ( l . items [ 0 ]. bufnr )) 2722call assert_equal ( 10 , l . items [ 0 ]. lnum ) 2723call g: Xsetlist ([], 'a' , { 'items' : [{ 'filename' : 'F2' , 'lnum' : 20 }, 2724 \{ 'filename' : 'F2' , 'lnum' : 30 }]}) 2725let l = g: Xgetlist ({ 'items' : 1 }) 2726call assert_equal ( 'F2' , bufname ( l . items [ 2 ]. bufnr )) 2727call assert_equal ( 30 , l . items [ 2 ]. lnum ) 2728call g: Xsetlist ([], 'r' , { 'items' : [{ 'filename' : 'F3' , 'lnum' : 40 }]}) 2729let l = g: Xgetlist ({ 'items' : 1 }) 2730call assert_equal ( 'F3' , bufname ( l . items [ 0 ]. bufnr )) 2731call assert_equal ( 40 , l . items [ 0 ]. lnum ) 2732call g: Xsetlist ([], 'r' , { 'items' : []}) 2733let l = g: Xgetlist ({ 'items' : 1 }) 2734call assert_equal ( 0 , len ( l . items )) 2735 2736call g: Xsetlist ([], 'r' , { 'title' : 'TestTitle' }) 2737call g: Xsetlist ([], 'r' , { 'items' : [{ 'filename' : 'F1' , 'lnum' : 10 , 'text' : 'L10' }]}) 2738call g: Xsetlist ([], 'r' , { 'items' : [{ 'filename' : 'F1' , 'lnum' : 10 , 'text' : 'L10' }]}) 2739call assert_equal ( 'TestTitle' , g: Xgetlist ({ 'title' : 1 }). title ) 2740 2741" Test for getting id of window associated with a location list window 2742if a: cchar == 'l' 2743only 2744call assert_equal ( 0 , g: Xgetlist ({ 'all' : 1 }). filewinid ) 2745let wid = win_getid () 2746Xopen 2747call assert_equal ( wid , g: Xgetlist ({ 'filewinid' : 1 }). filewinid ) 2748wincmd w 2749call assert_equal ( 0 , g: Xgetlist ({ 'filewinid' : 1 }). filewinid ) 2750only 2751endif 2752 2753" The following used to crash Vim with address sanitizer 2754call g: Xsetlist ([], 'f' ) 2755call g: Xsetlist ([], 'a' , { 'items' : [{ 'filename' : 'F1' , 'lnum' : 10 }]}) 2756call assert_equal ( 10 , g: Xgetlist ({ 'items' : 1 }). items [ 0 ]. lnum ) 2757 2758" Try setting the items using a string 2759call assert_equal ( -1 , g: Xsetlist ([], ' ' , { 'items' : 'Test' })) 2760 2761" Save and restore the quickfix stack 2762call g: Xsetlist ([], 'f' ) 2763call assert_equal ( 0 , g: Xgetlist ({ 'nr' : '$' }). nr ) 2764Xexpr "File1:10:Line1" 2765Xexpr "File2:20:Line2" 2766Xexpr "File3:30:Line3" 2767let last_qf = g: Xgetlist ({ 'nr' : '$' }). nr 2768call assert_equal ( 3 , last_qf ) 2769let qstack = [] 2770for i in range ( 1 , last_qf ) 2771let qstack = add ( qstack , g: Xgetlist ({ 'nr' : i , 'all' : 1 })) 2772endfor 2773call g: Xsetlist ([], 'f' ) 2774for i in range ( len ( qstack )) 2775call g: Xsetlist ([], ' ' , qstack [ i ]) 2776endfor 2777call assert_equal ( 3 , g: Xgetlist ({ 'nr' : '$' }). nr ) 2778call assert_equal ( 10 , g: Xgetlist ({ 'nr' : 1 , 'items' : 1 }). items [ 0 ]. lnum ) 2779call assert_equal ( 20 , g: Xgetlist ({ 'nr' : 2 , 'items' : 1 }). items [ 0 ]. lnum ) 2780call assert_equal ( 30 , g: Xgetlist ({ 'nr' : 3 , 'items' : 1 }). items [ 0 ]. lnum ) 2781call g: Xsetlist ([], 'f' ) 2782 2783" Swap two quickfix lists 2784Xexpr "File1:10:Line10" 2785Xexpr "File2:20:Line20" 2786Xexpr "File3:30:Line30" 2787call g: Xsetlist ([], 'r' , { 'nr' : 1 , 'title' : 'Colors' , 'context' :[ 'Colors' ]}) 2788call g: Xsetlist ([], 'r' , { 'nr' : 2 , 'title' : 'Fruits' , 'context' :[ 'Fruits' ]}) 2789let l1 = g: Xgetlist ({ 'nr' : 1 , 'all' : 1 }) 2790let l2 = g: Xgetlist ({ 'nr' : 2 , 'all' : 1 }) 2791let save_id = l1 . id 2792let l1 . id = l2 . id 2793let l2 . id = save_id 2794call g: Xsetlist ([], 'r' , l1 ) 2795call g: Xsetlist ([], 'r' , l2 ) 2796let newl1 = g: Xgetlist ({ 'nr' : 1 , 'all' : 1 }) 2797let newl2 = g: Xgetlist ({ 'nr' : 2 , 'all' : 1 }) 2798call assert_equal ( 'Fruits' , newl1 . title ) 2799call assert_equal ([ 'Fruits' ], newl1 . context ) 2800call assert_equal ( 'Line20' , newl1 . items [ 0 ]. text ) 2801call assert_equal ( 'Colors' , newl2 . title ) 2802call assert_equal ([ 'Colors' ], newl2 . context ) 2803call assert_equal ( 'Line10' , newl2 . items [ 0 ]. text ) 2804call g: Xsetlist ([], 'f' ) 2805 2806" Cannot specify both a non-empty list argument and a dict argument 2807call assert_fails ( "call g:Xsetlist([{}], ' ', {})" , 'E475:' ) 2808endfunc 2809 2810func Test_qf_property () 2811call Xproperty_tests ( 'c' ) 2812call Xproperty_tests ( 'l' ) 2813endfunc 2814 2815" Test for setting the current index in the location/quickfix list 2816func Xtest_setqfidx ( cchar ) 2817call s: setup_commands ( a: cchar ) 2818 2819Xgetexpr "F1:10:1:Line1\nF2:20:2:Line2\nF3:30:3:Line3" 2820Xgetexpr "F4:10:1:Line1\nF5:20:2:Line2\nF6:30:3:Line3" 2821Xgetexpr "F7:10:1:Line1\nF8:20:2:Line2\nF9:30:3:Line3" 2822 2823call g: Xsetlist ([], 'a' , { 'nr' : 3 , 'idx' : 2 }) 2824call g: Xsetlist ([], 'a' , { 'nr' : 2 , 'idx' : 2 }) 2825call g: Xsetlist ([], 'a' , { 'nr' : 1 , 'idx' : 3 }) 2826Xolder 2 2827Xopen 2828call assert_equal ( 3 , line ( '.' )) 2829Xnewer 2830call assert_equal ( 2 , line ( '.' )) 2831Xnewer 2832call assert_equal ( 2 , line ( '.' )) 2833" Update the current index with the quickfix window open 2834wincmd w 2835call g: Xsetlist ([], 'a' , { 'nr' : 3 , 'idx' : 3 }) 2836Xopen 2837call assert_equal ( 3 , line ( '.' )) 2838Xclose 2839 2840" Set the current index to the last entry 2841call g: Xsetlist ([], 'a' , { 'nr' : 1 , 'idx' : '$' }) 2842call assert_equal ( 3 , g: Xgetlist ({ 'nr' : 1 , 'idx' : 0 }). idx ) 2843" A large value should set the index to the last index 2844call g: Xsetlist ([], 'a' , { 'nr' : 1 , 'idx' : 1 }) 2845call g: Xsetlist ([], 'a' , { 'nr' : 1 , 'idx' : 999 }) 2846call assert_equal ( 3 , g: Xgetlist ({ 'nr' : 1 , 'idx' : 0 }). idx ) 2847" Invalid index values 2848call g: Xsetlist ([], 'a' , { 'nr' : 1 , 'idx' : -1 }) 2849call assert_equal ( 3 , g: Xgetlist ({ 'nr' : 1 , 'idx' : 0 }). idx ) 2850call g: Xsetlist ([], 'a' , { 'nr' : 1 , 'idx' : 0 }) 2851call assert_equal ( 3 , g: Xgetlist ({ 'nr' : 1 , 'idx' : 0 }). idx ) 2852call g: Xsetlist ([], 'a' , { 'nr' : 1 , 'idx' : 'xx' }) 2853call assert_equal ( 3 , g: Xgetlist ({ 'nr' : 1 , 'idx' : 0 }). idx ) 2854call assert_fails ( "call g:Xsetlist([], 'a', {'nr':1, 'idx':[]})" , 'E745:' ) 2855 2856call g: Xsetlist ([], 'f' ) 2857new |only 2858endfunc 2859 2860func Test_setqfidx () 2861call Xtest_setqfidx ( 'c' ) 2862call Xtest_setqfidx ( 'l' ) 2863endfunc 2864 2865" Tests for the QuickFixCmdPre/QuickFixCmdPost autocommands 2866func QfAutoCmdHandler ( loc , cmd ) 2867call add ( g: acmds , a: loc . a: cmd ) 2868endfunc 2869 2870func Test_Autocmd () 2871autocmd QuickFixCmdPre * call QfAutoCmdHandler ( 'pre' , expand ( '<amatch>' )) 2872autocmd QuickFixCmdPost * call QfAutoCmdHandler ( 'post' , expand ( '<amatch>' )) 2873 2874let g: acmds = [] 2875cexpr "F1:10:Line 10" 2876caddexpr "F1:20:Line 20" 2877cgetexpr "F1:30:Line 30" 2878cexpr "" 2879caddexpr "" 2880cgetexpr "" 2881silent ! cexpr non_existing_func() 2882silent ! caddexpr non_existing_func() 2883silent ! cgetexpr non_existing_func() 2884let l =<< trim END 2885precexpr 2886postcexpr 2887precaddexpr 2888postcaddexpr 2889precgetexpr 2890postcgetexpr 2891precexpr 2892postcexpr 2893precaddexpr 2894postcaddexpr 2895precgetexpr 2896postcgetexpr 2897precexpr 2898precaddexpr 2899precgetexpr 2900END 2901call assert_equal ( l , g: acmds ) 2902 2903let g: acmds = [] 2904enew ! |call append ( 0 , "F2:10:Line 10" ) 2905cbuffer ! 2906enew ! |call append ( 0 , "F2:20:Line 20" ) 2907cgetbuffer 2908enew ! |call append ( 0 , "F2:30:Line 30" ) 2909caddbuffer 2910new 2911let bnum = bufnr ( '%' ) 2912bunload 2913exe 'silent! cbuffer! ' . bnum 2914exe 'silent! cgetbuffer ' . bnum 2915exe 'silent! caddbuffer ' . bnum 2916enew ! 2917let l =<< trim END 2918precbuffer 2919postcbuffer 2920precgetbuffer 2921postcgetbuffer 2922precaddbuffer 2923postcaddbuffer 2924precbuffer 2925precgetbuffer 2926precaddbuffer 2927END 2928call assert_equal ( l , g: acmds ) 2929 2930call writefile ([ 'Xtest:1:Line1' ], 'Xtest' ) 2931call writefile ([], 'Xempty' ) 2932let g: acmds = [] 2933cfile Xtest 2934caddfile Xtest 2935cgetfile Xtest 2936cfile Xempty 2937caddfile Xempty 2938cgetfile Xempty 2939silent ! cfile do_not_exist 2940silent ! caddfile do_not_exist 2941silent ! cgetfile do_not_exist 2942let l =<< trim END 2943precfile 2944postcfile 2945precaddfile 2946postcaddfile 2947precgetfile 2948postcgetfile 2949precfile 2950postcfile 2951precaddfile 2952postcaddfile 2953precgetfile 2954postcgetfile 2955precfile 2956postcfile 2957precaddfile 2958postcaddfile 2959precgetfile 2960postcgetfile 2961END 2962call assert_equal ( l , g: acmds ) 2963 2964let g: acmds = [] 2965helpgrep quickfix 2966silent ! helpgrep non_existing_help_topic 2967vimgrep test Xtest 2968vimgrepadd test Xtest 2969silent ! vimgrep non_existing_test Xtest 2970silent ! vimgrepadd non_existing_test Xtest 2971set makeprg = 2972silent ! make 2973set makeprg & 2974let l =<< trim END 2975prehelpgrep 2976posthelpgrep 2977prehelpgrep 2978posthelpgrep 2979previmgrep 2980postvimgrep 2981previmgrepadd 2982postvimgrepadd 2983previmgrep 2984postvimgrep 2985previmgrepadd 2986postvimgrepadd 2987premake 2988postmake 2989END 2990call assert_equal ( l , g: acmds ) 2991 2992if has ( 'unix' ) 2993" Run this test only on Unix-like systems. The grepprg may not be set on 2994" non-Unix systems. 2995" The following lines are used for the grep test. Don't remove. 2996" Grep_Autocmd_Text: Match 1 2997" GrepAdd_Autocmd_Text: Match 2 2998let g: acmds = [] 2999silent grep Grep_Autocmd_Text test_quickfix.vim 3000silent grepadd GrepAdd_Autocmd_Text test_quickfix.vim 3001silent grep abc123def Xtest 3002silent grepadd abc123def Xtest 3003set grepprg = internal 3004silent grep Grep_Autocmd_Text test_quickfix.vim 3005silent grepadd GrepAdd_Autocmd_Text test_quickfix.vim 3006silent lgrep Grep_Autocmd_Text test_quickfix.vim 3007silent lgrepadd GrepAdd_Autocmd_Text test_quickfix.vim 3008set grepprg & vim 3009let l =<< trim END 3010pregrep 3011postgrep 3012pregrepadd 3013postgrepadd 3014pregrep 3015postgrep 3016pregrepadd 3017postgrepadd 3018pregrep 3019postgrep 3020pregrepadd 3021postgrepadd 3022prelgrep 3023postlgrep 3024prelgrepadd 3025postlgrepadd 3026END 3027call assert_equal ( l , g: acmds ) 3028endif 3029 3030call delete ( 'Xtest' ) 3031call delete ( 'Xempty' ) 3032au ! QuickFixCmdPre 3033au ! QuickFixCmdPost 3034endfunc 3035 3036func Test_Autocmd_Exception () 3037set efm = %m 3038lgetexpr '?' 3039 3040try 3041call DoesNotExit () 3042catch 3043lgetexpr '1' 3044finally 3045lgetexpr '1' 3046endtry 3047 3048call assert_equal ( '1' , getloclist ( 0 )[ 0 ]. text ) 3049 3050set efm & vim 3051endfunc 3052 3053func Test_caddbuffer_wrong () 3054" This used to cause a memory access in freed memory. 3055let save_efm = & efm 3056set efm = %EEEE%m,%WWWW,%+CCCC%>%#,%GGGG%.# 3057cgetexpr ['WWWW','EEEE' ,'CCCC' ] 3058let & efm = save_efm 3059caddbuffer 3060bwipe ! 3061endfunc 3062 3063func Test_caddexpr_wrong () 3064" This used to cause a memory access in freed memory. 3065cbuffer 3066cbuffer 3067copen 3068let save_efm = & efm 3069set efm = % 3070call assert_fails ( 'caddexpr ""' , 'E376:' ) 3071let & efm = save_efm 3072endfunc 3073 3074func Test_dirstack_cleanup () 3075" This used to cause a memory access in freed memory. 3076let save_efm = & efm 3077lexpr '0' 3078lopen 3079fun X ( c ) 3080let save_efm =& efm 3081set efm = %D%f 3082if a: c == 'c' 3083caddexpr '::' 3084else 3085laddexpr ':0:0' 3086endif 3087let & efm = save_efm 3088endfun 3089call X ( 'c' ) 3090call X ( 'l' ) 3091call setqflist ([], 'r' ) 3092caddbuffer 3093let & efm = save_efm 3094endfunc 3095 3096" Tests for jumping to entries from the location list window and quickfix 3097" window 3098func Test_cwindow_jump () 3099set efm = %f%%%l%%%m 3100lgetexpr ["F1%10%Line 10","F2%20%Line 20" ,"F3%30%Line 30" ] 3101lopen |only 3102lfirst 3103call assert_true ( winnr ( '$' ) == 2 ) 3104call assert_true ( winnr () == 1 ) 3105" Location list for the new window should be set 3106call assert_true ( getloclist ( 0 )[ 2 ]. text == 'Line 30' ) 3107 3108" Open a scratch buffer 3109" Open a new window and create a location list 3110" Open the location list window and close the other window 3111" Jump to an entry. 3112" Should create a new window and jump to the entry. The scratch buffer 3113" should not be used. 3114enew |only 3115set buftype = nofile 3116below new 3117lgetexpr ["F1%10%Line 10","F2%20%Line 20" ,"F3%30%Line 30" ] 3118lopen 31192 wincmd c 3120lnext 3121call assert_true ( winnr ( '$' ) == 3 ) 3122call assert_true ( winnr () == 2 ) 3123 3124" Open two windows with two different location lists 3125" Open the location list window and close the previous window 3126" Jump to an entry in the location list window 3127" Should open the file in the first window and not set the location list. 3128enew |only 3129lgetexpr ["F1%5%Line 5"] 3130below new 3131lgetexpr ["F1%10%Line 10","F2%20%Line 20" ,"F3%30%Line 30" ] 3132lopen 31332 wincmd c 3134lnext 3135call assert_true ( winnr () == 1 ) 3136call assert_true ( getloclist ( 0 )[ 0 ]. text == 'Line 5' ) 3137 3138enew |only 3139cgetexpr ["F1%10%Line 10","F2%20%Line 20" ,"F3%30%Line 30" ] 3140copen 3141cnext 3142call assert_true ( winnr ( '$' ) == 2 ) 3143call assert_true ( winnr () == 1 ) 3144 3145" open the quickfix buffer in two windows and jump to an entry. Should open 3146" the file in the first quickfix window. 3147enew |only 3148copen 3149let bnum = bufnr ( '' ) 3150exe 'sbuffer ' . bnum 3151wincmd b 3152cfirst 3153call assert_equal ( 2 , winnr ()) 3154call assert_equal ( 'F1' , @%) 3155enew |only 3156exe 'sb' bnum 3157exe 'botright sb' bnum 3158wincmd t 3159clast 3160call assert_equal ( 2 , winnr ()) 3161call assert_equal ( 'quickfix' , getwinvar ( 1 , '&buftype' )) 3162call assert_equal ( 'quickfix' , getwinvar ( 3 , '&buftype' )) 3163 3164" Jumping to a file from the location list window should find a usable 3165" window by wrapping around the window list. 3166enew |only 3167call setloclist ( 0 , [], 'f' ) 3168new |new 3169lgetexpr ["F1%10%Line 10","F2%20%Line 20" ,"F3%30%Line 30" ] 3170lopen 31711 close 3172call assert_equal ( 0 , getloclist ( 3 , { 'id' : 0 }). id ) 3173lnext 3174call assert_equal ( 3 , winnr ()) 3175call assert_equal ( getloclist ( 1 , { 'id' : 0 }). id , getloclist ( 3 , { 'id' : 0 }). id ) 3176 3177enew |only 3178set efm & vim 3179endfunc 3180 3181func Test_cwindow_highlight () 3182CheckScreendump 3183 3184let lines =<< trim END 3185call setline(1, ['some', 'text', 'with', 'matches']) 3186write XCwindow 3187vimgrep e XCwindow 3188redraw 3189cwindow 4 3190END 3191call writefile ( lines , 'XtestCwindow' ) 3192let buf = RunVimInTerminal ( '-S XtestCwindow' , #{ rows : 12 }) 3193call VerifyScreenDump ( buf , 'Test_quickfix_cwindow_1' , {}) 3194 3195call term_sendkeys ( buf , ":cnext\<CR>" ) 3196call VerifyScreenDump ( buf , 'Test_quickfix_cwindow_2' , {}) 3197 3198" clean up 3199call StopVimInTerminal ( buf ) 3200call delete ( 'XtestCwindow' ) 3201call delete ( 'XCwindow' ) 3202endfunc 3203 3204func XvimgrepTests ( cchar ) 3205call s: setup_commands ( a: cchar ) 3206 3207let lines =<< trim END 3208Editor:VIM vim 3209Editor:Emacs EmAcS 3210Editor:Notepad NOTEPAD 3211END 3212call writefile ( lines , 'Xtestfile1' ) 3213call writefile ([ 'Linux' , 'macOS' , 'MS-Windows' ], 'Xtestfile2' ) 3214 3215" Error cases 3216call assert_fails ( 'Xvimgrep /abc *' , 'E682:' ) 3217 3218let @/= '' 3219call assert_fails ( 'Xvimgrep // *' , 'E35:' ) 3220 3221call assert_fails ( 'Xvimgrep abc' , 'E683:' ) 3222call assert_fails ( 'Xvimgrep a1b2c3 Xtestfile1' , 'E480:' ) 3223call assert_fails ( 'Xvimgrep pat Xa1b2c3' , 'E480:' ) 3224 3225Xexpr "" 3226Xvimgrepadd Notepad Xtestfile1 3227Xvimgrepadd macOS Xtestfile2 3228let l = g: Xgetlist () 3229call assert_equal ( 2 , len ( l )) 3230call assert_equal ( 'Editor:Notepad NOTEPAD' , l [ 0 ]. text ) 3231 323210 Xvimgrep #\cvim#g Xtestfile? 3233let l = g: Xgetlist () 3234call assert_equal ( 2 , len ( l )) 3235call assert_equal ( 8 , l [ 0 ]. col ) 3236call assert_equal ( 11 , l [ 0 ]. end_col ) 3237call assert_equal ( 12 , l [ 1 ]. col ) 3238call assert_equal ( 15 , l [ 1 ]. end_col ) 3239 32401 Xvimgrep ?Editor? Xtestfile* 3241let l = g: Xgetlist () 3242call assert_equal ( 1 , len ( l )) 3243call assert_equal ( 'Editor:VIM vim' , l [ 0 ]. text ) 3244 3245edit + 3 Xtestfile2 3246Xvimgrep +\cemacs+j Xtestfile1 3247let l = g: Xgetlist () 3248call assert_equal ( 'Xtestfile2' , @%) 3249call assert_equal ( 'Editor:Emacs EmAcS' , l [ 0 ]. text ) 3250 3251" Test for unloading a buffer after vimgrep searched the buffer 3252 %bwipe 3253Xvimgrep /Editor/j Xtestfile* 3254call assert_equal ( 0 , getbufinfo ( 'Xtestfile1' )[ 0 ]. loaded ) 3255call assert_equal ([], getbufinfo ( 'Xtestfile2' )) 3256 3257" Test for opening the dummy buffer used by vimgrep in a window. The new 3258" window should be closed 3259 %bw ! 3260augroup QF_Test 3261au ! 3262autocmd BufReadPre * exe "sb " .. expand ( "<abuf>" ) 3263augroup END 3264call assert_fails ( "Xvimgrep /sublime/ Xtestfile1" , 'E480:' ) 3265call assert_equal ( 1 , winnr ( '$' )) 3266augroup QF_Test 3267au ! 3268augroup END 3269 3270call delete ( 'Xtestfile1' ) 3271call delete ( 'Xtestfile2' ) 3272endfunc 3273 3274" Tests for the :vimgrep command 3275func Test_vimgrep () 3276call XvimgrepTests ( 'c' ) 3277call XvimgrepTests ( 'l' ) 3278endfunc 3279 3280func Test_vimgrep_wildcards_expanded_once () 3281new X[id-01] file.txt 3282call setline ( 1 , 'some text to search for' ) 3283vimgrep text % 3284bwipe ! 3285endfunc 3286 3287" Test for incsearch highlighting of the :vimgrep pattern 3288" This test used to cause "E315: ml_get: invalid lnum" errors. 3289func Test_vimgrep_incsearch () 3290enew 3291set incsearch 3292call Ntest_override ( "char_avail" , 1 ) 3293 3294call feedkeys ( ":2vimgrep assert test_quickfix.vim test_cdo.vim\<CR>" , "ntx" ) 3295let l = getqflist () 3296call assert_equal ( 2 , len ( l )) 3297 3298call Ntest_override ( "ALL" , 0 ) 3299set noincsearch 3300endfunc 3301 3302" Test vimgrep with the last search pattern not set 3303func Test_vimgrep_with_no_last_search_pat () 3304let lines =<< trim [SCRIPT] 3305call assert_fails('vimgrep // *', 'E35:') 3306call writefile(v:errors, 'Xresult') 3307qall! 3308[SCRIPT] 3309call writefile ( lines , 'Xscript' ) 3310if RunVim ([], [], '--clean -S Xscript' ) 3311call assert_equal ([], readfile ( 'Xresult' )) 3312endif 3313call delete ( 'Xscript' ) 3314call delete ( 'Xresult' ) 3315endfunc 3316 3317" Test vimgrep without swap file 3318func Test_vimgrep_without_swap_file () 3319let lines =<< trim [SCRIPT] 3320vimgrep grep test_c* 3321call writefile(['done'], 'Xresult') 3322qall! 3323[SCRIPT] 3324call writefile ( lines , 'Xscript' ) 3325if RunVim ([], [], '--clean -n -S Xscript Xscript' ) 3326call assert_equal ([ 'done' ], readfile ( 'Xresult' )) 3327endif 3328call delete ( 'Xscript' ) 3329call delete ( 'Xresult' ) 3330endfunc 3331 3332func Test_vimgrep_existing_swapfile () 3333call writefile ([ 'match apple with apple' ], 'Xapple' ) 3334call writefile ([ 'swapfile' ], '.Xapple.swp' ) 3335let g: foundSwap = 0 3336let g: ignoreSwapExists = 1 3337augroup grep 3338au SwapExists * let foundSwap = 1 |let v: swapchoice = 'e' 3339augroup END 3340vimgrep apple Xapple 3341call assert_equal ( 1 , g: foundSwap ) 3342call assert_match ( '.Xapple.swo' , swapname ( '' )) 3343 3344call delete ( 'Xapple' ) 3345call delete ( '.Xapple.swp' ) 3346augroup grep 3347au ! SwapExists 3348augroup END 3349unlet g: ignoreSwapExists 3350endfunc 3351 3352func XfreeTests ( cchar ) 3353call s: setup_commands ( a: cchar ) 3354 3355enew |only 3356 3357" Deleting the quickfix stack should work even When the current list is 3358" somewhere in the middle of the stack 3359Xexpr ['Xfile1:10:10:Line 10','Xfile1:15:15:Line 15' ] 3360Xexpr ['Xfile2:20:20:Line 20','Xfile2:25:25:Line 25' ] 3361Xexpr ['Xfile3:30:30:Line 30','Xfile3:35:35:Line 35' ] 3362Xolder 3363call g: Xsetlist ([], 'f' ) 3364call assert_equal ( 0 , len ( g: Xgetlist ())) 3365 3366" After deleting the stack, adding a new list should create a stack with a 3367" single list. 3368Xexpr ['Xfile1:10:10:Line 10','Xfile1:15:15:Line 15' ] 3369call assert_equal ( 1 , g: Xgetlist ({ 'all' : 1 }). nr ) 3370 3371" Deleting the stack from a quickfix window should update/clear the 3372" quickfix/location list window. 3373Xexpr ['Xfile1:10:10:Line 10','Xfile1:15:15:Line 15' ] 3374Xexpr ['Xfile2:20:20:Line 20','Xfile2:25:25:Line 25' ] 3375Xexpr ['Xfile3:30:30:Line 30','Xfile3:35:35:Line 35' ] 3376Xolder 3377Xwindow 3378call g: Xsetlist ([], 'f' ) 3379call assert_equal ( 2 , winnr ( '$' )) 3380call assert_equal ( 1 , line ( '$' )) 3381Xclose 3382 3383" Deleting the stack from a non-quickfix window should update/clear the 3384" quickfix/location list window. 3385Xexpr ['Xfile1:10:10:Line 10','Xfile1:15:15:Line 15' ] 3386Xexpr ['Xfile2:20:20:Line 20','Xfile2:25:25:Line 25' ] 3387Xexpr ['Xfile3:30:30:Line 30','Xfile3:35:35:Line 35' ] 3388Xolder 3389Xwindow 3390wincmd p 3391call g: Xsetlist ([], 'f' ) 3392call assert_equal ( 0 , len ( g: Xgetlist ())) 3393wincmd p 3394call assert_equal ( 2 , winnr ( '$' )) 3395call assert_equal ( 1 , line ( '$' )) 3396 3397" After deleting the location list stack, if the location list window is 3398" opened, then a new location list should be created. So opening the 3399" location list window again should not create a new window. 3400if a: cchar == 'l' 3401lexpr ['Xfile1:10:10:Line 10','Xfile1:15:15:Line 15' ] 3402wincmd p 3403lopen 3404call assert_equal ( 2 , winnr ( '$' )) 3405endif 3406Xclose 3407endfunc 3408 3409" Tests for the quickfix free functionality 3410func Test_qf_free () 3411call XfreeTests ( 'c' ) 3412call XfreeTests ( 'l' ) 3413endfunc 3414 3415" Test for buffer overflow when parsing lines and adding new entries to 3416" the quickfix list. 3417func Test_bufoverflow () 3418set efm = %f:%l:%m 3419cgetexpr ['File1:100:' . repeat('x', 1025)] 3420 3421set efm = %+GCompiler:\ %.%#,%f:%l:%m 3422cgetexpr ['Compiler:' . repeat(' a', 1015),'File1:10:Hello World' ] 3423 3424set efm = %DEntering\ directory\ %f,%f:%l:%m 3425let lines =<< trim eval END 3426Entering directory $"{repeat('a', 1006)}" 3427File1:10:Hello World 3428END 3429cgetexpr lines 3430set efm & vim 3431endfunc 3432 3433" Tests for getting the quickfix stack size 3434func XsizeTests ( cchar ) 3435call s: setup_commands ( a: cchar ) 3436 3437call g: Xsetlist ([], 'f' ) 3438call assert_equal ( 0 , g: Xgetlist ({ 'nr' : '$' }). nr ) 3439call assert_equal ( '' , g: Xgetlist ({ 'nr' : '$' , 'all' : 1 }). title ) 3440call assert_equal ( 0 , g: Xgetlist ({ 'nr' : 0 }). nr ) 3441 3442Xexpr "File1:10:Line1" 3443Xexpr "File2:20:Line2" 3444Xexpr "File3:30:Line3" 3445Xolder |Xolder 3446call assert_equal ( 3 , g: Xgetlist ({ 'nr' : '$' }). nr ) 3447call g: Xsetlist ([], 'f' ) 3448 3449Xexpr "File1:10:Line1" 3450Xexpr "File2:20:Line2" 3451Xexpr "File3:30:Line3" 3452Xolder |Xolder 3453call g: Xsetlist ([], 'a' , { 'nr' : '$' , 'title' : 'Compiler' }) 3454call assert_equal ( 'Compiler' , g: Xgetlist ({ 'nr' : 3 , 'all' : 1 }). title ) 3455endfunc 3456 3457func Test_Qf_Size () 3458call XsizeTests ( 'c' ) 3459call XsizeTests ( 'l' ) 3460endfunc 3461 3462func Test_cclose_from_copen () 3463augroup QF_Test 3464au ! 3465au FileType qf : call assert_fails ( ':cclose' , 'E788' ) 3466augroup END 3467copen 3468augroup QF_Test 3469au ! 3470augroup END 3471augroup ! QF_Test 3472endfunc 3473 3474func Test_cclose_in_autocmd () 3475" Problem is only triggered if "starting" is zero, so that the OptionSet 3476" event will be triggered. 3477call Ntest_override ( 'starting' , 1 ) 3478augroup QF_Test 3479au ! 3480au FileType qf : call assert_fails ( ':cclose' , 'E788' ) 3481augroup END 3482copen 3483augroup QF_Test 3484au ! 3485augroup END 3486augroup ! QF_Test 3487call Ntest_override ( 'starting' , 0 ) 3488endfunc 3489 3490" Check that ":file" without an argument is possible even when "curbuf->b_ro_locked" 3491" is set. 3492func Test_file_from_copen () 3493" Works without argument. 3494augroup QF_Test 3495au ! 3496au FileType qf file 3497augroup END 3498copen 3499 3500augroup QF_Test 3501au ! 3502augroup END 3503cclose 3504 3505" Fails with argument. 3506augroup QF_Test 3507au ! 3508au FileType qf call assert_fails ( ':file foo' , 'E788' ) 3509augroup END 3510copen 3511augroup QF_Test 3512au ! 3513augroup END 3514cclose 3515 3516augroup ! QF_Test 3517endfunc 3518 3519func Test_resize_from_copen () 3520augroup QF_Test 3521au ! 3522au FileType qf resize 5 3523augroup END 3524try 3525" This should succeed without any exception. No other buffers are 3526" involved in the autocmd. 3527copen 3528finally 3529augroup QF_Test 3530au ! 3531augroup END 3532augroup ! QF_Test 3533endtry 3534endfunc 3535 3536func Test_filetype_autocmd () 3537" this changes the location list while it is in use to fill a buffer 3538lexpr '' 3539lopen 3540augroup FT_loclist 3541au FileType * call setloclist ( 0 , [], 'f' ) 3542augroup END 3543silent ! lolder 3544lexpr '' 3545 3546augroup FT_loclist 3547au ! FileType 3548augroup END 3549endfunc 3550 3551func Test_vimgrep_with_textlock () 3552new 3553 3554" Simple way to execute something with "textlock" set. 3555" Check that vimgrep without jumping can be executed. 3556au InsertCharPre * vimgrep /RunTheTest/j runtest.vim 3557normal ax 3558let qflist = getqflist () 3559call assert_true ( len ( qflist ) > 0 ) 3560call assert_match ( 'RunTheTest' , qflist [ 0 ]. text ) 3561call setqflist ([], 'r' ) 3562au ! InsertCharPre 3563 3564" Check that vimgrepadd without jumping can be executed. 3565au InsertCharPre * vimgrepadd /RunTheTest/j runtest.vim 3566normal ax 3567let qflist = getqflist () 3568call assert_true ( len ( qflist ) > 0 ) 3569call assert_match ( 'RunTheTest' , qflist [ 0 ]. text ) 3570call setqflist ([], 'r' ) 3571au ! InsertCharPre 3572 3573" Check that lvimgrep without jumping can be executed. 3574au InsertCharPre * lvimgrep /RunTheTest/j runtest.vim 3575normal ax 3576let qflist = getloclist ( 0 ) 3577call assert_true ( len ( qflist ) > 0 ) 3578call assert_match ( 'RunTheTest' , qflist [ 0 ]. text ) 3579call setloclist ( 0 , [], 'r' ) 3580au ! InsertCharPre 3581 3582" Check that lvimgrepadd without jumping can be executed. 3583au InsertCharPre * lvimgrepadd /RunTheTest/j runtest.vim 3584normal ax 3585let qflist = getloclist ( 0 ) 3586call assert_true ( len ( qflist ) > 0 ) 3587call assert_match ( 'RunTheTest' , qflist [ 0 ]. text ) 3588call setloclist ( 0 , [], 'r' ) 3589au ! InsertCharPre 3590 3591" trying to jump will give an error 3592au InsertCharPre * vimgrep /RunTheTest/ runtest.vim 3593call assert_fails ( 'normal ax' , 'E565:' ) 3594au ! InsertCharPre 3595 3596au InsertCharPre * vimgrepadd /RunTheTest/ runtest.vim 3597call assert_fails ( 'normal ax' , 'E565:' ) 3598au ! InsertCharPre 3599 3600au InsertCharPre * lvimgrep /RunTheTest/ runtest.vim 3601call assert_fails ( 'normal ax' , 'E565:' ) 3602au ! InsertCharPre 3603 3604au InsertCharPre * lvimgrepadd /RunTheTest/ runtest.vim 3605call assert_fails ( 'normal ax' , 'E565:' ) 3606au ! InsertCharPre 3607 3608bwipe ! 3609endfunc 3610 3611" Tests for the quickfix buffer b:changedtick variable 3612func Xchangedtick_tests ( cchar ) 3613call s: setup_commands ( a: cchar ) 3614 3615new |only 3616 3617Xexpr "" |Xexpr "" |Xexpr "" 3618 3619Xopen 3620Xolder 3621Xolder 3622Xaddexpr "F1:10:Line10" 3623Xaddexpr "F2:20:Line20" 3624call g: Xsetlist ([{ "filename" : "F3" , "lnum" : 30 , "text" : "Line30" }], 'a' ) 3625call g: Xsetlist ([], 'f' ) 3626call assert_equal ( 8 , getbufvar ( '%' , 'changedtick' )) 3627Xclose 3628endfunc 3629 3630func Test_changedtick () 3631call Xchangedtick_tests ( 'c' ) 3632call Xchangedtick_tests ( 'l' ) 3633endfunc 3634 3635" Tests for parsing an expression using setqflist() 3636func Xsetexpr_tests ( cchar ) 3637call s: setup_commands ( a: cchar ) 3638 3639let t = [ "File1:10:Line10" , "File1:20:Line20" ] 3640call g: Xsetlist ([], ' ' , { 'lines' : t }) 3641call g: Xsetlist ([], 'a' , { 'lines' : [ "File1:30:Line30" ]}) 3642 3643let l = g: Xgetlist () 3644call assert_equal ( 3 , len ( l )) 3645call assert_equal ( 20 , l [ 1 ]. lnum ) 3646call assert_equal ( 'Line30' , l [ 2 ]. text ) 3647call g: Xsetlist ([], 'r' , { 'lines' : [ "File2:5:Line5" ]}) 3648let l = g: Xgetlist () 3649call assert_equal ( 1 , len ( l )) 3650call assert_equal ( 'Line5' , l [ 0 ]. text ) 3651call assert_equal ( -1 , g: Xsetlist ([], 'a' , { 'lines' : 10 })) 3652call assert_equal ( -1 , g: Xsetlist ([], 'a' , { 'lines' : "F1:10:L10" })) 3653 3654call g: Xsetlist ([], 'f' ) 3655" Add entries to multiple lists 3656call g: Xsetlist ([], 'a' , { 'nr' : 1 , 'lines' : [ "File1:10:Line10" ]}) 3657call g: Xsetlist ([], 'a' , { 'nr' : 2 , 'lines' : [ "File2:20:Line20" ]}) 3658call g: Xsetlist ([], 'a' , { 'nr' : 1 , 'lines' : [ "File1:15:Line15" ]}) 3659call g: Xsetlist ([], 'a' , { 'nr' : 2 , 'lines' : [ "File2:25:Line25" ]}) 3660call assert_equal ( 'Line15' , g: Xgetlist ({ 'nr' : 1 , 'items' : 1 }). items [ 1 ]. text ) 3661call assert_equal ( 'Line25' , g: Xgetlist ({ 'nr' : 2 , 'items' : 1 }). items [ 1 ]. text ) 3662 3663" Adding entries using a custom efm 3664set efm & 3665call g: Xsetlist ([], ' ' , { 'efm' : '%f#%l#%m' , 3666 \'lines' : [ "F1#10#L10" , "F2#20#L20" ]}) 3667call assert_equal ( 20 , g: Xgetlist ({ 'items' : 1 }). items [ 1 ]. lnum ) 3668call g: Xsetlist ([], 'a' , { 'efm' : '%f#%l#%m' , 'lines' : [ "F3:30:L30" ]}) 3669call assert_equal ( 'F3:30:L30' , g: Xgetlist ({ 'items' : 1 }). items [ 2 ]. text ) 3670call assert_equal ( 20 , g: Xgetlist ({ 'items' : 1 }). items [ 1 ]. lnum ) 3671call assert_equal ( -1 , g: Xsetlist ([], 'a' , { 'efm' : [], 3672 \'lines' : [ 'F1:10:L10' ]})) 3673endfunc 3674 3675func Test_setexpr () 3676call Xsetexpr_tests ( 'c' ) 3677call Xsetexpr_tests ( 'l' ) 3678endfunc 3679 3680" Tests for per quickfix/location list directory stack 3681func Xmultidirstack_tests ( cchar ) 3682call s: setup_commands ( a: cchar ) 3683 3684call g: Xsetlist ([], 'f' ) 3685Xexpr "" |Xexpr "" 3686 3687call g: Xsetlist ([], 'a' , { 'nr' : 1 , 'lines' : [ "Entering dir 'Xone/a'" ]}) 3688call g: Xsetlist ([], 'a' , { 'nr' : 2 , 'lines' : [ "Entering dir 'Xtwo/a'" ]}) 3689call g: Xsetlist ([], 'a' , { 'nr' : 1 , 'lines' : [ "one.txt:3:one one one" ]}) 3690call g: Xsetlist ([], 'a' , { 'nr' : 2 , 'lines' : [ "two.txt:5:two two two" ]}) 3691 3692let l1 = g: Xgetlist ({ 'nr' : 1 , 'items' : 1 }) 3693let l2 = g: Xgetlist ({ 'nr' : 2 , 'items' : 1 }) 3694call assert_equal ( 'Xone/a/one.txt' , bufname ( l1 . items [ 1 ]. bufnr )) 3695call assert_equal ( 3 , l1 . items [ 1 ]. lnum ) 3696call assert_equal ( 'Xtwo/a/two.txt' , bufname ( l2 . items [ 1 ]. bufnr )) 3697call assert_equal ( 5 , l2 . items [ 1 ]. lnum ) 3698endfunc 3699 3700func Test_multidirstack () 3701call mkdir ( 'Xone/a' , 'p' ) 3702call mkdir ( 'Xtwo/a' , 'p' ) 3703let lines = [ '1' , '2' , 'one one one' , '4' , 'two two two' , '6' , '7' ] 3704call writefile ( lines , 'Xone/a/one.txt' ) 3705call writefile ( lines , 'Xtwo/a/two.txt' ) 3706let save_efm = & efm 3707set efm = %DEntering\ dir\ '%f',%f:%l:%m,%XLeaving\ dir\ '%f' 3708 3709call Xmultidirstack_tests ( 'c' ) 3710call Xmultidirstack_tests ( 'l' ) 3711 3712let & efm = save_efm 3713call delete ( 'Xone' , 'rf' ) 3714call delete ( 'Xtwo' , 'rf' ) 3715endfunc 3716 3717" Tests for per quickfix/location list file stack 3718func Xmultifilestack_tests ( cchar ) 3719call s: setup_commands ( a: cchar ) 3720 3721call g: Xsetlist ([], 'f' ) 3722Xexpr "" |Xexpr "" 3723 3724call g: Xsetlist ([], 'a' , { 'nr' : 1 , 'lines' : [ "[one.txt]" ]}) 3725call g: Xsetlist ([], 'a' , { 'nr' : 2 , 'lines' : [ "[two.txt]" ]}) 3726call g: Xsetlist ([], 'a' , { 'nr' : 1 , 'lines' : [ "(3,5) one one one" ]}) 3727call g: Xsetlist ([], 'a' , { 'nr' : 2 , 'lines' : [ "(5,9) two two two" ]}) 3728 3729let l1 = g: Xgetlist ({ 'nr' : 1 , 'items' : 1 }) 3730let l2 = g: Xgetlist ({ 'nr' : 2 , 'items' : 1 }) 3731call assert_equal ( 'one.txt' , bufname ( l1 . items [ 1 ]. bufnr )) 3732call assert_equal ( 3 , l1 . items [ 1 ]. lnum ) 3733call assert_equal ( 'two.txt' , bufname ( l2 . items [ 1 ]. bufnr )) 3734call assert_equal ( 5 , l2 . items [ 1 ]. lnum ) 3735 3736" Test for start of a new error line in the same line where a previous 3737" error line ends with a file stack. 3738let efm_val = 'Error\ l%l\ in\ %f,' 3739let efm_val .= '%-P%>(%f%r,Error\ l%l\ in\ %m,%-Q)%r' 3740let lines =<< trim END 3741(one.txt 3742Error l4 in one.txt 3743) (two.txt 3744Error l6 in two.txt 3745) 3746Error l8 in one.txt 3747END 3748let l = g: Xgetlist ({ 'lines' : lines , 'efm' : efm_val }) 3749call assert_equal ( 3 , len ( l . items )) 3750call assert_equal ( 'one.txt' , bufname ( l . items [ 0 ]. bufnr )) 3751call assert_equal ( 4 , l . items [ 0 ]. lnum ) 3752call assert_equal ( 'one.txt' , l . items [ 0 ]. text ) 3753call assert_equal ( 'two.txt' , bufname ( l . items [ 1 ]. bufnr )) 3754call assert_equal ( 6 , l . items [ 1 ]. lnum ) 3755call assert_equal ( 'two.txt' , l . items [ 1 ]. text ) 3756call assert_equal ( 'one.txt' , bufname ( l . items [ 2 ]. bufnr )) 3757call assert_equal ( 8 , l . items [ 2 ]. lnum ) 3758call assert_equal ( '' , l . items [ 2 ]. text ) 3759endfunc 3760 3761func Test_multifilestack () 3762let lines = [ '1' , '2' , 'one one one' , '4' , 'two two two' , '6' , '7' ] 3763call writefile ( lines , 'one.txt' ) 3764call writefile ( lines , 'two.txt' ) 3765let save_efm = & efm 3766set efm = %+P[%f],(%l\\,%c)\ %m,%-Q 3767 3768call Xmultifilestack_tests ( 'c' ) 3769call Xmultifilestack_tests ( 'l' ) 3770 3771let & efm = save_efm 3772call delete ( 'one.txt' ) 3773call delete ( 'two.txt' ) 3774endfunc 3775 3776" Tests for per buffer 'efm' setting 3777func Test_perbuf_efm () 3778call writefile ([ "File1-10-Line10" ], 'one.txt' ) 3779call writefile ([ "File2#20#Line20" ], 'two.txt' ) 3780set efm = %f#%l#%m 3781new |only 3782new 3783setlocal efm = %f-%l-%m 3784cfile one.txt 3785wincmd w 3786caddfile two.txt 3787 3788let l = getqflist () 3789call assert_equal ( 10 , l [ 0 ]. lnum ) 3790call assert_equal ( 'Line20' , l [ 1 ]. text ) 3791 3792set efm & 3793new |only 3794call delete ( 'one.txt' ) 3795call delete ( 'two.txt' ) 3796endfunc 3797 3798" Open multiple help windows using ":lhelpgrep 3799" This test used to crash Vim 3800func Test_Multi_LL_Help () 3801new |only 3802lhelpgrep window 3803lopen 3804e # 3805lhelpgrep buffer 3806call assert_equal ( 3 , winnr ( '$' )) 3807call assert_true ( len ( getloclist ( 1 )) != 0 ) 3808call assert_true ( len ( getloclist ( 2 )) != 0 ) 3809new |only 3810endfunc 3811 3812" Tests for adding new quickfix lists using setqflist() 3813func XaddQf_tests ( cchar ) 3814call s: setup_commands ( a: cchar ) 3815 3816" Create a new list using ' ' for action 3817call g: Xsetlist ([], 'f' ) 3818call g: Xsetlist ([], ' ' , { 'title' : 'Test1' }) 3819let l = g: Xgetlist ({ 'nr' : '$' , 'all' : 1 }) 3820call assert_equal ( 1 , l . nr ) 3821call assert_equal ( 'Test1' , l . title ) 3822 3823" Create a new list using ' ' for action and '$' for 'nr' 3824call g: Xsetlist ([], 'f' ) 3825call g: Xsetlist ([], ' ' , { 'title' : 'Test2' , 'nr' : '$' }) 3826let l = g: Xgetlist ({ 'nr' : '$' , 'all' : 1 }) 3827call assert_equal ( 1 , l . nr ) 3828call assert_equal ( 'Test2' , l . title ) 3829 3830" Create a new list using 'a' for action 3831call g: Xsetlist ([], 'f' ) 3832call g: Xsetlist ([], 'a' , { 'title' : 'Test3' }) 3833let l = g: Xgetlist ({ 'nr' : '$' , 'all' : 1 }) 3834call assert_equal ( 1 , l . nr ) 3835call assert_equal ( 'Test3' , l . title ) 3836 3837" Create a new list using 'a' for action and '$' for 'nr' 3838call g: Xsetlist ([], 'f' ) 3839call g: Xsetlist ([], 'a' , { 'title' : 'Test3' , 'nr' : '$' }) 3840call g: Xsetlist ([], 'a' , { 'title' : 'Test4' }) 3841let l = g: Xgetlist ({ 'nr' : '$' , 'all' : 1 }) 3842call assert_equal ( 1 , l . nr ) 3843call assert_equal ( 'Test4' , l . title ) 3844 3845" Adding a quickfix list should remove all the lists following the current 3846" list. 3847Xexpr "" |Xexpr "" |Xexpr "" 3848silent ! 10 Xolder 3849call g: Xsetlist ([], ' ' , { 'title' : 'Test5' }) 3850let l = g: Xgetlist ({ 'nr' : '$' , 'all' : 1 }) 3851call assert_equal ( 2 , l . nr ) 3852call assert_equal ( 'Test5' , l . title ) 3853 3854" Add a quickfix list using '$' as the list number. 3855let lastqf = g: Xgetlist ({ 'nr' : '$' }). nr 3856silent ! 99 Xolder 3857call g: Xsetlist ([], ' ' , { 'nr' : '$' , 'title' : 'Test6' }) 3858let l = g: Xgetlist ({ 'nr' : '$' , 'all' : 1 }) 3859call assert_equal ( lastqf + 1 , l . nr ) 3860call assert_equal ( 'Test6' , l . title ) 3861 3862" Add a quickfix list using 'nr' set to one more than the quickfix 3863" list size. 3864let lastqf = g: Xgetlist ({ 'nr' : '$' }). nr 3865silent ! 99 Xolder 3866call g: Xsetlist ([], ' ' , { 'nr' : lastqf + 1 , 'title' : 'Test7' }) 3867let l = g: Xgetlist ({ 'nr' : '$' , 'all' : 1 }) 3868call assert_equal ( lastqf + 1 , l . nr ) 3869call assert_equal ( 'Test7' , l . title ) 3870 3871" Add a quickfix list to a stack with 10 lists using 'nr' set to '$' 3872exe repeat ( 'Xexpr "" |' , 9 ) . 'Xexpr ""' 3873silent ! 99 Xolder 3874call g: Xsetlist ([], ' ' , { 'nr' : '$' , 'title' : 'Test8' }) 3875let l = g: Xgetlist ({ 'nr' : '$' , 'all' : 1 }) 3876call assert_equal ( 10 , l . nr ) 3877call assert_equal ( 'Test8' , l . title ) 3878 3879" Add a quickfix list using 'nr' set to a value greater than 10 3880call assert_equal ( -1 , g: Xsetlist ([], ' ' , { 'nr' : 12 , 'title' : 'Test9' })) 3881 3882" Try adding a quickfix list with 'nr' set to a value greater than the 3883" quickfix list size but less than 10. 3884call g: Xsetlist ([], 'f' ) 3885Xexpr "" |Xexpr "" |Xexpr "" 3886silent ! 99 Xolder 3887call assert_equal ( -1 , g: Xsetlist ([], ' ' , { 'nr' : 8 , 'title' : 'Test10' })) 3888 3889" Add a quickfix list using 'nr' set to a some string or list 3890call assert_equal ( -1 , g: Xsetlist ([], ' ' , { 'nr' : [ 1 , 2 ], 'title' : 'Test11' })) 3891endfunc 3892 3893func Test_add_qf () 3894call XaddQf_tests ( 'c' ) 3895call XaddQf_tests ( 'l' ) 3896endfunc 3897 3898" Test for getting the quickfix list items from some text without modifying 3899" the quickfix stack 3900func XgetListFromLines ( cchar ) 3901call s: setup_commands ( a: cchar ) 3902call g: Xsetlist ([], 'f' ) 3903 3904let l = g: Xgetlist ({ 'lines' : [ "File2:20:Line20" , "File2:30:Line30" ]}). items 3905call assert_equal ( 2 , len ( l )) 3906call assert_equal ( 30 , l [ 1 ]. lnum ) 3907 3908call assert_equal ({}, g: Xgetlist ({ 'lines' : 10 })) 3909call assert_equal ({}, g: Xgetlist ({ 'lines' : 'File1:10:Line10' })) 3910call assert_equal ([], g: Xgetlist ({ 'lines' : []}). items ) 3911call assert_equal ([], g: Xgetlist ({ 'lines' : [ 10 , 20 ]}). items ) 3912 3913" Parse text using a custom efm 3914set efm & 3915let l = g: Xgetlist ({ 'lines' :[ 'File3#30#Line30' ], 'efm' : '%f#%l#%m' }). items 3916call assert_equal ( 'Line30' , l [ 0 ]. text ) 3917let l = g: Xgetlist ({ 'lines' :[ 'File3:30:Line30' ], 'efm' : '%f-%l-%m' }). items 3918call assert_equal ( 'File3:30:Line30' , l [ 0 ]. text ) 3919let l = g: Xgetlist ({ 'lines' :[ 'File3:30:Line30' ], 'efm' : [ 1 , 2 ]}) 3920call assert_equal ({}, l ) 3921call assert_fails ( "call g:Xgetlist({'lines':['abc'], 'efm':'%2'})" , 'E376:' ) 3922call assert_fails ( "call g:Xgetlist({'lines':['abc'], 'efm':''})" , 'E378:' ) 3923 3924" Make sure that the quickfix stack is not modified 3925call assert_equal ( 0 , g: Xgetlist ({ 'nr' : '$' }). nr ) 3926endfunc 3927 3928func Test_get_list_from_lines () 3929call XgetListFromLines ( 'c' ) 3930call XgetListFromLines ( 'l' ) 3931endfunc 3932 3933" Tests for the quickfix list id 3934func Xqfid_tests ( cchar ) 3935call s: setup_commands ( a: cchar ) 3936 3937call g: Xsetlist ([], 'f' ) 3938call assert_equal ( 0 , g: Xgetlist ({ 'id' : 0 }). id ) 3939Xexpr '' 3940let start_id = g: Xgetlist ({ 'id' : 0 }). id 3941Xexpr '' |Xexpr '' 3942Xolder 3943call assert_equal ( start_id , g: Xgetlist ({ 'id' : 0 , 'nr' : 1 }). id ) 3944call assert_equal ( start_id + 1 , g: Xgetlist ({ 'id' : 0 , 'nr' : 0 }). id ) 3945call assert_equal ( start_id + 2 , g: Xgetlist ({ 'id' : 0 , 'nr' : '$' }). id ) 3946call assert_equal ( 0 , g: Xgetlist ({ 'id' : 0 , 'nr' : 99 }). id ) 3947call assert_equal ( 2 , g: Xgetlist ({ 'id' : start_id + 1 , 'nr' : 0 }). nr ) 3948call assert_equal ( 0 , g: Xgetlist ({ 'id' : 99 , 'nr' : 0 }). id ) 3949call assert_equal ( 0 , g: Xgetlist ({ 'id' : "abc" , 'nr' : 0 }). id ) 3950 3951call g: Xsetlist ([], 'a' , { 'id' : start_id , 'context' :[ 1 , 2 ]}) 3952call assert_equal ([ 1 , 2 ], g: Xgetlist ({ 'nr' : 1 , 'context' : 1 }). context ) 3953call g: Xsetlist ([], 'a' , { 'id' : start_id + 1 , 'lines' :[ 'F1:10:L10' ]}) 3954call assert_equal ( 'L10' , g: Xgetlist ({ 'nr' : 2 , 'items' : 1 }). items [ 0 ]. text ) 3955call assert_equal ( -1 , g: Xsetlist ([], 'a' , { 'id' : 999 , 'title' : 'Vim' })) 3956call assert_equal ( -1 , g: Xsetlist ([], 'a' , { 'id' : 'abc' , 'title' : 'Vim' })) 3957 3958let qfid = g: Xgetlist ({ 'id' : 0 , 'nr' : 0 }) 3959call g: Xsetlist ([], 'f' ) 3960call assert_equal ( 0 , g: Xgetlist ({ 'id' : qfid , 'nr' : 0 }). id ) 3961endfunc 3962 3963func Test_qf_id () 3964call Xqfid_tests ( 'c' ) 3965call Xqfid_tests ( 'l' ) 3966endfunc 3967 3968func Xqfjump_tests ( cchar ) 3969call s: setup_commands ( a: cchar ) 3970 3971call writefile ([ "Line1\tFoo" , "Line2" ], 'F1' ) 3972call writefile ([ "Line1\tBar" , "Line2" ], 'F2' ) 3973call writefile ([ "Line1\tBaz" , "Line2" ], 'F3' ) 3974 3975call g: Xsetlist ([], 'f' ) 3976 3977" Tests for 3978" Jumping to a line using a pattern 3979" Jumping to a column greater than the last column in a line 3980" Jumping to a line greater than the last line in the file 3981let l = [] 3982for i in range ( 1 , 7 ) 3983call add ( l , {}) 3984endfor 3985let l [ 0 ]. filename = 'F1' 3986let l [ 0 ]. pattern = 'Line1' 3987let l [ 1 ]. filename = 'F2' 3988let l [ 1 ]. pattern = 'Line1' 3989let l [ 2 ]. filename = 'F3' 3990let l [ 2 ]. pattern = 'Line1' 3991let l [ 3 ]. filename = 'F3' 3992let l [ 3 ]. lnum = 1 3993let l [ 3 ]. col = 9 3994let l [ 3 ]. vcol = 1 3995let l [ 4 ]. filename = 'F3' 3996let l [ 4 ]. lnum = 99 3997let l [ 5 ]. filename = 'F3' 3998let l [ 5 ]. lnum = 1 3999let l [ 5 ]. col = 99 4000let l [ 5 ]. vcol = 1 4001let l [ 6 ]. filename = 'F3' 4002let l [ 6 ]. pattern = 'abcxyz' 4003 4004call g: Xsetlist ([], ' ' , { 'items' : l }) 4005Xopen |only 40062 Xnext 4007call assert_equal ( 3 , g: Xgetlist ({ 'idx' : 0 }). idx ) 4008call assert_equal ( 'F3' , @%) 4009Xnext 4010call assert_equal ( 7 , col ( '.' )) 4011Xnext 4012call assert_equal ( 2 , line ( '.' )) 4013Xnext 4014call assert_equal ( 9 , col ( '.' )) 40152 4016Xnext 4017call assert_equal ( 2 , line ( '.' )) 4018 4019if a: cchar == 'l' 4020" When jumping to a location list entry in the location list window and 4021" no usable windows are available, then a new window should be opened. 4022enew ! |new |only 4023call g: Xsetlist ([], 'f' ) 4024setlocal buftype = nofile 4025new 4026let lines =<< trim END 4027F1:1:1:Line1 4028F1:2:2:Line2 4029F2:1:1:Line1 4030F2:2:2:Line2 4031F3:1:1:Line1 4032F3:2:2:Line2 4033END 4034call g: Xsetlist ([], ' ' , { 'lines' : lines }) 4035Xopen 4036let winid = win_getid () 4037wincmd p 4038close 4039call win_gotoid ( winid ) 4040Xnext 4041call assert_equal ( 3 , winnr ( '$' )) 4042call assert_equal ( 1 , winnr ()) 4043call assert_equal ( 2 , line ( '.' )) 4044 4045" When jumping to an entry in the location list window and the window 4046" associated with the location list is not present and a window containing 4047" the file is already present, then that window should be used. 4048close 4049belowright new 4050call g: Xsetlist ([], 'f' ) 4051edit F3 4052call win_gotoid ( winid ) 4053Xlast 4054call assert_equal ( 3 , winnr ()) 4055call assert_equal ( 6 , g: Xgetlist ({ 'size' : 1 }). size ) 4056call assert_equal ( winid , g: Xgetlist ({ 'winid' : 1 }). winid ) 4057endif 4058 4059" Cleanup 4060enew ! 4061new |only 4062 4063call delete ( 'F1' ) 4064call delete ( 'F2' ) 4065call delete ( 'F3' ) 4066endfunc 4067 4068func Test_qfjump () 4069call Xqfjump_tests ( 'c' ) 4070call Xqfjump_tests ( 'l' ) 4071endfunc 4072 4073" Tests for the getqflist() and getloclist() functions when the list is not 4074" present or is empty 4075func Xgetlist_empty_tests ( cchar ) 4076call s: setup_commands ( a: cchar ) 4077 4078" Empty quickfix stack 4079call g: Xsetlist ([], 'f' ) 4080call assert_equal ( '' , g: Xgetlist ({ 'context' : 0 }). context ) 4081call assert_equal ( 0 , g: Xgetlist ({ 'id' : 0 }). id ) 4082call assert_equal ( 0 , g: Xgetlist ({ 'idx' : 0 }). idx ) 4083call assert_equal ([], g: Xgetlist ({ 'items' : 0 }). items ) 4084call assert_equal ( 0 , g: Xgetlist ({ 'nr' : 0 }). nr ) 4085call assert_equal ( 0 , g: Xgetlist ({ 'size' : 0 }). size ) 4086call assert_equal ( '' , g: Xgetlist ({ 'title' : 0 }). title ) 4087call assert_equal ( 0 , g: Xgetlist ({ 'winid' : 0 }). winid ) 4088call assert_equal ( 0 , g: Xgetlist ({ 'changedtick' : 0 }). changedtick ) 4089if a: cchar == 'c' 4090call assert_equal ({ 'context' : '' , 'id' : 0 , 'idx' : 0 , 4091 \'items' : [], 'nr' : 0 , 'size' : 0 , 'qfbufnr' : 0 , 4092 \'title' : '' , 'winid' : 0 , 'changedtick' : 0 , 4093 \'quickfixtextfunc' : '' }, g: Xgetlist ({ 'all' : 0 })) 4094else 4095call assert_equal ({ 'context' : '' , 'id' : 0 , 'idx' : 0 , 4096 \'items' : [], 'nr' : 0 , 'size' : 0 , 'title' : '' , 4097 \'winid' : 0 , 'changedtick' : 0 , 'filewinid' : 0 , 4098 \'qfbufnr' : 0 , 'quickfixtextfunc' : '' }, 4099 \g: Xgetlist ({ 'all' : 0 })) 4100endif 4101 4102" Quickfix window with empty stack 4103silent ! Xopen 4104let qfwinid = ( a: cchar == 'c' ) ? win_getid () : 0 4105let qfbufnr = ( a: cchar == 'c' ) ? bufnr ( '' ) : 0 4106call assert_equal ( qfwinid , g: Xgetlist ({ 'winid' : 0 }). winid ) 4107Xclose 4108 4109" Empty quickfix list 4110Xexpr "" 4111call assert_equal ( '' , g: Xgetlist ({ 'context' : 0 }). context ) 4112call assert_notequal ( 0 , g: Xgetlist ({ 'id' : 0 }). id ) 4113call assert_equal ( 0 , g: Xgetlist ({ 'idx' : 0 }). idx ) 4114call assert_equal ([], g: Xgetlist ({ 'items' : 0 }). items ) 4115call assert_notequal ( 0 , g: Xgetlist ({ 'nr' : 0 }). nr ) 4116call assert_equal ( 0 , g: Xgetlist ({ 'size' : 0 }). size ) 4117call assert_notequal ( '' , g: Xgetlist ({ 'title' : 0 }). title ) 4118call assert_equal ( 0 , g: Xgetlist ({ 'winid' : 0 }). winid ) 4119call assert_equal ( 1 , g: Xgetlist ({ 'changedtick' : 0 }). changedtick ) 4120 4121let qfid = g: Xgetlist ({ 'id' : 0 }). id 4122call g: Xsetlist ([], 'f' ) 4123 4124" Non-existing quickfix identifier 4125call assert_equal ( '' , g: Xgetlist ({ 'id' : qfid , 'context' : 0 }). context ) 4126call assert_equal ( 0 , g: Xgetlist ({ 'id' : qfid }). id ) 4127call assert_equal ( 0 , g: Xgetlist ({ 'id' : qfid , 'idx' : 0 }). idx ) 4128call assert_equal ([], g: Xgetlist ({ 'id' : qfid , 'items' : 0 }). items ) 4129call assert_equal ( 0 , g: Xgetlist ({ 'id' : qfid , 'nr' : 0 }). nr ) 4130call assert_equal ( 0 , g: Xgetlist ({ 'id' : qfid , 'size' : 0 }). size ) 4131call assert_equal ( '' , g: Xgetlist ({ 'id' : qfid , 'title' : 0 }). title ) 4132call assert_equal ( 0 , g: Xgetlist ({ 'id' : qfid , 'winid' : 0 }). winid ) 4133call assert_equal ( 0 , g: Xgetlist ({ 'id' : qfid , 'changedtick' : 0 }). changedtick ) 4134if a: cchar == 'c' 4135call assert_equal ({ 'context' : '' , 'id' : 0 , 'idx' : 0 , 'items' : [], 4136 \'nr' : 0 , 'size' : 0 , 'title' : '' , 'winid' : 0 , 4137 \'qfbufnr' : qfbufnr , 'quickfixtextfunc' : '' , 4138 \'changedtick' : 0 }, g: Xgetlist ({ 'id' : qfid , 'all' : 0 })) 4139else 4140call assert_equal ({ 'context' : '' , 'id' : 0 , 'idx' : 0 , 'items' : [], 4141 \'nr' : 0 , 'size' : 0 , 'title' : '' , 'winid' : 0 , 4142 \'changedtick' : 0 , 'filewinid' : 0 , 'qfbufnr' : 0 , 4143 \'quickfixtextfunc' : '' }, 4144 \g: Xgetlist ({ 'id' : qfid , 'all' : 0 })) 4145endif 4146 4147" Non-existing quickfix list number 4148call assert_equal ( '' , g: Xgetlist ({ 'nr' : 5 , 'context' : 0 }). context ) 4149call assert_equal ( 0 , g: Xgetlist ({ 'nr' : 5 }). nr ) 4150call assert_equal ( 0 , g: Xgetlist ({ 'nr' : 5 , 'idx' : 0 }). idx ) 4151call assert_equal ([], g: Xgetlist ({ 'nr' : 5 , 'items' : 0 }). items ) 4152call assert_equal ( 0 , g: Xgetlist ({ 'nr' : 5 , 'id' : 0 }). id ) 4153call assert_equal ( 0 , g: Xgetlist ({ 'nr' : 5 , 'size' : 0 }). size ) 4154call assert_equal ( '' , g: Xgetlist ({ 'nr' : 5 , 'title' : 0 }). title ) 4155call assert_equal ( 0 , g: Xgetlist ({ 'nr' : 5 , 'winid' : 0 }). winid ) 4156call assert_equal ( 0 , g: Xgetlist ({ 'nr' : 5 , 'changedtick' : 0 }). changedtick ) 4157if a: cchar == 'c' 4158call assert_equal ({ 'context' : '' , 'id' : 0 , 'idx' : 0 , 'items' : [], 4159 \'nr' : 0 , 'size' : 0 , 'title' : '' , 'winid' : 0 , 4160 \'changedtick' : 0 , 'qfbufnr' : qfbufnr , 4161 \'quickfixtextfunc' : '' }, g: Xgetlist ({ 'nr' : 5 , 'all' : 0 })) 4162else 4163call assert_equal ({ 'context' : '' , 'id' : 0 , 'idx' : 0 , 'items' : [], 4164 \'nr' : 0 , 'size' : 0 , 'title' : '' , 'winid' : 0 , 4165 \'changedtick' : 0 , 'filewinid' : 0 , 'qfbufnr' : 0 , 4166 \'quickfixtextfunc' : '' }, g: Xgetlist ({ 'nr' : 5 , 'all' : 0 })) 4167endif 4168endfunc 4169 4170func Test_empty_list_quickfixtextfunc () 4171" This was crashing. Can only reproduce by running it in a separate Vim 4172" instance. 4173let lines =<< trim END 4174func s:Func(o) 4175cgetexpr '0' 4176endfunc 4177cope 4178let &quickfixtextfunc = 's:Func' 4179cgetfile [ex 4180END 4181call writefile ( lines , 'Xquickfixtextfunc' ) 4182call RunVim ([], [], '-e -s -S Xquickfixtextfunc -c qa' ) 4183call delete ( 'Xquickfixtextfunc' ) 4184endfunc 4185 4186func Test_getqflist () 4187call Xgetlist_empty_tests ( 'c' ) 4188call Xgetlist_empty_tests ( 'l' ) 4189endfunc 4190 4191func Test_getqflist_invalid_nr () 4192" The following commands used to crash Vim 4193cexpr "" 4194call getqflist ({ 'nr' : $ XXX_DOES_NOT_EXIST_XXX }) 4195 4196" Cleanup 4197call setqflist ([], 'r' ) 4198endfunc 4199 4200" Tests for the quickfix/location list changedtick 4201func Xqftick_tests ( cchar ) 4202call s: setup_commands ( a: cchar ) 4203 4204call g: Xsetlist ([], 'f' ) 4205 4206Xexpr "F1:10:Line10" 4207let qfid = g: Xgetlist ({ 'id' : 0 }). id 4208call assert_equal ( 1 , g: Xgetlist ({ 'changedtick' : 0 }). changedtick ) 4209Xaddexpr "F2:20:Line20\nF2:21:Line21" 4210call assert_equal ( 2 , g: Xgetlist ({ 'changedtick' : 0 }). changedtick ) 4211call g: Xsetlist ([], 'a' , { 'lines' : [ "F3:30:Line30" , "F3:31:Line31" ]}) 4212call assert_equal ( 3 , g: Xgetlist ({ 'changedtick' : 0 }). changedtick ) 4213call g: Xsetlist ([], 'r' , { 'lines' : [ "F4:40:Line40" ]}) 4214call assert_equal ( 4 , g: Xgetlist ({ 'changedtick' : 0 }). changedtick ) 4215call g: Xsetlist ([], 'a' , { 'title' : 'New Title' }) 4216call assert_equal ( 5 , g: Xgetlist ({ 'changedtick' : 0 }). changedtick ) 4217 4218enew ! 4219call append ( 0 , [ "F5:50:L50" , "F6:60:L60" ]) 4220Xaddbuffer 4221call assert_equal ( 6 , g: Xgetlist ({ 'changedtick' : 0 }). changedtick ) 4222enew ! 4223 4224call g: Xsetlist ([], 'a' , { 'context' : { 'bus' : 'pci' }}) 4225call assert_equal ( 7 , g: Xgetlist ({ 'changedtick' : 0 }). changedtick ) 4226call g: Xsetlist ([{ 'filename' : 'F7' , 'lnum' : 10 , 'text' : 'L7' }, 4227 \{ 'filename' : 'F7' , 'lnum' : 11 , 'text' : 'L11' }], 'a' ) 4228call assert_equal ( 8 , g: Xgetlist ({ 'changedtick' : 0 }). changedtick ) 4229call g: Xsetlist ([{ 'filename' : 'F7' , 'lnum' : 10 , 'text' : 'L7' }, 4230 \{ 'filename' : 'F7' , 'lnum' : 11 , 'text' : 'L11' }], ' ' ) 4231call assert_equal ( 1 , g: Xgetlist ({ 'changedtick' : 0 }). changedtick ) 4232call g: Xsetlist ([{ 'filename' : 'F7' , 'lnum' : 10 , 'text' : 'L7' }, 4233 \{ 'filename' : 'F7' , 'lnum' : 11 , 'text' : 'L11' }], 'r' ) 4234call assert_equal ( 2 , g: Xgetlist ({ 'changedtick' : 0 }). changedtick ) 4235 4236if isdirectory ( "Xone" ) 4237call delete ( "Xone" , 'rf' ) 4238endif 4239call writefile ([ "F8:80:L80" , "F8:81:L81" ], "Xone" ) 4240Xfile Xone 4241call assert_equal ( 1 , g: Xgetlist ({ 'changedtick' : 0 }). changedtick ) 4242Xaddfile Xone 4243call assert_equal ( 2 , g: Xgetlist ({ 'changedtick' : 0 }). changedtick ) 4244 4245" Test case for updating a non-current quickfix list 4246call g: Xsetlist ([], 'f' ) 4247Xexpr "F1:1:L1" 4248Xexpr "F2:2:L2" 4249call g: Xsetlist ([], 'a' , { 'nr' : 1 , "lines" : [ "F10:10:L10" ]}) 4250call assert_equal ( 1 , g: Xgetlist ({ 'changedtick' : 0 }). changedtick ) 4251call assert_equal ( 2 , g: Xgetlist ({ 'nr' : 1 , 'changedtick' : 0 }). changedtick ) 4252 4253call delete ( "Xone" ) 4254endfunc 4255 4256func Test_qf_tick () 4257call Xqftick_tests ( 'c' ) 4258call Xqftick_tests ( 'l' ) 4259endfunc 4260 4261" Test helpgrep with lang specifier 4262func Xtest_helpgrep_with_lang_specifier ( cchar ) 4263call s: setup_commands ( a: cchar ) 4264Xhelpgrep Vim@en 4265call assert_equal ( 'help' , & filetype ) 4266call assert_notequal ( 0 , g: Xgetlist ({ 'nr' : '$' }). nr ) 4267new |only 4268endfunc 4269 4270func Test_helpgrep_with_lang_specifier () 4271call Xtest_helpgrep_with_lang_specifier ( 'c' ) 4272call Xtest_helpgrep_with_lang_specifier ( 'l' ) 4273endfunc 4274 4275" The following test used to crash Vim. 4276" Open the location list window and close the regular window associated with 4277" the location list. When the garbage collection runs now, it incorrectly 4278" marks the location list context as not in use and frees the context. 4279func Test_ll_window_ctx () 4280call setloclist ( 0 , [], 'f' ) 4281call setloclist ( 0 , [], 'a' , { 'context' : []}) 4282lopen |only 4283call test_garbagecollect_now () 4284echo getloclist ( 0 , { 'context' : 1 }). context 4285enew |only 4286endfunc 4287 4288" Similar to the problem above, but for user data. 4289func Test_ll_window_user_data () 4290call setloclist ( 0 , [#{ bufnr : bufnr (), user_data : {}}]) 4291lopen 4292wincmd t 4293close 4294call test_garbagecollect_now () 4295call feedkeys ( "\<CR>" , 'tx' ) 4296call test_garbagecollect_now () 4297 %bwipe ! 4298endfunc 4299 4300" The following test used to crash vim 4301func Test_lfile_crash () 4302sp Xtest 4303au QuickFixCmdPre * bw 4304call assert_fails ( 'lfile' , 'E40:' ) 4305au ! QuickFixCmdPre 4306endfunc 4307 4308" The following test used to crash vim 4309func Test_lbuffer_crash () 4310sv Xtest 4311augroup QF_Test 4312au ! 4313au QuickFixCmdPre , QuickFixCmdPost , BufEnter , BufLeave * bw 4314augroup END 4315lbuffer 4316augroup QF_Test 4317au ! 4318augroup END 4319endfunc 4320 4321" The following test used to crash vim 4322func Test_lexpr_crash () 4323augroup QF_Test 4324au ! 4325au QuickFixCmdPre , QuickFixCmdPost , BufEnter , BufLeave * call setloclist ( 0 , [], 'f' ) 4326augroup END 4327lexpr "" 4328augroup QF_Test 4329au ! 4330augroup END 4331 4332enew |only 4333augroup QF_Test 4334au ! 4335au BufNew * call setloclist ( 0 , [], 'f' ) 4336augroup END 4337lexpr 'x:1:x' 4338augroup QF_Test 4339au ! 4340augroup END 4341 4342enew |only 4343lexpr '' 4344lopen 4345augroup QF_Test 4346au ! 4347au FileType * call setloclist ( 0 , [], 'f' ) 4348augroup END 4349lexpr '' 4350augroup QF_Test 4351au ! 4352augroup END 4353endfunc 4354 4355" The following test used to crash Vim 4356func Test_lvimgrep_crash () 4357" this leaves a swapfile .test_quickfix.vim.swp around, why? 4358sv Xtest 4359augroup QF_Test 4360au ! 4361au QuickFixCmdPre , QuickFixCmdPost , BufEnter , BufLeave * call setloclist ( 0 , [], 'f' ) 4362augroup END 4363lvimgrep quickfix test_quickfix.vim 4364augroup QF_Test 4365au ! 4366augroup END 4367 4368new |only 4369augroup QF_Test 4370au ! 4371au BufEnter * call setloclist ( 0 , [], 'r' ) 4372augroup END 4373call assert_fails ( 'lvimgrep Test_lvimgrep_crash *' , 'E926:' ) 4374augroup QF_Test 4375au ! 4376augroup END 4377 4378enew |only 4379endfunc 4380 4381func Test_lvimgrep_crash2 () 4382au BufNewFile x sfind 4383call assert_fails ( 'lvimgrep x x' , 'E471:' ) 4384call assert_fails ( 'lvimgrep x x x' , 'E471:' ) 4385 4386au ! BufNewFile 4387endfunc 4388 4389" Test for the position of the quickfix and location list window 4390func Test_qfwin_pos () 4391" Open two windows 4392new |only 4393new 4394cexpr ['F1:10:L10'] 4395copen 4396" Quickfix window should be the bottom most window 4397call assert_equal ( 3 , winnr ()) 4398close 4399" Open at the very top 4400wincmd t 4401topleft copen 4402call assert_equal ( 1 , winnr ()) 4403close 4404" open left of the current window 4405wincmd t 4406below new 4407leftabove copen 4408call assert_equal ( 2 , winnr ()) 4409close 4410" open right of the current window 4411rightbelow copen 4412call assert_equal ( 3 , winnr ()) 4413close 4414endfunc 4415 4416" Tests for quickfix/location lists changed by autocommands when 4417" :vimgrep/:lvimgrep commands are running. 4418func Test_vimgrep_autocmd () 4419call setqflist ([], 'f' ) 4420call writefile ([ 'stars' ], 'Xtest1.txt' , 'D' ) 4421call writefile ([ 'stars' ], 'Xtest2.txt' , 'D' ) 4422 4423" Test 1: 4424" When searching for a pattern using :vimgrep, if the quickfix list is 4425" changed by an autocmd, the results should be added to the correct quickfix 4426" list. 4427autocmd BufRead Xtest2.txt cexpr '' |cexpr '' 4428silent vimgrep stars Xtest*.txt 4429call assert_equal ( 1 , getqflist ({ 'nr' : 0 }). nr ) 4430call assert_equal ( 3 , getqflist ({ 'nr' : '$' }). nr ) 4431call assert_equal ( 'Xtest2.txt' , bufname ( getqflist ()[ 1 ]. bufnr )) 4432au ! BufRead Xtest2.txt 4433 4434" Test 2: 4435" When searching for a pattern using :vimgrep, if the quickfix list is 4436" freed, then a error should be given. 4437silent ! %bwipe ! 4438call setqflist ([], 'f' ) 4439autocmd BufRead Xtest2.txt for i in range ( 10 ) |cexpr '' |endfor 4440call assert_fails ( 'vimgrep stars Xtest*.txt' , 'E925:' ) 4441au ! BufRead Xtest2.txt 4442 4443" Test 3: 4444" When searching for a pattern using :lvimgrep, if the location list is 4445" freed, then the command should error out. 4446silent ! %bwipe ! 4447let g: save_winid = win_getid () 4448autocmd BufRead Xtest2.txt call setloclist ( g: save_winid , [], 'f' ) 4449call assert_fails ( 'lvimgrep stars Xtest*.txt' , 'E926:' ) 4450au ! BufRead Xtest2.txt 4451" cleanup the swap files 4452bw ! Xtest2.txt Xtest1.txt 4453 4454call setqflist ([], 'f' ) 4455endfunc 4456 4457" Test for an autocmd changing the current directory when running vimgrep 4458func Xvimgrep_autocmd_cd ( cchar ) 4459call s: setup_commands ( a: cchar ) 4460 4461 %bwipe 4462let save_cwd = getcwd () 4463 4464augroup QF_Test 4465au ! 4466autocmd BufRead * silent cd %:p:h 4467augroup END 4468 446910 Xvimgrep /vim/ Xdir/** 4470let l = g: Xgetlist () 4471call assert_equal ( 'f1.txt' , bufname ( l [ 0 ]. bufnr )) 4472call assert_equal ( 'f2.txt' , fnamemodify ( bufname ( l [ 2 ]. bufnr ), ':t' )) 4473 4474augroup QF_Test 4475au ! 4476augroup END 4477 4478exe 'cd ' . save_cwd 4479endfunc 4480 4481func Test_vimgrep_autocmd_cd () 4482call mkdir ( 'Xdir/a' , 'p' ) 4483call mkdir ( 'Xdir/b' , 'p' ) 4484call writefile ([ 'a_L1_vim' , 'a_L2_vim' ], 'Xdir/a/f1.txt' ) 4485call writefile ([ 'b_L1_vim' , 'b_L2_vim' ], 'Xdir/b/f2.txt' ) 4486call Xvimgrep_autocmd_cd ( 'c' ) 4487call Xvimgrep_autocmd_cd ( 'l' ) 4488 %bwipe 4489call delete ( 'Xdir' , 'rf' ) 4490endfunc 4491 4492" The following test used to crash Vim 4493func Test_lhelpgrep_autocmd () 4494lhelpgrep quickfix 4495augroup QF_Test 4496au ! 4497autocmd QuickFixCmdPost * call setloclist ( 0 , [], 'f' ) 4498augroup END 4499lhelpgrep buffer 4500call assert_equal ( 'help' , & filetype ) 4501call assert_equal ( 0 , getloclist ( 0 , { 'nr' : '$' }). nr ) 4502lhelpgrep tabpage 4503call assert_equal ( 'help' , & filetype ) 4504call assert_equal ( 1 , getloclist ( 0 , { 'nr' : '$' }). nr ) 4505augroup QF_Test 4506au ! 4507augroup END 4508 4509new |only 4510augroup QF_Test 4511au ! 4512au BufEnter * call setqflist ([], 'f' ) 4513augroup END 4514call assert_fails ( 'helpgrep quickfix' , 'E925:' ) 4515" run the test with a help window already open 4516help 4517wincmd w 4518call assert_fails ( 'helpgrep quickfix' , 'E925:' ) 4519augroup QF_Test 4520au ! 4521augroup END 4522 4523new |only 4524augroup QF_Test 4525au ! 4526au BufEnter * call setqflist ([], 'r' ) 4527augroup END 4528call assert_fails ( 'helpgrep quickfix' , 'E925:' ) 4529augroup QF_Test 4530au ! 4531augroup END 4532 4533new |only 4534augroup QF_Test 4535au ! 4536au BufEnter * call setloclist ( 0 , [], 'r' ) 4537augroup END 4538call assert_fails ( 'lhelpgrep quickfix' , 'E926:' ) 4539augroup QF_Test 4540au ! 4541augroup END 4542 4543" Replace the contents of a help window location list when it is still in 4544" use. 4545new |only 4546lhelpgrep quickfix 4547wincmd w 4548augroup QF_Test 4549au ! 4550autocmd WinEnter * call setloclist ( 0 , [], 'r' ) 4551augroup END 4552call assert_fails ( 'lhelpgrep win_getid' , 'E926:' ) 4553augroup QF_Test 4554au ! 4555augroup END 4556 4557 %bw ! 4558endfunc 4559 4560" The following test used to crash Vim 4561func Test_lhelpgrep_autocmd_free_loclist () 4562 %bw ! 4563lhelpgrep quickfix 4564wincmd w 4565augroup QF_Test 4566au ! 4567autocmd WinEnter * call setloclist ( 0 , [], 'f' ) 4568augroup END 4569lhelpgrep win_getid 4570wincmd w 4571wincmd w 4572wincmd w 4573augroup QF_Test 4574au ! 4575augroup END 4576 %bw ! 4577endfunc 4578 4579" Test for shortening/simplifying the file name when opening the 4580" quickfix window or when displaying the quickfix list 4581func Test_shorten_fname () 4582CheckUnix 4583 %bwipe 4584" Create a quickfix list with an absolute path filename 4585let fname = getcwd () . '/test_quickfix.vim' 4586call setqflist ([], ' ' , { 'lines' :[ fname . ":20:Line20" ], 'efm' : '%f:%l:%m' }) 4587call assert_equal ( fname , bufname ( 'test_quickfix.vim' )) 4588" Opening the quickfix window should simplify the file path 4589cwindow 4590call assert_equal ( 'test_quickfix.vim' , bufname ( 'test_quickfix.vim' )) 4591cclose 4592 %bwipe 4593" Create a quickfix list with an absolute path filename 4594call setqflist ([], ' ' , { 'lines' :[ fname . ":20:Line20" ], 'efm' : '%f:%l:%m' }) 4595call assert_equal ( fname , bufname ( 'test_quickfix.vim' )) 4596" Displaying the quickfix list should simplify the file path 4597silent ! clist 4598call assert_equal ( 'test_quickfix.vim' , bufname ( 'test_quickfix.vim' )) 4599" Add a few entries for the same file with different paths and check whether 4600" the buffer name is shortened 4601 %bwipe 4602call setqflist ([], 'f' ) 4603call setqflist ([{ 'filename' : 'test_quickfix.vim' , 'lnum' : 10 }, 4604 \{ 'filename' : '../testdir/test_quickfix.vim' , 'lnum' : 20 }, 4605 \{ 'filename' : fname , 'lnum' : 30 }], ' ' ) 4606copen 4607call assert_equal ([ 'test_quickfix.vim|10| ' , 4608 \'test_quickfix.vim|20| ' , 4609 \'test_quickfix.vim|30| ' ], getline ( 1 , '$' )) 4610cclose 4611endfunc 4612 4613" Quickfix title tests 4614" In the below tests, 'exe "cmd"' is used to invoke the quickfix commands. 4615" Otherwise due to indentation, the title is set with spaces at the beginning 4616" of the command. 4617func Test_qftitle () 4618call writefile ([ "F1:1:Line1" ], 'Xerr' ) 4619 4620" :cexpr 4621exe "cexpr readfile('Xerr')" 4622call assert_equal ( ":cexpr readfile('Xerr')" , getqflist ({ 'title' : 1 }). title ) 4623 4624" :cgetexpr 4625exe "cgetexpr readfile('Xerr')" 4626call assert_equal ( ":cgetexpr readfile('Xerr')" , 4627 \getqflist ({ 'title' : 1 }). title ) 4628 4629" :caddexpr 4630call setqflist ([], 'f' ) 4631exe "caddexpr readfile('Xerr')" 4632call assert_equal ( ":caddexpr readfile('Xerr')" , 4633 \getqflist ({ 'title' : 1 }). title ) 4634 4635" :cbuffer 4636new Xerr 4637exe "cbuffer" 4638call assert_equal ( ':cbuffer (Xerr)' , getqflist ({ 'title' : 1 }). title ) 4639 4640" :cgetbuffer 4641edit Xerr 4642exe "cgetbuffer" 4643call assert_equal ( ':cgetbuffer (Xerr)' , getqflist ({ 'title' : 1 }). title ) 4644 4645" :caddbuffer 4646call setqflist ([], 'f' ) 4647edit Xerr 4648exe "caddbuffer" 4649call assert_equal ( ':caddbuffer (Xerr)' , getqflist ({ 'title' : 1 }). title ) 4650 4651" :cfile 4652exe "cfile Xerr" 4653call assert_equal ( ':cfile Xerr' , getqflist ({ 'title' : 1 }). title ) 4654 4655" :cgetfile 4656exe "cgetfile Xerr" 4657call assert_equal ( ':cgetfile Xerr' , getqflist ({ 'title' : 1 }). title ) 4658 4659" :caddfile 4660call setqflist ([], 'f' ) 4661exe "caddfile Xerr" 4662call assert_equal ( ':caddfile Xerr' , getqflist ({ 'title' : 1 }). title ) 4663 4664" :grep 4665set grepprg = internal 4666exe "grep F1 Xerr" 4667call assert_equal ( ':grep F1 Xerr' , getqflist ({ 'title' : 1 }). title ) 4668 4669" :grepadd 4670call setqflist ([], 'f' ) 4671exe "grepadd F1 Xerr" 4672call assert_equal ( ':grepadd F1 Xerr' , getqflist ({ 'title' : 1 }). title ) 4673set grepprg & vim 4674 4675" :vimgrep 4676exe "vimgrep F1 Xerr" 4677call assert_equal ( ':vimgrep F1 Xerr' , getqflist ({ 'title' : 1 }). title ) 4678 4679" :vimgrepadd 4680call setqflist ([], 'f' ) 4681exe "vimgrepadd F1 Xerr" 4682call assert_equal ( ':vimgrepadd F1 Xerr' , getqflist ({ 'title' : 1 }). title ) 4683 4684call setqflist ([ 'F1:10:L10' ], ' ' ) 4685call assert_equal ( ':setqflist()' , getqflist ({ 'title' : 1 }). title ) 4686 4687call setqflist ([], 'f' ) 4688call setqflist ([ 'F1:10:L10' ], 'a' ) 4689call assert_equal ( ':setqflist()' , getqflist ({ 'title' : 1 }). title ) 4690 4691call setqflist ([], 'f' ) 4692call setqflist ([ 'F1:10:L10' ], 'r' ) 4693call assert_equal ( ':setqflist()' , getqflist ({ 'title' : 1 }). title ) 4694 4695close 4696call delete ( 'Xerr' ) 4697 4698call setqflist ([], ' ' , { 'title' : 'Errors' }) 4699copen 4700call assert_equal ( 'Errors' , w: quickfix_title ) 4701call setqflist ([], 'r' , { 'items' : [{ 'filename' : 'a.c' , 'lnum' : 10 }]}) 4702call assert_equal ( 'Errors' , w: quickfix_title ) 4703cclose 4704 4705" Switching to another quickfix list in one tab page should update the 4706" quickfix window title and statusline in all the other tab pages also 4707call setqflist ([], 'f' ) 4708 %bw ! 4709cgetexpr ['file_one:1:1: error in the first quickfix list'] 4710call setqflist ([], 'a' , { 'title' : 'first quickfix list' }) 4711cgetexpr ['file_two:2:1: error in the second quickfix list'] 4712call setqflist ([], 'a' , { 'title' : 'second quickfix list' }) 4713copen 4714wincmd t 4715tabnew two 4716copen 4717wincmd t 4718colder 4719call assert_equal ( 'first quickfix list' , gettabwinvar ( 1 , 2 , 'quickfix_title' )) 4720call assert_equal ( 'first quickfix list' , gettabwinvar ( 2 , 2 , 'quickfix_title' )) 4721call assert_equal ( 1 , tabpagewinnr ( 1 )) 4722call assert_equal ( 1 , tabpagewinnr ( 2 )) 4723tabnew 4724call setqflist ([], 'a' , { 'title' : 'new quickfix title' }) 4725call assert_equal ( 'new quickfix title' , gettabwinvar ( 1 , 2 , 'quickfix_title' )) 4726call assert_equal ( 'new quickfix title' , gettabwinvar ( 2 , 2 , 'quickfix_title' )) 4727 %bw ! 4728endfunc 4729 4730func Test_lbuffer_with_bwipe () 4731new 4732new 4733augroup nasty 4734au QuickFixCmdPre , QuickFixCmdPost , BufEnter , BufLeave * bwipe 4735augroup END 4736lbuffer 4737augroup nasty 4738au ! 4739augroup END 4740endfunc 4741 4742" Test for an autocmd freeing the quickfix/location list when cexpr/lexpr is 4743" running 4744func Xexpr_acmd_freelist ( cchar ) 4745call s: setup_commands ( a: cchar ) 4746 4747" This was using freed memory (but with what events?) 4748augroup nasty 4749au QuickFixCmdPre , QuickFixCmdPost , BufEnter , BufLeave * call g: Xsetlist ([], 'f' ) 4750augroup END 4751Xexpr "x" 4752augroup nasty 4753au ! 4754augroup END 4755endfunc 4756 4757func Test_cexpr_acmd_freelist () 4758call Xexpr_acmd_freelist ( 'c' ) 4759call Xexpr_acmd_freelist ( 'l' ) 4760endfunc 4761 4762" Test for commands that create a new quickfix/location list and jump to the 4763" first error automatically. 4764func Xjumpto_first_error_test ( cchar ) 4765call s: setup_commands ( a: cchar ) 4766 4767call s: create_test_file ( 'Xtestfile1' ) 4768call s: create_test_file ( 'Xtestfile2' ) 4769let l = [ 'Xtestfile1:2:Line2' , 'Xtestfile2:4:Line4' ] 4770 4771" Test for cexpr/lexpr 4772enew 4773Xexpr l 4774call assert_equal ( 'Xtestfile1' , @%) 4775call assert_equal ( 2 , line ( '.' )) 4776 4777" Test for cfile/lfile 4778enew 4779call writefile ( l , 'Xerr' ) 4780Xfile Xerr 4781call assert_equal ( 'Xtestfile1' , @%) 4782call assert_equal ( 2 , line ( '.' )) 4783 4784" Test for cbuffer/lbuffer 4785edit Xerr 4786Xbuffer 4787call assert_equal ( 'Xtestfile1' , @%) 4788call assert_equal ( 2 , line ( '.' )) 4789 4790call delete ( 'Xerr' ) 4791call delete ( 'Xtestfile1' ) 4792call delete ( 'Xtestfile2' ) 4793endfunc 4794 4795func Test_jumpto_first_error () 4796call Xjumpto_first_error_test ( 'c' ) 4797call Xjumpto_first_error_test ( 'l' ) 4798endfunc 4799 4800" Test for a quickfix autocmd changing the quickfix/location list before 4801" jumping to the first error in the new list. 4802func Xautocmd_changelist ( cchar ) 4803call s: setup_commands ( a: cchar ) 4804 4805" Test for cfile/lfile 4806call s: create_test_file ( 'Xtestfile1' ) 4807call s: create_test_file ( 'Xtestfile2' ) 4808Xexpr 'Xtestfile1:2:Line2' 4809autocmd QuickFixCmdPost * Xolder 4810call writefile ([ 'Xtestfile2:4:Line4' ], 'Xerr' ) 4811Xfile Xerr 4812call assert_equal ( 'Xtestfile2' , @%) 4813call assert_equal ( 4 , line ( '.' )) 4814autocmd ! QuickFixCmdPost 4815 4816" Test for cbuffer/lbuffer 4817call g: Xsetlist ([], 'f' ) 4818Xexpr 'Xtestfile1:2:Line2' 4819autocmd QuickFixCmdPost * Xolder 4820call writefile ([ 'Xtestfile2:4:Line4' ], 'Xerr' ) 4821edit Xerr 4822Xbuffer 4823call assert_equal ( 'Xtestfile2' , @%) 4824call assert_equal ( 4 , line ( '.' )) 4825autocmd ! QuickFixCmdPost 4826 4827" Test for cexpr/lexpr 4828call g: Xsetlist ([], 'f' ) 4829Xexpr 'Xtestfile1:2:Line2' 4830autocmd QuickFixCmdPost * Xolder 4831Xexpr 'Xtestfile2:4:Line4' 4832call assert_equal ( 'Xtestfile2' , @%) 4833call assert_equal ( 4 , line ( '.' )) 4834autocmd ! QuickFixCmdPost 4835 4836" The grepprg may not be set on non-Unix systems 4837if has ( 'unix' ) 4838" Test for grep/lgrep 4839call g: Xsetlist ([], 'f' ) 4840Xexpr 'Xtestfile1:2:Line2' 4841autocmd QuickFixCmdPost * Xolder 4842silent Xgrep Line5 Xtestfile2 4843call assert_equal ( 'Xtestfile2' , @%) 4844call assert_equal ( 5 , line ( '.' )) 4845autocmd ! QuickFixCmdPost 4846endif 4847 4848" Test for vimgrep/lvimgrep 4849call g: Xsetlist ([], 'f' ) 4850Xexpr 'Xtestfile1:2:Line2' 4851autocmd QuickFixCmdPost * Xolder 4852silent Xvimgrep Line5 Xtestfile2 4853call assert_equal ( 'Xtestfile2' , @%) 4854call assert_equal ( 5 , line ( '.' )) 4855autocmd ! QuickFixCmdPost 4856 4857" Test for autocommands clearing the quickfix list before jumping to the 4858" first error. This should not result in an error 4859autocmd QuickFixCmdPost * call g: Xsetlist ([], 'r' ) 4860let v: errmsg = '' 4861" Test for cfile/lfile 4862Xfile Xerr 4863call assert_true ( v: errmsg !~# 'E42:' ) 4864" Test for cbuffer/lbuffer 4865edit Xerr 4866Xbuffer 4867call assert_true ( v: errmsg !~# 'E42:' ) 4868" Test for cexpr/lexpr 4869Xexpr 'Xtestfile2:4:Line4' 4870call assert_true ( v: errmsg !~# 'E42:' ) 4871" Test for grep/lgrep 4872" The grepprg may not be set on non-Unix systems 4873if has ( 'unix' ) 4874silent Xgrep Line5 Xtestfile2 4875call assert_true ( v: errmsg !~# 'E42:' ) 4876endif 4877" Test for vimgrep/lvimgrep 4878call assert_fails ( 'silent Xvimgrep Line5 Xtestfile2' , 'E480:' ) 4879autocmd ! QuickFixCmdPost 4880 4881call delete ( 'Xerr' ) 4882call delete ( 'Xtestfile1' ) 4883call delete ( 'Xtestfile2' ) 4884endfunc 4885 4886func Test_autocmd_changelist () 4887call Xautocmd_changelist ( 'c' ) 4888call Xautocmd_changelist ( 'l' ) 4889endfunc 4890 4891" Tests for the ':filter /pat/ clist' command 4892func Test_filter_clist () 4893cexpr ['Xfile1:10:10:Line 10','Xfile2:15:15:Line 15' ] 4894call assert_equal ([ ' 2 Xfile2:15 col 15: Line 15' ], 4895 \split ( execute ( 'filter /Line 15/ clist' ), "\n" )) 4896call assert_equal ([ ' 1 Xfile1:10 col 10: Line 10' ], 4897 \split ( execute ( 'filter /Xfile1/ clist' ), "\n" )) 4898call assert_equal ([], split ( execute ( 'filter /abc/ clist' ), "\n" )) 4899 4900call setqflist ([{ 'module' : 'abc' , 'pattern' : 'pat1' }, 4901 \{ 'module' : 'pqr' , 'pattern' : 'pat2' }], ' ' ) 4902call assert_equal ([ ' 2 pqr:pat2: ' ], 4903 \split ( execute ( 'filter /pqr/ clist' ), "\n" )) 4904call assert_equal ([ ' 1 abc:pat1: ' ], 4905 \split ( execute ( 'filter /pat1/ clist' ), "\n" )) 4906endfunc 4907 4908" Tests for the "CTRL-W <CR>" command. 4909func Xview_result_split_tests ( cchar ) 4910call s: setup_commands ( a: cchar ) 4911 4912" Test that "CTRL-W <CR>" in a qf/ll window fails with empty list. 4913call g: Xsetlist ([]) 4914Xopen 4915let l: win_count = winnr ( '$' ) 4916call assert_fails ( 'execute "normal! \<C-W>\<CR>"' , 'E42' ) 4917call assert_equal ( l: win_count , winnr ( '$' )) 4918Xclose 4919endfunc 4920 4921func Test_view_result_split () 4922call Xview_result_split_tests ( 'c' ) 4923call Xview_result_split_tests ( 'l' ) 4924endfunc 4925 4926" Test that :cc sets curswant 4927func Test_curswant () 4928helpgrep quickfix 4929normal ! llll 49301 cc 4931call assert_equal ( getcurpos ()[ 4 ], virtcol ( '.' )) 4932cclose |helpclose 4933endfunc 4934 4935" Test for opening a file from the quickfix window using CTRL-W <Enter> 4936" doesn't leave an empty buffer around. 4937func Test_splitview () 4938call s: create_test_file ( 'Xtestfile1' ) 4939call s: create_test_file ( 'Xtestfile2' ) 4940new |only 4941let last_bufnr = bufnr ( 'Test_sv_1' , 1 ) 4942let l = [ 'Xtestfile1:2:Line2' , 'Xtestfile2:4:Line4' ] 4943cgetexpr l 4944copen 4945let numbufs = len ( getbufinfo ()) 4946exe "normal \<C-W>\<CR>" 4947copen 4948exe "normal j\<C-W>\<CR>" 4949" Make sure new empty buffers are not created 4950call assert_equal ( numbufs , len ( getbufinfo ())) 4951" Creating a new buffer should use the next available buffer number 4952call assert_equal ( last_bufnr + 4 , bufnr ( "Test_sv_2" , 1 )) 4953bwipe Test_sv_1 4954bwipe Test_sv_2 4955new |only 4956 4957" When split opening files from location list window, make sure that two 4958" windows doesn't refer to the same location list 4959lgetexpr l 4960let locid = getloclist ( 0 , { 'id' : 0 }). id 4961lopen 4962exe "normal \<C-W>\<CR>" 4963call assert_notequal ( locid , getloclist ( 0 , { 'id' : 0 }). id ) 4964call assert_equal ( 0 , getloclist ( 0 , { 'winid' : 0 }). winid ) 4965new |only 4966 4967" When split opening files from a helpgrep location list window, a new help 4968" window should be opened with a copy of the location list. 4969lhelpgrep window 4970let locid = getloclist ( 0 , { 'id' : 0 }). id 4971lwindow 4972exe "normal j\<C-W>\<CR>" 4973call assert_notequal ( locid , getloclist ( 0 , { 'id' : 0 }). id ) 4974call assert_equal ( 0 , getloclist ( 0 , { 'winid' : 0 }). winid ) 4975new |only 4976 4977" Using :split or :vsplit from a quickfix window should behave like a :new 4978" or a :vnew command 4979copen 4980split 4981call assert_equal ( 3 , winnr ( '$' )) 4982let l = getwininfo () 4983call assert_equal ([ 0 , 0 , 1 ], [ l [ 0 ]. quickfix , l [ 1 ]. quickfix , l [ 2 ]. quickfix ]) 4984close 4985copen 4986vsplit 4987let l = getwininfo () 4988call assert_equal ([ 0 , 0 , 1 ], [ l [ 0 ]. quickfix , l [ 1 ]. quickfix , l [ 2 ]. quickfix ]) 4989new |only 4990 4991call delete ( 'Xtestfile1' ) 4992call delete ( 'Xtestfile2' ) 4993endfunc 4994 4995" Test for parsing entries using visual screen column 4996func Test_viscol () 4997enew 4998call writefile ([ "Col1\tCol2\tCol3" ], 'Xfile1' , 'D' ) 4999edit Xfile1 5000 5001" Use byte offset for column number 5002set efm & 5003cexpr "Xfile1:1:5:XX\nXfile1:1:9:YY\nXfile1:1:20:ZZ" 5004call assert_equal ([ 5 , 8 ], [ col ( '.' ), virtcol ( '.' )]) 5005cnext 5006call assert_equal ([ 9 , 12 ], [ col ( '.' ), virtcol ( '.' )]) 5007cnext 5008call assert_equal ([ 14 , 20 ], [ col ( '.' ), virtcol ( '.' )]) 5009 5010" Use screen column offset for column number 5011set efm = %f:%l:%v:%m 5012cexpr "Xfile1:1:8:XX\nXfile1:1:12:YY\nXfile1:1:20:ZZ" 5013call assert_equal ([ 5 , 8 ], [ col ( '.' ), virtcol ( '.' )]) 5014cnext 5015call assert_equal ([ 9 , 12 ], [ col ( '.' ), virtcol ( '.' )]) 5016cnext 5017call assert_equal ([ 14 , 20 ], [ col ( '.' ), virtcol ( '.' )]) 5018cexpr "Xfile1:1:6:XX\nXfile1:1:15:YY\nXfile1:1:24:ZZ" 5019call assert_equal ([ 5 , 8 ], [ col ( '.' ), virtcol ( '.' )]) 5020cnext 5021call assert_equal ([ 10 , 16 ], [ col ( '.' ), virtcol ( '.' )]) 5022cnext 5023call assert_equal ([ 14 , 20 ], [ col ( '.' ), virtcol ( '.' )]) 5024 5025enew 5026call writefile ([ "Col1\täü\töß\tCol4" ], 'Xfile1' ) 5027 5028" Use byte offset for column number 5029set efm & 5030cexpr "Xfile1:1:8:XX\nXfile1:1:11:YY\nXfile1:1:16:ZZ" 5031call assert_equal ([ 8 , 10 ], [ col ( '.' ), virtcol ( '.' )]) 5032cnext 5033call assert_equal ([ 11 , 17 ], [ col ( '.' ), virtcol ( '.' )]) 5034cnext 5035call assert_equal ([ 16 , 25 ], [ col ( '.' ), virtcol ( '.' )]) 5036 5037" Use screen column offset for column number 5038set efm = %f:%l:%v:%m 5039cexpr "Xfile1:1:10:XX\nXfile1:1:17:YY\nXfile1:1:25:ZZ" 5040call assert_equal ([ 8 , 10 ], [ col ( '.' ), virtcol ( '.' )]) 5041cnext 5042call assert_equal ([ 11 , 17 ], [ col ( '.' ), virtcol ( '.' )]) 5043cnext 5044call assert_equal ([ 16 , 25 ], [ col ( '.' ), virtcol ( '.' )]) 5045 5046" Use screen column number with a multi-line error message 5047enew 5048call writefile ([ "à test" ], 'Xfile1' ) 5049set efm = %E===\ %f\ ===,%C%l:%v,%Z%m 5050cexpr ["=== Xfile1 ===","1:3" ,"errormsg" ] 5051call assert_equal ( 'Xfile1' , @%) 5052call assert_equal ([ 0 , 1 , 4 , 0 ], getpos ( '.' )) 5053 5054" Repeat previous test with byte offset %c: ensure that fix to issue #7145 5055" does not break this 5056set efm = %E===\ %f\ ===,%C%l:%c,%Z%m 5057cexpr ["=== Xfile1 ===","1:3" ,"errormsg" ] 5058call assert_equal ( 'Xfile1' , @%) 5059call assert_equal ([ 0 , 1 , 3 , 0 ], getpos ( '.' )) 5060 5061enew |only 5062set efm & 5063endfunc 5064 5065" Test that '%v' is not affected by 'tabstop': a <tab> is always counted as 5066" 8 screen columns, matching the column numbers reported by compilers. 5067func Test_viscol_tabstop () 5068enew 5069call writefile ([ "\tABCDEFGH" ], 'Xfile1' , 'D' ) 5070edit Xfile1 5071set efm = %f:%l:%v:%m 5072 5073" gcc reports column 9 for 'A' (the <tab> expands to 8 columns). The jump 5074" must land on 'A' (byte 2) for any 'tabstop' value. 5075for ts in [ 8 , 4 , 2 , 13 ] 5076exe 'setlocal tabstop=' .. ts 5077cexpr "Xfile1:1:9:XX" 5078call assert_equal ( 2 , col ( '.' ), 'tabstop=' .. ts ) 5079endfor 5080 5081" A multi-byte character after the tab: 'ä' is 2 bytes but 1 screen cell, 5082" so screen column 10 is the next character 'b' (byte 4). 5083call writefile ([ "\täbc" ], 'Xfile1' ) 5084edit ! Xfile1 5085setlocal tabstop = 4 5086cexpr "Xfile1:1:10:XX" 5087call assert_equal ( 4 , col ( '.' )) 5088 5089enew |only 5090set efm & 5091endfunc 5092 5093" Test for the quickfix window buffer 5094func Xqfbuf_test ( cchar ) 5095call s: setup_commands ( a: cchar ) 5096 5097" Quickfix buffer should be reused across closing and opening a quickfix 5098" window 5099Xexpr "F1:10:Line10" 5100Xopen 5101let qfbnum = bufnr ( '' ) 5102Xclose 5103" Even after the quickfix window is closed, the buffer should be loaded 5104call assert_true ( bufloaded ( qfbnum )) 5105call assert_true ( qfbnum , g: Xgetlist ({ 'qfbufnr' : 0 }). qfbufnr ) 5106Xopen 5107" Buffer should be reused when opening the window again 5108call assert_equal ( qfbnum , bufnr ( '' )) 5109Xclose 5110 5111" When quickfix buffer is wiped out, getqflist() should return 0 5112 %bw ! 5113Xexpr "" 5114Xopen 5115bw ! 5116call assert_equal ( 0 , g: Xgetlist ({ 'qfbufnr' : 0 }). qfbufnr ) 5117 5118if a: cchar == 'l' 5119 %bwipe 5120" For a location list, when both the file window and the location list 5121" window for the list are closed, then the buffer should be freed. 5122new |only 5123lexpr "F1:10:Line10" 5124let wid = win_getid () 5125lopen 5126let qfbnum = bufnr ( '' ) 5127call assert_match ( qfbnum . ' %a- "\[Location List]"' , execute ( 'ls' )) 5128close 5129" When the location list window is closed, the buffer name should not 5130" change to 'Quickfix List' 5131call assert_match ( qfbnum . 'u h- "\[Location List]"' , execute ( 'ls!' )) 5132call assert_true ( bufloaded ( qfbnum )) 5133 5134" After deleting a location list buffer using ":bdelete", opening the 5135" location list window should mark the buffer as a location list buffer. 5136exe "bdelete " . qfbnum 5137lopen 5138call assert_equal ( "quickfix" , & buftype ) 5139call assert_equal ( 1 , getwininfo ( win_getid ( winnr ()))[ 0 ]. loclist ) 5140call assert_equal ( wid , getloclist ( 0 , { 'filewinid' : 0 }). filewinid ) 5141call assert_false ( & swapfile ) 5142lclose 5143 5144" When the location list is cleared for the window, the buffer should be 5145" removed 5146call setloclist ( 0 , [], 'f' ) 5147call assert_false ( bufexists ( qfbnum )) 5148call assert_equal ( 0 , getloclist ( 0 , { 'qfbufnr' : 0 }). qfbufnr ) 5149 5150" When the location list is freed with the location list window open, the 5151" location list buffer should not be lost. It should be reused when the 5152" location list is again populated. 5153lexpr "F1:10:Line10" 5154lopen 5155let wid = win_getid () 5156let qfbnum = bufnr ( '' ) 5157wincmd p 5158call setloclist ( 0 , [], 'f' ) 5159lexpr "F1:10:Line10" 5160lopen 5161call assert_equal ( wid , win_getid ()) 5162call assert_equal ( qfbnum , bufnr ( '' )) 5163lclose 5164 5165" When the window with the location list is closed, the buffer should be 5166" removed 5167new |only 5168call assert_false ( bufexists ( qfbnum )) 5169endif 5170endfunc 5171 5172func Test_qfbuf () 5173call Xqfbuf_test ( 'c' ) 5174call Xqfbuf_test ( 'l' ) 5175endfunc 5176 5177" If there is an autocmd to use only one window, then opening the location 5178" list window used to crash Vim. 5179func Test_winonly_autocmd () 5180call s: create_test_file ( 'Xtest1' ) 5181" Autocmd to show only one Vim window at a time 5182autocmd WinEnter * only 5183new 5184" Load the location list 5185lexpr "Xtest1:5:Line5\nXtest1:10:Line10\nXtest1:15:Line15" 5186let loclistid = getloclist ( 0 , { 'id' : 0 }). id 5187" Open the location list window. Only this window will be shown and the file 5188" window is closed. 5189lopen 5190call assert_equal ( loclistid , getloclist ( 0 , { 'id' : 0 }). id ) 5191" Jump to an entry in the location list and make sure that the cursor is 5192" positioned correctly. 5193ll 3 5194call assert_equal ( loclistid , getloclist ( 0 , { 'id' : 0 }). id ) 5195call assert_equal ( 'Xtest1' , @%) 5196call assert_equal ( 15 , line ( '.' )) 5197" Cleanup 5198autocmd ! WinEnter 5199new |only 5200call delete ( 'Xtest1' ) 5201endfunc 5202 5203" Test to make sure that an empty quickfix buffer is not reused for loading 5204" a normal buffer. 5205func Test_empty_qfbuf () 5206enew |only 5207call writefile ([ "Test" ], 'Xfile1' ) 5208call setqflist ([], 'f' ) 5209copen |only 5210let qfbuf = bufnr ( '' ) 5211edit Xfile1 5212call assert_notequal ( qfbuf , bufnr ( '' )) 5213enew 5214call delete ( 'Xfile1' ) 5215endfunc 5216 5217" Test for the :cbelow, :cabove, :lbelow and :labove commands. 5218" And for the :cafter, :cbefore, :lafter and :lbefore commands. 5219func Xtest_below ( cchar ) 5220call s: setup_commands ( a: cchar ) 5221 5222" No quickfix/location list 5223call assert_fails ( 'Xbelow' , 'E42:' ) 5224call assert_fails ( 'Xabove' , 'E42:' ) 5225call assert_fails ( 'Xbefore' , 'E42:' ) 5226call assert_fails ( 'Xafter' , 'E42:' ) 5227 5228" Empty quickfix/location list 5229call g: Xsetlist ([]) 5230call assert_fails ( 'Xbelow' , 'E42:' ) 5231call assert_fails ( 'Xabove' , 'E42:' ) 5232call assert_fails ( 'Xbefore' , 'E42:' ) 5233call assert_fails ( 'Xafter' , 'E42:' ) 5234 5235call s: create_test_file ( 'X1' ) 5236call s: create_test_file ( 'X2' ) 5237call s: create_test_file ( 'X3' ) 5238call s: create_test_file ( 'X4' ) 5239 5240" Invalid entries 5241edit X1 5242call g: Xsetlist ([ "E1" , "E2" ]) 5243call assert_fails ( 'Xbelow' , 'E42:' ) 5244call assert_fails ( 'Xabove' , 'E42:' ) 5245call assert_fails ( '3Xbelow' , 'E42:' ) 5246call assert_fails ( '4Xabove' , 'E42:' ) 5247call assert_fails ( 'Xbefore' , 'E42:' ) 5248call assert_fails ( 'Xafter' , 'E42:' ) 5249call assert_fails ( '3Xbefore' , 'E42:' ) 5250call assert_fails ( '4Xafter' , 'E42:' ) 5251 5252" Test the commands with various arguments 5253Xexpr ["X1:5:3:L5","X2:5:2:L5" ,"X2:10:3:L10" ,"X2:15:4:L15" ,"X3:3:5:L3" ] 5254edit + 7 X2 5255Xabove 5256call assert_equal ([ 'X2' , 5 ], [ @%, line ( '.' )]) 5257call assert_fails ( 'Xabove' , 'E553:' ) 5258normal 7G 5259Xbefore 5260call assert_equal ([ 'X2' , 5 , 2 ], [ @%, line ( '.' ), col ( '.' )]) 5261call assert_fails ( 'Xbefore' , 'E553:' ) 5262 5263normal 2j 5264Xbelow 5265call assert_equal ([ 'X2' , 10 ], [ @%, line ( '.' )]) 5266normal 7G 5267Xafter 5268call assert_equal ([ 'X2' , 10 , 3 ], [ @%, line ( '.' ), col ( '.' )]) 5269 5270" Last error in this file 5271Xbelow 99 5272call assert_equal ([ 'X2' , 15 ], [ @%, line ( '.' )]) 5273call assert_fails ( 'Xbelow' , 'E553:' ) 5274normal gg 5275Xafter 99 5276call assert_equal ([ 'X2' , 15 , 4 ], [ @%, line ( '.' ), col ( '.' )]) 5277call assert_fails ( 'Xafter' , 'E553:' ) 5278 5279" First error in this file 5280Xabove 99 5281call assert_equal ([ 'X2' , 5 ], [ @%, line ( '.' )]) 5282call assert_fails ( 'Xabove' , 'E553:' ) 5283normal G 5284Xbefore 99 5285call assert_equal ([ 'X2' , 5 , 2 ], [ @%, line ( '.' ), col ( '.' )]) 5286call assert_fails ( 'Xbefore' , 'E553:' ) 5287 5288normal gg 5289Xbelow 2 5290call assert_equal ([ 'X2' , 10 ], [ @%, line ( '.' )]) 5291normal gg 5292Xafter 2 5293call assert_equal ([ 'X2' , 10 , 3 ], [ @%, line ( '.' ), col ( '.' )]) 5294 5295normal G 5296Xabove 2 5297call assert_equal ([ 'X2' , 10 ], [ @%, line ( '.' )]) 5298normal G 5299Xbefore 2 5300call assert_equal ([ 'X2' , 10 , 3 ], [ @%, line ( '.' ), col ( '.' )]) 5301 5302edit X4 5303call assert_fails ( 'Xabove' , 'E42:' ) 5304call assert_fails ( 'Xbelow' , 'E42:' ) 5305call assert_fails ( 'Xbefore' , 'E42:' ) 5306call assert_fails ( 'Xafter' , 'E42:' ) 5307if a: cchar == 'l' 5308" If a buffer has location list entries from some other window but not 5309" from the current window, then the commands should fail. 5310edit X1 |split |call setloclist ( 0 , [], 'f' ) 5311call assert_fails ( 'Xabove' , 'E776:' ) 5312call assert_fails ( 'Xbelow' , 'E776:' ) 5313call assert_fails ( 'Xbefore' , 'E776:' ) 5314call assert_fails ( 'Xafter' , 'E776:' ) 5315close 5316endif 5317 5318" Test for lines with multiple quickfix entries 5319let lines =<< trim END 5320X1:5:L5 5321X2:5:1:L5_1 5322X2:5:2:L5_2 5323X2:5:3:L5_3 5324X2:10:1:L10_1 5325X2:10:2:L10_2 5326X2:10:3:L10_3 5327X2:15:1:L15_1 5328X2:15:2:L15_2 5329X2:15:3:L15_3 5330X3:3:L3 5331END 5332Xexpr lines 5333edit + 1 X2 5334Xbelow 2 5335call assert_equal ([ 'X2' , 10 , 1 ], [ @%, line ( '.' ), col ( '.' )]) 5336normal 1G 5337Xafter 2 5338call assert_equal ([ 'X2' , 5 , 2 ], [ @%, line ( '.' ), col ( '.' )]) 5339 5340normal gg 5341Xbelow 99 5342call assert_equal ([ 'X2' , 15 , 1 ], [ @%, line ( '.' ), col ( '.' )]) 5343normal gg 5344Xafter 99 5345call assert_equal ([ 'X2' , 15 , 3 ], [ @%, line ( '.' ), col ( '.' )]) 5346 5347normal G 5348Xabove 2 5349call assert_equal ([ 'X2' , 10 , 1 ], [ @%, line ( '.' ), col ( '.' )]) 5350normal G 5351Xbefore 2 5352call assert_equal ([ 'X2' , 15 , 2 ], [ @%, line ( '.' ), col ( '.' )]) 5353 5354normal G 5355Xabove 99 5356call assert_equal ([ 'X2' , 5 , 1 ], [ @%, line ( '.' ), col ( '.' )]) 5357normal G 5358Xbefore 99 5359call assert_equal ([ 'X2' , 5 , 1 ], [ @%, line ( '.' ), col ( '.' )]) 5360 5361normal 10G 5362Xabove 5363call assert_equal ([ 'X2' , 5 , 1 ], [ @%, line ( '.' ), col ( '.' )]) 5364normal 10G$ 53652 Xbefore 5366call assert_equal ([ 'X2' , 10 , 2 ], [ @%, line ( '.' ), col ( '.' )]) 5367 5368normal 10G 5369Xbelow 5370call assert_equal ([ 'X2' , 15 , 1 ], [ @%, line ( '.' ), col ( '.' )]) 5371normal 9G 53725 Xafter 5373call assert_equal ([ 'X2' , 15 , 2 ], [ @%, line ( '.' ), col ( '.' )]) 5374 5375" Invalid range 5376if a: cchar == 'c' 5377call assert_fails ( '-2cbelow' , 'E16:' ) 5378call assert_fails ( '-2cafter' , 'E16:' ) 5379else 5380call assert_fails ( '-2lbelow' , 'E16:' ) 5381call assert_fails ( '-2lafter' , 'E16:' ) 5382endif 5383 5384call delete ( 'X1' ) 5385call delete ( 'X2' ) 5386call delete ( 'X3' ) 5387call delete ( 'X4' ) 5388endfunc 5389 5390func Test_cbelow () 5391call Xtest_below ( 'c' ) 5392call Xtest_below ( 'l' ) 5393endfunc 5394 5395func Test_quickfix_count () 5396let commands =<< trim END 5397cNext 5398cNfile 5399cabove 5400cbelow 5401cfirst 5402clast 5403cnewer 5404cnext 5405cnfile 5406colder 5407cprevious 5408crewind 5409lNext 5410lNfile 5411labove 5412lbelow 5413lfirst 5414llast 5415lnewer 5416lnext 5417lnfile 5418lolder 5419lprevious 5420lrewind 5421END 5422for cmd in commands 5423call assert_fails ( '-1' .. cmd , 'E16:' ) 5424call assert_fails ( '.' .. cmd , 'E16:' ) 5425call assert_fails ( '%' .. cmd , 'E16:' ) 5426call assert_fails ( '$' .. cmd , 'E16:' ) 5427endfor 5428endfunc 5429 5430" Test for aborting quickfix commands using QuickFixCmdPre 5431func Xtest_qfcmd_abort ( cchar ) 5432call s: setup_commands ( a: cchar ) 5433 5434call g: Xsetlist ([], 'f' ) 5435 5436" cexpr/lexpr 5437let e = '' 5438try 5439Xexpr ["F1:10:Line10","F2:20:Line20" ] 5440catch /.*/ 5441let e = v: exception 5442endtry 5443call assert_equal ( 'AbortCmd' , e ) 5444call assert_equal ( 0 , g: Xgetlist ({ 'nr' : '$' }). nr ) 5445 5446" cfile/lfile 5447call writefile ([ "F1:10:Line10" , "F2:20:Line20" ], 'Xfile1' ) 5448let e = '' 5449try 5450Xfile Xfile1 5451catch /.*/ 5452let e = v: exception 5453endtry 5454call assert_equal ( 'AbortCmd' , e ) 5455call assert_equal ( 0 , g: Xgetlist ({ 'nr' : '$' }). nr ) 5456call delete ( 'Xfile1' ) 5457 5458" cgetbuffer/lgetbuffer 5459enew ! 5460call append ( 0 , [ "F1:10:Line10" , "F2:20:Line20" ]) 5461let e = '' 5462try 5463Xgetbuffer 5464catch /.*/ 5465let e = v: exception 5466endtry 5467call assert_equal ( 'AbortCmd' , e ) 5468call assert_equal ( 0 , g: Xgetlist ({ 'nr' : '$' }). nr ) 5469enew ! 5470 5471" vimgrep/lvimgrep 5472let e = '' 5473try 5474Xvimgrep /func/ test_quickfix.vim 5475catch /.*/ 5476let e = v: exception 5477endtry 5478call assert_equal ( 'AbortCmd' , e ) 5479call assert_equal ( 0 , g: Xgetlist ({ 'nr' : '$' }). nr ) 5480 5481" helpgrep/lhelpgrep 5482let e = '' 5483try 5484Xhelpgrep quickfix 5485catch /.*/ 5486let e = v: exception 5487endtry 5488call assert_equal ( 'AbortCmd' , e ) 5489call assert_equal ( 0 , g: Xgetlist ({ 'nr' : '$' }). nr ) 5490 5491" grep/lgrep 5492if has ( 'unix' ) 5493let e = '' 5494try 5495silent Xgrep func test_quickfix.vim 5496catch /.*/ 5497let e = v: exception 5498endtry 5499call assert_equal ( 'AbortCmd' , e ) 5500call assert_equal ( 0 , g: Xgetlist ({ 'nr' : '$' }). nr ) 5501endif 5502endfunc 5503 5504func Test_qfcmd_abort () 5505augroup QF_Test 5506au ! 5507autocmd QuickFixCmdPre * throw "AbortCmd" 5508augroup END 5509 5510call Xtest_qfcmd_abort ( 'c' ) 5511call Xtest_qfcmd_abort ( 'l' ) 5512 5513augroup QF_Test 5514au ! 5515augroup END 5516endfunc 5517 5518" Test for using a file in one of the parent directories. 5519func Test_search_in_dirstack () 5520call mkdir ( 'Xtestdir/a/b/c' , 'p' ) 5521let save_cwd = getcwd () 5522call writefile ([ "X1_L1" , "X1_L2" ], 'Xtestdir/Xfile1' ) 5523call writefile ([ "X2_L1" , "X2_L2" ], 'Xtestdir/a/Xfile2' ) 5524call writefile ([ "X3_L1" , "X3_L2" ], 'Xtestdir/a/b/Xfile3' ) 5525call writefile ([ "X4_L1" , "X4_L2" ], 'Xtestdir/a/b/c/Xfile4' ) 5526 5527let lines = "Entering dir Xtestdir\n" . 5528 \"Entering dir a\n" . 5529 \"Entering dir b\n" . 5530 \"Xfile2:2:X2_L2\n" . 5531 \"Leaving dir a\n" . 5532 \"Xfile1:2:X1_L2\n" . 5533 \"Xfile3:1:X3_L1\n" . 5534 \"Entering dir c\n" . 5535 \"Xfile4:2:X4_L2\n" . 5536 \"Leaving dir c\n" 5537set efm = %DEntering\ dir\ %f,%XLeaving\ dir\ %f,%f:%l:%m 5538cexpr lines .."Leaving dir Xtestdir|\n" |let next = 1 5539call assert_equal ( 11 , getqflist ({ 'size' : 0 }). size ) 5540call assert_equal ( 4 , getqflist ({ 'idx' : 0 }). idx ) 5541call assert_equal ( 'X2_L2' , getline ( '.' )) 5542call assert_equal ( 1 , next ) 5543cnext 5544call assert_equal ( 6 , getqflist ({ 'idx' : 0 }). idx ) 5545call assert_equal ( 'X1_L2' , getline ( '.' )) 5546cnext 5547call assert_equal ( 7 , getqflist ({ 'idx' : 0 }). idx ) 5548call assert_equal ( 1 , line ( '$' )) 5549call assert_equal ( '' , getline ( 1 )) 5550cnext 5551call assert_equal ( 9 , getqflist ({ 'idx' : 0 }). idx ) 5552call assert_equal ( 1 , line ( '$' )) 5553call assert_equal ( '' , getline ( 1 )) 5554 5555set efm & 5556exe 'cd ' . save_cwd 5557call delete ( 'Xtestdir' , 'rf' ) 5558endfunc 5559 5560" Test for :cquit 5561func Test_cquit () 5562" Exit Vim with a non-zero value 5563if RunVim ([], [ "cquit 7" ], '' ) 5564call assert_equal ( 7 , v: shell_error ) 5565endif 5566 5567if RunVim ([], [ "50cquit" ], '' ) 5568call assert_equal ( 50 , v: shell_error ) 5569endif 5570 5571" Exit Vim with default value 5572if RunVim ([], [ "cquit" ], '' ) 5573call assert_equal ( 1 , v: shell_error ) 5574endif 5575 5576" Exit Vim with zero value 5577if RunVim ([], [ "cquit 0" ], '' ) 5578call assert_equal ( 0 , v: shell_error ) 5579endif 5580 5581" Exit Vim with negative value 5582call assert_fails ( '-3cquit' , 'E16:' ) 5583endfunc 5584 5585" Test for getting a specific item from a quickfix list 5586func Xtest_getqflist_by_idx ( cchar ) 5587call s: setup_commands ( a: cchar ) 5588" Empty list 5589call assert_equal ([], g: Xgetlist ({ 'idx' : 1 , 'items' : 0 }). items ) 5590Xexpr ['F1:10:L10','F1:20:L20' ] 5591let l = g: Xgetlist ({ 'idx' : 2 , 'items' : 0 }). items 5592call assert_equal ( bufnr ( 'F1' ), l [ 0 ]. bufnr ) 5593call assert_equal ( 20 , l [ 0 ]. lnum ) 5594call assert_equal ( 'L20' , l [ 0 ]. text ) 5595call assert_equal ([], g: Xgetlist ({ 'idx' : -1 , 'items' : 0 }). items ) 5596call assert_equal ([], g: Xgetlist ({ 'idx' : 3 , 'items' : 0 }). items ) 5597call assert_equal ({}, g: Xgetlist (#{ idx : "abc" })) 5598 %bwipe ! 5599endfunc 5600 5601func Test_getqflist_by_idx () 5602call Xtest_getqflist_by_idx ( 'c' ) 5603call Xtest_getqflist_by_idx ( 'l' ) 5604endfunc 5605 5606" Test for the 'quickfixtextfunc' setting 5607func Tqfexpr ( info ) 5608if a: info . quickfix 5609let qfl = getqflist ({ 'id' : a: info . id , 'items' : 1 }). items 5610else 5611let qfl = getloclist ( a: info . winid , { 'id' : a: info . id , 'items' : 1 }). items 5612endif 5613 5614let l = [] 5615for idx in range ( a: info . start_idx - 1 , a: info . end_idx - 1 ) 5616let e = qfl [ idx ] 5617let s = '' 5618if e . bufnr != 0 5619let bname = bufname ( e . bufnr ) 5620let s ..= fnamemodify ( bname , ':.' ) 5621endif 5622let s ..= '-' 5623let s ..= 'L' .. string ( e . lnum ) .. 'C' .. string ( e . col ) .. '-' 5624let s ..= e . text 5625call add ( l , s ) 5626endfor 5627 5628return l 5629endfunc 5630 5631func Xtest_qftextfunc ( cchar ) 5632call s: setup_commands ( a: cchar ) 5633 5634set efm = %f:%l:%c:%m 5635set quickfixtextfunc = Tqfexpr 5636call assert_equal ( 'Tqfexpr' , & quickfixtextfunc ) 5637call assert_equal ( '' , 5638 \g: Xgetlist ({ 'quickfixtextfunc' : 1 }). quickfixtextfunc ) 5639call g: Xsetlist ([ 5640 \{ 'filename' : 'F1' , 'lnum' : 10 , 'col' : 2 , 5641 \'end_col' : 7 , 'text' : 'green' }, 5642 \{ 'filename' : 'F1' , 'lnum' : 20 , 'end_lnum' : 25 , 'col' : 4 , 5643 \'end_col' : 8 , 'text' : 'blue' }, 5644 \]) 5645 5646Xwindow 5647call assert_equal ( 'F1-L10C2-green' , getline ( 1 )) 5648call assert_equal ( 'F1-L20C4-blue' , getline ( 2 )) 5649Xclose 5650set quickfixtextfunc & vim 5651Xwindow 5652call assert_equal ( 'F1|10 col 2-7| green' , getline ( 1 )) 5653call assert_equal ( 'F1|20-25 col 4-8| blue' , getline ( 2 )) 5654Xclose 5655 5656set efm = %f:%l:%c:%m 5657set quickfixtextfunc = Tqfexpr 5658" Update the list with only the cwindow 5659Xwindow 5660only 5661call g: Xsetlist ([ 5662 \{ 'filename' : 'F2' , 'lnum' : 20 , 'col' : 2 , 5663 \'end_col' : 7 , 'text' : 'red' } 5664 \]) 5665call assert_equal ([ 'F2-L20C2-red' ], getline ( 1 , '$' )) 5666new 5667Xclose 5668set efm & 5669set quickfixtextfunc & 5670 5671" Test for per list 'quickfixtextfunc' setting 5672func PerQfText ( info ) 5673if a: info . quickfix 5674let qfl = getqflist ({ 'id' : a: info . id , 'items' : 1 }). items 5675else 5676let qfl = getloclist ( a: info . winid , { 'id' : a: info . id , 'items' : 1 }). items 5677endif 5678if empty ( qfl ) 5679return [] 5680endif 5681let l = [] 5682for idx in range ( a: info . start_idx - 1 , a: info . end_idx - 1 ) 5683call add ( l , 'Line ' .. qfl [ idx ]. lnum .. ', Col ' .. qfl [ idx ]. col ) 5684endfor 5685return l 5686endfunc 5687set quickfixtextfunc = Tqfexpr 5688call g: Xsetlist ([], ' ' , { 'quickfixtextfunc' : "PerQfText" }) 5689Xaddexpr ['F1:10:2:green','F1:20:4:blue' ] 5690Xwindow 5691call assert_equal ( 'Line 10, Col 2' , getline ( 1 )) 5692call assert_equal ( 'Line 20, Col 4' , getline ( 2 )) 5693Xclose 5694call assert_equal ( function ( 'PerQfText' ), 5695 \g: Xgetlist ({ 'quickfixtextfunc' : 1 }). quickfixtextfunc ) 5696" Add entries to the list when the quickfix buffer is hidden 5697Xaddexpr ['F1:30:6:red'] 5698Xwindow 5699call assert_equal ( 'Line 30, Col 6' , getline ( 3 )) 5700Xclose 5701call g: Xsetlist ([], 'r' , { 'quickfixtextfunc' : '' }) 5702call assert_equal ( '' , g: Xgetlist ({ 'quickfixtextfunc' : 1 }). quickfixtextfunc ) 5703set quickfixtextfunc & 5704delfunc PerQfText 5705 5706" Non-existing function 5707set quickfixtextfunc = Tabc 5708call assert_fails ( "Xexpr ['F1:10:2:green', 'F1:20:4:blue']" , 'E117:' ) 5709call assert_fails ( "Xwindow" , 'E117:' ) 5710Xclose 5711set quickfixtextfunc & 5712 5713" set option to a non-function 5714set quickfixtextfunc = [10,\ 20] 5715call assert_fails ( "Xexpr ['F1:10:2:green', 'F1:20:4:blue']" , 'E117:' ) 5716call assert_fails ( "Xwindow" , 'E117:' ) 5717Xclose 5718set quickfixtextfunc & 5719 5720" set option to a function with different set of arguments 5721func Xqftext ( a , b , c ) 5722return a: a .. a: b .. a: c 5723endfunc 5724set quickfixtextfunc = Xqftext 5725call assert_fails ( "Xexpr ['F1:10:2:green', 'F1:20:4:blue']" , 'E119:' ) 5726call assert_fails ( "Xwindow" , 'E119:' ) 5727Xclose 5728 5729" set option to a function that returns a list with non-strings 5730func Xqftext2 ( d ) 5731return [ 'one' , [], 'two' ] 5732endfunc 5733set quickfixtextfunc = Xqftext2 5734call assert_fails ( "Xexpr ['F1:10:2:green', 'F1:20:4:blue', 'F1:30:6:red']" , 5735 \'E730:' ) 5736call assert_fails ( 'Xwindow' , 'E730:' ) 5737call assert_equal ([ 'one' , 'F1|20 col 4| blue' , 'F1|30 col 6| red' ], 5738 \getline ( 1 , '$' )) 5739Xclose 5740 5741set quickfixtextfunc & 5742delfunc Xqftext 5743delfunc Xqftext2 5744 5745" set the global option to a lambda function 5746set quickfixtextfunc = {d\ ->\ map(g:Xgetlist({'id'\ :\ d.id,\ 'items'\ :\ 1}).items[d.start_idx-1:d.end_idx-1],\ 'v:val.text')} 5747Xexpr ['F1:10:2:green','F1:20:4:blue' ] 5748Xwindow 5749call assert_equal ([ 'green' , 'blue' ], getline ( 1 , '$' )) 5750Xclose 5751" A callback option stores the resolved funcref, so a lambda reads back as its <lambda> handle 5752" (consistent with the per-list 'quickfixtextfunc' below). 5753call assert_match ( "function('<lambda>\\d\\+')" , & quickfixtextfunc ) 5754set quickfixtextfunc & 5755 5756" use a lambda function that returns an empty list 5757set quickfixtextfunc = {d\ ->\ []} 5758Xexpr ['F1:10:2:green','F1:20:4:blue' ] 5759Xwindow 5760call assert_equal ([ 'F1|10 col 2| green' , 'F1|20 col 4| blue' ], 5761 \getline ( 1 , '$' )) 5762Xclose 5763set quickfixtextfunc & 5764 5765" use a lambda function that returns a list with empty strings 5766set quickfixtextfunc = {d\ ->\ ['',\ '']} 5767Xexpr ['F1:10:2:green','F1:20:4:blue' ] 5768Xwindow 5769call assert_equal ([ 'F1|10 col 2| green' , 'F1|20 col 4| blue' ], 5770 \getline ( 1 , '$' )) 5771Xclose 5772set quickfixtextfunc & 5773 5774" set the per-quickfix list text function to a lambda function 5775call g: Xsetlist ([], ' ' , 5776 \{ 'quickfixtextfunc' : 5777 \{ d ->map ( g: Xgetlist ({ 'id' : d . id , 'items' : 1 }). items [ d . start_idx - 1 : d . end_idx - 1 ], 5778 \"'Line ' .. v:val.lnum .. ', Col ' .. v:val.col" )}}) 5779Xaddexpr ['F1:10:2:green','F1:20:4:blue' ] 5780Xwindow 5781call assert_equal ( 'Line 10, Col 2' , getline ( 1 )) 5782call assert_equal ( 'Line 20, Col 4' , getline ( 2 )) 5783Xclose 5784call assert_match ( "function('<lambda>\\d\\+')" , string ( g: Xgetlist ({ 'quickfixtextfunc' : 1 }). quickfixtextfunc )) 5785call g: Xsetlist ([], 'f' ) 5786endfunc 5787 5788func Test_qftextfunc () 5789call Xtest_qftextfunc ( 'c' ) 5790call Xtest_qftextfunc ( 'l' ) 5791endfunc 5792 5793func Test_qftextfunc_callback () 5794let lines =<< trim END 5795set efm=%f:%l:%c:%m 5796 5797#" Test for using a function name 5798LET &qftf = 'g:Tqfexpr' 5799cexpr "F0:0:0:L0" 5800copen 5801call assert_equal('F0-L0C0-L0', getline(1)) 5802cclose 5803 5804#" Test for using a function() 5805set qftf=function('g:Tqfexpr') 5806cexpr "F1:1:1:L1" 5807copen 5808call assert_equal('F1-L1C1-L1', getline(1)) 5809cclose 5810 5811#" Using a funcref variable to set 'quickfixtextfunc' 5812VAR Fn = function('g:Tqfexpr') 5813LET &qftf = Fn 5814cexpr "F2:2:2:L2" 5815copen 5816call assert_equal('F2-L2C2-L2', getline(1)) 5817cclose 5818 5819#" Using string(funcref_variable) to set 'quickfixtextfunc' 5820LET Fn = function('g:Tqfexpr') 5821LET &qftf = string(Fn) 5822cexpr "F3:3:3:L3" 5823copen 5824call assert_equal('F3-L3C3-L3', getline(1)) 5825cclose 5826 5827#" Test for using a funcref() 5828set qftf=funcref('g:Tqfexpr') 5829cexpr "F4:4:4:L4" 5830copen 5831call assert_equal('F4-L4C4-L4', getline(1)) 5832cclose 5833 5834#" Using a funcref variable to set 'quickfixtextfunc' 5835LET Fn = funcref('g:Tqfexpr') 5836LET &qftf = Fn 5837cexpr "F5:5:5:L5" 5838copen 5839call assert_equal('F5-L5C5-L5', getline(1)) 5840cclose 5841 5842#" Using a string(funcref_variable) to set 'quickfixtextfunc' 5843LET Fn = funcref('g:Tqfexpr') 5844LET &qftf = string(Fn) 5845cexpr "F5:5:5:L5" 5846copen 5847call assert_equal('F5-L5C5-L5', getline(1)) 5848cclose 5849 5850#" Test for using a lambda function with set 5851VAR optval = "LSTART a LMIDDLE Tqfexpr(a) LEND" 5852LET optval = substitute(optval, ' ', '\\ ', 'g') 5853exe "set qftf=" .. optval 5854cexpr "F6:6:6:L6" 5855copen 5856call assert_equal('F6-L6C6-L6', getline(1)) 5857cclose 5858 5859#" Set 'quickfixtextfunc' to a lambda expression 5860LET &qftf = LSTART a LMIDDLE Tqfexpr(a) LEND 5861cexpr "F7:7:7:L7" 5862copen 5863call assert_equal('F7-L7C7-L7', getline(1)) 5864cclose 5865 5866#" Set 'quickfixtextfunc' to string(lambda_expression) 5867LET &qftf = "LSTART a LMIDDLE Tqfexpr(a) LEND" 5868cexpr "F8:8:8:L8" 5869copen 5870call assert_equal('F8-L8C8-L8', getline(1)) 5871cclose 5872 5873#" Set 'quickfixtextfunc' to a variable with a lambda expression 5874VAR Lambda = LSTART a LMIDDLE Tqfexpr(a) LEND 5875LET &qftf = Lambda 5876cexpr "F9:9:9:L9" 5877copen 5878call assert_equal('F9-L9C9-L9', getline(1)) 5879cclose 5880 5881#" Set 'quickfixtextfunc' to a string(variable with a lambda expression) 5882LET Lambda = LSTART a LMIDDLE Tqfexpr(a) LEND 5883LET &qftf = string(Lambda) 5884cexpr "F9:9:9:L9" 5885copen 5886call assert_equal('F9-L9C9-L9', getline(1)) 5887cclose 5888END 5889call CheckLegacyAndVim9Success ( lines ) 5890 5891" Test for using a script-local function name 5892func s: TqfFunc2 ( info ) 5893let g: TqfFunc2Args = [ a: info . start_idx , a: info . end_idx ] 5894return '' 5895endfunc 5896let g: TqfFunc2Args = [] 5897set quickfixtextfunc = s:TqfFunc2 5898cexpr "F10:10:10:L10" 5899cclose 5900call assert_equal ([ 1 , 1 ], g: TqfFunc2Args ) 5901 5902let & quickfixtextfunc = 's:TqfFunc2' 5903cexpr "F11:11:11:L11" 5904cclose 5905call assert_equal ([ 1 , 1 ], g: TqfFunc2Args ) 5906delfunc s:TqfFunc2 5907 5908" set 'quickfixtextfunc' to a partial with dict. This used to cause a crash. 5909func SetQftfFunc () 5910let params = { 'qftf' : function ( 'g:DictQftfFunc' )} 5911let & quickfixtextfunc = params . qftf 5912endfunc 5913func g: DictQftfFunc ( _ ) dict 5914endfunc 5915call SetQftfFunc () 5916new 5917call SetQftfFunc () 5918bw 5919call test_garbagecollect_now () 5920new 5921set qftf = 5922wincmd w 5923set qftf = 5924: %bw ! 5925 5926" set per-quickfix list 'quickfixtextfunc' to a partial with dict. This used 5927" to cause a crash. 5928let & qftf = '' 5929func SetLocalQftfFunc () 5930let params = { 'qftf' : function ( 'g:DictQftfFunc' )} 5931call setqflist ([], 'a' , { 'quickfixtextfunc' : params . qftf }) 5932endfunc 5933call SetLocalQftfFunc () 5934call test_garbagecollect_now () 5935call setqflist ([], 'a' , { 'quickfixtextfunc' : '' }) 5936delfunc g:DictQftfFunc 5937delfunc SetQftfFunc 5938delfunc SetLocalQftfFunc 5939set efm & 5940endfunc 5941 5942" Test for updating a location list for some other window and check that 5943" 'qftextfunc' uses the correct location list. 5944func Test_qftextfunc_other_loclist () 5945 %bw ! 5946call setloclist ( 0 , [], 'f' ) 5947 5948" create a window and a location list for it and open the location list 5949" window 5950lexpr ['F1:10:12:one','F1:20:14:two' ] 5951let w1_id = win_getid () 5952call setloclist ( 0 , [], ' ' , 5953 \{ 'lines' : [ 'F1:10:12:one' , 'F1:20:14:two' ], 5954 \'quickfixtextfunc' : 5955 \{ d ->map ( getloclist ( d . winid , { 'id' : d . id , 5956 \'items' : 1 }). items [ d . start_idx - 1 : d . end_idx - 1 ], 5957 \"'Line ' .. v:val.lnum .. ', Col ' .. v:val.col" )}}) 5958lwindow 5959let w2_id = win_getid () 5960 5961" create another window and a location list for it and open the location 5962" list window 5963topleft new 5964let w3_id = win_getid () 5965call setloclist ( 0 , [], ' ' , 5966 \{ 'lines' : [ 'F2:30:32:eleven' , 'F2:40:34:twelve' ], 5967 \'quickfixtextfunc' : 5968 \{ d ->map ( getloclist ( d . winid , { 'id' : d . id , 5969 \'items' : 1 }). items [ d . start_idx - 1 : d . end_idx - 1 ], 5970 \"'Ligne ' .. v:val.lnum .. ', Colonne ' .. v:val.col" )}}) 5971lwindow 5972let w4_id = win_getid () 5973 5974topleft new 5975lexpr ['F3:50:52:green','F3:60:54:blue' ] 5976let w5_id = win_getid () 5977 5978" change the location list for some other window 5979call setloclist ( 0 , [], 'r' , { 'lines' : [ 'F3:55:56:aaa' , 'F3:57:58:bbb' ]}) 5980call setloclist ( w1_id , [], 'r' , { 'lines' : [ 'F1:62:63:bbb' , 'F1:64:65:ccc' ]}) 5981call setloclist ( w3_id , [], 'r' , { 'lines' : [ 'F2:76:77:ddd' , 'F2:78:79:eee' ]}) 5982call assert_equal ([ 'Line 62, Col 63' , 'Line 64, Col 65' ], 5983 \getbufline ( winbufnr ( w2_id ), 1 , '$' )) 5984call assert_equal ([ 'Ligne 76, Colonne 77' , 'Ligne 78, Colonne 79' ], 5985 \getbufline ( winbufnr ( w4_id ), 1 , '$' )) 5986call setloclist ( w2_id , [], 'r' , { 'lines' : [ 'F1:32:33:fff' , 'F1:34:35:ggg' ]}) 5987call setloclist ( w4_id , [], 'r' , { 'lines' : [ 'F2:46:47:hhh' , 'F2:48:49:jjj' ]}) 5988call assert_equal ([ 'Line 32, Col 33' , 'Line 34, Col 35' ], 5989 \getbufline ( winbufnr ( w2_id ), 1 , '$' )) 5990call assert_equal ([ 'Ligne 46, Colonne 47' , 'Ligne 48, Colonne 49' ], 5991 \getbufline ( winbufnr ( w4_id ), 1 , '$' )) 5992 5993call win_gotoid ( w5_id ) 5994lwindow 5995call assert_equal ([ 'F3|55 col 56| aaa' , 'F3|57 col 58| bbb' ], 5996 \getline ( 1 , '$' )) 5997 %bw ! 5998endfunc 5999 6000" Running :lhelpgrep command more than once in a help window, doesn't jump to 6001" the help topic 6002func Test_lhelpgrep_from_help_window () 6003call mkdir ( 'Xtestdir/doc' , 'p' ) 6004call writefile ([ 'window' ], 'Xtestdir/doc/a.txt' ) 6005call writefile ([ 'buffer' ], 'Xtestdir/doc/b.txt' ) 6006let save_rtp = & rtp 6007let & rtp = 'Xtestdir' 6008lhelpgrep window 6009lhelpgrep buffer 6010call assert_equal ( 'b.txt' , fnamemodify ( @%, ":p:t" )) 6011lhelpgrep window 6012call assert_equal ( 'a.txt' , fnamemodify ( @%, ":p:t" )) 6013let & rtp = save_rtp 6014call delete ( 'Xtestdir' , 'rf' ) 6015new |only ! 6016endfunc 6017 6018" Test for the crash fixed by 7.3.715 6019func Test_setloclist_crash () 6020 %bw ! 6021let g: BufNum = bufnr () 6022augroup QF_Test 6023au ! 6024au BufUnload * call setloclist ( 0 , [{ 'bufnr' : g: BufNum , 'lnum' : 1 , 'col' : 1 , 'text' : 'tango down' }]) 6025augroup END 6026 6027try 6028lvimgrep /.*/ *.mak 6029catch /E926:/ 6030endtry 6031call assert_equal ( 'tango down' , getloclist ( 0 , { 'items' : 0 }). items [ 0 ]. text ) 6032call assert_equal ( 1 , getloclist ( 0 , { 'size' : 0 }). size ) 6033 6034augroup QF_Test 6035au ! 6036augroup END 6037unlet g: BufNum 6038 %bw ! 6039endfunc 6040 6041" Test for adding an invalid entry with the quickfix window open and making 6042" sure that the window contents are not changed 6043func Test_add_invalid_entry_with_qf_window () 6044call setqflist ([], 'f' ) 6045cexpr "Xfile1:10:aa" 6046copen 6047call setqflist ([ 'bb' ], 'a' ) 6048call assert_equal ( 1 , line ( '$' )) 6049call assert_equal ([ 'Xfile1|10| aa' ], getline ( 1 , '$' )) 6050call assert_equal ([{ 'lnum' : 10 , 'end_lnum' : 0 , 'bufnr' : bufnr ( 'Xfile1' ) , 'col' : 0 , 'end_col' : 0 , 'pattern' : '' , 'valid' : 1 , 'vcol' : 0 , 'nr' : -1 , 'type' : '' , 'module' : '' , 'text' : 'aa' }] , getqflist ()) 6051 6052call setqflist ([{ 'lnum' : 10 , 'bufnr' : bufnr ( 'Xfile1' ) , 'col' : 0 , 'pattern' : '' , 'valid' : 1 , 'vcol' : 0 , 'nr' : -1 , 'type' : '' , 'module' : '' , 'text' : 'aa' }] , 'r' ) 6053call assert_equal ( 1 , line ( '$' )) 6054call assert_equal ([ 'Xfile1|10| aa' ] , getline ( 1 , '$' )) 6055call assert_equal ([{ 'lnum' : 10 , 'end_lnum' : 0 , 'bufnr' : bufnr ( 'Xfile1' ) , 'col' : 0 , 'end_col' : 0 , 'pattern' : '' , 'valid' : 1 , 'vcol' : 0 , 'nr' : -1 , 'type' : '' , 'module' : '' , 'text' : 'aa' }] , getqflist ()) 6056 6057call setqflist ([{ 'lnum' : 10 , 'end_lnum' : 0 , 'bufnr' : bufnr ( 'Xfile1' ) , 'col' : 0 , 'end_col' : 0 , 'pattern' : '' , 'valid' : 1 , 'vcol' : 0 , 'nr' : -1 , 'type' : '' , 'module' : '' , 'text' : 'aa' }] , 'r' ) 6058call assert_equal ( 1 , line ( '$' )) 6059call assert_equal ([ 'Xfile1|10| aa' ] , getline ( 1 , '$' )) 6060call assert_equal ([{ 'lnum' : 10 , 'end_lnum' : 0 , 'bufnr' : bufnr ( 'Xfile1' ) , 'col' : 0 , 'end_col' : 0 , 'pattern' : '' , 'valid' : 1 , 'vcol' : 0 , 'nr' : -1 , 'type' : '' , 'module' : '' , 'text' : 'aa' }] , getqflist ()) 6061 6062call setqflist ([{ 'lnum' : 10 , 'end_lnum' : -123 , 'bufnr' : bufnr ( 'Xfile1' ) , 'col' : 0 , 'end_col' : -456 , 'pattern' : '' , 'valid' : 1 , 'vcol' : 0 , 'nr' : -1 , 'type' : '' , 'module' : '' , 'text' : 'aa' }] , 'r' ) 6063call assert_equal ( 1 , line ( '$' )) 6064call assert_equal ([ 'Xfile1|10| aa' ] , getline ( 1 , '$' )) 6065call assert_equal ([{ 'lnum' : 10 , 'end_lnum' : -123 , 'bufnr' : bufnr ( 'Xfile1' ) , 'col' : 0 , 'end_col' : -456 , 'pattern' : '' , 'valid' : 1 , 'vcol' : 0 , 'nr' : -1 , 'type' : '' , 'module' : '' , 'text' : 'aa' }] , getqflist ()) 6066 6067call setqflist ([{ 'lnum' : 10 , 'end_lnum' : -123 , 'bufnr' : bufnr ( 'Xfile1' ) , 'col' : 666 , 'end_col' : 0 , 'pattern' : '' , 'valid' : 1 , 'vcol' : 0 , 'nr' : -1 , 'type' : '' , 'module' : '' , 'text' : 'aa' }] , 'r' ) 6068call assert_equal ( 1 , line ( '$' )) 6069call assert_equal ([ 'Xfile1|10 col 666| aa' ] , getline ( 1 , '$' )) 6070call assert_equal ([{ 'lnum' : 10 , 'end_lnum' : -123 , 'bufnr' : bufnr ( 'Xfile1' ) , 'col' : 666 , 'end_col' : 0 , 'pattern' : '' , 'valid' : 1 , 'vcol' : 0 , 'nr' : -1 , 'type' : '' , 'module' : '' , 'text' : 'aa' }] , getqflist ()) 6071 6072call setqflist ([{ 'lnum' : 10 , 'end_lnum' : -123 , 'bufnr' : bufnr ( 'Xfile1' ) , 'col' : 666 , 'end_col' : -456 , 'pattern' : '' , 'valid' : 1 , 'vcol' : 0 , 'nr' : -1 , 'type' : '' , 'module' : '' , 'text' : 'aa' }] , 'r' ) 6073call assert_equal ( 1 , line ( '$' )) 6074call assert_equal ([ 'Xfile1|10 col 666| aa' ] , getline ( 1 , '$' )) 6075call assert_equal ([{ 'lnum' : 10 , 'end_lnum' : -123 , 'bufnr' : bufnr ( 'Xfile1' ) , 'col' : 666 , 'end_col' : -456 , 'pattern' : '' , 'valid' : 1 , 'vcol' : 0 , 'nr' : -1 , 'type' : '' , 'module' : '' , 'text' : 'aa' }] , getqflist ()) 6076 6077call setqflist ([{ 'lnum' : 10 , 'end_lnum' : -123 , 'bufnr' : bufnr ( 'Xfile1' ) , 'col' : 666 , 'end_col' : 222 , 'pattern' : '' , 'valid' : 1 , 'vcol' : 0 , 'nr' : -1 , 'type' : '' , 'module' : '' , 'text' : 'aa' }] , 'r' ) 6078call assert_equal ( 1 , line ( '$' )) 6079call assert_equal ([ 'Xfile1|10 col 666-222| aa' ] , getline ( 1 , '$' )) 6080call assert_equal ([{ 'lnum' : 10 , 'end_lnum' : -123 , 'bufnr' : bufnr ( 'Xfile1' ) , 'col' : 666 , 'end_col' : 222 , 'pattern' : '' , 'valid' : 1 , 'vcol' : 0 , 'nr' : -1 , 'type' : '' , 'module' : '' , 'text' : 'aa' }] , getqflist ()) 6081 6082call setqflist ([{ 'lnum' : 10 , 'end_lnum' : 6 , 'bufnr' : bufnr ( 'Xfile1' ) , 'col' : 666 , 'end_col' : 222 , 'pattern' : '' , 'valid' : 1 , 'vcol' : 0 , 'nr' : -1 , 'type' : '' , 'module' : '' , 'text' : 'aa' }] , 'r' ) 6083call assert_equal ( 1 , line ( '$' )) 6084call assert_equal ([ 'Xfile1|10-6 col 666-222| aa' ] , getline ( 1 , '$' )) 6085call assert_equal ([{ 'lnum' : 10 , 'end_lnum' : 6 , 'bufnr' : bufnr ( 'Xfile1' ) , 'col' : 666 , 'end_col' : 222 , 'pattern' : '' , 'valid' : 1 , 'vcol' : 0 , 'nr' : -1 , 'type' : '' , 'module' : '' , 'text' : 'aa' }] , getqflist ()) 6086cclose 6087endfunc 6088 6089" Test for very weird problem: autocommand causes a failure, resulting opening 6090" the quickfix window to fail. This still splits the window, but otherwise 6091" should not mess up buffers. 6092func Test_quickfix_window_fails_to_open () 6093CheckScreendump 6094 6095let lines =<< trim END 6096anything 6097try 6098anything 6099endtry 6100END 6101call writefile ( lines , 'XquickfixFails' ) 6102 6103let lines =<< trim END 6104split XquickfixFails 6105silent vimgrep anything % 6106normal o 6107au BufLeave * ++once source XquickfixFails 6108" This will trigger the autocommand, which causes an error, what follows 6109" is aborted but the window was already split. 6110silent! cwindow 6111END 6112call writefile ( lines , 'XtestWinFails' ) 6113let buf = RunVimInTerminal ( '-S XtestWinFails' , #{ rows : 13 }) 6114call VerifyScreenDump ( buf , 'Test_quickfix_window_fails' , {}) 6115 6116" clean up 6117call term_sendkeys ( buf , ":bwipe!\<CR>" ) 6118call term_wait ( buf ) 6119call StopVimInTerminal ( buf ) 6120call delete ( 'XtestWinFails' ) 6121call delete ( 'XquickfixFails' ) 6122endfunc 6123 6124" Test for updating the quickfix buffer whenever the associated quickfix list 6125" is changed. 6126func Xqfbuf_update ( cchar ) 6127call s: setup_commands ( a: cchar ) 6128 6129Xexpr "F1:1:line1" 6130Xopen 6131call assert_equal ([ 'F1|1| line1' ], getline ( 1 , '$' )) 6132call assert_equal ( 1 , g: Xgetlist ({ 'changedtick' : 0 }). changedtick ) 6133 6134" Test setqflist() using the 'lines' key in 'what' 6135" add a new entry 6136call g: Xsetlist ([], 'a' , { 'lines' : [ 'F2:2: line2' ]}) 6137call assert_equal ([ 'F1|1| line1' , 'F2|2| line2' ], getline ( 1 , '$' )) 6138call assert_equal ( 2 , g: Xgetlist ({ 'changedtick' : 0 }). changedtick ) 6139" replace all the entries with a single entry 6140call g: Xsetlist ([], 'r' , { 'lines' : [ 'F3:3: line3' ]}) 6141call assert_equal ([ 'F3|3| line3' ], getline ( 1 , '$' )) 6142call assert_equal ( 3 , g: Xgetlist ({ 'changedtick' : 0 }). changedtick ) 6143" remove all the entries 6144call g: Xsetlist ([], 'r' , { 'lines' : []}) 6145call assert_equal ([ '' ], getline ( 1 , '$' )) 6146call assert_equal ( 4 , g: Xgetlist ({ 'changedtick' : 0 }). changedtick ) 6147" add a new list 6148call g: Xsetlist ([], ' ' , { 'lines' : [ 'F4:4: line4' ]}) 6149call assert_equal ([ 'F4|4| line4' ], getline ( 1 , '$' )) 6150call assert_equal ( 1 , g: Xgetlist ({ 'changedtick' : 0 }). changedtick ) 6151 6152" Test setqflist() using the 'items' key in 'what' 6153" add a new entry 6154call g: Xsetlist ([], 'a' , { 'items' : [{ 'filename' : 'F5' , 'lnum' : 5 , 'text' : 'line5' }]}) 6155call assert_equal ([ 'F4|4| line4' , 'F5|5| line5' ], getline ( 1 , '$' )) 6156call assert_equal ( 2 , g: Xgetlist ({ 'changedtick' : 0 }). changedtick ) 6157" replace all the entries with a single entry 6158call g: Xsetlist ([], 'r' , { 'items' : [{ 'filename' : 'F6' , 'lnum' : 6 , 'text' : 'line6' }]}) 6159call assert_equal ([ 'F6|6| line6' ], getline ( 1 , '$' )) 6160call assert_equal ( 3 , g: Xgetlist ({ 'changedtick' : 0 }). changedtick ) 6161" remove all the entries 6162call g: Xsetlist ([], 'r' , { 'items' : []}) 6163call assert_equal ([ '' ], getline ( 1 , '$' )) 6164call assert_equal ( 4 , g: Xgetlist ({ 'changedtick' : 0 }). changedtick ) 6165" add a new list 6166call g: Xsetlist ([], ' ' , { 'items' : [{ 'filename' : 'F7' , 'lnum' : 7 , 'text' : 'line7' }]}) 6167call assert_equal ([ 'F7|7| line7' ], getline ( 1 , '$' )) 6168call assert_equal ( 1 , g: Xgetlist ({ 'changedtick' : 0 }). changedtick ) 6169 6170call g: Xsetlist ([], ' ' , {}) 6171call assert_equal ([ '' ], getline ( 1 , '$' )) 6172call assert_equal ( 1 , g: Xgetlist ({ 'changedtick' : 0 }). changedtick ) 6173 6174Xclose 6175endfunc 6176 6177func Test_qfbuf_update () 6178call Xqfbuf_update ( 'c' ) 6179call Xqfbuf_update ( 'l' ) 6180endfunc 6181 6182func Test_vimgrep_noswapfile () 6183set noswapfile 6184call writefile ([ 'one' , 'two' , 'three' ], 'Xgreppie' ) 6185vimgrep two Xgreppie 6186call assert_equal ( 'two' , getline ( '.' )) 6187 6188call delete ( 'Xgreppie' ) 6189set swapfile 6190endfunc 6191 6192" Test for the :vimgrep 'f' flag (fuzzy match) 6193func Xvimgrep_fuzzy_match ( cchar ) 6194call s: setup_commands ( a: cchar ) 6195 6196Xvimgrep /three one/f Xfile* 6197let l = g: Xgetlist () 6198call assert_equal ( 2 , len ( l )) 6199call assert_equal ([ 'Xfile1' , 1 , 9 , 'one two three' ], 6200 \[ bufname ( l [ 0 ]. bufnr ), l [ 0 ]. lnum , l [ 0 ]. col , l [ 0 ]. text ]) 6201call assert_equal ([ 'Xfile2' , 2 , 1 , 'three one two' ], 6202 \[ bufname ( l [ 1 ]. bufnr ), l [ 1 ]. lnum , l [ 1 ]. col , l [ 1 ]. text ]) 6203 6204Xvimgrep /the/f Xfile* 6205let l = g: Xgetlist () 6206call assert_equal ( 3 , len ( l )) 6207call assert_equal ([ 'Xfile1' , 1 , 9 , 'one two three' ], 6208 \[ bufname ( l [ 0 ]. bufnr ), l [ 0 ]. lnum , l [ 0 ]. col , l [ 0 ]. text ]) 6209call assert_equal ([ 'Xfile2' , 2 , 1 , 'three one two' ], 6210 \[ bufname ( l [ 1 ]. bufnr ), l [ 1 ]. lnum , l [ 1 ]. col , l [ 1 ]. text ]) 6211call assert_equal ([ 'Xfile2' , 4 , 4 , 'aaathreeaaa' ], 6212 \[ bufname ( l [ 2 ]. bufnr ), l [ 2 ]. lnum , l [ 2 ]. col , l [ 2 ]. text ]) 6213 6214Xvimgrep /aaa/fg Xfile* 6215let l = g: Xgetlist () 6216call assert_equal ( 4 , len ( l )) 6217call assert_equal ([ 'Xfile1' , 2 , 1 , 'aaaaaa' ], 6218 \[ bufname ( l [ 0 ]. bufnr ), l [ 0 ]. lnum , l [ 0 ]. col , l [ 0 ]. text ]) 6219call assert_equal ([ 'Xfile1' , 2 , 4 , 'aaaaaa' ], 6220 \[ bufname ( l [ 1 ]. bufnr ), l [ 1 ]. lnum , l [ 1 ]. col , l [ 1 ]. text ]) 6221call assert_equal ([ 'Xfile2' , 4 , 1 , 'aaathreeaaa' ], 6222 \[ bufname ( l [ 2 ]. bufnr ), l [ 2 ]. lnum , l [ 2 ]. col , l [ 2 ]. text ]) 6223call assert_equal ([ 'Xfile2' , 4 , 9 , 'aaathreeaaa' ], 6224 \[ bufname ( l [ 3 ]. bufnr ), l [ 3 ]. lnum , l [ 3 ]. col , l [ 3 ]. text ]) 6225 6226call assert_fails ( 'Xvimgrep /xyz/fg Xfile*' , 'E480:' ) 6227endfunc 6228 6229func Test_vimgrep_fuzzy_match () 6230call writefile ([ 'one two three' , 'aaaaaa' ], 'Xfile1' ) 6231call writefile ([ 'one' , 'three one two' , 'two' , 'aaathreeaaa' ], 'Xfile2' ) 6232call Xvimgrep_fuzzy_match ( 'c' ) 6233call Xvimgrep_fuzzy_match ( 'l' ) 6234call delete ( 'Xfile1' ) 6235call delete ( 'Xfile2' ) 6236endfunc 6237 6238func Test_locationlist_open_in_newtab () 6239call s: create_test_file ( 'Xqftestfile1' ) 6240call s: create_test_file ( 'Xqftestfile2' ) 6241call s: create_test_file ( 'Xqftestfile3' ) 6242 6243 %bwipe ! 6244 6245let lines =<< trim END 6246Xqftestfile1:5:Line5 6247Xqftestfile2:10:Line10 6248Xqftestfile3:16:Line16 6249END 6250lgetexpr lines 6251 6252silent ! llast 6253call assert_equal ( 1 , tabpagenr ( '$' )) 6254call assert_equal ( 'Xqftestfile3' , bufname ()) 6255 6256set switchbuf = newtab 6257 6258silent ! lfirst 6259call assert_equal ( 2 , tabpagenr ( '$' )) 6260call assert_equal ( 'Xqftestfile1' , bufname ()) 6261 6262silent ! lnext 6263call assert_equal ( 3 , tabpagenr ( '$' )) 6264call assert_equal ( 'Xqftestfile2' , bufname ()) 6265 6266call delete ( 'Xqftestfile1' ) 6267call delete ( 'Xqftestfile2' ) 6268call delete ( 'Xqftestfile3' ) 6269set switchbuf & vim 6270 6271 %bwipe ! 6272endfunc 6273 6274" Test for win_gettype() in quickfix and location list windows 6275func Test_win_gettype () 6276copen 6277call assert_equal ( "quickfix" , win_gettype ()) 6278let wid = win_getid () 6279wincmd p 6280call assert_equal ( "quickfix" , win_gettype ( wid )) 6281cclose 6282lexpr '' 6283lopen 6284call assert_equal ( "loclist" , win_gettype ()) 6285let wid = win_getid () 6286wincmd p 6287call assert_equal ( "loclist" , win_gettype ( wid )) 6288lclose 6289endfunc 6290 6291fun Test_vimgrep_nomatch () 6292call XexprTests ( 'c' ) 6293call g: Xsetlist ([{ 'lnum' : 10 , 'text' : 'Line1' }]) 6294copen 6295if has ( "win32" ) 6296call assert_fails ( 'vimgrep foo *.zzz' , 'E479:' ) 6297let expected = [{ 'lnum' : 10 , 'bufnr' : 0 , 'end_lnum' : 0 , 'pattern' : '' , 'valid' : 0 , 'vcol' : 0 , 'nr' : 0 , 'module' : '' , 'type' : '' , 'end_col' : 0 , 'col' : 0 , 'text' : 'Line1' }] 6298else 6299call assert_fails ( 'vimgrep foo *.zzz' , 'E480:' ) 6300let expected = [] 6301endif 6302call assert_equal ( expected , getqflist ()) 6303cclose 6304endfunc 6305 6306" Test for opening the quickfix window in two tab pages and then closing one 6307" of the quickfix windows. This should not make the quickfix buffer unlisted. 6308" (github issue #9300). 6309func Test_two_qf_windows () 6310cexpr "F1:1:line1" 6311copen 6312tabnew 6313copen 6314call assert_true ( & buflisted ) 6315cclose 6316tabfirst 6317call assert_true ( & buflisted ) 6318let bnum = bufnr () 6319cclose 6320" if all the quickfix windows are closed, then buffer should be unlisted. 6321call assert_false ( buflisted ( bnum )) 6322 %bw ! 6323 6324" Repeat the test for a location list 6325lexpr "F2:2:line2" 6326lopen 6327let bnum = bufnr () 6328tabnew 6329exe "buffer" bnum 6330tabfirst 6331lclose 6332tablast 6333call assert_true ( buflisted ( bnum )) 6334tabclose 6335lopen 6336call assert_true ( buflisted ( bnum )) 6337lclose 6338call assert_false ( buflisted ( bnum )) 6339 %bw ! 6340endfunc 6341 6342" Weird sequence of commands that caused entering a wiped-out buffer 6343func Test_lopen_bwipe () 6344func R () 6345silent ! tab lopen 6346e x 6347silent ! lfile 6348endfunc 6349 6350cal R () 6351cal R () 6352cal R () 6353bw ! 6354delfunc R 6355endfunc 6356 6357" Another sequence of commands that caused all buffers to be wiped out 6358func Test_lopen_bwipe_all () 6359let lines =<< trim END 6360func R() 6361silent! tab lopen 6362e foo 6363silent! lfile 6364endfunc 6365cal R() 6366exe "norm \<C-W>\<C-V>0" 6367cal R() 6368bwipe 6369 6370call writefile(['done'], 'Xresult') 6371qall! 6372END 6373call writefile ( lines , 'Xscript' ) 6374if RunVim ([], [], '-u NONE -n -X -Z -e -m -s -S Xscript' ) 6375call assert_equal ([ 'done' ], readfile ( 'Xresult' )) 6376endif 6377 6378call delete ( 'Xscript' ) 6379call delete ( 'Xresult' ) 6380endfunc 6381 6382" Test for calling setqflist() function recursively 6383func Test_recursive_setqflist () 6384augroup QF_Test 6385au ! 6386autocmd BufWinEnter quickfix call setqflist ([], 'r' ) 6387augroup END 6388 6389copen 6390call assert_fails ( "call setqflist([], 'a')" , 'E952:' ) 6391 6392augroup QF_Test 6393au ! 6394augroup END 6395 %bw ! 6396endfunc 6397 6398" Test for failure to create a new window when selecting a file from the 6399" quickfix window 6400func Test_cwindow_newwin_fails () 6401cgetexpr ["Xfile1:10:L10","Xfile1:20:L20" ] 6402cwindow 6403only 6404let qf_wid = win_getid () 6405" create the maximum number of scratch windows 6406let hor_win_count = ( & lines - 1 ) / 2 6407let hor_split_count = hor_win_count - 1 6408for s in range ( 1 , hor_split_count ) |new |set buftype = nofile |endfor 6409call win_gotoid ( qf_wid ) 6410call assert_fails ( 'exe "normal \<CR>"' , 'E36:' ) 6411 %bw ! 6412endfunc 6413 6414" Test for updating the location list when only the location list window is 6415" present and the corresponding file window is closed. 6416func Test_loclist_update_with_llwin_only () 6417 %bw ! 6418new 6419wincmd w 6420lexpr ["Xfile1:1:Line1"] 6421lopen 6422wincmd p 6423close 6424call setloclist ( 2 , [], 'r' , { 'lines' : [ "Xtest2:2:Line2" ]}) 6425call assert_equal ([ 'Xtest2|2| Line2' ], getbufline ( winbufnr ( 2 ), 1 , '$' )) 6426 %bw ! 6427endfunc 6428 6429" Test for getting the quickfix list after a buffer with an error is wiped out 6430func Test_getqflist_wiped_out_buffer () 6431 %bw ! 6432cexpr ["Xtest1:34:Wiped out"] 6433let bnum = bufnr ( 'Xtest1' ) 6434call assert_equal ( bnum , getqflist ()[ 0 ]. bufnr ) 6435bw Xtest1 6436call assert_equal ( 0 , getqflist ()[ 0 ]. bufnr ) 6437 %bw ! 6438endfunc 6439 6440" Test for the status message that is displayed when opening a new quickfix 6441" list 6442func Test_qflist_statusmsg () 6443cexpr "1\n2" 6444cexpr "1\n2\n3\ntest_quickfix.vim:1:msg" 6445call assert_equal ( '(4 of 4): msg' , v: statusmsg ) 6446call setqflist ([], 'f' ) 6447 %bw ! 6448 6449" When creating a new quickfix list, if an autocmd changes the quickfix list 6450" in the stack, then an error message should be displayed. 6451augroup QF_Test 6452au ! 6453au BufEnter test_quickfix.vim colder 6454augroup END 6455cexpr "1\n2" 6456call assert_fails ( 'cexpr "1\n2\n3\ntest_quickfix.vim:1:msg"' , 'E925:' ) 6457call setqflist ([], 'f' ) 6458augroup QF_Test 6459au ! 6460augroup END 6461 %bw ! 6462 6463augroup QF_Test 6464au ! 6465au BufEnter test_quickfix.vim caddexpr "4" 6466augroup END 6467call assert_fails ( 'cexpr "1\n2\n3\ntest_quickfix.vim:1:msg"' , 'E925:' ) 6468call setqflist ([], 'f' ) 6469augroup QF_Test 6470au ! 6471augroup END 6472 %bw ! 6473endfunc 6474 6475func Test_quickfixtextfunc_recursive () 6476func s: QFTfunc ( o ) 6477cgete '0' 6478endfunc 6479copen 6480let & quickfixtextfunc = 's:QFTfunc' 6481cex "" 6482 6483let & quickfixtextfunc = '' 6484cclose 6485endfunc 6486 6487" Test for replacing the location list from an autocmd. This used to cause a 6488" read from freed memory. 6489func Test_loclist_replace_autocmd () 6490 %bw ! 6491call setloclist ( 0 , [], 'f' ) 6492let s: bufnr = bufnr () 6493cal setloclist ( 0 , [{ '0' : 0 , '' : '' }]) 6494au BufEnter * cal setloclist ( 1 , [{ 't' : '' }, { 'bufnr' : s: bufnr }], 'r' ) 6495lopen 6496try 6497exe "norm j\<CR>" 6498catch 6499endtry 6500lnext 6501 %bw ! 6502call setloclist ( 0 , [], 'f' ) 6503endfunc 6504 6505" Test for a very long error line and a very long information line 6506func Test_very_long_error_line () 6507let msg = repeat ( 'abcdefghijklmn' , 146 ) 6508let emsg = 'Xlonglines.c:1:' . msg 6509call writefile ([ msg , emsg ], 'Xerror' , 'D' ) 6510cfile Xerror 6511cwindow 6512call assert_equal ( $ '|| {msg}', getline(1)) 6513call assert_equal ( $ 'Xlonglines.c|1| {msg}', getline(2)) 6514cclose 6515 6516let l = execute ( 'clist!' ) ->split ( "\n" ) 6517call assert_equal ([ $ '1: {msg}', $'2 Xlonglines.c:1: {msg}'], l) 6518 6519let l = execute ( 'cc' ) ->split ( "\n" ) 6520call assert_equal ([ $ '(2 of2): {msg}'], l) 6521 6522call setqflist ([], 'f' ) 6523endfunc 6524 6525" In the quickfix window, spaces at the beginning of an informational line 6526" should not be removed but should be removed from an error line. 6527func Test_info_line_with_space () 6528cexpr ["a.c:20:12: error: expected';' before':' token", 6529 \' 20 | Afunc():' ,'' ,' | ^' ] 6530copen 6531call assert_equal ([ "a.c|20 col 12| error: expected ';' before ':' token" , 6532 \'|| 20 | Afunc():' , '|| ' , 6533 \'|| | ^' ], getline ( 1 , '$' )) 6534cclose 6535 6536let l = execute ( 'clist!' ) ->split ( "\n" ) 6537call assert_equal ([ " 1 a.c:20 col 12: error: expected ';' before ':' token" , 6538 \' 2: 20 | Afunc():' , ' 3: ' , ' 4: | ^' ], l ) 6539 6540call setqflist ([], 'f' ) 6541endfunc 6542 6543func s: QfTf ( _ ) 6544endfunc 6545 6546func Test_setqflist_cb_arg () 6547" This was changing the callback name in the dictionary. 6548let d = #{ quickfixtextfunc : 's:QfTf' } 6549call setqflist ([], 'a' , d ) 6550call assert_equal ( 's:QfTf' , d . quickfixtextfunc ) 6551 6552call setqflist ([], 'f' ) 6553endfunc 6554 6555" Test that setqflist() should not prevent :stopinsert from working 6556func Test_setqflist_stopinsert () 6557new 6558call setqflist ([], 'f' ) 6559copen 6560cclose 6561func StopInsert () 6562stopinsert 6563call setqflist ([{ 'text' : 'foo' }]) 6564return '' 6565endfunc 6566 6567call setline ( 1 , 'abc' ) 6568call cursor ( 1 , 1 ) 6569call feedkeys ( "i\<C-R>=StopInsert()\<CR>$" , 'tnix' ) 6570call assert_equal ( 'foo' , getqflist ()[ 0 ]. text ) 6571call assert_equal ([ 0 , 1 , 3 , 0 , v: maxcol ], getcurpos ()) 6572call assert_equal ([ 'abc' ], getline ( 1 , '$' )) 6573 6574delfunc StopInsert 6575call setqflist ([], 'f' ) 6576bwipe ! 6577endfunc 6578 6579func Test_quickfix_buffer_contents () 6580call setqflist ([{ 'filename' : 'filename' , 'pattern' : 'pattern' , 'text' : 'text' }]) 6581copen 6582call assert_equal ([ 'filename|pattern| text' ], getline ( 1 , '$' )) " The assert failed with Vim v9.0.0736; '| text' did not appear after the pattern. 6583call setqflist ([], 'f' ) 6584endfunc 6585 6586func XquickfixUpdateTests ( cchar ) 6587call s: setup_commands ( a: cchar ) 6588 6589" Setup: populate a couple buffers 6590new 6591call setline ( 1 , range ( 1 , 5 )) 6592let b1 = bufnr () 6593new 6594call setline ( 1 , range ( 1 , 3 )) 6595let b2 = bufnr () 6596" Setup: set a quickfix list. 6597let items = [{ 'bufnr' : b1 , 'lnum' : 1 }, { 'bufnr' : b1 , 'lnum' : 2 }, { 'bufnr' : b2 , 'lnum' : 1 }, { 'bufnr' : b2 , 'lnum' : 2 }] 6598call g: Xsetlist ( items ) 6599 6600" Open the quickfix list, select the third entry. 6601Xopen 6602exe "normal jj\<CR>" 6603call assert_equal ( 3 , g: Xgetlist ({ 'idx' : 0 }). idx ) 6604 6605" Update the quickfix list. Make sure the third entry is still selected. 6606call g: Xsetlist ([], 'u' , { 'items' : items }) 6607call assert_equal ( 3 , g: Xgetlist ({ 'idx' : 0 }). idx ) 6608 6609" Update the quickfix list again, but this time with missing line number 6610" information. Confirm that we keep the current buffer selected. 6611call g: Xsetlist ([{ 'bufnr' : b1 }, { 'bufnr' : b2 }], 'u' ) 6612call assert_equal ( 2 , g: Xgetlist ({ 'idx' : 0 }). idx ) 6613 6614Xclose 6615 6616" Cleanup the buffers we allocated during this test. 6617 %bwipe ! 6618endfunc 6619 6620" Test for updating a quickfix list using the "u" flag in setqflist() 6621func Test_quickfix_update () 6622call XquickfixUpdateTests ( 'c' ) 6623call XquickfixUpdateTests ( 'l' ) 6624endfunc 6625 6626func Test_quickfix_update_with_missing_coordinate_info () 6627new 6628call setline ( 1 , range ( 1 , 5 )) 6629let b1 = bufnr () 6630 6631new 6632call setline ( 1 , range ( 1 , 3 )) 6633let b2 = bufnr () 6634 6635new 6636call setline ( 1 , range ( 1 , 2 )) 6637let b3 = bufnr () 6638 6639" Setup: set a quickfix list with no coordinate information at all. 6640call setqflist ([{}, {}]) 6641 6642" Open the quickfix list, select the second entry. 6643copen 6644exe "normal j\<CR>" 6645call assert_equal ( 2 , getqflist ({ 'idx' : 0 }). idx ) 6646 6647" Update the quickfix list. As the previously selected entry has no 6648" coordinate information, we expect the first entry to now be selected. 6649call setqflist ([{ 'bufnr' : b1 }, { 'bufnr' : b2 }, { 'bufnr' : b3 }], 'u' ) 6650call assert_equal ( 1 , getqflist ({ 'idx' : 0 }). idx ) 6651 6652" Select the second entry in the quickfix list. 6653copen 6654exe "normal j\<CR>" 6655call assert_equal ( 2 , getqflist ({ 'idx' : 0 }). idx ) 6656 6657" Update the quickfix list again. The currently selected entry does not have 6658" a line number, but we should keep the file selected. 6659call setqflist ([{ 'bufnr' : b1 }, { 'bufnr' : b2 , 'lnum' : 3 }, { 'bufnr' : b3 }], 'u' ) 6660call assert_equal ( 2 , getqflist ({ 'idx' : 0 }). idx ) 6661 6662" Update the quickfix list again. The currently selected entry (bufnr=b2, lnum=3) 6663" is no longer present. We should pick the nearest entry. 6664call setqflist ([{ 'bufnr' : b1 }, { 'bufnr' : b2 , 'lnum' : 1 }, { 'bufnr' : b2 , 'lnum' : 4 }], 'u' ) 6665call assert_equal ( 3 , getqflist ({ 'idx' : 0 }). idx ) 6666 6667" Set the quickfix list again, with a specific column number. The currently selected entry doesn't have a 6668" column number, but they share a line number. 6669call setqflist ([{ 'bufnr' : b1 }, { 'bufnr' : b2 , 'lnum' : 4 , 'col' : 5 }, { 'bufnr' : b2 , 'lnum' : 4 , 'col' : 6 }], 'u' ) 6670call assert_equal ( 2 , getqflist ({ 'idx' : 0 }). idx ) 6671 6672" Set the quickfix list again. The currently selected column number (6) is 6673" no longer present. We should select the nearest column number. 6674call setqflist ([{ 'bufnr' : b1 }, { 'bufnr' : b2 , 'lnum' : 4 , 'col' : 2 }, { 'bufnr' : b2 , 'lnum' : 4 , 'col' : 4 }], 'u' ) 6675call assert_equal ( 3 , getqflist ({ 'idx' : 0 }). idx ) 6676 6677" Now set the quickfix list, but without columns. We should still pick the 6678" same line. 6679call setqflist ([{ 'bufnr' : b2 , 'lnum' : 3 }, { 'bufnr' : b2 , 'lnum' : 4 }, { 'bufnr' : b2 , 'lnum' : 4 }], 'u' ) 6680call assert_equal ( 2 , getqflist ({ 'idx' : 0 }). idx ) 6681 6682" Cleanup the buffers we allocated during this test. 6683 %bwipe ! 6684endfunc 6685 6686" Test for "%b" in "errorformat" 6687func Test_efm_format_b () 6688call setqflist ([], 'f' ) 6689new 6690call setline ( 1 , [ '1: abc' , '1: def' , '1: ghi' ]) 6691let b1 = bufnr () 6692new 6693call setline ( 1 , [ '2: abc' , '2: def' , '2: ghi' ]) 6694let b2 = bufnr () 6695new 6696call setline ( 1 , [ '3: abc' , '3: def' , '3: ghi' ]) 6697let b3 = bufnr () 6698new 6699let lines =<< trim eval END 6700{b1}:1:1 6701{b2}:2:2 6702{b3}:3:3 6703END 6704call setqflist ([], ' ' , #{ lines : lines , efm : '%b:%l:%c' }) 6705cfirst 6706call assert_equal ([ b1 , 1 , 1 ], [ bufnr (), line ( '.' ), col ( '.' )]) 6707cnext 6708call assert_equal ([ b2 , 2 , 2 ], [ bufnr (), line ( '.' ), col ( '.' )]) 6709cnext 6710call assert_equal ([ b3 , 3 , 3 ], [ bufnr (), line ( '.' ), col ( '.' )]) 6711enew ! 6712 6713" Use a non-existing buffer 6714let lines =<< trim eval END 67159991:1:1:m1 67169992:2:2:m2 6717{b3}:3:3:m3 6718END 6719call setqflist ([], ' ' , #{ lines : lines , efm : '%b:%l:%c:%m' }) 6720cfirst |cnext 6721call assert_equal ([ b3 , 3 , 3 ], [ bufnr (), line ( '.' ), col ( '.' )]) 6722" Lines with non-existing buffer numbers should be used as non-error lines 6723call assert_equal ([ 6724 \#{ lnum : 0 , bufnr : 0 , end_lnum : 0 , pattern : '' , valid : 0 , vcol : 0 , nr : -1 , 6725 \module : '' , type : '' , end_col : 0 , col : 0 , text : '9991:1:1:m1' }, 6726 \#{ lnum : 0 , bufnr : 0 , end_lnum : 0 , pattern : '' , valid : 0 , vcol : 0 , nr : -1 , 6727 \module : '' , type : '' , end_col : 0 , col : 0 , text : '9992:2:2:m2' }, 6728 \#{ lnum : 3 , bufnr : b3 , end_lnum : 0 , pattern : '' , valid : 1 , vcol : 0 , 6729 \nr : -1 , module : '' , type : '' , end_col : 0 , col : 3 , text : 'm3' }], 6730 \getqflist ()) 6731 %bw ! 6732call setqflist ([], 'f' ) 6733endfunc 6734 6735func XbufferTests_range ( cchar ) 6736call s: setup_commands ( a: cchar ) 6737 6738enew ! 6739let lines =<< trim END 6740Xtestfile7:700:10:Line 700 6741Xtestfile8:800:15:Line 800 6742END 6743silent ! call setline ( 1 , lines ) 6744norm ! Vy 6745" Note: We cannot use :Xbuffer here, 6746" it doesn't properly fail, so we need to 6747" test using the raw c/l commands. 6748" (also further down) 6749if ( a: cchar == 'c' ) 6750exe "'<,'>cbuffer!" 6751else 6752exe "'<,'>lbuffer!" 6753endif 6754let l = g: Xgetlist () 6755call assert_true ( len ( l ) == 1 && 6756 \l [ 0 ]. lnum == 700 && l [ 0 ]. col == 10 && l [ 0 ]. text ==# 'Line 700' ) 6757 6758enew ! 6759let lines =<< trim END 6760Xtestfile9:900:55:Line 900 6761Xtestfile10:950:66:Line 950 6762END 6763silent ! call setline ( 1 , lines ) 6764if ( a: cchar == 'c' ) 67651 cgetbuffer 6766else 67671 lgetbuffer 6768endif 6769let l = g: Xgetlist () 6770call assert_true ( len ( l ) == 1 && 6771 \l [ 0 ]. lnum == 900 && l [ 0 ]. col == 55 && l [ 0 ]. text ==# 'Line 900' ) 6772 6773enew ! 6774let lines =<< trim END 6775Xtestfile11:700:20:Line 700 6776Xtestfile12:750:25:Line 750 6777END 6778silent ! call setline ( 1 , lines ) 6779if ( a: cchar == 'c' ) 67801 , 1 caddbuffer 6781else 67821 , 1 laddbuffer 6783endif 6784let l = g: Xgetlist () 6785call assert_true ( len ( l ) == 2 && 6786 \l [ 0 ]. lnum == 900 && l [ 0 ]. col == 55 && l [ 0 ]. text ==# 'Line 900' && 6787 \l [ 1 ]. lnum == 700 && l [ 1 ]. col == 20 && l [ 1 ]. text ==# 'Line 700' ) 6788enew ! 6789 6790" Check for invalid range 6791" Using Xbuffer will not run the range check in the cbuffer/lbuffer 6792" commands. So directly call the commands. 6793if ( a: cchar == 'c' ) 6794call assert_fails ( '900,999caddbuffer' , 'E16:' ) 6795else 6796call assert_fails ( '900,999laddbuffer' , 'E16:' ) 6797endif 6798endfunc 6799 6800func Test_cbuffer_range () 6801call XbufferTests_range ( 'c' ) 6802call XbufferTests_range ( 'l' ) 6803endfunc 6804 6805" Test for displaying fname passed from setqflist() when the names include 6806" hard links to prevent seemingly duplicate entries. 6807func Xtest_hardlink_fname ( cchar ) 6808call s: setup_commands ( a: cchar ) 6809 %bwipe 6810" Create a sample source file 6811let lines =<< trim END 6812void sample() {} 6813int main() { sample(); return 0; } 6814END 6815call writefile ( lines , 'test_qf_hardlink1.c' , 'D' ) 6816defer delete('test_qf_hardlink1.c') 6817defer delete('test_qf_hardlink2.c') 6818call system ( 'ln test_qf_hardlink1.c test_qf_hardlink2.c' ) 6819if v: shell_error 6820throw 'Skipped: ln throws error on this platform' 6821endif 6822call g: Xsetlist ([], 'f' ) 6823" Make a qflist that contains the file and it's hard link 6824" like how LSP plugins set response into qflist 6825call g: Xsetlist ([{ 'filename' : 'test_qf_hardlink1.c' , 'lnum' : 1 }, 6826 \{ 'filename' : 'test_qf_hardlink2.c' , 'lnum' : 1 }], ' ' ) 6827Xopen 6828" Ensure that two entries are displayed with different name 6829" so that they aren't seen as duplication. 6830call assert_equal ([ 'test_qf_hardlink1.c|1| ' , 6831 \'test_qf_hardlink2.c|1| ' ], getline ( 1 , '$' )) 6832Xclose 6833endfunc 6834 6835func Test_hardlink_fname () 6836CheckUnix 6837CheckExecutable ln 6838call Xtest_hardlink_fname ( 'c' ) 6839call Xtest_hardlink_fname ( 'l' ) 6840endfunc 6841 6842" Test for checking if correct number of tests are deleted 6843" and current list stays the same after setting Xhistory 6844" to a smaller number. Do roughly the same for growing the stack. 6845func Xtest_resize_list_stack ( cchar ) 6846call s: setup_commands ( a: cchar ) 6847Xsethist 100 6848 6849for i in range ( 1 , 100 ) 6850Xexpr string(i) 6851endfor 6852Xopen 6853call assert_equal ( g: Xgetlist ({ 'nr' : '$' }). nr , 100 ) 6854call assert_equal ( "|| 100" , getline ( 1 )) 6855Xsethist 8 6856call assert_equal ( "|| 100" , getline ( 1 )) 6857Xolder 5 6858call assert_equal ( "|| 95" , getline ( 1 )) 6859Xsethist 6 6860call assert_equal ( "|| 95" , getline ( 1 )) 6861Xsethist 1 6862call assert_equal ( "|| 100" , getline ( 1 )) 6863 6864" grow array again 6865Xsethist 100 6866for i in range ( 1 , 99 ) 6867Xexpr string(i) 6868endfor 6869call assert_equal ( "|| 99" , getline ( 1 )) 6870Xolder 99 6871call assert_equal ( "|| 100" , getline ( 1 )) 6872 6873Xsethistdefault 6874endfunc 6875 6876func Test_resize_list_stack () 6877call Xtest_resize_list_stack ( 'c' ) 6878call Xtest_resize_list_stack ( 'l' ) 6879endfunc 6880 6881" Test to check if order of lists is from 6882" oldest at the bottom to newest at the top 6883func Xtest_Xhistory_check_order ( cchar ) 6884 6885Xsethist 100 6886 6887for i in range ( 1 , 100 ) 6888Xexpr string(i) 6889endfor 6890 6891Xopen 6892for i in range ( 100 , 1 , -1 ) 6893let l: ret = assert_equal ( "|| " .. i , getline ( 1 )) 6894 6895if ret == 1 || i == 1 6896break 6897endif 6898Xolder 6899endfor 6900 6901for i in range ( 1 , 50 ) 6902Xexpr string(i) 6903endfor 6904 6905for i in range ( 50 , 1 , -1 ) 6906let l: ret = assert_equal ( "|| " .. i , getline ( 1 )) 6907 6908if ret == 1 || i == 50 6909break 6910endif 6911Xolder 6912endfor 6913 6914for i in range ( 50 , 1 , -1 ) 6915let l: ret = assert_equal ( "|| " .. i , getline ( 1 )) 6916 6917if ret == 1 || i == 50 6918break 6919endif 6920Xolder 6921endfor 6922 6923Xsethistdefault 6924endfunc 6925 6926func Test_set_history_to_check_order () 6927call Xtest_Xhistory_check_order ( 'c' ) 6928call Xtest_Xhistory_check_order ( 'l' ) 6929endfunc 6930 6931" Check if 'lhistory' is the same between the location list window 6932" and associated normal window 6933func Test_win_and_loc_synced () 6934new 6935set lhistory = 2 6936lexpr "Text" 6937lopen 6938 6939" check if lhistory is synced when modified inside the 6940" location list window 6941setlocal lhistory = 1 6942wincmd k 6943call assert_equal ( & lhistory , 1 ) 6944 6945" check if lhistory is synced when modified inside the 6946" normal window 6947setlocal lhistory = 10 6948lopen 6949call assert_equal ( & lhistory , 10 ) 6950 6951wincmd k 6952lclose 6953wincmd q 6954 6955set lhistory & 6956endfunc 6957 6958" Test if setting the lhistory of one window doesn't affect the other 6959func Test_two_win_are_independent_of_history () 6960setlocal lhistory = 10 6961new 6962setlocal lhistory = 20 6963wincmd w 6964call assert_equal ( & lhistory , 10 ) 6965wincmd w 6966wincmd q 6967 6968set lhistory & 6969endfunc 6970 6971" Test if lhistory is copied over to a new window 6972func Test_lhistory_copied_over () 6973setlocal lhistory = 3 6974split 6975call assert_equal ( & lhistory , 3 ) 6976wincmd q 6977 6978set lhistory & 6979endfunc 6980 6981" Test if error occurs when given invalid history number 6982func Xtest_invalid_history_num ( cchar ) 6983call s: setup_commands ( a: cchar ) 6984 6985call assert_fails ( 'Xsethist -10000' , "E1542:" ) 6986call assert_fails ( 'Xsethist 10000' , "E1543:" ) 6987Xsethistdefault 6988endfunc 6989 6990func Test_invalid_history_num () 6991call Xtest_invalid_history_num ( 'c' ) 6992call Xtest_invalid_history_num ( 'l' ) 6993endfunc 6994 6995" Test if chistory and lhistory don't affect each other 6996func Test_chi_and_lhi_are_independent () 6997set chistory = 100 6998set lhistory = 100 6999 7000set chistory = 10 7001call assert_equal ( & lhistory , 100 ) 7002 7003set lhistory = 1 7004call assert_equal ( & chistory , 10 ) 7005 7006set chistory & 7007set lhistory & 7008endfunc 7009 7010func Test_quickfix_close_buffer_crash () 7011new 7012lexpr 'test' |lopen 7013wincmd k 7014lclose 7015wincmd q 7016endfunc 7017 7018func Test_vimgrep_dummy_buffer_crash () 7019augroup DummyCrash 7020autocmd ! 7021" Make the dummy buffer non-current, but still open in a window. 7022autocmd BufReadCmd * ++oncelet s: dummy_buf = bufnr () 7023 \|split |wincmd p |enew 7024 7025" Autocmds from cleaning up the dummy buffer in this case should be blocked. 7026autocmd BufWipeout * 7027 \call assert_notequal ( s: dummy_buf , str2nr ( expand ( '<abuf>' ))) 7028augroup END 7029 7030silent ! vimgrep /./ . 7031redraw ! " Window to freed dummy buffer used to remain; heap UAF. 7032call assert_equal ([], win_findbuf ( s: dummy_buf )) 7033call assert_equal ( 0 , bufexists ( s: dummy_buf )) 7034 7035unlet ! s: dummy_buf 7036autocmd ! DummyCrash 7037% bw ! 7038endfunc 7039 7040func Test_vimgrep_dummy_buffer_keep () 7041augroup DummyKeep 7042autocmd ! 7043" Trigger a wipe of the dummy buffer by aborting script processing. Prevent 7044" wiping it by splitting it from the autocmd window into an only window. 7045autocmd BufReadCmd * ++once let s: dummy_buf = bufnr () 7046\| tab split | call interrupt () 7047augroup END 7048 7049call assert_fails ( 'vimgrep /./ .' ) 7050call assert_equal ( 1 , bufexists ( s: dummy_buf )) 7051" Ensure it's no longer considered a dummy; should be able to switch to it. 7052execute s: dummy_buf 'sbuffer' 7053 7054unlet ! s: dummy_buf 7055autocmd ! DummyKeep 7056% bw ! 7057endfunc 7058 7059func Test_quickfix_restore_current_win () 7060let curwin = win_getid () 7061vsplit Xb 7062wincmd p 7063botright copen 7064cclose 7065 7066call assert_equal ( curwin , win_getid ()) 7067bw ! Xb 7068endfunc 7069 7070func Test_quickfixtextfunc_wipes_buffer () 7071let g: crash = "" 7072new 7073fu QFexpr ( dummy ) 7074bw 7075endfu 7076try 7077set quickfixtextfunc = QFexpr 7078lad "['0:4:e']" 7079lw 7080catch /^Vim\%((\S\+)\)\=:E565:/ 7081let g: crash = 'caught' 7082endtry 7083" close location list window 7084bw 7085delfunc QFexpr 7086set quickfixtextfunc = 7087call assert_equal ( 'caught' , g: crash ) 7088unlet g: crash 7089" close the newly opened window 7090bw 7091endfunc 7092 7093func Test_quickfix_longline_noeol () 7094let qf = 'Xquickfix' 7095let args = $ "-q {qf}" 7096let after =<< trim [CODE] 7097call writefile(['okay'], "XDONE") 7098qall! 7099[CODE] 7100defer delete("XDONE") 7101call writefile ([ repeat ( 'A' , 1024 )], qf , 'bD' ) 7102call RunVim ([], after , args ) 7103call WaitForAssert ({ -> assert_true ( filereadable ( "XDONE" ))}) 7104call assert_equal ([ 'okay' ], readfile ( "XDONE" )) 7105endfunc 7106 7107func Test_efm_overlongline () 7108let save_efm = & efm 7109" %r captures the tail. 7110set efm = %+O(%.%#)%r,%f:%l:%m 7111 7112" First line is longer than IOSIZE (1025) so the parser puts it in 7113" growbuf; the %r tail then far exceeds IObuff. 7114let lines = [ '(short)' .. repeat ( 'x' , 4000 ), 'Xfile:10:msg' ] 7115call writefile ( lines , 'Xqferrlong' , 'D' ) 7116 7117" Must complete without hanging or crashing. 7118cgetfile Xqferrlong 7119 7120" The well-formed line that follows is still parsed. 7121let well_formed = filter ( getqflist (), 'v:val.lnum == 10' ) 7122call assert_equal ( 1 , len ( well_formed )) 7123call assert_equal ( 'msg' , well_formed [ 0 ]. text ) 7124 7125let & efm = save_efm 7126call setqflist ([], 'f' ) 7127endfunc 7128 7129func Xtest_set_qftf_in_sandbox ( cchar ) 7130call s: setup_commands ( a: cchar ) 7131 7132call g: Xsetlist ([{ 'filename' : 'test.c' , 'lnum' : 1 , 'text' : 'trigger' }]) 7133let g: qftf_fn_called = v: false 7134func Qftf_Fn ( d ) 7135let g: qftf_fn_called = v: true 7136return [] 7137endfunc 7138 7139let g: caught_exception = v: false 7140try 7141sandbox call g:Xsetlist([], 'a' , #{quickfixtextfunc: 'g:Qftf_Fn' }) 7142catch /E48:/ 7143let g: caught_exception = v: true 7144endtry 7145copen 7146cclose 7147 7148call assert_equal ( v: true , g: caught_exception ) 7149call assert_equal ( v: false , g: qftf_fn_called ) 7150 7151delfunc Qftf_Fn 7152unlet g: caught_exception 7153unlet g: qftf_fn_called 7154% bw ! 7155endfunc 7156 7157" Test for setting the 'quickfixtextfunc' in a sandbox 7158func Test_set_qftf_in_sandbox () 7159call Xtest_set_qftf_in_sandbox ( 'c' ) 7160call Xtest_set_qftf_in_sandbox ( 'l' ) 7161endfunc 7162 7163" Test for the 'statusline' height remaining at one when the quickfix buffer 7164" is wiped out when quickfix window is the only window open. 7165func Test_qf_statusline_height () 7166% bw ! 7167copen 7168wincmd p 7169let prev_wh = winheight ( '.' ) 7170wincmd p 7171only 7172bw ! 7173copen 7174wincmd p 7175call assert_equal ( prev_wh , winheight ( '.' )) 7176% bw ! 7177endfunc 7178 7179" vim: shiftwidth=2 sts=2 expandtab