blob: 9fbef15f8f688e588c85dc4856572e362aa68b02 [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>
Bram Moolenaar537ef082016-07-09 17:56:19 +020018 command! -nargs=* Xbottom <mods>cbottom <args>
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +020019 command! -nargs=* Xclose <mods>cclose <args>
20 command! -nargs=* -bang Xfile <mods>cfile<bang> <args>
21 command! -nargs=* Xgetfile <mods>cgetfile <args>
22 command! -nargs=* Xaddfile <mods>caddfile <args>
23 command! -nargs=* -bang Xbuffer <mods>cbuffer<bang> <args>
24 command! -nargs=* Xgetbuffer <mods>cgetbuffer <args>
25 command! -nargs=* Xaddbuffer <mods>caddbuffer <args>
26 command! -nargs=* Xrewind <mods>crewind <args>
27 command! -nargs=* -bang Xnext <mods>cnext<bang> <args>
Bram Moolenaar0fcc7c62016-07-02 21:22:52 +020028 command! -nargs=* -bang Xprev <mods>cprev<bang> <args>
29 command! -nargs=* -bang Xfirst <mods>cfirst<bang> <args>
30 command! -nargs=* -bang Xlast <mods>clast<bang> <args>
31 command! -nargs=* -bang Xnfile <mods>cnfile<bang> <args>
32 command! -nargs=* -bang Xpfile <mods>cpfile<bang> <args>
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +020033 command! -nargs=* Xexpr <mods>cexpr <args>
34 command! -nargs=* Xvimgrep <mods>vimgrep <args>
Bram Moolenaar049cba92016-06-26 14:38:04 +020035 command! -nargs=* Xgrep <mods> grep <args>
36 command! -nargs=* Xgrepadd <mods> grepadd <args>
37 command! -nargs=* Xhelpgrep helpgrep <args>
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +020038 let g:Xgetlist = function('getqflist')
39 let g:Xsetlist = function('setqflist')
40 else
41 command! -nargs=* -bang Xlist <mods>llist<bang> <args>
42 command! -nargs=* Xgetexpr <mods>lgetexpr <args>
Bram Moolenaar361c8f02016-07-02 15:41:47 +020043 command! -nargs=* Xaddexpr <mods>laddexpr <args>
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +020044 command! -nargs=* Xolder <mods>lolder <args>
45 command! -nargs=* Xnewer <mods>lnewer <args>
46 command! -nargs=* Xopen <mods>lopen <args>
47 command! -nargs=* Xwindow <mods>lwindow <args>
Bram Moolenaar537ef082016-07-09 17:56:19 +020048 command! -nargs=* Xbottom <mods>lbottom <args>
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +020049 command! -nargs=* Xclose <mods>lclose <args>
50 command! -nargs=* -bang Xfile <mods>lfile<bang> <args>
51 command! -nargs=* Xgetfile <mods>lgetfile <args>
52 command! -nargs=* Xaddfile <mods>laddfile <args>
53 command! -nargs=* -bang Xbuffer <mods>lbuffer<bang> <args>
54 command! -nargs=* Xgetbuffer <mods>lgetbuffer <args>
55 command! -nargs=* Xaddbuffer <mods>laddbuffer <args>
56 command! -nargs=* Xrewind <mods>lrewind <args>
57 command! -nargs=* -bang Xnext <mods>lnext<bang> <args>
Bram Moolenaar0fcc7c62016-07-02 21:22:52 +020058 command! -nargs=* -bang Xprev <mods>lprev<bang> <args>
59 command! -nargs=* -bang Xfirst <mods>lfirst<bang> <args>
60 command! -nargs=* -bang Xlast <mods>llast<bang> <args>
61 command! -nargs=* -bang Xnfile <mods>lnfile<bang> <args>
62 command! -nargs=* -bang Xpfile <mods>lpfile<bang> <args>
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +020063 command! -nargs=* Xexpr <mods>lexpr <args>
64 command! -nargs=* Xvimgrep <mods>lvimgrep <args>
Bram Moolenaar049cba92016-06-26 14:38:04 +020065 command! -nargs=* Xgrep <mods> lgrep <args>
66 command! -nargs=* Xgrepadd <mods> lgrepadd <args>
67 command! -nargs=* Xhelpgrep lhelpgrep <args>
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +020068 let g:Xgetlist = function('getloclist', [0])
69 let g:Xsetlist = function('setloclist', [0])
70 endif
71endfunction
72
Bram Moolenaarda59dd52016-01-05 21:59:58 +010073" Tests for the :clist and :llist commands
74function XlistTests(cchar)
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +020075 call s:setup_commands(a:cchar)
Bram Moolenaarda59dd52016-01-05 21:59:58 +010076
77 " With an empty list, command should return error
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +020078 Xgetexpr []
79 silent! Xlist
Bram Moolenaarda59dd52016-01-05 21:59:58 +010080 call assert_true(v:errmsg ==# 'E42: No Errors')
81
82 " Populate the list and then try
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +020083 Xgetexpr ['non-error 1', 'Xtestfile1:1:3:Line1',
Bram Moolenaarda59dd52016-01-05 21:59:58 +010084 \ 'non-error 2', 'Xtestfile2:2:2:Line2',
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +020085 \ 'non-error 3', 'Xtestfile3:3:1:Line3']
Bram Moolenaarda59dd52016-01-05 21:59:58 +010086
87 " List only valid entries
88 redir => result
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +020089 Xlist
Bram Moolenaarda59dd52016-01-05 21:59:58 +010090 redir END
91 let l = split(result, "\n")
92 call assert_equal([' 2 Xtestfile1:1 col 3: Line1',
93 \ ' 4 Xtestfile2:2 col 2: Line2',
94 \ ' 6 Xtestfile3:3 col 1: Line3'], l)
95
96 " List all the entries
97 redir => result
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +020098 Xlist!
Bram Moolenaarda59dd52016-01-05 21:59:58 +010099 redir END
100 let l = split(result, "\n")
101 call assert_equal([' 1: non-error 1', ' 2 Xtestfile1:1 col 3: Line1',
102 \ ' 3: non-error 2', ' 4 Xtestfile2:2 col 2: Line2',
103 \ ' 5: non-error 3', ' 6 Xtestfile3:3 col 1: Line3'], l)
104
105 " List a range of errors
106 redir => result
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +0200107 Xlist 3,6
Bram Moolenaarda59dd52016-01-05 21:59:58 +0100108 redir END
109 let l = split(result, "\n")
110 call assert_equal([' 4 Xtestfile2:2 col 2: Line2',
111 \ ' 6 Xtestfile3:3 col 1: Line3'], l)
112
113 redir => result
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +0200114 Xlist! 3,4
Bram Moolenaarda59dd52016-01-05 21:59:58 +0100115 redir END
116 let l = split(result, "\n")
117 call assert_equal([' 3: non-error 2', ' 4 Xtestfile2:2 col 2: Line2'], l)
118
119 redir => result
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +0200120 Xlist -6,-4
Bram Moolenaarda59dd52016-01-05 21:59:58 +0100121 redir END
122 let l = split(result, "\n")
123 call assert_equal([' 2 Xtestfile1:1 col 3: Line1'], l)
124
125 redir => result
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +0200126 Xlist! -5,-3
Bram Moolenaarda59dd52016-01-05 21:59:58 +0100127 redir END
128 let l = split(result, "\n")
129 call assert_equal([' 2 Xtestfile1:1 col 3: Line1',
130 \ ' 3: non-error 2', ' 4 Xtestfile2:2 col 2: Line2'], l)
131endfunction
132
133function Test_clist()
134 call XlistTests('c')
135 call XlistTests('l')
136endfunction
137
138" Tests for the :colder, :cnewer, :lolder and :lnewer commands
139" Note that this test assumes that a quickfix/location list is
Bram Moolenaarcfc0a352016-01-09 20:23:00 +0100140" already set by the caller.
Bram Moolenaarda59dd52016-01-05 21:59:58 +0100141function XageTests(cchar)
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +0200142 call s:setup_commands(a:cchar)
Bram Moolenaarda59dd52016-01-05 21:59:58 +0100143
144 " Jumping to a non existent list should return error
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +0200145 silent! Xolder 99
Bram Moolenaarda59dd52016-01-05 21:59:58 +0100146 call assert_true(v:errmsg ==# 'E380: At bottom of quickfix stack')
147
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +0200148 silent! Xnewer 99
Bram Moolenaarda59dd52016-01-05 21:59:58 +0100149 call assert_true(v:errmsg ==# 'E381: At top of quickfix stack')
150
151 " Add three quickfix/location lists
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +0200152 Xgetexpr ['Xtestfile1:1:3:Line1']
153 Xgetexpr ['Xtestfile2:2:2:Line2']
154 Xgetexpr ['Xtestfile3:3:1:Line3']
Bram Moolenaarda59dd52016-01-05 21:59:58 +0100155
156 " Go back two lists
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +0200157 Xolder
158 let l = g:Xgetlist()
Bram Moolenaarda59dd52016-01-05 21:59:58 +0100159 call assert_equal('Line2', l[0].text)
160
161 " Go forward two lists
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +0200162 Xnewer
163 let l = g:Xgetlist()
Bram Moolenaarda59dd52016-01-05 21:59:58 +0100164 call assert_equal('Line3', l[0].text)
165
166 " Test for the optional count argument
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +0200167 Xolder 2
168 let l = g:Xgetlist()
Bram Moolenaarda59dd52016-01-05 21:59:58 +0100169 call assert_equal('Line1', l[0].text)
170
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +0200171 Xnewer 2
172 let l = g:Xgetlist()
Bram Moolenaarda59dd52016-01-05 21:59:58 +0100173 call assert_equal('Line3', l[0].text)
174endfunction
175
176function Test_cage()
Bram Moolenaarcfc0a352016-01-09 20:23:00 +0100177 let list = [{'bufnr': 1, 'lnum': 1}]
178 call setqflist(list)
Bram Moolenaarda59dd52016-01-05 21:59:58 +0100179 call XageTests('c')
Bram Moolenaarcfc0a352016-01-09 20:23:00 +0100180
181 call setloclist(0, list)
Bram Moolenaarda59dd52016-01-05 21:59:58 +0100182 call XageTests('l')
183endfunction
184
185" Tests for the :cwindow, :lwindow :cclose, :lclose, :copen and :lopen
186" commands
187function XwindowTests(cchar)
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +0200188 call s:setup_commands(a:cchar)
Bram Moolenaarda59dd52016-01-05 21:59:58 +0100189
190 " Create a list with no valid entries
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +0200191 Xgetexpr ['non-error 1', 'non-error 2', 'non-error 3']
Bram Moolenaarda59dd52016-01-05 21:59:58 +0100192
193 " Quickfix/Location window should not open with no valid errors
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +0200194 Xwindow
Bram Moolenaarda59dd52016-01-05 21:59:58 +0100195 call assert_true(winnr('$') == 1)
196
197 " Create a list with valid entries
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +0200198 Xgetexpr ['Xtestfile1:1:3:Line1', 'Xtestfile2:2:2:Line2',
199 \ 'Xtestfile3:3:1:Line3']
Bram Moolenaarda59dd52016-01-05 21:59:58 +0100200
201 " Open the window
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +0200202 Xwindow
Bram Moolenaarda59dd52016-01-05 21:59:58 +0100203 call assert_true(winnr('$') == 2 && winnr() == 2 &&
204 \ getline('.') ==# 'Xtestfile1|1 col 3| Line1')
Bram Moolenaar537ef082016-07-09 17:56:19 +0200205 redraw!
Bram Moolenaarda59dd52016-01-05 21:59:58 +0100206
207 " Close the window
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +0200208 Xclose
Bram Moolenaarda59dd52016-01-05 21:59:58 +0100209 call assert_true(winnr('$') == 1)
210
211 " Create a list with no valid entries
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +0200212 Xgetexpr ['non-error 1', 'non-error 2', 'non-error 3']
Bram Moolenaarda59dd52016-01-05 21:59:58 +0100213
214 " Open the window
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +0200215 Xopen 5
Bram Moolenaarda59dd52016-01-05 21:59:58 +0100216 call assert_true(winnr('$') == 2 && getline('.') ==# '|| non-error 1'
217 \ && winheight('.') == 5)
218
219 " Opening the window again, should move the cursor to that window
220 wincmd t
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +0200221 Xopen 7
Bram Moolenaarda59dd52016-01-05 21:59:58 +0100222 call assert_true(winnr('$') == 2 && winnr() == 2 &&
223 \ winheight('.') == 7 &&
224 \ getline('.') ==# '|| non-error 1')
225
226
227 " Calling cwindow should close the quickfix window with no valid errors
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +0200228 Xwindow
Bram Moolenaarda59dd52016-01-05 21:59:58 +0100229 call assert_true(winnr('$') == 1)
230endfunction
231
232function Test_cwindow()
233 call XwindowTests('c')
234 call XwindowTests('l')
235endfunction
236
237" Tests for the :cfile, :lfile, :caddfile, :laddfile, :cgetfile and :lgetfile
238" commands.
239function XfileTests(cchar)
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +0200240 call s:setup_commands(a:cchar)
Bram Moolenaarda59dd52016-01-05 21:59:58 +0100241
242 call writefile(['Xtestfile1:700:10:Line 700',
243 \ 'Xtestfile2:800:15:Line 800'], 'Xqftestfile1')
244
245 enew!
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +0200246 Xfile Xqftestfile1
247 let l = g:Xgetlist()
Bram Moolenaarda59dd52016-01-05 21:59:58 +0100248 call assert_true(len(l) == 2 &&
249 \ l[0].lnum == 700 && l[0].col == 10 && l[0].text ==# 'Line 700' &&
250 \ l[1].lnum == 800 && l[1].col == 15 && l[1].text ==# 'Line 800')
251
Bram Moolenaar049cba92016-06-26 14:38:04 +0200252 " Test with a non existent file
253 call assert_fails('Xfile non_existent_file', 'E40')
254
Bram Moolenaarda59dd52016-01-05 21:59:58 +0100255 " Run cfile/lfile from a modified buffer
256 enew!
257 silent! put ='Quickfix'
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +0200258 silent! Xfile Xqftestfile1
Bram Moolenaarda59dd52016-01-05 21:59:58 +0100259 call assert_true(v:errmsg ==# 'E37: No write since last change (add ! to override)')
260
261 call writefile(['Xtestfile3:900:30:Line 900'], 'Xqftestfile1')
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +0200262 Xaddfile Xqftestfile1
263 let l = g:Xgetlist()
Bram Moolenaarda59dd52016-01-05 21:59:58 +0100264 call assert_true(len(l) == 3 &&
265 \ l[2].lnum == 900 && l[2].col == 30 && l[2].text ==# 'Line 900')
266
267 call writefile(['Xtestfile1:222:77:Line 222',
268 \ 'Xtestfile2:333:88:Line 333'], 'Xqftestfile1')
269
270 enew!
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +0200271 Xgetfile Xqftestfile1
272 let l = g:Xgetlist()
Bram Moolenaarda59dd52016-01-05 21:59:58 +0100273 call assert_true(len(l) == 2 &&
274 \ l[0].lnum == 222 && l[0].col == 77 && l[0].text ==# 'Line 222' &&
275 \ l[1].lnum == 333 && l[1].col == 88 && l[1].text ==# 'Line 333')
276
277 call delete('Xqftestfile1')
278endfunction
279
280function Test_cfile()
281 call XfileTests('c')
282 call XfileTests('l')
283endfunction
284
285" Tests for the :cbuffer, :lbuffer, :caddbuffer, :laddbuffer, :cgetbuffer and
286" :lgetbuffer commands.
287function XbufferTests(cchar)
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +0200288 call s:setup_commands(a:cchar)
Bram Moolenaarda59dd52016-01-05 21:59:58 +0100289
290 enew!
291 silent! call setline(1, ['Xtestfile7:700:10:Line 700',
292 \ 'Xtestfile8:800:15:Line 800'])
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +0200293 Xbuffer!
294 let l = g:Xgetlist()
Bram Moolenaarda59dd52016-01-05 21:59:58 +0100295 call assert_true(len(l) == 2 &&
296 \ l[0].lnum == 700 && l[0].col == 10 && l[0].text ==# 'Line 700' &&
297 \ l[1].lnum == 800 && l[1].col == 15 && l[1].text ==# 'Line 800')
298
299 enew!
300 silent! call setline(1, ['Xtestfile9:900:55:Line 900',
301 \ 'Xtestfile10:950:66:Line 950'])
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +0200302 Xgetbuffer
303 let l = g:Xgetlist()
Bram Moolenaarda59dd52016-01-05 21:59:58 +0100304 call assert_true(len(l) == 2 &&
305 \ l[0].lnum == 900 && l[0].col == 55 && l[0].text ==# 'Line 900' &&
306 \ l[1].lnum == 950 && l[1].col == 66 && l[1].text ==# 'Line 950')
307
308 enew!
309 silent! call setline(1, ['Xtestfile11:700:20:Line 700',
310 \ 'Xtestfile12:750:25:Line 750'])
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +0200311 Xaddbuffer
312 let l = g:Xgetlist()
Bram Moolenaarda59dd52016-01-05 21:59:58 +0100313 call assert_true(len(l) == 4 &&
314 \ l[1].lnum == 950 && l[1].col == 66 && l[1].text ==# 'Line 950' &&
315 \ l[2].lnum == 700 && l[2].col == 20 && l[2].text ==# 'Line 700' &&
316 \ l[3].lnum == 750 && l[3].col == 25 && l[3].text ==# 'Line 750')
Bram Moolenaarab47c612016-06-14 22:02:26 +0200317 enew!
Bram Moolenaarda59dd52016-01-05 21:59:58 +0100318
319endfunction
320
321function Test_cbuffer()
322 call XbufferTests('c')
323 call XbufferTests('l')
324endfunction
325
Bram Moolenaar0fcc7c62016-07-02 21:22:52 +0200326function XexprTests(cchar)
327 call s:setup_commands(a:cchar)
328
329 call assert_fails('Xexpr 10', 'E777:')
330endfunction
331
332function Test_cexpr()
333 call XexprTests('c')
334 call XexprTests('l')
335endfunction
336
337" Tests for :cnext, :cprev, :cfirst, :clast commands
338function Xtest_browse(cchar)
339 call s:setup_commands(a:cchar)
340
341 call s:create_test_file('Xqftestfile1')
342 call s:create_test_file('Xqftestfile2')
343
344 Xgetexpr ['Xqftestfile1:5:Line5',
345 \ 'Xqftestfile1:6:Line6',
346 \ 'Xqftestfile2:10:Line10',
347 \ 'Xqftestfile2:11:Line11']
348
349 Xfirst
350 call assert_fails('Xprev', 'E553')
351 call assert_fails('Xpfile', 'E553')
352 Xnfile
353 call assert_equal('Xqftestfile2', bufname('%'))
354 call assert_equal(10, line('.'))
355 Xpfile
356 call assert_equal('Xqftestfile1', bufname('%'))
357 call assert_equal(6, line('.'))
358 Xlast
359 call assert_equal('Xqftestfile2', bufname('%'))
360 call assert_equal(11, line('.'))
361 call assert_fails('Xnext', 'E553')
362 call assert_fails('Xnfile', 'E553')
363 Xrewind
364 call assert_equal('Xqftestfile1', bufname('%'))
365 call assert_equal(5, line('.'))
366
367 call delete('Xqftestfile1')
368 call delete('Xqftestfile2')
369endfunction
370
371function Test_browse()
372 call Xtest_browse('c')
373 call Xtest_browse('l')
374endfunction
375
Bram Moolenaar75bdf6a2016-01-07 21:25:08 +0100376function Test_nomem()
Bram Moolenaar8e8df252016-05-25 21:23:21 +0200377 call test_alloc_fail(GetAllocId('qf_dirname_start'), 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_dirname_now'), 0, 0)
Bram Moolenaara260b872016-01-15 20:48:22 +0100381 call assert_fails('vimgrep vim 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_namebuf'), 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_errmsg'), 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
Bram Moolenaar8e8df252016-05-25 21:23:21 +0200389 call test_alloc_fail(GetAllocId('qf_pattern'), 0, 0)
Bram Moolenaara260b872016-01-15 20:48:22 +0100390 call assert_fails('cfile runtest.vim', 'E342:')
Bram Moolenaar75bdf6a2016-01-07 21:25:08 +0100391
392endfunc
393
Bram Moolenaar049cba92016-06-26 14:38:04 +0200394function! s:test_xhelpgrep(cchar)
395 call s:setup_commands(a:cchar)
396 Xhelpgrep quickfix
397 Xopen
398 if a:cchar == 'c'
399 let title_text = ':helpgrep quickfix'
400 else
401 let title_text = ':lhelpgrep quickfix'
402 endif
403 call assert_true(w:quickfix_title =~ title_text, w:quickfix_title)
Bram Moolenaar62ef7972016-01-19 14:51:54 +0100404 " This wipes out the buffer, make sure that doesn't cause trouble.
Bram Moolenaar049cba92016-06-26 14:38:04 +0200405 Xclose
406endfunction
407
408function Test_helpgrep()
409 call s:test_xhelpgrep('c')
410 call s:test_xhelpgrep('l')
Bram Moolenaar62ef7972016-01-19 14:51:54 +0100411endfunc
Bram Moolenaar75bdf6a2016-01-07 21:25:08 +0100412
Bram Moolenaar6920c722016-01-22 22:44:10 +0100413func Test_errortitle()
414 augroup QfBufWinEnter
415 au!
416 au BufWinEnter * :let g:a=get(w:, 'quickfix_title', 'NONE')
417 augroup END
418 copen
419 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'')'}]
420 call setqflist(a)
421 call assert_equal(':setqflist()', g:a)
422 augroup QfBufWinEnter
423 au!
424 augroup END
425 augroup! QfBufWinEnter
426endfunc
Bram Moolenaare27dba42016-03-15 14:11:10 +0100427
Bram Moolenaar5584df62016-03-18 21:00:51 +0100428func Test_vimgreptitle()
429 augroup QfBufWinEnter
430 au!
431 au BufWinEnter * :let g:a=get(w:, 'quickfix_title', 'NONE')
432 augroup END
433 try
434 vimgrep /pattern/j file
435 catch /E480/
436 endtry
437 copen
438 call assert_equal(': vimgrep /pattern/j file', g:a)
439 augroup QfBufWinEnter
440 au!
441 augroup END
442 augroup! QfBufWinEnter
443endfunc
444
Bram Moolenaare27dba42016-03-15 14:11:10 +0100445function XqfTitleTests(cchar)
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +0200446 call s:setup_commands(a:cchar)
Bram Moolenaare27dba42016-03-15 14:11:10 +0100447
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +0200448 Xgetexpr ['file:1:1:message']
449 let l = g:Xgetlist()
Bram Moolenaare27dba42016-03-15 14:11:10 +0100450 if a:cchar == 'c'
451 call setqflist(l, 'r')
452 else
453 call setloclist(0, l, 'r')
454 endif
455
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +0200456 Xopen
Bram Moolenaare27dba42016-03-15 14:11:10 +0100457 if a:cchar == 'c'
458 let title = ':setqflist()'
459 else
460 let title = ':setloclist()'
461 endif
462 call assert_equal(title, w:quickfix_title)
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +0200463 Xclose
Bram Moolenaare27dba42016-03-15 14:11:10 +0100464endfunction
465
466" Tests for quickfix window's title
467function Test_qf_title()
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +0200468 call XqfTitleTests('c')
469 call XqfTitleTests('l')
Bram Moolenaare27dba42016-03-15 14:11:10 +0100470endfunction
471
472" Tests for 'errorformat'
473function Test_efm()
474 let save_efm = &efm
475 set efm=%EEEE%m,%WWWW%m,%+CCCC%.%#,%-GGGG%.%#
476 cgetexpr ['WWWW', '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', 'EEEE', 'CCCC']
480 let l = strtrans(string(map(getqflist(), '[v:val.text, v:val.valid]')))
481 call assert_equal("[['W', 1], ['E^@CCCC', 1]]", l)
482 cgetexpr ['WWWW', 'GGGG', 'ZZZZ', 'EEEE', 'CCCC', 'YYYY']
483 let l = strtrans(string(map(getqflist(), '[v:val.text, v:val.valid]')))
484 call assert_equal("[['W', 1], ['ZZZZ', 0], ['E^@CCCC', 1], ['YYYY', 0]]", l)
485 let &efm = save_efm
486endfunction
Bram Moolenaar1ff2b642016-03-17 22:07:02 +0100487
488" This will test for problems in quickfix:
489" A. incorrectly copying location lists which caused the location list to show
490" a different name than the file that was actually being displayed.
491" B. not reusing the window for which the location list window is opened but
492" instead creating new windows.
493" C. make sure that the location list window is not reused instead of the
494" window it belongs to.
495"
496" Set up the test environment:
497function! ReadTestProtocol(name)
498 let base = substitute(a:name, '\v^test://(.*)%(\.[^.]+)?', '\1', '')
499 let word = substitute(base, '\v(.*)\..*', '\1', '')
500
501 setl modifiable
502 setl noreadonly
503 setl noswapfile
504 setl bufhidden=delete
505 %del _
506 " For problem 2:
507 " 'buftype' has to be set to reproduce the constant opening of new windows
508 setl buftype=nofile
509
510 call setline(1, word)
511
512 setl nomodified
513 setl nomodifiable
514 setl readonly
515 exe 'doautocmd BufRead ' . substitute(a:name, '\v^test://(.*)', '\1', '')
516endfunction
517
518function Test_locationlist()
519 enew
520
521 augroup testgroup
522 au!
523 autocmd BufReadCmd test://* call ReadTestProtocol(expand("<amatch>"))
524 augroup END
525
526 let words = [ "foo", "bar", "baz", "quux", "shmoo", "spam", "eggs" ]
527
528 let qflist = []
529 for word in words
530 call add(qflist, {'filename': 'test://' . word . '.txt', 'text': 'file ' . word . '.txt', })
531 " NOTE: problem 1:
532 " intentionally not setting 'lnum' so that the quickfix entries are not
533 " valid
534 call setloclist(0, qflist, ' ')
535 endfor
536
537 " Test A
538 lrewind
539 enew
540 lopen
541 lnext
542 lnext
543 lnext
544 lnext
545 vert split
546 wincmd L
547 lopen
548 wincmd p
549 lnext
550 let fileName = expand("%")
551 wincmd p
552 let locationListFileName = substitute(getline(line('.')), '\([^|]*\)|.*', '\1', '')
553 let fileName = substitute(fileName, '\\', '/', 'g')
554 let locationListFileName = substitute(locationListFileName, '\\', '/', 'g')
555 call assert_equal("test://bar.txt", fileName)
556 call assert_equal("test://bar.txt", locationListFileName)
557
558 wincmd n | only
559
560 " Test B:
561 lrewind
562 lopen
563 2
564 exe "normal \<CR>"
565 wincmd p
566 3
567 exe "normal \<CR>"
568 wincmd p
569 4
570 exe "normal \<CR>"
571 call assert_equal(2, winnr('$'))
572 wincmd n | only
573
574 " Test C:
575 lrewind
576 lopen
577 " Let's move the location list window to the top to check whether it (the
578 " first window found) will be reused when we try to open new windows:
579 wincmd K
580 2
581 exe "normal \<CR>"
582 wincmd p
583 3
584 exe "normal \<CR>"
585 wincmd p
586 4
587 exe "normal \<CR>"
588 1wincmd w
589 call assert_equal('quickfix', &buftype)
590 2wincmd w
591 let bufferName = expand("%")
592 let bufferName = substitute(bufferName, '\\', '/', 'g')
593 call assert_equal('test://quux.txt', bufferName)
594
595 wincmd n | only
596
597 augroup! testgroup
598endfunction
Bram Moolenaar0899d692016-03-19 13:35:03 +0100599
600function Test_locationlist_curwin_was_closed()
601 augroup testgroup
602 au!
Bram Moolenaard106e5b2016-04-21 19:38:07 +0200603 autocmd BufReadCmd test_curwin.txt call R(expand("<amatch>"))
Bram Moolenaar0899d692016-03-19 13:35:03 +0100604 augroup END
605
Bram Moolenaarffec3c52016-03-23 20:55:42 +0100606 function! R(n)
Bram Moolenaar0899d692016-03-19 13:35:03 +0100607 quit
608 endfunc
609
610 new
611 let q = []
Bram Moolenaard106e5b2016-04-21 19:38:07 +0200612 call add(q, {'filename': 'test_curwin.txt' })
Bram Moolenaar0899d692016-03-19 13:35:03 +0100613 call setloclist(0, q)
614 call assert_fails('lrewind', 'E924:')
615
616 augroup! testgroup
617endfunction
Bram Moolenaar7eba3d22016-03-19 22:54:09 +0100618
619" More tests for 'errorformat'
620function! Test_efm1()
621 if !has('unix')
622 " The 'errorformat' setting is different on non-Unix systems.
623 " This test works only on Unix-like systems.
624 return
625 endif
626
627 let l = [
628 \ '"Xtestfile", line 4.12: 1506-045 (S) Undeclared identifier fd_set.',
629 \ '"Xtestfile", line 6 col 19; this is an error',
630 \ 'gcc -c -DHAVE_CONFIsing-prototypes -I/usr/X11R6/include version.c',
631 \ 'Xtestfile:9: parse error before `asd''',
632 \ 'make: *** [vim] Error 1',
633 \ 'in file "Xtestfile" linenr 10: there is an error',
634 \ '',
635 \ '2 returned',
636 \ '"Xtestfile", line 11 col 1; this is an error',
637 \ '"Xtestfile", line 12 col 2; this is another error',
638 \ '"Xtestfile", line 14:10; this is an error in column 10',
639 \ '=Xtestfile=, line 15:10; this is another error, but in vcol 10 this time',
640 \ '"Xtestfile", linenr 16: yet another problem',
641 \ 'Error in "Xtestfile" at line 17:',
642 \ 'x should be a dot',
643 \ ' xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 17',
644 \ ' ^',
645 \ 'Error in "Xtestfile" at line 18:',
646 \ 'x should be a dot',
647 \ ' xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 18',
648 \ '.............^',
649 \ 'Error in "Xtestfile" at line 19:',
650 \ 'x should be a dot',
651 \ ' xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 19',
652 \ '--------------^',
653 \ 'Error in "Xtestfile" at line 20:',
654 \ 'x should be a dot',
655 \ ' xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 20',
656 \ ' ^',
657 \ '',
658 \ 'Does anyone know what is the problem and how to correction it?',
659 \ '"Xtestfile", line 21 col 9: What is the title of the quickfix window?',
660 \ '"Xtestfile", line 22 col 9: What is the title of the quickfix window?'
661 \ ]
662
663 call writefile(l, 'Xerrorfile1')
664 call writefile(l[:-2], 'Xerrorfile2')
665
666 let m = [
667 \ ' xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 2',
668 \ ' xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 3',
669 \ ' xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 4',
670 \ ' xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 5',
671 \ ' xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 6',
672 \ ' xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 7',
673 \ ' xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 8',
674 \ ' xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 9',
675 \ ' xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 10',
676 \ ' xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 11',
677 \ ' xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 12',
678 \ ' xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 13',
679 \ ' xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 14',
680 \ ' xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 15',
681 \ ' xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 16',
682 \ ' xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 17',
683 \ ' xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 18',
684 \ ' xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 19',
685 \ ' xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 20',
686 \ ' xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 21',
687 \ ' xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 22'
688 \ ]
689 call writefile(m, 'Xtestfile')
690
691 let save_efm = &efm
692 set efm+==%f=\\,\ line\ %l%*\\D%v%*[^\ ]\ %m
693 set efm^=%AError\ in\ \"%f\"\ at\ line\ %l:,%Z%p^,%C%m
694
695 exe 'cf Xerrorfile2'
696 clast
697 copen
698 call assert_equal(':cf Xerrorfile2', w:quickfix_title)
699 wincmd p
700
701 exe 'cf Xerrorfile1'
702 call assert_equal([4, 12], [line('.'), col('.')])
703 cn
704 call assert_equal([6, 19], [line('.'), col('.')])
705 cn
706 call assert_equal([9, 2], [line('.'), col('.')])
707 cn
708 call assert_equal([10, 2], [line('.'), col('.')])
709 cn
710 call assert_equal([11, 1], [line('.'), col('.')])
711 cn
712 call assert_equal([12, 2], [line('.'), col('.')])
713 cn
714 call assert_equal([14, 10], [line('.'), col('.')])
715 cn
716 call assert_equal([15, 3, 10], [line('.'), col('.'), virtcol('.')])
717 cn
718 call assert_equal([16, 2], [line('.'), col('.')])
719 cn
720 call assert_equal([17, 6], [line('.'), col('.')])
721 cn
722 call assert_equal([18, 7], [line('.'), col('.')])
723 cn
724 call assert_equal([19, 8], [line('.'), col('.')])
725 cn
726 call assert_equal([20, 9], [line('.'), col('.')])
727 clast
728 cprev
729 cprev
730 wincmd w
731 call assert_equal(':cf Xerrorfile1', w:quickfix_title)
732 wincmd p
733
734 let &efm = save_efm
735 call delete('Xerrorfile1')
736 call delete('Xerrorfile2')
737 call delete('Xtestfile')
738endfunction
Bram Moolenaarffec3c52016-03-23 20:55:42 +0100739
Bram Moolenaarab47c612016-06-14 22:02:26 +0200740" Test for quickfix directory stack support
741function! s:dir_stack_tests(cchar)
Bram Moolenaar38df43b2016-06-20 21:41:12 +0200742 call s:setup_commands(a:cchar)
743
Bram Moolenaarab47c612016-06-14 22:02:26 +0200744 let save_efm=&efm
745 set efm=%DEntering\ dir\ '%f',%f:%l:%m,%XLeaving\ dir\ '%f'
746
Bram Moolenaar361c8f02016-07-02 15:41:47 +0200747 let lines = ["Entering dir 'dir1/a'",
748 \ 'habits2.txt:1:Nine Healthy Habits',
749 \ "Entering dir 'b'",
750 \ 'habits3.txt:2:0 Hours of television',
751 \ 'habits2.txt:7:5 Small meals',
752 \ "Entering dir 'dir1/c'",
753 \ 'habits4.txt:3:1 Hour of exercise',
754 \ "Leaving dir 'dir1/c'",
755 \ "Leaving dir 'dir1/a'",
756 \ 'habits1.txt:4:2 Liters of water',
757 \ "Entering dir 'dir2'",
758 \ 'habits5.txt:5:3 Cups of hot green tea',
759 \ "Leaving dir 'dir2'"
760 \]
Bram Moolenaarab47c612016-06-14 22:02:26 +0200761
Bram Moolenaar361c8f02016-07-02 15:41:47 +0200762 Xexpr ""
763 for l in lines
764 Xaddexpr l
765 endfor
Bram Moolenaarab47c612016-06-14 22:02:26 +0200766
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +0200767 let qf = g:Xgetlist()
Bram Moolenaarab47c612016-06-14 22:02:26 +0200768
769 call assert_equal('dir1/a/habits2.txt', bufname(qf[1].bufnr))
770 call assert_equal(1, qf[1].lnum)
771 call assert_equal('dir1/a/b/habits3.txt', bufname(qf[3].bufnr))
772 call assert_equal(2, qf[3].lnum)
773 call assert_equal('dir1/a/habits2.txt', bufname(qf[4].bufnr))
774 call assert_equal(7, qf[4].lnum)
775 call assert_equal('dir1/c/habits4.txt', bufname(qf[6].bufnr))
776 call assert_equal(3, qf[6].lnum)
777 call assert_equal('habits1.txt', bufname(qf[9].bufnr))
778 call assert_equal(4, qf[9].lnum)
779 call assert_equal('dir2/habits5.txt', bufname(qf[11].bufnr))
780 call assert_equal(5, qf[11].lnum)
781
782 let &efm=save_efm
783endfunction
784
785" Tests for %D and %X errorformat options
786function! Test_efm_dirstack()
787 " Create the directory stack and files
788 call mkdir('dir1')
789 call mkdir('dir1/a')
790 call mkdir('dir1/a/b')
791 call mkdir('dir1/c')
792 call mkdir('dir2')
793
794 let lines = ["Nine Healthy Habits",
795 \ "0 Hours of television",
796 \ "1 Hour of exercise",
797 \ "2 Liters of water",
798 \ "3 Cups of hot green tea",
799 \ "4 Short mental breaks",
800 \ "5 Small meals",
801 \ "6 AM wake up time",
802 \ "7 Minutes of laughter",
803 \ "8 Hours of sleep (at least)",
804 \ "9 PM end of the day and off to bed"
805 \ ]
806 call writefile(lines, 'habits1.txt')
807 call writefile(lines, 'dir1/a/habits2.txt')
808 call writefile(lines, 'dir1/a/b/habits3.txt')
809 call writefile(lines, 'dir1/c/habits4.txt')
810 call writefile(lines, 'dir2/habits5.txt')
811
812 call s:dir_stack_tests('c')
813 call s:dir_stack_tests('l')
814
815 call delete('dir1', 'rf')
816 call delete('dir2', 'rf')
817 call delete('habits1.txt')
818endfunction
819
Bram Moolenaar0fcc7c62016-07-02 21:22:52 +0200820" Tests for invalid error format specifies
821function Xinvalid_efm_Tests(cchar)
822 call s:setup_commands(a:cchar)
823
Bram Moolenaar049cba92016-06-26 14:38:04 +0200824 let save_efm = &efm
825
Bram Moolenaar0fcc7c62016-07-02 21:22:52 +0200826 set efm=%f:%l:%m,%f:%f:%l:%m
827 call assert_fails('Xexpr "abc.txt:1:Hello world"', 'E372:')
828
829 set efm=%f:%l:%m,%f:%l:%r:%m
830 call assert_fails('Xexpr "abc.txt:1:Hello world"', 'E373:')
831
832 set efm=%f:%l:%m,%O:%f:%l:%m
833 call assert_fails('Xexpr "abc.txt:1:Hello world"', 'E373:')
834
835 set efm=%f:%l:%m,%f:%l:%*[^a-z
836 call assert_fails('Xexpr "abc.txt:1:Hello world"', 'E374:')
837
838 set efm=%f:%l:%m,%f:%l:%*c
839 call assert_fails('Xexpr "abc.txt:1:Hello world"', 'E375:')
840
841 set efm=%f:%l:%m,%L%M%N
842 call assert_fails('Xexpr "abc.txt:1:Hello world"', 'E376:')
843
844 set efm=%f:%l:%m,%f:%l:%m:%R
845 call assert_fails('Xexpr "abc.txt:1:Hello world"', 'E377:')
846
847 set efm=
848 call assert_fails('Xexpr "abc.txt:1:Hello world"', 'E378:')
849
850 set efm=%DEntering\ dir\ abc,%f:%l:%m
851 call assert_fails('Xexpr ["Entering dir abc", "abc.txt:1:Hello world"]', 'E379:')
852
853 let &efm = save_efm
854endfunction
855
856function Test_invalid_efm()
857 call Xinvalid_efm_Tests('c')
858 call Xinvalid_efm_Tests('l')
859endfunction
860
861" TODO:
862" Add tests for the following formats in 'errorformat'
863" %r %O
864function! Test_efm2()
865 let save_efm = &efm
Bram Moolenaar049cba92016-06-26 14:38:04 +0200866
867 " Test for %s format in efm
868 set efm=%f:%s
869 cexpr 'Xtestfile:Line search text'
Bram Moolenaar049cba92016-06-26 14:38:04 +0200870 let l = getqflist()
871 call assert_equal(l[0].pattern, '^\VLine search text\$')
872 call assert_equal(l[0].lnum, 0)
873
Bram Moolenaar0fcc7c62016-07-02 21:22:52 +0200874 " Test for %P, %Q and %t format specifiers
Bram Moolenaar049cba92016-06-26 14:38:04 +0200875 let lines=["[Xtestfile1]",
876 \ "(1,17) error: ';' missing",
877 \ "(21,2) warning: variable 'z' not defined",
878 \ "(67,3) error: end of file found before string ended",
879 \ "",
880 \ "[Xtestfile2]",
881 \ "",
882 \ "[Xtestfile3]",
883 \ "NEW compiler v1.1",
884 \ "(2,2) warning: variable 'x' not defined",
885 \ "(67,3) warning: 's' already defined"
886 \]
887 set efm=%+P[%f],(%l\\,%c)%*[\ ]%t%*[^:]:\ %m,%-Q
Bram Moolenaar361c8f02016-07-02 15:41:47 +0200888 cexpr ""
889 for l in lines
890 caddexpr l
891 endfor
Bram Moolenaar049cba92016-06-26 14:38:04 +0200892 let l = getqflist()
893 call assert_equal(9, len(l))
894 call assert_equal(21, l[2].lnum)
895 call assert_equal(2, l[2].col)
Bram Moolenaar0fcc7c62016-07-02 21:22:52 +0200896 call assert_equal('w', l[2].type)
897 call assert_equal('e', l[3].type)
898
899 " Tests for %E, %C and %Z format specifiers
900 let lines = ["Error 275",
901 \ "line 42",
902 \ "column 3",
903 \ "' ' expected after '--'"
904 \]
905 set efm=%EError\ %n,%Cline\ %l,%Ccolumn\ %c,%Z%m
906 cgetexpr lines
907 let l = getqflist()
908 call assert_equal(275, l[0].nr)
909 call assert_equal(42, l[0].lnum)
910 call assert_equal(3, l[0].col)
911 call assert_equal('E', l[0].type)
912 call assert_equal("\n' ' expected after '--'", l[0].text)
913
914 " Test for %>
915 let lines = ["Error in line 147 of foo.c:",
916 \"unknown variable 'i'"
917 \]
918 set efm=unknown\ variable\ %m,%E%>Error\ in\ line\ %l\ of\ %f:,%Z%m
919 cgetexpr lines
920 let l = getqflist()
921 call assert_equal(147, l[0].lnum)
922 call assert_equal('E', l[0].type)
923 call assert_equal("\nunknown variable 'i'", l[0].text)
Bram Moolenaar049cba92016-06-26 14:38:04 +0200924
925 let &efm = save_efm
926endfunction
927
Bram Moolenaarffec3c52016-03-23 20:55:42 +0100928function XquickfixChangedByAutocmd(cchar)
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +0200929 call s:setup_commands(a:cchar)
Bram Moolenaarffec3c52016-03-23 20:55:42 +0100930 if a:cchar == 'c'
Bram Moolenaarffec3c52016-03-23 20:55:42 +0100931 let ErrorNr = 'E925'
932 function! ReadFunc()
933 colder
934 cgetexpr []
935 endfunc
936 else
Bram Moolenaarffec3c52016-03-23 20:55:42 +0100937 let ErrorNr = 'E926'
938 function! ReadFunc()
939 lolder
940 lgetexpr []
941 endfunc
942 endif
943
944 augroup testgroup
945 au!
Bram Moolenaard106e5b2016-04-21 19:38:07 +0200946 autocmd BufReadCmd test_changed.txt call ReadFunc()
Bram Moolenaarffec3c52016-03-23 20:55:42 +0100947 augroup END
948
Bram Moolenaard106e5b2016-04-21 19:38:07 +0200949 new | only
Bram Moolenaarffec3c52016-03-23 20:55:42 +0100950 let words = [ "a", "b" ]
951 let qflist = []
952 for word in words
Bram Moolenaard106e5b2016-04-21 19:38:07 +0200953 call add(qflist, {'filename': 'test_changed.txt'})
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +0200954 call g:Xsetlist(qflist, ' ')
Bram Moolenaarffec3c52016-03-23 20:55:42 +0100955 endfor
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +0200956 call assert_fails('Xrewind', ErrorNr . ':')
Bram Moolenaarffec3c52016-03-23 20:55:42 +0100957
958 augroup! testgroup
959endfunc
960
961function Test_quickfix_was_changed_by_autocmd()
962 call XquickfixChangedByAutocmd('c')
963 call XquickfixChangedByAutocmd('l')
964endfunction
Bram Moolenaar8b201792016-03-25 15:01:10 +0100965
966func Test_caddbuffer_to_empty()
967 helpgr quickfix
968 call setqflist([], 'r')
969 cad
Bram Moolenaarf68f1d72016-03-25 17:14:06 +0100970 try
971 cn
972 catch
973 " number of matches is unknown
974 call assert_true(v:exception =~ 'E553:')
975 endtry
Bram Moolenaar8b201792016-03-25 15:01:10 +0100976 quit!
977endfunc
Bram Moolenaar89c64d52016-03-27 18:44:40 +0200978
979func Test_cgetexpr_works()
980 " this must not crash Vim
981 cgetexpr [$x]
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +0200982 lgetexpr [$x]
Bram Moolenaar89c64d52016-03-27 18:44:40 +0200983endfunc
Bram Moolenaarc1808d52016-04-18 20:04:00 +0200984
985" Tests for the setqflist() and setloclist() functions
986function SetXlistTests(cchar, bnum)
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +0200987 call s:setup_commands(a:cchar)
Bram Moolenaarc1808d52016-04-18 20:04:00 +0200988
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +0200989 call g:Xsetlist([{'bufnr': a:bnum, 'lnum': 1},
Bram Moolenaarc1808d52016-04-18 20:04:00 +0200990 \ {'bufnr': a:bnum, 'lnum': 2}])
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +0200991 let l = g:Xgetlist()
Bram Moolenaarc1808d52016-04-18 20:04:00 +0200992 call assert_equal(2, len(l))
993 call assert_equal(2, l[1].lnum)
994
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +0200995 Xnext
996 call g:Xsetlist([{'bufnr': a:bnum, 'lnum': 3}], 'a')
997 let l = g:Xgetlist()
Bram Moolenaarc1808d52016-04-18 20:04:00 +0200998 call assert_equal(3, len(l))
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +0200999 Xnext
Bram Moolenaarc1808d52016-04-18 20:04:00 +02001000 call assert_equal(3, line('.'))
1001
Bram Moolenaar2b2b8ae2016-05-24 19:59:51 +02001002 " Appending entries to the list should not change the cursor position
1003 " in the quickfix window
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001004 Xwindow
Bram Moolenaar2b2b8ae2016-05-24 19:59:51 +02001005 1
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001006 call g:Xsetlist([{'bufnr': a:bnum, 'lnum': 4},
Bram Moolenaar2b2b8ae2016-05-24 19:59:51 +02001007 \ {'bufnr': a:bnum, 'lnum': 5}], 'a')
1008 call assert_equal(1, line('.'))
1009 close
1010
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001011 call g:Xsetlist([{'bufnr': a:bnum, 'lnum': 3},
Bram Moolenaarc1808d52016-04-18 20:04:00 +02001012 \ {'bufnr': a:bnum, 'lnum': 4},
1013 \ {'bufnr': a:bnum, 'lnum': 5}], 'r')
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001014 let l = g:Xgetlist()
Bram Moolenaarc1808d52016-04-18 20:04:00 +02001015 call assert_equal(3, len(l))
1016 call assert_equal(5, l[2].lnum)
1017
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001018 call g:Xsetlist([])
1019 let l = g:Xgetlist()
Bram Moolenaarc1808d52016-04-18 20:04:00 +02001020 call assert_equal(0, len(l))
1021endfunction
1022
1023function Test_setqflist()
1024 new Xtestfile | only
1025 let bnum = bufnr('%')
1026 call setline(1, range(1,5))
1027
1028 call SetXlistTests('c', bnum)
1029 call SetXlistTests('l', bnum)
1030
Bram Moolenaar1cee6932016-06-09 22:17:22 +02001031 enew!
Bram Moolenaarc1808d52016-04-18 20:04:00 +02001032 call delete('Xtestfile')
1033endfunction
Bram Moolenaard106e5b2016-04-21 19:38:07 +02001034
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001035function Xlist_empty_middle(cchar)
1036 call s:setup_commands(a:cchar)
1037
Bram Moolenaar1cee6932016-06-09 22:17:22 +02001038 " create three quickfix lists
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001039 Xvimgrep Test_ test_quickfix.vim
1040 let testlen = len(g:Xgetlist())
Bram Moolenaar1cee6932016-06-09 22:17:22 +02001041 call assert_true(testlen > 0)
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001042 Xvimgrep empty test_quickfix.vim
1043 call assert_true(len(g:Xgetlist()) > 0)
1044 Xvimgrep matches test_quickfix.vim
1045 let matchlen = len(g:Xgetlist())
Bram Moolenaar1cee6932016-06-09 22:17:22 +02001046 call assert_true(matchlen > 0)
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001047 Xolder
Bram Moolenaar1cee6932016-06-09 22:17:22 +02001048 " make the middle list empty
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001049 call g:Xsetlist([], 'r')
1050 call assert_true(len(g:Xgetlist()) == 0)
1051 Xolder
1052 call assert_equal(testlen, len(g:Xgetlist()))
1053 Xnewer
1054 Xnewer
1055 call assert_equal(matchlen, len(g:Xgetlist()))
Bram Moolenaar1cee6932016-06-09 22:17:22 +02001056endfunc
1057
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001058function Test_setqflist_empty_middle()
1059 call Xlist_empty_middle('c')
1060 call Xlist_empty_middle('l')
1061endfunction
1062
1063function Xlist_empty_older(cchar)
1064 call s:setup_commands(a:cchar)
1065
Bram Moolenaar1cee6932016-06-09 22:17:22 +02001066 " create three quickfix lists
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001067 Xvimgrep one test_quickfix.vim
1068 let onelen = len(g:Xgetlist())
Bram Moolenaar1cee6932016-06-09 22:17:22 +02001069 call assert_true(onelen > 0)
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001070 Xvimgrep two test_quickfix.vim
1071 let twolen = len(g:Xgetlist())
Bram Moolenaar1cee6932016-06-09 22:17:22 +02001072 call assert_true(twolen > 0)
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001073 Xvimgrep three test_quickfix.vim
1074 let threelen = len(g:Xgetlist())
Bram Moolenaar1cee6932016-06-09 22:17:22 +02001075 call assert_true(threelen > 0)
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001076 Xolder 2
Bram Moolenaar1cee6932016-06-09 22:17:22 +02001077 " make the first list empty, check the others didn't change
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001078 call g:Xsetlist([], 'r')
1079 call assert_true(len(g:Xgetlist()) == 0)
1080 Xnewer
1081 call assert_equal(twolen, len(g:Xgetlist()))
1082 Xnewer
1083 call assert_equal(threelen, len(g:Xgetlist()))
1084endfunction
1085
1086function Test_setqflist_empty_older()
1087 call Xlist_empty_older('c')
1088 call Xlist_empty_older('l')
1089endfunction
Bram Moolenaar1cee6932016-06-09 22:17:22 +02001090
Bram Moolenaard106e5b2016-04-21 19:38:07 +02001091function! XquickfixSetListWithAct(cchar)
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001092 call s:setup_commands(a:cchar)
1093
Bram Moolenaard106e5b2016-04-21 19:38:07 +02001094 let list1 = [{'filename': 'fnameA', 'text': 'A'},
1095 \ {'filename': 'fnameB', 'text': 'B'}]
1096 let list2 = [{'filename': 'fnameC', 'text': 'C'},
1097 \ {'filename': 'fnameD', 'text': 'D'},
1098 \ {'filename': 'fnameE', 'text': 'E'}]
1099
1100 " {action} is unspecified. Same as specifing ' '.
1101 new | only
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001102 silent! Xnewer 99
1103 call g:Xsetlist(list1)
1104 call g:Xsetlist(list2)
1105 let li = g:Xgetlist()
Bram Moolenaard106e5b2016-04-21 19:38:07 +02001106 call assert_equal(3, len(li))
1107 call assert_equal('C', li[0]['text'])
1108 call assert_equal('D', li[1]['text'])
1109 call assert_equal('E', li[2]['text'])
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001110 silent! Xolder
1111 let li = g:Xgetlist()
Bram Moolenaard106e5b2016-04-21 19:38:07 +02001112 call assert_equal(2, len(li))
1113 call assert_equal('A', li[0]['text'])
1114 call assert_equal('B', li[1]['text'])
1115
1116 " {action} is specified ' '.
1117 new | only
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001118 silent! Xnewer 99
1119 call g:Xsetlist(list1)
1120 call g:Xsetlist(list2, ' ')
1121 let li = g:Xgetlist()
Bram Moolenaard106e5b2016-04-21 19:38:07 +02001122 call assert_equal(3, len(li))
1123 call assert_equal('C', li[0]['text'])
1124 call assert_equal('D', li[1]['text'])
1125 call assert_equal('E', li[2]['text'])
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001126 silent! Xolder
1127 let li = g:Xgetlist()
Bram Moolenaard106e5b2016-04-21 19:38:07 +02001128 call assert_equal(2, len(li))
1129 call assert_equal('A', li[0]['text'])
1130 call assert_equal('B', li[1]['text'])
1131
1132 " {action} is specified 'a'.
1133 new | only
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001134 silent! Xnewer 99
1135 call g:Xsetlist(list1)
1136 call g:Xsetlist(list2, 'a')
1137 let li = g:Xgetlist()
Bram Moolenaard106e5b2016-04-21 19:38:07 +02001138 call assert_equal(5, len(li))
1139 call assert_equal('A', li[0]['text'])
1140 call assert_equal('B', li[1]['text'])
1141 call assert_equal('C', li[2]['text'])
1142 call assert_equal('D', li[3]['text'])
1143 call assert_equal('E', li[4]['text'])
1144
1145 " {action} is specified 'r'.
1146 new | only
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001147 silent! Xnewer 99
1148 call g:Xsetlist(list1)
1149 call g:Xsetlist(list2, 'r')
1150 let li = g:Xgetlist()
Bram Moolenaard106e5b2016-04-21 19:38:07 +02001151 call assert_equal(3, len(li))
1152 call assert_equal('C', li[0]['text'])
1153 call assert_equal('D', li[1]['text'])
1154 call assert_equal('E', li[2]['text'])
1155
1156 " Test for wrong value.
1157 new | only
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001158 call assert_fails("call g:Xsetlist(0)", 'E714:')
1159 call assert_fails("call g:Xsetlist(list1, '')", 'E927:')
1160 call assert_fails("call g:Xsetlist(list1, 'aa')", 'E927:')
1161 call assert_fails("call g:Xsetlist(list1, ' a')", 'E927:')
1162 call assert_fails("call g:Xsetlist(list1, 0)", 'E928:')
Bram Moolenaard106e5b2016-04-21 19:38:07 +02001163endfunc
1164
1165function Test_quickfix_set_list_with_act()
1166 call XquickfixSetListWithAct('c')
1167 call XquickfixSetListWithAct('l')
1168endfunction
Bram Moolenaar6be8c8e2016-04-30 13:17:09 +02001169
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001170function XLongLinesTests(cchar)
1171 let l = g:Xgetlist()
Bram Moolenaar6be8c8e2016-04-30 13:17:09 +02001172
Bram Moolenaar049cba92016-06-26 14:38:04 +02001173 call assert_equal(4, len(l))
Bram Moolenaar6be8c8e2016-04-30 13:17:09 +02001174 call assert_equal(1, l[0].lnum)
1175 call assert_equal(1, l[0].col)
Bram Moolenaar049cba92016-06-26 14:38:04 +02001176 call assert_equal(1975, len(l[0].text))
Bram Moolenaar6be8c8e2016-04-30 13:17:09 +02001177 call assert_equal(2, l[1].lnum)
1178 call assert_equal(1, l[1].col)
1179 call assert_equal(4070, len(l[1].text))
1180 call assert_equal(3, l[2].lnum)
1181 call assert_equal(1, l[2].col)
Bram Moolenaar049cba92016-06-26 14:38:04 +02001182 call assert_equal(4070, len(l[2].text))
1183 call assert_equal(4, l[3].lnum)
1184 call assert_equal(1, l[3].col)
1185 call assert_equal(10, len(l[3].text))
Bram Moolenaar6be8c8e2016-04-30 13:17:09 +02001186
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001187 call g:Xsetlist([], 'r')
1188endfunction
Bram Moolenaar6be8c8e2016-04-30 13:17:09 +02001189
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001190function s:long_lines_tests(cchar)
1191 call s:setup_commands(a:cchar)
1192
Bram Moolenaar6be8c8e2016-04-30 13:17:09 +02001193 let testfile = 'samples/quickfix.txt'
1194
1195 " file
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001196 exe 'Xgetfile' testfile
1197 call XLongLinesTests(a:cchar)
Bram Moolenaar6be8c8e2016-04-30 13:17:09 +02001198
1199 " list
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001200 Xexpr readfile(testfile)
1201 call XLongLinesTests(a:cchar)
Bram Moolenaar6be8c8e2016-04-30 13:17:09 +02001202
1203 " string
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001204 Xexpr join(readfile(testfile), "\n")
1205 call XLongLinesTests(a:cchar)
Bram Moolenaar6be8c8e2016-04-30 13:17:09 +02001206
1207 " buffer
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001208 exe 'edit' testfile
1209 exe 'Xbuffer' bufnr('%')
Bram Moolenaarf50df392016-06-21 21:33:34 +02001210 call XLongLinesTests(a:cchar)
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001211endfunction
1212
1213function Test_long_lines()
1214 call s:long_lines_tests('c')
1215 call s:long_lines_tests('l')
1216endfunction
Bram Moolenaar049cba92016-06-26 14:38:04 +02001217
1218function! s:create_test_file(filename)
1219 let l = []
1220 for i in range(1, 20)
1221 call add(l, 'Line' . i)
1222 endfor
1223 call writefile(l, a:filename)
1224endfunction
1225
1226function! Test_switchbuf()
1227 call s:create_test_file('Xqftestfile1')
1228 call s:create_test_file('Xqftestfile2')
1229 call s:create_test_file('Xqftestfile3')
1230
1231 new | only
1232 edit Xqftestfile1
1233 let file1_winid = win_getid()
1234 new Xqftestfile2
1235 let file2_winid = win_getid()
1236 cgetexpr ['Xqftestfile1:5:Line5',
1237 \ 'Xqftestfile1:6:Line6',
1238 \ 'Xqftestfile2:10:Line10',
1239 \ 'Xqftestfile2:11:Line11',
1240 \ 'Xqftestfile3:15:Line15',
1241 \ 'Xqftestfile3:16:Line16']
1242
1243 new
1244 let winid = win_getid()
1245 cfirst | cnext
1246 call assert_equal(winid, win_getid())
1247 cnext | cnext
1248 call assert_equal(winid, win_getid())
1249 cnext | cnext
1250 call assert_equal(winid, win_getid())
1251 enew
1252
1253 set switchbuf=useopen
1254 cfirst | cnext
1255 call assert_equal(file1_winid, win_getid())
1256 cnext | cnext
1257 call assert_equal(file2_winid, win_getid())
1258 cnext | cnext
1259 call assert_equal(file2_winid, win_getid())
1260
1261 enew | only
1262 set switchbuf=usetab
1263 tabedit Xqftestfile1
1264 tabedit Xqftestfile2
1265 tabfirst
1266 cfirst | cnext
1267 call assert_equal(2, tabpagenr())
1268 cnext | cnext
1269 call assert_equal(3, tabpagenr())
1270 cnext | cnext
1271 call assert_equal(3, tabpagenr())
1272 tabfirst | tabonly | enew
1273
1274 set switchbuf=split
1275 cfirst | cnext
1276 call assert_equal(1, winnr('$'))
1277 cnext | cnext
1278 call assert_equal(2, winnr('$'))
1279 cnext | cnext
1280 call assert_equal(3, winnr('$'))
1281 enew | only
1282
1283 set switchbuf=newtab
1284 cfirst | cnext
1285 call assert_equal(1, tabpagenr('$'))
1286 cnext | cnext
1287 call assert_equal(2, tabpagenr('$'))
1288 cnext | cnext
1289 call assert_equal(3, tabpagenr('$'))
1290 tabfirst | enew | tabonly | only
1291
1292 set switchbuf=
1293 edit Xqftestfile1
1294 let file1_winid = win_getid()
1295 new Xqftestfile2
1296 let file2_winid = win_getid()
1297 copen
1298 exe "normal 1G\<CR>"
1299 call assert_equal(file1_winid, win_getid())
1300 copen
1301 exe "normal 3G\<CR>"
1302 call assert_equal(file2_winid, win_getid())
1303 copen | only
1304 exe "normal 5G\<CR>"
1305 call assert_equal(2, winnr('$'))
1306 call assert_equal(1, bufwinnr('Xqftestfile3'))
1307
1308 enew | only
1309
1310 call delete('Xqftestfile1')
1311 call delete('Xqftestfile2')
1312 call delete('Xqftestfile3')
1313endfunction
1314
1315function! Xadjust_qflnum(cchar)
1316 call s:setup_commands(a:cchar)
1317
1318 enew | only
1319
1320 call s:create_test_file('Xqftestfile')
1321 edit Xqftestfile
1322
1323 Xgetexpr ['Xqftestfile:5:Line5',
1324 \ 'Xqftestfile:10:Line10',
1325 \ 'Xqftestfile:15:Line15',
1326 \ 'Xqftestfile:20:Line20']
1327
1328 6,14delete
1329 call append(6, ['Buffer', 'Window'])
1330
1331 let l = g:Xgetlist()
1332
1333 call assert_equal(5, l[0].lnum)
1334 call assert_equal(6, l[2].lnum)
1335 call assert_equal(13, l[3].lnum)
1336
1337 enew!
1338 call delete('Xqftestfile')
1339endfunction
1340
1341function! Test_adjust_lnum()
1342 call Xadjust_qflnum('c')
1343 call Xadjust_qflnum('l')
1344endfunction
1345
1346" Tests for the :grep/:lgrep and :grepadd/:lgrepadd commands
1347function! s:test_xgrep(cchar)
1348 call s:setup_commands(a:cchar)
1349
1350 " The following lines are used for the grep test. Don't remove.
1351 " Grep_Test_Text: Match 1
1352 " Grep_Test_Text: Match 2
1353 " GrepAdd_Test_Text: Match 1
1354 " GrepAdd_Test_Text: Match 2
1355 enew! | only
1356 set makeef&vim
1357 silent Xgrep Grep_Test_Text: test_quickfix.vim
1358 call assert_true(len(g:Xgetlist()) == 3)
1359 Xopen
1360 call assert_true(w:quickfix_title =~ '^:grep')
1361 Xclose
1362 enew
1363 set makeef=Temp_File_##
1364 silent Xgrepadd GrepAdd_Test_Text: test_quickfix.vim
1365 call assert_true(len(g:Xgetlist()) == 6)
1366endfunction
1367
1368function! Test_grep()
1369 if !has('unix')
1370 " The grepprg may not be set on non-Unix systems
1371 return
1372 endif
1373
1374 call s:test_xgrep('c')
1375 call s:test_xgrep('l')
1376endfunction
Bram Moolenaar361c8f02016-07-02 15:41:47 +02001377
1378function! Test_two_windows()
1379 " Use one 'errorformat' for two windows. Add an expression to each of them,
1380 " make sure they each keep their own state.
1381 set efm=%DEntering\ dir\ '%f',%f:%l:%m,%XLeaving\ dir\ '%f'
1382 call mkdir('Xone/a', 'p')
1383 call mkdir('Xtwo/a', 'p')
1384 let lines = ['1', '2', 'one one one', '4', 'two two two', '6', '7']
1385 call writefile(lines, 'Xone/a/one.txt')
1386 call writefile(lines, 'Xtwo/a/two.txt')
1387
1388 new one
1389 let one_id = win_getid()
1390 lexpr ""
1391 new two
1392 let two_id = win_getid()
1393 lexpr ""
1394
1395 laddexpr "Entering dir 'Xtwo/a'"
1396 call win_gotoid(one_id)
1397 laddexpr "Entering dir 'Xone/a'"
1398 call win_gotoid(two_id)
1399 laddexpr 'two.txt:5:two two two'
1400 call win_gotoid(one_id)
1401 laddexpr 'one.txt:3:one one one'
1402
1403 let loc_one = getloclist(one_id)
1404echo string(loc_one)
1405 call assert_equal('Xone/a/one.txt', bufname(loc_one[1].bufnr))
1406 call assert_equal(3, loc_one[1].lnum)
1407
1408 let loc_two = getloclist(two_id)
1409echo string(loc_two)
1410 call assert_equal('Xtwo/a/two.txt', bufname(loc_two[1].bufnr))
1411 call assert_equal(5, loc_two[1].lnum)
1412
1413 call win_gotoid(one_id)
1414 bwipe!
1415 call win_gotoid(two_id)
1416 bwipe!
1417 call delete('Xone', 'rf')
1418 call delete('Xtwo', 'rf')
1419endfunc
Bram Moolenaardcb17002016-07-07 18:58:59 +02001420
Bram Moolenaar537ef082016-07-09 17:56:19 +02001421function XbottomTests(cchar)
1422 call s:setup_commands(a:cchar)
1423
1424 call g:Xsetlist([{'filename': 'foo', 'lnum': 42}])
1425 Xopen
Bram Moolenaardcb17002016-07-07 18:58:59 +02001426 let wid = win_getid()
1427 call assert_equal(1, line('.'))
1428 wincmd w
Bram Moolenaar537ef082016-07-09 17:56:19 +02001429 call g:Xsetlist([{'filename': 'var', 'lnum': 24}], 'a')
1430 Xbottom
Bram Moolenaardcb17002016-07-07 18:58:59 +02001431 call win_gotoid(wid)
1432 call assert_equal(2, line('.'))
Bram Moolenaar537ef082016-07-09 17:56:19 +02001433 Xclose
Bram Moolenaardcb17002016-07-07 18:58:59 +02001434endfunc
Bram Moolenaar537ef082016-07-09 17:56:19 +02001435
1436" Tests for the :cbottom and :lbottom commands
1437function Test_cbottom()
1438 call XbottomTests('c')
1439 call XbottomTests('l')
1440endfunction
Bram Moolenaarf6acffb2016-07-16 16:54:24 +02001441
1442function HistoryTest(cchar)
1443 call s:setup_commands(a:cchar)
1444
1445 call assert_fails(a:cchar . 'older 99', 'E380:')
1446 " clear all lists after the first one, then replace the first one.
1447 call g:Xsetlist([])
1448 Xolder
1449 let entry = {'filename': 'foo', 'lnum': 42}
1450 call g:Xsetlist([entry], 'r')
1451 call g:Xsetlist([entry, entry])
1452 call g:Xsetlist([entry, entry, entry])
1453 let res = split(execute(a:cchar . 'hist'), "\n")
1454 call assert_equal(3, len(res))
1455 let common = 'errors :set' . (a:cchar == 'c' ? 'qf' : 'loc') . 'list()'
1456 call assert_equal(' error list 1 of 3; 1 ' . common, res[0])
1457 call assert_equal(' error list 2 of 3; 2 ' . common, res[1])
1458 call assert_equal('> error list 3 of 3; 3 ' . common, res[2])
1459endfunc
1460
1461func Test_history()
1462 call HistoryTest('c')
1463 call HistoryTest('l')
1464endfunc