blob: 0744364fd63036b47801aa972e58b53634bef6d9 [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 Moolenaar1142a312019-10-16 14:51:39 +0200300func Test_copenHeight_tabline()
301 set tabline=foo showtabline=2
302 copen
303 wincmd H
304 let height = winheight(0)
305 copen 10
306 call assert_equal(height, winheight(0))
307 quit
308 set tabline& showtabline&
309endfunc
310
311
Bram Moolenaarda59dd52016-01-05 21:59:58 +0100312" Tests for the :cfile, :lfile, :caddfile, :laddfile, :cgetfile and :lgetfile
313" commands.
Bram Moolenaar2b946c92016-11-12 18:14:44 +0100314func XfileTests(cchar)
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +0200315 call s:setup_commands(a:cchar)
Bram Moolenaarda59dd52016-01-05 21:59:58 +0100316
317 call writefile(['Xtestfile1:700:10:Line 700',
318 \ 'Xtestfile2:800:15:Line 800'], 'Xqftestfile1')
319
320 enew!
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +0200321 Xfile Xqftestfile1
322 let l = g:Xgetlist()
Bram Moolenaarda59dd52016-01-05 21:59:58 +0100323 call assert_true(len(l) == 2 &&
324 \ l[0].lnum == 700 && l[0].col == 10 && l[0].text ==# 'Line 700' &&
325 \ l[1].lnum == 800 && l[1].col == 15 && l[1].text ==# 'Line 800')
326
Bram Moolenaar049cba92016-06-26 14:38:04 +0200327 " Test with a non existent file
328 call assert_fails('Xfile non_existent_file', 'E40')
329
Bram Moolenaarda59dd52016-01-05 21:59:58 +0100330 " Run cfile/lfile from a modified buffer
331 enew!
332 silent! put ='Quickfix'
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +0200333 silent! Xfile Xqftestfile1
Bram Moolenaarda59dd52016-01-05 21:59:58 +0100334 call assert_true(v:errmsg ==# 'E37: No write since last change (add ! to override)')
335
336 call writefile(['Xtestfile3:900:30:Line 900'], 'Xqftestfile1')
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +0200337 Xaddfile Xqftestfile1
338 let l = g:Xgetlist()
Bram Moolenaarda59dd52016-01-05 21:59:58 +0100339 call assert_true(len(l) == 3 &&
340 \ l[2].lnum == 900 && l[2].col == 30 && l[2].text ==# 'Line 900')
341
342 call writefile(['Xtestfile1:222:77:Line 222',
343 \ 'Xtestfile2:333:88:Line 333'], 'Xqftestfile1')
344
345 enew!
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +0200346 Xgetfile Xqftestfile1
347 let l = g:Xgetlist()
Bram Moolenaarda59dd52016-01-05 21:59:58 +0100348 call assert_true(len(l) == 2 &&
349 \ l[0].lnum == 222 && l[0].col == 77 && l[0].text ==# 'Line 222' &&
350 \ l[1].lnum == 333 && l[1].col == 88 && l[1].text ==# 'Line 333')
351
352 call delete('Xqftestfile1')
Bram Moolenaar2b946c92016-11-12 18:14:44 +0100353endfunc
Bram Moolenaarda59dd52016-01-05 21:59:58 +0100354
Bram Moolenaar2b946c92016-11-12 18:14:44 +0100355func Test_cfile()
Bram Moolenaarda59dd52016-01-05 21:59:58 +0100356 call XfileTests('c')
357 call XfileTests('l')
Bram Moolenaar2b946c92016-11-12 18:14:44 +0100358endfunc
Bram Moolenaarda59dd52016-01-05 21:59:58 +0100359
360" Tests for the :cbuffer, :lbuffer, :caddbuffer, :laddbuffer, :cgetbuffer and
361" :lgetbuffer commands.
Bram Moolenaar2b946c92016-11-12 18:14:44 +0100362func XbufferTests(cchar)
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +0200363 call s:setup_commands(a:cchar)
Bram Moolenaarda59dd52016-01-05 21:59:58 +0100364
365 enew!
366 silent! call setline(1, ['Xtestfile7:700:10:Line 700',
367 \ 'Xtestfile8:800:15:Line 800'])
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +0200368 Xbuffer!
369 let l = g:Xgetlist()
Bram Moolenaarda59dd52016-01-05 21:59:58 +0100370 call assert_true(len(l) == 2 &&
371 \ l[0].lnum == 700 && l[0].col == 10 && l[0].text ==# 'Line 700' &&
372 \ l[1].lnum == 800 && l[1].col == 15 && l[1].text ==# 'Line 800')
373
374 enew!
375 silent! call setline(1, ['Xtestfile9:900:55:Line 900',
376 \ 'Xtestfile10:950:66:Line 950'])
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +0200377 Xgetbuffer
378 let l = g:Xgetlist()
Bram Moolenaarda59dd52016-01-05 21:59:58 +0100379 call assert_true(len(l) == 2 &&
380 \ l[0].lnum == 900 && l[0].col == 55 && l[0].text ==# 'Line 900' &&
381 \ l[1].lnum == 950 && l[1].col == 66 && l[1].text ==# 'Line 950')
382
383 enew!
384 silent! call setline(1, ['Xtestfile11:700:20:Line 700',
385 \ 'Xtestfile12:750:25:Line 750'])
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +0200386 Xaddbuffer
387 let l = g:Xgetlist()
Bram Moolenaarda59dd52016-01-05 21:59:58 +0100388 call assert_true(len(l) == 4 &&
389 \ l[1].lnum == 950 && l[1].col == 66 && l[1].text ==# 'Line 950' &&
390 \ l[2].lnum == 700 && l[2].col == 20 && l[2].text ==# 'Line 700' &&
391 \ l[3].lnum == 750 && l[3].col == 25 && l[3].text ==# 'Line 750')
Bram Moolenaarab47c612016-06-14 22:02:26 +0200392 enew!
Bram Moolenaarda59dd52016-01-05 21:59:58 +0100393
Bram Moolenaaree85df32017-03-19 14:19:50 +0100394 " Check for invalid buffer
395 call assert_fails('Xbuffer 199', 'E474:')
396
397 " Check for unloaded buffer
398 edit Xtestfile1
399 let bnr = bufnr('%')
400 enew!
401 call assert_fails('Xbuffer ' . bnr, 'E681:')
402
403 " Check for invalid range
404 " Using Xbuffer will not run the range check in the cbuffer/lbuffer
405 " commands. So directly call the commands.
406 if (a:cchar == 'c')
407 call assert_fails('900,999cbuffer', 'E16:')
408 else
409 call assert_fails('900,999lbuffer', 'E16:')
410 endif
Bram Moolenaar2b946c92016-11-12 18:14:44 +0100411endfunc
Bram Moolenaarda59dd52016-01-05 21:59:58 +0100412
Bram Moolenaar2b946c92016-11-12 18:14:44 +0100413func Test_cbuffer()
Bram Moolenaarda59dd52016-01-05 21:59:58 +0100414 call XbufferTests('c')
415 call XbufferTests('l')
Bram Moolenaar2b946c92016-11-12 18:14:44 +0100416endfunc
Bram Moolenaarda59dd52016-01-05 21:59:58 +0100417
Bram Moolenaar2b946c92016-11-12 18:14:44 +0100418func XexprTests(cchar)
Bram Moolenaar0fcc7c62016-07-02 21:22:52 +0200419 call s:setup_commands(a:cchar)
420
421 call assert_fails('Xexpr 10', 'E777:')
Bram Moolenaar2b946c92016-11-12 18:14:44 +0100422endfunc
Bram Moolenaar0fcc7c62016-07-02 21:22:52 +0200423
Bram Moolenaar2b946c92016-11-12 18:14:44 +0100424func Test_cexpr()
Bram Moolenaar0fcc7c62016-07-02 21:22:52 +0200425 call XexprTests('c')
426 call XexprTests('l')
Bram Moolenaar2b946c92016-11-12 18:14:44 +0100427endfunc
Bram Moolenaar0fcc7c62016-07-02 21:22:52 +0200428
429" Tests for :cnext, :cprev, :cfirst, :clast commands
Bram Moolenaar2b946c92016-11-12 18:14:44 +0100430func Xtest_browse(cchar)
Bram Moolenaar0fcc7c62016-07-02 21:22:52 +0200431 call s:setup_commands(a:cchar)
432
Bram Moolenaar74240d32017-12-10 15:26:15 +0100433 call g:Xsetlist([], 'f')
Bram Moolenaarb6fa30c2017-03-29 14:19:25 +0200434 " Jumping to first or next location list entry without any error should
435 " result in failure
Bram Moolenaar74240d32017-12-10 15:26:15 +0100436 if a:cchar == 'c'
437 let err = 'E42:'
438 else
439 let err = 'E776:'
Bram Moolenaarb6fa30c2017-03-29 14:19:25 +0200440 endif
Bram Moolenaar74240d32017-12-10 15:26:15 +0100441 call assert_fails('Xnext', err)
442 call assert_fails('Xprev', err)
443 call assert_fails('Xnfile', err)
444 call assert_fails('Xpfile', err)
Bram Moolenaarb6fa30c2017-03-29 14:19:25 +0200445
Bram Moolenaar0fcc7c62016-07-02 21:22:52 +0200446 call s:create_test_file('Xqftestfile1')
447 call s:create_test_file('Xqftestfile2')
448
449 Xgetexpr ['Xqftestfile1:5:Line5',
450 \ 'Xqftestfile1:6:Line6',
451 \ 'Xqftestfile2:10:Line10',
Bram Moolenaar99895ea2017-04-20 22:44:47 +0200452 \ 'Xqftestfile2:11:Line11',
453 \ 'RegularLine1',
454 \ 'RegularLine2']
Bram Moolenaar0fcc7c62016-07-02 21:22:52 +0200455
456 Xfirst
457 call assert_fails('Xprev', 'E553')
458 call assert_fails('Xpfile', 'E553')
459 Xnfile
460 call assert_equal('Xqftestfile2', bufname('%'))
461 call assert_equal(10, line('.'))
462 Xpfile
463 call assert_equal('Xqftestfile1', bufname('%'))
464 call assert_equal(6, line('.'))
Bram Moolenaar74240d32017-12-10 15:26:15 +0100465 5Xcc
466 call assert_equal(5, g:Xgetlist({'idx':0}).idx)
467 2Xcc
468 call assert_equal(2, g:Xgetlist({'idx':0}).idx)
469 10Xcc
470 call assert_equal(6, g:Xgetlist({'idx':0}).idx)
Bram Moolenaar0fcc7c62016-07-02 21:22:52 +0200471 Xlast
Bram Moolenaar99895ea2017-04-20 22:44:47 +0200472 Xprev
Bram Moolenaar0fcc7c62016-07-02 21:22:52 +0200473 call assert_equal('Xqftestfile2', bufname('%'))
474 call assert_equal(11, line('.'))
475 call assert_fails('Xnext', 'E553')
476 call assert_fails('Xnfile', 'E553')
477 Xrewind
478 call assert_equal('Xqftestfile1', bufname('%'))
479 call assert_equal(5, line('.'))
480
Bram Moolenaar99895ea2017-04-20 22:44:47 +0200481 10Xnext
482 call assert_equal('Xqftestfile2', bufname('%'))
483 call assert_equal(11, line('.'))
484 10Xprev
485 call assert_equal('Xqftestfile1', bufname('%'))
486 call assert_equal(5, line('.'))
487
Bram Moolenaar74240d32017-12-10 15:26:15 +0100488 " Jumping to an error from the error window using cc command
489 Xgetexpr ['Xqftestfile1:5:Line5',
490 \ 'Xqftestfile1:6:Line6',
491 \ 'Xqftestfile2:10:Line10',
492 \ 'Xqftestfile2:11:Line11']
493 Xopen
494 10Xcc
495 call assert_equal(11, line('.'))
496 call assert_equal('Xqftestfile2', bufname('%'))
497
498 " Jumping to an error from the error window (when only the error window is
499 " present)
500 Xopen | only
501 Xlast 1
502 call assert_equal(5, line('.'))
503 call assert_equal('Xqftestfile1', bufname('%'))
504
Bram Moolenaaree85df32017-03-19 14:19:50 +0100505 Xexpr ""
506 call assert_fails('Xnext', 'E42:')
507
Bram Moolenaar0fcc7c62016-07-02 21:22:52 +0200508 call delete('Xqftestfile1')
509 call delete('Xqftestfile2')
Bram Moolenaarfc2b2702017-09-15 22:43:07 +0200510
511 " Should be able to use next/prev with invalid entries
512 Xexpr ""
513 call assert_equal(0, g:Xgetlist({'idx' : 0}).idx)
514 call assert_equal(0, g:Xgetlist({'size' : 0}).size)
515 Xaddexpr ['foo', 'bar', 'baz', 'quux', 'shmoo']
516 call assert_equal(5, g:Xgetlist({'size' : 0}).size)
517 Xlast
518 call assert_equal(5, g:Xgetlist({'idx' : 0}).idx)
519 Xfirst
520 call assert_equal(1, g:Xgetlist({'idx' : 0}).idx)
521 2Xnext
522 call assert_equal(3, g:Xgetlist({'idx' : 0}).idx)
Bram Moolenaar2b946c92016-11-12 18:14:44 +0100523endfunc
Bram Moolenaar0fcc7c62016-07-02 21:22:52 +0200524
Bram Moolenaar2b946c92016-11-12 18:14:44 +0100525func Test_browse()
Bram Moolenaar0fcc7c62016-07-02 21:22:52 +0200526 call Xtest_browse('c')
527 call Xtest_browse('l')
Bram Moolenaar2b946c92016-11-12 18:14:44 +0100528endfunc
Bram Moolenaar0fcc7c62016-07-02 21:22:52 +0200529
Bram Moolenaar2b946c92016-11-12 18:14:44 +0100530func Test_nomem()
Bram Moolenaar8e8df252016-05-25 21:23:21 +0200531 call test_alloc_fail(GetAllocId('qf_dirname_start'), 0, 0)
Bram Moolenaara260b872016-01-15 20:48:22 +0100532 call assert_fails('vimgrep vim runtest.vim', 'E342:')
Bram Moolenaar75bdf6a2016-01-07 21:25:08 +0100533
Bram Moolenaarce90e362019-09-08 18:58:44 +0200534 call GetAllocId('qf_dirname_now')->test_alloc_fail(0, 0)
Bram Moolenaara260b872016-01-15 20:48:22 +0100535 call assert_fails('vimgrep vim runtest.vim', 'E342:')
Bram Moolenaar75bdf6a2016-01-07 21:25:08 +0100536
Bram Moolenaar8e8df252016-05-25 21:23:21 +0200537 call test_alloc_fail(GetAllocId('qf_namebuf'), 0, 0)
Bram Moolenaara260b872016-01-15 20:48:22 +0100538 call assert_fails('cfile runtest.vim', 'E342:')
Bram Moolenaar75bdf6a2016-01-07 21:25:08 +0100539
Bram Moolenaar8e8df252016-05-25 21:23:21 +0200540 call test_alloc_fail(GetAllocId('qf_errmsg'), 0, 0)
Bram Moolenaara260b872016-01-15 20:48:22 +0100541 call assert_fails('cfile runtest.vim', 'E342:')
Bram Moolenaar75bdf6a2016-01-07 21:25:08 +0100542
Bram Moolenaar8e8df252016-05-25 21:23:21 +0200543 call test_alloc_fail(GetAllocId('qf_pattern'), 0, 0)
Bram Moolenaara260b872016-01-15 20:48:22 +0100544 call assert_fails('cfile runtest.vim', 'E342:')
Bram Moolenaar75bdf6a2016-01-07 21:25:08 +0100545
546endfunc
547
Bram Moolenaar2b946c92016-11-12 18:14:44 +0100548func s:test_xhelpgrep(cchar)
Bram Moolenaar049cba92016-06-26 14:38:04 +0200549 call s:setup_commands(a:cchar)
550 Xhelpgrep quickfix
551 Xopen
552 if a:cchar == 'c'
553 let title_text = ':helpgrep quickfix'
554 else
555 let title_text = ':lhelpgrep quickfix'
556 endif
557 call assert_true(w:quickfix_title =~ title_text, w:quickfix_title)
Bram Moolenaar99895ea2017-04-20 22:44:47 +0200558
559 " Jumping to a help topic should open the help window
560 only
561 Xnext
562 call assert_true(&buftype == 'help')
563 call assert_true(winnr('$') == 2)
564 " Jumping to the next match should reuse the help window
565 Xnext
566 call assert_true(&buftype == 'help')
567 call assert_true(winnr() == 1)
568 call assert_true(winnr('$') == 2)
569 " Jumping to the next match from the quickfix window should reuse the help
570 " window
571 Xopen
572 Xnext
573 call assert_true(&buftype == 'help')
574 call assert_true(winnr() == 1)
575 call assert_true(winnr('$') == 2)
576
Bram Moolenaar62ef7972016-01-19 14:51:54 +0100577 " This wipes out the buffer, make sure that doesn't cause trouble.
Bram Moolenaar049cba92016-06-26 14:38:04 +0200578 Xclose
Bram Moolenaaree85df32017-03-19 14:19:50 +0100579
Bram Moolenaarb4d5fba2017-09-11 19:31:28 +0200580 if a:cchar == 'l'
581 " When a help window is present, running :lhelpgrep should reuse the
582 " help window and not the current window
583 new | only
584 call g:Xsetlist([], 'f')
585 help index.txt
586 wincmd w
587 lhelpgrep quickfix
588 call assert_equal(1, winnr())
589 call assert_notequal([], getloclist(1))
590 call assert_equal([], getloclist(2))
591 endif
592
Bram Moolenaar99895ea2017-04-20 22:44:47 +0200593 new | only
594
Bram Moolenaaree85df32017-03-19 14:19:50 +0100595 " Search for non existing help string
596 call assert_fails('Xhelpgrep a1b2c3', 'E480:')
Bram Moolenaar108e7b42018-10-11 17:39:12 +0200597 " Invalid regular expression
598 call assert_fails('Xhelpgrep \@<!', 'E480:')
Bram Moolenaar2b946c92016-11-12 18:14:44 +0100599endfunc
Bram Moolenaar049cba92016-06-26 14:38:04 +0200600
Bram Moolenaar2b946c92016-11-12 18:14:44 +0100601func Test_helpgrep()
Bram Moolenaar049cba92016-06-26 14:38:04 +0200602 call s:test_xhelpgrep('c')
Bram Moolenaarcf25fdb2016-08-03 21:04:53 +0200603 helpclose
Bram Moolenaar049cba92016-06-26 14:38:04 +0200604 call s:test_xhelpgrep('l')
Bram Moolenaar62ef7972016-01-19 14:51:54 +0100605endfunc
Bram Moolenaar75bdf6a2016-01-07 21:25:08 +0100606
Bram Moolenaar6920c722016-01-22 22:44:10 +0100607func Test_errortitle()
608 augroup QfBufWinEnter
609 au!
610 au BufWinEnter * :let g:a=get(w:, 'quickfix_title', 'NONE')
611 augroup END
612 copen
613 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'')'}]
614 call setqflist(a)
615 call assert_equal(':setqflist()', g:a)
616 augroup QfBufWinEnter
617 au!
618 augroup END
619 augroup! QfBufWinEnter
620endfunc
Bram Moolenaare27dba42016-03-15 14:11:10 +0100621
Bram Moolenaar5584df62016-03-18 21:00:51 +0100622func Test_vimgreptitle()
623 augroup QfBufWinEnter
624 au!
625 au BufWinEnter * :let g:a=get(w:, 'quickfix_title', 'NONE')
626 augroup END
627 try
628 vimgrep /pattern/j file
629 catch /E480/
630 endtry
631 copen
632 call assert_equal(': vimgrep /pattern/j file', g:a)
633 augroup QfBufWinEnter
634 au!
635 augroup END
636 augroup! QfBufWinEnter
637endfunc
638
Bram Moolenaar2b946c92016-11-12 18:14:44 +0100639func XqfTitleTests(cchar)
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +0200640 call s:setup_commands(a:cchar)
Bram Moolenaare27dba42016-03-15 14:11:10 +0100641
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +0200642 Xgetexpr ['file:1:1:message']
643 let l = g:Xgetlist()
Bram Moolenaare27dba42016-03-15 14:11:10 +0100644 if a:cchar == 'c'
645 call setqflist(l, 'r')
646 else
647 call setloclist(0, l, 'r')
648 endif
649
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +0200650 Xopen
Bram Moolenaare27dba42016-03-15 14:11:10 +0100651 if a:cchar == 'c'
652 let title = ':setqflist()'
653 else
654 let title = ':setloclist()'
655 endif
656 call assert_equal(title, w:quickfix_title)
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +0200657 Xclose
Bram Moolenaar2b946c92016-11-12 18:14:44 +0100658endfunc
Bram Moolenaare27dba42016-03-15 14:11:10 +0100659
660" Tests for quickfix window's title
Bram Moolenaar2b946c92016-11-12 18:14:44 +0100661func Test_qf_title()
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +0200662 call XqfTitleTests('c')
663 call XqfTitleTests('l')
Bram Moolenaar2b946c92016-11-12 18:14:44 +0100664endfunc
Bram Moolenaare27dba42016-03-15 14:11:10 +0100665
666" Tests for 'errorformat'
Bram Moolenaar2b946c92016-11-12 18:14:44 +0100667func Test_efm()
Bram Moolenaare27dba42016-03-15 14:11:10 +0100668 let save_efm = &efm
669 set efm=%EEEE%m,%WWWW%m,%+CCCC%.%#,%-GGGG%.%#
670 cgetexpr ['WWWW', 'EEEE', 'CCCC']
671 let l = strtrans(string(map(getqflist(), '[v:val.text, v:val.valid]')))
672 call assert_equal("[['W', 1], ['E^@CCCC', 1]]", l)
673 cgetexpr ['WWWW', 'GGGG', 'EEEE', 'CCCC']
674 let l = strtrans(string(map(getqflist(), '[v:val.text, v:val.valid]')))
675 call assert_equal("[['W', 1], ['E^@CCCC', 1]]", l)
676 cgetexpr ['WWWW', 'GGGG', 'ZZZZ', 'EEEE', 'CCCC', 'YYYY']
677 let l = strtrans(string(map(getqflist(), '[v:val.text, v:val.valid]')))
678 call assert_equal("[['W', 1], ['ZZZZ', 0], ['E^@CCCC', 1], ['YYYY', 0]]", l)
679 let &efm = save_efm
Bram Moolenaar2b946c92016-11-12 18:14:44 +0100680endfunc
Bram Moolenaar1ff2b642016-03-17 22:07:02 +0100681
682" This will test for problems in quickfix:
683" A. incorrectly copying location lists which caused the location list to show
684" a different name than the file that was actually being displayed.
685" B. not reusing the window for which the location list window is opened but
686" instead creating new windows.
687" C. make sure that the location list window is not reused instead of the
688" window it belongs to.
689"
690" Set up the test environment:
Bram Moolenaar2b946c92016-11-12 18:14:44 +0100691func ReadTestProtocol(name)
Bram Moolenaar1ff2b642016-03-17 22:07:02 +0100692 let base = substitute(a:name, '\v^test://(.*)%(\.[^.]+)?', '\1', '')
693 let word = substitute(base, '\v(.*)\..*', '\1', '')
694
695 setl modifiable
696 setl noreadonly
697 setl noswapfile
698 setl bufhidden=delete
699 %del _
700 " For problem 2:
701 " 'buftype' has to be set to reproduce the constant opening of new windows
702 setl buftype=nofile
703
704 call setline(1, word)
705
706 setl nomodified
707 setl nomodifiable
708 setl readonly
709 exe 'doautocmd BufRead ' . substitute(a:name, '\v^test://(.*)', '\1', '')
Bram Moolenaar2b946c92016-11-12 18:14:44 +0100710endfunc
Bram Moolenaar1ff2b642016-03-17 22:07:02 +0100711
Bram Moolenaar2b946c92016-11-12 18:14:44 +0100712func Test_locationlist()
Bram Moolenaar1ff2b642016-03-17 22:07:02 +0100713 enew
714
715 augroup testgroup
716 au!
717 autocmd BufReadCmd test://* call ReadTestProtocol(expand("<amatch>"))
718 augroup END
719
720 let words = [ "foo", "bar", "baz", "quux", "shmoo", "spam", "eggs" ]
721
722 let qflist = []
723 for word in words
724 call add(qflist, {'filename': 'test://' . word . '.txt', 'text': 'file ' . word . '.txt', })
725 " NOTE: problem 1:
726 " intentionally not setting 'lnum' so that the quickfix entries are not
727 " valid
Bram Moolenaaraad222c2019-09-06 22:46:09 +0200728 eval qflist->setloclist(0, ' ')
Bram Moolenaar1ff2b642016-03-17 22:07:02 +0100729 endfor
730
731 " Test A
732 lrewind
733 enew
734 lopen
Bram Moolenaar99895ea2017-04-20 22:44:47 +0200735 4lnext
Bram Moolenaar1ff2b642016-03-17 22:07:02 +0100736 vert split
737 wincmd L
738 lopen
739 wincmd p
740 lnext
741 let fileName = expand("%")
742 wincmd p
743 let locationListFileName = substitute(getline(line('.')), '\([^|]*\)|.*', '\1', '')
744 let fileName = substitute(fileName, '\\', '/', 'g')
745 let locationListFileName = substitute(locationListFileName, '\\', '/', 'g')
746 call assert_equal("test://bar.txt", fileName)
747 call assert_equal("test://bar.txt", locationListFileName)
748
749 wincmd n | only
750
751 " Test B:
752 lrewind
753 lopen
754 2
755 exe "normal \<CR>"
756 wincmd p
757 3
758 exe "normal \<CR>"
759 wincmd p
760 4
761 exe "normal \<CR>"
762 call assert_equal(2, winnr('$'))
763 wincmd n | only
764
765 " Test C:
766 lrewind
767 lopen
768 " Let's move the location list window to the top to check whether it (the
769 " first window found) will be reused when we try to open new windows:
770 wincmd K
771 2
772 exe "normal \<CR>"
773 wincmd p
774 3
775 exe "normal \<CR>"
776 wincmd p
777 4
778 exe "normal \<CR>"
779 1wincmd w
780 call assert_equal('quickfix', &buftype)
781 2wincmd w
782 let bufferName = expand("%")
783 let bufferName = substitute(bufferName, '\\', '/', 'g')
784 call assert_equal('test://quux.txt', bufferName)
785
786 wincmd n | only
787
788 augroup! testgroup
Bram Moolenaaree85df32017-03-19 14:19:50 +0100789endfunc
Bram Moolenaar0899d692016-03-19 13:35:03 +0100790
Bram Moolenaar2b946c92016-11-12 18:14:44 +0100791func Test_locationlist_curwin_was_closed()
Bram Moolenaar0899d692016-03-19 13:35:03 +0100792 augroup testgroup
793 au!
Bram Moolenaard106e5b2016-04-21 19:38:07 +0200794 autocmd BufReadCmd test_curwin.txt call R(expand("<amatch>"))
Bram Moolenaar0899d692016-03-19 13:35:03 +0100795 augroup END
796
Bram Moolenaar2b946c92016-11-12 18:14:44 +0100797 func! R(n)
Bram Moolenaar0899d692016-03-19 13:35:03 +0100798 quit
799 endfunc
800
801 new
802 let q = []
Bram Moolenaard106e5b2016-04-21 19:38:07 +0200803 call add(q, {'filename': 'test_curwin.txt' })
Bram Moolenaar0899d692016-03-19 13:35:03 +0100804 call setloclist(0, q)
805 call assert_fails('lrewind', 'E924:')
806
807 augroup! testgroup
Bram Moolenaaree85df32017-03-19 14:19:50 +0100808endfunc
Bram Moolenaar7eba3d22016-03-19 22:54:09 +0100809
Bram Moolenaar2b946c92016-11-12 18:14:44 +0100810func Test_locationlist_cross_tab_jump()
Bram Moolenaar0a9046f2016-10-15 19:28:13 +0200811 call writefile(['loclistfoo'], 'loclistfoo')
812 call writefile(['loclistbar'], 'loclistbar')
813 set switchbuf=usetab
814
815 edit loclistfoo
816 tabedit loclistbar
817 silent lgrep loclistfoo loclist*
818 call assert_equal(1, tabpagenr())
819
820 enew | only | tabonly
821 set switchbuf&vim
822 call delete('loclistfoo')
823 call delete('loclistbar')
Bram Moolenaar2b946c92016-11-12 18:14:44 +0100824endfunc
Bram Moolenaar0a9046f2016-10-15 19:28:13 +0200825
Bram Moolenaar7eba3d22016-03-19 22:54:09 +0100826" More tests for 'errorformat'
Bram Moolenaar2b946c92016-11-12 18:14:44 +0100827func Test_efm1()
Bram Moolenaar7eba3d22016-03-19 22:54:09 +0100828 if !has('unix')
829 " The 'errorformat' setting is different on non-Unix systems.
830 " This test works only on Unix-like systems.
831 return
832 endif
833
Bram Moolenaarc79745a2019-05-20 22:12:34 +0200834 let l =<< trim [DATA]
Bram Moolenaare7eb9272019-06-24 00:58:07 +0200835 "Xtestfile", line 4.12: 1506-045 (S) Undeclared identifier fd_set.
836 "Xtestfile", line 6 col 19; this is an error
837 gcc -c -DHAVE_CONFIsing-prototypes -I/usr/X11R6/include version.c
838 Xtestfile:9: parse error before `asd'
839 make: *** [vim] Error 1
840 in file "Xtestfile" linenr 10: there is an error
841
842 2 returned
843 "Xtestfile", line 11 col 1; this is an error
844 "Xtestfile", line 12 col 2; this is another error
845 "Xtestfile", line 14:10; this is an error in column 10
846 =Xtestfile=, line 15:10; this is another error, but in vcol 10 this time
847 "Xtestfile", linenr 16: yet another problem
848 Error in "Xtestfile" at line 17:
849 x should be a dot
850 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 17
851 ^
852 Error in "Xtestfile" at line 18:
853 x should be a dot
854 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 18
855 .............^
856 Error in "Xtestfile" at line 19:
857 x should be a dot
858 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 19
859 --------------^
860 Error in "Xtestfile" at line 20:
861 x should be a dot
862 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 20
863 ^
864
865 Does anyone know what is the problem and how to correction it?
866 "Xtestfile", line 21 col 9: What is the title of the quickfix window?
867 "Xtestfile", line 22 col 9: What is the title of the quickfix window?
Bram Moolenaarc79745a2019-05-20 22:12:34 +0200868 [DATA]
Bram Moolenaar7eba3d22016-03-19 22:54:09 +0100869
870 call writefile(l, 'Xerrorfile1')
871 call writefile(l[:-2], 'Xerrorfile2')
872
Bram Moolenaare7eb9272019-06-24 00:58:07 +0200873 let m =<< [DATA]
874 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 2
875 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 3
876 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 4
877 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 5
878 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 6
879 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 7
880 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 8
881 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 9
882 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 10
883 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 11
884 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 12
885 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 13
886 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 14
887 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 15
888 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 16
889 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 17
890 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 18
891 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 19
892 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 20
893 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 21
894 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 22
895[DATA]
Bram Moolenaar7eba3d22016-03-19 22:54:09 +0100896 call writefile(m, 'Xtestfile')
897
898 let save_efm = &efm
899 set efm+==%f=\\,\ line\ %l%*\\D%v%*[^\ ]\ %m
900 set efm^=%AError\ in\ \"%f\"\ at\ line\ %l:,%Z%p^,%C%m
901
902 exe 'cf Xerrorfile2'
903 clast
904 copen
905 call assert_equal(':cf Xerrorfile2', w:quickfix_title)
906 wincmd p
907
908 exe 'cf Xerrorfile1'
909 call assert_equal([4, 12], [line('.'), col('.')])
910 cn
911 call assert_equal([6, 19], [line('.'), col('.')])
912 cn
913 call assert_equal([9, 2], [line('.'), col('.')])
914 cn
915 call assert_equal([10, 2], [line('.'), col('.')])
916 cn
917 call assert_equal([11, 1], [line('.'), col('.')])
918 cn
919 call assert_equal([12, 2], [line('.'), col('.')])
920 cn
921 call assert_equal([14, 10], [line('.'), col('.')])
922 cn
923 call assert_equal([15, 3, 10], [line('.'), col('.'), virtcol('.')])
924 cn
925 call assert_equal([16, 2], [line('.'), col('.')])
926 cn
927 call assert_equal([17, 6], [line('.'), col('.')])
928 cn
929 call assert_equal([18, 7], [line('.'), col('.')])
930 cn
931 call assert_equal([19, 8], [line('.'), col('.')])
932 cn
933 call assert_equal([20, 9], [line('.'), col('.')])
934 clast
935 cprev
936 cprev
937 wincmd w
938 call assert_equal(':cf Xerrorfile1', w:quickfix_title)
939 wincmd p
940
941 let &efm = save_efm
942 call delete('Xerrorfile1')
943 call delete('Xerrorfile2')
944 call delete('Xtestfile')
Bram Moolenaaree85df32017-03-19 14:19:50 +0100945endfunc
Bram Moolenaarffec3c52016-03-23 20:55:42 +0100946
Bram Moolenaarab47c612016-06-14 22:02:26 +0200947" Test for quickfix directory stack support
Bram Moolenaar2b946c92016-11-12 18:14:44 +0100948func s:dir_stack_tests(cchar)
Bram Moolenaar38df43b2016-06-20 21:41:12 +0200949 call s:setup_commands(a:cchar)
950
Bram Moolenaarab47c612016-06-14 22:02:26 +0200951 let save_efm=&efm
952 set efm=%DEntering\ dir\ '%f',%f:%l:%m,%XLeaving\ dir\ '%f'
953
Bram Moolenaar361c8f02016-07-02 15:41:47 +0200954 let lines = ["Entering dir 'dir1/a'",
955 \ 'habits2.txt:1:Nine Healthy Habits',
956 \ "Entering dir 'b'",
957 \ 'habits3.txt:2:0 Hours of television',
958 \ 'habits2.txt:7:5 Small meals',
959 \ "Entering dir 'dir1/c'",
960 \ 'habits4.txt:3:1 Hour of exercise',
961 \ "Leaving dir 'dir1/c'",
962 \ "Leaving dir 'dir1/a'",
963 \ 'habits1.txt:4:2 Liters of water',
964 \ "Entering dir 'dir2'",
965 \ 'habits5.txt:5:3 Cups of hot green tea',
966 \ "Leaving dir 'dir2'"
967 \]
Bram Moolenaarab47c612016-06-14 22:02:26 +0200968
Bram Moolenaar361c8f02016-07-02 15:41:47 +0200969 Xexpr ""
970 for l in lines
971 Xaddexpr l
972 endfor
Bram Moolenaarab47c612016-06-14 22:02:26 +0200973
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +0200974 let qf = g:Xgetlist()
Bram Moolenaarab47c612016-06-14 22:02:26 +0200975
976 call assert_equal('dir1/a/habits2.txt', bufname(qf[1].bufnr))
977 call assert_equal(1, qf[1].lnum)
978 call assert_equal('dir1/a/b/habits3.txt', bufname(qf[3].bufnr))
979 call assert_equal(2, qf[3].lnum)
980 call assert_equal('dir1/a/habits2.txt', bufname(qf[4].bufnr))
981 call assert_equal(7, qf[4].lnum)
982 call assert_equal('dir1/c/habits4.txt', bufname(qf[6].bufnr))
983 call assert_equal(3, qf[6].lnum)
984 call assert_equal('habits1.txt', bufname(qf[9].bufnr))
985 call assert_equal(4, qf[9].lnum)
986 call assert_equal('dir2/habits5.txt', bufname(qf[11].bufnr))
987 call assert_equal(5, qf[11].lnum)
988
989 let &efm=save_efm
Bram Moolenaar2b946c92016-11-12 18:14:44 +0100990endfunc
Bram Moolenaarab47c612016-06-14 22:02:26 +0200991
992" Tests for %D and %X errorformat options
Bram Moolenaar2b946c92016-11-12 18:14:44 +0100993func Test_efm_dirstack()
Bram Moolenaarab47c612016-06-14 22:02:26 +0200994 " Create the directory stack and files
995 call mkdir('dir1')
996 call mkdir('dir1/a')
997 call mkdir('dir1/a/b')
998 call mkdir('dir1/c')
999 call mkdir('dir2')
1000
1001 let lines = ["Nine Healthy Habits",
1002 \ "0 Hours of television",
1003 \ "1 Hour of exercise",
1004 \ "2 Liters of water",
1005 \ "3 Cups of hot green tea",
1006 \ "4 Short mental breaks",
1007 \ "5 Small meals",
1008 \ "6 AM wake up time",
1009 \ "7 Minutes of laughter",
1010 \ "8 Hours of sleep (at least)",
1011 \ "9 PM end of the day and off to bed"
1012 \ ]
1013 call writefile(lines, 'habits1.txt')
1014 call writefile(lines, 'dir1/a/habits2.txt')
1015 call writefile(lines, 'dir1/a/b/habits3.txt')
1016 call writefile(lines, 'dir1/c/habits4.txt')
1017 call writefile(lines, 'dir2/habits5.txt')
1018
1019 call s:dir_stack_tests('c')
1020 call s:dir_stack_tests('l')
1021
1022 call delete('dir1', 'rf')
1023 call delete('dir2', 'rf')
1024 call delete('habits1.txt')
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001025endfunc
Bram Moolenaarab47c612016-06-14 22:02:26 +02001026
Bram Moolenaar9b457942016-10-09 16:10:05 +02001027" Test for resync after continuing an ignored message
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001028func Xefm_ignore_continuations(cchar)
Bram Moolenaar9b457942016-10-09 16:10:05 +02001029 call s:setup_commands(a:cchar)
1030
1031 let save_efm = &efm
1032
1033 let &efm =
1034 \ '%Eerror %m %l,' .
1035 \ '%-Wignored %m %l,' .
1036 \ '%+Cmore ignored %m %l,' .
1037 \ '%Zignored end'
1038 Xgetexpr ['ignored warning 1', 'more ignored continuation 2', 'ignored end', 'error resync 4']
1039 let l = map(g:Xgetlist(), '[v:val.text, v:val.valid, v:val.lnum, v:val.type]')
1040 call assert_equal([['resync', 1, 4, 'E']], l)
1041
1042 let &efm = save_efm
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001043endfunc
Bram Moolenaar9b457942016-10-09 16:10:05 +02001044
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001045func Test_efm_ignore_continuations()
Bram Moolenaar9b457942016-10-09 16:10:05 +02001046 call Xefm_ignore_continuations('c')
1047 call Xefm_ignore_continuations('l')
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001048endfunc
Bram Moolenaar9b457942016-10-09 16:10:05 +02001049
Bram Moolenaar0fcc7c62016-07-02 21:22:52 +02001050" Tests for invalid error format specifies
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001051func Xinvalid_efm_Tests(cchar)
Bram Moolenaar0fcc7c62016-07-02 21:22:52 +02001052 call s:setup_commands(a:cchar)
1053
Bram Moolenaar049cba92016-06-26 14:38:04 +02001054 let save_efm = &efm
1055
Bram Moolenaar0fcc7c62016-07-02 21:22:52 +02001056 set efm=%f:%l:%m,%f:%f:%l:%m
1057 call assert_fails('Xexpr "abc.txt:1:Hello world"', 'E372:')
1058
1059 set efm=%f:%l:%m,%f:%l:%r:%m
1060 call assert_fails('Xexpr "abc.txt:1:Hello world"', 'E373:')
1061
1062 set efm=%f:%l:%m,%O:%f:%l:%m
1063 call assert_fails('Xexpr "abc.txt:1:Hello world"', 'E373:')
1064
1065 set efm=%f:%l:%m,%f:%l:%*[^a-z
1066 call assert_fails('Xexpr "abc.txt:1:Hello world"', 'E374:')
1067
1068 set efm=%f:%l:%m,%f:%l:%*c
1069 call assert_fails('Xexpr "abc.txt:1:Hello world"', 'E375:')
1070
1071 set efm=%f:%l:%m,%L%M%N
1072 call assert_fails('Xexpr "abc.txt:1:Hello world"', 'E376:')
1073
1074 set efm=%f:%l:%m,%f:%l:%m:%R
1075 call assert_fails('Xexpr "abc.txt:1:Hello world"', 'E377:')
1076
1077 set efm=
1078 call assert_fails('Xexpr "abc.txt:1:Hello world"', 'E378:')
1079
1080 set efm=%DEntering\ dir\ abc,%f:%l:%m
1081 call assert_fails('Xexpr ["Entering dir abc", "abc.txt:1:Hello world"]', 'E379:')
1082
1083 let &efm = save_efm
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001084endfunc
Bram Moolenaar0fcc7c62016-07-02 21:22:52 +02001085
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001086func Test_invalid_efm()
Bram Moolenaar0fcc7c62016-07-02 21:22:52 +02001087 call Xinvalid_efm_Tests('c')
1088 call Xinvalid_efm_Tests('l')
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001089endfunc
Bram Moolenaar0fcc7c62016-07-02 21:22:52 +02001090
1091" TODO:
1092" Add tests for the following formats in 'errorformat'
1093" %r %O
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001094func Test_efm2()
Bram Moolenaar0fcc7c62016-07-02 21:22:52 +02001095 let save_efm = &efm
Bram Moolenaar049cba92016-06-26 14:38:04 +02001096
1097 " Test for %s format in efm
1098 set efm=%f:%s
1099 cexpr 'Xtestfile:Line search text'
Bram Moolenaar049cba92016-06-26 14:38:04 +02001100 let l = getqflist()
1101 call assert_equal(l[0].pattern, '^\VLine search text\$')
1102 call assert_equal(l[0].lnum, 0)
1103
Bram Moolenaaree85df32017-03-19 14:19:50 +01001104 let l = split(execute('clist', ''), "\n")
1105 call assert_equal([' 1 Xtestfile:^\VLine search text\$: '], l)
1106
Bram Moolenaar0fcc7c62016-07-02 21:22:52 +02001107 " Test for %P, %Q and %t format specifiers
Bram Moolenaarc79745a2019-05-20 22:12:34 +02001108 let lines =<< trim [DATA]
Bram Moolenaare7eb9272019-06-24 00:58:07 +02001109 [Xtestfile1]
1110 (1,17) error: ';' missing
1111 (21,2) warning: variable 'z' not defined
1112 (67,3) error: end of file found before string ended
1113 --
Bram Moolenaarc79745a2019-05-20 22:12:34 +02001114
Bram Moolenaare7eb9272019-06-24 00:58:07 +02001115 [Xtestfile2]
1116 --
Bram Moolenaarc79745a2019-05-20 22:12:34 +02001117
Bram Moolenaare7eb9272019-06-24 00:58:07 +02001118 [Xtestfile3]
1119 NEW compiler v1.1
1120 (2,2) warning: variable 'x' not defined
1121 (67,3) warning: 's' already defined
1122 --
Bram Moolenaarc79745a2019-05-20 22:12:34 +02001123 [DATA]
1124
Bram Moolenaaree85df32017-03-19 14:19:50 +01001125 set efm=%+P[%f]%r,(%l\\,%c)%*[\ ]%t%*[^:]:\ %m,%+Q--%r
Bram Moolenaar391b1dd2017-03-04 13:47:11 +01001126 " To exercise the push/pop file functionality in quickfix, the test files
1127 " need to be created.
1128 call writefile(['Line1'], 'Xtestfile1')
1129 call writefile(['Line2'], 'Xtestfile2')
1130 call writefile(['Line3'], 'Xtestfile3')
Bram Moolenaar361c8f02016-07-02 15:41:47 +02001131 cexpr ""
1132 for l in lines
1133 caddexpr l
1134 endfor
Bram Moolenaar049cba92016-06-26 14:38:04 +02001135 let l = getqflist()
Bram Moolenaaree85df32017-03-19 14:19:50 +01001136 call assert_equal(12, len(l))
Bram Moolenaar049cba92016-06-26 14:38:04 +02001137 call assert_equal(21, l[2].lnum)
1138 call assert_equal(2, l[2].col)
Bram Moolenaar0fcc7c62016-07-02 21:22:52 +02001139 call assert_equal('w', l[2].type)
1140 call assert_equal('e', l[3].type)
Bram Moolenaar391b1dd2017-03-04 13:47:11 +01001141 call delete('Xtestfile1')
1142 call delete('Xtestfile2')
1143 call delete('Xtestfile3')
Bram Moolenaar0fcc7c62016-07-02 21:22:52 +02001144
1145 " Tests for %E, %C and %Z format specifiers
Bram Moolenaarc79745a2019-05-20 22:12:34 +02001146 let lines =<< trim [DATA]
Bram Moolenaare7eb9272019-06-24 00:58:07 +02001147 Error 275
1148 line 42
1149 column 3
1150 ' ' expected after '--'
Bram Moolenaarc79745a2019-05-20 22:12:34 +02001151 [DATA]
1152
Bram Moolenaar0fcc7c62016-07-02 21:22:52 +02001153 set efm=%EError\ %n,%Cline\ %l,%Ccolumn\ %c,%Z%m
1154 cgetexpr lines
1155 let l = getqflist()
1156 call assert_equal(275, l[0].nr)
1157 call assert_equal(42, l[0].lnum)
1158 call assert_equal(3, l[0].col)
1159 call assert_equal('E', l[0].type)
1160 call assert_equal("\n' ' expected after '--'", l[0].text)
1161
1162 " Test for %>
Bram Moolenaarc79745a2019-05-20 22:12:34 +02001163 let lines =<< trim [DATA]
Bram Moolenaare7eb9272019-06-24 00:58:07 +02001164 Error in line 147 of foo.c:
1165 unknown variable 'i'
Bram Moolenaarc79745a2019-05-20 22:12:34 +02001166 [DATA]
1167
Bram Moolenaar0fcc7c62016-07-02 21:22:52 +02001168 set efm=unknown\ variable\ %m,%E%>Error\ in\ line\ %l\ of\ %f:,%Z%m
1169 cgetexpr lines
1170 let l = getqflist()
1171 call assert_equal(147, l[0].lnum)
1172 call assert_equal('E', l[0].type)
1173 call assert_equal("\nunknown variable 'i'", l[0].text)
Bram Moolenaar049cba92016-06-26 14:38:04 +02001174
Bram Moolenaare87e6dd2016-07-17 19:25:04 +02001175 " Test for %A, %C and other formats
Bram Moolenaarc79745a2019-05-20 22:12:34 +02001176 let lines =<< trim [DATA]
Bram Moolenaare7eb9272019-06-24 00:58:07 +02001177 ==============================================================
1178 FAIL: testGetTypeIdCachesResult (dbfacadeTest.DjsDBFacadeTest)
1179 --------------------------------------------------------------
1180 Traceback (most recent call last):
1181 File "unittests/dbfacadeTest.py", line 89, in testFoo
1182 self.assertEquals(34, dtid)
1183 File "/usr/lib/python2.2/unittest.py", line 286, in
1184 failUnlessEqual
1185 raise self.failureException, \\
1186 AssertionError: 34 != 33
1187
1188 --------------------------------------------------------------
1189 Ran 27 tests in 0.063s
Bram Moolenaarc79745a2019-05-20 22:12:34 +02001190 [DATA]
1191
Bram Moolenaare87e6dd2016-07-17 19:25:04 +02001192 set efm=%C\ %.%#,%A\ \ File\ \"%f\"\\,\ line\ %l%.%#,%Z%[%^\ ]%\\@=%m
1193 cgetexpr lines
1194 let l = getqflist()
1195 call assert_equal(8, len(l))
1196 call assert_equal(89, l[4].lnum)
1197 call assert_equal(1, l[4].valid)
1198 call assert_equal('unittests/dbfacadeTest.py', bufname(l[4].bufnr))
1199
Bram Moolenaard76ce852018-05-01 15:02:04 +02001200 " Test for %o
1201 set efm=%f(%o):%l\ %m
Bram Moolenaarbc7845d2018-05-01 16:26:48 +02001202 cgetexpr ['Xotestfile(Language.PureScript.Types):20 Error']
1203 call writefile(['Line1'], 'Xotestfile')
Bram Moolenaard76ce852018-05-01 15:02:04 +02001204 let l = getqflist()
1205 call assert_equal(1, len(l), string(l))
1206 call assert_equal('Language.PureScript.Types', l[0].module)
1207 copen
1208 call assert_equal('Language.PureScript.Types|20| Error', getline(1))
1209 call feedkeys("\<CR>", 'xn')
Bram Moolenaarbc7845d2018-05-01 16:26:48 +02001210 call assert_equal('Xotestfile', expand('%:t'))
Bram Moolenaard76ce852018-05-01 15:02:04 +02001211 cclose
1212 bd
Bram Moolenaarbc7845d2018-05-01 16:26:48 +02001213 call delete("Xotestfile")
Bram Moolenaard76ce852018-05-01 15:02:04 +02001214
Bram Moolenaar99895ea2017-04-20 22:44:47 +02001215 " The following sequence of commands used to crash Vim
1216 set efm=%W%m
1217 cgetexpr ['msg1']
1218 let l = getqflist()
1219 call assert_equal(1, len(l), string(l))
1220 call assert_equal('msg1', l[0].text)
1221 set efm=%C%m
1222 lexpr 'msg2'
1223 let l = getloclist(0)
1224 call assert_equal(1, len(l), string(l))
1225 call assert_equal('msg2', l[0].text)
1226 lopen
1227 call setqflist([], 'r')
1228 caddbuf
1229 let l = getqflist()
1230 call assert_equal(1, len(l), string(l))
1231 call assert_equal('|| msg2', l[0].text)
1232
Bram Moolenaar78ddc062018-05-15 21:56:34 +02001233 " When matching error lines, case should be ignored. Test for this.
1234 set noignorecase
1235 let l=getqflist({'lines' : ['Xtest:FOO10:Line 20'], 'efm':'%f:foo%l:%m'})
1236 call assert_equal(10, l.items[0].lnum)
1237 call assert_equal('Line 20', l.items[0].text)
1238 set ignorecase&
1239
Bram Moolenaar99895ea2017-04-20 22:44:47 +02001240 new | only
Bram Moolenaar049cba92016-06-26 14:38:04 +02001241 let &efm = save_efm
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001242endfunc
Bram Moolenaar049cba92016-06-26 14:38:04 +02001243
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001244func XquickfixChangedByAutocmd(cchar)
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001245 call s:setup_commands(a:cchar)
Bram Moolenaarffec3c52016-03-23 20:55:42 +01001246 if a:cchar == 'c'
Bram Moolenaarffec3c52016-03-23 20:55:42 +01001247 let ErrorNr = 'E925'
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001248 func! ReadFunc()
Bram Moolenaarffec3c52016-03-23 20:55:42 +01001249 colder
1250 cgetexpr []
1251 endfunc
1252 else
Bram Moolenaarffec3c52016-03-23 20:55:42 +01001253 let ErrorNr = 'E926'
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001254 func! ReadFunc()
Bram Moolenaarffec3c52016-03-23 20:55:42 +01001255 lolder
1256 lgetexpr []
1257 endfunc
1258 endif
1259
1260 augroup testgroup
1261 au!
Bram Moolenaard106e5b2016-04-21 19:38:07 +02001262 autocmd BufReadCmd test_changed.txt call ReadFunc()
Bram Moolenaarffec3c52016-03-23 20:55:42 +01001263 augroup END
1264
Bram Moolenaard106e5b2016-04-21 19:38:07 +02001265 new | only
Bram Moolenaarffec3c52016-03-23 20:55:42 +01001266 let words = [ "a", "b" ]
1267 let qflist = []
1268 for word in words
Bram Moolenaard106e5b2016-04-21 19:38:07 +02001269 call add(qflist, {'filename': 'test_changed.txt'})
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001270 call g:Xsetlist(qflist, ' ')
Bram Moolenaarffec3c52016-03-23 20:55:42 +01001271 endfor
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001272 call assert_fails('Xrewind', ErrorNr . ':')
Bram Moolenaarffec3c52016-03-23 20:55:42 +01001273
1274 augroup! testgroup
1275endfunc
1276
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001277func Test_quickfix_was_changed_by_autocmd()
Bram Moolenaarffec3c52016-03-23 20:55:42 +01001278 call XquickfixChangedByAutocmd('c')
1279 call XquickfixChangedByAutocmd('l')
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001280endfunc
Bram Moolenaar8b201792016-03-25 15:01:10 +01001281
1282func Test_caddbuffer_to_empty()
1283 helpgr quickfix
1284 call setqflist([], 'r')
1285 cad
Bram Moolenaarf68f1d72016-03-25 17:14:06 +01001286 try
1287 cn
1288 catch
1289 " number of matches is unknown
1290 call assert_true(v:exception =~ 'E553:')
1291 endtry
Bram Moolenaar8b201792016-03-25 15:01:10 +01001292 quit!
1293endfunc
Bram Moolenaar89c64d52016-03-27 18:44:40 +02001294
1295func Test_cgetexpr_works()
1296 " this must not crash Vim
1297 cgetexpr [$x]
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001298 lgetexpr [$x]
Bram Moolenaar89c64d52016-03-27 18:44:40 +02001299endfunc
Bram Moolenaarc1808d52016-04-18 20:04:00 +02001300
1301" Tests for the setqflist() and setloclist() functions
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001302func SetXlistTests(cchar, bnum)
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001303 call s:setup_commands(a:cchar)
Bram Moolenaarc1808d52016-04-18 20:04:00 +02001304
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001305 call g:Xsetlist([{'bufnr': a:bnum, 'lnum': 1},
Bram Moolenaarc1808d52016-04-18 20:04:00 +02001306 \ {'bufnr': a:bnum, 'lnum': 2}])
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001307 let l = g:Xgetlist()
Bram Moolenaarc1808d52016-04-18 20:04:00 +02001308 call assert_equal(2, len(l))
1309 call assert_equal(2, l[1].lnum)
1310
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001311 Xnext
1312 call g:Xsetlist([{'bufnr': a:bnum, 'lnum': 3}], 'a')
1313 let l = g:Xgetlist()
Bram Moolenaarc1808d52016-04-18 20:04:00 +02001314 call assert_equal(3, len(l))
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001315 Xnext
Bram Moolenaarc1808d52016-04-18 20:04:00 +02001316 call assert_equal(3, line('.'))
1317
Bram Moolenaar2b2b8ae2016-05-24 19:59:51 +02001318 " Appending entries to the list should not change the cursor position
1319 " in the quickfix window
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001320 Xwindow
Bram Moolenaar2b2b8ae2016-05-24 19:59:51 +02001321 1
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001322 call g:Xsetlist([{'bufnr': a:bnum, 'lnum': 4},
Bram Moolenaar2b2b8ae2016-05-24 19:59:51 +02001323 \ {'bufnr': a:bnum, 'lnum': 5}], 'a')
1324 call assert_equal(1, line('.'))
1325 close
1326
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001327 call g:Xsetlist([{'bufnr': a:bnum, 'lnum': 3},
Bram Moolenaarc1808d52016-04-18 20:04:00 +02001328 \ {'bufnr': a:bnum, 'lnum': 4},
1329 \ {'bufnr': a:bnum, 'lnum': 5}], 'r')
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001330 let l = g:Xgetlist()
Bram Moolenaarc1808d52016-04-18 20:04:00 +02001331 call assert_equal(3, len(l))
1332 call assert_equal(5, l[2].lnum)
1333
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001334 call g:Xsetlist([])
1335 let l = g:Xgetlist()
Bram Moolenaarc1808d52016-04-18 20:04:00 +02001336 call assert_equal(0, len(l))
Bram Moolenaaree85df32017-03-19 14:19:50 +01001337
Bram Moolenaarf1d21c82017-04-22 21:20:46 +02001338 " Tests for setting the 'valid' flag
1339 call g:Xsetlist([{'bufnr':a:bnum, 'lnum':4, 'valid':0}])
1340 Xwindow
1341 call assert_equal(1, winnr('$'))
1342 let l = g:Xgetlist()
1343 call g:Xsetlist(l)
1344 call assert_equal(0, g:Xgetlist()[0].valid)
Bram Moolenaar9752c722018-12-22 16:49:34 +01001345 " Adding a non-valid entry should not mark the list as having valid entries
1346 call g:Xsetlist([{'bufnr':a:bnum, 'lnum':5, 'valid':0}], 'a')
1347 Xwindow
1348 call assert_equal(1, winnr('$'))
1349
1350 " :cnext/:cprev should still work even with invalid entries in the list
1351 let l = [{'bufnr' : a:bnum, 'lnum' : 1, 'text' : '1', 'valid' : 0},
1352 \ {'bufnr' : a:bnum, 'lnum' : 2, 'text' : '2', 'valid' : 0}]
1353 call g:Xsetlist(l)
1354 Xnext
1355 call assert_equal(2, g:Xgetlist({'idx' : 0}).idx)
1356 Xprev
1357 call assert_equal(1, g:Xgetlist({'idx' : 0}).idx)
1358 " :cnext/:cprev should still work after appending invalid entries to an
1359 " empty list
1360 call g:Xsetlist([])
1361 call g:Xsetlist(l, 'a')
1362 Xnext
1363 call assert_equal(2, g:Xgetlist({'idx' : 0}).idx)
1364 Xprev
1365 call assert_equal(1, g:Xgetlist({'idx' : 0}).idx)
1366
Bram Moolenaarf1d21c82017-04-22 21:20:46 +02001367 call g:Xsetlist([{'text':'Text1', 'valid':1}])
1368 Xwindow
1369 call assert_equal(2, winnr('$'))
1370 Xclose
1371 let save_efm = &efm
1372 set efm=%m
1373 Xgetexpr 'TestMessage'
1374 let l = g:Xgetlist()
1375 call g:Xsetlist(l)
1376 call assert_equal(1, g:Xgetlist()[0].valid)
1377 let &efm = save_efm
1378
Bram Moolenaaree85df32017-03-19 14:19:50 +01001379 " Error cases:
1380 " Refer to a non-existing buffer and pass a non-dictionary type
1381 call assert_fails("call g:Xsetlist([{'bufnr':998, 'lnum':4}," .
1382 \ " {'bufnr':999, 'lnum':5}])", 'E92:')
1383 call g:Xsetlist([[1, 2,3]])
1384 call assert_equal(0, len(g:Xgetlist()))
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001385endfunc
Bram Moolenaarc1808d52016-04-18 20:04:00 +02001386
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001387func Test_setqflist()
Bram Moolenaarc1808d52016-04-18 20:04:00 +02001388 new Xtestfile | only
1389 let bnum = bufnr('%')
1390 call setline(1, range(1,5))
1391
1392 call SetXlistTests('c', bnum)
1393 call SetXlistTests('l', bnum)
1394
Bram Moolenaar1cee6932016-06-09 22:17:22 +02001395 enew!
Bram Moolenaarc1808d52016-04-18 20:04:00 +02001396 call delete('Xtestfile')
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001397endfunc
Bram Moolenaard106e5b2016-04-21 19:38:07 +02001398
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001399func Xlist_empty_middle(cchar)
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001400 call s:setup_commands(a:cchar)
1401
Bram Moolenaar1cee6932016-06-09 22:17:22 +02001402 " create three quickfix lists
Bram Moolenaaree85df32017-03-19 14:19:50 +01001403 let @/ = 'Test_'
1404 Xvimgrep // test_quickfix.vim
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001405 let testlen = len(g:Xgetlist())
Bram Moolenaar1cee6932016-06-09 22:17:22 +02001406 call assert_true(testlen > 0)
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001407 Xvimgrep empty test_quickfix.vim
1408 call assert_true(len(g:Xgetlist()) > 0)
1409 Xvimgrep matches test_quickfix.vim
1410 let matchlen = len(g:Xgetlist())
Bram Moolenaar1cee6932016-06-09 22:17:22 +02001411 call assert_true(matchlen > 0)
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001412 Xolder
Bram Moolenaar1cee6932016-06-09 22:17:22 +02001413 " make the middle list empty
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001414 call g:Xsetlist([], 'r')
1415 call assert_true(len(g:Xgetlist()) == 0)
1416 Xolder
1417 call assert_equal(testlen, len(g:Xgetlist()))
1418 Xnewer
1419 Xnewer
1420 call assert_equal(matchlen, len(g:Xgetlist()))
Bram Moolenaar1cee6932016-06-09 22:17:22 +02001421endfunc
1422
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001423func Test_setqflist_empty_middle()
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001424 call Xlist_empty_middle('c')
1425 call Xlist_empty_middle('l')
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001426endfunc
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001427
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001428func Xlist_empty_older(cchar)
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001429 call s:setup_commands(a:cchar)
1430
Bram Moolenaar1cee6932016-06-09 22:17:22 +02001431 " create three quickfix lists
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001432 Xvimgrep one test_quickfix.vim
1433 let onelen = len(g:Xgetlist())
Bram Moolenaar1cee6932016-06-09 22:17:22 +02001434 call assert_true(onelen > 0)
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001435 Xvimgrep two test_quickfix.vim
1436 let twolen = len(g:Xgetlist())
Bram Moolenaar1cee6932016-06-09 22:17:22 +02001437 call assert_true(twolen > 0)
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001438 Xvimgrep three test_quickfix.vim
1439 let threelen = len(g:Xgetlist())
Bram Moolenaar1cee6932016-06-09 22:17:22 +02001440 call assert_true(threelen > 0)
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001441 Xolder 2
Bram Moolenaar1cee6932016-06-09 22:17:22 +02001442 " make the first list empty, check the others didn't change
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001443 call g:Xsetlist([], 'r')
1444 call assert_true(len(g:Xgetlist()) == 0)
1445 Xnewer
1446 call assert_equal(twolen, len(g:Xgetlist()))
1447 Xnewer
1448 call assert_equal(threelen, len(g:Xgetlist()))
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001449endfunc
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001450
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001451func Test_setqflist_empty_older()
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001452 call Xlist_empty_older('c')
1453 call Xlist_empty_older('l')
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001454endfunc
Bram Moolenaar1cee6932016-06-09 22:17:22 +02001455
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001456func XquickfixSetListWithAct(cchar)
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001457 call s:setup_commands(a:cchar)
1458
Bram Moolenaard106e5b2016-04-21 19:38:07 +02001459 let list1 = [{'filename': 'fnameA', 'text': 'A'},
1460 \ {'filename': 'fnameB', 'text': 'B'}]
1461 let list2 = [{'filename': 'fnameC', 'text': 'C'},
1462 \ {'filename': 'fnameD', 'text': 'D'},
1463 \ {'filename': 'fnameE', 'text': 'E'}]
1464
Bram Moolenaareeb1b9c2019-02-10 22:59:04 +01001465 " {action} is unspecified. Same as specifying ' '.
Bram Moolenaard106e5b2016-04-21 19:38:07 +02001466 new | only
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001467 silent! Xnewer 99
1468 call g:Xsetlist(list1)
1469 call g:Xsetlist(list2)
1470 let li = g:Xgetlist()
Bram Moolenaard106e5b2016-04-21 19:38:07 +02001471 call assert_equal(3, len(li))
1472 call assert_equal('C', li[0]['text'])
1473 call assert_equal('D', li[1]['text'])
1474 call assert_equal('E', li[2]['text'])
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001475 silent! Xolder
1476 let li = g:Xgetlist()
Bram Moolenaard106e5b2016-04-21 19:38:07 +02001477 call assert_equal(2, len(li))
1478 call assert_equal('A', li[0]['text'])
1479 call assert_equal('B', li[1]['text'])
1480
1481 " {action} is specified ' '.
1482 new | only
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001483 silent! Xnewer 99
1484 call g:Xsetlist(list1)
1485 call g:Xsetlist(list2, ' ')
1486 let li = g:Xgetlist()
Bram Moolenaard106e5b2016-04-21 19:38:07 +02001487 call assert_equal(3, len(li))
1488 call assert_equal('C', li[0]['text'])
1489 call assert_equal('D', li[1]['text'])
1490 call assert_equal('E', li[2]['text'])
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001491 silent! Xolder
1492 let li = g:Xgetlist()
Bram Moolenaard106e5b2016-04-21 19:38:07 +02001493 call assert_equal(2, len(li))
1494 call assert_equal('A', li[0]['text'])
1495 call assert_equal('B', li[1]['text'])
1496
1497 " {action} is specified 'a'.
1498 new | only
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001499 silent! Xnewer 99
1500 call g:Xsetlist(list1)
1501 call g:Xsetlist(list2, 'a')
1502 let li = g:Xgetlist()
Bram Moolenaard106e5b2016-04-21 19:38:07 +02001503 call assert_equal(5, len(li))
1504 call assert_equal('A', li[0]['text'])
1505 call assert_equal('B', li[1]['text'])
1506 call assert_equal('C', li[2]['text'])
1507 call assert_equal('D', li[3]['text'])
1508 call assert_equal('E', li[4]['text'])
1509
1510 " {action} is specified 'r'.
1511 new | only
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001512 silent! Xnewer 99
1513 call g:Xsetlist(list1)
1514 call g:Xsetlist(list2, 'r')
1515 let li = g:Xgetlist()
Bram Moolenaard106e5b2016-04-21 19:38:07 +02001516 call assert_equal(3, len(li))
1517 call assert_equal('C', li[0]['text'])
1518 call assert_equal('D', li[1]['text'])
1519 call assert_equal('E', li[2]['text'])
1520
1521 " Test for wrong value.
1522 new | only
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001523 call assert_fails("call g:Xsetlist(0)", 'E714:')
1524 call assert_fails("call g:Xsetlist(list1, '')", 'E927:')
1525 call assert_fails("call g:Xsetlist(list1, 'aa')", 'E927:')
1526 call assert_fails("call g:Xsetlist(list1, ' a')", 'E927:')
1527 call assert_fails("call g:Xsetlist(list1, 0)", 'E928:')
Bram Moolenaard106e5b2016-04-21 19:38:07 +02001528endfunc
1529
Bram Moolenaara0ca7d02017-12-19 10:22:19 +01001530func Test_setqflist_invalid_nr()
1531 " The following command used to crash Vim
Bram Moolenaaraad222c2019-09-06 22:46:09 +02001532 eval []->setqflist(' ', {'nr' : $XXX_DOES_NOT_EXIST})
Bram Moolenaara0ca7d02017-12-19 10:22:19 +01001533endfunc
1534
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001535func Test_quickfix_set_list_with_act()
Bram Moolenaard106e5b2016-04-21 19:38:07 +02001536 call XquickfixSetListWithAct('c')
1537 call XquickfixSetListWithAct('l')
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001538endfunc
Bram Moolenaar6be8c8e2016-04-30 13:17:09 +02001539
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001540func XLongLinesTests(cchar)
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001541 let l = g:Xgetlist()
Bram Moolenaar6be8c8e2016-04-30 13:17:09 +02001542
Bram Moolenaar049cba92016-06-26 14:38:04 +02001543 call assert_equal(4, len(l))
Bram Moolenaar6be8c8e2016-04-30 13:17:09 +02001544 call assert_equal(1, l[0].lnum)
1545 call assert_equal(1, l[0].col)
Bram Moolenaar049cba92016-06-26 14:38:04 +02001546 call assert_equal(1975, len(l[0].text))
Bram Moolenaar6be8c8e2016-04-30 13:17:09 +02001547 call assert_equal(2, l[1].lnum)
1548 call assert_equal(1, l[1].col)
1549 call assert_equal(4070, len(l[1].text))
1550 call assert_equal(3, l[2].lnum)
1551 call assert_equal(1, l[2].col)
Bram Moolenaar049cba92016-06-26 14:38:04 +02001552 call assert_equal(4070, len(l[2].text))
1553 call assert_equal(4, l[3].lnum)
1554 call assert_equal(1, l[3].col)
1555 call assert_equal(10, len(l[3].text))
Bram Moolenaar6be8c8e2016-04-30 13:17:09 +02001556
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001557 call g:Xsetlist([], 'r')
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001558endfunc
Bram Moolenaar6be8c8e2016-04-30 13:17:09 +02001559
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001560func s:long_lines_tests(cchar)
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001561 call s:setup_commands(a:cchar)
1562
Bram Moolenaar6be8c8e2016-04-30 13:17:09 +02001563 let testfile = 'samples/quickfix.txt'
1564
1565 " file
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001566 exe 'Xgetfile' testfile
1567 call XLongLinesTests(a:cchar)
Bram Moolenaar6be8c8e2016-04-30 13:17:09 +02001568
1569 " list
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001570 Xexpr readfile(testfile)
1571 call XLongLinesTests(a:cchar)
Bram Moolenaar6be8c8e2016-04-30 13:17:09 +02001572
1573 " string
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001574 Xexpr join(readfile(testfile), "\n")
1575 call XLongLinesTests(a:cchar)
Bram Moolenaar6be8c8e2016-04-30 13:17:09 +02001576
1577 " buffer
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001578 exe 'edit' testfile
1579 exe 'Xbuffer' bufnr('%')
Bram Moolenaarf50df392016-06-21 21:33:34 +02001580 call XLongLinesTests(a:cchar)
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001581endfunc
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001582
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001583func Test_long_lines()
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001584 call s:long_lines_tests('c')
1585 call s:long_lines_tests('l')
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001586endfunc
Bram Moolenaar049cba92016-06-26 14:38:04 +02001587
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001588func s:create_test_file(filename)
Bram Moolenaar049cba92016-06-26 14:38:04 +02001589 let l = []
1590 for i in range(1, 20)
1591 call add(l, 'Line' . i)
1592 endfor
1593 call writefile(l, a:filename)
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001594endfunc
Bram Moolenaar049cba92016-06-26 14:38:04 +02001595
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001596func Test_switchbuf()
Bram Moolenaar049cba92016-06-26 14:38:04 +02001597 call s:create_test_file('Xqftestfile1')
1598 call s:create_test_file('Xqftestfile2')
1599 call s:create_test_file('Xqftestfile3')
1600
1601 new | only
1602 edit Xqftestfile1
1603 let file1_winid = win_getid()
1604 new Xqftestfile2
1605 let file2_winid = win_getid()
1606 cgetexpr ['Xqftestfile1:5:Line5',
1607 \ 'Xqftestfile1:6:Line6',
1608 \ 'Xqftestfile2:10:Line10',
1609 \ 'Xqftestfile2:11:Line11',
1610 \ 'Xqftestfile3:15:Line15',
1611 \ 'Xqftestfile3:16:Line16']
1612
1613 new
1614 let winid = win_getid()
1615 cfirst | cnext
1616 call assert_equal(winid, win_getid())
Bram Moolenaar99895ea2017-04-20 22:44:47 +02001617 2cnext
Bram Moolenaar049cba92016-06-26 14:38:04 +02001618 call assert_equal(winid, win_getid())
Bram Moolenaar99895ea2017-04-20 22:44:47 +02001619 2cnext
Bram Moolenaar049cba92016-06-26 14:38:04 +02001620 call assert_equal(winid, win_getid())
1621 enew
1622
1623 set switchbuf=useopen
1624 cfirst | cnext
1625 call assert_equal(file1_winid, win_getid())
Bram Moolenaar99895ea2017-04-20 22:44:47 +02001626 2cnext
Bram Moolenaar049cba92016-06-26 14:38:04 +02001627 call assert_equal(file2_winid, win_getid())
Bram Moolenaar99895ea2017-04-20 22:44:47 +02001628 2cnext
Bram Moolenaar049cba92016-06-26 14:38:04 +02001629 call assert_equal(file2_winid, win_getid())
1630
1631 enew | only
1632 set switchbuf=usetab
1633 tabedit Xqftestfile1
1634 tabedit Xqftestfile2
Bram Moolenaar74240d32017-12-10 15:26:15 +01001635 tabedit Xqftestfile3
Bram Moolenaar049cba92016-06-26 14:38:04 +02001636 tabfirst
1637 cfirst | cnext
1638 call assert_equal(2, tabpagenr())
Bram Moolenaar99895ea2017-04-20 22:44:47 +02001639 2cnext
Bram Moolenaar049cba92016-06-26 14:38:04 +02001640 call assert_equal(3, tabpagenr())
Bram Moolenaar74240d32017-12-10 15:26:15 +01001641 6cnext
1642 call assert_equal(4, tabpagenr())
1643 2cpfile
1644 call assert_equal(2, tabpagenr())
1645 2cnfile
1646 call assert_equal(4, tabpagenr())
Bram Moolenaar049cba92016-06-26 14:38:04 +02001647 tabfirst | tabonly | enew
1648
1649 set switchbuf=split
1650 cfirst | cnext
1651 call assert_equal(1, winnr('$'))
1652 cnext | cnext
1653 call assert_equal(2, winnr('$'))
1654 cnext | cnext
1655 call assert_equal(3, winnr('$'))
1656 enew | only
1657
1658 set switchbuf=newtab
1659 cfirst | cnext
1660 call assert_equal(1, tabpagenr('$'))
1661 cnext | cnext
1662 call assert_equal(2, tabpagenr('$'))
1663 cnext | cnext
1664 call assert_equal(3, tabpagenr('$'))
1665 tabfirst | enew | tabonly | only
1666
Bram Moolenaar539aa6b2019-11-17 18:09:38 +01001667 set switchbuf=uselast
1668 split
1669 let last_winid = win_getid()
1670 copen
1671 exe "normal 1G\<CR>"
1672 call assert_equal(last_winid, win_getid())
1673 enew | only
1674
Bram Moolenaar049cba92016-06-26 14:38:04 +02001675 set switchbuf=
1676 edit Xqftestfile1
1677 let file1_winid = win_getid()
1678 new Xqftestfile2
1679 let file2_winid = win_getid()
1680 copen
1681 exe "normal 1G\<CR>"
1682 call assert_equal(file1_winid, win_getid())
1683 copen
1684 exe "normal 3G\<CR>"
1685 call assert_equal(file2_winid, win_getid())
1686 copen | only
1687 exe "normal 5G\<CR>"
1688 call assert_equal(2, winnr('$'))
1689 call assert_equal(1, bufwinnr('Xqftestfile3'))
1690
Bram Moolenaar391b1dd2017-03-04 13:47:11 +01001691 " If only quickfix window is open in the current tabpage, jumping to an
Bram Moolenaar1bc353b2019-09-01 14:45:28 +02001692 " entry with 'switchbuf' set to 'usetab' should search in other tabpages.
Bram Moolenaar049cba92016-06-26 14:38:04 +02001693 enew | only
Bram Moolenaar391b1dd2017-03-04 13:47:11 +01001694 set switchbuf=usetab
1695 tabedit Xqftestfile1
1696 tabedit Xqftestfile2
1697 tabedit Xqftestfile3
1698 tabfirst
1699 copen | only
1700 clast
1701 call assert_equal(4, tabpagenr())
1702 tabfirst | tabonly | enew | only
Bram Moolenaar049cba92016-06-26 14:38:04 +02001703
1704 call delete('Xqftestfile1')
1705 call delete('Xqftestfile2')
1706 call delete('Xqftestfile3')
Bram Moolenaar391b1dd2017-03-04 13:47:11 +01001707 set switchbuf&vim
1708
1709 enew | only
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001710endfunc
Bram Moolenaar049cba92016-06-26 14:38:04 +02001711
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001712func Xadjust_qflnum(cchar)
Bram Moolenaar049cba92016-06-26 14:38:04 +02001713 call s:setup_commands(a:cchar)
1714
1715 enew | only
1716
Bram Moolenaarc1542742016-07-20 21:44:37 +02001717 let fname = 'Xqftestfile' . a:cchar
1718 call s:create_test_file(fname)
1719 exe 'edit ' . fname
Bram Moolenaar049cba92016-06-26 14:38:04 +02001720
Bram Moolenaarc1542742016-07-20 21:44:37 +02001721 Xgetexpr [fname . ':5:Line5',
1722 \ fname . ':10:Line10',
1723 \ fname . ':15:Line15',
1724 \ fname . ':20:Line20']
Bram Moolenaar049cba92016-06-26 14:38:04 +02001725
1726 6,14delete
1727 call append(6, ['Buffer', 'Window'])
1728
1729 let l = g:Xgetlist()
1730
1731 call assert_equal(5, l[0].lnum)
1732 call assert_equal(6, l[2].lnum)
1733 call assert_equal(13, l[3].lnum)
1734
1735 enew!
Bram Moolenaarc1542742016-07-20 21:44:37 +02001736 call delete(fname)
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001737endfunc
Bram Moolenaar049cba92016-06-26 14:38:04 +02001738
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001739func Test_adjust_lnum()
Bram Moolenaarc1542742016-07-20 21:44:37 +02001740 call setloclist(0, [])
Bram Moolenaar049cba92016-06-26 14:38:04 +02001741 call Xadjust_qflnum('c')
Bram Moolenaarc1542742016-07-20 21:44:37 +02001742 call setqflist([])
Bram Moolenaar049cba92016-06-26 14:38:04 +02001743 call Xadjust_qflnum('l')
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001744endfunc
Bram Moolenaar049cba92016-06-26 14:38:04 +02001745
1746" Tests for the :grep/:lgrep and :grepadd/:lgrepadd commands
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001747func s:test_xgrep(cchar)
Bram Moolenaar049cba92016-06-26 14:38:04 +02001748 call s:setup_commands(a:cchar)
1749
1750 " The following lines are used for the grep test. Don't remove.
1751 " Grep_Test_Text: Match 1
1752 " Grep_Test_Text: Match 2
1753 " GrepAdd_Test_Text: Match 1
1754 " GrepAdd_Test_Text: Match 2
1755 enew! | only
1756 set makeef&vim
1757 silent Xgrep Grep_Test_Text: test_quickfix.vim
1758 call assert_true(len(g:Xgetlist()) == 3)
1759 Xopen
1760 call assert_true(w:quickfix_title =~ '^:grep')
1761 Xclose
1762 enew
1763 set makeef=Temp_File_##
1764 silent Xgrepadd GrepAdd_Test_Text: test_quickfix.vim
1765 call assert_true(len(g:Xgetlist()) == 6)
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001766endfunc
Bram Moolenaar049cba92016-06-26 14:38:04 +02001767
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001768func Test_grep()
Bram Moolenaar049cba92016-06-26 14:38:04 +02001769 if !has('unix')
1770 " The grepprg may not be set on non-Unix systems
1771 return
1772 endif
1773
1774 call s:test_xgrep('c')
1775 call s:test_xgrep('l')
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001776endfunc
Bram Moolenaar361c8f02016-07-02 15:41:47 +02001777
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001778func Test_two_windows()
Bram Moolenaar361c8f02016-07-02 15:41:47 +02001779 " Use one 'errorformat' for two windows. Add an expression to each of them,
1780 " make sure they each keep their own state.
1781 set efm=%DEntering\ dir\ '%f',%f:%l:%m,%XLeaving\ dir\ '%f'
1782 call mkdir('Xone/a', 'p')
1783 call mkdir('Xtwo/a', 'p')
1784 let lines = ['1', '2', 'one one one', '4', 'two two two', '6', '7']
1785 call writefile(lines, 'Xone/a/one.txt')
1786 call writefile(lines, 'Xtwo/a/two.txt')
1787
1788 new one
1789 let one_id = win_getid()
1790 lexpr ""
1791 new two
1792 let two_id = win_getid()
1793 lexpr ""
1794
1795 laddexpr "Entering dir 'Xtwo/a'"
1796 call win_gotoid(one_id)
1797 laddexpr "Entering dir 'Xone/a'"
1798 call win_gotoid(two_id)
1799 laddexpr 'two.txt:5:two two two'
1800 call win_gotoid(one_id)
1801 laddexpr 'one.txt:3:one one one'
1802
1803 let loc_one = getloclist(one_id)
Bram Moolenaar361c8f02016-07-02 15:41:47 +02001804 call assert_equal('Xone/a/one.txt', bufname(loc_one[1].bufnr))
1805 call assert_equal(3, loc_one[1].lnum)
1806
1807 let loc_two = getloclist(two_id)
Bram Moolenaar361c8f02016-07-02 15:41:47 +02001808 call assert_equal('Xtwo/a/two.txt', bufname(loc_two[1].bufnr))
1809 call assert_equal(5, loc_two[1].lnum)
1810
1811 call win_gotoid(one_id)
1812 bwipe!
1813 call win_gotoid(two_id)
1814 bwipe!
1815 call delete('Xone', 'rf')
1816 call delete('Xtwo', 'rf')
1817endfunc
Bram Moolenaardcb17002016-07-07 18:58:59 +02001818
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001819func XbottomTests(cchar)
Bram Moolenaar537ef082016-07-09 17:56:19 +02001820 call s:setup_commands(a:cchar)
1821
Bram Moolenaarb6fa30c2017-03-29 14:19:25 +02001822 " Calling lbottom without any errors should fail
1823 if a:cchar == 'l'
1824 call assert_fails('lbottom', 'E776:')
1825 endif
1826
Bram Moolenaar875feea2017-06-11 16:07:51 +02001827 call g:Xsetlist([{'filename': 'foo', 'lnum': 42}])
Bram Moolenaar537ef082016-07-09 17:56:19 +02001828 Xopen
Bram Moolenaardcb17002016-07-07 18:58:59 +02001829 let wid = win_getid()
1830 call assert_equal(1, line('.'))
1831 wincmd w
Bram Moolenaar875feea2017-06-11 16:07:51 +02001832 call g:Xsetlist([{'filename': 'var', 'lnum': 24}], 'a')
Bram Moolenaar537ef082016-07-09 17:56:19 +02001833 Xbottom
Bram Moolenaardcb17002016-07-07 18:58:59 +02001834 call win_gotoid(wid)
1835 call assert_equal(2, line('.'))
Bram Moolenaar537ef082016-07-09 17:56:19 +02001836 Xclose
Bram Moolenaardcb17002016-07-07 18:58:59 +02001837endfunc
Bram Moolenaar537ef082016-07-09 17:56:19 +02001838
1839" Tests for the :cbottom and :lbottom commands
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001840func Test_cbottom()
Bram Moolenaar537ef082016-07-09 17:56:19 +02001841 call XbottomTests('c')
1842 call XbottomTests('l')
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001843endfunc
Bram Moolenaarf6acffb2016-07-16 16:54:24 +02001844
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001845func HistoryTest(cchar)
Bram Moolenaarf6acffb2016-07-16 16:54:24 +02001846 call s:setup_commands(a:cchar)
1847
Bram Moolenaarf6acffb2016-07-16 16:54:24 +02001848 " clear all lists after the first one, then replace the first one.
1849 call g:Xsetlist([])
Bram Moolenaarb6fa30c2017-03-29 14:19:25 +02001850 call assert_fails('Xolder 99', 'E380:')
Bram Moolenaarf6acffb2016-07-16 16:54:24 +02001851 let entry = {'filename': 'foo', 'lnum': 42}
1852 call g:Xsetlist([entry], 'r')
1853 call g:Xsetlist([entry, entry])
1854 call g:Xsetlist([entry, entry, entry])
1855 let res = split(execute(a:cchar . 'hist'), "\n")
1856 call assert_equal(3, len(res))
1857 let common = 'errors :set' . (a:cchar == 'c' ? 'qf' : 'loc') . 'list()'
1858 call assert_equal(' error list 1 of 3; 1 ' . common, res[0])
1859 call assert_equal(' error list 2 of 3; 2 ' . common, res[1])
1860 call assert_equal('> error list 3 of 3; 3 ' . common, res[2])
Bram Moolenaarb4d5fba2017-09-11 19:31:28 +02001861
Bram Moolenaar8ffc7c82019-05-05 21:00:26 +02001862 " Test for changing the quickfix lists
1863 call assert_equal(3, g:Xgetlist({'nr' : 0}).nr)
1864 exe '1' . a:cchar . 'hist'
1865 call assert_equal(1, g:Xgetlist({'nr' : 0}).nr)
1866 exe '3' . a:cchar . 'hist'
1867 call assert_equal(3, g:Xgetlist({'nr' : 0}).nr)
1868 call assert_fails('-2' . a:cchar . 'hist', 'E16:')
1869 call assert_fails('4' . a:cchar . 'hist', 'E16:')
1870
Bram Moolenaarb4d5fba2017-09-11 19:31:28 +02001871 call g:Xsetlist([], 'f')
1872 let l = split(execute(a:cchar . 'hist'), "\n")
1873 call assert_equal('No entries', l[0])
Bram Moolenaar8ffc7c82019-05-05 21:00:26 +02001874 if a:cchar == 'c'
1875 call assert_fails('4chist', 'E16:')
1876 else
1877 call assert_fails('4lhist', 'E776:')
1878 endif
Bram Moolenaar5b69c222019-01-11 14:50:06 +01001879
1880 " An empty list should still show the stack history
1881 call g:Xsetlist([])
1882 let res = split(execute(a:cchar . 'hist'), "\n")
1883 call assert_equal('> error list 1 of 1; 0 ' . common, res[0])
1884
1885 call g:Xsetlist([], 'f')
Bram Moolenaarf6acffb2016-07-16 16:54:24 +02001886endfunc
1887
1888func Test_history()
1889 call HistoryTest('c')
1890 call HistoryTest('l')
1891endfunc
Bram Moolenaar015102e2016-07-16 18:24:56 +02001892
1893func Test_duplicate_buf()
1894 " make sure we can get the highest buffer number
1895 edit DoesNotExist
1896 edit DoesNotExist2
1897 let last_buffer = bufnr("$")
1898
1899 " make sure only one buffer is created
1900 call writefile(['this one', 'that one'], 'Xgrepthis')
1901 vimgrep one Xgrepthis
1902 vimgrep one Xgrepthis
1903 call assert_equal(last_buffer + 1, bufnr("$"))
1904
1905 call delete('Xgrepthis')
1906endfunc
Bram Moolenaard823fa92016-08-12 16:29:27 +02001907
1908" Quickfix/Location list set/get properties tests
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001909func Xproperty_tests(cchar)
Bram Moolenaard823fa92016-08-12 16:29:27 +02001910 call s:setup_commands(a:cchar)
1911
1912 " Error cases
1913 call assert_fails('call g:Xgetlist(99)', 'E715:')
1914 call assert_fails('call g:Xsetlist(99)', 'E714:')
1915 call assert_fails('call g:Xsetlist([], "a", [])', 'E715:')
1916
1917 " Set and get the title
Bram Moolenaarb6fa30c2017-03-29 14:19:25 +02001918 call g:Xsetlist([])
Bram Moolenaard823fa92016-08-12 16:29:27 +02001919 Xopen
1920 wincmd p
1921 call g:Xsetlist([{'filename':'foo', 'lnum':27}])
Bram Moolenaar86f100dc2017-06-28 21:26:27 +02001922 let s = g:Xsetlist([], 'a', {'title' : 'Sample'})
1923 call assert_equal(0, s)
Bram Moolenaard823fa92016-08-12 16:29:27 +02001924 let d = g:Xgetlist({"title":1})
1925 call assert_equal('Sample', d.title)
Bram Moolenaara2aa8a22018-04-24 13:55:00 +02001926 " Try setting title to a non-string value
1927 call assert_equal(-1, g:Xsetlist([], 'a', {'title' : ['Test']}))
1928 call assert_equal('Sample', g:Xgetlist({"title":1}).title)
Bram Moolenaard823fa92016-08-12 16:29:27 +02001929
1930 Xopen
1931 call assert_equal('Sample', w:quickfix_title)
1932 Xclose
1933
Bram Moolenaar2b529bb2016-08-27 13:35:35 +02001934 " Tests for action argument
1935 silent! Xolder 999
1936 let qfnr = g:Xgetlist({'all':1}).nr
1937 call g:Xsetlist([], 'r', {'title' : 'N1'})
1938 call assert_equal('N1', g:Xgetlist({'all':1}).title)
1939 call g:Xsetlist([], ' ', {'title' : 'N2'})
1940 call assert_equal(qfnr + 1, g:Xgetlist({'all':1}).nr)
Bram Moolenaar890680c2016-09-27 21:28:56 +02001941
1942 let res = g:Xgetlist({'nr': 0})
1943 call assert_equal(qfnr + 1, res.nr)
1944 call assert_equal(['nr'], keys(res))
1945
Bram Moolenaar2b529bb2016-08-27 13:35:35 +02001946 call g:Xsetlist([], ' ', {'title' : 'N3'})
1947 call assert_equal('N2', g:Xgetlist({'nr':2, 'title':1}).title)
1948
Bram Moolenaaree85df32017-03-19 14:19:50 +01001949 " Changing the title of an earlier quickfix list
Bram Moolenaar55b69262017-08-13 13:42:01 +02001950 call g:Xsetlist([], 'r', {'title' : 'NewTitle', 'nr' : 2})
Bram Moolenaaree85df32017-03-19 14:19:50 +01001951 call assert_equal('NewTitle', g:Xgetlist({'nr':2, 'title':1}).title)
1952
1953 " Changing the title of an invalid quickfix list
1954 call assert_equal(-1, g:Xsetlist([], ' ',
1955 \ {'title' : 'SomeTitle', 'nr' : 99}))
1956 call assert_equal(-1, g:Xsetlist([], ' ',
1957 \ {'title' : 'SomeTitle', 'nr' : 'abc'}))
1958
1959 if a:cchar == 'c'
1960 copen
1961 call assert_equal({'winid':win_getid()}, getqflist({'winid':1}))
1962 cclose
1963 endif
1964
Bram Moolenaard823fa92016-08-12 16:29:27 +02001965 " Invalid arguments
1966 call assert_fails('call g:Xgetlist([])', 'E715')
1967 call assert_fails('call g:Xsetlist([], "a", [])', 'E715')
1968 let s = g:Xsetlist([], 'a', {'abc':1})
1969 call assert_equal(-1, s)
1970
1971 call assert_equal({}, g:Xgetlist({'abc':1}))
Bram Moolenaara6d48492017-12-12 22:45:31 +01001972 call assert_equal('', g:Xgetlist({'nr':99, 'title':1}).title)
1973 call assert_equal('', g:Xgetlist({'nr':[], 'title':1}).title)
Bram Moolenaard823fa92016-08-12 16:29:27 +02001974
1975 if a:cchar == 'l'
Bram Moolenaar890680c2016-09-27 21:28:56 +02001976 call assert_equal({}, getloclist(99, {'title': 1}))
Bram Moolenaard823fa92016-08-12 16:29:27 +02001977 endif
Bram Moolenaar8f77c5a2017-04-30 14:21:00 +02001978
1979 " Context related tests
Bram Moolenaar86f100dc2017-06-28 21:26:27 +02001980 let s = g:Xsetlist([], 'a', {'context':[1,2,3]})
1981 call assert_equal(0, s)
Bram Moolenaar8f77c5a2017-04-30 14:21:00 +02001982 call test_garbagecollect_now()
1983 let d = g:Xgetlist({'context':1})
1984 call assert_equal([1,2,3], d.context)
1985 call g:Xsetlist([], 'a', {'context':{'color':'green'}})
1986 let d = g:Xgetlist({'context':1})
1987 call assert_equal({'color':'green'}, d.context)
1988 call g:Xsetlist([], 'a', {'context':"Context info"})
1989 let d = g:Xgetlist({'context':1})
1990 call assert_equal("Context info", d.context)
1991 call g:Xsetlist([], 'a', {'context':246})
1992 let d = g:Xgetlist({'context':1})
1993 call assert_equal(246, d.context)
1994 if a:cchar == 'l'
1995 " Test for copying context across two different location lists
1996 new | only
1997 let w1_id = win_getid()
1998 let l = [1]
1999 call setloclist(0, [], 'a', {'context':l})
2000 new
2001 let w2_id = win_getid()
2002 call add(l, 2)
2003 call assert_equal([1, 2], getloclist(w1_id, {'context':1}).context)
2004 call assert_equal([1, 2], getloclist(w2_id, {'context':1}).context)
2005 unlet! l
2006 call assert_equal([1, 2], getloclist(w2_id, {'context':1}).context)
2007 only
2008 call setloclist(0, [], 'f')
Bram Moolenaara6d48492017-12-12 22:45:31 +01002009 call assert_equal('', getloclist(0, {'context':1}).context)
Bram Moolenaar8f77c5a2017-04-30 14:21:00 +02002010 endif
Bram Moolenaar6e62da32017-05-28 08:16:25 +02002011
2012 " Test for changing the context of previous quickfix lists
2013 call g:Xsetlist([], 'f')
2014 Xexpr "One"
2015 Xexpr "Two"
2016 Xexpr "Three"
Bram Moolenaar55b69262017-08-13 13:42:01 +02002017 call g:Xsetlist([], 'r', {'context' : [1], 'nr' : 1})
2018 call g:Xsetlist([], 'a', {'context' : [2], 'nr' : 2})
Bram Moolenaar6e62da32017-05-28 08:16:25 +02002019 " Also, check for setting the context using quickfix list number zero.
Bram Moolenaar55b69262017-08-13 13:42:01 +02002020 call g:Xsetlist([], 'r', {'context' : [3], 'nr' : 0})
Bram Moolenaar6e62da32017-05-28 08:16:25 +02002021 call test_garbagecollect_now()
2022 let l = g:Xgetlist({'nr' : 1, 'context' : 1})
2023 call assert_equal([1], l.context)
2024 let l = g:Xgetlist({'nr' : 2, 'context' : 1})
2025 call assert_equal([2], l.context)
2026 let l = g:Xgetlist({'nr' : 3, 'context' : 1})
2027 call assert_equal([3], l.context)
2028
2029 " Test for changing the context through reference and for garbage
2030 " collection of quickfix context
2031 let l = ["red"]
2032 call g:Xsetlist([], ' ', {'context' : l})
2033 call add(l, "blue")
2034 let x = g:Xgetlist({'context' : 1})
2035 call add(x.context, "green")
2036 call assert_equal(["red", "blue", "green"], l)
2037 call assert_equal(["red", "blue", "green"], x.context)
2038 unlet l
2039 call test_garbagecollect_now()
2040 let m = g:Xgetlist({'context' : 1})
2041 call assert_equal(["red", "blue", "green"], m.context)
Bram Moolenaar6a8958d2017-06-22 21:33:20 +02002042
2043 " Test for setting/getting items
2044 Xexpr ""
2045 let qfprev = g:Xgetlist({'nr':0})
Bram Moolenaar86f100dc2017-06-28 21:26:27 +02002046 let s = g:Xsetlist([], ' ', {'title':'Green',
Bram Moolenaar6a8958d2017-06-22 21:33:20 +02002047 \ 'items' : [{'filename':'F1', 'lnum':10}]})
Bram Moolenaar86f100dc2017-06-28 21:26:27 +02002048 call assert_equal(0, s)
Bram Moolenaar6a8958d2017-06-22 21:33:20 +02002049 let qfcur = g:Xgetlist({'nr':0})
2050 call assert_true(qfcur.nr == qfprev.nr + 1)
2051 let l = g:Xgetlist({'items':1})
2052 call assert_equal('F1', bufname(l.items[0].bufnr))
2053 call assert_equal(10, l.items[0].lnum)
2054 call g:Xsetlist([], 'a', {'items' : [{'filename':'F2', 'lnum':20},
2055 \ {'filename':'F2', 'lnum':30}]})
2056 let l = g:Xgetlist({'items':1})
2057 call assert_equal('F2', bufname(l.items[2].bufnr))
2058 call assert_equal(30, l.items[2].lnum)
2059 call g:Xsetlist([], 'r', {'items' : [{'filename':'F3', 'lnum':40}]})
2060 let l = g:Xgetlist({'items':1})
2061 call assert_equal('F3', bufname(l.items[0].bufnr))
2062 call assert_equal(40, l.items[0].lnum)
2063 call g:Xsetlist([], 'r', {'items' : []})
2064 let l = g:Xgetlist({'items':1})
2065 call assert_equal(0, len(l.items))
2066
Bram Moolenaarb4d5fba2017-09-11 19:31:28 +02002067 call g:Xsetlist([], 'r', {'title' : 'TestTitle'})
2068 call g:Xsetlist([], 'r', {'items' : [{'filename' : 'F1', 'lnum' : 10, 'text' : 'L10'}]})
2069 call g:Xsetlist([], 'r', {'items' : [{'filename' : 'F1', 'lnum' : 10, 'text' : 'L10'}]})
2070 call assert_equal('TestTitle', g:Xgetlist({'title' : 1}).title)
2071
Bram Moolenaarc9cc9c72018-09-02 15:18:42 +02002072 " Test for getting id of window associated with a location list window
2073 if a:cchar == 'l'
2074 only
2075 call assert_equal(0, g:Xgetlist({'all' : 1}).filewinid)
2076 let wid = win_getid()
2077 Xopen
2078 call assert_equal(wid, g:Xgetlist({'filewinid' : 1}).filewinid)
2079 wincmd w
2080 call assert_equal(0, g:Xgetlist({'filewinid' : 1}).filewinid)
2081 only
2082 endif
2083
Bram Moolenaarae338332017-08-11 20:25:26 +02002084 " The following used to crash Vim with address sanitizer
2085 call g:Xsetlist([], 'f')
2086 call g:Xsetlist([], 'a', {'items' : [{'filename':'F1', 'lnum':10}]})
2087 call assert_equal(10, g:Xgetlist({'items':1}).items[0].lnum)
2088
Bram Moolenaara2aa8a22018-04-24 13:55:00 +02002089 " Try setting the items using a string
2090 call assert_equal(-1, g:Xsetlist([], ' ', {'items' : 'Test'}))
2091
Bram Moolenaar6a8958d2017-06-22 21:33:20 +02002092 " Save and restore the quickfix stack
2093 call g:Xsetlist([], 'f')
2094 call assert_equal(0, g:Xgetlist({'nr':'$'}).nr)
2095 Xexpr "File1:10:Line1"
2096 Xexpr "File2:20:Line2"
2097 Xexpr "File3:30:Line3"
2098 let last_qf = g:Xgetlist({'nr':'$'}).nr
2099 call assert_equal(3, last_qf)
2100 let qstack = []
2101 for i in range(1, last_qf)
2102 let qstack = add(qstack, g:Xgetlist({'nr':i, 'all':1}))
2103 endfor
2104 call g:Xsetlist([], 'f')
2105 for i in range(len(qstack))
2106 call g:Xsetlist([], ' ', qstack[i])
2107 endfor
2108 call assert_equal(3, g:Xgetlist({'nr':'$'}).nr)
2109 call assert_equal(10, g:Xgetlist({'nr':1, 'items':1}).items[0].lnum)
2110 call assert_equal(20, g:Xgetlist({'nr':2, 'items':1}).items[0].lnum)
2111 call assert_equal(30, g:Xgetlist({'nr':3, 'items':1}).items[0].lnum)
2112 call g:Xsetlist([], 'f')
2113
2114 " Swap two quickfix lists
2115 Xexpr "File1:10:Line10"
2116 Xexpr "File2:20:Line20"
2117 Xexpr "File3:30:Line30"
2118 call g:Xsetlist([], 'r', {'nr':1,'title':'Colors','context':['Colors']})
2119 call g:Xsetlist([], 'r', {'nr':2,'title':'Fruits','context':['Fruits']})
2120 let l1=g:Xgetlist({'nr':1,'all':1})
2121 let l2=g:Xgetlist({'nr':2,'all':1})
Bram Moolenaara539f4f2017-08-30 20:33:55 +02002122 let save_id = l1.id
2123 let l1.id=l2.id
2124 let l2.id=save_id
Bram Moolenaar6a8958d2017-06-22 21:33:20 +02002125 call g:Xsetlist([], 'r', l1)
2126 call g:Xsetlist([], 'r', l2)
2127 let newl1=g:Xgetlist({'nr':1,'all':1})
2128 let newl2=g:Xgetlist({'nr':2,'all':1})
Bram Moolenaarb4d5fba2017-09-11 19:31:28 +02002129 call assert_equal('Fruits', newl1.title)
Bram Moolenaar6a8958d2017-06-22 21:33:20 +02002130 call assert_equal(['Fruits'], newl1.context)
2131 call assert_equal('Line20', newl1.items[0].text)
Bram Moolenaarb4d5fba2017-09-11 19:31:28 +02002132 call assert_equal('Colors', newl2.title)
Bram Moolenaar6a8958d2017-06-22 21:33:20 +02002133 call assert_equal(['Colors'], newl2.context)
2134 call assert_equal('Line10', newl2.items[0].text)
2135 call g:Xsetlist([], 'f')
Bram Moolenaaree85df32017-03-19 14:19:50 +01002136endfunc
Bram Moolenaard823fa92016-08-12 16:29:27 +02002137
Bram Moolenaar2b946c92016-11-12 18:14:44 +01002138func Test_qf_property()
Bram Moolenaard823fa92016-08-12 16:29:27 +02002139 call Xproperty_tests('c')
2140 call Xproperty_tests('l')
Bram Moolenaaree85df32017-03-19 14:19:50 +01002141endfunc
Bram Moolenaar04c4ce62016-09-01 15:45:58 +02002142
Bram Moolenaar5b69c222019-01-11 14:50:06 +01002143" Test for setting the current index in the location/quickfix list
2144func Xtest_setqfidx(cchar)
2145 call s:setup_commands(a:cchar)
2146
2147 Xgetexpr "F1:10:1:Line1\nF2:20:2:Line2\nF3:30:3:Line3"
2148 Xgetexpr "F4:10:1:Line1\nF5:20:2:Line2\nF6:30:3:Line3"
2149 Xgetexpr "F7:10:1:Line1\nF8:20:2:Line2\nF9:30:3:Line3"
2150
2151 call g:Xsetlist([], 'a', {'nr' : 3, 'idx' : 2})
2152 call g:Xsetlist([], 'a', {'nr' : 2, 'idx' : 2})
2153 call g:Xsetlist([], 'a', {'nr' : 1, 'idx' : 3})
2154 Xolder 2
2155 Xopen
2156 call assert_equal(3, line('.'))
2157 Xnewer
2158 call assert_equal(2, line('.'))
2159 Xnewer
2160 call assert_equal(2, line('.'))
2161 " Update the current index with the quickfix window open
2162 wincmd w
2163 call g:Xsetlist([], 'a', {'nr' : 3, 'idx' : 3})
2164 Xopen
2165 call assert_equal(3, line('.'))
2166 Xclose
2167
2168 " Set the current index to the last entry
2169 call g:Xsetlist([], 'a', {'nr' : 1, 'idx' : '$'})
2170 call assert_equal(3, g:Xgetlist({'nr' : 1, 'idx' : 0}).idx)
2171 " A large value should set the index to the last index
2172 call g:Xsetlist([], 'a', {'nr' : 1, 'idx' : 1})
2173 call g:Xsetlist([], 'a', {'nr' : 1, 'idx' : 999})
2174 call assert_equal(3, g:Xgetlist({'nr' : 1, 'idx' : 0}).idx)
2175 " Invalid index values
2176 call g:Xsetlist([], 'a', {'nr' : 1, 'idx' : -1})
2177 call assert_equal(3, g:Xgetlist({'nr' : 1, 'idx' : 0}).idx)
2178 call g:Xsetlist([], 'a', {'nr' : 1, 'idx' : 0})
2179 call assert_equal(3, g:Xgetlist({'nr' : 1, 'idx' : 0}).idx)
2180 call g:Xsetlist([], 'a', {'nr' : 1, 'idx' : 'xx'})
2181 call assert_equal(3, g:Xgetlist({'nr' : 1, 'idx' : 0}).idx)
2182 call assert_fails("call g:Xsetlist([], 'a', {'nr':1, 'idx':[]})", 'E745:')
2183
2184 call g:Xsetlist([], 'f')
2185 new | only
2186endfunc
2187
2188func Test_setqfidx()
2189 call Xtest_setqfidx('c')
2190 call Xtest_setqfidx('l')
2191endfunc
2192
Bram Moolenaar04c4ce62016-09-01 15:45:58 +02002193" Tests for the QuickFixCmdPre/QuickFixCmdPost autocommands
Bram Moolenaar2b946c92016-11-12 18:14:44 +01002194func QfAutoCmdHandler(loc, cmd)
Bram Moolenaar04c4ce62016-09-01 15:45:58 +02002195 call add(g:acmds, a:loc . a:cmd)
Bram Moolenaar2b946c92016-11-12 18:14:44 +01002196endfunc
Bram Moolenaar04c4ce62016-09-01 15:45:58 +02002197
Bram Moolenaar2b946c92016-11-12 18:14:44 +01002198func Test_Autocmd()
Bram Moolenaar04c4ce62016-09-01 15:45:58 +02002199 autocmd QuickFixCmdPre * call QfAutoCmdHandler('pre', expand('<amatch>'))
2200 autocmd QuickFixCmdPost * call QfAutoCmdHandler('post', expand('<amatch>'))
2201
2202 let g:acmds = []
2203 cexpr "F1:10:Line 10"
2204 caddexpr "F1:20:Line 20"
2205 cgetexpr "F1:30:Line 30"
Bram Moolenaar1ed22762017-11-28 18:03:44 +01002206 cexpr ""
2207 caddexpr ""
2208 cgetexpr ""
2209 silent! cexpr non_existing_func()
2210 silent! caddexpr non_existing_func()
2211 silent! cgetexpr non_existing_func()
Bram Moolenaar04c4ce62016-09-01 15:45:58 +02002212 let l = ['precexpr',
2213 \ 'postcexpr',
2214 \ 'precaddexpr',
2215 \ 'postcaddexpr',
2216 \ 'precgetexpr',
2217 \ 'postcgetexpr',
Bram Moolenaar1ed22762017-11-28 18:03:44 +01002218 \ 'precexpr',
2219 \ 'postcexpr',
2220 \ 'precaddexpr',
2221 \ 'postcaddexpr',
2222 \ 'precgetexpr',
2223 \ 'postcgetexpr',
2224 \ 'precexpr',
2225 \ 'precaddexpr',
2226 \ 'precgetexpr']
2227 call assert_equal(l, g:acmds)
2228
2229 let g:acmds = []
2230 enew! | call append(0, "F2:10:Line 10")
2231 cbuffer!
2232 enew! | call append(0, "F2:20:Line 20")
2233 cgetbuffer
2234 enew! | call append(0, "F2:30:Line 30")
2235 caddbuffer
2236 new
2237 let bnum = bufnr('%')
2238 bunload
2239 exe 'silent! cbuffer! ' . bnum
2240 exe 'silent! cgetbuffer ' . bnum
2241 exe 'silent! caddbuffer ' . bnum
2242 enew!
2243 let l = ['precbuffer',
Bram Moolenaar04c4ce62016-09-01 15:45:58 +02002244 \ 'postcbuffer',
2245 \ 'precgetbuffer',
2246 \ 'postcgetbuffer',
2247 \ 'precaddbuffer',
Bram Moolenaar1ed22762017-11-28 18:03:44 +01002248 \ 'postcaddbuffer',
2249 \ 'precbuffer',
2250 \ 'precgetbuffer',
2251 \ 'precaddbuffer']
Bram Moolenaar04c4ce62016-09-01 15:45:58 +02002252 call assert_equal(l, g:acmds)
Bram Moolenaar1ed22762017-11-28 18:03:44 +01002253
2254 call writefile(['Xtest:1:Line1'], 'Xtest')
2255 call writefile([], 'Xempty')
2256 let g:acmds = []
2257 cfile Xtest
2258 caddfile Xtest
2259 cgetfile Xtest
2260 cfile Xempty
2261 caddfile Xempty
2262 cgetfile Xempty
2263 silent! cfile do_not_exist
2264 silent! caddfile do_not_exist
2265 silent! cgetfile do_not_exist
2266 let l = ['precfile',
2267 \ 'postcfile',
2268 \ 'precaddfile',
2269 \ 'postcaddfile',
2270 \ 'precgetfile',
2271 \ 'postcgetfile',
2272 \ 'precfile',
2273 \ 'postcfile',
2274 \ 'precaddfile',
2275 \ 'postcaddfile',
2276 \ 'precgetfile',
2277 \ 'postcgetfile',
2278 \ 'precfile',
2279 \ 'postcfile',
2280 \ 'precaddfile',
2281 \ 'postcaddfile',
2282 \ 'precgetfile',
2283 \ 'postcgetfile']
2284 call assert_equal(l, g:acmds)
2285
2286 let g:acmds = []
2287 helpgrep quickfix
2288 silent! helpgrep non_existing_help_topic
2289 vimgrep test Xtest
2290 vimgrepadd test Xtest
2291 silent! vimgrep non_existing_test Xtest
2292 silent! vimgrepadd non_existing_test Xtest
2293 set makeprg=
2294 silent! make
2295 set makeprg&
2296 let l = ['prehelpgrep',
2297 \ 'posthelpgrep',
2298 \ 'prehelpgrep',
2299 \ 'posthelpgrep',
2300 \ 'previmgrep',
2301 \ 'postvimgrep',
2302 \ 'previmgrepadd',
2303 \ 'postvimgrepadd',
2304 \ 'previmgrep',
2305 \ 'postvimgrep',
2306 \ 'previmgrepadd',
2307 \ 'postvimgrepadd',
2308 \ 'premake',
2309 \ 'postmake']
2310 call assert_equal(l, g:acmds)
2311
2312 if has('unix')
2313 " Run this test only on Unix-like systems. The grepprg may not be set on
2314 " non-Unix systems.
2315 " The following lines are used for the grep test. Don't remove.
2316 " Grep_Autocmd_Text: Match 1
2317 " GrepAdd_Autocmd_Text: Match 2
2318 let g:acmds = []
2319 silent grep Grep_Autocmd_Text test_quickfix.vim
2320 silent grepadd GrepAdd_Autocmd_Text test_quickfix.vim
2321 silent grep abc123def Xtest
2322 silent grepadd abc123def Xtest
2323 let l = ['pregrep',
2324 \ 'postgrep',
2325 \ 'pregrepadd',
2326 \ 'postgrepadd',
2327 \ 'pregrep',
2328 \ 'postgrep',
2329 \ 'pregrepadd',
2330 \ 'postgrepadd']
2331 call assert_equal(l, g:acmds)
2332 endif
2333
2334 call delete('Xtest')
2335 call delete('Xempty')
Bram Moolenaarb254af32017-12-18 19:48:58 +01002336 au! QuickFixCmdPre
2337 au! QuickFixCmdPost
Bram Moolenaar2b946c92016-11-12 18:14:44 +01002338endfunc
Bram Moolenaar21662be2016-11-06 14:46:44 +01002339
Bram Moolenaar2b946c92016-11-12 18:14:44 +01002340func Test_Autocmd_Exception()
Bram Moolenaar21662be2016-11-06 14:46:44 +01002341 set efm=%m
2342 lgetexpr '?'
2343
2344 try
2345 call DoesNotExit()
2346 catch
2347 lgetexpr '1'
2348 finally
2349 lgetexpr '1'
2350 endtry
2351
2352 call assert_equal('1', getloclist(0)[0].text)
2353
2354 set efm&vim
Bram Moolenaar2b946c92016-11-12 18:14:44 +01002355endfunc
Bram Moolenaar63bed3d2016-11-12 15:36:54 +01002356
Bram Moolenaar2b946c92016-11-12 18:14:44 +01002357func Test_caddbuffer_wrong()
2358 " This used to cause a memory access in freed memory.
Bram Moolenaar63bed3d2016-11-12 15:36:54 +01002359 let save_efm = &efm
2360 set efm=%EEEE%m,%WWWW,%+CCCC%>%#,%GGGG%.#
2361 cgetexpr ['WWWW', 'EEEE', 'CCCC']
2362 let &efm = save_efm
Bram Moolenaar2b946c92016-11-12 18:14:44 +01002363 caddbuffer
Bram Moolenaar63bed3d2016-11-12 15:36:54 +01002364 bwipe!
2365endfunc
Bram Moolenaar2b946c92016-11-12 18:14:44 +01002366
2367func Test_caddexpr_wrong()
2368 " This used to cause a memory access in freed memory.
2369 cbuffer
2370 cbuffer
2371 copen
2372 let save_efm = &efm
2373 set efm=%
2374 call assert_fails('caddexpr ""', 'E376:')
2375 let &efm = save_efm
2376endfunc
Bram Moolenaar7618e002016-11-13 15:09:26 +01002377
2378func Test_dirstack_cleanup()
2379 " This used to cause a memory access in freed memory.
2380 let save_efm = &efm
2381 lexpr '0'
2382 lopen
2383 fun X(c)
2384 let save_efm=&efm
2385 set efm=%D%f
2386 if a:c == 'c'
2387 caddexpr '::'
2388 else
2389 laddexpr ':0:0'
2390 endif
2391 let &efm=save_efm
2392 endfun
2393 call X('c')
2394 call X('l')
2395 call setqflist([], 'r')
2396 caddbuffer
2397 let &efm = save_efm
2398endfunc
Bram Moolenaar391b1dd2017-03-04 13:47:11 +01002399
2400" Tests for jumping to entries from the location list window and quickfix
2401" window
2402func Test_cwindow_jump()
2403 set efm=%f%%%l%%%m
2404 lgetexpr ["F1%10%Line 10", "F2%20%Line 20", "F3%30%Line 30"]
2405 lopen | only
2406 lfirst
2407 call assert_true(winnr('$') == 2)
2408 call assert_true(winnr() == 1)
2409 " Location list for the new window should be set
2410 call assert_true(getloclist(0)[2].text == 'Line 30')
2411
2412 " Open a scratch buffer
2413 " Open a new window and create a location list
2414 " Open the location list window and close the other window
2415 " Jump to an entry.
Bram Moolenaareeb1b9c2019-02-10 22:59:04 +01002416 " Should create a new window and jump to the entry. The scratch buffer
Bram Moolenaar391b1dd2017-03-04 13:47:11 +01002417 " should not be used.
2418 enew | only
2419 set buftype=nofile
2420 below new
2421 lgetexpr ["F1%10%Line 10", "F2%20%Line 20", "F3%30%Line 30"]
2422 lopen
2423 2wincmd c
2424 lnext
2425 call assert_true(winnr('$') == 3)
2426 call assert_true(winnr() == 2)
2427
2428 " Open two windows with two different location lists
2429 " Open the location list window and close the previous window
2430 " Jump to an entry in the location list window
2431 " Should open the file in the first window and not set the location list.
2432 enew | only
2433 lgetexpr ["F1%5%Line 5"]
2434 below new
2435 lgetexpr ["F1%10%Line 10", "F2%20%Line 20", "F3%30%Line 30"]
2436 lopen
2437 2wincmd c
2438 lnext
2439 call assert_true(winnr() == 1)
2440 call assert_true(getloclist(0)[0].text == 'Line 5')
2441
2442 enew | only
2443 cgetexpr ["F1%10%Line 10", "F2%20%Line 20", "F3%30%Line 30"]
2444 copen
2445 cnext
2446 call assert_true(winnr('$') == 2)
2447 call assert_true(winnr() == 1)
2448
2449 enew | only
2450 set efm&vim
2451endfunc
Bram Moolenaaree85df32017-03-19 14:19:50 +01002452
Bram Moolenaare00fdf32019-09-15 19:09:42 +02002453func Test_cwindow_highlight()
2454 CheckScreendump
2455
2456 let lines =<< trim END
2457 set t_u7=
2458 call setline(1, ['some', 'text', 'with', 'matches'])
2459 write XCwindow
2460 vimgrep e XCwindow
2461 redraw
2462 cwindow 4
2463 END
2464 call writefile(lines, 'XtestCwindow')
2465 let buf = RunVimInTerminal('-S XtestCwindow', #{rows: 12})
2466 call VerifyScreenDump(buf, 'Test_quickfix_cwindow_1', {})
2467
2468 call term_sendkeys(buf, ":cnext\<CR>")
2469 call VerifyScreenDump(buf, 'Test_quickfix_cwindow_2', {})
2470
2471 " clean up
2472 call StopVimInTerminal(buf)
2473 call delete('XtestCwindow')
2474 call delete('XCwindow')
2475endfunc
2476
Bram Moolenaaree85df32017-03-19 14:19:50 +01002477func XvimgrepTests(cchar)
2478 call s:setup_commands(a:cchar)
2479
2480 call writefile(['Editor:VIM vim',
2481 \ 'Editor:Emacs EmAcS',
2482 \ 'Editor:Notepad NOTEPAD'], 'Xtestfile1')
2483 call writefile(['Linux', 'MacOS', 'MS-Windows'], 'Xtestfile2')
2484
2485 " Error cases
2486 call assert_fails('Xvimgrep /abc *', 'E682:')
2487
2488 let @/=''
2489 call assert_fails('Xvimgrep // *', 'E35:')
2490
2491 call assert_fails('Xvimgrep abc', 'E683:')
2492 call assert_fails('Xvimgrep a1b2c3 Xtestfile1', 'E480:')
2493 call assert_fails('Xvimgrep pat Xa1b2c3', 'E480:')
2494
2495 Xexpr ""
2496 Xvimgrepadd Notepad Xtestfile1
2497 Xvimgrepadd MacOS Xtestfile2
2498 let l = g:Xgetlist()
2499 call assert_equal(2, len(l))
2500 call assert_equal('Editor:Notepad NOTEPAD', l[0].text)
2501
2502 Xvimgrep #\cvim#g Xtestfile?
2503 let l = g:Xgetlist()
2504 call assert_equal(2, len(l))
2505 call assert_equal(8, l[0].col)
2506 call assert_equal(12, l[1].col)
2507
2508 1Xvimgrep ?Editor? Xtestfile*
2509 let l = g:Xgetlist()
2510 call assert_equal(1, len(l))
2511 call assert_equal('Editor:VIM vim', l[0].text)
2512
2513 edit +3 Xtestfile2
2514 Xvimgrep +\cemacs+j Xtestfile1
2515 let l = g:Xgetlist()
2516 call assert_equal('Xtestfile2', bufname(''))
2517 call assert_equal('Editor:Emacs EmAcS', l[0].text)
2518
Bram Moolenaar2225ebb2018-04-24 15:48:11 +02002519 " Test for unloading a buffer after vimgrep searched the buffer
2520 %bwipe
2521 Xvimgrep /Editor/j Xtestfile*
2522 call assert_equal(0, getbufinfo('Xtestfile1')[0].loaded)
2523 call assert_equal([], getbufinfo('Xtestfile2'))
2524
Bram Moolenaaree85df32017-03-19 14:19:50 +01002525 call delete('Xtestfile1')
2526 call delete('Xtestfile2')
2527endfunc
2528
2529" Tests for the :vimgrep command
2530func Test_vimgrep()
2531 call XvimgrepTests('c')
2532 call XvimgrepTests('l')
2533endfunc
Bram Moolenaar69f40be2017-04-02 15:15:49 +02002534
Bram Moolenaar1c299432018-10-28 14:36:09 +01002535" Test for incsearch highlighting of the :vimgrep pattern
2536" This test used to cause "E315: ml_get: invalid lnum" errors.
2537func Test_vimgrep_incsearch()
2538 enew
2539 set incsearch
2540 call test_override("char_avail", 1)
2541
2542 call feedkeys(":2vimgrep assert test_quickfix.vim test_cdo.vim\<CR>", "ntx")
2543 let l = getqflist()
2544 call assert_equal(2, len(l))
2545
2546 call test_override("ALL", 0)
2547 set noincsearch
2548endfunc
2549
Bram Moolenaar69f40be2017-04-02 15:15:49 +02002550func XfreeTests(cchar)
2551 call s:setup_commands(a:cchar)
2552
2553 enew | only
2554
2555 " Deleting the quickfix stack should work even When the current list is
2556 " somewhere in the middle of the stack
2557 Xexpr ['Xfile1:10:10:Line 10', 'Xfile1:15:15:Line 15']
2558 Xexpr ['Xfile2:20:20:Line 20', 'Xfile2:25:25:Line 25']
2559 Xexpr ['Xfile3:30:30:Line 30', 'Xfile3:35:35:Line 35']
2560 Xolder
2561 call g:Xsetlist([], 'f')
2562 call assert_equal(0, len(g:Xgetlist()))
2563
2564 " After deleting the stack, adding a new list should create a stack with a
2565 " single list.
2566 Xexpr ['Xfile1:10:10:Line 10', 'Xfile1:15:15:Line 15']
2567 call assert_equal(1, g:Xgetlist({'all':1}).nr)
2568
2569 " Deleting the stack from a quickfix window should update/clear the
2570 " quickfix/location list window.
2571 Xexpr ['Xfile1:10:10:Line 10', 'Xfile1:15:15:Line 15']
2572 Xexpr ['Xfile2:20:20:Line 20', 'Xfile2:25:25:Line 25']
2573 Xexpr ['Xfile3:30:30:Line 30', 'Xfile3:35:35:Line 35']
2574 Xolder
2575 Xwindow
2576 call g:Xsetlist([], 'f')
2577 call assert_equal(2, winnr('$'))
2578 call assert_equal(1, line('$'))
2579 Xclose
2580
2581 " Deleting the stack from a non-quickfix window should update/clear the
2582 " quickfix/location list window.
2583 Xexpr ['Xfile1:10:10:Line 10', 'Xfile1:15:15:Line 15']
2584 Xexpr ['Xfile2:20:20:Line 20', 'Xfile2:25:25:Line 25']
2585 Xexpr ['Xfile3:30:30:Line 30', 'Xfile3:35:35:Line 35']
2586 Xolder
2587 Xwindow
2588 wincmd p
2589 call g:Xsetlist([], 'f')
2590 call assert_equal(0, len(g:Xgetlist()))
2591 wincmd p
2592 call assert_equal(2, winnr('$'))
2593 call assert_equal(1, line('$'))
2594
2595 " After deleting the location list stack, if the location list window is
2596 " opened, then a new location list should be created. So opening the
2597 " location list window again should not create a new window.
2598 if a:cchar == 'l'
2599 lexpr ['Xfile1:10:10:Line 10', 'Xfile1:15:15:Line 15']
2600 wincmd p
2601 lopen
2602 call assert_equal(2, winnr('$'))
2603 endif
2604 Xclose
2605endfunc
2606
Bram Moolenaar74240d32017-12-10 15:26:15 +01002607" Tests for the quickfix free functionality
Bram Moolenaar69f40be2017-04-02 15:15:49 +02002608func Test_qf_free()
2609 call XfreeTests('c')
2610 call XfreeTests('l')
2611endfunc
Bram Moolenaar6e62da32017-05-28 08:16:25 +02002612
2613" Test for buffer overflow when parsing lines and adding new entries to
2614" the quickfix list.
2615func Test_bufoverflow()
2616 set efm=%f:%l:%m
2617 cgetexpr ['File1:100:' . repeat('x', 1025)]
2618
2619 set efm=%+GCompiler:\ %.%#,%f:%l:%m
2620 cgetexpr ['Compiler: ' . repeat('a', 1015), 'File1:10:Hello World']
2621
2622 set efm=%DEntering\ directory\ %f,%f:%l:%m
2623 cgetexpr ['Entering directory ' . repeat('a', 1006),
2624 \ 'File1:10:Hello World']
2625 set efm&vim
2626endfunc
2627
Bram Moolenaar875feea2017-06-11 16:07:51 +02002628" Tests for getting the quickfix stack size
2629func XsizeTests(cchar)
2630 call s:setup_commands(a:cchar)
2631
2632 call g:Xsetlist([], 'f')
2633 call assert_equal(0, g:Xgetlist({'nr':'$'}).nr)
Bram Moolenaara6d48492017-12-12 22:45:31 +01002634 call assert_equal('', g:Xgetlist({'nr':'$', 'all':1}).title)
2635 call assert_equal(0, g:Xgetlist({'nr':0}).nr)
Bram Moolenaar875feea2017-06-11 16:07:51 +02002636
2637 Xexpr "File1:10:Line1"
2638 Xexpr "File2:20:Line2"
2639 Xexpr "File3:30:Line3"
2640 Xolder | Xolder
2641 call assert_equal(3, g:Xgetlist({'nr':'$'}).nr)
2642 call g:Xsetlist([], 'f')
2643
2644 Xexpr "File1:10:Line1"
2645 Xexpr "File2:20:Line2"
2646 Xexpr "File3:30:Line3"
2647 Xolder | Xolder
2648 call g:Xsetlist([], 'a', {'nr':'$', 'title':'Compiler'})
2649 call assert_equal('Compiler', g:Xgetlist({'nr':3, 'all':1}).title)
2650endfunc
2651
2652func Test_Qf_Size()
2653 call XsizeTests('c')
2654 call XsizeTests('l')
2655endfunc
Bram Moolenaar18141832017-06-25 21:17:25 +02002656
Bram Moolenaar9c4feff2017-06-28 22:26:54 +02002657func Test_cclose_from_copen()
2658 augroup QF_Test
2659 au!
2660 au FileType qf :call assert_fails(':cclose', 'E788')
2661 augroup END
2662 copen
2663 augroup QF_Test
2664 au!
2665 augroup END
2666 augroup! QF_Test
2667endfunc
2668
Bram Moolenaar18141832017-06-25 21:17:25 +02002669func Test_cclose_in_autocmd()
2670 " Problem is only triggered if "starting" is zero, so that the OptionsSet
2671 " event will be triggered.
2672 call test_override('starting', 1)
2673 augroup QF_Test
2674 au!
2675 au FileType qf :call assert_fails(':cclose', 'E788')
2676 augroup END
2677 copen
2678 augroup QF_Test
2679 au!
2680 augroup END
2681 augroup! QF_Test
2682 call test_override('starting', 0)
2683endfunc
Bram Moolenaar9c4feff2017-06-28 22:26:54 +02002684
Bram Moolenaar379fb762018-08-30 15:58:28 +02002685" Check that ":file" without an argument is possible even when "curbuf_lock"
2686" is set.
2687func Test_file_from_copen()
2688 " Works without argument.
2689 augroup QF_Test
2690 au!
2691 au FileType qf file
2692 augroup END
2693 copen
2694
2695 augroup QF_Test
2696 au!
2697 augroup END
2698 cclose
2699
2700 " Fails with argument.
2701 augroup QF_Test
2702 au!
2703 au FileType qf call assert_fails(':file foo', 'E788')
2704 augroup END
2705 copen
2706 augroup QF_Test
2707 au!
2708 augroup END
2709 cclose
2710
2711 augroup! QF_Test
Bram Moolenaar6a0cc912019-10-26 16:48:44 +02002712endfunc
Bram Moolenaar379fb762018-08-30 15:58:28 +02002713
Bram Moolenaar9c4feff2017-06-28 22:26:54 +02002714func Test_resize_from_copen()
2715 augroup QF_Test
2716 au!
2717 au FileType qf resize 5
2718 augroup END
2719 try
2720 " This should succeed without any exception. No other buffers are
2721 " involved in the autocmd.
2722 copen
2723 finally
2724 augroup QF_Test
2725 au!
2726 augroup END
2727 augroup! QF_Test
2728 endtry
2729endfunc
Bram Moolenaara8788f42017-07-19 17:06:20 +02002730
2731" Tests for the quickfix buffer b:changedtick variable
2732func Xchangedtick_tests(cchar)
2733 call s:setup_commands(a:cchar)
2734
2735 new | only
2736
2737 Xexpr "" | Xexpr "" | Xexpr ""
2738
2739 Xopen
2740 Xolder
2741 Xolder
2742 Xaddexpr "F1:10:Line10"
2743 Xaddexpr "F2:20:Line20"
2744 call g:Xsetlist([{"filename":"F3", "lnum":30, "text":"Line30"}], 'a')
2745 call g:Xsetlist([], 'f')
2746 call assert_equal(8, getbufvar('%', 'changedtick'))
2747 Xclose
2748endfunc
2749
2750func Test_changedtick()
Bram Moolenaarae338332017-08-11 20:25:26 +02002751 call Xchangedtick_tests('c')
2752 call Xchangedtick_tests('l')
2753endfunc
2754
2755" Tests for parsing an expression using setqflist()
2756func Xsetexpr_tests(cchar)
2757 call s:setup_commands(a:cchar)
2758
2759 let t = ["File1:10:Line10", "File1:20:Line20"]
Bram Moolenaar2c809b72017-09-01 18:34:02 +02002760 call g:Xsetlist([], ' ', {'lines' : t})
2761 call g:Xsetlist([], 'a', {'lines' : ["File1:30:Line30"]})
Bram Moolenaarae338332017-08-11 20:25:26 +02002762
2763 let l = g:Xgetlist()
2764 call assert_equal(3, len(l))
2765 call assert_equal(20, l[1].lnum)
2766 call assert_equal('Line30', l[2].text)
Bram Moolenaar2c809b72017-09-01 18:34:02 +02002767 call g:Xsetlist([], 'r', {'lines' : ["File2:5:Line5"]})
Bram Moolenaarae338332017-08-11 20:25:26 +02002768 let l = g:Xgetlist()
2769 call assert_equal(1, len(l))
2770 call assert_equal('Line5', l[0].text)
Bram Moolenaar2c809b72017-09-01 18:34:02 +02002771 call assert_equal(-1, g:Xsetlist([], 'a', {'lines' : 10}))
2772 call assert_equal(-1, g:Xsetlist([], 'a', {'lines' : "F1:10:L10"}))
Bram Moolenaarae338332017-08-11 20:25:26 +02002773
2774 call g:Xsetlist([], 'f')
2775 " Add entries to multiple lists
Bram Moolenaar2c809b72017-09-01 18:34:02 +02002776 call g:Xsetlist([], 'a', {'nr' : 1, 'lines' : ["File1:10:Line10"]})
2777 call g:Xsetlist([], 'a', {'nr' : 2, 'lines' : ["File2:20:Line20"]})
2778 call g:Xsetlist([], 'a', {'nr' : 1, 'lines' : ["File1:15:Line15"]})
2779 call g:Xsetlist([], 'a', {'nr' : 2, 'lines' : ["File2:25:Line25"]})
Bram Moolenaarae338332017-08-11 20:25:26 +02002780 call assert_equal('Line15', g:Xgetlist({'nr':1, 'items':1}).items[1].text)
2781 call assert_equal('Line25', g:Xgetlist({'nr':2, 'items':1}).items[1].text)
Bram Moolenaar36538222017-09-02 19:51:44 +02002782
2783 " Adding entries using a custom efm
2784 set efm&
2785 call g:Xsetlist([], ' ', {'efm' : '%f#%l#%m',
2786 \ 'lines' : ["F1#10#L10", "F2#20#L20"]})
2787 call assert_equal(20, g:Xgetlist({'items':1}).items[1].lnum)
2788 call g:Xsetlist([], 'a', {'efm' : '%f#%l#%m', 'lines' : ["F3:30:L30"]})
2789 call assert_equal('F3:30:L30', g:Xgetlist({'items':1}).items[2].text)
2790 call assert_equal(20, g:Xgetlist({'items':1}).items[1].lnum)
2791 call assert_equal(-1, g:Xsetlist([], 'a', {'efm' : [],
2792 \ 'lines' : ['F1:10:L10']}))
Bram Moolenaarae338332017-08-11 20:25:26 +02002793endfunc
2794
2795func Test_setexpr()
2796 call Xsetexpr_tests('c')
2797 call Xsetexpr_tests('l')
2798endfunc
2799
2800" Tests for per quickfix/location list directory stack
2801func Xmultidirstack_tests(cchar)
2802 call s:setup_commands(a:cchar)
2803
2804 call g:Xsetlist([], 'f')
2805 Xexpr "" | Xexpr ""
2806
Bram Moolenaar2c809b72017-09-01 18:34:02 +02002807 call g:Xsetlist([], 'a', {'nr' : 1, 'lines' : ["Entering dir 'Xone/a'"]})
2808 call g:Xsetlist([], 'a', {'nr' : 2, 'lines' : ["Entering dir 'Xtwo/a'"]})
2809 call g:Xsetlist([], 'a', {'nr' : 1, 'lines' : ["one.txt:3:one one one"]})
2810 call g:Xsetlist([], 'a', {'nr' : 2, 'lines' : ["two.txt:5:two two two"]})
Bram Moolenaarae338332017-08-11 20:25:26 +02002811
2812 let l1 = g:Xgetlist({'nr':1, 'items':1})
2813 let l2 = g:Xgetlist({'nr':2, 'items':1})
2814 call assert_equal('Xone/a/one.txt', bufname(l1.items[1].bufnr))
2815 call assert_equal(3, l1.items[1].lnum)
2816 call assert_equal('Xtwo/a/two.txt', bufname(l2.items[1].bufnr))
2817 call assert_equal(5, l2.items[1].lnum)
2818endfunc
2819
2820func Test_multidirstack()
2821 call mkdir('Xone/a', 'p')
2822 call mkdir('Xtwo/a', 'p')
2823 let lines = ['1', '2', 'one one one', '4', 'two two two', '6', '7']
2824 call writefile(lines, 'Xone/a/one.txt')
2825 call writefile(lines, 'Xtwo/a/two.txt')
2826 let save_efm = &efm
2827 set efm=%DEntering\ dir\ '%f',%f:%l:%m,%XLeaving\ dir\ '%f'
2828
2829 call Xmultidirstack_tests('c')
2830 call Xmultidirstack_tests('l')
2831
2832 let &efm = save_efm
2833 call delete('Xone', 'rf')
2834 call delete('Xtwo', 'rf')
2835endfunc
2836
2837" Tests for per quickfix/location list file stack
2838func Xmultifilestack_tests(cchar)
2839 call s:setup_commands(a:cchar)
2840
2841 call g:Xsetlist([], 'f')
2842 Xexpr "" | Xexpr ""
2843
Bram Moolenaar2c809b72017-09-01 18:34:02 +02002844 call g:Xsetlist([], 'a', {'nr' : 1, 'lines' : ["[one.txt]"]})
2845 call g:Xsetlist([], 'a', {'nr' : 2, 'lines' : ["[two.txt]"]})
2846 call g:Xsetlist([], 'a', {'nr' : 1, 'lines' : ["(3,5) one one one"]})
2847 call g:Xsetlist([], 'a', {'nr' : 2, 'lines' : ["(5,9) two two two"]})
Bram Moolenaarae338332017-08-11 20:25:26 +02002848
2849 let l1 = g:Xgetlist({'nr':1, 'items':1})
2850 let l2 = g:Xgetlist({'nr':2, 'items':1})
2851 call assert_equal('one.txt', bufname(l1.items[1].bufnr))
2852 call assert_equal(3, l1.items[1].lnum)
2853 call assert_equal('two.txt', bufname(l2.items[1].bufnr))
2854 call assert_equal(5, l2.items[1].lnum)
Bram Moolenaare333e792018-04-08 13:27:39 +02002855
2856 " Test for start of a new error line in the same line where a previous
2857 " error line ends with a file stack.
2858 let efm_val = 'Error\ l%l\ in\ %f,'
2859 let efm_val .= '%-P%>(%f%r,Error\ l%l\ in\ %m,%-Q)%r'
2860 let l = g:Xgetlist({'lines' : [
2861 \ '(one.txt',
2862 \ 'Error l4 in one.txt',
2863 \ ') (two.txt',
2864 \ 'Error l6 in two.txt',
2865 \ ')',
2866 \ 'Error l8 in one.txt'
2867 \ ], 'efm' : efm_val})
2868 call assert_equal(3, len(l.items))
2869 call assert_equal('one.txt', bufname(l.items[0].bufnr))
2870 call assert_equal(4, l.items[0].lnum)
2871 call assert_equal('one.txt', l.items[0].text)
2872 call assert_equal('two.txt', bufname(l.items[1].bufnr))
2873 call assert_equal(6, l.items[1].lnum)
2874 call assert_equal('two.txt', l.items[1].text)
2875 call assert_equal('one.txt', bufname(l.items[2].bufnr))
2876 call assert_equal(8, l.items[2].lnum)
2877 call assert_equal('', l.items[2].text)
Bram Moolenaarae338332017-08-11 20:25:26 +02002878endfunc
2879
2880func Test_multifilestack()
2881 let lines = ['1', '2', 'one one one', '4', 'two two two', '6', '7']
2882 call writefile(lines, 'one.txt')
2883 call writefile(lines, 'two.txt')
2884 let save_efm = &efm
2885 set efm=%+P[%f],(%l\\,%c)\ %m,%-Q
2886
2887 call Xmultifilestack_tests('c')
2888 call Xmultifilestack_tests('l')
2889
2890 let &efm = save_efm
2891 call delete('one.txt')
2892 call delete('two.txt')
2893endfunc
2894
2895" Tests for per buffer 'efm' setting
2896func Test_perbuf_efm()
2897 call writefile(["File1-10-Line10"], 'one.txt')
2898 call writefile(["File2#20#Line20"], 'two.txt')
2899 set efm=%f#%l#%m
2900 new | only
2901 new
2902 setlocal efm=%f-%l-%m
2903 cfile one.txt
2904 wincmd w
2905 caddfile two.txt
2906
2907 let l = getqflist()
2908 call assert_equal(10, l[0].lnum)
2909 call assert_equal('Line20', l[1].text)
2910
2911 set efm&
2912 new | only
2913 call delete('one.txt')
2914 call delete('two.txt')
Bram Moolenaara8788f42017-07-19 17:06:20 +02002915endfunc
Bram Moolenaard28cc3f2017-07-27 22:03:50 +02002916
2917" Open multiple help windows using ":lhelpgrep
2918" This test used to crash Vim
2919func Test_Multi_LL_Help()
2920 new | only
2921 lhelpgrep window
2922 lopen
2923 e#
2924 lhelpgrep buffer
2925 call assert_equal(3, winnr('$'))
2926 call assert_true(len(getloclist(1)) != 0)
2927 call assert_true(len(getloclist(2)) != 0)
2928 new | only
2929endfunc
Bram Moolenaar55b69262017-08-13 13:42:01 +02002930
2931" Tests for adding new quickfix lists using setqflist()
2932func XaddQf_tests(cchar)
2933 call s:setup_commands(a:cchar)
2934
2935 " Create a new list using ' ' for action
2936 call g:Xsetlist([], 'f')
2937 call g:Xsetlist([], ' ', {'title' : 'Test1'})
2938 let l = g:Xgetlist({'nr' : '$', 'all' : 1})
2939 call assert_equal(1, l.nr)
2940 call assert_equal('Test1', l.title)
2941
2942 " Create a new list using ' ' for action and '$' for 'nr'
2943 call g:Xsetlist([], 'f')
2944 call g:Xsetlist([], ' ', {'title' : 'Test2', 'nr' : '$'})
2945 let l = g:Xgetlist({'nr' : '$', 'all' : 1})
2946 call assert_equal(1, l.nr)
2947 call assert_equal('Test2', l.title)
2948
2949 " Create a new list using 'a' for action
2950 call g:Xsetlist([], 'f')
2951 call g:Xsetlist([], 'a', {'title' : 'Test3'})
2952 let l = g:Xgetlist({'nr' : '$', 'all' : 1})
2953 call assert_equal(1, l.nr)
2954 call assert_equal('Test3', l.title)
2955
2956 " Create a new list using 'a' for action and '$' for 'nr'
2957 call g:Xsetlist([], 'f')
2958 call g:Xsetlist([], 'a', {'title' : 'Test3', 'nr' : '$'})
2959 call g:Xsetlist([], 'a', {'title' : 'Test4'})
2960 let l = g:Xgetlist({'nr' : '$', 'all' : 1})
2961 call assert_equal(1, l.nr)
2962 call assert_equal('Test4', l.title)
2963
2964 " Adding a quickfix list should remove all the lists following the current
2965 " list.
2966 Xexpr "" | Xexpr "" | Xexpr ""
2967 silent! 10Xolder
2968 call g:Xsetlist([], ' ', {'title' : 'Test5'})
2969 let l = g:Xgetlist({'nr' : '$', 'all' : 1})
2970 call assert_equal(2, l.nr)
2971 call assert_equal('Test5', l.title)
2972
2973 " Add a quickfix list using '$' as the list number.
2974 let lastqf = g:Xgetlist({'nr':'$'}).nr
2975 silent! 99Xolder
2976 call g:Xsetlist([], ' ', {'nr' : '$', 'title' : 'Test6'})
2977 let l = g:Xgetlist({'nr' : '$', 'all' : 1})
2978 call assert_equal(lastqf + 1, l.nr)
2979 call assert_equal('Test6', l.title)
2980
2981 " Add a quickfix list using 'nr' set to one more than the quickfix
2982 " list size.
2983 let lastqf = g:Xgetlist({'nr':'$'}).nr
2984 silent! 99Xolder
2985 call g:Xsetlist([], ' ', {'nr' : lastqf + 1, 'title' : 'Test7'})
2986 let l = g:Xgetlist({'nr' : '$', 'all' : 1})
2987 call assert_equal(lastqf + 1, l.nr)
2988 call assert_equal('Test7', l.title)
2989
2990 " Add a quickfix list to a stack with 10 lists using 'nr' set to '$'
2991 exe repeat('Xexpr "" |', 9) . 'Xexpr ""'
2992 silent! 99Xolder
2993 call g:Xsetlist([], ' ', {'nr' : '$', 'title' : 'Test8'})
2994 let l = g:Xgetlist({'nr' : '$', 'all' : 1})
2995 call assert_equal(10, l.nr)
2996 call assert_equal('Test8', l.title)
2997
2998 " Add a quickfix list using 'nr' set to a value greater than 10
2999 call assert_equal(-1, g:Xsetlist([], ' ', {'nr' : 12, 'title' : 'Test9'}))
3000
3001 " Try adding a quickfix list with 'nr' set to a value greater than the
3002 " quickfix list size but less than 10.
3003 call g:Xsetlist([], 'f')
3004 Xexpr "" | Xexpr "" | Xexpr ""
3005 silent! 99Xolder
3006 call assert_equal(-1, g:Xsetlist([], ' ', {'nr' : 8, 'title' : 'Test10'}))
3007
3008 " Add a quickfix list using 'nr' set to a some string or list
3009 call assert_equal(-1, g:Xsetlist([], ' ', {'nr' : [1,2], 'title' : 'Test11'}))
3010endfunc
3011
3012func Test_add_qf()
3013 call XaddQf_tests('c')
3014 call XaddQf_tests('l')
3015endfunc
Bram Moolenaar7adf06f2017-08-27 15:23:41 +02003016
3017" Test for getting the quickfix list items from some text without modifying
3018" the quickfix stack
Bram Moolenaar2c809b72017-09-01 18:34:02 +02003019func XgetListFromLines(cchar)
Bram Moolenaar7adf06f2017-08-27 15:23:41 +02003020 call s:setup_commands(a:cchar)
3021 call g:Xsetlist([], 'f')
3022
Bram Moolenaar2c809b72017-09-01 18:34:02 +02003023 let l = g:Xgetlist({'lines' : ["File2:20:Line20", "File2:30:Line30"]}).items
Bram Moolenaar7adf06f2017-08-27 15:23:41 +02003024 call assert_equal(2, len(l))
3025 call assert_equal(30, l[1].lnum)
3026
Bram Moolenaar2c809b72017-09-01 18:34:02 +02003027 call assert_equal({}, g:Xgetlist({'lines' : 10}))
3028 call assert_equal({}, g:Xgetlist({'lines' : 'File1:10:Line10'}))
3029 call assert_equal([], g:Xgetlist({'lines' : []}).items)
3030 call assert_equal([], g:Xgetlist({'lines' : [10, 20]}).items)
Bram Moolenaar7adf06f2017-08-27 15:23:41 +02003031
Bram Moolenaar36538222017-09-02 19:51:44 +02003032 " Parse text using a custom efm
3033 set efm&
3034 let l = g:Xgetlist({'lines':['File3#30#Line30'], 'efm' : '%f#%l#%m'}).items
3035 call assert_equal('Line30', l[0].text)
3036 let l = g:Xgetlist({'lines':['File3:30:Line30'], 'efm' : '%f-%l-%m'}).items
3037 call assert_equal('File3:30:Line30', l[0].text)
3038 let l = g:Xgetlist({'lines':['File3:30:Line30'], 'efm' : [1,2]})
3039 call assert_equal({}, l)
3040 call assert_fails("call g:Xgetlist({'lines':['abc'], 'efm':'%2'})", 'E376:')
3041 call assert_fails("call g:Xgetlist({'lines':['abc'], 'efm':''})", 'E378:')
3042
Bram Moolenaar7adf06f2017-08-27 15:23:41 +02003043 " Make sure that the quickfix stack is not modified
3044 call assert_equal(0, g:Xgetlist({'nr' : '$'}).nr)
3045endfunc
3046
Bram Moolenaar2c809b72017-09-01 18:34:02 +02003047func Test_get_list_from_lines()
3048 call XgetListFromLines('c')
3049 call XgetListFromLines('l')
Bram Moolenaar7adf06f2017-08-27 15:23:41 +02003050endfunc
Bram Moolenaara539f4f2017-08-30 20:33:55 +02003051
3052" Tests for the quickfix list id
3053func Xqfid_tests(cchar)
3054 call s:setup_commands(a:cchar)
3055
3056 call g:Xsetlist([], 'f')
Bram Moolenaara6d48492017-12-12 22:45:31 +01003057 call assert_equal(0, g:Xgetlist({'id':0}).id)
Bram Moolenaara539f4f2017-08-30 20:33:55 +02003058 Xexpr ''
3059 let start_id = g:Xgetlist({'id' : 0}).id
3060 Xexpr '' | Xexpr ''
3061 Xolder
3062 call assert_equal(start_id, g:Xgetlist({'id':0, 'nr':1}).id)
3063 call assert_equal(start_id + 1, g:Xgetlist({'id':0, 'nr':0}).id)
3064 call assert_equal(start_id + 2, g:Xgetlist({'id':0, 'nr':'$'}).id)
Bram Moolenaara6d48492017-12-12 22:45:31 +01003065 call assert_equal(0, g:Xgetlist({'id':0, 'nr':99}).id)
Bram Moolenaara539f4f2017-08-30 20:33:55 +02003066 call assert_equal(2, g:Xgetlist({'id':start_id + 1, 'nr':0}).nr)
Bram Moolenaara6d48492017-12-12 22:45:31 +01003067 call assert_equal(0, g:Xgetlist({'id':99, 'nr':0}).id)
3068 call assert_equal(0, g:Xgetlist({'id':"abc", 'nr':0}).id)
Bram Moolenaara539f4f2017-08-30 20:33:55 +02003069
3070 call g:Xsetlist([], 'a', {'id':start_id, 'context':[1,2]})
3071 call assert_equal([1,2], g:Xgetlist({'nr':1, 'context':1}).context)
Bram Moolenaar2c809b72017-09-01 18:34:02 +02003072 call g:Xsetlist([], 'a', {'id':start_id+1, 'lines':['F1:10:L10']})
Bram Moolenaara539f4f2017-08-30 20:33:55 +02003073 call assert_equal('L10', g:Xgetlist({'nr':2, 'items':1}).items[0].text)
3074 call assert_equal(-1, g:Xsetlist([], 'a', {'id':999, 'title':'Vim'}))
3075 call assert_equal(-1, g:Xsetlist([], 'a', {'id':'abc', 'title':'Vim'}))
3076
3077 let qfid = g:Xgetlist({'id':0, 'nr':0})
3078 call g:Xsetlist([], 'f')
Bram Moolenaara6d48492017-12-12 22:45:31 +01003079 call assert_equal(0, g:Xgetlist({'id':qfid, 'nr':0}).id)
Bram Moolenaara539f4f2017-08-30 20:33:55 +02003080endfunc
3081
3082func Test_qf_id()
3083 call Xqfid_tests('c')
3084 call Xqfid_tests('l')
3085endfunc
Bram Moolenaar74240d32017-12-10 15:26:15 +01003086
3087func Xqfjump_tests(cchar)
3088 call s:setup_commands(a:cchar)
3089
3090 call writefile(["Line1\tFoo", "Line2"], 'F1')
3091 call writefile(["Line1\tBar", "Line2"], 'F2')
3092 call writefile(["Line1\tBaz", "Line2"], 'F3')
3093
3094 call g:Xsetlist([], 'f')
3095
3096 " Tests for
3097 " Jumping to a line using a pattern
3098 " Jumping to a column greater than the last column in a line
3099 " Jumping to a line greater than the last line in the file
3100 let l = []
3101 for i in range(1, 7)
3102 call add(l, {})
3103 endfor
3104 let l[0].filename='F1'
3105 let l[0].pattern='Line1'
3106 let l[1].filename='F2'
3107 let l[1].pattern='Line1'
3108 let l[2].filename='F3'
3109 let l[2].pattern='Line1'
3110 let l[3].filename='F3'
3111 let l[3].lnum=1
3112 let l[3].col=9
3113 let l[3].vcol=1
3114 let l[4].filename='F3'
3115 let l[4].lnum=99
3116 let l[5].filename='F3'
3117 let l[5].lnum=1
3118 let l[5].col=99
3119 let l[5].vcol=1
3120 let l[6].filename='F3'
3121 let l[6].pattern='abcxyz'
3122
3123 call g:Xsetlist([], ' ', {'items' : l})
3124 Xopen | only
3125 2Xnext
3126 call assert_equal(3, g:Xgetlist({'idx' : 0}).idx)
3127 call assert_equal('F3', bufname('%'))
3128 Xnext
3129 call assert_equal(7, col('.'))
3130 Xnext
3131 call assert_equal(2, line('.'))
3132 Xnext
3133 call assert_equal(9, col('.'))
3134 2
3135 Xnext
3136 call assert_equal(2, line('.'))
3137
3138 if a:cchar == 'l'
3139 " When jumping to a location list entry in the location list window and
3140 " no usable windows are available, then a new window should be opened.
3141 enew! | new | only
3142 call g:Xsetlist([], 'f')
3143 setlocal buftype=nofile
3144 new
3145 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']})
3146 Xopen
3147 let winid = win_getid()
3148 wincmd p
3149 close
3150 call win_gotoid(winid)
3151 Xnext
3152 call assert_equal(3, winnr('$'))
3153 call assert_equal(1, winnr())
3154 call assert_equal(2, line('.'))
3155
3156 " When jumping to an entry in the location list window and the window
3157 " associated with the location list is not present and a window containing
3158 " the file is already present, then that window should be used.
3159 close
3160 belowright new
3161 call g:Xsetlist([], 'f')
3162 edit F3
3163 call win_gotoid(winid)
3164 Xlast
3165 call assert_equal(3, winnr())
3166 call assert_equal(6, g:Xgetlist({'size' : 1}).size)
3167 call assert_equal(winid, g:Xgetlist({'winid' : 1}).winid)
3168 endif
3169
3170 " Cleanup
3171 enew!
3172 new | only
3173
3174 call delete('F1')
3175 call delete('F2')
3176 call delete('F3')
3177endfunc
3178
3179func Test_qfjump()
3180 call Xqfjump_tests('c')
3181 call Xqfjump_tests('l')
3182endfunc
Bram Moolenaara6d48492017-12-12 22:45:31 +01003183
3184" Tests for the getqflist() and getloclist() functions when the list is not
3185" present or is empty
3186func Xgetlist_empty_tests(cchar)
3187 call s:setup_commands(a:cchar)
3188
3189 " Empty quickfix stack
3190 call g:Xsetlist([], 'f')
3191 call assert_equal('', g:Xgetlist({'context' : 0}).context)
3192 call assert_equal(0, g:Xgetlist({'id' : 0}).id)
3193 call assert_equal(0, g:Xgetlist({'idx' : 0}).idx)
3194 call assert_equal([], g:Xgetlist({'items' : 0}).items)
3195 call assert_equal(0, g:Xgetlist({'nr' : 0}).nr)
3196 call assert_equal(0, g:Xgetlist({'size' : 0}).size)
3197 call assert_equal('', g:Xgetlist({'title' : 0}).title)
3198 call assert_equal(0, g:Xgetlist({'winid' : 0}).winid)
Bram Moolenaarb254af32017-12-18 19:48:58 +01003199 call assert_equal(0, g:Xgetlist({'changedtick' : 0}).changedtick)
Bram Moolenaarc9cc9c72018-09-02 15:18:42 +02003200 if a:cchar == 'c'
3201 call assert_equal({'context' : '', 'id' : 0, 'idx' : 0,
Bram Moolenaar647e24b2019-03-17 16:39:46 +01003202 \ 'items' : [], 'nr' : 0, 'size' : 0, 'qfbufnr' : 0,
Bram Moolenaarc9cc9c72018-09-02 15:18:42 +02003203 \ 'title' : '', 'winid' : 0, 'changedtick': 0},
3204 \ g:Xgetlist({'all' : 0}))
3205 else
3206 call assert_equal({'context' : '', 'id' : 0, 'idx' : 0,
3207 \ 'items' : [], 'nr' : 0, 'size' : 0, 'title' : '',
Bram Moolenaar647e24b2019-03-17 16:39:46 +01003208 \ 'winid' : 0, 'changedtick': 0, 'filewinid' : 0,
3209 \ 'qfbufnr' : 0},
Bram Moolenaarc9cc9c72018-09-02 15:18:42 +02003210 \ g:Xgetlist({'all' : 0}))
3211 endif
Bram Moolenaara6d48492017-12-12 22:45:31 +01003212
Bram Moolenaar2ec364e2018-01-27 11:52:13 +01003213 " Quickfix window with empty stack
3214 silent! Xopen
3215 let qfwinid = (a:cchar == 'c') ? win_getid() : 0
Bram Moolenaar647e24b2019-03-17 16:39:46 +01003216 let qfbufnr = (a:cchar == 'c') ? bufnr('') : 0
Bram Moolenaar2ec364e2018-01-27 11:52:13 +01003217 call assert_equal(qfwinid, g:Xgetlist({'winid' : 0}).winid)
3218 Xclose
3219
Bram Moolenaara6d48492017-12-12 22:45:31 +01003220 " Empty quickfix list
3221 Xexpr ""
3222 call assert_equal('', g:Xgetlist({'context' : 0}).context)
3223 call assert_notequal(0, g:Xgetlist({'id' : 0}).id)
3224 call assert_equal(0, g:Xgetlist({'idx' : 0}).idx)
3225 call assert_equal([], g:Xgetlist({'items' : 0}).items)
3226 call assert_notequal(0, g:Xgetlist({'nr' : 0}).nr)
3227 call assert_equal(0, g:Xgetlist({'size' : 0}).size)
3228 call assert_notequal('', g:Xgetlist({'title' : 0}).title)
3229 call assert_equal(0, g:Xgetlist({'winid' : 0}).winid)
Bram Moolenaarb254af32017-12-18 19:48:58 +01003230 call assert_equal(1, g:Xgetlist({'changedtick' : 0}).changedtick)
Bram Moolenaara6d48492017-12-12 22:45:31 +01003231
3232 let qfid = g:Xgetlist({'id' : 0}).id
3233 call g:Xsetlist([], 'f')
3234
3235 " Non-existing quickfix identifier
3236 call assert_equal('', g:Xgetlist({'id' : qfid, 'context' : 0}).context)
3237 call assert_equal(0, g:Xgetlist({'id' : qfid}).id)
3238 call assert_equal(0, g:Xgetlist({'id' : qfid, 'idx' : 0}).idx)
3239 call assert_equal([], g:Xgetlist({'id' : qfid, 'items' : 0}).items)
3240 call assert_equal(0, g:Xgetlist({'id' : qfid, 'nr' : 0}).nr)
3241 call assert_equal(0, g:Xgetlist({'id' : qfid, 'size' : 0}).size)
3242 call assert_equal('', g:Xgetlist({'id' : qfid, 'title' : 0}).title)
3243 call assert_equal(0, g:Xgetlist({'id' : qfid, 'winid' : 0}).winid)
Bram Moolenaarb254af32017-12-18 19:48:58 +01003244 call assert_equal(0, g:Xgetlist({'id' : qfid, 'changedtick' : 0}).changedtick)
Bram Moolenaarc9cc9c72018-09-02 15:18:42 +02003245 if a:cchar == 'c'
3246 call assert_equal({'context' : '', 'id' : 0, 'idx' : 0, 'items' : [],
3247 \ 'nr' : 0, 'size' : 0, 'title' : '', 'winid' : 0,
Bram Moolenaar647e24b2019-03-17 16:39:46 +01003248 \ 'qfbufnr' : qfbufnr,
Bram Moolenaarc9cc9c72018-09-02 15:18:42 +02003249 \ 'changedtick' : 0}, g:Xgetlist({'id' : qfid, 'all' : 0}))
3250 else
3251 call assert_equal({'context' : '', 'id' : 0, 'idx' : 0, 'items' : [],
3252 \ 'nr' : 0, 'size' : 0, 'title' : '', 'winid' : 0,
Bram Moolenaar647e24b2019-03-17 16:39:46 +01003253 \ 'changedtick' : 0, 'filewinid' : 0, 'qfbufnr' : 0},
Bram Moolenaarc9cc9c72018-09-02 15:18:42 +02003254 \ g:Xgetlist({'id' : qfid, 'all' : 0}))
3255 endif
Bram Moolenaara6d48492017-12-12 22:45:31 +01003256
3257 " Non-existing quickfix list number
3258 call assert_equal('', g:Xgetlist({'nr' : 5, 'context' : 0}).context)
3259 call assert_equal(0, g:Xgetlist({'nr' : 5}).nr)
3260 call assert_equal(0, g:Xgetlist({'nr' : 5, 'idx' : 0}).idx)
3261 call assert_equal([], g:Xgetlist({'nr' : 5, 'items' : 0}).items)
3262 call assert_equal(0, g:Xgetlist({'nr' : 5, 'id' : 0}).id)
3263 call assert_equal(0, g:Xgetlist({'nr' : 5, 'size' : 0}).size)
3264 call assert_equal('', g:Xgetlist({'nr' : 5, 'title' : 0}).title)
3265 call assert_equal(0, g:Xgetlist({'nr' : 5, 'winid' : 0}).winid)
Bram Moolenaarb254af32017-12-18 19:48:58 +01003266 call assert_equal(0, g:Xgetlist({'nr' : 5, 'changedtick' : 0}).changedtick)
Bram Moolenaarc9cc9c72018-09-02 15:18:42 +02003267 if a:cchar == 'c'
3268 call assert_equal({'context' : '', 'id' : 0, 'idx' : 0, 'items' : [],
3269 \ 'nr' : 0, 'size' : 0, 'title' : '', 'winid' : 0,
Bram Moolenaar647e24b2019-03-17 16:39:46 +01003270 \ 'changedtick' : 0, 'qfbufnr' : qfbufnr},
3271 \ g:Xgetlist({'nr' : 5, 'all' : 0}))
Bram Moolenaarc9cc9c72018-09-02 15:18:42 +02003272 else
3273 call assert_equal({'context' : '', 'id' : 0, 'idx' : 0, 'items' : [],
3274 \ 'nr' : 0, 'size' : 0, 'title' : '', 'winid' : 0,
Bram Moolenaar647e24b2019-03-17 16:39:46 +01003275 \ 'changedtick' : 0, 'filewinid' : 0, 'qfbufnr' : 0},
Bram Moolenaarc9cc9c72018-09-02 15:18:42 +02003276 \ g:Xgetlist({'nr' : 5, 'all' : 0}))
3277 endif
Bram Moolenaara6d48492017-12-12 22:45:31 +01003278endfunc
3279
3280func Test_getqflist()
3281 call Xgetlist_empty_tests('c')
3282 call Xgetlist_empty_tests('l')
3283endfunc
Bram Moolenaarb254af32017-12-18 19:48:58 +01003284
Bram Moolenaara0ca7d02017-12-19 10:22:19 +01003285func Test_getqflist_invalid_nr()
3286 " The following commands used to crash Vim
3287 cexpr ""
3288 call getqflist({'nr' : $XXX_DOES_NOT_EXIST_XXX})
3289
3290 " Cleanup
3291 call setqflist([], 'r')
3292endfunc
3293
Bram Moolenaarb254af32017-12-18 19:48:58 +01003294" Tests for the quickfix/location list changedtick
3295func Xqftick_tests(cchar)
3296 call s:setup_commands(a:cchar)
3297
3298 call g:Xsetlist([], 'f')
3299
3300 Xexpr "F1:10:Line10"
3301 let qfid = g:Xgetlist({'id' : 0}).id
3302 call assert_equal(1, g:Xgetlist({'changedtick' : 0}).changedtick)
3303 Xaddexpr "F2:20:Line20\nF2:21:Line21"
3304 call assert_equal(2, g:Xgetlist({'changedtick' : 0}).changedtick)
3305 call g:Xsetlist([], 'a', {'lines' : ["F3:30:Line30", "F3:31:Line31"]})
3306 call assert_equal(3, g:Xgetlist({'changedtick' : 0}).changedtick)
3307 call g:Xsetlist([], 'r', {'lines' : ["F4:40:Line40"]})
3308 call assert_equal(4, g:Xgetlist({'changedtick' : 0}).changedtick)
3309 call g:Xsetlist([], 'a', {'title' : 'New Title'})
3310 call assert_equal(5, g:Xgetlist({'changedtick' : 0}).changedtick)
3311
3312 enew!
3313 call append(0, ["F5:50:L50", "F6:60:L60"])
3314 Xaddbuffer
3315 call assert_equal(6, g:Xgetlist({'changedtick' : 0}).changedtick)
3316 enew!
3317
3318 call g:Xsetlist([], 'a', {'context' : {'bus' : 'pci'}})
3319 call assert_equal(7, g:Xgetlist({'changedtick' : 0}).changedtick)
3320 call g:Xsetlist([{'filename' : 'F7', 'lnum' : 10, 'text' : 'L7'},
3321 \ {'filename' : 'F7', 'lnum' : 11, 'text' : 'L11'}], 'a')
3322 call assert_equal(8, g:Xgetlist({'changedtick' : 0}).changedtick)
3323 call g:Xsetlist([{'filename' : 'F7', 'lnum' : 10, 'text' : 'L7'},
3324 \ {'filename' : 'F7', 'lnum' : 11, 'text' : 'L11'}], ' ')
3325 call assert_equal(1, g:Xgetlist({'changedtick' : 0}).changedtick)
3326 call g:Xsetlist([{'filename' : 'F7', 'lnum' : 10, 'text' : 'L7'},
3327 \ {'filename' : 'F7', 'lnum' : 11, 'text' : 'L11'}], 'r')
3328 call assert_equal(2, g:Xgetlist({'changedtick' : 0}).changedtick)
3329
3330 call writefile(["F8:80:L80", "F8:81:L81"], "Xone")
3331 Xfile Xone
3332 call assert_equal(1, g:Xgetlist({'changedtick' : 0}).changedtick)
3333 Xaddfile Xone
3334 call assert_equal(2, g:Xgetlist({'changedtick' : 0}).changedtick)
3335
3336 " Test case for updating a non-current quickfix list
3337 call g:Xsetlist([], 'f')
3338 Xexpr "F1:1:L1"
3339 Xexpr "F2:2:L2"
3340 call g:Xsetlist([], 'a', {'nr' : 1, "lines" : ["F10:10:L10"]})
3341 call assert_equal(1, g:Xgetlist({'changedtick' : 0}).changedtick)
3342 call assert_equal(2, g:Xgetlist({'nr' : 1, 'changedtick' : 0}).changedtick)
3343
3344 call delete("Xone")
3345endfunc
3346
3347func Test_qf_tick()
3348 call Xqftick_tests('c')
3349 call Xqftick_tests('l')
3350endfunc
Bram Moolenaar12237442017-12-19 12:38:52 +01003351
Bram Moolenaarc631f2d2018-08-21 21:58:13 +02003352" Test helpgrep with lang specifier
3353func Xtest_helpgrep_with_lang_specifier(cchar)
3354 call s:setup_commands(a:cchar)
3355 Xhelpgrep Vim@en
3356 call assert_equal('help', &filetype)
3357 call assert_notequal(0, g:Xgetlist({'nr' : '$'}).nr)
3358 new | only
3359endfunc
3360
3361func Test_helpgrep_with_lang_specifier()
3362 call Xtest_helpgrep_with_lang_specifier('c')
3363 call Xtest_helpgrep_with_lang_specifier('l')
3364endfunc
3365
Bram Moolenaar12237442017-12-19 12:38:52 +01003366" The following test used to crash Vim.
3367" Open the location list window and close the regular window associated with
3368" the location list. When the garbage collection runs now, it incorrectly
3369" marks the location list context as not in use and frees the context.
3370func Test_ll_window_ctx()
3371 call setloclist(0, [], 'f')
3372 call setloclist(0, [], 'a', {'context' : []})
3373 lopen | only
3374 call test_garbagecollect_now()
3375 echo getloclist(0, {'context' : 1}).context
3376 enew | only
3377endfunc
3378
Bram Moolenaar14a4deb2017-12-19 16:48:55 +01003379" The following test used to crash vim
3380func Test_lfile_crash()
3381 sp Xtest
3382 au QuickFixCmdPre * bw
3383 call assert_fails('lfile', 'E40')
3384 au! QuickFixCmdPre
3385endfunc
Bram Moolenaar3c097222017-12-21 20:54:49 +01003386
3387" The following test used to crash vim
3388func Test_lbuffer_crash()
3389 sv Xtest
3390 augroup QF_Test
3391 au!
3392 au * * bw
3393 augroup END
3394 lbuffer
3395 augroup QF_Test
3396 au!
3397 augroup END
3398endfunc
3399
3400" The following test used to crash vim
3401func Test_lexpr_crash()
3402 augroup QF_Test
3403 au!
3404 au * * call setloclist(0, [], 'f')
3405 augroup END
3406 lexpr ""
3407 augroup QF_Test
3408 au!
3409 augroup END
Bram Moolenaar9f84ded2018-10-20 20:54:02 +02003410
Bram Moolenaar3c097222017-12-21 20:54:49 +01003411 enew | only
Bram Moolenaar9f84ded2018-10-20 20:54:02 +02003412 augroup QF_Test
3413 au!
3414 au BufNew * call setloclist(0, [], 'f')
3415 augroup END
3416 lexpr 'x:1:x'
3417 augroup QF_Test
3418 au!
3419 augroup END
3420
3421 enew | only
3422 lexpr ''
3423 lopen
3424 augroup QF_Test
3425 au!
3426 au FileType * call setloclist(0, [], 'f')
3427 augroup END
3428 lexpr ''
3429 augroup QF_Test
3430 au!
3431 augroup END
Bram Moolenaar3c097222017-12-21 20:54:49 +01003432endfunc
3433
3434" The following test used to crash Vim
3435func Test_lvimgrep_crash()
3436 sv Xtest
3437 augroup QF_Test
3438 au!
3439 au * * call setloclist(0, [], 'f')
3440 augroup END
3441 lvimgrep quickfix test_quickfix.vim
3442 augroup QF_Test
3443 au!
3444 augroup END
Bram Moolenaarb6f14802018-10-21 18:47:43 +02003445
3446 new | only
3447 augroup QF_Test
3448 au!
3449 au BufEnter * call setloclist(0, [], 'r')
3450 augroup END
3451 call assert_fails('lvimgrep Test_lvimgrep_crash *', 'E926:')
3452 augroup QF_Test
3453 au!
3454 augroup END
3455
Bram Moolenaar3c097222017-12-21 20:54:49 +01003456 enew | only
3457endfunc
Bram Moolenaarde046542017-12-26 13:53:11 +01003458
3459" Test for the position of the quickfix and location list window
3460func Test_qfwin_pos()
3461 " Open two windows
3462 new | only
3463 new
3464 cexpr ['F1:10:L10']
3465 copen
3466 " Quickfix window should be the bottom most window
3467 call assert_equal(3, winnr())
3468 close
3469 " Open at the very top
3470 wincmd t
3471 topleft copen
3472 call assert_equal(1, winnr())
3473 close
3474 " open left of the current window
3475 wincmd t
3476 below new
3477 leftabove copen
3478 call assert_equal(2, winnr())
3479 close
3480 " open right of the current window
3481 rightbelow copen
3482 call assert_equal(3, winnr())
3483 close
3484endfunc
Bram Moolenaare1bb8792018-04-06 22:58:23 +02003485
3486" Tests for quickfix/location lists changed by autocommands when
3487" :vimgrep/:lvimgrep commands are running.
3488func Test_vimgrep_autocmd()
3489 call setqflist([], 'f')
3490 call writefile(['stars'], 'Xtest1.txt')
3491 call writefile(['stars'], 'Xtest2.txt')
3492
3493 " Test 1:
3494 " When searching for a pattern using :vimgrep, if the quickfix list is
3495 " changed by an autocmd, the results should be added to the correct quickfix
3496 " list.
3497 autocmd BufRead Xtest2.txt cexpr '' | cexpr ''
3498 silent vimgrep stars Xtest*.txt
3499 call assert_equal(1, getqflist({'nr' : 0}).nr)
3500 call assert_equal(3, getqflist({'nr' : '$'}).nr)
3501 call assert_equal('Xtest2.txt', bufname(getqflist()[1].bufnr))
3502 au! BufRead Xtest2.txt
3503
3504 " Test 2:
3505 " When searching for a pattern using :vimgrep, if the quickfix list is
3506 " freed, then a error should be given.
3507 silent! %bwipe!
3508 call setqflist([], 'f')
3509 autocmd BufRead Xtest2.txt for i in range(10) | cexpr '' | endfor
3510 call assert_fails('vimgrep stars Xtest*.txt', 'E925:')
3511 au! BufRead Xtest2.txt
3512
3513 " Test 3:
3514 " When searching for a pattern using :lvimgrep, if the location list is
3515 " freed, then the command should error out.
3516 silent! %bwipe!
3517 let g:save_winid = win_getid()
3518 autocmd BufRead Xtest2.txt call setloclist(g:save_winid, [], 'f')
3519 call assert_fails('lvimgrep stars Xtest*.txt', 'E926:')
3520 au! BufRead Xtest2.txt
3521
3522 call delete('Xtest1.txt')
3523 call delete('Xtest2.txt')
3524 call setqflist([], 'f')
3525endfunc
Bram Moolenaar3b9474b2018-04-23 21:29:48 +02003526
3527" The following test used to crash Vim
3528func Test_lhelpgrep_autocmd()
3529 lhelpgrep quickfix
3530 autocmd QuickFixCmdPost * call setloclist(0, [], 'f')
3531 lhelpgrep buffer
3532 call assert_equal('help', &filetype)
3533 call assert_equal(0, getloclist(0, {'nr' : '$'}).nr)
3534 lhelpgrep tabpage
3535 call assert_equal('help', &filetype)
3536 call assert_equal(1, getloclist(0, {'nr' : '$'}).nr)
3537 au! QuickFixCmdPost
Bram Moolenaarb6f14802018-10-21 18:47:43 +02003538
3539 new | only
3540 augroup QF_Test
3541 au!
3542 au BufEnter * call setqflist([], 'f')
3543 augroup END
3544 call assert_fails('helpgrep quickfix', 'E925:')
3545 augroup QF_Test
3546 au! BufEnter
3547 augroup END
3548
3549 new | only
3550 augroup QF_Test
3551 au!
3552 au BufEnter * call setqflist([], 'r')
3553 augroup END
3554 call assert_fails('helpgrep quickfix', 'E925:')
3555 augroup QF_Test
3556 au! BufEnter
3557 augroup END
3558
3559 new | only
3560 augroup QF_Test
3561 au!
3562 au BufEnter * call setloclist(0, [], 'r')
3563 augroup END
3564 call assert_fails('lhelpgrep quickfix', 'E926:')
3565 augroup QF_Test
3566 au! BufEnter
3567 augroup END
3568
Bram Moolenaar3b9474b2018-04-23 21:29:48 +02003569 new | only
3570endfunc
Bram Moolenaara796d462018-05-01 14:30:36 +02003571
3572" Test for shortening/simplifying the file name when opening the
3573" quickfix window or when displaying the quickfix list
3574func Test_shorten_fname()
3575 if !has('unix')
3576 return
3577 endif
3578 %bwipe
3579 " Create a quickfix list with a absolute path filename
3580 let fname = getcwd() . '/test_quickfix.vim'
3581 call setqflist([], ' ', {'lines':[fname . ":20:Line20"], 'efm':'%f:%l:%m'})
3582 call assert_equal(fname, bufname('test_quickfix.vim'))
3583 " Opening the quickfix window should simplify the file path
3584 cwindow
3585 call assert_equal('test_quickfix.vim', bufname('test_quickfix.vim'))
3586 cclose
3587 %bwipe
3588 " Create a quickfix list with a absolute path filename
3589 call setqflist([], ' ', {'lines':[fname . ":20:Line20"], 'efm':'%f:%l:%m'})
3590 call assert_equal(fname, bufname('test_quickfix.vim'))
3591 " Displaying the quickfix list should simplify the file path
3592 silent! clist
3593 call assert_equal('test_quickfix.vim', bufname('test_quickfix.vim'))
3594endfunc
Bram Moolenaar8b62e312018-05-13 15:29:04 +02003595
3596" Quickfix title tests
3597" In the below tests, 'exe "cmd"' is used to invoke the quickfix commands.
3598" Otherwise due to indentation, the title is set with spaces at the beginning
3599" of the command.
3600func Test_qftitle()
3601 call writefile(["F1:1:Line1"], 'Xerr')
3602
3603 " :cexpr
3604 exe "cexpr readfile('Xerr')"
3605 call assert_equal(":cexpr readfile('Xerr')", getqflist({'title' : 1}).title)
3606
3607 " :cgetexpr
3608 exe "cgetexpr readfile('Xerr')"
3609 call assert_equal(":cgetexpr readfile('Xerr')",
3610 \ getqflist({'title' : 1}).title)
3611
3612 " :caddexpr
3613 call setqflist([], 'f')
3614 exe "caddexpr readfile('Xerr')"
3615 call assert_equal(":caddexpr readfile('Xerr')",
3616 \ getqflist({'title' : 1}).title)
3617
3618 " :cbuffer
3619 new Xerr
3620 exe "cbuffer"
3621 call assert_equal(':cbuffer (Xerr)', getqflist({'title' : 1}).title)
3622
3623 " :cgetbuffer
3624 edit Xerr
3625 exe "cgetbuffer"
3626 call assert_equal(':cgetbuffer (Xerr)', getqflist({'title' : 1}).title)
3627
3628 " :caddbuffer
3629 call setqflist([], 'f')
3630 edit Xerr
3631 exe "caddbuffer"
3632 call assert_equal(':caddbuffer (Xerr)', getqflist({'title' : 1}).title)
3633
3634 " :cfile
3635 exe "cfile Xerr"
3636 call assert_equal(':cfile Xerr', getqflist({'title' : 1}).title)
3637
3638 " :cgetfile
3639 exe "cgetfile Xerr"
3640 call assert_equal(':cgetfile Xerr', getqflist({'title' : 1}).title)
3641
3642 " :caddfile
3643 call setqflist([], 'f')
3644 exe "caddfile Xerr"
3645 call assert_equal(':caddfile Xerr', getqflist({'title' : 1}).title)
3646
3647 " :grep
3648 set grepprg=internal
3649 exe "grep F1 Xerr"
3650 call assert_equal(':grep F1 Xerr', getqflist({'title' : 1}).title)
3651
3652 " :grepadd
3653 call setqflist([], 'f')
3654 exe "grepadd F1 Xerr"
3655 call assert_equal(':grepadd F1 Xerr', getqflist({'title' : 1}).title)
3656 set grepprg&vim
3657
3658 " :vimgrep
3659 exe "vimgrep F1 Xerr"
3660 call assert_equal(':vimgrep F1 Xerr', getqflist({'title' : 1}).title)
3661
3662 " :vimgrepadd
3663 call setqflist([], 'f')
3664 exe "vimgrepadd F1 Xerr"
3665 call assert_equal(':vimgrepadd F1 Xerr', getqflist({'title' : 1}).title)
3666
3667 call setqflist(['F1:10:L10'], ' ')
3668 call assert_equal(':setqflist()', getqflist({'title' : 1}).title)
3669
3670 call setqflist([], 'f')
3671 call setqflist(['F1:10:L10'], 'a')
3672 call assert_equal(':setqflist()', getqflist({'title' : 1}).title)
3673
3674 call setqflist([], 'f')
3675 call setqflist(['F1:10:L10'], 'r')
3676 call assert_equal(':setqflist()', getqflist({'title' : 1}).title)
3677
3678 close
3679 call delete('Xerr')
3680
3681 call setqflist([], ' ', {'title' : 'Errors'})
3682 copen
3683 call assert_equal('Errors', w:quickfix_title)
3684 call setqflist([], 'r', {'items' : [{'filename' : 'a.c', 'lnum' : 10}]})
3685 call assert_equal('Errors', w:quickfix_title)
3686 cclose
3687endfunc
Bram Moolenaar600323b2018-06-16 22:16:47 +02003688
3689func Test_lbuffer_with_bwipe()
3690 new
3691 new
3692 augroup nasty
3693 au * * bwipe
3694 augroup END
3695 lbuffer
3696 augroup nasty
3697 au!
3698 augroup END
3699endfunc
Bram Moolenaar0366c012018-06-18 20:52:13 +02003700
Bram Moolenaar531b9a32018-07-03 16:54:23 +02003701" Test for an autocmd freeing the quickfix/location list when cexpr/lexpr is
3702" running
3703func Xexpr_acmd_freelist(cchar)
3704 call s:setup_commands(a:cchar)
3705
Bram Moolenaar0366c012018-06-18 20:52:13 +02003706 " This was using freed memory.
3707 augroup nasty
Bram Moolenaar531b9a32018-07-03 16:54:23 +02003708 au * * call g:Xsetlist([], 'f')
Bram Moolenaar0366c012018-06-18 20:52:13 +02003709 augroup END
Bram Moolenaar531b9a32018-07-03 16:54:23 +02003710 Xexpr "x"
Bram Moolenaar0366c012018-06-18 20:52:13 +02003711 augroup nasty
3712 au!
3713 augroup END
3714endfunc
Bram Moolenaar531b9a32018-07-03 16:54:23 +02003715
3716func Test_cexpr_acmd_freelist()
3717 call Xexpr_acmd_freelist('c')
3718 call Xexpr_acmd_freelist('l')
3719endfunc
3720
3721" Test for commands that create a new quickfix/location list and jump to the
3722" first error automatically.
3723func Xjumpto_first_error_test(cchar)
3724 call s:setup_commands(a:cchar)
3725
3726 call s:create_test_file('Xtestfile1')
3727 call s:create_test_file('Xtestfile2')
3728 let l = ['Xtestfile1:2:Line2', 'Xtestfile2:4:Line4']
3729
3730 " Test for cexpr/lexpr
3731 enew
3732 Xexpr l
3733 call assert_equal('Xtestfile1', bufname(''))
3734 call assert_equal(2, line('.'))
3735
3736 " Test for cfile/lfile
3737 enew
3738 call writefile(l, 'Xerr')
3739 Xfile Xerr
3740 call assert_equal('Xtestfile1', bufname(''))
3741 call assert_equal(2, line('.'))
3742
3743 " Test for cbuffer/lbuffer
3744 edit Xerr
3745 Xbuffer
3746 call assert_equal('Xtestfile1', bufname(''))
3747 call assert_equal(2, line('.'))
3748
3749 call delete('Xerr')
3750 call delete('Xtestfile1')
3751 call delete('Xtestfile2')
3752endfunc
3753
3754func Test_jumpto_first_error()
3755 call Xjumpto_first_error_test('c')
3756 call Xjumpto_first_error_test('l')
3757endfunc
3758
3759" Test for a quickfix autocmd changing the quickfix/location list before
3760" jumping to the first error in the new list.
3761func Xautocmd_changelist(cchar)
3762 call s:setup_commands(a:cchar)
3763
3764 " Test for cfile/lfile
3765 call s:create_test_file('Xtestfile1')
3766 call s:create_test_file('Xtestfile2')
3767 Xexpr 'Xtestfile1:2:Line2'
3768 autocmd QuickFixCmdPost * Xolder
3769 call writefile(['Xtestfile2:4:Line4'], 'Xerr')
3770 Xfile Xerr
3771 call assert_equal('Xtestfile2', bufname(''))
3772 call assert_equal(4, line('.'))
3773 autocmd! QuickFixCmdPost
3774
3775 " Test for cbuffer/lbuffer
3776 call g:Xsetlist([], 'f')
3777 Xexpr 'Xtestfile1:2:Line2'
3778 autocmd QuickFixCmdPost * Xolder
3779 call writefile(['Xtestfile2:4:Line4'], 'Xerr')
3780 edit Xerr
3781 Xbuffer
3782 call assert_equal('Xtestfile2', bufname(''))
3783 call assert_equal(4, line('.'))
3784 autocmd! QuickFixCmdPost
3785
3786 " Test for cexpr/lexpr
3787 call g:Xsetlist([], 'f')
3788 Xexpr 'Xtestfile1:2:Line2'
3789 autocmd QuickFixCmdPost * Xolder
3790 Xexpr 'Xtestfile2:4:Line4'
3791 call assert_equal('Xtestfile2', bufname(''))
3792 call assert_equal(4, line('.'))
3793 autocmd! QuickFixCmdPost
3794
Bram Moolenaar851332e2018-07-03 19:16:00 +02003795 " The grepprg may not be set on non-Unix systems
3796 if has('unix')
3797 " Test for grep/lgrep
3798 call g:Xsetlist([], 'f')
3799 Xexpr 'Xtestfile1:2:Line2'
3800 autocmd QuickFixCmdPost * Xolder
3801 silent Xgrep Line5 Xtestfile2
3802 call assert_equal('Xtestfile2', bufname(''))
3803 call assert_equal(5, line('.'))
3804 autocmd! QuickFixCmdPost
3805 endif
Bram Moolenaar531b9a32018-07-03 16:54:23 +02003806
3807 " Test for vimgrep/lvimgrep
3808 call g:Xsetlist([], 'f')
3809 Xexpr 'Xtestfile1:2:Line2'
3810 autocmd QuickFixCmdPost * Xolder
3811 silent Xvimgrep Line5 Xtestfile2
3812 call assert_equal('Xtestfile2', bufname(''))
3813 call assert_equal(5, line('.'))
3814 autocmd! QuickFixCmdPost
3815
Bram Moolenaar3f347e42018-08-09 21:19:20 +02003816 " Test for autocommands clearing the quickfix list before jumping to the
3817 " first error. This should not result in an error
3818 autocmd QuickFixCmdPost * call g:Xsetlist([], 'r')
3819 let v:errmsg = ''
3820 " Test for cfile/lfile
3821 Xfile Xerr
3822 call assert_true(v:errmsg !~# 'E42:')
3823 " Test for cbuffer/lbuffer
3824 edit Xerr
3825 Xbuffer
3826 call assert_true(v:errmsg !~# 'E42:')
3827 " Test for cexpr/lexpr
3828 Xexpr 'Xtestfile2:4:Line4'
3829 call assert_true(v:errmsg !~# 'E42:')
3830 " Test for grep/lgrep
3831 " The grepprg may not be set on non-Unix systems
3832 if has('unix')
3833 silent Xgrep Line5 Xtestfile2
3834 call assert_true(v:errmsg !~# 'E42:')
3835 endif
3836 " Test for vimgrep/lvimgrep
3837 call assert_fails('silent Xvimgrep Line5 Xtestfile2', 'E480:')
3838 autocmd! QuickFixCmdPost
3839
Bram Moolenaar531b9a32018-07-03 16:54:23 +02003840 call delete('Xerr')
3841 call delete('Xtestfile1')
3842 call delete('Xtestfile2')
3843endfunc
3844
3845func Test_autocmd_changelist()
3846 call Xautocmd_changelist('c')
3847 call Xautocmd_changelist('l')
3848endfunc
Bram Moolenaar4cde86c2018-07-08 16:01:08 +02003849
3850" Tests for the ':filter /pat/ clist' command
3851func Test_filter_clist()
3852 cexpr ['Xfile1:10:10:Line 10', 'Xfile2:15:15:Line 15']
3853 call assert_equal([' 2 Xfile2:15 col 15: Line 15'],
3854 \ split(execute('filter /Line 15/ clist'), "\n"))
3855 call assert_equal([' 1 Xfile1:10 col 10: Line 10'],
3856 \ split(execute('filter /Xfile1/ clist'), "\n"))
3857 call assert_equal([], split(execute('filter /abc/ clist'), "\n"))
3858
3859 call setqflist([{'module' : 'abc', 'pattern' : 'pat1'},
3860 \ {'module' : 'pqr', 'pattern' : 'pat2'}], ' ')
3861 call assert_equal([' 2 pqr:pat2: '],
3862 \ split(execute('filter /pqr/ clist'), "\n"))
3863 call assert_equal([' 1 abc:pat1: '],
3864 \ split(execute('filter /pat1/ clist'), "\n"))
3865endfunc
Bram Moolenaar0a08c632018-07-25 22:36:52 +02003866
3867" Tests for the "CTRL-W <CR>" command.
3868func Xview_result_split_tests(cchar)
3869 call s:setup_commands(a:cchar)
3870
3871 " Test that "CTRL-W <CR>" in a qf/ll window fails with empty list.
3872 call g:Xsetlist([])
3873 Xopen
3874 let l:win_count = winnr('$')
3875 call assert_fails('execute "normal! \<C-W>\<CR>"', 'E42')
3876 call assert_equal(l:win_count, winnr('$'))
3877 Xclose
3878endfunc
3879
3880func Test_view_result_split()
3881 call Xview_result_split_tests('c')
3882 call Xview_result_split_tests('l')
3883endfunc
Bram Moolenaar2dfcef42018-08-15 22:29:51 +02003884
3885" Test that :cc sets curswant
3886func Test_curswant()
3887 helpgrep quickfix
3888 normal! llll
3889 1cc
3890 call assert_equal(getcurpos()[4], virtcol('.'))
3891 cclose | helpclose
3892endfunc
Bram Moolenaarb2443732018-11-11 22:50:27 +01003893
3894" Test for opening a file from the quickfix window using CTRL-W <Enter>
3895" doesn't leave an empty buffer around.
3896func Test_splitview()
3897 call s:create_test_file('Xtestfile1')
3898 call s:create_test_file('Xtestfile2')
3899 new | only
3900 let last_bufnr = bufnr('Test_sv_1', 1)
3901 let l = ['Xtestfile1:2:Line2', 'Xtestfile2:4:Line4']
3902 cgetexpr l
3903 copen
3904 let numbufs = len(getbufinfo())
3905 exe "normal \<C-W>\<CR>"
3906 copen
3907 exe "normal j\<C-W>\<CR>"
3908 " Make sure new empty buffers are not created
3909 call assert_equal(numbufs, len(getbufinfo()))
3910 " Creating a new buffer should use the next available buffer number
3911 call assert_equal(last_bufnr + 4, bufnr("Test_sv_2", 1))
3912 bwipe Test_sv_1
3913 bwipe Test_sv_2
3914 new | only
3915
3916 " When split opening files from location list window, make sure that two
3917 " windows doesn't refer to the same location list
3918 lgetexpr l
3919 let locid = getloclist(0, {'id' : 0}).id
3920 lopen
3921 exe "normal \<C-W>\<CR>"
3922 call assert_notequal(locid, getloclist(0, {'id' : 0}).id)
3923 call assert_equal(0, getloclist(0, {'winid' : 0}).winid)
3924 new | only
3925
3926 " When split opening files from a helpgrep location list window, a new help
Bram Moolenaareeb1b9c2019-02-10 22:59:04 +01003927 " window should be opened with a copy of the location list.
Bram Moolenaarb2443732018-11-11 22:50:27 +01003928 lhelpgrep window
3929 let locid = getloclist(0, {'id' : 0}).id
3930 lwindow
3931 exe "normal j\<C-W>\<CR>"
3932 call assert_notequal(locid, getloclist(0, {'id' : 0}).id)
3933 call assert_equal(0, getloclist(0, {'winid' : 0}).winid)
3934 new | only
3935
3936 call delete('Xtestfile1')
3937 call delete('Xtestfile2')
3938endfunc
Bram Moolenaarc45eb772019-01-31 14:27:04 +01003939
3940" Test for parsing entries using visual screen column
3941func Test_viscol()
3942 enew
3943 call writefile(["Col1\tCol2\tCol3"], 'Xfile1')
3944 edit Xfile1
3945
3946 " Use byte offset for column number
3947 set efm&
3948 cexpr "Xfile1:1:5:XX\nXfile1:1:9:YY\nXfile1:1:20:ZZ"
3949 call assert_equal([5, 8], [col('.'), virtcol('.')])
3950 cnext
3951 call assert_equal([9, 12], [col('.'), virtcol('.')])
3952 cnext
3953 call assert_equal([14, 20], [col('.'), virtcol('.')])
3954
3955 " Use screen column offset for column number
3956 set efm=%f:%l:%v:%m
3957 cexpr "Xfile1:1:8:XX\nXfile1:1:12:YY\nXfile1:1:20:ZZ"
3958 call assert_equal([5, 8], [col('.'), virtcol('.')])
3959 cnext
3960 call assert_equal([9, 12], [col('.'), virtcol('.')])
3961 cnext
3962 call assert_equal([14, 20], [col('.'), virtcol('.')])
3963 cexpr "Xfile1:1:6:XX\nXfile1:1:15:YY\nXfile1:1:24:ZZ"
3964 call assert_equal([5, 8], [col('.'), virtcol('.')])
3965 cnext
3966 call assert_equal([10, 16], [col('.'), virtcol('.')])
3967 cnext
3968 call assert_equal([14, 20], [col('.'), virtcol('.')])
3969
3970 enew
3971 call writefile(["Col1\täü\töß\tCol4"], 'Xfile1')
3972
3973 " Use byte offset for column number
3974 set efm&
3975 cexpr "Xfile1:1:8:XX\nXfile1:1:11:YY\nXfile1:1:16:ZZ"
3976 call assert_equal([8, 10], [col('.'), virtcol('.')])
3977 cnext
3978 call assert_equal([11, 17], [col('.'), virtcol('.')])
3979 cnext
3980 call assert_equal([16, 25], [col('.'), virtcol('.')])
3981
3982 " Use screen column offset for column number
3983 set efm=%f:%l:%v:%m
3984 cexpr "Xfile1:1:10:XX\nXfile1:1:17:YY\nXfile1:1:25:ZZ"
3985 call assert_equal([8, 10], [col('.'), virtcol('.')])
3986 cnext
3987 call assert_equal([11, 17], [col('.'), virtcol('.')])
3988 cnext
3989 call assert_equal([16, 25], [col('.'), virtcol('.')])
3990
3991 enew | only
3992 set efm&
3993 call delete('Xfile1')
3994endfunc
Bram Moolenaaree8188f2019-02-05 21:23:04 +01003995
3996" Test for the quickfix window buffer
3997func Xqfbuf_test(cchar)
3998 call s:setup_commands(a:cchar)
3999
4000 " Quickfix buffer should be reused across closing and opening a quickfix
4001 " window
4002 Xexpr "F1:10:Line10"
4003 Xopen
4004 let qfbnum = bufnr('')
4005 Xclose
4006 " Even after the quickfix window is closed, the buffer should be loaded
4007 call assert_true(bufloaded(qfbnum))
Bram Moolenaar647e24b2019-03-17 16:39:46 +01004008 call assert_true(qfbnum, g:Xgetlist({'qfbufnr' : 0}).qfbufnr)
Bram Moolenaaree8188f2019-02-05 21:23:04 +01004009 Xopen
4010 " Buffer should be reused when opening the window again
4011 call assert_equal(qfbnum, bufnr(''))
4012 Xclose
4013
4014 if a:cchar == 'l'
4015 %bwipe
4016 " For a location list, when both the file window and the location list
4017 " window for the list are closed, then the buffer should be freed.
4018 new | only
4019 lexpr "F1:10:Line10"
4020 let wid = win_getid()
4021 lopen
4022 let qfbnum = bufnr('')
4023 call assert_match(qfbnum . ' %a- "\[Location List]"', execute('ls'))
4024 close
4025 " When the location list window is closed, the buffer name should not
4026 " change to 'Quickfix List'
Bram Moolenaar647e24b2019-03-17 16:39:46 +01004027 call assert_match(qfbnum . 'u h- "\[Location List]"', execute('ls!'))
Bram Moolenaaree8188f2019-02-05 21:23:04 +01004028 call assert_true(bufloaded(qfbnum))
4029
Bram Moolenaard82a81c2019-03-02 07:57:18 +01004030 " After deleting a location list buffer using ":bdelete", opening the
4031 " location list window should mark the buffer as a location list buffer.
4032 exe "bdelete " . qfbnum
4033 lopen
4034 call assert_equal("quickfix", &buftype)
4035 call assert_equal(1, getwininfo(win_getid(winnr()))[0].loclist)
4036 call assert_equal(wid, getloclist(0, {'filewinid' : 0}).filewinid)
4037 call assert_false(&swapfile)
4038 lclose
4039
Bram Moolenaareeb1b9c2019-02-10 22:59:04 +01004040 " When the location list is cleared for the window, the buffer should be
4041 " removed
4042 call setloclist(0, [], 'f')
4043 call assert_false(bufexists(qfbnum))
Bram Moolenaar647e24b2019-03-17 16:39:46 +01004044 call assert_equal(0, getloclist(0, {'qfbufnr' : 0}).qfbufnr)
Bram Moolenaareeb1b9c2019-02-10 22:59:04 +01004045
4046 " When the location list is freed with the location list window open, the
4047 " location list buffer should not be lost. It should be reused when the
4048 " location list is again populated.
4049 lexpr "F1:10:Line10"
4050 lopen
4051 let wid = win_getid()
4052 let qfbnum = bufnr('')
4053 wincmd p
4054 call setloclist(0, [], 'f')
4055 lexpr "F1:10:Line10"
4056 lopen
4057 call assert_equal(wid, win_getid())
4058 call assert_equal(qfbnum, bufnr(''))
4059 lclose
4060
4061 " When the window with the location list is closed, the buffer should be
4062 " removed
Bram Moolenaaree8188f2019-02-05 21:23:04 +01004063 new | only
Bram Moolenaareeb1b9c2019-02-10 22:59:04 +01004064 call assert_false(bufexists(qfbnum))
Bram Moolenaaree8188f2019-02-05 21:23:04 +01004065 endif
4066endfunc
4067
4068func Test_qfbuf()
4069 call Xqfbuf_test('c')
4070 call Xqfbuf_test('l')
4071endfunc
Bram Moolenaareeb1b9c2019-02-10 22:59:04 +01004072
4073" If there is an autocmd to use only one window, then opening the location
4074" list window used to crash Vim.
4075func Test_winonly_autocmd()
4076 call s:create_test_file('Xtest1')
4077 " Autocmd to show only one Vim window at a time
4078 autocmd WinEnter * only
4079 new
4080 " Load the location list
4081 lexpr "Xtest1:5:Line5\nXtest1:10:Line10\nXtest1:15:Line15"
4082 let loclistid = getloclist(0, {'id' : 0}).id
4083 " Open the location list window. Only this window will be shown and the file
4084 " window is closed.
4085 lopen
4086 call assert_equal(loclistid, getloclist(0, {'id' : 0}).id)
4087 " Jump to an entry in the location list and make sure that the cursor is
4088 " positioned correctly.
4089 ll 3
4090 call assert_equal(loclistid, getloclist(0, {'id' : 0}).id)
4091 call assert_equal('Xtest1', bufname(''))
4092 call assert_equal(15, line('.'))
4093 " Cleanup
4094 autocmd! WinEnter
4095 new | only
4096 call delete('Xtest1')
4097endfunc
Bram Moolenaar39803d82019-04-07 12:04:51 +02004098
4099" Test to make sure that an empty quickfix buffer is not reused for loading
4100" a normal buffer.
4101func Test_empty_qfbuf()
4102 enew | only
4103 call writefile(["Test"], 'Xfile1')
4104 call setqflist([], 'f')
4105 copen | only
4106 let qfbuf = bufnr('')
4107 edit Xfile1
4108 call assert_notequal(qfbuf, bufnr(''))
4109 enew
4110 call delete('Xfile1')
4111endfunc
Bram Moolenaar3ff33112019-05-03 21:56:35 +02004112
4113" Test for the :cbelow, :cabove, :lbelow and :labove commands.
Bram Moolenaarcf6a55c2019-05-05 15:02:30 +02004114" And for the :cafter, :cbefore, :lafter and :lbefore commands.
Bram Moolenaar3ff33112019-05-03 21:56:35 +02004115func Xtest_below(cchar)
4116 call s:setup_commands(a:cchar)
4117
4118 " No quickfix/location list
4119 call assert_fails('Xbelow', 'E42:')
4120 call assert_fails('Xabove', 'E42:')
Bram Moolenaarcf6a55c2019-05-05 15:02:30 +02004121 call assert_fails('Xbefore', 'E42:')
4122 call assert_fails('Xafter', 'E42:')
Bram Moolenaar3ff33112019-05-03 21:56:35 +02004123
4124 " Empty quickfix/location list
4125 call g:Xsetlist([])
4126 call assert_fails('Xbelow', 'E42:')
4127 call assert_fails('Xabove', 'E42:')
Bram Moolenaarcf6a55c2019-05-05 15:02:30 +02004128 call assert_fails('Xbefore', 'E42:')
4129 call assert_fails('Xafter', 'E42:')
Bram Moolenaar3ff33112019-05-03 21:56:35 +02004130
4131 call s:create_test_file('X1')
4132 call s:create_test_file('X2')
4133 call s:create_test_file('X3')
4134 call s:create_test_file('X4')
4135
4136 " Invalid entries
4137 edit X1
4138 call g:Xsetlist(["E1", "E2"])
4139 call assert_fails('Xbelow', 'E42:')
4140 call assert_fails('Xabove', 'E42:')
4141 call assert_fails('3Xbelow', 'E42:')
4142 call assert_fails('4Xabove', 'E42:')
Bram Moolenaarcf6a55c2019-05-05 15:02:30 +02004143 call assert_fails('Xbefore', 'E42:')
4144 call assert_fails('Xafter', 'E42:')
4145 call assert_fails('3Xbefore', 'E42:')
4146 call assert_fails('4Xafter', 'E42:')
Bram Moolenaar3ff33112019-05-03 21:56:35 +02004147
4148 " Test the commands with various arguments
Bram Moolenaarcf6a55c2019-05-05 15:02:30 +02004149 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 +02004150 edit +7 X2
4151 Xabove
4152 call assert_equal(['X2', 5], [bufname(''), line('.')])
4153 call assert_fails('Xabove', 'E553:')
Bram Moolenaarcf6a55c2019-05-05 15:02:30 +02004154 normal 7G
4155 Xbefore
4156 call assert_equal(['X2', 5, 2], [bufname(''), line('.'), col('.')])
4157 call assert_fails('Xbefore', 'E553:')
4158
Bram Moolenaar3ff33112019-05-03 21:56:35 +02004159 normal 2j
4160 Xbelow
4161 call assert_equal(['X2', 10], [bufname(''), line('.')])
Bram Moolenaarcf6a55c2019-05-05 15:02:30 +02004162 normal 7G
4163 Xafter
4164 call assert_equal(['X2', 10, 3], [bufname(''), line('.'), col('.')])
4165
Bram Moolenaar3ff33112019-05-03 21:56:35 +02004166 " Last error in this file
4167 Xbelow 99
4168 call assert_equal(['X2', 15], [bufname(''), line('.')])
4169 call assert_fails('Xbelow', 'E553:')
Bram Moolenaarcf6a55c2019-05-05 15:02:30 +02004170 normal gg
4171 Xafter 99
4172 call assert_equal(['X2', 15, 4], [bufname(''), line('.'), col('.')])
4173 call assert_fails('Xafter', 'E553:')
4174
Bram Moolenaar3ff33112019-05-03 21:56:35 +02004175 " First error in this file
4176 Xabove 99
4177 call assert_equal(['X2', 5], [bufname(''), line('.')])
4178 call assert_fails('Xabove', 'E553:')
Bram Moolenaarcf6a55c2019-05-05 15:02:30 +02004179 normal G
4180 Xbefore 99
4181 call assert_equal(['X2', 5, 2], [bufname(''), line('.'), col('.')])
4182 call assert_fails('Xbefore', 'E553:')
4183
Bram Moolenaar3ff33112019-05-03 21:56:35 +02004184 normal gg
4185 Xbelow 2
4186 call assert_equal(['X2', 10], [bufname(''), line('.')])
Bram Moolenaarcf6a55c2019-05-05 15:02:30 +02004187 normal gg
4188 Xafter 2
4189 call assert_equal(['X2', 10, 3], [bufname(''), line('.'), col('.')])
4190
Bram Moolenaar3ff33112019-05-03 21:56:35 +02004191 normal G
4192 Xabove 2
4193 call assert_equal(['X2', 10], [bufname(''), line('.')])
Bram Moolenaarcf6a55c2019-05-05 15:02:30 +02004194 normal G
4195 Xbefore 2
4196 call assert_equal(['X2', 10, 3], [bufname(''), line('.'), col('.')])
4197
Bram Moolenaar3ff33112019-05-03 21:56:35 +02004198 edit X4
4199 call assert_fails('Xabove', 'E42:')
4200 call assert_fails('Xbelow', 'E42:')
Bram Moolenaarcf6a55c2019-05-05 15:02:30 +02004201 call assert_fails('Xbefore', 'E42:')
4202 call assert_fails('Xafter', 'E42:')
Bram Moolenaar3ff33112019-05-03 21:56:35 +02004203 if a:cchar == 'l'
4204 " If a buffer has location list entries from some other window but not
4205 " from the current window, then the commands should fail.
4206 edit X1 | split | call setloclist(0, [], 'f')
4207 call assert_fails('Xabove', 'E776:')
4208 call assert_fails('Xbelow', 'E776:')
Bram Moolenaarcf6a55c2019-05-05 15:02:30 +02004209 call assert_fails('Xbefore', 'E776:')
4210 call assert_fails('Xafter', 'E776:')
Bram Moolenaar3ff33112019-05-03 21:56:35 +02004211 close
4212 endif
4213
4214 " Test for lines with multiple quickfix entries
4215 Xexpr ["X1:5:L5", "X2:5:1:L5_1", "X2:5:2:L5_2", "X2:5:3:L5_3",
4216 \ "X2:10:1:L10_1", "X2:10:2:L10_2", "X2:10:3:L10_3",
4217 \ "X2:15:1:L15_1", "X2:15:2:L15_2", "X2:15:3:L15_3", "X3:3:L3"]
4218 edit +1 X2
4219 Xbelow 2
4220 call assert_equal(['X2', 10, 1], [bufname(''), line('.'), col('.')])
Bram Moolenaarcf6a55c2019-05-05 15:02:30 +02004221 normal 1G
4222 Xafter 2
4223 call assert_equal(['X2', 5, 2], [bufname(''), line('.'), col('.')])
4224
Bram Moolenaar3ff33112019-05-03 21:56:35 +02004225 normal gg
4226 Xbelow 99
4227 call assert_equal(['X2', 15, 1], [bufname(''), line('.'), col('.')])
Bram Moolenaarcf6a55c2019-05-05 15:02:30 +02004228 normal gg
4229 Xafter 99
4230 call assert_equal(['X2', 15, 3], [bufname(''), line('.'), col('.')])
4231
Bram Moolenaar3ff33112019-05-03 21:56:35 +02004232 normal G
4233 Xabove 2
4234 call assert_equal(['X2', 10, 1], [bufname(''), line('.'), col('.')])
4235 normal G
Bram Moolenaarcf6a55c2019-05-05 15:02:30 +02004236 Xbefore 2
4237 call assert_equal(['X2', 15, 2], [bufname(''), line('.'), col('.')])
4238
4239 normal G
Bram Moolenaar3ff33112019-05-03 21:56:35 +02004240 Xabove 99
4241 call assert_equal(['X2', 5, 1], [bufname(''), line('.'), col('.')])
Bram Moolenaarcf6a55c2019-05-05 15:02:30 +02004242 normal G
4243 Xbefore 99
4244 call assert_equal(['X2', 5, 1], [bufname(''), line('.'), col('.')])
4245
Bram Moolenaar3ff33112019-05-03 21:56:35 +02004246 normal 10G
4247 Xabove
4248 call assert_equal(['X2', 5, 1], [bufname(''), line('.'), col('.')])
Bram Moolenaarcf6a55c2019-05-05 15:02:30 +02004249 normal 10G$
4250 2Xbefore
4251 call assert_equal(['X2', 10, 2], [bufname(''), line('.'), col('.')])
4252
Bram Moolenaar3ff33112019-05-03 21:56:35 +02004253 normal 10G
4254 Xbelow
4255 call assert_equal(['X2', 15, 1], [bufname(''), line('.'), col('.')])
Bram Moolenaarcf6a55c2019-05-05 15:02:30 +02004256 normal 9G
4257 5Xafter
4258 call assert_equal(['X2', 15, 2], [bufname(''), line('.'), col('.')])
Bram Moolenaar3ff33112019-05-03 21:56:35 +02004259
4260 " Invalid range
4261 if a:cchar == 'c'
Bram Moolenaar25190db2019-05-04 15:05:28 +02004262 call assert_fails('-2cbelow', 'E16:')
Bram Moolenaarcf6a55c2019-05-05 15:02:30 +02004263 call assert_fails('-2cafter', 'E16:')
Bram Moolenaar3ff33112019-05-03 21:56:35 +02004264 else
Bram Moolenaar25190db2019-05-04 15:05:28 +02004265 call assert_fails('-2lbelow', 'E16:')
Bram Moolenaarcf6a55c2019-05-05 15:02:30 +02004266 call assert_fails('-2lafter', 'E16:')
Bram Moolenaar3ff33112019-05-03 21:56:35 +02004267 endif
4268
4269 call delete('X1')
4270 call delete('X2')
4271 call delete('X3')
4272 call delete('X4')
4273endfunc
4274
4275func Test_cbelow()
4276 call Xtest_below('c')
4277 call Xtest_below('l')
4278endfunc
Bram Moolenaar25190db2019-05-04 15:05:28 +02004279
4280func Test_quickfix_count()
4281 let commands = [
4282 \ 'cNext',
4283 \ 'cNfile',
4284 \ 'cabove',
4285 \ 'cbelow',
4286 \ 'cfirst',
4287 \ 'clast',
4288 \ 'cnewer',
4289 \ 'cnext',
4290 \ 'cnfile',
4291 \ 'colder',
4292 \ 'cprevious',
4293 \ 'crewind',
4294 \
4295 \ 'lNext',
4296 \ 'lNfile',
4297 \ 'labove',
4298 \ 'lbelow',
4299 \ 'lfirst',
4300 \ 'llast',
4301 \ 'lnewer',
4302 \ 'lnext',
4303 \ 'lnfile',
4304 \ 'lolder',
4305 \ 'lprevious',
4306 \ 'lrewind',
4307 \ ]
4308 for cmd in commands
4309 call assert_fails('-1' .. cmd, 'E16:')
4310 call assert_fails('.' .. cmd, 'E16:')
4311 call assert_fails('%' .. cmd, 'E16:')
4312 call assert_fails('$' .. cmd, 'E16:')
4313 endfor
4314endfunc
Bram Moolenaar6a0cc912019-10-26 16:48:44 +02004315
4316" Test for aborting quickfix commands using QuickFixCmdPre
4317func Xtest_qfcmd_abort(cchar)
4318 call s:setup_commands(a:cchar)
4319
4320 call g:Xsetlist([], 'f')
4321
4322 " cexpr/lexpr
4323 let e = ''
4324 try
4325 Xexpr ["F1:10:Line10", "F2:20:Line20"]
4326 catch /.*/
4327 let e = v:exception
4328 endtry
4329 call assert_equal('AbortCmd', e)
4330 call assert_equal(0, g:Xgetlist({'nr' : '$'}).nr)
4331
4332 " cfile/lfile
4333 call writefile(["F1:10:Line10", "F2:20:Line20"], 'Xfile1')
4334 let e = ''
4335 try
4336 Xfile Xfile1
4337 catch /.*/
4338 let e = v:exception
4339 endtry
4340 call assert_equal('AbortCmd', e)
4341 call assert_equal(0, g:Xgetlist({'nr' : '$'}).nr)
4342 call delete('Xfile1')
4343
4344 " cgetbuffer/lgetbuffer
4345 enew!
4346 call append(0, ["F1:10:Line10", "F2:20:Line20"])
4347 let e = ''
4348 try
4349 Xgetbuffer
4350 catch /.*/
4351 let e = v:exception
4352 endtry
4353 call assert_equal('AbortCmd', e)
4354 call assert_equal(0, g:Xgetlist({'nr' : '$'}).nr)
4355 enew!
4356
4357 " vimgrep/lvimgrep
4358 let e = ''
4359 try
4360 Xvimgrep /func/ test_quickfix.vim
4361 catch /.*/
4362 let e = v:exception
4363 endtry
4364 call assert_equal('AbortCmd', e)
4365 call assert_equal(0, g:Xgetlist({'nr' : '$'}).nr)
4366
4367 " helpgrep/lhelpgrep
4368 let e = ''
4369 try
4370 Xhelpgrep quickfix
4371 catch /.*/
4372 let e = v:exception
4373 endtry
4374 call assert_equal('AbortCmd', e)
4375 call assert_equal(0, g:Xgetlist({'nr' : '$'}).nr)
4376
4377 " grep/lgrep
4378 if has('unix')
4379 let e = ''
4380 try
4381 silent Xgrep func test_quickfix.vim
4382 catch /.*/
4383 let e = v:exception
4384 endtry
4385 call assert_equal('AbortCmd', e)
4386 call assert_equal(0, g:Xgetlist({'nr' : '$'}).nr)
4387 endif
4388endfunc
4389
4390func Test_qfcmd_abort()
4391 augroup QF_Test
4392 au!
4393 autocmd QuickFixCmdPre * throw "AbortCmd"
4394 augroup END
4395
4396 call Xtest_qfcmd_abort('c')
4397 call Xtest_qfcmd_abort('l')
4398
4399 augroup QF_Test
4400 au!
4401 augroup END
4402endfunc
4403
Bram Moolenaard8a8c4c2019-11-16 21:04:57 +01004404" Test for using a file in one of the parent directories.
4405func Test_search_in_dirstack()
4406 call mkdir('Xtestdir/a/b/c', 'p')
4407 let save_cwd = getcwd()
4408 call writefile(["X1_L1", "X1_L2"], 'Xtestdir/Xfile1')
4409 call writefile(["X2_L1", "X2_L2"], 'Xtestdir/a/Xfile2')
4410 call writefile(["X3_L1", "X3_L2"], 'Xtestdir/a/b/Xfile3')
4411 call writefile(["X4_L1", "X4_L2"], 'Xtestdir/a/b/c/Xfile4')
4412
4413 let lines = "Entering dir Xtestdir\n" .
4414 \ "Entering dir a\n" .
4415 \ "Entering dir b\n" .
4416 \ "Xfile2:2:X2_L2\n" .
4417 \ "Leaving dir a\n" .
4418 \ "Xfile1:2:X1_L2\n" .
4419 \ "Xfile3:1:X3_L1\n" .
4420 \ "Entering dir c\n" .
4421 \ "Xfile4:2:X4_L2\n" .
4422 \ "Leaving dir c\n" .
4423 \ "Leaving dir Xtestdir\n"
4424 set efm=%DEntering\ dir\ %f,%XLeaving\ dir\ %f,%f:%l:%m
4425 cexpr lines
4426 call assert_equal(11, getqflist({'size' : 0}).size)
4427 call assert_equal(4, getqflist({'idx' : 0}).idx)
4428 call assert_equal('X2_L2', getline('.'))
4429 cnext
4430 call assert_equal(6, getqflist({'idx' : 0}).idx)
4431 call assert_equal('X1_L2', getline('.'))
4432 cnext
4433 call assert_equal(7, getqflist({'idx' : 0}).idx)
4434 call assert_equal(1, line('$'))
4435 call assert_equal('', getline(1))
4436 cnext
4437 call assert_equal(9, getqflist({'idx' : 0}).idx)
4438 call assert_equal(1, line('$'))
4439 call assert_equal('', getline(1))
4440
4441 set efm&
4442 exe 'cd ' . save_cwd
4443 call delete('Xtestdir', 'rf')
4444endfunc
4445
Bram Moolenaar6a0cc912019-10-26 16:48:44 +02004446" vim: shiftwidth=2 sts=2 expandtab