blob: 56bf9cb28f2d470e6b917e4de6a802b7c6cd9b4a [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>
13 command! -nargs=* Xolder <mods>colder <args>
14 command! -nargs=* Xnewer <mods>cnewer <args>
15 command! -nargs=* Xopen <mods>copen <args>
16 command! -nargs=* Xwindow <mods>cwindow <args>
17 command! -nargs=* Xclose <mods>cclose <args>
18 command! -nargs=* -bang Xfile <mods>cfile<bang> <args>
19 command! -nargs=* Xgetfile <mods>cgetfile <args>
20 command! -nargs=* Xaddfile <mods>caddfile <args>
21 command! -nargs=* -bang Xbuffer <mods>cbuffer<bang> <args>
22 command! -nargs=* Xgetbuffer <mods>cgetbuffer <args>
23 command! -nargs=* Xaddbuffer <mods>caddbuffer <args>
24 command! -nargs=* Xrewind <mods>crewind <args>
25 command! -nargs=* -bang Xnext <mods>cnext<bang> <args>
26 command! -nargs=* Xexpr <mods>cexpr <args>
27 command! -nargs=* Xvimgrep <mods>vimgrep <args>
28 let g:Xgetlist = function('getqflist')
29 let g:Xsetlist = function('setqflist')
30 else
31 command! -nargs=* -bang Xlist <mods>llist<bang> <args>
32 command! -nargs=* Xgetexpr <mods>lgetexpr <args>
33 command! -nargs=* Xolder <mods>lolder <args>
34 command! -nargs=* Xnewer <mods>lnewer <args>
35 command! -nargs=* Xopen <mods>lopen <args>
36 command! -nargs=* Xwindow <mods>lwindow <args>
37 command! -nargs=* Xclose <mods>lclose <args>
38 command! -nargs=* -bang Xfile <mods>lfile<bang> <args>
39 command! -nargs=* Xgetfile <mods>lgetfile <args>
40 command! -nargs=* Xaddfile <mods>laddfile <args>
41 command! -nargs=* -bang Xbuffer <mods>lbuffer<bang> <args>
42 command! -nargs=* Xgetbuffer <mods>lgetbuffer <args>
43 command! -nargs=* Xaddbuffer <mods>laddbuffer <args>
44 command! -nargs=* Xrewind <mods>lrewind <args>
45 command! -nargs=* -bang Xnext <mods>lnext<bang> <args>
46 command! -nargs=* Xexpr <mods>lexpr <args>
47 command! -nargs=* Xvimgrep <mods>lvimgrep <args>
48 let g:Xgetlist = function('getloclist', [0])
49 let g:Xsetlist = function('setloclist', [0])
50 endif
51endfunction
52
Bram Moolenaarda59dd52016-01-05 21:59:58 +010053" Tests for the :clist and :llist commands
54function XlistTests(cchar)
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +020055 call s:setup_commands(a:cchar)
Bram Moolenaarda59dd52016-01-05 21:59:58 +010056
57 " With an empty list, command should return error
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +020058 Xgetexpr []
59 silent! Xlist
Bram Moolenaarda59dd52016-01-05 21:59:58 +010060 call assert_true(v:errmsg ==# 'E42: No Errors')
61
62 " Populate the list and then try
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +020063 Xgetexpr ['non-error 1', 'Xtestfile1:1:3:Line1',
Bram Moolenaarda59dd52016-01-05 21:59:58 +010064 \ 'non-error 2', 'Xtestfile2:2:2:Line2',
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +020065 \ 'non-error 3', 'Xtestfile3:3:1:Line3']
Bram Moolenaarda59dd52016-01-05 21:59:58 +010066
67 " List only valid entries
68 redir => result
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +020069 Xlist
Bram Moolenaarda59dd52016-01-05 21:59:58 +010070 redir END
71 let l = split(result, "\n")
72 call assert_equal([' 2 Xtestfile1:1 col 3: Line1',
73 \ ' 4 Xtestfile2:2 col 2: Line2',
74 \ ' 6 Xtestfile3:3 col 1: Line3'], l)
75
76 " List all the entries
77 redir => result
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +020078 Xlist!
Bram Moolenaarda59dd52016-01-05 21:59:58 +010079 redir END
80 let l = split(result, "\n")
81 call assert_equal([' 1: non-error 1', ' 2 Xtestfile1:1 col 3: Line1',
82 \ ' 3: non-error 2', ' 4 Xtestfile2:2 col 2: Line2',
83 \ ' 5: non-error 3', ' 6 Xtestfile3:3 col 1: Line3'], l)
84
85 " List a range of errors
86 redir => result
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +020087 Xlist 3,6
Bram Moolenaarda59dd52016-01-05 21:59:58 +010088 redir END
89 let l = split(result, "\n")
90 call assert_equal([' 4 Xtestfile2:2 col 2: Line2',
91 \ ' 6 Xtestfile3:3 col 1: Line3'], l)
92
93 redir => result
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +020094 Xlist! 3,4
Bram Moolenaarda59dd52016-01-05 21:59:58 +010095 redir END
96 let l = split(result, "\n")
97 call assert_equal([' 3: non-error 2', ' 4 Xtestfile2:2 col 2: Line2'], l)
98
99 redir => result
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +0200100 Xlist -6,-4
Bram Moolenaarda59dd52016-01-05 21:59:58 +0100101 redir END
102 let l = split(result, "\n")
103 call assert_equal([' 2 Xtestfile1:1 col 3: Line1'], l)
104
105 redir => result
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +0200106 Xlist! -5,-3
Bram Moolenaarda59dd52016-01-05 21:59:58 +0100107 redir END
108 let l = split(result, "\n")
109 call assert_equal([' 2 Xtestfile1:1 col 3: Line1',
110 \ ' 3: non-error 2', ' 4 Xtestfile2:2 col 2: Line2'], l)
111endfunction
112
113function Test_clist()
114 call XlistTests('c')
115 call XlistTests('l')
116endfunction
117
118" Tests for the :colder, :cnewer, :lolder and :lnewer commands
119" Note that this test assumes that a quickfix/location list is
Bram Moolenaarcfc0a352016-01-09 20:23:00 +0100120" already set by the caller.
Bram Moolenaarda59dd52016-01-05 21:59:58 +0100121function XageTests(cchar)
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +0200122 call s:setup_commands(a:cchar)
Bram Moolenaarda59dd52016-01-05 21:59:58 +0100123
124 " Jumping to a non existent list should return error
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +0200125 silent! Xolder 99
Bram Moolenaarda59dd52016-01-05 21:59:58 +0100126 call assert_true(v:errmsg ==# 'E380: At bottom of quickfix stack')
127
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +0200128 silent! Xnewer 99
Bram Moolenaarda59dd52016-01-05 21:59:58 +0100129 call assert_true(v:errmsg ==# 'E381: At top of quickfix stack')
130
131 " Add three quickfix/location lists
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +0200132 Xgetexpr ['Xtestfile1:1:3:Line1']
133 Xgetexpr ['Xtestfile2:2:2:Line2']
134 Xgetexpr ['Xtestfile3:3:1:Line3']
Bram Moolenaarda59dd52016-01-05 21:59:58 +0100135
136 " Go back two lists
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +0200137 Xolder
138 let l = g:Xgetlist()
Bram Moolenaarda59dd52016-01-05 21:59:58 +0100139 call assert_equal('Line2', l[0].text)
140
141 " Go forward two lists
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +0200142 Xnewer
143 let l = g:Xgetlist()
Bram Moolenaarda59dd52016-01-05 21:59:58 +0100144 call assert_equal('Line3', l[0].text)
145
146 " Test for the optional count argument
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +0200147 Xolder 2
148 let l = g:Xgetlist()
Bram Moolenaarda59dd52016-01-05 21:59:58 +0100149 call assert_equal('Line1', l[0].text)
150
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +0200151 Xnewer 2
152 let l = g:Xgetlist()
Bram Moolenaarda59dd52016-01-05 21:59:58 +0100153 call assert_equal('Line3', l[0].text)
154endfunction
155
156function Test_cage()
Bram Moolenaarcfc0a352016-01-09 20:23:00 +0100157 let list = [{'bufnr': 1, 'lnum': 1}]
158 call setqflist(list)
Bram Moolenaarda59dd52016-01-05 21:59:58 +0100159 call XageTests('c')
Bram Moolenaarcfc0a352016-01-09 20:23:00 +0100160
161 call setloclist(0, list)
Bram Moolenaarda59dd52016-01-05 21:59:58 +0100162 call XageTests('l')
163endfunction
164
165" Tests for the :cwindow, :lwindow :cclose, :lclose, :copen and :lopen
166" commands
167function XwindowTests(cchar)
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +0200168 call s:setup_commands(a:cchar)
Bram Moolenaarda59dd52016-01-05 21:59:58 +0100169
170 " Create a list with no valid entries
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +0200171 Xgetexpr ['non-error 1', 'non-error 2', 'non-error 3']
Bram Moolenaarda59dd52016-01-05 21:59:58 +0100172
173 " Quickfix/Location window should not open with no valid errors
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +0200174 Xwindow
Bram Moolenaarda59dd52016-01-05 21:59:58 +0100175 call assert_true(winnr('$') == 1)
176
177 " Create a list with valid entries
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +0200178 Xgetexpr ['Xtestfile1:1:3:Line1', 'Xtestfile2:2:2:Line2',
179 \ 'Xtestfile3:3:1:Line3']
Bram Moolenaarda59dd52016-01-05 21:59:58 +0100180
181 " Open the window
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +0200182 Xwindow
Bram Moolenaarda59dd52016-01-05 21:59:58 +0100183 call assert_true(winnr('$') == 2 && winnr() == 2 &&
184 \ getline('.') ==# 'Xtestfile1|1 col 3| Line1')
185
186 " Close the window
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +0200187 Xclose
Bram Moolenaarda59dd52016-01-05 21:59:58 +0100188 call assert_true(winnr('$') == 1)
189
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 " Open the window
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +0200194 Xopen 5
Bram Moolenaarda59dd52016-01-05 21:59:58 +0100195 call assert_true(winnr('$') == 2 && getline('.') ==# '|| non-error 1'
196 \ && winheight('.') == 5)
197
198 " Opening the window again, should move the cursor to that window
199 wincmd t
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +0200200 Xopen 7
Bram Moolenaarda59dd52016-01-05 21:59:58 +0100201 call assert_true(winnr('$') == 2 && winnr() == 2 &&
202 \ winheight('.') == 7 &&
203 \ getline('.') ==# '|| non-error 1')
204
205
206 " Calling cwindow should close the quickfix window with no valid errors
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +0200207 Xwindow
Bram Moolenaarda59dd52016-01-05 21:59:58 +0100208 call assert_true(winnr('$') == 1)
209endfunction
210
211function Test_cwindow()
212 call XwindowTests('c')
213 call XwindowTests('l')
214endfunction
215
216" Tests for the :cfile, :lfile, :caddfile, :laddfile, :cgetfile and :lgetfile
217" commands.
218function XfileTests(cchar)
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +0200219 call s:setup_commands(a:cchar)
Bram Moolenaarda59dd52016-01-05 21:59:58 +0100220
221 call writefile(['Xtestfile1:700:10:Line 700',
222 \ 'Xtestfile2:800:15:Line 800'], 'Xqftestfile1')
223
224 enew!
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +0200225 Xfile Xqftestfile1
226 let l = g:Xgetlist()
Bram Moolenaarda59dd52016-01-05 21:59:58 +0100227 call assert_true(len(l) == 2 &&
228 \ l[0].lnum == 700 && l[0].col == 10 && l[0].text ==# 'Line 700' &&
229 \ l[1].lnum == 800 && l[1].col == 15 && l[1].text ==# 'Line 800')
230
231 " Run cfile/lfile from a modified buffer
232 enew!
233 silent! put ='Quickfix'
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +0200234 silent! Xfile Xqftestfile1
Bram Moolenaarda59dd52016-01-05 21:59:58 +0100235 call assert_true(v:errmsg ==# 'E37: No write since last change (add ! to override)')
236
237 call writefile(['Xtestfile3:900:30:Line 900'], 'Xqftestfile1')
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +0200238 Xaddfile Xqftestfile1
239 let l = g:Xgetlist()
Bram Moolenaarda59dd52016-01-05 21:59:58 +0100240 call assert_true(len(l) == 3 &&
241 \ l[2].lnum == 900 && l[2].col == 30 && l[2].text ==# 'Line 900')
242
243 call writefile(['Xtestfile1:222:77:Line 222',
244 \ 'Xtestfile2:333:88:Line 333'], 'Xqftestfile1')
245
246 enew!
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +0200247 Xgetfile Xqftestfile1
248 let l = g:Xgetlist()
Bram Moolenaarda59dd52016-01-05 21:59:58 +0100249 call assert_true(len(l) == 2 &&
250 \ l[0].lnum == 222 && l[0].col == 77 && l[0].text ==# 'Line 222' &&
251 \ l[1].lnum == 333 && l[1].col == 88 && l[1].text ==# 'Line 333')
252
253 call delete('Xqftestfile1')
254endfunction
255
256function Test_cfile()
257 call XfileTests('c')
258 call XfileTests('l')
259endfunction
260
261" Tests for the :cbuffer, :lbuffer, :caddbuffer, :laddbuffer, :cgetbuffer and
262" :lgetbuffer commands.
263function XbufferTests(cchar)
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +0200264 call s:setup_commands(a:cchar)
Bram Moolenaarda59dd52016-01-05 21:59:58 +0100265
266 enew!
267 silent! call setline(1, ['Xtestfile7:700:10:Line 700',
268 \ 'Xtestfile8:800:15:Line 800'])
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +0200269 Xbuffer!
270 let l = g:Xgetlist()
Bram Moolenaarda59dd52016-01-05 21:59:58 +0100271 call assert_true(len(l) == 2 &&
272 \ l[0].lnum == 700 && l[0].col == 10 && l[0].text ==# 'Line 700' &&
273 \ l[1].lnum == 800 && l[1].col == 15 && l[1].text ==# 'Line 800')
274
275 enew!
276 silent! call setline(1, ['Xtestfile9:900:55:Line 900',
277 \ 'Xtestfile10:950:66:Line 950'])
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +0200278 Xgetbuffer
279 let l = g:Xgetlist()
Bram Moolenaarda59dd52016-01-05 21:59:58 +0100280 call assert_true(len(l) == 2 &&
281 \ l[0].lnum == 900 && l[0].col == 55 && l[0].text ==# 'Line 900' &&
282 \ l[1].lnum == 950 && l[1].col == 66 && l[1].text ==# 'Line 950')
283
284 enew!
285 silent! call setline(1, ['Xtestfile11:700:20:Line 700',
286 \ 'Xtestfile12:750:25:Line 750'])
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +0200287 Xaddbuffer
288 let l = g:Xgetlist()
Bram Moolenaarda59dd52016-01-05 21:59:58 +0100289 call assert_true(len(l) == 4 &&
290 \ l[1].lnum == 950 && l[1].col == 66 && l[1].text ==# 'Line 950' &&
291 \ l[2].lnum == 700 && l[2].col == 20 && l[2].text ==# 'Line 700' &&
292 \ l[3].lnum == 750 && l[3].col == 25 && l[3].text ==# 'Line 750')
Bram Moolenaarab47c612016-06-14 22:02:26 +0200293 enew!
Bram Moolenaarda59dd52016-01-05 21:59:58 +0100294
295endfunction
296
297function Test_cbuffer()
298 call XbufferTests('c')
299 call XbufferTests('l')
300endfunction
301
Bram Moolenaar75bdf6a2016-01-07 21:25:08 +0100302function Test_nomem()
Bram Moolenaar8e8df252016-05-25 21:23:21 +0200303 call test_alloc_fail(GetAllocId('qf_dirname_start'), 0, 0)
Bram Moolenaara260b872016-01-15 20:48:22 +0100304 call assert_fails('vimgrep vim runtest.vim', 'E342:')
Bram Moolenaar75bdf6a2016-01-07 21:25:08 +0100305
Bram Moolenaar8e8df252016-05-25 21:23:21 +0200306 call test_alloc_fail(GetAllocId('qf_dirname_now'), 0, 0)
Bram Moolenaara260b872016-01-15 20:48:22 +0100307 call assert_fails('vimgrep vim runtest.vim', 'E342:')
Bram Moolenaar75bdf6a2016-01-07 21:25:08 +0100308
Bram Moolenaar8e8df252016-05-25 21:23:21 +0200309 call test_alloc_fail(GetAllocId('qf_namebuf'), 0, 0)
Bram Moolenaara260b872016-01-15 20:48:22 +0100310 call assert_fails('cfile runtest.vim', 'E342:')
Bram Moolenaar75bdf6a2016-01-07 21:25:08 +0100311
Bram Moolenaar8e8df252016-05-25 21:23:21 +0200312 call test_alloc_fail(GetAllocId('qf_errmsg'), 0, 0)
Bram Moolenaara260b872016-01-15 20:48:22 +0100313 call assert_fails('cfile runtest.vim', 'E342:')
Bram Moolenaar75bdf6a2016-01-07 21:25:08 +0100314
Bram Moolenaar8e8df252016-05-25 21:23:21 +0200315 call test_alloc_fail(GetAllocId('qf_pattern'), 0, 0)
Bram Moolenaara260b872016-01-15 20:48:22 +0100316 call assert_fails('cfile runtest.vim', 'E342:')
Bram Moolenaar75bdf6a2016-01-07 21:25:08 +0100317
318endfunc
319
Bram Moolenaar62ef7972016-01-19 14:51:54 +0100320function Test_helpgrep()
321 helpgrep quickfix
322 copen
323 " This wipes out the buffer, make sure that doesn't cause trouble.
324 cclose
325endfunc
Bram Moolenaar75bdf6a2016-01-07 21:25:08 +0100326
Bram Moolenaar6920c722016-01-22 22:44:10 +0100327func Test_errortitle()
328 augroup QfBufWinEnter
329 au!
330 au BufWinEnter * :let g:a=get(w:, 'quickfix_title', 'NONE')
331 augroup END
332 copen
333 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'')'}]
334 call setqflist(a)
335 call assert_equal(':setqflist()', g:a)
336 augroup QfBufWinEnter
337 au!
338 augroup END
339 augroup! QfBufWinEnter
340endfunc
Bram Moolenaare27dba42016-03-15 14:11:10 +0100341
Bram Moolenaar5584df62016-03-18 21:00:51 +0100342func Test_vimgreptitle()
343 augroup QfBufWinEnter
344 au!
345 au BufWinEnter * :let g:a=get(w:, 'quickfix_title', 'NONE')
346 augroup END
347 try
348 vimgrep /pattern/j file
349 catch /E480/
350 endtry
351 copen
352 call assert_equal(': vimgrep /pattern/j file', g:a)
353 augroup QfBufWinEnter
354 au!
355 augroup END
356 augroup! QfBufWinEnter
357endfunc
358
Bram Moolenaare27dba42016-03-15 14:11:10 +0100359function XqfTitleTests(cchar)
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +0200360 call s:setup_commands(a:cchar)
Bram Moolenaare27dba42016-03-15 14:11:10 +0100361
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +0200362 Xgetexpr ['file:1:1:message']
363 let l = g:Xgetlist()
Bram Moolenaare27dba42016-03-15 14:11:10 +0100364 if a:cchar == 'c'
365 call setqflist(l, 'r')
366 else
367 call setloclist(0, l, 'r')
368 endif
369
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +0200370 Xopen
Bram Moolenaare27dba42016-03-15 14:11:10 +0100371 if a:cchar == 'c'
372 let title = ':setqflist()'
373 else
374 let title = ':setloclist()'
375 endif
376 call assert_equal(title, w:quickfix_title)
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +0200377 Xclose
Bram Moolenaare27dba42016-03-15 14:11:10 +0100378endfunction
379
380" Tests for quickfix window's title
381function Test_qf_title()
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +0200382 call XqfTitleTests('c')
383 call XqfTitleTests('l')
Bram Moolenaare27dba42016-03-15 14:11:10 +0100384endfunction
385
386" Tests for 'errorformat'
387function Test_efm()
388 let save_efm = &efm
389 set efm=%EEEE%m,%WWWW%m,%+CCCC%.%#,%-GGGG%.%#
390 cgetexpr ['WWWW', 'EEEE', 'CCCC']
391 let l = strtrans(string(map(getqflist(), '[v:val.text, v:val.valid]')))
392 call assert_equal("[['W', 1], ['E^@CCCC', 1]]", l)
393 cgetexpr ['WWWW', 'GGGG', 'EEEE', 'CCCC']
394 let l = strtrans(string(map(getqflist(), '[v:val.text, v:val.valid]')))
395 call assert_equal("[['W', 1], ['E^@CCCC', 1]]", l)
396 cgetexpr ['WWWW', 'GGGG', 'ZZZZ', 'EEEE', 'CCCC', 'YYYY']
397 let l = strtrans(string(map(getqflist(), '[v:val.text, v:val.valid]')))
398 call assert_equal("[['W', 1], ['ZZZZ', 0], ['E^@CCCC', 1], ['YYYY', 0]]", l)
399 let &efm = save_efm
400endfunction
Bram Moolenaar1ff2b642016-03-17 22:07:02 +0100401
402" This will test for problems in quickfix:
403" A. incorrectly copying location lists which caused the location list to show
404" a different name than the file that was actually being displayed.
405" B. not reusing the window for which the location list window is opened but
406" instead creating new windows.
407" C. make sure that the location list window is not reused instead of the
408" window it belongs to.
409"
410" Set up the test environment:
411function! ReadTestProtocol(name)
412 let base = substitute(a:name, '\v^test://(.*)%(\.[^.]+)?', '\1', '')
413 let word = substitute(base, '\v(.*)\..*', '\1', '')
414
415 setl modifiable
416 setl noreadonly
417 setl noswapfile
418 setl bufhidden=delete
419 %del _
420 " For problem 2:
421 " 'buftype' has to be set to reproduce the constant opening of new windows
422 setl buftype=nofile
423
424 call setline(1, word)
425
426 setl nomodified
427 setl nomodifiable
428 setl readonly
429 exe 'doautocmd BufRead ' . substitute(a:name, '\v^test://(.*)', '\1', '')
430endfunction
431
432function Test_locationlist()
433 enew
434
435 augroup testgroup
436 au!
437 autocmd BufReadCmd test://* call ReadTestProtocol(expand("<amatch>"))
438 augroup END
439
440 let words = [ "foo", "bar", "baz", "quux", "shmoo", "spam", "eggs" ]
441
442 let qflist = []
443 for word in words
444 call add(qflist, {'filename': 'test://' . word . '.txt', 'text': 'file ' . word . '.txt', })
445 " NOTE: problem 1:
446 " intentionally not setting 'lnum' so that the quickfix entries are not
447 " valid
448 call setloclist(0, qflist, ' ')
449 endfor
450
451 " Test A
452 lrewind
453 enew
454 lopen
455 lnext
456 lnext
457 lnext
458 lnext
459 vert split
460 wincmd L
461 lopen
462 wincmd p
463 lnext
464 let fileName = expand("%")
465 wincmd p
466 let locationListFileName = substitute(getline(line('.')), '\([^|]*\)|.*', '\1', '')
467 let fileName = substitute(fileName, '\\', '/', 'g')
468 let locationListFileName = substitute(locationListFileName, '\\', '/', 'g')
469 call assert_equal("test://bar.txt", fileName)
470 call assert_equal("test://bar.txt", locationListFileName)
471
472 wincmd n | only
473
474 " Test B:
475 lrewind
476 lopen
477 2
478 exe "normal \<CR>"
479 wincmd p
480 3
481 exe "normal \<CR>"
482 wincmd p
483 4
484 exe "normal \<CR>"
485 call assert_equal(2, winnr('$'))
486 wincmd n | only
487
488 " Test C:
489 lrewind
490 lopen
491 " Let's move the location list window to the top to check whether it (the
492 " first window found) will be reused when we try to open new windows:
493 wincmd K
494 2
495 exe "normal \<CR>"
496 wincmd p
497 3
498 exe "normal \<CR>"
499 wincmd p
500 4
501 exe "normal \<CR>"
502 1wincmd w
503 call assert_equal('quickfix', &buftype)
504 2wincmd w
505 let bufferName = expand("%")
506 let bufferName = substitute(bufferName, '\\', '/', 'g')
507 call assert_equal('test://quux.txt', bufferName)
508
509 wincmd n | only
510
511 augroup! testgroup
512endfunction
Bram Moolenaar0899d692016-03-19 13:35:03 +0100513
514function Test_locationlist_curwin_was_closed()
515 augroup testgroup
516 au!
Bram Moolenaard106e5b2016-04-21 19:38:07 +0200517 autocmd BufReadCmd test_curwin.txt call R(expand("<amatch>"))
Bram Moolenaar0899d692016-03-19 13:35:03 +0100518 augroup END
519
Bram Moolenaarffec3c52016-03-23 20:55:42 +0100520 function! R(n)
Bram Moolenaar0899d692016-03-19 13:35:03 +0100521 quit
522 endfunc
523
524 new
525 let q = []
Bram Moolenaard106e5b2016-04-21 19:38:07 +0200526 call add(q, {'filename': 'test_curwin.txt' })
Bram Moolenaar0899d692016-03-19 13:35:03 +0100527 call setloclist(0, q)
528 call assert_fails('lrewind', 'E924:')
529
530 augroup! testgroup
531endfunction
Bram Moolenaar7eba3d22016-03-19 22:54:09 +0100532
533" More tests for 'errorformat'
534function! Test_efm1()
535 if !has('unix')
536 " The 'errorformat' setting is different on non-Unix systems.
537 " This test works only on Unix-like systems.
538 return
539 endif
540
541 let l = [
542 \ '"Xtestfile", line 4.12: 1506-045 (S) Undeclared identifier fd_set.',
543 \ '"Xtestfile", line 6 col 19; this is an error',
544 \ 'gcc -c -DHAVE_CONFIsing-prototypes -I/usr/X11R6/include version.c',
545 \ 'Xtestfile:9: parse error before `asd''',
546 \ 'make: *** [vim] Error 1',
547 \ 'in file "Xtestfile" linenr 10: there is an error',
548 \ '',
549 \ '2 returned',
550 \ '"Xtestfile", line 11 col 1; this is an error',
551 \ '"Xtestfile", line 12 col 2; this is another error',
552 \ '"Xtestfile", line 14:10; this is an error in column 10',
553 \ '=Xtestfile=, line 15:10; this is another error, but in vcol 10 this time',
554 \ '"Xtestfile", linenr 16: yet another problem',
555 \ 'Error in "Xtestfile" at line 17:',
556 \ 'x should be a dot',
557 \ ' xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 17',
558 \ ' ^',
559 \ 'Error in "Xtestfile" at line 18:',
560 \ 'x should be a dot',
561 \ ' xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 18',
562 \ '.............^',
563 \ 'Error in "Xtestfile" at line 19:',
564 \ 'x should be a dot',
565 \ ' xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 19',
566 \ '--------------^',
567 \ 'Error in "Xtestfile" at line 20:',
568 \ 'x should be a dot',
569 \ ' xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 20',
570 \ ' ^',
571 \ '',
572 \ 'Does anyone know what is the problem and how to correction it?',
573 \ '"Xtestfile", line 21 col 9: What is the title of the quickfix window?',
574 \ '"Xtestfile", line 22 col 9: What is the title of the quickfix window?'
575 \ ]
576
577 call writefile(l, 'Xerrorfile1')
578 call writefile(l[:-2], 'Xerrorfile2')
579
580 let m = [
581 \ ' xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 2',
582 \ ' xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 3',
583 \ ' xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 4',
584 \ ' xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 5',
585 \ ' xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 6',
586 \ ' xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 7',
587 \ ' xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 8',
588 \ ' xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 9',
589 \ ' xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 10',
590 \ ' xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 11',
591 \ ' xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 12',
592 \ ' xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 13',
593 \ ' xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 14',
594 \ ' xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 15',
595 \ ' xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 16',
596 \ ' xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 17',
597 \ ' xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 18',
598 \ ' xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 19',
599 \ ' xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 20',
600 \ ' xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 21',
601 \ ' xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 22'
602 \ ]
603 call writefile(m, 'Xtestfile')
604
605 let save_efm = &efm
606 set efm+==%f=\\,\ line\ %l%*\\D%v%*[^\ ]\ %m
607 set efm^=%AError\ in\ \"%f\"\ at\ line\ %l:,%Z%p^,%C%m
608
609 exe 'cf Xerrorfile2'
610 clast
611 copen
612 call assert_equal(':cf Xerrorfile2', w:quickfix_title)
613 wincmd p
614
615 exe 'cf Xerrorfile1'
616 call assert_equal([4, 12], [line('.'), col('.')])
617 cn
618 call assert_equal([6, 19], [line('.'), col('.')])
619 cn
620 call assert_equal([9, 2], [line('.'), col('.')])
621 cn
622 call assert_equal([10, 2], [line('.'), col('.')])
623 cn
624 call assert_equal([11, 1], [line('.'), col('.')])
625 cn
626 call assert_equal([12, 2], [line('.'), col('.')])
627 cn
628 call assert_equal([14, 10], [line('.'), col('.')])
629 cn
630 call assert_equal([15, 3, 10], [line('.'), col('.'), virtcol('.')])
631 cn
632 call assert_equal([16, 2], [line('.'), col('.')])
633 cn
634 call assert_equal([17, 6], [line('.'), col('.')])
635 cn
636 call assert_equal([18, 7], [line('.'), col('.')])
637 cn
638 call assert_equal([19, 8], [line('.'), col('.')])
639 cn
640 call assert_equal([20, 9], [line('.'), col('.')])
641 clast
642 cprev
643 cprev
644 wincmd w
645 call assert_equal(':cf Xerrorfile1', w:quickfix_title)
646 wincmd p
647
648 let &efm = save_efm
649 call delete('Xerrorfile1')
650 call delete('Xerrorfile2')
651 call delete('Xtestfile')
652endfunction
Bram Moolenaarffec3c52016-03-23 20:55:42 +0100653
Bram Moolenaarab47c612016-06-14 22:02:26 +0200654" Test for quickfix directory stack support
655function! s:dir_stack_tests(cchar)
Bram Moolenaar38df43b2016-06-20 21:41:12 +0200656 call s:setup_commands(a:cchar)
657
Bram Moolenaarab47c612016-06-14 22:02:26 +0200658 let save_efm=&efm
659 set efm=%DEntering\ dir\ '%f',%f:%l:%m,%XLeaving\ dir\ '%f'
660
661 let l = "Entering dir 'dir1/a'\n" .
662 \ 'habits2.txt:1:Nine Healthy Habits' . "\n" .
663 \ "Entering dir 'b'\n" .
664 \ 'habits3.txt:2:0 Hours of television' . "\n" .
665 \ 'habits2.txt:7:5 Small meals' . "\n" .
666 \ "Entering dir 'dir1/c'\n" .
667 \ 'habits4.txt:3:1 Hour of exercise' . "\n" .
668 \ "Leaving dir 'dir1/c'\n" .
669 \ "Leaving dir 'dir1/a'\n" .
670 \ 'habits1.txt:4:2 Liters of water' . "\n" .
671 \ "Entering dir 'dir2'\n" .
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +0200672 \ 'habits5.txt:5:3 Cups of hot green tea' . "\n"
Bram Moolenaarab47c612016-06-14 22:02:26 +0200673 \ "Leaving dir 'dir2'\n"
674
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +0200675 Xgetexpr l
Bram Moolenaarab47c612016-06-14 22:02:26 +0200676
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +0200677 let qf = g:Xgetlist()
Bram Moolenaarab47c612016-06-14 22:02:26 +0200678
679 call assert_equal('dir1/a/habits2.txt', bufname(qf[1].bufnr))
680 call assert_equal(1, qf[1].lnum)
681 call assert_equal('dir1/a/b/habits3.txt', bufname(qf[3].bufnr))
682 call assert_equal(2, qf[3].lnum)
683 call assert_equal('dir1/a/habits2.txt', bufname(qf[4].bufnr))
684 call assert_equal(7, qf[4].lnum)
685 call assert_equal('dir1/c/habits4.txt', bufname(qf[6].bufnr))
686 call assert_equal(3, qf[6].lnum)
687 call assert_equal('habits1.txt', bufname(qf[9].bufnr))
688 call assert_equal(4, qf[9].lnum)
689 call assert_equal('dir2/habits5.txt', bufname(qf[11].bufnr))
690 call assert_equal(5, qf[11].lnum)
691
692 let &efm=save_efm
693endfunction
694
695" Tests for %D and %X errorformat options
696function! Test_efm_dirstack()
697 " Create the directory stack and files
698 call mkdir('dir1')
699 call mkdir('dir1/a')
700 call mkdir('dir1/a/b')
701 call mkdir('dir1/c')
702 call mkdir('dir2')
703
704 let lines = ["Nine Healthy Habits",
705 \ "0 Hours of television",
706 \ "1 Hour of exercise",
707 \ "2 Liters of water",
708 \ "3 Cups of hot green tea",
709 \ "4 Short mental breaks",
710 \ "5 Small meals",
711 \ "6 AM wake up time",
712 \ "7 Minutes of laughter",
713 \ "8 Hours of sleep (at least)",
714 \ "9 PM end of the day and off to bed"
715 \ ]
716 call writefile(lines, 'habits1.txt')
717 call writefile(lines, 'dir1/a/habits2.txt')
718 call writefile(lines, 'dir1/a/b/habits3.txt')
719 call writefile(lines, 'dir1/c/habits4.txt')
720 call writefile(lines, 'dir2/habits5.txt')
721
722 call s:dir_stack_tests('c')
723 call s:dir_stack_tests('l')
724
725 call delete('dir1', 'rf')
726 call delete('dir2', 'rf')
727 call delete('habits1.txt')
728endfunction
729
Bram Moolenaarffec3c52016-03-23 20:55:42 +0100730function XquickfixChangedByAutocmd(cchar)
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +0200731 call s:setup_commands(a:cchar)
Bram Moolenaarffec3c52016-03-23 20:55:42 +0100732 if a:cchar == 'c'
Bram Moolenaarffec3c52016-03-23 20:55:42 +0100733 let ErrorNr = 'E925'
734 function! ReadFunc()
735 colder
736 cgetexpr []
737 endfunc
738 else
Bram Moolenaarffec3c52016-03-23 20:55:42 +0100739 let ErrorNr = 'E926'
740 function! ReadFunc()
741 lolder
742 lgetexpr []
743 endfunc
744 endif
745
746 augroup testgroup
747 au!
Bram Moolenaard106e5b2016-04-21 19:38:07 +0200748 autocmd BufReadCmd test_changed.txt call ReadFunc()
Bram Moolenaarffec3c52016-03-23 20:55:42 +0100749 augroup END
750
Bram Moolenaard106e5b2016-04-21 19:38:07 +0200751 new | only
Bram Moolenaarffec3c52016-03-23 20:55:42 +0100752 let words = [ "a", "b" ]
753 let qflist = []
754 for word in words
Bram Moolenaard106e5b2016-04-21 19:38:07 +0200755 call add(qflist, {'filename': 'test_changed.txt'})
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +0200756 call g:Xsetlist(qflist, ' ')
Bram Moolenaarffec3c52016-03-23 20:55:42 +0100757 endfor
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +0200758 call assert_fails('Xrewind', ErrorNr . ':')
Bram Moolenaarffec3c52016-03-23 20:55:42 +0100759
760 augroup! testgroup
761endfunc
762
763function Test_quickfix_was_changed_by_autocmd()
764 call XquickfixChangedByAutocmd('c')
765 call XquickfixChangedByAutocmd('l')
766endfunction
Bram Moolenaar8b201792016-03-25 15:01:10 +0100767
768func Test_caddbuffer_to_empty()
769 helpgr quickfix
770 call setqflist([], 'r')
771 cad
Bram Moolenaarf68f1d72016-03-25 17:14:06 +0100772 try
773 cn
774 catch
775 " number of matches is unknown
776 call assert_true(v:exception =~ 'E553:')
777 endtry
Bram Moolenaar8b201792016-03-25 15:01:10 +0100778 quit!
779endfunc
Bram Moolenaar89c64d52016-03-27 18:44:40 +0200780
781func Test_cgetexpr_works()
782 " this must not crash Vim
783 cgetexpr [$x]
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +0200784 lgetexpr [$x]
Bram Moolenaar89c64d52016-03-27 18:44:40 +0200785endfunc
Bram Moolenaarc1808d52016-04-18 20:04:00 +0200786
787" Tests for the setqflist() and setloclist() functions
788function SetXlistTests(cchar, bnum)
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +0200789 call s:setup_commands(a:cchar)
Bram Moolenaarc1808d52016-04-18 20:04:00 +0200790
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +0200791 call g:Xsetlist([{'bufnr': a:bnum, 'lnum': 1},
Bram Moolenaarc1808d52016-04-18 20:04:00 +0200792 \ {'bufnr': a:bnum, 'lnum': 2}])
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +0200793 let l = g:Xgetlist()
Bram Moolenaarc1808d52016-04-18 20:04:00 +0200794 call assert_equal(2, len(l))
795 call assert_equal(2, l[1].lnum)
796
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +0200797 Xnext
798 call g:Xsetlist([{'bufnr': a:bnum, 'lnum': 3}], 'a')
799 let l = g:Xgetlist()
Bram Moolenaarc1808d52016-04-18 20:04:00 +0200800 call assert_equal(3, len(l))
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +0200801 Xnext
Bram Moolenaarc1808d52016-04-18 20:04:00 +0200802 call assert_equal(3, line('.'))
803
Bram Moolenaar2b2b8ae2016-05-24 19:59:51 +0200804 " Appending entries to the list should not change the cursor position
805 " in the quickfix window
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +0200806 Xwindow
Bram Moolenaar2b2b8ae2016-05-24 19:59:51 +0200807 1
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +0200808 call g:Xsetlist([{'bufnr': a:bnum, 'lnum': 4},
Bram Moolenaar2b2b8ae2016-05-24 19:59:51 +0200809 \ {'bufnr': a:bnum, 'lnum': 5}], 'a')
810 call assert_equal(1, line('.'))
811 close
812
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +0200813 call g:Xsetlist([{'bufnr': a:bnum, 'lnum': 3},
Bram Moolenaarc1808d52016-04-18 20:04:00 +0200814 \ {'bufnr': a:bnum, 'lnum': 4},
815 \ {'bufnr': a:bnum, 'lnum': 5}], 'r')
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +0200816 let l = g:Xgetlist()
Bram Moolenaarc1808d52016-04-18 20:04:00 +0200817 call assert_equal(3, len(l))
818 call assert_equal(5, l[2].lnum)
819
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +0200820 call g:Xsetlist([])
821 let l = g:Xgetlist()
Bram Moolenaarc1808d52016-04-18 20:04:00 +0200822 call assert_equal(0, len(l))
823endfunction
824
825function Test_setqflist()
826 new Xtestfile | only
827 let bnum = bufnr('%')
828 call setline(1, range(1,5))
829
830 call SetXlistTests('c', bnum)
831 call SetXlistTests('l', bnum)
832
Bram Moolenaar1cee6932016-06-09 22:17:22 +0200833 enew!
Bram Moolenaarc1808d52016-04-18 20:04:00 +0200834 call delete('Xtestfile')
835endfunction
Bram Moolenaard106e5b2016-04-21 19:38:07 +0200836
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +0200837function Xlist_empty_middle(cchar)
838 call s:setup_commands(a:cchar)
839
Bram Moolenaar1cee6932016-06-09 22:17:22 +0200840 " create three quickfix lists
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +0200841 Xvimgrep Test_ test_quickfix.vim
842 let testlen = len(g:Xgetlist())
Bram Moolenaar1cee6932016-06-09 22:17:22 +0200843 call assert_true(testlen > 0)
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +0200844 Xvimgrep empty test_quickfix.vim
845 call assert_true(len(g:Xgetlist()) > 0)
846 Xvimgrep matches test_quickfix.vim
847 let matchlen = len(g:Xgetlist())
Bram Moolenaar1cee6932016-06-09 22:17:22 +0200848 call assert_true(matchlen > 0)
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +0200849 Xolder
Bram Moolenaar1cee6932016-06-09 22:17:22 +0200850 " make the middle list empty
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +0200851 call g:Xsetlist([], 'r')
852 call assert_true(len(g:Xgetlist()) == 0)
853 Xolder
854 call assert_equal(testlen, len(g:Xgetlist()))
855 Xnewer
856 Xnewer
857 call assert_equal(matchlen, len(g:Xgetlist()))
Bram Moolenaar1cee6932016-06-09 22:17:22 +0200858endfunc
859
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +0200860function Test_setqflist_empty_middle()
861 call Xlist_empty_middle('c')
862 call Xlist_empty_middle('l')
863endfunction
864
865function Xlist_empty_older(cchar)
866 call s:setup_commands(a:cchar)
867
Bram Moolenaar1cee6932016-06-09 22:17:22 +0200868 " create three quickfix lists
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +0200869 Xvimgrep one test_quickfix.vim
870 let onelen = len(g:Xgetlist())
Bram Moolenaar1cee6932016-06-09 22:17:22 +0200871 call assert_true(onelen > 0)
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +0200872 Xvimgrep two test_quickfix.vim
873 let twolen = len(g:Xgetlist())
Bram Moolenaar1cee6932016-06-09 22:17:22 +0200874 call assert_true(twolen > 0)
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +0200875 Xvimgrep three test_quickfix.vim
876 let threelen = len(g:Xgetlist())
Bram Moolenaar1cee6932016-06-09 22:17:22 +0200877 call assert_true(threelen > 0)
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +0200878 Xolder 2
Bram Moolenaar1cee6932016-06-09 22:17:22 +0200879 " make the first list empty, check the others didn't change
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +0200880 call g:Xsetlist([], 'r')
881 call assert_true(len(g:Xgetlist()) == 0)
882 Xnewer
883 call assert_equal(twolen, len(g:Xgetlist()))
884 Xnewer
885 call assert_equal(threelen, len(g:Xgetlist()))
886endfunction
887
888function Test_setqflist_empty_older()
889 call Xlist_empty_older('c')
890 call Xlist_empty_older('l')
891endfunction
Bram Moolenaar1cee6932016-06-09 22:17:22 +0200892
Bram Moolenaard106e5b2016-04-21 19:38:07 +0200893function! XquickfixSetListWithAct(cchar)
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +0200894 call s:setup_commands(a:cchar)
895
Bram Moolenaard106e5b2016-04-21 19:38:07 +0200896 let list1 = [{'filename': 'fnameA', 'text': 'A'},
897 \ {'filename': 'fnameB', 'text': 'B'}]
898 let list2 = [{'filename': 'fnameC', 'text': 'C'},
899 \ {'filename': 'fnameD', 'text': 'D'},
900 \ {'filename': 'fnameE', 'text': 'E'}]
901
902 " {action} is unspecified. Same as specifing ' '.
903 new | only
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +0200904 silent! Xnewer 99
905 call g:Xsetlist(list1)
906 call g:Xsetlist(list2)
907 let li = g:Xgetlist()
Bram Moolenaard106e5b2016-04-21 19:38:07 +0200908 call assert_equal(3, len(li))
909 call assert_equal('C', li[0]['text'])
910 call assert_equal('D', li[1]['text'])
911 call assert_equal('E', li[2]['text'])
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +0200912 silent! Xolder
913 let li = g:Xgetlist()
Bram Moolenaard106e5b2016-04-21 19:38:07 +0200914 call assert_equal(2, len(li))
915 call assert_equal('A', li[0]['text'])
916 call assert_equal('B', li[1]['text'])
917
918 " {action} is specified ' '.
919 new | only
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +0200920 silent! Xnewer 99
921 call g:Xsetlist(list1)
922 call g:Xsetlist(list2, ' ')
923 let li = g:Xgetlist()
Bram Moolenaard106e5b2016-04-21 19:38:07 +0200924 call assert_equal(3, len(li))
925 call assert_equal('C', li[0]['text'])
926 call assert_equal('D', li[1]['text'])
927 call assert_equal('E', li[2]['text'])
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +0200928 silent! Xolder
929 let li = g:Xgetlist()
Bram Moolenaard106e5b2016-04-21 19:38:07 +0200930 call assert_equal(2, len(li))
931 call assert_equal('A', li[0]['text'])
932 call assert_equal('B', li[1]['text'])
933
934 " {action} is specified 'a'.
935 new | only
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +0200936 silent! Xnewer 99
937 call g:Xsetlist(list1)
938 call g:Xsetlist(list2, 'a')
939 let li = g:Xgetlist()
Bram Moolenaard106e5b2016-04-21 19:38:07 +0200940 call assert_equal(5, len(li))
941 call assert_equal('A', li[0]['text'])
942 call assert_equal('B', li[1]['text'])
943 call assert_equal('C', li[2]['text'])
944 call assert_equal('D', li[3]['text'])
945 call assert_equal('E', li[4]['text'])
946
947 " {action} is specified 'r'.
948 new | only
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +0200949 silent! Xnewer 99
950 call g:Xsetlist(list1)
951 call g:Xsetlist(list2, 'r')
952 let li = g:Xgetlist()
Bram Moolenaard106e5b2016-04-21 19:38:07 +0200953 call assert_equal(3, len(li))
954 call assert_equal('C', li[0]['text'])
955 call assert_equal('D', li[1]['text'])
956 call assert_equal('E', li[2]['text'])
957
958 " Test for wrong value.
959 new | only
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +0200960 call assert_fails("call g:Xsetlist(0)", 'E714:')
961 call assert_fails("call g:Xsetlist(list1, '')", 'E927:')
962 call assert_fails("call g:Xsetlist(list1, 'aa')", 'E927:')
963 call assert_fails("call g:Xsetlist(list1, ' a')", 'E927:')
964 call assert_fails("call g:Xsetlist(list1, 0)", 'E928:')
Bram Moolenaard106e5b2016-04-21 19:38:07 +0200965endfunc
966
967function Test_quickfix_set_list_with_act()
968 call XquickfixSetListWithAct('c')
969 call XquickfixSetListWithAct('l')
970endfunction
Bram Moolenaar6be8c8e2016-04-30 13:17:09 +0200971
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +0200972function XLongLinesTests(cchar)
973 let l = g:Xgetlist()
Bram Moolenaar6be8c8e2016-04-30 13:17:09 +0200974
975 call assert_equal(3, len(l))
976 call assert_equal(1, l[0].lnum)
977 call assert_equal(1, l[0].col)
978 call assert_equal(4070, len(l[0].text))
979 call assert_equal(2, l[1].lnum)
980 call assert_equal(1, l[1].col)
981 call assert_equal(4070, len(l[1].text))
982 call assert_equal(3, l[2].lnum)
983 call assert_equal(1, l[2].col)
984 call assert_equal(10, len(l[2].text))
985
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +0200986 call g:Xsetlist([], 'r')
987endfunction
Bram Moolenaar6be8c8e2016-04-30 13:17:09 +0200988
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +0200989function s:long_lines_tests(cchar)
990 call s:setup_commands(a:cchar)
991
Bram Moolenaar6be8c8e2016-04-30 13:17:09 +0200992 let testfile = 'samples/quickfix.txt'
993
994 " file
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +0200995 exe 'Xgetfile' testfile
996 call XLongLinesTests(a:cchar)
Bram Moolenaar6be8c8e2016-04-30 13:17:09 +0200997
998 " list
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +0200999 Xexpr readfile(testfile)
1000 call XLongLinesTests(a:cchar)
Bram Moolenaar6be8c8e2016-04-30 13:17:09 +02001001
1002 " string
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001003 Xexpr join(readfile(testfile), "\n")
1004 call XLongLinesTests(a:cchar)
Bram Moolenaar6be8c8e2016-04-30 13:17:09 +02001005
1006 " buffer
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001007 exe 'edit' testfile
1008 exe 'Xbuffer' bufnr('%')
1009endfunction
1010
1011function Test_long_lines()
1012 call s:long_lines_tests('c')
1013 call s:long_lines_tests('l')
1014endfunction