blob: ccd7778e42151e7c1af50d637bd1350b498231dc [file] [log] [blame]
Bram Moolenaareeb1b9c2019-02-10 22:59:04 +01001" Test for the quickfix feature.
Bram Moolenaarda59dd52016-01-05 21:59:58 +01002
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 Moolenaar55b69262017-08-13 13:42:01 +020014 command! -nargs=* -count Xolder <mods><count>colder <args>
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +020015 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>
Bram Moolenaar74240d32017-12-10 15:26:15 +010031 command! -nargs=* -bang -range Xnfile <mods><count>cnfile<bang> <args>
Bram Moolenaar0fcc7c62016-07-02 21:22:52 +020032 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 Moolenaar74240d32017-12-10 15:26:15 +010039 command! -nargs=0 -count Xcc <count>cc
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +020040 let g:Xgetlist = function('getqflist')
41 let g:Xsetlist = function('setqflist')
Bram Moolenaarb6fa30c2017-03-29 14:19:25 +020042 call setqflist([], 'f')
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +020043 else
44 command! -nargs=* -bang Xlist <mods>llist<bang> <args>
45 command! -nargs=* Xgetexpr <mods>lgetexpr <args>
Bram Moolenaar361c8f02016-07-02 15:41:47 +020046 command! -nargs=* Xaddexpr <mods>laddexpr <args>
Bram Moolenaar55b69262017-08-13 13:42:01 +020047 command! -nargs=* -count Xolder <mods><count>lolder <args>
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +020048 command! -nargs=* Xnewer <mods>lnewer <args>
49 command! -nargs=* Xopen <mods>lopen <args>
50 command! -nargs=* Xwindow <mods>lwindow <args>
Bram Moolenaar537ef082016-07-09 17:56:19 +020051 command! -nargs=* Xbottom <mods>lbottom <args>
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +020052 command! -nargs=* Xclose <mods>lclose <args>
53 command! -nargs=* -bang Xfile <mods>lfile<bang> <args>
54 command! -nargs=* Xgetfile <mods>lgetfile <args>
55 command! -nargs=* Xaddfile <mods>laddfile <args>
56 command! -nargs=* -bang Xbuffer <mods>lbuffer<bang> <args>
57 command! -nargs=* Xgetbuffer <mods>lgetbuffer <args>
58 command! -nargs=* Xaddbuffer <mods>laddbuffer <args>
59 command! -nargs=* Xrewind <mods>lrewind <args>
Bram Moolenaar99895ea2017-04-20 22:44:47 +020060 command! -count -nargs=* -bang Xnext <mods><count>lnext<bang> <args>
61 command! -count -nargs=* -bang Xprev <mods><count>lprev<bang> <args>
Bram Moolenaar0fcc7c62016-07-02 21:22:52 +020062 command! -nargs=* -bang Xfirst <mods>lfirst<bang> <args>
63 command! -nargs=* -bang Xlast <mods>llast<bang> <args>
Bram Moolenaar74240d32017-12-10 15:26:15 +010064 command! -nargs=* -bang -range Xnfile <mods><count>lnfile<bang> <args>
Bram Moolenaar0fcc7c62016-07-02 21:22:52 +020065 command! -nargs=* -bang Xpfile <mods>lpfile<bang> <args>
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +020066 command! -nargs=* Xexpr <mods>lexpr <args>
Bram Moolenaaree85df32017-03-19 14:19:50 +010067 command! -range -nargs=* Xvimgrep <mods><count>lvimgrep <args>
68 command! -nargs=* Xvimgrepadd <mods>lvimgrepadd <args>
Bram Moolenaar049cba92016-06-26 14:38:04 +020069 command! -nargs=* Xgrep <mods> lgrep <args>
70 command! -nargs=* Xgrepadd <mods> lgrepadd <args>
71 command! -nargs=* Xhelpgrep lhelpgrep <args>
Bram Moolenaar74240d32017-12-10 15:26:15 +010072 command! -nargs=0 -count Xcc <count>ll
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +020073 let g:Xgetlist = function('getloclist', [0])
74 let g:Xsetlist = function('setloclist', [0])
Bram Moolenaarb6fa30c2017-03-29 14:19:25 +020075 call setloclist(0, [], 'f')
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +020076 endif
Bram Moolenaar2b946c92016-11-12 18:14:44 +010077endfunc
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +020078
Bram Moolenaarda59dd52016-01-05 21:59:58 +010079" Tests for the :clist and :llist commands
Bram Moolenaar2b946c92016-11-12 18:14:44 +010080func XlistTests(cchar)
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +020081 call s:setup_commands(a:cchar)
Bram Moolenaarda59dd52016-01-05 21:59:58 +010082
Bram Moolenaarb6fa30c2017-03-29 14:19:25 +020083 if a:cchar == 'l'
84 call assert_fails('llist', 'E776:')
85 endif
Bram Moolenaarda59dd52016-01-05 21:59:58 +010086 " With an empty list, command should return error
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +020087 Xgetexpr []
88 silent! Xlist
Bram Moolenaarda59dd52016-01-05 21:59:58 +010089 call assert_true(v:errmsg ==# 'E42: No Errors')
90
91 " Populate the list and then try
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +020092 Xgetexpr ['non-error 1', 'Xtestfile1:1:3:Line1',
Bram Moolenaarda59dd52016-01-05 21:59:58 +010093 \ 'non-error 2', 'Xtestfile2:2:2:Line2',
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +020094 \ 'non-error 3', 'Xtestfile3:3:1:Line3']
Bram Moolenaarda59dd52016-01-05 21:59:58 +010095
96 " List only valid entries
Bram Moolenaaree85df32017-03-19 14:19:50 +010097 let l = split(execute('Xlist', ''), "\n")
Bram Moolenaarda59dd52016-01-05 21:59:58 +010098 call assert_equal([' 2 Xtestfile1:1 col 3: Line1',
99 \ ' 4 Xtestfile2:2 col 2: Line2',
100 \ ' 6 Xtestfile3:3 col 1: Line3'], l)
101
102 " List all the entries
Bram Moolenaaree85df32017-03-19 14:19:50 +0100103 let l = split(execute('Xlist!', ''), "\n")
Bram Moolenaarda59dd52016-01-05 21:59:58 +0100104 call assert_equal([' 1: non-error 1', ' 2 Xtestfile1:1 col 3: Line1',
105 \ ' 3: non-error 2', ' 4 Xtestfile2:2 col 2: Line2',
106 \ ' 5: non-error 3', ' 6 Xtestfile3:3 col 1: Line3'], l)
107
108 " List a range of errors
Bram Moolenaaree85df32017-03-19 14:19:50 +0100109 let l = split(execute('Xlist 3,6', ''), "\n")
Bram Moolenaarda59dd52016-01-05 21:59:58 +0100110 call assert_equal([' 4 Xtestfile2:2 col 2: Line2',
111 \ ' 6 Xtestfile3:3 col 1: Line3'], l)
112
Bram Moolenaaree85df32017-03-19 14:19:50 +0100113 let l = split(execute('Xlist! 3,4', ''), "\n")
Bram Moolenaarda59dd52016-01-05 21:59:58 +0100114 call assert_equal([' 3: non-error 2', ' 4 Xtestfile2:2 col 2: Line2'], l)
115
Bram Moolenaaree85df32017-03-19 14:19:50 +0100116 let l = split(execute('Xlist -6,-4', ''), "\n")
Bram Moolenaarda59dd52016-01-05 21:59:58 +0100117 call assert_equal([' 2 Xtestfile1:1 col 3: Line1'], l)
118
Bram Moolenaaree85df32017-03-19 14:19:50 +0100119 let l = split(execute('Xlist! -5,-3', ''), "\n")
Bram Moolenaarda59dd52016-01-05 21:59:58 +0100120 call assert_equal([' 2 Xtestfile1:1 col 3: Line1',
121 \ ' 3: non-error 2', ' 4 Xtestfile2:2 col 2: Line2'], l)
Bram Moolenaar391b1dd2017-03-04 13:47:11 +0100122
123 " Test for '+'
Bram Moolenaaree85df32017-03-19 14:19:50 +0100124 let l = split(execute('Xlist! +2', ''), "\n")
Bram Moolenaar391b1dd2017-03-04 13:47:11 +0100125 call assert_equal([' 2 Xtestfile1:1 col 3: Line1',
126 \ ' 3: non-error 2', ' 4 Xtestfile2:2 col 2: Line2'], l)
Bram Moolenaaree85df32017-03-19 14:19:50 +0100127
128 " Different types of errors
129 call g:Xsetlist([{'lnum':10,'col':5,'type':'W', 'text':'Warning','nr':11},
130 \ {'lnum':20,'col':10,'type':'e','text':'Error','nr':22},
131 \ {'lnum':30,'col':15,'type':'i','text':'Info','nr':33},
132 \ {'lnum':40,'col':20,'type':'x', 'text':'Other','nr':44},
133 \ {'lnum':50,'col':25,'type':"\<C-A>",'text':'one','nr':55}])
134 let l = split(execute('Xlist', ""), "\n")
135 call assert_equal([' 1:10 col 5 warning 11: Warning',
136 \ ' 2:20 col 10 error 22: Error',
137 \ ' 3:30 col 15 info 33: Info',
138 \ ' 4:40 col 20 x 44: Other',
139 \ ' 5:50 col 25 55: one'], l)
140
Bram Moolenaard76ce852018-05-01 15:02:04 +0200141 " Test for module names, one needs to explicitly set `'valid':v:true` so
142 call g:Xsetlist([
143 \ {'lnum':10,'col':5,'type':'W','module':'Data.Text','text':'ModuleWarning','nr':11,'valid':v:true},
144 \ {'lnum':20,'col':10,'type':'W','module':'Data.Text','filename':'Data/Text.hs','text':'ModuleWarning','nr':22,'valid':v:true},
145 \ {'lnum':30,'col':15,'type':'W','filename':'Data/Text.hs','text':'FileWarning','nr':33,'valid':v:true}])
146 let l = split(execute('Xlist', ""), "\n")
147 call assert_equal([' 1 Data.Text:10 col 5 warning 11: ModuleWarning',
148 \ ' 2 Data.Text:20 col 10 warning 22: ModuleWarning',
149 \ ' 3 Data/Text.hs:30 col 15 warning 33: FileWarning'], l)
150
Bram Moolenaaree85df32017-03-19 14:19:50 +0100151 " Error cases
152 call assert_fails('Xlist abc', 'E488:')
Bram Moolenaar2b946c92016-11-12 18:14:44 +0100153endfunc
Bram Moolenaarda59dd52016-01-05 21:59:58 +0100154
Bram Moolenaar2b946c92016-11-12 18:14:44 +0100155func Test_clist()
Bram Moolenaarda59dd52016-01-05 21:59:58 +0100156 call XlistTests('c')
157 call XlistTests('l')
Bram Moolenaar2b946c92016-11-12 18:14:44 +0100158endfunc
Bram Moolenaarda59dd52016-01-05 21:59:58 +0100159
160" Tests for the :colder, :cnewer, :lolder and :lnewer commands
161" Note that this test assumes that a quickfix/location list is
Bram Moolenaarcfc0a352016-01-09 20:23:00 +0100162" already set by the caller.
Bram Moolenaar2b946c92016-11-12 18:14:44 +0100163func XageTests(cchar)
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +0200164 call s:setup_commands(a:cchar)
Bram Moolenaarda59dd52016-01-05 21:59:58 +0100165
Bram Moolenaar87f59b02019-04-04 14:04:11 +0200166 if a:cchar == 'l'
167 " No location list for the current window
168 call assert_fails('lolder', 'E776:')
169 call assert_fails('lnewer', 'E776:')
170 endif
171
Bram Moolenaarcf1ba352017-10-27 00:55:04 +0200172 let list = [{'bufnr': bufnr('%'), 'lnum': 1}]
Bram Moolenaarb6fa30c2017-03-29 14:19:25 +0200173 call g:Xsetlist(list)
174
Bram Moolenaarda59dd52016-01-05 21:59:58 +0100175 " Jumping to a non existent list should return error
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +0200176 silent! Xolder 99
Bram Moolenaarda59dd52016-01-05 21:59:58 +0100177 call assert_true(v:errmsg ==# 'E380: At bottom of quickfix stack')
178
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +0200179 silent! Xnewer 99
Bram Moolenaarda59dd52016-01-05 21:59:58 +0100180 call assert_true(v:errmsg ==# 'E381: At top of quickfix stack')
181
182 " Add three quickfix/location lists
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +0200183 Xgetexpr ['Xtestfile1:1:3:Line1']
184 Xgetexpr ['Xtestfile2:2:2:Line2']
185 Xgetexpr ['Xtestfile3:3:1:Line3']
Bram Moolenaarda59dd52016-01-05 21:59:58 +0100186
187 " Go back two lists
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +0200188 Xolder
189 let l = g:Xgetlist()
Bram Moolenaarda59dd52016-01-05 21:59:58 +0100190 call assert_equal('Line2', l[0].text)
191
192 " Go forward two lists
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +0200193 Xnewer
194 let l = g:Xgetlist()
Bram Moolenaarda59dd52016-01-05 21:59:58 +0100195 call assert_equal('Line3', l[0].text)
196
197 " Test for the optional count argument
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +0200198 Xolder 2
199 let l = g:Xgetlist()
Bram Moolenaarda59dd52016-01-05 21:59:58 +0100200 call assert_equal('Line1', l[0].text)
201
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +0200202 Xnewer 2
203 let l = g:Xgetlist()
Bram Moolenaarda59dd52016-01-05 21:59:58 +0100204 call assert_equal('Line3', l[0].text)
Bram Moolenaar2b946c92016-11-12 18:14:44 +0100205endfunc
Bram Moolenaarda59dd52016-01-05 21:59:58 +0100206
Bram Moolenaar2b946c92016-11-12 18:14:44 +0100207func Test_cage()
Bram Moolenaarda59dd52016-01-05 21:59:58 +0100208 call XageTests('c')
209 call XageTests('l')
Bram Moolenaar2b946c92016-11-12 18:14:44 +0100210endfunc
Bram Moolenaarda59dd52016-01-05 21:59:58 +0100211
212" Tests for the :cwindow, :lwindow :cclose, :lclose, :copen and :lopen
213" commands
Bram Moolenaar2b946c92016-11-12 18:14:44 +0100214func XwindowTests(cchar)
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +0200215 call s:setup_commands(a:cchar)
Bram Moolenaarda59dd52016-01-05 21:59:58 +0100216
Bram Moolenaarb6fa30c2017-03-29 14:19:25 +0200217 " Opening the location list window without any errors should fail
218 if a:cchar == 'l'
219 call assert_fails('lopen', 'E776:')
220 endif
221
Bram Moolenaarda59dd52016-01-05 21:59:58 +0100222 " Create a list with no valid entries
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +0200223 Xgetexpr ['non-error 1', 'non-error 2', 'non-error 3']
Bram Moolenaarda59dd52016-01-05 21:59:58 +0100224
225 " Quickfix/Location window should not open with no valid errors
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +0200226 Xwindow
Bram Moolenaarda59dd52016-01-05 21:59:58 +0100227 call assert_true(winnr('$') == 1)
228
229 " Create a list with valid entries
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +0200230 Xgetexpr ['Xtestfile1:1:3:Line1', 'Xtestfile2:2:2:Line2',
231 \ 'Xtestfile3:3:1:Line3']
Bram Moolenaarda59dd52016-01-05 21:59:58 +0100232
233 " Open the window
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +0200234 Xwindow
Bram Moolenaarda59dd52016-01-05 21:59:58 +0100235 call assert_true(winnr('$') == 2 && winnr() == 2 &&
236 \ getline('.') ==# 'Xtestfile1|1 col 3| Line1')
Bram Moolenaar537ef082016-07-09 17:56:19 +0200237 redraw!
Bram Moolenaarda59dd52016-01-05 21:59:58 +0100238
239 " Close the window
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +0200240 Xclose
Bram Moolenaarda59dd52016-01-05 21:59:58 +0100241 call assert_true(winnr('$') == 1)
242
243 " Create a list with no valid entries
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +0200244 Xgetexpr ['non-error 1', 'non-error 2', 'non-error 3']
Bram Moolenaarda59dd52016-01-05 21:59:58 +0100245
246 " Open the window
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +0200247 Xopen 5
Bram Moolenaarda59dd52016-01-05 21:59:58 +0100248 call assert_true(winnr('$') == 2 && getline('.') ==# '|| non-error 1'
249 \ && winheight('.') == 5)
250
251 " Opening the window again, should move the cursor to that window
252 wincmd t
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +0200253 Xopen 7
Bram Moolenaarda59dd52016-01-05 21:59:58 +0100254 call assert_true(winnr('$') == 2 && winnr() == 2 &&
255 \ winheight('.') == 7 &&
256 \ getline('.') ==# '|| non-error 1')
257
258
259 " Calling cwindow should close the quickfix window with no valid errors
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +0200260 Xwindow
Bram Moolenaarda59dd52016-01-05 21:59:58 +0100261 call assert_true(winnr('$') == 1)
Bram Moolenaarb6fa30c2017-03-29 14:19:25 +0200262
263 if a:cchar == 'c'
264 " Opening the quickfix window in multiple tab pages should reuse the
265 " quickfix buffer
266 Xgetexpr ['Xtestfile1:1:3:Line1', 'Xtestfile2:2:2:Line2',
267 \ 'Xtestfile3:3:1:Line3']
268 Xopen
269 let qfbufnum = bufnr('%')
270 tabnew
271 Xopen
272 call assert_equal(qfbufnum, bufnr('%'))
273 new | only | tabonly
274 endif
Bram Moolenaar2b946c92016-11-12 18:14:44 +0100275endfunc
Bram Moolenaarda59dd52016-01-05 21:59:58 +0100276
Bram Moolenaar2b946c92016-11-12 18:14:44 +0100277func Test_cwindow()
Bram Moolenaarda59dd52016-01-05 21:59:58 +0100278 call XwindowTests('c')
279 call XwindowTests('l')
Bram Moolenaar2b946c92016-11-12 18:14:44 +0100280endfunc
Bram Moolenaarda59dd52016-01-05 21:59:58 +0100281
Bram Moolenaar36d50222019-05-02 20:17:40 +0200282func Test_copenHeight()
283 copen
284 wincmd H
285 let height = winheight(0)
286 copen 10
287 call assert_equal(height, winheight(0))
288 quit
289endfunc
290
Bram Moolenaarda59dd52016-01-05 21:59:58 +0100291" Tests for the :cfile, :lfile, :caddfile, :laddfile, :cgetfile and :lgetfile
292" commands.
Bram Moolenaar2b946c92016-11-12 18:14:44 +0100293func XfileTests(cchar)
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +0200294 call s:setup_commands(a:cchar)
Bram Moolenaarda59dd52016-01-05 21:59:58 +0100295
296 call writefile(['Xtestfile1:700:10:Line 700',
297 \ 'Xtestfile2:800:15:Line 800'], 'Xqftestfile1')
298
299 enew!
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +0200300 Xfile Xqftestfile1
301 let l = g:Xgetlist()
Bram Moolenaarda59dd52016-01-05 21:59:58 +0100302 call assert_true(len(l) == 2 &&
303 \ l[0].lnum == 700 && l[0].col == 10 && l[0].text ==# 'Line 700' &&
304 \ l[1].lnum == 800 && l[1].col == 15 && l[1].text ==# 'Line 800')
305
Bram Moolenaar049cba92016-06-26 14:38:04 +0200306 " Test with a non existent file
307 call assert_fails('Xfile non_existent_file', 'E40')
308
Bram Moolenaarda59dd52016-01-05 21:59:58 +0100309 " Run cfile/lfile from a modified buffer
310 enew!
311 silent! put ='Quickfix'
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +0200312 silent! Xfile Xqftestfile1
Bram Moolenaarda59dd52016-01-05 21:59:58 +0100313 call assert_true(v:errmsg ==# 'E37: No write since last change (add ! to override)')
314
315 call writefile(['Xtestfile3:900:30:Line 900'], 'Xqftestfile1')
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +0200316 Xaddfile Xqftestfile1
317 let l = g:Xgetlist()
Bram Moolenaarda59dd52016-01-05 21:59:58 +0100318 call assert_true(len(l) == 3 &&
319 \ l[2].lnum == 900 && l[2].col == 30 && l[2].text ==# 'Line 900')
320
321 call writefile(['Xtestfile1:222:77:Line 222',
322 \ 'Xtestfile2:333:88:Line 333'], 'Xqftestfile1')
323
324 enew!
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +0200325 Xgetfile Xqftestfile1
326 let l = g:Xgetlist()
Bram Moolenaarda59dd52016-01-05 21:59:58 +0100327 call assert_true(len(l) == 2 &&
328 \ l[0].lnum == 222 && l[0].col == 77 && l[0].text ==# 'Line 222' &&
329 \ l[1].lnum == 333 && l[1].col == 88 && l[1].text ==# 'Line 333')
330
331 call delete('Xqftestfile1')
Bram Moolenaar2b946c92016-11-12 18:14:44 +0100332endfunc
Bram Moolenaarda59dd52016-01-05 21:59:58 +0100333
Bram Moolenaar2b946c92016-11-12 18:14:44 +0100334func Test_cfile()
Bram Moolenaarda59dd52016-01-05 21:59:58 +0100335 call XfileTests('c')
336 call XfileTests('l')
Bram Moolenaar2b946c92016-11-12 18:14:44 +0100337endfunc
Bram Moolenaarda59dd52016-01-05 21:59:58 +0100338
339" Tests for the :cbuffer, :lbuffer, :caddbuffer, :laddbuffer, :cgetbuffer and
340" :lgetbuffer commands.
Bram Moolenaar2b946c92016-11-12 18:14:44 +0100341func XbufferTests(cchar)
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +0200342 call s:setup_commands(a:cchar)
Bram Moolenaarda59dd52016-01-05 21:59:58 +0100343
344 enew!
345 silent! call setline(1, ['Xtestfile7:700:10:Line 700',
346 \ 'Xtestfile8:800:15:Line 800'])
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +0200347 Xbuffer!
348 let l = g:Xgetlist()
Bram Moolenaarda59dd52016-01-05 21:59:58 +0100349 call assert_true(len(l) == 2 &&
350 \ l[0].lnum == 700 && l[0].col == 10 && l[0].text ==# 'Line 700' &&
351 \ l[1].lnum == 800 && l[1].col == 15 && l[1].text ==# 'Line 800')
352
353 enew!
354 silent! call setline(1, ['Xtestfile9:900:55:Line 900',
355 \ 'Xtestfile10:950:66:Line 950'])
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +0200356 Xgetbuffer
357 let l = g:Xgetlist()
Bram Moolenaarda59dd52016-01-05 21:59:58 +0100358 call assert_true(len(l) == 2 &&
359 \ l[0].lnum == 900 && l[0].col == 55 && l[0].text ==# 'Line 900' &&
360 \ l[1].lnum == 950 && l[1].col == 66 && l[1].text ==# 'Line 950')
361
362 enew!
363 silent! call setline(1, ['Xtestfile11:700:20:Line 700',
364 \ 'Xtestfile12:750:25:Line 750'])
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +0200365 Xaddbuffer
366 let l = g:Xgetlist()
Bram Moolenaarda59dd52016-01-05 21:59:58 +0100367 call assert_true(len(l) == 4 &&
368 \ l[1].lnum == 950 && l[1].col == 66 && l[1].text ==# 'Line 950' &&
369 \ l[2].lnum == 700 && l[2].col == 20 && l[2].text ==# 'Line 700' &&
370 \ l[3].lnum == 750 && l[3].col == 25 && l[3].text ==# 'Line 750')
Bram Moolenaarab47c612016-06-14 22:02:26 +0200371 enew!
Bram Moolenaarda59dd52016-01-05 21:59:58 +0100372
Bram Moolenaaree85df32017-03-19 14:19:50 +0100373 " Check for invalid buffer
374 call assert_fails('Xbuffer 199', 'E474:')
375
376 " Check for unloaded buffer
377 edit Xtestfile1
378 let bnr = bufnr('%')
379 enew!
380 call assert_fails('Xbuffer ' . bnr, 'E681:')
381
382 " Check for invalid range
383 " Using Xbuffer will not run the range check in the cbuffer/lbuffer
384 " commands. So directly call the commands.
385 if (a:cchar == 'c')
386 call assert_fails('900,999cbuffer', 'E16:')
387 else
388 call assert_fails('900,999lbuffer', 'E16:')
389 endif
Bram Moolenaar2b946c92016-11-12 18:14:44 +0100390endfunc
Bram Moolenaarda59dd52016-01-05 21:59:58 +0100391
Bram Moolenaar2b946c92016-11-12 18:14:44 +0100392func Test_cbuffer()
Bram Moolenaarda59dd52016-01-05 21:59:58 +0100393 call XbufferTests('c')
394 call XbufferTests('l')
Bram Moolenaar2b946c92016-11-12 18:14:44 +0100395endfunc
Bram Moolenaarda59dd52016-01-05 21:59:58 +0100396
Bram Moolenaar2b946c92016-11-12 18:14:44 +0100397func XexprTests(cchar)
Bram Moolenaar0fcc7c62016-07-02 21:22:52 +0200398 call s:setup_commands(a:cchar)
399
400 call assert_fails('Xexpr 10', 'E777:')
Bram Moolenaar2b946c92016-11-12 18:14:44 +0100401endfunc
Bram Moolenaar0fcc7c62016-07-02 21:22:52 +0200402
Bram Moolenaar2b946c92016-11-12 18:14:44 +0100403func Test_cexpr()
Bram Moolenaar0fcc7c62016-07-02 21:22:52 +0200404 call XexprTests('c')
405 call XexprTests('l')
Bram Moolenaar2b946c92016-11-12 18:14:44 +0100406endfunc
Bram Moolenaar0fcc7c62016-07-02 21:22:52 +0200407
408" Tests for :cnext, :cprev, :cfirst, :clast commands
Bram Moolenaar2b946c92016-11-12 18:14:44 +0100409func Xtest_browse(cchar)
Bram Moolenaar0fcc7c62016-07-02 21:22:52 +0200410 call s:setup_commands(a:cchar)
411
Bram Moolenaar74240d32017-12-10 15:26:15 +0100412 call g:Xsetlist([], 'f')
Bram Moolenaarb6fa30c2017-03-29 14:19:25 +0200413 " Jumping to first or next location list entry without any error should
414 " result in failure
Bram Moolenaar74240d32017-12-10 15:26:15 +0100415 if a:cchar == 'c'
416 let err = 'E42:'
417 else
418 let err = 'E776:'
Bram Moolenaarb6fa30c2017-03-29 14:19:25 +0200419 endif
Bram Moolenaar74240d32017-12-10 15:26:15 +0100420 call assert_fails('Xnext', err)
421 call assert_fails('Xprev', err)
422 call assert_fails('Xnfile', err)
423 call assert_fails('Xpfile', err)
Bram Moolenaarb6fa30c2017-03-29 14:19:25 +0200424
Bram Moolenaar0fcc7c62016-07-02 21:22:52 +0200425 call s:create_test_file('Xqftestfile1')
426 call s:create_test_file('Xqftestfile2')
427
428 Xgetexpr ['Xqftestfile1:5:Line5',
429 \ 'Xqftestfile1:6:Line6',
430 \ 'Xqftestfile2:10:Line10',
Bram Moolenaar99895ea2017-04-20 22:44:47 +0200431 \ 'Xqftestfile2:11:Line11',
432 \ 'RegularLine1',
433 \ 'RegularLine2']
Bram Moolenaar0fcc7c62016-07-02 21:22:52 +0200434
435 Xfirst
436 call assert_fails('Xprev', 'E553')
437 call assert_fails('Xpfile', 'E553')
438 Xnfile
439 call assert_equal('Xqftestfile2', bufname('%'))
440 call assert_equal(10, line('.'))
441 Xpfile
442 call assert_equal('Xqftestfile1', bufname('%'))
443 call assert_equal(6, line('.'))
Bram Moolenaar74240d32017-12-10 15:26:15 +0100444 5Xcc
445 call assert_equal(5, g:Xgetlist({'idx':0}).idx)
446 2Xcc
447 call assert_equal(2, g:Xgetlist({'idx':0}).idx)
448 10Xcc
449 call assert_equal(6, g:Xgetlist({'idx':0}).idx)
Bram Moolenaar0fcc7c62016-07-02 21:22:52 +0200450 Xlast
Bram Moolenaar99895ea2017-04-20 22:44:47 +0200451 Xprev
Bram Moolenaar0fcc7c62016-07-02 21:22:52 +0200452 call assert_equal('Xqftestfile2', bufname('%'))
453 call assert_equal(11, line('.'))
454 call assert_fails('Xnext', 'E553')
455 call assert_fails('Xnfile', 'E553')
456 Xrewind
457 call assert_equal('Xqftestfile1', bufname('%'))
458 call assert_equal(5, line('.'))
459
Bram Moolenaar99895ea2017-04-20 22:44:47 +0200460 10Xnext
461 call assert_equal('Xqftestfile2', bufname('%'))
462 call assert_equal(11, line('.'))
463 10Xprev
464 call assert_equal('Xqftestfile1', bufname('%'))
465 call assert_equal(5, line('.'))
466
Bram Moolenaar74240d32017-12-10 15:26:15 +0100467 " Jumping to an error from the error window using cc command
468 Xgetexpr ['Xqftestfile1:5:Line5',
469 \ 'Xqftestfile1:6:Line6',
470 \ 'Xqftestfile2:10:Line10',
471 \ 'Xqftestfile2:11:Line11']
472 Xopen
473 10Xcc
474 call assert_equal(11, line('.'))
475 call assert_equal('Xqftestfile2', bufname('%'))
476
477 " Jumping to an error from the error window (when only the error window is
478 " present)
479 Xopen | only
480 Xlast 1
481 call assert_equal(5, line('.'))
482 call assert_equal('Xqftestfile1', bufname('%'))
483
Bram Moolenaaree85df32017-03-19 14:19:50 +0100484 Xexpr ""
485 call assert_fails('Xnext', 'E42:')
486
Bram Moolenaar0fcc7c62016-07-02 21:22:52 +0200487 call delete('Xqftestfile1')
488 call delete('Xqftestfile2')
Bram Moolenaarfc2b2702017-09-15 22:43:07 +0200489
490 " Should be able to use next/prev with invalid entries
491 Xexpr ""
492 call assert_equal(0, g:Xgetlist({'idx' : 0}).idx)
493 call assert_equal(0, g:Xgetlist({'size' : 0}).size)
494 Xaddexpr ['foo', 'bar', 'baz', 'quux', 'shmoo']
495 call assert_equal(5, g:Xgetlist({'size' : 0}).size)
496 Xlast
497 call assert_equal(5, g:Xgetlist({'idx' : 0}).idx)
498 Xfirst
499 call assert_equal(1, g:Xgetlist({'idx' : 0}).idx)
500 2Xnext
501 call assert_equal(3, g:Xgetlist({'idx' : 0}).idx)
Bram Moolenaar2b946c92016-11-12 18:14:44 +0100502endfunc
Bram Moolenaar0fcc7c62016-07-02 21:22:52 +0200503
Bram Moolenaar2b946c92016-11-12 18:14:44 +0100504func Test_browse()
Bram Moolenaar0fcc7c62016-07-02 21:22:52 +0200505 call Xtest_browse('c')
506 call Xtest_browse('l')
Bram Moolenaar2b946c92016-11-12 18:14:44 +0100507endfunc
Bram Moolenaar0fcc7c62016-07-02 21:22:52 +0200508
Bram Moolenaar2b946c92016-11-12 18:14:44 +0100509func Test_nomem()
Bram Moolenaar8e8df252016-05-25 21:23:21 +0200510 call test_alloc_fail(GetAllocId('qf_dirname_start'), 0, 0)
Bram Moolenaara260b872016-01-15 20:48:22 +0100511 call assert_fails('vimgrep vim runtest.vim', 'E342:')
Bram Moolenaar75bdf6a2016-01-07 21:25:08 +0100512
Bram Moolenaar8e8df252016-05-25 21:23:21 +0200513 call test_alloc_fail(GetAllocId('qf_dirname_now'), 0, 0)
Bram Moolenaara260b872016-01-15 20:48:22 +0100514 call assert_fails('vimgrep vim runtest.vim', 'E342:')
Bram Moolenaar75bdf6a2016-01-07 21:25:08 +0100515
Bram Moolenaar8e8df252016-05-25 21:23:21 +0200516 call test_alloc_fail(GetAllocId('qf_namebuf'), 0, 0)
Bram Moolenaara260b872016-01-15 20:48:22 +0100517 call assert_fails('cfile runtest.vim', 'E342:')
Bram Moolenaar75bdf6a2016-01-07 21:25:08 +0100518
Bram Moolenaar8e8df252016-05-25 21:23:21 +0200519 call test_alloc_fail(GetAllocId('qf_errmsg'), 0, 0)
Bram Moolenaara260b872016-01-15 20:48:22 +0100520 call assert_fails('cfile runtest.vim', 'E342:')
Bram Moolenaar75bdf6a2016-01-07 21:25:08 +0100521
Bram Moolenaar8e8df252016-05-25 21:23:21 +0200522 call test_alloc_fail(GetAllocId('qf_pattern'), 0, 0)
Bram Moolenaara260b872016-01-15 20:48:22 +0100523 call assert_fails('cfile runtest.vim', 'E342:')
Bram Moolenaar75bdf6a2016-01-07 21:25:08 +0100524
525endfunc
526
Bram Moolenaar2b946c92016-11-12 18:14:44 +0100527func s:test_xhelpgrep(cchar)
Bram Moolenaar049cba92016-06-26 14:38:04 +0200528 call s:setup_commands(a:cchar)
529 Xhelpgrep quickfix
530 Xopen
531 if a:cchar == 'c'
532 let title_text = ':helpgrep quickfix'
533 else
534 let title_text = ':lhelpgrep quickfix'
535 endif
536 call assert_true(w:quickfix_title =~ title_text, w:quickfix_title)
Bram Moolenaar99895ea2017-04-20 22:44:47 +0200537
538 " Jumping to a help topic should open the help window
539 only
540 Xnext
541 call assert_true(&buftype == 'help')
542 call assert_true(winnr('$') == 2)
543 " Jumping to the next match should reuse the help window
544 Xnext
545 call assert_true(&buftype == 'help')
546 call assert_true(winnr() == 1)
547 call assert_true(winnr('$') == 2)
548 " Jumping to the next match from the quickfix window should reuse the help
549 " window
550 Xopen
551 Xnext
552 call assert_true(&buftype == 'help')
553 call assert_true(winnr() == 1)
554 call assert_true(winnr('$') == 2)
555
Bram Moolenaar62ef7972016-01-19 14:51:54 +0100556 " This wipes out the buffer, make sure that doesn't cause trouble.
Bram Moolenaar049cba92016-06-26 14:38:04 +0200557 Xclose
Bram Moolenaaree85df32017-03-19 14:19:50 +0100558
Bram Moolenaarb4d5fba2017-09-11 19:31:28 +0200559 if a:cchar == 'l'
560 " When a help window is present, running :lhelpgrep should reuse the
561 " help window and not the current window
562 new | only
563 call g:Xsetlist([], 'f')
564 help index.txt
565 wincmd w
566 lhelpgrep quickfix
567 call assert_equal(1, winnr())
568 call assert_notequal([], getloclist(1))
569 call assert_equal([], getloclist(2))
570 endif
571
Bram Moolenaar99895ea2017-04-20 22:44:47 +0200572 new | only
573
Bram Moolenaaree85df32017-03-19 14:19:50 +0100574 " Search for non existing help string
575 call assert_fails('Xhelpgrep a1b2c3', 'E480:')
Bram Moolenaar108e7b42018-10-11 17:39:12 +0200576 " Invalid regular expression
577 call assert_fails('Xhelpgrep \@<!', 'E480:')
Bram Moolenaar2b946c92016-11-12 18:14:44 +0100578endfunc
Bram Moolenaar049cba92016-06-26 14:38:04 +0200579
Bram Moolenaar2b946c92016-11-12 18:14:44 +0100580func Test_helpgrep()
Bram Moolenaar049cba92016-06-26 14:38:04 +0200581 call s:test_xhelpgrep('c')
Bram Moolenaarcf25fdb2016-08-03 21:04:53 +0200582 helpclose
Bram Moolenaar049cba92016-06-26 14:38:04 +0200583 call s:test_xhelpgrep('l')
Bram Moolenaar62ef7972016-01-19 14:51:54 +0100584endfunc
Bram Moolenaar75bdf6a2016-01-07 21:25:08 +0100585
Bram Moolenaar6920c722016-01-22 22:44:10 +0100586func Test_errortitle()
587 augroup QfBufWinEnter
588 au!
589 au BufWinEnter * :let g:a=get(w:, 'quickfix_title', 'NONE')
590 augroup END
591 copen
592 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'')'}]
593 call setqflist(a)
594 call assert_equal(':setqflist()', g:a)
595 augroup QfBufWinEnter
596 au!
597 augroup END
598 augroup! QfBufWinEnter
599endfunc
Bram Moolenaare27dba42016-03-15 14:11:10 +0100600
Bram Moolenaar5584df62016-03-18 21:00:51 +0100601func Test_vimgreptitle()
602 augroup QfBufWinEnter
603 au!
604 au BufWinEnter * :let g:a=get(w:, 'quickfix_title', 'NONE')
605 augroup END
606 try
607 vimgrep /pattern/j file
608 catch /E480/
609 endtry
610 copen
611 call assert_equal(': vimgrep /pattern/j file', g:a)
612 augroup QfBufWinEnter
613 au!
614 augroup END
615 augroup! QfBufWinEnter
616endfunc
617
Bram Moolenaar2b946c92016-11-12 18:14:44 +0100618func XqfTitleTests(cchar)
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +0200619 call s:setup_commands(a:cchar)
Bram Moolenaare27dba42016-03-15 14:11:10 +0100620
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +0200621 Xgetexpr ['file:1:1:message']
622 let l = g:Xgetlist()
Bram Moolenaare27dba42016-03-15 14:11:10 +0100623 if a:cchar == 'c'
624 call setqflist(l, 'r')
625 else
626 call setloclist(0, l, 'r')
627 endif
628
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +0200629 Xopen
Bram Moolenaare27dba42016-03-15 14:11:10 +0100630 if a:cchar == 'c'
631 let title = ':setqflist()'
632 else
633 let title = ':setloclist()'
634 endif
635 call assert_equal(title, w:quickfix_title)
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +0200636 Xclose
Bram Moolenaar2b946c92016-11-12 18:14:44 +0100637endfunc
Bram Moolenaare27dba42016-03-15 14:11:10 +0100638
639" Tests for quickfix window's title
Bram Moolenaar2b946c92016-11-12 18:14:44 +0100640func Test_qf_title()
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +0200641 call XqfTitleTests('c')
642 call XqfTitleTests('l')
Bram Moolenaar2b946c92016-11-12 18:14:44 +0100643endfunc
Bram Moolenaare27dba42016-03-15 14:11:10 +0100644
645" Tests for 'errorformat'
Bram Moolenaar2b946c92016-11-12 18:14:44 +0100646func Test_efm()
Bram Moolenaare27dba42016-03-15 14:11:10 +0100647 let save_efm = &efm
648 set efm=%EEEE%m,%WWWW%m,%+CCCC%.%#,%-GGGG%.%#
649 cgetexpr ['WWWW', 'EEEE', 'CCCC']
650 let l = strtrans(string(map(getqflist(), '[v:val.text, v:val.valid]')))
651 call assert_equal("[['W', 1], ['E^@CCCC', 1]]", l)
652 cgetexpr ['WWWW', 'GGGG', 'EEEE', 'CCCC']
653 let l = strtrans(string(map(getqflist(), '[v:val.text, v:val.valid]')))
654 call assert_equal("[['W', 1], ['E^@CCCC', 1]]", l)
655 cgetexpr ['WWWW', 'GGGG', 'ZZZZ', 'EEEE', 'CCCC', 'YYYY']
656 let l = strtrans(string(map(getqflist(), '[v:val.text, v:val.valid]')))
657 call assert_equal("[['W', 1], ['ZZZZ', 0], ['E^@CCCC', 1], ['YYYY', 0]]", l)
658 let &efm = save_efm
Bram Moolenaar2b946c92016-11-12 18:14:44 +0100659endfunc
Bram Moolenaar1ff2b642016-03-17 22:07:02 +0100660
661" This will test for problems in quickfix:
662" A. incorrectly copying location lists which caused the location list to show
663" a different name than the file that was actually being displayed.
664" B. not reusing the window for which the location list window is opened but
665" instead creating new windows.
666" C. make sure that the location list window is not reused instead of the
667" window it belongs to.
668"
669" Set up the test environment:
Bram Moolenaar2b946c92016-11-12 18:14:44 +0100670func ReadTestProtocol(name)
Bram Moolenaar1ff2b642016-03-17 22:07:02 +0100671 let base = substitute(a:name, '\v^test://(.*)%(\.[^.]+)?', '\1', '')
672 let word = substitute(base, '\v(.*)\..*', '\1', '')
673
674 setl modifiable
675 setl noreadonly
676 setl noswapfile
677 setl bufhidden=delete
678 %del _
679 " For problem 2:
680 " 'buftype' has to be set to reproduce the constant opening of new windows
681 setl buftype=nofile
682
683 call setline(1, word)
684
685 setl nomodified
686 setl nomodifiable
687 setl readonly
688 exe 'doautocmd BufRead ' . substitute(a:name, '\v^test://(.*)', '\1', '')
Bram Moolenaar2b946c92016-11-12 18:14:44 +0100689endfunc
Bram Moolenaar1ff2b642016-03-17 22:07:02 +0100690
Bram Moolenaar2b946c92016-11-12 18:14:44 +0100691func Test_locationlist()
Bram Moolenaar1ff2b642016-03-17 22:07:02 +0100692 enew
693
694 augroup testgroup
695 au!
696 autocmd BufReadCmd test://* call ReadTestProtocol(expand("<amatch>"))
697 augroup END
698
699 let words = [ "foo", "bar", "baz", "quux", "shmoo", "spam", "eggs" ]
700
701 let qflist = []
702 for word in words
703 call add(qflist, {'filename': 'test://' . word . '.txt', 'text': 'file ' . word . '.txt', })
704 " NOTE: problem 1:
705 " intentionally not setting 'lnum' so that the quickfix entries are not
706 " valid
707 call setloclist(0, qflist, ' ')
708 endfor
709
710 " Test A
711 lrewind
712 enew
713 lopen
Bram Moolenaar99895ea2017-04-20 22:44:47 +0200714 4lnext
Bram Moolenaar1ff2b642016-03-17 22:07:02 +0100715 vert split
716 wincmd L
717 lopen
718 wincmd p
719 lnext
720 let fileName = expand("%")
721 wincmd p
722 let locationListFileName = substitute(getline(line('.')), '\([^|]*\)|.*', '\1', '')
723 let fileName = substitute(fileName, '\\', '/', 'g')
724 let locationListFileName = substitute(locationListFileName, '\\', '/', 'g')
725 call assert_equal("test://bar.txt", fileName)
726 call assert_equal("test://bar.txt", locationListFileName)
727
728 wincmd n | only
729
730 " Test B:
731 lrewind
732 lopen
733 2
734 exe "normal \<CR>"
735 wincmd p
736 3
737 exe "normal \<CR>"
738 wincmd p
739 4
740 exe "normal \<CR>"
741 call assert_equal(2, winnr('$'))
742 wincmd n | only
743
744 " Test C:
745 lrewind
746 lopen
747 " Let's move the location list window to the top to check whether it (the
748 " first window found) will be reused when we try to open new windows:
749 wincmd K
750 2
751 exe "normal \<CR>"
752 wincmd p
753 3
754 exe "normal \<CR>"
755 wincmd p
756 4
757 exe "normal \<CR>"
758 1wincmd w
759 call assert_equal('quickfix', &buftype)
760 2wincmd w
761 let bufferName = expand("%")
762 let bufferName = substitute(bufferName, '\\', '/', 'g')
763 call assert_equal('test://quux.txt', bufferName)
764
765 wincmd n | only
766
767 augroup! testgroup
Bram Moolenaaree85df32017-03-19 14:19:50 +0100768endfunc
Bram Moolenaar0899d692016-03-19 13:35:03 +0100769
Bram Moolenaar2b946c92016-11-12 18:14:44 +0100770func Test_locationlist_curwin_was_closed()
Bram Moolenaar0899d692016-03-19 13:35:03 +0100771 augroup testgroup
772 au!
Bram Moolenaard106e5b2016-04-21 19:38:07 +0200773 autocmd BufReadCmd test_curwin.txt call R(expand("<amatch>"))
Bram Moolenaar0899d692016-03-19 13:35:03 +0100774 augroup END
775
Bram Moolenaar2b946c92016-11-12 18:14:44 +0100776 func! R(n)
Bram Moolenaar0899d692016-03-19 13:35:03 +0100777 quit
778 endfunc
779
780 new
781 let q = []
Bram Moolenaard106e5b2016-04-21 19:38:07 +0200782 call add(q, {'filename': 'test_curwin.txt' })
Bram Moolenaar0899d692016-03-19 13:35:03 +0100783 call setloclist(0, q)
784 call assert_fails('lrewind', 'E924:')
785
786 augroup! testgroup
Bram Moolenaaree85df32017-03-19 14:19:50 +0100787endfunc
Bram Moolenaar7eba3d22016-03-19 22:54:09 +0100788
Bram Moolenaar2b946c92016-11-12 18:14:44 +0100789func Test_locationlist_cross_tab_jump()
Bram Moolenaar0a9046f2016-10-15 19:28:13 +0200790 call writefile(['loclistfoo'], 'loclistfoo')
791 call writefile(['loclistbar'], 'loclistbar')
792 set switchbuf=usetab
793
794 edit loclistfoo
795 tabedit loclistbar
796 silent lgrep loclistfoo loclist*
797 call assert_equal(1, tabpagenr())
798
799 enew | only | tabonly
800 set switchbuf&vim
801 call delete('loclistfoo')
802 call delete('loclistbar')
Bram Moolenaar2b946c92016-11-12 18:14:44 +0100803endfunc
Bram Moolenaar0a9046f2016-10-15 19:28:13 +0200804
Bram Moolenaar7eba3d22016-03-19 22:54:09 +0100805" More tests for 'errorformat'
Bram Moolenaar2b946c92016-11-12 18:14:44 +0100806func Test_efm1()
Bram Moolenaar7eba3d22016-03-19 22:54:09 +0100807 if !has('unix')
808 " The 'errorformat' setting is different on non-Unix systems.
809 " This test works only on Unix-like systems.
810 return
811 endif
812
813 let l = [
814 \ '"Xtestfile", line 4.12: 1506-045 (S) Undeclared identifier fd_set.',
815 \ '"Xtestfile", line 6 col 19; this is an error',
816 \ 'gcc -c -DHAVE_CONFIsing-prototypes -I/usr/X11R6/include version.c',
817 \ 'Xtestfile:9: parse error before `asd''',
818 \ 'make: *** [vim] Error 1',
819 \ 'in file "Xtestfile" linenr 10: there is an error',
820 \ '',
821 \ '2 returned',
822 \ '"Xtestfile", line 11 col 1; this is an error',
823 \ '"Xtestfile", line 12 col 2; this is another error',
824 \ '"Xtestfile", line 14:10; this is an error in column 10',
825 \ '=Xtestfile=, line 15:10; this is another error, but in vcol 10 this time',
826 \ '"Xtestfile", linenr 16: yet another problem',
827 \ 'Error in "Xtestfile" at line 17:',
828 \ 'x should be a dot',
829 \ ' xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 17',
830 \ ' ^',
831 \ 'Error in "Xtestfile" at line 18:',
832 \ 'x should be a dot',
833 \ ' xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 18',
834 \ '.............^',
835 \ 'Error in "Xtestfile" at line 19:',
836 \ 'x should be a dot',
837 \ ' xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 19',
838 \ '--------------^',
839 \ 'Error in "Xtestfile" at line 20:',
840 \ 'x should be a dot',
841 \ ' xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 20',
842 \ ' ^',
843 \ '',
844 \ 'Does anyone know what is the problem and how to correction it?',
845 \ '"Xtestfile", line 21 col 9: What is the title of the quickfix window?',
846 \ '"Xtestfile", line 22 col 9: What is the title of the quickfix window?'
847 \ ]
848
849 call writefile(l, 'Xerrorfile1')
850 call writefile(l[:-2], 'Xerrorfile2')
851
852 let m = [
853 \ ' xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 2',
854 \ ' xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 3',
855 \ ' xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 4',
856 \ ' xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 5',
857 \ ' xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 6',
858 \ ' xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 7',
859 \ ' xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 8',
860 \ ' xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 9',
861 \ ' xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 10',
862 \ ' xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 11',
863 \ ' xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 12',
864 \ ' xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 13',
865 \ ' xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 14',
866 \ ' xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 15',
867 \ ' xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 16',
868 \ ' xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 17',
869 \ ' xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 18',
870 \ ' xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 19',
871 \ ' xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 20',
872 \ ' xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 21',
873 \ ' xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 22'
874 \ ]
875 call writefile(m, 'Xtestfile')
876
877 let save_efm = &efm
878 set efm+==%f=\\,\ line\ %l%*\\D%v%*[^\ ]\ %m
879 set efm^=%AError\ in\ \"%f\"\ at\ line\ %l:,%Z%p^,%C%m
880
881 exe 'cf Xerrorfile2'
882 clast
883 copen
884 call assert_equal(':cf Xerrorfile2', w:quickfix_title)
885 wincmd p
886
887 exe 'cf Xerrorfile1'
888 call assert_equal([4, 12], [line('.'), col('.')])
889 cn
890 call assert_equal([6, 19], [line('.'), col('.')])
891 cn
892 call assert_equal([9, 2], [line('.'), col('.')])
893 cn
894 call assert_equal([10, 2], [line('.'), col('.')])
895 cn
896 call assert_equal([11, 1], [line('.'), col('.')])
897 cn
898 call assert_equal([12, 2], [line('.'), col('.')])
899 cn
900 call assert_equal([14, 10], [line('.'), col('.')])
901 cn
902 call assert_equal([15, 3, 10], [line('.'), col('.'), virtcol('.')])
903 cn
904 call assert_equal([16, 2], [line('.'), col('.')])
905 cn
906 call assert_equal([17, 6], [line('.'), col('.')])
907 cn
908 call assert_equal([18, 7], [line('.'), col('.')])
909 cn
910 call assert_equal([19, 8], [line('.'), col('.')])
911 cn
912 call assert_equal([20, 9], [line('.'), col('.')])
913 clast
914 cprev
915 cprev
916 wincmd w
917 call assert_equal(':cf Xerrorfile1', w:quickfix_title)
918 wincmd p
919
920 let &efm = save_efm
921 call delete('Xerrorfile1')
922 call delete('Xerrorfile2')
923 call delete('Xtestfile')
Bram Moolenaaree85df32017-03-19 14:19:50 +0100924endfunc
Bram Moolenaarffec3c52016-03-23 20:55:42 +0100925
Bram Moolenaarab47c612016-06-14 22:02:26 +0200926" Test for quickfix directory stack support
Bram Moolenaar2b946c92016-11-12 18:14:44 +0100927func s:dir_stack_tests(cchar)
Bram Moolenaar38df43b2016-06-20 21:41:12 +0200928 call s:setup_commands(a:cchar)
929
Bram Moolenaarab47c612016-06-14 22:02:26 +0200930 let save_efm=&efm
931 set efm=%DEntering\ dir\ '%f',%f:%l:%m,%XLeaving\ dir\ '%f'
932
Bram Moolenaar361c8f02016-07-02 15:41:47 +0200933 let lines = ["Entering dir 'dir1/a'",
934 \ 'habits2.txt:1:Nine Healthy Habits',
935 \ "Entering dir 'b'",
936 \ 'habits3.txt:2:0 Hours of television',
937 \ 'habits2.txt:7:5 Small meals',
938 \ "Entering dir 'dir1/c'",
939 \ 'habits4.txt:3:1 Hour of exercise',
940 \ "Leaving dir 'dir1/c'",
941 \ "Leaving dir 'dir1/a'",
942 \ 'habits1.txt:4:2 Liters of water',
943 \ "Entering dir 'dir2'",
944 \ 'habits5.txt:5:3 Cups of hot green tea',
945 \ "Leaving dir 'dir2'"
946 \]
Bram Moolenaarab47c612016-06-14 22:02:26 +0200947
Bram Moolenaar361c8f02016-07-02 15:41:47 +0200948 Xexpr ""
949 for l in lines
950 Xaddexpr l
951 endfor
Bram Moolenaarab47c612016-06-14 22:02:26 +0200952
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +0200953 let qf = g:Xgetlist()
Bram Moolenaarab47c612016-06-14 22:02:26 +0200954
955 call assert_equal('dir1/a/habits2.txt', bufname(qf[1].bufnr))
956 call assert_equal(1, qf[1].lnum)
957 call assert_equal('dir1/a/b/habits3.txt', bufname(qf[3].bufnr))
958 call assert_equal(2, qf[3].lnum)
959 call assert_equal('dir1/a/habits2.txt', bufname(qf[4].bufnr))
960 call assert_equal(7, qf[4].lnum)
961 call assert_equal('dir1/c/habits4.txt', bufname(qf[6].bufnr))
962 call assert_equal(3, qf[6].lnum)
963 call assert_equal('habits1.txt', bufname(qf[9].bufnr))
964 call assert_equal(4, qf[9].lnum)
965 call assert_equal('dir2/habits5.txt', bufname(qf[11].bufnr))
966 call assert_equal(5, qf[11].lnum)
967
968 let &efm=save_efm
Bram Moolenaar2b946c92016-11-12 18:14:44 +0100969endfunc
Bram Moolenaarab47c612016-06-14 22:02:26 +0200970
971" Tests for %D and %X errorformat options
Bram Moolenaar2b946c92016-11-12 18:14:44 +0100972func Test_efm_dirstack()
Bram Moolenaarab47c612016-06-14 22:02:26 +0200973 " Create the directory stack and files
974 call mkdir('dir1')
975 call mkdir('dir1/a')
976 call mkdir('dir1/a/b')
977 call mkdir('dir1/c')
978 call mkdir('dir2')
979
980 let lines = ["Nine Healthy Habits",
981 \ "0 Hours of television",
982 \ "1 Hour of exercise",
983 \ "2 Liters of water",
984 \ "3 Cups of hot green tea",
985 \ "4 Short mental breaks",
986 \ "5 Small meals",
987 \ "6 AM wake up time",
988 \ "7 Minutes of laughter",
989 \ "8 Hours of sleep (at least)",
990 \ "9 PM end of the day and off to bed"
991 \ ]
992 call writefile(lines, 'habits1.txt')
993 call writefile(lines, 'dir1/a/habits2.txt')
994 call writefile(lines, 'dir1/a/b/habits3.txt')
995 call writefile(lines, 'dir1/c/habits4.txt')
996 call writefile(lines, 'dir2/habits5.txt')
997
998 call s:dir_stack_tests('c')
999 call s:dir_stack_tests('l')
1000
1001 call delete('dir1', 'rf')
1002 call delete('dir2', 'rf')
1003 call delete('habits1.txt')
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001004endfunc
Bram Moolenaarab47c612016-06-14 22:02:26 +02001005
Bram Moolenaar9b457942016-10-09 16:10:05 +02001006" Test for resync after continuing an ignored message
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001007func Xefm_ignore_continuations(cchar)
Bram Moolenaar9b457942016-10-09 16:10:05 +02001008 call s:setup_commands(a:cchar)
1009
1010 let save_efm = &efm
1011
1012 let &efm =
1013 \ '%Eerror %m %l,' .
1014 \ '%-Wignored %m %l,' .
1015 \ '%+Cmore ignored %m %l,' .
1016 \ '%Zignored end'
1017 Xgetexpr ['ignored warning 1', 'more ignored continuation 2', 'ignored end', 'error resync 4']
1018 let l = map(g:Xgetlist(), '[v:val.text, v:val.valid, v:val.lnum, v:val.type]')
1019 call assert_equal([['resync', 1, 4, 'E']], l)
1020
1021 let &efm = save_efm
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001022endfunc
Bram Moolenaar9b457942016-10-09 16:10:05 +02001023
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001024func Test_efm_ignore_continuations()
Bram Moolenaar9b457942016-10-09 16:10:05 +02001025 call Xefm_ignore_continuations('c')
1026 call Xefm_ignore_continuations('l')
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001027endfunc
Bram Moolenaar9b457942016-10-09 16:10:05 +02001028
Bram Moolenaar0fcc7c62016-07-02 21:22:52 +02001029" Tests for invalid error format specifies
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001030func Xinvalid_efm_Tests(cchar)
Bram Moolenaar0fcc7c62016-07-02 21:22:52 +02001031 call s:setup_commands(a:cchar)
1032
Bram Moolenaar049cba92016-06-26 14:38:04 +02001033 let save_efm = &efm
1034
Bram Moolenaar0fcc7c62016-07-02 21:22:52 +02001035 set efm=%f:%l:%m,%f:%f:%l:%m
1036 call assert_fails('Xexpr "abc.txt:1:Hello world"', 'E372:')
1037
1038 set efm=%f:%l:%m,%f:%l:%r:%m
1039 call assert_fails('Xexpr "abc.txt:1:Hello world"', 'E373:')
1040
1041 set efm=%f:%l:%m,%O:%f:%l:%m
1042 call assert_fails('Xexpr "abc.txt:1:Hello world"', 'E373:')
1043
1044 set efm=%f:%l:%m,%f:%l:%*[^a-z
1045 call assert_fails('Xexpr "abc.txt:1:Hello world"', 'E374:')
1046
1047 set efm=%f:%l:%m,%f:%l:%*c
1048 call assert_fails('Xexpr "abc.txt:1:Hello world"', 'E375:')
1049
1050 set efm=%f:%l:%m,%L%M%N
1051 call assert_fails('Xexpr "abc.txt:1:Hello world"', 'E376:')
1052
1053 set efm=%f:%l:%m,%f:%l:%m:%R
1054 call assert_fails('Xexpr "abc.txt:1:Hello world"', 'E377:')
1055
1056 set efm=
1057 call assert_fails('Xexpr "abc.txt:1:Hello world"', 'E378:')
1058
1059 set efm=%DEntering\ dir\ abc,%f:%l:%m
1060 call assert_fails('Xexpr ["Entering dir abc", "abc.txt:1:Hello world"]', 'E379:')
1061
1062 let &efm = save_efm
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001063endfunc
Bram Moolenaar0fcc7c62016-07-02 21:22:52 +02001064
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001065func Test_invalid_efm()
Bram Moolenaar0fcc7c62016-07-02 21:22:52 +02001066 call Xinvalid_efm_Tests('c')
1067 call Xinvalid_efm_Tests('l')
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001068endfunc
Bram Moolenaar0fcc7c62016-07-02 21:22:52 +02001069
1070" TODO:
1071" Add tests for the following formats in 'errorformat'
1072" %r %O
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001073func Test_efm2()
Bram Moolenaar0fcc7c62016-07-02 21:22:52 +02001074 let save_efm = &efm
Bram Moolenaar049cba92016-06-26 14:38:04 +02001075
1076 " Test for %s format in efm
1077 set efm=%f:%s
1078 cexpr 'Xtestfile:Line search text'
Bram Moolenaar049cba92016-06-26 14:38:04 +02001079 let l = getqflist()
1080 call assert_equal(l[0].pattern, '^\VLine search text\$')
1081 call assert_equal(l[0].lnum, 0)
1082
Bram Moolenaaree85df32017-03-19 14:19:50 +01001083 let l = split(execute('clist', ''), "\n")
1084 call assert_equal([' 1 Xtestfile:^\VLine search text\$: '], l)
1085
Bram Moolenaar0fcc7c62016-07-02 21:22:52 +02001086 " Test for %P, %Q and %t format specifiers
Bram Moolenaar049cba92016-06-26 14:38:04 +02001087 let lines=["[Xtestfile1]",
1088 \ "(1,17) error: ';' missing",
1089 \ "(21,2) warning: variable 'z' not defined",
1090 \ "(67,3) error: end of file found before string ended",
Bram Moolenaaree85df32017-03-19 14:19:50 +01001091 \ "--",
Bram Moolenaar049cba92016-06-26 14:38:04 +02001092 \ "",
1093 \ "[Xtestfile2]",
Bram Moolenaaree85df32017-03-19 14:19:50 +01001094 \ "--",
Bram Moolenaar049cba92016-06-26 14:38:04 +02001095 \ "",
1096 \ "[Xtestfile3]",
1097 \ "NEW compiler v1.1",
1098 \ "(2,2) warning: variable 'x' not defined",
Bram Moolenaaree85df32017-03-19 14:19:50 +01001099 \ "(67,3) warning: 's' already defined",
1100 \ "--"
Bram Moolenaar049cba92016-06-26 14:38:04 +02001101 \]
Bram Moolenaaree85df32017-03-19 14:19:50 +01001102 set efm=%+P[%f]%r,(%l\\,%c)%*[\ ]%t%*[^:]:\ %m,%+Q--%r
Bram Moolenaar391b1dd2017-03-04 13:47:11 +01001103 " To exercise the push/pop file functionality in quickfix, the test files
1104 " need to be created.
1105 call writefile(['Line1'], 'Xtestfile1')
1106 call writefile(['Line2'], 'Xtestfile2')
1107 call writefile(['Line3'], 'Xtestfile3')
Bram Moolenaar361c8f02016-07-02 15:41:47 +02001108 cexpr ""
1109 for l in lines
1110 caddexpr l
1111 endfor
Bram Moolenaar049cba92016-06-26 14:38:04 +02001112 let l = getqflist()
Bram Moolenaaree85df32017-03-19 14:19:50 +01001113 call assert_equal(12, len(l))
Bram Moolenaar049cba92016-06-26 14:38:04 +02001114 call assert_equal(21, l[2].lnum)
1115 call assert_equal(2, l[2].col)
Bram Moolenaar0fcc7c62016-07-02 21:22:52 +02001116 call assert_equal('w', l[2].type)
1117 call assert_equal('e', l[3].type)
Bram Moolenaar391b1dd2017-03-04 13:47:11 +01001118 call delete('Xtestfile1')
1119 call delete('Xtestfile2')
1120 call delete('Xtestfile3')
Bram Moolenaar0fcc7c62016-07-02 21:22:52 +02001121
1122 " Tests for %E, %C and %Z format specifiers
1123 let lines = ["Error 275",
1124 \ "line 42",
1125 \ "column 3",
1126 \ "' ' expected after '--'"
1127 \]
1128 set efm=%EError\ %n,%Cline\ %l,%Ccolumn\ %c,%Z%m
1129 cgetexpr lines
1130 let l = getqflist()
1131 call assert_equal(275, l[0].nr)
1132 call assert_equal(42, l[0].lnum)
1133 call assert_equal(3, l[0].col)
1134 call assert_equal('E', l[0].type)
1135 call assert_equal("\n' ' expected after '--'", l[0].text)
1136
1137 " Test for %>
1138 let lines = ["Error in line 147 of foo.c:",
1139 \"unknown variable 'i'"
1140 \]
1141 set efm=unknown\ variable\ %m,%E%>Error\ in\ line\ %l\ of\ %f:,%Z%m
1142 cgetexpr lines
1143 let l = getqflist()
1144 call assert_equal(147, l[0].lnum)
1145 call assert_equal('E', l[0].type)
1146 call assert_equal("\nunknown variable 'i'", l[0].text)
Bram Moolenaar049cba92016-06-26 14:38:04 +02001147
Bram Moolenaare87e6dd2016-07-17 19:25:04 +02001148 " Test for %A, %C and other formats
1149 let lines = [
1150 \"==============================================================",
1151 \"FAIL: testGetTypeIdCachesResult (dbfacadeTest.DjsDBFacadeTest)",
1152 \"--------------------------------------------------------------",
1153 \"Traceback (most recent call last):",
1154 \' File "unittests/dbfacadeTest.py", line 89, in testFoo',
1155 \" self.assertEquals(34, dtid)",
1156 \' File "/usr/lib/python2.2/unittest.py", line 286, in',
1157 \" failUnlessEqual",
1158 \" raise self.failureException, \\",
1159 \"AssertionError: 34 != 33",
1160 \"",
1161 \"--------------------------------------------------------------",
1162 \"Ran 27 tests in 0.063s"
1163 \]
1164 set efm=%C\ %.%#,%A\ \ File\ \"%f\"\\,\ line\ %l%.%#,%Z%[%^\ ]%\\@=%m
1165 cgetexpr lines
1166 let l = getqflist()
1167 call assert_equal(8, len(l))
1168 call assert_equal(89, l[4].lnum)
1169 call assert_equal(1, l[4].valid)
1170 call assert_equal('unittests/dbfacadeTest.py', bufname(l[4].bufnr))
1171
Bram Moolenaard76ce852018-05-01 15:02:04 +02001172 " Test for %o
1173 set efm=%f(%o):%l\ %m
Bram Moolenaarbc7845d2018-05-01 16:26:48 +02001174 cgetexpr ['Xotestfile(Language.PureScript.Types):20 Error']
1175 call writefile(['Line1'], 'Xotestfile')
Bram Moolenaard76ce852018-05-01 15:02:04 +02001176 let l = getqflist()
1177 call assert_equal(1, len(l), string(l))
1178 call assert_equal('Language.PureScript.Types', l[0].module)
1179 copen
1180 call assert_equal('Language.PureScript.Types|20| Error', getline(1))
1181 call feedkeys("\<CR>", 'xn')
Bram Moolenaarbc7845d2018-05-01 16:26:48 +02001182 call assert_equal('Xotestfile', expand('%:t'))
Bram Moolenaard76ce852018-05-01 15:02:04 +02001183 cclose
1184 bd
Bram Moolenaarbc7845d2018-05-01 16:26:48 +02001185 call delete("Xotestfile")
Bram Moolenaard76ce852018-05-01 15:02:04 +02001186
Bram Moolenaar99895ea2017-04-20 22:44:47 +02001187 " The following sequence of commands used to crash Vim
1188 set efm=%W%m
1189 cgetexpr ['msg1']
1190 let l = getqflist()
1191 call assert_equal(1, len(l), string(l))
1192 call assert_equal('msg1', l[0].text)
1193 set efm=%C%m
1194 lexpr 'msg2'
1195 let l = getloclist(0)
1196 call assert_equal(1, len(l), string(l))
1197 call assert_equal('msg2', l[0].text)
1198 lopen
1199 call setqflist([], 'r')
1200 caddbuf
1201 let l = getqflist()
1202 call assert_equal(1, len(l), string(l))
1203 call assert_equal('|| msg2', l[0].text)
1204
Bram Moolenaar78ddc062018-05-15 21:56:34 +02001205 " When matching error lines, case should be ignored. Test for this.
1206 set noignorecase
1207 let l=getqflist({'lines' : ['Xtest:FOO10:Line 20'], 'efm':'%f:foo%l:%m'})
1208 call assert_equal(10, l.items[0].lnum)
1209 call assert_equal('Line 20', l.items[0].text)
1210 set ignorecase&
1211
Bram Moolenaar99895ea2017-04-20 22:44:47 +02001212 new | only
Bram Moolenaar049cba92016-06-26 14:38:04 +02001213 let &efm = save_efm
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001214endfunc
Bram Moolenaar049cba92016-06-26 14:38:04 +02001215
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001216func XquickfixChangedByAutocmd(cchar)
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001217 call s:setup_commands(a:cchar)
Bram Moolenaarffec3c52016-03-23 20:55:42 +01001218 if a:cchar == 'c'
Bram Moolenaarffec3c52016-03-23 20:55:42 +01001219 let ErrorNr = 'E925'
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001220 func! ReadFunc()
Bram Moolenaarffec3c52016-03-23 20:55:42 +01001221 colder
1222 cgetexpr []
1223 endfunc
1224 else
Bram Moolenaarffec3c52016-03-23 20:55:42 +01001225 let ErrorNr = 'E926'
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001226 func! ReadFunc()
Bram Moolenaarffec3c52016-03-23 20:55:42 +01001227 lolder
1228 lgetexpr []
1229 endfunc
1230 endif
1231
1232 augroup testgroup
1233 au!
Bram Moolenaard106e5b2016-04-21 19:38:07 +02001234 autocmd BufReadCmd test_changed.txt call ReadFunc()
Bram Moolenaarffec3c52016-03-23 20:55:42 +01001235 augroup END
1236
Bram Moolenaard106e5b2016-04-21 19:38:07 +02001237 new | only
Bram Moolenaarffec3c52016-03-23 20:55:42 +01001238 let words = [ "a", "b" ]
1239 let qflist = []
1240 for word in words
Bram Moolenaard106e5b2016-04-21 19:38:07 +02001241 call add(qflist, {'filename': 'test_changed.txt'})
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001242 call g:Xsetlist(qflist, ' ')
Bram Moolenaarffec3c52016-03-23 20:55:42 +01001243 endfor
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001244 call assert_fails('Xrewind', ErrorNr . ':')
Bram Moolenaarffec3c52016-03-23 20:55:42 +01001245
1246 augroup! testgroup
1247endfunc
1248
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001249func Test_quickfix_was_changed_by_autocmd()
Bram Moolenaarffec3c52016-03-23 20:55:42 +01001250 call XquickfixChangedByAutocmd('c')
1251 call XquickfixChangedByAutocmd('l')
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001252endfunc
Bram Moolenaar8b201792016-03-25 15:01:10 +01001253
1254func Test_caddbuffer_to_empty()
1255 helpgr quickfix
1256 call setqflist([], 'r')
1257 cad
Bram Moolenaarf68f1d72016-03-25 17:14:06 +01001258 try
1259 cn
1260 catch
1261 " number of matches is unknown
1262 call assert_true(v:exception =~ 'E553:')
1263 endtry
Bram Moolenaar8b201792016-03-25 15:01:10 +01001264 quit!
1265endfunc
Bram Moolenaar89c64d52016-03-27 18:44:40 +02001266
1267func Test_cgetexpr_works()
1268 " this must not crash Vim
1269 cgetexpr [$x]
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001270 lgetexpr [$x]
Bram Moolenaar89c64d52016-03-27 18:44:40 +02001271endfunc
Bram Moolenaarc1808d52016-04-18 20:04:00 +02001272
1273" Tests for the setqflist() and setloclist() functions
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001274func SetXlistTests(cchar, bnum)
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001275 call s:setup_commands(a:cchar)
Bram Moolenaarc1808d52016-04-18 20:04:00 +02001276
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001277 call g:Xsetlist([{'bufnr': a:bnum, 'lnum': 1},
Bram Moolenaarc1808d52016-04-18 20:04:00 +02001278 \ {'bufnr': a:bnum, 'lnum': 2}])
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001279 let l = g:Xgetlist()
Bram Moolenaarc1808d52016-04-18 20:04:00 +02001280 call assert_equal(2, len(l))
1281 call assert_equal(2, l[1].lnum)
1282
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001283 Xnext
1284 call g:Xsetlist([{'bufnr': a:bnum, 'lnum': 3}], 'a')
1285 let l = g:Xgetlist()
Bram Moolenaarc1808d52016-04-18 20:04:00 +02001286 call assert_equal(3, len(l))
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001287 Xnext
Bram Moolenaarc1808d52016-04-18 20:04:00 +02001288 call assert_equal(3, line('.'))
1289
Bram Moolenaar2b2b8ae2016-05-24 19:59:51 +02001290 " Appending entries to the list should not change the cursor position
1291 " in the quickfix window
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001292 Xwindow
Bram Moolenaar2b2b8ae2016-05-24 19:59:51 +02001293 1
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001294 call g:Xsetlist([{'bufnr': a:bnum, 'lnum': 4},
Bram Moolenaar2b2b8ae2016-05-24 19:59:51 +02001295 \ {'bufnr': a:bnum, 'lnum': 5}], 'a')
1296 call assert_equal(1, line('.'))
1297 close
1298
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001299 call g:Xsetlist([{'bufnr': a:bnum, 'lnum': 3},
Bram Moolenaarc1808d52016-04-18 20:04:00 +02001300 \ {'bufnr': a:bnum, 'lnum': 4},
1301 \ {'bufnr': a:bnum, 'lnum': 5}], 'r')
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001302 let l = g:Xgetlist()
Bram Moolenaarc1808d52016-04-18 20:04:00 +02001303 call assert_equal(3, len(l))
1304 call assert_equal(5, l[2].lnum)
1305
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001306 call g:Xsetlist([])
1307 let l = g:Xgetlist()
Bram Moolenaarc1808d52016-04-18 20:04:00 +02001308 call assert_equal(0, len(l))
Bram Moolenaaree85df32017-03-19 14:19:50 +01001309
Bram Moolenaarf1d21c82017-04-22 21:20:46 +02001310 " Tests for setting the 'valid' flag
1311 call g:Xsetlist([{'bufnr':a:bnum, 'lnum':4, 'valid':0}])
1312 Xwindow
1313 call assert_equal(1, winnr('$'))
1314 let l = g:Xgetlist()
1315 call g:Xsetlist(l)
1316 call assert_equal(0, g:Xgetlist()[0].valid)
Bram Moolenaar9752c722018-12-22 16:49:34 +01001317 " Adding a non-valid entry should not mark the list as having valid entries
1318 call g:Xsetlist([{'bufnr':a:bnum, 'lnum':5, 'valid':0}], 'a')
1319 Xwindow
1320 call assert_equal(1, winnr('$'))
1321
1322 " :cnext/:cprev should still work even with invalid entries in the list
1323 let l = [{'bufnr' : a:bnum, 'lnum' : 1, 'text' : '1', 'valid' : 0},
1324 \ {'bufnr' : a:bnum, 'lnum' : 2, 'text' : '2', 'valid' : 0}]
1325 call g:Xsetlist(l)
1326 Xnext
1327 call assert_equal(2, g:Xgetlist({'idx' : 0}).idx)
1328 Xprev
1329 call assert_equal(1, g:Xgetlist({'idx' : 0}).idx)
1330 " :cnext/:cprev should still work after appending invalid entries to an
1331 " empty list
1332 call g:Xsetlist([])
1333 call g:Xsetlist(l, 'a')
1334 Xnext
1335 call assert_equal(2, g:Xgetlist({'idx' : 0}).idx)
1336 Xprev
1337 call assert_equal(1, g:Xgetlist({'idx' : 0}).idx)
1338
Bram Moolenaarf1d21c82017-04-22 21:20:46 +02001339 call g:Xsetlist([{'text':'Text1', 'valid':1}])
1340 Xwindow
1341 call assert_equal(2, winnr('$'))
1342 Xclose
1343 let save_efm = &efm
1344 set efm=%m
1345 Xgetexpr 'TestMessage'
1346 let l = g:Xgetlist()
1347 call g:Xsetlist(l)
1348 call assert_equal(1, g:Xgetlist()[0].valid)
1349 let &efm = save_efm
1350
Bram Moolenaaree85df32017-03-19 14:19:50 +01001351 " Error cases:
1352 " Refer to a non-existing buffer and pass a non-dictionary type
1353 call assert_fails("call g:Xsetlist([{'bufnr':998, 'lnum':4}," .
1354 \ " {'bufnr':999, 'lnum':5}])", 'E92:')
1355 call g:Xsetlist([[1, 2,3]])
1356 call assert_equal(0, len(g:Xgetlist()))
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001357endfunc
Bram Moolenaarc1808d52016-04-18 20:04:00 +02001358
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001359func Test_setqflist()
Bram Moolenaarc1808d52016-04-18 20:04:00 +02001360 new Xtestfile | only
1361 let bnum = bufnr('%')
1362 call setline(1, range(1,5))
1363
1364 call SetXlistTests('c', bnum)
1365 call SetXlistTests('l', bnum)
1366
Bram Moolenaar1cee6932016-06-09 22:17:22 +02001367 enew!
Bram Moolenaarc1808d52016-04-18 20:04:00 +02001368 call delete('Xtestfile')
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001369endfunc
Bram Moolenaard106e5b2016-04-21 19:38:07 +02001370
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001371func Xlist_empty_middle(cchar)
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001372 call s:setup_commands(a:cchar)
1373
Bram Moolenaar1cee6932016-06-09 22:17:22 +02001374 " create three quickfix lists
Bram Moolenaaree85df32017-03-19 14:19:50 +01001375 let @/ = 'Test_'
1376 Xvimgrep // test_quickfix.vim
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001377 let testlen = len(g:Xgetlist())
Bram Moolenaar1cee6932016-06-09 22:17:22 +02001378 call assert_true(testlen > 0)
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001379 Xvimgrep empty test_quickfix.vim
1380 call assert_true(len(g:Xgetlist()) > 0)
1381 Xvimgrep matches test_quickfix.vim
1382 let matchlen = len(g:Xgetlist())
Bram Moolenaar1cee6932016-06-09 22:17:22 +02001383 call assert_true(matchlen > 0)
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001384 Xolder
Bram Moolenaar1cee6932016-06-09 22:17:22 +02001385 " make the middle list empty
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001386 call g:Xsetlist([], 'r')
1387 call assert_true(len(g:Xgetlist()) == 0)
1388 Xolder
1389 call assert_equal(testlen, len(g:Xgetlist()))
1390 Xnewer
1391 Xnewer
1392 call assert_equal(matchlen, len(g:Xgetlist()))
Bram Moolenaar1cee6932016-06-09 22:17:22 +02001393endfunc
1394
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001395func Test_setqflist_empty_middle()
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001396 call Xlist_empty_middle('c')
1397 call Xlist_empty_middle('l')
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001398endfunc
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001399
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001400func Xlist_empty_older(cchar)
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001401 call s:setup_commands(a:cchar)
1402
Bram Moolenaar1cee6932016-06-09 22:17:22 +02001403 " create three quickfix lists
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001404 Xvimgrep one test_quickfix.vim
1405 let onelen = len(g:Xgetlist())
Bram Moolenaar1cee6932016-06-09 22:17:22 +02001406 call assert_true(onelen > 0)
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001407 Xvimgrep two test_quickfix.vim
1408 let twolen = len(g:Xgetlist())
Bram Moolenaar1cee6932016-06-09 22:17:22 +02001409 call assert_true(twolen > 0)
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001410 Xvimgrep three test_quickfix.vim
1411 let threelen = len(g:Xgetlist())
Bram Moolenaar1cee6932016-06-09 22:17:22 +02001412 call assert_true(threelen > 0)
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001413 Xolder 2
Bram Moolenaar1cee6932016-06-09 22:17:22 +02001414 " make the first list empty, check the others didn't change
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001415 call g:Xsetlist([], 'r')
1416 call assert_true(len(g:Xgetlist()) == 0)
1417 Xnewer
1418 call assert_equal(twolen, len(g:Xgetlist()))
1419 Xnewer
1420 call assert_equal(threelen, len(g:Xgetlist()))
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001421endfunc
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001422
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001423func Test_setqflist_empty_older()
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001424 call Xlist_empty_older('c')
1425 call Xlist_empty_older('l')
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001426endfunc
Bram Moolenaar1cee6932016-06-09 22:17:22 +02001427
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001428func XquickfixSetListWithAct(cchar)
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001429 call s:setup_commands(a:cchar)
1430
Bram Moolenaard106e5b2016-04-21 19:38:07 +02001431 let list1 = [{'filename': 'fnameA', 'text': 'A'},
1432 \ {'filename': 'fnameB', 'text': 'B'}]
1433 let list2 = [{'filename': 'fnameC', 'text': 'C'},
1434 \ {'filename': 'fnameD', 'text': 'D'},
1435 \ {'filename': 'fnameE', 'text': 'E'}]
1436
Bram Moolenaareeb1b9c2019-02-10 22:59:04 +01001437 " {action} is unspecified. Same as specifying ' '.
Bram Moolenaard106e5b2016-04-21 19:38:07 +02001438 new | only
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001439 silent! Xnewer 99
1440 call g:Xsetlist(list1)
1441 call g:Xsetlist(list2)
1442 let li = g:Xgetlist()
Bram Moolenaard106e5b2016-04-21 19:38:07 +02001443 call assert_equal(3, len(li))
1444 call assert_equal('C', li[0]['text'])
1445 call assert_equal('D', li[1]['text'])
1446 call assert_equal('E', li[2]['text'])
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001447 silent! Xolder
1448 let li = g:Xgetlist()
Bram Moolenaard106e5b2016-04-21 19:38:07 +02001449 call assert_equal(2, len(li))
1450 call assert_equal('A', li[0]['text'])
1451 call assert_equal('B', li[1]['text'])
1452
1453 " {action} is specified ' '.
1454 new | only
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001455 silent! Xnewer 99
1456 call g:Xsetlist(list1)
1457 call g:Xsetlist(list2, ' ')
1458 let li = g:Xgetlist()
Bram Moolenaard106e5b2016-04-21 19:38:07 +02001459 call assert_equal(3, len(li))
1460 call assert_equal('C', li[0]['text'])
1461 call assert_equal('D', li[1]['text'])
1462 call assert_equal('E', li[2]['text'])
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001463 silent! Xolder
1464 let li = g:Xgetlist()
Bram Moolenaard106e5b2016-04-21 19:38:07 +02001465 call assert_equal(2, len(li))
1466 call assert_equal('A', li[0]['text'])
1467 call assert_equal('B', li[1]['text'])
1468
1469 " {action} is specified 'a'.
1470 new | only
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001471 silent! Xnewer 99
1472 call g:Xsetlist(list1)
1473 call g:Xsetlist(list2, 'a')
1474 let li = g:Xgetlist()
Bram Moolenaard106e5b2016-04-21 19:38:07 +02001475 call assert_equal(5, len(li))
1476 call assert_equal('A', li[0]['text'])
1477 call assert_equal('B', li[1]['text'])
1478 call assert_equal('C', li[2]['text'])
1479 call assert_equal('D', li[3]['text'])
1480 call assert_equal('E', li[4]['text'])
1481
1482 " {action} is specified 'r'.
1483 new | only
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001484 silent! Xnewer 99
1485 call g:Xsetlist(list1)
1486 call g:Xsetlist(list2, 'r')
1487 let li = g:Xgetlist()
Bram Moolenaard106e5b2016-04-21 19:38:07 +02001488 call assert_equal(3, len(li))
1489 call assert_equal('C', li[0]['text'])
1490 call assert_equal('D', li[1]['text'])
1491 call assert_equal('E', li[2]['text'])
1492
1493 " Test for wrong value.
1494 new | only
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001495 call assert_fails("call g:Xsetlist(0)", 'E714:')
1496 call assert_fails("call g:Xsetlist(list1, '')", 'E927:')
1497 call assert_fails("call g:Xsetlist(list1, 'aa')", 'E927:')
1498 call assert_fails("call g:Xsetlist(list1, ' a')", 'E927:')
1499 call assert_fails("call g:Xsetlist(list1, 0)", 'E928:')
Bram Moolenaard106e5b2016-04-21 19:38:07 +02001500endfunc
1501
Bram Moolenaara0ca7d02017-12-19 10:22:19 +01001502func Test_setqflist_invalid_nr()
1503 " The following command used to crash Vim
1504 call setqflist([], ' ', {'nr' : $XXX_DOES_NOT_EXIST})
1505endfunc
1506
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001507func Test_quickfix_set_list_with_act()
Bram Moolenaard106e5b2016-04-21 19:38:07 +02001508 call XquickfixSetListWithAct('c')
1509 call XquickfixSetListWithAct('l')
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001510endfunc
Bram Moolenaar6be8c8e2016-04-30 13:17:09 +02001511
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001512func XLongLinesTests(cchar)
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001513 let l = g:Xgetlist()
Bram Moolenaar6be8c8e2016-04-30 13:17:09 +02001514
Bram Moolenaar049cba92016-06-26 14:38:04 +02001515 call assert_equal(4, len(l))
Bram Moolenaar6be8c8e2016-04-30 13:17:09 +02001516 call assert_equal(1, l[0].lnum)
1517 call assert_equal(1, l[0].col)
Bram Moolenaar049cba92016-06-26 14:38:04 +02001518 call assert_equal(1975, len(l[0].text))
Bram Moolenaar6be8c8e2016-04-30 13:17:09 +02001519 call assert_equal(2, l[1].lnum)
1520 call assert_equal(1, l[1].col)
1521 call assert_equal(4070, len(l[1].text))
1522 call assert_equal(3, l[2].lnum)
1523 call assert_equal(1, l[2].col)
Bram Moolenaar049cba92016-06-26 14:38:04 +02001524 call assert_equal(4070, len(l[2].text))
1525 call assert_equal(4, l[3].lnum)
1526 call assert_equal(1, l[3].col)
1527 call assert_equal(10, len(l[3].text))
Bram Moolenaar6be8c8e2016-04-30 13:17:09 +02001528
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001529 call g:Xsetlist([], 'r')
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001530endfunc
Bram Moolenaar6be8c8e2016-04-30 13:17:09 +02001531
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001532func s:long_lines_tests(cchar)
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001533 call s:setup_commands(a:cchar)
1534
Bram Moolenaar6be8c8e2016-04-30 13:17:09 +02001535 let testfile = 'samples/quickfix.txt'
1536
1537 " file
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001538 exe 'Xgetfile' testfile
1539 call XLongLinesTests(a:cchar)
Bram Moolenaar6be8c8e2016-04-30 13:17:09 +02001540
1541 " list
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001542 Xexpr readfile(testfile)
1543 call XLongLinesTests(a:cchar)
Bram Moolenaar6be8c8e2016-04-30 13:17:09 +02001544
1545 " string
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001546 Xexpr join(readfile(testfile), "\n")
1547 call XLongLinesTests(a:cchar)
Bram Moolenaar6be8c8e2016-04-30 13:17:09 +02001548
1549 " buffer
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001550 exe 'edit' testfile
1551 exe 'Xbuffer' bufnr('%')
Bram Moolenaarf50df392016-06-21 21:33:34 +02001552 call XLongLinesTests(a:cchar)
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001553endfunc
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001554
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001555func Test_long_lines()
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001556 call s:long_lines_tests('c')
1557 call s:long_lines_tests('l')
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001558endfunc
Bram Moolenaar049cba92016-06-26 14:38:04 +02001559
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001560func s:create_test_file(filename)
Bram Moolenaar049cba92016-06-26 14:38:04 +02001561 let l = []
1562 for i in range(1, 20)
1563 call add(l, 'Line' . i)
1564 endfor
1565 call writefile(l, a:filename)
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001566endfunc
Bram Moolenaar049cba92016-06-26 14:38:04 +02001567
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001568func Test_switchbuf()
Bram Moolenaar049cba92016-06-26 14:38:04 +02001569 call s:create_test_file('Xqftestfile1')
1570 call s:create_test_file('Xqftestfile2')
1571 call s:create_test_file('Xqftestfile3')
1572
1573 new | only
1574 edit Xqftestfile1
1575 let file1_winid = win_getid()
1576 new Xqftestfile2
1577 let file2_winid = win_getid()
1578 cgetexpr ['Xqftestfile1:5:Line5',
1579 \ 'Xqftestfile1:6:Line6',
1580 \ 'Xqftestfile2:10:Line10',
1581 \ 'Xqftestfile2:11:Line11',
1582 \ 'Xqftestfile3:15:Line15',
1583 \ 'Xqftestfile3:16:Line16']
1584
1585 new
1586 let winid = win_getid()
1587 cfirst | cnext
1588 call assert_equal(winid, win_getid())
Bram Moolenaar99895ea2017-04-20 22:44:47 +02001589 2cnext
Bram Moolenaar049cba92016-06-26 14:38:04 +02001590 call assert_equal(winid, win_getid())
Bram Moolenaar99895ea2017-04-20 22:44:47 +02001591 2cnext
Bram Moolenaar049cba92016-06-26 14:38:04 +02001592 call assert_equal(winid, win_getid())
1593 enew
1594
1595 set switchbuf=useopen
1596 cfirst | cnext
1597 call assert_equal(file1_winid, win_getid())
Bram Moolenaar99895ea2017-04-20 22:44:47 +02001598 2cnext
Bram Moolenaar049cba92016-06-26 14:38:04 +02001599 call assert_equal(file2_winid, win_getid())
Bram Moolenaar99895ea2017-04-20 22:44:47 +02001600 2cnext
Bram Moolenaar049cba92016-06-26 14:38:04 +02001601 call assert_equal(file2_winid, win_getid())
1602
1603 enew | only
1604 set switchbuf=usetab
1605 tabedit Xqftestfile1
1606 tabedit Xqftestfile2
Bram Moolenaar74240d32017-12-10 15:26:15 +01001607 tabedit Xqftestfile3
Bram Moolenaar049cba92016-06-26 14:38:04 +02001608 tabfirst
1609 cfirst | cnext
1610 call assert_equal(2, tabpagenr())
Bram Moolenaar99895ea2017-04-20 22:44:47 +02001611 2cnext
Bram Moolenaar049cba92016-06-26 14:38:04 +02001612 call assert_equal(3, tabpagenr())
Bram Moolenaar74240d32017-12-10 15:26:15 +01001613 6cnext
1614 call assert_equal(4, tabpagenr())
1615 2cpfile
1616 call assert_equal(2, tabpagenr())
1617 2cnfile
1618 call assert_equal(4, tabpagenr())
Bram Moolenaar049cba92016-06-26 14:38:04 +02001619 tabfirst | tabonly | enew
1620
1621 set switchbuf=split
1622 cfirst | cnext
1623 call assert_equal(1, winnr('$'))
1624 cnext | cnext
1625 call assert_equal(2, winnr('$'))
1626 cnext | cnext
1627 call assert_equal(3, winnr('$'))
1628 enew | only
1629
1630 set switchbuf=newtab
1631 cfirst | cnext
1632 call assert_equal(1, tabpagenr('$'))
1633 cnext | cnext
1634 call assert_equal(2, tabpagenr('$'))
1635 cnext | cnext
1636 call assert_equal(3, tabpagenr('$'))
1637 tabfirst | enew | tabonly | only
1638
1639 set switchbuf=
1640 edit Xqftestfile1
1641 let file1_winid = win_getid()
1642 new Xqftestfile2
1643 let file2_winid = win_getid()
1644 copen
1645 exe "normal 1G\<CR>"
1646 call assert_equal(file1_winid, win_getid())
1647 copen
1648 exe "normal 3G\<CR>"
1649 call assert_equal(file2_winid, win_getid())
1650 copen | only
1651 exe "normal 5G\<CR>"
1652 call assert_equal(2, winnr('$'))
1653 call assert_equal(1, bufwinnr('Xqftestfile3'))
1654
Bram Moolenaar391b1dd2017-03-04 13:47:11 +01001655 " If only quickfix window is open in the current tabpage, jumping to an
1656 " entry with 'switchubf' set to 'usetab' should search in other tabpages.
Bram Moolenaar049cba92016-06-26 14:38:04 +02001657 enew | only
Bram Moolenaar391b1dd2017-03-04 13:47:11 +01001658 set switchbuf=usetab
1659 tabedit Xqftestfile1
1660 tabedit Xqftestfile2
1661 tabedit Xqftestfile3
1662 tabfirst
1663 copen | only
1664 clast
1665 call assert_equal(4, tabpagenr())
1666 tabfirst | tabonly | enew | only
Bram Moolenaar049cba92016-06-26 14:38:04 +02001667
1668 call delete('Xqftestfile1')
1669 call delete('Xqftestfile2')
1670 call delete('Xqftestfile3')
Bram Moolenaar391b1dd2017-03-04 13:47:11 +01001671 set switchbuf&vim
1672
1673 enew | only
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001674endfunc
Bram Moolenaar049cba92016-06-26 14:38:04 +02001675
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001676func Xadjust_qflnum(cchar)
Bram Moolenaar049cba92016-06-26 14:38:04 +02001677 call s:setup_commands(a:cchar)
1678
1679 enew | only
1680
Bram Moolenaarc1542742016-07-20 21:44:37 +02001681 let fname = 'Xqftestfile' . a:cchar
1682 call s:create_test_file(fname)
1683 exe 'edit ' . fname
Bram Moolenaar049cba92016-06-26 14:38:04 +02001684
Bram Moolenaarc1542742016-07-20 21:44:37 +02001685 Xgetexpr [fname . ':5:Line5',
1686 \ fname . ':10:Line10',
1687 \ fname . ':15:Line15',
1688 \ fname . ':20:Line20']
Bram Moolenaar049cba92016-06-26 14:38:04 +02001689
1690 6,14delete
1691 call append(6, ['Buffer', 'Window'])
1692
1693 let l = g:Xgetlist()
1694
1695 call assert_equal(5, l[0].lnum)
1696 call assert_equal(6, l[2].lnum)
1697 call assert_equal(13, l[3].lnum)
1698
1699 enew!
Bram Moolenaarc1542742016-07-20 21:44:37 +02001700 call delete(fname)
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001701endfunc
Bram Moolenaar049cba92016-06-26 14:38:04 +02001702
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001703func Test_adjust_lnum()
Bram Moolenaarc1542742016-07-20 21:44:37 +02001704 call setloclist(0, [])
Bram Moolenaar049cba92016-06-26 14:38:04 +02001705 call Xadjust_qflnum('c')
Bram Moolenaarc1542742016-07-20 21:44:37 +02001706 call setqflist([])
Bram Moolenaar049cba92016-06-26 14:38:04 +02001707 call Xadjust_qflnum('l')
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001708endfunc
Bram Moolenaar049cba92016-06-26 14:38:04 +02001709
1710" Tests for the :grep/:lgrep and :grepadd/:lgrepadd commands
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001711func s:test_xgrep(cchar)
Bram Moolenaar049cba92016-06-26 14:38:04 +02001712 call s:setup_commands(a:cchar)
1713
1714 " The following lines are used for the grep test. Don't remove.
1715 " Grep_Test_Text: Match 1
1716 " Grep_Test_Text: Match 2
1717 " GrepAdd_Test_Text: Match 1
1718 " GrepAdd_Test_Text: Match 2
1719 enew! | only
1720 set makeef&vim
1721 silent Xgrep Grep_Test_Text: test_quickfix.vim
1722 call assert_true(len(g:Xgetlist()) == 3)
1723 Xopen
1724 call assert_true(w:quickfix_title =~ '^:grep')
1725 Xclose
1726 enew
1727 set makeef=Temp_File_##
1728 silent Xgrepadd GrepAdd_Test_Text: test_quickfix.vim
1729 call assert_true(len(g:Xgetlist()) == 6)
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001730endfunc
Bram Moolenaar049cba92016-06-26 14:38:04 +02001731
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001732func Test_grep()
Bram Moolenaar049cba92016-06-26 14:38:04 +02001733 if !has('unix')
1734 " The grepprg may not be set on non-Unix systems
1735 return
1736 endif
1737
1738 call s:test_xgrep('c')
1739 call s:test_xgrep('l')
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001740endfunc
Bram Moolenaar361c8f02016-07-02 15:41:47 +02001741
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001742func Test_two_windows()
Bram Moolenaar361c8f02016-07-02 15:41:47 +02001743 " Use one 'errorformat' for two windows. Add an expression to each of them,
1744 " make sure they each keep their own state.
1745 set efm=%DEntering\ dir\ '%f',%f:%l:%m,%XLeaving\ dir\ '%f'
1746 call mkdir('Xone/a', 'p')
1747 call mkdir('Xtwo/a', 'p')
1748 let lines = ['1', '2', 'one one one', '4', 'two two two', '6', '7']
1749 call writefile(lines, 'Xone/a/one.txt')
1750 call writefile(lines, 'Xtwo/a/two.txt')
1751
1752 new one
1753 let one_id = win_getid()
1754 lexpr ""
1755 new two
1756 let two_id = win_getid()
1757 lexpr ""
1758
1759 laddexpr "Entering dir 'Xtwo/a'"
1760 call win_gotoid(one_id)
1761 laddexpr "Entering dir 'Xone/a'"
1762 call win_gotoid(two_id)
1763 laddexpr 'two.txt:5:two two two'
1764 call win_gotoid(one_id)
1765 laddexpr 'one.txt:3:one one one'
1766
1767 let loc_one = getloclist(one_id)
Bram Moolenaar361c8f02016-07-02 15:41:47 +02001768 call assert_equal('Xone/a/one.txt', bufname(loc_one[1].bufnr))
1769 call assert_equal(3, loc_one[1].lnum)
1770
1771 let loc_two = getloclist(two_id)
Bram Moolenaar361c8f02016-07-02 15:41:47 +02001772 call assert_equal('Xtwo/a/two.txt', bufname(loc_two[1].bufnr))
1773 call assert_equal(5, loc_two[1].lnum)
1774
1775 call win_gotoid(one_id)
1776 bwipe!
1777 call win_gotoid(two_id)
1778 bwipe!
1779 call delete('Xone', 'rf')
1780 call delete('Xtwo', 'rf')
1781endfunc
Bram Moolenaardcb17002016-07-07 18:58:59 +02001782
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001783func XbottomTests(cchar)
Bram Moolenaar537ef082016-07-09 17:56:19 +02001784 call s:setup_commands(a:cchar)
1785
Bram Moolenaarb6fa30c2017-03-29 14:19:25 +02001786 " Calling lbottom without any errors should fail
1787 if a:cchar == 'l'
1788 call assert_fails('lbottom', 'E776:')
1789 endif
1790
Bram Moolenaar875feea2017-06-11 16:07:51 +02001791 call g:Xsetlist([{'filename': 'foo', 'lnum': 42}])
Bram Moolenaar537ef082016-07-09 17:56:19 +02001792 Xopen
Bram Moolenaardcb17002016-07-07 18:58:59 +02001793 let wid = win_getid()
1794 call assert_equal(1, line('.'))
1795 wincmd w
Bram Moolenaar875feea2017-06-11 16:07:51 +02001796 call g:Xsetlist([{'filename': 'var', 'lnum': 24}], 'a')
Bram Moolenaar537ef082016-07-09 17:56:19 +02001797 Xbottom
Bram Moolenaardcb17002016-07-07 18:58:59 +02001798 call win_gotoid(wid)
1799 call assert_equal(2, line('.'))
Bram Moolenaar537ef082016-07-09 17:56:19 +02001800 Xclose
Bram Moolenaardcb17002016-07-07 18:58:59 +02001801endfunc
Bram Moolenaar537ef082016-07-09 17:56:19 +02001802
1803" Tests for the :cbottom and :lbottom commands
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001804func Test_cbottom()
Bram Moolenaar537ef082016-07-09 17:56:19 +02001805 call XbottomTests('c')
1806 call XbottomTests('l')
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001807endfunc
Bram Moolenaarf6acffb2016-07-16 16:54:24 +02001808
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001809func HistoryTest(cchar)
Bram Moolenaarf6acffb2016-07-16 16:54:24 +02001810 call s:setup_commands(a:cchar)
1811
Bram Moolenaarf6acffb2016-07-16 16:54:24 +02001812 " clear all lists after the first one, then replace the first one.
1813 call g:Xsetlist([])
Bram Moolenaarb6fa30c2017-03-29 14:19:25 +02001814 call assert_fails('Xolder 99', 'E380:')
Bram Moolenaarf6acffb2016-07-16 16:54:24 +02001815 let entry = {'filename': 'foo', 'lnum': 42}
1816 call g:Xsetlist([entry], 'r')
1817 call g:Xsetlist([entry, entry])
1818 call g:Xsetlist([entry, entry, entry])
1819 let res = split(execute(a:cchar . 'hist'), "\n")
1820 call assert_equal(3, len(res))
1821 let common = 'errors :set' . (a:cchar == 'c' ? 'qf' : 'loc') . 'list()'
1822 call assert_equal(' error list 1 of 3; 1 ' . common, res[0])
1823 call assert_equal(' error list 2 of 3; 2 ' . common, res[1])
1824 call assert_equal('> error list 3 of 3; 3 ' . common, res[2])
Bram Moolenaarb4d5fba2017-09-11 19:31:28 +02001825
1826 call g:Xsetlist([], 'f')
1827 let l = split(execute(a:cchar . 'hist'), "\n")
1828 call assert_equal('No entries', l[0])
Bram Moolenaar5b69c222019-01-11 14:50:06 +01001829
1830 " An empty list should still show the stack history
1831 call g:Xsetlist([])
1832 let res = split(execute(a:cchar . 'hist'), "\n")
1833 call assert_equal('> error list 1 of 1; 0 ' . common, res[0])
1834
1835 call g:Xsetlist([], 'f')
Bram Moolenaarf6acffb2016-07-16 16:54:24 +02001836endfunc
1837
1838func Test_history()
1839 call HistoryTest('c')
1840 call HistoryTest('l')
1841endfunc
Bram Moolenaar015102e2016-07-16 18:24:56 +02001842
1843func Test_duplicate_buf()
1844 " make sure we can get the highest buffer number
1845 edit DoesNotExist
1846 edit DoesNotExist2
1847 let last_buffer = bufnr("$")
1848
1849 " make sure only one buffer is created
1850 call writefile(['this one', 'that one'], 'Xgrepthis')
1851 vimgrep one Xgrepthis
1852 vimgrep one Xgrepthis
1853 call assert_equal(last_buffer + 1, bufnr("$"))
1854
1855 call delete('Xgrepthis')
1856endfunc
Bram Moolenaard823fa92016-08-12 16:29:27 +02001857
1858" Quickfix/Location list set/get properties tests
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001859func Xproperty_tests(cchar)
Bram Moolenaard823fa92016-08-12 16:29:27 +02001860 call s:setup_commands(a:cchar)
1861
1862 " Error cases
1863 call assert_fails('call g:Xgetlist(99)', 'E715:')
1864 call assert_fails('call g:Xsetlist(99)', 'E714:')
1865 call assert_fails('call g:Xsetlist([], "a", [])', 'E715:')
1866
1867 " Set and get the title
Bram Moolenaarb6fa30c2017-03-29 14:19:25 +02001868 call g:Xsetlist([])
Bram Moolenaard823fa92016-08-12 16:29:27 +02001869 Xopen
1870 wincmd p
1871 call g:Xsetlist([{'filename':'foo', 'lnum':27}])
Bram Moolenaar86f100dc2017-06-28 21:26:27 +02001872 let s = g:Xsetlist([], 'a', {'title' : 'Sample'})
1873 call assert_equal(0, s)
Bram Moolenaard823fa92016-08-12 16:29:27 +02001874 let d = g:Xgetlist({"title":1})
1875 call assert_equal('Sample', d.title)
Bram Moolenaara2aa8a22018-04-24 13:55:00 +02001876 " Try setting title to a non-string value
1877 call assert_equal(-1, g:Xsetlist([], 'a', {'title' : ['Test']}))
1878 call assert_equal('Sample', g:Xgetlist({"title":1}).title)
Bram Moolenaard823fa92016-08-12 16:29:27 +02001879
1880 Xopen
1881 call assert_equal('Sample', w:quickfix_title)
1882 Xclose
1883
Bram Moolenaar2b529bb2016-08-27 13:35:35 +02001884 " Tests for action argument
1885 silent! Xolder 999
1886 let qfnr = g:Xgetlist({'all':1}).nr
1887 call g:Xsetlist([], 'r', {'title' : 'N1'})
1888 call assert_equal('N1', g:Xgetlist({'all':1}).title)
1889 call g:Xsetlist([], ' ', {'title' : 'N2'})
1890 call assert_equal(qfnr + 1, g:Xgetlist({'all':1}).nr)
Bram Moolenaar890680c2016-09-27 21:28:56 +02001891
1892 let res = g:Xgetlist({'nr': 0})
1893 call assert_equal(qfnr + 1, res.nr)
1894 call assert_equal(['nr'], keys(res))
1895
Bram Moolenaar2b529bb2016-08-27 13:35:35 +02001896 call g:Xsetlist([], ' ', {'title' : 'N3'})
1897 call assert_equal('N2', g:Xgetlist({'nr':2, 'title':1}).title)
1898
Bram Moolenaaree85df32017-03-19 14:19:50 +01001899 " Changing the title of an earlier quickfix list
Bram Moolenaar55b69262017-08-13 13:42:01 +02001900 call g:Xsetlist([], 'r', {'title' : 'NewTitle', 'nr' : 2})
Bram Moolenaaree85df32017-03-19 14:19:50 +01001901 call assert_equal('NewTitle', g:Xgetlist({'nr':2, 'title':1}).title)
1902
1903 " Changing the title of an invalid quickfix list
1904 call assert_equal(-1, g:Xsetlist([], ' ',
1905 \ {'title' : 'SomeTitle', 'nr' : 99}))
1906 call assert_equal(-1, g:Xsetlist([], ' ',
1907 \ {'title' : 'SomeTitle', 'nr' : 'abc'}))
1908
1909 if a:cchar == 'c'
1910 copen
1911 call assert_equal({'winid':win_getid()}, getqflist({'winid':1}))
1912 cclose
1913 endif
1914
Bram Moolenaard823fa92016-08-12 16:29:27 +02001915 " Invalid arguments
1916 call assert_fails('call g:Xgetlist([])', 'E715')
1917 call assert_fails('call g:Xsetlist([], "a", [])', 'E715')
1918 let s = g:Xsetlist([], 'a', {'abc':1})
1919 call assert_equal(-1, s)
1920
1921 call assert_equal({}, g:Xgetlist({'abc':1}))
Bram Moolenaara6d48492017-12-12 22:45:31 +01001922 call assert_equal('', g:Xgetlist({'nr':99, 'title':1}).title)
1923 call assert_equal('', g:Xgetlist({'nr':[], 'title':1}).title)
Bram Moolenaard823fa92016-08-12 16:29:27 +02001924
1925 if a:cchar == 'l'
Bram Moolenaar890680c2016-09-27 21:28:56 +02001926 call assert_equal({}, getloclist(99, {'title': 1}))
Bram Moolenaard823fa92016-08-12 16:29:27 +02001927 endif
Bram Moolenaar8f77c5a2017-04-30 14:21:00 +02001928
1929 " Context related tests
Bram Moolenaar86f100dc2017-06-28 21:26:27 +02001930 let s = g:Xsetlist([], 'a', {'context':[1,2,3]})
1931 call assert_equal(0, s)
Bram Moolenaar8f77c5a2017-04-30 14:21:00 +02001932 call test_garbagecollect_now()
1933 let d = g:Xgetlist({'context':1})
1934 call assert_equal([1,2,3], d.context)
1935 call g:Xsetlist([], 'a', {'context':{'color':'green'}})
1936 let d = g:Xgetlist({'context':1})
1937 call assert_equal({'color':'green'}, d.context)
1938 call g:Xsetlist([], 'a', {'context':"Context info"})
1939 let d = g:Xgetlist({'context':1})
1940 call assert_equal("Context info", d.context)
1941 call g:Xsetlist([], 'a', {'context':246})
1942 let d = g:Xgetlist({'context':1})
1943 call assert_equal(246, d.context)
1944 if a:cchar == 'l'
1945 " Test for copying context across two different location lists
1946 new | only
1947 let w1_id = win_getid()
1948 let l = [1]
1949 call setloclist(0, [], 'a', {'context':l})
1950 new
1951 let w2_id = win_getid()
1952 call add(l, 2)
1953 call assert_equal([1, 2], getloclist(w1_id, {'context':1}).context)
1954 call assert_equal([1, 2], getloclist(w2_id, {'context':1}).context)
1955 unlet! l
1956 call assert_equal([1, 2], getloclist(w2_id, {'context':1}).context)
1957 only
1958 call setloclist(0, [], 'f')
Bram Moolenaara6d48492017-12-12 22:45:31 +01001959 call assert_equal('', getloclist(0, {'context':1}).context)
Bram Moolenaar8f77c5a2017-04-30 14:21:00 +02001960 endif
Bram Moolenaar6e62da32017-05-28 08:16:25 +02001961
1962 " Test for changing the context of previous quickfix lists
1963 call g:Xsetlist([], 'f')
1964 Xexpr "One"
1965 Xexpr "Two"
1966 Xexpr "Three"
Bram Moolenaar55b69262017-08-13 13:42:01 +02001967 call g:Xsetlist([], 'r', {'context' : [1], 'nr' : 1})
1968 call g:Xsetlist([], 'a', {'context' : [2], 'nr' : 2})
Bram Moolenaar6e62da32017-05-28 08:16:25 +02001969 " Also, check for setting the context using quickfix list number zero.
Bram Moolenaar55b69262017-08-13 13:42:01 +02001970 call g:Xsetlist([], 'r', {'context' : [3], 'nr' : 0})
Bram Moolenaar6e62da32017-05-28 08:16:25 +02001971 call test_garbagecollect_now()
1972 let l = g:Xgetlist({'nr' : 1, 'context' : 1})
1973 call assert_equal([1], l.context)
1974 let l = g:Xgetlist({'nr' : 2, 'context' : 1})
1975 call assert_equal([2], l.context)
1976 let l = g:Xgetlist({'nr' : 3, 'context' : 1})
1977 call assert_equal([3], l.context)
1978
1979 " Test for changing the context through reference and for garbage
1980 " collection of quickfix context
1981 let l = ["red"]
1982 call g:Xsetlist([], ' ', {'context' : l})
1983 call add(l, "blue")
1984 let x = g:Xgetlist({'context' : 1})
1985 call add(x.context, "green")
1986 call assert_equal(["red", "blue", "green"], l)
1987 call assert_equal(["red", "blue", "green"], x.context)
1988 unlet l
1989 call test_garbagecollect_now()
1990 let m = g:Xgetlist({'context' : 1})
1991 call assert_equal(["red", "blue", "green"], m.context)
Bram Moolenaar6a8958d2017-06-22 21:33:20 +02001992
1993 " Test for setting/getting items
1994 Xexpr ""
1995 let qfprev = g:Xgetlist({'nr':0})
Bram Moolenaar86f100dc2017-06-28 21:26:27 +02001996 let s = g:Xsetlist([], ' ', {'title':'Green',
Bram Moolenaar6a8958d2017-06-22 21:33:20 +02001997 \ 'items' : [{'filename':'F1', 'lnum':10}]})
Bram Moolenaar86f100dc2017-06-28 21:26:27 +02001998 call assert_equal(0, s)
Bram Moolenaar6a8958d2017-06-22 21:33:20 +02001999 let qfcur = g:Xgetlist({'nr':0})
2000 call assert_true(qfcur.nr == qfprev.nr + 1)
2001 let l = g:Xgetlist({'items':1})
2002 call assert_equal('F1', bufname(l.items[0].bufnr))
2003 call assert_equal(10, l.items[0].lnum)
2004 call g:Xsetlist([], 'a', {'items' : [{'filename':'F2', 'lnum':20},
2005 \ {'filename':'F2', 'lnum':30}]})
2006 let l = g:Xgetlist({'items':1})
2007 call assert_equal('F2', bufname(l.items[2].bufnr))
2008 call assert_equal(30, l.items[2].lnum)
2009 call g:Xsetlist([], 'r', {'items' : [{'filename':'F3', 'lnum':40}]})
2010 let l = g:Xgetlist({'items':1})
2011 call assert_equal('F3', bufname(l.items[0].bufnr))
2012 call assert_equal(40, l.items[0].lnum)
2013 call g:Xsetlist([], 'r', {'items' : []})
2014 let l = g:Xgetlist({'items':1})
2015 call assert_equal(0, len(l.items))
2016
Bram Moolenaarb4d5fba2017-09-11 19:31:28 +02002017 call g:Xsetlist([], 'r', {'title' : 'TestTitle'})
2018 call g:Xsetlist([], 'r', {'items' : [{'filename' : 'F1', 'lnum' : 10, 'text' : 'L10'}]})
2019 call g:Xsetlist([], 'r', {'items' : [{'filename' : 'F1', 'lnum' : 10, 'text' : 'L10'}]})
2020 call assert_equal('TestTitle', g:Xgetlist({'title' : 1}).title)
2021
Bram Moolenaarc9cc9c72018-09-02 15:18:42 +02002022 " Test for getting id of window associated with a location list window
2023 if a:cchar == 'l'
2024 only
2025 call assert_equal(0, g:Xgetlist({'all' : 1}).filewinid)
2026 let wid = win_getid()
2027 Xopen
2028 call assert_equal(wid, g:Xgetlist({'filewinid' : 1}).filewinid)
2029 wincmd w
2030 call assert_equal(0, g:Xgetlist({'filewinid' : 1}).filewinid)
2031 only
2032 endif
2033
Bram Moolenaarae338332017-08-11 20:25:26 +02002034 " The following used to crash Vim with address sanitizer
2035 call g:Xsetlist([], 'f')
2036 call g:Xsetlist([], 'a', {'items' : [{'filename':'F1', 'lnum':10}]})
2037 call assert_equal(10, g:Xgetlist({'items':1}).items[0].lnum)
2038
Bram Moolenaara2aa8a22018-04-24 13:55:00 +02002039 " Try setting the items using a string
2040 call assert_equal(-1, g:Xsetlist([], ' ', {'items' : 'Test'}))
2041
Bram Moolenaar6a8958d2017-06-22 21:33:20 +02002042 " Save and restore the quickfix stack
2043 call g:Xsetlist([], 'f')
2044 call assert_equal(0, g:Xgetlist({'nr':'$'}).nr)
2045 Xexpr "File1:10:Line1"
2046 Xexpr "File2:20:Line2"
2047 Xexpr "File3:30:Line3"
2048 let last_qf = g:Xgetlist({'nr':'$'}).nr
2049 call assert_equal(3, last_qf)
2050 let qstack = []
2051 for i in range(1, last_qf)
2052 let qstack = add(qstack, g:Xgetlist({'nr':i, 'all':1}))
2053 endfor
2054 call g:Xsetlist([], 'f')
2055 for i in range(len(qstack))
2056 call g:Xsetlist([], ' ', qstack[i])
2057 endfor
2058 call assert_equal(3, g:Xgetlist({'nr':'$'}).nr)
2059 call assert_equal(10, g:Xgetlist({'nr':1, 'items':1}).items[0].lnum)
2060 call assert_equal(20, g:Xgetlist({'nr':2, 'items':1}).items[0].lnum)
2061 call assert_equal(30, g:Xgetlist({'nr':3, 'items':1}).items[0].lnum)
2062 call g:Xsetlist([], 'f')
2063
2064 " Swap two quickfix lists
2065 Xexpr "File1:10:Line10"
2066 Xexpr "File2:20:Line20"
2067 Xexpr "File3:30:Line30"
2068 call g:Xsetlist([], 'r', {'nr':1,'title':'Colors','context':['Colors']})
2069 call g:Xsetlist([], 'r', {'nr':2,'title':'Fruits','context':['Fruits']})
2070 let l1=g:Xgetlist({'nr':1,'all':1})
2071 let l2=g:Xgetlist({'nr':2,'all':1})
Bram Moolenaara539f4f2017-08-30 20:33:55 +02002072 let save_id = l1.id
2073 let l1.id=l2.id
2074 let l2.id=save_id
Bram Moolenaar6a8958d2017-06-22 21:33:20 +02002075 call g:Xsetlist([], 'r', l1)
2076 call g:Xsetlist([], 'r', l2)
2077 let newl1=g:Xgetlist({'nr':1,'all':1})
2078 let newl2=g:Xgetlist({'nr':2,'all':1})
Bram Moolenaarb4d5fba2017-09-11 19:31:28 +02002079 call assert_equal('Fruits', newl1.title)
Bram Moolenaar6a8958d2017-06-22 21:33:20 +02002080 call assert_equal(['Fruits'], newl1.context)
2081 call assert_equal('Line20', newl1.items[0].text)
Bram Moolenaarb4d5fba2017-09-11 19:31:28 +02002082 call assert_equal('Colors', newl2.title)
Bram Moolenaar6a8958d2017-06-22 21:33:20 +02002083 call assert_equal(['Colors'], newl2.context)
2084 call assert_equal('Line10', newl2.items[0].text)
2085 call g:Xsetlist([], 'f')
Bram Moolenaaree85df32017-03-19 14:19:50 +01002086endfunc
Bram Moolenaard823fa92016-08-12 16:29:27 +02002087
Bram Moolenaar2b946c92016-11-12 18:14:44 +01002088func Test_qf_property()
Bram Moolenaard823fa92016-08-12 16:29:27 +02002089 call Xproperty_tests('c')
2090 call Xproperty_tests('l')
Bram Moolenaaree85df32017-03-19 14:19:50 +01002091endfunc
Bram Moolenaar04c4ce62016-09-01 15:45:58 +02002092
Bram Moolenaar5b69c222019-01-11 14:50:06 +01002093" Test for setting the current index in the location/quickfix list
2094func Xtest_setqfidx(cchar)
2095 call s:setup_commands(a:cchar)
2096
2097 Xgetexpr "F1:10:1:Line1\nF2:20:2:Line2\nF3:30:3:Line3"
2098 Xgetexpr "F4:10:1:Line1\nF5:20:2:Line2\nF6:30:3:Line3"
2099 Xgetexpr "F7:10:1:Line1\nF8:20:2:Line2\nF9:30:3:Line3"
2100
2101 call g:Xsetlist([], 'a', {'nr' : 3, 'idx' : 2})
2102 call g:Xsetlist([], 'a', {'nr' : 2, 'idx' : 2})
2103 call g:Xsetlist([], 'a', {'nr' : 1, 'idx' : 3})
2104 Xolder 2
2105 Xopen
2106 call assert_equal(3, line('.'))
2107 Xnewer
2108 call assert_equal(2, line('.'))
2109 Xnewer
2110 call assert_equal(2, line('.'))
2111 " Update the current index with the quickfix window open
2112 wincmd w
2113 call g:Xsetlist([], 'a', {'nr' : 3, 'idx' : 3})
2114 Xopen
2115 call assert_equal(3, line('.'))
2116 Xclose
2117
2118 " Set the current index to the last entry
2119 call g:Xsetlist([], 'a', {'nr' : 1, 'idx' : '$'})
2120 call assert_equal(3, g:Xgetlist({'nr' : 1, 'idx' : 0}).idx)
2121 " A large value should set the index to the last index
2122 call g:Xsetlist([], 'a', {'nr' : 1, 'idx' : 1})
2123 call g:Xsetlist([], 'a', {'nr' : 1, 'idx' : 999})
2124 call assert_equal(3, g:Xgetlist({'nr' : 1, 'idx' : 0}).idx)
2125 " Invalid index values
2126 call g:Xsetlist([], 'a', {'nr' : 1, 'idx' : -1})
2127 call assert_equal(3, g:Xgetlist({'nr' : 1, 'idx' : 0}).idx)
2128 call g:Xsetlist([], 'a', {'nr' : 1, 'idx' : 0})
2129 call assert_equal(3, g:Xgetlist({'nr' : 1, 'idx' : 0}).idx)
2130 call g:Xsetlist([], 'a', {'nr' : 1, 'idx' : 'xx'})
2131 call assert_equal(3, g:Xgetlist({'nr' : 1, 'idx' : 0}).idx)
2132 call assert_fails("call g:Xsetlist([], 'a', {'nr':1, 'idx':[]})", 'E745:')
2133
2134 call g:Xsetlist([], 'f')
2135 new | only
2136endfunc
2137
2138func Test_setqfidx()
2139 call Xtest_setqfidx('c')
2140 call Xtest_setqfidx('l')
2141endfunc
2142
Bram Moolenaar04c4ce62016-09-01 15:45:58 +02002143" Tests for the QuickFixCmdPre/QuickFixCmdPost autocommands
Bram Moolenaar2b946c92016-11-12 18:14:44 +01002144func QfAutoCmdHandler(loc, cmd)
Bram Moolenaar04c4ce62016-09-01 15:45:58 +02002145 call add(g:acmds, a:loc . a:cmd)
Bram Moolenaar2b946c92016-11-12 18:14:44 +01002146endfunc
Bram Moolenaar04c4ce62016-09-01 15:45:58 +02002147
Bram Moolenaar2b946c92016-11-12 18:14:44 +01002148func Test_Autocmd()
Bram Moolenaar04c4ce62016-09-01 15:45:58 +02002149 autocmd QuickFixCmdPre * call QfAutoCmdHandler('pre', expand('<amatch>'))
2150 autocmd QuickFixCmdPost * call QfAutoCmdHandler('post', expand('<amatch>'))
2151
2152 let g:acmds = []
2153 cexpr "F1:10:Line 10"
2154 caddexpr "F1:20:Line 20"
2155 cgetexpr "F1:30:Line 30"
Bram Moolenaar1ed22762017-11-28 18:03:44 +01002156 cexpr ""
2157 caddexpr ""
2158 cgetexpr ""
2159 silent! cexpr non_existing_func()
2160 silent! caddexpr non_existing_func()
2161 silent! cgetexpr non_existing_func()
Bram Moolenaar04c4ce62016-09-01 15:45:58 +02002162 let l = ['precexpr',
2163 \ 'postcexpr',
2164 \ 'precaddexpr',
2165 \ 'postcaddexpr',
2166 \ 'precgetexpr',
2167 \ 'postcgetexpr',
Bram Moolenaar1ed22762017-11-28 18:03:44 +01002168 \ 'precexpr',
2169 \ 'postcexpr',
2170 \ 'precaddexpr',
2171 \ 'postcaddexpr',
2172 \ 'precgetexpr',
2173 \ 'postcgetexpr',
2174 \ 'precexpr',
2175 \ 'precaddexpr',
2176 \ 'precgetexpr']
2177 call assert_equal(l, g:acmds)
2178
2179 let g:acmds = []
2180 enew! | call append(0, "F2:10:Line 10")
2181 cbuffer!
2182 enew! | call append(0, "F2:20:Line 20")
2183 cgetbuffer
2184 enew! | call append(0, "F2:30:Line 30")
2185 caddbuffer
2186 new
2187 let bnum = bufnr('%')
2188 bunload
2189 exe 'silent! cbuffer! ' . bnum
2190 exe 'silent! cgetbuffer ' . bnum
2191 exe 'silent! caddbuffer ' . bnum
2192 enew!
2193 let l = ['precbuffer',
Bram Moolenaar04c4ce62016-09-01 15:45:58 +02002194 \ 'postcbuffer',
2195 \ 'precgetbuffer',
2196 \ 'postcgetbuffer',
2197 \ 'precaddbuffer',
Bram Moolenaar1ed22762017-11-28 18:03:44 +01002198 \ 'postcaddbuffer',
2199 \ 'precbuffer',
2200 \ 'precgetbuffer',
2201 \ 'precaddbuffer']
Bram Moolenaar04c4ce62016-09-01 15:45:58 +02002202 call assert_equal(l, g:acmds)
Bram Moolenaar1ed22762017-11-28 18:03:44 +01002203
2204 call writefile(['Xtest:1:Line1'], 'Xtest')
2205 call writefile([], 'Xempty')
2206 let g:acmds = []
2207 cfile Xtest
2208 caddfile Xtest
2209 cgetfile Xtest
2210 cfile Xempty
2211 caddfile Xempty
2212 cgetfile Xempty
2213 silent! cfile do_not_exist
2214 silent! caddfile do_not_exist
2215 silent! cgetfile do_not_exist
2216 let l = ['precfile',
2217 \ 'postcfile',
2218 \ 'precaddfile',
2219 \ 'postcaddfile',
2220 \ 'precgetfile',
2221 \ 'postcgetfile',
2222 \ 'precfile',
2223 \ 'postcfile',
2224 \ 'precaddfile',
2225 \ 'postcaddfile',
2226 \ 'precgetfile',
2227 \ 'postcgetfile',
2228 \ 'precfile',
2229 \ 'postcfile',
2230 \ 'precaddfile',
2231 \ 'postcaddfile',
2232 \ 'precgetfile',
2233 \ 'postcgetfile']
2234 call assert_equal(l, g:acmds)
2235
2236 let g:acmds = []
2237 helpgrep quickfix
2238 silent! helpgrep non_existing_help_topic
2239 vimgrep test Xtest
2240 vimgrepadd test Xtest
2241 silent! vimgrep non_existing_test Xtest
2242 silent! vimgrepadd non_existing_test Xtest
2243 set makeprg=
2244 silent! make
2245 set makeprg&
2246 let l = ['prehelpgrep',
2247 \ 'posthelpgrep',
2248 \ 'prehelpgrep',
2249 \ 'posthelpgrep',
2250 \ 'previmgrep',
2251 \ 'postvimgrep',
2252 \ 'previmgrepadd',
2253 \ 'postvimgrepadd',
2254 \ 'previmgrep',
2255 \ 'postvimgrep',
2256 \ 'previmgrepadd',
2257 \ 'postvimgrepadd',
2258 \ 'premake',
2259 \ 'postmake']
2260 call assert_equal(l, g:acmds)
2261
2262 if has('unix')
2263 " Run this test only on Unix-like systems. The grepprg may not be set on
2264 " non-Unix systems.
2265 " The following lines are used for the grep test. Don't remove.
2266 " Grep_Autocmd_Text: Match 1
2267 " GrepAdd_Autocmd_Text: Match 2
2268 let g:acmds = []
2269 silent grep Grep_Autocmd_Text test_quickfix.vim
2270 silent grepadd GrepAdd_Autocmd_Text test_quickfix.vim
2271 silent grep abc123def Xtest
2272 silent grepadd abc123def Xtest
2273 let l = ['pregrep',
2274 \ 'postgrep',
2275 \ 'pregrepadd',
2276 \ 'postgrepadd',
2277 \ 'pregrep',
2278 \ 'postgrep',
2279 \ 'pregrepadd',
2280 \ 'postgrepadd']
2281 call assert_equal(l, g:acmds)
2282 endif
2283
2284 call delete('Xtest')
2285 call delete('Xempty')
Bram Moolenaarb254af32017-12-18 19:48:58 +01002286 au! QuickFixCmdPre
2287 au! QuickFixCmdPost
Bram Moolenaar2b946c92016-11-12 18:14:44 +01002288endfunc
Bram Moolenaar21662be2016-11-06 14:46:44 +01002289
Bram Moolenaar2b946c92016-11-12 18:14:44 +01002290func Test_Autocmd_Exception()
Bram Moolenaar21662be2016-11-06 14:46:44 +01002291 set efm=%m
2292 lgetexpr '?'
2293
2294 try
2295 call DoesNotExit()
2296 catch
2297 lgetexpr '1'
2298 finally
2299 lgetexpr '1'
2300 endtry
2301
2302 call assert_equal('1', getloclist(0)[0].text)
2303
2304 set efm&vim
Bram Moolenaar2b946c92016-11-12 18:14:44 +01002305endfunc
Bram Moolenaar63bed3d2016-11-12 15:36:54 +01002306
Bram Moolenaar2b946c92016-11-12 18:14:44 +01002307func Test_caddbuffer_wrong()
2308 " This used to cause a memory access in freed memory.
Bram Moolenaar63bed3d2016-11-12 15:36:54 +01002309 let save_efm = &efm
2310 set efm=%EEEE%m,%WWWW,%+CCCC%>%#,%GGGG%.#
2311 cgetexpr ['WWWW', 'EEEE', 'CCCC']
2312 let &efm = save_efm
Bram Moolenaar2b946c92016-11-12 18:14:44 +01002313 caddbuffer
Bram Moolenaar63bed3d2016-11-12 15:36:54 +01002314 bwipe!
2315endfunc
Bram Moolenaar2b946c92016-11-12 18:14:44 +01002316
2317func Test_caddexpr_wrong()
2318 " This used to cause a memory access in freed memory.
2319 cbuffer
2320 cbuffer
2321 copen
2322 let save_efm = &efm
2323 set efm=%
2324 call assert_fails('caddexpr ""', 'E376:')
2325 let &efm = save_efm
2326endfunc
Bram Moolenaar7618e002016-11-13 15:09:26 +01002327
2328func Test_dirstack_cleanup()
2329 " This used to cause a memory access in freed memory.
2330 let save_efm = &efm
2331 lexpr '0'
2332 lopen
2333 fun X(c)
2334 let save_efm=&efm
2335 set efm=%D%f
2336 if a:c == 'c'
2337 caddexpr '::'
2338 else
2339 laddexpr ':0:0'
2340 endif
2341 let &efm=save_efm
2342 endfun
2343 call X('c')
2344 call X('l')
2345 call setqflist([], 'r')
2346 caddbuffer
2347 let &efm = save_efm
2348endfunc
Bram Moolenaar391b1dd2017-03-04 13:47:11 +01002349
2350" Tests for jumping to entries from the location list window and quickfix
2351" window
2352func Test_cwindow_jump()
2353 set efm=%f%%%l%%%m
2354 lgetexpr ["F1%10%Line 10", "F2%20%Line 20", "F3%30%Line 30"]
2355 lopen | only
2356 lfirst
2357 call assert_true(winnr('$') == 2)
2358 call assert_true(winnr() == 1)
2359 " Location list for the new window should be set
2360 call assert_true(getloclist(0)[2].text == 'Line 30')
2361
2362 " Open a scratch buffer
2363 " Open a new window and create a location list
2364 " Open the location list window and close the other window
2365 " Jump to an entry.
Bram Moolenaareeb1b9c2019-02-10 22:59:04 +01002366 " Should create a new window and jump to the entry. The scratch buffer
Bram Moolenaar391b1dd2017-03-04 13:47:11 +01002367 " should not be used.
2368 enew | only
2369 set buftype=nofile
2370 below new
2371 lgetexpr ["F1%10%Line 10", "F2%20%Line 20", "F3%30%Line 30"]
2372 lopen
2373 2wincmd c
2374 lnext
2375 call assert_true(winnr('$') == 3)
2376 call assert_true(winnr() == 2)
2377
2378 " Open two windows with two different location lists
2379 " Open the location list window and close the previous window
2380 " Jump to an entry in the location list window
2381 " Should open the file in the first window and not set the location list.
2382 enew | only
2383 lgetexpr ["F1%5%Line 5"]
2384 below new
2385 lgetexpr ["F1%10%Line 10", "F2%20%Line 20", "F3%30%Line 30"]
2386 lopen
2387 2wincmd c
2388 lnext
2389 call assert_true(winnr() == 1)
2390 call assert_true(getloclist(0)[0].text == 'Line 5')
2391
2392 enew | only
2393 cgetexpr ["F1%10%Line 10", "F2%20%Line 20", "F3%30%Line 30"]
2394 copen
2395 cnext
2396 call assert_true(winnr('$') == 2)
2397 call assert_true(winnr() == 1)
2398
2399 enew | only
2400 set efm&vim
2401endfunc
Bram Moolenaaree85df32017-03-19 14:19:50 +01002402
2403func XvimgrepTests(cchar)
2404 call s:setup_commands(a:cchar)
2405
2406 call writefile(['Editor:VIM vim',
2407 \ 'Editor:Emacs EmAcS',
2408 \ 'Editor:Notepad NOTEPAD'], 'Xtestfile1')
2409 call writefile(['Linux', 'MacOS', 'MS-Windows'], 'Xtestfile2')
2410
2411 " Error cases
2412 call assert_fails('Xvimgrep /abc *', 'E682:')
2413
2414 let @/=''
2415 call assert_fails('Xvimgrep // *', 'E35:')
2416
2417 call assert_fails('Xvimgrep abc', 'E683:')
2418 call assert_fails('Xvimgrep a1b2c3 Xtestfile1', 'E480:')
2419 call assert_fails('Xvimgrep pat Xa1b2c3', 'E480:')
2420
2421 Xexpr ""
2422 Xvimgrepadd Notepad Xtestfile1
2423 Xvimgrepadd MacOS Xtestfile2
2424 let l = g:Xgetlist()
2425 call assert_equal(2, len(l))
2426 call assert_equal('Editor:Notepad NOTEPAD', l[0].text)
2427
2428 Xvimgrep #\cvim#g Xtestfile?
2429 let l = g:Xgetlist()
2430 call assert_equal(2, len(l))
2431 call assert_equal(8, l[0].col)
2432 call assert_equal(12, l[1].col)
2433
2434 1Xvimgrep ?Editor? Xtestfile*
2435 let l = g:Xgetlist()
2436 call assert_equal(1, len(l))
2437 call assert_equal('Editor:VIM vim', l[0].text)
2438
2439 edit +3 Xtestfile2
2440 Xvimgrep +\cemacs+j Xtestfile1
2441 let l = g:Xgetlist()
2442 call assert_equal('Xtestfile2', bufname(''))
2443 call assert_equal('Editor:Emacs EmAcS', l[0].text)
2444
Bram Moolenaar2225ebb2018-04-24 15:48:11 +02002445 " Test for unloading a buffer after vimgrep searched the buffer
2446 %bwipe
2447 Xvimgrep /Editor/j Xtestfile*
2448 call assert_equal(0, getbufinfo('Xtestfile1')[0].loaded)
2449 call assert_equal([], getbufinfo('Xtestfile2'))
2450
Bram Moolenaaree85df32017-03-19 14:19:50 +01002451 call delete('Xtestfile1')
2452 call delete('Xtestfile2')
2453endfunc
2454
2455" Tests for the :vimgrep command
2456func Test_vimgrep()
2457 call XvimgrepTests('c')
2458 call XvimgrepTests('l')
2459endfunc
Bram Moolenaar69f40be2017-04-02 15:15:49 +02002460
Bram Moolenaar1c299432018-10-28 14:36:09 +01002461" Test for incsearch highlighting of the :vimgrep pattern
2462" This test used to cause "E315: ml_get: invalid lnum" errors.
2463func Test_vimgrep_incsearch()
2464 enew
2465 set incsearch
2466 call test_override("char_avail", 1)
2467
2468 call feedkeys(":2vimgrep assert test_quickfix.vim test_cdo.vim\<CR>", "ntx")
2469 let l = getqflist()
2470 call assert_equal(2, len(l))
2471
2472 call test_override("ALL", 0)
2473 set noincsearch
2474endfunc
2475
Bram Moolenaar69f40be2017-04-02 15:15:49 +02002476func XfreeTests(cchar)
2477 call s:setup_commands(a:cchar)
2478
2479 enew | only
2480
2481 " Deleting the quickfix stack should work even When the current list is
2482 " somewhere in the middle of the stack
2483 Xexpr ['Xfile1:10:10:Line 10', 'Xfile1:15:15:Line 15']
2484 Xexpr ['Xfile2:20:20:Line 20', 'Xfile2:25:25:Line 25']
2485 Xexpr ['Xfile3:30:30:Line 30', 'Xfile3:35:35:Line 35']
2486 Xolder
2487 call g:Xsetlist([], 'f')
2488 call assert_equal(0, len(g:Xgetlist()))
2489
2490 " After deleting the stack, adding a new list should create a stack with a
2491 " single list.
2492 Xexpr ['Xfile1:10:10:Line 10', 'Xfile1:15:15:Line 15']
2493 call assert_equal(1, g:Xgetlist({'all':1}).nr)
2494
2495 " Deleting the stack from a quickfix window should update/clear the
2496 " quickfix/location list window.
2497 Xexpr ['Xfile1:10:10:Line 10', 'Xfile1:15:15:Line 15']
2498 Xexpr ['Xfile2:20:20:Line 20', 'Xfile2:25:25:Line 25']
2499 Xexpr ['Xfile3:30:30:Line 30', 'Xfile3:35:35:Line 35']
2500 Xolder
2501 Xwindow
2502 call g:Xsetlist([], 'f')
2503 call assert_equal(2, winnr('$'))
2504 call assert_equal(1, line('$'))
2505 Xclose
2506
2507 " Deleting the stack from a non-quickfix window should update/clear the
2508 " quickfix/location list window.
2509 Xexpr ['Xfile1:10:10:Line 10', 'Xfile1:15:15:Line 15']
2510 Xexpr ['Xfile2:20:20:Line 20', 'Xfile2:25:25:Line 25']
2511 Xexpr ['Xfile3:30:30:Line 30', 'Xfile3:35:35:Line 35']
2512 Xolder
2513 Xwindow
2514 wincmd p
2515 call g:Xsetlist([], 'f')
2516 call assert_equal(0, len(g:Xgetlist()))
2517 wincmd p
2518 call assert_equal(2, winnr('$'))
2519 call assert_equal(1, line('$'))
2520
2521 " After deleting the location list stack, if the location list window is
2522 " opened, then a new location list should be created. So opening the
2523 " location list window again should not create a new window.
2524 if a:cchar == 'l'
2525 lexpr ['Xfile1:10:10:Line 10', 'Xfile1:15:15:Line 15']
2526 wincmd p
2527 lopen
2528 call assert_equal(2, winnr('$'))
2529 endif
2530 Xclose
2531endfunc
2532
Bram Moolenaar74240d32017-12-10 15:26:15 +01002533" Tests for the quickfix free functionality
Bram Moolenaar69f40be2017-04-02 15:15:49 +02002534func Test_qf_free()
2535 call XfreeTests('c')
2536 call XfreeTests('l')
2537endfunc
Bram Moolenaar6e62da32017-05-28 08:16:25 +02002538
2539" Test for buffer overflow when parsing lines and adding new entries to
2540" the quickfix list.
2541func Test_bufoverflow()
2542 set efm=%f:%l:%m
2543 cgetexpr ['File1:100:' . repeat('x', 1025)]
2544
2545 set efm=%+GCompiler:\ %.%#,%f:%l:%m
2546 cgetexpr ['Compiler: ' . repeat('a', 1015), 'File1:10:Hello World']
2547
2548 set efm=%DEntering\ directory\ %f,%f:%l:%m
2549 cgetexpr ['Entering directory ' . repeat('a', 1006),
2550 \ 'File1:10:Hello World']
2551 set efm&vim
2552endfunc
2553
Bram Moolenaar875feea2017-06-11 16:07:51 +02002554" Tests for getting the quickfix stack size
2555func XsizeTests(cchar)
2556 call s:setup_commands(a:cchar)
2557
2558 call g:Xsetlist([], 'f')
2559 call assert_equal(0, g:Xgetlist({'nr':'$'}).nr)
Bram Moolenaara6d48492017-12-12 22:45:31 +01002560 call assert_equal('', g:Xgetlist({'nr':'$', 'all':1}).title)
2561 call assert_equal(0, g:Xgetlist({'nr':0}).nr)
Bram Moolenaar875feea2017-06-11 16:07:51 +02002562
2563 Xexpr "File1:10:Line1"
2564 Xexpr "File2:20:Line2"
2565 Xexpr "File3:30:Line3"
2566 Xolder | Xolder
2567 call assert_equal(3, g:Xgetlist({'nr':'$'}).nr)
2568 call g:Xsetlist([], 'f')
2569
2570 Xexpr "File1:10:Line1"
2571 Xexpr "File2:20:Line2"
2572 Xexpr "File3:30:Line3"
2573 Xolder | Xolder
2574 call g:Xsetlist([], 'a', {'nr':'$', 'title':'Compiler'})
2575 call assert_equal('Compiler', g:Xgetlist({'nr':3, 'all':1}).title)
2576endfunc
2577
2578func Test_Qf_Size()
2579 call XsizeTests('c')
2580 call XsizeTests('l')
2581endfunc
Bram Moolenaar18141832017-06-25 21:17:25 +02002582
Bram Moolenaar9c4feff2017-06-28 22:26:54 +02002583func Test_cclose_from_copen()
2584 augroup QF_Test
2585 au!
2586 au FileType qf :call assert_fails(':cclose', 'E788')
2587 augroup END
2588 copen
2589 augroup QF_Test
2590 au!
2591 augroup END
2592 augroup! QF_Test
2593endfunc
2594
Bram Moolenaar18141832017-06-25 21:17:25 +02002595func Test_cclose_in_autocmd()
2596 " Problem is only triggered if "starting" is zero, so that the OptionsSet
2597 " event will be triggered.
2598 call test_override('starting', 1)
2599 augroup QF_Test
2600 au!
2601 au FileType qf :call assert_fails(':cclose', 'E788')
2602 augroup END
2603 copen
2604 augroup QF_Test
2605 au!
2606 augroup END
2607 augroup! QF_Test
2608 call test_override('starting', 0)
2609endfunc
Bram Moolenaar9c4feff2017-06-28 22:26:54 +02002610
Bram Moolenaar379fb762018-08-30 15:58:28 +02002611" Check that ":file" without an argument is possible even when "curbuf_lock"
2612" is set.
2613func Test_file_from_copen()
2614 " Works without argument.
2615 augroup QF_Test
2616 au!
2617 au FileType qf file
2618 augroup END
2619 copen
2620
2621 augroup QF_Test
2622 au!
2623 augroup END
2624 cclose
2625
2626 " Fails with argument.
2627 augroup QF_Test
2628 au!
2629 au FileType qf call assert_fails(':file foo', 'E788')
2630 augroup END
2631 copen
2632 augroup QF_Test
2633 au!
2634 augroup END
2635 cclose
2636
2637 augroup! QF_Test
2638endfunction
2639
Bram Moolenaar9c4feff2017-06-28 22:26:54 +02002640func Test_resize_from_copen()
2641 augroup QF_Test
2642 au!
2643 au FileType qf resize 5
2644 augroup END
2645 try
2646 " This should succeed without any exception. No other buffers are
2647 " involved in the autocmd.
2648 copen
2649 finally
2650 augroup QF_Test
2651 au!
2652 augroup END
2653 augroup! QF_Test
2654 endtry
2655endfunc
Bram Moolenaara8788f42017-07-19 17:06:20 +02002656
2657" Tests for the quickfix buffer b:changedtick variable
2658func Xchangedtick_tests(cchar)
2659 call s:setup_commands(a:cchar)
2660
2661 new | only
2662
2663 Xexpr "" | Xexpr "" | Xexpr ""
2664
2665 Xopen
2666 Xolder
2667 Xolder
2668 Xaddexpr "F1:10:Line10"
2669 Xaddexpr "F2:20:Line20"
2670 call g:Xsetlist([{"filename":"F3", "lnum":30, "text":"Line30"}], 'a')
2671 call g:Xsetlist([], 'f')
2672 call assert_equal(8, getbufvar('%', 'changedtick'))
2673 Xclose
2674endfunc
2675
2676func Test_changedtick()
Bram Moolenaarae338332017-08-11 20:25:26 +02002677 call Xchangedtick_tests('c')
2678 call Xchangedtick_tests('l')
2679endfunc
2680
2681" Tests for parsing an expression using setqflist()
2682func Xsetexpr_tests(cchar)
2683 call s:setup_commands(a:cchar)
2684
2685 let t = ["File1:10:Line10", "File1:20:Line20"]
Bram Moolenaar2c809b72017-09-01 18:34:02 +02002686 call g:Xsetlist([], ' ', {'lines' : t})
2687 call g:Xsetlist([], 'a', {'lines' : ["File1:30:Line30"]})
Bram Moolenaarae338332017-08-11 20:25:26 +02002688
2689 let l = g:Xgetlist()
2690 call assert_equal(3, len(l))
2691 call assert_equal(20, l[1].lnum)
2692 call assert_equal('Line30', l[2].text)
Bram Moolenaar2c809b72017-09-01 18:34:02 +02002693 call g:Xsetlist([], 'r', {'lines' : ["File2:5:Line5"]})
Bram Moolenaarae338332017-08-11 20:25:26 +02002694 let l = g:Xgetlist()
2695 call assert_equal(1, len(l))
2696 call assert_equal('Line5', l[0].text)
Bram Moolenaar2c809b72017-09-01 18:34:02 +02002697 call assert_equal(-1, g:Xsetlist([], 'a', {'lines' : 10}))
2698 call assert_equal(-1, g:Xsetlist([], 'a', {'lines' : "F1:10:L10"}))
Bram Moolenaarae338332017-08-11 20:25:26 +02002699
2700 call g:Xsetlist([], 'f')
2701 " Add entries to multiple lists
Bram Moolenaar2c809b72017-09-01 18:34:02 +02002702 call g:Xsetlist([], 'a', {'nr' : 1, 'lines' : ["File1:10:Line10"]})
2703 call g:Xsetlist([], 'a', {'nr' : 2, 'lines' : ["File2:20:Line20"]})
2704 call g:Xsetlist([], 'a', {'nr' : 1, 'lines' : ["File1:15:Line15"]})
2705 call g:Xsetlist([], 'a', {'nr' : 2, 'lines' : ["File2:25:Line25"]})
Bram Moolenaarae338332017-08-11 20:25:26 +02002706 call assert_equal('Line15', g:Xgetlist({'nr':1, 'items':1}).items[1].text)
2707 call assert_equal('Line25', g:Xgetlist({'nr':2, 'items':1}).items[1].text)
Bram Moolenaar36538222017-09-02 19:51:44 +02002708
2709 " Adding entries using a custom efm
2710 set efm&
2711 call g:Xsetlist([], ' ', {'efm' : '%f#%l#%m',
2712 \ 'lines' : ["F1#10#L10", "F2#20#L20"]})
2713 call assert_equal(20, g:Xgetlist({'items':1}).items[1].lnum)
2714 call g:Xsetlist([], 'a', {'efm' : '%f#%l#%m', 'lines' : ["F3:30:L30"]})
2715 call assert_equal('F3:30:L30', g:Xgetlist({'items':1}).items[2].text)
2716 call assert_equal(20, g:Xgetlist({'items':1}).items[1].lnum)
2717 call assert_equal(-1, g:Xsetlist([], 'a', {'efm' : [],
2718 \ 'lines' : ['F1:10:L10']}))
Bram Moolenaarae338332017-08-11 20:25:26 +02002719endfunc
2720
2721func Test_setexpr()
2722 call Xsetexpr_tests('c')
2723 call Xsetexpr_tests('l')
2724endfunc
2725
2726" Tests for per quickfix/location list directory stack
2727func Xmultidirstack_tests(cchar)
2728 call s:setup_commands(a:cchar)
2729
2730 call g:Xsetlist([], 'f')
2731 Xexpr "" | Xexpr ""
2732
Bram Moolenaar2c809b72017-09-01 18:34:02 +02002733 call g:Xsetlist([], 'a', {'nr' : 1, 'lines' : ["Entering dir 'Xone/a'"]})
2734 call g:Xsetlist([], 'a', {'nr' : 2, 'lines' : ["Entering dir 'Xtwo/a'"]})
2735 call g:Xsetlist([], 'a', {'nr' : 1, 'lines' : ["one.txt:3:one one one"]})
2736 call g:Xsetlist([], 'a', {'nr' : 2, 'lines' : ["two.txt:5:two two two"]})
Bram Moolenaarae338332017-08-11 20:25:26 +02002737
2738 let l1 = g:Xgetlist({'nr':1, 'items':1})
2739 let l2 = g:Xgetlist({'nr':2, 'items':1})
2740 call assert_equal('Xone/a/one.txt', bufname(l1.items[1].bufnr))
2741 call assert_equal(3, l1.items[1].lnum)
2742 call assert_equal('Xtwo/a/two.txt', bufname(l2.items[1].bufnr))
2743 call assert_equal(5, l2.items[1].lnum)
2744endfunc
2745
2746func Test_multidirstack()
2747 call mkdir('Xone/a', 'p')
2748 call mkdir('Xtwo/a', 'p')
2749 let lines = ['1', '2', 'one one one', '4', 'two two two', '6', '7']
2750 call writefile(lines, 'Xone/a/one.txt')
2751 call writefile(lines, 'Xtwo/a/two.txt')
2752 let save_efm = &efm
2753 set efm=%DEntering\ dir\ '%f',%f:%l:%m,%XLeaving\ dir\ '%f'
2754
2755 call Xmultidirstack_tests('c')
2756 call Xmultidirstack_tests('l')
2757
2758 let &efm = save_efm
2759 call delete('Xone', 'rf')
2760 call delete('Xtwo', 'rf')
2761endfunc
2762
2763" Tests for per quickfix/location list file stack
2764func Xmultifilestack_tests(cchar)
2765 call s:setup_commands(a:cchar)
2766
2767 call g:Xsetlist([], 'f')
2768 Xexpr "" | Xexpr ""
2769
Bram Moolenaar2c809b72017-09-01 18:34:02 +02002770 call g:Xsetlist([], 'a', {'nr' : 1, 'lines' : ["[one.txt]"]})
2771 call g:Xsetlist([], 'a', {'nr' : 2, 'lines' : ["[two.txt]"]})
2772 call g:Xsetlist([], 'a', {'nr' : 1, 'lines' : ["(3,5) one one one"]})
2773 call g:Xsetlist([], 'a', {'nr' : 2, 'lines' : ["(5,9) two two two"]})
Bram Moolenaarae338332017-08-11 20:25:26 +02002774
2775 let l1 = g:Xgetlist({'nr':1, 'items':1})
2776 let l2 = g:Xgetlist({'nr':2, 'items':1})
2777 call assert_equal('one.txt', bufname(l1.items[1].bufnr))
2778 call assert_equal(3, l1.items[1].lnum)
2779 call assert_equal('two.txt', bufname(l2.items[1].bufnr))
2780 call assert_equal(5, l2.items[1].lnum)
Bram Moolenaare333e792018-04-08 13:27:39 +02002781
2782 " Test for start of a new error line in the same line where a previous
2783 " error line ends with a file stack.
2784 let efm_val = 'Error\ l%l\ in\ %f,'
2785 let efm_val .= '%-P%>(%f%r,Error\ l%l\ in\ %m,%-Q)%r'
2786 let l = g:Xgetlist({'lines' : [
2787 \ '(one.txt',
2788 \ 'Error l4 in one.txt',
2789 \ ') (two.txt',
2790 \ 'Error l6 in two.txt',
2791 \ ')',
2792 \ 'Error l8 in one.txt'
2793 \ ], 'efm' : efm_val})
2794 call assert_equal(3, len(l.items))
2795 call assert_equal('one.txt', bufname(l.items[0].bufnr))
2796 call assert_equal(4, l.items[0].lnum)
2797 call assert_equal('one.txt', l.items[0].text)
2798 call assert_equal('two.txt', bufname(l.items[1].bufnr))
2799 call assert_equal(6, l.items[1].lnum)
2800 call assert_equal('two.txt', l.items[1].text)
2801 call assert_equal('one.txt', bufname(l.items[2].bufnr))
2802 call assert_equal(8, l.items[2].lnum)
2803 call assert_equal('', l.items[2].text)
Bram Moolenaarae338332017-08-11 20:25:26 +02002804endfunc
2805
2806func Test_multifilestack()
2807 let lines = ['1', '2', 'one one one', '4', 'two two two', '6', '7']
2808 call writefile(lines, 'one.txt')
2809 call writefile(lines, 'two.txt')
2810 let save_efm = &efm
2811 set efm=%+P[%f],(%l\\,%c)\ %m,%-Q
2812
2813 call Xmultifilestack_tests('c')
2814 call Xmultifilestack_tests('l')
2815
2816 let &efm = save_efm
2817 call delete('one.txt')
2818 call delete('two.txt')
2819endfunc
2820
2821" Tests for per buffer 'efm' setting
2822func Test_perbuf_efm()
2823 call writefile(["File1-10-Line10"], 'one.txt')
2824 call writefile(["File2#20#Line20"], 'two.txt')
2825 set efm=%f#%l#%m
2826 new | only
2827 new
2828 setlocal efm=%f-%l-%m
2829 cfile one.txt
2830 wincmd w
2831 caddfile two.txt
2832
2833 let l = getqflist()
2834 call assert_equal(10, l[0].lnum)
2835 call assert_equal('Line20', l[1].text)
2836
2837 set efm&
2838 new | only
2839 call delete('one.txt')
2840 call delete('two.txt')
Bram Moolenaara8788f42017-07-19 17:06:20 +02002841endfunc
Bram Moolenaard28cc3f2017-07-27 22:03:50 +02002842
2843" Open multiple help windows using ":lhelpgrep
2844" This test used to crash Vim
2845func Test_Multi_LL_Help()
2846 new | only
2847 lhelpgrep window
2848 lopen
2849 e#
2850 lhelpgrep buffer
2851 call assert_equal(3, winnr('$'))
2852 call assert_true(len(getloclist(1)) != 0)
2853 call assert_true(len(getloclist(2)) != 0)
2854 new | only
2855endfunc
Bram Moolenaar55b69262017-08-13 13:42:01 +02002856
2857" Tests for adding new quickfix lists using setqflist()
2858func XaddQf_tests(cchar)
2859 call s:setup_commands(a:cchar)
2860
2861 " Create a new list using ' ' for action
2862 call g:Xsetlist([], 'f')
2863 call g:Xsetlist([], ' ', {'title' : 'Test1'})
2864 let l = g:Xgetlist({'nr' : '$', 'all' : 1})
2865 call assert_equal(1, l.nr)
2866 call assert_equal('Test1', l.title)
2867
2868 " Create a new list using ' ' for action and '$' for 'nr'
2869 call g:Xsetlist([], 'f')
2870 call g:Xsetlist([], ' ', {'title' : 'Test2', 'nr' : '$'})
2871 let l = g:Xgetlist({'nr' : '$', 'all' : 1})
2872 call assert_equal(1, l.nr)
2873 call assert_equal('Test2', l.title)
2874
2875 " Create a new list using 'a' for action
2876 call g:Xsetlist([], 'f')
2877 call g:Xsetlist([], 'a', {'title' : 'Test3'})
2878 let l = g:Xgetlist({'nr' : '$', 'all' : 1})
2879 call assert_equal(1, l.nr)
2880 call assert_equal('Test3', l.title)
2881
2882 " Create a new list using 'a' for action and '$' for 'nr'
2883 call g:Xsetlist([], 'f')
2884 call g:Xsetlist([], 'a', {'title' : 'Test3', 'nr' : '$'})
2885 call g:Xsetlist([], 'a', {'title' : 'Test4'})
2886 let l = g:Xgetlist({'nr' : '$', 'all' : 1})
2887 call assert_equal(1, l.nr)
2888 call assert_equal('Test4', l.title)
2889
2890 " Adding a quickfix list should remove all the lists following the current
2891 " list.
2892 Xexpr "" | Xexpr "" | Xexpr ""
2893 silent! 10Xolder
2894 call g:Xsetlist([], ' ', {'title' : 'Test5'})
2895 let l = g:Xgetlist({'nr' : '$', 'all' : 1})
2896 call assert_equal(2, l.nr)
2897 call assert_equal('Test5', l.title)
2898
2899 " Add a quickfix list using '$' as the list number.
2900 let lastqf = g:Xgetlist({'nr':'$'}).nr
2901 silent! 99Xolder
2902 call g:Xsetlist([], ' ', {'nr' : '$', 'title' : 'Test6'})
2903 let l = g:Xgetlist({'nr' : '$', 'all' : 1})
2904 call assert_equal(lastqf + 1, l.nr)
2905 call assert_equal('Test6', l.title)
2906
2907 " Add a quickfix list using 'nr' set to one more than the quickfix
2908 " list size.
2909 let lastqf = g:Xgetlist({'nr':'$'}).nr
2910 silent! 99Xolder
2911 call g:Xsetlist([], ' ', {'nr' : lastqf + 1, 'title' : 'Test7'})
2912 let l = g:Xgetlist({'nr' : '$', 'all' : 1})
2913 call assert_equal(lastqf + 1, l.nr)
2914 call assert_equal('Test7', l.title)
2915
2916 " Add a quickfix list to a stack with 10 lists using 'nr' set to '$'
2917 exe repeat('Xexpr "" |', 9) . 'Xexpr ""'
2918 silent! 99Xolder
2919 call g:Xsetlist([], ' ', {'nr' : '$', 'title' : 'Test8'})
2920 let l = g:Xgetlist({'nr' : '$', 'all' : 1})
2921 call assert_equal(10, l.nr)
2922 call assert_equal('Test8', l.title)
2923
2924 " Add a quickfix list using 'nr' set to a value greater than 10
2925 call assert_equal(-1, g:Xsetlist([], ' ', {'nr' : 12, 'title' : 'Test9'}))
2926
2927 " Try adding a quickfix list with 'nr' set to a value greater than the
2928 " quickfix list size but less than 10.
2929 call g:Xsetlist([], 'f')
2930 Xexpr "" | Xexpr "" | Xexpr ""
2931 silent! 99Xolder
2932 call assert_equal(-1, g:Xsetlist([], ' ', {'nr' : 8, 'title' : 'Test10'}))
2933
2934 " Add a quickfix list using 'nr' set to a some string or list
2935 call assert_equal(-1, g:Xsetlist([], ' ', {'nr' : [1,2], 'title' : 'Test11'}))
2936endfunc
2937
2938func Test_add_qf()
2939 call XaddQf_tests('c')
2940 call XaddQf_tests('l')
2941endfunc
Bram Moolenaar7adf06f2017-08-27 15:23:41 +02002942
2943" Test for getting the quickfix list items from some text without modifying
2944" the quickfix stack
Bram Moolenaar2c809b72017-09-01 18:34:02 +02002945func XgetListFromLines(cchar)
Bram Moolenaar7adf06f2017-08-27 15:23:41 +02002946 call s:setup_commands(a:cchar)
2947 call g:Xsetlist([], 'f')
2948
Bram Moolenaar2c809b72017-09-01 18:34:02 +02002949 let l = g:Xgetlist({'lines' : ["File2:20:Line20", "File2:30:Line30"]}).items
Bram Moolenaar7adf06f2017-08-27 15:23:41 +02002950 call assert_equal(2, len(l))
2951 call assert_equal(30, l[1].lnum)
2952
Bram Moolenaar2c809b72017-09-01 18:34:02 +02002953 call assert_equal({}, g:Xgetlist({'lines' : 10}))
2954 call assert_equal({}, g:Xgetlist({'lines' : 'File1:10:Line10'}))
2955 call assert_equal([], g:Xgetlist({'lines' : []}).items)
2956 call assert_equal([], g:Xgetlist({'lines' : [10, 20]}).items)
Bram Moolenaar7adf06f2017-08-27 15:23:41 +02002957
Bram Moolenaar36538222017-09-02 19:51:44 +02002958 " Parse text using a custom efm
2959 set efm&
2960 let l = g:Xgetlist({'lines':['File3#30#Line30'], 'efm' : '%f#%l#%m'}).items
2961 call assert_equal('Line30', l[0].text)
2962 let l = g:Xgetlist({'lines':['File3:30:Line30'], 'efm' : '%f-%l-%m'}).items
2963 call assert_equal('File3:30:Line30', l[0].text)
2964 let l = g:Xgetlist({'lines':['File3:30:Line30'], 'efm' : [1,2]})
2965 call assert_equal({}, l)
2966 call assert_fails("call g:Xgetlist({'lines':['abc'], 'efm':'%2'})", 'E376:')
2967 call assert_fails("call g:Xgetlist({'lines':['abc'], 'efm':''})", 'E378:')
2968
Bram Moolenaar7adf06f2017-08-27 15:23:41 +02002969 " Make sure that the quickfix stack is not modified
2970 call assert_equal(0, g:Xgetlist({'nr' : '$'}).nr)
2971endfunc
2972
Bram Moolenaar2c809b72017-09-01 18:34:02 +02002973func Test_get_list_from_lines()
2974 call XgetListFromLines('c')
2975 call XgetListFromLines('l')
Bram Moolenaar7adf06f2017-08-27 15:23:41 +02002976endfunc
Bram Moolenaara539f4f2017-08-30 20:33:55 +02002977
2978" Tests for the quickfix list id
2979func Xqfid_tests(cchar)
2980 call s:setup_commands(a:cchar)
2981
2982 call g:Xsetlist([], 'f')
Bram Moolenaara6d48492017-12-12 22:45:31 +01002983 call assert_equal(0, g:Xgetlist({'id':0}).id)
Bram Moolenaara539f4f2017-08-30 20:33:55 +02002984 Xexpr ''
2985 let start_id = g:Xgetlist({'id' : 0}).id
2986 Xexpr '' | Xexpr ''
2987 Xolder
2988 call assert_equal(start_id, g:Xgetlist({'id':0, 'nr':1}).id)
2989 call assert_equal(start_id + 1, g:Xgetlist({'id':0, 'nr':0}).id)
2990 call assert_equal(start_id + 2, g:Xgetlist({'id':0, 'nr':'$'}).id)
Bram Moolenaara6d48492017-12-12 22:45:31 +01002991 call assert_equal(0, g:Xgetlist({'id':0, 'nr':99}).id)
Bram Moolenaara539f4f2017-08-30 20:33:55 +02002992 call assert_equal(2, g:Xgetlist({'id':start_id + 1, 'nr':0}).nr)
Bram Moolenaara6d48492017-12-12 22:45:31 +01002993 call assert_equal(0, g:Xgetlist({'id':99, 'nr':0}).id)
2994 call assert_equal(0, g:Xgetlist({'id':"abc", 'nr':0}).id)
Bram Moolenaara539f4f2017-08-30 20:33:55 +02002995
2996 call g:Xsetlist([], 'a', {'id':start_id, 'context':[1,2]})
2997 call assert_equal([1,2], g:Xgetlist({'nr':1, 'context':1}).context)
Bram Moolenaar2c809b72017-09-01 18:34:02 +02002998 call g:Xsetlist([], 'a', {'id':start_id+1, 'lines':['F1:10:L10']})
Bram Moolenaara539f4f2017-08-30 20:33:55 +02002999 call assert_equal('L10', g:Xgetlist({'nr':2, 'items':1}).items[0].text)
3000 call assert_equal(-1, g:Xsetlist([], 'a', {'id':999, 'title':'Vim'}))
3001 call assert_equal(-1, g:Xsetlist([], 'a', {'id':'abc', 'title':'Vim'}))
3002
3003 let qfid = g:Xgetlist({'id':0, 'nr':0})
3004 call g:Xsetlist([], 'f')
Bram Moolenaara6d48492017-12-12 22:45:31 +01003005 call assert_equal(0, g:Xgetlist({'id':qfid, 'nr':0}).id)
Bram Moolenaara539f4f2017-08-30 20:33:55 +02003006endfunc
3007
3008func Test_qf_id()
3009 call Xqfid_tests('c')
3010 call Xqfid_tests('l')
3011endfunc
Bram Moolenaar74240d32017-12-10 15:26:15 +01003012
3013func Xqfjump_tests(cchar)
3014 call s:setup_commands(a:cchar)
3015
3016 call writefile(["Line1\tFoo", "Line2"], 'F1')
3017 call writefile(["Line1\tBar", "Line2"], 'F2')
3018 call writefile(["Line1\tBaz", "Line2"], 'F3')
3019
3020 call g:Xsetlist([], 'f')
3021
3022 " Tests for
3023 " Jumping to a line using a pattern
3024 " Jumping to a column greater than the last column in a line
3025 " Jumping to a line greater than the last line in the file
3026 let l = []
3027 for i in range(1, 7)
3028 call add(l, {})
3029 endfor
3030 let l[0].filename='F1'
3031 let l[0].pattern='Line1'
3032 let l[1].filename='F2'
3033 let l[1].pattern='Line1'
3034 let l[2].filename='F3'
3035 let l[2].pattern='Line1'
3036 let l[3].filename='F3'
3037 let l[3].lnum=1
3038 let l[3].col=9
3039 let l[3].vcol=1
3040 let l[4].filename='F3'
3041 let l[4].lnum=99
3042 let l[5].filename='F3'
3043 let l[5].lnum=1
3044 let l[5].col=99
3045 let l[5].vcol=1
3046 let l[6].filename='F3'
3047 let l[6].pattern='abcxyz'
3048
3049 call g:Xsetlist([], ' ', {'items' : l})
3050 Xopen | only
3051 2Xnext
3052 call assert_equal(3, g:Xgetlist({'idx' : 0}).idx)
3053 call assert_equal('F3', bufname('%'))
3054 Xnext
3055 call assert_equal(7, col('.'))
3056 Xnext
3057 call assert_equal(2, line('.'))
3058 Xnext
3059 call assert_equal(9, col('.'))
3060 2
3061 Xnext
3062 call assert_equal(2, line('.'))
3063
3064 if a:cchar == 'l'
3065 " When jumping to a location list entry in the location list window and
3066 " no usable windows are available, then a new window should be opened.
3067 enew! | new | only
3068 call g:Xsetlist([], 'f')
3069 setlocal buftype=nofile
3070 new
3071 call g:Xsetlist([], ' ', {'lines' : ['F1:1:1:Line1', 'F1:2:2:Line2', 'F2:1:1:Line1', 'F2:2:2:Line2', 'F3:1:1:Line1', 'F3:2:2:Line2']})
3072 Xopen
3073 let winid = win_getid()
3074 wincmd p
3075 close
3076 call win_gotoid(winid)
3077 Xnext
3078 call assert_equal(3, winnr('$'))
3079 call assert_equal(1, winnr())
3080 call assert_equal(2, line('.'))
3081
3082 " When jumping to an entry in the location list window and the window
3083 " associated with the location list is not present and a window containing
3084 " the file is already present, then that window should be used.
3085 close
3086 belowright new
3087 call g:Xsetlist([], 'f')
3088 edit F3
3089 call win_gotoid(winid)
3090 Xlast
3091 call assert_equal(3, winnr())
3092 call assert_equal(6, g:Xgetlist({'size' : 1}).size)
3093 call assert_equal(winid, g:Xgetlist({'winid' : 1}).winid)
3094 endif
3095
3096 " Cleanup
3097 enew!
3098 new | only
3099
3100 call delete('F1')
3101 call delete('F2')
3102 call delete('F3')
3103endfunc
3104
3105func Test_qfjump()
3106 call Xqfjump_tests('c')
3107 call Xqfjump_tests('l')
3108endfunc
Bram Moolenaara6d48492017-12-12 22:45:31 +01003109
3110" Tests for the getqflist() and getloclist() functions when the list is not
3111" present or is empty
3112func Xgetlist_empty_tests(cchar)
3113 call s:setup_commands(a:cchar)
3114
3115 " Empty quickfix stack
3116 call g:Xsetlist([], 'f')
3117 call assert_equal('', g:Xgetlist({'context' : 0}).context)
3118 call assert_equal(0, g:Xgetlist({'id' : 0}).id)
3119 call assert_equal(0, g:Xgetlist({'idx' : 0}).idx)
3120 call assert_equal([], g:Xgetlist({'items' : 0}).items)
3121 call assert_equal(0, g:Xgetlist({'nr' : 0}).nr)
3122 call assert_equal(0, g:Xgetlist({'size' : 0}).size)
3123 call assert_equal('', g:Xgetlist({'title' : 0}).title)
3124 call assert_equal(0, g:Xgetlist({'winid' : 0}).winid)
Bram Moolenaarb254af32017-12-18 19:48:58 +01003125 call assert_equal(0, g:Xgetlist({'changedtick' : 0}).changedtick)
Bram Moolenaarc9cc9c72018-09-02 15:18:42 +02003126 if a:cchar == 'c'
3127 call assert_equal({'context' : '', 'id' : 0, 'idx' : 0,
Bram Moolenaar647e24b2019-03-17 16:39:46 +01003128 \ 'items' : [], 'nr' : 0, 'size' : 0, 'qfbufnr' : 0,
Bram Moolenaarc9cc9c72018-09-02 15:18:42 +02003129 \ 'title' : '', 'winid' : 0, 'changedtick': 0},
3130 \ g:Xgetlist({'all' : 0}))
3131 else
3132 call assert_equal({'context' : '', 'id' : 0, 'idx' : 0,
3133 \ 'items' : [], 'nr' : 0, 'size' : 0, 'title' : '',
Bram Moolenaar647e24b2019-03-17 16:39:46 +01003134 \ 'winid' : 0, 'changedtick': 0, 'filewinid' : 0,
3135 \ 'qfbufnr' : 0},
Bram Moolenaarc9cc9c72018-09-02 15:18:42 +02003136 \ g:Xgetlist({'all' : 0}))
3137 endif
Bram Moolenaara6d48492017-12-12 22:45:31 +01003138
Bram Moolenaar2ec364e2018-01-27 11:52:13 +01003139 " Quickfix window with empty stack
3140 silent! Xopen
3141 let qfwinid = (a:cchar == 'c') ? win_getid() : 0
Bram Moolenaar647e24b2019-03-17 16:39:46 +01003142 let qfbufnr = (a:cchar == 'c') ? bufnr('') : 0
Bram Moolenaar2ec364e2018-01-27 11:52:13 +01003143 call assert_equal(qfwinid, g:Xgetlist({'winid' : 0}).winid)
3144 Xclose
3145
Bram Moolenaara6d48492017-12-12 22:45:31 +01003146 " Empty quickfix list
3147 Xexpr ""
3148 call assert_equal('', g:Xgetlist({'context' : 0}).context)
3149 call assert_notequal(0, g:Xgetlist({'id' : 0}).id)
3150 call assert_equal(0, g:Xgetlist({'idx' : 0}).idx)
3151 call assert_equal([], g:Xgetlist({'items' : 0}).items)
3152 call assert_notequal(0, g:Xgetlist({'nr' : 0}).nr)
3153 call assert_equal(0, g:Xgetlist({'size' : 0}).size)
3154 call assert_notequal('', g:Xgetlist({'title' : 0}).title)
3155 call assert_equal(0, g:Xgetlist({'winid' : 0}).winid)
Bram Moolenaarb254af32017-12-18 19:48:58 +01003156 call assert_equal(1, g:Xgetlist({'changedtick' : 0}).changedtick)
Bram Moolenaara6d48492017-12-12 22:45:31 +01003157
3158 let qfid = g:Xgetlist({'id' : 0}).id
3159 call g:Xsetlist([], 'f')
3160
3161 " Non-existing quickfix identifier
3162 call assert_equal('', g:Xgetlist({'id' : qfid, 'context' : 0}).context)
3163 call assert_equal(0, g:Xgetlist({'id' : qfid}).id)
3164 call assert_equal(0, g:Xgetlist({'id' : qfid, 'idx' : 0}).idx)
3165 call assert_equal([], g:Xgetlist({'id' : qfid, 'items' : 0}).items)
3166 call assert_equal(0, g:Xgetlist({'id' : qfid, 'nr' : 0}).nr)
3167 call assert_equal(0, g:Xgetlist({'id' : qfid, 'size' : 0}).size)
3168 call assert_equal('', g:Xgetlist({'id' : qfid, 'title' : 0}).title)
3169 call assert_equal(0, g:Xgetlist({'id' : qfid, 'winid' : 0}).winid)
Bram Moolenaarb254af32017-12-18 19:48:58 +01003170 call assert_equal(0, g:Xgetlist({'id' : qfid, 'changedtick' : 0}).changedtick)
Bram Moolenaarc9cc9c72018-09-02 15:18:42 +02003171 if a:cchar == 'c'
3172 call assert_equal({'context' : '', 'id' : 0, 'idx' : 0, 'items' : [],
3173 \ 'nr' : 0, 'size' : 0, 'title' : '', 'winid' : 0,
Bram Moolenaar647e24b2019-03-17 16:39:46 +01003174 \ 'qfbufnr' : qfbufnr,
Bram Moolenaarc9cc9c72018-09-02 15:18:42 +02003175 \ 'changedtick' : 0}, g:Xgetlist({'id' : qfid, 'all' : 0}))
3176 else
3177 call assert_equal({'context' : '', 'id' : 0, 'idx' : 0, 'items' : [],
3178 \ 'nr' : 0, 'size' : 0, 'title' : '', 'winid' : 0,
Bram Moolenaar647e24b2019-03-17 16:39:46 +01003179 \ 'changedtick' : 0, 'filewinid' : 0, 'qfbufnr' : 0},
Bram Moolenaarc9cc9c72018-09-02 15:18:42 +02003180 \ g:Xgetlist({'id' : qfid, 'all' : 0}))
3181 endif
Bram Moolenaara6d48492017-12-12 22:45:31 +01003182
3183 " Non-existing quickfix list number
3184 call assert_equal('', g:Xgetlist({'nr' : 5, 'context' : 0}).context)
3185 call assert_equal(0, g:Xgetlist({'nr' : 5}).nr)
3186 call assert_equal(0, g:Xgetlist({'nr' : 5, 'idx' : 0}).idx)
3187 call assert_equal([], g:Xgetlist({'nr' : 5, 'items' : 0}).items)
3188 call assert_equal(0, g:Xgetlist({'nr' : 5, 'id' : 0}).id)
3189 call assert_equal(0, g:Xgetlist({'nr' : 5, 'size' : 0}).size)
3190 call assert_equal('', g:Xgetlist({'nr' : 5, 'title' : 0}).title)
3191 call assert_equal(0, g:Xgetlist({'nr' : 5, 'winid' : 0}).winid)
Bram Moolenaarb254af32017-12-18 19:48:58 +01003192 call assert_equal(0, g:Xgetlist({'nr' : 5, 'changedtick' : 0}).changedtick)
Bram Moolenaarc9cc9c72018-09-02 15:18:42 +02003193 if a:cchar == 'c'
3194 call assert_equal({'context' : '', 'id' : 0, 'idx' : 0, 'items' : [],
3195 \ 'nr' : 0, 'size' : 0, 'title' : '', 'winid' : 0,
Bram Moolenaar647e24b2019-03-17 16:39:46 +01003196 \ 'changedtick' : 0, 'qfbufnr' : qfbufnr},
3197 \ g:Xgetlist({'nr' : 5, 'all' : 0}))
Bram Moolenaarc9cc9c72018-09-02 15:18:42 +02003198 else
3199 call assert_equal({'context' : '', 'id' : 0, 'idx' : 0, 'items' : [],
3200 \ 'nr' : 0, 'size' : 0, 'title' : '', 'winid' : 0,
Bram Moolenaar647e24b2019-03-17 16:39:46 +01003201 \ 'changedtick' : 0, 'filewinid' : 0, 'qfbufnr' : 0},
Bram Moolenaarc9cc9c72018-09-02 15:18:42 +02003202 \ g:Xgetlist({'nr' : 5, 'all' : 0}))
3203 endif
Bram Moolenaara6d48492017-12-12 22:45:31 +01003204endfunc
3205
3206func Test_getqflist()
3207 call Xgetlist_empty_tests('c')
3208 call Xgetlist_empty_tests('l')
3209endfunc
Bram Moolenaarb254af32017-12-18 19:48:58 +01003210
Bram Moolenaara0ca7d02017-12-19 10:22:19 +01003211func Test_getqflist_invalid_nr()
3212 " The following commands used to crash Vim
3213 cexpr ""
3214 call getqflist({'nr' : $XXX_DOES_NOT_EXIST_XXX})
3215
3216 " Cleanup
3217 call setqflist([], 'r')
3218endfunc
3219
Bram Moolenaarb254af32017-12-18 19:48:58 +01003220" Tests for the quickfix/location list changedtick
3221func Xqftick_tests(cchar)
3222 call s:setup_commands(a:cchar)
3223
3224 call g:Xsetlist([], 'f')
3225
3226 Xexpr "F1:10:Line10"
3227 let qfid = g:Xgetlist({'id' : 0}).id
3228 call assert_equal(1, g:Xgetlist({'changedtick' : 0}).changedtick)
3229 Xaddexpr "F2:20:Line20\nF2:21:Line21"
3230 call assert_equal(2, g:Xgetlist({'changedtick' : 0}).changedtick)
3231 call g:Xsetlist([], 'a', {'lines' : ["F3:30:Line30", "F3:31:Line31"]})
3232 call assert_equal(3, g:Xgetlist({'changedtick' : 0}).changedtick)
3233 call g:Xsetlist([], 'r', {'lines' : ["F4:40:Line40"]})
3234 call assert_equal(4, g:Xgetlist({'changedtick' : 0}).changedtick)
3235 call g:Xsetlist([], 'a', {'title' : 'New Title'})
3236 call assert_equal(5, g:Xgetlist({'changedtick' : 0}).changedtick)
3237
3238 enew!
3239 call append(0, ["F5:50:L50", "F6:60:L60"])
3240 Xaddbuffer
3241 call assert_equal(6, g:Xgetlist({'changedtick' : 0}).changedtick)
3242 enew!
3243
3244 call g:Xsetlist([], 'a', {'context' : {'bus' : 'pci'}})
3245 call assert_equal(7, g:Xgetlist({'changedtick' : 0}).changedtick)
3246 call g:Xsetlist([{'filename' : 'F7', 'lnum' : 10, 'text' : 'L7'},
3247 \ {'filename' : 'F7', 'lnum' : 11, 'text' : 'L11'}], 'a')
3248 call assert_equal(8, g:Xgetlist({'changedtick' : 0}).changedtick)
3249 call g:Xsetlist([{'filename' : 'F7', 'lnum' : 10, 'text' : 'L7'},
3250 \ {'filename' : 'F7', 'lnum' : 11, 'text' : 'L11'}], ' ')
3251 call assert_equal(1, g:Xgetlist({'changedtick' : 0}).changedtick)
3252 call g:Xsetlist([{'filename' : 'F7', 'lnum' : 10, 'text' : 'L7'},
3253 \ {'filename' : 'F7', 'lnum' : 11, 'text' : 'L11'}], 'r')
3254 call assert_equal(2, g:Xgetlist({'changedtick' : 0}).changedtick)
3255
3256 call writefile(["F8:80:L80", "F8:81:L81"], "Xone")
3257 Xfile Xone
3258 call assert_equal(1, g:Xgetlist({'changedtick' : 0}).changedtick)
3259 Xaddfile Xone
3260 call assert_equal(2, g:Xgetlist({'changedtick' : 0}).changedtick)
3261
3262 " Test case for updating a non-current quickfix list
3263 call g:Xsetlist([], 'f')
3264 Xexpr "F1:1:L1"
3265 Xexpr "F2:2:L2"
3266 call g:Xsetlist([], 'a', {'nr' : 1, "lines" : ["F10:10:L10"]})
3267 call assert_equal(1, g:Xgetlist({'changedtick' : 0}).changedtick)
3268 call assert_equal(2, g:Xgetlist({'nr' : 1, 'changedtick' : 0}).changedtick)
3269
3270 call delete("Xone")
3271endfunc
3272
3273func Test_qf_tick()
3274 call Xqftick_tests('c')
3275 call Xqftick_tests('l')
3276endfunc
Bram Moolenaar12237442017-12-19 12:38:52 +01003277
Bram Moolenaarc631f2d2018-08-21 21:58:13 +02003278" Test helpgrep with lang specifier
3279func Xtest_helpgrep_with_lang_specifier(cchar)
3280 call s:setup_commands(a:cchar)
3281 Xhelpgrep Vim@en
3282 call assert_equal('help', &filetype)
3283 call assert_notequal(0, g:Xgetlist({'nr' : '$'}).nr)
3284 new | only
3285endfunc
3286
3287func Test_helpgrep_with_lang_specifier()
3288 call Xtest_helpgrep_with_lang_specifier('c')
3289 call Xtest_helpgrep_with_lang_specifier('l')
3290endfunc
3291
Bram Moolenaar12237442017-12-19 12:38:52 +01003292" The following test used to crash Vim.
3293" Open the location list window and close the regular window associated with
3294" the location list. When the garbage collection runs now, it incorrectly
3295" marks the location list context as not in use and frees the context.
3296func Test_ll_window_ctx()
3297 call setloclist(0, [], 'f')
3298 call setloclist(0, [], 'a', {'context' : []})
3299 lopen | only
3300 call test_garbagecollect_now()
3301 echo getloclist(0, {'context' : 1}).context
3302 enew | only
3303endfunc
3304
Bram Moolenaar14a4deb2017-12-19 16:48:55 +01003305" The following test used to crash vim
3306func Test_lfile_crash()
3307 sp Xtest
3308 au QuickFixCmdPre * bw
3309 call assert_fails('lfile', 'E40')
3310 au! QuickFixCmdPre
3311endfunc
Bram Moolenaar3c097222017-12-21 20:54:49 +01003312
3313" The following test used to crash vim
3314func Test_lbuffer_crash()
3315 sv Xtest
3316 augroup QF_Test
3317 au!
3318 au * * bw
3319 augroup END
3320 lbuffer
3321 augroup QF_Test
3322 au!
3323 augroup END
3324endfunc
3325
3326" The following test used to crash vim
3327func Test_lexpr_crash()
3328 augroup QF_Test
3329 au!
3330 au * * call setloclist(0, [], 'f')
3331 augroup END
3332 lexpr ""
3333 augroup QF_Test
3334 au!
3335 augroup END
Bram Moolenaar9f84ded2018-10-20 20:54:02 +02003336
Bram Moolenaar3c097222017-12-21 20:54:49 +01003337 enew | only
Bram Moolenaar9f84ded2018-10-20 20:54:02 +02003338 augroup QF_Test
3339 au!
3340 au BufNew * call setloclist(0, [], 'f')
3341 augroup END
3342 lexpr 'x:1:x'
3343 augroup QF_Test
3344 au!
3345 augroup END
3346
3347 enew | only
3348 lexpr ''
3349 lopen
3350 augroup QF_Test
3351 au!
3352 au FileType * call setloclist(0, [], 'f')
3353 augroup END
3354 lexpr ''
3355 augroup QF_Test
3356 au!
3357 augroup END
Bram Moolenaar3c097222017-12-21 20:54:49 +01003358endfunc
3359
3360" The following test used to crash Vim
3361func Test_lvimgrep_crash()
3362 sv Xtest
3363 augroup QF_Test
3364 au!
3365 au * * call setloclist(0, [], 'f')
3366 augroup END
3367 lvimgrep quickfix test_quickfix.vim
3368 augroup QF_Test
3369 au!
3370 augroup END
Bram Moolenaarb6f14802018-10-21 18:47:43 +02003371
3372 new | only
3373 augroup QF_Test
3374 au!
3375 au BufEnter * call setloclist(0, [], 'r')
3376 augroup END
3377 call assert_fails('lvimgrep Test_lvimgrep_crash *', 'E926:')
3378 augroup QF_Test
3379 au!
3380 augroup END
3381
Bram Moolenaar3c097222017-12-21 20:54:49 +01003382 enew | only
3383endfunc
Bram Moolenaarde046542017-12-26 13:53:11 +01003384
3385" Test for the position of the quickfix and location list window
3386func Test_qfwin_pos()
3387 " Open two windows
3388 new | only
3389 new
3390 cexpr ['F1:10:L10']
3391 copen
3392 " Quickfix window should be the bottom most window
3393 call assert_equal(3, winnr())
3394 close
3395 " Open at the very top
3396 wincmd t
3397 topleft copen
3398 call assert_equal(1, winnr())
3399 close
3400 " open left of the current window
3401 wincmd t
3402 below new
3403 leftabove copen
3404 call assert_equal(2, winnr())
3405 close
3406 " open right of the current window
3407 rightbelow copen
3408 call assert_equal(3, winnr())
3409 close
3410endfunc
Bram Moolenaare1bb8792018-04-06 22:58:23 +02003411
3412" Tests for quickfix/location lists changed by autocommands when
3413" :vimgrep/:lvimgrep commands are running.
3414func Test_vimgrep_autocmd()
3415 call setqflist([], 'f')
3416 call writefile(['stars'], 'Xtest1.txt')
3417 call writefile(['stars'], 'Xtest2.txt')
3418
3419 " Test 1:
3420 " When searching for a pattern using :vimgrep, if the quickfix list is
3421 " changed by an autocmd, the results should be added to the correct quickfix
3422 " list.
3423 autocmd BufRead Xtest2.txt cexpr '' | cexpr ''
3424 silent vimgrep stars Xtest*.txt
3425 call assert_equal(1, getqflist({'nr' : 0}).nr)
3426 call assert_equal(3, getqflist({'nr' : '$'}).nr)
3427 call assert_equal('Xtest2.txt', bufname(getqflist()[1].bufnr))
3428 au! BufRead Xtest2.txt
3429
3430 " Test 2:
3431 " When searching for a pattern using :vimgrep, if the quickfix list is
3432 " freed, then a error should be given.
3433 silent! %bwipe!
3434 call setqflist([], 'f')
3435 autocmd BufRead Xtest2.txt for i in range(10) | cexpr '' | endfor
3436 call assert_fails('vimgrep stars Xtest*.txt', 'E925:')
3437 au! BufRead Xtest2.txt
3438
3439 " Test 3:
3440 " When searching for a pattern using :lvimgrep, if the location list is
3441 " freed, then the command should error out.
3442 silent! %bwipe!
3443 let g:save_winid = win_getid()
3444 autocmd BufRead Xtest2.txt call setloclist(g:save_winid, [], 'f')
3445 call assert_fails('lvimgrep stars Xtest*.txt', 'E926:')
3446 au! BufRead Xtest2.txt
3447
3448 call delete('Xtest1.txt')
3449 call delete('Xtest2.txt')
3450 call setqflist([], 'f')
3451endfunc
Bram Moolenaar3b9474b2018-04-23 21:29:48 +02003452
3453" The following test used to crash Vim
3454func Test_lhelpgrep_autocmd()
3455 lhelpgrep quickfix
3456 autocmd QuickFixCmdPost * call setloclist(0, [], 'f')
3457 lhelpgrep buffer
3458 call assert_equal('help', &filetype)
3459 call assert_equal(0, getloclist(0, {'nr' : '$'}).nr)
3460 lhelpgrep tabpage
3461 call assert_equal('help', &filetype)
3462 call assert_equal(1, getloclist(0, {'nr' : '$'}).nr)
3463 au! QuickFixCmdPost
Bram Moolenaarb6f14802018-10-21 18:47:43 +02003464
3465 new | only
3466 augroup QF_Test
3467 au!
3468 au BufEnter * call setqflist([], 'f')
3469 augroup END
3470 call assert_fails('helpgrep quickfix', 'E925:')
3471 augroup QF_Test
3472 au! BufEnter
3473 augroup END
3474
3475 new | only
3476 augroup QF_Test
3477 au!
3478 au BufEnter * call setqflist([], 'r')
3479 augroup END
3480 call assert_fails('helpgrep quickfix', 'E925:')
3481 augroup QF_Test
3482 au! BufEnter
3483 augroup END
3484
3485 new | only
3486 augroup QF_Test
3487 au!
3488 au BufEnter * call setloclist(0, [], 'r')
3489 augroup END
3490 call assert_fails('lhelpgrep quickfix', 'E926:')
3491 augroup QF_Test
3492 au! BufEnter
3493 augroup END
3494
Bram Moolenaar3b9474b2018-04-23 21:29:48 +02003495 new | only
3496endfunc
Bram Moolenaara796d462018-05-01 14:30:36 +02003497
3498" Test for shortening/simplifying the file name when opening the
3499" quickfix window or when displaying the quickfix list
3500func Test_shorten_fname()
3501 if !has('unix')
3502 return
3503 endif
3504 %bwipe
3505 " Create a quickfix list with a absolute path filename
3506 let fname = getcwd() . '/test_quickfix.vim'
3507 call setqflist([], ' ', {'lines':[fname . ":20:Line20"], 'efm':'%f:%l:%m'})
3508 call assert_equal(fname, bufname('test_quickfix.vim'))
3509 " Opening the quickfix window should simplify the file path
3510 cwindow
3511 call assert_equal('test_quickfix.vim', bufname('test_quickfix.vim'))
3512 cclose
3513 %bwipe
3514 " Create a quickfix list with a absolute path filename
3515 call setqflist([], ' ', {'lines':[fname . ":20:Line20"], 'efm':'%f:%l:%m'})
3516 call assert_equal(fname, bufname('test_quickfix.vim'))
3517 " Displaying the quickfix list should simplify the file path
3518 silent! clist
3519 call assert_equal('test_quickfix.vim', bufname('test_quickfix.vim'))
3520endfunc
Bram Moolenaar8b62e312018-05-13 15:29:04 +02003521
3522" Quickfix title tests
3523" In the below tests, 'exe "cmd"' is used to invoke the quickfix commands.
3524" Otherwise due to indentation, the title is set with spaces at the beginning
3525" of the command.
3526func Test_qftitle()
3527 call writefile(["F1:1:Line1"], 'Xerr')
3528
3529 " :cexpr
3530 exe "cexpr readfile('Xerr')"
3531 call assert_equal(":cexpr readfile('Xerr')", getqflist({'title' : 1}).title)
3532
3533 " :cgetexpr
3534 exe "cgetexpr readfile('Xerr')"
3535 call assert_equal(":cgetexpr readfile('Xerr')",
3536 \ getqflist({'title' : 1}).title)
3537
3538 " :caddexpr
3539 call setqflist([], 'f')
3540 exe "caddexpr readfile('Xerr')"
3541 call assert_equal(":caddexpr readfile('Xerr')",
3542 \ getqflist({'title' : 1}).title)
3543
3544 " :cbuffer
3545 new Xerr
3546 exe "cbuffer"
3547 call assert_equal(':cbuffer (Xerr)', getqflist({'title' : 1}).title)
3548
3549 " :cgetbuffer
3550 edit Xerr
3551 exe "cgetbuffer"
3552 call assert_equal(':cgetbuffer (Xerr)', getqflist({'title' : 1}).title)
3553
3554 " :caddbuffer
3555 call setqflist([], 'f')
3556 edit Xerr
3557 exe "caddbuffer"
3558 call assert_equal(':caddbuffer (Xerr)', getqflist({'title' : 1}).title)
3559
3560 " :cfile
3561 exe "cfile Xerr"
3562 call assert_equal(':cfile Xerr', getqflist({'title' : 1}).title)
3563
3564 " :cgetfile
3565 exe "cgetfile Xerr"
3566 call assert_equal(':cgetfile Xerr', getqflist({'title' : 1}).title)
3567
3568 " :caddfile
3569 call setqflist([], 'f')
3570 exe "caddfile Xerr"
3571 call assert_equal(':caddfile Xerr', getqflist({'title' : 1}).title)
3572
3573 " :grep
3574 set grepprg=internal
3575 exe "grep F1 Xerr"
3576 call assert_equal(':grep F1 Xerr', getqflist({'title' : 1}).title)
3577
3578 " :grepadd
3579 call setqflist([], 'f')
3580 exe "grepadd F1 Xerr"
3581 call assert_equal(':grepadd F1 Xerr', getqflist({'title' : 1}).title)
3582 set grepprg&vim
3583
3584 " :vimgrep
3585 exe "vimgrep F1 Xerr"
3586 call assert_equal(':vimgrep F1 Xerr', getqflist({'title' : 1}).title)
3587
3588 " :vimgrepadd
3589 call setqflist([], 'f')
3590 exe "vimgrepadd F1 Xerr"
3591 call assert_equal(':vimgrepadd F1 Xerr', getqflist({'title' : 1}).title)
3592
3593 call setqflist(['F1:10:L10'], ' ')
3594 call assert_equal(':setqflist()', getqflist({'title' : 1}).title)
3595
3596 call setqflist([], 'f')
3597 call setqflist(['F1:10:L10'], 'a')
3598 call assert_equal(':setqflist()', getqflist({'title' : 1}).title)
3599
3600 call setqflist([], 'f')
3601 call setqflist(['F1:10:L10'], 'r')
3602 call assert_equal(':setqflist()', getqflist({'title' : 1}).title)
3603
3604 close
3605 call delete('Xerr')
3606
3607 call setqflist([], ' ', {'title' : 'Errors'})
3608 copen
3609 call assert_equal('Errors', w:quickfix_title)
3610 call setqflist([], 'r', {'items' : [{'filename' : 'a.c', 'lnum' : 10}]})
3611 call assert_equal('Errors', w:quickfix_title)
3612 cclose
3613endfunc
Bram Moolenaar600323b2018-06-16 22:16:47 +02003614
3615func Test_lbuffer_with_bwipe()
3616 new
3617 new
3618 augroup nasty
3619 au * * bwipe
3620 augroup END
3621 lbuffer
3622 augroup nasty
3623 au!
3624 augroup END
3625endfunc
Bram Moolenaar0366c012018-06-18 20:52:13 +02003626
Bram Moolenaar531b9a32018-07-03 16:54:23 +02003627" Test for an autocmd freeing the quickfix/location list when cexpr/lexpr is
3628" running
3629func Xexpr_acmd_freelist(cchar)
3630 call s:setup_commands(a:cchar)
3631
Bram Moolenaar0366c012018-06-18 20:52:13 +02003632 " This was using freed memory.
3633 augroup nasty
Bram Moolenaar531b9a32018-07-03 16:54:23 +02003634 au * * call g:Xsetlist([], 'f')
Bram Moolenaar0366c012018-06-18 20:52:13 +02003635 augroup END
Bram Moolenaar531b9a32018-07-03 16:54:23 +02003636 Xexpr "x"
Bram Moolenaar0366c012018-06-18 20:52:13 +02003637 augroup nasty
3638 au!
3639 augroup END
3640endfunc
Bram Moolenaar531b9a32018-07-03 16:54:23 +02003641
3642func Test_cexpr_acmd_freelist()
3643 call Xexpr_acmd_freelist('c')
3644 call Xexpr_acmd_freelist('l')
3645endfunc
3646
3647" Test for commands that create a new quickfix/location list and jump to the
3648" first error automatically.
3649func Xjumpto_first_error_test(cchar)
3650 call s:setup_commands(a:cchar)
3651
3652 call s:create_test_file('Xtestfile1')
3653 call s:create_test_file('Xtestfile2')
3654 let l = ['Xtestfile1:2:Line2', 'Xtestfile2:4:Line4']
3655
3656 " Test for cexpr/lexpr
3657 enew
3658 Xexpr l
3659 call assert_equal('Xtestfile1', bufname(''))
3660 call assert_equal(2, line('.'))
3661
3662 " Test for cfile/lfile
3663 enew
3664 call writefile(l, 'Xerr')
3665 Xfile Xerr
3666 call assert_equal('Xtestfile1', bufname(''))
3667 call assert_equal(2, line('.'))
3668
3669 " Test for cbuffer/lbuffer
3670 edit Xerr
3671 Xbuffer
3672 call assert_equal('Xtestfile1', bufname(''))
3673 call assert_equal(2, line('.'))
3674
3675 call delete('Xerr')
3676 call delete('Xtestfile1')
3677 call delete('Xtestfile2')
3678endfunc
3679
3680func Test_jumpto_first_error()
3681 call Xjumpto_first_error_test('c')
3682 call Xjumpto_first_error_test('l')
3683endfunc
3684
3685" Test for a quickfix autocmd changing the quickfix/location list before
3686" jumping to the first error in the new list.
3687func Xautocmd_changelist(cchar)
3688 call s:setup_commands(a:cchar)
3689
3690 " Test for cfile/lfile
3691 call s:create_test_file('Xtestfile1')
3692 call s:create_test_file('Xtestfile2')
3693 Xexpr 'Xtestfile1:2:Line2'
3694 autocmd QuickFixCmdPost * Xolder
3695 call writefile(['Xtestfile2:4:Line4'], 'Xerr')
3696 Xfile Xerr
3697 call assert_equal('Xtestfile2', bufname(''))
3698 call assert_equal(4, line('.'))
3699 autocmd! QuickFixCmdPost
3700
3701 " Test for cbuffer/lbuffer
3702 call g:Xsetlist([], 'f')
3703 Xexpr 'Xtestfile1:2:Line2'
3704 autocmd QuickFixCmdPost * Xolder
3705 call writefile(['Xtestfile2:4:Line4'], 'Xerr')
3706 edit Xerr
3707 Xbuffer
3708 call assert_equal('Xtestfile2', bufname(''))
3709 call assert_equal(4, line('.'))
3710 autocmd! QuickFixCmdPost
3711
3712 " Test for cexpr/lexpr
3713 call g:Xsetlist([], 'f')
3714 Xexpr 'Xtestfile1:2:Line2'
3715 autocmd QuickFixCmdPost * Xolder
3716 Xexpr 'Xtestfile2:4:Line4'
3717 call assert_equal('Xtestfile2', bufname(''))
3718 call assert_equal(4, line('.'))
3719 autocmd! QuickFixCmdPost
3720
Bram Moolenaar851332e2018-07-03 19:16:00 +02003721 " The grepprg may not be set on non-Unix systems
3722 if has('unix')
3723 " Test for grep/lgrep
3724 call g:Xsetlist([], 'f')
3725 Xexpr 'Xtestfile1:2:Line2'
3726 autocmd QuickFixCmdPost * Xolder
3727 silent Xgrep Line5 Xtestfile2
3728 call assert_equal('Xtestfile2', bufname(''))
3729 call assert_equal(5, line('.'))
3730 autocmd! QuickFixCmdPost
3731 endif
Bram Moolenaar531b9a32018-07-03 16:54:23 +02003732
3733 " Test for vimgrep/lvimgrep
3734 call g:Xsetlist([], 'f')
3735 Xexpr 'Xtestfile1:2:Line2'
3736 autocmd QuickFixCmdPost * Xolder
3737 silent Xvimgrep Line5 Xtestfile2
3738 call assert_equal('Xtestfile2', bufname(''))
3739 call assert_equal(5, line('.'))
3740 autocmd! QuickFixCmdPost
3741
Bram Moolenaar3f347e42018-08-09 21:19:20 +02003742 " Test for autocommands clearing the quickfix list before jumping to the
3743 " first error. This should not result in an error
3744 autocmd QuickFixCmdPost * call g:Xsetlist([], 'r')
3745 let v:errmsg = ''
3746 " Test for cfile/lfile
3747 Xfile Xerr
3748 call assert_true(v:errmsg !~# 'E42:')
3749 " Test for cbuffer/lbuffer
3750 edit Xerr
3751 Xbuffer
3752 call assert_true(v:errmsg !~# 'E42:')
3753 " Test for cexpr/lexpr
3754 Xexpr 'Xtestfile2:4:Line4'
3755 call assert_true(v:errmsg !~# 'E42:')
3756 " Test for grep/lgrep
3757 " The grepprg may not be set on non-Unix systems
3758 if has('unix')
3759 silent Xgrep Line5 Xtestfile2
3760 call assert_true(v:errmsg !~# 'E42:')
3761 endif
3762 " Test for vimgrep/lvimgrep
3763 call assert_fails('silent Xvimgrep Line5 Xtestfile2', 'E480:')
3764 autocmd! QuickFixCmdPost
3765
Bram Moolenaar531b9a32018-07-03 16:54:23 +02003766 call delete('Xerr')
3767 call delete('Xtestfile1')
3768 call delete('Xtestfile2')
3769endfunc
3770
3771func Test_autocmd_changelist()
3772 call Xautocmd_changelist('c')
3773 call Xautocmd_changelist('l')
3774endfunc
Bram Moolenaar4cde86c2018-07-08 16:01:08 +02003775
3776" Tests for the ':filter /pat/ clist' command
3777func Test_filter_clist()
3778 cexpr ['Xfile1:10:10:Line 10', 'Xfile2:15:15:Line 15']
3779 call assert_equal([' 2 Xfile2:15 col 15: Line 15'],
3780 \ split(execute('filter /Line 15/ clist'), "\n"))
3781 call assert_equal([' 1 Xfile1:10 col 10: Line 10'],
3782 \ split(execute('filter /Xfile1/ clist'), "\n"))
3783 call assert_equal([], split(execute('filter /abc/ clist'), "\n"))
3784
3785 call setqflist([{'module' : 'abc', 'pattern' : 'pat1'},
3786 \ {'module' : 'pqr', 'pattern' : 'pat2'}], ' ')
3787 call assert_equal([' 2 pqr:pat2: '],
3788 \ split(execute('filter /pqr/ clist'), "\n"))
3789 call assert_equal([' 1 abc:pat1: '],
3790 \ split(execute('filter /pat1/ clist'), "\n"))
3791endfunc
Bram Moolenaar0a08c632018-07-25 22:36:52 +02003792
3793" Tests for the "CTRL-W <CR>" command.
3794func Xview_result_split_tests(cchar)
3795 call s:setup_commands(a:cchar)
3796
3797 " Test that "CTRL-W <CR>" in a qf/ll window fails with empty list.
3798 call g:Xsetlist([])
3799 Xopen
3800 let l:win_count = winnr('$')
3801 call assert_fails('execute "normal! \<C-W>\<CR>"', 'E42')
3802 call assert_equal(l:win_count, winnr('$'))
3803 Xclose
3804endfunc
3805
3806func Test_view_result_split()
3807 call Xview_result_split_tests('c')
3808 call Xview_result_split_tests('l')
3809endfunc
Bram Moolenaar2dfcef42018-08-15 22:29:51 +02003810
3811" Test that :cc sets curswant
3812func Test_curswant()
3813 helpgrep quickfix
3814 normal! llll
3815 1cc
3816 call assert_equal(getcurpos()[4], virtcol('.'))
3817 cclose | helpclose
3818endfunc
Bram Moolenaarb2443732018-11-11 22:50:27 +01003819
3820" Test for opening a file from the quickfix window using CTRL-W <Enter>
3821" doesn't leave an empty buffer around.
3822func Test_splitview()
3823 call s:create_test_file('Xtestfile1')
3824 call s:create_test_file('Xtestfile2')
3825 new | only
3826 let last_bufnr = bufnr('Test_sv_1', 1)
3827 let l = ['Xtestfile1:2:Line2', 'Xtestfile2:4:Line4']
3828 cgetexpr l
3829 copen
3830 let numbufs = len(getbufinfo())
3831 exe "normal \<C-W>\<CR>"
3832 copen
3833 exe "normal j\<C-W>\<CR>"
3834 " Make sure new empty buffers are not created
3835 call assert_equal(numbufs, len(getbufinfo()))
3836 " Creating a new buffer should use the next available buffer number
3837 call assert_equal(last_bufnr + 4, bufnr("Test_sv_2", 1))
3838 bwipe Test_sv_1
3839 bwipe Test_sv_2
3840 new | only
3841
3842 " When split opening files from location list window, make sure that two
3843 " windows doesn't refer to the same location list
3844 lgetexpr l
3845 let locid = getloclist(0, {'id' : 0}).id
3846 lopen
3847 exe "normal \<C-W>\<CR>"
3848 call assert_notequal(locid, getloclist(0, {'id' : 0}).id)
3849 call assert_equal(0, getloclist(0, {'winid' : 0}).winid)
3850 new | only
3851
3852 " When split opening files from a helpgrep location list window, a new help
Bram Moolenaareeb1b9c2019-02-10 22:59:04 +01003853 " window should be opened with a copy of the location list.
Bram Moolenaarb2443732018-11-11 22:50:27 +01003854 lhelpgrep window
3855 let locid = getloclist(0, {'id' : 0}).id
3856 lwindow
3857 exe "normal j\<C-W>\<CR>"
3858 call assert_notequal(locid, getloclist(0, {'id' : 0}).id)
3859 call assert_equal(0, getloclist(0, {'winid' : 0}).winid)
3860 new | only
3861
3862 call delete('Xtestfile1')
3863 call delete('Xtestfile2')
3864endfunc
Bram Moolenaarc45eb772019-01-31 14:27:04 +01003865
3866" Test for parsing entries using visual screen column
3867func Test_viscol()
3868 enew
3869 call writefile(["Col1\tCol2\tCol3"], 'Xfile1')
3870 edit Xfile1
3871
3872 " Use byte offset for column number
3873 set efm&
3874 cexpr "Xfile1:1:5:XX\nXfile1:1:9:YY\nXfile1:1:20:ZZ"
3875 call assert_equal([5, 8], [col('.'), virtcol('.')])
3876 cnext
3877 call assert_equal([9, 12], [col('.'), virtcol('.')])
3878 cnext
3879 call assert_equal([14, 20], [col('.'), virtcol('.')])
3880
3881 " Use screen column offset for column number
3882 set efm=%f:%l:%v:%m
3883 cexpr "Xfile1:1:8:XX\nXfile1:1:12:YY\nXfile1:1:20:ZZ"
3884 call assert_equal([5, 8], [col('.'), virtcol('.')])
3885 cnext
3886 call assert_equal([9, 12], [col('.'), virtcol('.')])
3887 cnext
3888 call assert_equal([14, 20], [col('.'), virtcol('.')])
3889 cexpr "Xfile1:1:6:XX\nXfile1:1:15:YY\nXfile1:1:24:ZZ"
3890 call assert_equal([5, 8], [col('.'), virtcol('.')])
3891 cnext
3892 call assert_equal([10, 16], [col('.'), virtcol('.')])
3893 cnext
3894 call assert_equal([14, 20], [col('.'), virtcol('.')])
3895
3896 enew
3897 call writefile(["Col1\täü\töß\tCol4"], 'Xfile1')
3898
3899 " Use byte offset for column number
3900 set efm&
3901 cexpr "Xfile1:1:8:XX\nXfile1:1:11:YY\nXfile1:1:16:ZZ"
3902 call assert_equal([8, 10], [col('.'), virtcol('.')])
3903 cnext
3904 call assert_equal([11, 17], [col('.'), virtcol('.')])
3905 cnext
3906 call assert_equal([16, 25], [col('.'), virtcol('.')])
3907
3908 " Use screen column offset for column number
3909 set efm=%f:%l:%v:%m
3910 cexpr "Xfile1:1:10:XX\nXfile1:1:17:YY\nXfile1:1:25:ZZ"
3911 call assert_equal([8, 10], [col('.'), virtcol('.')])
3912 cnext
3913 call assert_equal([11, 17], [col('.'), virtcol('.')])
3914 cnext
3915 call assert_equal([16, 25], [col('.'), virtcol('.')])
3916
3917 enew | only
3918 set efm&
3919 call delete('Xfile1')
3920endfunc
Bram Moolenaaree8188f2019-02-05 21:23:04 +01003921
3922" Test for the quickfix window buffer
3923func Xqfbuf_test(cchar)
3924 call s:setup_commands(a:cchar)
3925
3926 " Quickfix buffer should be reused across closing and opening a quickfix
3927 " window
3928 Xexpr "F1:10:Line10"
3929 Xopen
3930 let qfbnum = bufnr('')
3931 Xclose
3932 " Even after the quickfix window is closed, the buffer should be loaded
3933 call assert_true(bufloaded(qfbnum))
Bram Moolenaar647e24b2019-03-17 16:39:46 +01003934 call assert_true(qfbnum, g:Xgetlist({'qfbufnr' : 0}).qfbufnr)
Bram Moolenaaree8188f2019-02-05 21:23:04 +01003935 Xopen
3936 " Buffer should be reused when opening the window again
3937 call assert_equal(qfbnum, bufnr(''))
3938 Xclose
3939
3940 if a:cchar == 'l'
3941 %bwipe
3942 " For a location list, when both the file window and the location list
3943 " window for the list are closed, then the buffer should be freed.
3944 new | only
3945 lexpr "F1:10:Line10"
3946 let wid = win_getid()
3947 lopen
3948 let qfbnum = bufnr('')
3949 call assert_match(qfbnum . ' %a- "\[Location List]"', execute('ls'))
3950 close
3951 " When the location list window is closed, the buffer name should not
3952 " change to 'Quickfix List'
Bram Moolenaar647e24b2019-03-17 16:39:46 +01003953 call assert_match(qfbnum . 'u h- "\[Location List]"', execute('ls!'))
Bram Moolenaaree8188f2019-02-05 21:23:04 +01003954 call assert_true(bufloaded(qfbnum))
3955
Bram Moolenaard82a81c2019-03-02 07:57:18 +01003956 " After deleting a location list buffer using ":bdelete", opening the
3957 " location list window should mark the buffer as a location list buffer.
3958 exe "bdelete " . qfbnum
3959 lopen
3960 call assert_equal("quickfix", &buftype)
3961 call assert_equal(1, getwininfo(win_getid(winnr()))[0].loclist)
3962 call assert_equal(wid, getloclist(0, {'filewinid' : 0}).filewinid)
3963 call assert_false(&swapfile)
3964 lclose
3965
Bram Moolenaareeb1b9c2019-02-10 22:59:04 +01003966 " When the location list is cleared for the window, the buffer should be
3967 " removed
3968 call setloclist(0, [], 'f')
3969 call assert_false(bufexists(qfbnum))
Bram Moolenaar647e24b2019-03-17 16:39:46 +01003970 call assert_equal(0, getloclist(0, {'qfbufnr' : 0}).qfbufnr)
Bram Moolenaareeb1b9c2019-02-10 22:59:04 +01003971
3972 " When the location list is freed with the location list window open, the
3973 " location list buffer should not be lost. It should be reused when the
3974 " location list is again populated.
3975 lexpr "F1:10:Line10"
3976 lopen
3977 let wid = win_getid()
3978 let qfbnum = bufnr('')
3979 wincmd p
3980 call setloclist(0, [], 'f')
3981 lexpr "F1:10:Line10"
3982 lopen
3983 call assert_equal(wid, win_getid())
3984 call assert_equal(qfbnum, bufnr(''))
3985 lclose
3986
3987 " When the window with the location list is closed, the buffer should be
3988 " removed
Bram Moolenaaree8188f2019-02-05 21:23:04 +01003989 new | only
Bram Moolenaareeb1b9c2019-02-10 22:59:04 +01003990 call assert_false(bufexists(qfbnum))
Bram Moolenaaree8188f2019-02-05 21:23:04 +01003991 endif
3992endfunc
3993
3994func Test_qfbuf()
3995 call Xqfbuf_test('c')
3996 call Xqfbuf_test('l')
3997endfunc
Bram Moolenaareeb1b9c2019-02-10 22:59:04 +01003998
3999" If there is an autocmd to use only one window, then opening the location
4000" list window used to crash Vim.
4001func Test_winonly_autocmd()
4002 call s:create_test_file('Xtest1')
4003 " Autocmd to show only one Vim window at a time
4004 autocmd WinEnter * only
4005 new
4006 " Load the location list
4007 lexpr "Xtest1:5:Line5\nXtest1:10:Line10\nXtest1:15:Line15"
4008 let loclistid = getloclist(0, {'id' : 0}).id
4009 " Open the location list window. Only this window will be shown and the file
4010 " window is closed.
4011 lopen
4012 call assert_equal(loclistid, getloclist(0, {'id' : 0}).id)
4013 " Jump to an entry in the location list and make sure that the cursor is
4014 " positioned correctly.
4015 ll 3
4016 call assert_equal(loclistid, getloclist(0, {'id' : 0}).id)
4017 call assert_equal('Xtest1', bufname(''))
4018 call assert_equal(15, line('.'))
4019 " Cleanup
4020 autocmd! WinEnter
4021 new | only
4022 call delete('Xtest1')
4023endfunc
Bram Moolenaar39803d82019-04-07 12:04:51 +02004024
4025" Test to make sure that an empty quickfix buffer is not reused for loading
4026" a normal buffer.
4027func Test_empty_qfbuf()
4028 enew | only
4029 call writefile(["Test"], 'Xfile1')
4030 call setqflist([], 'f')
4031 copen | only
4032 let qfbuf = bufnr('')
4033 edit Xfile1
4034 call assert_notequal(qfbuf, bufnr(''))
4035 enew
4036 call delete('Xfile1')
4037endfunc