blob: c77f3c94c07aeb66150853f387087e9a53bf85cd [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>
Bram Moolenaar99895ea2017-04-20 22:44:47 +020027 command! -count -nargs=* -bang Xnext <mods><count>cnext<bang> <args>
28 command! -count -nargs=* -bang Xprev <mods><count>cprev<bang> <args>
Bram Moolenaar0fcc7c62016-07-02 21:22:52 +020029 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>
Bram Moolenaaree85df32017-03-19 14:19:50 +010034 command! -range -nargs=* Xvimgrep <mods><count>vimgrep <args>
35 command! -nargs=* Xvimgrepadd <mods>vimgrepadd <args>
Bram Moolenaar049cba92016-06-26 14:38:04 +020036 command! -nargs=* Xgrep <mods> grep <args>
37 command! -nargs=* Xgrepadd <mods> grepadd <args>
38 command! -nargs=* Xhelpgrep helpgrep <args>
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +020039 let g:Xgetlist = function('getqflist')
40 let g:Xsetlist = function('setqflist')
Bram Moolenaarb6fa30c2017-03-29 14:19:25 +020041 call setqflist([], 'f')
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +020042 else
43 command! -nargs=* -bang Xlist <mods>llist<bang> <args>
44 command! -nargs=* Xgetexpr <mods>lgetexpr <args>
Bram Moolenaar361c8f02016-07-02 15:41:47 +020045 command! -nargs=* Xaddexpr <mods>laddexpr <args>
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +020046 command! -nargs=* Xolder <mods>lolder <args>
47 command! -nargs=* Xnewer <mods>lnewer <args>
48 command! -nargs=* Xopen <mods>lopen <args>
49 command! -nargs=* Xwindow <mods>lwindow <args>
Bram Moolenaar537ef082016-07-09 17:56:19 +020050 command! -nargs=* Xbottom <mods>lbottom <args>
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +020051 command! -nargs=* Xclose <mods>lclose <args>
52 command! -nargs=* -bang Xfile <mods>lfile<bang> <args>
53 command! -nargs=* Xgetfile <mods>lgetfile <args>
54 command! -nargs=* Xaddfile <mods>laddfile <args>
55 command! -nargs=* -bang Xbuffer <mods>lbuffer<bang> <args>
56 command! -nargs=* Xgetbuffer <mods>lgetbuffer <args>
57 command! -nargs=* Xaddbuffer <mods>laddbuffer <args>
58 command! -nargs=* Xrewind <mods>lrewind <args>
Bram Moolenaar99895ea2017-04-20 22:44:47 +020059 command! -count -nargs=* -bang Xnext <mods><count>lnext<bang> <args>
60 command! -count -nargs=* -bang Xprev <mods><count>lprev<bang> <args>
Bram Moolenaar0fcc7c62016-07-02 21:22:52 +020061 command! -nargs=* -bang Xfirst <mods>lfirst<bang> <args>
62 command! -nargs=* -bang Xlast <mods>llast<bang> <args>
63 command! -nargs=* -bang Xnfile <mods>lnfile<bang> <args>
64 command! -nargs=* -bang Xpfile <mods>lpfile<bang> <args>
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +020065 command! -nargs=* Xexpr <mods>lexpr <args>
Bram Moolenaaree85df32017-03-19 14:19:50 +010066 command! -range -nargs=* Xvimgrep <mods><count>lvimgrep <args>
67 command! -nargs=* Xvimgrepadd <mods>lvimgrepadd <args>
Bram Moolenaar049cba92016-06-26 14:38:04 +020068 command! -nargs=* Xgrep <mods> lgrep <args>
69 command! -nargs=* Xgrepadd <mods> lgrepadd <args>
70 command! -nargs=* Xhelpgrep lhelpgrep <args>
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +020071 let g:Xgetlist = function('getloclist', [0])
72 let g:Xsetlist = function('setloclist', [0])
Bram Moolenaarb6fa30c2017-03-29 14:19:25 +020073 call setloclist(0, [], 'f')
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +020074 endif
Bram Moolenaar2b946c92016-11-12 18:14:44 +010075endfunc
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +020076
Bram Moolenaarda59dd52016-01-05 21:59:58 +010077" Tests for the :clist and :llist commands
Bram Moolenaar2b946c92016-11-12 18:14:44 +010078func XlistTests(cchar)
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +020079 call s:setup_commands(a:cchar)
Bram Moolenaarda59dd52016-01-05 21:59:58 +010080
Bram Moolenaarb6fa30c2017-03-29 14:19:25 +020081 if a:cchar == 'l'
82 call assert_fails('llist', 'E776:')
83 endif
Bram Moolenaarda59dd52016-01-05 21:59:58 +010084 " With an empty list, command should return error
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +020085 Xgetexpr []
86 silent! Xlist
Bram Moolenaarda59dd52016-01-05 21:59:58 +010087 call assert_true(v:errmsg ==# 'E42: No Errors')
88
89 " Populate the list and then try
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +020090 Xgetexpr ['non-error 1', 'Xtestfile1:1:3:Line1',
Bram Moolenaarda59dd52016-01-05 21:59:58 +010091 \ 'non-error 2', 'Xtestfile2:2:2:Line2',
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +020092 \ 'non-error 3', 'Xtestfile3:3:1:Line3']
Bram Moolenaarda59dd52016-01-05 21:59:58 +010093
94 " List only valid entries
Bram Moolenaaree85df32017-03-19 14:19:50 +010095 let l = split(execute('Xlist', ''), "\n")
Bram Moolenaarda59dd52016-01-05 21:59:58 +010096 call assert_equal([' 2 Xtestfile1:1 col 3: Line1',
97 \ ' 4 Xtestfile2:2 col 2: Line2',
98 \ ' 6 Xtestfile3:3 col 1: Line3'], l)
99
100 " List all the entries
Bram Moolenaaree85df32017-03-19 14:19:50 +0100101 let l = split(execute('Xlist!', ''), "\n")
Bram Moolenaarda59dd52016-01-05 21:59:58 +0100102 call assert_equal([' 1: non-error 1', ' 2 Xtestfile1:1 col 3: Line1',
103 \ ' 3: non-error 2', ' 4 Xtestfile2:2 col 2: Line2',
104 \ ' 5: non-error 3', ' 6 Xtestfile3:3 col 1: Line3'], l)
105
106 " List a range of errors
Bram Moolenaaree85df32017-03-19 14:19:50 +0100107 let l = split(execute('Xlist 3,6', ''), "\n")
Bram Moolenaarda59dd52016-01-05 21:59:58 +0100108 call assert_equal([' 4 Xtestfile2:2 col 2: Line2',
109 \ ' 6 Xtestfile3:3 col 1: Line3'], l)
110
Bram Moolenaaree85df32017-03-19 14:19:50 +0100111 let l = split(execute('Xlist! 3,4', ''), "\n")
Bram Moolenaarda59dd52016-01-05 21:59:58 +0100112 call assert_equal([' 3: non-error 2', ' 4 Xtestfile2:2 col 2: Line2'], l)
113
Bram Moolenaaree85df32017-03-19 14:19:50 +0100114 let l = split(execute('Xlist -6,-4', ''), "\n")
Bram Moolenaarda59dd52016-01-05 21:59:58 +0100115 call assert_equal([' 2 Xtestfile1:1 col 3: Line1'], l)
116
Bram Moolenaaree85df32017-03-19 14:19:50 +0100117 let l = split(execute('Xlist! -5,-3', ''), "\n")
Bram Moolenaarda59dd52016-01-05 21:59:58 +0100118 call assert_equal([' 2 Xtestfile1:1 col 3: Line1',
119 \ ' 3: non-error 2', ' 4 Xtestfile2:2 col 2: Line2'], l)
Bram Moolenaar391b1dd2017-03-04 13:47:11 +0100120
121 " Test for '+'
Bram Moolenaaree85df32017-03-19 14:19:50 +0100122 let l = split(execute('Xlist! +2', ''), "\n")
Bram Moolenaar391b1dd2017-03-04 13:47:11 +0100123 call assert_equal([' 2 Xtestfile1:1 col 3: Line1',
124 \ ' 3: non-error 2', ' 4 Xtestfile2:2 col 2: Line2'], l)
Bram Moolenaaree85df32017-03-19 14:19:50 +0100125
126 " Different types of errors
127 call g:Xsetlist([{'lnum':10,'col':5,'type':'W', 'text':'Warning','nr':11},
128 \ {'lnum':20,'col':10,'type':'e','text':'Error','nr':22},
129 \ {'lnum':30,'col':15,'type':'i','text':'Info','nr':33},
130 \ {'lnum':40,'col':20,'type':'x', 'text':'Other','nr':44},
131 \ {'lnum':50,'col':25,'type':"\<C-A>",'text':'one','nr':55}])
132 let l = split(execute('Xlist', ""), "\n")
133 call assert_equal([' 1:10 col 5 warning 11: Warning',
134 \ ' 2:20 col 10 error 22: Error',
135 \ ' 3:30 col 15 info 33: Info',
136 \ ' 4:40 col 20 x 44: Other',
137 \ ' 5:50 col 25 55: one'], l)
138
139 " Error cases
140 call assert_fails('Xlist abc', 'E488:')
Bram Moolenaar2b946c92016-11-12 18:14:44 +0100141endfunc
Bram Moolenaarda59dd52016-01-05 21:59:58 +0100142
Bram Moolenaar2b946c92016-11-12 18:14:44 +0100143func Test_clist()
Bram Moolenaarda59dd52016-01-05 21:59:58 +0100144 call XlistTests('c')
145 call XlistTests('l')
Bram Moolenaar2b946c92016-11-12 18:14:44 +0100146endfunc
Bram Moolenaarda59dd52016-01-05 21:59:58 +0100147
148" Tests for the :colder, :cnewer, :lolder and :lnewer commands
149" Note that this test assumes that a quickfix/location list is
Bram Moolenaarcfc0a352016-01-09 20:23:00 +0100150" already set by the caller.
Bram Moolenaar2b946c92016-11-12 18:14:44 +0100151func XageTests(cchar)
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +0200152 call s:setup_commands(a:cchar)
Bram Moolenaarda59dd52016-01-05 21:59:58 +0100153
Bram Moolenaarb6fa30c2017-03-29 14:19:25 +0200154 let list = [{'bufnr': 1, 'lnum': 1}]
155 call g:Xsetlist(list)
156
Bram Moolenaarda59dd52016-01-05 21:59:58 +0100157 " Jumping to a non existent list should return error
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +0200158 silent! Xolder 99
Bram Moolenaarda59dd52016-01-05 21:59:58 +0100159 call assert_true(v:errmsg ==# 'E380: At bottom of quickfix stack')
160
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +0200161 silent! Xnewer 99
Bram Moolenaarda59dd52016-01-05 21:59:58 +0100162 call assert_true(v:errmsg ==# 'E381: At top of quickfix stack')
163
164 " Add three quickfix/location lists
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +0200165 Xgetexpr ['Xtestfile1:1:3:Line1']
166 Xgetexpr ['Xtestfile2:2:2:Line2']
167 Xgetexpr ['Xtestfile3:3:1:Line3']
Bram Moolenaarda59dd52016-01-05 21:59:58 +0100168
169 " Go back two lists
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +0200170 Xolder
171 let l = g:Xgetlist()
Bram Moolenaarda59dd52016-01-05 21:59:58 +0100172 call assert_equal('Line2', l[0].text)
173
174 " Go forward two lists
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +0200175 Xnewer
176 let l = g:Xgetlist()
Bram Moolenaarda59dd52016-01-05 21:59:58 +0100177 call assert_equal('Line3', l[0].text)
178
179 " Test for the optional count argument
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +0200180 Xolder 2
181 let l = g:Xgetlist()
Bram Moolenaarda59dd52016-01-05 21:59:58 +0100182 call assert_equal('Line1', l[0].text)
183
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +0200184 Xnewer 2
185 let l = g:Xgetlist()
Bram Moolenaarda59dd52016-01-05 21:59:58 +0100186 call assert_equal('Line3', l[0].text)
Bram Moolenaar2b946c92016-11-12 18:14:44 +0100187endfunc
Bram Moolenaarda59dd52016-01-05 21:59:58 +0100188
Bram Moolenaar2b946c92016-11-12 18:14:44 +0100189func Test_cage()
Bram Moolenaarda59dd52016-01-05 21:59:58 +0100190 call XageTests('c')
191 call XageTests('l')
Bram Moolenaar2b946c92016-11-12 18:14:44 +0100192endfunc
Bram Moolenaarda59dd52016-01-05 21:59:58 +0100193
194" Tests for the :cwindow, :lwindow :cclose, :lclose, :copen and :lopen
195" commands
Bram Moolenaar2b946c92016-11-12 18:14:44 +0100196func XwindowTests(cchar)
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +0200197 call s:setup_commands(a:cchar)
Bram Moolenaarda59dd52016-01-05 21:59:58 +0100198
Bram Moolenaarb6fa30c2017-03-29 14:19:25 +0200199 " Opening the location list window without any errors should fail
200 if a:cchar == 'l'
201 call assert_fails('lopen', 'E776:')
202 endif
203
Bram Moolenaarda59dd52016-01-05 21:59:58 +0100204 " Create a list with no valid entries
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +0200205 Xgetexpr ['non-error 1', 'non-error 2', 'non-error 3']
Bram Moolenaarda59dd52016-01-05 21:59:58 +0100206
207 " Quickfix/Location window should not open with no valid errors
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +0200208 Xwindow
Bram Moolenaarda59dd52016-01-05 21:59:58 +0100209 call assert_true(winnr('$') == 1)
210
211 " Create a list with valid entries
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +0200212 Xgetexpr ['Xtestfile1:1:3:Line1', 'Xtestfile2:2:2:Line2',
213 \ 'Xtestfile3:3:1:Line3']
Bram Moolenaarda59dd52016-01-05 21:59:58 +0100214
215 " Open the window
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +0200216 Xwindow
Bram Moolenaarda59dd52016-01-05 21:59:58 +0100217 call assert_true(winnr('$') == 2 && winnr() == 2 &&
218 \ getline('.') ==# 'Xtestfile1|1 col 3| Line1')
Bram Moolenaar537ef082016-07-09 17:56:19 +0200219 redraw!
Bram Moolenaarda59dd52016-01-05 21:59:58 +0100220
221 " Close the window
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +0200222 Xclose
Bram Moolenaarda59dd52016-01-05 21:59:58 +0100223 call assert_true(winnr('$') == 1)
224
225 " Create a list with no valid entries
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +0200226 Xgetexpr ['non-error 1', 'non-error 2', 'non-error 3']
Bram Moolenaarda59dd52016-01-05 21:59:58 +0100227
228 " Open the window
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +0200229 Xopen 5
Bram Moolenaarda59dd52016-01-05 21:59:58 +0100230 call assert_true(winnr('$') == 2 && getline('.') ==# '|| non-error 1'
231 \ && winheight('.') == 5)
232
233 " Opening the window again, should move the cursor to that window
234 wincmd t
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +0200235 Xopen 7
Bram Moolenaarda59dd52016-01-05 21:59:58 +0100236 call assert_true(winnr('$') == 2 && winnr() == 2 &&
237 \ winheight('.') == 7 &&
238 \ getline('.') ==# '|| non-error 1')
239
240
241 " Calling cwindow should close the quickfix window with no valid errors
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +0200242 Xwindow
Bram Moolenaarda59dd52016-01-05 21:59:58 +0100243 call assert_true(winnr('$') == 1)
Bram Moolenaarb6fa30c2017-03-29 14:19:25 +0200244
245 if a:cchar == 'c'
246 " Opening the quickfix window in multiple tab pages should reuse the
247 " quickfix buffer
248 Xgetexpr ['Xtestfile1:1:3:Line1', 'Xtestfile2:2:2:Line2',
249 \ 'Xtestfile3:3:1:Line3']
250 Xopen
251 let qfbufnum = bufnr('%')
252 tabnew
253 Xopen
254 call assert_equal(qfbufnum, bufnr('%'))
255 new | only | tabonly
256 endif
Bram Moolenaar2b946c92016-11-12 18:14:44 +0100257endfunc
Bram Moolenaarda59dd52016-01-05 21:59:58 +0100258
Bram Moolenaar2b946c92016-11-12 18:14:44 +0100259func Test_cwindow()
Bram Moolenaarda59dd52016-01-05 21:59:58 +0100260 call XwindowTests('c')
261 call XwindowTests('l')
Bram Moolenaar2b946c92016-11-12 18:14:44 +0100262endfunc
Bram Moolenaarda59dd52016-01-05 21:59:58 +0100263
264" Tests for the :cfile, :lfile, :caddfile, :laddfile, :cgetfile and :lgetfile
265" commands.
Bram Moolenaar2b946c92016-11-12 18:14:44 +0100266func XfileTests(cchar)
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +0200267 call s:setup_commands(a:cchar)
Bram Moolenaarda59dd52016-01-05 21:59:58 +0100268
269 call writefile(['Xtestfile1:700:10:Line 700',
270 \ 'Xtestfile2:800:15:Line 800'], 'Xqftestfile1')
271
272 enew!
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +0200273 Xfile Xqftestfile1
274 let l = g:Xgetlist()
Bram Moolenaarda59dd52016-01-05 21:59:58 +0100275 call assert_true(len(l) == 2 &&
276 \ l[0].lnum == 700 && l[0].col == 10 && l[0].text ==# 'Line 700' &&
277 \ l[1].lnum == 800 && l[1].col == 15 && l[1].text ==# 'Line 800')
278
Bram Moolenaar049cba92016-06-26 14:38:04 +0200279 " Test with a non existent file
280 call assert_fails('Xfile non_existent_file', 'E40')
281
Bram Moolenaarda59dd52016-01-05 21:59:58 +0100282 " Run cfile/lfile from a modified buffer
283 enew!
284 silent! put ='Quickfix'
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +0200285 silent! Xfile Xqftestfile1
Bram Moolenaarda59dd52016-01-05 21:59:58 +0100286 call assert_true(v:errmsg ==# 'E37: No write since last change (add ! to override)')
287
288 call writefile(['Xtestfile3:900:30:Line 900'], 'Xqftestfile1')
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +0200289 Xaddfile Xqftestfile1
290 let l = g:Xgetlist()
Bram Moolenaarda59dd52016-01-05 21:59:58 +0100291 call assert_true(len(l) == 3 &&
292 \ l[2].lnum == 900 && l[2].col == 30 && l[2].text ==# 'Line 900')
293
294 call writefile(['Xtestfile1:222:77:Line 222',
295 \ 'Xtestfile2:333:88:Line 333'], 'Xqftestfile1')
296
297 enew!
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +0200298 Xgetfile Xqftestfile1
299 let l = g:Xgetlist()
Bram Moolenaarda59dd52016-01-05 21:59:58 +0100300 call assert_true(len(l) == 2 &&
301 \ l[0].lnum == 222 && l[0].col == 77 && l[0].text ==# 'Line 222' &&
302 \ l[1].lnum == 333 && l[1].col == 88 && l[1].text ==# 'Line 333')
303
304 call delete('Xqftestfile1')
Bram Moolenaar2b946c92016-11-12 18:14:44 +0100305endfunc
Bram Moolenaarda59dd52016-01-05 21:59:58 +0100306
Bram Moolenaar2b946c92016-11-12 18:14:44 +0100307func Test_cfile()
Bram Moolenaarda59dd52016-01-05 21:59:58 +0100308 call XfileTests('c')
309 call XfileTests('l')
Bram Moolenaar2b946c92016-11-12 18:14:44 +0100310endfunc
Bram Moolenaarda59dd52016-01-05 21:59:58 +0100311
312" Tests for the :cbuffer, :lbuffer, :caddbuffer, :laddbuffer, :cgetbuffer and
313" :lgetbuffer commands.
Bram Moolenaar2b946c92016-11-12 18:14:44 +0100314func XbufferTests(cchar)
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +0200315 call s:setup_commands(a:cchar)
Bram Moolenaarda59dd52016-01-05 21:59:58 +0100316
317 enew!
318 silent! call setline(1, ['Xtestfile7:700:10:Line 700',
319 \ 'Xtestfile8:800:15:Line 800'])
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +0200320 Xbuffer!
321 let l = g:Xgetlist()
Bram Moolenaarda59dd52016-01-05 21:59:58 +0100322 call assert_true(len(l) == 2 &&
323 \ l[0].lnum == 700 && l[0].col == 10 && l[0].text ==# 'Line 700' &&
324 \ l[1].lnum == 800 && l[1].col == 15 && l[1].text ==# 'Line 800')
325
326 enew!
327 silent! call setline(1, ['Xtestfile9:900:55:Line 900',
328 \ 'Xtestfile10:950:66:Line 950'])
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +0200329 Xgetbuffer
330 let l = g:Xgetlist()
Bram Moolenaarda59dd52016-01-05 21:59:58 +0100331 call assert_true(len(l) == 2 &&
332 \ l[0].lnum == 900 && l[0].col == 55 && l[0].text ==# 'Line 900' &&
333 \ l[1].lnum == 950 && l[1].col == 66 && l[1].text ==# 'Line 950')
334
335 enew!
336 silent! call setline(1, ['Xtestfile11:700:20:Line 700',
337 \ 'Xtestfile12:750:25:Line 750'])
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +0200338 Xaddbuffer
339 let l = g:Xgetlist()
Bram Moolenaarda59dd52016-01-05 21:59:58 +0100340 call assert_true(len(l) == 4 &&
341 \ l[1].lnum == 950 && l[1].col == 66 && l[1].text ==# 'Line 950' &&
342 \ l[2].lnum == 700 && l[2].col == 20 && l[2].text ==# 'Line 700' &&
343 \ l[3].lnum == 750 && l[3].col == 25 && l[3].text ==# 'Line 750')
Bram Moolenaarab47c612016-06-14 22:02:26 +0200344 enew!
Bram Moolenaarda59dd52016-01-05 21:59:58 +0100345
Bram Moolenaaree85df32017-03-19 14:19:50 +0100346 " Check for invalid buffer
347 call assert_fails('Xbuffer 199', 'E474:')
348
349 " Check for unloaded buffer
350 edit Xtestfile1
351 let bnr = bufnr('%')
352 enew!
353 call assert_fails('Xbuffer ' . bnr, 'E681:')
354
355 " Check for invalid range
356 " Using Xbuffer will not run the range check in the cbuffer/lbuffer
357 " commands. So directly call the commands.
358 if (a:cchar == 'c')
359 call assert_fails('900,999cbuffer', 'E16:')
360 else
361 call assert_fails('900,999lbuffer', 'E16:')
362 endif
Bram Moolenaar2b946c92016-11-12 18:14:44 +0100363endfunc
Bram Moolenaarda59dd52016-01-05 21:59:58 +0100364
Bram Moolenaar2b946c92016-11-12 18:14:44 +0100365func Test_cbuffer()
Bram Moolenaarda59dd52016-01-05 21:59:58 +0100366 call XbufferTests('c')
367 call XbufferTests('l')
Bram Moolenaar2b946c92016-11-12 18:14:44 +0100368endfunc
Bram Moolenaarda59dd52016-01-05 21:59:58 +0100369
Bram Moolenaar2b946c92016-11-12 18:14:44 +0100370func XexprTests(cchar)
Bram Moolenaar0fcc7c62016-07-02 21:22:52 +0200371 call s:setup_commands(a:cchar)
372
373 call assert_fails('Xexpr 10', 'E777:')
Bram Moolenaar2b946c92016-11-12 18:14:44 +0100374endfunc
Bram Moolenaar0fcc7c62016-07-02 21:22:52 +0200375
Bram Moolenaar2b946c92016-11-12 18:14:44 +0100376func Test_cexpr()
Bram Moolenaar0fcc7c62016-07-02 21:22:52 +0200377 call XexprTests('c')
378 call XexprTests('l')
Bram Moolenaar2b946c92016-11-12 18:14:44 +0100379endfunc
Bram Moolenaar0fcc7c62016-07-02 21:22:52 +0200380
381" Tests for :cnext, :cprev, :cfirst, :clast commands
Bram Moolenaar2b946c92016-11-12 18:14:44 +0100382func Xtest_browse(cchar)
Bram Moolenaar0fcc7c62016-07-02 21:22:52 +0200383 call s:setup_commands(a:cchar)
384
Bram Moolenaarb6fa30c2017-03-29 14:19:25 +0200385 " Jumping to first or next location list entry without any error should
386 " result in failure
387 if a:cchar == 'l'
388 call assert_fails('lfirst', 'E776:')
389 call assert_fails('lnext', 'E776:')
390 endif
391
Bram Moolenaar0fcc7c62016-07-02 21:22:52 +0200392 call s:create_test_file('Xqftestfile1')
393 call s:create_test_file('Xqftestfile2')
394
395 Xgetexpr ['Xqftestfile1:5:Line5',
396 \ 'Xqftestfile1:6:Line6',
397 \ 'Xqftestfile2:10:Line10',
Bram Moolenaar99895ea2017-04-20 22:44:47 +0200398 \ 'Xqftestfile2:11:Line11',
399 \ 'RegularLine1',
400 \ 'RegularLine2']
Bram Moolenaar0fcc7c62016-07-02 21:22:52 +0200401
402 Xfirst
403 call assert_fails('Xprev', 'E553')
404 call assert_fails('Xpfile', 'E553')
405 Xnfile
406 call assert_equal('Xqftestfile2', bufname('%'))
407 call assert_equal(10, line('.'))
408 Xpfile
409 call assert_equal('Xqftestfile1', bufname('%'))
410 call assert_equal(6, line('.'))
411 Xlast
Bram Moolenaar99895ea2017-04-20 22:44:47 +0200412 Xprev
Bram Moolenaar0fcc7c62016-07-02 21:22:52 +0200413 call assert_equal('Xqftestfile2', bufname('%'))
414 call assert_equal(11, line('.'))
415 call assert_fails('Xnext', 'E553')
416 call assert_fails('Xnfile', 'E553')
417 Xrewind
418 call assert_equal('Xqftestfile1', bufname('%'))
419 call assert_equal(5, line('.'))
420
Bram Moolenaar99895ea2017-04-20 22:44:47 +0200421 10Xnext
422 call assert_equal('Xqftestfile2', bufname('%'))
423 call assert_equal(11, line('.'))
424 10Xprev
425 call assert_equal('Xqftestfile1', bufname('%'))
426 call assert_equal(5, line('.'))
427
Bram Moolenaaree85df32017-03-19 14:19:50 +0100428 Xexpr ""
429 call assert_fails('Xnext', 'E42:')
430
Bram Moolenaar0fcc7c62016-07-02 21:22:52 +0200431 call delete('Xqftestfile1')
432 call delete('Xqftestfile2')
Bram Moolenaar2b946c92016-11-12 18:14:44 +0100433endfunc
Bram Moolenaar0fcc7c62016-07-02 21:22:52 +0200434
Bram Moolenaar2b946c92016-11-12 18:14:44 +0100435func Test_browse()
Bram Moolenaar0fcc7c62016-07-02 21:22:52 +0200436 call Xtest_browse('c')
437 call Xtest_browse('l')
Bram Moolenaar2b946c92016-11-12 18:14:44 +0100438endfunc
Bram Moolenaar0fcc7c62016-07-02 21:22:52 +0200439
Bram Moolenaar2b946c92016-11-12 18:14:44 +0100440func Test_nomem()
Bram Moolenaar8e8df252016-05-25 21:23:21 +0200441 call test_alloc_fail(GetAllocId('qf_dirname_start'), 0, 0)
Bram Moolenaara260b872016-01-15 20:48:22 +0100442 call assert_fails('vimgrep vim runtest.vim', 'E342:')
Bram Moolenaar75bdf6a2016-01-07 21:25:08 +0100443
Bram Moolenaar8e8df252016-05-25 21:23:21 +0200444 call test_alloc_fail(GetAllocId('qf_dirname_now'), 0, 0)
Bram Moolenaara260b872016-01-15 20:48:22 +0100445 call assert_fails('vimgrep vim runtest.vim', 'E342:')
Bram Moolenaar75bdf6a2016-01-07 21:25:08 +0100446
Bram Moolenaar8e8df252016-05-25 21:23:21 +0200447 call test_alloc_fail(GetAllocId('qf_namebuf'), 0, 0)
Bram Moolenaara260b872016-01-15 20:48:22 +0100448 call assert_fails('cfile runtest.vim', 'E342:')
Bram Moolenaar75bdf6a2016-01-07 21:25:08 +0100449
Bram Moolenaar8e8df252016-05-25 21:23:21 +0200450 call test_alloc_fail(GetAllocId('qf_errmsg'), 0, 0)
Bram Moolenaara260b872016-01-15 20:48:22 +0100451 call assert_fails('cfile runtest.vim', 'E342:')
Bram Moolenaar75bdf6a2016-01-07 21:25:08 +0100452
Bram Moolenaar8e8df252016-05-25 21:23:21 +0200453 call test_alloc_fail(GetAllocId('qf_pattern'), 0, 0)
Bram Moolenaara260b872016-01-15 20:48:22 +0100454 call assert_fails('cfile runtest.vim', 'E342:')
Bram Moolenaar75bdf6a2016-01-07 21:25:08 +0100455
456endfunc
457
Bram Moolenaar2b946c92016-11-12 18:14:44 +0100458func s:test_xhelpgrep(cchar)
Bram Moolenaar049cba92016-06-26 14:38:04 +0200459 call s:setup_commands(a:cchar)
460 Xhelpgrep quickfix
461 Xopen
462 if a:cchar == 'c'
463 let title_text = ':helpgrep quickfix'
464 else
465 let title_text = ':lhelpgrep quickfix'
466 endif
467 call assert_true(w:quickfix_title =~ title_text, w:quickfix_title)
Bram Moolenaar99895ea2017-04-20 22:44:47 +0200468
469 " Jumping to a help topic should open the help window
470 only
471 Xnext
472 call assert_true(&buftype == 'help')
473 call assert_true(winnr('$') == 2)
474 " Jumping to the next match should reuse the help window
475 Xnext
476 call assert_true(&buftype == 'help')
477 call assert_true(winnr() == 1)
478 call assert_true(winnr('$') == 2)
479 " Jumping to the next match from the quickfix window should reuse the help
480 " window
481 Xopen
482 Xnext
483 call assert_true(&buftype == 'help')
484 call assert_true(winnr() == 1)
485 call assert_true(winnr('$') == 2)
486
Bram Moolenaar62ef7972016-01-19 14:51:54 +0100487 " This wipes out the buffer, make sure that doesn't cause trouble.
Bram Moolenaar049cba92016-06-26 14:38:04 +0200488 Xclose
Bram Moolenaaree85df32017-03-19 14:19:50 +0100489
Bram Moolenaar99895ea2017-04-20 22:44:47 +0200490 new | only
491
Bram Moolenaaree85df32017-03-19 14:19:50 +0100492 " Search for non existing help string
493 call assert_fails('Xhelpgrep a1b2c3', 'E480:')
Bram Moolenaar2b946c92016-11-12 18:14:44 +0100494endfunc
Bram Moolenaar049cba92016-06-26 14:38:04 +0200495
Bram Moolenaar2b946c92016-11-12 18:14:44 +0100496func Test_helpgrep()
Bram Moolenaar049cba92016-06-26 14:38:04 +0200497 call s:test_xhelpgrep('c')
Bram Moolenaarcf25fdb2016-08-03 21:04:53 +0200498 helpclose
Bram Moolenaar049cba92016-06-26 14:38:04 +0200499 call s:test_xhelpgrep('l')
Bram Moolenaar62ef7972016-01-19 14:51:54 +0100500endfunc
Bram Moolenaar75bdf6a2016-01-07 21:25:08 +0100501
Bram Moolenaar6920c722016-01-22 22:44:10 +0100502func Test_errortitle()
503 augroup QfBufWinEnter
504 au!
505 au BufWinEnter * :let g:a=get(w:, 'quickfix_title', 'NONE')
506 augroup END
507 copen
508 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'')'}]
509 call setqflist(a)
510 call assert_equal(':setqflist()', g:a)
511 augroup QfBufWinEnter
512 au!
513 augroup END
514 augroup! QfBufWinEnter
515endfunc
Bram Moolenaare27dba42016-03-15 14:11:10 +0100516
Bram Moolenaar5584df62016-03-18 21:00:51 +0100517func Test_vimgreptitle()
518 augroup QfBufWinEnter
519 au!
520 au BufWinEnter * :let g:a=get(w:, 'quickfix_title', 'NONE')
521 augroup END
522 try
523 vimgrep /pattern/j file
524 catch /E480/
525 endtry
526 copen
527 call assert_equal(': vimgrep /pattern/j file', g:a)
528 augroup QfBufWinEnter
529 au!
530 augroup END
531 augroup! QfBufWinEnter
532endfunc
533
Bram Moolenaar2b946c92016-11-12 18:14:44 +0100534func XqfTitleTests(cchar)
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +0200535 call s:setup_commands(a:cchar)
Bram Moolenaare27dba42016-03-15 14:11:10 +0100536
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +0200537 Xgetexpr ['file:1:1:message']
538 let l = g:Xgetlist()
Bram Moolenaare27dba42016-03-15 14:11:10 +0100539 if a:cchar == 'c'
540 call setqflist(l, 'r')
541 else
542 call setloclist(0, l, 'r')
543 endif
544
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +0200545 Xopen
Bram Moolenaare27dba42016-03-15 14:11:10 +0100546 if a:cchar == 'c'
547 let title = ':setqflist()'
548 else
549 let title = ':setloclist()'
550 endif
551 call assert_equal(title, w:quickfix_title)
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +0200552 Xclose
Bram Moolenaar2b946c92016-11-12 18:14:44 +0100553endfunc
Bram Moolenaare27dba42016-03-15 14:11:10 +0100554
555" Tests for quickfix window's title
Bram Moolenaar2b946c92016-11-12 18:14:44 +0100556func Test_qf_title()
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +0200557 call XqfTitleTests('c')
558 call XqfTitleTests('l')
Bram Moolenaar2b946c92016-11-12 18:14:44 +0100559endfunc
Bram Moolenaare27dba42016-03-15 14:11:10 +0100560
561" Tests for 'errorformat'
Bram Moolenaar2b946c92016-11-12 18:14:44 +0100562func Test_efm()
Bram Moolenaare27dba42016-03-15 14:11:10 +0100563 let save_efm = &efm
564 set efm=%EEEE%m,%WWWW%m,%+CCCC%.%#,%-GGGG%.%#
565 cgetexpr ['WWWW', 'EEEE', 'CCCC']
566 let l = strtrans(string(map(getqflist(), '[v:val.text, v:val.valid]')))
567 call assert_equal("[['W', 1], ['E^@CCCC', 1]]", l)
568 cgetexpr ['WWWW', 'GGGG', 'EEEE', 'CCCC']
569 let l = strtrans(string(map(getqflist(), '[v:val.text, v:val.valid]')))
570 call assert_equal("[['W', 1], ['E^@CCCC', 1]]", l)
571 cgetexpr ['WWWW', 'GGGG', 'ZZZZ', 'EEEE', 'CCCC', 'YYYY']
572 let l = strtrans(string(map(getqflist(), '[v:val.text, v:val.valid]')))
573 call assert_equal("[['W', 1], ['ZZZZ', 0], ['E^@CCCC', 1], ['YYYY', 0]]", l)
574 let &efm = save_efm
Bram Moolenaar2b946c92016-11-12 18:14:44 +0100575endfunc
Bram Moolenaar1ff2b642016-03-17 22:07:02 +0100576
577" This will test for problems in quickfix:
578" A. incorrectly copying location lists which caused the location list to show
579" a different name than the file that was actually being displayed.
580" B. not reusing the window for which the location list window is opened but
581" instead creating new windows.
582" C. make sure that the location list window is not reused instead of the
583" window it belongs to.
584"
585" Set up the test environment:
Bram Moolenaar2b946c92016-11-12 18:14:44 +0100586func ReadTestProtocol(name)
Bram Moolenaar1ff2b642016-03-17 22:07:02 +0100587 let base = substitute(a:name, '\v^test://(.*)%(\.[^.]+)?', '\1', '')
588 let word = substitute(base, '\v(.*)\..*', '\1', '')
589
590 setl modifiable
591 setl noreadonly
592 setl noswapfile
593 setl bufhidden=delete
594 %del _
595 " For problem 2:
596 " 'buftype' has to be set to reproduce the constant opening of new windows
597 setl buftype=nofile
598
599 call setline(1, word)
600
601 setl nomodified
602 setl nomodifiable
603 setl readonly
604 exe 'doautocmd BufRead ' . substitute(a:name, '\v^test://(.*)', '\1', '')
Bram Moolenaar2b946c92016-11-12 18:14:44 +0100605endfunc
Bram Moolenaar1ff2b642016-03-17 22:07:02 +0100606
Bram Moolenaar2b946c92016-11-12 18:14:44 +0100607func Test_locationlist()
Bram Moolenaar1ff2b642016-03-17 22:07:02 +0100608 enew
609
610 augroup testgroup
611 au!
612 autocmd BufReadCmd test://* call ReadTestProtocol(expand("<amatch>"))
613 augroup END
614
615 let words = [ "foo", "bar", "baz", "quux", "shmoo", "spam", "eggs" ]
616
617 let qflist = []
618 for word in words
619 call add(qflist, {'filename': 'test://' . word . '.txt', 'text': 'file ' . word . '.txt', })
620 " NOTE: problem 1:
621 " intentionally not setting 'lnum' so that the quickfix entries are not
622 " valid
623 call setloclist(0, qflist, ' ')
624 endfor
625
626 " Test A
627 lrewind
628 enew
629 lopen
Bram Moolenaar99895ea2017-04-20 22:44:47 +0200630 4lnext
Bram Moolenaar1ff2b642016-03-17 22:07:02 +0100631 vert split
632 wincmd L
633 lopen
634 wincmd p
635 lnext
636 let fileName = expand("%")
637 wincmd p
638 let locationListFileName = substitute(getline(line('.')), '\([^|]*\)|.*', '\1', '')
639 let fileName = substitute(fileName, '\\', '/', 'g')
640 let locationListFileName = substitute(locationListFileName, '\\', '/', 'g')
641 call assert_equal("test://bar.txt", fileName)
642 call assert_equal("test://bar.txt", locationListFileName)
643
644 wincmd n | only
645
646 " Test B:
647 lrewind
648 lopen
649 2
650 exe "normal \<CR>"
651 wincmd p
652 3
653 exe "normal \<CR>"
654 wincmd p
655 4
656 exe "normal \<CR>"
657 call assert_equal(2, winnr('$'))
658 wincmd n | only
659
660 " Test C:
661 lrewind
662 lopen
663 " Let's move the location list window to the top to check whether it (the
664 " first window found) will be reused when we try to open new windows:
665 wincmd K
666 2
667 exe "normal \<CR>"
668 wincmd p
669 3
670 exe "normal \<CR>"
671 wincmd p
672 4
673 exe "normal \<CR>"
674 1wincmd w
675 call assert_equal('quickfix', &buftype)
676 2wincmd w
677 let bufferName = expand("%")
678 let bufferName = substitute(bufferName, '\\', '/', 'g')
679 call assert_equal('test://quux.txt', bufferName)
680
681 wincmd n | only
682
683 augroup! testgroup
Bram Moolenaaree85df32017-03-19 14:19:50 +0100684endfunc
Bram Moolenaar0899d692016-03-19 13:35:03 +0100685
Bram Moolenaar2b946c92016-11-12 18:14:44 +0100686func Test_locationlist_curwin_was_closed()
Bram Moolenaar0899d692016-03-19 13:35:03 +0100687 augroup testgroup
688 au!
Bram Moolenaard106e5b2016-04-21 19:38:07 +0200689 autocmd BufReadCmd test_curwin.txt call R(expand("<amatch>"))
Bram Moolenaar0899d692016-03-19 13:35:03 +0100690 augroup END
691
Bram Moolenaar2b946c92016-11-12 18:14:44 +0100692 func! R(n)
Bram Moolenaar0899d692016-03-19 13:35:03 +0100693 quit
694 endfunc
695
696 new
697 let q = []
Bram Moolenaard106e5b2016-04-21 19:38:07 +0200698 call add(q, {'filename': 'test_curwin.txt' })
Bram Moolenaar0899d692016-03-19 13:35:03 +0100699 call setloclist(0, q)
700 call assert_fails('lrewind', 'E924:')
701
702 augroup! testgroup
Bram Moolenaaree85df32017-03-19 14:19:50 +0100703endfunc
Bram Moolenaar7eba3d22016-03-19 22:54:09 +0100704
Bram Moolenaar2b946c92016-11-12 18:14:44 +0100705func Test_locationlist_cross_tab_jump()
Bram Moolenaar0a9046f2016-10-15 19:28:13 +0200706 call writefile(['loclistfoo'], 'loclistfoo')
707 call writefile(['loclistbar'], 'loclistbar')
708 set switchbuf=usetab
709
710 edit loclistfoo
711 tabedit loclistbar
712 silent lgrep loclistfoo loclist*
713 call assert_equal(1, tabpagenr())
714
715 enew | only | tabonly
716 set switchbuf&vim
717 call delete('loclistfoo')
718 call delete('loclistbar')
Bram Moolenaar2b946c92016-11-12 18:14:44 +0100719endfunc
Bram Moolenaar0a9046f2016-10-15 19:28:13 +0200720
Bram Moolenaar7eba3d22016-03-19 22:54:09 +0100721" More tests for 'errorformat'
Bram Moolenaar2b946c92016-11-12 18:14:44 +0100722func Test_efm1()
Bram Moolenaar7eba3d22016-03-19 22:54:09 +0100723 if !has('unix')
724 " The 'errorformat' setting is different on non-Unix systems.
725 " This test works only on Unix-like systems.
726 return
727 endif
728
729 let l = [
730 \ '"Xtestfile", line 4.12: 1506-045 (S) Undeclared identifier fd_set.',
731 \ '"Xtestfile", line 6 col 19; this is an error',
732 \ 'gcc -c -DHAVE_CONFIsing-prototypes -I/usr/X11R6/include version.c',
733 \ 'Xtestfile:9: parse error before `asd''',
734 \ 'make: *** [vim] Error 1',
735 \ 'in file "Xtestfile" linenr 10: there is an error',
736 \ '',
737 \ '2 returned',
738 \ '"Xtestfile", line 11 col 1; this is an error',
739 \ '"Xtestfile", line 12 col 2; this is another error',
740 \ '"Xtestfile", line 14:10; this is an error in column 10',
741 \ '=Xtestfile=, line 15:10; this is another error, but in vcol 10 this time',
742 \ '"Xtestfile", linenr 16: yet another problem',
743 \ 'Error in "Xtestfile" at line 17:',
744 \ 'x should be a dot',
745 \ ' xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 17',
746 \ ' ^',
747 \ 'Error in "Xtestfile" at line 18:',
748 \ 'x should be a dot',
749 \ ' xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 18',
750 \ '.............^',
751 \ 'Error in "Xtestfile" at line 19:',
752 \ 'x should be a dot',
753 \ ' xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 19',
754 \ '--------------^',
755 \ 'Error in "Xtestfile" at line 20:',
756 \ 'x should be a dot',
757 \ ' xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 20',
758 \ ' ^',
759 \ '',
760 \ 'Does anyone know what is the problem and how to correction it?',
761 \ '"Xtestfile", line 21 col 9: What is the title of the quickfix window?',
762 \ '"Xtestfile", line 22 col 9: What is the title of the quickfix window?'
763 \ ]
764
765 call writefile(l, 'Xerrorfile1')
766 call writefile(l[:-2], 'Xerrorfile2')
767
768 let m = [
769 \ ' xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 2',
770 \ ' xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 3',
771 \ ' xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 4',
772 \ ' xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 5',
773 \ ' xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 6',
774 \ ' xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 7',
775 \ ' xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 8',
776 \ ' xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 9',
777 \ ' xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 10',
778 \ ' xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 11',
779 \ ' xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 12',
780 \ ' xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 13',
781 \ ' xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 14',
782 \ ' xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 15',
783 \ ' xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 16',
784 \ ' xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 17',
785 \ ' xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 18',
786 \ ' xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 19',
787 \ ' xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 20',
788 \ ' xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 21',
789 \ ' xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 22'
790 \ ]
791 call writefile(m, 'Xtestfile')
792
793 let save_efm = &efm
794 set efm+==%f=\\,\ line\ %l%*\\D%v%*[^\ ]\ %m
795 set efm^=%AError\ in\ \"%f\"\ at\ line\ %l:,%Z%p^,%C%m
796
797 exe 'cf Xerrorfile2'
798 clast
799 copen
800 call assert_equal(':cf Xerrorfile2', w:quickfix_title)
801 wincmd p
802
803 exe 'cf Xerrorfile1'
804 call assert_equal([4, 12], [line('.'), col('.')])
805 cn
806 call assert_equal([6, 19], [line('.'), col('.')])
807 cn
808 call assert_equal([9, 2], [line('.'), col('.')])
809 cn
810 call assert_equal([10, 2], [line('.'), col('.')])
811 cn
812 call assert_equal([11, 1], [line('.'), col('.')])
813 cn
814 call assert_equal([12, 2], [line('.'), col('.')])
815 cn
816 call assert_equal([14, 10], [line('.'), col('.')])
817 cn
818 call assert_equal([15, 3, 10], [line('.'), col('.'), virtcol('.')])
819 cn
820 call assert_equal([16, 2], [line('.'), col('.')])
821 cn
822 call assert_equal([17, 6], [line('.'), col('.')])
823 cn
824 call assert_equal([18, 7], [line('.'), col('.')])
825 cn
826 call assert_equal([19, 8], [line('.'), col('.')])
827 cn
828 call assert_equal([20, 9], [line('.'), col('.')])
829 clast
830 cprev
831 cprev
832 wincmd w
833 call assert_equal(':cf Xerrorfile1', w:quickfix_title)
834 wincmd p
835
836 let &efm = save_efm
837 call delete('Xerrorfile1')
838 call delete('Xerrorfile2')
839 call delete('Xtestfile')
Bram Moolenaaree85df32017-03-19 14:19:50 +0100840endfunc
Bram Moolenaarffec3c52016-03-23 20:55:42 +0100841
Bram Moolenaarab47c612016-06-14 22:02:26 +0200842" Test for quickfix directory stack support
Bram Moolenaar2b946c92016-11-12 18:14:44 +0100843func s:dir_stack_tests(cchar)
Bram Moolenaar38df43b2016-06-20 21:41:12 +0200844 call s:setup_commands(a:cchar)
845
Bram Moolenaarab47c612016-06-14 22:02:26 +0200846 let save_efm=&efm
847 set efm=%DEntering\ dir\ '%f',%f:%l:%m,%XLeaving\ dir\ '%f'
848
Bram Moolenaar361c8f02016-07-02 15:41:47 +0200849 let lines = ["Entering dir 'dir1/a'",
850 \ 'habits2.txt:1:Nine Healthy Habits',
851 \ "Entering dir 'b'",
852 \ 'habits3.txt:2:0 Hours of television',
853 \ 'habits2.txt:7:5 Small meals',
854 \ "Entering dir 'dir1/c'",
855 \ 'habits4.txt:3:1 Hour of exercise',
856 \ "Leaving dir 'dir1/c'",
857 \ "Leaving dir 'dir1/a'",
858 \ 'habits1.txt:4:2 Liters of water',
859 \ "Entering dir 'dir2'",
860 \ 'habits5.txt:5:3 Cups of hot green tea',
861 \ "Leaving dir 'dir2'"
862 \]
Bram Moolenaarab47c612016-06-14 22:02:26 +0200863
Bram Moolenaar361c8f02016-07-02 15:41:47 +0200864 Xexpr ""
865 for l in lines
866 Xaddexpr l
867 endfor
Bram Moolenaarab47c612016-06-14 22:02:26 +0200868
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +0200869 let qf = g:Xgetlist()
Bram Moolenaarab47c612016-06-14 22:02:26 +0200870
871 call assert_equal('dir1/a/habits2.txt', bufname(qf[1].bufnr))
872 call assert_equal(1, qf[1].lnum)
873 call assert_equal('dir1/a/b/habits3.txt', bufname(qf[3].bufnr))
874 call assert_equal(2, qf[3].lnum)
875 call assert_equal('dir1/a/habits2.txt', bufname(qf[4].bufnr))
876 call assert_equal(7, qf[4].lnum)
877 call assert_equal('dir1/c/habits4.txt', bufname(qf[6].bufnr))
878 call assert_equal(3, qf[6].lnum)
879 call assert_equal('habits1.txt', bufname(qf[9].bufnr))
880 call assert_equal(4, qf[9].lnum)
881 call assert_equal('dir2/habits5.txt', bufname(qf[11].bufnr))
882 call assert_equal(5, qf[11].lnum)
883
884 let &efm=save_efm
Bram Moolenaar2b946c92016-11-12 18:14:44 +0100885endfunc
Bram Moolenaarab47c612016-06-14 22:02:26 +0200886
887" Tests for %D and %X errorformat options
Bram Moolenaar2b946c92016-11-12 18:14:44 +0100888func Test_efm_dirstack()
Bram Moolenaarab47c612016-06-14 22:02:26 +0200889 " Create the directory stack and files
890 call mkdir('dir1')
891 call mkdir('dir1/a')
892 call mkdir('dir1/a/b')
893 call mkdir('dir1/c')
894 call mkdir('dir2')
895
896 let lines = ["Nine Healthy Habits",
897 \ "0 Hours of television",
898 \ "1 Hour of exercise",
899 \ "2 Liters of water",
900 \ "3 Cups of hot green tea",
901 \ "4 Short mental breaks",
902 \ "5 Small meals",
903 \ "6 AM wake up time",
904 \ "7 Minutes of laughter",
905 \ "8 Hours of sleep (at least)",
906 \ "9 PM end of the day and off to bed"
907 \ ]
908 call writefile(lines, 'habits1.txt')
909 call writefile(lines, 'dir1/a/habits2.txt')
910 call writefile(lines, 'dir1/a/b/habits3.txt')
911 call writefile(lines, 'dir1/c/habits4.txt')
912 call writefile(lines, 'dir2/habits5.txt')
913
914 call s:dir_stack_tests('c')
915 call s:dir_stack_tests('l')
916
917 call delete('dir1', 'rf')
918 call delete('dir2', 'rf')
919 call delete('habits1.txt')
Bram Moolenaar2b946c92016-11-12 18:14:44 +0100920endfunc
Bram Moolenaarab47c612016-06-14 22:02:26 +0200921
Bram Moolenaar9b457942016-10-09 16:10:05 +0200922" Test for resync after continuing an ignored message
Bram Moolenaar2b946c92016-11-12 18:14:44 +0100923func Xefm_ignore_continuations(cchar)
Bram Moolenaar9b457942016-10-09 16:10:05 +0200924 call s:setup_commands(a:cchar)
925
926 let save_efm = &efm
927
928 let &efm =
929 \ '%Eerror %m %l,' .
930 \ '%-Wignored %m %l,' .
931 \ '%+Cmore ignored %m %l,' .
932 \ '%Zignored end'
933 Xgetexpr ['ignored warning 1', 'more ignored continuation 2', 'ignored end', 'error resync 4']
934 let l = map(g:Xgetlist(), '[v:val.text, v:val.valid, v:val.lnum, v:val.type]')
935 call assert_equal([['resync', 1, 4, 'E']], l)
936
937 let &efm = save_efm
Bram Moolenaar2b946c92016-11-12 18:14:44 +0100938endfunc
Bram Moolenaar9b457942016-10-09 16:10:05 +0200939
Bram Moolenaar2b946c92016-11-12 18:14:44 +0100940func Test_efm_ignore_continuations()
Bram Moolenaar9b457942016-10-09 16:10:05 +0200941 call Xefm_ignore_continuations('c')
942 call Xefm_ignore_continuations('l')
Bram Moolenaar2b946c92016-11-12 18:14:44 +0100943endfunc
Bram Moolenaar9b457942016-10-09 16:10:05 +0200944
Bram Moolenaar0fcc7c62016-07-02 21:22:52 +0200945" Tests for invalid error format specifies
Bram Moolenaar2b946c92016-11-12 18:14:44 +0100946func Xinvalid_efm_Tests(cchar)
Bram Moolenaar0fcc7c62016-07-02 21:22:52 +0200947 call s:setup_commands(a:cchar)
948
Bram Moolenaar049cba92016-06-26 14:38:04 +0200949 let save_efm = &efm
950
Bram Moolenaar0fcc7c62016-07-02 21:22:52 +0200951 set efm=%f:%l:%m,%f:%f:%l:%m
952 call assert_fails('Xexpr "abc.txt:1:Hello world"', 'E372:')
953
954 set efm=%f:%l:%m,%f:%l:%r:%m
955 call assert_fails('Xexpr "abc.txt:1:Hello world"', 'E373:')
956
957 set efm=%f:%l:%m,%O:%f:%l:%m
958 call assert_fails('Xexpr "abc.txt:1:Hello world"', 'E373:')
959
960 set efm=%f:%l:%m,%f:%l:%*[^a-z
961 call assert_fails('Xexpr "abc.txt:1:Hello world"', 'E374:')
962
963 set efm=%f:%l:%m,%f:%l:%*c
964 call assert_fails('Xexpr "abc.txt:1:Hello world"', 'E375:')
965
966 set efm=%f:%l:%m,%L%M%N
967 call assert_fails('Xexpr "abc.txt:1:Hello world"', 'E376:')
968
969 set efm=%f:%l:%m,%f:%l:%m:%R
970 call assert_fails('Xexpr "abc.txt:1:Hello world"', 'E377:')
971
972 set efm=
973 call assert_fails('Xexpr "abc.txt:1:Hello world"', 'E378:')
974
975 set efm=%DEntering\ dir\ abc,%f:%l:%m
976 call assert_fails('Xexpr ["Entering dir abc", "abc.txt:1:Hello world"]', 'E379:')
977
978 let &efm = save_efm
Bram Moolenaar2b946c92016-11-12 18:14:44 +0100979endfunc
Bram Moolenaar0fcc7c62016-07-02 21:22:52 +0200980
Bram Moolenaar2b946c92016-11-12 18:14:44 +0100981func Test_invalid_efm()
Bram Moolenaar0fcc7c62016-07-02 21:22:52 +0200982 call Xinvalid_efm_Tests('c')
983 call Xinvalid_efm_Tests('l')
Bram Moolenaar2b946c92016-11-12 18:14:44 +0100984endfunc
Bram Moolenaar0fcc7c62016-07-02 21:22:52 +0200985
986" TODO:
987" Add tests for the following formats in 'errorformat'
988" %r %O
Bram Moolenaar2b946c92016-11-12 18:14:44 +0100989func Test_efm2()
Bram Moolenaar0fcc7c62016-07-02 21:22:52 +0200990 let save_efm = &efm
Bram Moolenaar049cba92016-06-26 14:38:04 +0200991
992 " Test for %s format in efm
993 set efm=%f:%s
994 cexpr 'Xtestfile:Line search text'
Bram Moolenaar049cba92016-06-26 14:38:04 +0200995 let l = getqflist()
996 call assert_equal(l[0].pattern, '^\VLine search text\$')
997 call assert_equal(l[0].lnum, 0)
998
Bram Moolenaaree85df32017-03-19 14:19:50 +0100999 let l = split(execute('clist', ''), "\n")
1000 call assert_equal([' 1 Xtestfile:^\VLine search text\$: '], l)
1001
Bram Moolenaar0fcc7c62016-07-02 21:22:52 +02001002 " Test for %P, %Q and %t format specifiers
Bram Moolenaar049cba92016-06-26 14:38:04 +02001003 let lines=["[Xtestfile1]",
1004 \ "(1,17) error: ';' missing",
1005 \ "(21,2) warning: variable 'z' not defined",
1006 \ "(67,3) error: end of file found before string ended",
Bram Moolenaaree85df32017-03-19 14:19:50 +01001007 \ "--",
Bram Moolenaar049cba92016-06-26 14:38:04 +02001008 \ "",
1009 \ "[Xtestfile2]",
Bram Moolenaaree85df32017-03-19 14:19:50 +01001010 \ "--",
Bram Moolenaar049cba92016-06-26 14:38:04 +02001011 \ "",
1012 \ "[Xtestfile3]",
1013 \ "NEW compiler v1.1",
1014 \ "(2,2) warning: variable 'x' not defined",
Bram Moolenaaree85df32017-03-19 14:19:50 +01001015 \ "(67,3) warning: 's' already defined",
1016 \ "--"
Bram Moolenaar049cba92016-06-26 14:38:04 +02001017 \]
Bram Moolenaaree85df32017-03-19 14:19:50 +01001018 set efm=%+P[%f]%r,(%l\\,%c)%*[\ ]%t%*[^:]:\ %m,%+Q--%r
Bram Moolenaar391b1dd2017-03-04 13:47:11 +01001019 " To exercise the push/pop file functionality in quickfix, the test files
1020 " need to be created.
1021 call writefile(['Line1'], 'Xtestfile1')
1022 call writefile(['Line2'], 'Xtestfile2')
1023 call writefile(['Line3'], 'Xtestfile3')
Bram Moolenaar361c8f02016-07-02 15:41:47 +02001024 cexpr ""
1025 for l in lines
1026 caddexpr l
1027 endfor
Bram Moolenaar049cba92016-06-26 14:38:04 +02001028 let l = getqflist()
Bram Moolenaaree85df32017-03-19 14:19:50 +01001029 call assert_equal(12, len(l))
Bram Moolenaar049cba92016-06-26 14:38:04 +02001030 call assert_equal(21, l[2].lnum)
1031 call assert_equal(2, l[2].col)
Bram Moolenaar0fcc7c62016-07-02 21:22:52 +02001032 call assert_equal('w', l[2].type)
1033 call assert_equal('e', l[3].type)
Bram Moolenaar391b1dd2017-03-04 13:47:11 +01001034 call delete('Xtestfile1')
1035 call delete('Xtestfile2')
1036 call delete('Xtestfile3')
Bram Moolenaar0fcc7c62016-07-02 21:22:52 +02001037
1038 " Tests for %E, %C and %Z format specifiers
1039 let lines = ["Error 275",
1040 \ "line 42",
1041 \ "column 3",
1042 \ "' ' expected after '--'"
1043 \]
1044 set efm=%EError\ %n,%Cline\ %l,%Ccolumn\ %c,%Z%m
1045 cgetexpr lines
1046 let l = getqflist()
1047 call assert_equal(275, l[0].nr)
1048 call assert_equal(42, l[0].lnum)
1049 call assert_equal(3, l[0].col)
1050 call assert_equal('E', l[0].type)
1051 call assert_equal("\n' ' expected after '--'", l[0].text)
1052
1053 " Test for %>
1054 let lines = ["Error in line 147 of foo.c:",
1055 \"unknown variable 'i'"
1056 \]
1057 set efm=unknown\ variable\ %m,%E%>Error\ in\ line\ %l\ of\ %f:,%Z%m
1058 cgetexpr lines
1059 let l = getqflist()
1060 call assert_equal(147, l[0].lnum)
1061 call assert_equal('E', l[0].type)
1062 call assert_equal("\nunknown variable 'i'", l[0].text)
Bram Moolenaar049cba92016-06-26 14:38:04 +02001063
Bram Moolenaare87e6dd2016-07-17 19:25:04 +02001064 " Test for %A, %C and other formats
1065 let lines = [
1066 \"==============================================================",
1067 \"FAIL: testGetTypeIdCachesResult (dbfacadeTest.DjsDBFacadeTest)",
1068 \"--------------------------------------------------------------",
1069 \"Traceback (most recent call last):",
1070 \' File "unittests/dbfacadeTest.py", line 89, in testFoo',
1071 \" self.assertEquals(34, dtid)",
1072 \' File "/usr/lib/python2.2/unittest.py", line 286, in',
1073 \" failUnlessEqual",
1074 \" raise self.failureException, \\",
1075 \"AssertionError: 34 != 33",
1076 \"",
1077 \"--------------------------------------------------------------",
1078 \"Ran 27 tests in 0.063s"
1079 \]
1080 set efm=%C\ %.%#,%A\ \ File\ \"%f\"\\,\ line\ %l%.%#,%Z%[%^\ ]%\\@=%m
1081 cgetexpr lines
1082 let l = getqflist()
1083 call assert_equal(8, len(l))
1084 call assert_equal(89, l[4].lnum)
1085 call assert_equal(1, l[4].valid)
1086 call assert_equal('unittests/dbfacadeTest.py', bufname(l[4].bufnr))
1087
Bram Moolenaar99895ea2017-04-20 22:44:47 +02001088 " The following sequence of commands used to crash Vim
1089 set efm=%W%m
1090 cgetexpr ['msg1']
1091 let l = getqflist()
1092 call assert_equal(1, len(l), string(l))
1093 call assert_equal('msg1', l[0].text)
1094 set efm=%C%m
1095 lexpr 'msg2'
1096 let l = getloclist(0)
1097 call assert_equal(1, len(l), string(l))
1098 call assert_equal('msg2', l[0].text)
1099 lopen
1100 call setqflist([], 'r')
1101 caddbuf
1102 let l = getqflist()
1103 call assert_equal(1, len(l), string(l))
1104 call assert_equal('|| msg2', l[0].text)
1105
1106 new | only
Bram Moolenaar049cba92016-06-26 14:38:04 +02001107 let &efm = save_efm
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001108endfunc
Bram Moolenaar049cba92016-06-26 14:38:04 +02001109
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001110func XquickfixChangedByAutocmd(cchar)
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001111 call s:setup_commands(a:cchar)
Bram Moolenaarffec3c52016-03-23 20:55:42 +01001112 if a:cchar == 'c'
Bram Moolenaarffec3c52016-03-23 20:55:42 +01001113 let ErrorNr = 'E925'
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001114 func! ReadFunc()
Bram Moolenaarffec3c52016-03-23 20:55:42 +01001115 colder
1116 cgetexpr []
1117 endfunc
1118 else
Bram Moolenaarffec3c52016-03-23 20:55:42 +01001119 let ErrorNr = 'E926'
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001120 func! ReadFunc()
Bram Moolenaarffec3c52016-03-23 20:55:42 +01001121 lolder
1122 lgetexpr []
1123 endfunc
1124 endif
1125
1126 augroup testgroup
1127 au!
Bram Moolenaard106e5b2016-04-21 19:38:07 +02001128 autocmd BufReadCmd test_changed.txt call ReadFunc()
Bram Moolenaarffec3c52016-03-23 20:55:42 +01001129 augroup END
1130
Bram Moolenaard106e5b2016-04-21 19:38:07 +02001131 new | only
Bram Moolenaarffec3c52016-03-23 20:55:42 +01001132 let words = [ "a", "b" ]
1133 let qflist = []
1134 for word in words
Bram Moolenaard106e5b2016-04-21 19:38:07 +02001135 call add(qflist, {'filename': 'test_changed.txt'})
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001136 call g:Xsetlist(qflist, ' ')
Bram Moolenaarffec3c52016-03-23 20:55:42 +01001137 endfor
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001138 call assert_fails('Xrewind', ErrorNr . ':')
Bram Moolenaarffec3c52016-03-23 20:55:42 +01001139
1140 augroup! testgroup
1141endfunc
1142
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001143func Test_quickfix_was_changed_by_autocmd()
Bram Moolenaarffec3c52016-03-23 20:55:42 +01001144 call XquickfixChangedByAutocmd('c')
1145 call XquickfixChangedByAutocmd('l')
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001146endfunc
Bram Moolenaar8b201792016-03-25 15:01:10 +01001147
1148func Test_caddbuffer_to_empty()
1149 helpgr quickfix
1150 call setqflist([], 'r')
1151 cad
Bram Moolenaarf68f1d72016-03-25 17:14:06 +01001152 try
1153 cn
1154 catch
1155 " number of matches is unknown
1156 call assert_true(v:exception =~ 'E553:')
1157 endtry
Bram Moolenaar8b201792016-03-25 15:01:10 +01001158 quit!
1159endfunc
Bram Moolenaar89c64d52016-03-27 18:44:40 +02001160
1161func Test_cgetexpr_works()
1162 " this must not crash Vim
1163 cgetexpr [$x]
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001164 lgetexpr [$x]
Bram Moolenaar89c64d52016-03-27 18:44:40 +02001165endfunc
Bram Moolenaarc1808d52016-04-18 20:04:00 +02001166
1167" Tests for the setqflist() and setloclist() functions
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001168func SetXlistTests(cchar, bnum)
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001169 call s:setup_commands(a:cchar)
Bram Moolenaarc1808d52016-04-18 20:04:00 +02001170
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001171 call g:Xsetlist([{'bufnr': a:bnum, 'lnum': 1},
Bram Moolenaarc1808d52016-04-18 20:04:00 +02001172 \ {'bufnr': a:bnum, 'lnum': 2}])
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001173 let l = g:Xgetlist()
Bram Moolenaarc1808d52016-04-18 20:04:00 +02001174 call assert_equal(2, len(l))
1175 call assert_equal(2, l[1].lnum)
1176
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001177 Xnext
1178 call g:Xsetlist([{'bufnr': a:bnum, 'lnum': 3}], 'a')
1179 let l = g:Xgetlist()
Bram Moolenaarc1808d52016-04-18 20:04:00 +02001180 call assert_equal(3, len(l))
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001181 Xnext
Bram Moolenaarc1808d52016-04-18 20:04:00 +02001182 call assert_equal(3, line('.'))
1183
Bram Moolenaar2b2b8ae2016-05-24 19:59:51 +02001184 " Appending entries to the list should not change the cursor position
1185 " in the quickfix window
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001186 Xwindow
Bram Moolenaar2b2b8ae2016-05-24 19:59:51 +02001187 1
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001188 call g:Xsetlist([{'bufnr': a:bnum, 'lnum': 4},
Bram Moolenaar2b2b8ae2016-05-24 19:59:51 +02001189 \ {'bufnr': a:bnum, 'lnum': 5}], 'a')
1190 call assert_equal(1, line('.'))
1191 close
1192
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001193 call g:Xsetlist([{'bufnr': a:bnum, 'lnum': 3},
Bram Moolenaarc1808d52016-04-18 20:04:00 +02001194 \ {'bufnr': a:bnum, 'lnum': 4},
1195 \ {'bufnr': a:bnum, 'lnum': 5}], 'r')
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001196 let l = g:Xgetlist()
Bram Moolenaarc1808d52016-04-18 20:04:00 +02001197 call assert_equal(3, len(l))
1198 call assert_equal(5, l[2].lnum)
1199
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001200 call g:Xsetlist([])
1201 let l = g:Xgetlist()
Bram Moolenaarc1808d52016-04-18 20:04:00 +02001202 call assert_equal(0, len(l))
Bram Moolenaaree85df32017-03-19 14:19:50 +01001203
1204 " Error cases:
1205 " Refer to a non-existing buffer and pass a non-dictionary type
1206 call assert_fails("call g:Xsetlist([{'bufnr':998, 'lnum':4}," .
1207 \ " {'bufnr':999, 'lnum':5}])", 'E92:')
1208 call g:Xsetlist([[1, 2,3]])
1209 call assert_equal(0, len(g:Xgetlist()))
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001210endfunc
Bram Moolenaarc1808d52016-04-18 20:04:00 +02001211
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001212func Test_setqflist()
Bram Moolenaarc1808d52016-04-18 20:04:00 +02001213 new Xtestfile | only
1214 let bnum = bufnr('%')
1215 call setline(1, range(1,5))
1216
1217 call SetXlistTests('c', bnum)
1218 call SetXlistTests('l', bnum)
1219
Bram Moolenaar1cee6932016-06-09 22:17:22 +02001220 enew!
Bram Moolenaarc1808d52016-04-18 20:04:00 +02001221 call delete('Xtestfile')
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001222endfunc
Bram Moolenaard106e5b2016-04-21 19:38:07 +02001223
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001224func Xlist_empty_middle(cchar)
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001225 call s:setup_commands(a:cchar)
1226
Bram Moolenaar1cee6932016-06-09 22:17:22 +02001227 " create three quickfix lists
Bram Moolenaaree85df32017-03-19 14:19:50 +01001228 let @/ = 'Test_'
1229 Xvimgrep // test_quickfix.vim
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001230 let testlen = len(g:Xgetlist())
Bram Moolenaar1cee6932016-06-09 22:17:22 +02001231 call assert_true(testlen > 0)
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001232 Xvimgrep empty test_quickfix.vim
1233 call assert_true(len(g:Xgetlist()) > 0)
1234 Xvimgrep matches test_quickfix.vim
1235 let matchlen = len(g:Xgetlist())
Bram Moolenaar1cee6932016-06-09 22:17:22 +02001236 call assert_true(matchlen > 0)
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001237 Xolder
Bram Moolenaar1cee6932016-06-09 22:17:22 +02001238 " make the middle list empty
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001239 call g:Xsetlist([], 'r')
1240 call assert_true(len(g:Xgetlist()) == 0)
1241 Xolder
1242 call assert_equal(testlen, len(g:Xgetlist()))
1243 Xnewer
1244 Xnewer
1245 call assert_equal(matchlen, len(g:Xgetlist()))
Bram Moolenaar1cee6932016-06-09 22:17:22 +02001246endfunc
1247
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001248func Test_setqflist_empty_middle()
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001249 call Xlist_empty_middle('c')
1250 call Xlist_empty_middle('l')
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001251endfunc
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001252
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001253func Xlist_empty_older(cchar)
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001254 call s:setup_commands(a:cchar)
1255
Bram Moolenaar1cee6932016-06-09 22:17:22 +02001256 " create three quickfix lists
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001257 Xvimgrep one test_quickfix.vim
1258 let onelen = len(g:Xgetlist())
Bram Moolenaar1cee6932016-06-09 22:17:22 +02001259 call assert_true(onelen > 0)
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001260 Xvimgrep two test_quickfix.vim
1261 let twolen = len(g:Xgetlist())
Bram Moolenaar1cee6932016-06-09 22:17:22 +02001262 call assert_true(twolen > 0)
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001263 Xvimgrep three test_quickfix.vim
1264 let threelen = len(g:Xgetlist())
Bram Moolenaar1cee6932016-06-09 22:17:22 +02001265 call assert_true(threelen > 0)
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001266 Xolder 2
Bram Moolenaar1cee6932016-06-09 22:17:22 +02001267 " make the first list empty, check the others didn't change
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001268 call g:Xsetlist([], 'r')
1269 call assert_true(len(g:Xgetlist()) == 0)
1270 Xnewer
1271 call assert_equal(twolen, len(g:Xgetlist()))
1272 Xnewer
1273 call assert_equal(threelen, len(g:Xgetlist()))
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001274endfunc
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001275
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001276func Test_setqflist_empty_older()
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001277 call Xlist_empty_older('c')
1278 call Xlist_empty_older('l')
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001279endfunc
Bram Moolenaar1cee6932016-06-09 22:17:22 +02001280
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001281func XquickfixSetListWithAct(cchar)
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001282 call s:setup_commands(a:cchar)
1283
Bram Moolenaard106e5b2016-04-21 19:38:07 +02001284 let list1 = [{'filename': 'fnameA', 'text': 'A'},
1285 \ {'filename': 'fnameB', 'text': 'B'}]
1286 let list2 = [{'filename': 'fnameC', 'text': 'C'},
1287 \ {'filename': 'fnameD', 'text': 'D'},
1288 \ {'filename': 'fnameE', 'text': 'E'}]
1289
1290 " {action} is unspecified. Same as specifing ' '.
1291 new | only
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001292 silent! Xnewer 99
1293 call g:Xsetlist(list1)
1294 call g:Xsetlist(list2)
1295 let li = g:Xgetlist()
Bram Moolenaard106e5b2016-04-21 19:38:07 +02001296 call assert_equal(3, len(li))
1297 call assert_equal('C', li[0]['text'])
1298 call assert_equal('D', li[1]['text'])
1299 call assert_equal('E', li[2]['text'])
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001300 silent! Xolder
1301 let li = g:Xgetlist()
Bram Moolenaard106e5b2016-04-21 19:38:07 +02001302 call assert_equal(2, len(li))
1303 call assert_equal('A', li[0]['text'])
1304 call assert_equal('B', li[1]['text'])
1305
1306 " {action} is specified ' '.
1307 new | only
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001308 silent! Xnewer 99
1309 call g:Xsetlist(list1)
1310 call g:Xsetlist(list2, ' ')
1311 let li = g:Xgetlist()
Bram Moolenaard106e5b2016-04-21 19:38:07 +02001312 call assert_equal(3, len(li))
1313 call assert_equal('C', li[0]['text'])
1314 call assert_equal('D', li[1]['text'])
1315 call assert_equal('E', li[2]['text'])
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001316 silent! Xolder
1317 let li = g:Xgetlist()
Bram Moolenaard106e5b2016-04-21 19:38:07 +02001318 call assert_equal(2, len(li))
1319 call assert_equal('A', li[0]['text'])
1320 call assert_equal('B', li[1]['text'])
1321
1322 " {action} is specified 'a'.
1323 new | only
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001324 silent! Xnewer 99
1325 call g:Xsetlist(list1)
1326 call g:Xsetlist(list2, 'a')
1327 let li = g:Xgetlist()
Bram Moolenaard106e5b2016-04-21 19:38:07 +02001328 call assert_equal(5, len(li))
1329 call assert_equal('A', li[0]['text'])
1330 call assert_equal('B', li[1]['text'])
1331 call assert_equal('C', li[2]['text'])
1332 call assert_equal('D', li[3]['text'])
1333 call assert_equal('E', li[4]['text'])
1334
1335 " {action} is specified 'r'.
1336 new | only
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001337 silent! Xnewer 99
1338 call g:Xsetlist(list1)
1339 call g:Xsetlist(list2, 'r')
1340 let li = g:Xgetlist()
Bram Moolenaard106e5b2016-04-21 19:38:07 +02001341 call assert_equal(3, len(li))
1342 call assert_equal('C', li[0]['text'])
1343 call assert_equal('D', li[1]['text'])
1344 call assert_equal('E', li[2]['text'])
1345
1346 " Test for wrong value.
1347 new | only
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001348 call assert_fails("call g:Xsetlist(0)", 'E714:')
1349 call assert_fails("call g:Xsetlist(list1, '')", 'E927:')
1350 call assert_fails("call g:Xsetlist(list1, 'aa')", 'E927:')
1351 call assert_fails("call g:Xsetlist(list1, ' a')", 'E927:')
1352 call assert_fails("call g:Xsetlist(list1, 0)", 'E928:')
Bram Moolenaard106e5b2016-04-21 19:38:07 +02001353endfunc
1354
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001355func Test_quickfix_set_list_with_act()
Bram Moolenaard106e5b2016-04-21 19:38:07 +02001356 call XquickfixSetListWithAct('c')
1357 call XquickfixSetListWithAct('l')
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001358endfunc
Bram Moolenaar6be8c8e2016-04-30 13:17:09 +02001359
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001360func XLongLinesTests(cchar)
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001361 let l = g:Xgetlist()
Bram Moolenaar6be8c8e2016-04-30 13:17:09 +02001362
Bram Moolenaar049cba92016-06-26 14:38:04 +02001363 call assert_equal(4, len(l))
Bram Moolenaar6be8c8e2016-04-30 13:17:09 +02001364 call assert_equal(1, l[0].lnum)
1365 call assert_equal(1, l[0].col)
Bram Moolenaar049cba92016-06-26 14:38:04 +02001366 call assert_equal(1975, len(l[0].text))
Bram Moolenaar6be8c8e2016-04-30 13:17:09 +02001367 call assert_equal(2, l[1].lnum)
1368 call assert_equal(1, l[1].col)
1369 call assert_equal(4070, len(l[1].text))
1370 call assert_equal(3, l[2].lnum)
1371 call assert_equal(1, l[2].col)
Bram Moolenaar049cba92016-06-26 14:38:04 +02001372 call assert_equal(4070, len(l[2].text))
1373 call assert_equal(4, l[3].lnum)
1374 call assert_equal(1, l[3].col)
1375 call assert_equal(10, len(l[3].text))
Bram Moolenaar6be8c8e2016-04-30 13:17:09 +02001376
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001377 call g:Xsetlist([], 'r')
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001378endfunc
Bram Moolenaar6be8c8e2016-04-30 13:17:09 +02001379
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001380func s:long_lines_tests(cchar)
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001381 call s:setup_commands(a:cchar)
1382
Bram Moolenaar6be8c8e2016-04-30 13:17:09 +02001383 let testfile = 'samples/quickfix.txt'
1384
1385 " file
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001386 exe 'Xgetfile' testfile
1387 call XLongLinesTests(a:cchar)
Bram Moolenaar6be8c8e2016-04-30 13:17:09 +02001388
1389 " list
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001390 Xexpr readfile(testfile)
1391 call XLongLinesTests(a:cchar)
Bram Moolenaar6be8c8e2016-04-30 13:17:09 +02001392
1393 " string
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001394 Xexpr join(readfile(testfile), "\n")
1395 call XLongLinesTests(a:cchar)
Bram Moolenaar6be8c8e2016-04-30 13:17:09 +02001396
1397 " buffer
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001398 exe 'edit' testfile
1399 exe 'Xbuffer' bufnr('%')
Bram Moolenaarf50df392016-06-21 21:33:34 +02001400 call XLongLinesTests(a:cchar)
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001401endfunc
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001402
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001403func Test_long_lines()
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001404 call s:long_lines_tests('c')
1405 call s:long_lines_tests('l')
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001406endfunc
Bram Moolenaar049cba92016-06-26 14:38:04 +02001407
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001408func s:create_test_file(filename)
Bram Moolenaar049cba92016-06-26 14:38:04 +02001409 let l = []
1410 for i in range(1, 20)
1411 call add(l, 'Line' . i)
1412 endfor
1413 call writefile(l, a:filename)
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001414endfunc
Bram Moolenaar049cba92016-06-26 14:38:04 +02001415
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001416func Test_switchbuf()
Bram Moolenaar049cba92016-06-26 14:38:04 +02001417 call s:create_test_file('Xqftestfile1')
1418 call s:create_test_file('Xqftestfile2')
1419 call s:create_test_file('Xqftestfile3')
1420
1421 new | only
1422 edit Xqftestfile1
1423 let file1_winid = win_getid()
1424 new Xqftestfile2
1425 let file2_winid = win_getid()
1426 cgetexpr ['Xqftestfile1:5:Line5',
1427 \ 'Xqftestfile1:6:Line6',
1428 \ 'Xqftestfile2:10:Line10',
1429 \ 'Xqftestfile2:11:Line11',
1430 \ 'Xqftestfile3:15:Line15',
1431 \ 'Xqftestfile3:16:Line16']
1432
1433 new
1434 let winid = win_getid()
1435 cfirst | cnext
1436 call assert_equal(winid, win_getid())
Bram Moolenaar99895ea2017-04-20 22:44:47 +02001437 2cnext
Bram Moolenaar049cba92016-06-26 14:38:04 +02001438 call assert_equal(winid, win_getid())
Bram Moolenaar99895ea2017-04-20 22:44:47 +02001439 2cnext
Bram Moolenaar049cba92016-06-26 14:38:04 +02001440 call assert_equal(winid, win_getid())
1441 enew
1442
1443 set switchbuf=useopen
1444 cfirst | cnext
1445 call assert_equal(file1_winid, win_getid())
Bram Moolenaar99895ea2017-04-20 22:44:47 +02001446 2cnext
Bram Moolenaar049cba92016-06-26 14:38:04 +02001447 call assert_equal(file2_winid, win_getid())
Bram Moolenaar99895ea2017-04-20 22:44:47 +02001448 2cnext
Bram Moolenaar049cba92016-06-26 14:38:04 +02001449 call assert_equal(file2_winid, win_getid())
1450
1451 enew | only
1452 set switchbuf=usetab
1453 tabedit Xqftestfile1
1454 tabedit Xqftestfile2
1455 tabfirst
1456 cfirst | cnext
1457 call assert_equal(2, tabpagenr())
Bram Moolenaar99895ea2017-04-20 22:44:47 +02001458 2cnext
Bram Moolenaar049cba92016-06-26 14:38:04 +02001459 call assert_equal(3, tabpagenr())
Bram Moolenaar99895ea2017-04-20 22:44:47 +02001460 2cnext
Bram Moolenaar049cba92016-06-26 14:38:04 +02001461 call assert_equal(3, tabpagenr())
1462 tabfirst | tabonly | enew
1463
1464 set switchbuf=split
1465 cfirst | cnext
1466 call assert_equal(1, winnr('$'))
1467 cnext | cnext
1468 call assert_equal(2, winnr('$'))
1469 cnext | cnext
1470 call assert_equal(3, winnr('$'))
1471 enew | only
1472
1473 set switchbuf=newtab
1474 cfirst | cnext
1475 call assert_equal(1, tabpagenr('$'))
1476 cnext | cnext
1477 call assert_equal(2, tabpagenr('$'))
1478 cnext | cnext
1479 call assert_equal(3, tabpagenr('$'))
1480 tabfirst | enew | tabonly | only
1481
1482 set switchbuf=
1483 edit Xqftestfile1
1484 let file1_winid = win_getid()
1485 new Xqftestfile2
1486 let file2_winid = win_getid()
1487 copen
1488 exe "normal 1G\<CR>"
1489 call assert_equal(file1_winid, win_getid())
1490 copen
1491 exe "normal 3G\<CR>"
1492 call assert_equal(file2_winid, win_getid())
1493 copen | only
1494 exe "normal 5G\<CR>"
1495 call assert_equal(2, winnr('$'))
1496 call assert_equal(1, bufwinnr('Xqftestfile3'))
1497
Bram Moolenaar391b1dd2017-03-04 13:47:11 +01001498 " If only quickfix window is open in the current tabpage, jumping to an
1499 " entry with 'switchubf' set to 'usetab' should search in other tabpages.
Bram Moolenaar049cba92016-06-26 14:38:04 +02001500 enew | only
Bram Moolenaar391b1dd2017-03-04 13:47:11 +01001501 set switchbuf=usetab
1502 tabedit Xqftestfile1
1503 tabedit Xqftestfile2
1504 tabedit Xqftestfile3
1505 tabfirst
1506 copen | only
1507 clast
1508 call assert_equal(4, tabpagenr())
1509 tabfirst | tabonly | enew | only
Bram Moolenaar049cba92016-06-26 14:38:04 +02001510
1511 call delete('Xqftestfile1')
1512 call delete('Xqftestfile2')
1513 call delete('Xqftestfile3')
Bram Moolenaar391b1dd2017-03-04 13:47:11 +01001514 set switchbuf&vim
1515
1516 enew | only
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001517endfunc
Bram Moolenaar049cba92016-06-26 14:38:04 +02001518
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001519func Xadjust_qflnum(cchar)
Bram Moolenaar049cba92016-06-26 14:38:04 +02001520 call s:setup_commands(a:cchar)
1521
1522 enew | only
1523
Bram Moolenaarc1542742016-07-20 21:44:37 +02001524 let fname = 'Xqftestfile' . a:cchar
1525 call s:create_test_file(fname)
1526 exe 'edit ' . fname
Bram Moolenaar049cba92016-06-26 14:38:04 +02001527
Bram Moolenaarc1542742016-07-20 21:44:37 +02001528 Xgetexpr [fname . ':5:Line5',
1529 \ fname . ':10:Line10',
1530 \ fname . ':15:Line15',
1531 \ fname . ':20:Line20']
Bram Moolenaar049cba92016-06-26 14:38:04 +02001532
1533 6,14delete
1534 call append(6, ['Buffer', 'Window'])
1535
1536 let l = g:Xgetlist()
1537
1538 call assert_equal(5, l[0].lnum)
1539 call assert_equal(6, l[2].lnum)
1540 call assert_equal(13, l[3].lnum)
1541
1542 enew!
Bram Moolenaarc1542742016-07-20 21:44:37 +02001543 call delete(fname)
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001544endfunc
Bram Moolenaar049cba92016-06-26 14:38:04 +02001545
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001546func Test_adjust_lnum()
Bram Moolenaarc1542742016-07-20 21:44:37 +02001547 call setloclist(0, [])
Bram Moolenaar049cba92016-06-26 14:38:04 +02001548 call Xadjust_qflnum('c')
Bram Moolenaarc1542742016-07-20 21:44:37 +02001549 call setqflist([])
Bram Moolenaar049cba92016-06-26 14:38:04 +02001550 call Xadjust_qflnum('l')
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001551endfunc
Bram Moolenaar049cba92016-06-26 14:38:04 +02001552
1553" Tests for the :grep/:lgrep and :grepadd/:lgrepadd commands
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001554func s:test_xgrep(cchar)
Bram Moolenaar049cba92016-06-26 14:38:04 +02001555 call s:setup_commands(a:cchar)
1556
1557 " The following lines are used for the grep test. Don't remove.
1558 " Grep_Test_Text: Match 1
1559 " Grep_Test_Text: Match 2
1560 " GrepAdd_Test_Text: Match 1
1561 " GrepAdd_Test_Text: Match 2
1562 enew! | only
1563 set makeef&vim
1564 silent Xgrep Grep_Test_Text: test_quickfix.vim
1565 call assert_true(len(g:Xgetlist()) == 3)
1566 Xopen
1567 call assert_true(w:quickfix_title =~ '^:grep')
1568 Xclose
1569 enew
1570 set makeef=Temp_File_##
1571 silent Xgrepadd GrepAdd_Test_Text: test_quickfix.vim
1572 call assert_true(len(g:Xgetlist()) == 6)
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001573endfunc
Bram Moolenaar049cba92016-06-26 14:38:04 +02001574
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001575func Test_grep()
Bram Moolenaar049cba92016-06-26 14:38:04 +02001576 if !has('unix')
1577 " The grepprg may not be set on non-Unix systems
1578 return
1579 endif
1580
1581 call s:test_xgrep('c')
1582 call s:test_xgrep('l')
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001583endfunc
Bram Moolenaar361c8f02016-07-02 15:41:47 +02001584
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001585func Test_two_windows()
Bram Moolenaar361c8f02016-07-02 15:41:47 +02001586 " Use one 'errorformat' for two windows. Add an expression to each of them,
1587 " make sure they each keep their own state.
1588 set efm=%DEntering\ dir\ '%f',%f:%l:%m,%XLeaving\ dir\ '%f'
1589 call mkdir('Xone/a', 'p')
1590 call mkdir('Xtwo/a', 'p')
1591 let lines = ['1', '2', 'one one one', '4', 'two two two', '6', '7']
1592 call writefile(lines, 'Xone/a/one.txt')
1593 call writefile(lines, 'Xtwo/a/two.txt')
1594
1595 new one
1596 let one_id = win_getid()
1597 lexpr ""
1598 new two
1599 let two_id = win_getid()
1600 lexpr ""
1601
1602 laddexpr "Entering dir 'Xtwo/a'"
1603 call win_gotoid(one_id)
1604 laddexpr "Entering dir 'Xone/a'"
1605 call win_gotoid(two_id)
1606 laddexpr 'two.txt:5:two two two'
1607 call win_gotoid(one_id)
1608 laddexpr 'one.txt:3:one one one'
1609
1610 let loc_one = getloclist(one_id)
Bram Moolenaar361c8f02016-07-02 15:41:47 +02001611 call assert_equal('Xone/a/one.txt', bufname(loc_one[1].bufnr))
1612 call assert_equal(3, loc_one[1].lnum)
1613
1614 let loc_two = getloclist(two_id)
Bram Moolenaar361c8f02016-07-02 15:41:47 +02001615 call assert_equal('Xtwo/a/two.txt', bufname(loc_two[1].bufnr))
1616 call assert_equal(5, loc_two[1].lnum)
1617
1618 call win_gotoid(one_id)
1619 bwipe!
1620 call win_gotoid(two_id)
1621 bwipe!
1622 call delete('Xone', 'rf')
1623 call delete('Xtwo', 'rf')
1624endfunc
Bram Moolenaardcb17002016-07-07 18:58:59 +02001625
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001626func XbottomTests(cchar)
Bram Moolenaar537ef082016-07-09 17:56:19 +02001627 call s:setup_commands(a:cchar)
1628
Bram Moolenaarb6fa30c2017-03-29 14:19:25 +02001629 " Calling lbottom without any errors should fail
1630 if a:cchar == 'l'
1631 call assert_fails('lbottom', 'E776:')
1632 endif
1633
Bram Moolenaar537ef082016-07-09 17:56:19 +02001634 call g:Xsetlist([{'filename': 'foo', 'lnum': 42}])
1635 Xopen
Bram Moolenaardcb17002016-07-07 18:58:59 +02001636 let wid = win_getid()
1637 call assert_equal(1, line('.'))
1638 wincmd w
Bram Moolenaar537ef082016-07-09 17:56:19 +02001639 call g:Xsetlist([{'filename': 'var', 'lnum': 24}], 'a')
1640 Xbottom
Bram Moolenaardcb17002016-07-07 18:58:59 +02001641 call win_gotoid(wid)
1642 call assert_equal(2, line('.'))
Bram Moolenaar537ef082016-07-09 17:56:19 +02001643 Xclose
Bram Moolenaardcb17002016-07-07 18:58:59 +02001644endfunc
Bram Moolenaar537ef082016-07-09 17:56:19 +02001645
1646" Tests for the :cbottom and :lbottom commands
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001647func Test_cbottom()
Bram Moolenaar537ef082016-07-09 17:56:19 +02001648 call XbottomTests('c')
1649 call XbottomTests('l')
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001650endfunc
Bram Moolenaarf6acffb2016-07-16 16:54:24 +02001651
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001652func HistoryTest(cchar)
Bram Moolenaarf6acffb2016-07-16 16:54:24 +02001653 call s:setup_commands(a:cchar)
1654
Bram Moolenaarf6acffb2016-07-16 16:54:24 +02001655 " clear all lists after the first one, then replace the first one.
1656 call g:Xsetlist([])
Bram Moolenaarb6fa30c2017-03-29 14:19:25 +02001657 call assert_fails('Xolder 99', 'E380:')
Bram Moolenaarf6acffb2016-07-16 16:54:24 +02001658 let entry = {'filename': 'foo', 'lnum': 42}
1659 call g:Xsetlist([entry], 'r')
1660 call g:Xsetlist([entry, entry])
1661 call g:Xsetlist([entry, entry, entry])
1662 let res = split(execute(a:cchar . 'hist'), "\n")
1663 call assert_equal(3, len(res))
1664 let common = 'errors :set' . (a:cchar == 'c' ? 'qf' : 'loc') . 'list()'
1665 call assert_equal(' error list 1 of 3; 1 ' . common, res[0])
1666 call assert_equal(' error list 2 of 3; 2 ' . common, res[1])
1667 call assert_equal('> error list 3 of 3; 3 ' . common, res[2])
1668endfunc
1669
1670func Test_history()
1671 call HistoryTest('c')
1672 call HistoryTest('l')
1673endfunc
Bram Moolenaar015102e2016-07-16 18:24:56 +02001674
1675func Test_duplicate_buf()
1676 " make sure we can get the highest buffer number
1677 edit DoesNotExist
1678 edit DoesNotExist2
1679 let last_buffer = bufnr("$")
1680
1681 " make sure only one buffer is created
1682 call writefile(['this one', 'that one'], 'Xgrepthis')
1683 vimgrep one Xgrepthis
1684 vimgrep one Xgrepthis
1685 call assert_equal(last_buffer + 1, bufnr("$"))
1686
1687 call delete('Xgrepthis')
1688endfunc
Bram Moolenaard823fa92016-08-12 16:29:27 +02001689
1690" Quickfix/Location list set/get properties tests
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001691func Xproperty_tests(cchar)
Bram Moolenaard823fa92016-08-12 16:29:27 +02001692 call s:setup_commands(a:cchar)
1693
1694 " Error cases
1695 call assert_fails('call g:Xgetlist(99)', 'E715:')
1696 call assert_fails('call g:Xsetlist(99)', 'E714:')
1697 call assert_fails('call g:Xsetlist([], "a", [])', 'E715:')
1698
1699 " Set and get the title
Bram Moolenaarb6fa30c2017-03-29 14:19:25 +02001700 call g:Xsetlist([])
Bram Moolenaard823fa92016-08-12 16:29:27 +02001701 Xopen
1702 wincmd p
1703 call g:Xsetlist([{'filename':'foo', 'lnum':27}])
1704 call g:Xsetlist([], 'a', {'title' : 'Sample'})
1705 let d = g:Xgetlist({"title":1})
1706 call assert_equal('Sample', d.title)
1707
1708 Xopen
1709 call assert_equal('Sample', w:quickfix_title)
1710 Xclose
1711
Bram Moolenaar2b529bb2016-08-27 13:35:35 +02001712 " Tests for action argument
1713 silent! Xolder 999
1714 let qfnr = g:Xgetlist({'all':1}).nr
1715 call g:Xsetlist([], 'r', {'title' : 'N1'})
1716 call assert_equal('N1', g:Xgetlist({'all':1}).title)
1717 call g:Xsetlist([], ' ', {'title' : 'N2'})
1718 call assert_equal(qfnr + 1, g:Xgetlist({'all':1}).nr)
Bram Moolenaar890680c2016-09-27 21:28:56 +02001719
1720 let res = g:Xgetlist({'nr': 0})
1721 call assert_equal(qfnr + 1, res.nr)
1722 call assert_equal(['nr'], keys(res))
1723
Bram Moolenaar2b529bb2016-08-27 13:35:35 +02001724 call g:Xsetlist([], ' ', {'title' : 'N3'})
1725 call assert_equal('N2', g:Xgetlist({'nr':2, 'title':1}).title)
1726
Bram Moolenaaree85df32017-03-19 14:19:50 +01001727 " Changing the title of an earlier quickfix list
1728 call g:Xsetlist([], ' ', {'title' : 'NewTitle', 'nr' : 2})
1729 call assert_equal('NewTitle', g:Xgetlist({'nr':2, 'title':1}).title)
1730
1731 " Changing the title of an invalid quickfix list
1732 call assert_equal(-1, g:Xsetlist([], ' ',
1733 \ {'title' : 'SomeTitle', 'nr' : 99}))
1734 call assert_equal(-1, g:Xsetlist([], ' ',
1735 \ {'title' : 'SomeTitle', 'nr' : 'abc'}))
1736
1737 if a:cchar == 'c'
1738 copen
1739 call assert_equal({'winid':win_getid()}, getqflist({'winid':1}))
1740 cclose
1741 endif
1742
Bram Moolenaard823fa92016-08-12 16:29:27 +02001743 " Invalid arguments
1744 call assert_fails('call g:Xgetlist([])', 'E715')
1745 call assert_fails('call g:Xsetlist([], "a", [])', 'E715')
1746 let s = g:Xsetlist([], 'a', {'abc':1})
1747 call assert_equal(-1, s)
1748
1749 call assert_equal({}, g:Xgetlist({'abc':1}))
Bram Moolenaaree85df32017-03-19 14:19:50 +01001750 call assert_equal({}, g:Xgetlist({'nr':99, 'title':1}))
1751 call assert_equal({}, g:Xgetlist({'nr':[], 'title':1}))
Bram Moolenaard823fa92016-08-12 16:29:27 +02001752
1753 if a:cchar == 'l'
Bram Moolenaar890680c2016-09-27 21:28:56 +02001754 call assert_equal({}, getloclist(99, {'title': 1}))
Bram Moolenaard823fa92016-08-12 16:29:27 +02001755 endif
Bram Moolenaaree85df32017-03-19 14:19:50 +01001756endfunc
Bram Moolenaard823fa92016-08-12 16:29:27 +02001757
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001758func Test_qf_property()
Bram Moolenaard823fa92016-08-12 16:29:27 +02001759 call Xproperty_tests('c')
1760 call Xproperty_tests('l')
Bram Moolenaaree85df32017-03-19 14:19:50 +01001761endfunc
Bram Moolenaar04c4ce62016-09-01 15:45:58 +02001762
1763" Tests for the QuickFixCmdPre/QuickFixCmdPost autocommands
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001764func QfAutoCmdHandler(loc, cmd)
Bram Moolenaar04c4ce62016-09-01 15:45:58 +02001765 call add(g:acmds, a:loc . a:cmd)
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001766endfunc
Bram Moolenaar04c4ce62016-09-01 15:45:58 +02001767
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001768func Test_Autocmd()
Bram Moolenaar04c4ce62016-09-01 15:45:58 +02001769 autocmd QuickFixCmdPre * call QfAutoCmdHandler('pre', expand('<amatch>'))
1770 autocmd QuickFixCmdPost * call QfAutoCmdHandler('post', expand('<amatch>'))
1771
1772 let g:acmds = []
1773 cexpr "F1:10:Line 10"
1774 caddexpr "F1:20:Line 20"
1775 cgetexpr "F1:30:Line 30"
1776 enew! | call append(0, "F2:10:Line 10")
1777 cbuffer!
1778 enew! | call append(0, "F2:20:Line 20")
1779 cgetbuffer
1780 enew! | call append(0, "F2:30:Line 30")
1781 caddbuffer
1782
1783 let l = ['precexpr',
1784 \ 'postcexpr',
1785 \ 'precaddexpr',
1786 \ 'postcaddexpr',
1787 \ 'precgetexpr',
1788 \ 'postcgetexpr',
1789 \ 'precbuffer',
1790 \ 'postcbuffer',
1791 \ 'precgetbuffer',
1792 \ 'postcgetbuffer',
1793 \ 'precaddbuffer',
1794 \ 'postcaddbuffer']
1795 call assert_equal(l, g:acmds)
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001796endfunc
Bram Moolenaar21662be2016-11-06 14:46:44 +01001797
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001798func Test_Autocmd_Exception()
Bram Moolenaar21662be2016-11-06 14:46:44 +01001799 set efm=%m
1800 lgetexpr '?'
1801
1802 try
1803 call DoesNotExit()
1804 catch
1805 lgetexpr '1'
1806 finally
1807 lgetexpr '1'
1808 endtry
1809
1810 call assert_equal('1', getloclist(0)[0].text)
1811
1812 set efm&vim
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001813endfunc
Bram Moolenaar63bed3d2016-11-12 15:36:54 +01001814
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001815func Test_caddbuffer_wrong()
1816 " This used to cause a memory access in freed memory.
Bram Moolenaar63bed3d2016-11-12 15:36:54 +01001817 let save_efm = &efm
1818 set efm=%EEEE%m,%WWWW,%+CCCC%>%#,%GGGG%.#
1819 cgetexpr ['WWWW', 'EEEE', 'CCCC']
1820 let &efm = save_efm
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001821 caddbuffer
Bram Moolenaar63bed3d2016-11-12 15:36:54 +01001822 bwipe!
1823endfunc
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001824
1825func Test_caddexpr_wrong()
1826 " This used to cause a memory access in freed memory.
1827 cbuffer
1828 cbuffer
1829 copen
1830 let save_efm = &efm
1831 set efm=%
1832 call assert_fails('caddexpr ""', 'E376:')
1833 let &efm = save_efm
1834endfunc
Bram Moolenaar7618e002016-11-13 15:09:26 +01001835
1836func Test_dirstack_cleanup()
1837 " This used to cause a memory access in freed memory.
1838 let save_efm = &efm
1839 lexpr '0'
1840 lopen
1841 fun X(c)
1842 let save_efm=&efm
1843 set efm=%D%f
1844 if a:c == 'c'
1845 caddexpr '::'
1846 else
1847 laddexpr ':0:0'
1848 endif
1849 let &efm=save_efm
1850 endfun
1851 call X('c')
1852 call X('l')
1853 call setqflist([], 'r')
1854 caddbuffer
1855 let &efm = save_efm
1856endfunc
Bram Moolenaar391b1dd2017-03-04 13:47:11 +01001857
1858" Tests for jumping to entries from the location list window and quickfix
1859" window
1860func Test_cwindow_jump()
1861 set efm=%f%%%l%%%m
1862 lgetexpr ["F1%10%Line 10", "F2%20%Line 20", "F3%30%Line 30"]
1863 lopen | only
1864 lfirst
1865 call assert_true(winnr('$') == 2)
1866 call assert_true(winnr() == 1)
1867 " Location list for the new window should be set
1868 call assert_true(getloclist(0)[2].text == 'Line 30')
1869
1870 " Open a scratch buffer
1871 " Open a new window and create a location list
1872 " Open the location list window and close the other window
1873 " Jump to an entry.
1874 " Should create a new window and jump to the entry. The scrtach buffer
1875 " should not be used.
1876 enew | only
1877 set buftype=nofile
1878 below new
1879 lgetexpr ["F1%10%Line 10", "F2%20%Line 20", "F3%30%Line 30"]
1880 lopen
1881 2wincmd c
1882 lnext
1883 call assert_true(winnr('$') == 3)
1884 call assert_true(winnr() == 2)
1885
1886 " Open two windows with two different location lists
1887 " Open the location list window and close the previous window
1888 " Jump to an entry in the location list window
1889 " Should open the file in the first window and not set the location list.
1890 enew | only
1891 lgetexpr ["F1%5%Line 5"]
1892 below new
1893 lgetexpr ["F1%10%Line 10", "F2%20%Line 20", "F3%30%Line 30"]
1894 lopen
1895 2wincmd c
1896 lnext
1897 call assert_true(winnr() == 1)
1898 call assert_true(getloclist(0)[0].text == 'Line 5')
1899
1900 enew | only
1901 cgetexpr ["F1%10%Line 10", "F2%20%Line 20", "F3%30%Line 30"]
1902 copen
1903 cnext
1904 call assert_true(winnr('$') == 2)
1905 call assert_true(winnr() == 1)
1906
1907 enew | only
1908 set efm&vim
1909endfunc
Bram Moolenaaree85df32017-03-19 14:19:50 +01001910
1911func XvimgrepTests(cchar)
1912 call s:setup_commands(a:cchar)
1913
1914 call writefile(['Editor:VIM vim',
1915 \ 'Editor:Emacs EmAcS',
1916 \ 'Editor:Notepad NOTEPAD'], 'Xtestfile1')
1917 call writefile(['Linux', 'MacOS', 'MS-Windows'], 'Xtestfile2')
1918
1919 " Error cases
1920 call assert_fails('Xvimgrep /abc *', 'E682:')
1921
1922 let @/=''
1923 call assert_fails('Xvimgrep // *', 'E35:')
1924
1925 call assert_fails('Xvimgrep abc', 'E683:')
1926 call assert_fails('Xvimgrep a1b2c3 Xtestfile1', 'E480:')
1927 call assert_fails('Xvimgrep pat Xa1b2c3', 'E480:')
1928
1929 Xexpr ""
1930 Xvimgrepadd Notepad Xtestfile1
1931 Xvimgrepadd MacOS Xtestfile2
1932 let l = g:Xgetlist()
1933 call assert_equal(2, len(l))
1934 call assert_equal('Editor:Notepad NOTEPAD', l[0].text)
1935
1936 Xvimgrep #\cvim#g Xtestfile?
1937 let l = g:Xgetlist()
1938 call assert_equal(2, len(l))
1939 call assert_equal(8, l[0].col)
1940 call assert_equal(12, l[1].col)
1941
1942 1Xvimgrep ?Editor? Xtestfile*
1943 let l = g:Xgetlist()
1944 call assert_equal(1, len(l))
1945 call assert_equal('Editor:VIM vim', l[0].text)
1946
1947 edit +3 Xtestfile2
1948 Xvimgrep +\cemacs+j Xtestfile1
1949 let l = g:Xgetlist()
1950 call assert_equal('Xtestfile2', bufname(''))
1951 call assert_equal('Editor:Emacs EmAcS', l[0].text)
1952
1953 call delete('Xtestfile1')
1954 call delete('Xtestfile2')
1955endfunc
1956
1957" Tests for the :vimgrep command
1958func Test_vimgrep()
1959 call XvimgrepTests('c')
1960 call XvimgrepTests('l')
1961endfunc
Bram Moolenaar69f40be2017-04-02 15:15:49 +02001962
1963func XfreeTests(cchar)
1964 call s:setup_commands(a:cchar)
1965
1966 enew | only
1967
1968 " Deleting the quickfix stack should work even When the current list is
1969 " somewhere in the middle of the stack
1970 Xexpr ['Xfile1:10:10:Line 10', 'Xfile1:15:15:Line 15']
1971 Xexpr ['Xfile2:20:20:Line 20', 'Xfile2:25:25:Line 25']
1972 Xexpr ['Xfile3:30:30:Line 30', 'Xfile3:35:35:Line 35']
1973 Xolder
1974 call g:Xsetlist([], 'f')
1975 call assert_equal(0, len(g:Xgetlist()))
1976
1977 " After deleting the stack, adding a new list should create a stack with a
1978 " single list.
1979 Xexpr ['Xfile1:10:10:Line 10', 'Xfile1:15:15:Line 15']
1980 call assert_equal(1, g:Xgetlist({'all':1}).nr)
1981
1982 " Deleting the stack from a quickfix window should update/clear the
1983 " quickfix/location list window.
1984 Xexpr ['Xfile1:10:10:Line 10', 'Xfile1:15:15:Line 15']
1985 Xexpr ['Xfile2:20:20:Line 20', 'Xfile2:25:25:Line 25']
1986 Xexpr ['Xfile3:30:30:Line 30', 'Xfile3:35:35:Line 35']
1987 Xolder
1988 Xwindow
1989 call g:Xsetlist([], 'f')
1990 call assert_equal(2, winnr('$'))
1991 call assert_equal(1, line('$'))
1992 Xclose
1993
1994 " Deleting the stack from a non-quickfix window should update/clear the
1995 " quickfix/location list window.
1996 Xexpr ['Xfile1:10:10:Line 10', 'Xfile1:15:15:Line 15']
1997 Xexpr ['Xfile2:20:20:Line 20', 'Xfile2:25:25:Line 25']
1998 Xexpr ['Xfile3:30:30:Line 30', 'Xfile3:35:35:Line 35']
1999 Xolder
2000 Xwindow
2001 wincmd p
2002 call g:Xsetlist([], 'f')
2003 call assert_equal(0, len(g:Xgetlist()))
2004 wincmd p
2005 call assert_equal(2, winnr('$'))
2006 call assert_equal(1, line('$'))
2007
2008 " After deleting the location list stack, if the location list window is
2009 " opened, then a new location list should be created. So opening the
2010 " location list window again should not create a new window.
2011 if a:cchar == 'l'
2012 lexpr ['Xfile1:10:10:Line 10', 'Xfile1:15:15:Line 15']
2013 wincmd p
2014 lopen
2015 call assert_equal(2, winnr('$'))
2016 endif
2017 Xclose
2018endfunc
2019
2020" Tests for the quickifx free functionality
2021func Test_qf_free()
2022 call XfreeTests('c')
2023 call XfreeTests('l')
2024endfunc