blob: 54995f78766f97739b4764675fdc22f3aa4604c9 [file] [log] [blame]
Bram Moolenaarda59dd52016-01-05 21:59:58 +01001" Test for the quickfix commands.
2
3if !has('quickfix')
4 finish
5endif
6
Bram Moolenaar7eba3d22016-03-19 22:54:09 +01007set encoding=utf-8
8
Bram Moolenaar2b946c92016-11-12 18:14:44 +01009func s:setup_commands(cchar)
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +020010 if a:cchar == 'c'
11 command! -nargs=* -bang Xlist <mods>clist<bang> <args>
12 command! -nargs=* Xgetexpr <mods>cgetexpr <args>
Bram Moolenaar361c8f02016-07-02 15:41:47 +020013 command! -nargs=* Xaddexpr <mods>caddexpr <args>
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +020014 command! -nargs=* Xolder <mods>colder <args>
15 command! -nargs=* Xnewer <mods>cnewer <args>
16 command! -nargs=* Xopen <mods>copen <args>
17 command! -nargs=* Xwindow <mods>cwindow <args>
Bram Moolenaar537ef082016-07-09 17:56:19 +020018 command! -nargs=* Xbottom <mods>cbottom <args>
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +020019 command! -nargs=* Xclose <mods>cclose <args>
20 command! -nargs=* -bang Xfile <mods>cfile<bang> <args>
21 command! -nargs=* Xgetfile <mods>cgetfile <args>
22 command! -nargs=* Xaddfile <mods>caddfile <args>
23 command! -nargs=* -bang Xbuffer <mods>cbuffer<bang> <args>
24 command! -nargs=* Xgetbuffer <mods>cgetbuffer <args>
25 command! -nargs=* Xaddbuffer <mods>caddbuffer <args>
26 command! -nargs=* Xrewind <mods>crewind <args>
27 command! -nargs=* -bang Xnext <mods>cnext<bang> <args>
Bram Moolenaar0fcc7c62016-07-02 21:22:52 +020028 command! -nargs=* -bang Xprev <mods>cprev<bang> <args>
29 command! -nargs=* -bang Xfirst <mods>cfirst<bang> <args>
30 command! -nargs=* -bang Xlast <mods>clast<bang> <args>
31 command! -nargs=* -bang Xnfile <mods>cnfile<bang> <args>
32 command! -nargs=* -bang Xpfile <mods>cpfile<bang> <args>
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +020033 command! -nargs=* Xexpr <mods>cexpr <args>
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>
59 command! -nargs=* -bang Xnext <mods>lnext<bang> <args>
Bram Moolenaar0fcc7c62016-07-02 21:22:52 +020060 command! -nargs=* -bang Xprev <mods>lprev<bang> <args>
61 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',
398 \ 'Xqftestfile2:11:Line11']
399
400 Xfirst
401 call assert_fails('Xprev', 'E553')
402 call assert_fails('Xpfile', 'E553')
403 Xnfile
404 call assert_equal('Xqftestfile2', bufname('%'))
405 call assert_equal(10, line('.'))
406 Xpfile
407 call assert_equal('Xqftestfile1', bufname('%'))
408 call assert_equal(6, line('.'))
409 Xlast
410 call assert_equal('Xqftestfile2', bufname('%'))
411 call assert_equal(11, line('.'))
412 call assert_fails('Xnext', 'E553')
413 call assert_fails('Xnfile', 'E553')
414 Xrewind
415 call assert_equal('Xqftestfile1', bufname('%'))
416 call assert_equal(5, line('.'))
417
Bram Moolenaaree85df32017-03-19 14:19:50 +0100418 Xexpr ""
419 call assert_fails('Xnext', 'E42:')
420
Bram Moolenaar0fcc7c62016-07-02 21:22:52 +0200421 call delete('Xqftestfile1')
422 call delete('Xqftestfile2')
Bram Moolenaar2b946c92016-11-12 18:14:44 +0100423endfunc
Bram Moolenaar0fcc7c62016-07-02 21:22:52 +0200424
Bram Moolenaar2b946c92016-11-12 18:14:44 +0100425func Test_browse()
Bram Moolenaar0fcc7c62016-07-02 21:22:52 +0200426 call Xtest_browse('c')
427 call Xtest_browse('l')
Bram Moolenaar2b946c92016-11-12 18:14:44 +0100428endfunc
Bram Moolenaar0fcc7c62016-07-02 21:22:52 +0200429
Bram Moolenaar2b946c92016-11-12 18:14:44 +0100430func Test_nomem()
Bram Moolenaar8e8df252016-05-25 21:23:21 +0200431 call test_alloc_fail(GetAllocId('qf_dirname_start'), 0, 0)
Bram Moolenaara260b872016-01-15 20:48:22 +0100432 call assert_fails('vimgrep vim runtest.vim', 'E342:')
Bram Moolenaar75bdf6a2016-01-07 21:25:08 +0100433
Bram Moolenaar8e8df252016-05-25 21:23:21 +0200434 call test_alloc_fail(GetAllocId('qf_dirname_now'), 0, 0)
Bram Moolenaara260b872016-01-15 20:48:22 +0100435 call assert_fails('vimgrep vim runtest.vim', 'E342:')
Bram Moolenaar75bdf6a2016-01-07 21:25:08 +0100436
Bram Moolenaar8e8df252016-05-25 21:23:21 +0200437 call test_alloc_fail(GetAllocId('qf_namebuf'), 0, 0)
Bram Moolenaara260b872016-01-15 20:48:22 +0100438 call assert_fails('cfile runtest.vim', 'E342:')
Bram Moolenaar75bdf6a2016-01-07 21:25:08 +0100439
Bram Moolenaar8e8df252016-05-25 21:23:21 +0200440 call test_alloc_fail(GetAllocId('qf_errmsg'), 0, 0)
Bram Moolenaara260b872016-01-15 20:48:22 +0100441 call assert_fails('cfile runtest.vim', 'E342:')
Bram Moolenaar75bdf6a2016-01-07 21:25:08 +0100442
Bram Moolenaar8e8df252016-05-25 21:23:21 +0200443 call test_alloc_fail(GetAllocId('qf_pattern'), 0, 0)
Bram Moolenaara260b872016-01-15 20:48:22 +0100444 call assert_fails('cfile runtest.vim', 'E342:')
Bram Moolenaar75bdf6a2016-01-07 21:25:08 +0100445
446endfunc
447
Bram Moolenaar2b946c92016-11-12 18:14:44 +0100448func s:test_xhelpgrep(cchar)
Bram Moolenaar049cba92016-06-26 14:38:04 +0200449 call s:setup_commands(a:cchar)
450 Xhelpgrep quickfix
451 Xopen
452 if a:cchar == 'c'
453 let title_text = ':helpgrep quickfix'
454 else
455 let title_text = ':lhelpgrep quickfix'
456 endif
457 call assert_true(w:quickfix_title =~ title_text, w:quickfix_title)
Bram Moolenaar62ef7972016-01-19 14:51:54 +0100458 " This wipes out the buffer, make sure that doesn't cause trouble.
Bram Moolenaar049cba92016-06-26 14:38:04 +0200459 Xclose
Bram Moolenaaree85df32017-03-19 14:19:50 +0100460
461 " Search for non existing help string
462 call assert_fails('Xhelpgrep a1b2c3', 'E480:')
Bram Moolenaar2b946c92016-11-12 18:14:44 +0100463endfunc
Bram Moolenaar049cba92016-06-26 14:38:04 +0200464
Bram Moolenaar2b946c92016-11-12 18:14:44 +0100465func Test_helpgrep()
Bram Moolenaar049cba92016-06-26 14:38:04 +0200466 call s:test_xhelpgrep('c')
Bram Moolenaarcf25fdb2016-08-03 21:04:53 +0200467 helpclose
Bram Moolenaar049cba92016-06-26 14:38:04 +0200468 call s:test_xhelpgrep('l')
Bram Moolenaar62ef7972016-01-19 14:51:54 +0100469endfunc
Bram Moolenaar75bdf6a2016-01-07 21:25:08 +0100470
Bram Moolenaar6920c722016-01-22 22:44:10 +0100471func Test_errortitle()
472 augroup QfBufWinEnter
473 au!
474 au BufWinEnter * :let g:a=get(w:, 'quickfix_title', 'NONE')
475 augroup END
476 copen
477 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'')'}]
478 call setqflist(a)
479 call assert_equal(':setqflist()', g:a)
480 augroup QfBufWinEnter
481 au!
482 augroup END
483 augroup! QfBufWinEnter
484endfunc
Bram Moolenaare27dba42016-03-15 14:11:10 +0100485
Bram Moolenaar5584df62016-03-18 21:00:51 +0100486func Test_vimgreptitle()
487 augroup QfBufWinEnter
488 au!
489 au BufWinEnter * :let g:a=get(w:, 'quickfix_title', 'NONE')
490 augroup END
491 try
492 vimgrep /pattern/j file
493 catch /E480/
494 endtry
495 copen
496 call assert_equal(': vimgrep /pattern/j file', g:a)
497 augroup QfBufWinEnter
498 au!
499 augroup END
500 augroup! QfBufWinEnter
501endfunc
502
Bram Moolenaar2b946c92016-11-12 18:14:44 +0100503func XqfTitleTests(cchar)
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +0200504 call s:setup_commands(a:cchar)
Bram Moolenaare27dba42016-03-15 14:11:10 +0100505
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +0200506 Xgetexpr ['file:1:1:message']
507 let l = g:Xgetlist()
Bram Moolenaare27dba42016-03-15 14:11:10 +0100508 if a:cchar == 'c'
509 call setqflist(l, 'r')
510 else
511 call setloclist(0, l, 'r')
512 endif
513
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +0200514 Xopen
Bram Moolenaare27dba42016-03-15 14:11:10 +0100515 if a:cchar == 'c'
516 let title = ':setqflist()'
517 else
518 let title = ':setloclist()'
519 endif
520 call assert_equal(title, w:quickfix_title)
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +0200521 Xclose
Bram Moolenaar2b946c92016-11-12 18:14:44 +0100522endfunc
Bram Moolenaare27dba42016-03-15 14:11:10 +0100523
524" Tests for quickfix window's title
Bram Moolenaar2b946c92016-11-12 18:14:44 +0100525func Test_qf_title()
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +0200526 call XqfTitleTests('c')
527 call XqfTitleTests('l')
Bram Moolenaar2b946c92016-11-12 18:14:44 +0100528endfunc
Bram Moolenaare27dba42016-03-15 14:11:10 +0100529
530" Tests for 'errorformat'
Bram Moolenaar2b946c92016-11-12 18:14:44 +0100531func Test_efm()
Bram Moolenaare27dba42016-03-15 14:11:10 +0100532 let save_efm = &efm
533 set efm=%EEEE%m,%WWWW%m,%+CCCC%.%#,%-GGGG%.%#
534 cgetexpr ['WWWW', 'EEEE', 'CCCC']
535 let l = strtrans(string(map(getqflist(), '[v:val.text, v:val.valid]')))
536 call assert_equal("[['W', 1], ['E^@CCCC', 1]]", l)
537 cgetexpr ['WWWW', 'GGGG', 'EEEE', 'CCCC']
538 let l = strtrans(string(map(getqflist(), '[v:val.text, v:val.valid]')))
539 call assert_equal("[['W', 1], ['E^@CCCC', 1]]", l)
540 cgetexpr ['WWWW', 'GGGG', 'ZZZZ', 'EEEE', 'CCCC', 'YYYY']
541 let l = strtrans(string(map(getqflist(), '[v:val.text, v:val.valid]')))
542 call assert_equal("[['W', 1], ['ZZZZ', 0], ['E^@CCCC', 1], ['YYYY', 0]]", l)
543 let &efm = save_efm
Bram Moolenaar2b946c92016-11-12 18:14:44 +0100544endfunc
Bram Moolenaar1ff2b642016-03-17 22:07:02 +0100545
546" This will test for problems in quickfix:
547" A. incorrectly copying location lists which caused the location list to show
548" a different name than the file that was actually being displayed.
549" B. not reusing the window for which the location list window is opened but
550" instead creating new windows.
551" C. make sure that the location list window is not reused instead of the
552" window it belongs to.
553"
554" Set up the test environment:
Bram Moolenaar2b946c92016-11-12 18:14:44 +0100555func ReadTestProtocol(name)
Bram Moolenaar1ff2b642016-03-17 22:07:02 +0100556 let base = substitute(a:name, '\v^test://(.*)%(\.[^.]+)?', '\1', '')
557 let word = substitute(base, '\v(.*)\..*', '\1', '')
558
559 setl modifiable
560 setl noreadonly
561 setl noswapfile
562 setl bufhidden=delete
563 %del _
564 " For problem 2:
565 " 'buftype' has to be set to reproduce the constant opening of new windows
566 setl buftype=nofile
567
568 call setline(1, word)
569
570 setl nomodified
571 setl nomodifiable
572 setl readonly
573 exe 'doautocmd BufRead ' . substitute(a:name, '\v^test://(.*)', '\1', '')
Bram Moolenaar2b946c92016-11-12 18:14:44 +0100574endfunc
Bram Moolenaar1ff2b642016-03-17 22:07:02 +0100575
Bram Moolenaar2b946c92016-11-12 18:14:44 +0100576func Test_locationlist()
Bram Moolenaar1ff2b642016-03-17 22:07:02 +0100577 enew
578
579 augroup testgroup
580 au!
581 autocmd BufReadCmd test://* call ReadTestProtocol(expand("<amatch>"))
582 augroup END
583
584 let words = [ "foo", "bar", "baz", "quux", "shmoo", "spam", "eggs" ]
585
586 let qflist = []
587 for word in words
588 call add(qflist, {'filename': 'test://' . word . '.txt', 'text': 'file ' . word . '.txt', })
589 " NOTE: problem 1:
590 " intentionally not setting 'lnum' so that the quickfix entries are not
591 " valid
592 call setloclist(0, qflist, ' ')
593 endfor
594
595 " Test A
596 lrewind
597 enew
598 lopen
599 lnext
600 lnext
601 lnext
602 lnext
603 vert split
604 wincmd L
605 lopen
606 wincmd p
607 lnext
608 let fileName = expand("%")
609 wincmd p
610 let locationListFileName = substitute(getline(line('.')), '\([^|]*\)|.*', '\1', '')
611 let fileName = substitute(fileName, '\\', '/', 'g')
612 let locationListFileName = substitute(locationListFileName, '\\', '/', 'g')
613 call assert_equal("test://bar.txt", fileName)
614 call assert_equal("test://bar.txt", locationListFileName)
615
616 wincmd n | only
617
618 " Test B:
619 lrewind
620 lopen
621 2
622 exe "normal \<CR>"
623 wincmd p
624 3
625 exe "normal \<CR>"
626 wincmd p
627 4
628 exe "normal \<CR>"
629 call assert_equal(2, winnr('$'))
630 wincmd n | only
631
632 " Test C:
633 lrewind
634 lopen
635 " Let's move the location list window to the top to check whether it (the
636 " first window found) will be reused when we try to open new windows:
637 wincmd K
638 2
639 exe "normal \<CR>"
640 wincmd p
641 3
642 exe "normal \<CR>"
643 wincmd p
644 4
645 exe "normal \<CR>"
646 1wincmd w
647 call assert_equal('quickfix', &buftype)
648 2wincmd w
649 let bufferName = expand("%")
650 let bufferName = substitute(bufferName, '\\', '/', 'g')
651 call assert_equal('test://quux.txt', bufferName)
652
653 wincmd n | only
654
655 augroup! testgroup
Bram Moolenaaree85df32017-03-19 14:19:50 +0100656endfunc
Bram Moolenaar0899d692016-03-19 13:35:03 +0100657
Bram Moolenaar2b946c92016-11-12 18:14:44 +0100658func Test_locationlist_curwin_was_closed()
Bram Moolenaar0899d692016-03-19 13:35:03 +0100659 augroup testgroup
660 au!
Bram Moolenaard106e5b2016-04-21 19:38:07 +0200661 autocmd BufReadCmd test_curwin.txt call R(expand("<amatch>"))
Bram Moolenaar0899d692016-03-19 13:35:03 +0100662 augroup END
663
Bram Moolenaar2b946c92016-11-12 18:14:44 +0100664 func! R(n)
Bram Moolenaar0899d692016-03-19 13:35:03 +0100665 quit
666 endfunc
667
668 new
669 let q = []
Bram Moolenaard106e5b2016-04-21 19:38:07 +0200670 call add(q, {'filename': 'test_curwin.txt' })
Bram Moolenaar0899d692016-03-19 13:35:03 +0100671 call setloclist(0, q)
672 call assert_fails('lrewind', 'E924:')
673
674 augroup! testgroup
Bram Moolenaaree85df32017-03-19 14:19:50 +0100675endfunc
Bram Moolenaar7eba3d22016-03-19 22:54:09 +0100676
Bram Moolenaar2b946c92016-11-12 18:14:44 +0100677func Test_locationlist_cross_tab_jump()
Bram Moolenaar0a9046f2016-10-15 19:28:13 +0200678 call writefile(['loclistfoo'], 'loclistfoo')
679 call writefile(['loclistbar'], 'loclistbar')
680 set switchbuf=usetab
681
682 edit loclistfoo
683 tabedit loclistbar
684 silent lgrep loclistfoo loclist*
685 call assert_equal(1, tabpagenr())
686
687 enew | only | tabonly
688 set switchbuf&vim
689 call delete('loclistfoo')
690 call delete('loclistbar')
Bram Moolenaar2b946c92016-11-12 18:14:44 +0100691endfunc
Bram Moolenaar0a9046f2016-10-15 19:28:13 +0200692
Bram Moolenaar7eba3d22016-03-19 22:54:09 +0100693" More tests for 'errorformat'
Bram Moolenaar2b946c92016-11-12 18:14:44 +0100694func Test_efm1()
Bram Moolenaar7eba3d22016-03-19 22:54:09 +0100695 if !has('unix')
696 " The 'errorformat' setting is different on non-Unix systems.
697 " This test works only on Unix-like systems.
698 return
699 endif
700
701 let l = [
702 \ '"Xtestfile", line 4.12: 1506-045 (S) Undeclared identifier fd_set.',
703 \ '"Xtestfile", line 6 col 19; this is an error',
704 \ 'gcc -c -DHAVE_CONFIsing-prototypes -I/usr/X11R6/include version.c',
705 \ 'Xtestfile:9: parse error before `asd''',
706 \ 'make: *** [vim] Error 1',
707 \ 'in file "Xtestfile" linenr 10: there is an error',
708 \ '',
709 \ '2 returned',
710 \ '"Xtestfile", line 11 col 1; this is an error',
711 \ '"Xtestfile", line 12 col 2; this is another error',
712 \ '"Xtestfile", line 14:10; this is an error in column 10',
713 \ '=Xtestfile=, line 15:10; this is another error, but in vcol 10 this time',
714 \ '"Xtestfile", linenr 16: yet another problem',
715 \ 'Error in "Xtestfile" at line 17:',
716 \ 'x should be a dot',
717 \ ' xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 17',
718 \ ' ^',
719 \ 'Error in "Xtestfile" at line 18:',
720 \ 'x should be a dot',
721 \ ' xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 18',
722 \ '.............^',
723 \ 'Error in "Xtestfile" at line 19:',
724 \ 'x should be a dot',
725 \ ' xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 19',
726 \ '--------------^',
727 \ 'Error in "Xtestfile" at line 20:',
728 \ 'x should be a dot',
729 \ ' xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 20',
730 \ ' ^',
731 \ '',
732 \ 'Does anyone know what is the problem and how to correction it?',
733 \ '"Xtestfile", line 21 col 9: What is the title of the quickfix window?',
734 \ '"Xtestfile", line 22 col 9: What is the title of the quickfix window?'
735 \ ]
736
737 call writefile(l, 'Xerrorfile1')
738 call writefile(l[:-2], 'Xerrorfile2')
739
740 let m = [
741 \ ' xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 2',
742 \ ' xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 3',
743 \ ' xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 4',
744 \ ' xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 5',
745 \ ' xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 6',
746 \ ' xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 7',
747 \ ' xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 8',
748 \ ' xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 9',
749 \ ' xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 10',
750 \ ' xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 11',
751 \ ' xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 12',
752 \ ' xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 13',
753 \ ' xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 14',
754 \ ' xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 15',
755 \ ' xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 16',
756 \ ' xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 17',
757 \ ' xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 18',
758 \ ' xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 19',
759 \ ' xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 20',
760 \ ' xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 21',
761 \ ' xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 22'
762 \ ]
763 call writefile(m, 'Xtestfile')
764
765 let save_efm = &efm
766 set efm+==%f=\\,\ line\ %l%*\\D%v%*[^\ ]\ %m
767 set efm^=%AError\ in\ \"%f\"\ at\ line\ %l:,%Z%p^,%C%m
768
769 exe 'cf Xerrorfile2'
770 clast
771 copen
772 call assert_equal(':cf Xerrorfile2', w:quickfix_title)
773 wincmd p
774
775 exe 'cf Xerrorfile1'
776 call assert_equal([4, 12], [line('.'), col('.')])
777 cn
778 call assert_equal([6, 19], [line('.'), col('.')])
779 cn
780 call assert_equal([9, 2], [line('.'), col('.')])
781 cn
782 call assert_equal([10, 2], [line('.'), col('.')])
783 cn
784 call assert_equal([11, 1], [line('.'), col('.')])
785 cn
786 call assert_equal([12, 2], [line('.'), col('.')])
787 cn
788 call assert_equal([14, 10], [line('.'), col('.')])
789 cn
790 call assert_equal([15, 3, 10], [line('.'), col('.'), virtcol('.')])
791 cn
792 call assert_equal([16, 2], [line('.'), col('.')])
793 cn
794 call assert_equal([17, 6], [line('.'), col('.')])
795 cn
796 call assert_equal([18, 7], [line('.'), col('.')])
797 cn
798 call assert_equal([19, 8], [line('.'), col('.')])
799 cn
800 call assert_equal([20, 9], [line('.'), col('.')])
801 clast
802 cprev
803 cprev
804 wincmd w
805 call assert_equal(':cf Xerrorfile1', w:quickfix_title)
806 wincmd p
807
808 let &efm = save_efm
809 call delete('Xerrorfile1')
810 call delete('Xerrorfile2')
811 call delete('Xtestfile')
Bram Moolenaaree85df32017-03-19 14:19:50 +0100812endfunc
Bram Moolenaarffec3c52016-03-23 20:55:42 +0100813
Bram Moolenaarab47c612016-06-14 22:02:26 +0200814" Test for quickfix directory stack support
Bram Moolenaar2b946c92016-11-12 18:14:44 +0100815func s:dir_stack_tests(cchar)
Bram Moolenaar38df43b2016-06-20 21:41:12 +0200816 call s:setup_commands(a:cchar)
817
Bram Moolenaarab47c612016-06-14 22:02:26 +0200818 let save_efm=&efm
819 set efm=%DEntering\ dir\ '%f',%f:%l:%m,%XLeaving\ dir\ '%f'
820
Bram Moolenaar361c8f02016-07-02 15:41:47 +0200821 let lines = ["Entering dir 'dir1/a'",
822 \ 'habits2.txt:1:Nine Healthy Habits',
823 \ "Entering dir 'b'",
824 \ 'habits3.txt:2:0 Hours of television',
825 \ 'habits2.txt:7:5 Small meals',
826 \ "Entering dir 'dir1/c'",
827 \ 'habits4.txt:3:1 Hour of exercise',
828 \ "Leaving dir 'dir1/c'",
829 \ "Leaving dir 'dir1/a'",
830 \ 'habits1.txt:4:2 Liters of water',
831 \ "Entering dir 'dir2'",
832 \ 'habits5.txt:5:3 Cups of hot green tea',
833 \ "Leaving dir 'dir2'"
834 \]
Bram Moolenaarab47c612016-06-14 22:02:26 +0200835
Bram Moolenaar361c8f02016-07-02 15:41:47 +0200836 Xexpr ""
837 for l in lines
838 Xaddexpr l
839 endfor
Bram Moolenaarab47c612016-06-14 22:02:26 +0200840
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +0200841 let qf = g:Xgetlist()
Bram Moolenaarab47c612016-06-14 22:02:26 +0200842
843 call assert_equal('dir1/a/habits2.txt', bufname(qf[1].bufnr))
844 call assert_equal(1, qf[1].lnum)
845 call assert_equal('dir1/a/b/habits3.txt', bufname(qf[3].bufnr))
846 call assert_equal(2, qf[3].lnum)
847 call assert_equal('dir1/a/habits2.txt', bufname(qf[4].bufnr))
848 call assert_equal(7, qf[4].lnum)
849 call assert_equal('dir1/c/habits4.txt', bufname(qf[6].bufnr))
850 call assert_equal(3, qf[6].lnum)
851 call assert_equal('habits1.txt', bufname(qf[9].bufnr))
852 call assert_equal(4, qf[9].lnum)
853 call assert_equal('dir2/habits5.txt', bufname(qf[11].bufnr))
854 call assert_equal(5, qf[11].lnum)
855
856 let &efm=save_efm
Bram Moolenaar2b946c92016-11-12 18:14:44 +0100857endfunc
Bram Moolenaarab47c612016-06-14 22:02:26 +0200858
859" Tests for %D and %X errorformat options
Bram Moolenaar2b946c92016-11-12 18:14:44 +0100860func Test_efm_dirstack()
Bram Moolenaarab47c612016-06-14 22:02:26 +0200861 " Create the directory stack and files
862 call mkdir('dir1')
863 call mkdir('dir1/a')
864 call mkdir('dir1/a/b')
865 call mkdir('dir1/c')
866 call mkdir('dir2')
867
868 let lines = ["Nine Healthy Habits",
869 \ "0 Hours of television",
870 \ "1 Hour of exercise",
871 \ "2 Liters of water",
872 \ "3 Cups of hot green tea",
873 \ "4 Short mental breaks",
874 \ "5 Small meals",
875 \ "6 AM wake up time",
876 \ "7 Minutes of laughter",
877 \ "8 Hours of sleep (at least)",
878 \ "9 PM end of the day and off to bed"
879 \ ]
880 call writefile(lines, 'habits1.txt')
881 call writefile(lines, 'dir1/a/habits2.txt')
882 call writefile(lines, 'dir1/a/b/habits3.txt')
883 call writefile(lines, 'dir1/c/habits4.txt')
884 call writefile(lines, 'dir2/habits5.txt')
885
886 call s:dir_stack_tests('c')
887 call s:dir_stack_tests('l')
888
889 call delete('dir1', 'rf')
890 call delete('dir2', 'rf')
891 call delete('habits1.txt')
Bram Moolenaar2b946c92016-11-12 18:14:44 +0100892endfunc
Bram Moolenaarab47c612016-06-14 22:02:26 +0200893
Bram Moolenaar9b457942016-10-09 16:10:05 +0200894" Test for resync after continuing an ignored message
Bram Moolenaar2b946c92016-11-12 18:14:44 +0100895func Xefm_ignore_continuations(cchar)
Bram Moolenaar9b457942016-10-09 16:10:05 +0200896 call s:setup_commands(a:cchar)
897
898 let save_efm = &efm
899
900 let &efm =
901 \ '%Eerror %m %l,' .
902 \ '%-Wignored %m %l,' .
903 \ '%+Cmore ignored %m %l,' .
904 \ '%Zignored end'
905 Xgetexpr ['ignored warning 1', 'more ignored continuation 2', 'ignored end', 'error resync 4']
906 let l = map(g:Xgetlist(), '[v:val.text, v:val.valid, v:val.lnum, v:val.type]')
907 call assert_equal([['resync', 1, 4, 'E']], l)
908
909 let &efm = save_efm
Bram Moolenaar2b946c92016-11-12 18:14:44 +0100910endfunc
Bram Moolenaar9b457942016-10-09 16:10:05 +0200911
Bram Moolenaar2b946c92016-11-12 18:14:44 +0100912func Test_efm_ignore_continuations()
Bram Moolenaar9b457942016-10-09 16:10:05 +0200913 call Xefm_ignore_continuations('c')
914 call Xefm_ignore_continuations('l')
Bram Moolenaar2b946c92016-11-12 18:14:44 +0100915endfunc
Bram Moolenaar9b457942016-10-09 16:10:05 +0200916
Bram Moolenaar0fcc7c62016-07-02 21:22:52 +0200917" Tests for invalid error format specifies
Bram Moolenaar2b946c92016-11-12 18:14:44 +0100918func Xinvalid_efm_Tests(cchar)
Bram Moolenaar0fcc7c62016-07-02 21:22:52 +0200919 call s:setup_commands(a:cchar)
920
Bram Moolenaar049cba92016-06-26 14:38:04 +0200921 let save_efm = &efm
922
Bram Moolenaar0fcc7c62016-07-02 21:22:52 +0200923 set efm=%f:%l:%m,%f:%f:%l:%m
924 call assert_fails('Xexpr "abc.txt:1:Hello world"', 'E372:')
925
926 set efm=%f:%l:%m,%f:%l:%r:%m
927 call assert_fails('Xexpr "abc.txt:1:Hello world"', 'E373:')
928
929 set efm=%f:%l:%m,%O:%f:%l:%m
930 call assert_fails('Xexpr "abc.txt:1:Hello world"', 'E373:')
931
932 set efm=%f:%l:%m,%f:%l:%*[^a-z
933 call assert_fails('Xexpr "abc.txt:1:Hello world"', 'E374:')
934
935 set efm=%f:%l:%m,%f:%l:%*c
936 call assert_fails('Xexpr "abc.txt:1:Hello world"', 'E375:')
937
938 set efm=%f:%l:%m,%L%M%N
939 call assert_fails('Xexpr "abc.txt:1:Hello world"', 'E376:')
940
941 set efm=%f:%l:%m,%f:%l:%m:%R
942 call assert_fails('Xexpr "abc.txt:1:Hello world"', 'E377:')
943
944 set efm=
945 call assert_fails('Xexpr "abc.txt:1:Hello world"', 'E378:')
946
947 set efm=%DEntering\ dir\ abc,%f:%l:%m
948 call assert_fails('Xexpr ["Entering dir abc", "abc.txt:1:Hello world"]', 'E379:')
949
950 let &efm = save_efm
Bram Moolenaar2b946c92016-11-12 18:14:44 +0100951endfunc
Bram Moolenaar0fcc7c62016-07-02 21:22:52 +0200952
Bram Moolenaar2b946c92016-11-12 18:14:44 +0100953func Test_invalid_efm()
Bram Moolenaar0fcc7c62016-07-02 21:22:52 +0200954 call Xinvalid_efm_Tests('c')
955 call Xinvalid_efm_Tests('l')
Bram Moolenaar2b946c92016-11-12 18:14:44 +0100956endfunc
Bram Moolenaar0fcc7c62016-07-02 21:22:52 +0200957
958" TODO:
959" Add tests for the following formats in 'errorformat'
960" %r %O
Bram Moolenaar2b946c92016-11-12 18:14:44 +0100961func Test_efm2()
Bram Moolenaar0fcc7c62016-07-02 21:22:52 +0200962 let save_efm = &efm
Bram Moolenaar049cba92016-06-26 14:38:04 +0200963
964 " Test for %s format in efm
965 set efm=%f:%s
966 cexpr 'Xtestfile:Line search text'
Bram Moolenaar049cba92016-06-26 14:38:04 +0200967 let l = getqflist()
968 call assert_equal(l[0].pattern, '^\VLine search text\$')
969 call assert_equal(l[0].lnum, 0)
970
Bram Moolenaaree85df32017-03-19 14:19:50 +0100971 let l = split(execute('clist', ''), "\n")
972 call assert_equal([' 1 Xtestfile:^\VLine search text\$: '], l)
973
Bram Moolenaar0fcc7c62016-07-02 21:22:52 +0200974 " Test for %P, %Q and %t format specifiers
Bram Moolenaar049cba92016-06-26 14:38:04 +0200975 let lines=["[Xtestfile1]",
976 \ "(1,17) error: ';' missing",
977 \ "(21,2) warning: variable 'z' not defined",
978 \ "(67,3) error: end of file found before string ended",
Bram Moolenaaree85df32017-03-19 14:19:50 +0100979 \ "--",
Bram Moolenaar049cba92016-06-26 14:38:04 +0200980 \ "",
981 \ "[Xtestfile2]",
Bram Moolenaaree85df32017-03-19 14:19:50 +0100982 \ "--",
Bram Moolenaar049cba92016-06-26 14:38:04 +0200983 \ "",
984 \ "[Xtestfile3]",
985 \ "NEW compiler v1.1",
986 \ "(2,2) warning: variable 'x' not defined",
Bram Moolenaaree85df32017-03-19 14:19:50 +0100987 \ "(67,3) warning: 's' already defined",
988 \ "--"
Bram Moolenaar049cba92016-06-26 14:38:04 +0200989 \]
Bram Moolenaaree85df32017-03-19 14:19:50 +0100990 set efm=%+P[%f]%r,(%l\\,%c)%*[\ ]%t%*[^:]:\ %m,%+Q--%r
Bram Moolenaar391b1dd2017-03-04 13:47:11 +0100991 " To exercise the push/pop file functionality in quickfix, the test files
992 " need to be created.
993 call writefile(['Line1'], 'Xtestfile1')
994 call writefile(['Line2'], 'Xtestfile2')
995 call writefile(['Line3'], 'Xtestfile3')
Bram Moolenaar361c8f02016-07-02 15:41:47 +0200996 cexpr ""
997 for l in lines
998 caddexpr l
999 endfor
Bram Moolenaar049cba92016-06-26 14:38:04 +02001000 let l = getqflist()
Bram Moolenaaree85df32017-03-19 14:19:50 +01001001 call assert_equal(12, len(l))
Bram Moolenaar049cba92016-06-26 14:38:04 +02001002 call assert_equal(21, l[2].lnum)
1003 call assert_equal(2, l[2].col)
Bram Moolenaar0fcc7c62016-07-02 21:22:52 +02001004 call assert_equal('w', l[2].type)
1005 call assert_equal('e', l[3].type)
Bram Moolenaar391b1dd2017-03-04 13:47:11 +01001006 call delete('Xtestfile1')
1007 call delete('Xtestfile2')
1008 call delete('Xtestfile3')
Bram Moolenaar0fcc7c62016-07-02 21:22:52 +02001009
1010 " Tests for %E, %C and %Z format specifiers
1011 let lines = ["Error 275",
1012 \ "line 42",
1013 \ "column 3",
1014 \ "' ' expected after '--'"
1015 \]
1016 set efm=%EError\ %n,%Cline\ %l,%Ccolumn\ %c,%Z%m
1017 cgetexpr lines
1018 let l = getqflist()
1019 call assert_equal(275, l[0].nr)
1020 call assert_equal(42, l[0].lnum)
1021 call assert_equal(3, l[0].col)
1022 call assert_equal('E', l[0].type)
1023 call assert_equal("\n' ' expected after '--'", l[0].text)
1024
1025 " Test for %>
1026 let lines = ["Error in line 147 of foo.c:",
1027 \"unknown variable 'i'"
1028 \]
1029 set efm=unknown\ variable\ %m,%E%>Error\ in\ line\ %l\ of\ %f:,%Z%m
1030 cgetexpr lines
1031 let l = getqflist()
1032 call assert_equal(147, l[0].lnum)
1033 call assert_equal('E', l[0].type)
1034 call assert_equal("\nunknown variable 'i'", l[0].text)
Bram Moolenaar049cba92016-06-26 14:38:04 +02001035
Bram Moolenaare87e6dd2016-07-17 19:25:04 +02001036 " Test for %A, %C and other formats
1037 let lines = [
1038 \"==============================================================",
1039 \"FAIL: testGetTypeIdCachesResult (dbfacadeTest.DjsDBFacadeTest)",
1040 \"--------------------------------------------------------------",
1041 \"Traceback (most recent call last):",
1042 \' File "unittests/dbfacadeTest.py", line 89, in testFoo',
1043 \" self.assertEquals(34, dtid)",
1044 \' File "/usr/lib/python2.2/unittest.py", line 286, in',
1045 \" failUnlessEqual",
1046 \" raise self.failureException, \\",
1047 \"AssertionError: 34 != 33",
1048 \"",
1049 \"--------------------------------------------------------------",
1050 \"Ran 27 tests in 0.063s"
1051 \]
1052 set efm=%C\ %.%#,%A\ \ File\ \"%f\"\\,\ line\ %l%.%#,%Z%[%^\ ]%\\@=%m
1053 cgetexpr lines
1054 let l = getqflist()
1055 call assert_equal(8, len(l))
1056 call assert_equal(89, l[4].lnum)
1057 call assert_equal(1, l[4].valid)
1058 call assert_equal('unittests/dbfacadeTest.py', bufname(l[4].bufnr))
1059
Bram Moolenaar049cba92016-06-26 14:38:04 +02001060 let &efm = save_efm
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001061endfunc
Bram Moolenaar049cba92016-06-26 14:38:04 +02001062
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001063func XquickfixChangedByAutocmd(cchar)
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001064 call s:setup_commands(a:cchar)
Bram Moolenaarffec3c52016-03-23 20:55:42 +01001065 if a:cchar == 'c'
Bram Moolenaarffec3c52016-03-23 20:55:42 +01001066 let ErrorNr = 'E925'
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001067 func! ReadFunc()
Bram Moolenaarffec3c52016-03-23 20:55:42 +01001068 colder
1069 cgetexpr []
1070 endfunc
1071 else
Bram Moolenaarffec3c52016-03-23 20:55:42 +01001072 let ErrorNr = 'E926'
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001073 func! ReadFunc()
Bram Moolenaarffec3c52016-03-23 20:55:42 +01001074 lolder
1075 lgetexpr []
1076 endfunc
1077 endif
1078
1079 augroup testgroup
1080 au!
Bram Moolenaard106e5b2016-04-21 19:38:07 +02001081 autocmd BufReadCmd test_changed.txt call ReadFunc()
Bram Moolenaarffec3c52016-03-23 20:55:42 +01001082 augroup END
1083
Bram Moolenaard106e5b2016-04-21 19:38:07 +02001084 new | only
Bram Moolenaarffec3c52016-03-23 20:55:42 +01001085 let words = [ "a", "b" ]
1086 let qflist = []
1087 for word in words
Bram Moolenaard106e5b2016-04-21 19:38:07 +02001088 call add(qflist, {'filename': 'test_changed.txt'})
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001089 call g:Xsetlist(qflist, ' ')
Bram Moolenaarffec3c52016-03-23 20:55:42 +01001090 endfor
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001091 call assert_fails('Xrewind', ErrorNr . ':')
Bram Moolenaarffec3c52016-03-23 20:55:42 +01001092
1093 augroup! testgroup
1094endfunc
1095
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001096func Test_quickfix_was_changed_by_autocmd()
Bram Moolenaarffec3c52016-03-23 20:55:42 +01001097 call XquickfixChangedByAutocmd('c')
1098 call XquickfixChangedByAutocmd('l')
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001099endfunc
Bram Moolenaar8b201792016-03-25 15:01:10 +01001100
1101func Test_caddbuffer_to_empty()
1102 helpgr quickfix
1103 call setqflist([], 'r')
1104 cad
Bram Moolenaarf68f1d72016-03-25 17:14:06 +01001105 try
1106 cn
1107 catch
1108 " number of matches is unknown
1109 call assert_true(v:exception =~ 'E553:')
1110 endtry
Bram Moolenaar8b201792016-03-25 15:01:10 +01001111 quit!
1112endfunc
Bram Moolenaar89c64d52016-03-27 18:44:40 +02001113
1114func Test_cgetexpr_works()
1115 " this must not crash Vim
1116 cgetexpr [$x]
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001117 lgetexpr [$x]
Bram Moolenaar89c64d52016-03-27 18:44:40 +02001118endfunc
Bram Moolenaarc1808d52016-04-18 20:04:00 +02001119
1120" Tests for the setqflist() and setloclist() functions
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001121func SetXlistTests(cchar, bnum)
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001122 call s:setup_commands(a:cchar)
Bram Moolenaarc1808d52016-04-18 20:04:00 +02001123
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001124 call g:Xsetlist([{'bufnr': a:bnum, 'lnum': 1},
Bram Moolenaarc1808d52016-04-18 20:04:00 +02001125 \ {'bufnr': a:bnum, 'lnum': 2}])
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001126 let l = g:Xgetlist()
Bram Moolenaarc1808d52016-04-18 20:04:00 +02001127 call assert_equal(2, len(l))
1128 call assert_equal(2, l[1].lnum)
1129
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001130 Xnext
1131 call g:Xsetlist([{'bufnr': a:bnum, 'lnum': 3}], 'a')
1132 let l = g:Xgetlist()
Bram Moolenaarc1808d52016-04-18 20:04:00 +02001133 call assert_equal(3, len(l))
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001134 Xnext
Bram Moolenaarc1808d52016-04-18 20:04:00 +02001135 call assert_equal(3, line('.'))
1136
Bram Moolenaar2b2b8ae2016-05-24 19:59:51 +02001137 " Appending entries to the list should not change the cursor position
1138 " in the quickfix window
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001139 Xwindow
Bram Moolenaar2b2b8ae2016-05-24 19:59:51 +02001140 1
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001141 call g:Xsetlist([{'bufnr': a:bnum, 'lnum': 4},
Bram Moolenaar2b2b8ae2016-05-24 19:59:51 +02001142 \ {'bufnr': a:bnum, 'lnum': 5}], 'a')
1143 call assert_equal(1, line('.'))
1144 close
1145
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001146 call g:Xsetlist([{'bufnr': a:bnum, 'lnum': 3},
Bram Moolenaarc1808d52016-04-18 20:04:00 +02001147 \ {'bufnr': a:bnum, 'lnum': 4},
1148 \ {'bufnr': a:bnum, 'lnum': 5}], 'r')
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001149 let l = g:Xgetlist()
Bram Moolenaarc1808d52016-04-18 20:04:00 +02001150 call assert_equal(3, len(l))
1151 call assert_equal(5, l[2].lnum)
1152
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001153 call g:Xsetlist([])
1154 let l = g:Xgetlist()
Bram Moolenaarc1808d52016-04-18 20:04:00 +02001155 call assert_equal(0, len(l))
Bram Moolenaaree85df32017-03-19 14:19:50 +01001156
1157 " Error cases:
1158 " Refer to a non-existing buffer and pass a non-dictionary type
1159 call assert_fails("call g:Xsetlist([{'bufnr':998, 'lnum':4}," .
1160 \ " {'bufnr':999, 'lnum':5}])", 'E92:')
1161 call g:Xsetlist([[1, 2,3]])
1162 call assert_equal(0, len(g:Xgetlist()))
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001163endfunc
Bram Moolenaarc1808d52016-04-18 20:04:00 +02001164
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001165func Test_setqflist()
Bram Moolenaarc1808d52016-04-18 20:04:00 +02001166 new Xtestfile | only
1167 let bnum = bufnr('%')
1168 call setline(1, range(1,5))
1169
1170 call SetXlistTests('c', bnum)
1171 call SetXlistTests('l', bnum)
1172
Bram Moolenaar1cee6932016-06-09 22:17:22 +02001173 enew!
Bram Moolenaarc1808d52016-04-18 20:04:00 +02001174 call delete('Xtestfile')
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001175endfunc
Bram Moolenaard106e5b2016-04-21 19:38:07 +02001176
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001177func Xlist_empty_middle(cchar)
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001178 call s:setup_commands(a:cchar)
1179
Bram Moolenaar1cee6932016-06-09 22:17:22 +02001180 " create three quickfix lists
Bram Moolenaaree85df32017-03-19 14:19:50 +01001181 let @/ = 'Test_'
1182 Xvimgrep // test_quickfix.vim
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001183 let testlen = len(g:Xgetlist())
Bram Moolenaar1cee6932016-06-09 22:17:22 +02001184 call assert_true(testlen > 0)
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001185 Xvimgrep empty test_quickfix.vim
1186 call assert_true(len(g:Xgetlist()) > 0)
1187 Xvimgrep matches test_quickfix.vim
1188 let matchlen = len(g:Xgetlist())
Bram Moolenaar1cee6932016-06-09 22:17:22 +02001189 call assert_true(matchlen > 0)
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001190 Xolder
Bram Moolenaar1cee6932016-06-09 22:17:22 +02001191 " make the middle list empty
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001192 call g:Xsetlist([], 'r')
1193 call assert_true(len(g:Xgetlist()) == 0)
1194 Xolder
1195 call assert_equal(testlen, len(g:Xgetlist()))
1196 Xnewer
1197 Xnewer
1198 call assert_equal(matchlen, len(g:Xgetlist()))
Bram Moolenaar1cee6932016-06-09 22:17:22 +02001199endfunc
1200
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001201func Test_setqflist_empty_middle()
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001202 call Xlist_empty_middle('c')
1203 call Xlist_empty_middle('l')
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001204endfunc
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001205
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001206func Xlist_empty_older(cchar)
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001207 call s:setup_commands(a:cchar)
1208
Bram Moolenaar1cee6932016-06-09 22:17:22 +02001209 " create three quickfix lists
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001210 Xvimgrep one test_quickfix.vim
1211 let onelen = len(g:Xgetlist())
Bram Moolenaar1cee6932016-06-09 22:17:22 +02001212 call assert_true(onelen > 0)
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001213 Xvimgrep two test_quickfix.vim
1214 let twolen = len(g:Xgetlist())
Bram Moolenaar1cee6932016-06-09 22:17:22 +02001215 call assert_true(twolen > 0)
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001216 Xvimgrep three test_quickfix.vim
1217 let threelen = len(g:Xgetlist())
Bram Moolenaar1cee6932016-06-09 22:17:22 +02001218 call assert_true(threelen > 0)
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001219 Xolder 2
Bram Moolenaar1cee6932016-06-09 22:17:22 +02001220 " make the first list empty, check the others didn't change
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001221 call g:Xsetlist([], 'r')
1222 call assert_true(len(g:Xgetlist()) == 0)
1223 Xnewer
1224 call assert_equal(twolen, len(g:Xgetlist()))
1225 Xnewer
1226 call assert_equal(threelen, len(g:Xgetlist()))
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001227endfunc
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001228
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001229func Test_setqflist_empty_older()
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001230 call Xlist_empty_older('c')
1231 call Xlist_empty_older('l')
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001232endfunc
Bram Moolenaar1cee6932016-06-09 22:17:22 +02001233
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001234func XquickfixSetListWithAct(cchar)
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001235 call s:setup_commands(a:cchar)
1236
Bram Moolenaard106e5b2016-04-21 19:38:07 +02001237 let list1 = [{'filename': 'fnameA', 'text': 'A'},
1238 \ {'filename': 'fnameB', 'text': 'B'}]
1239 let list2 = [{'filename': 'fnameC', 'text': 'C'},
1240 \ {'filename': 'fnameD', 'text': 'D'},
1241 \ {'filename': 'fnameE', 'text': 'E'}]
1242
1243 " {action} is unspecified. Same as specifing ' '.
1244 new | only
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001245 silent! Xnewer 99
1246 call g:Xsetlist(list1)
1247 call g:Xsetlist(list2)
1248 let li = g:Xgetlist()
Bram Moolenaard106e5b2016-04-21 19:38:07 +02001249 call assert_equal(3, len(li))
1250 call assert_equal('C', li[0]['text'])
1251 call assert_equal('D', li[1]['text'])
1252 call assert_equal('E', li[2]['text'])
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001253 silent! Xolder
1254 let li = g:Xgetlist()
Bram Moolenaard106e5b2016-04-21 19:38:07 +02001255 call assert_equal(2, len(li))
1256 call assert_equal('A', li[0]['text'])
1257 call assert_equal('B', li[1]['text'])
1258
1259 " {action} is specified ' '.
1260 new | only
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001261 silent! Xnewer 99
1262 call g:Xsetlist(list1)
1263 call g:Xsetlist(list2, ' ')
1264 let li = g:Xgetlist()
Bram Moolenaard106e5b2016-04-21 19:38:07 +02001265 call assert_equal(3, len(li))
1266 call assert_equal('C', li[0]['text'])
1267 call assert_equal('D', li[1]['text'])
1268 call assert_equal('E', li[2]['text'])
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001269 silent! Xolder
1270 let li = g:Xgetlist()
Bram Moolenaard106e5b2016-04-21 19:38:07 +02001271 call assert_equal(2, len(li))
1272 call assert_equal('A', li[0]['text'])
1273 call assert_equal('B', li[1]['text'])
1274
1275 " {action} is specified 'a'.
1276 new | only
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001277 silent! Xnewer 99
1278 call g:Xsetlist(list1)
1279 call g:Xsetlist(list2, 'a')
1280 let li = g:Xgetlist()
Bram Moolenaard106e5b2016-04-21 19:38:07 +02001281 call assert_equal(5, len(li))
1282 call assert_equal('A', li[0]['text'])
1283 call assert_equal('B', li[1]['text'])
1284 call assert_equal('C', li[2]['text'])
1285 call assert_equal('D', li[3]['text'])
1286 call assert_equal('E', li[4]['text'])
1287
1288 " {action} is specified 'r'.
1289 new | only
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001290 silent! Xnewer 99
1291 call g:Xsetlist(list1)
1292 call g:Xsetlist(list2, 'r')
1293 let li = g:Xgetlist()
Bram Moolenaard106e5b2016-04-21 19:38:07 +02001294 call assert_equal(3, len(li))
1295 call assert_equal('C', li[0]['text'])
1296 call assert_equal('D', li[1]['text'])
1297 call assert_equal('E', li[2]['text'])
1298
1299 " Test for wrong value.
1300 new | only
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001301 call assert_fails("call g:Xsetlist(0)", 'E714:')
1302 call assert_fails("call g:Xsetlist(list1, '')", 'E927:')
1303 call assert_fails("call g:Xsetlist(list1, 'aa')", 'E927:')
1304 call assert_fails("call g:Xsetlist(list1, ' a')", 'E927:')
1305 call assert_fails("call g:Xsetlist(list1, 0)", 'E928:')
Bram Moolenaard106e5b2016-04-21 19:38:07 +02001306endfunc
1307
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001308func Test_quickfix_set_list_with_act()
Bram Moolenaard106e5b2016-04-21 19:38:07 +02001309 call XquickfixSetListWithAct('c')
1310 call XquickfixSetListWithAct('l')
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001311endfunc
Bram Moolenaar6be8c8e2016-04-30 13:17:09 +02001312
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001313func XLongLinesTests(cchar)
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001314 let l = g:Xgetlist()
Bram Moolenaar6be8c8e2016-04-30 13:17:09 +02001315
Bram Moolenaar049cba92016-06-26 14:38:04 +02001316 call assert_equal(4, len(l))
Bram Moolenaar6be8c8e2016-04-30 13:17:09 +02001317 call assert_equal(1, l[0].lnum)
1318 call assert_equal(1, l[0].col)
Bram Moolenaar049cba92016-06-26 14:38:04 +02001319 call assert_equal(1975, len(l[0].text))
Bram Moolenaar6be8c8e2016-04-30 13:17:09 +02001320 call assert_equal(2, l[1].lnum)
1321 call assert_equal(1, l[1].col)
1322 call assert_equal(4070, len(l[1].text))
1323 call assert_equal(3, l[2].lnum)
1324 call assert_equal(1, l[2].col)
Bram Moolenaar049cba92016-06-26 14:38:04 +02001325 call assert_equal(4070, len(l[2].text))
1326 call assert_equal(4, l[3].lnum)
1327 call assert_equal(1, l[3].col)
1328 call assert_equal(10, len(l[3].text))
Bram Moolenaar6be8c8e2016-04-30 13:17:09 +02001329
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001330 call g:Xsetlist([], 'r')
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001331endfunc
Bram Moolenaar6be8c8e2016-04-30 13:17:09 +02001332
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001333func s:long_lines_tests(cchar)
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001334 call s:setup_commands(a:cchar)
1335
Bram Moolenaar6be8c8e2016-04-30 13:17:09 +02001336 let testfile = 'samples/quickfix.txt'
1337
1338 " file
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001339 exe 'Xgetfile' testfile
1340 call XLongLinesTests(a:cchar)
Bram Moolenaar6be8c8e2016-04-30 13:17:09 +02001341
1342 " list
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001343 Xexpr readfile(testfile)
1344 call XLongLinesTests(a:cchar)
Bram Moolenaar6be8c8e2016-04-30 13:17:09 +02001345
1346 " string
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001347 Xexpr join(readfile(testfile), "\n")
1348 call XLongLinesTests(a:cchar)
Bram Moolenaar6be8c8e2016-04-30 13:17:09 +02001349
1350 " buffer
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001351 exe 'edit' testfile
1352 exe 'Xbuffer' bufnr('%')
Bram Moolenaarf50df392016-06-21 21:33:34 +02001353 call XLongLinesTests(a:cchar)
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001354endfunc
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001355
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001356func Test_long_lines()
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001357 call s:long_lines_tests('c')
1358 call s:long_lines_tests('l')
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001359endfunc
Bram Moolenaar049cba92016-06-26 14:38:04 +02001360
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001361func s:create_test_file(filename)
Bram Moolenaar049cba92016-06-26 14:38:04 +02001362 let l = []
1363 for i in range(1, 20)
1364 call add(l, 'Line' . i)
1365 endfor
1366 call writefile(l, a:filename)
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001367endfunc
Bram Moolenaar049cba92016-06-26 14:38:04 +02001368
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001369func Test_switchbuf()
Bram Moolenaar049cba92016-06-26 14:38:04 +02001370 call s:create_test_file('Xqftestfile1')
1371 call s:create_test_file('Xqftestfile2')
1372 call s:create_test_file('Xqftestfile3')
1373
1374 new | only
1375 edit Xqftestfile1
1376 let file1_winid = win_getid()
1377 new Xqftestfile2
1378 let file2_winid = win_getid()
1379 cgetexpr ['Xqftestfile1:5:Line5',
1380 \ 'Xqftestfile1:6:Line6',
1381 \ 'Xqftestfile2:10:Line10',
1382 \ 'Xqftestfile2:11:Line11',
1383 \ 'Xqftestfile3:15:Line15',
1384 \ 'Xqftestfile3:16:Line16']
1385
1386 new
1387 let winid = win_getid()
1388 cfirst | cnext
1389 call assert_equal(winid, win_getid())
1390 cnext | cnext
1391 call assert_equal(winid, win_getid())
1392 cnext | cnext
1393 call assert_equal(winid, win_getid())
1394 enew
1395
1396 set switchbuf=useopen
1397 cfirst | cnext
1398 call assert_equal(file1_winid, win_getid())
1399 cnext | cnext
1400 call assert_equal(file2_winid, win_getid())
1401 cnext | cnext
1402 call assert_equal(file2_winid, win_getid())
1403
1404 enew | only
1405 set switchbuf=usetab
1406 tabedit Xqftestfile1
1407 tabedit Xqftestfile2
1408 tabfirst
1409 cfirst | cnext
1410 call assert_equal(2, tabpagenr())
1411 cnext | cnext
1412 call assert_equal(3, tabpagenr())
1413 cnext | cnext
1414 call assert_equal(3, tabpagenr())
1415 tabfirst | tabonly | enew
1416
1417 set switchbuf=split
1418 cfirst | cnext
1419 call assert_equal(1, winnr('$'))
1420 cnext | cnext
1421 call assert_equal(2, winnr('$'))
1422 cnext | cnext
1423 call assert_equal(3, winnr('$'))
1424 enew | only
1425
1426 set switchbuf=newtab
1427 cfirst | cnext
1428 call assert_equal(1, tabpagenr('$'))
1429 cnext | cnext
1430 call assert_equal(2, tabpagenr('$'))
1431 cnext | cnext
1432 call assert_equal(3, tabpagenr('$'))
1433 tabfirst | enew | tabonly | only
1434
1435 set switchbuf=
1436 edit Xqftestfile1
1437 let file1_winid = win_getid()
1438 new Xqftestfile2
1439 let file2_winid = win_getid()
1440 copen
1441 exe "normal 1G\<CR>"
1442 call assert_equal(file1_winid, win_getid())
1443 copen
1444 exe "normal 3G\<CR>"
1445 call assert_equal(file2_winid, win_getid())
1446 copen | only
1447 exe "normal 5G\<CR>"
1448 call assert_equal(2, winnr('$'))
1449 call assert_equal(1, bufwinnr('Xqftestfile3'))
1450
Bram Moolenaar391b1dd2017-03-04 13:47:11 +01001451 " If only quickfix window is open in the current tabpage, jumping to an
1452 " entry with 'switchubf' set to 'usetab' should search in other tabpages.
Bram Moolenaar049cba92016-06-26 14:38:04 +02001453 enew | only
Bram Moolenaar391b1dd2017-03-04 13:47:11 +01001454 set switchbuf=usetab
1455 tabedit Xqftestfile1
1456 tabedit Xqftestfile2
1457 tabedit Xqftestfile3
1458 tabfirst
1459 copen | only
1460 clast
1461 call assert_equal(4, tabpagenr())
1462 tabfirst | tabonly | enew | only
Bram Moolenaar049cba92016-06-26 14:38:04 +02001463
1464 call delete('Xqftestfile1')
1465 call delete('Xqftestfile2')
1466 call delete('Xqftestfile3')
Bram Moolenaar391b1dd2017-03-04 13:47:11 +01001467 set switchbuf&vim
1468
1469 enew | only
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001470endfunc
Bram Moolenaar049cba92016-06-26 14:38:04 +02001471
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001472func Xadjust_qflnum(cchar)
Bram Moolenaar049cba92016-06-26 14:38:04 +02001473 call s:setup_commands(a:cchar)
1474
1475 enew | only
1476
Bram Moolenaarc1542742016-07-20 21:44:37 +02001477 let fname = 'Xqftestfile' . a:cchar
1478 call s:create_test_file(fname)
1479 exe 'edit ' . fname
Bram Moolenaar049cba92016-06-26 14:38:04 +02001480
Bram Moolenaarc1542742016-07-20 21:44:37 +02001481 Xgetexpr [fname . ':5:Line5',
1482 \ fname . ':10:Line10',
1483 \ fname . ':15:Line15',
1484 \ fname . ':20:Line20']
Bram Moolenaar049cba92016-06-26 14:38:04 +02001485
1486 6,14delete
1487 call append(6, ['Buffer', 'Window'])
1488
1489 let l = g:Xgetlist()
1490
1491 call assert_equal(5, l[0].lnum)
1492 call assert_equal(6, l[2].lnum)
1493 call assert_equal(13, l[3].lnum)
1494
1495 enew!
Bram Moolenaarc1542742016-07-20 21:44:37 +02001496 call delete(fname)
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001497endfunc
Bram Moolenaar049cba92016-06-26 14:38:04 +02001498
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001499func Test_adjust_lnum()
Bram Moolenaarc1542742016-07-20 21:44:37 +02001500 call setloclist(0, [])
Bram Moolenaar049cba92016-06-26 14:38:04 +02001501 call Xadjust_qflnum('c')
Bram Moolenaarc1542742016-07-20 21:44:37 +02001502 call setqflist([])
Bram Moolenaar049cba92016-06-26 14:38:04 +02001503 call Xadjust_qflnum('l')
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001504endfunc
Bram Moolenaar049cba92016-06-26 14:38:04 +02001505
1506" Tests for the :grep/:lgrep and :grepadd/:lgrepadd commands
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001507func s:test_xgrep(cchar)
Bram Moolenaar049cba92016-06-26 14:38:04 +02001508 call s:setup_commands(a:cchar)
1509
1510 " The following lines are used for the grep test. Don't remove.
1511 " Grep_Test_Text: Match 1
1512 " Grep_Test_Text: Match 2
1513 " GrepAdd_Test_Text: Match 1
1514 " GrepAdd_Test_Text: Match 2
1515 enew! | only
1516 set makeef&vim
1517 silent Xgrep Grep_Test_Text: test_quickfix.vim
1518 call assert_true(len(g:Xgetlist()) == 3)
1519 Xopen
1520 call assert_true(w:quickfix_title =~ '^:grep')
1521 Xclose
1522 enew
1523 set makeef=Temp_File_##
1524 silent Xgrepadd GrepAdd_Test_Text: test_quickfix.vim
1525 call assert_true(len(g:Xgetlist()) == 6)
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001526endfunc
Bram Moolenaar049cba92016-06-26 14:38:04 +02001527
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001528func Test_grep()
Bram Moolenaar049cba92016-06-26 14:38:04 +02001529 if !has('unix')
1530 " The grepprg may not be set on non-Unix systems
1531 return
1532 endif
1533
1534 call s:test_xgrep('c')
1535 call s:test_xgrep('l')
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001536endfunc
Bram Moolenaar361c8f02016-07-02 15:41:47 +02001537
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001538func Test_two_windows()
Bram Moolenaar361c8f02016-07-02 15:41:47 +02001539 " Use one 'errorformat' for two windows. Add an expression to each of them,
1540 " make sure they each keep their own state.
1541 set efm=%DEntering\ dir\ '%f',%f:%l:%m,%XLeaving\ dir\ '%f'
1542 call mkdir('Xone/a', 'p')
1543 call mkdir('Xtwo/a', 'p')
1544 let lines = ['1', '2', 'one one one', '4', 'two two two', '6', '7']
1545 call writefile(lines, 'Xone/a/one.txt')
1546 call writefile(lines, 'Xtwo/a/two.txt')
1547
1548 new one
1549 let one_id = win_getid()
1550 lexpr ""
1551 new two
1552 let two_id = win_getid()
1553 lexpr ""
1554
1555 laddexpr "Entering dir 'Xtwo/a'"
1556 call win_gotoid(one_id)
1557 laddexpr "Entering dir 'Xone/a'"
1558 call win_gotoid(two_id)
1559 laddexpr 'two.txt:5:two two two'
1560 call win_gotoid(one_id)
1561 laddexpr 'one.txt:3:one one one'
1562
1563 let loc_one = getloclist(one_id)
Bram Moolenaar361c8f02016-07-02 15:41:47 +02001564 call assert_equal('Xone/a/one.txt', bufname(loc_one[1].bufnr))
1565 call assert_equal(3, loc_one[1].lnum)
1566
1567 let loc_two = getloclist(two_id)
Bram Moolenaar361c8f02016-07-02 15:41:47 +02001568 call assert_equal('Xtwo/a/two.txt', bufname(loc_two[1].bufnr))
1569 call assert_equal(5, loc_two[1].lnum)
1570
1571 call win_gotoid(one_id)
1572 bwipe!
1573 call win_gotoid(two_id)
1574 bwipe!
1575 call delete('Xone', 'rf')
1576 call delete('Xtwo', 'rf')
1577endfunc
Bram Moolenaardcb17002016-07-07 18:58:59 +02001578
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001579func XbottomTests(cchar)
Bram Moolenaar537ef082016-07-09 17:56:19 +02001580 call s:setup_commands(a:cchar)
1581
Bram Moolenaarb6fa30c2017-03-29 14:19:25 +02001582 " Calling lbottom without any errors should fail
1583 if a:cchar == 'l'
1584 call assert_fails('lbottom', 'E776:')
1585 endif
1586
Bram Moolenaar537ef082016-07-09 17:56:19 +02001587 call g:Xsetlist([{'filename': 'foo', 'lnum': 42}])
1588 Xopen
Bram Moolenaardcb17002016-07-07 18:58:59 +02001589 let wid = win_getid()
1590 call assert_equal(1, line('.'))
1591 wincmd w
Bram Moolenaar537ef082016-07-09 17:56:19 +02001592 call g:Xsetlist([{'filename': 'var', 'lnum': 24}], 'a')
1593 Xbottom
Bram Moolenaardcb17002016-07-07 18:58:59 +02001594 call win_gotoid(wid)
1595 call assert_equal(2, line('.'))
Bram Moolenaar537ef082016-07-09 17:56:19 +02001596 Xclose
Bram Moolenaardcb17002016-07-07 18:58:59 +02001597endfunc
Bram Moolenaar537ef082016-07-09 17:56:19 +02001598
1599" Tests for the :cbottom and :lbottom commands
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001600func Test_cbottom()
Bram Moolenaar537ef082016-07-09 17:56:19 +02001601 call XbottomTests('c')
1602 call XbottomTests('l')
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001603endfunc
Bram Moolenaarf6acffb2016-07-16 16:54:24 +02001604
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001605func HistoryTest(cchar)
Bram Moolenaarf6acffb2016-07-16 16:54:24 +02001606 call s:setup_commands(a:cchar)
1607
Bram Moolenaarf6acffb2016-07-16 16:54:24 +02001608 " clear all lists after the first one, then replace the first one.
1609 call g:Xsetlist([])
Bram Moolenaarb6fa30c2017-03-29 14:19:25 +02001610 call assert_fails('Xolder 99', 'E380:')
Bram Moolenaarf6acffb2016-07-16 16:54:24 +02001611 let entry = {'filename': 'foo', 'lnum': 42}
1612 call g:Xsetlist([entry], 'r')
1613 call g:Xsetlist([entry, entry])
1614 call g:Xsetlist([entry, entry, entry])
1615 let res = split(execute(a:cchar . 'hist'), "\n")
1616 call assert_equal(3, len(res))
1617 let common = 'errors :set' . (a:cchar == 'c' ? 'qf' : 'loc') . 'list()'
1618 call assert_equal(' error list 1 of 3; 1 ' . common, res[0])
1619 call assert_equal(' error list 2 of 3; 2 ' . common, res[1])
1620 call assert_equal('> error list 3 of 3; 3 ' . common, res[2])
1621endfunc
1622
1623func Test_history()
1624 call HistoryTest('c')
1625 call HistoryTest('l')
1626endfunc
Bram Moolenaar015102e2016-07-16 18:24:56 +02001627
1628func Test_duplicate_buf()
1629 " make sure we can get the highest buffer number
1630 edit DoesNotExist
1631 edit DoesNotExist2
1632 let last_buffer = bufnr("$")
1633
1634 " make sure only one buffer is created
1635 call writefile(['this one', 'that one'], 'Xgrepthis')
1636 vimgrep one Xgrepthis
1637 vimgrep one Xgrepthis
1638 call assert_equal(last_buffer + 1, bufnr("$"))
1639
1640 call delete('Xgrepthis')
1641endfunc
Bram Moolenaard823fa92016-08-12 16:29:27 +02001642
1643" Quickfix/Location list set/get properties tests
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001644func Xproperty_tests(cchar)
Bram Moolenaard823fa92016-08-12 16:29:27 +02001645 call s:setup_commands(a:cchar)
1646
1647 " Error cases
1648 call assert_fails('call g:Xgetlist(99)', 'E715:')
1649 call assert_fails('call g:Xsetlist(99)', 'E714:')
1650 call assert_fails('call g:Xsetlist([], "a", [])', 'E715:')
1651
1652 " Set and get the title
Bram Moolenaarb6fa30c2017-03-29 14:19:25 +02001653 call g:Xsetlist([])
Bram Moolenaard823fa92016-08-12 16:29:27 +02001654 Xopen
1655 wincmd p
1656 call g:Xsetlist([{'filename':'foo', 'lnum':27}])
1657 call g:Xsetlist([], 'a', {'title' : 'Sample'})
1658 let d = g:Xgetlist({"title":1})
1659 call assert_equal('Sample', d.title)
1660
1661 Xopen
1662 call assert_equal('Sample', w:quickfix_title)
1663 Xclose
1664
Bram Moolenaar2b529bb2016-08-27 13:35:35 +02001665 " Tests for action argument
1666 silent! Xolder 999
1667 let qfnr = g:Xgetlist({'all':1}).nr
1668 call g:Xsetlist([], 'r', {'title' : 'N1'})
1669 call assert_equal('N1', g:Xgetlist({'all':1}).title)
1670 call g:Xsetlist([], ' ', {'title' : 'N2'})
1671 call assert_equal(qfnr + 1, g:Xgetlist({'all':1}).nr)
Bram Moolenaar890680c2016-09-27 21:28:56 +02001672
1673 let res = g:Xgetlist({'nr': 0})
1674 call assert_equal(qfnr + 1, res.nr)
1675 call assert_equal(['nr'], keys(res))
1676
Bram Moolenaar2b529bb2016-08-27 13:35:35 +02001677 call g:Xsetlist([], ' ', {'title' : 'N3'})
1678 call assert_equal('N2', g:Xgetlist({'nr':2, 'title':1}).title)
1679
Bram Moolenaaree85df32017-03-19 14:19:50 +01001680 " Changing the title of an earlier quickfix list
1681 call g:Xsetlist([], ' ', {'title' : 'NewTitle', 'nr' : 2})
1682 call assert_equal('NewTitle', g:Xgetlist({'nr':2, 'title':1}).title)
1683
1684 " Changing the title of an invalid quickfix list
1685 call assert_equal(-1, g:Xsetlist([], ' ',
1686 \ {'title' : 'SomeTitle', 'nr' : 99}))
1687 call assert_equal(-1, g:Xsetlist([], ' ',
1688 \ {'title' : 'SomeTitle', 'nr' : 'abc'}))
1689
1690 if a:cchar == 'c'
1691 copen
1692 call assert_equal({'winid':win_getid()}, getqflist({'winid':1}))
1693 cclose
1694 endif
1695
Bram Moolenaard823fa92016-08-12 16:29:27 +02001696 " Invalid arguments
1697 call assert_fails('call g:Xgetlist([])', 'E715')
1698 call assert_fails('call g:Xsetlist([], "a", [])', 'E715')
1699 let s = g:Xsetlist([], 'a', {'abc':1})
1700 call assert_equal(-1, s)
1701
1702 call assert_equal({}, g:Xgetlist({'abc':1}))
Bram Moolenaaree85df32017-03-19 14:19:50 +01001703 call assert_equal({}, g:Xgetlist({'nr':99, 'title':1}))
1704 call assert_equal({}, g:Xgetlist({'nr':[], 'title':1}))
Bram Moolenaard823fa92016-08-12 16:29:27 +02001705
1706 if a:cchar == 'l'
Bram Moolenaar890680c2016-09-27 21:28:56 +02001707 call assert_equal({}, getloclist(99, {'title': 1}))
Bram Moolenaard823fa92016-08-12 16:29:27 +02001708 endif
Bram Moolenaaree85df32017-03-19 14:19:50 +01001709endfunc
Bram Moolenaard823fa92016-08-12 16:29:27 +02001710
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001711func Test_qf_property()
Bram Moolenaard823fa92016-08-12 16:29:27 +02001712 call Xproperty_tests('c')
1713 call Xproperty_tests('l')
Bram Moolenaaree85df32017-03-19 14:19:50 +01001714endfunc
Bram Moolenaar04c4ce62016-09-01 15:45:58 +02001715
1716" Tests for the QuickFixCmdPre/QuickFixCmdPost autocommands
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001717func QfAutoCmdHandler(loc, cmd)
Bram Moolenaar04c4ce62016-09-01 15:45:58 +02001718 call add(g:acmds, a:loc . a:cmd)
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001719endfunc
Bram Moolenaar04c4ce62016-09-01 15:45:58 +02001720
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001721func Test_Autocmd()
Bram Moolenaar04c4ce62016-09-01 15:45:58 +02001722 autocmd QuickFixCmdPre * call QfAutoCmdHandler('pre', expand('<amatch>'))
1723 autocmd QuickFixCmdPost * call QfAutoCmdHandler('post', expand('<amatch>'))
1724
1725 let g:acmds = []
1726 cexpr "F1:10:Line 10"
1727 caddexpr "F1:20:Line 20"
1728 cgetexpr "F1:30:Line 30"
1729 enew! | call append(0, "F2:10:Line 10")
1730 cbuffer!
1731 enew! | call append(0, "F2:20:Line 20")
1732 cgetbuffer
1733 enew! | call append(0, "F2:30:Line 30")
1734 caddbuffer
1735
1736 let l = ['precexpr',
1737 \ 'postcexpr',
1738 \ 'precaddexpr',
1739 \ 'postcaddexpr',
1740 \ 'precgetexpr',
1741 \ 'postcgetexpr',
1742 \ 'precbuffer',
1743 \ 'postcbuffer',
1744 \ 'precgetbuffer',
1745 \ 'postcgetbuffer',
1746 \ 'precaddbuffer',
1747 \ 'postcaddbuffer']
1748 call assert_equal(l, g:acmds)
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001749endfunc
Bram Moolenaar21662be2016-11-06 14:46:44 +01001750
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001751func Test_Autocmd_Exception()
Bram Moolenaar21662be2016-11-06 14:46:44 +01001752 set efm=%m
1753 lgetexpr '?'
1754
1755 try
1756 call DoesNotExit()
1757 catch
1758 lgetexpr '1'
1759 finally
1760 lgetexpr '1'
1761 endtry
1762
1763 call assert_equal('1', getloclist(0)[0].text)
1764
1765 set efm&vim
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001766endfunc
Bram Moolenaar63bed3d2016-11-12 15:36:54 +01001767
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001768func Test_caddbuffer_wrong()
1769 " This used to cause a memory access in freed memory.
Bram Moolenaar63bed3d2016-11-12 15:36:54 +01001770 let save_efm = &efm
1771 set efm=%EEEE%m,%WWWW,%+CCCC%>%#,%GGGG%.#
1772 cgetexpr ['WWWW', 'EEEE', 'CCCC']
1773 let &efm = save_efm
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001774 caddbuffer
Bram Moolenaar63bed3d2016-11-12 15:36:54 +01001775 bwipe!
1776endfunc
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001777
1778func Test_caddexpr_wrong()
1779 " This used to cause a memory access in freed memory.
1780 cbuffer
1781 cbuffer
1782 copen
1783 let save_efm = &efm
1784 set efm=%
1785 call assert_fails('caddexpr ""', 'E376:')
1786 let &efm = save_efm
1787endfunc
Bram Moolenaar7618e002016-11-13 15:09:26 +01001788
1789func Test_dirstack_cleanup()
1790 " This used to cause a memory access in freed memory.
1791 let save_efm = &efm
1792 lexpr '0'
1793 lopen
1794 fun X(c)
1795 let save_efm=&efm
1796 set efm=%D%f
1797 if a:c == 'c'
1798 caddexpr '::'
1799 else
1800 laddexpr ':0:0'
1801 endif
1802 let &efm=save_efm
1803 endfun
1804 call X('c')
1805 call X('l')
1806 call setqflist([], 'r')
1807 caddbuffer
1808 let &efm = save_efm
1809endfunc
Bram Moolenaar391b1dd2017-03-04 13:47:11 +01001810
1811" Tests for jumping to entries from the location list window and quickfix
1812" window
1813func Test_cwindow_jump()
1814 set efm=%f%%%l%%%m
1815 lgetexpr ["F1%10%Line 10", "F2%20%Line 20", "F3%30%Line 30"]
1816 lopen | only
1817 lfirst
1818 call assert_true(winnr('$') == 2)
1819 call assert_true(winnr() == 1)
1820 " Location list for the new window should be set
1821 call assert_true(getloclist(0)[2].text == 'Line 30')
1822
1823 " Open a scratch buffer
1824 " Open a new window and create a location list
1825 " Open the location list window and close the other window
1826 " Jump to an entry.
1827 " Should create a new window and jump to the entry. The scrtach buffer
1828 " should not be used.
1829 enew | only
1830 set buftype=nofile
1831 below new
1832 lgetexpr ["F1%10%Line 10", "F2%20%Line 20", "F3%30%Line 30"]
1833 lopen
1834 2wincmd c
1835 lnext
1836 call assert_true(winnr('$') == 3)
1837 call assert_true(winnr() == 2)
1838
1839 " Open two windows with two different location lists
1840 " Open the location list window and close the previous window
1841 " Jump to an entry in the location list window
1842 " Should open the file in the first window and not set the location list.
1843 enew | only
1844 lgetexpr ["F1%5%Line 5"]
1845 below new
1846 lgetexpr ["F1%10%Line 10", "F2%20%Line 20", "F3%30%Line 30"]
1847 lopen
1848 2wincmd c
1849 lnext
1850 call assert_true(winnr() == 1)
1851 call assert_true(getloclist(0)[0].text == 'Line 5')
1852
1853 enew | only
1854 cgetexpr ["F1%10%Line 10", "F2%20%Line 20", "F3%30%Line 30"]
1855 copen
1856 cnext
1857 call assert_true(winnr('$') == 2)
1858 call assert_true(winnr() == 1)
1859
1860 enew | only
1861 set efm&vim
1862endfunc
Bram Moolenaaree85df32017-03-19 14:19:50 +01001863
1864func XvimgrepTests(cchar)
1865 call s:setup_commands(a:cchar)
1866
1867 call writefile(['Editor:VIM vim',
1868 \ 'Editor:Emacs EmAcS',
1869 \ 'Editor:Notepad NOTEPAD'], 'Xtestfile1')
1870 call writefile(['Linux', 'MacOS', 'MS-Windows'], 'Xtestfile2')
1871
1872 " Error cases
1873 call assert_fails('Xvimgrep /abc *', 'E682:')
1874
1875 let @/=''
1876 call assert_fails('Xvimgrep // *', 'E35:')
1877
1878 call assert_fails('Xvimgrep abc', 'E683:')
1879 call assert_fails('Xvimgrep a1b2c3 Xtestfile1', 'E480:')
1880 call assert_fails('Xvimgrep pat Xa1b2c3', 'E480:')
1881
1882 Xexpr ""
1883 Xvimgrepadd Notepad Xtestfile1
1884 Xvimgrepadd MacOS Xtestfile2
1885 let l = g:Xgetlist()
1886 call assert_equal(2, len(l))
1887 call assert_equal('Editor:Notepad NOTEPAD', l[0].text)
1888
1889 Xvimgrep #\cvim#g Xtestfile?
1890 let l = g:Xgetlist()
1891 call assert_equal(2, len(l))
1892 call assert_equal(8, l[0].col)
1893 call assert_equal(12, l[1].col)
1894
1895 1Xvimgrep ?Editor? Xtestfile*
1896 let l = g:Xgetlist()
1897 call assert_equal(1, len(l))
1898 call assert_equal('Editor:VIM vim', l[0].text)
1899
1900 edit +3 Xtestfile2
1901 Xvimgrep +\cemacs+j Xtestfile1
1902 let l = g:Xgetlist()
1903 call assert_equal('Xtestfile2', bufname(''))
1904 call assert_equal('Editor:Emacs EmAcS', l[0].text)
1905
1906 call delete('Xtestfile1')
1907 call delete('Xtestfile2')
1908endfunc
1909
1910" Tests for the :vimgrep command
1911func Test_vimgrep()
1912 call XvimgrepTests('c')
1913 call XvimgrepTests('l')
1914endfunc
Bram Moolenaar69f40be2017-04-02 15:15:49 +02001915
1916func XfreeTests(cchar)
1917 call s:setup_commands(a:cchar)
1918
1919 enew | only
1920
1921 " Deleting the quickfix stack should work even When the current list is
1922 " somewhere in the middle of the stack
1923 Xexpr ['Xfile1:10:10:Line 10', 'Xfile1:15:15:Line 15']
1924 Xexpr ['Xfile2:20:20:Line 20', 'Xfile2:25:25:Line 25']
1925 Xexpr ['Xfile3:30:30:Line 30', 'Xfile3:35:35:Line 35']
1926 Xolder
1927 call g:Xsetlist([], 'f')
1928 call assert_equal(0, len(g:Xgetlist()))
1929
1930 " After deleting the stack, adding a new list should create a stack with a
1931 " single list.
1932 Xexpr ['Xfile1:10:10:Line 10', 'Xfile1:15:15:Line 15']
1933 call assert_equal(1, g:Xgetlist({'all':1}).nr)
1934
1935 " Deleting the stack from a quickfix window should update/clear the
1936 " quickfix/location list window.
1937 Xexpr ['Xfile1:10:10:Line 10', 'Xfile1:15:15:Line 15']
1938 Xexpr ['Xfile2:20:20:Line 20', 'Xfile2:25:25:Line 25']
1939 Xexpr ['Xfile3:30:30:Line 30', 'Xfile3:35:35:Line 35']
1940 Xolder
1941 Xwindow
1942 call g:Xsetlist([], 'f')
1943 call assert_equal(2, winnr('$'))
1944 call assert_equal(1, line('$'))
1945 Xclose
1946
1947 " Deleting the stack from a non-quickfix window should update/clear the
1948 " quickfix/location list window.
1949 Xexpr ['Xfile1:10:10:Line 10', 'Xfile1:15:15:Line 15']
1950 Xexpr ['Xfile2:20:20:Line 20', 'Xfile2:25:25:Line 25']
1951 Xexpr ['Xfile3:30:30:Line 30', 'Xfile3:35:35:Line 35']
1952 Xolder
1953 Xwindow
1954 wincmd p
1955 call g:Xsetlist([], 'f')
1956 call assert_equal(0, len(g:Xgetlist()))
1957 wincmd p
1958 call assert_equal(2, winnr('$'))
1959 call assert_equal(1, line('$'))
1960
1961 " After deleting the location list stack, if the location list window is
1962 " opened, then a new location list should be created. So opening the
1963 " location list window again should not create a new window.
1964 if a:cchar == 'l'
1965 lexpr ['Xfile1:10:10:Line 10', 'Xfile1:15:15:Line 15']
1966 wincmd p
1967 lopen
1968 call assert_equal(2, winnr('$'))
1969 endif
1970 Xclose
1971endfunc
1972
1973" Tests for the quickifx free functionality
1974func Test_qf_free()
1975 call XfreeTests('c')
1976 call XfreeTests('l')
1977endfunc