blob: e0ab2b3aa2a3691e599c26d5f29b2b35e9de934a [file] [log] [blame]
Bram Moolenaareeb1b9c2019-02-10 22:59:04 +01001" Test for the quickfix feature.
Bram Moolenaarda59dd52016-01-05 21:59:58 +01002
Bram Moolenaarb46fecd2019-06-15 17:58:09 +02003source check.vim
4CheckFeature quickfix
Bram Moolenaarda59dd52016-01-05 21:59:58 +01005
Bram Moolenaare00fdf32019-09-15 19:09:42 +02006source screendump.vim
7
Bram Moolenaar7eba3d22016-03-19 22:54:09 +01008set encoding=utf-8
9
Bram Moolenaar2b946c92016-11-12 18:14:44 +010010func s:setup_commands(cchar)
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +020011 if a:cchar == 'c'
12 command! -nargs=* -bang Xlist <mods>clist<bang> <args>
13 command! -nargs=* Xgetexpr <mods>cgetexpr <args>
Bram Moolenaar361c8f02016-07-02 15:41:47 +020014 command! -nargs=* Xaddexpr <mods>caddexpr <args>
Bram Moolenaar55b69262017-08-13 13:42:01 +020015 command! -nargs=* -count Xolder <mods><count>colder <args>
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +020016 command! -nargs=* Xnewer <mods>cnewer <args>
17 command! -nargs=* Xopen <mods>copen <args>
18 command! -nargs=* Xwindow <mods>cwindow <args>
Bram Moolenaar537ef082016-07-09 17:56:19 +020019 command! -nargs=* Xbottom <mods>cbottom <args>
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +020020 command! -nargs=* Xclose <mods>cclose <args>
21 command! -nargs=* -bang Xfile <mods>cfile<bang> <args>
22 command! -nargs=* Xgetfile <mods>cgetfile <args>
23 command! -nargs=* Xaddfile <mods>caddfile <args>
24 command! -nargs=* -bang Xbuffer <mods>cbuffer<bang> <args>
25 command! -nargs=* Xgetbuffer <mods>cgetbuffer <args>
26 command! -nargs=* Xaddbuffer <mods>caddbuffer <args>
27 command! -nargs=* Xrewind <mods>crewind <args>
Bram Moolenaar99895ea2017-04-20 22:44:47 +020028 command! -count -nargs=* -bang Xnext <mods><count>cnext<bang> <args>
29 command! -count -nargs=* -bang Xprev <mods><count>cprev<bang> <args>
Bram Moolenaar0fcc7c62016-07-02 21:22:52 +020030 command! -nargs=* -bang Xfirst <mods>cfirst<bang> <args>
31 command! -nargs=* -bang Xlast <mods>clast<bang> <args>
Bram Moolenaar25190db2019-05-04 15:05:28 +020032 command! -count -nargs=* -bang Xnfile <mods><count>cnfile<bang> <args>
Bram Moolenaar0fcc7c62016-07-02 21:22:52 +020033 command! -nargs=* -bang Xpfile <mods>cpfile<bang> <args>
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +020034 command! -nargs=* Xexpr <mods>cexpr <args>
Bram Moolenaaree85df32017-03-19 14:19:50 +010035 command! -range -nargs=* Xvimgrep <mods><count>vimgrep <args>
36 command! -nargs=* Xvimgrepadd <mods>vimgrepadd <args>
Bram Moolenaar049cba92016-06-26 14:38:04 +020037 command! -nargs=* Xgrep <mods> grep <args>
38 command! -nargs=* Xgrepadd <mods> grepadd <args>
39 command! -nargs=* Xhelpgrep helpgrep <args>
Bram Moolenaar74240d32017-12-10 15:26:15 +010040 command! -nargs=0 -count Xcc <count>cc
Bram Moolenaar3ff33112019-05-03 21:56:35 +020041 command! -count=1 -nargs=0 Xbelow <mods><count>cbelow
42 command! -count=1 -nargs=0 Xabove <mods><count>cabove
Bram Moolenaarcf6a55c2019-05-05 15:02:30 +020043 command! -count=1 -nargs=0 Xbefore <mods><count>cbefore
44 command! -count=1 -nargs=0 Xafter <mods><count>cafter
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +020045 let g:Xgetlist = function('getqflist')
46 let g:Xsetlist = function('setqflist')
Bram Moolenaarb6fa30c2017-03-29 14:19:25 +020047 call setqflist([], 'f')
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +020048 else
49 command! -nargs=* -bang Xlist <mods>llist<bang> <args>
50 command! -nargs=* Xgetexpr <mods>lgetexpr <args>
Bram Moolenaar361c8f02016-07-02 15:41:47 +020051 command! -nargs=* Xaddexpr <mods>laddexpr <args>
Bram Moolenaar55b69262017-08-13 13:42:01 +020052 command! -nargs=* -count Xolder <mods><count>lolder <args>
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +020053 command! -nargs=* Xnewer <mods>lnewer <args>
54 command! -nargs=* Xopen <mods>lopen <args>
55 command! -nargs=* Xwindow <mods>lwindow <args>
Bram Moolenaar537ef082016-07-09 17:56:19 +020056 command! -nargs=* Xbottom <mods>lbottom <args>
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +020057 command! -nargs=* Xclose <mods>lclose <args>
58 command! -nargs=* -bang Xfile <mods>lfile<bang> <args>
59 command! -nargs=* Xgetfile <mods>lgetfile <args>
60 command! -nargs=* Xaddfile <mods>laddfile <args>
61 command! -nargs=* -bang Xbuffer <mods>lbuffer<bang> <args>
62 command! -nargs=* Xgetbuffer <mods>lgetbuffer <args>
63 command! -nargs=* Xaddbuffer <mods>laddbuffer <args>
64 command! -nargs=* Xrewind <mods>lrewind <args>
Bram Moolenaar99895ea2017-04-20 22:44:47 +020065 command! -count -nargs=* -bang Xnext <mods><count>lnext<bang> <args>
66 command! -count -nargs=* -bang Xprev <mods><count>lprev<bang> <args>
Bram Moolenaar0fcc7c62016-07-02 21:22:52 +020067 command! -nargs=* -bang Xfirst <mods>lfirst<bang> <args>
68 command! -nargs=* -bang Xlast <mods>llast<bang> <args>
Bram Moolenaar25190db2019-05-04 15:05:28 +020069 command! -count -nargs=* -bang Xnfile <mods><count>lnfile<bang> <args>
Bram Moolenaar0fcc7c62016-07-02 21:22:52 +020070 command! -nargs=* -bang Xpfile <mods>lpfile<bang> <args>
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +020071 command! -nargs=* Xexpr <mods>lexpr <args>
Bram Moolenaaree85df32017-03-19 14:19:50 +010072 command! -range -nargs=* Xvimgrep <mods><count>lvimgrep <args>
73 command! -nargs=* Xvimgrepadd <mods>lvimgrepadd <args>
Bram Moolenaar049cba92016-06-26 14:38:04 +020074 command! -nargs=* Xgrep <mods> lgrep <args>
75 command! -nargs=* Xgrepadd <mods> lgrepadd <args>
76 command! -nargs=* Xhelpgrep lhelpgrep <args>
Bram Moolenaar74240d32017-12-10 15:26:15 +010077 command! -nargs=0 -count Xcc <count>ll
Bram Moolenaar3ff33112019-05-03 21:56:35 +020078 command! -count=1 -nargs=0 Xbelow <mods><count>lbelow
79 command! -count=1 -nargs=0 Xabove <mods><count>labove
Bram Moolenaarcf6a55c2019-05-05 15:02:30 +020080 command! -count=1 -nargs=0 Xbefore <mods><count>lbefore
81 command! -count=1 -nargs=0 Xafter <mods><count>lafter
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +020082 let g:Xgetlist = function('getloclist', [0])
83 let g:Xsetlist = function('setloclist', [0])
Bram Moolenaarb6fa30c2017-03-29 14:19:25 +020084 call setloclist(0, [], 'f')
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +020085 endif
Bram Moolenaar2b946c92016-11-12 18:14:44 +010086endfunc
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +020087
Bram Moolenaarda59dd52016-01-05 21:59:58 +010088" Tests for the :clist and :llist commands
Bram Moolenaar2b946c92016-11-12 18:14:44 +010089func XlistTests(cchar)
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +020090 call s:setup_commands(a:cchar)
Bram Moolenaarda59dd52016-01-05 21:59:58 +010091
Bram Moolenaarb6fa30c2017-03-29 14:19:25 +020092 if a:cchar == 'l'
93 call assert_fails('llist', 'E776:')
94 endif
Bram Moolenaarda59dd52016-01-05 21:59:58 +010095 " With an empty list, command should return error
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +020096 Xgetexpr []
97 silent! Xlist
Bram Moolenaarda59dd52016-01-05 21:59:58 +010098 call assert_true(v:errmsg ==# 'E42: No Errors')
99
100 " Populate the list and then try
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +0200101 Xgetexpr ['non-error 1', 'Xtestfile1:1:3:Line1',
Bram Moolenaarda59dd52016-01-05 21:59:58 +0100102 \ 'non-error 2', 'Xtestfile2:2:2:Line2',
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +0200103 \ 'non-error 3', 'Xtestfile3:3:1:Line3']
Bram Moolenaarda59dd52016-01-05 21:59:58 +0100104
105 " List only valid entries
Bram Moolenaaree85df32017-03-19 14:19:50 +0100106 let l = split(execute('Xlist', ''), "\n")
Bram Moolenaarda59dd52016-01-05 21:59:58 +0100107 call assert_equal([' 2 Xtestfile1:1 col 3: Line1',
108 \ ' 4 Xtestfile2:2 col 2: Line2',
109 \ ' 6 Xtestfile3:3 col 1: Line3'], l)
110
111 " List all the entries
Bram Moolenaaree85df32017-03-19 14:19:50 +0100112 let l = split(execute('Xlist!', ''), "\n")
Bram Moolenaarda59dd52016-01-05 21:59:58 +0100113 call assert_equal([' 1: non-error 1', ' 2 Xtestfile1:1 col 3: Line1',
114 \ ' 3: non-error 2', ' 4 Xtestfile2:2 col 2: Line2',
115 \ ' 5: non-error 3', ' 6 Xtestfile3:3 col 1: Line3'], l)
116
117 " List a range of errors
Bram Moolenaaree85df32017-03-19 14:19:50 +0100118 let l = split(execute('Xlist 3,6', ''), "\n")
Bram Moolenaarda59dd52016-01-05 21:59:58 +0100119 call assert_equal([' 4 Xtestfile2:2 col 2: Line2',
120 \ ' 6 Xtestfile3:3 col 1: Line3'], l)
121
Bram Moolenaaree85df32017-03-19 14:19:50 +0100122 let l = split(execute('Xlist! 3,4', ''), "\n")
Bram Moolenaarda59dd52016-01-05 21:59:58 +0100123 call assert_equal([' 3: non-error 2', ' 4 Xtestfile2:2 col 2: Line2'], l)
124
Bram Moolenaaree85df32017-03-19 14:19:50 +0100125 let l = split(execute('Xlist -6,-4', ''), "\n")
Bram Moolenaarda59dd52016-01-05 21:59:58 +0100126 call assert_equal([' 2 Xtestfile1:1 col 3: Line1'], l)
127
Bram Moolenaaree85df32017-03-19 14:19:50 +0100128 let l = split(execute('Xlist! -5,-3', ''), "\n")
Bram Moolenaarda59dd52016-01-05 21:59:58 +0100129 call assert_equal([' 2 Xtestfile1:1 col 3: Line1',
130 \ ' 3: non-error 2', ' 4 Xtestfile2:2 col 2: Line2'], l)
Bram Moolenaar391b1dd2017-03-04 13:47:11 +0100131
132 " Test for '+'
Bram Moolenaaree85df32017-03-19 14:19:50 +0100133 let l = split(execute('Xlist! +2', ''), "\n")
Bram Moolenaar391b1dd2017-03-04 13:47:11 +0100134 call assert_equal([' 2 Xtestfile1:1 col 3: Line1',
135 \ ' 3: non-error 2', ' 4 Xtestfile2:2 col 2: Line2'], l)
Bram Moolenaaree85df32017-03-19 14:19:50 +0100136
137 " Different types of errors
138 call g:Xsetlist([{'lnum':10,'col':5,'type':'W', 'text':'Warning','nr':11},
139 \ {'lnum':20,'col':10,'type':'e','text':'Error','nr':22},
140 \ {'lnum':30,'col':15,'type':'i','text':'Info','nr':33},
141 \ {'lnum':40,'col':20,'type':'x', 'text':'Other','nr':44},
142 \ {'lnum':50,'col':25,'type':"\<C-A>",'text':'one','nr':55}])
143 let l = split(execute('Xlist', ""), "\n")
144 call assert_equal([' 1:10 col 5 warning 11: Warning',
145 \ ' 2:20 col 10 error 22: Error',
146 \ ' 3:30 col 15 info 33: Info',
147 \ ' 4:40 col 20 x 44: Other',
148 \ ' 5:50 col 25 55: one'], l)
149
Bram Moolenaard76ce852018-05-01 15:02:04 +0200150 " Test for module names, one needs to explicitly set `'valid':v:true` so
151 call g:Xsetlist([
152 \ {'lnum':10,'col':5,'type':'W','module':'Data.Text','text':'ModuleWarning','nr':11,'valid':v:true},
153 \ {'lnum':20,'col':10,'type':'W','module':'Data.Text','filename':'Data/Text.hs','text':'ModuleWarning','nr':22,'valid':v:true},
154 \ {'lnum':30,'col':15,'type':'W','filename':'Data/Text.hs','text':'FileWarning','nr':33,'valid':v:true}])
155 let l = split(execute('Xlist', ""), "\n")
156 call assert_equal([' 1 Data.Text:10 col 5 warning 11: ModuleWarning',
157 \ ' 2 Data.Text:20 col 10 warning 22: ModuleWarning',
158 \ ' 3 Data/Text.hs:30 col 15 warning 33: FileWarning'], l)
159
Bram Moolenaaree85df32017-03-19 14:19:50 +0100160 " Error cases
161 call assert_fails('Xlist abc', 'E488:')
Bram Moolenaar2b946c92016-11-12 18:14:44 +0100162endfunc
Bram Moolenaarda59dd52016-01-05 21:59:58 +0100163
Bram Moolenaar2b946c92016-11-12 18:14:44 +0100164func Test_clist()
Bram Moolenaarda59dd52016-01-05 21:59:58 +0100165 call XlistTests('c')
166 call XlistTests('l')
Bram Moolenaar2b946c92016-11-12 18:14:44 +0100167endfunc
Bram Moolenaarda59dd52016-01-05 21:59:58 +0100168
169" Tests for the :colder, :cnewer, :lolder and :lnewer commands
170" Note that this test assumes that a quickfix/location list is
Bram Moolenaarcfc0a352016-01-09 20:23:00 +0100171" already set by the caller.
Bram Moolenaar2b946c92016-11-12 18:14:44 +0100172func XageTests(cchar)
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +0200173 call s:setup_commands(a:cchar)
Bram Moolenaarda59dd52016-01-05 21:59:58 +0100174
Bram Moolenaar87f59b02019-04-04 14:04:11 +0200175 if a:cchar == 'l'
176 " No location list for the current window
177 call assert_fails('lolder', 'E776:')
178 call assert_fails('lnewer', 'E776:')
179 endif
180
Bram Moolenaarcf1ba352017-10-27 00:55:04 +0200181 let list = [{'bufnr': bufnr('%'), 'lnum': 1}]
Bram Moolenaarb6fa30c2017-03-29 14:19:25 +0200182 call g:Xsetlist(list)
183
Bram Moolenaarda59dd52016-01-05 21:59:58 +0100184 " Jumping to a non existent list should return error
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +0200185 silent! Xolder 99
Bram Moolenaarda59dd52016-01-05 21:59:58 +0100186 call assert_true(v:errmsg ==# 'E380: At bottom of quickfix stack')
187
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +0200188 silent! Xnewer 99
Bram Moolenaarda59dd52016-01-05 21:59:58 +0100189 call assert_true(v:errmsg ==# 'E381: At top of quickfix stack')
190
191 " Add three quickfix/location lists
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +0200192 Xgetexpr ['Xtestfile1:1:3:Line1']
193 Xgetexpr ['Xtestfile2:2:2:Line2']
194 Xgetexpr ['Xtestfile3:3:1:Line3']
Bram Moolenaarda59dd52016-01-05 21:59:58 +0100195
196 " Go back two lists
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +0200197 Xolder
198 let l = g:Xgetlist()
Bram Moolenaarda59dd52016-01-05 21:59:58 +0100199 call assert_equal('Line2', l[0].text)
200
201 " Go forward two lists
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +0200202 Xnewer
203 let l = g:Xgetlist()
Bram Moolenaarda59dd52016-01-05 21:59:58 +0100204 call assert_equal('Line3', l[0].text)
205
206 " Test for the optional count argument
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +0200207 Xolder 2
208 let l = g:Xgetlist()
Bram Moolenaarda59dd52016-01-05 21:59:58 +0100209 call assert_equal('Line1', l[0].text)
210
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +0200211 Xnewer 2
212 let l = g:Xgetlist()
Bram Moolenaarda59dd52016-01-05 21:59:58 +0100213 call assert_equal('Line3', l[0].text)
Bram Moolenaar2b946c92016-11-12 18:14:44 +0100214endfunc
Bram Moolenaarda59dd52016-01-05 21:59:58 +0100215
Bram Moolenaar2b946c92016-11-12 18:14:44 +0100216func Test_cage()
Bram Moolenaarda59dd52016-01-05 21:59:58 +0100217 call XageTests('c')
218 call XageTests('l')
Bram Moolenaar2b946c92016-11-12 18:14:44 +0100219endfunc
Bram Moolenaarda59dd52016-01-05 21:59:58 +0100220
221" Tests for the :cwindow, :lwindow :cclose, :lclose, :copen and :lopen
222" commands
Bram Moolenaar2b946c92016-11-12 18:14:44 +0100223func XwindowTests(cchar)
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +0200224 call s:setup_commands(a:cchar)
Bram Moolenaarda59dd52016-01-05 21:59:58 +0100225
Bram Moolenaarb6fa30c2017-03-29 14:19:25 +0200226 " Opening the location list window without any errors should fail
227 if a:cchar == 'l'
228 call assert_fails('lopen', 'E776:')
229 endif
230
Bram Moolenaarda59dd52016-01-05 21:59:58 +0100231 " Create a list with no valid entries
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +0200232 Xgetexpr ['non-error 1', 'non-error 2', 'non-error 3']
Bram Moolenaarda59dd52016-01-05 21:59:58 +0100233
234 " Quickfix/Location window should not open with no valid errors
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +0200235 Xwindow
Bram Moolenaarda59dd52016-01-05 21:59:58 +0100236 call assert_true(winnr('$') == 1)
237
238 " Create a list with valid entries
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +0200239 Xgetexpr ['Xtestfile1:1:3:Line1', 'Xtestfile2:2:2:Line2',
240 \ 'Xtestfile3:3:1:Line3']
Bram Moolenaarda59dd52016-01-05 21:59:58 +0100241
242 " Open the window
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +0200243 Xwindow
Bram Moolenaarda59dd52016-01-05 21:59:58 +0100244 call assert_true(winnr('$') == 2 && winnr() == 2 &&
245 \ getline('.') ==# 'Xtestfile1|1 col 3| Line1')
Bram Moolenaar537ef082016-07-09 17:56:19 +0200246 redraw!
Bram Moolenaarda59dd52016-01-05 21:59:58 +0100247
248 " Close the window
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +0200249 Xclose
Bram Moolenaarda59dd52016-01-05 21:59:58 +0100250 call assert_true(winnr('$') == 1)
251
252 " Create a list with no valid entries
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +0200253 Xgetexpr ['non-error 1', 'non-error 2', 'non-error 3']
Bram Moolenaarda59dd52016-01-05 21:59:58 +0100254
255 " Open the window
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +0200256 Xopen 5
Bram Moolenaarda59dd52016-01-05 21:59:58 +0100257 call assert_true(winnr('$') == 2 && getline('.') ==# '|| non-error 1'
258 \ && winheight('.') == 5)
259
260 " Opening the window again, should move the cursor to that window
261 wincmd t
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +0200262 Xopen 7
Bram Moolenaarda59dd52016-01-05 21:59:58 +0100263 call assert_true(winnr('$') == 2 && winnr() == 2 &&
264 \ winheight('.') == 7 &&
265 \ getline('.') ==# '|| non-error 1')
266
267
268 " Calling cwindow should close the quickfix window with no valid errors
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +0200269 Xwindow
Bram Moolenaarda59dd52016-01-05 21:59:58 +0100270 call assert_true(winnr('$') == 1)
Bram Moolenaarb6fa30c2017-03-29 14:19:25 +0200271
272 if a:cchar == 'c'
273 " Opening the quickfix window in multiple tab pages should reuse the
274 " quickfix buffer
275 Xgetexpr ['Xtestfile1:1:3:Line1', 'Xtestfile2:2:2:Line2',
276 \ 'Xtestfile3:3:1:Line3']
277 Xopen
278 let qfbufnum = bufnr('%')
279 tabnew
280 Xopen
281 call assert_equal(qfbufnum, bufnr('%'))
282 new | only | tabonly
283 endif
Bram Moolenaar2b946c92016-11-12 18:14:44 +0100284endfunc
Bram Moolenaarda59dd52016-01-05 21:59:58 +0100285
Bram Moolenaar2b946c92016-11-12 18:14:44 +0100286func Test_cwindow()
Bram Moolenaarda59dd52016-01-05 21:59:58 +0100287 call XwindowTests('c')
288 call XwindowTests('l')
Bram Moolenaar2b946c92016-11-12 18:14:44 +0100289endfunc
Bram Moolenaarda59dd52016-01-05 21:59:58 +0100290
Bram Moolenaar36d50222019-05-02 20:17:40 +0200291func Test_copenHeight()
292 copen
293 wincmd H
294 let height = winheight(0)
295 copen 10
296 call assert_equal(height, winheight(0))
297 quit
298endfunc
299
Bram Moolenaarda59dd52016-01-05 21:59:58 +0100300" Tests for the :cfile, :lfile, :caddfile, :laddfile, :cgetfile and :lgetfile
301" commands.
Bram Moolenaar2b946c92016-11-12 18:14:44 +0100302func XfileTests(cchar)
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +0200303 call s:setup_commands(a:cchar)
Bram Moolenaarda59dd52016-01-05 21:59:58 +0100304
305 call writefile(['Xtestfile1:700:10:Line 700',
306 \ 'Xtestfile2:800:15:Line 800'], 'Xqftestfile1')
307
308 enew!
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +0200309 Xfile Xqftestfile1
310 let l = g:Xgetlist()
Bram Moolenaarda59dd52016-01-05 21:59:58 +0100311 call assert_true(len(l) == 2 &&
312 \ l[0].lnum == 700 && l[0].col == 10 && l[0].text ==# 'Line 700' &&
313 \ l[1].lnum == 800 && l[1].col == 15 && l[1].text ==# 'Line 800')
314
Bram Moolenaar049cba92016-06-26 14:38:04 +0200315 " Test with a non existent file
316 call assert_fails('Xfile non_existent_file', 'E40')
317
Bram Moolenaarda59dd52016-01-05 21:59:58 +0100318 " Run cfile/lfile from a modified buffer
319 enew!
320 silent! put ='Quickfix'
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +0200321 silent! Xfile Xqftestfile1
Bram Moolenaarda59dd52016-01-05 21:59:58 +0100322 call assert_true(v:errmsg ==# 'E37: No write since last change (add ! to override)')
323
324 call writefile(['Xtestfile3:900:30:Line 900'], 'Xqftestfile1')
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +0200325 Xaddfile Xqftestfile1
326 let l = g:Xgetlist()
Bram Moolenaarda59dd52016-01-05 21:59:58 +0100327 call assert_true(len(l) == 3 &&
328 \ l[2].lnum == 900 && l[2].col == 30 && l[2].text ==# 'Line 900')
329
330 call writefile(['Xtestfile1:222:77:Line 222',
331 \ 'Xtestfile2:333:88:Line 333'], 'Xqftestfile1')
332
333 enew!
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +0200334 Xgetfile Xqftestfile1
335 let l = g:Xgetlist()
Bram Moolenaarda59dd52016-01-05 21:59:58 +0100336 call assert_true(len(l) == 2 &&
337 \ l[0].lnum == 222 && l[0].col == 77 && l[0].text ==# 'Line 222' &&
338 \ l[1].lnum == 333 && l[1].col == 88 && l[1].text ==# 'Line 333')
339
340 call delete('Xqftestfile1')
Bram Moolenaar2b946c92016-11-12 18:14:44 +0100341endfunc
Bram Moolenaarda59dd52016-01-05 21:59:58 +0100342
Bram Moolenaar2b946c92016-11-12 18:14:44 +0100343func Test_cfile()
Bram Moolenaarda59dd52016-01-05 21:59:58 +0100344 call XfileTests('c')
345 call XfileTests('l')
Bram Moolenaar2b946c92016-11-12 18:14:44 +0100346endfunc
Bram Moolenaarda59dd52016-01-05 21:59:58 +0100347
348" Tests for the :cbuffer, :lbuffer, :caddbuffer, :laddbuffer, :cgetbuffer and
349" :lgetbuffer commands.
Bram Moolenaar2b946c92016-11-12 18:14:44 +0100350func XbufferTests(cchar)
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +0200351 call s:setup_commands(a:cchar)
Bram Moolenaarda59dd52016-01-05 21:59:58 +0100352
353 enew!
354 silent! call setline(1, ['Xtestfile7:700:10:Line 700',
355 \ 'Xtestfile8:800:15:Line 800'])
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +0200356 Xbuffer!
357 let l = g:Xgetlist()
Bram Moolenaarda59dd52016-01-05 21:59:58 +0100358 call assert_true(len(l) == 2 &&
359 \ l[0].lnum == 700 && l[0].col == 10 && l[0].text ==# 'Line 700' &&
360 \ l[1].lnum == 800 && l[1].col == 15 && l[1].text ==# 'Line 800')
361
362 enew!
363 silent! call setline(1, ['Xtestfile9:900:55:Line 900',
364 \ 'Xtestfile10:950:66:Line 950'])
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +0200365 Xgetbuffer
366 let l = g:Xgetlist()
Bram Moolenaarda59dd52016-01-05 21:59:58 +0100367 call assert_true(len(l) == 2 &&
368 \ l[0].lnum == 900 && l[0].col == 55 && l[0].text ==# 'Line 900' &&
369 \ l[1].lnum == 950 && l[1].col == 66 && l[1].text ==# 'Line 950')
370
371 enew!
372 silent! call setline(1, ['Xtestfile11:700:20:Line 700',
373 \ 'Xtestfile12:750:25:Line 750'])
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +0200374 Xaddbuffer
375 let l = g:Xgetlist()
Bram Moolenaarda59dd52016-01-05 21:59:58 +0100376 call assert_true(len(l) == 4 &&
377 \ l[1].lnum == 950 && l[1].col == 66 && l[1].text ==# 'Line 950' &&
378 \ l[2].lnum == 700 && l[2].col == 20 && l[2].text ==# 'Line 700' &&
379 \ l[3].lnum == 750 && l[3].col == 25 && l[3].text ==# 'Line 750')
Bram Moolenaarab47c612016-06-14 22:02:26 +0200380 enew!
Bram Moolenaarda59dd52016-01-05 21:59:58 +0100381
Bram Moolenaaree85df32017-03-19 14:19:50 +0100382 " Check for invalid buffer
383 call assert_fails('Xbuffer 199', 'E474:')
384
385 " Check for unloaded buffer
386 edit Xtestfile1
387 let bnr = bufnr('%')
388 enew!
389 call assert_fails('Xbuffer ' . bnr, 'E681:')
390
391 " Check for invalid range
392 " Using Xbuffer will not run the range check in the cbuffer/lbuffer
393 " commands. So directly call the commands.
394 if (a:cchar == 'c')
395 call assert_fails('900,999cbuffer', 'E16:')
396 else
397 call assert_fails('900,999lbuffer', 'E16:')
398 endif
Bram Moolenaar2b946c92016-11-12 18:14:44 +0100399endfunc
Bram Moolenaarda59dd52016-01-05 21:59:58 +0100400
Bram Moolenaar2b946c92016-11-12 18:14:44 +0100401func Test_cbuffer()
Bram Moolenaarda59dd52016-01-05 21:59:58 +0100402 call XbufferTests('c')
403 call XbufferTests('l')
Bram Moolenaar2b946c92016-11-12 18:14:44 +0100404endfunc
Bram Moolenaarda59dd52016-01-05 21:59:58 +0100405
Bram Moolenaar2b946c92016-11-12 18:14:44 +0100406func XexprTests(cchar)
Bram Moolenaar0fcc7c62016-07-02 21:22:52 +0200407 call s:setup_commands(a:cchar)
408
409 call assert_fails('Xexpr 10', 'E777:')
Bram Moolenaar2b946c92016-11-12 18:14:44 +0100410endfunc
Bram Moolenaar0fcc7c62016-07-02 21:22:52 +0200411
Bram Moolenaar2b946c92016-11-12 18:14:44 +0100412func Test_cexpr()
Bram Moolenaar0fcc7c62016-07-02 21:22:52 +0200413 call XexprTests('c')
414 call XexprTests('l')
Bram Moolenaar2b946c92016-11-12 18:14:44 +0100415endfunc
Bram Moolenaar0fcc7c62016-07-02 21:22:52 +0200416
417" Tests for :cnext, :cprev, :cfirst, :clast commands
Bram Moolenaar2b946c92016-11-12 18:14:44 +0100418func Xtest_browse(cchar)
Bram Moolenaar0fcc7c62016-07-02 21:22:52 +0200419 call s:setup_commands(a:cchar)
420
Bram Moolenaar74240d32017-12-10 15:26:15 +0100421 call g:Xsetlist([], 'f')
Bram Moolenaarb6fa30c2017-03-29 14:19:25 +0200422 " Jumping to first or next location list entry without any error should
423 " result in failure
Bram Moolenaar74240d32017-12-10 15:26:15 +0100424 if a:cchar == 'c'
425 let err = 'E42:'
426 else
427 let err = 'E776:'
Bram Moolenaarb6fa30c2017-03-29 14:19:25 +0200428 endif
Bram Moolenaar74240d32017-12-10 15:26:15 +0100429 call assert_fails('Xnext', err)
430 call assert_fails('Xprev', err)
431 call assert_fails('Xnfile', err)
432 call assert_fails('Xpfile', err)
Bram Moolenaarb6fa30c2017-03-29 14:19:25 +0200433
Bram Moolenaar0fcc7c62016-07-02 21:22:52 +0200434 call s:create_test_file('Xqftestfile1')
435 call s:create_test_file('Xqftestfile2')
436
437 Xgetexpr ['Xqftestfile1:5:Line5',
438 \ 'Xqftestfile1:6:Line6',
439 \ 'Xqftestfile2:10:Line10',
Bram Moolenaar99895ea2017-04-20 22:44:47 +0200440 \ 'Xqftestfile2:11:Line11',
441 \ 'RegularLine1',
442 \ 'RegularLine2']
Bram Moolenaar0fcc7c62016-07-02 21:22:52 +0200443
444 Xfirst
445 call assert_fails('Xprev', 'E553')
446 call assert_fails('Xpfile', 'E553')
447 Xnfile
448 call assert_equal('Xqftestfile2', bufname('%'))
449 call assert_equal(10, line('.'))
450 Xpfile
451 call assert_equal('Xqftestfile1', bufname('%'))
452 call assert_equal(6, line('.'))
Bram Moolenaar74240d32017-12-10 15:26:15 +0100453 5Xcc
454 call assert_equal(5, g:Xgetlist({'idx':0}).idx)
455 2Xcc
456 call assert_equal(2, g:Xgetlist({'idx':0}).idx)
457 10Xcc
458 call assert_equal(6, g:Xgetlist({'idx':0}).idx)
Bram Moolenaar0fcc7c62016-07-02 21:22:52 +0200459 Xlast
Bram Moolenaar99895ea2017-04-20 22:44:47 +0200460 Xprev
Bram Moolenaar0fcc7c62016-07-02 21:22:52 +0200461 call assert_equal('Xqftestfile2', bufname('%'))
462 call assert_equal(11, line('.'))
463 call assert_fails('Xnext', 'E553')
464 call assert_fails('Xnfile', 'E553')
465 Xrewind
466 call assert_equal('Xqftestfile1', bufname('%'))
467 call assert_equal(5, line('.'))
468
Bram Moolenaar99895ea2017-04-20 22:44:47 +0200469 10Xnext
470 call assert_equal('Xqftestfile2', bufname('%'))
471 call assert_equal(11, line('.'))
472 10Xprev
473 call assert_equal('Xqftestfile1', bufname('%'))
474 call assert_equal(5, line('.'))
475
Bram Moolenaar74240d32017-12-10 15:26:15 +0100476 " Jumping to an error from the error window using cc command
477 Xgetexpr ['Xqftestfile1:5:Line5',
478 \ 'Xqftestfile1:6:Line6',
479 \ 'Xqftestfile2:10:Line10',
480 \ 'Xqftestfile2:11:Line11']
481 Xopen
482 10Xcc
483 call assert_equal(11, line('.'))
484 call assert_equal('Xqftestfile2', bufname('%'))
485
486 " Jumping to an error from the error window (when only the error window is
487 " present)
488 Xopen | only
489 Xlast 1
490 call assert_equal(5, line('.'))
491 call assert_equal('Xqftestfile1', bufname('%'))
492
Bram Moolenaaree85df32017-03-19 14:19:50 +0100493 Xexpr ""
494 call assert_fails('Xnext', 'E42:')
495
Bram Moolenaar0fcc7c62016-07-02 21:22:52 +0200496 call delete('Xqftestfile1')
497 call delete('Xqftestfile2')
Bram Moolenaarfc2b2702017-09-15 22:43:07 +0200498
499 " Should be able to use next/prev with invalid entries
500 Xexpr ""
501 call assert_equal(0, g:Xgetlist({'idx' : 0}).idx)
502 call assert_equal(0, g:Xgetlist({'size' : 0}).size)
503 Xaddexpr ['foo', 'bar', 'baz', 'quux', 'shmoo']
504 call assert_equal(5, g:Xgetlist({'size' : 0}).size)
505 Xlast
506 call assert_equal(5, g:Xgetlist({'idx' : 0}).idx)
507 Xfirst
508 call assert_equal(1, g:Xgetlist({'idx' : 0}).idx)
509 2Xnext
510 call assert_equal(3, g:Xgetlist({'idx' : 0}).idx)
Bram Moolenaar2b946c92016-11-12 18:14:44 +0100511endfunc
Bram Moolenaar0fcc7c62016-07-02 21:22:52 +0200512
Bram Moolenaar2b946c92016-11-12 18:14:44 +0100513func Test_browse()
Bram Moolenaar0fcc7c62016-07-02 21:22:52 +0200514 call Xtest_browse('c')
515 call Xtest_browse('l')
Bram Moolenaar2b946c92016-11-12 18:14:44 +0100516endfunc
Bram Moolenaar0fcc7c62016-07-02 21:22:52 +0200517
Bram Moolenaar2b946c92016-11-12 18:14:44 +0100518func Test_nomem()
Bram Moolenaar8e8df252016-05-25 21:23:21 +0200519 call test_alloc_fail(GetAllocId('qf_dirname_start'), 0, 0)
Bram Moolenaara260b872016-01-15 20:48:22 +0100520 call assert_fails('vimgrep vim runtest.vim', 'E342:')
Bram Moolenaar75bdf6a2016-01-07 21:25:08 +0100521
Bram Moolenaarce90e362019-09-08 18:58:44 +0200522 call GetAllocId('qf_dirname_now')->test_alloc_fail(0, 0)
Bram Moolenaara260b872016-01-15 20:48:22 +0100523 call assert_fails('vimgrep vim runtest.vim', 'E342:')
Bram Moolenaar75bdf6a2016-01-07 21:25:08 +0100524
Bram Moolenaar8e8df252016-05-25 21:23:21 +0200525 call test_alloc_fail(GetAllocId('qf_namebuf'), 0, 0)
Bram Moolenaara260b872016-01-15 20:48:22 +0100526 call assert_fails('cfile runtest.vim', 'E342:')
Bram Moolenaar75bdf6a2016-01-07 21:25:08 +0100527
Bram Moolenaar8e8df252016-05-25 21:23:21 +0200528 call test_alloc_fail(GetAllocId('qf_errmsg'), 0, 0)
Bram Moolenaara260b872016-01-15 20:48:22 +0100529 call assert_fails('cfile runtest.vim', 'E342:')
Bram Moolenaar75bdf6a2016-01-07 21:25:08 +0100530
Bram Moolenaar8e8df252016-05-25 21:23:21 +0200531 call test_alloc_fail(GetAllocId('qf_pattern'), 0, 0)
Bram Moolenaara260b872016-01-15 20:48:22 +0100532 call assert_fails('cfile runtest.vim', 'E342:')
Bram Moolenaar75bdf6a2016-01-07 21:25:08 +0100533
534endfunc
535
Bram Moolenaar2b946c92016-11-12 18:14:44 +0100536func s:test_xhelpgrep(cchar)
Bram Moolenaar049cba92016-06-26 14:38:04 +0200537 call s:setup_commands(a:cchar)
538 Xhelpgrep quickfix
539 Xopen
540 if a:cchar == 'c'
541 let title_text = ':helpgrep quickfix'
542 else
543 let title_text = ':lhelpgrep quickfix'
544 endif
545 call assert_true(w:quickfix_title =~ title_text, w:quickfix_title)
Bram Moolenaar99895ea2017-04-20 22:44:47 +0200546
547 " Jumping to a help topic should open the help window
548 only
549 Xnext
550 call assert_true(&buftype == 'help')
551 call assert_true(winnr('$') == 2)
552 " Jumping to the next match should reuse the help window
553 Xnext
554 call assert_true(&buftype == 'help')
555 call assert_true(winnr() == 1)
556 call assert_true(winnr('$') == 2)
557 " Jumping to the next match from the quickfix window should reuse the help
558 " window
559 Xopen
560 Xnext
561 call assert_true(&buftype == 'help')
562 call assert_true(winnr() == 1)
563 call assert_true(winnr('$') == 2)
564
Bram Moolenaar62ef7972016-01-19 14:51:54 +0100565 " This wipes out the buffer, make sure that doesn't cause trouble.
Bram Moolenaar049cba92016-06-26 14:38:04 +0200566 Xclose
Bram Moolenaaree85df32017-03-19 14:19:50 +0100567
Bram Moolenaarb4d5fba2017-09-11 19:31:28 +0200568 if a:cchar == 'l'
569 " When a help window is present, running :lhelpgrep should reuse the
570 " help window and not the current window
571 new | only
572 call g:Xsetlist([], 'f')
573 help index.txt
574 wincmd w
575 lhelpgrep quickfix
576 call assert_equal(1, winnr())
577 call assert_notequal([], getloclist(1))
578 call assert_equal([], getloclist(2))
579 endif
580
Bram Moolenaar99895ea2017-04-20 22:44:47 +0200581 new | only
582
Bram Moolenaaree85df32017-03-19 14:19:50 +0100583 " Search for non existing help string
584 call assert_fails('Xhelpgrep a1b2c3', 'E480:')
Bram Moolenaar108e7b42018-10-11 17:39:12 +0200585 " Invalid regular expression
586 call assert_fails('Xhelpgrep \@<!', 'E480:')
Bram Moolenaar2b946c92016-11-12 18:14:44 +0100587endfunc
Bram Moolenaar049cba92016-06-26 14:38:04 +0200588
Bram Moolenaar2b946c92016-11-12 18:14:44 +0100589func Test_helpgrep()
Bram Moolenaar049cba92016-06-26 14:38:04 +0200590 call s:test_xhelpgrep('c')
Bram Moolenaarcf25fdb2016-08-03 21:04:53 +0200591 helpclose
Bram Moolenaar049cba92016-06-26 14:38:04 +0200592 call s:test_xhelpgrep('l')
Bram Moolenaar62ef7972016-01-19 14:51:54 +0100593endfunc
Bram Moolenaar75bdf6a2016-01-07 21:25:08 +0100594
Bram Moolenaar6920c722016-01-22 22:44:10 +0100595func Test_errortitle()
596 augroup QfBufWinEnter
597 au!
598 au BufWinEnter * :let g:a=get(w:, 'quickfix_title', 'NONE')
599 augroup END
600 copen
601 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'')'}]
602 call setqflist(a)
603 call assert_equal(':setqflist()', g:a)
604 augroup QfBufWinEnter
605 au!
606 augroup END
607 augroup! QfBufWinEnter
608endfunc
Bram Moolenaare27dba42016-03-15 14:11:10 +0100609
Bram Moolenaar5584df62016-03-18 21:00:51 +0100610func Test_vimgreptitle()
611 augroup QfBufWinEnter
612 au!
613 au BufWinEnter * :let g:a=get(w:, 'quickfix_title', 'NONE')
614 augroup END
615 try
616 vimgrep /pattern/j file
617 catch /E480/
618 endtry
619 copen
620 call assert_equal(': vimgrep /pattern/j file', g:a)
621 augroup QfBufWinEnter
622 au!
623 augroup END
624 augroup! QfBufWinEnter
625endfunc
626
Bram Moolenaar2b946c92016-11-12 18:14:44 +0100627func XqfTitleTests(cchar)
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +0200628 call s:setup_commands(a:cchar)
Bram Moolenaare27dba42016-03-15 14:11:10 +0100629
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +0200630 Xgetexpr ['file:1:1:message']
631 let l = g:Xgetlist()
Bram Moolenaare27dba42016-03-15 14:11:10 +0100632 if a:cchar == 'c'
633 call setqflist(l, 'r')
634 else
635 call setloclist(0, l, 'r')
636 endif
637
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +0200638 Xopen
Bram Moolenaare27dba42016-03-15 14:11:10 +0100639 if a:cchar == 'c'
640 let title = ':setqflist()'
641 else
642 let title = ':setloclist()'
643 endif
644 call assert_equal(title, w:quickfix_title)
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +0200645 Xclose
Bram Moolenaar2b946c92016-11-12 18:14:44 +0100646endfunc
Bram Moolenaare27dba42016-03-15 14:11:10 +0100647
648" Tests for quickfix window's title
Bram Moolenaar2b946c92016-11-12 18:14:44 +0100649func Test_qf_title()
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +0200650 call XqfTitleTests('c')
651 call XqfTitleTests('l')
Bram Moolenaar2b946c92016-11-12 18:14:44 +0100652endfunc
Bram Moolenaare27dba42016-03-15 14:11:10 +0100653
654" Tests for 'errorformat'
Bram Moolenaar2b946c92016-11-12 18:14:44 +0100655func Test_efm()
Bram Moolenaare27dba42016-03-15 14:11:10 +0100656 let save_efm = &efm
657 set efm=%EEEE%m,%WWWW%m,%+CCCC%.%#,%-GGGG%.%#
658 cgetexpr ['WWWW', 'EEEE', 'CCCC']
659 let l = strtrans(string(map(getqflist(), '[v:val.text, v:val.valid]')))
660 call assert_equal("[['W', 1], ['E^@CCCC', 1]]", l)
661 cgetexpr ['WWWW', 'GGGG', 'EEEE', 'CCCC']
662 let l = strtrans(string(map(getqflist(), '[v:val.text, v:val.valid]')))
663 call assert_equal("[['W', 1], ['E^@CCCC', 1]]", l)
664 cgetexpr ['WWWW', 'GGGG', 'ZZZZ', 'EEEE', 'CCCC', 'YYYY']
665 let l = strtrans(string(map(getqflist(), '[v:val.text, v:val.valid]')))
666 call assert_equal("[['W', 1], ['ZZZZ', 0], ['E^@CCCC', 1], ['YYYY', 0]]", l)
667 let &efm = save_efm
Bram Moolenaar2b946c92016-11-12 18:14:44 +0100668endfunc
Bram Moolenaar1ff2b642016-03-17 22:07:02 +0100669
670" This will test for problems in quickfix:
671" A. incorrectly copying location lists which caused the location list to show
672" a different name than the file that was actually being displayed.
673" B. not reusing the window for which the location list window is opened but
674" instead creating new windows.
675" C. make sure that the location list window is not reused instead of the
676" window it belongs to.
677"
678" Set up the test environment:
Bram Moolenaar2b946c92016-11-12 18:14:44 +0100679func ReadTestProtocol(name)
Bram Moolenaar1ff2b642016-03-17 22:07:02 +0100680 let base = substitute(a:name, '\v^test://(.*)%(\.[^.]+)?', '\1', '')
681 let word = substitute(base, '\v(.*)\..*', '\1', '')
682
683 setl modifiable
684 setl noreadonly
685 setl noswapfile
686 setl bufhidden=delete
687 %del _
688 " For problem 2:
689 " 'buftype' has to be set to reproduce the constant opening of new windows
690 setl buftype=nofile
691
692 call setline(1, word)
693
694 setl nomodified
695 setl nomodifiable
696 setl readonly
697 exe 'doautocmd BufRead ' . substitute(a:name, '\v^test://(.*)', '\1', '')
Bram Moolenaar2b946c92016-11-12 18:14:44 +0100698endfunc
Bram Moolenaar1ff2b642016-03-17 22:07:02 +0100699
Bram Moolenaar2b946c92016-11-12 18:14:44 +0100700func Test_locationlist()
Bram Moolenaar1ff2b642016-03-17 22:07:02 +0100701 enew
702
703 augroup testgroup
704 au!
705 autocmd BufReadCmd test://* call ReadTestProtocol(expand("<amatch>"))
706 augroup END
707
708 let words = [ "foo", "bar", "baz", "quux", "shmoo", "spam", "eggs" ]
709
710 let qflist = []
711 for word in words
712 call add(qflist, {'filename': 'test://' . word . '.txt', 'text': 'file ' . word . '.txt', })
713 " NOTE: problem 1:
714 " intentionally not setting 'lnum' so that the quickfix entries are not
715 " valid
Bram Moolenaaraad222c2019-09-06 22:46:09 +0200716 eval qflist->setloclist(0, ' ')
Bram Moolenaar1ff2b642016-03-17 22:07:02 +0100717 endfor
718
719 " Test A
720 lrewind
721 enew
722 lopen
Bram Moolenaar99895ea2017-04-20 22:44:47 +0200723 4lnext
Bram Moolenaar1ff2b642016-03-17 22:07:02 +0100724 vert split
725 wincmd L
726 lopen
727 wincmd p
728 lnext
729 let fileName = expand("%")
730 wincmd p
731 let locationListFileName = substitute(getline(line('.')), '\([^|]*\)|.*', '\1', '')
732 let fileName = substitute(fileName, '\\', '/', 'g')
733 let locationListFileName = substitute(locationListFileName, '\\', '/', 'g')
734 call assert_equal("test://bar.txt", fileName)
735 call assert_equal("test://bar.txt", locationListFileName)
736
737 wincmd n | only
738
739 " Test B:
740 lrewind
741 lopen
742 2
743 exe "normal \<CR>"
744 wincmd p
745 3
746 exe "normal \<CR>"
747 wincmd p
748 4
749 exe "normal \<CR>"
750 call assert_equal(2, winnr('$'))
751 wincmd n | only
752
753 " Test C:
754 lrewind
755 lopen
756 " Let's move the location list window to the top to check whether it (the
757 " first window found) will be reused when we try to open new windows:
758 wincmd K
759 2
760 exe "normal \<CR>"
761 wincmd p
762 3
763 exe "normal \<CR>"
764 wincmd p
765 4
766 exe "normal \<CR>"
767 1wincmd w
768 call assert_equal('quickfix', &buftype)
769 2wincmd w
770 let bufferName = expand("%")
771 let bufferName = substitute(bufferName, '\\', '/', 'g')
772 call assert_equal('test://quux.txt', bufferName)
773
774 wincmd n | only
775
776 augroup! testgroup
Bram Moolenaaree85df32017-03-19 14:19:50 +0100777endfunc
Bram Moolenaar0899d692016-03-19 13:35:03 +0100778
Bram Moolenaar2b946c92016-11-12 18:14:44 +0100779func Test_locationlist_curwin_was_closed()
Bram Moolenaar0899d692016-03-19 13:35:03 +0100780 augroup testgroup
781 au!
Bram Moolenaard106e5b2016-04-21 19:38:07 +0200782 autocmd BufReadCmd test_curwin.txt call R(expand("<amatch>"))
Bram Moolenaar0899d692016-03-19 13:35:03 +0100783 augroup END
784
Bram Moolenaar2b946c92016-11-12 18:14:44 +0100785 func! R(n)
Bram Moolenaar0899d692016-03-19 13:35:03 +0100786 quit
787 endfunc
788
789 new
790 let q = []
Bram Moolenaard106e5b2016-04-21 19:38:07 +0200791 call add(q, {'filename': 'test_curwin.txt' })
Bram Moolenaar0899d692016-03-19 13:35:03 +0100792 call setloclist(0, q)
793 call assert_fails('lrewind', 'E924:')
794
795 augroup! testgroup
Bram Moolenaaree85df32017-03-19 14:19:50 +0100796endfunc
Bram Moolenaar7eba3d22016-03-19 22:54:09 +0100797
Bram Moolenaar2b946c92016-11-12 18:14:44 +0100798func Test_locationlist_cross_tab_jump()
Bram Moolenaar0a9046f2016-10-15 19:28:13 +0200799 call writefile(['loclistfoo'], 'loclistfoo')
800 call writefile(['loclistbar'], 'loclistbar')
801 set switchbuf=usetab
802
803 edit loclistfoo
804 tabedit loclistbar
805 silent lgrep loclistfoo loclist*
806 call assert_equal(1, tabpagenr())
807
808 enew | only | tabonly
809 set switchbuf&vim
810 call delete('loclistfoo')
811 call delete('loclistbar')
Bram Moolenaar2b946c92016-11-12 18:14:44 +0100812endfunc
Bram Moolenaar0a9046f2016-10-15 19:28:13 +0200813
Bram Moolenaar7eba3d22016-03-19 22:54:09 +0100814" More tests for 'errorformat'
Bram Moolenaar2b946c92016-11-12 18:14:44 +0100815func Test_efm1()
Bram Moolenaar7eba3d22016-03-19 22:54:09 +0100816 if !has('unix')
817 " The 'errorformat' setting is different on non-Unix systems.
818 " This test works only on Unix-like systems.
819 return
820 endif
821
Bram Moolenaarc79745a2019-05-20 22:12:34 +0200822 let l =<< trim [DATA]
Bram Moolenaare7eb9272019-06-24 00:58:07 +0200823 "Xtestfile", line 4.12: 1506-045 (S) Undeclared identifier fd_set.
824 "Xtestfile", line 6 col 19; this is an error
825 gcc -c -DHAVE_CONFIsing-prototypes -I/usr/X11R6/include version.c
826 Xtestfile:9: parse error before `asd'
827 make: *** [vim] Error 1
828 in file "Xtestfile" linenr 10: there is an error
829
830 2 returned
831 "Xtestfile", line 11 col 1; this is an error
832 "Xtestfile", line 12 col 2; this is another error
833 "Xtestfile", line 14:10; this is an error in column 10
834 =Xtestfile=, line 15:10; this is another error, but in vcol 10 this time
835 "Xtestfile", linenr 16: yet another problem
836 Error in "Xtestfile" at line 17:
837 x should be a dot
838 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 17
839 ^
840 Error in "Xtestfile" at line 18:
841 x should be a dot
842 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 18
843 .............^
844 Error in "Xtestfile" at line 19:
845 x should be a dot
846 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 19
847 --------------^
848 Error in "Xtestfile" at line 20:
849 x should be a dot
850 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 20
851 ^
852
853 Does anyone know what is the problem and how to correction it?
854 "Xtestfile", line 21 col 9: What is the title of the quickfix window?
855 "Xtestfile", line 22 col 9: What is the title of the quickfix window?
Bram Moolenaarc79745a2019-05-20 22:12:34 +0200856 [DATA]
Bram Moolenaar7eba3d22016-03-19 22:54:09 +0100857
858 call writefile(l, 'Xerrorfile1')
859 call writefile(l[:-2], 'Xerrorfile2')
860
Bram Moolenaare7eb9272019-06-24 00:58:07 +0200861 let m =<< [DATA]
862 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 2
863 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 3
864 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 4
865 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 5
866 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 6
867 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 7
868 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 8
869 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 9
870 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 10
871 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 11
872 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 12
873 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 13
874 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 14
875 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 15
876 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 16
877 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 17
878 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 18
879 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 19
880 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 20
881 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 21
882 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 22
883[DATA]
Bram Moolenaar7eba3d22016-03-19 22:54:09 +0100884 call writefile(m, 'Xtestfile')
885
886 let save_efm = &efm
887 set efm+==%f=\\,\ line\ %l%*\\D%v%*[^\ ]\ %m
888 set efm^=%AError\ in\ \"%f\"\ at\ line\ %l:,%Z%p^,%C%m
889
890 exe 'cf Xerrorfile2'
891 clast
892 copen
893 call assert_equal(':cf Xerrorfile2', w:quickfix_title)
894 wincmd p
895
896 exe 'cf Xerrorfile1'
897 call assert_equal([4, 12], [line('.'), col('.')])
898 cn
899 call assert_equal([6, 19], [line('.'), col('.')])
900 cn
901 call assert_equal([9, 2], [line('.'), col('.')])
902 cn
903 call assert_equal([10, 2], [line('.'), col('.')])
904 cn
905 call assert_equal([11, 1], [line('.'), col('.')])
906 cn
907 call assert_equal([12, 2], [line('.'), col('.')])
908 cn
909 call assert_equal([14, 10], [line('.'), col('.')])
910 cn
911 call assert_equal([15, 3, 10], [line('.'), col('.'), virtcol('.')])
912 cn
913 call assert_equal([16, 2], [line('.'), col('.')])
914 cn
915 call assert_equal([17, 6], [line('.'), col('.')])
916 cn
917 call assert_equal([18, 7], [line('.'), col('.')])
918 cn
919 call assert_equal([19, 8], [line('.'), col('.')])
920 cn
921 call assert_equal([20, 9], [line('.'), col('.')])
922 clast
923 cprev
924 cprev
925 wincmd w
926 call assert_equal(':cf Xerrorfile1', w:quickfix_title)
927 wincmd p
928
929 let &efm = save_efm
930 call delete('Xerrorfile1')
931 call delete('Xerrorfile2')
932 call delete('Xtestfile')
Bram Moolenaaree85df32017-03-19 14:19:50 +0100933endfunc
Bram Moolenaarffec3c52016-03-23 20:55:42 +0100934
Bram Moolenaarab47c612016-06-14 22:02:26 +0200935" Test for quickfix directory stack support
Bram Moolenaar2b946c92016-11-12 18:14:44 +0100936func s:dir_stack_tests(cchar)
Bram Moolenaar38df43b2016-06-20 21:41:12 +0200937 call s:setup_commands(a:cchar)
938
Bram Moolenaarab47c612016-06-14 22:02:26 +0200939 let save_efm=&efm
940 set efm=%DEntering\ dir\ '%f',%f:%l:%m,%XLeaving\ dir\ '%f'
941
Bram Moolenaar361c8f02016-07-02 15:41:47 +0200942 let lines = ["Entering dir 'dir1/a'",
943 \ 'habits2.txt:1:Nine Healthy Habits',
944 \ "Entering dir 'b'",
945 \ 'habits3.txt:2:0 Hours of television',
946 \ 'habits2.txt:7:5 Small meals',
947 \ "Entering dir 'dir1/c'",
948 \ 'habits4.txt:3:1 Hour of exercise',
949 \ "Leaving dir 'dir1/c'",
950 \ "Leaving dir 'dir1/a'",
951 \ 'habits1.txt:4:2 Liters of water',
952 \ "Entering dir 'dir2'",
953 \ 'habits5.txt:5:3 Cups of hot green tea',
954 \ "Leaving dir 'dir2'"
955 \]
Bram Moolenaarab47c612016-06-14 22:02:26 +0200956
Bram Moolenaar361c8f02016-07-02 15:41:47 +0200957 Xexpr ""
958 for l in lines
959 Xaddexpr l
960 endfor
Bram Moolenaarab47c612016-06-14 22:02:26 +0200961
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +0200962 let qf = g:Xgetlist()
Bram Moolenaarab47c612016-06-14 22:02:26 +0200963
964 call assert_equal('dir1/a/habits2.txt', bufname(qf[1].bufnr))
965 call assert_equal(1, qf[1].lnum)
966 call assert_equal('dir1/a/b/habits3.txt', bufname(qf[3].bufnr))
967 call assert_equal(2, qf[3].lnum)
968 call assert_equal('dir1/a/habits2.txt', bufname(qf[4].bufnr))
969 call assert_equal(7, qf[4].lnum)
970 call assert_equal('dir1/c/habits4.txt', bufname(qf[6].bufnr))
971 call assert_equal(3, qf[6].lnum)
972 call assert_equal('habits1.txt', bufname(qf[9].bufnr))
973 call assert_equal(4, qf[9].lnum)
974 call assert_equal('dir2/habits5.txt', bufname(qf[11].bufnr))
975 call assert_equal(5, qf[11].lnum)
976
977 let &efm=save_efm
Bram Moolenaar2b946c92016-11-12 18:14:44 +0100978endfunc
Bram Moolenaarab47c612016-06-14 22:02:26 +0200979
980" Tests for %D and %X errorformat options
Bram Moolenaar2b946c92016-11-12 18:14:44 +0100981func Test_efm_dirstack()
Bram Moolenaarab47c612016-06-14 22:02:26 +0200982 " Create the directory stack and files
983 call mkdir('dir1')
984 call mkdir('dir1/a')
985 call mkdir('dir1/a/b')
986 call mkdir('dir1/c')
987 call mkdir('dir2')
988
989 let lines = ["Nine Healthy Habits",
990 \ "0 Hours of television",
991 \ "1 Hour of exercise",
992 \ "2 Liters of water",
993 \ "3 Cups of hot green tea",
994 \ "4 Short mental breaks",
995 \ "5 Small meals",
996 \ "6 AM wake up time",
997 \ "7 Minutes of laughter",
998 \ "8 Hours of sleep (at least)",
999 \ "9 PM end of the day and off to bed"
1000 \ ]
1001 call writefile(lines, 'habits1.txt')
1002 call writefile(lines, 'dir1/a/habits2.txt')
1003 call writefile(lines, 'dir1/a/b/habits3.txt')
1004 call writefile(lines, 'dir1/c/habits4.txt')
1005 call writefile(lines, 'dir2/habits5.txt')
1006
1007 call s:dir_stack_tests('c')
1008 call s:dir_stack_tests('l')
1009
1010 call delete('dir1', 'rf')
1011 call delete('dir2', 'rf')
1012 call delete('habits1.txt')
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001013endfunc
Bram Moolenaarab47c612016-06-14 22:02:26 +02001014
Bram Moolenaar9b457942016-10-09 16:10:05 +02001015" Test for resync after continuing an ignored message
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001016func Xefm_ignore_continuations(cchar)
Bram Moolenaar9b457942016-10-09 16:10:05 +02001017 call s:setup_commands(a:cchar)
1018
1019 let save_efm = &efm
1020
1021 let &efm =
1022 \ '%Eerror %m %l,' .
1023 \ '%-Wignored %m %l,' .
1024 \ '%+Cmore ignored %m %l,' .
1025 \ '%Zignored end'
1026 Xgetexpr ['ignored warning 1', 'more ignored continuation 2', 'ignored end', 'error resync 4']
1027 let l = map(g:Xgetlist(), '[v:val.text, v:val.valid, v:val.lnum, v:val.type]')
1028 call assert_equal([['resync', 1, 4, 'E']], l)
1029
1030 let &efm = save_efm
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001031endfunc
Bram Moolenaar9b457942016-10-09 16:10:05 +02001032
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001033func Test_efm_ignore_continuations()
Bram Moolenaar9b457942016-10-09 16:10:05 +02001034 call Xefm_ignore_continuations('c')
1035 call Xefm_ignore_continuations('l')
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001036endfunc
Bram Moolenaar9b457942016-10-09 16:10:05 +02001037
Bram Moolenaar0fcc7c62016-07-02 21:22:52 +02001038" Tests for invalid error format specifies
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001039func Xinvalid_efm_Tests(cchar)
Bram Moolenaar0fcc7c62016-07-02 21:22:52 +02001040 call s:setup_commands(a:cchar)
1041
Bram Moolenaar049cba92016-06-26 14:38:04 +02001042 let save_efm = &efm
1043
Bram Moolenaar0fcc7c62016-07-02 21:22:52 +02001044 set efm=%f:%l:%m,%f:%f:%l:%m
1045 call assert_fails('Xexpr "abc.txt:1:Hello world"', 'E372:')
1046
1047 set efm=%f:%l:%m,%f:%l:%r:%m
1048 call assert_fails('Xexpr "abc.txt:1:Hello world"', 'E373:')
1049
1050 set efm=%f:%l:%m,%O:%f:%l:%m
1051 call assert_fails('Xexpr "abc.txt:1:Hello world"', 'E373:')
1052
1053 set efm=%f:%l:%m,%f:%l:%*[^a-z
1054 call assert_fails('Xexpr "abc.txt:1:Hello world"', 'E374:')
1055
1056 set efm=%f:%l:%m,%f:%l:%*c
1057 call assert_fails('Xexpr "abc.txt:1:Hello world"', 'E375:')
1058
1059 set efm=%f:%l:%m,%L%M%N
1060 call assert_fails('Xexpr "abc.txt:1:Hello world"', 'E376:')
1061
1062 set efm=%f:%l:%m,%f:%l:%m:%R
1063 call assert_fails('Xexpr "abc.txt:1:Hello world"', 'E377:')
1064
1065 set efm=
1066 call assert_fails('Xexpr "abc.txt:1:Hello world"', 'E378:')
1067
1068 set efm=%DEntering\ dir\ abc,%f:%l:%m
1069 call assert_fails('Xexpr ["Entering dir abc", "abc.txt:1:Hello world"]', 'E379:')
1070
1071 let &efm = save_efm
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001072endfunc
Bram Moolenaar0fcc7c62016-07-02 21:22:52 +02001073
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001074func Test_invalid_efm()
Bram Moolenaar0fcc7c62016-07-02 21:22:52 +02001075 call Xinvalid_efm_Tests('c')
1076 call Xinvalid_efm_Tests('l')
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001077endfunc
Bram Moolenaar0fcc7c62016-07-02 21:22:52 +02001078
1079" TODO:
1080" Add tests for the following formats in 'errorformat'
1081" %r %O
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001082func Test_efm2()
Bram Moolenaar0fcc7c62016-07-02 21:22:52 +02001083 let save_efm = &efm
Bram Moolenaar049cba92016-06-26 14:38:04 +02001084
1085 " Test for %s format in efm
1086 set efm=%f:%s
1087 cexpr 'Xtestfile:Line search text'
Bram Moolenaar049cba92016-06-26 14:38:04 +02001088 let l = getqflist()
1089 call assert_equal(l[0].pattern, '^\VLine search text\$')
1090 call assert_equal(l[0].lnum, 0)
1091
Bram Moolenaaree85df32017-03-19 14:19:50 +01001092 let l = split(execute('clist', ''), "\n")
1093 call assert_equal([' 1 Xtestfile:^\VLine search text\$: '], l)
1094
Bram Moolenaar0fcc7c62016-07-02 21:22:52 +02001095 " Test for %P, %Q and %t format specifiers
Bram Moolenaarc79745a2019-05-20 22:12:34 +02001096 let lines =<< trim [DATA]
Bram Moolenaare7eb9272019-06-24 00:58:07 +02001097 [Xtestfile1]
1098 (1,17) error: ';' missing
1099 (21,2) warning: variable 'z' not defined
1100 (67,3) error: end of file found before string ended
1101 --
Bram Moolenaarc79745a2019-05-20 22:12:34 +02001102
Bram Moolenaare7eb9272019-06-24 00:58:07 +02001103 [Xtestfile2]
1104 --
Bram Moolenaarc79745a2019-05-20 22:12:34 +02001105
Bram Moolenaare7eb9272019-06-24 00:58:07 +02001106 [Xtestfile3]
1107 NEW compiler v1.1
1108 (2,2) warning: variable 'x' not defined
1109 (67,3) warning: 's' already defined
1110 --
Bram Moolenaarc79745a2019-05-20 22:12:34 +02001111 [DATA]
1112
Bram Moolenaaree85df32017-03-19 14:19:50 +01001113 set efm=%+P[%f]%r,(%l\\,%c)%*[\ ]%t%*[^:]:\ %m,%+Q--%r
Bram Moolenaar391b1dd2017-03-04 13:47:11 +01001114 " To exercise the push/pop file functionality in quickfix, the test files
1115 " need to be created.
1116 call writefile(['Line1'], 'Xtestfile1')
1117 call writefile(['Line2'], 'Xtestfile2')
1118 call writefile(['Line3'], 'Xtestfile3')
Bram Moolenaar361c8f02016-07-02 15:41:47 +02001119 cexpr ""
1120 for l in lines
1121 caddexpr l
1122 endfor
Bram Moolenaar049cba92016-06-26 14:38:04 +02001123 let l = getqflist()
Bram Moolenaaree85df32017-03-19 14:19:50 +01001124 call assert_equal(12, len(l))
Bram Moolenaar049cba92016-06-26 14:38:04 +02001125 call assert_equal(21, l[2].lnum)
1126 call assert_equal(2, l[2].col)
Bram Moolenaar0fcc7c62016-07-02 21:22:52 +02001127 call assert_equal('w', l[2].type)
1128 call assert_equal('e', l[3].type)
Bram Moolenaar391b1dd2017-03-04 13:47:11 +01001129 call delete('Xtestfile1')
1130 call delete('Xtestfile2')
1131 call delete('Xtestfile3')
Bram Moolenaar0fcc7c62016-07-02 21:22:52 +02001132
1133 " Tests for %E, %C and %Z format specifiers
Bram Moolenaarc79745a2019-05-20 22:12:34 +02001134 let lines =<< trim [DATA]
Bram Moolenaare7eb9272019-06-24 00:58:07 +02001135 Error 275
1136 line 42
1137 column 3
1138 ' ' expected after '--'
Bram Moolenaarc79745a2019-05-20 22:12:34 +02001139 [DATA]
1140
Bram Moolenaar0fcc7c62016-07-02 21:22:52 +02001141 set efm=%EError\ %n,%Cline\ %l,%Ccolumn\ %c,%Z%m
1142 cgetexpr lines
1143 let l = getqflist()
1144 call assert_equal(275, l[0].nr)
1145 call assert_equal(42, l[0].lnum)
1146 call assert_equal(3, l[0].col)
1147 call assert_equal('E', l[0].type)
1148 call assert_equal("\n' ' expected after '--'", l[0].text)
1149
1150 " Test for %>
Bram Moolenaarc79745a2019-05-20 22:12:34 +02001151 let lines =<< trim [DATA]
Bram Moolenaare7eb9272019-06-24 00:58:07 +02001152 Error in line 147 of foo.c:
1153 unknown variable 'i'
Bram Moolenaarc79745a2019-05-20 22:12:34 +02001154 [DATA]
1155
Bram Moolenaar0fcc7c62016-07-02 21:22:52 +02001156 set efm=unknown\ variable\ %m,%E%>Error\ in\ line\ %l\ of\ %f:,%Z%m
1157 cgetexpr lines
1158 let l = getqflist()
1159 call assert_equal(147, l[0].lnum)
1160 call assert_equal('E', l[0].type)
1161 call assert_equal("\nunknown variable 'i'", l[0].text)
Bram Moolenaar049cba92016-06-26 14:38:04 +02001162
Bram Moolenaare87e6dd2016-07-17 19:25:04 +02001163 " Test for %A, %C and other formats
Bram Moolenaarc79745a2019-05-20 22:12:34 +02001164 let lines =<< trim [DATA]
Bram Moolenaare7eb9272019-06-24 00:58:07 +02001165 ==============================================================
1166 FAIL: testGetTypeIdCachesResult (dbfacadeTest.DjsDBFacadeTest)
1167 --------------------------------------------------------------
1168 Traceback (most recent call last):
1169 File "unittests/dbfacadeTest.py", line 89, in testFoo
1170 self.assertEquals(34, dtid)
1171 File "/usr/lib/python2.2/unittest.py", line 286, in
1172 failUnlessEqual
1173 raise self.failureException, \\
1174 AssertionError: 34 != 33
1175
1176 --------------------------------------------------------------
1177 Ran 27 tests in 0.063s
Bram Moolenaarc79745a2019-05-20 22:12:34 +02001178 [DATA]
1179
Bram Moolenaare87e6dd2016-07-17 19:25:04 +02001180 set efm=%C\ %.%#,%A\ \ File\ \"%f\"\\,\ line\ %l%.%#,%Z%[%^\ ]%\\@=%m
1181 cgetexpr lines
1182 let l = getqflist()
1183 call assert_equal(8, len(l))
1184 call assert_equal(89, l[4].lnum)
1185 call assert_equal(1, l[4].valid)
1186 call assert_equal('unittests/dbfacadeTest.py', bufname(l[4].bufnr))
1187
Bram Moolenaard76ce852018-05-01 15:02:04 +02001188 " Test for %o
1189 set efm=%f(%o):%l\ %m
Bram Moolenaarbc7845d2018-05-01 16:26:48 +02001190 cgetexpr ['Xotestfile(Language.PureScript.Types):20 Error']
1191 call writefile(['Line1'], 'Xotestfile')
Bram Moolenaard76ce852018-05-01 15:02:04 +02001192 let l = getqflist()
1193 call assert_equal(1, len(l), string(l))
1194 call assert_equal('Language.PureScript.Types', l[0].module)
1195 copen
1196 call assert_equal('Language.PureScript.Types|20| Error', getline(1))
1197 call feedkeys("\<CR>", 'xn')
Bram Moolenaarbc7845d2018-05-01 16:26:48 +02001198 call assert_equal('Xotestfile', expand('%:t'))
Bram Moolenaard76ce852018-05-01 15:02:04 +02001199 cclose
1200 bd
Bram Moolenaarbc7845d2018-05-01 16:26:48 +02001201 call delete("Xotestfile")
Bram Moolenaard76ce852018-05-01 15:02:04 +02001202
Bram Moolenaar99895ea2017-04-20 22:44:47 +02001203 " The following sequence of commands used to crash Vim
1204 set efm=%W%m
1205 cgetexpr ['msg1']
1206 let l = getqflist()
1207 call assert_equal(1, len(l), string(l))
1208 call assert_equal('msg1', l[0].text)
1209 set efm=%C%m
1210 lexpr 'msg2'
1211 let l = getloclist(0)
1212 call assert_equal(1, len(l), string(l))
1213 call assert_equal('msg2', l[0].text)
1214 lopen
1215 call setqflist([], 'r')
1216 caddbuf
1217 let l = getqflist()
1218 call assert_equal(1, len(l), string(l))
1219 call assert_equal('|| msg2', l[0].text)
1220
Bram Moolenaar78ddc062018-05-15 21:56:34 +02001221 " When matching error lines, case should be ignored. Test for this.
1222 set noignorecase
1223 let l=getqflist({'lines' : ['Xtest:FOO10:Line 20'], 'efm':'%f:foo%l:%m'})
1224 call assert_equal(10, l.items[0].lnum)
1225 call assert_equal('Line 20', l.items[0].text)
1226 set ignorecase&
1227
Bram Moolenaar99895ea2017-04-20 22:44:47 +02001228 new | only
Bram Moolenaar049cba92016-06-26 14:38:04 +02001229 let &efm = save_efm
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001230endfunc
Bram Moolenaar049cba92016-06-26 14:38:04 +02001231
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001232func XquickfixChangedByAutocmd(cchar)
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001233 call s:setup_commands(a:cchar)
Bram Moolenaarffec3c52016-03-23 20:55:42 +01001234 if a:cchar == 'c'
Bram Moolenaarffec3c52016-03-23 20:55:42 +01001235 let ErrorNr = 'E925'
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001236 func! ReadFunc()
Bram Moolenaarffec3c52016-03-23 20:55:42 +01001237 colder
1238 cgetexpr []
1239 endfunc
1240 else
Bram Moolenaarffec3c52016-03-23 20:55:42 +01001241 let ErrorNr = 'E926'
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001242 func! ReadFunc()
Bram Moolenaarffec3c52016-03-23 20:55:42 +01001243 lolder
1244 lgetexpr []
1245 endfunc
1246 endif
1247
1248 augroup testgroup
1249 au!
Bram Moolenaard106e5b2016-04-21 19:38:07 +02001250 autocmd BufReadCmd test_changed.txt call ReadFunc()
Bram Moolenaarffec3c52016-03-23 20:55:42 +01001251 augroup END
1252
Bram Moolenaard106e5b2016-04-21 19:38:07 +02001253 new | only
Bram Moolenaarffec3c52016-03-23 20:55:42 +01001254 let words = [ "a", "b" ]
1255 let qflist = []
1256 for word in words
Bram Moolenaard106e5b2016-04-21 19:38:07 +02001257 call add(qflist, {'filename': 'test_changed.txt'})
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001258 call g:Xsetlist(qflist, ' ')
Bram Moolenaarffec3c52016-03-23 20:55:42 +01001259 endfor
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001260 call assert_fails('Xrewind', ErrorNr . ':')
Bram Moolenaarffec3c52016-03-23 20:55:42 +01001261
1262 augroup! testgroup
1263endfunc
1264
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001265func Test_quickfix_was_changed_by_autocmd()
Bram Moolenaarffec3c52016-03-23 20:55:42 +01001266 call XquickfixChangedByAutocmd('c')
1267 call XquickfixChangedByAutocmd('l')
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001268endfunc
Bram Moolenaar8b201792016-03-25 15:01:10 +01001269
1270func Test_caddbuffer_to_empty()
1271 helpgr quickfix
1272 call setqflist([], 'r')
1273 cad
Bram Moolenaarf68f1d72016-03-25 17:14:06 +01001274 try
1275 cn
1276 catch
1277 " number of matches is unknown
1278 call assert_true(v:exception =~ 'E553:')
1279 endtry
Bram Moolenaar8b201792016-03-25 15:01:10 +01001280 quit!
1281endfunc
Bram Moolenaar89c64d52016-03-27 18:44:40 +02001282
1283func Test_cgetexpr_works()
1284 " this must not crash Vim
1285 cgetexpr [$x]
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001286 lgetexpr [$x]
Bram Moolenaar89c64d52016-03-27 18:44:40 +02001287endfunc
Bram Moolenaarc1808d52016-04-18 20:04:00 +02001288
1289" Tests for the setqflist() and setloclist() functions
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001290func SetXlistTests(cchar, bnum)
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001291 call s:setup_commands(a:cchar)
Bram Moolenaarc1808d52016-04-18 20:04:00 +02001292
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001293 call g:Xsetlist([{'bufnr': a:bnum, 'lnum': 1},
Bram Moolenaarc1808d52016-04-18 20:04:00 +02001294 \ {'bufnr': a:bnum, 'lnum': 2}])
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001295 let l = g:Xgetlist()
Bram Moolenaarc1808d52016-04-18 20:04:00 +02001296 call assert_equal(2, len(l))
1297 call assert_equal(2, l[1].lnum)
1298
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001299 Xnext
1300 call g:Xsetlist([{'bufnr': a:bnum, 'lnum': 3}], 'a')
1301 let l = g:Xgetlist()
Bram Moolenaarc1808d52016-04-18 20:04:00 +02001302 call assert_equal(3, len(l))
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001303 Xnext
Bram Moolenaarc1808d52016-04-18 20:04:00 +02001304 call assert_equal(3, line('.'))
1305
Bram Moolenaar2b2b8ae2016-05-24 19:59:51 +02001306 " Appending entries to the list should not change the cursor position
1307 " in the quickfix window
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001308 Xwindow
Bram Moolenaar2b2b8ae2016-05-24 19:59:51 +02001309 1
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001310 call g:Xsetlist([{'bufnr': a:bnum, 'lnum': 4},
Bram Moolenaar2b2b8ae2016-05-24 19:59:51 +02001311 \ {'bufnr': a:bnum, 'lnum': 5}], 'a')
1312 call assert_equal(1, line('.'))
1313 close
1314
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001315 call g:Xsetlist([{'bufnr': a:bnum, 'lnum': 3},
Bram Moolenaarc1808d52016-04-18 20:04:00 +02001316 \ {'bufnr': a:bnum, 'lnum': 4},
1317 \ {'bufnr': a:bnum, 'lnum': 5}], 'r')
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001318 let l = g:Xgetlist()
Bram Moolenaarc1808d52016-04-18 20:04:00 +02001319 call assert_equal(3, len(l))
1320 call assert_equal(5, l[2].lnum)
1321
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001322 call g:Xsetlist([])
1323 let l = g:Xgetlist()
Bram Moolenaarc1808d52016-04-18 20:04:00 +02001324 call assert_equal(0, len(l))
Bram Moolenaaree85df32017-03-19 14:19:50 +01001325
Bram Moolenaarf1d21c82017-04-22 21:20:46 +02001326 " Tests for setting the 'valid' flag
1327 call g:Xsetlist([{'bufnr':a:bnum, 'lnum':4, 'valid':0}])
1328 Xwindow
1329 call assert_equal(1, winnr('$'))
1330 let l = g:Xgetlist()
1331 call g:Xsetlist(l)
1332 call assert_equal(0, g:Xgetlist()[0].valid)
Bram Moolenaar9752c722018-12-22 16:49:34 +01001333 " Adding a non-valid entry should not mark the list as having valid entries
1334 call g:Xsetlist([{'bufnr':a:bnum, 'lnum':5, 'valid':0}], 'a')
1335 Xwindow
1336 call assert_equal(1, winnr('$'))
1337
1338 " :cnext/:cprev should still work even with invalid entries in the list
1339 let l = [{'bufnr' : a:bnum, 'lnum' : 1, 'text' : '1', 'valid' : 0},
1340 \ {'bufnr' : a:bnum, 'lnum' : 2, 'text' : '2', 'valid' : 0}]
1341 call g:Xsetlist(l)
1342 Xnext
1343 call assert_equal(2, g:Xgetlist({'idx' : 0}).idx)
1344 Xprev
1345 call assert_equal(1, g:Xgetlist({'idx' : 0}).idx)
1346 " :cnext/:cprev should still work after appending invalid entries to an
1347 " empty list
1348 call g:Xsetlist([])
1349 call g:Xsetlist(l, 'a')
1350 Xnext
1351 call assert_equal(2, g:Xgetlist({'idx' : 0}).idx)
1352 Xprev
1353 call assert_equal(1, g:Xgetlist({'idx' : 0}).idx)
1354
Bram Moolenaarf1d21c82017-04-22 21:20:46 +02001355 call g:Xsetlist([{'text':'Text1', 'valid':1}])
1356 Xwindow
1357 call assert_equal(2, winnr('$'))
1358 Xclose
1359 let save_efm = &efm
1360 set efm=%m
1361 Xgetexpr 'TestMessage'
1362 let l = g:Xgetlist()
1363 call g:Xsetlist(l)
1364 call assert_equal(1, g:Xgetlist()[0].valid)
1365 let &efm = save_efm
1366
Bram Moolenaaree85df32017-03-19 14:19:50 +01001367 " Error cases:
1368 " Refer to a non-existing buffer and pass a non-dictionary type
1369 call assert_fails("call g:Xsetlist([{'bufnr':998, 'lnum':4}," .
1370 \ " {'bufnr':999, 'lnum':5}])", 'E92:')
1371 call g:Xsetlist([[1, 2,3]])
1372 call assert_equal(0, len(g:Xgetlist()))
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001373endfunc
Bram Moolenaarc1808d52016-04-18 20:04:00 +02001374
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001375func Test_setqflist()
Bram Moolenaarc1808d52016-04-18 20:04:00 +02001376 new Xtestfile | only
1377 let bnum = bufnr('%')
1378 call setline(1, range(1,5))
1379
1380 call SetXlistTests('c', bnum)
1381 call SetXlistTests('l', bnum)
1382
Bram Moolenaar1cee6932016-06-09 22:17:22 +02001383 enew!
Bram Moolenaarc1808d52016-04-18 20:04:00 +02001384 call delete('Xtestfile')
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001385endfunc
Bram Moolenaard106e5b2016-04-21 19:38:07 +02001386
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001387func Xlist_empty_middle(cchar)
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001388 call s:setup_commands(a:cchar)
1389
Bram Moolenaar1cee6932016-06-09 22:17:22 +02001390 " create three quickfix lists
Bram Moolenaaree85df32017-03-19 14:19:50 +01001391 let @/ = 'Test_'
1392 Xvimgrep // test_quickfix.vim
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001393 let testlen = len(g:Xgetlist())
Bram Moolenaar1cee6932016-06-09 22:17:22 +02001394 call assert_true(testlen > 0)
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001395 Xvimgrep empty test_quickfix.vim
1396 call assert_true(len(g:Xgetlist()) > 0)
1397 Xvimgrep matches test_quickfix.vim
1398 let matchlen = len(g:Xgetlist())
Bram Moolenaar1cee6932016-06-09 22:17:22 +02001399 call assert_true(matchlen > 0)
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001400 Xolder
Bram Moolenaar1cee6932016-06-09 22:17:22 +02001401 " make the middle list empty
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001402 call g:Xsetlist([], 'r')
1403 call assert_true(len(g:Xgetlist()) == 0)
1404 Xolder
1405 call assert_equal(testlen, len(g:Xgetlist()))
1406 Xnewer
1407 Xnewer
1408 call assert_equal(matchlen, len(g:Xgetlist()))
Bram Moolenaar1cee6932016-06-09 22:17:22 +02001409endfunc
1410
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001411func Test_setqflist_empty_middle()
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001412 call Xlist_empty_middle('c')
1413 call Xlist_empty_middle('l')
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001414endfunc
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001415
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001416func Xlist_empty_older(cchar)
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001417 call s:setup_commands(a:cchar)
1418
Bram Moolenaar1cee6932016-06-09 22:17:22 +02001419 " create three quickfix lists
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001420 Xvimgrep one test_quickfix.vim
1421 let onelen = len(g:Xgetlist())
Bram Moolenaar1cee6932016-06-09 22:17:22 +02001422 call assert_true(onelen > 0)
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001423 Xvimgrep two test_quickfix.vim
1424 let twolen = len(g:Xgetlist())
Bram Moolenaar1cee6932016-06-09 22:17:22 +02001425 call assert_true(twolen > 0)
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001426 Xvimgrep three test_quickfix.vim
1427 let threelen = len(g:Xgetlist())
Bram Moolenaar1cee6932016-06-09 22:17:22 +02001428 call assert_true(threelen > 0)
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001429 Xolder 2
Bram Moolenaar1cee6932016-06-09 22:17:22 +02001430 " make the first list empty, check the others didn't change
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001431 call g:Xsetlist([], 'r')
1432 call assert_true(len(g:Xgetlist()) == 0)
1433 Xnewer
1434 call assert_equal(twolen, len(g:Xgetlist()))
1435 Xnewer
1436 call assert_equal(threelen, len(g:Xgetlist()))
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001437endfunc
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001438
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001439func Test_setqflist_empty_older()
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001440 call Xlist_empty_older('c')
1441 call Xlist_empty_older('l')
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001442endfunc
Bram Moolenaar1cee6932016-06-09 22:17:22 +02001443
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001444func XquickfixSetListWithAct(cchar)
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001445 call s:setup_commands(a:cchar)
1446
Bram Moolenaard106e5b2016-04-21 19:38:07 +02001447 let list1 = [{'filename': 'fnameA', 'text': 'A'},
1448 \ {'filename': 'fnameB', 'text': 'B'}]
1449 let list2 = [{'filename': 'fnameC', 'text': 'C'},
1450 \ {'filename': 'fnameD', 'text': 'D'},
1451 \ {'filename': 'fnameE', 'text': 'E'}]
1452
Bram Moolenaareeb1b9c2019-02-10 22:59:04 +01001453 " {action} is unspecified. Same as specifying ' '.
Bram Moolenaard106e5b2016-04-21 19:38:07 +02001454 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 ' '.
1470 new | only
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001471 silent! Xnewer 99
1472 call g:Xsetlist(list1)
1473 call g:Xsetlist(list2, ' ')
1474 let li = g:Xgetlist()
Bram Moolenaard106e5b2016-04-21 19:38:07 +02001475 call assert_equal(3, len(li))
1476 call assert_equal('C', li[0]['text'])
1477 call assert_equal('D', li[1]['text'])
1478 call assert_equal('E', li[2]['text'])
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001479 silent! Xolder
1480 let li = g:Xgetlist()
Bram Moolenaard106e5b2016-04-21 19:38:07 +02001481 call assert_equal(2, len(li))
1482 call assert_equal('A', li[0]['text'])
1483 call assert_equal('B', li[1]['text'])
1484
1485 " {action} is specified 'a'.
1486 new | only
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001487 silent! Xnewer 99
1488 call g:Xsetlist(list1)
1489 call g:Xsetlist(list2, 'a')
1490 let li = g:Xgetlist()
Bram Moolenaard106e5b2016-04-21 19:38:07 +02001491 call assert_equal(5, len(li))
1492 call assert_equal('A', li[0]['text'])
1493 call assert_equal('B', li[1]['text'])
1494 call assert_equal('C', li[2]['text'])
1495 call assert_equal('D', li[3]['text'])
1496 call assert_equal('E', li[4]['text'])
1497
1498 " {action} is specified 'r'.
1499 new | only
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001500 silent! Xnewer 99
1501 call g:Xsetlist(list1)
1502 call g:Xsetlist(list2, 'r')
1503 let li = g:Xgetlist()
Bram Moolenaard106e5b2016-04-21 19:38:07 +02001504 call assert_equal(3, len(li))
1505 call assert_equal('C', li[0]['text'])
1506 call assert_equal('D', li[1]['text'])
1507 call assert_equal('E', li[2]['text'])
1508
1509 " Test for wrong value.
1510 new | only
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001511 call assert_fails("call g:Xsetlist(0)", 'E714:')
1512 call assert_fails("call g:Xsetlist(list1, '')", 'E927:')
1513 call assert_fails("call g:Xsetlist(list1, 'aa')", 'E927:')
1514 call assert_fails("call g:Xsetlist(list1, ' a')", 'E927:')
1515 call assert_fails("call g:Xsetlist(list1, 0)", 'E928:')
Bram Moolenaard106e5b2016-04-21 19:38:07 +02001516endfunc
1517
Bram Moolenaara0ca7d02017-12-19 10:22:19 +01001518func Test_setqflist_invalid_nr()
1519 " The following command used to crash Vim
Bram Moolenaaraad222c2019-09-06 22:46:09 +02001520 eval []->setqflist(' ', {'nr' : $XXX_DOES_NOT_EXIST})
Bram Moolenaara0ca7d02017-12-19 10:22:19 +01001521endfunc
1522
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001523func Test_quickfix_set_list_with_act()
Bram Moolenaard106e5b2016-04-21 19:38:07 +02001524 call XquickfixSetListWithAct('c')
1525 call XquickfixSetListWithAct('l')
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001526endfunc
Bram Moolenaar6be8c8e2016-04-30 13:17:09 +02001527
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001528func XLongLinesTests(cchar)
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001529 let l = g:Xgetlist()
Bram Moolenaar6be8c8e2016-04-30 13:17:09 +02001530
Bram Moolenaar049cba92016-06-26 14:38:04 +02001531 call assert_equal(4, len(l))
Bram Moolenaar6be8c8e2016-04-30 13:17:09 +02001532 call assert_equal(1, l[0].lnum)
1533 call assert_equal(1, l[0].col)
Bram Moolenaar049cba92016-06-26 14:38:04 +02001534 call assert_equal(1975, len(l[0].text))
Bram Moolenaar6be8c8e2016-04-30 13:17:09 +02001535 call assert_equal(2, l[1].lnum)
1536 call assert_equal(1, l[1].col)
1537 call assert_equal(4070, len(l[1].text))
1538 call assert_equal(3, l[2].lnum)
1539 call assert_equal(1, l[2].col)
Bram Moolenaar049cba92016-06-26 14:38:04 +02001540 call assert_equal(4070, len(l[2].text))
1541 call assert_equal(4, l[3].lnum)
1542 call assert_equal(1, l[3].col)
1543 call assert_equal(10, len(l[3].text))
Bram Moolenaar6be8c8e2016-04-30 13:17:09 +02001544
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001545 call g:Xsetlist([], 'r')
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001546endfunc
Bram Moolenaar6be8c8e2016-04-30 13:17:09 +02001547
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001548func s:long_lines_tests(cchar)
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001549 call s:setup_commands(a:cchar)
1550
Bram Moolenaar6be8c8e2016-04-30 13:17:09 +02001551 let testfile = 'samples/quickfix.txt'
1552
1553 " file
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001554 exe 'Xgetfile' testfile
1555 call XLongLinesTests(a:cchar)
Bram Moolenaar6be8c8e2016-04-30 13:17:09 +02001556
1557 " list
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001558 Xexpr readfile(testfile)
1559 call XLongLinesTests(a:cchar)
Bram Moolenaar6be8c8e2016-04-30 13:17:09 +02001560
1561 " string
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001562 Xexpr join(readfile(testfile), "\n")
1563 call XLongLinesTests(a:cchar)
Bram Moolenaar6be8c8e2016-04-30 13:17:09 +02001564
1565 " buffer
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001566 exe 'edit' testfile
1567 exe 'Xbuffer' bufnr('%')
Bram Moolenaarf50df392016-06-21 21:33:34 +02001568 call XLongLinesTests(a:cchar)
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001569endfunc
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001570
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001571func Test_long_lines()
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001572 call s:long_lines_tests('c')
1573 call s:long_lines_tests('l')
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001574endfunc
Bram Moolenaar049cba92016-06-26 14:38:04 +02001575
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001576func s:create_test_file(filename)
Bram Moolenaar049cba92016-06-26 14:38:04 +02001577 let l = []
1578 for i in range(1, 20)
1579 call add(l, 'Line' . i)
1580 endfor
1581 call writefile(l, a:filename)
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001582endfunc
Bram Moolenaar049cba92016-06-26 14:38:04 +02001583
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001584func Test_switchbuf()
Bram Moolenaar049cba92016-06-26 14:38:04 +02001585 call s:create_test_file('Xqftestfile1')
1586 call s:create_test_file('Xqftestfile2')
1587 call s:create_test_file('Xqftestfile3')
1588
1589 new | only
1590 edit Xqftestfile1
1591 let file1_winid = win_getid()
1592 new Xqftestfile2
1593 let file2_winid = win_getid()
1594 cgetexpr ['Xqftestfile1:5:Line5',
1595 \ 'Xqftestfile1:6:Line6',
1596 \ 'Xqftestfile2:10:Line10',
1597 \ 'Xqftestfile2:11:Line11',
1598 \ 'Xqftestfile3:15:Line15',
1599 \ 'Xqftestfile3:16:Line16']
1600
1601 new
1602 let winid = win_getid()
1603 cfirst | cnext
1604 call assert_equal(winid, win_getid())
Bram Moolenaar99895ea2017-04-20 22:44:47 +02001605 2cnext
Bram Moolenaar049cba92016-06-26 14:38:04 +02001606 call assert_equal(winid, win_getid())
Bram Moolenaar99895ea2017-04-20 22:44:47 +02001607 2cnext
Bram Moolenaar049cba92016-06-26 14:38:04 +02001608 call assert_equal(winid, win_getid())
1609 enew
1610
1611 set switchbuf=useopen
1612 cfirst | cnext
1613 call assert_equal(file1_winid, win_getid())
Bram Moolenaar99895ea2017-04-20 22:44:47 +02001614 2cnext
Bram Moolenaar049cba92016-06-26 14:38:04 +02001615 call assert_equal(file2_winid, win_getid())
Bram Moolenaar99895ea2017-04-20 22:44:47 +02001616 2cnext
Bram Moolenaar049cba92016-06-26 14:38:04 +02001617 call assert_equal(file2_winid, win_getid())
1618
1619 enew | only
1620 set switchbuf=usetab
1621 tabedit Xqftestfile1
1622 tabedit Xqftestfile2
Bram Moolenaar74240d32017-12-10 15:26:15 +01001623 tabedit Xqftestfile3
Bram Moolenaar049cba92016-06-26 14:38:04 +02001624 tabfirst
1625 cfirst | cnext
1626 call assert_equal(2, tabpagenr())
Bram Moolenaar99895ea2017-04-20 22:44:47 +02001627 2cnext
Bram Moolenaar049cba92016-06-26 14:38:04 +02001628 call assert_equal(3, tabpagenr())
Bram Moolenaar74240d32017-12-10 15:26:15 +01001629 6cnext
1630 call assert_equal(4, tabpagenr())
1631 2cpfile
1632 call assert_equal(2, tabpagenr())
1633 2cnfile
1634 call assert_equal(4, tabpagenr())
Bram Moolenaar049cba92016-06-26 14:38:04 +02001635 tabfirst | tabonly | enew
1636
1637 set switchbuf=split
1638 cfirst | cnext
1639 call assert_equal(1, winnr('$'))
1640 cnext | cnext
1641 call assert_equal(2, winnr('$'))
1642 cnext | cnext
1643 call assert_equal(3, winnr('$'))
1644 enew | only
1645
1646 set switchbuf=newtab
1647 cfirst | cnext
1648 call assert_equal(1, tabpagenr('$'))
1649 cnext | cnext
1650 call assert_equal(2, tabpagenr('$'))
1651 cnext | cnext
1652 call assert_equal(3, tabpagenr('$'))
1653 tabfirst | enew | tabonly | only
1654
1655 set switchbuf=
1656 edit Xqftestfile1
1657 let file1_winid = win_getid()
1658 new Xqftestfile2
1659 let file2_winid = win_getid()
1660 copen
1661 exe "normal 1G\<CR>"
1662 call assert_equal(file1_winid, win_getid())
1663 copen
1664 exe "normal 3G\<CR>"
1665 call assert_equal(file2_winid, win_getid())
1666 copen | only
1667 exe "normal 5G\<CR>"
1668 call assert_equal(2, winnr('$'))
1669 call assert_equal(1, bufwinnr('Xqftestfile3'))
1670
Bram Moolenaar391b1dd2017-03-04 13:47:11 +01001671 " If only quickfix window is open in the current tabpage, jumping to an
Bram Moolenaar1bc353b2019-09-01 14:45:28 +02001672 " entry with 'switchbuf' set to 'usetab' should search in other tabpages.
Bram Moolenaar049cba92016-06-26 14:38:04 +02001673 enew | only
Bram Moolenaar391b1dd2017-03-04 13:47:11 +01001674 set switchbuf=usetab
1675 tabedit Xqftestfile1
1676 tabedit Xqftestfile2
1677 tabedit Xqftestfile3
1678 tabfirst
1679 copen | only
1680 clast
1681 call assert_equal(4, tabpagenr())
1682 tabfirst | tabonly | enew | only
Bram Moolenaar049cba92016-06-26 14:38:04 +02001683
1684 call delete('Xqftestfile1')
1685 call delete('Xqftestfile2')
1686 call delete('Xqftestfile3')
Bram Moolenaar391b1dd2017-03-04 13:47:11 +01001687 set switchbuf&vim
1688
1689 enew | only
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001690endfunc
Bram Moolenaar049cba92016-06-26 14:38:04 +02001691
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001692func Xadjust_qflnum(cchar)
Bram Moolenaar049cba92016-06-26 14:38:04 +02001693 call s:setup_commands(a:cchar)
1694
1695 enew | only
1696
Bram Moolenaarc1542742016-07-20 21:44:37 +02001697 let fname = 'Xqftestfile' . a:cchar
1698 call s:create_test_file(fname)
1699 exe 'edit ' . fname
Bram Moolenaar049cba92016-06-26 14:38:04 +02001700
Bram Moolenaarc1542742016-07-20 21:44:37 +02001701 Xgetexpr [fname . ':5:Line5',
1702 \ fname . ':10:Line10',
1703 \ fname . ':15:Line15',
1704 \ fname . ':20:Line20']
Bram Moolenaar049cba92016-06-26 14:38:04 +02001705
1706 6,14delete
1707 call append(6, ['Buffer', 'Window'])
1708
1709 let l = g:Xgetlist()
1710
1711 call assert_equal(5, l[0].lnum)
1712 call assert_equal(6, l[2].lnum)
1713 call assert_equal(13, l[3].lnum)
1714
1715 enew!
Bram Moolenaarc1542742016-07-20 21:44:37 +02001716 call delete(fname)
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001717endfunc
Bram Moolenaar049cba92016-06-26 14:38:04 +02001718
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001719func Test_adjust_lnum()
Bram Moolenaarc1542742016-07-20 21:44:37 +02001720 call setloclist(0, [])
Bram Moolenaar049cba92016-06-26 14:38:04 +02001721 call Xadjust_qflnum('c')
Bram Moolenaarc1542742016-07-20 21:44:37 +02001722 call setqflist([])
Bram Moolenaar049cba92016-06-26 14:38:04 +02001723 call Xadjust_qflnum('l')
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001724endfunc
Bram Moolenaar049cba92016-06-26 14:38:04 +02001725
1726" Tests for the :grep/:lgrep and :grepadd/:lgrepadd commands
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001727func s:test_xgrep(cchar)
Bram Moolenaar049cba92016-06-26 14:38:04 +02001728 call s:setup_commands(a:cchar)
1729
1730 " The following lines are used for the grep test. Don't remove.
1731 " Grep_Test_Text: Match 1
1732 " Grep_Test_Text: Match 2
1733 " GrepAdd_Test_Text: Match 1
1734 " GrepAdd_Test_Text: Match 2
1735 enew! | only
1736 set makeef&vim
1737 silent Xgrep Grep_Test_Text: test_quickfix.vim
1738 call assert_true(len(g:Xgetlist()) == 3)
1739 Xopen
1740 call assert_true(w:quickfix_title =~ '^:grep')
1741 Xclose
1742 enew
1743 set makeef=Temp_File_##
1744 silent Xgrepadd GrepAdd_Test_Text: test_quickfix.vim
1745 call assert_true(len(g:Xgetlist()) == 6)
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001746endfunc
Bram Moolenaar049cba92016-06-26 14:38:04 +02001747
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001748func Test_grep()
Bram Moolenaar049cba92016-06-26 14:38:04 +02001749 if !has('unix')
1750 " The grepprg may not be set on non-Unix systems
1751 return
1752 endif
1753
1754 call s:test_xgrep('c')
1755 call s:test_xgrep('l')
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001756endfunc
Bram Moolenaar361c8f02016-07-02 15:41:47 +02001757
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001758func Test_two_windows()
Bram Moolenaar361c8f02016-07-02 15:41:47 +02001759 " Use one 'errorformat' for two windows. Add an expression to each of them,
1760 " make sure they each keep their own state.
1761 set efm=%DEntering\ dir\ '%f',%f:%l:%m,%XLeaving\ dir\ '%f'
1762 call mkdir('Xone/a', 'p')
1763 call mkdir('Xtwo/a', 'p')
1764 let lines = ['1', '2', 'one one one', '4', 'two two two', '6', '7']
1765 call writefile(lines, 'Xone/a/one.txt')
1766 call writefile(lines, 'Xtwo/a/two.txt')
1767
1768 new one
1769 let one_id = win_getid()
1770 lexpr ""
1771 new two
1772 let two_id = win_getid()
1773 lexpr ""
1774
1775 laddexpr "Entering dir 'Xtwo/a'"
1776 call win_gotoid(one_id)
1777 laddexpr "Entering dir 'Xone/a'"
1778 call win_gotoid(two_id)
1779 laddexpr 'two.txt:5:two two two'
1780 call win_gotoid(one_id)
1781 laddexpr 'one.txt:3:one one one'
1782
1783 let loc_one = getloclist(one_id)
Bram Moolenaar361c8f02016-07-02 15:41:47 +02001784 call assert_equal('Xone/a/one.txt', bufname(loc_one[1].bufnr))
1785 call assert_equal(3, loc_one[1].lnum)
1786
1787 let loc_two = getloclist(two_id)
Bram Moolenaar361c8f02016-07-02 15:41:47 +02001788 call assert_equal('Xtwo/a/two.txt', bufname(loc_two[1].bufnr))
1789 call assert_equal(5, loc_two[1].lnum)
1790
1791 call win_gotoid(one_id)
1792 bwipe!
1793 call win_gotoid(two_id)
1794 bwipe!
1795 call delete('Xone', 'rf')
1796 call delete('Xtwo', 'rf')
1797endfunc
Bram Moolenaardcb17002016-07-07 18:58:59 +02001798
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001799func XbottomTests(cchar)
Bram Moolenaar537ef082016-07-09 17:56:19 +02001800 call s:setup_commands(a:cchar)
1801
Bram Moolenaarb6fa30c2017-03-29 14:19:25 +02001802 " Calling lbottom without any errors should fail
1803 if a:cchar == 'l'
1804 call assert_fails('lbottom', 'E776:')
1805 endif
1806
Bram Moolenaar875feea2017-06-11 16:07:51 +02001807 call g:Xsetlist([{'filename': 'foo', 'lnum': 42}])
Bram Moolenaar537ef082016-07-09 17:56:19 +02001808 Xopen
Bram Moolenaardcb17002016-07-07 18:58:59 +02001809 let wid = win_getid()
1810 call assert_equal(1, line('.'))
1811 wincmd w
Bram Moolenaar875feea2017-06-11 16:07:51 +02001812 call g:Xsetlist([{'filename': 'var', 'lnum': 24}], 'a')
Bram Moolenaar537ef082016-07-09 17:56:19 +02001813 Xbottom
Bram Moolenaardcb17002016-07-07 18:58:59 +02001814 call win_gotoid(wid)
1815 call assert_equal(2, line('.'))
Bram Moolenaar537ef082016-07-09 17:56:19 +02001816 Xclose
Bram Moolenaardcb17002016-07-07 18:58:59 +02001817endfunc
Bram Moolenaar537ef082016-07-09 17:56:19 +02001818
1819" Tests for the :cbottom and :lbottom commands
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001820func Test_cbottom()
Bram Moolenaar537ef082016-07-09 17:56:19 +02001821 call XbottomTests('c')
1822 call XbottomTests('l')
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001823endfunc
Bram Moolenaarf6acffb2016-07-16 16:54:24 +02001824
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001825func HistoryTest(cchar)
Bram Moolenaarf6acffb2016-07-16 16:54:24 +02001826 call s:setup_commands(a:cchar)
1827
Bram Moolenaarf6acffb2016-07-16 16:54:24 +02001828 " clear all lists after the first one, then replace the first one.
1829 call g:Xsetlist([])
Bram Moolenaarb6fa30c2017-03-29 14:19:25 +02001830 call assert_fails('Xolder 99', 'E380:')
Bram Moolenaarf6acffb2016-07-16 16:54:24 +02001831 let entry = {'filename': 'foo', 'lnum': 42}
1832 call g:Xsetlist([entry], 'r')
1833 call g:Xsetlist([entry, entry])
1834 call g:Xsetlist([entry, entry, entry])
1835 let res = split(execute(a:cchar . 'hist'), "\n")
1836 call assert_equal(3, len(res))
1837 let common = 'errors :set' . (a:cchar == 'c' ? 'qf' : 'loc') . 'list()'
1838 call assert_equal(' error list 1 of 3; 1 ' . common, res[0])
1839 call assert_equal(' error list 2 of 3; 2 ' . common, res[1])
1840 call assert_equal('> error list 3 of 3; 3 ' . common, res[2])
Bram Moolenaarb4d5fba2017-09-11 19:31:28 +02001841
Bram Moolenaar8ffc7c82019-05-05 21:00:26 +02001842 " Test for changing the quickfix lists
1843 call assert_equal(3, g:Xgetlist({'nr' : 0}).nr)
1844 exe '1' . a:cchar . 'hist'
1845 call assert_equal(1, g:Xgetlist({'nr' : 0}).nr)
1846 exe '3' . a:cchar . 'hist'
1847 call assert_equal(3, g:Xgetlist({'nr' : 0}).nr)
1848 call assert_fails('-2' . a:cchar . 'hist', 'E16:')
1849 call assert_fails('4' . a:cchar . 'hist', 'E16:')
1850
Bram Moolenaarb4d5fba2017-09-11 19:31:28 +02001851 call g:Xsetlist([], 'f')
1852 let l = split(execute(a:cchar . 'hist'), "\n")
1853 call assert_equal('No entries', l[0])
Bram Moolenaar8ffc7c82019-05-05 21:00:26 +02001854 if a:cchar == 'c'
1855 call assert_fails('4chist', 'E16:')
1856 else
1857 call assert_fails('4lhist', 'E776:')
1858 endif
Bram Moolenaar5b69c222019-01-11 14:50:06 +01001859
1860 " An empty list should still show the stack history
1861 call g:Xsetlist([])
1862 let res = split(execute(a:cchar . 'hist'), "\n")
1863 call assert_equal('> error list 1 of 1; 0 ' . common, res[0])
1864
1865 call g:Xsetlist([], 'f')
Bram Moolenaarf6acffb2016-07-16 16:54:24 +02001866endfunc
1867
1868func Test_history()
1869 call HistoryTest('c')
1870 call HistoryTest('l')
1871endfunc
Bram Moolenaar015102e2016-07-16 18:24:56 +02001872
1873func Test_duplicate_buf()
1874 " make sure we can get the highest buffer number
1875 edit DoesNotExist
1876 edit DoesNotExist2
1877 let last_buffer = bufnr("$")
1878
1879 " make sure only one buffer is created
1880 call writefile(['this one', 'that one'], 'Xgrepthis')
1881 vimgrep one Xgrepthis
1882 vimgrep one Xgrepthis
1883 call assert_equal(last_buffer + 1, bufnr("$"))
1884
1885 call delete('Xgrepthis')
1886endfunc
Bram Moolenaard823fa92016-08-12 16:29:27 +02001887
1888" Quickfix/Location list set/get properties tests
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001889func Xproperty_tests(cchar)
Bram Moolenaard823fa92016-08-12 16:29:27 +02001890 call s:setup_commands(a:cchar)
1891
1892 " Error cases
1893 call assert_fails('call g:Xgetlist(99)', 'E715:')
1894 call assert_fails('call g:Xsetlist(99)', 'E714:')
1895 call assert_fails('call g:Xsetlist([], "a", [])', 'E715:')
1896
1897 " Set and get the title
Bram Moolenaarb6fa30c2017-03-29 14:19:25 +02001898 call g:Xsetlist([])
Bram Moolenaard823fa92016-08-12 16:29:27 +02001899 Xopen
1900 wincmd p
1901 call g:Xsetlist([{'filename':'foo', 'lnum':27}])
Bram Moolenaar86f100dc2017-06-28 21:26:27 +02001902 let s = g:Xsetlist([], 'a', {'title' : 'Sample'})
1903 call assert_equal(0, s)
Bram Moolenaard823fa92016-08-12 16:29:27 +02001904 let d = g:Xgetlist({"title":1})
1905 call assert_equal('Sample', d.title)
Bram Moolenaara2aa8a22018-04-24 13:55:00 +02001906 " Try setting title to a non-string value
1907 call assert_equal(-1, g:Xsetlist([], 'a', {'title' : ['Test']}))
1908 call assert_equal('Sample', g:Xgetlist({"title":1}).title)
Bram Moolenaard823fa92016-08-12 16:29:27 +02001909
1910 Xopen
1911 call assert_equal('Sample', w:quickfix_title)
1912 Xclose
1913
Bram Moolenaar2b529bb2016-08-27 13:35:35 +02001914 " Tests for action argument
1915 silent! Xolder 999
1916 let qfnr = g:Xgetlist({'all':1}).nr
1917 call g:Xsetlist([], 'r', {'title' : 'N1'})
1918 call assert_equal('N1', g:Xgetlist({'all':1}).title)
1919 call g:Xsetlist([], ' ', {'title' : 'N2'})
1920 call assert_equal(qfnr + 1, g:Xgetlist({'all':1}).nr)
Bram Moolenaar890680c2016-09-27 21:28:56 +02001921
1922 let res = g:Xgetlist({'nr': 0})
1923 call assert_equal(qfnr + 1, res.nr)
1924 call assert_equal(['nr'], keys(res))
1925
Bram Moolenaar2b529bb2016-08-27 13:35:35 +02001926 call g:Xsetlist([], ' ', {'title' : 'N3'})
1927 call assert_equal('N2', g:Xgetlist({'nr':2, 'title':1}).title)
1928
Bram Moolenaaree85df32017-03-19 14:19:50 +01001929 " Changing the title of an earlier quickfix list
Bram Moolenaar55b69262017-08-13 13:42:01 +02001930 call g:Xsetlist([], 'r', {'title' : 'NewTitle', 'nr' : 2})
Bram Moolenaaree85df32017-03-19 14:19:50 +01001931 call assert_equal('NewTitle', g:Xgetlist({'nr':2, 'title':1}).title)
1932
1933 " Changing the title of an invalid quickfix list
1934 call assert_equal(-1, g:Xsetlist([], ' ',
1935 \ {'title' : 'SomeTitle', 'nr' : 99}))
1936 call assert_equal(-1, g:Xsetlist([], ' ',
1937 \ {'title' : 'SomeTitle', 'nr' : 'abc'}))
1938
1939 if a:cchar == 'c'
1940 copen
1941 call assert_equal({'winid':win_getid()}, getqflist({'winid':1}))
1942 cclose
1943 endif
1944
Bram Moolenaard823fa92016-08-12 16:29:27 +02001945 " Invalid arguments
1946 call assert_fails('call g:Xgetlist([])', 'E715')
1947 call assert_fails('call g:Xsetlist([], "a", [])', 'E715')
1948 let s = g:Xsetlist([], 'a', {'abc':1})
1949 call assert_equal(-1, s)
1950
1951 call assert_equal({}, g:Xgetlist({'abc':1}))
Bram Moolenaara6d48492017-12-12 22:45:31 +01001952 call assert_equal('', g:Xgetlist({'nr':99, 'title':1}).title)
1953 call assert_equal('', g:Xgetlist({'nr':[], 'title':1}).title)
Bram Moolenaard823fa92016-08-12 16:29:27 +02001954
1955 if a:cchar == 'l'
Bram Moolenaar890680c2016-09-27 21:28:56 +02001956 call assert_equal({}, getloclist(99, {'title': 1}))
Bram Moolenaard823fa92016-08-12 16:29:27 +02001957 endif
Bram Moolenaar8f77c5a2017-04-30 14:21:00 +02001958
1959 " Context related tests
Bram Moolenaar86f100dc2017-06-28 21:26:27 +02001960 let s = g:Xsetlist([], 'a', {'context':[1,2,3]})
1961 call assert_equal(0, s)
Bram Moolenaar8f77c5a2017-04-30 14:21:00 +02001962 call test_garbagecollect_now()
1963 let d = g:Xgetlist({'context':1})
1964 call assert_equal([1,2,3], d.context)
1965 call g:Xsetlist([], 'a', {'context':{'color':'green'}})
1966 let d = g:Xgetlist({'context':1})
1967 call assert_equal({'color':'green'}, d.context)
1968 call g:Xsetlist([], 'a', {'context':"Context info"})
1969 let d = g:Xgetlist({'context':1})
1970 call assert_equal("Context info", d.context)
1971 call g:Xsetlist([], 'a', {'context':246})
1972 let d = g:Xgetlist({'context':1})
1973 call assert_equal(246, d.context)
1974 if a:cchar == 'l'
1975 " Test for copying context across two different location lists
1976 new | only
1977 let w1_id = win_getid()
1978 let l = [1]
1979 call setloclist(0, [], 'a', {'context':l})
1980 new
1981 let w2_id = win_getid()
1982 call add(l, 2)
1983 call assert_equal([1, 2], getloclist(w1_id, {'context':1}).context)
1984 call assert_equal([1, 2], getloclist(w2_id, {'context':1}).context)
1985 unlet! l
1986 call assert_equal([1, 2], getloclist(w2_id, {'context':1}).context)
1987 only
1988 call setloclist(0, [], 'f')
Bram Moolenaara6d48492017-12-12 22:45:31 +01001989 call assert_equal('', getloclist(0, {'context':1}).context)
Bram Moolenaar8f77c5a2017-04-30 14:21:00 +02001990 endif
Bram Moolenaar6e62da32017-05-28 08:16:25 +02001991
1992 " Test for changing the context of previous quickfix lists
1993 call g:Xsetlist([], 'f')
1994 Xexpr "One"
1995 Xexpr "Two"
1996 Xexpr "Three"
Bram Moolenaar55b69262017-08-13 13:42:01 +02001997 call g:Xsetlist([], 'r', {'context' : [1], 'nr' : 1})
1998 call g:Xsetlist([], 'a', {'context' : [2], 'nr' : 2})
Bram Moolenaar6e62da32017-05-28 08:16:25 +02001999 " Also, check for setting the context using quickfix list number zero.
Bram Moolenaar55b69262017-08-13 13:42:01 +02002000 call g:Xsetlist([], 'r', {'context' : [3], 'nr' : 0})
Bram Moolenaar6e62da32017-05-28 08:16:25 +02002001 call test_garbagecollect_now()
2002 let l = g:Xgetlist({'nr' : 1, 'context' : 1})
2003 call assert_equal([1], l.context)
2004 let l = g:Xgetlist({'nr' : 2, 'context' : 1})
2005 call assert_equal([2], l.context)
2006 let l = g:Xgetlist({'nr' : 3, 'context' : 1})
2007 call assert_equal([3], l.context)
2008
2009 " Test for changing the context through reference and for garbage
2010 " collection of quickfix context
2011 let l = ["red"]
2012 call g:Xsetlist([], ' ', {'context' : l})
2013 call add(l, "blue")
2014 let x = g:Xgetlist({'context' : 1})
2015 call add(x.context, "green")
2016 call assert_equal(["red", "blue", "green"], l)
2017 call assert_equal(["red", "blue", "green"], x.context)
2018 unlet l
2019 call test_garbagecollect_now()
2020 let m = g:Xgetlist({'context' : 1})
2021 call assert_equal(["red", "blue", "green"], m.context)
Bram Moolenaar6a8958d2017-06-22 21:33:20 +02002022
2023 " Test for setting/getting items
2024 Xexpr ""
2025 let qfprev = g:Xgetlist({'nr':0})
Bram Moolenaar86f100dc2017-06-28 21:26:27 +02002026 let s = g:Xsetlist([], ' ', {'title':'Green',
Bram Moolenaar6a8958d2017-06-22 21:33:20 +02002027 \ 'items' : [{'filename':'F1', 'lnum':10}]})
Bram Moolenaar86f100dc2017-06-28 21:26:27 +02002028 call assert_equal(0, s)
Bram Moolenaar6a8958d2017-06-22 21:33:20 +02002029 let qfcur = g:Xgetlist({'nr':0})
2030 call assert_true(qfcur.nr == qfprev.nr + 1)
2031 let l = g:Xgetlist({'items':1})
2032 call assert_equal('F1', bufname(l.items[0].bufnr))
2033 call assert_equal(10, l.items[0].lnum)
2034 call g:Xsetlist([], 'a', {'items' : [{'filename':'F2', 'lnum':20},
2035 \ {'filename':'F2', 'lnum':30}]})
2036 let l = g:Xgetlist({'items':1})
2037 call assert_equal('F2', bufname(l.items[2].bufnr))
2038 call assert_equal(30, l.items[2].lnum)
2039 call g:Xsetlist([], 'r', {'items' : [{'filename':'F3', 'lnum':40}]})
2040 let l = g:Xgetlist({'items':1})
2041 call assert_equal('F3', bufname(l.items[0].bufnr))
2042 call assert_equal(40, l.items[0].lnum)
2043 call g:Xsetlist([], 'r', {'items' : []})
2044 let l = g:Xgetlist({'items':1})
2045 call assert_equal(0, len(l.items))
2046
Bram Moolenaarb4d5fba2017-09-11 19:31:28 +02002047 call g:Xsetlist([], 'r', {'title' : 'TestTitle'})
2048 call g:Xsetlist([], 'r', {'items' : [{'filename' : 'F1', 'lnum' : 10, 'text' : 'L10'}]})
2049 call g:Xsetlist([], 'r', {'items' : [{'filename' : 'F1', 'lnum' : 10, 'text' : 'L10'}]})
2050 call assert_equal('TestTitle', g:Xgetlist({'title' : 1}).title)
2051
Bram Moolenaarc9cc9c72018-09-02 15:18:42 +02002052 " Test for getting id of window associated with a location list window
2053 if a:cchar == 'l'
2054 only
2055 call assert_equal(0, g:Xgetlist({'all' : 1}).filewinid)
2056 let wid = win_getid()
2057 Xopen
2058 call assert_equal(wid, g:Xgetlist({'filewinid' : 1}).filewinid)
2059 wincmd w
2060 call assert_equal(0, g:Xgetlist({'filewinid' : 1}).filewinid)
2061 only
2062 endif
2063
Bram Moolenaarae338332017-08-11 20:25:26 +02002064 " The following used to crash Vim with address sanitizer
2065 call g:Xsetlist([], 'f')
2066 call g:Xsetlist([], 'a', {'items' : [{'filename':'F1', 'lnum':10}]})
2067 call assert_equal(10, g:Xgetlist({'items':1}).items[0].lnum)
2068
Bram Moolenaara2aa8a22018-04-24 13:55:00 +02002069 " Try setting the items using a string
2070 call assert_equal(-1, g:Xsetlist([], ' ', {'items' : 'Test'}))
2071
Bram Moolenaar6a8958d2017-06-22 21:33:20 +02002072 " Save and restore the quickfix stack
2073 call g:Xsetlist([], 'f')
2074 call assert_equal(0, g:Xgetlist({'nr':'$'}).nr)
2075 Xexpr "File1:10:Line1"
2076 Xexpr "File2:20:Line2"
2077 Xexpr "File3:30:Line3"
2078 let last_qf = g:Xgetlist({'nr':'$'}).nr
2079 call assert_equal(3, last_qf)
2080 let qstack = []
2081 for i in range(1, last_qf)
2082 let qstack = add(qstack, g:Xgetlist({'nr':i, 'all':1}))
2083 endfor
2084 call g:Xsetlist([], 'f')
2085 for i in range(len(qstack))
2086 call g:Xsetlist([], ' ', qstack[i])
2087 endfor
2088 call assert_equal(3, g:Xgetlist({'nr':'$'}).nr)
2089 call assert_equal(10, g:Xgetlist({'nr':1, 'items':1}).items[0].lnum)
2090 call assert_equal(20, g:Xgetlist({'nr':2, 'items':1}).items[0].lnum)
2091 call assert_equal(30, g:Xgetlist({'nr':3, 'items':1}).items[0].lnum)
2092 call g:Xsetlist([], 'f')
2093
2094 " Swap two quickfix lists
2095 Xexpr "File1:10:Line10"
2096 Xexpr "File2:20:Line20"
2097 Xexpr "File3:30:Line30"
2098 call g:Xsetlist([], 'r', {'nr':1,'title':'Colors','context':['Colors']})
2099 call g:Xsetlist([], 'r', {'nr':2,'title':'Fruits','context':['Fruits']})
2100 let l1=g:Xgetlist({'nr':1,'all':1})
2101 let l2=g:Xgetlist({'nr':2,'all':1})
Bram Moolenaara539f4f2017-08-30 20:33:55 +02002102 let save_id = l1.id
2103 let l1.id=l2.id
2104 let l2.id=save_id
Bram Moolenaar6a8958d2017-06-22 21:33:20 +02002105 call g:Xsetlist([], 'r', l1)
2106 call g:Xsetlist([], 'r', l2)
2107 let newl1=g:Xgetlist({'nr':1,'all':1})
2108 let newl2=g:Xgetlist({'nr':2,'all':1})
Bram Moolenaarb4d5fba2017-09-11 19:31:28 +02002109 call assert_equal('Fruits', newl1.title)
Bram Moolenaar6a8958d2017-06-22 21:33:20 +02002110 call assert_equal(['Fruits'], newl1.context)
2111 call assert_equal('Line20', newl1.items[0].text)
Bram Moolenaarb4d5fba2017-09-11 19:31:28 +02002112 call assert_equal('Colors', newl2.title)
Bram Moolenaar6a8958d2017-06-22 21:33:20 +02002113 call assert_equal(['Colors'], newl2.context)
2114 call assert_equal('Line10', newl2.items[0].text)
2115 call g:Xsetlist([], 'f')
Bram Moolenaaree85df32017-03-19 14:19:50 +01002116endfunc
Bram Moolenaard823fa92016-08-12 16:29:27 +02002117
Bram Moolenaar2b946c92016-11-12 18:14:44 +01002118func Test_qf_property()
Bram Moolenaard823fa92016-08-12 16:29:27 +02002119 call Xproperty_tests('c')
2120 call Xproperty_tests('l')
Bram Moolenaaree85df32017-03-19 14:19:50 +01002121endfunc
Bram Moolenaar04c4ce62016-09-01 15:45:58 +02002122
Bram Moolenaar5b69c222019-01-11 14:50:06 +01002123" Test for setting the current index in the location/quickfix list
2124func Xtest_setqfidx(cchar)
2125 call s:setup_commands(a:cchar)
2126
2127 Xgetexpr "F1:10:1:Line1\nF2:20:2:Line2\nF3:30:3:Line3"
2128 Xgetexpr "F4:10:1:Line1\nF5:20:2:Line2\nF6:30:3:Line3"
2129 Xgetexpr "F7:10:1:Line1\nF8:20:2:Line2\nF9:30:3:Line3"
2130
2131 call g:Xsetlist([], 'a', {'nr' : 3, 'idx' : 2})
2132 call g:Xsetlist([], 'a', {'nr' : 2, 'idx' : 2})
2133 call g:Xsetlist([], 'a', {'nr' : 1, 'idx' : 3})
2134 Xolder 2
2135 Xopen
2136 call assert_equal(3, line('.'))
2137 Xnewer
2138 call assert_equal(2, line('.'))
2139 Xnewer
2140 call assert_equal(2, line('.'))
2141 " Update the current index with the quickfix window open
2142 wincmd w
2143 call g:Xsetlist([], 'a', {'nr' : 3, 'idx' : 3})
2144 Xopen
2145 call assert_equal(3, line('.'))
2146 Xclose
2147
2148 " Set the current index to the last entry
2149 call g:Xsetlist([], 'a', {'nr' : 1, 'idx' : '$'})
2150 call assert_equal(3, g:Xgetlist({'nr' : 1, 'idx' : 0}).idx)
2151 " A large value should set the index to the last index
2152 call g:Xsetlist([], 'a', {'nr' : 1, 'idx' : 1})
2153 call g:Xsetlist([], 'a', {'nr' : 1, 'idx' : 999})
2154 call assert_equal(3, g:Xgetlist({'nr' : 1, 'idx' : 0}).idx)
2155 " Invalid index values
2156 call g:Xsetlist([], 'a', {'nr' : 1, 'idx' : -1})
2157 call assert_equal(3, g:Xgetlist({'nr' : 1, 'idx' : 0}).idx)
2158 call g:Xsetlist([], 'a', {'nr' : 1, 'idx' : 0})
2159 call assert_equal(3, g:Xgetlist({'nr' : 1, 'idx' : 0}).idx)
2160 call g:Xsetlist([], 'a', {'nr' : 1, 'idx' : 'xx'})
2161 call assert_equal(3, g:Xgetlist({'nr' : 1, 'idx' : 0}).idx)
2162 call assert_fails("call g:Xsetlist([], 'a', {'nr':1, 'idx':[]})", 'E745:')
2163
2164 call g:Xsetlist([], 'f')
2165 new | only
2166endfunc
2167
2168func Test_setqfidx()
2169 call Xtest_setqfidx('c')
2170 call Xtest_setqfidx('l')
2171endfunc
2172
Bram Moolenaar04c4ce62016-09-01 15:45:58 +02002173" Tests for the QuickFixCmdPre/QuickFixCmdPost autocommands
Bram Moolenaar2b946c92016-11-12 18:14:44 +01002174func QfAutoCmdHandler(loc, cmd)
Bram Moolenaar04c4ce62016-09-01 15:45:58 +02002175 call add(g:acmds, a:loc . a:cmd)
Bram Moolenaar2b946c92016-11-12 18:14:44 +01002176endfunc
Bram Moolenaar04c4ce62016-09-01 15:45:58 +02002177
Bram Moolenaar2b946c92016-11-12 18:14:44 +01002178func Test_Autocmd()
Bram Moolenaar04c4ce62016-09-01 15:45:58 +02002179 autocmd QuickFixCmdPre * call QfAutoCmdHandler('pre', expand('<amatch>'))
2180 autocmd QuickFixCmdPost * call QfAutoCmdHandler('post', expand('<amatch>'))
2181
2182 let g:acmds = []
2183 cexpr "F1:10:Line 10"
2184 caddexpr "F1:20:Line 20"
2185 cgetexpr "F1:30:Line 30"
Bram Moolenaar1ed22762017-11-28 18:03:44 +01002186 cexpr ""
2187 caddexpr ""
2188 cgetexpr ""
2189 silent! cexpr non_existing_func()
2190 silent! caddexpr non_existing_func()
2191 silent! cgetexpr non_existing_func()
Bram Moolenaar04c4ce62016-09-01 15:45:58 +02002192 let l = ['precexpr',
2193 \ 'postcexpr',
2194 \ 'precaddexpr',
2195 \ 'postcaddexpr',
2196 \ 'precgetexpr',
2197 \ 'postcgetexpr',
Bram Moolenaar1ed22762017-11-28 18:03:44 +01002198 \ 'precexpr',
2199 \ 'postcexpr',
2200 \ 'precaddexpr',
2201 \ 'postcaddexpr',
2202 \ 'precgetexpr',
2203 \ 'postcgetexpr',
2204 \ 'precexpr',
2205 \ 'precaddexpr',
2206 \ 'precgetexpr']
2207 call assert_equal(l, g:acmds)
2208
2209 let g:acmds = []
2210 enew! | call append(0, "F2:10:Line 10")
2211 cbuffer!
2212 enew! | call append(0, "F2:20:Line 20")
2213 cgetbuffer
2214 enew! | call append(0, "F2:30:Line 30")
2215 caddbuffer
2216 new
2217 let bnum = bufnr('%')
2218 bunload
2219 exe 'silent! cbuffer! ' . bnum
2220 exe 'silent! cgetbuffer ' . bnum
2221 exe 'silent! caddbuffer ' . bnum
2222 enew!
2223 let l = ['precbuffer',
Bram Moolenaar04c4ce62016-09-01 15:45:58 +02002224 \ 'postcbuffer',
2225 \ 'precgetbuffer',
2226 \ 'postcgetbuffer',
2227 \ 'precaddbuffer',
Bram Moolenaar1ed22762017-11-28 18:03:44 +01002228 \ 'postcaddbuffer',
2229 \ 'precbuffer',
2230 \ 'precgetbuffer',
2231 \ 'precaddbuffer']
Bram Moolenaar04c4ce62016-09-01 15:45:58 +02002232 call assert_equal(l, g:acmds)
Bram Moolenaar1ed22762017-11-28 18:03:44 +01002233
2234 call writefile(['Xtest:1:Line1'], 'Xtest')
2235 call writefile([], 'Xempty')
2236 let g:acmds = []
2237 cfile Xtest
2238 caddfile Xtest
2239 cgetfile Xtest
2240 cfile Xempty
2241 caddfile Xempty
2242 cgetfile Xempty
2243 silent! cfile do_not_exist
2244 silent! caddfile do_not_exist
2245 silent! cgetfile do_not_exist
2246 let l = ['precfile',
2247 \ 'postcfile',
2248 \ 'precaddfile',
2249 \ 'postcaddfile',
2250 \ 'precgetfile',
2251 \ 'postcgetfile',
2252 \ 'precfile',
2253 \ 'postcfile',
2254 \ 'precaddfile',
2255 \ 'postcaddfile',
2256 \ 'precgetfile',
2257 \ 'postcgetfile',
2258 \ 'precfile',
2259 \ 'postcfile',
2260 \ 'precaddfile',
2261 \ 'postcaddfile',
2262 \ 'precgetfile',
2263 \ 'postcgetfile']
2264 call assert_equal(l, g:acmds)
2265
2266 let g:acmds = []
2267 helpgrep quickfix
2268 silent! helpgrep non_existing_help_topic
2269 vimgrep test Xtest
2270 vimgrepadd test Xtest
2271 silent! vimgrep non_existing_test Xtest
2272 silent! vimgrepadd non_existing_test Xtest
2273 set makeprg=
2274 silent! make
2275 set makeprg&
2276 let l = ['prehelpgrep',
2277 \ 'posthelpgrep',
2278 \ 'prehelpgrep',
2279 \ 'posthelpgrep',
2280 \ 'previmgrep',
2281 \ 'postvimgrep',
2282 \ 'previmgrepadd',
2283 \ 'postvimgrepadd',
2284 \ 'previmgrep',
2285 \ 'postvimgrep',
2286 \ 'previmgrepadd',
2287 \ 'postvimgrepadd',
2288 \ 'premake',
2289 \ 'postmake']
2290 call assert_equal(l, g:acmds)
2291
2292 if has('unix')
2293 " Run this test only on Unix-like systems. The grepprg may not be set on
2294 " non-Unix systems.
2295 " The following lines are used for the grep test. Don't remove.
2296 " Grep_Autocmd_Text: Match 1
2297 " GrepAdd_Autocmd_Text: Match 2
2298 let g:acmds = []
2299 silent grep Grep_Autocmd_Text test_quickfix.vim
2300 silent grepadd GrepAdd_Autocmd_Text test_quickfix.vim
2301 silent grep abc123def Xtest
2302 silent grepadd abc123def Xtest
2303 let l = ['pregrep',
2304 \ 'postgrep',
2305 \ 'pregrepadd',
2306 \ 'postgrepadd',
2307 \ 'pregrep',
2308 \ 'postgrep',
2309 \ 'pregrepadd',
2310 \ 'postgrepadd']
2311 call assert_equal(l, g:acmds)
2312 endif
2313
2314 call delete('Xtest')
2315 call delete('Xempty')
Bram Moolenaarb254af32017-12-18 19:48:58 +01002316 au! QuickFixCmdPre
2317 au! QuickFixCmdPost
Bram Moolenaar2b946c92016-11-12 18:14:44 +01002318endfunc
Bram Moolenaar21662be2016-11-06 14:46:44 +01002319
Bram Moolenaar2b946c92016-11-12 18:14:44 +01002320func Test_Autocmd_Exception()
Bram Moolenaar21662be2016-11-06 14:46:44 +01002321 set efm=%m
2322 lgetexpr '?'
2323
2324 try
2325 call DoesNotExit()
2326 catch
2327 lgetexpr '1'
2328 finally
2329 lgetexpr '1'
2330 endtry
2331
2332 call assert_equal('1', getloclist(0)[0].text)
2333
2334 set efm&vim
Bram Moolenaar2b946c92016-11-12 18:14:44 +01002335endfunc
Bram Moolenaar63bed3d2016-11-12 15:36:54 +01002336
Bram Moolenaar2b946c92016-11-12 18:14:44 +01002337func Test_caddbuffer_wrong()
2338 " This used to cause a memory access in freed memory.
Bram Moolenaar63bed3d2016-11-12 15:36:54 +01002339 let save_efm = &efm
2340 set efm=%EEEE%m,%WWWW,%+CCCC%>%#,%GGGG%.#
2341 cgetexpr ['WWWW', 'EEEE', 'CCCC']
2342 let &efm = save_efm
Bram Moolenaar2b946c92016-11-12 18:14:44 +01002343 caddbuffer
Bram Moolenaar63bed3d2016-11-12 15:36:54 +01002344 bwipe!
2345endfunc
Bram Moolenaar2b946c92016-11-12 18:14:44 +01002346
2347func Test_caddexpr_wrong()
2348 " This used to cause a memory access in freed memory.
2349 cbuffer
2350 cbuffer
2351 copen
2352 let save_efm = &efm
2353 set efm=%
2354 call assert_fails('caddexpr ""', 'E376:')
2355 let &efm = save_efm
2356endfunc
Bram Moolenaar7618e002016-11-13 15:09:26 +01002357
2358func Test_dirstack_cleanup()
2359 " This used to cause a memory access in freed memory.
2360 let save_efm = &efm
2361 lexpr '0'
2362 lopen
2363 fun X(c)
2364 let save_efm=&efm
2365 set efm=%D%f
2366 if a:c == 'c'
2367 caddexpr '::'
2368 else
2369 laddexpr ':0:0'
2370 endif
2371 let &efm=save_efm
2372 endfun
2373 call X('c')
2374 call X('l')
2375 call setqflist([], 'r')
2376 caddbuffer
2377 let &efm = save_efm
2378endfunc
Bram Moolenaar391b1dd2017-03-04 13:47:11 +01002379
2380" Tests for jumping to entries from the location list window and quickfix
2381" window
2382func Test_cwindow_jump()
2383 set efm=%f%%%l%%%m
2384 lgetexpr ["F1%10%Line 10", "F2%20%Line 20", "F3%30%Line 30"]
2385 lopen | only
2386 lfirst
2387 call assert_true(winnr('$') == 2)
2388 call assert_true(winnr() == 1)
2389 " Location list for the new window should be set
2390 call assert_true(getloclist(0)[2].text == 'Line 30')
2391
2392 " Open a scratch buffer
2393 " Open a new window and create a location list
2394 " Open the location list window and close the other window
2395 " Jump to an entry.
Bram Moolenaareeb1b9c2019-02-10 22:59:04 +01002396 " Should create a new window and jump to the entry. The scratch buffer
Bram Moolenaar391b1dd2017-03-04 13:47:11 +01002397 " should not be used.
2398 enew | only
2399 set buftype=nofile
2400 below new
2401 lgetexpr ["F1%10%Line 10", "F2%20%Line 20", "F3%30%Line 30"]
2402 lopen
2403 2wincmd c
2404 lnext
2405 call assert_true(winnr('$') == 3)
2406 call assert_true(winnr() == 2)
2407
2408 " Open two windows with two different location lists
2409 " Open the location list window and close the previous window
2410 " Jump to an entry in the location list window
2411 " Should open the file in the first window and not set the location list.
2412 enew | only
2413 lgetexpr ["F1%5%Line 5"]
2414 below new
2415 lgetexpr ["F1%10%Line 10", "F2%20%Line 20", "F3%30%Line 30"]
2416 lopen
2417 2wincmd c
2418 lnext
2419 call assert_true(winnr() == 1)
2420 call assert_true(getloclist(0)[0].text == 'Line 5')
2421
2422 enew | only
2423 cgetexpr ["F1%10%Line 10", "F2%20%Line 20", "F3%30%Line 30"]
2424 copen
2425 cnext
2426 call assert_true(winnr('$') == 2)
2427 call assert_true(winnr() == 1)
2428
2429 enew | only
2430 set efm&vim
2431endfunc
Bram Moolenaaree85df32017-03-19 14:19:50 +01002432
Bram Moolenaare00fdf32019-09-15 19:09:42 +02002433func Test_cwindow_highlight()
2434 CheckScreendump
2435
2436 let lines =<< trim END
2437 set t_u7=
2438 call setline(1, ['some', 'text', 'with', 'matches'])
2439 write XCwindow
2440 vimgrep e XCwindow
2441 redraw
2442 cwindow 4
2443 END
2444 call writefile(lines, 'XtestCwindow')
2445 let buf = RunVimInTerminal('-S XtestCwindow', #{rows: 12})
2446 call VerifyScreenDump(buf, 'Test_quickfix_cwindow_1', {})
2447
2448 call term_sendkeys(buf, ":cnext\<CR>")
2449 call VerifyScreenDump(buf, 'Test_quickfix_cwindow_2', {})
2450
2451 " clean up
2452 call StopVimInTerminal(buf)
2453 call delete('XtestCwindow')
2454 call delete('XCwindow')
2455endfunc
2456
Bram Moolenaaree85df32017-03-19 14:19:50 +01002457func XvimgrepTests(cchar)
2458 call s:setup_commands(a:cchar)
2459
2460 call writefile(['Editor:VIM vim',
2461 \ 'Editor:Emacs EmAcS',
2462 \ 'Editor:Notepad NOTEPAD'], 'Xtestfile1')
2463 call writefile(['Linux', 'MacOS', 'MS-Windows'], 'Xtestfile2')
2464
2465 " Error cases
2466 call assert_fails('Xvimgrep /abc *', 'E682:')
2467
2468 let @/=''
2469 call assert_fails('Xvimgrep // *', 'E35:')
2470
2471 call assert_fails('Xvimgrep abc', 'E683:')
2472 call assert_fails('Xvimgrep a1b2c3 Xtestfile1', 'E480:')
2473 call assert_fails('Xvimgrep pat Xa1b2c3', 'E480:')
2474
2475 Xexpr ""
2476 Xvimgrepadd Notepad Xtestfile1
2477 Xvimgrepadd MacOS Xtestfile2
2478 let l = g:Xgetlist()
2479 call assert_equal(2, len(l))
2480 call assert_equal('Editor:Notepad NOTEPAD', l[0].text)
2481
2482 Xvimgrep #\cvim#g Xtestfile?
2483 let l = g:Xgetlist()
2484 call assert_equal(2, len(l))
2485 call assert_equal(8, l[0].col)
2486 call assert_equal(12, l[1].col)
2487
2488 1Xvimgrep ?Editor? Xtestfile*
2489 let l = g:Xgetlist()
2490 call assert_equal(1, len(l))
2491 call assert_equal('Editor:VIM vim', l[0].text)
2492
2493 edit +3 Xtestfile2
2494 Xvimgrep +\cemacs+j Xtestfile1
2495 let l = g:Xgetlist()
2496 call assert_equal('Xtestfile2', bufname(''))
2497 call assert_equal('Editor:Emacs EmAcS', l[0].text)
2498
Bram Moolenaar2225ebb2018-04-24 15:48:11 +02002499 " Test for unloading a buffer after vimgrep searched the buffer
2500 %bwipe
2501 Xvimgrep /Editor/j Xtestfile*
2502 call assert_equal(0, getbufinfo('Xtestfile1')[0].loaded)
2503 call assert_equal([], getbufinfo('Xtestfile2'))
2504
Bram Moolenaaree85df32017-03-19 14:19:50 +01002505 call delete('Xtestfile1')
2506 call delete('Xtestfile2')
2507endfunc
2508
2509" Tests for the :vimgrep command
2510func Test_vimgrep()
2511 call XvimgrepTests('c')
2512 call XvimgrepTests('l')
2513endfunc
Bram Moolenaar69f40be2017-04-02 15:15:49 +02002514
Bram Moolenaar1c299432018-10-28 14:36:09 +01002515" Test for incsearch highlighting of the :vimgrep pattern
2516" This test used to cause "E315: ml_get: invalid lnum" errors.
2517func Test_vimgrep_incsearch()
2518 enew
2519 set incsearch
2520 call test_override("char_avail", 1)
2521
2522 call feedkeys(":2vimgrep assert test_quickfix.vim test_cdo.vim\<CR>", "ntx")
2523 let l = getqflist()
2524 call assert_equal(2, len(l))
2525
2526 call test_override("ALL", 0)
2527 set noincsearch
2528endfunc
2529
Bram Moolenaar69f40be2017-04-02 15:15:49 +02002530func XfreeTests(cchar)
2531 call s:setup_commands(a:cchar)
2532
2533 enew | only
2534
2535 " Deleting the quickfix stack should work even When the current list is
2536 " somewhere in the middle of the stack
2537 Xexpr ['Xfile1:10:10:Line 10', 'Xfile1:15:15:Line 15']
2538 Xexpr ['Xfile2:20:20:Line 20', 'Xfile2:25:25:Line 25']
2539 Xexpr ['Xfile3:30:30:Line 30', 'Xfile3:35:35:Line 35']
2540 Xolder
2541 call g:Xsetlist([], 'f')
2542 call assert_equal(0, len(g:Xgetlist()))
2543
2544 " After deleting the stack, adding a new list should create a stack with a
2545 " single list.
2546 Xexpr ['Xfile1:10:10:Line 10', 'Xfile1:15:15:Line 15']
2547 call assert_equal(1, g:Xgetlist({'all':1}).nr)
2548
2549 " Deleting the stack from a quickfix window should update/clear the
2550 " quickfix/location list window.
2551 Xexpr ['Xfile1:10:10:Line 10', 'Xfile1:15:15:Line 15']
2552 Xexpr ['Xfile2:20:20:Line 20', 'Xfile2:25:25:Line 25']
2553 Xexpr ['Xfile3:30:30:Line 30', 'Xfile3:35:35:Line 35']
2554 Xolder
2555 Xwindow
2556 call g:Xsetlist([], 'f')
2557 call assert_equal(2, winnr('$'))
2558 call assert_equal(1, line('$'))
2559 Xclose
2560
2561 " Deleting the stack from a non-quickfix window should update/clear the
2562 " quickfix/location list window.
2563 Xexpr ['Xfile1:10:10:Line 10', 'Xfile1:15:15:Line 15']
2564 Xexpr ['Xfile2:20:20:Line 20', 'Xfile2:25:25:Line 25']
2565 Xexpr ['Xfile3:30:30:Line 30', 'Xfile3:35:35:Line 35']
2566 Xolder
2567 Xwindow
2568 wincmd p
2569 call g:Xsetlist([], 'f')
2570 call assert_equal(0, len(g:Xgetlist()))
2571 wincmd p
2572 call assert_equal(2, winnr('$'))
2573 call assert_equal(1, line('$'))
2574
2575 " After deleting the location list stack, if the location list window is
2576 " opened, then a new location list should be created. So opening the
2577 " location list window again should not create a new window.
2578 if a:cchar == 'l'
2579 lexpr ['Xfile1:10:10:Line 10', 'Xfile1:15:15:Line 15']
2580 wincmd p
2581 lopen
2582 call assert_equal(2, winnr('$'))
2583 endif
2584 Xclose
2585endfunc
2586
Bram Moolenaar74240d32017-12-10 15:26:15 +01002587" Tests for the quickfix free functionality
Bram Moolenaar69f40be2017-04-02 15:15:49 +02002588func Test_qf_free()
2589 call XfreeTests('c')
2590 call XfreeTests('l')
2591endfunc
Bram Moolenaar6e62da32017-05-28 08:16:25 +02002592
2593" Test for buffer overflow when parsing lines and adding new entries to
2594" the quickfix list.
2595func Test_bufoverflow()
2596 set efm=%f:%l:%m
2597 cgetexpr ['File1:100:' . repeat('x', 1025)]
2598
2599 set efm=%+GCompiler:\ %.%#,%f:%l:%m
2600 cgetexpr ['Compiler: ' . repeat('a', 1015), 'File1:10:Hello World']
2601
2602 set efm=%DEntering\ directory\ %f,%f:%l:%m
2603 cgetexpr ['Entering directory ' . repeat('a', 1006),
2604 \ 'File1:10:Hello World']
2605 set efm&vim
2606endfunc
2607
Bram Moolenaar875feea2017-06-11 16:07:51 +02002608" Tests for getting the quickfix stack size
2609func XsizeTests(cchar)
2610 call s:setup_commands(a:cchar)
2611
2612 call g:Xsetlist([], 'f')
2613 call assert_equal(0, g:Xgetlist({'nr':'$'}).nr)
Bram Moolenaara6d48492017-12-12 22:45:31 +01002614 call assert_equal('', g:Xgetlist({'nr':'$', 'all':1}).title)
2615 call assert_equal(0, g:Xgetlist({'nr':0}).nr)
Bram Moolenaar875feea2017-06-11 16:07:51 +02002616
2617 Xexpr "File1:10:Line1"
2618 Xexpr "File2:20:Line2"
2619 Xexpr "File3:30:Line3"
2620 Xolder | Xolder
2621 call assert_equal(3, g:Xgetlist({'nr':'$'}).nr)
2622 call g:Xsetlist([], 'f')
2623
2624 Xexpr "File1:10:Line1"
2625 Xexpr "File2:20:Line2"
2626 Xexpr "File3:30:Line3"
2627 Xolder | Xolder
2628 call g:Xsetlist([], 'a', {'nr':'$', 'title':'Compiler'})
2629 call assert_equal('Compiler', g:Xgetlist({'nr':3, 'all':1}).title)
2630endfunc
2631
2632func Test_Qf_Size()
2633 call XsizeTests('c')
2634 call XsizeTests('l')
2635endfunc
Bram Moolenaar18141832017-06-25 21:17:25 +02002636
Bram Moolenaar9c4feff2017-06-28 22:26:54 +02002637func Test_cclose_from_copen()
2638 augroup QF_Test
2639 au!
2640 au FileType qf :call assert_fails(':cclose', 'E788')
2641 augroup END
2642 copen
2643 augroup QF_Test
2644 au!
2645 augroup END
2646 augroup! QF_Test
2647endfunc
2648
Bram Moolenaar18141832017-06-25 21:17:25 +02002649func Test_cclose_in_autocmd()
2650 " Problem is only triggered if "starting" is zero, so that the OptionsSet
2651 " event will be triggered.
2652 call test_override('starting', 1)
2653 augroup QF_Test
2654 au!
2655 au FileType qf :call assert_fails(':cclose', 'E788')
2656 augroup END
2657 copen
2658 augroup QF_Test
2659 au!
2660 augroup END
2661 augroup! QF_Test
2662 call test_override('starting', 0)
2663endfunc
Bram Moolenaar9c4feff2017-06-28 22:26:54 +02002664
Bram Moolenaar379fb762018-08-30 15:58:28 +02002665" Check that ":file" without an argument is possible even when "curbuf_lock"
2666" is set.
2667func Test_file_from_copen()
2668 " Works without argument.
2669 augroup QF_Test
2670 au!
2671 au FileType qf file
2672 augroup END
2673 copen
2674
2675 augroup QF_Test
2676 au!
2677 augroup END
2678 cclose
2679
2680 " Fails with argument.
2681 augroup QF_Test
2682 au!
2683 au FileType qf call assert_fails(':file foo', 'E788')
2684 augroup END
2685 copen
2686 augroup QF_Test
2687 au!
2688 augroup END
2689 cclose
2690
2691 augroup! QF_Test
2692endfunction
2693
Bram Moolenaar9c4feff2017-06-28 22:26:54 +02002694func Test_resize_from_copen()
2695 augroup QF_Test
2696 au!
2697 au FileType qf resize 5
2698 augroup END
2699 try
2700 " This should succeed without any exception. No other buffers are
2701 " involved in the autocmd.
2702 copen
2703 finally
2704 augroup QF_Test
2705 au!
2706 augroup END
2707 augroup! QF_Test
2708 endtry
2709endfunc
Bram Moolenaara8788f42017-07-19 17:06:20 +02002710
2711" Tests for the quickfix buffer b:changedtick variable
2712func Xchangedtick_tests(cchar)
2713 call s:setup_commands(a:cchar)
2714
2715 new | only
2716
2717 Xexpr "" | Xexpr "" | Xexpr ""
2718
2719 Xopen
2720 Xolder
2721 Xolder
2722 Xaddexpr "F1:10:Line10"
2723 Xaddexpr "F2:20:Line20"
2724 call g:Xsetlist([{"filename":"F3", "lnum":30, "text":"Line30"}], 'a')
2725 call g:Xsetlist([], 'f')
2726 call assert_equal(8, getbufvar('%', 'changedtick'))
2727 Xclose
2728endfunc
2729
2730func Test_changedtick()
Bram Moolenaarae338332017-08-11 20:25:26 +02002731 call Xchangedtick_tests('c')
2732 call Xchangedtick_tests('l')
2733endfunc
2734
2735" Tests for parsing an expression using setqflist()
2736func Xsetexpr_tests(cchar)
2737 call s:setup_commands(a:cchar)
2738
2739 let t = ["File1:10:Line10", "File1:20:Line20"]
Bram Moolenaar2c809b72017-09-01 18:34:02 +02002740 call g:Xsetlist([], ' ', {'lines' : t})
2741 call g:Xsetlist([], 'a', {'lines' : ["File1:30:Line30"]})
Bram Moolenaarae338332017-08-11 20:25:26 +02002742
2743 let l = g:Xgetlist()
2744 call assert_equal(3, len(l))
2745 call assert_equal(20, l[1].lnum)
2746 call assert_equal('Line30', l[2].text)
Bram Moolenaar2c809b72017-09-01 18:34:02 +02002747 call g:Xsetlist([], 'r', {'lines' : ["File2:5:Line5"]})
Bram Moolenaarae338332017-08-11 20:25:26 +02002748 let l = g:Xgetlist()
2749 call assert_equal(1, len(l))
2750 call assert_equal('Line5', l[0].text)
Bram Moolenaar2c809b72017-09-01 18:34:02 +02002751 call assert_equal(-1, g:Xsetlist([], 'a', {'lines' : 10}))
2752 call assert_equal(-1, g:Xsetlist([], 'a', {'lines' : "F1:10:L10"}))
Bram Moolenaarae338332017-08-11 20:25:26 +02002753
2754 call g:Xsetlist([], 'f')
2755 " Add entries to multiple lists
Bram Moolenaar2c809b72017-09-01 18:34:02 +02002756 call g:Xsetlist([], 'a', {'nr' : 1, 'lines' : ["File1:10:Line10"]})
2757 call g:Xsetlist([], 'a', {'nr' : 2, 'lines' : ["File2:20:Line20"]})
2758 call g:Xsetlist([], 'a', {'nr' : 1, 'lines' : ["File1:15:Line15"]})
2759 call g:Xsetlist([], 'a', {'nr' : 2, 'lines' : ["File2:25:Line25"]})
Bram Moolenaarae338332017-08-11 20:25:26 +02002760 call assert_equal('Line15', g:Xgetlist({'nr':1, 'items':1}).items[1].text)
2761 call assert_equal('Line25', g:Xgetlist({'nr':2, 'items':1}).items[1].text)
Bram Moolenaar36538222017-09-02 19:51:44 +02002762
2763 " Adding entries using a custom efm
2764 set efm&
2765 call g:Xsetlist([], ' ', {'efm' : '%f#%l#%m',
2766 \ 'lines' : ["F1#10#L10", "F2#20#L20"]})
2767 call assert_equal(20, g:Xgetlist({'items':1}).items[1].lnum)
2768 call g:Xsetlist([], 'a', {'efm' : '%f#%l#%m', 'lines' : ["F3:30:L30"]})
2769 call assert_equal('F3:30:L30', g:Xgetlist({'items':1}).items[2].text)
2770 call assert_equal(20, g:Xgetlist({'items':1}).items[1].lnum)
2771 call assert_equal(-1, g:Xsetlist([], 'a', {'efm' : [],
2772 \ 'lines' : ['F1:10:L10']}))
Bram Moolenaarae338332017-08-11 20:25:26 +02002773endfunc
2774
2775func Test_setexpr()
2776 call Xsetexpr_tests('c')
2777 call Xsetexpr_tests('l')
2778endfunc
2779
2780" Tests for per quickfix/location list directory stack
2781func Xmultidirstack_tests(cchar)
2782 call s:setup_commands(a:cchar)
2783
2784 call g:Xsetlist([], 'f')
2785 Xexpr "" | Xexpr ""
2786
Bram Moolenaar2c809b72017-09-01 18:34:02 +02002787 call g:Xsetlist([], 'a', {'nr' : 1, 'lines' : ["Entering dir 'Xone/a'"]})
2788 call g:Xsetlist([], 'a', {'nr' : 2, 'lines' : ["Entering dir 'Xtwo/a'"]})
2789 call g:Xsetlist([], 'a', {'nr' : 1, 'lines' : ["one.txt:3:one one one"]})
2790 call g:Xsetlist([], 'a', {'nr' : 2, 'lines' : ["two.txt:5:two two two"]})
Bram Moolenaarae338332017-08-11 20:25:26 +02002791
2792 let l1 = g:Xgetlist({'nr':1, 'items':1})
2793 let l2 = g:Xgetlist({'nr':2, 'items':1})
2794 call assert_equal('Xone/a/one.txt', bufname(l1.items[1].bufnr))
2795 call assert_equal(3, l1.items[1].lnum)
2796 call assert_equal('Xtwo/a/two.txt', bufname(l2.items[1].bufnr))
2797 call assert_equal(5, l2.items[1].lnum)
2798endfunc
2799
2800func Test_multidirstack()
2801 call mkdir('Xone/a', 'p')
2802 call mkdir('Xtwo/a', 'p')
2803 let lines = ['1', '2', 'one one one', '4', 'two two two', '6', '7']
2804 call writefile(lines, 'Xone/a/one.txt')
2805 call writefile(lines, 'Xtwo/a/two.txt')
2806 let save_efm = &efm
2807 set efm=%DEntering\ dir\ '%f',%f:%l:%m,%XLeaving\ dir\ '%f'
2808
2809 call Xmultidirstack_tests('c')
2810 call Xmultidirstack_tests('l')
2811
2812 let &efm = save_efm
2813 call delete('Xone', 'rf')
2814 call delete('Xtwo', 'rf')
2815endfunc
2816
2817" Tests for per quickfix/location list file stack
2818func Xmultifilestack_tests(cchar)
2819 call s:setup_commands(a:cchar)
2820
2821 call g:Xsetlist([], 'f')
2822 Xexpr "" | Xexpr ""
2823
Bram Moolenaar2c809b72017-09-01 18:34:02 +02002824 call g:Xsetlist([], 'a', {'nr' : 1, 'lines' : ["[one.txt]"]})
2825 call g:Xsetlist([], 'a', {'nr' : 2, 'lines' : ["[two.txt]"]})
2826 call g:Xsetlist([], 'a', {'nr' : 1, 'lines' : ["(3,5) one one one"]})
2827 call g:Xsetlist([], 'a', {'nr' : 2, 'lines' : ["(5,9) two two two"]})
Bram Moolenaarae338332017-08-11 20:25:26 +02002828
2829 let l1 = g:Xgetlist({'nr':1, 'items':1})
2830 let l2 = g:Xgetlist({'nr':2, 'items':1})
2831 call assert_equal('one.txt', bufname(l1.items[1].bufnr))
2832 call assert_equal(3, l1.items[1].lnum)
2833 call assert_equal('two.txt', bufname(l2.items[1].bufnr))
2834 call assert_equal(5, l2.items[1].lnum)
Bram Moolenaare333e792018-04-08 13:27:39 +02002835
2836 " Test for start of a new error line in the same line where a previous
2837 " error line ends with a file stack.
2838 let efm_val = 'Error\ l%l\ in\ %f,'
2839 let efm_val .= '%-P%>(%f%r,Error\ l%l\ in\ %m,%-Q)%r'
2840 let l = g:Xgetlist({'lines' : [
2841 \ '(one.txt',
2842 \ 'Error l4 in one.txt',
2843 \ ') (two.txt',
2844 \ 'Error l6 in two.txt',
2845 \ ')',
2846 \ 'Error l8 in one.txt'
2847 \ ], 'efm' : efm_val})
2848 call assert_equal(3, len(l.items))
2849 call assert_equal('one.txt', bufname(l.items[0].bufnr))
2850 call assert_equal(4, l.items[0].lnum)
2851 call assert_equal('one.txt', l.items[0].text)
2852 call assert_equal('two.txt', bufname(l.items[1].bufnr))
2853 call assert_equal(6, l.items[1].lnum)
2854 call assert_equal('two.txt', l.items[1].text)
2855 call assert_equal('one.txt', bufname(l.items[2].bufnr))
2856 call assert_equal(8, l.items[2].lnum)
2857 call assert_equal('', l.items[2].text)
Bram Moolenaarae338332017-08-11 20:25:26 +02002858endfunc
2859
2860func Test_multifilestack()
2861 let lines = ['1', '2', 'one one one', '4', 'two two two', '6', '7']
2862 call writefile(lines, 'one.txt')
2863 call writefile(lines, 'two.txt')
2864 let save_efm = &efm
2865 set efm=%+P[%f],(%l\\,%c)\ %m,%-Q
2866
2867 call Xmultifilestack_tests('c')
2868 call Xmultifilestack_tests('l')
2869
2870 let &efm = save_efm
2871 call delete('one.txt')
2872 call delete('two.txt')
2873endfunc
2874
2875" Tests for per buffer 'efm' setting
2876func Test_perbuf_efm()
2877 call writefile(["File1-10-Line10"], 'one.txt')
2878 call writefile(["File2#20#Line20"], 'two.txt')
2879 set efm=%f#%l#%m
2880 new | only
2881 new
2882 setlocal efm=%f-%l-%m
2883 cfile one.txt
2884 wincmd w
2885 caddfile two.txt
2886
2887 let l = getqflist()
2888 call assert_equal(10, l[0].lnum)
2889 call assert_equal('Line20', l[1].text)
2890
2891 set efm&
2892 new | only
2893 call delete('one.txt')
2894 call delete('two.txt')
Bram Moolenaara8788f42017-07-19 17:06:20 +02002895endfunc
Bram Moolenaard28cc3f2017-07-27 22:03:50 +02002896
2897" Open multiple help windows using ":lhelpgrep
2898" This test used to crash Vim
2899func Test_Multi_LL_Help()
2900 new | only
2901 lhelpgrep window
2902 lopen
2903 e#
2904 lhelpgrep buffer
2905 call assert_equal(3, winnr('$'))
2906 call assert_true(len(getloclist(1)) != 0)
2907 call assert_true(len(getloclist(2)) != 0)
2908 new | only
2909endfunc
Bram Moolenaar55b69262017-08-13 13:42:01 +02002910
2911" Tests for adding new quickfix lists using setqflist()
2912func XaddQf_tests(cchar)
2913 call s:setup_commands(a:cchar)
2914
2915 " Create a new list using ' ' for action
2916 call g:Xsetlist([], 'f')
2917 call g:Xsetlist([], ' ', {'title' : 'Test1'})
2918 let l = g:Xgetlist({'nr' : '$', 'all' : 1})
2919 call assert_equal(1, l.nr)
2920 call assert_equal('Test1', l.title)
2921
2922 " Create a new list using ' ' for action and '$' for 'nr'
2923 call g:Xsetlist([], 'f')
2924 call g:Xsetlist([], ' ', {'title' : 'Test2', 'nr' : '$'})
2925 let l = g:Xgetlist({'nr' : '$', 'all' : 1})
2926 call assert_equal(1, l.nr)
2927 call assert_equal('Test2', l.title)
2928
2929 " Create a new list using 'a' for action
2930 call g:Xsetlist([], 'f')
2931 call g:Xsetlist([], 'a', {'title' : 'Test3'})
2932 let l = g:Xgetlist({'nr' : '$', 'all' : 1})
2933 call assert_equal(1, l.nr)
2934 call assert_equal('Test3', l.title)
2935
2936 " Create a new list using 'a' for action and '$' for 'nr'
2937 call g:Xsetlist([], 'f')
2938 call g:Xsetlist([], 'a', {'title' : 'Test3', 'nr' : '$'})
2939 call g:Xsetlist([], 'a', {'title' : 'Test4'})
2940 let l = g:Xgetlist({'nr' : '$', 'all' : 1})
2941 call assert_equal(1, l.nr)
2942 call assert_equal('Test4', l.title)
2943
2944 " Adding a quickfix list should remove all the lists following the current
2945 " list.
2946 Xexpr "" | Xexpr "" | Xexpr ""
2947 silent! 10Xolder
2948 call g:Xsetlist([], ' ', {'title' : 'Test5'})
2949 let l = g:Xgetlist({'nr' : '$', 'all' : 1})
2950 call assert_equal(2, l.nr)
2951 call assert_equal('Test5', l.title)
2952
2953 " Add a quickfix list using '$' as the list number.
2954 let lastqf = g:Xgetlist({'nr':'$'}).nr
2955 silent! 99Xolder
2956 call g:Xsetlist([], ' ', {'nr' : '$', 'title' : 'Test6'})
2957 let l = g:Xgetlist({'nr' : '$', 'all' : 1})
2958 call assert_equal(lastqf + 1, l.nr)
2959 call assert_equal('Test6', l.title)
2960
2961 " Add a quickfix list using 'nr' set to one more than the quickfix
2962 " list size.
2963 let lastqf = g:Xgetlist({'nr':'$'}).nr
2964 silent! 99Xolder
2965 call g:Xsetlist([], ' ', {'nr' : lastqf + 1, 'title' : 'Test7'})
2966 let l = g:Xgetlist({'nr' : '$', 'all' : 1})
2967 call assert_equal(lastqf + 1, l.nr)
2968 call assert_equal('Test7', l.title)
2969
2970 " Add a quickfix list to a stack with 10 lists using 'nr' set to '$'
2971 exe repeat('Xexpr "" |', 9) . 'Xexpr ""'
2972 silent! 99Xolder
2973 call g:Xsetlist([], ' ', {'nr' : '$', 'title' : 'Test8'})
2974 let l = g:Xgetlist({'nr' : '$', 'all' : 1})
2975 call assert_equal(10, l.nr)
2976 call assert_equal('Test8', l.title)
2977
2978 " Add a quickfix list using 'nr' set to a value greater than 10
2979 call assert_equal(-1, g:Xsetlist([], ' ', {'nr' : 12, 'title' : 'Test9'}))
2980
2981 " Try adding a quickfix list with 'nr' set to a value greater than the
2982 " quickfix list size but less than 10.
2983 call g:Xsetlist([], 'f')
2984 Xexpr "" | Xexpr "" | Xexpr ""
2985 silent! 99Xolder
2986 call assert_equal(-1, g:Xsetlist([], ' ', {'nr' : 8, 'title' : 'Test10'}))
2987
2988 " Add a quickfix list using 'nr' set to a some string or list
2989 call assert_equal(-1, g:Xsetlist([], ' ', {'nr' : [1,2], 'title' : 'Test11'}))
2990endfunc
2991
2992func Test_add_qf()
2993 call XaddQf_tests('c')
2994 call XaddQf_tests('l')
2995endfunc
Bram Moolenaar7adf06f2017-08-27 15:23:41 +02002996
2997" Test for getting the quickfix list items from some text without modifying
2998" the quickfix stack
Bram Moolenaar2c809b72017-09-01 18:34:02 +02002999func XgetListFromLines(cchar)
Bram Moolenaar7adf06f2017-08-27 15:23:41 +02003000 call s:setup_commands(a:cchar)
3001 call g:Xsetlist([], 'f')
3002
Bram Moolenaar2c809b72017-09-01 18:34:02 +02003003 let l = g:Xgetlist({'lines' : ["File2:20:Line20", "File2:30:Line30"]}).items
Bram Moolenaar7adf06f2017-08-27 15:23:41 +02003004 call assert_equal(2, len(l))
3005 call assert_equal(30, l[1].lnum)
3006
Bram Moolenaar2c809b72017-09-01 18:34:02 +02003007 call assert_equal({}, g:Xgetlist({'lines' : 10}))
3008 call assert_equal({}, g:Xgetlist({'lines' : 'File1:10:Line10'}))
3009 call assert_equal([], g:Xgetlist({'lines' : []}).items)
3010 call assert_equal([], g:Xgetlist({'lines' : [10, 20]}).items)
Bram Moolenaar7adf06f2017-08-27 15:23:41 +02003011
Bram Moolenaar36538222017-09-02 19:51:44 +02003012 " Parse text using a custom efm
3013 set efm&
3014 let l = g:Xgetlist({'lines':['File3#30#Line30'], 'efm' : '%f#%l#%m'}).items
3015 call assert_equal('Line30', l[0].text)
3016 let l = g:Xgetlist({'lines':['File3:30:Line30'], 'efm' : '%f-%l-%m'}).items
3017 call assert_equal('File3:30:Line30', l[0].text)
3018 let l = g:Xgetlist({'lines':['File3:30:Line30'], 'efm' : [1,2]})
3019 call assert_equal({}, l)
3020 call assert_fails("call g:Xgetlist({'lines':['abc'], 'efm':'%2'})", 'E376:')
3021 call assert_fails("call g:Xgetlist({'lines':['abc'], 'efm':''})", 'E378:')
3022
Bram Moolenaar7adf06f2017-08-27 15:23:41 +02003023 " Make sure that the quickfix stack is not modified
3024 call assert_equal(0, g:Xgetlist({'nr' : '$'}).nr)
3025endfunc
3026
Bram Moolenaar2c809b72017-09-01 18:34:02 +02003027func Test_get_list_from_lines()
3028 call XgetListFromLines('c')
3029 call XgetListFromLines('l')
Bram Moolenaar7adf06f2017-08-27 15:23:41 +02003030endfunc
Bram Moolenaara539f4f2017-08-30 20:33:55 +02003031
3032" Tests for the quickfix list id
3033func Xqfid_tests(cchar)
3034 call s:setup_commands(a:cchar)
3035
3036 call g:Xsetlist([], 'f')
Bram Moolenaara6d48492017-12-12 22:45:31 +01003037 call assert_equal(0, g:Xgetlist({'id':0}).id)
Bram Moolenaara539f4f2017-08-30 20:33:55 +02003038 Xexpr ''
3039 let start_id = g:Xgetlist({'id' : 0}).id
3040 Xexpr '' | Xexpr ''
3041 Xolder
3042 call assert_equal(start_id, g:Xgetlist({'id':0, 'nr':1}).id)
3043 call assert_equal(start_id + 1, g:Xgetlist({'id':0, 'nr':0}).id)
3044 call assert_equal(start_id + 2, g:Xgetlist({'id':0, 'nr':'$'}).id)
Bram Moolenaara6d48492017-12-12 22:45:31 +01003045 call assert_equal(0, g:Xgetlist({'id':0, 'nr':99}).id)
Bram Moolenaara539f4f2017-08-30 20:33:55 +02003046 call assert_equal(2, g:Xgetlist({'id':start_id + 1, 'nr':0}).nr)
Bram Moolenaara6d48492017-12-12 22:45:31 +01003047 call assert_equal(0, g:Xgetlist({'id':99, 'nr':0}).id)
3048 call assert_equal(0, g:Xgetlist({'id':"abc", 'nr':0}).id)
Bram Moolenaara539f4f2017-08-30 20:33:55 +02003049
3050 call g:Xsetlist([], 'a', {'id':start_id, 'context':[1,2]})
3051 call assert_equal([1,2], g:Xgetlist({'nr':1, 'context':1}).context)
Bram Moolenaar2c809b72017-09-01 18:34:02 +02003052 call g:Xsetlist([], 'a', {'id':start_id+1, 'lines':['F1:10:L10']})
Bram Moolenaara539f4f2017-08-30 20:33:55 +02003053 call assert_equal('L10', g:Xgetlist({'nr':2, 'items':1}).items[0].text)
3054 call assert_equal(-1, g:Xsetlist([], 'a', {'id':999, 'title':'Vim'}))
3055 call assert_equal(-1, g:Xsetlist([], 'a', {'id':'abc', 'title':'Vim'}))
3056
3057 let qfid = g:Xgetlist({'id':0, 'nr':0})
3058 call g:Xsetlist([], 'f')
Bram Moolenaara6d48492017-12-12 22:45:31 +01003059 call assert_equal(0, g:Xgetlist({'id':qfid, 'nr':0}).id)
Bram Moolenaara539f4f2017-08-30 20:33:55 +02003060endfunc
3061
3062func Test_qf_id()
3063 call Xqfid_tests('c')
3064 call Xqfid_tests('l')
3065endfunc
Bram Moolenaar74240d32017-12-10 15:26:15 +01003066
3067func Xqfjump_tests(cchar)
3068 call s:setup_commands(a:cchar)
3069
3070 call writefile(["Line1\tFoo", "Line2"], 'F1')
3071 call writefile(["Line1\tBar", "Line2"], 'F2')
3072 call writefile(["Line1\tBaz", "Line2"], 'F3')
3073
3074 call g:Xsetlist([], 'f')
3075
3076 " Tests for
3077 " Jumping to a line using a pattern
3078 " Jumping to a column greater than the last column in a line
3079 " Jumping to a line greater than the last line in the file
3080 let l = []
3081 for i in range(1, 7)
3082 call add(l, {})
3083 endfor
3084 let l[0].filename='F1'
3085 let l[0].pattern='Line1'
3086 let l[1].filename='F2'
3087 let l[1].pattern='Line1'
3088 let l[2].filename='F3'
3089 let l[2].pattern='Line1'
3090 let l[3].filename='F3'
3091 let l[3].lnum=1
3092 let l[3].col=9
3093 let l[3].vcol=1
3094 let l[4].filename='F3'
3095 let l[4].lnum=99
3096 let l[5].filename='F3'
3097 let l[5].lnum=1
3098 let l[5].col=99
3099 let l[5].vcol=1
3100 let l[6].filename='F3'
3101 let l[6].pattern='abcxyz'
3102
3103 call g:Xsetlist([], ' ', {'items' : l})
3104 Xopen | only
3105 2Xnext
3106 call assert_equal(3, g:Xgetlist({'idx' : 0}).idx)
3107 call assert_equal('F3', bufname('%'))
3108 Xnext
3109 call assert_equal(7, col('.'))
3110 Xnext
3111 call assert_equal(2, line('.'))
3112 Xnext
3113 call assert_equal(9, col('.'))
3114 2
3115 Xnext
3116 call assert_equal(2, line('.'))
3117
3118 if a:cchar == 'l'
3119 " When jumping to a location list entry in the location list window and
3120 " no usable windows are available, then a new window should be opened.
3121 enew! | new | only
3122 call g:Xsetlist([], 'f')
3123 setlocal buftype=nofile
3124 new
3125 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']})
3126 Xopen
3127 let winid = win_getid()
3128 wincmd p
3129 close
3130 call win_gotoid(winid)
3131 Xnext
3132 call assert_equal(3, winnr('$'))
3133 call assert_equal(1, winnr())
3134 call assert_equal(2, line('.'))
3135
3136 " When jumping to an entry in the location list window and the window
3137 " associated with the location list is not present and a window containing
3138 " the file is already present, then that window should be used.
3139 close
3140 belowright new
3141 call g:Xsetlist([], 'f')
3142 edit F3
3143 call win_gotoid(winid)
3144 Xlast
3145 call assert_equal(3, winnr())
3146 call assert_equal(6, g:Xgetlist({'size' : 1}).size)
3147 call assert_equal(winid, g:Xgetlist({'winid' : 1}).winid)
3148 endif
3149
3150 " Cleanup
3151 enew!
3152 new | only
3153
3154 call delete('F1')
3155 call delete('F2')
3156 call delete('F3')
3157endfunc
3158
3159func Test_qfjump()
3160 call Xqfjump_tests('c')
3161 call Xqfjump_tests('l')
3162endfunc
Bram Moolenaara6d48492017-12-12 22:45:31 +01003163
3164" Tests for the getqflist() and getloclist() functions when the list is not
3165" present or is empty
3166func Xgetlist_empty_tests(cchar)
3167 call s:setup_commands(a:cchar)
3168
3169 " Empty quickfix stack
3170 call g:Xsetlist([], 'f')
3171 call assert_equal('', g:Xgetlist({'context' : 0}).context)
3172 call assert_equal(0, g:Xgetlist({'id' : 0}).id)
3173 call assert_equal(0, g:Xgetlist({'idx' : 0}).idx)
3174 call assert_equal([], g:Xgetlist({'items' : 0}).items)
3175 call assert_equal(0, g:Xgetlist({'nr' : 0}).nr)
3176 call assert_equal(0, g:Xgetlist({'size' : 0}).size)
3177 call assert_equal('', g:Xgetlist({'title' : 0}).title)
3178 call assert_equal(0, g:Xgetlist({'winid' : 0}).winid)
Bram Moolenaarb254af32017-12-18 19:48:58 +01003179 call assert_equal(0, g:Xgetlist({'changedtick' : 0}).changedtick)
Bram Moolenaarc9cc9c72018-09-02 15:18:42 +02003180 if a:cchar == 'c'
3181 call assert_equal({'context' : '', 'id' : 0, 'idx' : 0,
Bram Moolenaar647e24b2019-03-17 16:39:46 +01003182 \ 'items' : [], 'nr' : 0, 'size' : 0, 'qfbufnr' : 0,
Bram Moolenaarc9cc9c72018-09-02 15:18:42 +02003183 \ 'title' : '', 'winid' : 0, 'changedtick': 0},
3184 \ g:Xgetlist({'all' : 0}))
3185 else
3186 call assert_equal({'context' : '', 'id' : 0, 'idx' : 0,
3187 \ 'items' : [], 'nr' : 0, 'size' : 0, 'title' : '',
Bram Moolenaar647e24b2019-03-17 16:39:46 +01003188 \ 'winid' : 0, 'changedtick': 0, 'filewinid' : 0,
3189 \ 'qfbufnr' : 0},
Bram Moolenaarc9cc9c72018-09-02 15:18:42 +02003190 \ g:Xgetlist({'all' : 0}))
3191 endif
Bram Moolenaara6d48492017-12-12 22:45:31 +01003192
Bram Moolenaar2ec364e2018-01-27 11:52:13 +01003193 " Quickfix window with empty stack
3194 silent! Xopen
3195 let qfwinid = (a:cchar == 'c') ? win_getid() : 0
Bram Moolenaar647e24b2019-03-17 16:39:46 +01003196 let qfbufnr = (a:cchar == 'c') ? bufnr('') : 0
Bram Moolenaar2ec364e2018-01-27 11:52:13 +01003197 call assert_equal(qfwinid, g:Xgetlist({'winid' : 0}).winid)
3198 Xclose
3199
Bram Moolenaara6d48492017-12-12 22:45:31 +01003200 " Empty quickfix list
3201 Xexpr ""
3202 call assert_equal('', g:Xgetlist({'context' : 0}).context)
3203 call assert_notequal(0, g:Xgetlist({'id' : 0}).id)
3204 call assert_equal(0, g:Xgetlist({'idx' : 0}).idx)
3205 call assert_equal([], g:Xgetlist({'items' : 0}).items)
3206 call assert_notequal(0, g:Xgetlist({'nr' : 0}).nr)
3207 call assert_equal(0, g:Xgetlist({'size' : 0}).size)
3208 call assert_notequal('', g:Xgetlist({'title' : 0}).title)
3209 call assert_equal(0, g:Xgetlist({'winid' : 0}).winid)
Bram Moolenaarb254af32017-12-18 19:48:58 +01003210 call assert_equal(1, g:Xgetlist({'changedtick' : 0}).changedtick)
Bram Moolenaara6d48492017-12-12 22:45:31 +01003211
3212 let qfid = g:Xgetlist({'id' : 0}).id
3213 call g:Xsetlist([], 'f')
3214
3215 " Non-existing quickfix identifier
3216 call assert_equal('', g:Xgetlist({'id' : qfid, 'context' : 0}).context)
3217 call assert_equal(0, g:Xgetlist({'id' : qfid}).id)
3218 call assert_equal(0, g:Xgetlist({'id' : qfid, 'idx' : 0}).idx)
3219 call assert_equal([], g:Xgetlist({'id' : qfid, 'items' : 0}).items)
3220 call assert_equal(0, g:Xgetlist({'id' : qfid, 'nr' : 0}).nr)
3221 call assert_equal(0, g:Xgetlist({'id' : qfid, 'size' : 0}).size)
3222 call assert_equal('', g:Xgetlist({'id' : qfid, 'title' : 0}).title)
3223 call assert_equal(0, g:Xgetlist({'id' : qfid, 'winid' : 0}).winid)
Bram Moolenaarb254af32017-12-18 19:48:58 +01003224 call assert_equal(0, g:Xgetlist({'id' : qfid, 'changedtick' : 0}).changedtick)
Bram Moolenaarc9cc9c72018-09-02 15:18:42 +02003225 if a:cchar == 'c'
3226 call assert_equal({'context' : '', 'id' : 0, 'idx' : 0, 'items' : [],
3227 \ 'nr' : 0, 'size' : 0, 'title' : '', 'winid' : 0,
Bram Moolenaar647e24b2019-03-17 16:39:46 +01003228 \ 'qfbufnr' : qfbufnr,
Bram Moolenaarc9cc9c72018-09-02 15:18:42 +02003229 \ 'changedtick' : 0}, g:Xgetlist({'id' : qfid, 'all' : 0}))
3230 else
3231 call assert_equal({'context' : '', 'id' : 0, 'idx' : 0, 'items' : [],
3232 \ 'nr' : 0, 'size' : 0, 'title' : '', 'winid' : 0,
Bram Moolenaar647e24b2019-03-17 16:39:46 +01003233 \ 'changedtick' : 0, 'filewinid' : 0, 'qfbufnr' : 0},
Bram Moolenaarc9cc9c72018-09-02 15:18:42 +02003234 \ g:Xgetlist({'id' : qfid, 'all' : 0}))
3235 endif
Bram Moolenaara6d48492017-12-12 22:45:31 +01003236
3237 " Non-existing quickfix list number
3238 call assert_equal('', g:Xgetlist({'nr' : 5, 'context' : 0}).context)
3239 call assert_equal(0, g:Xgetlist({'nr' : 5}).nr)
3240 call assert_equal(0, g:Xgetlist({'nr' : 5, 'idx' : 0}).idx)
3241 call assert_equal([], g:Xgetlist({'nr' : 5, 'items' : 0}).items)
3242 call assert_equal(0, g:Xgetlist({'nr' : 5, 'id' : 0}).id)
3243 call assert_equal(0, g:Xgetlist({'nr' : 5, 'size' : 0}).size)
3244 call assert_equal('', g:Xgetlist({'nr' : 5, 'title' : 0}).title)
3245 call assert_equal(0, g:Xgetlist({'nr' : 5, 'winid' : 0}).winid)
Bram Moolenaarb254af32017-12-18 19:48:58 +01003246 call assert_equal(0, g:Xgetlist({'nr' : 5, 'changedtick' : 0}).changedtick)
Bram Moolenaarc9cc9c72018-09-02 15:18:42 +02003247 if a:cchar == 'c'
3248 call assert_equal({'context' : '', 'id' : 0, 'idx' : 0, 'items' : [],
3249 \ 'nr' : 0, 'size' : 0, 'title' : '', 'winid' : 0,
Bram Moolenaar647e24b2019-03-17 16:39:46 +01003250 \ 'changedtick' : 0, 'qfbufnr' : qfbufnr},
3251 \ g:Xgetlist({'nr' : 5, 'all' : 0}))
Bram Moolenaarc9cc9c72018-09-02 15:18:42 +02003252 else
3253 call assert_equal({'context' : '', 'id' : 0, 'idx' : 0, 'items' : [],
3254 \ 'nr' : 0, 'size' : 0, 'title' : '', 'winid' : 0,
Bram Moolenaar647e24b2019-03-17 16:39:46 +01003255 \ 'changedtick' : 0, 'filewinid' : 0, 'qfbufnr' : 0},
Bram Moolenaarc9cc9c72018-09-02 15:18:42 +02003256 \ g:Xgetlist({'nr' : 5, 'all' : 0}))
3257 endif
Bram Moolenaara6d48492017-12-12 22:45:31 +01003258endfunc
3259
3260func Test_getqflist()
3261 call Xgetlist_empty_tests('c')
3262 call Xgetlist_empty_tests('l')
3263endfunc
Bram Moolenaarb254af32017-12-18 19:48:58 +01003264
Bram Moolenaara0ca7d02017-12-19 10:22:19 +01003265func Test_getqflist_invalid_nr()
3266 " The following commands used to crash Vim
3267 cexpr ""
3268 call getqflist({'nr' : $XXX_DOES_NOT_EXIST_XXX})
3269
3270 " Cleanup
3271 call setqflist([], 'r')
3272endfunc
3273
Bram Moolenaarb254af32017-12-18 19:48:58 +01003274" Tests for the quickfix/location list changedtick
3275func Xqftick_tests(cchar)
3276 call s:setup_commands(a:cchar)
3277
3278 call g:Xsetlist([], 'f')
3279
3280 Xexpr "F1:10:Line10"
3281 let qfid = g:Xgetlist({'id' : 0}).id
3282 call assert_equal(1, g:Xgetlist({'changedtick' : 0}).changedtick)
3283 Xaddexpr "F2:20:Line20\nF2:21:Line21"
3284 call assert_equal(2, g:Xgetlist({'changedtick' : 0}).changedtick)
3285 call g:Xsetlist([], 'a', {'lines' : ["F3:30:Line30", "F3:31:Line31"]})
3286 call assert_equal(3, g:Xgetlist({'changedtick' : 0}).changedtick)
3287 call g:Xsetlist([], 'r', {'lines' : ["F4:40:Line40"]})
3288 call assert_equal(4, g:Xgetlist({'changedtick' : 0}).changedtick)
3289 call g:Xsetlist([], 'a', {'title' : 'New Title'})
3290 call assert_equal(5, g:Xgetlist({'changedtick' : 0}).changedtick)
3291
3292 enew!
3293 call append(0, ["F5:50:L50", "F6:60:L60"])
3294 Xaddbuffer
3295 call assert_equal(6, g:Xgetlist({'changedtick' : 0}).changedtick)
3296 enew!
3297
3298 call g:Xsetlist([], 'a', {'context' : {'bus' : 'pci'}})
3299 call assert_equal(7, g:Xgetlist({'changedtick' : 0}).changedtick)
3300 call g:Xsetlist([{'filename' : 'F7', 'lnum' : 10, 'text' : 'L7'},
3301 \ {'filename' : 'F7', 'lnum' : 11, 'text' : 'L11'}], 'a')
3302 call assert_equal(8, g:Xgetlist({'changedtick' : 0}).changedtick)
3303 call g:Xsetlist([{'filename' : 'F7', 'lnum' : 10, 'text' : 'L7'},
3304 \ {'filename' : 'F7', 'lnum' : 11, 'text' : 'L11'}], ' ')
3305 call assert_equal(1, g:Xgetlist({'changedtick' : 0}).changedtick)
3306 call g:Xsetlist([{'filename' : 'F7', 'lnum' : 10, 'text' : 'L7'},
3307 \ {'filename' : 'F7', 'lnum' : 11, 'text' : 'L11'}], 'r')
3308 call assert_equal(2, g:Xgetlist({'changedtick' : 0}).changedtick)
3309
3310 call writefile(["F8:80:L80", "F8:81:L81"], "Xone")
3311 Xfile Xone
3312 call assert_equal(1, g:Xgetlist({'changedtick' : 0}).changedtick)
3313 Xaddfile Xone
3314 call assert_equal(2, g:Xgetlist({'changedtick' : 0}).changedtick)
3315
3316 " Test case for updating a non-current quickfix list
3317 call g:Xsetlist([], 'f')
3318 Xexpr "F1:1:L1"
3319 Xexpr "F2:2:L2"
3320 call g:Xsetlist([], 'a', {'nr' : 1, "lines" : ["F10:10:L10"]})
3321 call assert_equal(1, g:Xgetlist({'changedtick' : 0}).changedtick)
3322 call assert_equal(2, g:Xgetlist({'nr' : 1, 'changedtick' : 0}).changedtick)
3323
3324 call delete("Xone")
3325endfunc
3326
3327func Test_qf_tick()
3328 call Xqftick_tests('c')
3329 call Xqftick_tests('l')
3330endfunc
Bram Moolenaar12237442017-12-19 12:38:52 +01003331
Bram Moolenaarc631f2d2018-08-21 21:58:13 +02003332" Test helpgrep with lang specifier
3333func Xtest_helpgrep_with_lang_specifier(cchar)
3334 call s:setup_commands(a:cchar)
3335 Xhelpgrep Vim@en
3336 call assert_equal('help', &filetype)
3337 call assert_notequal(0, g:Xgetlist({'nr' : '$'}).nr)
3338 new | only
3339endfunc
3340
3341func Test_helpgrep_with_lang_specifier()
3342 call Xtest_helpgrep_with_lang_specifier('c')
3343 call Xtest_helpgrep_with_lang_specifier('l')
3344endfunc
3345
Bram Moolenaar12237442017-12-19 12:38:52 +01003346" The following test used to crash Vim.
3347" Open the location list window and close the regular window associated with
3348" the location list. When the garbage collection runs now, it incorrectly
3349" marks the location list context as not in use and frees the context.
3350func Test_ll_window_ctx()
3351 call setloclist(0, [], 'f')
3352 call setloclist(0, [], 'a', {'context' : []})
3353 lopen | only
3354 call test_garbagecollect_now()
3355 echo getloclist(0, {'context' : 1}).context
3356 enew | only
3357endfunc
3358
Bram Moolenaar14a4deb2017-12-19 16:48:55 +01003359" The following test used to crash vim
3360func Test_lfile_crash()
3361 sp Xtest
3362 au QuickFixCmdPre * bw
3363 call assert_fails('lfile', 'E40')
3364 au! QuickFixCmdPre
3365endfunc
Bram Moolenaar3c097222017-12-21 20:54:49 +01003366
3367" The following test used to crash vim
3368func Test_lbuffer_crash()
3369 sv Xtest
3370 augroup QF_Test
3371 au!
3372 au * * bw
3373 augroup END
3374 lbuffer
3375 augroup QF_Test
3376 au!
3377 augroup END
3378endfunc
3379
3380" The following test used to crash vim
3381func Test_lexpr_crash()
3382 augroup QF_Test
3383 au!
3384 au * * call setloclist(0, [], 'f')
3385 augroup END
3386 lexpr ""
3387 augroup QF_Test
3388 au!
3389 augroup END
Bram Moolenaar9f84ded2018-10-20 20:54:02 +02003390
Bram Moolenaar3c097222017-12-21 20:54:49 +01003391 enew | only
Bram Moolenaar9f84ded2018-10-20 20:54:02 +02003392 augroup QF_Test
3393 au!
3394 au BufNew * call setloclist(0, [], 'f')
3395 augroup END
3396 lexpr 'x:1:x'
3397 augroup QF_Test
3398 au!
3399 augroup END
3400
3401 enew | only
3402 lexpr ''
3403 lopen
3404 augroup QF_Test
3405 au!
3406 au FileType * call setloclist(0, [], 'f')
3407 augroup END
3408 lexpr ''
3409 augroup QF_Test
3410 au!
3411 augroup END
Bram Moolenaar3c097222017-12-21 20:54:49 +01003412endfunc
3413
3414" The following test used to crash Vim
3415func Test_lvimgrep_crash()
3416 sv Xtest
3417 augroup QF_Test
3418 au!
3419 au * * call setloclist(0, [], 'f')
3420 augroup END
3421 lvimgrep quickfix test_quickfix.vim
3422 augroup QF_Test
3423 au!
3424 augroup END
Bram Moolenaarb6f14802018-10-21 18:47:43 +02003425
3426 new | only
3427 augroup QF_Test
3428 au!
3429 au BufEnter * call setloclist(0, [], 'r')
3430 augroup END
3431 call assert_fails('lvimgrep Test_lvimgrep_crash *', 'E926:')
3432 augroup QF_Test
3433 au!
3434 augroup END
3435
Bram Moolenaar3c097222017-12-21 20:54:49 +01003436 enew | only
3437endfunc
Bram Moolenaarde046542017-12-26 13:53:11 +01003438
3439" Test for the position of the quickfix and location list window
3440func Test_qfwin_pos()
3441 " Open two windows
3442 new | only
3443 new
3444 cexpr ['F1:10:L10']
3445 copen
3446 " Quickfix window should be the bottom most window
3447 call assert_equal(3, winnr())
3448 close
3449 " Open at the very top
3450 wincmd t
3451 topleft copen
3452 call assert_equal(1, winnr())
3453 close
3454 " open left of the current window
3455 wincmd t
3456 below new
3457 leftabove copen
3458 call assert_equal(2, winnr())
3459 close
3460 " open right of the current window
3461 rightbelow copen
3462 call assert_equal(3, winnr())
3463 close
3464endfunc
Bram Moolenaare1bb8792018-04-06 22:58:23 +02003465
3466" Tests for quickfix/location lists changed by autocommands when
3467" :vimgrep/:lvimgrep commands are running.
3468func Test_vimgrep_autocmd()
3469 call setqflist([], 'f')
3470 call writefile(['stars'], 'Xtest1.txt')
3471 call writefile(['stars'], 'Xtest2.txt')
3472
3473 " Test 1:
3474 " When searching for a pattern using :vimgrep, if the quickfix list is
3475 " changed by an autocmd, the results should be added to the correct quickfix
3476 " list.
3477 autocmd BufRead Xtest2.txt cexpr '' | cexpr ''
3478 silent vimgrep stars Xtest*.txt
3479 call assert_equal(1, getqflist({'nr' : 0}).nr)
3480 call assert_equal(3, getqflist({'nr' : '$'}).nr)
3481 call assert_equal('Xtest2.txt', bufname(getqflist()[1].bufnr))
3482 au! BufRead Xtest2.txt
3483
3484 " Test 2:
3485 " When searching for a pattern using :vimgrep, if the quickfix list is
3486 " freed, then a error should be given.
3487 silent! %bwipe!
3488 call setqflist([], 'f')
3489 autocmd BufRead Xtest2.txt for i in range(10) | cexpr '' | endfor
3490 call assert_fails('vimgrep stars Xtest*.txt', 'E925:')
3491 au! BufRead Xtest2.txt
3492
3493 " Test 3:
3494 " When searching for a pattern using :lvimgrep, if the location list is
3495 " freed, then the command should error out.
3496 silent! %bwipe!
3497 let g:save_winid = win_getid()
3498 autocmd BufRead Xtest2.txt call setloclist(g:save_winid, [], 'f')
3499 call assert_fails('lvimgrep stars Xtest*.txt', 'E926:')
3500 au! BufRead Xtest2.txt
3501
3502 call delete('Xtest1.txt')
3503 call delete('Xtest2.txt')
3504 call setqflist([], 'f')
3505endfunc
Bram Moolenaar3b9474b2018-04-23 21:29:48 +02003506
3507" The following test used to crash Vim
3508func Test_lhelpgrep_autocmd()
3509 lhelpgrep quickfix
3510 autocmd QuickFixCmdPost * call setloclist(0, [], 'f')
3511 lhelpgrep buffer
3512 call assert_equal('help', &filetype)
3513 call assert_equal(0, getloclist(0, {'nr' : '$'}).nr)
3514 lhelpgrep tabpage
3515 call assert_equal('help', &filetype)
3516 call assert_equal(1, getloclist(0, {'nr' : '$'}).nr)
3517 au! QuickFixCmdPost
Bram Moolenaarb6f14802018-10-21 18:47:43 +02003518
3519 new | only
3520 augroup QF_Test
3521 au!
3522 au BufEnter * call setqflist([], 'f')
3523 augroup END
3524 call assert_fails('helpgrep quickfix', 'E925:')
3525 augroup QF_Test
3526 au! BufEnter
3527 augroup END
3528
3529 new | only
3530 augroup QF_Test
3531 au!
3532 au BufEnter * call setqflist([], 'r')
3533 augroup END
3534 call assert_fails('helpgrep quickfix', 'E925:')
3535 augroup QF_Test
3536 au! BufEnter
3537 augroup END
3538
3539 new | only
3540 augroup QF_Test
3541 au!
3542 au BufEnter * call setloclist(0, [], 'r')
3543 augroup END
3544 call assert_fails('lhelpgrep quickfix', 'E926:')
3545 augroup QF_Test
3546 au! BufEnter
3547 augroup END
3548
Bram Moolenaar3b9474b2018-04-23 21:29:48 +02003549 new | only
3550endfunc
Bram Moolenaara796d462018-05-01 14:30:36 +02003551
3552" Test for shortening/simplifying the file name when opening the
3553" quickfix window or when displaying the quickfix list
3554func Test_shorten_fname()
3555 if !has('unix')
3556 return
3557 endif
3558 %bwipe
3559 " Create a quickfix list with a absolute path filename
3560 let fname = getcwd() . '/test_quickfix.vim'
3561 call setqflist([], ' ', {'lines':[fname . ":20:Line20"], 'efm':'%f:%l:%m'})
3562 call assert_equal(fname, bufname('test_quickfix.vim'))
3563 " Opening the quickfix window should simplify the file path
3564 cwindow
3565 call assert_equal('test_quickfix.vim', bufname('test_quickfix.vim'))
3566 cclose
3567 %bwipe
3568 " Create a quickfix list with a absolute path filename
3569 call setqflist([], ' ', {'lines':[fname . ":20:Line20"], 'efm':'%f:%l:%m'})
3570 call assert_equal(fname, bufname('test_quickfix.vim'))
3571 " Displaying the quickfix list should simplify the file path
3572 silent! clist
3573 call assert_equal('test_quickfix.vim', bufname('test_quickfix.vim'))
3574endfunc
Bram Moolenaar8b62e312018-05-13 15:29:04 +02003575
3576" Quickfix title tests
3577" In the below tests, 'exe "cmd"' is used to invoke the quickfix commands.
3578" Otherwise due to indentation, the title is set with spaces at the beginning
3579" of the command.
3580func Test_qftitle()
3581 call writefile(["F1:1:Line1"], 'Xerr')
3582
3583 " :cexpr
3584 exe "cexpr readfile('Xerr')"
3585 call assert_equal(":cexpr readfile('Xerr')", getqflist({'title' : 1}).title)
3586
3587 " :cgetexpr
3588 exe "cgetexpr readfile('Xerr')"
3589 call assert_equal(":cgetexpr readfile('Xerr')",
3590 \ getqflist({'title' : 1}).title)
3591
3592 " :caddexpr
3593 call setqflist([], 'f')
3594 exe "caddexpr readfile('Xerr')"
3595 call assert_equal(":caddexpr readfile('Xerr')",
3596 \ getqflist({'title' : 1}).title)
3597
3598 " :cbuffer
3599 new Xerr
3600 exe "cbuffer"
3601 call assert_equal(':cbuffer (Xerr)', getqflist({'title' : 1}).title)
3602
3603 " :cgetbuffer
3604 edit Xerr
3605 exe "cgetbuffer"
3606 call assert_equal(':cgetbuffer (Xerr)', getqflist({'title' : 1}).title)
3607
3608 " :caddbuffer
3609 call setqflist([], 'f')
3610 edit Xerr
3611 exe "caddbuffer"
3612 call assert_equal(':caddbuffer (Xerr)', getqflist({'title' : 1}).title)
3613
3614 " :cfile
3615 exe "cfile Xerr"
3616 call assert_equal(':cfile Xerr', getqflist({'title' : 1}).title)
3617
3618 " :cgetfile
3619 exe "cgetfile Xerr"
3620 call assert_equal(':cgetfile Xerr', getqflist({'title' : 1}).title)
3621
3622 " :caddfile
3623 call setqflist([], 'f')
3624 exe "caddfile Xerr"
3625 call assert_equal(':caddfile Xerr', getqflist({'title' : 1}).title)
3626
3627 " :grep
3628 set grepprg=internal
3629 exe "grep F1 Xerr"
3630 call assert_equal(':grep F1 Xerr', getqflist({'title' : 1}).title)
3631
3632 " :grepadd
3633 call setqflist([], 'f')
3634 exe "grepadd F1 Xerr"
3635 call assert_equal(':grepadd F1 Xerr', getqflist({'title' : 1}).title)
3636 set grepprg&vim
3637
3638 " :vimgrep
3639 exe "vimgrep F1 Xerr"
3640 call assert_equal(':vimgrep F1 Xerr', getqflist({'title' : 1}).title)
3641
3642 " :vimgrepadd
3643 call setqflist([], 'f')
3644 exe "vimgrepadd F1 Xerr"
3645 call assert_equal(':vimgrepadd F1 Xerr', getqflist({'title' : 1}).title)
3646
3647 call setqflist(['F1:10:L10'], ' ')
3648 call assert_equal(':setqflist()', getqflist({'title' : 1}).title)
3649
3650 call setqflist([], 'f')
3651 call setqflist(['F1:10:L10'], 'a')
3652 call assert_equal(':setqflist()', getqflist({'title' : 1}).title)
3653
3654 call setqflist([], 'f')
3655 call setqflist(['F1:10:L10'], 'r')
3656 call assert_equal(':setqflist()', getqflist({'title' : 1}).title)
3657
3658 close
3659 call delete('Xerr')
3660
3661 call setqflist([], ' ', {'title' : 'Errors'})
3662 copen
3663 call assert_equal('Errors', w:quickfix_title)
3664 call setqflist([], 'r', {'items' : [{'filename' : 'a.c', 'lnum' : 10}]})
3665 call assert_equal('Errors', w:quickfix_title)
3666 cclose
3667endfunc
Bram Moolenaar600323b2018-06-16 22:16:47 +02003668
3669func Test_lbuffer_with_bwipe()
3670 new
3671 new
3672 augroup nasty
3673 au * * bwipe
3674 augroup END
3675 lbuffer
3676 augroup nasty
3677 au!
3678 augroup END
3679endfunc
Bram Moolenaar0366c012018-06-18 20:52:13 +02003680
Bram Moolenaar531b9a32018-07-03 16:54:23 +02003681" Test for an autocmd freeing the quickfix/location list when cexpr/lexpr is
3682" running
3683func Xexpr_acmd_freelist(cchar)
3684 call s:setup_commands(a:cchar)
3685
Bram Moolenaar0366c012018-06-18 20:52:13 +02003686 " This was using freed memory.
3687 augroup nasty
Bram Moolenaar531b9a32018-07-03 16:54:23 +02003688 au * * call g:Xsetlist([], 'f')
Bram Moolenaar0366c012018-06-18 20:52:13 +02003689 augroup END
Bram Moolenaar531b9a32018-07-03 16:54:23 +02003690 Xexpr "x"
Bram Moolenaar0366c012018-06-18 20:52:13 +02003691 augroup nasty
3692 au!
3693 augroup END
3694endfunc
Bram Moolenaar531b9a32018-07-03 16:54:23 +02003695
3696func Test_cexpr_acmd_freelist()
3697 call Xexpr_acmd_freelist('c')
3698 call Xexpr_acmd_freelist('l')
3699endfunc
3700
3701" Test for commands that create a new quickfix/location list and jump to the
3702" first error automatically.
3703func Xjumpto_first_error_test(cchar)
3704 call s:setup_commands(a:cchar)
3705
3706 call s:create_test_file('Xtestfile1')
3707 call s:create_test_file('Xtestfile2')
3708 let l = ['Xtestfile1:2:Line2', 'Xtestfile2:4:Line4']
3709
3710 " Test for cexpr/lexpr
3711 enew
3712 Xexpr l
3713 call assert_equal('Xtestfile1', bufname(''))
3714 call assert_equal(2, line('.'))
3715
3716 " Test for cfile/lfile
3717 enew
3718 call writefile(l, 'Xerr')
3719 Xfile Xerr
3720 call assert_equal('Xtestfile1', bufname(''))
3721 call assert_equal(2, line('.'))
3722
3723 " Test for cbuffer/lbuffer
3724 edit Xerr
3725 Xbuffer
3726 call assert_equal('Xtestfile1', bufname(''))
3727 call assert_equal(2, line('.'))
3728
3729 call delete('Xerr')
3730 call delete('Xtestfile1')
3731 call delete('Xtestfile2')
3732endfunc
3733
3734func Test_jumpto_first_error()
3735 call Xjumpto_first_error_test('c')
3736 call Xjumpto_first_error_test('l')
3737endfunc
3738
3739" Test for a quickfix autocmd changing the quickfix/location list before
3740" jumping to the first error in the new list.
3741func Xautocmd_changelist(cchar)
3742 call s:setup_commands(a:cchar)
3743
3744 " Test for cfile/lfile
3745 call s:create_test_file('Xtestfile1')
3746 call s:create_test_file('Xtestfile2')
3747 Xexpr 'Xtestfile1:2:Line2'
3748 autocmd QuickFixCmdPost * Xolder
3749 call writefile(['Xtestfile2:4:Line4'], 'Xerr')
3750 Xfile Xerr
3751 call assert_equal('Xtestfile2', bufname(''))
3752 call assert_equal(4, line('.'))
3753 autocmd! QuickFixCmdPost
3754
3755 " Test for cbuffer/lbuffer
3756 call g:Xsetlist([], 'f')
3757 Xexpr 'Xtestfile1:2:Line2'
3758 autocmd QuickFixCmdPost * Xolder
3759 call writefile(['Xtestfile2:4:Line4'], 'Xerr')
3760 edit Xerr
3761 Xbuffer
3762 call assert_equal('Xtestfile2', bufname(''))
3763 call assert_equal(4, line('.'))
3764 autocmd! QuickFixCmdPost
3765
3766 " Test for cexpr/lexpr
3767 call g:Xsetlist([], 'f')
3768 Xexpr 'Xtestfile1:2:Line2'
3769 autocmd QuickFixCmdPost * Xolder
3770 Xexpr 'Xtestfile2:4:Line4'
3771 call assert_equal('Xtestfile2', bufname(''))
3772 call assert_equal(4, line('.'))
3773 autocmd! QuickFixCmdPost
3774
Bram Moolenaar851332e2018-07-03 19:16:00 +02003775 " The grepprg may not be set on non-Unix systems
3776 if has('unix')
3777 " Test for grep/lgrep
3778 call g:Xsetlist([], 'f')
3779 Xexpr 'Xtestfile1:2:Line2'
3780 autocmd QuickFixCmdPost * Xolder
3781 silent Xgrep Line5 Xtestfile2
3782 call assert_equal('Xtestfile2', bufname(''))
3783 call assert_equal(5, line('.'))
3784 autocmd! QuickFixCmdPost
3785 endif
Bram Moolenaar531b9a32018-07-03 16:54:23 +02003786
3787 " Test for vimgrep/lvimgrep
3788 call g:Xsetlist([], 'f')
3789 Xexpr 'Xtestfile1:2:Line2'
3790 autocmd QuickFixCmdPost * Xolder
3791 silent Xvimgrep Line5 Xtestfile2
3792 call assert_equal('Xtestfile2', bufname(''))
3793 call assert_equal(5, line('.'))
3794 autocmd! QuickFixCmdPost
3795
Bram Moolenaar3f347e42018-08-09 21:19:20 +02003796 " Test for autocommands clearing the quickfix list before jumping to the
3797 " first error. This should not result in an error
3798 autocmd QuickFixCmdPost * call g:Xsetlist([], 'r')
3799 let v:errmsg = ''
3800 " Test for cfile/lfile
3801 Xfile Xerr
3802 call assert_true(v:errmsg !~# 'E42:')
3803 " Test for cbuffer/lbuffer
3804 edit Xerr
3805 Xbuffer
3806 call assert_true(v:errmsg !~# 'E42:')
3807 " Test for cexpr/lexpr
3808 Xexpr 'Xtestfile2:4:Line4'
3809 call assert_true(v:errmsg !~# 'E42:')
3810 " Test for grep/lgrep
3811 " The grepprg may not be set on non-Unix systems
3812 if has('unix')
3813 silent Xgrep Line5 Xtestfile2
3814 call assert_true(v:errmsg !~# 'E42:')
3815 endif
3816 " Test for vimgrep/lvimgrep
3817 call assert_fails('silent Xvimgrep Line5 Xtestfile2', 'E480:')
3818 autocmd! QuickFixCmdPost
3819
Bram Moolenaar531b9a32018-07-03 16:54:23 +02003820 call delete('Xerr')
3821 call delete('Xtestfile1')
3822 call delete('Xtestfile2')
3823endfunc
3824
3825func Test_autocmd_changelist()
3826 call Xautocmd_changelist('c')
3827 call Xautocmd_changelist('l')
3828endfunc
Bram Moolenaar4cde86c2018-07-08 16:01:08 +02003829
3830" Tests for the ':filter /pat/ clist' command
3831func Test_filter_clist()
3832 cexpr ['Xfile1:10:10:Line 10', 'Xfile2:15:15:Line 15']
3833 call assert_equal([' 2 Xfile2:15 col 15: Line 15'],
3834 \ split(execute('filter /Line 15/ clist'), "\n"))
3835 call assert_equal([' 1 Xfile1:10 col 10: Line 10'],
3836 \ split(execute('filter /Xfile1/ clist'), "\n"))
3837 call assert_equal([], split(execute('filter /abc/ clist'), "\n"))
3838
3839 call setqflist([{'module' : 'abc', 'pattern' : 'pat1'},
3840 \ {'module' : 'pqr', 'pattern' : 'pat2'}], ' ')
3841 call assert_equal([' 2 pqr:pat2: '],
3842 \ split(execute('filter /pqr/ clist'), "\n"))
3843 call assert_equal([' 1 abc:pat1: '],
3844 \ split(execute('filter /pat1/ clist'), "\n"))
3845endfunc
Bram Moolenaar0a08c632018-07-25 22:36:52 +02003846
3847" Tests for the "CTRL-W <CR>" command.
3848func Xview_result_split_tests(cchar)
3849 call s:setup_commands(a:cchar)
3850
3851 " Test that "CTRL-W <CR>" in a qf/ll window fails with empty list.
3852 call g:Xsetlist([])
3853 Xopen
3854 let l:win_count = winnr('$')
3855 call assert_fails('execute "normal! \<C-W>\<CR>"', 'E42')
3856 call assert_equal(l:win_count, winnr('$'))
3857 Xclose
3858endfunc
3859
3860func Test_view_result_split()
3861 call Xview_result_split_tests('c')
3862 call Xview_result_split_tests('l')
3863endfunc
Bram Moolenaar2dfcef42018-08-15 22:29:51 +02003864
3865" Test that :cc sets curswant
3866func Test_curswant()
3867 helpgrep quickfix
3868 normal! llll
3869 1cc
3870 call assert_equal(getcurpos()[4], virtcol('.'))
3871 cclose | helpclose
3872endfunc
Bram Moolenaarb2443732018-11-11 22:50:27 +01003873
3874" Test for opening a file from the quickfix window using CTRL-W <Enter>
3875" doesn't leave an empty buffer around.
3876func Test_splitview()
3877 call s:create_test_file('Xtestfile1')
3878 call s:create_test_file('Xtestfile2')
3879 new | only
3880 let last_bufnr = bufnr('Test_sv_1', 1)
3881 let l = ['Xtestfile1:2:Line2', 'Xtestfile2:4:Line4']
3882 cgetexpr l
3883 copen
3884 let numbufs = len(getbufinfo())
3885 exe "normal \<C-W>\<CR>"
3886 copen
3887 exe "normal j\<C-W>\<CR>"
3888 " Make sure new empty buffers are not created
3889 call assert_equal(numbufs, len(getbufinfo()))
3890 " Creating a new buffer should use the next available buffer number
3891 call assert_equal(last_bufnr + 4, bufnr("Test_sv_2", 1))
3892 bwipe Test_sv_1
3893 bwipe Test_sv_2
3894 new | only
3895
3896 " When split opening files from location list window, make sure that two
3897 " windows doesn't refer to the same location list
3898 lgetexpr l
3899 let locid = getloclist(0, {'id' : 0}).id
3900 lopen
3901 exe "normal \<C-W>\<CR>"
3902 call assert_notequal(locid, getloclist(0, {'id' : 0}).id)
3903 call assert_equal(0, getloclist(0, {'winid' : 0}).winid)
3904 new | only
3905
3906 " When split opening files from a helpgrep location list window, a new help
Bram Moolenaareeb1b9c2019-02-10 22:59:04 +01003907 " window should be opened with a copy of the location list.
Bram Moolenaarb2443732018-11-11 22:50:27 +01003908 lhelpgrep window
3909 let locid = getloclist(0, {'id' : 0}).id
3910 lwindow
3911 exe "normal j\<C-W>\<CR>"
3912 call assert_notequal(locid, getloclist(0, {'id' : 0}).id)
3913 call assert_equal(0, getloclist(0, {'winid' : 0}).winid)
3914 new | only
3915
3916 call delete('Xtestfile1')
3917 call delete('Xtestfile2')
3918endfunc
Bram Moolenaarc45eb772019-01-31 14:27:04 +01003919
3920" Test for parsing entries using visual screen column
3921func Test_viscol()
3922 enew
3923 call writefile(["Col1\tCol2\tCol3"], 'Xfile1')
3924 edit Xfile1
3925
3926 " Use byte offset for column number
3927 set efm&
3928 cexpr "Xfile1:1:5:XX\nXfile1:1:9:YY\nXfile1:1:20:ZZ"
3929 call assert_equal([5, 8], [col('.'), virtcol('.')])
3930 cnext
3931 call assert_equal([9, 12], [col('.'), virtcol('.')])
3932 cnext
3933 call assert_equal([14, 20], [col('.'), virtcol('.')])
3934
3935 " Use screen column offset for column number
3936 set efm=%f:%l:%v:%m
3937 cexpr "Xfile1:1:8:XX\nXfile1:1:12:YY\nXfile1:1:20:ZZ"
3938 call assert_equal([5, 8], [col('.'), virtcol('.')])
3939 cnext
3940 call assert_equal([9, 12], [col('.'), virtcol('.')])
3941 cnext
3942 call assert_equal([14, 20], [col('.'), virtcol('.')])
3943 cexpr "Xfile1:1:6:XX\nXfile1:1:15:YY\nXfile1:1:24:ZZ"
3944 call assert_equal([5, 8], [col('.'), virtcol('.')])
3945 cnext
3946 call assert_equal([10, 16], [col('.'), virtcol('.')])
3947 cnext
3948 call assert_equal([14, 20], [col('.'), virtcol('.')])
3949
3950 enew
3951 call writefile(["Col1\täü\töß\tCol4"], 'Xfile1')
3952
3953 " Use byte offset for column number
3954 set efm&
3955 cexpr "Xfile1:1:8:XX\nXfile1:1:11:YY\nXfile1:1:16:ZZ"
3956 call assert_equal([8, 10], [col('.'), virtcol('.')])
3957 cnext
3958 call assert_equal([11, 17], [col('.'), virtcol('.')])
3959 cnext
3960 call assert_equal([16, 25], [col('.'), virtcol('.')])
3961
3962 " Use screen column offset for column number
3963 set efm=%f:%l:%v:%m
3964 cexpr "Xfile1:1:10:XX\nXfile1:1:17:YY\nXfile1:1:25:ZZ"
3965 call assert_equal([8, 10], [col('.'), virtcol('.')])
3966 cnext
3967 call assert_equal([11, 17], [col('.'), virtcol('.')])
3968 cnext
3969 call assert_equal([16, 25], [col('.'), virtcol('.')])
3970
3971 enew | only
3972 set efm&
3973 call delete('Xfile1')
3974endfunc
Bram Moolenaaree8188f2019-02-05 21:23:04 +01003975
3976" Test for the quickfix window buffer
3977func Xqfbuf_test(cchar)
3978 call s:setup_commands(a:cchar)
3979
3980 " Quickfix buffer should be reused across closing and opening a quickfix
3981 " window
3982 Xexpr "F1:10:Line10"
3983 Xopen
3984 let qfbnum = bufnr('')
3985 Xclose
3986 " Even after the quickfix window is closed, the buffer should be loaded
3987 call assert_true(bufloaded(qfbnum))
Bram Moolenaar647e24b2019-03-17 16:39:46 +01003988 call assert_true(qfbnum, g:Xgetlist({'qfbufnr' : 0}).qfbufnr)
Bram Moolenaaree8188f2019-02-05 21:23:04 +01003989 Xopen
3990 " Buffer should be reused when opening the window again
3991 call assert_equal(qfbnum, bufnr(''))
3992 Xclose
3993
3994 if a:cchar == 'l'
3995 %bwipe
3996 " For a location list, when both the file window and the location list
3997 " window for the list are closed, then the buffer should be freed.
3998 new | only
3999 lexpr "F1:10:Line10"
4000 let wid = win_getid()
4001 lopen
4002 let qfbnum = bufnr('')
4003 call assert_match(qfbnum . ' %a- "\[Location List]"', execute('ls'))
4004 close
4005 " When the location list window is closed, the buffer name should not
4006 " change to 'Quickfix List'
Bram Moolenaar647e24b2019-03-17 16:39:46 +01004007 call assert_match(qfbnum . 'u h- "\[Location List]"', execute('ls!'))
Bram Moolenaaree8188f2019-02-05 21:23:04 +01004008 call assert_true(bufloaded(qfbnum))
4009
Bram Moolenaard82a81c2019-03-02 07:57:18 +01004010 " After deleting a location list buffer using ":bdelete", opening the
4011 " location list window should mark the buffer as a location list buffer.
4012 exe "bdelete " . qfbnum
4013 lopen
4014 call assert_equal("quickfix", &buftype)
4015 call assert_equal(1, getwininfo(win_getid(winnr()))[0].loclist)
4016 call assert_equal(wid, getloclist(0, {'filewinid' : 0}).filewinid)
4017 call assert_false(&swapfile)
4018 lclose
4019
Bram Moolenaareeb1b9c2019-02-10 22:59:04 +01004020 " When the location list is cleared for the window, the buffer should be
4021 " removed
4022 call setloclist(0, [], 'f')
4023 call assert_false(bufexists(qfbnum))
Bram Moolenaar647e24b2019-03-17 16:39:46 +01004024 call assert_equal(0, getloclist(0, {'qfbufnr' : 0}).qfbufnr)
Bram Moolenaareeb1b9c2019-02-10 22:59:04 +01004025
4026 " When the location list is freed with the location list window open, the
4027 " location list buffer should not be lost. It should be reused when the
4028 " location list is again populated.
4029 lexpr "F1:10:Line10"
4030 lopen
4031 let wid = win_getid()
4032 let qfbnum = bufnr('')
4033 wincmd p
4034 call setloclist(0, [], 'f')
4035 lexpr "F1:10:Line10"
4036 lopen
4037 call assert_equal(wid, win_getid())
4038 call assert_equal(qfbnum, bufnr(''))
4039 lclose
4040
4041 " When the window with the location list is closed, the buffer should be
4042 " removed
Bram Moolenaaree8188f2019-02-05 21:23:04 +01004043 new | only
Bram Moolenaareeb1b9c2019-02-10 22:59:04 +01004044 call assert_false(bufexists(qfbnum))
Bram Moolenaaree8188f2019-02-05 21:23:04 +01004045 endif
4046endfunc
4047
4048func Test_qfbuf()
4049 call Xqfbuf_test('c')
4050 call Xqfbuf_test('l')
4051endfunc
Bram Moolenaareeb1b9c2019-02-10 22:59:04 +01004052
4053" If there is an autocmd to use only one window, then opening the location
4054" list window used to crash Vim.
4055func Test_winonly_autocmd()
4056 call s:create_test_file('Xtest1')
4057 " Autocmd to show only one Vim window at a time
4058 autocmd WinEnter * only
4059 new
4060 " Load the location list
4061 lexpr "Xtest1:5:Line5\nXtest1:10:Line10\nXtest1:15:Line15"
4062 let loclistid = getloclist(0, {'id' : 0}).id
4063 " Open the location list window. Only this window will be shown and the file
4064 " window is closed.
4065 lopen
4066 call assert_equal(loclistid, getloclist(0, {'id' : 0}).id)
4067 " Jump to an entry in the location list and make sure that the cursor is
4068 " positioned correctly.
4069 ll 3
4070 call assert_equal(loclistid, getloclist(0, {'id' : 0}).id)
4071 call assert_equal('Xtest1', bufname(''))
4072 call assert_equal(15, line('.'))
4073 " Cleanup
4074 autocmd! WinEnter
4075 new | only
4076 call delete('Xtest1')
4077endfunc
Bram Moolenaar39803d82019-04-07 12:04:51 +02004078
4079" Test to make sure that an empty quickfix buffer is not reused for loading
4080" a normal buffer.
4081func Test_empty_qfbuf()
4082 enew | only
4083 call writefile(["Test"], 'Xfile1')
4084 call setqflist([], 'f')
4085 copen | only
4086 let qfbuf = bufnr('')
4087 edit Xfile1
4088 call assert_notequal(qfbuf, bufnr(''))
4089 enew
4090 call delete('Xfile1')
4091endfunc
Bram Moolenaar3ff33112019-05-03 21:56:35 +02004092
4093" Test for the :cbelow, :cabove, :lbelow and :labove commands.
Bram Moolenaarcf6a55c2019-05-05 15:02:30 +02004094" And for the :cafter, :cbefore, :lafter and :lbefore commands.
Bram Moolenaar3ff33112019-05-03 21:56:35 +02004095func Xtest_below(cchar)
4096 call s:setup_commands(a:cchar)
4097
4098 " No quickfix/location list
4099 call assert_fails('Xbelow', 'E42:')
4100 call assert_fails('Xabove', 'E42:')
Bram Moolenaarcf6a55c2019-05-05 15:02:30 +02004101 call assert_fails('Xbefore', 'E42:')
4102 call assert_fails('Xafter', 'E42:')
Bram Moolenaar3ff33112019-05-03 21:56:35 +02004103
4104 " Empty quickfix/location list
4105 call g:Xsetlist([])
4106 call assert_fails('Xbelow', 'E42:')
4107 call assert_fails('Xabove', 'E42:')
Bram Moolenaarcf6a55c2019-05-05 15:02:30 +02004108 call assert_fails('Xbefore', 'E42:')
4109 call assert_fails('Xafter', 'E42:')
Bram Moolenaar3ff33112019-05-03 21:56:35 +02004110
4111 call s:create_test_file('X1')
4112 call s:create_test_file('X2')
4113 call s:create_test_file('X3')
4114 call s:create_test_file('X4')
4115
4116 " Invalid entries
4117 edit X1
4118 call g:Xsetlist(["E1", "E2"])
4119 call assert_fails('Xbelow', 'E42:')
4120 call assert_fails('Xabove', 'E42:')
4121 call assert_fails('3Xbelow', 'E42:')
4122 call assert_fails('4Xabove', 'E42:')
Bram Moolenaarcf6a55c2019-05-05 15:02:30 +02004123 call assert_fails('Xbefore', 'E42:')
4124 call assert_fails('Xafter', 'E42:')
4125 call assert_fails('3Xbefore', 'E42:')
4126 call assert_fails('4Xafter', 'E42:')
Bram Moolenaar3ff33112019-05-03 21:56:35 +02004127
4128 " Test the commands with various arguments
Bram Moolenaarcf6a55c2019-05-05 15:02:30 +02004129 Xexpr ["X1:5:3:L5", "X2:5:2:L5", "X2:10:3:L10", "X2:15:4:L15", "X3:3:5:L3"]
Bram Moolenaar3ff33112019-05-03 21:56:35 +02004130 edit +7 X2
4131 Xabove
4132 call assert_equal(['X2', 5], [bufname(''), line('.')])
4133 call assert_fails('Xabove', 'E553:')
Bram Moolenaarcf6a55c2019-05-05 15:02:30 +02004134 normal 7G
4135 Xbefore
4136 call assert_equal(['X2', 5, 2], [bufname(''), line('.'), col('.')])
4137 call assert_fails('Xbefore', 'E553:')
4138
Bram Moolenaar3ff33112019-05-03 21:56:35 +02004139 normal 2j
4140 Xbelow
4141 call assert_equal(['X2', 10], [bufname(''), line('.')])
Bram Moolenaarcf6a55c2019-05-05 15:02:30 +02004142 normal 7G
4143 Xafter
4144 call assert_equal(['X2', 10, 3], [bufname(''), line('.'), col('.')])
4145
Bram Moolenaar3ff33112019-05-03 21:56:35 +02004146 " Last error in this file
4147 Xbelow 99
4148 call assert_equal(['X2', 15], [bufname(''), line('.')])
4149 call assert_fails('Xbelow', 'E553:')
Bram Moolenaarcf6a55c2019-05-05 15:02:30 +02004150 normal gg
4151 Xafter 99
4152 call assert_equal(['X2', 15, 4], [bufname(''), line('.'), col('.')])
4153 call assert_fails('Xafter', 'E553:')
4154
Bram Moolenaar3ff33112019-05-03 21:56:35 +02004155 " First error in this file
4156 Xabove 99
4157 call assert_equal(['X2', 5], [bufname(''), line('.')])
4158 call assert_fails('Xabove', 'E553:')
Bram Moolenaarcf6a55c2019-05-05 15:02:30 +02004159 normal G
4160 Xbefore 99
4161 call assert_equal(['X2', 5, 2], [bufname(''), line('.'), col('.')])
4162 call assert_fails('Xbefore', 'E553:')
4163
Bram Moolenaar3ff33112019-05-03 21:56:35 +02004164 normal gg
4165 Xbelow 2
4166 call assert_equal(['X2', 10], [bufname(''), line('.')])
Bram Moolenaarcf6a55c2019-05-05 15:02:30 +02004167 normal gg
4168 Xafter 2
4169 call assert_equal(['X2', 10, 3], [bufname(''), line('.'), col('.')])
4170
Bram Moolenaar3ff33112019-05-03 21:56:35 +02004171 normal G
4172 Xabove 2
4173 call assert_equal(['X2', 10], [bufname(''), line('.')])
Bram Moolenaarcf6a55c2019-05-05 15:02:30 +02004174 normal G
4175 Xbefore 2
4176 call assert_equal(['X2', 10, 3], [bufname(''), line('.'), col('.')])
4177
Bram Moolenaar3ff33112019-05-03 21:56:35 +02004178 edit X4
4179 call assert_fails('Xabove', 'E42:')
4180 call assert_fails('Xbelow', 'E42:')
Bram Moolenaarcf6a55c2019-05-05 15:02:30 +02004181 call assert_fails('Xbefore', 'E42:')
4182 call assert_fails('Xafter', 'E42:')
Bram Moolenaar3ff33112019-05-03 21:56:35 +02004183 if a:cchar == 'l'
4184 " If a buffer has location list entries from some other window but not
4185 " from the current window, then the commands should fail.
4186 edit X1 | split | call setloclist(0, [], 'f')
4187 call assert_fails('Xabove', 'E776:')
4188 call assert_fails('Xbelow', 'E776:')
Bram Moolenaarcf6a55c2019-05-05 15:02:30 +02004189 call assert_fails('Xbefore', 'E776:')
4190 call assert_fails('Xafter', 'E776:')
Bram Moolenaar3ff33112019-05-03 21:56:35 +02004191 close
4192 endif
4193
4194 " Test for lines with multiple quickfix entries
4195 Xexpr ["X1:5:L5", "X2:5:1:L5_1", "X2:5:2:L5_2", "X2:5:3:L5_3",
4196 \ "X2:10:1:L10_1", "X2:10:2:L10_2", "X2:10:3:L10_3",
4197 \ "X2:15:1:L15_1", "X2:15:2:L15_2", "X2:15:3:L15_3", "X3:3:L3"]
4198 edit +1 X2
4199 Xbelow 2
4200 call assert_equal(['X2', 10, 1], [bufname(''), line('.'), col('.')])
Bram Moolenaarcf6a55c2019-05-05 15:02:30 +02004201 normal 1G
4202 Xafter 2
4203 call assert_equal(['X2', 5, 2], [bufname(''), line('.'), col('.')])
4204
Bram Moolenaar3ff33112019-05-03 21:56:35 +02004205 normal gg
4206 Xbelow 99
4207 call assert_equal(['X2', 15, 1], [bufname(''), line('.'), col('.')])
Bram Moolenaarcf6a55c2019-05-05 15:02:30 +02004208 normal gg
4209 Xafter 99
4210 call assert_equal(['X2', 15, 3], [bufname(''), line('.'), col('.')])
4211
Bram Moolenaar3ff33112019-05-03 21:56:35 +02004212 normal G
4213 Xabove 2
4214 call assert_equal(['X2', 10, 1], [bufname(''), line('.'), col('.')])
4215 normal G
Bram Moolenaarcf6a55c2019-05-05 15:02:30 +02004216 Xbefore 2
4217 call assert_equal(['X2', 15, 2], [bufname(''), line('.'), col('.')])
4218
4219 normal G
Bram Moolenaar3ff33112019-05-03 21:56:35 +02004220 Xabove 99
4221 call assert_equal(['X2', 5, 1], [bufname(''), line('.'), col('.')])
Bram Moolenaarcf6a55c2019-05-05 15:02:30 +02004222 normal G
4223 Xbefore 99
4224 call assert_equal(['X2', 5, 1], [bufname(''), line('.'), col('.')])
4225
Bram Moolenaar3ff33112019-05-03 21:56:35 +02004226 normal 10G
4227 Xabove
4228 call assert_equal(['X2', 5, 1], [bufname(''), line('.'), col('.')])
Bram Moolenaarcf6a55c2019-05-05 15:02:30 +02004229 normal 10G$
4230 2Xbefore
4231 call assert_equal(['X2', 10, 2], [bufname(''), line('.'), col('.')])
4232
Bram Moolenaar3ff33112019-05-03 21:56:35 +02004233 normal 10G
4234 Xbelow
4235 call assert_equal(['X2', 15, 1], [bufname(''), line('.'), col('.')])
Bram Moolenaarcf6a55c2019-05-05 15:02:30 +02004236 normal 9G
4237 5Xafter
4238 call assert_equal(['X2', 15, 2], [bufname(''), line('.'), col('.')])
Bram Moolenaar3ff33112019-05-03 21:56:35 +02004239
4240 " Invalid range
4241 if a:cchar == 'c'
Bram Moolenaar25190db2019-05-04 15:05:28 +02004242 call assert_fails('-2cbelow', 'E16:')
Bram Moolenaarcf6a55c2019-05-05 15:02:30 +02004243 call assert_fails('-2cafter', 'E16:')
Bram Moolenaar3ff33112019-05-03 21:56:35 +02004244 else
Bram Moolenaar25190db2019-05-04 15:05:28 +02004245 call assert_fails('-2lbelow', 'E16:')
Bram Moolenaarcf6a55c2019-05-05 15:02:30 +02004246 call assert_fails('-2lafter', 'E16:')
Bram Moolenaar3ff33112019-05-03 21:56:35 +02004247 endif
4248
4249 call delete('X1')
4250 call delete('X2')
4251 call delete('X3')
4252 call delete('X4')
4253endfunc
4254
4255func Test_cbelow()
4256 call Xtest_below('c')
4257 call Xtest_below('l')
4258endfunc
Bram Moolenaar25190db2019-05-04 15:05:28 +02004259
4260func Test_quickfix_count()
4261 let commands = [
4262 \ 'cNext',
4263 \ 'cNfile',
4264 \ 'cabove',
4265 \ 'cbelow',
4266 \ 'cfirst',
4267 \ 'clast',
4268 \ 'cnewer',
4269 \ 'cnext',
4270 \ 'cnfile',
4271 \ 'colder',
4272 \ 'cprevious',
4273 \ 'crewind',
4274 \
4275 \ 'lNext',
4276 \ 'lNfile',
4277 \ 'labove',
4278 \ 'lbelow',
4279 \ 'lfirst',
4280 \ 'llast',
4281 \ 'lnewer',
4282 \ 'lnext',
4283 \ 'lnfile',
4284 \ 'lolder',
4285 \ 'lprevious',
4286 \ 'lrewind',
4287 \ ]
4288 for cmd in commands
4289 call assert_fails('-1' .. cmd, 'E16:')
4290 call assert_fails('.' .. cmd, 'E16:')
4291 call assert_fails('%' .. cmd, 'E16:')
4292 call assert_fails('$' .. cmd, 'E16:')
4293 endfor
4294endfunc