blob: 248e6e2f13809776a22a4895e599adee43450330 [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 Moolenaar2b946c92016-11-12 18:14:44 +01009func s:setup_commands(cchar)
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +020010 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
Bram Moolenaar2b946c92016-11-12 18:14:44 +010071endfunc
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +020072
Bram Moolenaarda59dd52016-01-05 21:59:58 +010073" Tests for the :clist and :llist commands
Bram Moolenaar2b946c92016-11-12 18:14:44 +010074func 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)
Bram Moolenaar391b1dd2017-03-04 13:47:11 +0100131
132 " Test for '+'
133 redir => result
134 Xlist! +2
135 redir END
136 let l = split(result, "\n")
137 call assert_equal([' 2 Xtestfile1:1 col 3: Line1',
138 \ ' 3: non-error 2', ' 4 Xtestfile2:2 col 2: Line2'], l)
Bram Moolenaar2b946c92016-11-12 18:14:44 +0100139endfunc
Bram Moolenaarda59dd52016-01-05 21:59:58 +0100140
Bram Moolenaar2b946c92016-11-12 18:14:44 +0100141func Test_clist()
Bram Moolenaarda59dd52016-01-05 21:59:58 +0100142 call XlistTests('c')
143 call XlistTests('l')
Bram Moolenaar2b946c92016-11-12 18:14:44 +0100144endfunc
Bram Moolenaarda59dd52016-01-05 21:59:58 +0100145
146" Tests for the :colder, :cnewer, :lolder and :lnewer commands
147" Note that this test assumes that a quickfix/location list is
Bram Moolenaarcfc0a352016-01-09 20:23:00 +0100148" already set by the caller.
Bram Moolenaar2b946c92016-11-12 18:14:44 +0100149func XageTests(cchar)
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +0200150 call s:setup_commands(a:cchar)
Bram Moolenaarda59dd52016-01-05 21:59:58 +0100151
152 " Jumping to a non existent list should return error
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +0200153 silent! Xolder 99
Bram Moolenaarda59dd52016-01-05 21:59:58 +0100154 call assert_true(v:errmsg ==# 'E380: At bottom of quickfix stack')
155
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +0200156 silent! Xnewer 99
Bram Moolenaarda59dd52016-01-05 21:59:58 +0100157 call assert_true(v:errmsg ==# 'E381: At top of quickfix stack')
158
159 " Add three quickfix/location lists
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +0200160 Xgetexpr ['Xtestfile1:1:3:Line1']
161 Xgetexpr ['Xtestfile2:2:2:Line2']
162 Xgetexpr ['Xtestfile3:3:1:Line3']
Bram Moolenaarda59dd52016-01-05 21:59:58 +0100163
164 " Go back two lists
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +0200165 Xolder
166 let l = g:Xgetlist()
Bram Moolenaarda59dd52016-01-05 21:59:58 +0100167 call assert_equal('Line2', l[0].text)
168
169 " Go forward two lists
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +0200170 Xnewer
171 let l = g:Xgetlist()
Bram Moolenaarda59dd52016-01-05 21:59:58 +0100172 call assert_equal('Line3', l[0].text)
173
174 " Test for the optional count argument
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +0200175 Xolder 2
176 let l = g:Xgetlist()
Bram Moolenaarda59dd52016-01-05 21:59:58 +0100177 call assert_equal('Line1', l[0].text)
178
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +0200179 Xnewer 2
180 let l = g:Xgetlist()
Bram Moolenaarda59dd52016-01-05 21:59:58 +0100181 call assert_equal('Line3', l[0].text)
Bram Moolenaar2b946c92016-11-12 18:14:44 +0100182endfunc
Bram Moolenaarda59dd52016-01-05 21:59:58 +0100183
Bram Moolenaar2b946c92016-11-12 18:14:44 +0100184func Test_cage()
Bram Moolenaarcfc0a352016-01-09 20:23:00 +0100185 let list = [{'bufnr': 1, 'lnum': 1}]
186 call setqflist(list)
Bram Moolenaarda59dd52016-01-05 21:59:58 +0100187 call XageTests('c')
Bram Moolenaarcfc0a352016-01-09 20:23:00 +0100188
189 call setloclist(0, list)
Bram Moolenaarda59dd52016-01-05 21:59:58 +0100190 call XageTests('l')
Bram Moolenaar2b946c92016-11-12 18:14:44 +0100191endfunc
Bram Moolenaarda59dd52016-01-05 21:59:58 +0100192
193" Tests for the :cwindow, :lwindow :cclose, :lclose, :copen and :lopen
194" commands
Bram Moolenaar2b946c92016-11-12 18:14:44 +0100195func XwindowTests(cchar)
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +0200196 call s:setup_commands(a:cchar)
Bram Moolenaarda59dd52016-01-05 21:59:58 +0100197
198 " Create a list with no valid entries
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +0200199 Xgetexpr ['non-error 1', 'non-error 2', 'non-error 3']
Bram Moolenaarda59dd52016-01-05 21:59:58 +0100200
201 " Quickfix/Location window should not open with no valid errors
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +0200202 Xwindow
Bram Moolenaarda59dd52016-01-05 21:59:58 +0100203 call assert_true(winnr('$') == 1)
204
205 " Create a list with valid entries
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +0200206 Xgetexpr ['Xtestfile1:1:3:Line1', 'Xtestfile2:2:2:Line2',
207 \ 'Xtestfile3:3:1:Line3']
Bram Moolenaarda59dd52016-01-05 21:59:58 +0100208
209 " Open the window
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +0200210 Xwindow
Bram Moolenaarda59dd52016-01-05 21:59:58 +0100211 call assert_true(winnr('$') == 2 && winnr() == 2 &&
212 \ getline('.') ==# 'Xtestfile1|1 col 3| Line1')
Bram Moolenaar537ef082016-07-09 17:56:19 +0200213 redraw!
Bram Moolenaarda59dd52016-01-05 21:59:58 +0100214
215 " Close the window
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +0200216 Xclose
Bram Moolenaarda59dd52016-01-05 21:59:58 +0100217 call assert_true(winnr('$') == 1)
218
219 " Create a list with no valid entries
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +0200220 Xgetexpr ['non-error 1', 'non-error 2', 'non-error 3']
Bram Moolenaarda59dd52016-01-05 21:59:58 +0100221
222 " Open the window
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +0200223 Xopen 5
Bram Moolenaarda59dd52016-01-05 21:59:58 +0100224 call assert_true(winnr('$') == 2 && getline('.') ==# '|| non-error 1'
225 \ && winheight('.') == 5)
226
227 " Opening the window again, should move the cursor to that window
228 wincmd t
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +0200229 Xopen 7
Bram Moolenaarda59dd52016-01-05 21:59:58 +0100230 call assert_true(winnr('$') == 2 && winnr() == 2 &&
231 \ winheight('.') == 7 &&
232 \ getline('.') ==# '|| non-error 1')
233
234
235 " Calling cwindow should close the quickfix window with no valid errors
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +0200236 Xwindow
Bram Moolenaarda59dd52016-01-05 21:59:58 +0100237 call assert_true(winnr('$') == 1)
Bram Moolenaar2b946c92016-11-12 18:14:44 +0100238endfunc
Bram Moolenaarda59dd52016-01-05 21:59:58 +0100239
Bram Moolenaar2b946c92016-11-12 18:14:44 +0100240func Test_cwindow()
Bram Moolenaarda59dd52016-01-05 21:59:58 +0100241 call XwindowTests('c')
242 call XwindowTests('l')
Bram Moolenaar2b946c92016-11-12 18:14:44 +0100243endfunc
Bram Moolenaarda59dd52016-01-05 21:59:58 +0100244
245" Tests for the :cfile, :lfile, :caddfile, :laddfile, :cgetfile and :lgetfile
246" commands.
Bram Moolenaar2b946c92016-11-12 18:14:44 +0100247func XfileTests(cchar)
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +0200248 call s:setup_commands(a:cchar)
Bram Moolenaarda59dd52016-01-05 21:59:58 +0100249
250 call writefile(['Xtestfile1:700:10:Line 700',
251 \ 'Xtestfile2:800:15:Line 800'], 'Xqftestfile1')
252
253 enew!
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +0200254 Xfile Xqftestfile1
255 let l = g:Xgetlist()
Bram Moolenaarda59dd52016-01-05 21:59:58 +0100256 call assert_true(len(l) == 2 &&
257 \ l[0].lnum == 700 && l[0].col == 10 && l[0].text ==# 'Line 700' &&
258 \ l[1].lnum == 800 && l[1].col == 15 && l[1].text ==# 'Line 800')
259
Bram Moolenaar049cba92016-06-26 14:38:04 +0200260 " Test with a non existent file
261 call assert_fails('Xfile non_existent_file', 'E40')
262
Bram Moolenaarda59dd52016-01-05 21:59:58 +0100263 " Run cfile/lfile from a modified buffer
264 enew!
265 silent! put ='Quickfix'
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +0200266 silent! Xfile Xqftestfile1
Bram Moolenaarda59dd52016-01-05 21:59:58 +0100267 call assert_true(v:errmsg ==# 'E37: No write since last change (add ! to override)')
268
269 call writefile(['Xtestfile3:900:30:Line 900'], 'Xqftestfile1')
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +0200270 Xaddfile Xqftestfile1
271 let l = g:Xgetlist()
Bram Moolenaarda59dd52016-01-05 21:59:58 +0100272 call assert_true(len(l) == 3 &&
273 \ l[2].lnum == 900 && l[2].col == 30 && l[2].text ==# 'Line 900')
274
275 call writefile(['Xtestfile1:222:77:Line 222',
276 \ 'Xtestfile2:333:88:Line 333'], 'Xqftestfile1')
277
278 enew!
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +0200279 Xgetfile Xqftestfile1
280 let l = g:Xgetlist()
Bram Moolenaarda59dd52016-01-05 21:59:58 +0100281 call assert_true(len(l) == 2 &&
282 \ l[0].lnum == 222 && l[0].col == 77 && l[0].text ==# 'Line 222' &&
283 \ l[1].lnum == 333 && l[1].col == 88 && l[1].text ==# 'Line 333')
284
285 call delete('Xqftestfile1')
Bram Moolenaar2b946c92016-11-12 18:14:44 +0100286endfunc
Bram Moolenaarda59dd52016-01-05 21:59:58 +0100287
Bram Moolenaar2b946c92016-11-12 18:14:44 +0100288func Test_cfile()
Bram Moolenaarda59dd52016-01-05 21:59:58 +0100289 call XfileTests('c')
290 call XfileTests('l')
Bram Moolenaar2b946c92016-11-12 18:14:44 +0100291endfunc
Bram Moolenaarda59dd52016-01-05 21:59:58 +0100292
293" Tests for the :cbuffer, :lbuffer, :caddbuffer, :laddbuffer, :cgetbuffer and
294" :lgetbuffer commands.
Bram Moolenaar2b946c92016-11-12 18:14:44 +0100295func XbufferTests(cchar)
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +0200296 call s:setup_commands(a:cchar)
Bram Moolenaarda59dd52016-01-05 21:59:58 +0100297
298 enew!
299 silent! call setline(1, ['Xtestfile7:700:10:Line 700',
300 \ 'Xtestfile8:800:15:Line 800'])
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +0200301 Xbuffer!
302 let l = g:Xgetlist()
Bram Moolenaarda59dd52016-01-05 21:59:58 +0100303 call assert_true(len(l) == 2 &&
304 \ l[0].lnum == 700 && l[0].col == 10 && l[0].text ==# 'Line 700' &&
305 \ l[1].lnum == 800 && l[1].col == 15 && l[1].text ==# 'Line 800')
306
307 enew!
308 silent! call setline(1, ['Xtestfile9:900:55:Line 900',
309 \ 'Xtestfile10:950:66:Line 950'])
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +0200310 Xgetbuffer
311 let l = g:Xgetlist()
Bram Moolenaarda59dd52016-01-05 21:59:58 +0100312 call assert_true(len(l) == 2 &&
313 \ l[0].lnum == 900 && l[0].col == 55 && l[0].text ==# 'Line 900' &&
314 \ l[1].lnum == 950 && l[1].col == 66 && l[1].text ==# 'Line 950')
315
316 enew!
317 silent! call setline(1, ['Xtestfile11:700:20:Line 700',
318 \ 'Xtestfile12:750:25:Line 750'])
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +0200319 Xaddbuffer
320 let l = g:Xgetlist()
Bram Moolenaarda59dd52016-01-05 21:59:58 +0100321 call assert_true(len(l) == 4 &&
322 \ l[1].lnum == 950 && l[1].col == 66 && l[1].text ==# 'Line 950' &&
323 \ l[2].lnum == 700 && l[2].col == 20 && l[2].text ==# 'Line 700' &&
324 \ l[3].lnum == 750 && l[3].col == 25 && l[3].text ==# 'Line 750')
Bram Moolenaarab47c612016-06-14 22:02:26 +0200325 enew!
Bram Moolenaarda59dd52016-01-05 21:59:58 +0100326
Bram Moolenaar2b946c92016-11-12 18:14:44 +0100327endfunc
Bram Moolenaarda59dd52016-01-05 21:59:58 +0100328
Bram Moolenaar2b946c92016-11-12 18:14:44 +0100329func Test_cbuffer()
Bram Moolenaarda59dd52016-01-05 21:59:58 +0100330 call XbufferTests('c')
331 call XbufferTests('l')
Bram Moolenaar2b946c92016-11-12 18:14:44 +0100332endfunc
Bram Moolenaarda59dd52016-01-05 21:59:58 +0100333
Bram Moolenaar2b946c92016-11-12 18:14:44 +0100334func XexprTests(cchar)
Bram Moolenaar0fcc7c62016-07-02 21:22:52 +0200335 call s:setup_commands(a:cchar)
336
337 call assert_fails('Xexpr 10', 'E777:')
Bram Moolenaar2b946c92016-11-12 18:14:44 +0100338endfunc
Bram Moolenaar0fcc7c62016-07-02 21:22:52 +0200339
Bram Moolenaar2b946c92016-11-12 18:14:44 +0100340func Test_cexpr()
Bram Moolenaar0fcc7c62016-07-02 21:22:52 +0200341 call XexprTests('c')
342 call XexprTests('l')
Bram Moolenaar2b946c92016-11-12 18:14:44 +0100343endfunc
Bram Moolenaar0fcc7c62016-07-02 21:22:52 +0200344
345" Tests for :cnext, :cprev, :cfirst, :clast commands
Bram Moolenaar2b946c92016-11-12 18:14:44 +0100346func Xtest_browse(cchar)
Bram Moolenaar0fcc7c62016-07-02 21:22:52 +0200347 call s:setup_commands(a:cchar)
348
349 call s:create_test_file('Xqftestfile1')
350 call s:create_test_file('Xqftestfile2')
351
352 Xgetexpr ['Xqftestfile1:5:Line5',
353 \ 'Xqftestfile1:6:Line6',
354 \ 'Xqftestfile2:10:Line10',
355 \ 'Xqftestfile2:11:Line11']
356
357 Xfirst
358 call assert_fails('Xprev', 'E553')
359 call assert_fails('Xpfile', 'E553')
360 Xnfile
361 call assert_equal('Xqftestfile2', bufname('%'))
362 call assert_equal(10, line('.'))
363 Xpfile
364 call assert_equal('Xqftestfile1', bufname('%'))
365 call assert_equal(6, line('.'))
366 Xlast
367 call assert_equal('Xqftestfile2', bufname('%'))
368 call assert_equal(11, line('.'))
369 call assert_fails('Xnext', 'E553')
370 call assert_fails('Xnfile', 'E553')
371 Xrewind
372 call assert_equal('Xqftestfile1', bufname('%'))
373 call assert_equal(5, line('.'))
374
375 call delete('Xqftestfile1')
376 call delete('Xqftestfile2')
Bram Moolenaar2b946c92016-11-12 18:14:44 +0100377endfunc
Bram Moolenaar0fcc7c62016-07-02 21:22:52 +0200378
Bram Moolenaar2b946c92016-11-12 18:14:44 +0100379func Test_browse()
Bram Moolenaar0fcc7c62016-07-02 21:22:52 +0200380 call Xtest_browse('c')
381 call Xtest_browse('l')
Bram Moolenaar2b946c92016-11-12 18:14:44 +0100382endfunc
Bram Moolenaar0fcc7c62016-07-02 21:22:52 +0200383
Bram Moolenaar2b946c92016-11-12 18:14:44 +0100384func Test_nomem()
Bram Moolenaar8e8df252016-05-25 21:23:21 +0200385 call test_alloc_fail(GetAllocId('qf_dirname_start'), 0, 0)
Bram Moolenaara260b872016-01-15 20:48:22 +0100386 call assert_fails('vimgrep vim runtest.vim', 'E342:')
Bram Moolenaar75bdf6a2016-01-07 21:25:08 +0100387
Bram Moolenaar8e8df252016-05-25 21:23:21 +0200388 call test_alloc_fail(GetAllocId('qf_dirname_now'), 0, 0)
Bram Moolenaara260b872016-01-15 20:48:22 +0100389 call assert_fails('vimgrep vim runtest.vim', 'E342:')
Bram Moolenaar75bdf6a2016-01-07 21:25:08 +0100390
Bram Moolenaar8e8df252016-05-25 21:23:21 +0200391 call test_alloc_fail(GetAllocId('qf_namebuf'), 0, 0)
Bram Moolenaara260b872016-01-15 20:48:22 +0100392 call assert_fails('cfile runtest.vim', 'E342:')
Bram Moolenaar75bdf6a2016-01-07 21:25:08 +0100393
Bram Moolenaar8e8df252016-05-25 21:23:21 +0200394 call test_alloc_fail(GetAllocId('qf_errmsg'), 0, 0)
Bram Moolenaara260b872016-01-15 20:48:22 +0100395 call assert_fails('cfile runtest.vim', 'E342:')
Bram Moolenaar75bdf6a2016-01-07 21:25:08 +0100396
Bram Moolenaar8e8df252016-05-25 21:23:21 +0200397 call test_alloc_fail(GetAllocId('qf_pattern'), 0, 0)
Bram Moolenaara260b872016-01-15 20:48:22 +0100398 call assert_fails('cfile runtest.vim', 'E342:')
Bram Moolenaar75bdf6a2016-01-07 21:25:08 +0100399
400endfunc
401
Bram Moolenaar2b946c92016-11-12 18:14:44 +0100402func s:test_xhelpgrep(cchar)
Bram Moolenaar049cba92016-06-26 14:38:04 +0200403 call s:setup_commands(a:cchar)
404 Xhelpgrep quickfix
405 Xopen
406 if a:cchar == 'c'
407 let title_text = ':helpgrep quickfix'
408 else
409 let title_text = ':lhelpgrep quickfix'
410 endif
411 call assert_true(w:quickfix_title =~ title_text, w:quickfix_title)
Bram Moolenaar62ef7972016-01-19 14:51:54 +0100412 " This wipes out the buffer, make sure that doesn't cause trouble.
Bram Moolenaar049cba92016-06-26 14:38:04 +0200413 Xclose
Bram Moolenaar2b946c92016-11-12 18:14:44 +0100414endfunc
Bram Moolenaar049cba92016-06-26 14:38:04 +0200415
Bram Moolenaar2b946c92016-11-12 18:14:44 +0100416func Test_helpgrep()
Bram Moolenaar049cba92016-06-26 14:38:04 +0200417 call s:test_xhelpgrep('c')
Bram Moolenaarcf25fdb2016-08-03 21:04:53 +0200418 helpclose
Bram Moolenaar049cba92016-06-26 14:38:04 +0200419 call s:test_xhelpgrep('l')
Bram Moolenaar62ef7972016-01-19 14:51:54 +0100420endfunc
Bram Moolenaar75bdf6a2016-01-07 21:25:08 +0100421
Bram Moolenaar6920c722016-01-22 22:44:10 +0100422func Test_errortitle()
423 augroup QfBufWinEnter
424 au!
425 au BufWinEnter * :let g:a=get(w:, 'quickfix_title', 'NONE')
426 augroup END
427 copen
428 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'')'}]
429 call setqflist(a)
430 call assert_equal(':setqflist()', g:a)
431 augroup QfBufWinEnter
432 au!
433 augroup END
434 augroup! QfBufWinEnter
435endfunc
Bram Moolenaare27dba42016-03-15 14:11:10 +0100436
Bram Moolenaar5584df62016-03-18 21:00:51 +0100437func Test_vimgreptitle()
438 augroup QfBufWinEnter
439 au!
440 au BufWinEnter * :let g:a=get(w:, 'quickfix_title', 'NONE')
441 augroup END
442 try
443 vimgrep /pattern/j file
444 catch /E480/
445 endtry
446 copen
447 call assert_equal(': vimgrep /pattern/j file', g:a)
448 augroup QfBufWinEnter
449 au!
450 augroup END
451 augroup! QfBufWinEnter
452endfunc
453
Bram Moolenaar2b946c92016-11-12 18:14:44 +0100454func XqfTitleTests(cchar)
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +0200455 call s:setup_commands(a:cchar)
Bram Moolenaare27dba42016-03-15 14:11:10 +0100456
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +0200457 Xgetexpr ['file:1:1:message']
458 let l = g:Xgetlist()
Bram Moolenaare27dba42016-03-15 14:11:10 +0100459 if a:cchar == 'c'
460 call setqflist(l, 'r')
461 else
462 call setloclist(0, l, 'r')
463 endif
464
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +0200465 Xopen
Bram Moolenaare27dba42016-03-15 14:11:10 +0100466 if a:cchar == 'c'
467 let title = ':setqflist()'
468 else
469 let title = ':setloclist()'
470 endif
471 call assert_equal(title, w:quickfix_title)
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +0200472 Xclose
Bram Moolenaar2b946c92016-11-12 18:14:44 +0100473endfunc
Bram Moolenaare27dba42016-03-15 14:11:10 +0100474
475" Tests for quickfix window's title
Bram Moolenaar2b946c92016-11-12 18:14:44 +0100476func Test_qf_title()
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +0200477 call XqfTitleTests('c')
478 call XqfTitleTests('l')
Bram Moolenaar2b946c92016-11-12 18:14:44 +0100479endfunc
Bram Moolenaare27dba42016-03-15 14:11:10 +0100480
481" Tests for 'errorformat'
Bram Moolenaar2b946c92016-11-12 18:14:44 +0100482func Test_efm()
Bram Moolenaare27dba42016-03-15 14:11:10 +0100483 let save_efm = &efm
484 set efm=%EEEE%m,%WWWW%m,%+CCCC%.%#,%-GGGG%.%#
485 cgetexpr ['WWWW', 'EEEE', 'CCCC']
486 let l = strtrans(string(map(getqflist(), '[v:val.text, v:val.valid]')))
487 call assert_equal("[['W', 1], ['E^@CCCC', 1]]", l)
488 cgetexpr ['WWWW', 'GGGG', 'EEEE', 'CCCC']
489 let l = strtrans(string(map(getqflist(), '[v:val.text, v:val.valid]')))
490 call assert_equal("[['W', 1], ['E^@CCCC', 1]]", l)
491 cgetexpr ['WWWW', 'GGGG', 'ZZZZ', 'EEEE', 'CCCC', 'YYYY']
492 let l = strtrans(string(map(getqflist(), '[v:val.text, v:val.valid]')))
493 call assert_equal("[['W', 1], ['ZZZZ', 0], ['E^@CCCC', 1], ['YYYY', 0]]", l)
494 let &efm = save_efm
Bram Moolenaar2b946c92016-11-12 18:14:44 +0100495endfunc
Bram Moolenaar1ff2b642016-03-17 22:07:02 +0100496
497" This will test for problems in quickfix:
498" A. incorrectly copying location lists which caused the location list to show
499" a different name than the file that was actually being displayed.
500" B. not reusing the window for which the location list window is opened but
501" instead creating new windows.
502" C. make sure that the location list window is not reused instead of the
503" window it belongs to.
504"
505" Set up the test environment:
Bram Moolenaar2b946c92016-11-12 18:14:44 +0100506func ReadTestProtocol(name)
Bram Moolenaar1ff2b642016-03-17 22:07:02 +0100507 let base = substitute(a:name, '\v^test://(.*)%(\.[^.]+)?', '\1', '')
508 let word = substitute(base, '\v(.*)\..*', '\1', '')
509
510 setl modifiable
511 setl noreadonly
512 setl noswapfile
513 setl bufhidden=delete
514 %del _
515 " For problem 2:
516 " 'buftype' has to be set to reproduce the constant opening of new windows
517 setl buftype=nofile
518
519 call setline(1, word)
520
521 setl nomodified
522 setl nomodifiable
523 setl readonly
524 exe 'doautocmd BufRead ' . substitute(a:name, '\v^test://(.*)', '\1', '')
Bram Moolenaar2b946c92016-11-12 18:14:44 +0100525endfunc
Bram Moolenaar1ff2b642016-03-17 22:07:02 +0100526
Bram Moolenaar2b946c92016-11-12 18:14:44 +0100527func Test_locationlist()
Bram Moolenaar1ff2b642016-03-17 22:07:02 +0100528 enew
529
530 augroup testgroup
531 au!
532 autocmd BufReadCmd test://* call ReadTestProtocol(expand("<amatch>"))
533 augroup END
534
535 let words = [ "foo", "bar", "baz", "quux", "shmoo", "spam", "eggs" ]
536
537 let qflist = []
538 for word in words
539 call add(qflist, {'filename': 'test://' . word . '.txt', 'text': 'file ' . word . '.txt', })
540 " NOTE: problem 1:
541 " intentionally not setting 'lnum' so that the quickfix entries are not
542 " valid
543 call setloclist(0, qflist, ' ')
544 endfor
545
546 " Test A
547 lrewind
548 enew
549 lopen
550 lnext
551 lnext
552 lnext
553 lnext
554 vert split
555 wincmd L
556 lopen
557 wincmd p
558 lnext
559 let fileName = expand("%")
560 wincmd p
561 let locationListFileName = substitute(getline(line('.')), '\([^|]*\)|.*', '\1', '')
562 let fileName = substitute(fileName, '\\', '/', 'g')
563 let locationListFileName = substitute(locationListFileName, '\\', '/', 'g')
564 call assert_equal("test://bar.txt", fileName)
565 call assert_equal("test://bar.txt", locationListFileName)
566
567 wincmd n | only
568
569 " Test B:
570 lrewind
571 lopen
572 2
573 exe "normal \<CR>"
574 wincmd p
575 3
576 exe "normal \<CR>"
577 wincmd p
578 4
579 exe "normal \<CR>"
580 call assert_equal(2, winnr('$'))
581 wincmd n | only
582
583 " Test C:
584 lrewind
585 lopen
586 " Let's move the location list window to the top to check whether it (the
587 " first window found) will be reused when we try to open new windows:
588 wincmd K
589 2
590 exe "normal \<CR>"
591 wincmd p
592 3
593 exe "normal \<CR>"
594 wincmd p
595 4
596 exe "normal \<CR>"
597 1wincmd w
598 call assert_equal('quickfix', &buftype)
599 2wincmd w
600 let bufferName = expand("%")
601 let bufferName = substitute(bufferName, '\\', '/', 'g')
602 call assert_equal('test://quux.txt', bufferName)
603
604 wincmd n | only
605
606 augroup! testgroup
Bram Moolenaar2b946c92016-11-12 18:14:44 +0100607 endfunc
Bram Moolenaar0899d692016-03-19 13:35:03 +0100608
Bram Moolenaar2b946c92016-11-12 18:14:44 +0100609func Test_locationlist_curwin_was_closed()
Bram Moolenaar0899d692016-03-19 13:35:03 +0100610 augroup testgroup
611 au!
Bram Moolenaard106e5b2016-04-21 19:38:07 +0200612 autocmd BufReadCmd test_curwin.txt call R(expand("<amatch>"))
Bram Moolenaar0899d692016-03-19 13:35:03 +0100613 augroup END
614
Bram Moolenaar2b946c92016-11-12 18:14:44 +0100615 func! R(n)
Bram Moolenaar0899d692016-03-19 13:35:03 +0100616 quit
617 endfunc
618
619 new
620 let q = []
Bram Moolenaard106e5b2016-04-21 19:38:07 +0200621 call add(q, {'filename': 'test_curwin.txt' })
Bram Moolenaar0899d692016-03-19 13:35:03 +0100622 call setloclist(0, q)
623 call assert_fails('lrewind', 'E924:')
624
625 augroup! testgroup
Bram Moolenaar2b946c92016-11-12 18:14:44 +0100626 endfunc
Bram Moolenaar7eba3d22016-03-19 22:54:09 +0100627
Bram Moolenaar2b946c92016-11-12 18:14:44 +0100628func Test_locationlist_cross_tab_jump()
Bram Moolenaar0a9046f2016-10-15 19:28:13 +0200629 call writefile(['loclistfoo'], 'loclistfoo')
630 call writefile(['loclistbar'], 'loclistbar')
631 set switchbuf=usetab
632
633 edit loclistfoo
634 tabedit loclistbar
635 silent lgrep loclistfoo loclist*
636 call assert_equal(1, tabpagenr())
637
638 enew | only | tabonly
639 set switchbuf&vim
640 call delete('loclistfoo')
641 call delete('loclistbar')
Bram Moolenaar2b946c92016-11-12 18:14:44 +0100642endfunc
Bram Moolenaar0a9046f2016-10-15 19:28:13 +0200643
Bram Moolenaar7eba3d22016-03-19 22:54:09 +0100644" More tests for 'errorformat'
Bram Moolenaar2b946c92016-11-12 18:14:44 +0100645func Test_efm1()
Bram Moolenaar7eba3d22016-03-19 22:54:09 +0100646 if !has('unix')
647 " The 'errorformat' setting is different on non-Unix systems.
648 " This test works only on Unix-like systems.
649 return
650 endif
651
652 let l = [
653 \ '"Xtestfile", line 4.12: 1506-045 (S) Undeclared identifier fd_set.',
654 \ '"Xtestfile", line 6 col 19; this is an error',
655 \ 'gcc -c -DHAVE_CONFIsing-prototypes -I/usr/X11R6/include version.c',
656 \ 'Xtestfile:9: parse error before `asd''',
657 \ 'make: *** [vim] Error 1',
658 \ 'in file "Xtestfile" linenr 10: there is an error',
659 \ '',
660 \ '2 returned',
661 \ '"Xtestfile", line 11 col 1; this is an error',
662 \ '"Xtestfile", line 12 col 2; this is another error',
663 \ '"Xtestfile", line 14:10; this is an error in column 10',
664 \ '=Xtestfile=, line 15:10; this is another error, but in vcol 10 this time',
665 \ '"Xtestfile", linenr 16: yet another problem',
666 \ 'Error in "Xtestfile" at line 17:',
667 \ 'x should be a dot',
668 \ ' xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 17',
669 \ ' ^',
670 \ 'Error in "Xtestfile" at line 18:',
671 \ 'x should be a dot',
672 \ ' xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 18',
673 \ '.............^',
674 \ 'Error in "Xtestfile" at line 19:',
675 \ 'x should be a dot',
676 \ ' xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 19',
677 \ '--------------^',
678 \ 'Error in "Xtestfile" at line 20:',
679 \ 'x should be a dot',
680 \ ' xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 20',
681 \ ' ^',
682 \ '',
683 \ 'Does anyone know what is the problem and how to correction it?',
684 \ '"Xtestfile", line 21 col 9: What is the title of the quickfix window?',
685 \ '"Xtestfile", line 22 col 9: What is the title of the quickfix window?'
686 \ ]
687
688 call writefile(l, 'Xerrorfile1')
689 call writefile(l[:-2], 'Xerrorfile2')
690
691 let m = [
692 \ ' xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 2',
693 \ ' xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 3',
694 \ ' xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 4',
695 \ ' xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 5',
696 \ ' xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 6',
697 \ ' xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 7',
698 \ ' xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 8',
699 \ ' xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 9',
700 \ ' xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 10',
701 \ ' xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 11',
702 \ ' xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 12',
703 \ ' xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 13',
704 \ ' xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 14',
705 \ ' xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 15',
706 \ ' xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 16',
707 \ ' xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 17',
708 \ ' xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 18',
709 \ ' xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 19',
710 \ ' xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 20',
711 \ ' xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 21',
712 \ ' xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 22'
713 \ ]
714 call writefile(m, 'Xtestfile')
715
716 let save_efm = &efm
717 set efm+==%f=\\,\ line\ %l%*\\D%v%*[^\ ]\ %m
718 set efm^=%AError\ in\ \"%f\"\ at\ line\ %l:,%Z%p^,%C%m
719
720 exe 'cf Xerrorfile2'
721 clast
722 copen
723 call assert_equal(':cf Xerrorfile2', w:quickfix_title)
724 wincmd p
725
726 exe 'cf Xerrorfile1'
727 call assert_equal([4, 12], [line('.'), col('.')])
728 cn
729 call assert_equal([6, 19], [line('.'), col('.')])
730 cn
731 call assert_equal([9, 2], [line('.'), col('.')])
732 cn
733 call assert_equal([10, 2], [line('.'), col('.')])
734 cn
735 call assert_equal([11, 1], [line('.'), col('.')])
736 cn
737 call assert_equal([12, 2], [line('.'), col('.')])
738 cn
739 call assert_equal([14, 10], [line('.'), col('.')])
740 cn
741 call assert_equal([15, 3, 10], [line('.'), col('.'), virtcol('.')])
742 cn
743 call assert_equal([16, 2], [line('.'), col('.')])
744 cn
745 call assert_equal([17, 6], [line('.'), col('.')])
746 cn
747 call assert_equal([18, 7], [line('.'), col('.')])
748 cn
749 call assert_equal([19, 8], [line('.'), col('.')])
750 cn
751 call assert_equal([20, 9], [line('.'), col('.')])
752 clast
753 cprev
754 cprev
755 wincmd w
756 call assert_equal(':cf Xerrorfile1', w:quickfix_title)
757 wincmd p
758
759 let &efm = save_efm
760 call delete('Xerrorfile1')
761 call delete('Xerrorfile2')
762 call delete('Xtestfile')
Bram Moolenaar2b946c92016-11-12 18:14:44 +0100763 endfunc
Bram Moolenaarffec3c52016-03-23 20:55:42 +0100764
Bram Moolenaarab47c612016-06-14 22:02:26 +0200765" Test for quickfix directory stack support
Bram Moolenaar2b946c92016-11-12 18:14:44 +0100766func s:dir_stack_tests(cchar)
Bram Moolenaar38df43b2016-06-20 21:41:12 +0200767 call s:setup_commands(a:cchar)
768
Bram Moolenaarab47c612016-06-14 22:02:26 +0200769 let save_efm=&efm
770 set efm=%DEntering\ dir\ '%f',%f:%l:%m,%XLeaving\ dir\ '%f'
771
Bram Moolenaar361c8f02016-07-02 15:41:47 +0200772 let lines = ["Entering dir 'dir1/a'",
773 \ 'habits2.txt:1:Nine Healthy Habits',
774 \ "Entering dir 'b'",
775 \ 'habits3.txt:2:0 Hours of television',
776 \ 'habits2.txt:7:5 Small meals',
777 \ "Entering dir 'dir1/c'",
778 \ 'habits4.txt:3:1 Hour of exercise',
779 \ "Leaving dir 'dir1/c'",
780 \ "Leaving dir 'dir1/a'",
781 \ 'habits1.txt:4:2 Liters of water',
782 \ "Entering dir 'dir2'",
783 \ 'habits5.txt:5:3 Cups of hot green tea',
784 \ "Leaving dir 'dir2'"
785 \]
Bram Moolenaarab47c612016-06-14 22:02:26 +0200786
Bram Moolenaar361c8f02016-07-02 15:41:47 +0200787 Xexpr ""
788 for l in lines
789 Xaddexpr l
790 endfor
Bram Moolenaarab47c612016-06-14 22:02:26 +0200791
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +0200792 let qf = g:Xgetlist()
Bram Moolenaarab47c612016-06-14 22:02:26 +0200793
794 call assert_equal('dir1/a/habits2.txt', bufname(qf[1].bufnr))
795 call assert_equal(1, qf[1].lnum)
796 call assert_equal('dir1/a/b/habits3.txt', bufname(qf[3].bufnr))
797 call assert_equal(2, qf[3].lnum)
798 call assert_equal('dir1/a/habits2.txt', bufname(qf[4].bufnr))
799 call assert_equal(7, qf[4].lnum)
800 call assert_equal('dir1/c/habits4.txt', bufname(qf[6].bufnr))
801 call assert_equal(3, qf[6].lnum)
802 call assert_equal('habits1.txt', bufname(qf[9].bufnr))
803 call assert_equal(4, qf[9].lnum)
804 call assert_equal('dir2/habits5.txt', bufname(qf[11].bufnr))
805 call assert_equal(5, qf[11].lnum)
806
807 let &efm=save_efm
Bram Moolenaar2b946c92016-11-12 18:14:44 +0100808endfunc
Bram Moolenaarab47c612016-06-14 22:02:26 +0200809
810" Tests for %D and %X errorformat options
Bram Moolenaar2b946c92016-11-12 18:14:44 +0100811func Test_efm_dirstack()
Bram Moolenaarab47c612016-06-14 22:02:26 +0200812 " Create the directory stack and files
813 call mkdir('dir1')
814 call mkdir('dir1/a')
815 call mkdir('dir1/a/b')
816 call mkdir('dir1/c')
817 call mkdir('dir2')
818
819 let lines = ["Nine Healthy Habits",
820 \ "0 Hours of television",
821 \ "1 Hour of exercise",
822 \ "2 Liters of water",
823 \ "3 Cups of hot green tea",
824 \ "4 Short mental breaks",
825 \ "5 Small meals",
826 \ "6 AM wake up time",
827 \ "7 Minutes of laughter",
828 \ "8 Hours of sleep (at least)",
829 \ "9 PM end of the day and off to bed"
830 \ ]
831 call writefile(lines, 'habits1.txt')
832 call writefile(lines, 'dir1/a/habits2.txt')
833 call writefile(lines, 'dir1/a/b/habits3.txt')
834 call writefile(lines, 'dir1/c/habits4.txt')
835 call writefile(lines, 'dir2/habits5.txt')
836
837 call s:dir_stack_tests('c')
838 call s:dir_stack_tests('l')
839
840 call delete('dir1', 'rf')
841 call delete('dir2', 'rf')
842 call delete('habits1.txt')
Bram Moolenaar2b946c92016-11-12 18:14:44 +0100843endfunc
Bram Moolenaarab47c612016-06-14 22:02:26 +0200844
Bram Moolenaar9b457942016-10-09 16:10:05 +0200845" Test for resync after continuing an ignored message
Bram Moolenaar2b946c92016-11-12 18:14:44 +0100846func Xefm_ignore_continuations(cchar)
Bram Moolenaar9b457942016-10-09 16:10:05 +0200847 call s:setup_commands(a:cchar)
848
849 let save_efm = &efm
850
851 let &efm =
852 \ '%Eerror %m %l,' .
853 \ '%-Wignored %m %l,' .
854 \ '%+Cmore ignored %m %l,' .
855 \ '%Zignored end'
856 Xgetexpr ['ignored warning 1', 'more ignored continuation 2', 'ignored end', 'error resync 4']
857 let l = map(g:Xgetlist(), '[v:val.text, v:val.valid, v:val.lnum, v:val.type]')
858 call assert_equal([['resync', 1, 4, 'E']], l)
859
860 let &efm = save_efm
Bram Moolenaar2b946c92016-11-12 18:14:44 +0100861endfunc
Bram Moolenaar9b457942016-10-09 16:10:05 +0200862
Bram Moolenaar2b946c92016-11-12 18:14:44 +0100863func Test_efm_ignore_continuations()
Bram Moolenaar9b457942016-10-09 16:10:05 +0200864 call Xefm_ignore_continuations('c')
865 call Xefm_ignore_continuations('l')
Bram Moolenaar2b946c92016-11-12 18:14:44 +0100866endfunc
Bram Moolenaar9b457942016-10-09 16:10:05 +0200867
Bram Moolenaar0fcc7c62016-07-02 21:22:52 +0200868" Tests for invalid error format specifies
Bram Moolenaar2b946c92016-11-12 18:14:44 +0100869func Xinvalid_efm_Tests(cchar)
Bram Moolenaar0fcc7c62016-07-02 21:22:52 +0200870 call s:setup_commands(a:cchar)
871
Bram Moolenaar049cba92016-06-26 14:38:04 +0200872 let save_efm = &efm
873
Bram Moolenaar0fcc7c62016-07-02 21:22:52 +0200874 set efm=%f:%l:%m,%f:%f:%l:%m
875 call assert_fails('Xexpr "abc.txt:1:Hello world"', 'E372:')
876
877 set efm=%f:%l:%m,%f:%l:%r:%m
878 call assert_fails('Xexpr "abc.txt:1:Hello world"', 'E373:')
879
880 set efm=%f:%l:%m,%O:%f:%l:%m
881 call assert_fails('Xexpr "abc.txt:1:Hello world"', 'E373:')
882
883 set efm=%f:%l:%m,%f:%l:%*[^a-z
884 call assert_fails('Xexpr "abc.txt:1:Hello world"', 'E374:')
885
886 set efm=%f:%l:%m,%f:%l:%*c
887 call assert_fails('Xexpr "abc.txt:1:Hello world"', 'E375:')
888
889 set efm=%f:%l:%m,%L%M%N
890 call assert_fails('Xexpr "abc.txt:1:Hello world"', 'E376:')
891
892 set efm=%f:%l:%m,%f:%l:%m:%R
893 call assert_fails('Xexpr "abc.txt:1:Hello world"', 'E377:')
894
895 set efm=
896 call assert_fails('Xexpr "abc.txt:1:Hello world"', 'E378:')
897
898 set efm=%DEntering\ dir\ abc,%f:%l:%m
899 call assert_fails('Xexpr ["Entering dir abc", "abc.txt:1:Hello world"]', 'E379:')
900
901 let &efm = save_efm
Bram Moolenaar2b946c92016-11-12 18:14:44 +0100902endfunc
Bram Moolenaar0fcc7c62016-07-02 21:22:52 +0200903
Bram Moolenaar2b946c92016-11-12 18:14:44 +0100904func Test_invalid_efm()
Bram Moolenaar0fcc7c62016-07-02 21:22:52 +0200905 call Xinvalid_efm_Tests('c')
906 call Xinvalid_efm_Tests('l')
Bram Moolenaar2b946c92016-11-12 18:14:44 +0100907endfunc
Bram Moolenaar0fcc7c62016-07-02 21:22:52 +0200908
909" TODO:
910" Add tests for the following formats in 'errorformat'
911" %r %O
Bram Moolenaar2b946c92016-11-12 18:14:44 +0100912func Test_efm2()
Bram Moolenaar0fcc7c62016-07-02 21:22:52 +0200913 let save_efm = &efm
Bram Moolenaar049cba92016-06-26 14:38:04 +0200914
915 " Test for %s format in efm
916 set efm=%f:%s
917 cexpr 'Xtestfile:Line search text'
Bram Moolenaar049cba92016-06-26 14:38:04 +0200918 let l = getqflist()
919 call assert_equal(l[0].pattern, '^\VLine search text\$')
920 call assert_equal(l[0].lnum, 0)
921
Bram Moolenaar0fcc7c62016-07-02 21:22:52 +0200922 " Test for %P, %Q and %t format specifiers
Bram Moolenaar049cba92016-06-26 14:38:04 +0200923 let lines=["[Xtestfile1]",
924 \ "(1,17) error: ';' missing",
925 \ "(21,2) warning: variable 'z' not defined",
926 \ "(67,3) error: end of file found before string ended",
927 \ "",
928 \ "[Xtestfile2]",
929 \ "",
930 \ "[Xtestfile3]",
931 \ "NEW compiler v1.1",
932 \ "(2,2) warning: variable 'x' not defined",
933 \ "(67,3) warning: 's' already defined"
934 \]
935 set efm=%+P[%f],(%l\\,%c)%*[\ ]%t%*[^:]:\ %m,%-Q
Bram Moolenaar391b1dd2017-03-04 13:47:11 +0100936 " To exercise the push/pop file functionality in quickfix, the test files
937 " need to be created.
938 call writefile(['Line1'], 'Xtestfile1')
939 call writefile(['Line2'], 'Xtestfile2')
940 call writefile(['Line3'], 'Xtestfile3')
Bram Moolenaar361c8f02016-07-02 15:41:47 +0200941 cexpr ""
942 for l in lines
943 caddexpr l
944 endfor
Bram Moolenaar049cba92016-06-26 14:38:04 +0200945 let l = getqflist()
946 call assert_equal(9, len(l))
947 call assert_equal(21, l[2].lnum)
948 call assert_equal(2, l[2].col)
Bram Moolenaar0fcc7c62016-07-02 21:22:52 +0200949 call assert_equal('w', l[2].type)
950 call assert_equal('e', l[3].type)
Bram Moolenaar391b1dd2017-03-04 13:47:11 +0100951 call delete('Xtestfile1')
952 call delete('Xtestfile2')
953 call delete('Xtestfile3')
Bram Moolenaar0fcc7c62016-07-02 21:22:52 +0200954
955 " Tests for %E, %C and %Z format specifiers
956 let lines = ["Error 275",
957 \ "line 42",
958 \ "column 3",
959 \ "' ' expected after '--'"
960 \]
961 set efm=%EError\ %n,%Cline\ %l,%Ccolumn\ %c,%Z%m
962 cgetexpr lines
963 let l = getqflist()
964 call assert_equal(275, l[0].nr)
965 call assert_equal(42, l[0].lnum)
966 call assert_equal(3, l[0].col)
967 call assert_equal('E', l[0].type)
968 call assert_equal("\n' ' expected after '--'", l[0].text)
969
970 " Test for %>
971 let lines = ["Error in line 147 of foo.c:",
972 \"unknown variable 'i'"
973 \]
974 set efm=unknown\ variable\ %m,%E%>Error\ in\ line\ %l\ of\ %f:,%Z%m
975 cgetexpr lines
976 let l = getqflist()
977 call assert_equal(147, l[0].lnum)
978 call assert_equal('E', l[0].type)
979 call assert_equal("\nunknown variable 'i'", l[0].text)
Bram Moolenaar049cba92016-06-26 14:38:04 +0200980
Bram Moolenaare87e6dd2016-07-17 19:25:04 +0200981 " Test for %A, %C and other formats
982 let lines = [
983 \"==============================================================",
984 \"FAIL: testGetTypeIdCachesResult (dbfacadeTest.DjsDBFacadeTest)",
985 \"--------------------------------------------------------------",
986 \"Traceback (most recent call last):",
987 \' File "unittests/dbfacadeTest.py", line 89, in testFoo',
988 \" self.assertEquals(34, dtid)",
989 \' File "/usr/lib/python2.2/unittest.py", line 286, in',
990 \" failUnlessEqual",
991 \" raise self.failureException, \\",
992 \"AssertionError: 34 != 33",
993 \"",
994 \"--------------------------------------------------------------",
995 \"Ran 27 tests in 0.063s"
996 \]
997 set efm=%C\ %.%#,%A\ \ File\ \"%f\"\\,\ line\ %l%.%#,%Z%[%^\ ]%\\@=%m
998 cgetexpr lines
999 let l = getqflist()
1000 call assert_equal(8, len(l))
1001 call assert_equal(89, l[4].lnum)
1002 call assert_equal(1, l[4].valid)
1003 call assert_equal('unittests/dbfacadeTest.py', bufname(l[4].bufnr))
1004
Bram Moolenaar049cba92016-06-26 14:38:04 +02001005 let &efm = save_efm
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001006endfunc
Bram Moolenaar049cba92016-06-26 14:38:04 +02001007
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001008func XquickfixChangedByAutocmd(cchar)
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001009 call s:setup_commands(a:cchar)
Bram Moolenaarffec3c52016-03-23 20:55:42 +01001010 if a:cchar == 'c'
Bram Moolenaarffec3c52016-03-23 20:55:42 +01001011 let ErrorNr = 'E925'
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001012 func! ReadFunc()
Bram Moolenaarffec3c52016-03-23 20:55:42 +01001013 colder
1014 cgetexpr []
1015 endfunc
1016 else
Bram Moolenaarffec3c52016-03-23 20:55:42 +01001017 let ErrorNr = 'E926'
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001018 func! ReadFunc()
Bram Moolenaarffec3c52016-03-23 20:55:42 +01001019 lolder
1020 lgetexpr []
1021 endfunc
1022 endif
1023
1024 augroup testgroup
1025 au!
Bram Moolenaard106e5b2016-04-21 19:38:07 +02001026 autocmd BufReadCmd test_changed.txt call ReadFunc()
Bram Moolenaarffec3c52016-03-23 20:55:42 +01001027 augroup END
1028
Bram Moolenaard106e5b2016-04-21 19:38:07 +02001029 new | only
Bram Moolenaarffec3c52016-03-23 20:55:42 +01001030 let words = [ "a", "b" ]
1031 let qflist = []
1032 for word in words
Bram Moolenaard106e5b2016-04-21 19:38:07 +02001033 call add(qflist, {'filename': 'test_changed.txt'})
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001034 call g:Xsetlist(qflist, ' ')
Bram Moolenaarffec3c52016-03-23 20:55:42 +01001035 endfor
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001036 call assert_fails('Xrewind', ErrorNr . ':')
Bram Moolenaarffec3c52016-03-23 20:55:42 +01001037
1038 augroup! testgroup
1039endfunc
1040
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001041func Test_quickfix_was_changed_by_autocmd()
Bram Moolenaarffec3c52016-03-23 20:55:42 +01001042 call XquickfixChangedByAutocmd('c')
1043 call XquickfixChangedByAutocmd('l')
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001044endfunc
Bram Moolenaar8b201792016-03-25 15:01:10 +01001045
1046func Test_caddbuffer_to_empty()
1047 helpgr quickfix
1048 call setqflist([], 'r')
1049 cad
Bram Moolenaarf68f1d72016-03-25 17:14:06 +01001050 try
1051 cn
1052 catch
1053 " number of matches is unknown
1054 call assert_true(v:exception =~ 'E553:')
1055 endtry
Bram Moolenaar8b201792016-03-25 15:01:10 +01001056 quit!
1057endfunc
Bram Moolenaar89c64d52016-03-27 18:44:40 +02001058
1059func Test_cgetexpr_works()
1060 " this must not crash Vim
1061 cgetexpr [$x]
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001062 lgetexpr [$x]
Bram Moolenaar89c64d52016-03-27 18:44:40 +02001063endfunc
Bram Moolenaarc1808d52016-04-18 20:04:00 +02001064
1065" Tests for the setqflist() and setloclist() functions
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001066func SetXlistTests(cchar, bnum)
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001067 call s:setup_commands(a:cchar)
Bram Moolenaarc1808d52016-04-18 20:04:00 +02001068
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001069 call g:Xsetlist([{'bufnr': a:bnum, 'lnum': 1},
Bram Moolenaarc1808d52016-04-18 20:04:00 +02001070 \ {'bufnr': a:bnum, 'lnum': 2}])
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001071 let l = g:Xgetlist()
Bram Moolenaarc1808d52016-04-18 20:04:00 +02001072 call assert_equal(2, len(l))
1073 call assert_equal(2, l[1].lnum)
1074
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001075 Xnext
1076 call g:Xsetlist([{'bufnr': a:bnum, 'lnum': 3}], 'a')
1077 let l = g:Xgetlist()
Bram Moolenaarc1808d52016-04-18 20:04:00 +02001078 call assert_equal(3, len(l))
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001079 Xnext
Bram Moolenaarc1808d52016-04-18 20:04:00 +02001080 call assert_equal(3, line('.'))
1081
Bram Moolenaar2b2b8ae2016-05-24 19:59:51 +02001082 " Appending entries to the list should not change the cursor position
1083 " in the quickfix window
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001084 Xwindow
Bram Moolenaar2b2b8ae2016-05-24 19:59:51 +02001085 1
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001086 call g:Xsetlist([{'bufnr': a:bnum, 'lnum': 4},
Bram Moolenaar2b2b8ae2016-05-24 19:59:51 +02001087 \ {'bufnr': a:bnum, 'lnum': 5}], 'a')
1088 call assert_equal(1, line('.'))
1089 close
1090
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001091 call g:Xsetlist([{'bufnr': a:bnum, 'lnum': 3},
Bram Moolenaarc1808d52016-04-18 20:04:00 +02001092 \ {'bufnr': a:bnum, 'lnum': 4},
1093 \ {'bufnr': a:bnum, 'lnum': 5}], 'r')
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001094 let l = g:Xgetlist()
Bram Moolenaarc1808d52016-04-18 20:04:00 +02001095 call assert_equal(3, len(l))
1096 call assert_equal(5, l[2].lnum)
1097
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001098 call g:Xsetlist([])
1099 let l = g:Xgetlist()
Bram Moolenaarc1808d52016-04-18 20:04:00 +02001100 call assert_equal(0, len(l))
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001101endfunc
Bram Moolenaarc1808d52016-04-18 20:04:00 +02001102
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001103func Test_setqflist()
Bram Moolenaarc1808d52016-04-18 20:04:00 +02001104 new Xtestfile | only
1105 let bnum = bufnr('%')
1106 call setline(1, range(1,5))
1107
1108 call SetXlistTests('c', bnum)
1109 call SetXlistTests('l', bnum)
1110
Bram Moolenaar1cee6932016-06-09 22:17:22 +02001111 enew!
Bram Moolenaarc1808d52016-04-18 20:04:00 +02001112 call delete('Xtestfile')
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001113endfunc
Bram Moolenaard106e5b2016-04-21 19:38:07 +02001114
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001115func Xlist_empty_middle(cchar)
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001116 call s:setup_commands(a:cchar)
1117
Bram Moolenaar1cee6932016-06-09 22:17:22 +02001118 " create three quickfix lists
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001119 Xvimgrep Test_ test_quickfix.vim
1120 let testlen = len(g:Xgetlist())
Bram Moolenaar1cee6932016-06-09 22:17:22 +02001121 call assert_true(testlen > 0)
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001122 Xvimgrep empty test_quickfix.vim
1123 call assert_true(len(g:Xgetlist()) > 0)
1124 Xvimgrep matches test_quickfix.vim
1125 let matchlen = len(g:Xgetlist())
Bram Moolenaar1cee6932016-06-09 22:17:22 +02001126 call assert_true(matchlen > 0)
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001127 Xolder
Bram Moolenaar1cee6932016-06-09 22:17:22 +02001128 " make the middle list empty
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001129 call g:Xsetlist([], 'r')
1130 call assert_true(len(g:Xgetlist()) == 0)
1131 Xolder
1132 call assert_equal(testlen, len(g:Xgetlist()))
1133 Xnewer
1134 Xnewer
1135 call assert_equal(matchlen, len(g:Xgetlist()))
Bram Moolenaar1cee6932016-06-09 22:17:22 +02001136endfunc
1137
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001138func Test_setqflist_empty_middle()
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001139 call Xlist_empty_middle('c')
1140 call Xlist_empty_middle('l')
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001141endfunc
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001142
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001143func Xlist_empty_older(cchar)
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001144 call s:setup_commands(a:cchar)
1145
Bram Moolenaar1cee6932016-06-09 22:17:22 +02001146 " create three quickfix lists
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001147 Xvimgrep one test_quickfix.vim
1148 let onelen = len(g:Xgetlist())
Bram Moolenaar1cee6932016-06-09 22:17:22 +02001149 call assert_true(onelen > 0)
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001150 Xvimgrep two test_quickfix.vim
1151 let twolen = len(g:Xgetlist())
Bram Moolenaar1cee6932016-06-09 22:17:22 +02001152 call assert_true(twolen > 0)
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001153 Xvimgrep three test_quickfix.vim
1154 let threelen = len(g:Xgetlist())
Bram Moolenaar1cee6932016-06-09 22:17:22 +02001155 call assert_true(threelen > 0)
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001156 Xolder 2
Bram Moolenaar1cee6932016-06-09 22:17:22 +02001157 " make the first list empty, check the others didn't change
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001158 call g:Xsetlist([], 'r')
1159 call assert_true(len(g:Xgetlist()) == 0)
1160 Xnewer
1161 call assert_equal(twolen, len(g:Xgetlist()))
1162 Xnewer
1163 call assert_equal(threelen, len(g:Xgetlist()))
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001164endfunc
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001165
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001166func Test_setqflist_empty_older()
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001167 call Xlist_empty_older('c')
1168 call Xlist_empty_older('l')
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001169endfunc
Bram Moolenaar1cee6932016-06-09 22:17:22 +02001170
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001171func XquickfixSetListWithAct(cchar)
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001172 call s:setup_commands(a:cchar)
1173
Bram Moolenaard106e5b2016-04-21 19:38:07 +02001174 let list1 = [{'filename': 'fnameA', 'text': 'A'},
1175 \ {'filename': 'fnameB', 'text': 'B'}]
1176 let list2 = [{'filename': 'fnameC', 'text': 'C'},
1177 \ {'filename': 'fnameD', 'text': 'D'},
1178 \ {'filename': 'fnameE', 'text': 'E'}]
1179
1180 " {action} is unspecified. Same as specifing ' '.
1181 new | only
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001182 silent! Xnewer 99
1183 call g:Xsetlist(list1)
1184 call g:Xsetlist(list2)
1185 let li = g:Xgetlist()
Bram Moolenaard106e5b2016-04-21 19:38:07 +02001186 call assert_equal(3, len(li))
1187 call assert_equal('C', li[0]['text'])
1188 call assert_equal('D', li[1]['text'])
1189 call assert_equal('E', li[2]['text'])
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001190 silent! Xolder
1191 let li = g:Xgetlist()
Bram Moolenaard106e5b2016-04-21 19:38:07 +02001192 call assert_equal(2, len(li))
1193 call assert_equal('A', li[0]['text'])
1194 call assert_equal('B', li[1]['text'])
1195
1196 " {action} is specified ' '.
1197 new | only
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001198 silent! Xnewer 99
1199 call g:Xsetlist(list1)
1200 call g:Xsetlist(list2, ' ')
1201 let li = g:Xgetlist()
Bram Moolenaard106e5b2016-04-21 19:38:07 +02001202 call assert_equal(3, len(li))
1203 call assert_equal('C', li[0]['text'])
1204 call assert_equal('D', li[1]['text'])
1205 call assert_equal('E', li[2]['text'])
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001206 silent! Xolder
1207 let li = g:Xgetlist()
Bram Moolenaard106e5b2016-04-21 19:38:07 +02001208 call assert_equal(2, len(li))
1209 call assert_equal('A', li[0]['text'])
1210 call assert_equal('B', li[1]['text'])
1211
1212 " {action} is specified 'a'.
1213 new | only
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001214 silent! Xnewer 99
1215 call g:Xsetlist(list1)
1216 call g:Xsetlist(list2, 'a')
1217 let li = g:Xgetlist()
Bram Moolenaard106e5b2016-04-21 19:38:07 +02001218 call assert_equal(5, len(li))
1219 call assert_equal('A', li[0]['text'])
1220 call assert_equal('B', li[1]['text'])
1221 call assert_equal('C', li[2]['text'])
1222 call assert_equal('D', li[3]['text'])
1223 call assert_equal('E', li[4]['text'])
1224
1225 " {action} is specified 'r'.
1226 new | only
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001227 silent! Xnewer 99
1228 call g:Xsetlist(list1)
1229 call g:Xsetlist(list2, 'r')
1230 let li = g:Xgetlist()
Bram Moolenaard106e5b2016-04-21 19:38:07 +02001231 call assert_equal(3, len(li))
1232 call assert_equal('C', li[0]['text'])
1233 call assert_equal('D', li[1]['text'])
1234 call assert_equal('E', li[2]['text'])
1235
1236 " Test for wrong value.
1237 new | only
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001238 call assert_fails("call g:Xsetlist(0)", 'E714:')
1239 call assert_fails("call g:Xsetlist(list1, '')", 'E927:')
1240 call assert_fails("call g:Xsetlist(list1, 'aa')", 'E927:')
1241 call assert_fails("call g:Xsetlist(list1, ' a')", 'E927:')
1242 call assert_fails("call g:Xsetlist(list1, 0)", 'E928:')
Bram Moolenaard106e5b2016-04-21 19:38:07 +02001243endfunc
1244
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001245func Test_quickfix_set_list_with_act()
Bram Moolenaard106e5b2016-04-21 19:38:07 +02001246 call XquickfixSetListWithAct('c')
1247 call XquickfixSetListWithAct('l')
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001248endfunc
Bram Moolenaar6be8c8e2016-04-30 13:17:09 +02001249
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001250func XLongLinesTests(cchar)
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001251 let l = g:Xgetlist()
Bram Moolenaar6be8c8e2016-04-30 13:17:09 +02001252
Bram Moolenaar049cba92016-06-26 14:38:04 +02001253 call assert_equal(4, len(l))
Bram Moolenaar6be8c8e2016-04-30 13:17:09 +02001254 call assert_equal(1, l[0].lnum)
1255 call assert_equal(1, l[0].col)
Bram Moolenaar049cba92016-06-26 14:38:04 +02001256 call assert_equal(1975, len(l[0].text))
Bram Moolenaar6be8c8e2016-04-30 13:17:09 +02001257 call assert_equal(2, l[1].lnum)
1258 call assert_equal(1, l[1].col)
1259 call assert_equal(4070, len(l[1].text))
1260 call assert_equal(3, l[2].lnum)
1261 call assert_equal(1, l[2].col)
Bram Moolenaar049cba92016-06-26 14:38:04 +02001262 call assert_equal(4070, len(l[2].text))
1263 call assert_equal(4, l[3].lnum)
1264 call assert_equal(1, l[3].col)
1265 call assert_equal(10, len(l[3].text))
Bram Moolenaar6be8c8e2016-04-30 13:17:09 +02001266
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001267 call g:Xsetlist([], 'r')
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001268endfunc
Bram Moolenaar6be8c8e2016-04-30 13:17:09 +02001269
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001270func s:long_lines_tests(cchar)
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001271 call s:setup_commands(a:cchar)
1272
Bram Moolenaar6be8c8e2016-04-30 13:17:09 +02001273 let testfile = 'samples/quickfix.txt'
1274
1275 " file
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001276 exe 'Xgetfile' testfile
1277 call XLongLinesTests(a:cchar)
Bram Moolenaar6be8c8e2016-04-30 13:17:09 +02001278
1279 " list
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001280 Xexpr readfile(testfile)
1281 call XLongLinesTests(a:cchar)
Bram Moolenaar6be8c8e2016-04-30 13:17:09 +02001282
1283 " string
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001284 Xexpr join(readfile(testfile), "\n")
1285 call XLongLinesTests(a:cchar)
Bram Moolenaar6be8c8e2016-04-30 13:17:09 +02001286
1287 " buffer
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001288 exe 'edit' testfile
1289 exe 'Xbuffer' bufnr('%')
Bram Moolenaarf50df392016-06-21 21:33:34 +02001290 call XLongLinesTests(a:cchar)
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001291endfunc
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001292
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001293func Test_long_lines()
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001294 call s:long_lines_tests('c')
1295 call s:long_lines_tests('l')
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001296endfunc
Bram Moolenaar049cba92016-06-26 14:38:04 +02001297
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001298func s:create_test_file(filename)
Bram Moolenaar049cba92016-06-26 14:38:04 +02001299 let l = []
1300 for i in range(1, 20)
1301 call add(l, 'Line' . i)
1302 endfor
1303 call writefile(l, a:filename)
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001304endfunc
Bram Moolenaar049cba92016-06-26 14:38:04 +02001305
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001306func Test_switchbuf()
Bram Moolenaar049cba92016-06-26 14:38:04 +02001307 call s:create_test_file('Xqftestfile1')
1308 call s:create_test_file('Xqftestfile2')
1309 call s:create_test_file('Xqftestfile3')
1310
1311 new | only
1312 edit Xqftestfile1
1313 let file1_winid = win_getid()
1314 new Xqftestfile2
1315 let file2_winid = win_getid()
1316 cgetexpr ['Xqftestfile1:5:Line5',
1317 \ 'Xqftestfile1:6:Line6',
1318 \ 'Xqftestfile2:10:Line10',
1319 \ 'Xqftestfile2:11:Line11',
1320 \ 'Xqftestfile3:15:Line15',
1321 \ 'Xqftestfile3:16:Line16']
1322
1323 new
1324 let winid = win_getid()
1325 cfirst | cnext
1326 call assert_equal(winid, win_getid())
1327 cnext | cnext
1328 call assert_equal(winid, win_getid())
1329 cnext | cnext
1330 call assert_equal(winid, win_getid())
1331 enew
1332
1333 set switchbuf=useopen
1334 cfirst | cnext
1335 call assert_equal(file1_winid, win_getid())
1336 cnext | cnext
1337 call assert_equal(file2_winid, win_getid())
1338 cnext | cnext
1339 call assert_equal(file2_winid, win_getid())
1340
1341 enew | only
1342 set switchbuf=usetab
1343 tabedit Xqftestfile1
1344 tabedit Xqftestfile2
1345 tabfirst
1346 cfirst | cnext
1347 call assert_equal(2, tabpagenr())
1348 cnext | cnext
1349 call assert_equal(3, tabpagenr())
1350 cnext | cnext
1351 call assert_equal(3, tabpagenr())
1352 tabfirst | tabonly | enew
1353
1354 set switchbuf=split
1355 cfirst | cnext
1356 call assert_equal(1, winnr('$'))
1357 cnext | cnext
1358 call assert_equal(2, winnr('$'))
1359 cnext | cnext
1360 call assert_equal(3, winnr('$'))
1361 enew | only
1362
1363 set switchbuf=newtab
1364 cfirst | cnext
1365 call assert_equal(1, tabpagenr('$'))
1366 cnext | cnext
1367 call assert_equal(2, tabpagenr('$'))
1368 cnext | cnext
1369 call assert_equal(3, tabpagenr('$'))
1370 tabfirst | enew | tabonly | only
1371
1372 set switchbuf=
1373 edit Xqftestfile1
1374 let file1_winid = win_getid()
1375 new Xqftestfile2
1376 let file2_winid = win_getid()
1377 copen
1378 exe "normal 1G\<CR>"
1379 call assert_equal(file1_winid, win_getid())
1380 copen
1381 exe "normal 3G\<CR>"
1382 call assert_equal(file2_winid, win_getid())
1383 copen | only
1384 exe "normal 5G\<CR>"
1385 call assert_equal(2, winnr('$'))
1386 call assert_equal(1, bufwinnr('Xqftestfile3'))
1387
Bram Moolenaar391b1dd2017-03-04 13:47:11 +01001388 " If only quickfix window is open in the current tabpage, jumping to an
1389 " entry with 'switchubf' set to 'usetab' should search in other tabpages.
Bram Moolenaar049cba92016-06-26 14:38:04 +02001390 enew | only
Bram Moolenaar391b1dd2017-03-04 13:47:11 +01001391 set switchbuf=usetab
1392 tabedit Xqftestfile1
1393 tabedit Xqftestfile2
1394 tabedit Xqftestfile3
1395 tabfirst
1396 copen | only
1397 clast
1398 call assert_equal(4, tabpagenr())
1399 tabfirst | tabonly | enew | only
Bram Moolenaar049cba92016-06-26 14:38:04 +02001400
1401 call delete('Xqftestfile1')
1402 call delete('Xqftestfile2')
1403 call delete('Xqftestfile3')
Bram Moolenaar391b1dd2017-03-04 13:47:11 +01001404 set switchbuf&vim
1405
1406 enew | only
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001407endfunc
Bram Moolenaar049cba92016-06-26 14:38:04 +02001408
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001409func Xadjust_qflnum(cchar)
Bram Moolenaar049cba92016-06-26 14:38:04 +02001410 call s:setup_commands(a:cchar)
1411
1412 enew | only
1413
Bram Moolenaarc1542742016-07-20 21:44:37 +02001414 let fname = 'Xqftestfile' . a:cchar
1415 call s:create_test_file(fname)
1416 exe 'edit ' . fname
Bram Moolenaar049cba92016-06-26 14:38:04 +02001417
Bram Moolenaarc1542742016-07-20 21:44:37 +02001418 Xgetexpr [fname . ':5:Line5',
1419 \ fname . ':10:Line10',
1420 \ fname . ':15:Line15',
1421 \ fname . ':20:Line20']
Bram Moolenaar049cba92016-06-26 14:38:04 +02001422
1423 6,14delete
1424 call append(6, ['Buffer', 'Window'])
1425
1426 let l = g:Xgetlist()
1427
1428 call assert_equal(5, l[0].lnum)
1429 call assert_equal(6, l[2].lnum)
1430 call assert_equal(13, l[3].lnum)
1431
1432 enew!
Bram Moolenaarc1542742016-07-20 21:44:37 +02001433 call delete(fname)
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001434endfunc
Bram Moolenaar049cba92016-06-26 14:38:04 +02001435
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001436func Test_adjust_lnum()
Bram Moolenaarc1542742016-07-20 21:44:37 +02001437 call setloclist(0, [])
Bram Moolenaar049cba92016-06-26 14:38:04 +02001438 call Xadjust_qflnum('c')
Bram Moolenaarc1542742016-07-20 21:44:37 +02001439 call setqflist([])
Bram Moolenaar049cba92016-06-26 14:38:04 +02001440 call Xadjust_qflnum('l')
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001441endfunc
Bram Moolenaar049cba92016-06-26 14:38:04 +02001442
1443" Tests for the :grep/:lgrep and :grepadd/:lgrepadd commands
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001444func s:test_xgrep(cchar)
Bram Moolenaar049cba92016-06-26 14:38:04 +02001445 call s:setup_commands(a:cchar)
1446
1447 " The following lines are used for the grep test. Don't remove.
1448 " Grep_Test_Text: Match 1
1449 " Grep_Test_Text: Match 2
1450 " GrepAdd_Test_Text: Match 1
1451 " GrepAdd_Test_Text: Match 2
1452 enew! | only
1453 set makeef&vim
1454 silent Xgrep Grep_Test_Text: test_quickfix.vim
1455 call assert_true(len(g:Xgetlist()) == 3)
1456 Xopen
1457 call assert_true(w:quickfix_title =~ '^:grep')
1458 Xclose
1459 enew
1460 set makeef=Temp_File_##
1461 silent Xgrepadd GrepAdd_Test_Text: test_quickfix.vim
1462 call assert_true(len(g:Xgetlist()) == 6)
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001463endfunc
Bram Moolenaar049cba92016-06-26 14:38:04 +02001464
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001465func Test_grep()
Bram Moolenaar049cba92016-06-26 14:38:04 +02001466 if !has('unix')
1467 " The grepprg may not be set on non-Unix systems
1468 return
1469 endif
1470
1471 call s:test_xgrep('c')
1472 call s:test_xgrep('l')
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001473endfunc
Bram Moolenaar361c8f02016-07-02 15:41:47 +02001474
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001475func Test_two_windows()
Bram Moolenaar361c8f02016-07-02 15:41:47 +02001476 " Use one 'errorformat' for two windows. Add an expression to each of them,
1477 " make sure they each keep their own state.
1478 set efm=%DEntering\ dir\ '%f',%f:%l:%m,%XLeaving\ dir\ '%f'
1479 call mkdir('Xone/a', 'p')
1480 call mkdir('Xtwo/a', 'p')
1481 let lines = ['1', '2', 'one one one', '4', 'two two two', '6', '7']
1482 call writefile(lines, 'Xone/a/one.txt')
1483 call writefile(lines, 'Xtwo/a/two.txt')
1484
1485 new one
1486 let one_id = win_getid()
1487 lexpr ""
1488 new two
1489 let two_id = win_getid()
1490 lexpr ""
1491
1492 laddexpr "Entering dir 'Xtwo/a'"
1493 call win_gotoid(one_id)
1494 laddexpr "Entering dir 'Xone/a'"
1495 call win_gotoid(two_id)
1496 laddexpr 'two.txt:5:two two two'
1497 call win_gotoid(one_id)
1498 laddexpr 'one.txt:3:one one one'
1499
1500 let loc_one = getloclist(one_id)
Bram Moolenaar361c8f02016-07-02 15:41:47 +02001501 call assert_equal('Xone/a/one.txt', bufname(loc_one[1].bufnr))
1502 call assert_equal(3, loc_one[1].lnum)
1503
1504 let loc_two = getloclist(two_id)
Bram Moolenaar361c8f02016-07-02 15:41:47 +02001505 call assert_equal('Xtwo/a/two.txt', bufname(loc_two[1].bufnr))
1506 call assert_equal(5, loc_two[1].lnum)
1507
1508 call win_gotoid(one_id)
1509 bwipe!
1510 call win_gotoid(two_id)
1511 bwipe!
1512 call delete('Xone', 'rf')
1513 call delete('Xtwo', 'rf')
1514endfunc
Bram Moolenaardcb17002016-07-07 18:58:59 +02001515
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001516func XbottomTests(cchar)
Bram Moolenaar537ef082016-07-09 17:56:19 +02001517 call s:setup_commands(a:cchar)
1518
1519 call g:Xsetlist([{'filename': 'foo', 'lnum': 42}])
1520 Xopen
Bram Moolenaardcb17002016-07-07 18:58:59 +02001521 let wid = win_getid()
1522 call assert_equal(1, line('.'))
1523 wincmd w
Bram Moolenaar537ef082016-07-09 17:56:19 +02001524 call g:Xsetlist([{'filename': 'var', 'lnum': 24}], 'a')
1525 Xbottom
Bram Moolenaardcb17002016-07-07 18:58:59 +02001526 call win_gotoid(wid)
1527 call assert_equal(2, line('.'))
Bram Moolenaar537ef082016-07-09 17:56:19 +02001528 Xclose
Bram Moolenaardcb17002016-07-07 18:58:59 +02001529endfunc
Bram Moolenaar537ef082016-07-09 17:56:19 +02001530
1531" Tests for the :cbottom and :lbottom commands
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001532func Test_cbottom()
Bram Moolenaar537ef082016-07-09 17:56:19 +02001533 call XbottomTests('c')
1534 call XbottomTests('l')
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001535endfunc
Bram Moolenaarf6acffb2016-07-16 16:54:24 +02001536
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001537func HistoryTest(cchar)
Bram Moolenaarf6acffb2016-07-16 16:54:24 +02001538 call s:setup_commands(a:cchar)
1539
1540 call assert_fails(a:cchar . 'older 99', 'E380:')
1541 " clear all lists after the first one, then replace the first one.
1542 call g:Xsetlist([])
1543 Xolder
1544 let entry = {'filename': 'foo', 'lnum': 42}
1545 call g:Xsetlist([entry], 'r')
1546 call g:Xsetlist([entry, entry])
1547 call g:Xsetlist([entry, entry, entry])
1548 let res = split(execute(a:cchar . 'hist'), "\n")
1549 call assert_equal(3, len(res))
1550 let common = 'errors :set' . (a:cchar == 'c' ? 'qf' : 'loc') . 'list()'
1551 call assert_equal(' error list 1 of 3; 1 ' . common, res[0])
1552 call assert_equal(' error list 2 of 3; 2 ' . common, res[1])
1553 call assert_equal('> error list 3 of 3; 3 ' . common, res[2])
1554endfunc
1555
1556func Test_history()
1557 call HistoryTest('c')
1558 call HistoryTest('l')
1559endfunc
Bram Moolenaar015102e2016-07-16 18:24:56 +02001560
1561func Test_duplicate_buf()
1562 " make sure we can get the highest buffer number
1563 edit DoesNotExist
1564 edit DoesNotExist2
1565 let last_buffer = bufnr("$")
1566
1567 " make sure only one buffer is created
1568 call writefile(['this one', 'that one'], 'Xgrepthis')
1569 vimgrep one Xgrepthis
1570 vimgrep one Xgrepthis
1571 call assert_equal(last_buffer + 1, bufnr("$"))
1572
1573 call delete('Xgrepthis')
1574endfunc
Bram Moolenaard823fa92016-08-12 16:29:27 +02001575
1576" Quickfix/Location list set/get properties tests
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001577func Xproperty_tests(cchar)
Bram Moolenaard823fa92016-08-12 16:29:27 +02001578 call s:setup_commands(a:cchar)
1579
1580 " Error cases
1581 call assert_fails('call g:Xgetlist(99)', 'E715:')
1582 call assert_fails('call g:Xsetlist(99)', 'E714:')
1583 call assert_fails('call g:Xsetlist([], "a", [])', 'E715:')
1584
1585 " Set and get the title
1586 Xopen
1587 wincmd p
1588 call g:Xsetlist([{'filename':'foo', 'lnum':27}])
1589 call g:Xsetlist([], 'a', {'title' : 'Sample'})
1590 let d = g:Xgetlist({"title":1})
1591 call assert_equal('Sample', d.title)
1592
1593 Xopen
1594 call assert_equal('Sample', w:quickfix_title)
1595 Xclose
1596
Bram Moolenaar2b529bb2016-08-27 13:35:35 +02001597 " Tests for action argument
1598 silent! Xolder 999
1599 let qfnr = g:Xgetlist({'all':1}).nr
1600 call g:Xsetlist([], 'r', {'title' : 'N1'})
1601 call assert_equal('N1', g:Xgetlist({'all':1}).title)
1602 call g:Xsetlist([], ' ', {'title' : 'N2'})
1603 call assert_equal(qfnr + 1, g:Xgetlist({'all':1}).nr)
Bram Moolenaar890680c2016-09-27 21:28:56 +02001604
1605 let res = g:Xgetlist({'nr': 0})
1606 call assert_equal(qfnr + 1, res.nr)
1607 call assert_equal(['nr'], keys(res))
1608
Bram Moolenaar2b529bb2016-08-27 13:35:35 +02001609 call g:Xsetlist([], ' ', {'title' : 'N3'})
1610 call assert_equal('N2', g:Xgetlist({'nr':2, 'title':1}).title)
1611
Bram Moolenaard823fa92016-08-12 16:29:27 +02001612 " Invalid arguments
1613 call assert_fails('call g:Xgetlist([])', 'E715')
1614 call assert_fails('call g:Xsetlist([], "a", [])', 'E715')
1615 let s = g:Xsetlist([], 'a', {'abc':1})
1616 call assert_equal(-1, s)
1617
1618 call assert_equal({}, g:Xgetlist({'abc':1}))
1619
1620 if a:cchar == 'l'
Bram Moolenaar890680c2016-09-27 21:28:56 +02001621 call assert_equal({}, getloclist(99, {'title': 1}))
Bram Moolenaard823fa92016-08-12 16:29:27 +02001622 endif
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001623 endfunc
Bram Moolenaard823fa92016-08-12 16:29:27 +02001624
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001625func Test_qf_property()
Bram Moolenaard823fa92016-08-12 16:29:27 +02001626 call Xproperty_tests('c')
1627 call Xproperty_tests('l')
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001628 endfunc
Bram Moolenaar04c4ce62016-09-01 15:45:58 +02001629
1630" Tests for the QuickFixCmdPre/QuickFixCmdPost autocommands
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001631func QfAutoCmdHandler(loc, cmd)
Bram Moolenaar04c4ce62016-09-01 15:45:58 +02001632 call add(g:acmds, a:loc . a:cmd)
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001633endfunc
Bram Moolenaar04c4ce62016-09-01 15:45:58 +02001634
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001635func Test_Autocmd()
Bram Moolenaar04c4ce62016-09-01 15:45:58 +02001636 autocmd QuickFixCmdPre * call QfAutoCmdHandler('pre', expand('<amatch>'))
1637 autocmd QuickFixCmdPost * call QfAutoCmdHandler('post', expand('<amatch>'))
1638
1639 let g:acmds = []
1640 cexpr "F1:10:Line 10"
1641 caddexpr "F1:20:Line 20"
1642 cgetexpr "F1:30:Line 30"
1643 enew! | call append(0, "F2:10:Line 10")
1644 cbuffer!
1645 enew! | call append(0, "F2:20:Line 20")
1646 cgetbuffer
1647 enew! | call append(0, "F2:30:Line 30")
1648 caddbuffer
1649
1650 let l = ['precexpr',
1651 \ 'postcexpr',
1652 \ 'precaddexpr',
1653 \ 'postcaddexpr',
1654 \ 'precgetexpr',
1655 \ 'postcgetexpr',
1656 \ 'precbuffer',
1657 \ 'postcbuffer',
1658 \ 'precgetbuffer',
1659 \ 'postcgetbuffer',
1660 \ 'precaddbuffer',
1661 \ 'postcaddbuffer']
1662 call assert_equal(l, g:acmds)
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001663endfunc
Bram Moolenaar21662be2016-11-06 14:46:44 +01001664
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001665func Test_Autocmd_Exception()
Bram Moolenaar21662be2016-11-06 14:46:44 +01001666 set efm=%m
1667 lgetexpr '?'
1668
1669 try
1670 call DoesNotExit()
1671 catch
1672 lgetexpr '1'
1673 finally
1674 lgetexpr '1'
1675 endtry
1676
1677 call assert_equal('1', getloclist(0)[0].text)
1678
1679 set efm&vim
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001680endfunc
Bram Moolenaar63bed3d2016-11-12 15:36:54 +01001681
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001682func Test_caddbuffer_wrong()
1683 " This used to cause a memory access in freed memory.
Bram Moolenaar63bed3d2016-11-12 15:36:54 +01001684 let save_efm = &efm
1685 set efm=%EEEE%m,%WWWW,%+CCCC%>%#,%GGGG%.#
1686 cgetexpr ['WWWW', 'EEEE', 'CCCC']
1687 let &efm = save_efm
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001688 caddbuffer
Bram Moolenaar63bed3d2016-11-12 15:36:54 +01001689 bwipe!
1690endfunc
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001691
1692func Test_caddexpr_wrong()
1693 " This used to cause a memory access in freed memory.
1694 cbuffer
1695 cbuffer
1696 copen
1697 let save_efm = &efm
1698 set efm=%
1699 call assert_fails('caddexpr ""', 'E376:')
1700 let &efm = save_efm
1701endfunc
Bram Moolenaar7618e002016-11-13 15:09:26 +01001702
1703func Test_dirstack_cleanup()
1704 " This used to cause a memory access in freed memory.
1705 let save_efm = &efm
1706 lexpr '0'
1707 lopen
1708 fun X(c)
1709 let save_efm=&efm
1710 set efm=%D%f
1711 if a:c == 'c'
1712 caddexpr '::'
1713 else
1714 laddexpr ':0:0'
1715 endif
1716 let &efm=save_efm
1717 endfun
1718 call X('c')
1719 call X('l')
1720 call setqflist([], 'r')
1721 caddbuffer
1722 let &efm = save_efm
1723endfunc
Bram Moolenaar391b1dd2017-03-04 13:47:11 +01001724
1725" Tests for jumping to entries from the location list window and quickfix
1726" window
1727func Test_cwindow_jump()
1728 set efm=%f%%%l%%%m
1729 lgetexpr ["F1%10%Line 10", "F2%20%Line 20", "F3%30%Line 30"]
1730 lopen | only
1731 lfirst
1732 call assert_true(winnr('$') == 2)
1733 call assert_true(winnr() == 1)
1734 " Location list for the new window should be set
1735 call assert_true(getloclist(0)[2].text == 'Line 30')
1736
1737 " Open a scratch buffer
1738 " Open a new window and create a location list
1739 " Open the location list window and close the other window
1740 " Jump to an entry.
1741 " Should create a new window and jump to the entry. The scrtach buffer
1742 " should not be used.
1743 enew | only
1744 set buftype=nofile
1745 below new
1746 lgetexpr ["F1%10%Line 10", "F2%20%Line 20", "F3%30%Line 30"]
1747 lopen
1748 2wincmd c
1749 lnext
1750 call assert_true(winnr('$') == 3)
1751 call assert_true(winnr() == 2)
1752
1753 " Open two windows with two different location lists
1754 " Open the location list window and close the previous window
1755 " Jump to an entry in the location list window
1756 " Should open the file in the first window and not set the location list.
1757 enew | only
1758 lgetexpr ["F1%5%Line 5"]
1759 below new
1760 lgetexpr ["F1%10%Line 10", "F2%20%Line 20", "F3%30%Line 30"]
1761 lopen
1762 2wincmd c
1763 lnext
1764 call assert_true(winnr() == 1)
1765 call assert_true(getloclist(0)[0].text == 'Line 5')
1766
1767 enew | only
1768 cgetexpr ["F1%10%Line 10", "F2%20%Line 20", "F3%30%Line 30"]
1769 copen
1770 cnext
1771 call assert_true(winnr('$') == 2)
1772 call assert_true(winnr() == 1)
1773
1774 enew | only
1775 set efm&vim
1776endfunc