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