blob: d624baf80a1696bbdc5368bf8003bb72aeec58f9 [file] [log] [blame]
Bram Moolenaarda59dd52016-01-05 21:59:58 +01001" Test for the quickfix commands.
2
3if !has('quickfix')
4 finish
5endif
6
Bram Moolenaar7eba3d22016-03-19 22:54:09 +01007set encoding=utf-8
8
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02009function! s:setup_commands(cchar)
10 if a:cchar == 'c'
11 command! -nargs=* -bang Xlist <mods>clist<bang> <args>
12 command! -nargs=* Xgetexpr <mods>cgetexpr <args>
Bram Moolenaar361c8f02016-07-02 15:41:47 +020013 command! -nargs=* Xaddexpr <mods>caddexpr <args>
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +020014 command! -nargs=* Xolder <mods>colder <args>
15 command! -nargs=* Xnewer <mods>cnewer <args>
16 command! -nargs=* Xopen <mods>copen <args>
17 command! -nargs=* Xwindow <mods>cwindow <args>
18 command! -nargs=* Xclose <mods>cclose <args>
19 command! -nargs=* -bang Xfile <mods>cfile<bang> <args>
20 command! -nargs=* Xgetfile <mods>cgetfile <args>
21 command! -nargs=* Xaddfile <mods>caddfile <args>
22 command! -nargs=* -bang Xbuffer <mods>cbuffer<bang> <args>
23 command! -nargs=* Xgetbuffer <mods>cgetbuffer <args>
24 command! -nargs=* Xaddbuffer <mods>caddbuffer <args>
25 command! -nargs=* Xrewind <mods>crewind <args>
26 command! -nargs=* -bang Xnext <mods>cnext<bang> <args>
Bram Moolenaar0fcc7c62016-07-02 21:22:52 +020027 command! -nargs=* -bang Xprev <mods>cprev<bang> <args>
28 command! -nargs=* -bang Xfirst <mods>cfirst<bang> <args>
29 command! -nargs=* -bang Xlast <mods>clast<bang> <args>
30 command! -nargs=* -bang Xnfile <mods>cnfile<bang> <args>
31 command! -nargs=* -bang Xpfile <mods>cpfile<bang> <args>
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +020032 command! -nargs=* Xexpr <mods>cexpr <args>
33 command! -nargs=* Xvimgrep <mods>vimgrep <args>
Bram Moolenaar049cba92016-06-26 14:38:04 +020034 command! -nargs=* Xgrep <mods> grep <args>
35 command! -nargs=* Xgrepadd <mods> grepadd <args>
36 command! -nargs=* Xhelpgrep helpgrep <args>
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +020037 let g:Xgetlist = function('getqflist')
38 let g:Xsetlist = function('setqflist')
39 else
40 command! -nargs=* -bang Xlist <mods>llist<bang> <args>
41 command! -nargs=* Xgetexpr <mods>lgetexpr <args>
Bram Moolenaar361c8f02016-07-02 15:41:47 +020042 command! -nargs=* Xaddexpr <mods>laddexpr <args>
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +020043 command! -nargs=* Xolder <mods>lolder <args>
44 command! -nargs=* Xnewer <mods>lnewer <args>
45 command! -nargs=* Xopen <mods>lopen <args>
46 command! -nargs=* Xwindow <mods>lwindow <args>
47 command! -nargs=* Xclose <mods>lclose <args>
48 command! -nargs=* -bang Xfile <mods>lfile<bang> <args>
49 command! -nargs=* Xgetfile <mods>lgetfile <args>
50 command! -nargs=* Xaddfile <mods>laddfile <args>
51 command! -nargs=* -bang Xbuffer <mods>lbuffer<bang> <args>
52 command! -nargs=* Xgetbuffer <mods>lgetbuffer <args>
53 command! -nargs=* Xaddbuffer <mods>laddbuffer <args>
54 command! -nargs=* Xrewind <mods>lrewind <args>
55 command! -nargs=* -bang Xnext <mods>lnext<bang> <args>
Bram Moolenaar0fcc7c62016-07-02 21:22:52 +020056 command! -nargs=* -bang Xprev <mods>lprev<bang> <args>
57 command! -nargs=* -bang Xfirst <mods>lfirst<bang> <args>
58 command! -nargs=* -bang Xlast <mods>llast<bang> <args>
59 command! -nargs=* -bang Xnfile <mods>lnfile<bang> <args>
60 command! -nargs=* -bang Xpfile <mods>lpfile<bang> <args>
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +020061 command! -nargs=* Xexpr <mods>lexpr <args>
62 command! -nargs=* Xvimgrep <mods>lvimgrep <args>
Bram Moolenaar049cba92016-06-26 14:38:04 +020063 command! -nargs=* Xgrep <mods> lgrep <args>
64 command! -nargs=* Xgrepadd <mods> lgrepadd <args>
65 command! -nargs=* Xhelpgrep lhelpgrep <args>
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +020066 let g:Xgetlist = function('getloclist', [0])
67 let g:Xsetlist = function('setloclist', [0])
68 endif
69endfunction
70
Bram Moolenaarda59dd52016-01-05 21:59:58 +010071" Tests for the :clist and :llist commands
72function XlistTests(cchar)
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +020073 call s:setup_commands(a:cchar)
Bram Moolenaarda59dd52016-01-05 21:59:58 +010074
75 " With an empty list, command should return error
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +020076 Xgetexpr []
77 silent! Xlist
Bram Moolenaarda59dd52016-01-05 21:59:58 +010078 call assert_true(v:errmsg ==# 'E42: No Errors')
79
80 " Populate the list and then try
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +020081 Xgetexpr ['non-error 1', 'Xtestfile1:1:3:Line1',
Bram Moolenaarda59dd52016-01-05 21:59:58 +010082 \ 'non-error 2', 'Xtestfile2:2:2:Line2',
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +020083 \ 'non-error 3', 'Xtestfile3:3:1:Line3']
Bram Moolenaarda59dd52016-01-05 21:59:58 +010084
85 " List only valid entries
86 redir => result
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +020087 Xlist
Bram Moolenaarda59dd52016-01-05 21:59:58 +010088 redir END
89 let l = split(result, "\n")
90 call assert_equal([' 2 Xtestfile1:1 col 3: Line1',
91 \ ' 4 Xtestfile2:2 col 2: Line2',
92 \ ' 6 Xtestfile3:3 col 1: Line3'], l)
93
94 " List all the entries
95 redir => result
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +020096 Xlist!
Bram Moolenaarda59dd52016-01-05 21:59:58 +010097 redir END
98 let l = split(result, "\n")
99 call assert_equal([' 1: non-error 1', ' 2 Xtestfile1:1 col 3: Line1',
100 \ ' 3: non-error 2', ' 4 Xtestfile2:2 col 2: Line2',
101 \ ' 5: non-error 3', ' 6 Xtestfile3:3 col 1: Line3'], l)
102
103 " List a range of errors
104 redir => result
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +0200105 Xlist 3,6
Bram Moolenaarda59dd52016-01-05 21:59:58 +0100106 redir END
107 let l = split(result, "\n")
108 call assert_equal([' 4 Xtestfile2:2 col 2: Line2',
109 \ ' 6 Xtestfile3:3 col 1: Line3'], l)
110
111 redir => result
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +0200112 Xlist! 3,4
Bram Moolenaarda59dd52016-01-05 21:59:58 +0100113 redir END
114 let l = split(result, "\n")
115 call assert_equal([' 3: non-error 2', ' 4 Xtestfile2:2 col 2: Line2'], l)
116
117 redir => result
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +0200118 Xlist -6,-4
Bram Moolenaarda59dd52016-01-05 21:59:58 +0100119 redir END
120 let l = split(result, "\n")
121 call assert_equal([' 2 Xtestfile1:1 col 3: Line1'], l)
122
123 redir => result
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +0200124 Xlist! -5,-3
Bram Moolenaarda59dd52016-01-05 21:59:58 +0100125 redir END
126 let l = split(result, "\n")
127 call assert_equal([' 2 Xtestfile1:1 col 3: Line1',
128 \ ' 3: non-error 2', ' 4 Xtestfile2:2 col 2: Line2'], l)
129endfunction
130
131function Test_clist()
132 call XlistTests('c')
133 call XlistTests('l')
134endfunction
135
136" Tests for the :colder, :cnewer, :lolder and :lnewer commands
137" Note that this test assumes that a quickfix/location list is
Bram Moolenaarcfc0a352016-01-09 20:23:00 +0100138" already set by the caller.
Bram Moolenaarda59dd52016-01-05 21:59:58 +0100139function XageTests(cchar)
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +0200140 call s:setup_commands(a:cchar)
Bram Moolenaarda59dd52016-01-05 21:59:58 +0100141
142 " Jumping to a non existent list should return error
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +0200143 silent! Xolder 99
Bram Moolenaarda59dd52016-01-05 21:59:58 +0100144 call assert_true(v:errmsg ==# 'E380: At bottom of quickfix stack')
145
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +0200146 silent! Xnewer 99
Bram Moolenaarda59dd52016-01-05 21:59:58 +0100147 call assert_true(v:errmsg ==# 'E381: At top of quickfix stack')
148
149 " Add three quickfix/location lists
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +0200150 Xgetexpr ['Xtestfile1:1:3:Line1']
151 Xgetexpr ['Xtestfile2:2:2:Line2']
152 Xgetexpr ['Xtestfile3:3:1:Line3']
Bram Moolenaarda59dd52016-01-05 21:59:58 +0100153
154 " Go back two lists
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +0200155 Xolder
156 let l = g:Xgetlist()
Bram Moolenaarda59dd52016-01-05 21:59:58 +0100157 call assert_equal('Line2', l[0].text)
158
159 " Go forward two lists
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +0200160 Xnewer
161 let l = g:Xgetlist()
Bram Moolenaarda59dd52016-01-05 21:59:58 +0100162 call assert_equal('Line3', l[0].text)
163
164 " Test for the optional count argument
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +0200165 Xolder 2
166 let l = g:Xgetlist()
Bram Moolenaarda59dd52016-01-05 21:59:58 +0100167 call assert_equal('Line1', l[0].text)
168
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +0200169 Xnewer 2
170 let l = g:Xgetlist()
Bram Moolenaarda59dd52016-01-05 21:59:58 +0100171 call assert_equal('Line3', l[0].text)
172endfunction
173
174function Test_cage()
Bram Moolenaarcfc0a352016-01-09 20:23:00 +0100175 let list = [{'bufnr': 1, 'lnum': 1}]
176 call setqflist(list)
Bram Moolenaarda59dd52016-01-05 21:59:58 +0100177 call XageTests('c')
Bram Moolenaarcfc0a352016-01-09 20:23:00 +0100178
179 call setloclist(0, list)
Bram Moolenaarda59dd52016-01-05 21:59:58 +0100180 call XageTests('l')
181endfunction
182
183" Tests for the :cwindow, :lwindow :cclose, :lclose, :copen and :lopen
184" commands
185function XwindowTests(cchar)
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +0200186 call s:setup_commands(a:cchar)
Bram Moolenaarda59dd52016-01-05 21:59:58 +0100187
188 " Create a list with no valid entries
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +0200189 Xgetexpr ['non-error 1', 'non-error 2', 'non-error 3']
Bram Moolenaarda59dd52016-01-05 21:59:58 +0100190
191 " Quickfix/Location window should not open with no valid errors
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +0200192 Xwindow
Bram Moolenaarda59dd52016-01-05 21:59:58 +0100193 call assert_true(winnr('$') == 1)
194
195 " Create a list with valid entries
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +0200196 Xgetexpr ['Xtestfile1:1:3:Line1', 'Xtestfile2:2:2:Line2',
197 \ 'Xtestfile3:3:1:Line3']
Bram Moolenaarda59dd52016-01-05 21:59:58 +0100198
199 " Open the window
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +0200200 Xwindow
Bram Moolenaarda59dd52016-01-05 21:59:58 +0100201 call assert_true(winnr('$') == 2 && winnr() == 2 &&
202 \ getline('.') ==# 'Xtestfile1|1 col 3| Line1')
203
204 " Close the window
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +0200205 Xclose
Bram Moolenaarda59dd52016-01-05 21:59:58 +0100206 call assert_true(winnr('$') == 1)
207
208 " Create a list with no valid entries
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +0200209 Xgetexpr ['non-error 1', 'non-error 2', 'non-error 3']
Bram Moolenaarda59dd52016-01-05 21:59:58 +0100210
211 " Open the window
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +0200212 Xopen 5
Bram Moolenaarda59dd52016-01-05 21:59:58 +0100213 call assert_true(winnr('$') == 2 && getline('.') ==# '|| non-error 1'
214 \ && winheight('.') == 5)
215
216 " Opening the window again, should move the cursor to that window
217 wincmd t
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +0200218 Xopen 7
Bram Moolenaarda59dd52016-01-05 21:59:58 +0100219 call assert_true(winnr('$') == 2 && winnr() == 2 &&
220 \ winheight('.') == 7 &&
221 \ getline('.') ==# '|| non-error 1')
222
223
224 " Calling cwindow should close the quickfix window with no valid errors
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +0200225 Xwindow
Bram Moolenaarda59dd52016-01-05 21:59:58 +0100226 call assert_true(winnr('$') == 1)
227endfunction
228
229function Test_cwindow()
230 call XwindowTests('c')
231 call XwindowTests('l')
232endfunction
233
234" Tests for the :cfile, :lfile, :caddfile, :laddfile, :cgetfile and :lgetfile
235" commands.
236function XfileTests(cchar)
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +0200237 call s:setup_commands(a:cchar)
Bram Moolenaarda59dd52016-01-05 21:59:58 +0100238
239 call writefile(['Xtestfile1:700:10:Line 700',
240 \ 'Xtestfile2:800:15:Line 800'], 'Xqftestfile1')
241
242 enew!
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +0200243 Xfile Xqftestfile1
244 let l = g:Xgetlist()
Bram Moolenaarda59dd52016-01-05 21:59:58 +0100245 call assert_true(len(l) == 2 &&
246 \ l[0].lnum == 700 && l[0].col == 10 && l[0].text ==# 'Line 700' &&
247 \ l[1].lnum == 800 && l[1].col == 15 && l[1].text ==# 'Line 800')
248
Bram Moolenaar049cba92016-06-26 14:38:04 +0200249 " Test with a non existent file
250 call assert_fails('Xfile non_existent_file', 'E40')
251
Bram Moolenaarda59dd52016-01-05 21:59:58 +0100252 " Run cfile/lfile from a modified buffer
253 enew!
254 silent! put ='Quickfix'
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +0200255 silent! Xfile Xqftestfile1
Bram Moolenaarda59dd52016-01-05 21:59:58 +0100256 call assert_true(v:errmsg ==# 'E37: No write since last change (add ! to override)')
257
258 call writefile(['Xtestfile3:900:30:Line 900'], 'Xqftestfile1')
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +0200259 Xaddfile Xqftestfile1
260 let l = g:Xgetlist()
Bram Moolenaarda59dd52016-01-05 21:59:58 +0100261 call assert_true(len(l) == 3 &&
262 \ l[2].lnum == 900 && l[2].col == 30 && l[2].text ==# 'Line 900')
263
264 call writefile(['Xtestfile1:222:77:Line 222',
265 \ 'Xtestfile2:333:88:Line 333'], 'Xqftestfile1')
266
267 enew!
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +0200268 Xgetfile Xqftestfile1
269 let l = g:Xgetlist()
Bram Moolenaarda59dd52016-01-05 21:59:58 +0100270 call assert_true(len(l) == 2 &&
271 \ l[0].lnum == 222 && l[0].col == 77 && l[0].text ==# 'Line 222' &&
272 \ l[1].lnum == 333 && l[1].col == 88 && l[1].text ==# 'Line 333')
273
274 call delete('Xqftestfile1')
275endfunction
276
277function Test_cfile()
278 call XfileTests('c')
279 call XfileTests('l')
280endfunction
281
282" Tests for the :cbuffer, :lbuffer, :caddbuffer, :laddbuffer, :cgetbuffer and
283" :lgetbuffer commands.
284function XbufferTests(cchar)
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +0200285 call s:setup_commands(a:cchar)
Bram Moolenaarda59dd52016-01-05 21:59:58 +0100286
287 enew!
288 silent! call setline(1, ['Xtestfile7:700:10:Line 700',
289 \ 'Xtestfile8:800:15:Line 800'])
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +0200290 Xbuffer!
291 let l = g:Xgetlist()
Bram Moolenaarda59dd52016-01-05 21:59:58 +0100292 call assert_true(len(l) == 2 &&
293 \ l[0].lnum == 700 && l[0].col == 10 && l[0].text ==# 'Line 700' &&
294 \ l[1].lnum == 800 && l[1].col == 15 && l[1].text ==# 'Line 800')
295
296 enew!
297 silent! call setline(1, ['Xtestfile9:900:55:Line 900',
298 \ 'Xtestfile10:950:66:Line 950'])
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +0200299 Xgetbuffer
300 let l = g:Xgetlist()
Bram Moolenaarda59dd52016-01-05 21:59:58 +0100301 call assert_true(len(l) == 2 &&
302 \ l[0].lnum == 900 && l[0].col == 55 && l[0].text ==# 'Line 900' &&
303 \ l[1].lnum == 950 && l[1].col == 66 && l[1].text ==# 'Line 950')
304
305 enew!
306 silent! call setline(1, ['Xtestfile11:700:20:Line 700',
307 \ 'Xtestfile12:750:25:Line 750'])
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +0200308 Xaddbuffer
309 let l = g:Xgetlist()
Bram Moolenaarda59dd52016-01-05 21:59:58 +0100310 call assert_true(len(l) == 4 &&
311 \ l[1].lnum == 950 && l[1].col == 66 && l[1].text ==# 'Line 950' &&
312 \ l[2].lnum == 700 && l[2].col == 20 && l[2].text ==# 'Line 700' &&
313 \ l[3].lnum == 750 && l[3].col == 25 && l[3].text ==# 'Line 750')
Bram Moolenaarab47c612016-06-14 22:02:26 +0200314 enew!
Bram Moolenaarda59dd52016-01-05 21:59:58 +0100315
316endfunction
317
318function Test_cbuffer()
319 call XbufferTests('c')
320 call XbufferTests('l')
321endfunction
322
Bram Moolenaar0fcc7c62016-07-02 21:22:52 +0200323function XexprTests(cchar)
324 call s:setup_commands(a:cchar)
325
326 call assert_fails('Xexpr 10', 'E777:')
327endfunction
328
329function Test_cexpr()
330 call XexprTests('c')
331 call XexprTests('l')
332endfunction
333
334" Tests for :cnext, :cprev, :cfirst, :clast commands
335function Xtest_browse(cchar)
336 call s:setup_commands(a:cchar)
337
338 call s:create_test_file('Xqftestfile1')
339 call s:create_test_file('Xqftestfile2')
340
341 Xgetexpr ['Xqftestfile1:5:Line5',
342 \ 'Xqftestfile1:6:Line6',
343 \ 'Xqftestfile2:10:Line10',
344 \ 'Xqftestfile2:11:Line11']
345
346 Xfirst
347 call assert_fails('Xprev', 'E553')
348 call assert_fails('Xpfile', 'E553')
349 Xnfile
350 call assert_equal('Xqftestfile2', bufname('%'))
351 call assert_equal(10, line('.'))
352 Xpfile
353 call assert_equal('Xqftestfile1', bufname('%'))
354 call assert_equal(6, line('.'))
355 Xlast
356 call assert_equal('Xqftestfile2', bufname('%'))
357 call assert_equal(11, line('.'))
358 call assert_fails('Xnext', 'E553')
359 call assert_fails('Xnfile', 'E553')
360 Xrewind
361 call assert_equal('Xqftestfile1', bufname('%'))
362 call assert_equal(5, line('.'))
363
364 call delete('Xqftestfile1')
365 call delete('Xqftestfile2')
366endfunction
367
368function Test_browse()
369 call Xtest_browse('c')
370 call Xtest_browse('l')
371endfunction
372
Bram Moolenaar75bdf6a2016-01-07 21:25:08 +0100373function Test_nomem()
Bram Moolenaar8e8df252016-05-25 21:23:21 +0200374 call test_alloc_fail(GetAllocId('qf_dirname_start'), 0, 0)
Bram Moolenaara260b872016-01-15 20:48:22 +0100375 call assert_fails('vimgrep vim runtest.vim', 'E342:')
Bram Moolenaar75bdf6a2016-01-07 21:25:08 +0100376
Bram Moolenaar8e8df252016-05-25 21:23:21 +0200377 call test_alloc_fail(GetAllocId('qf_dirname_now'), 0, 0)
Bram Moolenaara260b872016-01-15 20:48:22 +0100378 call assert_fails('vimgrep vim runtest.vim', 'E342:')
Bram Moolenaar75bdf6a2016-01-07 21:25:08 +0100379
Bram Moolenaar8e8df252016-05-25 21:23:21 +0200380 call test_alloc_fail(GetAllocId('qf_namebuf'), 0, 0)
Bram Moolenaara260b872016-01-15 20:48:22 +0100381 call assert_fails('cfile runtest.vim', 'E342:')
Bram Moolenaar75bdf6a2016-01-07 21:25:08 +0100382
Bram Moolenaar8e8df252016-05-25 21:23:21 +0200383 call test_alloc_fail(GetAllocId('qf_errmsg'), 0, 0)
Bram Moolenaara260b872016-01-15 20:48:22 +0100384 call assert_fails('cfile runtest.vim', 'E342:')
Bram Moolenaar75bdf6a2016-01-07 21:25:08 +0100385
Bram Moolenaar8e8df252016-05-25 21:23:21 +0200386 call test_alloc_fail(GetAllocId('qf_pattern'), 0, 0)
Bram Moolenaara260b872016-01-15 20:48:22 +0100387 call assert_fails('cfile runtest.vim', 'E342:')
Bram Moolenaar75bdf6a2016-01-07 21:25:08 +0100388
389endfunc
390
Bram Moolenaar049cba92016-06-26 14:38:04 +0200391function! s:test_xhelpgrep(cchar)
392 call s:setup_commands(a:cchar)
393 Xhelpgrep quickfix
394 Xopen
395 if a:cchar == 'c'
396 let title_text = ':helpgrep quickfix'
397 else
398 let title_text = ':lhelpgrep quickfix'
399 endif
400 call assert_true(w:quickfix_title =~ title_text, w:quickfix_title)
Bram Moolenaar62ef7972016-01-19 14:51:54 +0100401 " This wipes out the buffer, make sure that doesn't cause trouble.
Bram Moolenaar049cba92016-06-26 14:38:04 +0200402 Xclose
403endfunction
404
405function Test_helpgrep()
406 call s:test_xhelpgrep('c')
407 call s:test_xhelpgrep('l')
Bram Moolenaar62ef7972016-01-19 14:51:54 +0100408endfunc
Bram Moolenaar75bdf6a2016-01-07 21:25:08 +0100409
Bram Moolenaar6920c722016-01-22 22:44:10 +0100410func Test_errortitle()
411 augroup QfBufWinEnter
412 au!
413 au BufWinEnter * :let g:a=get(w:, 'quickfix_title', 'NONE')
414 augroup END
415 copen
416 let 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'')'}]
417 call setqflist(a)
418 call assert_equal(':setqflist()', g:a)
419 augroup QfBufWinEnter
420 au!
421 augroup END
422 augroup! QfBufWinEnter
423endfunc
Bram Moolenaare27dba42016-03-15 14:11:10 +0100424
Bram Moolenaar5584df62016-03-18 21:00:51 +0100425func Test_vimgreptitle()
426 augroup QfBufWinEnter
427 au!
428 au BufWinEnter * :let g:a=get(w:, 'quickfix_title', 'NONE')
429 augroup END
430 try
431 vimgrep /pattern/j file
432 catch /E480/
433 endtry
434 copen
435 call assert_equal(': vimgrep /pattern/j file', g:a)
436 augroup QfBufWinEnter
437 au!
438 augroup END
439 augroup! QfBufWinEnter
440endfunc
441
Bram Moolenaare27dba42016-03-15 14:11:10 +0100442function XqfTitleTests(cchar)
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +0200443 call s:setup_commands(a:cchar)
Bram Moolenaare27dba42016-03-15 14:11:10 +0100444
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +0200445 Xgetexpr ['file:1:1:message']
446 let l = g:Xgetlist()
Bram Moolenaare27dba42016-03-15 14:11:10 +0100447 if a:cchar == 'c'
448 call setqflist(l, 'r')
449 else
450 call setloclist(0, l, 'r')
451 endif
452
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +0200453 Xopen
Bram Moolenaare27dba42016-03-15 14:11:10 +0100454 if a:cchar == 'c'
455 let title = ':setqflist()'
456 else
457 let title = ':setloclist()'
458 endif
459 call assert_equal(title, w:quickfix_title)
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +0200460 Xclose
Bram Moolenaare27dba42016-03-15 14:11:10 +0100461endfunction
462
463" Tests for quickfix window's title
464function Test_qf_title()
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +0200465 call XqfTitleTests('c')
466 call XqfTitleTests('l')
Bram Moolenaare27dba42016-03-15 14:11:10 +0100467endfunction
468
469" Tests for 'errorformat'
470function Test_efm()
471 let save_efm = &efm
472 set efm=%EEEE%m,%WWWW%m,%+CCCC%.%#,%-GGGG%.%#
473 cgetexpr ['WWWW', 'EEEE', 'CCCC']
474 let l = strtrans(string(map(getqflist(), '[v:val.text, v:val.valid]')))
475 call assert_equal("[['W', 1], ['E^@CCCC', 1]]", l)
476 cgetexpr ['WWWW', 'GGGG', 'EEEE', 'CCCC']
477 let l = strtrans(string(map(getqflist(), '[v:val.text, v:val.valid]')))
478 call assert_equal("[['W', 1], ['E^@CCCC', 1]]", l)
479 cgetexpr ['WWWW', 'GGGG', 'ZZZZ', 'EEEE', 'CCCC', 'YYYY']
480 let l = strtrans(string(map(getqflist(), '[v:val.text, v:val.valid]')))
481 call assert_equal("[['W', 1], ['ZZZZ', 0], ['E^@CCCC', 1], ['YYYY', 0]]", l)
482 let &efm = save_efm
483endfunction
Bram Moolenaar1ff2b642016-03-17 22:07:02 +0100484
485" This will test for problems in quickfix:
486" A. incorrectly copying location lists which caused the location list to show
487" a different name than the file that was actually being displayed.
488" B. not reusing the window for which the location list window is opened but
489" instead creating new windows.
490" C. make sure that the location list window is not reused instead of the
491" window it belongs to.
492"
493" Set up the test environment:
494function! ReadTestProtocol(name)
495 let base = substitute(a:name, '\v^test://(.*)%(\.[^.]+)?', '\1', '')
496 let word = substitute(base, '\v(.*)\..*', '\1', '')
497
498 setl modifiable
499 setl noreadonly
500 setl noswapfile
501 setl bufhidden=delete
502 %del _
503 " For problem 2:
504 " 'buftype' has to be set to reproduce the constant opening of new windows
505 setl buftype=nofile
506
507 call setline(1, word)
508
509 setl nomodified
510 setl nomodifiable
511 setl readonly
512 exe 'doautocmd BufRead ' . substitute(a:name, '\v^test://(.*)', '\1', '')
513endfunction
514
515function Test_locationlist()
516 enew
517
518 augroup testgroup
519 au!
520 autocmd BufReadCmd test://* call ReadTestProtocol(expand("<amatch>"))
521 augroup END
522
523 let words = [ "foo", "bar", "baz", "quux", "shmoo", "spam", "eggs" ]
524
525 let qflist = []
526 for word in words
527 call add(qflist, {'filename': 'test://' . word . '.txt', 'text': 'file ' . word . '.txt', })
528 " NOTE: problem 1:
529 " intentionally not setting 'lnum' so that the quickfix entries are not
530 " valid
531 call setloclist(0, qflist, ' ')
532 endfor
533
534 " Test A
535 lrewind
536 enew
537 lopen
538 lnext
539 lnext
540 lnext
541 lnext
542 vert split
543 wincmd L
544 lopen
545 wincmd p
546 lnext
547 let fileName = expand("%")
548 wincmd p
549 let locationListFileName = substitute(getline(line('.')), '\([^|]*\)|.*', '\1', '')
550 let fileName = substitute(fileName, '\\', '/', 'g')
551 let locationListFileName = substitute(locationListFileName, '\\', '/', 'g')
552 call assert_equal("test://bar.txt", fileName)
553 call assert_equal("test://bar.txt", locationListFileName)
554
555 wincmd n | only
556
557 " Test B:
558 lrewind
559 lopen
560 2
561 exe "normal \<CR>"
562 wincmd p
563 3
564 exe "normal \<CR>"
565 wincmd p
566 4
567 exe "normal \<CR>"
568 call assert_equal(2, winnr('$'))
569 wincmd n | only
570
571 " Test C:
572 lrewind
573 lopen
574 " Let's move the location list window to the top to check whether it (the
575 " first window found) will be reused when we try to open new windows:
576 wincmd K
577 2
578 exe "normal \<CR>"
579 wincmd p
580 3
581 exe "normal \<CR>"
582 wincmd p
583 4
584 exe "normal \<CR>"
585 1wincmd w
586 call assert_equal('quickfix', &buftype)
587 2wincmd w
588 let bufferName = expand("%")
589 let bufferName = substitute(bufferName, '\\', '/', 'g')
590 call assert_equal('test://quux.txt', bufferName)
591
592 wincmd n | only
593
594 augroup! testgroup
595endfunction
Bram Moolenaar0899d692016-03-19 13:35:03 +0100596
597function Test_locationlist_curwin_was_closed()
598 augroup testgroup
599 au!
Bram Moolenaard106e5b2016-04-21 19:38:07 +0200600 autocmd BufReadCmd test_curwin.txt call R(expand("<amatch>"))
Bram Moolenaar0899d692016-03-19 13:35:03 +0100601 augroup END
602
Bram Moolenaarffec3c52016-03-23 20:55:42 +0100603 function! R(n)
Bram Moolenaar0899d692016-03-19 13:35:03 +0100604 quit
605 endfunc
606
607 new
608 let q = []
Bram Moolenaard106e5b2016-04-21 19:38:07 +0200609 call add(q, {'filename': 'test_curwin.txt' })
Bram Moolenaar0899d692016-03-19 13:35:03 +0100610 call setloclist(0, q)
611 call assert_fails('lrewind', 'E924:')
612
613 augroup! testgroup
614endfunction
Bram Moolenaar7eba3d22016-03-19 22:54:09 +0100615
616" More tests for 'errorformat'
617function! Test_efm1()
618 if !has('unix')
619 " The 'errorformat' setting is different on non-Unix systems.
620 " This test works only on Unix-like systems.
621 return
622 endif
623
624 let l = [
625 \ '"Xtestfile", line 4.12: 1506-045 (S) Undeclared identifier fd_set.',
626 \ '"Xtestfile", line 6 col 19; this is an error',
627 \ 'gcc -c -DHAVE_CONFIsing-prototypes -I/usr/X11R6/include version.c',
628 \ 'Xtestfile:9: parse error before `asd''',
629 \ 'make: *** [vim] Error 1',
630 \ 'in file "Xtestfile" linenr 10: there is an error',
631 \ '',
632 \ '2 returned',
633 \ '"Xtestfile", line 11 col 1; this is an error',
634 \ '"Xtestfile", line 12 col 2; this is another error',
635 \ '"Xtestfile", line 14:10; this is an error in column 10',
636 \ '=Xtestfile=, line 15:10; this is another error, but in vcol 10 this time',
637 \ '"Xtestfile", linenr 16: yet another problem',
638 \ 'Error in "Xtestfile" at line 17:',
639 \ 'x should be a dot',
640 \ ' xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 17',
641 \ ' ^',
642 \ 'Error in "Xtestfile" at line 18:',
643 \ 'x should be a dot',
644 \ ' xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 18',
645 \ '.............^',
646 \ 'Error in "Xtestfile" at line 19:',
647 \ 'x should be a dot',
648 \ ' xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 19',
649 \ '--------------^',
650 \ 'Error in "Xtestfile" at line 20:',
651 \ 'x should be a dot',
652 \ ' xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 20',
653 \ ' ^',
654 \ '',
655 \ 'Does anyone know what is the problem and how to correction it?',
656 \ '"Xtestfile", line 21 col 9: What is the title of the quickfix window?',
657 \ '"Xtestfile", line 22 col 9: What is the title of the quickfix window?'
658 \ ]
659
660 call writefile(l, 'Xerrorfile1')
661 call writefile(l[:-2], 'Xerrorfile2')
662
663 let m = [
664 \ ' xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 2',
665 \ ' xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 3',
666 \ ' xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 4',
667 \ ' xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 5',
668 \ ' xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 6',
669 \ ' xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 7',
670 \ ' xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 8',
671 \ ' xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 9',
672 \ ' xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 10',
673 \ ' xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 11',
674 \ ' xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 12',
675 \ ' xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 13',
676 \ ' xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 14',
677 \ ' xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 15',
678 \ ' xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 16',
679 \ ' xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 17',
680 \ ' xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 18',
681 \ ' xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 19',
682 \ ' xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 20',
683 \ ' xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 21',
684 \ ' xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 22'
685 \ ]
686 call writefile(m, 'Xtestfile')
687
688 let save_efm = &efm
689 set efm+==%f=\\,\ line\ %l%*\\D%v%*[^\ ]\ %m
690 set efm^=%AError\ in\ \"%f\"\ at\ line\ %l:,%Z%p^,%C%m
691
692 exe 'cf Xerrorfile2'
693 clast
694 copen
695 call assert_equal(':cf Xerrorfile2', w:quickfix_title)
696 wincmd p
697
698 exe 'cf Xerrorfile1'
699 call assert_equal([4, 12], [line('.'), col('.')])
700 cn
701 call assert_equal([6, 19], [line('.'), col('.')])
702 cn
703 call assert_equal([9, 2], [line('.'), col('.')])
704 cn
705 call assert_equal([10, 2], [line('.'), col('.')])
706 cn
707 call assert_equal([11, 1], [line('.'), col('.')])
708 cn
709 call assert_equal([12, 2], [line('.'), col('.')])
710 cn
711 call assert_equal([14, 10], [line('.'), col('.')])
712 cn
713 call assert_equal([15, 3, 10], [line('.'), col('.'), virtcol('.')])
714 cn
715 call assert_equal([16, 2], [line('.'), col('.')])
716 cn
717 call assert_equal([17, 6], [line('.'), col('.')])
718 cn
719 call assert_equal([18, 7], [line('.'), col('.')])
720 cn
721 call assert_equal([19, 8], [line('.'), col('.')])
722 cn
723 call assert_equal([20, 9], [line('.'), col('.')])
724 clast
725 cprev
726 cprev
727 wincmd w
728 call assert_equal(':cf Xerrorfile1', w:quickfix_title)
729 wincmd p
730
731 let &efm = save_efm
732 call delete('Xerrorfile1')
733 call delete('Xerrorfile2')
734 call delete('Xtestfile')
735endfunction
Bram Moolenaarffec3c52016-03-23 20:55:42 +0100736
Bram Moolenaarab47c612016-06-14 22:02:26 +0200737" Test for quickfix directory stack support
738function! s:dir_stack_tests(cchar)
Bram Moolenaar38df43b2016-06-20 21:41:12 +0200739 call s:setup_commands(a:cchar)
740
Bram Moolenaarab47c612016-06-14 22:02:26 +0200741 let save_efm=&efm
742 set efm=%DEntering\ dir\ '%f',%f:%l:%m,%XLeaving\ dir\ '%f'
743
Bram Moolenaar361c8f02016-07-02 15:41:47 +0200744 let lines = ["Entering dir 'dir1/a'",
745 \ 'habits2.txt:1:Nine Healthy Habits',
746 \ "Entering dir 'b'",
747 \ 'habits3.txt:2:0 Hours of television',
748 \ 'habits2.txt:7:5 Small meals',
749 \ "Entering dir 'dir1/c'",
750 \ 'habits4.txt:3:1 Hour of exercise',
751 \ "Leaving dir 'dir1/c'",
752 \ "Leaving dir 'dir1/a'",
753 \ 'habits1.txt:4:2 Liters of water',
754 \ "Entering dir 'dir2'",
755 \ 'habits5.txt:5:3 Cups of hot green tea',
756 \ "Leaving dir 'dir2'"
757 \]
Bram Moolenaarab47c612016-06-14 22:02:26 +0200758
Bram Moolenaar361c8f02016-07-02 15:41:47 +0200759 Xexpr ""
760 for l in lines
761 Xaddexpr l
762 endfor
Bram Moolenaarab47c612016-06-14 22:02:26 +0200763
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +0200764 let qf = g:Xgetlist()
Bram Moolenaarab47c612016-06-14 22:02:26 +0200765
766 call assert_equal('dir1/a/habits2.txt', bufname(qf[1].bufnr))
767 call assert_equal(1, qf[1].lnum)
768 call assert_equal('dir1/a/b/habits3.txt', bufname(qf[3].bufnr))
769 call assert_equal(2, qf[3].lnum)
770 call assert_equal('dir1/a/habits2.txt', bufname(qf[4].bufnr))
771 call assert_equal(7, qf[4].lnum)
772 call assert_equal('dir1/c/habits4.txt', bufname(qf[6].bufnr))
773 call assert_equal(3, qf[6].lnum)
774 call assert_equal('habits1.txt', bufname(qf[9].bufnr))
775 call assert_equal(4, qf[9].lnum)
776 call assert_equal('dir2/habits5.txt', bufname(qf[11].bufnr))
777 call assert_equal(5, qf[11].lnum)
778
779 let &efm=save_efm
780endfunction
781
782" Tests for %D and %X errorformat options
783function! Test_efm_dirstack()
784 " Create the directory stack and files
785 call mkdir('dir1')
786 call mkdir('dir1/a')
787 call mkdir('dir1/a/b')
788 call mkdir('dir1/c')
789 call mkdir('dir2')
790
791 let lines = ["Nine Healthy Habits",
792 \ "0 Hours of television",
793 \ "1 Hour of exercise",
794 \ "2 Liters of water",
795 \ "3 Cups of hot green tea",
796 \ "4 Short mental breaks",
797 \ "5 Small meals",
798 \ "6 AM wake up time",
799 \ "7 Minutes of laughter",
800 \ "8 Hours of sleep (at least)",
801 \ "9 PM end of the day and off to bed"
802 \ ]
803 call writefile(lines, 'habits1.txt')
804 call writefile(lines, 'dir1/a/habits2.txt')
805 call writefile(lines, 'dir1/a/b/habits3.txt')
806 call writefile(lines, 'dir1/c/habits4.txt')
807 call writefile(lines, 'dir2/habits5.txt')
808
809 call s:dir_stack_tests('c')
810 call s:dir_stack_tests('l')
811
812 call delete('dir1', 'rf')
813 call delete('dir2', 'rf')
814 call delete('habits1.txt')
815endfunction
816
Bram Moolenaar0fcc7c62016-07-02 21:22:52 +0200817" Tests for invalid error format specifies
818function Xinvalid_efm_Tests(cchar)
819 call s:setup_commands(a:cchar)
820
Bram Moolenaar049cba92016-06-26 14:38:04 +0200821 let save_efm = &efm
822
Bram Moolenaar0fcc7c62016-07-02 21:22:52 +0200823 set efm=%f:%l:%m,%f:%f:%l:%m
824 call assert_fails('Xexpr "abc.txt:1:Hello world"', 'E372:')
825
826 set efm=%f:%l:%m,%f:%l:%r:%m
827 call assert_fails('Xexpr "abc.txt:1:Hello world"', 'E373:')
828
829 set efm=%f:%l:%m,%O:%f:%l:%m
830 call assert_fails('Xexpr "abc.txt:1:Hello world"', 'E373:')
831
832 set efm=%f:%l:%m,%f:%l:%*[^a-z
833 call assert_fails('Xexpr "abc.txt:1:Hello world"', 'E374:')
834
835 set efm=%f:%l:%m,%f:%l:%*c
836 call assert_fails('Xexpr "abc.txt:1:Hello world"', 'E375:')
837
838 set efm=%f:%l:%m,%L%M%N
839 call assert_fails('Xexpr "abc.txt:1:Hello world"', 'E376:')
840
841 set efm=%f:%l:%m,%f:%l:%m:%R
842 call assert_fails('Xexpr "abc.txt:1:Hello world"', 'E377:')
843
844 set efm=
845 call assert_fails('Xexpr "abc.txt:1:Hello world"', 'E378:')
846
847 set efm=%DEntering\ dir\ abc,%f:%l:%m
848 call assert_fails('Xexpr ["Entering dir abc", "abc.txt:1:Hello world"]', 'E379:')
849
850 let &efm = save_efm
851endfunction
852
853function Test_invalid_efm()
854 call Xinvalid_efm_Tests('c')
855 call Xinvalid_efm_Tests('l')
856endfunction
857
858" TODO:
859" Add tests for the following formats in 'errorformat'
860" %r %O
861function! Test_efm2()
862 let save_efm = &efm
Bram Moolenaar049cba92016-06-26 14:38:04 +0200863
864 " Test for %s format in efm
865 set efm=%f:%s
866 cexpr 'Xtestfile:Line search text'
Bram Moolenaar049cba92016-06-26 14:38:04 +0200867 let l = getqflist()
868 call assert_equal(l[0].pattern, '^\VLine search text\$')
869 call assert_equal(l[0].lnum, 0)
870
Bram Moolenaar0fcc7c62016-07-02 21:22:52 +0200871 " Test for %P, %Q and %t format specifiers
Bram Moolenaar049cba92016-06-26 14:38:04 +0200872 let lines=["[Xtestfile1]",
873 \ "(1,17) error: ';' missing",
874 \ "(21,2) warning: variable 'z' not defined",
875 \ "(67,3) error: end of file found before string ended",
876 \ "",
877 \ "[Xtestfile2]",
878 \ "",
879 \ "[Xtestfile3]",
880 \ "NEW compiler v1.1",
881 \ "(2,2) warning: variable 'x' not defined",
882 \ "(67,3) warning: 's' already defined"
883 \]
884 set efm=%+P[%f],(%l\\,%c)%*[\ ]%t%*[^:]:\ %m,%-Q
Bram Moolenaar361c8f02016-07-02 15:41:47 +0200885 cexpr ""
886 for l in lines
887 caddexpr l
888 endfor
Bram Moolenaar049cba92016-06-26 14:38:04 +0200889 let l = getqflist()
890 call assert_equal(9, len(l))
891 call assert_equal(21, l[2].lnum)
892 call assert_equal(2, l[2].col)
Bram Moolenaar0fcc7c62016-07-02 21:22:52 +0200893 call assert_equal('w', l[2].type)
894 call assert_equal('e', l[3].type)
895
896 " Tests for %E, %C and %Z format specifiers
897 let lines = ["Error 275",
898 \ "line 42",
899 \ "column 3",
900 \ "' ' expected after '--'"
901 \]
902 set efm=%EError\ %n,%Cline\ %l,%Ccolumn\ %c,%Z%m
903 cgetexpr lines
904 let l = getqflist()
905 call assert_equal(275, l[0].nr)
906 call assert_equal(42, l[0].lnum)
907 call assert_equal(3, l[0].col)
908 call assert_equal('E', l[0].type)
909 call assert_equal("\n' ' expected after '--'", l[0].text)
910
911 " Test for %>
912 let lines = ["Error in line 147 of foo.c:",
913 \"unknown variable 'i'"
914 \]
915 set efm=unknown\ variable\ %m,%E%>Error\ in\ line\ %l\ of\ %f:,%Z%m
916 cgetexpr lines
917 let l = getqflist()
918 call assert_equal(147, l[0].lnum)
919 call assert_equal('E', l[0].type)
920 call assert_equal("\nunknown variable 'i'", l[0].text)
Bram Moolenaar049cba92016-06-26 14:38:04 +0200921
922 let &efm = save_efm
923endfunction
924
Bram Moolenaarffec3c52016-03-23 20:55:42 +0100925function XquickfixChangedByAutocmd(cchar)
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +0200926 call s:setup_commands(a:cchar)
Bram Moolenaarffec3c52016-03-23 20:55:42 +0100927 if a:cchar == 'c'
Bram Moolenaarffec3c52016-03-23 20:55:42 +0100928 let ErrorNr = 'E925'
929 function! ReadFunc()
930 colder
931 cgetexpr []
932 endfunc
933 else
Bram Moolenaarffec3c52016-03-23 20:55:42 +0100934 let ErrorNr = 'E926'
935 function! ReadFunc()
936 lolder
937 lgetexpr []
938 endfunc
939 endif
940
941 augroup testgroup
942 au!
Bram Moolenaard106e5b2016-04-21 19:38:07 +0200943 autocmd BufReadCmd test_changed.txt call ReadFunc()
Bram Moolenaarffec3c52016-03-23 20:55:42 +0100944 augroup END
945
Bram Moolenaard106e5b2016-04-21 19:38:07 +0200946 new | only
Bram Moolenaarffec3c52016-03-23 20:55:42 +0100947 let words = [ "a", "b" ]
948 let qflist = []
949 for word in words
Bram Moolenaard106e5b2016-04-21 19:38:07 +0200950 call add(qflist, {'filename': 'test_changed.txt'})
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +0200951 call g:Xsetlist(qflist, ' ')
Bram Moolenaarffec3c52016-03-23 20:55:42 +0100952 endfor
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +0200953 call assert_fails('Xrewind', ErrorNr . ':')
Bram Moolenaarffec3c52016-03-23 20:55:42 +0100954
955 augroup! testgroup
956endfunc
957
958function Test_quickfix_was_changed_by_autocmd()
959 call XquickfixChangedByAutocmd('c')
960 call XquickfixChangedByAutocmd('l')
961endfunction
Bram Moolenaar8b201792016-03-25 15:01:10 +0100962
963func Test_caddbuffer_to_empty()
964 helpgr quickfix
965 call setqflist([], 'r')
966 cad
Bram Moolenaarf68f1d72016-03-25 17:14:06 +0100967 try
968 cn
969 catch
970 " number of matches is unknown
971 call assert_true(v:exception =~ 'E553:')
972 endtry
Bram Moolenaar8b201792016-03-25 15:01:10 +0100973 quit!
974endfunc
Bram Moolenaar89c64d52016-03-27 18:44:40 +0200975
976func Test_cgetexpr_works()
977 " this must not crash Vim
978 cgetexpr [$x]
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +0200979 lgetexpr [$x]
Bram Moolenaar89c64d52016-03-27 18:44:40 +0200980endfunc
Bram Moolenaarc1808d52016-04-18 20:04:00 +0200981
982" Tests for the setqflist() and setloclist() functions
983function SetXlistTests(cchar, bnum)
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +0200984 call s:setup_commands(a:cchar)
Bram Moolenaarc1808d52016-04-18 20:04:00 +0200985
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +0200986 call g:Xsetlist([{'bufnr': a:bnum, 'lnum': 1},
Bram Moolenaarc1808d52016-04-18 20:04:00 +0200987 \ {'bufnr': a:bnum, 'lnum': 2}])
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +0200988 let l = g:Xgetlist()
Bram Moolenaarc1808d52016-04-18 20:04:00 +0200989 call assert_equal(2, len(l))
990 call assert_equal(2, l[1].lnum)
991
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +0200992 Xnext
993 call g:Xsetlist([{'bufnr': a:bnum, 'lnum': 3}], 'a')
994 let l = g:Xgetlist()
Bram Moolenaarc1808d52016-04-18 20:04:00 +0200995 call assert_equal(3, len(l))
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +0200996 Xnext
Bram Moolenaarc1808d52016-04-18 20:04:00 +0200997 call assert_equal(3, line('.'))
998
Bram Moolenaar2b2b8ae2016-05-24 19:59:51 +0200999 " Appending entries to the list should not change the cursor position
1000 " in the quickfix window
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001001 Xwindow
Bram Moolenaar2b2b8ae2016-05-24 19:59:51 +02001002 1
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001003 call g:Xsetlist([{'bufnr': a:bnum, 'lnum': 4},
Bram Moolenaar2b2b8ae2016-05-24 19:59:51 +02001004 \ {'bufnr': a:bnum, 'lnum': 5}], 'a')
1005 call assert_equal(1, line('.'))
1006 close
1007
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001008 call g:Xsetlist([{'bufnr': a:bnum, 'lnum': 3},
Bram Moolenaarc1808d52016-04-18 20:04:00 +02001009 \ {'bufnr': a:bnum, 'lnum': 4},
1010 \ {'bufnr': a:bnum, 'lnum': 5}], 'r')
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001011 let l = g:Xgetlist()
Bram Moolenaarc1808d52016-04-18 20:04:00 +02001012 call assert_equal(3, len(l))
1013 call assert_equal(5, l[2].lnum)
1014
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001015 call g:Xsetlist([])
1016 let l = g:Xgetlist()
Bram Moolenaarc1808d52016-04-18 20:04:00 +02001017 call assert_equal(0, len(l))
1018endfunction
1019
1020function Test_setqflist()
1021 new Xtestfile | only
1022 let bnum = bufnr('%')
1023 call setline(1, range(1,5))
1024
1025 call SetXlistTests('c', bnum)
1026 call SetXlistTests('l', bnum)
1027
Bram Moolenaar1cee6932016-06-09 22:17:22 +02001028 enew!
Bram Moolenaarc1808d52016-04-18 20:04:00 +02001029 call delete('Xtestfile')
1030endfunction
Bram Moolenaard106e5b2016-04-21 19:38:07 +02001031
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001032function Xlist_empty_middle(cchar)
1033 call s:setup_commands(a:cchar)
1034
Bram Moolenaar1cee6932016-06-09 22:17:22 +02001035 " create three quickfix lists
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001036 Xvimgrep Test_ test_quickfix.vim
1037 let testlen = len(g:Xgetlist())
Bram Moolenaar1cee6932016-06-09 22:17:22 +02001038 call assert_true(testlen > 0)
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001039 Xvimgrep empty test_quickfix.vim
1040 call assert_true(len(g:Xgetlist()) > 0)
1041 Xvimgrep matches test_quickfix.vim
1042 let matchlen = len(g:Xgetlist())
Bram Moolenaar1cee6932016-06-09 22:17:22 +02001043 call assert_true(matchlen > 0)
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001044 Xolder
Bram Moolenaar1cee6932016-06-09 22:17:22 +02001045 " make the middle list empty
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001046 call g:Xsetlist([], 'r')
1047 call assert_true(len(g:Xgetlist()) == 0)
1048 Xolder
1049 call assert_equal(testlen, len(g:Xgetlist()))
1050 Xnewer
1051 Xnewer
1052 call assert_equal(matchlen, len(g:Xgetlist()))
Bram Moolenaar1cee6932016-06-09 22:17:22 +02001053endfunc
1054
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001055function Test_setqflist_empty_middle()
1056 call Xlist_empty_middle('c')
1057 call Xlist_empty_middle('l')
1058endfunction
1059
1060function Xlist_empty_older(cchar)
1061 call s:setup_commands(a:cchar)
1062
Bram Moolenaar1cee6932016-06-09 22:17:22 +02001063 " create three quickfix lists
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001064 Xvimgrep one test_quickfix.vim
1065 let onelen = len(g:Xgetlist())
Bram Moolenaar1cee6932016-06-09 22:17:22 +02001066 call assert_true(onelen > 0)
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001067 Xvimgrep two test_quickfix.vim
1068 let twolen = len(g:Xgetlist())
Bram Moolenaar1cee6932016-06-09 22:17:22 +02001069 call assert_true(twolen > 0)
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001070 Xvimgrep three test_quickfix.vim
1071 let threelen = len(g:Xgetlist())
Bram Moolenaar1cee6932016-06-09 22:17:22 +02001072 call assert_true(threelen > 0)
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001073 Xolder 2
Bram Moolenaar1cee6932016-06-09 22:17:22 +02001074 " make the first list empty, check the others didn't change
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001075 call g:Xsetlist([], 'r')
1076 call assert_true(len(g:Xgetlist()) == 0)
1077 Xnewer
1078 call assert_equal(twolen, len(g:Xgetlist()))
1079 Xnewer
1080 call assert_equal(threelen, len(g:Xgetlist()))
1081endfunction
1082
1083function Test_setqflist_empty_older()
1084 call Xlist_empty_older('c')
1085 call Xlist_empty_older('l')
1086endfunction
Bram Moolenaar1cee6932016-06-09 22:17:22 +02001087
Bram Moolenaard106e5b2016-04-21 19:38:07 +02001088function! XquickfixSetListWithAct(cchar)
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001089 call s:setup_commands(a:cchar)
1090
Bram Moolenaard106e5b2016-04-21 19:38:07 +02001091 let list1 = [{'filename': 'fnameA', 'text': 'A'},
1092 \ {'filename': 'fnameB', 'text': 'B'}]
1093 let list2 = [{'filename': 'fnameC', 'text': 'C'},
1094 \ {'filename': 'fnameD', 'text': 'D'},
1095 \ {'filename': 'fnameE', 'text': 'E'}]
1096
1097 " {action} is unspecified. Same as specifing ' '.
1098 new | only
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001099 silent! Xnewer 99
1100 call g:Xsetlist(list1)
1101 call g:Xsetlist(list2)
1102 let li = g:Xgetlist()
Bram Moolenaard106e5b2016-04-21 19:38:07 +02001103 call assert_equal(3, len(li))
1104 call assert_equal('C', li[0]['text'])
1105 call assert_equal('D', li[1]['text'])
1106 call assert_equal('E', li[2]['text'])
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001107 silent! Xolder
1108 let li = g:Xgetlist()
Bram Moolenaard106e5b2016-04-21 19:38:07 +02001109 call assert_equal(2, len(li))
1110 call assert_equal('A', li[0]['text'])
1111 call assert_equal('B', li[1]['text'])
1112
1113 " {action} is specified ' '.
1114 new | only
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001115 silent! Xnewer 99
1116 call g:Xsetlist(list1)
1117 call g:Xsetlist(list2, ' ')
1118 let li = g:Xgetlist()
Bram Moolenaard106e5b2016-04-21 19:38:07 +02001119 call assert_equal(3, len(li))
1120 call assert_equal('C', li[0]['text'])
1121 call assert_equal('D', li[1]['text'])
1122 call assert_equal('E', li[2]['text'])
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001123 silent! Xolder
1124 let li = g:Xgetlist()
Bram Moolenaard106e5b2016-04-21 19:38:07 +02001125 call assert_equal(2, len(li))
1126 call assert_equal('A', li[0]['text'])
1127 call assert_equal('B', li[1]['text'])
1128
1129 " {action} is specified 'a'.
1130 new | only
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001131 silent! Xnewer 99
1132 call g:Xsetlist(list1)
1133 call g:Xsetlist(list2, 'a')
1134 let li = g:Xgetlist()
Bram Moolenaard106e5b2016-04-21 19:38:07 +02001135 call assert_equal(5, len(li))
1136 call assert_equal('A', li[0]['text'])
1137 call assert_equal('B', li[1]['text'])
1138 call assert_equal('C', li[2]['text'])
1139 call assert_equal('D', li[3]['text'])
1140 call assert_equal('E', li[4]['text'])
1141
1142 " {action} is specified 'r'.
1143 new | only
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001144 silent! Xnewer 99
1145 call g:Xsetlist(list1)
1146 call g:Xsetlist(list2, 'r')
1147 let li = g:Xgetlist()
Bram Moolenaard106e5b2016-04-21 19:38:07 +02001148 call assert_equal(3, len(li))
1149 call assert_equal('C', li[0]['text'])
1150 call assert_equal('D', li[1]['text'])
1151 call assert_equal('E', li[2]['text'])
1152
1153 " Test for wrong value.
1154 new | only
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001155 call assert_fails("call g:Xsetlist(0)", 'E714:')
1156 call assert_fails("call g:Xsetlist(list1, '')", 'E927:')
1157 call assert_fails("call g:Xsetlist(list1, 'aa')", 'E927:')
1158 call assert_fails("call g:Xsetlist(list1, ' a')", 'E927:')
1159 call assert_fails("call g:Xsetlist(list1, 0)", 'E928:')
Bram Moolenaard106e5b2016-04-21 19:38:07 +02001160endfunc
1161
1162function Test_quickfix_set_list_with_act()
1163 call XquickfixSetListWithAct('c')
1164 call XquickfixSetListWithAct('l')
1165endfunction
Bram Moolenaar6be8c8e2016-04-30 13:17:09 +02001166
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001167function XLongLinesTests(cchar)
1168 let l = g:Xgetlist()
Bram Moolenaar6be8c8e2016-04-30 13:17:09 +02001169
Bram Moolenaar049cba92016-06-26 14:38:04 +02001170 call assert_equal(4, len(l))
Bram Moolenaar6be8c8e2016-04-30 13:17:09 +02001171 call assert_equal(1, l[0].lnum)
1172 call assert_equal(1, l[0].col)
Bram Moolenaar049cba92016-06-26 14:38:04 +02001173 call assert_equal(1975, len(l[0].text))
Bram Moolenaar6be8c8e2016-04-30 13:17:09 +02001174 call assert_equal(2, l[1].lnum)
1175 call assert_equal(1, l[1].col)
1176 call assert_equal(4070, len(l[1].text))
1177 call assert_equal(3, l[2].lnum)
1178 call assert_equal(1, l[2].col)
Bram Moolenaar049cba92016-06-26 14:38:04 +02001179 call assert_equal(4070, len(l[2].text))
1180 call assert_equal(4, l[3].lnum)
1181 call assert_equal(1, l[3].col)
1182 call assert_equal(10, len(l[3].text))
Bram Moolenaar6be8c8e2016-04-30 13:17:09 +02001183
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001184 call g:Xsetlist([], 'r')
1185endfunction
Bram Moolenaar6be8c8e2016-04-30 13:17:09 +02001186
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001187function s:long_lines_tests(cchar)
1188 call s:setup_commands(a:cchar)
1189
Bram Moolenaar6be8c8e2016-04-30 13:17:09 +02001190 let testfile = 'samples/quickfix.txt'
1191
1192 " file
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001193 exe 'Xgetfile' testfile
1194 call XLongLinesTests(a:cchar)
Bram Moolenaar6be8c8e2016-04-30 13:17:09 +02001195
1196 " list
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001197 Xexpr readfile(testfile)
1198 call XLongLinesTests(a:cchar)
Bram Moolenaar6be8c8e2016-04-30 13:17:09 +02001199
1200 " string
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001201 Xexpr join(readfile(testfile), "\n")
1202 call XLongLinesTests(a:cchar)
Bram Moolenaar6be8c8e2016-04-30 13:17:09 +02001203
1204 " buffer
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001205 exe 'edit' testfile
1206 exe 'Xbuffer' bufnr('%')
Bram Moolenaarf50df392016-06-21 21:33:34 +02001207 call XLongLinesTests(a:cchar)
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001208endfunction
1209
1210function Test_long_lines()
1211 call s:long_lines_tests('c')
1212 call s:long_lines_tests('l')
1213endfunction
Bram Moolenaar049cba92016-06-26 14:38:04 +02001214
1215function! s:create_test_file(filename)
1216 let l = []
1217 for i in range(1, 20)
1218 call add(l, 'Line' . i)
1219 endfor
1220 call writefile(l, a:filename)
1221endfunction
1222
1223function! Test_switchbuf()
1224 call s:create_test_file('Xqftestfile1')
1225 call s:create_test_file('Xqftestfile2')
1226 call s:create_test_file('Xqftestfile3')
1227
1228 new | only
1229 edit Xqftestfile1
1230 let file1_winid = win_getid()
1231 new Xqftestfile2
1232 let file2_winid = win_getid()
1233 cgetexpr ['Xqftestfile1:5:Line5',
1234 \ 'Xqftestfile1:6:Line6',
1235 \ 'Xqftestfile2:10:Line10',
1236 \ 'Xqftestfile2:11:Line11',
1237 \ 'Xqftestfile3:15:Line15',
1238 \ 'Xqftestfile3:16:Line16']
1239
1240 new
1241 let winid = win_getid()
1242 cfirst | cnext
1243 call assert_equal(winid, win_getid())
1244 cnext | cnext
1245 call assert_equal(winid, win_getid())
1246 cnext | cnext
1247 call assert_equal(winid, win_getid())
1248 enew
1249
1250 set switchbuf=useopen
1251 cfirst | cnext
1252 call assert_equal(file1_winid, win_getid())
1253 cnext | cnext
1254 call assert_equal(file2_winid, win_getid())
1255 cnext | cnext
1256 call assert_equal(file2_winid, win_getid())
1257
1258 enew | only
1259 set switchbuf=usetab
1260 tabedit Xqftestfile1
1261 tabedit Xqftestfile2
1262 tabfirst
1263 cfirst | cnext
1264 call assert_equal(2, tabpagenr())
1265 cnext | cnext
1266 call assert_equal(3, tabpagenr())
1267 cnext | cnext
1268 call assert_equal(3, tabpagenr())
1269 tabfirst | tabonly | enew
1270
1271 set switchbuf=split
1272 cfirst | cnext
1273 call assert_equal(1, winnr('$'))
1274 cnext | cnext
1275 call assert_equal(2, winnr('$'))
1276 cnext | cnext
1277 call assert_equal(3, winnr('$'))
1278 enew | only
1279
1280 set switchbuf=newtab
1281 cfirst | cnext
1282 call assert_equal(1, tabpagenr('$'))
1283 cnext | cnext
1284 call assert_equal(2, tabpagenr('$'))
1285 cnext | cnext
1286 call assert_equal(3, tabpagenr('$'))
1287 tabfirst | enew | tabonly | only
1288
1289 set switchbuf=
1290 edit Xqftestfile1
1291 let file1_winid = win_getid()
1292 new Xqftestfile2
1293 let file2_winid = win_getid()
1294 copen
1295 exe "normal 1G\<CR>"
1296 call assert_equal(file1_winid, win_getid())
1297 copen
1298 exe "normal 3G\<CR>"
1299 call assert_equal(file2_winid, win_getid())
1300 copen | only
1301 exe "normal 5G\<CR>"
1302 call assert_equal(2, winnr('$'))
1303 call assert_equal(1, bufwinnr('Xqftestfile3'))
1304
1305 enew | only
1306
1307 call delete('Xqftestfile1')
1308 call delete('Xqftestfile2')
1309 call delete('Xqftestfile3')
1310endfunction
1311
1312function! Xadjust_qflnum(cchar)
1313 call s:setup_commands(a:cchar)
1314
1315 enew | only
1316
1317 call s:create_test_file('Xqftestfile')
1318 edit Xqftestfile
1319
1320 Xgetexpr ['Xqftestfile:5:Line5',
1321 \ 'Xqftestfile:10:Line10',
1322 \ 'Xqftestfile:15:Line15',
1323 \ 'Xqftestfile:20:Line20']
1324
1325 6,14delete
1326 call append(6, ['Buffer', 'Window'])
1327
1328 let l = g:Xgetlist()
1329
1330 call assert_equal(5, l[0].lnum)
1331 call assert_equal(6, l[2].lnum)
1332 call assert_equal(13, l[3].lnum)
1333
1334 enew!
1335 call delete('Xqftestfile')
1336endfunction
1337
1338function! Test_adjust_lnum()
1339 call Xadjust_qflnum('c')
1340 call Xadjust_qflnum('l')
1341endfunction
1342
1343" Tests for the :grep/:lgrep and :grepadd/:lgrepadd commands
1344function! s:test_xgrep(cchar)
1345 call s:setup_commands(a:cchar)
1346
1347 " The following lines are used for the grep test. Don't remove.
1348 " Grep_Test_Text: Match 1
1349 " Grep_Test_Text: Match 2
1350 " GrepAdd_Test_Text: Match 1
1351 " GrepAdd_Test_Text: Match 2
1352 enew! | only
1353 set makeef&vim
1354 silent Xgrep Grep_Test_Text: test_quickfix.vim
1355 call assert_true(len(g:Xgetlist()) == 3)
1356 Xopen
1357 call assert_true(w:quickfix_title =~ '^:grep')
1358 Xclose
1359 enew
1360 set makeef=Temp_File_##
1361 silent Xgrepadd GrepAdd_Test_Text: test_quickfix.vim
1362 call assert_true(len(g:Xgetlist()) == 6)
1363endfunction
1364
1365function! Test_grep()
1366 if !has('unix')
1367 " The grepprg may not be set on non-Unix systems
1368 return
1369 endif
1370
1371 call s:test_xgrep('c')
1372 call s:test_xgrep('l')
1373endfunction
Bram Moolenaar361c8f02016-07-02 15:41:47 +02001374
1375function! Test_two_windows()
1376 " Use one 'errorformat' for two windows. Add an expression to each of them,
1377 " make sure they each keep their own state.
1378 set efm=%DEntering\ dir\ '%f',%f:%l:%m,%XLeaving\ dir\ '%f'
1379 call mkdir('Xone/a', 'p')
1380 call mkdir('Xtwo/a', 'p')
1381 let lines = ['1', '2', 'one one one', '4', 'two two two', '6', '7']
1382 call writefile(lines, 'Xone/a/one.txt')
1383 call writefile(lines, 'Xtwo/a/two.txt')
1384
1385 new one
1386 let one_id = win_getid()
1387 lexpr ""
1388 new two
1389 let two_id = win_getid()
1390 lexpr ""
1391
1392 laddexpr "Entering dir 'Xtwo/a'"
1393 call win_gotoid(one_id)
1394 laddexpr "Entering dir 'Xone/a'"
1395 call win_gotoid(two_id)
1396 laddexpr 'two.txt:5:two two two'
1397 call win_gotoid(one_id)
1398 laddexpr 'one.txt:3:one one one'
1399
1400 let loc_one = getloclist(one_id)
1401echo string(loc_one)
1402 call assert_equal('Xone/a/one.txt', bufname(loc_one[1].bufnr))
1403 call assert_equal(3, loc_one[1].lnum)
1404
1405 let loc_two = getloclist(two_id)
1406echo string(loc_two)
1407 call assert_equal('Xtwo/a/two.txt', bufname(loc_two[1].bufnr))
1408 call assert_equal(5, loc_two[1].lnum)
1409
1410 call win_gotoid(one_id)
1411 bwipe!
1412 call win_gotoid(two_id)
1413 bwipe!
1414 call delete('Xone', 'rf')
1415 call delete('Xtwo', 'rf')
1416endfunc