comparison src/testdir/test_quickfix.vim @ 9317:fa3f71185144 v7.4.1941

commit https://github.com/vim/vim/commit/3ef5bf7d459d6b8a21aaefc80f65448f5a7aa59f Author: Bram Moolenaar <Bram@vim.org> Date: Wed Jun 15 22:41:31 2016 +0200 patch 7.4.1941 Problem: Not all quickfix tests are also done with the location lists. Solution: Test more quickfix code. Use user commands instead of "exe". (Yegappan Lakshmanan)
author Christian Brabandt <cb@256bit.org>
date Wed, 15 Jun 2016 22:45:07 +0200
parents 178252c6850e
children 674f9e3ccd1a
comparison
equal deleted inserted replaced
9316:405c0bba9d1d 9317:fa3f71185144
4 finish 4 finish
5 endif 5 endif
6 6
7 set encoding=utf-8 7 set encoding=utf-8
8 8
9 function! 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
51 endfunction
52
9 " Tests for the :clist and :llist commands 53 " Tests for the :clist and :llist commands
10 function XlistTests(cchar) 54 function XlistTests(cchar)
11 let Xlist = a:cchar . 'list' 55 call s:setup_commands(a:cchar)
12 let Xgetexpr = a:cchar . 'getexpr'
13 56
14 " With an empty list, command should return error 57 " With an empty list, command should return error
15 exe Xgetexpr . ' []' 58 Xgetexpr []
16 exe 'silent! ' . Xlist 59 silent! Xlist
17 call assert_true(v:errmsg ==# 'E42: No Errors') 60 call assert_true(v:errmsg ==# 'E42: No Errors')
18 61
19 " Populate the list and then try 62 " Populate the list and then try
20 exe Xgetexpr . " ['non-error 1', 'Xtestfile1:1:3:Line1', 63 Xgetexpr ['non-error 1', 'Xtestfile1:1:3:Line1',
21 \ 'non-error 2', 'Xtestfile2:2:2:Line2', 64 \ 'non-error 2', 'Xtestfile2:2:2:Line2',
22 \ 'non-error 3', 'Xtestfile3:3:1:Line3']" 65 \ 'non-error 3', 'Xtestfile3:3:1:Line3']
23 66
24 " List only valid entries 67 " List only valid entries
25 redir => result 68 redir => result
26 exe Xlist 69 Xlist
27 redir END 70 redir END
28 let l = split(result, "\n") 71 let l = split(result, "\n")
29 call assert_equal([' 2 Xtestfile1:1 col 3: Line1', 72 call assert_equal([' 2 Xtestfile1:1 col 3: Line1',
30 \ ' 4 Xtestfile2:2 col 2: Line2', 73 \ ' 4 Xtestfile2:2 col 2: Line2',
31 \ ' 6 Xtestfile3:3 col 1: Line3'], l) 74 \ ' 6 Xtestfile3:3 col 1: Line3'], l)
32 75
33 " List all the entries 76 " List all the entries
34 redir => result 77 redir => result
35 exe Xlist . "!" 78 Xlist!
36 redir END 79 redir END
37 let l = split(result, "\n") 80 let l = split(result, "\n")
38 call assert_equal([' 1: non-error 1', ' 2 Xtestfile1:1 col 3: Line1', 81 call assert_equal([' 1: non-error 1', ' 2 Xtestfile1:1 col 3: Line1',
39 \ ' 3: non-error 2', ' 4 Xtestfile2:2 col 2: Line2', 82 \ ' 3: non-error 2', ' 4 Xtestfile2:2 col 2: Line2',
40 \ ' 5: non-error 3', ' 6 Xtestfile3:3 col 1: Line3'], l) 83 \ ' 5: non-error 3', ' 6 Xtestfile3:3 col 1: Line3'], l)
41 84
42 " List a range of errors 85 " List a range of errors
43 redir => result 86 redir => result
44 exe Xlist . " 3,6" 87 Xlist 3,6
45 redir END 88 redir END
46 let l = split(result, "\n") 89 let l = split(result, "\n")
47 call assert_equal([' 4 Xtestfile2:2 col 2: Line2', 90 call assert_equal([' 4 Xtestfile2:2 col 2: Line2',
48 \ ' 6 Xtestfile3:3 col 1: Line3'], l) 91 \ ' 6 Xtestfile3:3 col 1: Line3'], l)
49 92
50 redir => result 93 redir => result
51 exe Xlist . "! 3,4" 94 Xlist! 3,4
52 redir END 95 redir END
53 let l = split(result, "\n") 96 let l = split(result, "\n")
54 call assert_equal([' 3: non-error 2', ' 4 Xtestfile2:2 col 2: Line2'], l) 97 call assert_equal([' 3: non-error 2', ' 4 Xtestfile2:2 col 2: Line2'], l)
55 98
56 redir => result 99 redir => result
57 exe Xlist . " -6,-4" 100 Xlist -6,-4
58 redir END 101 redir END
59 let l = split(result, "\n") 102 let l = split(result, "\n")
60 call assert_equal([' 2 Xtestfile1:1 col 3: Line1'], l) 103 call assert_equal([' 2 Xtestfile1:1 col 3: Line1'], l)
61 104
62 redir => result 105 redir => result
63 exe Xlist . "! -5,-3" 106 Xlist! -5,-3
64 redir END 107 redir END
65 let l = split(result, "\n") 108 let l = split(result, "\n")
66 call assert_equal([' 2 Xtestfile1:1 col 3: Line1', 109 call assert_equal([' 2 Xtestfile1:1 col 3: Line1',
67 \ ' 3: non-error 2', ' 4 Xtestfile2:2 col 2: Line2'], l) 110 \ ' 3: non-error 2', ' 4 Xtestfile2:2 col 2: Line2'], l)
68 endfunction 111 endfunction
74 117
75 " Tests for the :colder, :cnewer, :lolder and :lnewer commands 118 " Tests for the :colder, :cnewer, :lolder and :lnewer commands
76 " Note that this test assumes that a quickfix/location list is 119 " Note that this test assumes that a quickfix/location list is
77 " already set by the caller. 120 " already set by the caller.
78 function XageTests(cchar) 121 function XageTests(cchar)
79 let Xolder = a:cchar . 'older' 122 call s:setup_commands(a:cchar)
80 let Xnewer = a:cchar . 'newer'
81 let Xgetexpr = a:cchar . 'getexpr'
82 if a:cchar == 'c'
83 let Xgetlist = function('getqflist')
84 else
85 let Xgetlist = function('getloclist', [0])
86 endif
87 123
88 " Jumping to a non existent list should return error 124 " Jumping to a non existent list should return error
89 exe 'silent! ' . Xolder . ' 99' 125 silent! Xolder 99
90 call assert_true(v:errmsg ==# 'E380: At bottom of quickfix stack') 126 call assert_true(v:errmsg ==# 'E380: At bottom of quickfix stack')
91 127
92 exe 'silent! ' . Xnewer . ' 99' 128 silent! Xnewer 99
93 call assert_true(v:errmsg ==# 'E381: At top of quickfix stack') 129 call assert_true(v:errmsg ==# 'E381: At top of quickfix stack')
94 130
95 " Add three quickfix/location lists 131 " Add three quickfix/location lists
96 exe Xgetexpr . " ['Xtestfile1:1:3:Line1']" 132 Xgetexpr ['Xtestfile1:1:3:Line1']
97 exe Xgetexpr . " ['Xtestfile2:2:2:Line2']" 133 Xgetexpr ['Xtestfile2:2:2:Line2']
98 exe Xgetexpr . " ['Xtestfile3:3:1:Line3']" 134 Xgetexpr ['Xtestfile3:3:1:Line3']
99 135
100 " Go back two lists 136 " Go back two lists
101 exe Xolder 137 Xolder
102 let l = Xgetlist() 138 let l = g:Xgetlist()
103 call assert_equal('Line2', l[0].text) 139 call assert_equal('Line2', l[0].text)
104 140
105 " Go forward two lists 141 " Go forward two lists
106 exe Xnewer 142 Xnewer
107 let l = Xgetlist() 143 let l = g:Xgetlist()
108 call assert_equal('Line3', l[0].text) 144 call assert_equal('Line3', l[0].text)
109 145
110 " Test for the optional count argument 146 " Test for the optional count argument
111 exe Xolder . ' 2' 147 Xolder 2
112 let l = Xgetlist() 148 let l = g:Xgetlist()
113 call assert_equal('Line1', l[0].text) 149 call assert_equal('Line1', l[0].text)
114 150
115 exe Xnewer . ' 2' 151 Xnewer 2
116 let l = Xgetlist() 152 let l = g:Xgetlist()
117 call assert_equal('Line3', l[0].text) 153 call assert_equal('Line3', l[0].text)
118 endfunction 154 endfunction
119 155
120 function Test_cage() 156 function Test_cage()
121 let list = [{'bufnr': 1, 'lnum': 1}] 157 let list = [{'bufnr': 1, 'lnum': 1}]
127 endfunction 163 endfunction
128 164
129 " Tests for the :cwindow, :lwindow :cclose, :lclose, :copen and :lopen 165 " Tests for the :cwindow, :lwindow :cclose, :lclose, :copen and :lopen
130 " commands 166 " commands
131 function XwindowTests(cchar) 167 function XwindowTests(cchar)
132 let Xwindow = a:cchar . 'window' 168 call s:setup_commands(a:cchar)
133 let Xclose = a:cchar . 'close'
134 let Xopen = a:cchar . 'open'
135 let Xgetexpr = a:cchar . 'getexpr'
136 169
137 " Create a list with no valid entries 170 " Create a list with no valid entries
138 exe Xgetexpr . " ['non-error 1', 'non-error 2', 'non-error 3']" 171 Xgetexpr ['non-error 1', 'non-error 2', 'non-error 3']
139 172
140 " Quickfix/Location window should not open with no valid errors 173 " Quickfix/Location window should not open with no valid errors
141 exe Xwindow 174 Xwindow
142 call assert_true(winnr('$') == 1) 175 call assert_true(winnr('$') == 1)
143 176
144 " Create a list with valid entries 177 " Create a list with valid entries
145 exe Xgetexpr . " ['Xtestfile1:1:3:Line1', 'Xtestfile2:2:2:Line2', 178 Xgetexpr ['Xtestfile1:1:3:Line1', 'Xtestfile2:2:2:Line2',
146 \ 'Xtestfile3:3:1:Line3']" 179 \ 'Xtestfile3:3:1:Line3']
147 180
148 " Open the window 181 " Open the window
149 exe Xwindow 182 Xwindow
150 call assert_true(winnr('$') == 2 && winnr() == 2 && 183 call assert_true(winnr('$') == 2 && winnr() == 2 &&
151 \ getline('.') ==# 'Xtestfile1|1 col 3| Line1') 184 \ getline('.') ==# 'Xtestfile1|1 col 3| Line1')
152 185
153 " Close the window 186 " Close the window
154 exe Xclose 187 Xclose
155 call assert_true(winnr('$') == 1) 188 call assert_true(winnr('$') == 1)
156 189
157 " Create a list with no valid entries 190 " Create a list with no valid entries
158 exe Xgetexpr . " ['non-error 1', 'non-error 2', 'non-error 3']" 191 Xgetexpr ['non-error 1', 'non-error 2', 'non-error 3']
159 192
160 " Open the window 193 " Open the window
161 exe Xopen . ' 5' 194 Xopen 5
162 call assert_true(winnr('$') == 2 && getline('.') ==# '|| non-error 1' 195 call assert_true(winnr('$') == 2 && getline('.') ==# '|| non-error 1'
163 \ && winheight('.') == 5) 196 \ && winheight('.') == 5)
164 197
165 " Opening the window again, should move the cursor to that window 198 " Opening the window again, should move the cursor to that window
166 wincmd t 199 wincmd t
167 exe Xopen . ' 7' 200 Xopen 7
168 call assert_true(winnr('$') == 2 && winnr() == 2 && 201 call assert_true(winnr('$') == 2 && winnr() == 2 &&
169 \ winheight('.') == 7 && 202 \ winheight('.') == 7 &&
170 \ getline('.') ==# '|| non-error 1') 203 \ getline('.') ==# '|| non-error 1')
171 204
172 205
173 " Calling cwindow should close the quickfix window with no valid errors 206 " Calling cwindow should close the quickfix window with no valid errors
174 exe Xwindow 207 Xwindow
175 call assert_true(winnr('$') == 1) 208 call assert_true(winnr('$') == 1)
176 endfunction 209 endfunction
177 210
178 function Test_cwindow() 211 function Test_cwindow()
179 call XwindowTests('c') 212 call XwindowTests('c')
181 endfunction 214 endfunction
182 215
183 " Tests for the :cfile, :lfile, :caddfile, :laddfile, :cgetfile and :lgetfile 216 " Tests for the :cfile, :lfile, :caddfile, :laddfile, :cgetfile and :lgetfile
184 " commands. 217 " commands.
185 function XfileTests(cchar) 218 function XfileTests(cchar)
186 let Xfile = a:cchar . 'file' 219 call s:setup_commands(a:cchar)
187 let Xgetfile = a:cchar . 'getfile'
188 let Xaddfile = a:cchar . 'addfile'
189 if a:cchar == 'c'
190 let Xgetlist = function('getqflist')
191 else
192 let Xgetlist = function('getloclist', [0])
193 endif
194 220
195 call writefile(['Xtestfile1:700:10:Line 700', 221 call writefile(['Xtestfile1:700:10:Line 700',
196 \ 'Xtestfile2:800:15:Line 800'], 'Xqftestfile1') 222 \ 'Xtestfile2:800:15:Line 800'], 'Xqftestfile1')
197 223
198 enew! 224 enew!
199 exe Xfile . ' Xqftestfile1' 225 Xfile Xqftestfile1
200 let l = Xgetlist() 226 let l = g:Xgetlist()
201 call assert_true(len(l) == 2 && 227 call assert_true(len(l) == 2 &&
202 \ l[0].lnum == 700 && l[0].col == 10 && l[0].text ==# 'Line 700' && 228 \ l[0].lnum == 700 && l[0].col == 10 && l[0].text ==# 'Line 700' &&
203 \ l[1].lnum == 800 && l[1].col == 15 && l[1].text ==# 'Line 800') 229 \ l[1].lnum == 800 && l[1].col == 15 && l[1].text ==# 'Line 800')
204 230
205 " Run cfile/lfile from a modified buffer 231 " Run cfile/lfile from a modified buffer
206 enew! 232 enew!
207 silent! put ='Quickfix' 233 silent! put ='Quickfix'
208 exe 'silent! ' . Xfile . ' Xqftestfile1' 234 silent! Xfile Xqftestfile1
209 call assert_true(v:errmsg ==# 'E37: No write since last change (add ! to override)') 235 call assert_true(v:errmsg ==# 'E37: No write since last change (add ! to override)')
210 236
211 call writefile(['Xtestfile3:900:30:Line 900'], 'Xqftestfile1') 237 call writefile(['Xtestfile3:900:30:Line 900'], 'Xqftestfile1')
212 exe Xaddfile . ' Xqftestfile1' 238 Xaddfile Xqftestfile1
213 let l = Xgetlist() 239 let l = g:Xgetlist()
214 call assert_true(len(l) == 3 && 240 call assert_true(len(l) == 3 &&
215 \ l[2].lnum == 900 && l[2].col == 30 && l[2].text ==# 'Line 900') 241 \ l[2].lnum == 900 && l[2].col == 30 && l[2].text ==# 'Line 900')
216 242
217 call writefile(['Xtestfile1:222:77:Line 222', 243 call writefile(['Xtestfile1:222:77:Line 222',
218 \ 'Xtestfile2:333:88:Line 333'], 'Xqftestfile1') 244 \ 'Xtestfile2:333:88:Line 333'], 'Xqftestfile1')
219 245
220 enew! 246 enew!
221 exe Xgetfile . ' Xqftestfile1' 247 Xgetfile Xqftestfile1
222 let l = Xgetlist() 248 let l = g:Xgetlist()
223 call assert_true(len(l) == 2 && 249 call assert_true(len(l) == 2 &&
224 \ l[0].lnum == 222 && l[0].col == 77 && l[0].text ==# 'Line 222' && 250 \ l[0].lnum == 222 && l[0].col == 77 && l[0].text ==# 'Line 222' &&
225 \ l[1].lnum == 333 && l[1].col == 88 && l[1].text ==# 'Line 333') 251 \ l[1].lnum == 333 && l[1].col == 88 && l[1].text ==# 'Line 333')
226 252
227 call delete('Xqftestfile1') 253 call delete('Xqftestfile1')
233 endfunction 259 endfunction
234 260
235 " Tests for the :cbuffer, :lbuffer, :caddbuffer, :laddbuffer, :cgetbuffer and 261 " Tests for the :cbuffer, :lbuffer, :caddbuffer, :laddbuffer, :cgetbuffer and
236 " :lgetbuffer commands. 262 " :lgetbuffer commands.
237 function XbufferTests(cchar) 263 function XbufferTests(cchar)
238 let Xbuffer = a:cchar . 'buffer' 264 call s:setup_commands(a:cchar)
239 let Xgetbuffer = a:cchar . 'getbuffer'
240 let Xaddbuffer = a:cchar . 'addbuffer'
241 if a:cchar == 'c'
242 let Xgetlist = function('getqflist')
243 else
244 let Xgetlist = function('getloclist', [0])
245 endif
246 265
247 enew! 266 enew!
248 silent! call setline(1, ['Xtestfile7:700:10:Line 700', 267 silent! call setline(1, ['Xtestfile7:700:10:Line 700',
249 \ 'Xtestfile8:800:15:Line 800']) 268 \ 'Xtestfile8:800:15:Line 800'])
250 exe Xbuffer . "!" 269 Xbuffer!
251 let l = Xgetlist() 270 let l = g:Xgetlist()
252 call assert_true(len(l) == 2 && 271 call assert_true(len(l) == 2 &&
253 \ l[0].lnum == 700 && l[0].col == 10 && l[0].text ==# 'Line 700' && 272 \ l[0].lnum == 700 && l[0].col == 10 && l[0].text ==# 'Line 700' &&
254 \ l[1].lnum == 800 && l[1].col == 15 && l[1].text ==# 'Line 800') 273 \ l[1].lnum == 800 && l[1].col == 15 && l[1].text ==# 'Line 800')
255 274
256 enew! 275 enew!
257 silent! call setline(1, ['Xtestfile9:900:55:Line 900', 276 silent! call setline(1, ['Xtestfile9:900:55:Line 900',
258 \ 'Xtestfile10:950:66:Line 950']) 277 \ 'Xtestfile10:950:66:Line 950'])
259 exe Xgetbuffer 278 Xgetbuffer
260 let l = Xgetlist() 279 let l = g:Xgetlist()
261 call assert_true(len(l) == 2 && 280 call assert_true(len(l) == 2 &&
262 \ l[0].lnum == 900 && l[0].col == 55 && l[0].text ==# 'Line 900' && 281 \ l[0].lnum == 900 && l[0].col == 55 && l[0].text ==# 'Line 900' &&
263 \ l[1].lnum == 950 && l[1].col == 66 && l[1].text ==# 'Line 950') 282 \ l[1].lnum == 950 && l[1].col == 66 && l[1].text ==# 'Line 950')
264 283
265 enew! 284 enew!
266 silent! call setline(1, ['Xtestfile11:700:20:Line 700', 285 silent! call setline(1, ['Xtestfile11:700:20:Line 700',
267 \ 'Xtestfile12:750:25:Line 750']) 286 \ 'Xtestfile12:750:25:Line 750'])
268 exe Xaddbuffer 287 Xaddbuffer
269 let l = Xgetlist() 288 let l = g:Xgetlist()
270 call assert_true(len(l) == 4 && 289 call assert_true(len(l) == 4 &&
271 \ l[1].lnum == 950 && l[1].col == 66 && l[1].text ==# 'Line 950' && 290 \ l[1].lnum == 950 && l[1].col == 66 && l[1].text ==# 'Line 950' &&
272 \ l[2].lnum == 700 && l[2].col == 20 && l[2].text ==# 'Line 700' && 291 \ l[2].lnum == 700 && l[2].col == 20 && l[2].text ==# 'Line 700' &&
273 \ l[3].lnum == 750 && l[3].col == 25 && l[3].text ==# 'Line 750') 292 \ l[3].lnum == 750 && l[3].col == 25 && l[3].text ==# 'Line 750')
274 enew! 293 enew!
336 augroup END 355 augroup END
337 augroup! QfBufWinEnter 356 augroup! QfBufWinEnter
338 endfunc 357 endfunc
339 358
340 function XqfTitleTests(cchar) 359 function XqfTitleTests(cchar)
341 let Xgetexpr = a:cchar . 'getexpr' 360 call s:setup_commands(a:cchar)
342 if a:cchar == 'c' 361
343 let Xgetlist = function('getqflist') 362 Xgetexpr ['file:1:1:message']
344 else 363 let l = g:Xgetlist()
345 let Xgetlist = function('getloclist', [0])
346 endif
347 let Xopen = a:cchar . 'open'
348 let Xclose = a:cchar . 'close'
349
350 exe Xgetexpr . " ['file:1:1:message']"
351 let l = Xgetlist()
352 if a:cchar == 'c' 364 if a:cchar == 'c'
353 call setqflist(l, 'r') 365 call setqflist(l, 'r')
354 else 366 else
355 call setloclist(0, l, 'r') 367 call setloclist(0, l, 'r')
356 endif 368 endif
357 369
358 exe Xopen 370 Xopen
359 if a:cchar == 'c' 371 if a:cchar == 'c'
360 let title = ':setqflist()' 372 let title = ':setqflist()'
361 else 373 else
362 let title = ':setloclist()' 374 let title = ':setloclist()'
363 endif 375 endif
364 call assert_equal(title, w:quickfix_title) 376 call assert_equal(title, w:quickfix_title)
365 exe Xclose 377 Xclose
366 endfunction 378 endfunction
367 379
368 " Tests for quickfix window's title 380 " Tests for quickfix window's title
369 function Test_qf_title() 381 function Test_qf_title()
370 call XqfTitleTests('c') 382 call XqfTitleTests('c')
371 call XqfTitleTests('l') 383 call XqfTitleTests('l')
372 endfunction 384 endfunction
373 385
374 " Tests for 'errorformat' 386 " Tests for 'errorformat'
375 function Test_efm() 387 function Test_efm()
376 let save_efm = &efm 388 let save_efm = &efm
639 call delete('Xtestfile') 651 call delete('Xtestfile')
640 endfunction 652 endfunction
641 653
642 " Test for quickfix directory stack support 654 " Test for quickfix directory stack support
643 function! s:dir_stack_tests(cchar) 655 function! s:dir_stack_tests(cchar)
644 let Xgetexpr = a:cchar . 'getexpr'
645 if a:cchar == 'c'
646 let Xgetlist = function('getqflist')
647 else
648 let Xgetlist = function('getloclist', [0])
649 endif
650
651 let save_efm=&efm 656 let save_efm=&efm
652 set efm=%DEntering\ dir\ '%f',%f:%l:%m,%XLeaving\ dir\ '%f' 657 set efm=%DEntering\ dir\ '%f',%f:%l:%m,%XLeaving\ dir\ '%f'
653 658
654 let l = "Entering dir 'dir1/a'\n" . 659 let l = "Entering dir 'dir1/a'\n" .
655 \ 'habits2.txt:1:Nine Healthy Habits' . "\n" . 660 \ 'habits2.txt:1:Nine Healthy Habits' . "\n" .
660 \ 'habits4.txt:3:1 Hour of exercise' . "\n" . 665 \ 'habits4.txt:3:1 Hour of exercise' . "\n" .
661 \ "Leaving dir 'dir1/c'\n" . 666 \ "Leaving dir 'dir1/c'\n" .
662 \ "Leaving dir 'dir1/a'\n" . 667 \ "Leaving dir 'dir1/a'\n" .
663 \ 'habits1.txt:4:2 Liters of water' . "\n" . 668 \ 'habits1.txt:4:2 Liters of water' . "\n" .
664 \ "Entering dir 'dir2'\n" . 669 \ "Entering dir 'dir2'\n" .
665 \ 'habits5.txt:5:3 Cups of hot green tea' . "\n" . 670 \ 'habits5.txt:5:3 Cups of hot green tea' . "\n"
666 \ "Leaving dir 'dir2'\n" 671 \ "Leaving dir 'dir2'\n"
667 672
668 exe Xgetexpr . " l" 673 Xgetexpr l
669 674
670 let qf = Xgetlist() 675 let qf = g:Xgetlist()
671 676
672 call assert_equal('dir1/a/habits2.txt', bufname(qf[1].bufnr)) 677 call assert_equal('dir1/a/habits2.txt', bufname(qf[1].bufnr))
673 call assert_equal(1, qf[1].lnum) 678 call assert_equal(1, qf[1].lnum)
674 call assert_equal('dir1/a/b/habits3.txt', bufname(qf[3].bufnr)) 679 call assert_equal('dir1/a/b/habits3.txt', bufname(qf[3].bufnr))
675 call assert_equal(2, qf[3].lnum) 680 call assert_equal(2, qf[3].lnum)
719 call delete('dir2', 'rf') 724 call delete('dir2', 'rf')
720 call delete('habits1.txt') 725 call delete('habits1.txt')
721 endfunction 726 endfunction
722 727
723 function XquickfixChangedByAutocmd(cchar) 728 function XquickfixChangedByAutocmd(cchar)
724 let Xolder = a:cchar . 'older' 729 call s:setup_commands(a:cchar)
725 let Xgetexpr = a:cchar . 'getexpr'
726 let Xrewind = a:cchar . 'rewind'
727 if a:cchar == 'c' 730 if a:cchar == 'c'
728 let Xsetlist = function('setqflist')
729 let ErrorNr = 'E925' 731 let ErrorNr = 'E925'
730 function! ReadFunc() 732 function! ReadFunc()
731 colder 733 colder
732 cgetexpr [] 734 cgetexpr []
733 endfunc 735 endfunc
734 else 736 else
735 let Xsetlist = function('setloclist', [0])
736 let ErrorNr = 'E926' 737 let ErrorNr = 'E926'
737 function! ReadFunc() 738 function! ReadFunc()
738 lolder 739 lolder
739 lgetexpr [] 740 lgetexpr []
740 endfunc 741 endfunc
748 new | only 749 new | only
749 let words = [ "a", "b" ] 750 let words = [ "a", "b" ]
750 let qflist = [] 751 let qflist = []
751 for word in words 752 for word in words
752 call add(qflist, {'filename': 'test_changed.txt'}) 753 call add(qflist, {'filename': 'test_changed.txt'})
753 call Xsetlist(qflist, ' ') 754 call g:Xsetlist(qflist, ' ')
754 endfor 755 endfor
755 exec "call assert_fails('" . Xrewind . "', '" . ErrorNr . ":')" 756 call assert_fails('Xrewind', ErrorNr . ':')
756 757
757 augroup! testgroup 758 augroup! testgroup
758 endfunc 759 endfunc
759 760
760 function Test_quickfix_was_changed_by_autocmd() 761 function Test_quickfix_was_changed_by_autocmd()
776 endfunc 777 endfunc
777 778
778 func Test_cgetexpr_works() 779 func Test_cgetexpr_works()
779 " this must not crash Vim 780 " this must not crash Vim
780 cgetexpr [$x] 781 cgetexpr [$x]
782 lgetexpr [$x]
781 endfunc 783 endfunc
782 784
783 " Tests for the setqflist() and setloclist() functions 785 " Tests for the setqflist() and setloclist() functions
784 function SetXlistTests(cchar, bnum) 786 function SetXlistTests(cchar, bnum)
785 let Xwindow = a:cchar . 'window' 787 call s:setup_commands(a:cchar)
786 let Xnext = a:cchar . 'next' 788
787 if a:cchar == 'c' 789 call g:Xsetlist([{'bufnr': a:bnum, 'lnum': 1},
788 let Xsetlist = function('setqflist')
789 let Xgetlist = function('getqflist')
790 else
791 let Xsetlist = function('setloclist', [0])
792 let Xgetlist = function('getloclist', [0])
793 endif
794
795 call Xsetlist([{'bufnr': a:bnum, 'lnum': 1},
796 \ {'bufnr': a:bnum, 'lnum': 2}]) 790 \ {'bufnr': a:bnum, 'lnum': 2}])
797 let l = Xgetlist() 791 let l = g:Xgetlist()
798 call assert_equal(2, len(l)) 792 call assert_equal(2, len(l))
799 call assert_equal(2, l[1].lnum) 793 call assert_equal(2, l[1].lnum)
800 794
801 exe Xnext 795 Xnext
802 call Xsetlist([{'bufnr': a:bnum, 'lnum': 3}], 'a') 796 call g:Xsetlist([{'bufnr': a:bnum, 'lnum': 3}], 'a')
803 let l = Xgetlist() 797 let l = g:Xgetlist()
804 call assert_equal(3, len(l)) 798 call assert_equal(3, len(l))
805 exe Xnext 799 Xnext
806 call assert_equal(3, line('.')) 800 call assert_equal(3, line('.'))
807 801
808 " Appending entries to the list should not change the cursor position 802 " Appending entries to the list should not change the cursor position
809 " in the quickfix window 803 " in the quickfix window
810 exe Xwindow 804 Xwindow
811 1 805 1
812 call Xsetlist([{'bufnr': a:bnum, 'lnum': 4}, 806 call g:Xsetlist([{'bufnr': a:bnum, 'lnum': 4},
813 \ {'bufnr': a:bnum, 'lnum': 5}], 'a') 807 \ {'bufnr': a:bnum, 'lnum': 5}], 'a')
814 call assert_equal(1, line('.')) 808 call assert_equal(1, line('.'))
815 close 809 close
816 810
817 call Xsetlist([{'bufnr': a:bnum, 'lnum': 3}, 811 call g:Xsetlist([{'bufnr': a:bnum, 'lnum': 3},
818 \ {'bufnr': a:bnum, 'lnum': 4}, 812 \ {'bufnr': a:bnum, 'lnum': 4},
819 \ {'bufnr': a:bnum, 'lnum': 5}], 'r') 813 \ {'bufnr': a:bnum, 'lnum': 5}], 'r')
820 let l = Xgetlist() 814 let l = g:Xgetlist()
821 call assert_equal(3, len(l)) 815 call assert_equal(3, len(l))
822 call assert_equal(5, l[2].lnum) 816 call assert_equal(5, l[2].lnum)
823 817
824 call Xsetlist([]) 818 call g:Xsetlist([])
825 let l = Xgetlist() 819 let l = g:Xgetlist()
826 call assert_equal(0, len(l)) 820 call assert_equal(0, len(l))
827 endfunction 821 endfunction
828 822
829 function Test_setqflist() 823 function Test_setqflist()
830 new Xtestfile | only 824 new Xtestfile | only
836 830
837 enew! 831 enew!
838 call delete('Xtestfile') 832 call delete('Xtestfile')
839 endfunction 833 endfunction
840 834
841 func Test_setqflist_empty_middle() 835 function Xlist_empty_middle(cchar)
836 call s:setup_commands(a:cchar)
837
842 " create three quickfix lists 838 " create three quickfix lists
843 vimgrep Test_ test_quickfix.vim 839 Xvimgrep Test_ test_quickfix.vim
844 let testlen = len(getqflist()) 840 let testlen = len(g:Xgetlist())
845 call assert_true(testlen > 0) 841 call assert_true(testlen > 0)
846 vimgrep empty test_quickfix.vim 842 Xvimgrep empty test_quickfix.vim
847 call assert_true(len(getqflist()) > 0) 843 call assert_true(len(g:Xgetlist()) > 0)
848 vimgrep matches test_quickfix.vim 844 Xvimgrep matches test_quickfix.vim
849 let matchlen = len(getqflist()) 845 let matchlen = len(g:Xgetlist())
850 call assert_true(matchlen > 0) 846 call assert_true(matchlen > 0)
851 colder 847 Xolder
852 " make the middle list empty 848 " make the middle list empty
853 call setqflist([], 'r') 849 call g:Xsetlist([], 'r')
854 call assert_true(len(getqflist()) == 0) 850 call assert_true(len(g:Xgetlist()) == 0)
855 colder 851 Xolder
856 call assert_equal(testlen, len(getqflist())) 852 call assert_equal(testlen, len(g:Xgetlist()))
857 cnewer 853 Xnewer
858 cnewer 854 Xnewer
859 call assert_equal(matchlen, len(getqflist())) 855 call assert_equal(matchlen, len(g:Xgetlist()))
860 endfunc 856 endfunc
861 857
862 func Test_setqflist_empty_older() 858 function Test_setqflist_empty_middle()
859 call Xlist_empty_middle('c')
860 call Xlist_empty_middle('l')
861 endfunction
862
863 function Xlist_empty_older(cchar)
864 call s:setup_commands(a:cchar)
865
863 " create three quickfix lists 866 " create three quickfix lists
864 vimgrep one test_quickfix.vim 867 Xvimgrep one test_quickfix.vim
865 let onelen = len(getqflist()) 868 let onelen = len(g:Xgetlist())
866 call assert_true(onelen > 0) 869 call assert_true(onelen > 0)
867 vimgrep two test_quickfix.vim 870 Xvimgrep two test_quickfix.vim
868 let twolen = len(getqflist()) 871 let twolen = len(g:Xgetlist())
869 call assert_true(twolen > 0) 872 call assert_true(twolen > 0)
870 vimgrep three test_quickfix.vim 873 Xvimgrep three test_quickfix.vim
871 let threelen = len(getqflist()) 874 let threelen = len(g:Xgetlist())
872 call assert_true(threelen > 0) 875 call assert_true(threelen > 0)
873 colder 2 876 Xolder 2
874 " make the first list empty, check the others didn't change 877 " make the first list empty, check the others didn't change
875 call setqflist([], 'r') 878 call g:Xsetlist([], 'r')
876 call assert_true(len(getqflist()) == 0) 879 call assert_true(len(g:Xgetlist()) == 0)
877 cnewer 880 Xnewer
878 call assert_equal(twolen, len(getqflist())) 881 call assert_equal(twolen, len(g:Xgetlist()))
879 cnewer 882 Xnewer
880 call assert_equal(threelen, len(getqflist())) 883 call assert_equal(threelen, len(g:Xgetlist()))
881 endfunc 884 endfunction
885
886 function Test_setqflist_empty_older()
887 call Xlist_empty_older('c')
888 call Xlist_empty_older('l')
889 endfunction
882 890
883 function! XquickfixSetListWithAct(cchar) 891 function! XquickfixSetListWithAct(cchar)
884 let Xolder = a:cchar . 'older' 892 call s:setup_commands(a:cchar)
885 let Xnewer = a:cchar . 'newer' 893
886 if a:cchar == 'c'
887 let Xsetlist = function('setqflist')
888 let Xgetlist = function('getqflist')
889 else
890 let Xsetlist = function('setloclist', [0])
891 let Xgetlist = function('getloclist', [0])
892 endif
893 let list1 = [{'filename': 'fnameA', 'text': 'A'}, 894 let list1 = [{'filename': 'fnameA', 'text': 'A'},
894 \ {'filename': 'fnameB', 'text': 'B'}] 895 \ {'filename': 'fnameB', 'text': 'B'}]
895 let list2 = [{'filename': 'fnameC', 'text': 'C'}, 896 let list2 = [{'filename': 'fnameC', 'text': 'C'},
896 \ {'filename': 'fnameD', 'text': 'D'}, 897 \ {'filename': 'fnameD', 'text': 'D'},
897 \ {'filename': 'fnameE', 'text': 'E'}] 898 \ {'filename': 'fnameE', 'text': 'E'}]
898 899
899 " {action} is unspecified. Same as specifing ' '. 900 " {action} is unspecified. Same as specifing ' '.
900 new | only 901 new | only
901 exec "silent! " . Xnewer . "99" 902 silent! Xnewer 99
902 call Xsetlist(list1) 903 call g:Xsetlist(list1)
903 call Xsetlist(list2) 904 call g:Xsetlist(list2)
904 let li = Xgetlist() 905 let li = g:Xgetlist()
905 call assert_equal(3, len(li)) 906 call assert_equal(3, len(li))
906 call assert_equal('C', li[0]['text']) 907 call assert_equal('C', li[0]['text'])
907 call assert_equal('D', li[1]['text']) 908 call assert_equal('D', li[1]['text'])
908 call assert_equal('E', li[2]['text']) 909 call assert_equal('E', li[2]['text'])
909 exec "silent! " . Xolder 910 silent! Xolder
910 let li = Xgetlist() 911 let li = g:Xgetlist()
911 call assert_equal(2, len(li)) 912 call assert_equal(2, len(li))
912 call assert_equal('A', li[0]['text']) 913 call assert_equal('A', li[0]['text'])
913 call assert_equal('B', li[1]['text']) 914 call assert_equal('B', li[1]['text'])
914 915
915 " {action} is specified ' '. 916 " {action} is specified ' '.
916 new | only 917 new | only
917 exec "silent! " . Xnewer . "99" 918 silent! Xnewer 99
918 call Xsetlist(list1) 919 call g:Xsetlist(list1)
919 call Xsetlist(list2, ' ') 920 call g:Xsetlist(list2, ' ')
920 let li = Xgetlist() 921 let li = g:Xgetlist()
921 call assert_equal(3, len(li)) 922 call assert_equal(3, len(li))
922 call assert_equal('C', li[0]['text']) 923 call assert_equal('C', li[0]['text'])
923 call assert_equal('D', li[1]['text']) 924 call assert_equal('D', li[1]['text'])
924 call assert_equal('E', li[2]['text']) 925 call assert_equal('E', li[2]['text'])
925 exec "silent! " . Xolder 926 silent! Xolder
926 let li = Xgetlist() 927 let li = g:Xgetlist()
927 call assert_equal(2, len(li)) 928 call assert_equal(2, len(li))
928 call assert_equal('A', li[0]['text']) 929 call assert_equal('A', li[0]['text'])
929 call assert_equal('B', li[1]['text']) 930 call assert_equal('B', li[1]['text'])
930 931
931 " {action} is specified 'a'. 932 " {action} is specified 'a'.
932 new | only 933 new | only
933 exec "silent! " . Xnewer . "99" 934 silent! Xnewer 99
934 call Xsetlist(list1) 935 call g:Xsetlist(list1)
935 call Xsetlist(list2, 'a') 936 call g:Xsetlist(list2, 'a')
936 let li = Xgetlist() 937 let li = g:Xgetlist()
937 call assert_equal(5, len(li)) 938 call assert_equal(5, len(li))
938 call assert_equal('A', li[0]['text']) 939 call assert_equal('A', li[0]['text'])
939 call assert_equal('B', li[1]['text']) 940 call assert_equal('B', li[1]['text'])
940 call assert_equal('C', li[2]['text']) 941 call assert_equal('C', li[2]['text'])
941 call assert_equal('D', li[3]['text']) 942 call assert_equal('D', li[3]['text'])
942 call assert_equal('E', li[4]['text']) 943 call assert_equal('E', li[4]['text'])
943 944
944 " {action} is specified 'r'. 945 " {action} is specified 'r'.
945 new | only 946 new | only
946 exec "silent! " . Xnewer . "99" 947 silent! Xnewer 99
947 call Xsetlist(list1) 948 call g:Xsetlist(list1)
948 call Xsetlist(list2, 'r') 949 call g:Xsetlist(list2, 'r')
949 let li = Xgetlist() 950 let li = g:Xgetlist()
950 call assert_equal(3, len(li)) 951 call assert_equal(3, len(li))
951 call assert_equal('C', li[0]['text']) 952 call assert_equal('C', li[0]['text'])
952 call assert_equal('D', li[1]['text']) 953 call assert_equal('D', li[1]['text'])
953 call assert_equal('E', li[2]['text']) 954 call assert_equal('E', li[2]['text'])
954 955
955 " Test for wrong value. 956 " Test for wrong value.
956 new | only 957 new | only
957 call assert_fails("call Xsetlist(0)", 'E714:') 958 call assert_fails("call g:Xsetlist(0)", 'E714:')
958 call assert_fails("call Xsetlist(list1, '')", 'E927:') 959 call assert_fails("call g:Xsetlist(list1, '')", 'E927:')
959 call assert_fails("call Xsetlist(list1, 'aa')", 'E927:') 960 call assert_fails("call g:Xsetlist(list1, 'aa')", 'E927:')
960 call assert_fails("call Xsetlist(list1, ' a')", 'E927:') 961 call assert_fails("call g:Xsetlist(list1, ' a')", 'E927:')
961 call assert_fails("call Xsetlist(list1, 0)", 'E928:') 962 call assert_fails("call g:Xsetlist(list1, 0)", 'E928:')
962 endfunc 963 endfunc
963 964
964 function Test_quickfix_set_list_with_act() 965 function Test_quickfix_set_list_with_act()
965 call XquickfixSetListWithAct('c') 966 call XquickfixSetListWithAct('c')
966 call XquickfixSetListWithAct('l') 967 call XquickfixSetListWithAct('l')
967 endfunction 968 endfunction
968 969
969 func XLongLinesTests() 970 function XLongLinesTests(cchar)
970 let l = getqflist() 971 let l = g:Xgetlist()
971 972
972 call assert_equal(3, len(l)) 973 call assert_equal(3, len(l))
973 call assert_equal(1, l[0].lnum) 974 call assert_equal(1, l[0].lnum)
974 call assert_equal(1, l[0].col) 975 call assert_equal(1, l[0].col)
975 call assert_equal(4070, len(l[0].text)) 976 call assert_equal(4070, len(l[0].text))
978 call assert_equal(4070, len(l[1].text)) 979 call assert_equal(4070, len(l[1].text))
979 call assert_equal(3, l[2].lnum) 980 call assert_equal(3, l[2].lnum)
980 call assert_equal(1, l[2].col) 981 call assert_equal(1, l[2].col)
981 call assert_equal(10, len(l[2].text)) 982 call assert_equal(10, len(l[2].text))
982 983
983 call setqflist([], 'r') 984 call g:Xsetlist([], 'r')
984 endfunc 985 endfunction
985 986
986 func Test_long_lines() 987 function s:long_lines_tests(cchar)
988 call s:setup_commands(a:cchar)
989
987 let testfile = 'samples/quickfix.txt' 990 let testfile = 'samples/quickfix.txt'
988 991
989 " file 992 " file
990 exe 'cgetfile' testfile 993 exe 'Xgetfile' testfile
991 call XLongLinesTests() 994 call XLongLinesTests(a:cchar)
992 995
993 " list 996 " list
994 cexpr readfile(testfile) 997 Xexpr readfile(testfile)
995 call XLongLinesTests() 998 call XLongLinesTests(a:cchar)
996 999
997 " string 1000 " string
998 cexpr join(readfile(testfile), "\n") 1001 Xexpr join(readfile(testfile), "\n")
999 call XLongLinesTests() 1002 call XLongLinesTests(a:cchar)
1000 1003
1001 " buffer 1004 " buffer
1002 e testfile 1005 exe 'edit' testfile
1003 exe 'cbuffer' bufnr('%') 1006 exe 'Xbuffer' bufnr('%')
1004 endfunc 1007 endfunction
1008
1009 function Test_long_lines()
1010 call s:long_lines_tests('c')
1011 call s:long_lines_tests('l')
1012 endfunction