robin/laufey
git clone https://git.robinwobin.dev/robin/laufey
f907614088
master
1local t =require ( 'test.testutil' ) 2local n =require ( 'test.functional.testnvim' )() 3local Screen =require ( 'test.functional.ui.screen' ) 4 5local describe , it , before_each , after_each , finally = 6t . describe , t . it , t . before_each , t . after_each , t . finally 7local feed =n . feed 8local eq =t . eq 9local pcall_err =t . pcall_err 10local clear =n . clear 11local fn =n . fn 12local command =n . command 13local write_file =t . write_file 14local api =n . api 15local source =n . source 16 17local file_base ='Xtest-functional-ex_cmds-quickfix_commands' 18 19before_each ( clear ) 20 21for _ , c in ipairs ( { 'l' , 'c' } ) do 22local file =( '%s.%s' ): format ( file_base , c ) 23local filecmd =c .. 'file' 24local getfcmd =c .. 'getfile' 25local addfcmd =c .. 'addfile' 26local getlist =( c == 'c' ) and fn . getqflist or function () 27return fn . getloclist ( 0 ) 28end 29 30describe (( ':%s*file commands' ): format ( c ), function () 31before_each ( function () 32write_file ( 33file , 34( [[ 35%s-1.res:700:10:Line 700 36%s-2.res:800:15:Line 800 37]] ): format ( file , file ) 38) 39end ) 40after_each ( function () 41os . remove ( file ) 42end ) 43 44it ( 'work' , function () 45command (( '%s %s' ): format ( filecmd , file )) 46-- Second line of each entry (i.e. `nr=-1, …`) was obtained from actual 47-- results. First line (i.e. `{lnum=…`) was obtained from legacy test. 48local list ={ 49{ 50lnum =700 , 51end_lnum =0 , 52col =10 , 53end_col =0 , 54text ='Line 700' , 55module ='' , 56nr =- 1 , 57bufnr =2 , 58valid =1 , 59pattern ='' , 60vcol =0 , 61[ 'type' ] ='' , 62} , 63{ 64lnum =800 , 65end_lnum =0 , 66col =15 , 67end_col =0 , 68text ='Line 800' , 69module ='' , 70nr =- 1 , 71bufnr =3 , 72valid =1 , 73pattern ='' , 74vcol =0 , 75[ 'type' ] ='' , 76} , 77} 78eq ( list , getlist ()) 79eq (( '%s-1.res' ): format ( file ), fn . bufname ( list [ 1 ]. bufnr )) 80eq (( '%s-2.res' ): format ( file ), fn . bufname ( list [ 2 ]. bufnr )) 81 82-- Run cfile/lfile from a modified buffer 83command ( 'set nohidden' ) 84command ( 'enew!' ) 85api . nvim_buf_set_lines ( 0 , 1 , 1 , true , { 'Quickfix' } ) 86eq ( 87( 'Vim(%s):E37: No write since last change (add ! to override)' ): format ( filecmd ), 88pcall_err ( command , ( '%s %s' ): format ( filecmd , file )) 89) 90 91write_file ( 92file , 93( [[ 94%s-3.res:900:30:Line 900 95]] ): format ( file ) 96) 97command (( '%s %s' ): format ( addfcmd , file )) 98list [ # list + 1 ] ={ 99lnum =900 , 100end_lnum =0 , 101col =30 , 102end_col =0 , 103text ='Line 900' , 104module ='' , 105nr =- 1 , 106bufnr =5 , 107valid =1 , 108pattern ='' , 109vcol =0 , 110[ 'type' ] ='' , 111} 112eq ( list , getlist ()) 113eq (( '%s-3.res' ): format ( file ), fn . bufname ( list [ 3 ]. bufnr )) 114 115write_file ( 116file , 117( [[ 118%s-1.res:222:77:Line 222 119%s-2.res:333:88:Line 333 120]] ): format ( file , file ) 121) 122command ( 'enew!' ) 123command (( '%s %s' ): format ( getfcmd , file )) 124list ={ 125{ 126lnum =222 , 127end_lnum =0 , 128col =77 , 129end_col =0 , 130text ='Line 222' , 131module ='' , 132nr =- 1 , 133bufnr =2 , 134valid =1 , 135pattern ='' , 136vcol =0 , 137[ 'type' ] ='' , 138} , 139{ 140lnum =333 , 141end_lnum =0 , 142col =88 , 143end_col =0 , 144text ='Line 333' , 145module ='' , 146nr =- 1 , 147bufnr =3 , 148valid =1 , 149pattern ='' , 150vcol =0 , 151[ 'type' ] ='' , 152} , 153} 154eq ( list , getlist ()) 155eq (( '%s-1.res' ): format ( file ), fn . bufname ( list [ 1 ]. bufnr )) 156eq (( '%s-2.res' ): format ( file ), fn . bufname ( list [ 2 ]. bufnr )) 157end ) 158end ) 159end 160 161describe ( 'quickfix' , function () 162it ( 'location-list update on buffer modification' , function () 163source ( [[ 164new 165setl bt=nofile 166let lines = ['Line 1', 'Line 2', 'Line 3', 'Line 4', 'Line 5'] 167call append(0, lines) 168new 169setl bt=nofile 170call append(0, lines) 171let qf_item = { 172\ 'lnum': 4, 173\ 'text': "This is the error line.", 174\ } 175let qf_item['bufnr'] = bufnr('%') 176call setloclist(0, [qf_item]) 177wincmd p 178let qf_item['bufnr'] = bufnr('%') 179call setloclist(0, [qf_item]) 1801del _ 181call append(0, ['New line 1', 'New line 2', 'New line 3']) 182silent ll 183]] ) 184eq ( { 0 , 6 , 1 , 0 , 1 } , fn . getcurpos ()) 185end ) 186 187it ( 'BufAdd does not cause E16 when reusing quickfix buffer #18135' , function () 188local file =file_base .. '_reuse_qfbuf_BufAdd' 189write_file ( file , ( '\n' ): rep ( 100 ) .. 'foo' ) 190finally ( function () 191os . remove ( file ) 192end ) 193source ( [[ 194set grepprg=internal 195autocmd BufAdd * call and(0, 0) 196autocmd QuickFixCmdPost grep ++nested cclose | cwindow 197]] ) 198command ( 'grep foo ' .. file ) 199command ( 'grep foo ' .. file ) 200end ) 201 202it ( 'jump message does not scroll with cmdheight=0 and shm+=O #29597' , function () 203local screen =Screen . new ( 40 , 6 ) 204command ( 'set cmdheight=0' ) 205local file =file_base .. '_reuse_qfbuf_BufAdd' 206write_file ( file , 'foobar' ) 207finally ( function () 208os . remove ( file ) 209end ) 210command ( 'vimgrep /foo/gj ' .. file ) 211feed ( ':cc<CR>' ) 212screen : expect ( [[ 213^foobar | 214{1:~ }|*4 215(1 of 1): foobar | 216]] ) 217end ) 218end ) 219 220it ( ':vimgrep can specify Unicode pattern without delimiters' , function () 221eq ( 222'Vim(vimgrep):E480: No match: →' , 223pcall_err ( command , 'vimgrep → test/functional/fixtures/tty-test.c' ) 224) 225local screen =Screen . new ( 40 , 6 ) 226screen : set_default_attr_ids ( { 227[ 0 ] ={ bold =true , foreground =Screen . colors . Blue } , -- NonText 228[ 1 ] ={ reverse =true } , -- IncSearch 229} ) 230feed ( 'i→<Esc>:vimgrep →' ) 231screen : expect ( [[ 232{1:→} | 233{0:~ }|*4 234:vimgrep →^ | 235]] ) 236end )