blob: eec3bde17f6ad55b9a7c35dc00c8f4f7050da1e3 [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>
Bram Moolenaarf9ae1542019-11-18 22:02:16 +010017 command! -nargs=* Xopen <mods> copen <args>
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +020018 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 Moolenaarf9ae1542019-11-18 22:02:16 +010035 command! -count -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>
Bram Moolenaarf9ae1542019-11-18 22:02:16 +010054 command! -nargs=* Xopen <mods> lopen <args>
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +020055 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 Moolenaarf9ae1542019-11-18 22:02:16 +010072 command! -count -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 Moolenaarf9ae1542019-11-18 22:02:16 +0100160 " For help entries in the quickfix list, only the filename without directory
161 " should be displayed
162 Xhelpgrep setqflist()
163 let l = split(execute('Xlist 1', ''), "\n")
164 call assert_match('^ 1 [^\\/]\{-}:', l[0])
165
Bram Moolenaaree85df32017-03-19 14:19:50 +0100166 " Error cases
167 call assert_fails('Xlist abc', 'E488:')
Bram Moolenaar2b946c92016-11-12 18:14:44 +0100168endfunc
Bram Moolenaarda59dd52016-01-05 21:59:58 +0100169
Bram Moolenaar2b946c92016-11-12 18:14:44 +0100170func Test_clist()
Bram Moolenaarda59dd52016-01-05 21:59:58 +0100171 call XlistTests('c')
172 call XlistTests('l')
Bram Moolenaar2b946c92016-11-12 18:14:44 +0100173endfunc
Bram Moolenaarda59dd52016-01-05 21:59:58 +0100174
175" Tests for the :colder, :cnewer, :lolder and :lnewer commands
176" Note that this test assumes that a quickfix/location list is
Bram Moolenaarcfc0a352016-01-09 20:23:00 +0100177" already set by the caller.
Bram Moolenaar2b946c92016-11-12 18:14:44 +0100178func XageTests(cchar)
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +0200179 call s:setup_commands(a:cchar)
Bram Moolenaarda59dd52016-01-05 21:59:58 +0100180
Bram Moolenaar87f59b02019-04-04 14:04:11 +0200181 if a:cchar == 'l'
182 " No location list for the current window
183 call assert_fails('lolder', 'E776:')
184 call assert_fails('lnewer', 'E776:')
185 endif
186
Bram Moolenaarcf1ba352017-10-27 00:55:04 +0200187 let list = [{'bufnr': bufnr('%'), 'lnum': 1}]
Bram Moolenaarb6fa30c2017-03-29 14:19:25 +0200188 call g:Xsetlist(list)
189
Bram Moolenaarda59dd52016-01-05 21:59:58 +0100190 " Jumping to a non existent list should return error
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +0200191 silent! Xolder 99
Bram Moolenaarda59dd52016-01-05 21:59:58 +0100192 call assert_true(v:errmsg ==# 'E380: At bottom of quickfix stack')
193
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +0200194 silent! Xnewer 99
Bram Moolenaarda59dd52016-01-05 21:59:58 +0100195 call assert_true(v:errmsg ==# 'E381: At top of quickfix stack')
196
197 " Add three quickfix/location lists
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +0200198 Xgetexpr ['Xtestfile1:1:3:Line1']
199 Xgetexpr ['Xtestfile2:2:2:Line2']
200 Xgetexpr ['Xtestfile3:3:1:Line3']
Bram Moolenaarda59dd52016-01-05 21:59:58 +0100201
202 " Go back two lists
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +0200203 Xolder
204 let l = g:Xgetlist()
Bram Moolenaarda59dd52016-01-05 21:59:58 +0100205 call assert_equal('Line2', l[0].text)
206
207 " Go forward two lists
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +0200208 Xnewer
209 let l = g:Xgetlist()
Bram Moolenaarda59dd52016-01-05 21:59:58 +0100210 call assert_equal('Line3', l[0].text)
211
212 " Test for the optional count argument
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +0200213 Xolder 2
214 let l = g:Xgetlist()
Bram Moolenaarda59dd52016-01-05 21:59:58 +0100215 call assert_equal('Line1', l[0].text)
216
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +0200217 Xnewer 2
218 let l = g:Xgetlist()
Bram Moolenaarda59dd52016-01-05 21:59:58 +0100219 call assert_equal('Line3', l[0].text)
Bram Moolenaar2b946c92016-11-12 18:14:44 +0100220endfunc
Bram Moolenaarda59dd52016-01-05 21:59:58 +0100221
Bram Moolenaar2b946c92016-11-12 18:14:44 +0100222func Test_cage()
Bram Moolenaarda59dd52016-01-05 21:59:58 +0100223 call XageTests('c')
224 call XageTests('l')
Bram Moolenaar2b946c92016-11-12 18:14:44 +0100225endfunc
Bram Moolenaarda59dd52016-01-05 21:59:58 +0100226
227" Tests for the :cwindow, :lwindow :cclose, :lclose, :copen and :lopen
228" commands
Bram Moolenaar2b946c92016-11-12 18:14:44 +0100229func XwindowTests(cchar)
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +0200230 call s:setup_commands(a:cchar)
Bram Moolenaarda59dd52016-01-05 21:59:58 +0100231
Bram Moolenaarb6fa30c2017-03-29 14:19:25 +0200232 " Opening the location list window without any errors should fail
233 if a:cchar == 'l'
234 call assert_fails('lopen', 'E776:')
235 endif
236
Bram Moolenaarda59dd52016-01-05 21:59:58 +0100237 " Create a list with no valid entries
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +0200238 Xgetexpr ['non-error 1', 'non-error 2', 'non-error 3']
Bram Moolenaarda59dd52016-01-05 21:59:58 +0100239
240 " Quickfix/Location window should not open with no valid errors
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +0200241 Xwindow
Bram Moolenaarda59dd52016-01-05 21:59:58 +0100242 call assert_true(winnr('$') == 1)
243
244 " Create a list with valid entries
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +0200245 Xgetexpr ['Xtestfile1:1:3:Line1', 'Xtestfile2:2:2:Line2',
246 \ 'Xtestfile3:3:1:Line3']
Bram Moolenaarda59dd52016-01-05 21:59:58 +0100247
248 " Open the window
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +0200249 Xwindow
Bram Moolenaarda59dd52016-01-05 21:59:58 +0100250 call assert_true(winnr('$') == 2 && winnr() == 2 &&
251 \ getline('.') ==# 'Xtestfile1|1 col 3| Line1')
Bram Moolenaar537ef082016-07-09 17:56:19 +0200252 redraw!
Bram Moolenaarda59dd52016-01-05 21:59:58 +0100253
254 " Close the window
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +0200255 Xclose
Bram Moolenaarda59dd52016-01-05 21:59:58 +0100256 call assert_true(winnr('$') == 1)
257
258 " Create a list with no valid entries
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +0200259 Xgetexpr ['non-error 1', 'non-error 2', 'non-error 3']
Bram Moolenaarda59dd52016-01-05 21:59:58 +0100260
261 " Open the window
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +0200262 Xopen 5
Bram Moolenaarda59dd52016-01-05 21:59:58 +0100263 call assert_true(winnr('$') == 2 && getline('.') ==# '|| non-error 1'
264 \ && winheight('.') == 5)
265
266 " Opening the window again, should move the cursor to that window
267 wincmd t
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +0200268 Xopen 7
Bram Moolenaarda59dd52016-01-05 21:59:58 +0100269 call assert_true(winnr('$') == 2 && winnr() == 2 &&
270 \ winheight('.') == 7 &&
271 \ getline('.') ==# '|| non-error 1')
272
273
274 " Calling cwindow should close the quickfix window with no valid errors
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +0200275 Xwindow
Bram Moolenaarda59dd52016-01-05 21:59:58 +0100276 call assert_true(winnr('$') == 1)
Bram Moolenaarb6fa30c2017-03-29 14:19:25 +0200277
Bram Moolenaarf9ae1542019-11-18 22:02:16 +0100278 " Specifying the width should adjust the width for a vertically split
279 " quickfix window.
280 vert Xopen
281 call assert_equal(10, winwidth(0))
282 vert Xopen 12
283 call assert_equal(12, winwidth(0))
284 Xclose
285
Bram Moolenaarb6fa30c2017-03-29 14:19:25 +0200286 if a:cchar == 'c'
287 " Opening the quickfix window in multiple tab pages should reuse the
288 " quickfix buffer
289 Xgetexpr ['Xtestfile1:1:3:Line1', 'Xtestfile2:2:2:Line2',
290 \ 'Xtestfile3:3:1:Line3']
291 Xopen
292 let qfbufnum = bufnr('%')
293 tabnew
294 Xopen
295 call assert_equal(qfbufnum, bufnr('%'))
296 new | only | tabonly
297 endif
Bram Moolenaar2b946c92016-11-12 18:14:44 +0100298endfunc
Bram Moolenaarda59dd52016-01-05 21:59:58 +0100299
Bram Moolenaar2b946c92016-11-12 18:14:44 +0100300func Test_cwindow()
Bram Moolenaarda59dd52016-01-05 21:59:58 +0100301 call XwindowTests('c')
302 call XwindowTests('l')
Bram Moolenaar2b946c92016-11-12 18:14:44 +0100303endfunc
Bram Moolenaarda59dd52016-01-05 21:59:58 +0100304
Bram Moolenaar36d50222019-05-02 20:17:40 +0200305func Test_copenHeight()
306 copen
307 wincmd H
308 let height = winheight(0)
309 copen 10
310 call assert_equal(height, winheight(0))
311 quit
312endfunc
313
Bram Moolenaar1142a312019-10-16 14:51:39 +0200314func Test_copenHeight_tabline()
315 set tabline=foo showtabline=2
316 copen
317 wincmd H
318 let height = winheight(0)
319 copen 10
320 call assert_equal(height, winheight(0))
321 quit
322 set tabline& showtabline&
323endfunc
324
325
Bram Moolenaarda59dd52016-01-05 21:59:58 +0100326" Tests for the :cfile, :lfile, :caddfile, :laddfile, :cgetfile and :lgetfile
327" commands.
Bram Moolenaar2b946c92016-11-12 18:14:44 +0100328func XfileTests(cchar)
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +0200329 call s:setup_commands(a:cchar)
Bram Moolenaarda59dd52016-01-05 21:59:58 +0100330
331 call writefile(['Xtestfile1:700:10:Line 700',
332 \ 'Xtestfile2:800:15:Line 800'], 'Xqftestfile1')
333
334 enew!
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +0200335 Xfile Xqftestfile1
336 let l = g:Xgetlist()
Bram Moolenaarda59dd52016-01-05 21:59:58 +0100337 call assert_true(len(l) == 2 &&
338 \ l[0].lnum == 700 && l[0].col == 10 && l[0].text ==# 'Line 700' &&
339 \ l[1].lnum == 800 && l[1].col == 15 && l[1].text ==# 'Line 800')
340
Bram Moolenaar049cba92016-06-26 14:38:04 +0200341 " Test with a non existent file
342 call assert_fails('Xfile non_existent_file', 'E40')
343
Bram Moolenaarda59dd52016-01-05 21:59:58 +0100344 " Run cfile/lfile from a modified buffer
345 enew!
346 silent! put ='Quickfix'
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +0200347 silent! Xfile Xqftestfile1
Bram Moolenaarda59dd52016-01-05 21:59:58 +0100348 call assert_true(v:errmsg ==# 'E37: No write since last change (add ! to override)')
349
350 call writefile(['Xtestfile3:900:30:Line 900'], 'Xqftestfile1')
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +0200351 Xaddfile Xqftestfile1
352 let l = g:Xgetlist()
Bram Moolenaarda59dd52016-01-05 21:59:58 +0100353 call assert_true(len(l) == 3 &&
354 \ l[2].lnum == 900 && l[2].col == 30 && l[2].text ==# 'Line 900')
355
356 call writefile(['Xtestfile1:222:77:Line 222',
357 \ 'Xtestfile2:333:88:Line 333'], 'Xqftestfile1')
358
359 enew!
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +0200360 Xgetfile Xqftestfile1
361 let l = g:Xgetlist()
Bram Moolenaarda59dd52016-01-05 21:59:58 +0100362 call assert_true(len(l) == 2 &&
363 \ l[0].lnum == 222 && l[0].col == 77 && l[0].text ==# 'Line 222' &&
364 \ l[1].lnum == 333 && l[1].col == 88 && l[1].text ==# 'Line 333')
365
366 call delete('Xqftestfile1')
Bram Moolenaar2b946c92016-11-12 18:14:44 +0100367endfunc
Bram Moolenaarda59dd52016-01-05 21:59:58 +0100368
Bram Moolenaar2b946c92016-11-12 18:14:44 +0100369func Test_cfile()
Bram Moolenaarda59dd52016-01-05 21:59:58 +0100370 call XfileTests('c')
371 call XfileTests('l')
Bram Moolenaar2b946c92016-11-12 18:14:44 +0100372endfunc
Bram Moolenaarda59dd52016-01-05 21:59:58 +0100373
374" Tests for the :cbuffer, :lbuffer, :caddbuffer, :laddbuffer, :cgetbuffer and
375" :lgetbuffer commands.
Bram Moolenaar2b946c92016-11-12 18:14:44 +0100376func XbufferTests(cchar)
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +0200377 call s:setup_commands(a:cchar)
Bram Moolenaarda59dd52016-01-05 21:59:58 +0100378
379 enew!
380 silent! call setline(1, ['Xtestfile7:700:10:Line 700',
381 \ 'Xtestfile8:800:15:Line 800'])
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +0200382 Xbuffer!
383 let l = g:Xgetlist()
Bram Moolenaarda59dd52016-01-05 21:59:58 +0100384 call assert_true(len(l) == 2 &&
385 \ l[0].lnum == 700 && l[0].col == 10 && l[0].text ==# 'Line 700' &&
386 \ l[1].lnum == 800 && l[1].col == 15 && l[1].text ==# 'Line 800')
387
388 enew!
389 silent! call setline(1, ['Xtestfile9:900:55:Line 900',
390 \ 'Xtestfile10:950:66:Line 950'])
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +0200391 Xgetbuffer
392 let l = g:Xgetlist()
Bram Moolenaarda59dd52016-01-05 21:59:58 +0100393 call assert_true(len(l) == 2 &&
394 \ l[0].lnum == 900 && l[0].col == 55 && l[0].text ==# 'Line 900' &&
395 \ l[1].lnum == 950 && l[1].col == 66 && l[1].text ==# 'Line 950')
396
397 enew!
398 silent! call setline(1, ['Xtestfile11:700:20:Line 700',
399 \ 'Xtestfile12:750:25:Line 750'])
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +0200400 Xaddbuffer
401 let l = g:Xgetlist()
Bram Moolenaarda59dd52016-01-05 21:59:58 +0100402 call assert_true(len(l) == 4 &&
403 \ l[1].lnum == 950 && l[1].col == 66 && l[1].text ==# 'Line 950' &&
404 \ l[2].lnum == 700 && l[2].col == 20 && l[2].text ==# 'Line 700' &&
405 \ l[3].lnum == 750 && l[3].col == 25 && l[3].text ==# 'Line 750')
Bram Moolenaarab47c612016-06-14 22:02:26 +0200406 enew!
Bram Moolenaarda59dd52016-01-05 21:59:58 +0100407
Bram Moolenaaree85df32017-03-19 14:19:50 +0100408 " Check for invalid buffer
409 call assert_fails('Xbuffer 199', 'E474:')
410
411 " Check for unloaded buffer
412 edit Xtestfile1
413 let bnr = bufnr('%')
414 enew!
415 call assert_fails('Xbuffer ' . bnr, 'E681:')
416
417 " Check for invalid range
418 " Using Xbuffer will not run the range check in the cbuffer/lbuffer
419 " commands. So directly call the commands.
420 if (a:cchar == 'c')
421 call assert_fails('900,999cbuffer', 'E16:')
422 else
423 call assert_fails('900,999lbuffer', 'E16:')
424 endif
Bram Moolenaar2b946c92016-11-12 18:14:44 +0100425endfunc
Bram Moolenaarda59dd52016-01-05 21:59:58 +0100426
Bram Moolenaar2b946c92016-11-12 18:14:44 +0100427func Test_cbuffer()
Bram Moolenaarda59dd52016-01-05 21:59:58 +0100428 call XbufferTests('c')
429 call XbufferTests('l')
Bram Moolenaar2b946c92016-11-12 18:14:44 +0100430endfunc
Bram Moolenaarda59dd52016-01-05 21:59:58 +0100431
Bram Moolenaar2b946c92016-11-12 18:14:44 +0100432func XexprTests(cchar)
Bram Moolenaar0fcc7c62016-07-02 21:22:52 +0200433 call s:setup_commands(a:cchar)
434
435 call assert_fails('Xexpr 10', 'E777:')
Bram Moolenaar2b946c92016-11-12 18:14:44 +0100436endfunc
Bram Moolenaar0fcc7c62016-07-02 21:22:52 +0200437
Bram Moolenaar2b946c92016-11-12 18:14:44 +0100438func Test_cexpr()
Bram Moolenaar0fcc7c62016-07-02 21:22:52 +0200439 call XexprTests('c')
440 call XexprTests('l')
Bram Moolenaar2b946c92016-11-12 18:14:44 +0100441endfunc
Bram Moolenaar0fcc7c62016-07-02 21:22:52 +0200442
443" Tests for :cnext, :cprev, :cfirst, :clast commands
Bram Moolenaar2b946c92016-11-12 18:14:44 +0100444func Xtest_browse(cchar)
Bram Moolenaar0fcc7c62016-07-02 21:22:52 +0200445 call s:setup_commands(a:cchar)
446
Bram Moolenaar74240d32017-12-10 15:26:15 +0100447 call g:Xsetlist([], 'f')
Bram Moolenaarb6fa30c2017-03-29 14:19:25 +0200448 " Jumping to first or next location list entry without any error should
449 " result in failure
Bram Moolenaar74240d32017-12-10 15:26:15 +0100450 if a:cchar == 'c'
451 let err = 'E42:'
452 else
453 let err = 'E776:'
Bram Moolenaarb6fa30c2017-03-29 14:19:25 +0200454 endif
Bram Moolenaar74240d32017-12-10 15:26:15 +0100455 call assert_fails('Xnext', err)
456 call assert_fails('Xprev', err)
457 call assert_fails('Xnfile', err)
458 call assert_fails('Xpfile', err)
Bram Moolenaarb6fa30c2017-03-29 14:19:25 +0200459
Bram Moolenaarf9ae1542019-11-18 22:02:16 +0100460 Xexpr ''
461 let cmd = (a:cchar == 'c') ? '$cc' : '$ll'
462 call assert_fails(cmd, 'E42:')
463
Bram Moolenaar0fcc7c62016-07-02 21:22:52 +0200464 call s:create_test_file('Xqftestfile1')
465 call s:create_test_file('Xqftestfile2')
466
467 Xgetexpr ['Xqftestfile1:5:Line5',
468 \ 'Xqftestfile1:6:Line6',
469 \ 'Xqftestfile2:10:Line10',
Bram Moolenaar99895ea2017-04-20 22:44:47 +0200470 \ 'Xqftestfile2:11:Line11',
471 \ 'RegularLine1',
472 \ 'RegularLine2']
Bram Moolenaar0fcc7c62016-07-02 21:22:52 +0200473
474 Xfirst
475 call assert_fails('Xprev', 'E553')
476 call assert_fails('Xpfile', 'E553')
477 Xnfile
478 call assert_equal('Xqftestfile2', bufname('%'))
479 call assert_equal(10, line('.'))
480 Xpfile
481 call assert_equal('Xqftestfile1', bufname('%'))
482 call assert_equal(6, line('.'))
Bram Moolenaar74240d32017-12-10 15:26:15 +0100483 5Xcc
484 call assert_equal(5, g:Xgetlist({'idx':0}).idx)
485 2Xcc
486 call assert_equal(2, g:Xgetlist({'idx':0}).idx)
Bram Moolenaarf9ae1542019-11-18 22:02:16 +0100487 if a:cchar == 'c'
488 cc
489 else
490 ll
491 endif
492 call assert_equal(2, g:Xgetlist({'idx':0}).idx)
Bram Moolenaar74240d32017-12-10 15:26:15 +0100493 10Xcc
494 call assert_equal(6, g:Xgetlist({'idx':0}).idx)
Bram Moolenaar0fcc7c62016-07-02 21:22:52 +0200495 Xlast
Bram Moolenaar99895ea2017-04-20 22:44:47 +0200496 Xprev
Bram Moolenaar0fcc7c62016-07-02 21:22:52 +0200497 call assert_equal('Xqftestfile2', bufname('%'))
498 call assert_equal(11, line('.'))
499 call assert_fails('Xnext', 'E553')
500 call assert_fails('Xnfile', 'E553')
Bram Moolenaarf9ae1542019-11-18 22:02:16 +0100501 " To process the range using quickfix list entries, directly use the
502 " quickfix commands (don't use the user defined commands)
503 if a:cchar == 'c'
504 $cc
505 else
506 $ll
507 endif
508 call assert_equal(6, g:Xgetlist({'idx':0}).idx)
Bram Moolenaar0fcc7c62016-07-02 21:22:52 +0200509 Xrewind
510 call assert_equal('Xqftestfile1', bufname('%'))
511 call assert_equal(5, line('.'))
512
Bram Moolenaar99895ea2017-04-20 22:44:47 +0200513 10Xnext
514 call assert_equal('Xqftestfile2', bufname('%'))
515 call assert_equal(11, line('.'))
516 10Xprev
517 call assert_equal('Xqftestfile1', bufname('%'))
518 call assert_equal(5, line('.'))
519
Bram Moolenaar74240d32017-12-10 15:26:15 +0100520 " Jumping to an error from the error window using cc command
521 Xgetexpr ['Xqftestfile1:5:Line5',
522 \ 'Xqftestfile1:6:Line6',
523 \ 'Xqftestfile2:10:Line10',
524 \ 'Xqftestfile2:11:Line11']
525 Xopen
526 10Xcc
527 call assert_equal(11, line('.'))
528 call assert_equal('Xqftestfile2', bufname('%'))
529
530 " Jumping to an error from the error window (when only the error window is
531 " present)
532 Xopen | only
533 Xlast 1
534 call assert_equal(5, line('.'))
535 call assert_equal('Xqftestfile1', bufname('%'))
536
Bram Moolenaaree85df32017-03-19 14:19:50 +0100537 Xexpr ""
538 call assert_fails('Xnext', 'E42:')
539
Bram Moolenaar0fcc7c62016-07-02 21:22:52 +0200540 call delete('Xqftestfile1')
541 call delete('Xqftestfile2')
Bram Moolenaarfc2b2702017-09-15 22:43:07 +0200542
543 " Should be able to use next/prev with invalid entries
544 Xexpr ""
545 call assert_equal(0, g:Xgetlist({'idx' : 0}).idx)
546 call assert_equal(0, g:Xgetlist({'size' : 0}).size)
547 Xaddexpr ['foo', 'bar', 'baz', 'quux', 'shmoo']
548 call assert_equal(5, g:Xgetlist({'size' : 0}).size)
549 Xlast
550 call assert_equal(5, g:Xgetlist({'idx' : 0}).idx)
551 Xfirst
552 call assert_equal(1, g:Xgetlist({'idx' : 0}).idx)
553 2Xnext
554 call assert_equal(3, g:Xgetlist({'idx' : 0}).idx)
Bram Moolenaar2b946c92016-11-12 18:14:44 +0100555endfunc
Bram Moolenaar0fcc7c62016-07-02 21:22:52 +0200556
Bram Moolenaar2b946c92016-11-12 18:14:44 +0100557func Test_browse()
Bram Moolenaar0fcc7c62016-07-02 21:22:52 +0200558 call Xtest_browse('c')
559 call Xtest_browse('l')
Bram Moolenaar2b946c92016-11-12 18:14:44 +0100560endfunc
Bram Moolenaar0fcc7c62016-07-02 21:22:52 +0200561
Bram Moolenaar2b946c92016-11-12 18:14:44 +0100562func Test_nomem()
Bram Moolenaar8e8df252016-05-25 21:23:21 +0200563 call test_alloc_fail(GetAllocId('qf_dirname_start'), 0, 0)
Bram Moolenaara260b872016-01-15 20:48:22 +0100564 call assert_fails('vimgrep vim runtest.vim', 'E342:')
Bram Moolenaar75bdf6a2016-01-07 21:25:08 +0100565
Bram Moolenaarce90e362019-09-08 18:58:44 +0200566 call GetAllocId('qf_dirname_now')->test_alloc_fail(0, 0)
Bram Moolenaara260b872016-01-15 20:48:22 +0100567 call assert_fails('vimgrep vim runtest.vim', 'E342:')
Bram Moolenaar75bdf6a2016-01-07 21:25:08 +0100568
Bram Moolenaar8e8df252016-05-25 21:23:21 +0200569 call test_alloc_fail(GetAllocId('qf_namebuf'), 0, 0)
Bram Moolenaara260b872016-01-15 20:48:22 +0100570 call assert_fails('cfile runtest.vim', 'E342:')
Bram Moolenaar75bdf6a2016-01-07 21:25:08 +0100571
Bram Moolenaar8e8df252016-05-25 21:23:21 +0200572 call test_alloc_fail(GetAllocId('qf_errmsg'), 0, 0)
Bram Moolenaara260b872016-01-15 20:48:22 +0100573 call assert_fails('cfile runtest.vim', 'E342:')
Bram Moolenaar75bdf6a2016-01-07 21:25:08 +0100574
Bram Moolenaar8e8df252016-05-25 21:23:21 +0200575 call test_alloc_fail(GetAllocId('qf_pattern'), 0, 0)
Bram Moolenaara260b872016-01-15 20:48:22 +0100576 call assert_fails('cfile runtest.vim', 'E342:')
Bram Moolenaar75bdf6a2016-01-07 21:25:08 +0100577
578endfunc
579
Bram Moolenaar2b946c92016-11-12 18:14:44 +0100580func s:test_xhelpgrep(cchar)
Bram Moolenaar049cba92016-06-26 14:38:04 +0200581 call s:setup_commands(a:cchar)
582 Xhelpgrep quickfix
583 Xopen
584 if a:cchar == 'c'
585 let title_text = ':helpgrep quickfix'
586 else
587 let title_text = ':lhelpgrep quickfix'
588 endif
589 call assert_true(w:quickfix_title =~ title_text, w:quickfix_title)
Bram Moolenaar99895ea2017-04-20 22:44:47 +0200590
591 " Jumping to a help topic should open the help window
592 only
593 Xnext
594 call assert_true(&buftype == 'help')
595 call assert_true(winnr('$') == 2)
596 " Jumping to the next match should reuse the help window
597 Xnext
598 call assert_true(&buftype == 'help')
599 call assert_true(winnr() == 1)
600 call assert_true(winnr('$') == 2)
601 " Jumping to the next match from the quickfix window should reuse the help
602 " window
603 Xopen
604 Xnext
605 call assert_true(&buftype == 'help')
606 call assert_true(winnr() == 1)
607 call assert_true(winnr('$') == 2)
608
Bram Moolenaar62ef7972016-01-19 14:51:54 +0100609 " This wipes out the buffer, make sure that doesn't cause trouble.
Bram Moolenaar049cba92016-06-26 14:38:04 +0200610 Xclose
Bram Moolenaaree85df32017-03-19 14:19:50 +0100611
Bram Moolenaarf9ae1542019-11-18 22:02:16 +0100612 " When the current window is vertically split, jumping to a help match
613 " should open the help window at the top.
614 only | enew
615 let w1 = win_getid()
616 vert new
617 let w2 = win_getid()
618 Xnext
619 let w3 = win_getid()
620 call assert_true(&buftype == 'help')
621 call assert_true(winnr() == 1)
622 call assert_equal(['col', [['leaf', w3],
623 \ ['row', [['leaf', w2], ['leaf', w1]]]]], winlayout())
624
625 new | only
626 set buftype=help
627 set modified
628 call assert_fails('Xnext', 'E37:')
629 set nomodified
630 new | only
631
Bram Moolenaarb4d5fba2017-09-11 19:31:28 +0200632 if a:cchar == 'l'
633 " When a help window is present, running :lhelpgrep should reuse the
634 " help window and not the current window
635 new | only
636 call g:Xsetlist([], 'f')
637 help index.txt
638 wincmd w
639 lhelpgrep quickfix
640 call assert_equal(1, winnr())
641 call assert_notequal([], getloclist(1))
642 call assert_equal([], getloclist(2))
643 endif
644
Bram Moolenaar99895ea2017-04-20 22:44:47 +0200645 new | only
646
Bram Moolenaaree85df32017-03-19 14:19:50 +0100647 " Search for non existing help string
648 call assert_fails('Xhelpgrep a1b2c3', 'E480:')
Bram Moolenaar108e7b42018-10-11 17:39:12 +0200649 " Invalid regular expression
650 call assert_fails('Xhelpgrep \@<!', 'E480:')
Bram Moolenaar2b946c92016-11-12 18:14:44 +0100651endfunc
Bram Moolenaar049cba92016-06-26 14:38:04 +0200652
Bram Moolenaar2b946c92016-11-12 18:14:44 +0100653func Test_helpgrep()
Bram Moolenaar049cba92016-06-26 14:38:04 +0200654 call s:test_xhelpgrep('c')
Bram Moolenaarcf25fdb2016-08-03 21:04:53 +0200655 helpclose
Bram Moolenaar049cba92016-06-26 14:38:04 +0200656 call s:test_xhelpgrep('l')
Bram Moolenaar62ef7972016-01-19 14:51:54 +0100657endfunc
Bram Moolenaar75bdf6a2016-01-07 21:25:08 +0100658
Bram Moolenaar6920c722016-01-22 22:44:10 +0100659func Test_errortitle()
660 augroup QfBufWinEnter
661 au!
662 au BufWinEnter * :let g:a=get(w:, 'quickfix_title', 'NONE')
663 augroup END
664 copen
665 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'')'}]
666 call setqflist(a)
667 call assert_equal(':setqflist()', g:a)
668 augroup QfBufWinEnter
669 au!
670 augroup END
671 augroup! QfBufWinEnter
672endfunc
Bram Moolenaare27dba42016-03-15 14:11:10 +0100673
Bram Moolenaar5584df62016-03-18 21:00:51 +0100674func Test_vimgreptitle()
675 augroup QfBufWinEnter
676 au!
677 au BufWinEnter * :let g:a=get(w:, 'quickfix_title', 'NONE')
678 augroup END
679 try
680 vimgrep /pattern/j file
681 catch /E480/
682 endtry
683 copen
684 call assert_equal(': vimgrep /pattern/j file', g:a)
685 augroup QfBufWinEnter
686 au!
687 augroup END
688 augroup! QfBufWinEnter
689endfunc
690
Bram Moolenaar2b946c92016-11-12 18:14:44 +0100691func XqfTitleTests(cchar)
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +0200692 call s:setup_commands(a:cchar)
Bram Moolenaare27dba42016-03-15 14:11:10 +0100693
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +0200694 Xgetexpr ['file:1:1:message']
695 let l = g:Xgetlist()
Bram Moolenaare27dba42016-03-15 14:11:10 +0100696 if a:cchar == 'c'
697 call setqflist(l, 'r')
698 else
699 call setloclist(0, l, 'r')
700 endif
701
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +0200702 Xopen
Bram Moolenaare27dba42016-03-15 14:11:10 +0100703 if a:cchar == 'c'
704 let title = ':setqflist()'
705 else
706 let title = ':setloclist()'
707 endif
708 call assert_equal(title, w:quickfix_title)
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +0200709 Xclose
Bram Moolenaar2b946c92016-11-12 18:14:44 +0100710endfunc
Bram Moolenaare27dba42016-03-15 14:11:10 +0100711
712" Tests for quickfix window's title
Bram Moolenaar2b946c92016-11-12 18:14:44 +0100713func Test_qf_title()
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +0200714 call XqfTitleTests('c')
715 call XqfTitleTests('l')
Bram Moolenaar2b946c92016-11-12 18:14:44 +0100716endfunc
Bram Moolenaare27dba42016-03-15 14:11:10 +0100717
718" Tests for 'errorformat'
Bram Moolenaar2b946c92016-11-12 18:14:44 +0100719func Test_efm()
Bram Moolenaare27dba42016-03-15 14:11:10 +0100720 let save_efm = &efm
721 set efm=%EEEE%m,%WWWW%m,%+CCCC%.%#,%-GGGG%.%#
722 cgetexpr ['WWWW', 'EEEE', 'CCCC']
723 let l = strtrans(string(map(getqflist(), '[v:val.text, v:val.valid]')))
724 call assert_equal("[['W', 1], ['E^@CCCC', 1]]", l)
725 cgetexpr ['WWWW', 'GGGG', 'EEEE', 'CCCC']
726 let l = strtrans(string(map(getqflist(), '[v:val.text, v:val.valid]')))
727 call assert_equal("[['W', 1], ['E^@CCCC', 1]]", l)
728 cgetexpr ['WWWW', 'GGGG', 'ZZZZ', 'EEEE', 'CCCC', 'YYYY']
729 let l = strtrans(string(map(getqflist(), '[v:val.text, v:val.valid]')))
730 call assert_equal("[['W', 1], ['ZZZZ', 0], ['E^@CCCC', 1], ['YYYY', 0]]", l)
731 let &efm = save_efm
Bram Moolenaar2b946c92016-11-12 18:14:44 +0100732endfunc
Bram Moolenaar1ff2b642016-03-17 22:07:02 +0100733
734" This will test for problems in quickfix:
735" A. incorrectly copying location lists which caused the location list to show
736" a different name than the file that was actually being displayed.
737" B. not reusing the window for which the location list window is opened but
738" instead creating new windows.
739" C. make sure that the location list window is not reused instead of the
740" window it belongs to.
741"
742" Set up the test environment:
Bram Moolenaar2b946c92016-11-12 18:14:44 +0100743func ReadTestProtocol(name)
Bram Moolenaar1ff2b642016-03-17 22:07:02 +0100744 let base = substitute(a:name, '\v^test://(.*)%(\.[^.]+)?', '\1', '')
745 let word = substitute(base, '\v(.*)\..*', '\1', '')
746
747 setl modifiable
748 setl noreadonly
749 setl noswapfile
750 setl bufhidden=delete
751 %del _
752 " For problem 2:
753 " 'buftype' has to be set to reproduce the constant opening of new windows
754 setl buftype=nofile
755
756 call setline(1, word)
757
758 setl nomodified
759 setl nomodifiable
760 setl readonly
761 exe 'doautocmd BufRead ' . substitute(a:name, '\v^test://(.*)', '\1', '')
Bram Moolenaar2b946c92016-11-12 18:14:44 +0100762endfunc
Bram Moolenaar1ff2b642016-03-17 22:07:02 +0100763
Bram Moolenaar2b946c92016-11-12 18:14:44 +0100764func Test_locationlist()
Bram Moolenaar1ff2b642016-03-17 22:07:02 +0100765 enew
766
767 augroup testgroup
768 au!
769 autocmd BufReadCmd test://* call ReadTestProtocol(expand("<amatch>"))
770 augroup END
771
772 let words = [ "foo", "bar", "baz", "quux", "shmoo", "spam", "eggs" ]
773
774 let qflist = []
775 for word in words
776 call add(qflist, {'filename': 'test://' . word . '.txt', 'text': 'file ' . word . '.txt', })
777 " NOTE: problem 1:
778 " intentionally not setting 'lnum' so that the quickfix entries are not
779 " valid
Bram Moolenaaraad222c2019-09-06 22:46:09 +0200780 eval qflist->setloclist(0, ' ')
Bram Moolenaar1ff2b642016-03-17 22:07:02 +0100781 endfor
782
783 " Test A
784 lrewind
785 enew
786 lopen
Bram Moolenaar99895ea2017-04-20 22:44:47 +0200787 4lnext
Bram Moolenaar1ff2b642016-03-17 22:07:02 +0100788 vert split
789 wincmd L
790 lopen
791 wincmd p
792 lnext
793 let fileName = expand("%")
794 wincmd p
795 let locationListFileName = substitute(getline(line('.')), '\([^|]*\)|.*', '\1', '')
796 let fileName = substitute(fileName, '\\', '/', 'g')
797 let locationListFileName = substitute(locationListFileName, '\\', '/', 'g')
798 call assert_equal("test://bar.txt", fileName)
799 call assert_equal("test://bar.txt", locationListFileName)
800
801 wincmd n | only
802
803 " Test B:
804 lrewind
805 lopen
806 2
807 exe "normal \<CR>"
808 wincmd p
809 3
810 exe "normal \<CR>"
811 wincmd p
812 4
813 exe "normal \<CR>"
814 call assert_equal(2, winnr('$'))
815 wincmd n | only
816
817 " Test C:
818 lrewind
819 lopen
820 " Let's move the location list window to the top to check whether it (the
821 " first window found) will be reused when we try to open new windows:
822 wincmd K
823 2
824 exe "normal \<CR>"
825 wincmd p
826 3
827 exe "normal \<CR>"
828 wincmd p
829 4
830 exe "normal \<CR>"
831 1wincmd w
832 call assert_equal('quickfix', &buftype)
833 2wincmd w
834 let bufferName = expand("%")
835 let bufferName = substitute(bufferName, '\\', '/', 'g')
836 call assert_equal('test://quux.txt', bufferName)
837
838 wincmd n | only
839
840 augroup! testgroup
Bram Moolenaaree85df32017-03-19 14:19:50 +0100841endfunc
Bram Moolenaar0899d692016-03-19 13:35:03 +0100842
Bram Moolenaar2b946c92016-11-12 18:14:44 +0100843func Test_locationlist_curwin_was_closed()
Bram Moolenaar0899d692016-03-19 13:35:03 +0100844 augroup testgroup
845 au!
Bram Moolenaard106e5b2016-04-21 19:38:07 +0200846 autocmd BufReadCmd test_curwin.txt call R(expand("<amatch>"))
Bram Moolenaar0899d692016-03-19 13:35:03 +0100847 augroup END
848
Bram Moolenaar2b946c92016-11-12 18:14:44 +0100849 func! R(n)
Bram Moolenaar0899d692016-03-19 13:35:03 +0100850 quit
851 endfunc
852
853 new
854 let q = []
Bram Moolenaard106e5b2016-04-21 19:38:07 +0200855 call add(q, {'filename': 'test_curwin.txt' })
Bram Moolenaar0899d692016-03-19 13:35:03 +0100856 call setloclist(0, q)
857 call assert_fails('lrewind', 'E924:')
858
859 augroup! testgroup
Bram Moolenaaree85df32017-03-19 14:19:50 +0100860endfunc
Bram Moolenaar7eba3d22016-03-19 22:54:09 +0100861
Bram Moolenaar2b946c92016-11-12 18:14:44 +0100862func Test_locationlist_cross_tab_jump()
Bram Moolenaar0a9046f2016-10-15 19:28:13 +0200863 call writefile(['loclistfoo'], 'loclistfoo')
864 call writefile(['loclistbar'], 'loclistbar')
865 set switchbuf=usetab
866
867 edit loclistfoo
868 tabedit loclistbar
869 silent lgrep loclistfoo loclist*
870 call assert_equal(1, tabpagenr())
871
872 enew | only | tabonly
873 set switchbuf&vim
874 call delete('loclistfoo')
875 call delete('loclistbar')
Bram Moolenaar2b946c92016-11-12 18:14:44 +0100876endfunc
Bram Moolenaar0a9046f2016-10-15 19:28:13 +0200877
Bram Moolenaar7eba3d22016-03-19 22:54:09 +0100878" More tests for 'errorformat'
Bram Moolenaar2b946c92016-11-12 18:14:44 +0100879func Test_efm1()
Bram Moolenaar7eba3d22016-03-19 22:54:09 +0100880 if !has('unix')
881 " The 'errorformat' setting is different on non-Unix systems.
882 " This test works only on Unix-like systems.
883 return
884 endif
885
Bram Moolenaarc79745a2019-05-20 22:12:34 +0200886 let l =<< trim [DATA]
Bram Moolenaare7eb9272019-06-24 00:58:07 +0200887 "Xtestfile", line 4.12: 1506-045 (S) Undeclared identifier fd_set.
888 "Xtestfile", line 6 col 19; this is an error
889 gcc -c -DHAVE_CONFIsing-prototypes -I/usr/X11R6/include version.c
890 Xtestfile:9: parse error before `asd'
891 make: *** [vim] Error 1
892 in file "Xtestfile" linenr 10: there is an error
893
894 2 returned
895 "Xtestfile", line 11 col 1; this is an error
896 "Xtestfile", line 12 col 2; this is another error
897 "Xtestfile", line 14:10; this is an error in column 10
898 =Xtestfile=, line 15:10; this is another error, but in vcol 10 this time
899 "Xtestfile", linenr 16: yet another problem
900 Error in "Xtestfile" at line 17:
901 x should be a dot
902 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 17
903 ^
904 Error in "Xtestfile" at line 18:
905 x should be a dot
906 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 18
907 .............^
908 Error in "Xtestfile" at line 19:
909 x should be a dot
910 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 19
911 --------------^
912 Error in "Xtestfile" at line 20:
913 x should be a dot
914 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 20
915 ^
916
917 Does anyone know what is the problem and how to correction it?
918 "Xtestfile", line 21 col 9: What is the title of the quickfix window?
919 "Xtestfile", line 22 col 9: What is the title of the quickfix window?
Bram Moolenaarc79745a2019-05-20 22:12:34 +0200920 [DATA]
Bram Moolenaar7eba3d22016-03-19 22:54:09 +0100921
922 call writefile(l, 'Xerrorfile1')
923 call writefile(l[:-2], 'Xerrorfile2')
924
Bram Moolenaare7eb9272019-06-24 00:58:07 +0200925 let m =<< [DATA]
926 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 2
927 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 3
928 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 4
929 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 5
930 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 6
931 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 7
932 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 8
933 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 9
934 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 10
935 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 11
936 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 12
937 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 13
938 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 14
939 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 15
940 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 16
941 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 17
942 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 18
943 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 19
944 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 20
945 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 21
946 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 22
947[DATA]
Bram Moolenaar7eba3d22016-03-19 22:54:09 +0100948 call writefile(m, 'Xtestfile')
949
950 let save_efm = &efm
951 set efm+==%f=\\,\ line\ %l%*\\D%v%*[^\ ]\ %m
952 set efm^=%AError\ in\ \"%f\"\ at\ line\ %l:,%Z%p^,%C%m
953
954 exe 'cf Xerrorfile2'
955 clast
956 copen
957 call assert_equal(':cf Xerrorfile2', w:quickfix_title)
958 wincmd p
959
960 exe 'cf Xerrorfile1'
961 call assert_equal([4, 12], [line('.'), col('.')])
962 cn
963 call assert_equal([6, 19], [line('.'), col('.')])
964 cn
965 call assert_equal([9, 2], [line('.'), col('.')])
966 cn
967 call assert_equal([10, 2], [line('.'), col('.')])
968 cn
969 call assert_equal([11, 1], [line('.'), col('.')])
970 cn
971 call assert_equal([12, 2], [line('.'), col('.')])
972 cn
973 call assert_equal([14, 10], [line('.'), col('.')])
974 cn
975 call assert_equal([15, 3, 10], [line('.'), col('.'), virtcol('.')])
976 cn
977 call assert_equal([16, 2], [line('.'), col('.')])
978 cn
979 call assert_equal([17, 6], [line('.'), col('.')])
980 cn
981 call assert_equal([18, 7], [line('.'), col('.')])
982 cn
983 call assert_equal([19, 8], [line('.'), col('.')])
984 cn
985 call assert_equal([20, 9], [line('.'), col('.')])
986 clast
987 cprev
988 cprev
989 wincmd w
990 call assert_equal(':cf Xerrorfile1', w:quickfix_title)
991 wincmd p
992
993 let &efm = save_efm
994 call delete('Xerrorfile1')
995 call delete('Xerrorfile2')
996 call delete('Xtestfile')
Bram Moolenaaree85df32017-03-19 14:19:50 +0100997endfunc
Bram Moolenaarffec3c52016-03-23 20:55:42 +0100998
Bram Moolenaarab47c612016-06-14 22:02:26 +0200999" Test for quickfix directory stack support
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001000func s:dir_stack_tests(cchar)
Bram Moolenaar38df43b2016-06-20 21:41:12 +02001001 call s:setup_commands(a:cchar)
1002
Bram Moolenaarab47c612016-06-14 22:02:26 +02001003 let save_efm=&efm
1004 set efm=%DEntering\ dir\ '%f',%f:%l:%m,%XLeaving\ dir\ '%f'
1005
Bram Moolenaar361c8f02016-07-02 15:41:47 +02001006 let lines = ["Entering dir 'dir1/a'",
1007 \ 'habits2.txt:1:Nine Healthy Habits',
1008 \ "Entering dir 'b'",
1009 \ 'habits3.txt:2:0 Hours of television',
1010 \ 'habits2.txt:7:5 Small meals',
1011 \ "Entering dir 'dir1/c'",
1012 \ 'habits4.txt:3:1 Hour of exercise',
1013 \ "Leaving dir 'dir1/c'",
1014 \ "Leaving dir 'dir1/a'",
1015 \ 'habits1.txt:4:2 Liters of water',
1016 \ "Entering dir 'dir2'",
1017 \ 'habits5.txt:5:3 Cups of hot green tea',
1018 \ "Leaving dir 'dir2'"
1019 \]
Bram Moolenaarab47c612016-06-14 22:02:26 +02001020
Bram Moolenaar361c8f02016-07-02 15:41:47 +02001021 Xexpr ""
1022 for l in lines
1023 Xaddexpr l
1024 endfor
Bram Moolenaarab47c612016-06-14 22:02:26 +02001025
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001026 let qf = g:Xgetlist()
Bram Moolenaarab47c612016-06-14 22:02:26 +02001027
1028 call assert_equal('dir1/a/habits2.txt', bufname(qf[1].bufnr))
1029 call assert_equal(1, qf[1].lnum)
1030 call assert_equal('dir1/a/b/habits3.txt', bufname(qf[3].bufnr))
1031 call assert_equal(2, qf[3].lnum)
1032 call assert_equal('dir1/a/habits2.txt', bufname(qf[4].bufnr))
1033 call assert_equal(7, qf[4].lnum)
1034 call assert_equal('dir1/c/habits4.txt', bufname(qf[6].bufnr))
1035 call assert_equal(3, qf[6].lnum)
1036 call assert_equal('habits1.txt', bufname(qf[9].bufnr))
1037 call assert_equal(4, qf[9].lnum)
1038 call assert_equal('dir2/habits5.txt', bufname(qf[11].bufnr))
1039 call assert_equal(5, qf[11].lnum)
1040
1041 let &efm=save_efm
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001042endfunc
Bram Moolenaarab47c612016-06-14 22:02:26 +02001043
1044" Tests for %D and %X errorformat options
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001045func Test_efm_dirstack()
Bram Moolenaarab47c612016-06-14 22:02:26 +02001046 " Create the directory stack and files
1047 call mkdir('dir1')
1048 call mkdir('dir1/a')
1049 call mkdir('dir1/a/b')
1050 call mkdir('dir1/c')
1051 call mkdir('dir2')
1052
1053 let lines = ["Nine Healthy Habits",
1054 \ "0 Hours of television",
1055 \ "1 Hour of exercise",
1056 \ "2 Liters of water",
1057 \ "3 Cups of hot green tea",
1058 \ "4 Short mental breaks",
1059 \ "5 Small meals",
1060 \ "6 AM wake up time",
1061 \ "7 Minutes of laughter",
1062 \ "8 Hours of sleep (at least)",
1063 \ "9 PM end of the day and off to bed"
1064 \ ]
1065 call writefile(lines, 'habits1.txt')
1066 call writefile(lines, 'dir1/a/habits2.txt')
1067 call writefile(lines, 'dir1/a/b/habits3.txt')
1068 call writefile(lines, 'dir1/c/habits4.txt')
1069 call writefile(lines, 'dir2/habits5.txt')
1070
1071 call s:dir_stack_tests('c')
1072 call s:dir_stack_tests('l')
1073
1074 call delete('dir1', 'rf')
1075 call delete('dir2', 'rf')
1076 call delete('habits1.txt')
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001077endfunc
Bram Moolenaarab47c612016-06-14 22:02:26 +02001078
Bram Moolenaar9b457942016-10-09 16:10:05 +02001079" Test for resync after continuing an ignored message
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001080func Xefm_ignore_continuations(cchar)
Bram Moolenaar9b457942016-10-09 16:10:05 +02001081 call s:setup_commands(a:cchar)
1082
1083 let save_efm = &efm
1084
1085 let &efm =
1086 \ '%Eerror %m %l,' .
1087 \ '%-Wignored %m %l,' .
1088 \ '%+Cmore ignored %m %l,' .
1089 \ '%Zignored end'
1090 Xgetexpr ['ignored warning 1', 'more ignored continuation 2', 'ignored end', 'error resync 4']
1091 let l = map(g:Xgetlist(), '[v:val.text, v:val.valid, v:val.lnum, v:val.type]')
1092 call assert_equal([['resync', 1, 4, 'E']], l)
1093
1094 let &efm = save_efm
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001095endfunc
Bram Moolenaar9b457942016-10-09 16:10:05 +02001096
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001097func Test_efm_ignore_continuations()
Bram Moolenaar9b457942016-10-09 16:10:05 +02001098 call Xefm_ignore_continuations('c')
1099 call Xefm_ignore_continuations('l')
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001100endfunc
Bram Moolenaar9b457942016-10-09 16:10:05 +02001101
Bram Moolenaar0fcc7c62016-07-02 21:22:52 +02001102" Tests for invalid error format specifies
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001103func Xinvalid_efm_Tests(cchar)
Bram Moolenaar0fcc7c62016-07-02 21:22:52 +02001104 call s:setup_commands(a:cchar)
1105
Bram Moolenaar049cba92016-06-26 14:38:04 +02001106 let save_efm = &efm
1107
Bram Moolenaar0fcc7c62016-07-02 21:22:52 +02001108 set efm=%f:%l:%m,%f:%f:%l:%m
1109 call assert_fails('Xexpr "abc.txt:1:Hello world"', 'E372:')
1110
1111 set efm=%f:%l:%m,%f:%l:%r:%m
1112 call assert_fails('Xexpr "abc.txt:1:Hello world"', 'E373:')
1113
1114 set efm=%f:%l:%m,%O:%f:%l:%m
1115 call assert_fails('Xexpr "abc.txt:1:Hello world"', 'E373:')
1116
1117 set efm=%f:%l:%m,%f:%l:%*[^a-z
1118 call assert_fails('Xexpr "abc.txt:1:Hello world"', 'E374:')
1119
1120 set efm=%f:%l:%m,%f:%l:%*c
1121 call assert_fails('Xexpr "abc.txt:1:Hello world"', 'E375:')
1122
1123 set efm=%f:%l:%m,%L%M%N
1124 call assert_fails('Xexpr "abc.txt:1:Hello world"', 'E376:')
1125
1126 set efm=%f:%l:%m,%f:%l:%m:%R
1127 call assert_fails('Xexpr "abc.txt:1:Hello world"', 'E377:')
1128
1129 set efm=
1130 call assert_fails('Xexpr "abc.txt:1:Hello world"', 'E378:')
1131
1132 set efm=%DEntering\ dir\ abc,%f:%l:%m
1133 call assert_fails('Xexpr ["Entering dir abc", "abc.txt:1:Hello world"]', 'E379:')
1134
1135 let &efm = save_efm
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001136endfunc
Bram Moolenaar0fcc7c62016-07-02 21:22:52 +02001137
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001138func Test_invalid_efm()
Bram Moolenaar0fcc7c62016-07-02 21:22:52 +02001139 call Xinvalid_efm_Tests('c')
1140 call Xinvalid_efm_Tests('l')
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001141endfunc
Bram Moolenaar0fcc7c62016-07-02 21:22:52 +02001142
1143" TODO:
1144" Add tests for the following formats in 'errorformat'
1145" %r %O
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001146func Test_efm2()
Bram Moolenaar0fcc7c62016-07-02 21:22:52 +02001147 let save_efm = &efm
Bram Moolenaar049cba92016-06-26 14:38:04 +02001148
1149 " Test for %s format in efm
1150 set efm=%f:%s
1151 cexpr 'Xtestfile:Line search text'
Bram Moolenaar049cba92016-06-26 14:38:04 +02001152 let l = getqflist()
1153 call assert_equal(l[0].pattern, '^\VLine search text\$')
1154 call assert_equal(l[0].lnum, 0)
1155
Bram Moolenaaree85df32017-03-19 14:19:50 +01001156 let l = split(execute('clist', ''), "\n")
1157 call assert_equal([' 1 Xtestfile:^\VLine search text\$: '], l)
1158
Bram Moolenaar0fcc7c62016-07-02 21:22:52 +02001159 " Test for %P, %Q and %t format specifiers
Bram Moolenaarc79745a2019-05-20 22:12:34 +02001160 let lines =<< trim [DATA]
Bram Moolenaare7eb9272019-06-24 00:58:07 +02001161 [Xtestfile1]
1162 (1,17) error: ';' missing
1163 (21,2) warning: variable 'z' not defined
1164 (67,3) error: end of file found before string ended
1165 --
Bram Moolenaarc79745a2019-05-20 22:12:34 +02001166
Bram Moolenaare7eb9272019-06-24 00:58:07 +02001167 [Xtestfile2]
1168 --
Bram Moolenaarc79745a2019-05-20 22:12:34 +02001169
Bram Moolenaare7eb9272019-06-24 00:58:07 +02001170 [Xtestfile3]
1171 NEW compiler v1.1
1172 (2,2) warning: variable 'x' not defined
1173 (67,3) warning: 's' already defined
1174 --
Bram Moolenaarc79745a2019-05-20 22:12:34 +02001175 [DATA]
1176
Bram Moolenaaree85df32017-03-19 14:19:50 +01001177 set efm=%+P[%f]%r,(%l\\,%c)%*[\ ]%t%*[^:]:\ %m,%+Q--%r
Bram Moolenaar391b1dd2017-03-04 13:47:11 +01001178 " To exercise the push/pop file functionality in quickfix, the test files
1179 " need to be created.
1180 call writefile(['Line1'], 'Xtestfile1')
1181 call writefile(['Line2'], 'Xtestfile2')
1182 call writefile(['Line3'], 'Xtestfile3')
Bram Moolenaar361c8f02016-07-02 15:41:47 +02001183 cexpr ""
1184 for l in lines
1185 caddexpr l
1186 endfor
Bram Moolenaar049cba92016-06-26 14:38:04 +02001187 let l = getqflist()
Bram Moolenaaree85df32017-03-19 14:19:50 +01001188 call assert_equal(12, len(l))
Bram Moolenaar049cba92016-06-26 14:38:04 +02001189 call assert_equal(21, l[2].lnum)
1190 call assert_equal(2, l[2].col)
Bram Moolenaar0fcc7c62016-07-02 21:22:52 +02001191 call assert_equal('w', l[2].type)
1192 call assert_equal('e', l[3].type)
Bram Moolenaar391b1dd2017-03-04 13:47:11 +01001193 call delete('Xtestfile1')
1194 call delete('Xtestfile2')
1195 call delete('Xtestfile3')
Bram Moolenaar0fcc7c62016-07-02 21:22:52 +02001196
1197 " Tests for %E, %C and %Z format specifiers
Bram Moolenaarc79745a2019-05-20 22:12:34 +02001198 let lines =<< trim [DATA]
Bram Moolenaare7eb9272019-06-24 00:58:07 +02001199 Error 275
1200 line 42
1201 column 3
1202 ' ' expected after '--'
Bram Moolenaarc79745a2019-05-20 22:12:34 +02001203 [DATA]
1204
Bram Moolenaar0fcc7c62016-07-02 21:22:52 +02001205 set efm=%EError\ %n,%Cline\ %l,%Ccolumn\ %c,%Z%m
1206 cgetexpr lines
1207 let l = getqflist()
1208 call assert_equal(275, l[0].nr)
1209 call assert_equal(42, l[0].lnum)
1210 call assert_equal(3, l[0].col)
1211 call assert_equal('E', l[0].type)
1212 call assert_equal("\n' ' expected after '--'", l[0].text)
1213
1214 " Test for %>
Bram Moolenaarc79745a2019-05-20 22:12:34 +02001215 let lines =<< trim [DATA]
Bram Moolenaare7eb9272019-06-24 00:58:07 +02001216 Error in line 147 of foo.c:
1217 unknown variable 'i'
Bram Moolenaarc79745a2019-05-20 22:12:34 +02001218 [DATA]
1219
Bram Moolenaar0fcc7c62016-07-02 21:22:52 +02001220 set efm=unknown\ variable\ %m,%E%>Error\ in\ line\ %l\ of\ %f:,%Z%m
1221 cgetexpr lines
1222 let l = getqflist()
1223 call assert_equal(147, l[0].lnum)
1224 call assert_equal('E', l[0].type)
1225 call assert_equal("\nunknown variable 'i'", l[0].text)
Bram Moolenaar049cba92016-06-26 14:38:04 +02001226
Bram Moolenaare87e6dd2016-07-17 19:25:04 +02001227 " Test for %A, %C and other formats
Bram Moolenaarc79745a2019-05-20 22:12:34 +02001228 let lines =<< trim [DATA]
Bram Moolenaare7eb9272019-06-24 00:58:07 +02001229 ==============================================================
1230 FAIL: testGetTypeIdCachesResult (dbfacadeTest.DjsDBFacadeTest)
1231 --------------------------------------------------------------
1232 Traceback (most recent call last):
1233 File "unittests/dbfacadeTest.py", line 89, in testFoo
1234 self.assertEquals(34, dtid)
1235 File "/usr/lib/python2.2/unittest.py", line 286, in
1236 failUnlessEqual
1237 raise self.failureException, \\
1238 AssertionError: 34 != 33
1239
1240 --------------------------------------------------------------
1241 Ran 27 tests in 0.063s
Bram Moolenaarc79745a2019-05-20 22:12:34 +02001242 [DATA]
1243
Bram Moolenaare87e6dd2016-07-17 19:25:04 +02001244 set efm=%C\ %.%#,%A\ \ File\ \"%f\"\\,\ line\ %l%.%#,%Z%[%^\ ]%\\@=%m
1245 cgetexpr lines
1246 let l = getqflist()
1247 call assert_equal(8, len(l))
1248 call assert_equal(89, l[4].lnum)
1249 call assert_equal(1, l[4].valid)
1250 call assert_equal('unittests/dbfacadeTest.py', bufname(l[4].bufnr))
1251
Bram Moolenaard76ce852018-05-01 15:02:04 +02001252 " Test for %o
1253 set efm=%f(%o):%l\ %m
Bram Moolenaarbc7845d2018-05-01 16:26:48 +02001254 cgetexpr ['Xotestfile(Language.PureScript.Types):20 Error']
1255 call writefile(['Line1'], 'Xotestfile')
Bram Moolenaard76ce852018-05-01 15:02:04 +02001256 let l = getqflist()
1257 call assert_equal(1, len(l), string(l))
1258 call assert_equal('Language.PureScript.Types', l[0].module)
1259 copen
1260 call assert_equal('Language.PureScript.Types|20| Error', getline(1))
1261 call feedkeys("\<CR>", 'xn')
Bram Moolenaarbc7845d2018-05-01 16:26:48 +02001262 call assert_equal('Xotestfile', expand('%:t'))
Bram Moolenaard76ce852018-05-01 15:02:04 +02001263 cclose
1264 bd
Bram Moolenaarbc7845d2018-05-01 16:26:48 +02001265 call delete("Xotestfile")
Bram Moolenaard76ce852018-05-01 15:02:04 +02001266
Bram Moolenaar99895ea2017-04-20 22:44:47 +02001267 " The following sequence of commands used to crash Vim
1268 set efm=%W%m
1269 cgetexpr ['msg1']
1270 let l = getqflist()
1271 call assert_equal(1, len(l), string(l))
1272 call assert_equal('msg1', l[0].text)
1273 set efm=%C%m
1274 lexpr 'msg2'
1275 let l = getloclist(0)
1276 call assert_equal(1, len(l), string(l))
1277 call assert_equal('msg2', l[0].text)
1278 lopen
1279 call setqflist([], 'r')
1280 caddbuf
1281 let l = getqflist()
1282 call assert_equal(1, len(l), string(l))
1283 call assert_equal('|| msg2', l[0].text)
1284
Bram Moolenaar78ddc062018-05-15 21:56:34 +02001285 " When matching error lines, case should be ignored. Test for this.
1286 set noignorecase
1287 let l=getqflist({'lines' : ['Xtest:FOO10:Line 20'], 'efm':'%f:foo%l:%m'})
1288 call assert_equal(10, l.items[0].lnum)
1289 call assert_equal('Line 20', l.items[0].text)
1290 set ignorecase&
1291
Bram Moolenaar99895ea2017-04-20 22:44:47 +02001292 new | only
Bram Moolenaar049cba92016-06-26 14:38:04 +02001293 let &efm = save_efm
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001294endfunc
Bram Moolenaar049cba92016-06-26 14:38:04 +02001295
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001296func XquickfixChangedByAutocmd(cchar)
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001297 call s:setup_commands(a:cchar)
Bram Moolenaarffec3c52016-03-23 20:55:42 +01001298 if a:cchar == 'c'
Bram Moolenaarffec3c52016-03-23 20:55:42 +01001299 let ErrorNr = 'E925'
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001300 func! ReadFunc()
Bram Moolenaarffec3c52016-03-23 20:55:42 +01001301 colder
1302 cgetexpr []
1303 endfunc
1304 else
Bram Moolenaarffec3c52016-03-23 20:55:42 +01001305 let ErrorNr = 'E926'
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001306 func! ReadFunc()
Bram Moolenaarffec3c52016-03-23 20:55:42 +01001307 lolder
1308 lgetexpr []
1309 endfunc
1310 endif
1311
1312 augroup testgroup
1313 au!
Bram Moolenaard106e5b2016-04-21 19:38:07 +02001314 autocmd BufReadCmd test_changed.txt call ReadFunc()
Bram Moolenaarffec3c52016-03-23 20:55:42 +01001315 augroup END
1316
Bram Moolenaard106e5b2016-04-21 19:38:07 +02001317 new | only
Bram Moolenaarffec3c52016-03-23 20:55:42 +01001318 let words = [ "a", "b" ]
1319 let qflist = []
1320 for word in words
Bram Moolenaard106e5b2016-04-21 19:38:07 +02001321 call add(qflist, {'filename': 'test_changed.txt'})
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001322 call g:Xsetlist(qflist, ' ')
Bram Moolenaarffec3c52016-03-23 20:55:42 +01001323 endfor
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001324 call assert_fails('Xrewind', ErrorNr . ':')
Bram Moolenaarffec3c52016-03-23 20:55:42 +01001325
1326 augroup! testgroup
1327endfunc
1328
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001329func Test_quickfix_was_changed_by_autocmd()
Bram Moolenaarffec3c52016-03-23 20:55:42 +01001330 call XquickfixChangedByAutocmd('c')
1331 call XquickfixChangedByAutocmd('l')
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001332endfunc
Bram Moolenaar8b201792016-03-25 15:01:10 +01001333
1334func Test_caddbuffer_to_empty()
1335 helpgr quickfix
1336 call setqflist([], 'r')
1337 cad
Bram Moolenaarf68f1d72016-03-25 17:14:06 +01001338 try
1339 cn
1340 catch
1341 " number of matches is unknown
1342 call assert_true(v:exception =~ 'E553:')
1343 endtry
Bram Moolenaar8b201792016-03-25 15:01:10 +01001344 quit!
1345endfunc
Bram Moolenaar89c64d52016-03-27 18:44:40 +02001346
1347func Test_cgetexpr_works()
1348 " this must not crash Vim
1349 cgetexpr [$x]
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001350 lgetexpr [$x]
Bram Moolenaar89c64d52016-03-27 18:44:40 +02001351endfunc
Bram Moolenaarc1808d52016-04-18 20:04:00 +02001352
1353" Tests for the setqflist() and setloclist() functions
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001354func SetXlistTests(cchar, bnum)
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001355 call s:setup_commands(a:cchar)
Bram Moolenaarc1808d52016-04-18 20:04:00 +02001356
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001357 call g:Xsetlist([{'bufnr': a:bnum, 'lnum': 1},
Bram Moolenaarc1808d52016-04-18 20:04:00 +02001358 \ {'bufnr': a:bnum, 'lnum': 2}])
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001359 let l = g:Xgetlist()
Bram Moolenaarc1808d52016-04-18 20:04:00 +02001360 call assert_equal(2, len(l))
1361 call assert_equal(2, l[1].lnum)
1362
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001363 Xnext
1364 call g:Xsetlist([{'bufnr': a:bnum, 'lnum': 3}], 'a')
1365 let l = g:Xgetlist()
Bram Moolenaarc1808d52016-04-18 20:04:00 +02001366 call assert_equal(3, len(l))
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001367 Xnext
Bram Moolenaarc1808d52016-04-18 20:04:00 +02001368 call assert_equal(3, line('.'))
1369
Bram Moolenaar2b2b8ae2016-05-24 19:59:51 +02001370 " Appending entries to the list should not change the cursor position
1371 " in the quickfix window
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001372 Xwindow
Bram Moolenaar2b2b8ae2016-05-24 19:59:51 +02001373 1
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001374 call g:Xsetlist([{'bufnr': a:bnum, 'lnum': 4},
Bram Moolenaar2b2b8ae2016-05-24 19:59:51 +02001375 \ {'bufnr': a:bnum, 'lnum': 5}], 'a')
1376 call assert_equal(1, line('.'))
1377 close
1378
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001379 call g:Xsetlist([{'bufnr': a:bnum, 'lnum': 3},
Bram Moolenaarc1808d52016-04-18 20:04:00 +02001380 \ {'bufnr': a:bnum, 'lnum': 4},
1381 \ {'bufnr': a:bnum, 'lnum': 5}], 'r')
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001382 let l = g:Xgetlist()
Bram Moolenaarc1808d52016-04-18 20:04:00 +02001383 call assert_equal(3, len(l))
1384 call assert_equal(5, l[2].lnum)
1385
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001386 call g:Xsetlist([])
1387 let l = g:Xgetlist()
Bram Moolenaarc1808d52016-04-18 20:04:00 +02001388 call assert_equal(0, len(l))
Bram Moolenaaree85df32017-03-19 14:19:50 +01001389
Bram Moolenaarf1d21c82017-04-22 21:20:46 +02001390 " Tests for setting the 'valid' flag
1391 call g:Xsetlist([{'bufnr':a:bnum, 'lnum':4, 'valid':0}])
1392 Xwindow
1393 call assert_equal(1, winnr('$'))
1394 let l = g:Xgetlist()
1395 call g:Xsetlist(l)
1396 call assert_equal(0, g:Xgetlist()[0].valid)
Bram Moolenaar9752c722018-12-22 16:49:34 +01001397 " Adding a non-valid entry should not mark the list as having valid entries
1398 call g:Xsetlist([{'bufnr':a:bnum, 'lnum':5, 'valid':0}], 'a')
1399 Xwindow
1400 call assert_equal(1, winnr('$'))
1401
1402 " :cnext/:cprev should still work even with invalid entries in the list
1403 let l = [{'bufnr' : a:bnum, 'lnum' : 1, 'text' : '1', 'valid' : 0},
1404 \ {'bufnr' : a:bnum, 'lnum' : 2, 'text' : '2', 'valid' : 0}]
1405 call g:Xsetlist(l)
1406 Xnext
1407 call assert_equal(2, g:Xgetlist({'idx' : 0}).idx)
1408 Xprev
1409 call assert_equal(1, g:Xgetlist({'idx' : 0}).idx)
1410 " :cnext/:cprev should still work after appending invalid entries to an
1411 " empty list
1412 call g:Xsetlist([])
1413 call g:Xsetlist(l, 'a')
1414 Xnext
1415 call assert_equal(2, g:Xgetlist({'idx' : 0}).idx)
1416 Xprev
1417 call assert_equal(1, g:Xgetlist({'idx' : 0}).idx)
1418
Bram Moolenaarf1d21c82017-04-22 21:20:46 +02001419 call g:Xsetlist([{'text':'Text1', 'valid':1}])
1420 Xwindow
1421 call assert_equal(2, winnr('$'))
1422 Xclose
1423 let save_efm = &efm
1424 set efm=%m
1425 Xgetexpr 'TestMessage'
1426 let l = g:Xgetlist()
1427 call g:Xsetlist(l)
1428 call assert_equal(1, g:Xgetlist()[0].valid)
1429 let &efm = save_efm
1430
Bram Moolenaaree85df32017-03-19 14:19:50 +01001431 " Error cases:
1432 " Refer to a non-existing buffer and pass a non-dictionary type
1433 call assert_fails("call g:Xsetlist([{'bufnr':998, 'lnum':4}," .
1434 \ " {'bufnr':999, 'lnum':5}])", 'E92:')
1435 call g:Xsetlist([[1, 2,3]])
1436 call assert_equal(0, len(g:Xgetlist()))
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001437endfunc
Bram Moolenaarc1808d52016-04-18 20:04:00 +02001438
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001439func Test_setqflist()
Bram Moolenaarc1808d52016-04-18 20:04:00 +02001440 new Xtestfile | only
1441 let bnum = bufnr('%')
1442 call setline(1, range(1,5))
1443
1444 call SetXlistTests('c', bnum)
1445 call SetXlistTests('l', bnum)
1446
Bram Moolenaar1cee6932016-06-09 22:17:22 +02001447 enew!
Bram Moolenaarc1808d52016-04-18 20:04:00 +02001448 call delete('Xtestfile')
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001449endfunc
Bram Moolenaard106e5b2016-04-21 19:38:07 +02001450
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001451func Xlist_empty_middle(cchar)
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001452 call s:setup_commands(a:cchar)
1453
Bram Moolenaar1cee6932016-06-09 22:17:22 +02001454 " create three quickfix lists
Bram Moolenaaree85df32017-03-19 14:19:50 +01001455 let @/ = 'Test_'
1456 Xvimgrep // test_quickfix.vim
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001457 let testlen = len(g:Xgetlist())
Bram Moolenaar1cee6932016-06-09 22:17:22 +02001458 call assert_true(testlen > 0)
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001459 Xvimgrep empty test_quickfix.vim
1460 call assert_true(len(g:Xgetlist()) > 0)
1461 Xvimgrep matches test_quickfix.vim
1462 let matchlen = len(g:Xgetlist())
Bram Moolenaar1cee6932016-06-09 22:17:22 +02001463 call assert_true(matchlen > 0)
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001464 Xolder
Bram Moolenaar1cee6932016-06-09 22:17:22 +02001465 " make the middle list empty
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001466 call g:Xsetlist([], 'r')
1467 call assert_true(len(g:Xgetlist()) == 0)
1468 Xolder
1469 call assert_equal(testlen, len(g:Xgetlist()))
1470 Xnewer
1471 Xnewer
1472 call assert_equal(matchlen, len(g:Xgetlist()))
Bram Moolenaar1cee6932016-06-09 22:17:22 +02001473endfunc
1474
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001475func Test_setqflist_empty_middle()
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001476 call Xlist_empty_middle('c')
1477 call Xlist_empty_middle('l')
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001478endfunc
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001479
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001480func Xlist_empty_older(cchar)
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001481 call s:setup_commands(a:cchar)
1482
Bram Moolenaar1cee6932016-06-09 22:17:22 +02001483 " create three quickfix lists
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001484 Xvimgrep one test_quickfix.vim
1485 let onelen = len(g:Xgetlist())
Bram Moolenaar1cee6932016-06-09 22:17:22 +02001486 call assert_true(onelen > 0)
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001487 Xvimgrep two test_quickfix.vim
1488 let twolen = len(g:Xgetlist())
Bram Moolenaar1cee6932016-06-09 22:17:22 +02001489 call assert_true(twolen > 0)
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001490 Xvimgrep three test_quickfix.vim
1491 let threelen = len(g:Xgetlist())
Bram Moolenaar1cee6932016-06-09 22:17:22 +02001492 call assert_true(threelen > 0)
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001493 Xolder 2
Bram Moolenaar1cee6932016-06-09 22:17:22 +02001494 " make the first list empty, check the others didn't change
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001495 call g:Xsetlist([], 'r')
1496 call assert_true(len(g:Xgetlist()) == 0)
1497 Xnewer
1498 call assert_equal(twolen, len(g:Xgetlist()))
1499 Xnewer
1500 call assert_equal(threelen, len(g:Xgetlist()))
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001501endfunc
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001502
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001503func Test_setqflist_empty_older()
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001504 call Xlist_empty_older('c')
1505 call Xlist_empty_older('l')
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001506endfunc
Bram Moolenaar1cee6932016-06-09 22:17:22 +02001507
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001508func XquickfixSetListWithAct(cchar)
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001509 call s:setup_commands(a:cchar)
1510
Bram Moolenaard106e5b2016-04-21 19:38:07 +02001511 let list1 = [{'filename': 'fnameA', 'text': 'A'},
1512 \ {'filename': 'fnameB', 'text': 'B'}]
1513 let list2 = [{'filename': 'fnameC', 'text': 'C'},
1514 \ {'filename': 'fnameD', 'text': 'D'},
1515 \ {'filename': 'fnameE', 'text': 'E'}]
1516
Bram Moolenaareeb1b9c2019-02-10 22:59:04 +01001517 " {action} is unspecified. Same as specifying ' '.
Bram Moolenaard106e5b2016-04-21 19:38:07 +02001518 new | only
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001519 silent! Xnewer 99
1520 call g:Xsetlist(list1)
1521 call g:Xsetlist(list2)
1522 let li = g:Xgetlist()
Bram Moolenaard106e5b2016-04-21 19:38:07 +02001523 call assert_equal(3, len(li))
1524 call assert_equal('C', li[0]['text'])
1525 call assert_equal('D', li[1]['text'])
1526 call assert_equal('E', li[2]['text'])
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001527 silent! Xolder
1528 let li = g:Xgetlist()
Bram Moolenaard106e5b2016-04-21 19:38:07 +02001529 call assert_equal(2, len(li))
1530 call assert_equal('A', li[0]['text'])
1531 call assert_equal('B', li[1]['text'])
1532
1533 " {action} is specified ' '.
1534 new | only
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001535 silent! Xnewer 99
1536 call g:Xsetlist(list1)
1537 call g:Xsetlist(list2, ' ')
1538 let li = g:Xgetlist()
Bram Moolenaard106e5b2016-04-21 19:38:07 +02001539 call assert_equal(3, len(li))
1540 call assert_equal('C', li[0]['text'])
1541 call assert_equal('D', li[1]['text'])
1542 call assert_equal('E', li[2]['text'])
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001543 silent! Xolder
1544 let li = g:Xgetlist()
Bram Moolenaard106e5b2016-04-21 19:38:07 +02001545 call assert_equal(2, len(li))
1546 call assert_equal('A', li[0]['text'])
1547 call assert_equal('B', li[1]['text'])
1548
1549 " {action} is specified 'a'.
1550 new | only
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001551 silent! Xnewer 99
1552 call g:Xsetlist(list1)
1553 call g:Xsetlist(list2, 'a')
1554 let li = g:Xgetlist()
Bram Moolenaard106e5b2016-04-21 19:38:07 +02001555 call assert_equal(5, len(li))
1556 call assert_equal('A', li[0]['text'])
1557 call assert_equal('B', li[1]['text'])
1558 call assert_equal('C', li[2]['text'])
1559 call assert_equal('D', li[3]['text'])
1560 call assert_equal('E', li[4]['text'])
1561
1562 " {action} is specified 'r'.
1563 new | only
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001564 silent! Xnewer 99
1565 call g:Xsetlist(list1)
1566 call g:Xsetlist(list2, 'r')
1567 let li = g:Xgetlist()
Bram Moolenaard106e5b2016-04-21 19:38:07 +02001568 call assert_equal(3, len(li))
1569 call assert_equal('C', li[0]['text'])
1570 call assert_equal('D', li[1]['text'])
1571 call assert_equal('E', li[2]['text'])
1572
1573 " Test for wrong value.
1574 new | only
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001575 call assert_fails("call g:Xsetlist(0)", 'E714:')
1576 call assert_fails("call g:Xsetlist(list1, '')", 'E927:')
1577 call assert_fails("call g:Xsetlist(list1, 'aa')", 'E927:')
1578 call assert_fails("call g:Xsetlist(list1, ' a')", 'E927:')
1579 call assert_fails("call g:Xsetlist(list1, 0)", 'E928:')
Bram Moolenaard106e5b2016-04-21 19:38:07 +02001580endfunc
1581
Bram Moolenaara0ca7d02017-12-19 10:22:19 +01001582func Test_setqflist_invalid_nr()
1583 " The following command used to crash Vim
Bram Moolenaaraad222c2019-09-06 22:46:09 +02001584 eval []->setqflist(' ', {'nr' : $XXX_DOES_NOT_EXIST})
Bram Moolenaara0ca7d02017-12-19 10:22:19 +01001585endfunc
1586
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001587func Test_quickfix_set_list_with_act()
Bram Moolenaard106e5b2016-04-21 19:38:07 +02001588 call XquickfixSetListWithAct('c')
1589 call XquickfixSetListWithAct('l')
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001590endfunc
Bram Moolenaar6be8c8e2016-04-30 13:17:09 +02001591
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001592func XLongLinesTests(cchar)
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001593 let l = g:Xgetlist()
Bram Moolenaar6be8c8e2016-04-30 13:17:09 +02001594
Bram Moolenaar049cba92016-06-26 14:38:04 +02001595 call assert_equal(4, len(l))
Bram Moolenaar6be8c8e2016-04-30 13:17:09 +02001596 call assert_equal(1, l[0].lnum)
1597 call assert_equal(1, l[0].col)
Bram Moolenaar049cba92016-06-26 14:38:04 +02001598 call assert_equal(1975, len(l[0].text))
Bram Moolenaar6be8c8e2016-04-30 13:17:09 +02001599 call assert_equal(2, l[1].lnum)
1600 call assert_equal(1, l[1].col)
1601 call assert_equal(4070, len(l[1].text))
1602 call assert_equal(3, l[2].lnum)
1603 call assert_equal(1, l[2].col)
Bram Moolenaar049cba92016-06-26 14:38:04 +02001604 call assert_equal(4070, len(l[2].text))
1605 call assert_equal(4, l[3].lnum)
1606 call assert_equal(1, l[3].col)
1607 call assert_equal(10, len(l[3].text))
Bram Moolenaar6be8c8e2016-04-30 13:17:09 +02001608
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001609 call g:Xsetlist([], 'r')
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001610endfunc
Bram Moolenaar6be8c8e2016-04-30 13:17:09 +02001611
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001612func s:long_lines_tests(cchar)
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001613 call s:setup_commands(a:cchar)
1614
Bram Moolenaar6be8c8e2016-04-30 13:17:09 +02001615 let testfile = 'samples/quickfix.txt'
1616
1617 " file
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001618 exe 'Xgetfile' testfile
1619 call XLongLinesTests(a:cchar)
Bram Moolenaar6be8c8e2016-04-30 13:17:09 +02001620
1621 " list
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001622 Xexpr readfile(testfile)
1623 call XLongLinesTests(a:cchar)
Bram Moolenaar6be8c8e2016-04-30 13:17:09 +02001624
1625 " string
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001626 Xexpr join(readfile(testfile), "\n")
1627 call XLongLinesTests(a:cchar)
Bram Moolenaar6be8c8e2016-04-30 13:17:09 +02001628
1629 " buffer
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001630 exe 'edit' testfile
1631 exe 'Xbuffer' bufnr('%')
Bram Moolenaarf50df392016-06-21 21:33:34 +02001632 call XLongLinesTests(a:cchar)
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001633endfunc
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001634
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001635func Test_long_lines()
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001636 call s:long_lines_tests('c')
1637 call s:long_lines_tests('l')
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001638endfunc
Bram Moolenaar049cba92016-06-26 14:38:04 +02001639
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001640func s:create_test_file(filename)
Bram Moolenaar049cba92016-06-26 14:38:04 +02001641 let l = []
1642 for i in range(1, 20)
1643 call add(l, 'Line' . i)
1644 endfor
1645 call writefile(l, a:filename)
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001646endfunc
Bram Moolenaar049cba92016-06-26 14:38:04 +02001647
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001648func Test_switchbuf()
Bram Moolenaar049cba92016-06-26 14:38:04 +02001649 call s:create_test_file('Xqftestfile1')
1650 call s:create_test_file('Xqftestfile2')
1651 call s:create_test_file('Xqftestfile3')
1652
1653 new | only
1654 edit Xqftestfile1
1655 let file1_winid = win_getid()
1656 new Xqftestfile2
1657 let file2_winid = win_getid()
1658 cgetexpr ['Xqftestfile1:5:Line5',
1659 \ 'Xqftestfile1:6:Line6',
1660 \ 'Xqftestfile2:10:Line10',
1661 \ 'Xqftestfile2:11:Line11',
1662 \ 'Xqftestfile3:15:Line15',
1663 \ 'Xqftestfile3:16:Line16']
1664
1665 new
1666 let winid = win_getid()
1667 cfirst | cnext
1668 call assert_equal(winid, win_getid())
Bram Moolenaar99895ea2017-04-20 22:44:47 +02001669 2cnext
Bram Moolenaar049cba92016-06-26 14:38:04 +02001670 call assert_equal(winid, win_getid())
Bram Moolenaar99895ea2017-04-20 22:44:47 +02001671 2cnext
Bram Moolenaar049cba92016-06-26 14:38:04 +02001672 call assert_equal(winid, win_getid())
Bram Moolenaar049cba92016-06-26 14:38:04 +02001673
Bram Moolenaarf9ae1542019-11-18 22:02:16 +01001674 " Test for 'switchbuf' set to search for files in windows in the current
1675 " tabpage and jump to an existing window (if present)
Bram Moolenaar049cba92016-06-26 14:38:04 +02001676 set switchbuf=useopen
Bram Moolenaarf9ae1542019-11-18 22:02:16 +01001677 enew
Bram Moolenaar049cba92016-06-26 14:38:04 +02001678 cfirst | cnext
1679 call assert_equal(file1_winid, win_getid())
Bram Moolenaar99895ea2017-04-20 22:44:47 +02001680 2cnext
Bram Moolenaar049cba92016-06-26 14:38:04 +02001681 call assert_equal(file2_winid, win_getid())
Bram Moolenaar99895ea2017-04-20 22:44:47 +02001682 2cnext
Bram Moolenaar049cba92016-06-26 14:38:04 +02001683 call assert_equal(file2_winid, win_getid())
1684
Bram Moolenaarf9ae1542019-11-18 22:02:16 +01001685 " Test for 'switchbuf' set to search for files in tabpages and jump to an
1686 " existing tabpage (if present)
Bram Moolenaar049cba92016-06-26 14:38:04 +02001687 enew | only
1688 set switchbuf=usetab
1689 tabedit Xqftestfile1
1690 tabedit Xqftestfile2
Bram Moolenaar74240d32017-12-10 15:26:15 +01001691 tabedit Xqftestfile3
Bram Moolenaar049cba92016-06-26 14:38:04 +02001692 tabfirst
1693 cfirst | cnext
1694 call assert_equal(2, tabpagenr())
Bram Moolenaar99895ea2017-04-20 22:44:47 +02001695 2cnext
Bram Moolenaar049cba92016-06-26 14:38:04 +02001696 call assert_equal(3, tabpagenr())
Bram Moolenaar74240d32017-12-10 15:26:15 +01001697 6cnext
1698 call assert_equal(4, tabpagenr())
1699 2cpfile
1700 call assert_equal(2, tabpagenr())
1701 2cnfile
1702 call assert_equal(4, tabpagenr())
Bram Moolenaar049cba92016-06-26 14:38:04 +02001703 tabfirst | tabonly | enew
1704
Bram Moolenaarf9ae1542019-11-18 22:02:16 +01001705 " Test for 'switchbuf' set to open a new window for every file
Bram Moolenaar049cba92016-06-26 14:38:04 +02001706 set switchbuf=split
1707 cfirst | cnext
1708 call assert_equal(1, winnr('$'))
1709 cnext | cnext
1710 call assert_equal(2, winnr('$'))
1711 cnext | cnext
1712 call assert_equal(3, winnr('$'))
Bram Moolenaar049cba92016-06-26 14:38:04 +02001713
Bram Moolenaarf9ae1542019-11-18 22:02:16 +01001714 " Test for 'switchbuf' set to open a new tabpage for every file
Bram Moolenaar049cba92016-06-26 14:38:04 +02001715 set switchbuf=newtab
Bram Moolenaarf9ae1542019-11-18 22:02:16 +01001716 enew | only
Bram Moolenaar049cba92016-06-26 14:38:04 +02001717 cfirst | cnext
1718 call assert_equal(1, tabpagenr('$'))
1719 cnext | cnext
1720 call assert_equal(2, tabpagenr('$'))
1721 cnext | cnext
1722 call assert_equal(3, tabpagenr('$'))
1723 tabfirst | enew | tabonly | only
1724
Bram Moolenaar539aa6b2019-11-17 18:09:38 +01001725 set switchbuf=uselast
1726 split
1727 let last_winid = win_getid()
1728 copen
1729 exe "normal 1G\<CR>"
1730 call assert_equal(last_winid, win_getid())
1731 enew | only
1732
Bram Moolenaarf9ae1542019-11-18 22:02:16 +01001733 " With an empty 'switchbuf', jumping to a quickfix entry should open the
1734 " file in an existing window (if present)
Bram Moolenaar049cba92016-06-26 14:38:04 +02001735 set switchbuf=
1736 edit Xqftestfile1
1737 let file1_winid = win_getid()
1738 new Xqftestfile2
1739 let file2_winid = win_getid()
1740 copen
1741 exe "normal 1G\<CR>"
1742 call assert_equal(file1_winid, win_getid())
1743 copen
1744 exe "normal 3G\<CR>"
1745 call assert_equal(file2_winid, win_getid())
1746 copen | only
1747 exe "normal 5G\<CR>"
1748 call assert_equal(2, winnr('$'))
1749 call assert_equal(1, bufwinnr('Xqftestfile3'))
1750
Bram Moolenaar391b1dd2017-03-04 13:47:11 +01001751 " If only quickfix window is open in the current tabpage, jumping to an
Bram Moolenaar1bc353b2019-09-01 14:45:28 +02001752 " entry with 'switchbuf' set to 'usetab' should search in other tabpages.
Bram Moolenaar049cba92016-06-26 14:38:04 +02001753 enew | only
Bram Moolenaar391b1dd2017-03-04 13:47:11 +01001754 set switchbuf=usetab
1755 tabedit Xqftestfile1
1756 tabedit Xqftestfile2
1757 tabedit Xqftestfile3
1758 tabfirst
1759 copen | only
1760 clast
1761 call assert_equal(4, tabpagenr())
1762 tabfirst | tabonly | enew | only
Bram Moolenaar049cba92016-06-26 14:38:04 +02001763
Bram Moolenaarf9ae1542019-11-18 22:02:16 +01001764 " Jumping to a file that is not present in any of the tabpages and the
1765 " current tabpage doesn't have any usable windows, should open it in a new
1766 " window in the current tabpage.
1767 copen | only
1768 cfirst
1769 call assert_equal(1, tabpagenr())
1770 call assert_equal('Xqftestfile1', bufname(''))
1771
1772 " If opening a file changes 'switchbuf', then the new value should be
1773 " retained.
1774 call writefile(["vim: switchbuf=split"], 'Xqftestfile1')
1775 enew | only
1776 set switchbuf&vim
1777 cexpr "Xqftestfile1:1:10"
1778 call assert_equal('split', &switchbuf)
1779 call writefile(["vim: switchbuf=usetab"], 'Xqftestfile1')
1780 enew | only
1781 set switchbuf=useopen
1782 cexpr "Xqftestfile1:1:10"
1783 call assert_equal('usetab', &switchbuf)
1784 call writefile(["vim: switchbuf&vim"], 'Xqftestfile1')
1785 enew | only
1786 set switchbuf=useopen
1787 cexpr "Xqftestfile1:1:10"
1788 call assert_equal('', &switchbuf)
1789
Bram Moolenaar049cba92016-06-26 14:38:04 +02001790 call delete('Xqftestfile1')
1791 call delete('Xqftestfile2')
1792 call delete('Xqftestfile3')
Bram Moolenaar391b1dd2017-03-04 13:47:11 +01001793 set switchbuf&vim
1794
1795 enew | only
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001796endfunc
Bram Moolenaar049cba92016-06-26 14:38:04 +02001797
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001798func Xadjust_qflnum(cchar)
Bram Moolenaar049cba92016-06-26 14:38:04 +02001799 call s:setup_commands(a:cchar)
1800
1801 enew | only
1802
Bram Moolenaarc1542742016-07-20 21:44:37 +02001803 let fname = 'Xqftestfile' . a:cchar
1804 call s:create_test_file(fname)
1805 exe 'edit ' . fname
Bram Moolenaar049cba92016-06-26 14:38:04 +02001806
Bram Moolenaarc1542742016-07-20 21:44:37 +02001807 Xgetexpr [fname . ':5:Line5',
1808 \ fname . ':10:Line10',
1809 \ fname . ':15:Line15',
1810 \ fname . ':20:Line20']
Bram Moolenaar049cba92016-06-26 14:38:04 +02001811
1812 6,14delete
1813 call append(6, ['Buffer', 'Window'])
1814
1815 let l = g:Xgetlist()
Bram Moolenaar049cba92016-06-26 14:38:04 +02001816 call assert_equal(5, l[0].lnum)
1817 call assert_equal(6, l[2].lnum)
1818 call assert_equal(13, l[3].lnum)
1819
Bram Moolenaarf9ae1542019-11-18 22:02:16 +01001820 " If a file doesn't have any quickfix entries, then deleting lines in the
1821 " file should not update the quickfix list
1822 call g:Xsetlist([], 'f')
1823 1,2delete
1824 call assert_equal([], g:Xgetlist())
1825
Bram Moolenaar049cba92016-06-26 14:38:04 +02001826 enew!
Bram Moolenaarc1542742016-07-20 21:44:37 +02001827 call delete(fname)
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001828endfunc
Bram Moolenaar049cba92016-06-26 14:38:04 +02001829
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001830func Test_adjust_lnum()
Bram Moolenaarc1542742016-07-20 21:44:37 +02001831 call setloclist(0, [])
Bram Moolenaar049cba92016-06-26 14:38:04 +02001832 call Xadjust_qflnum('c')
Bram Moolenaarc1542742016-07-20 21:44:37 +02001833 call setqflist([])
Bram Moolenaar049cba92016-06-26 14:38:04 +02001834 call Xadjust_qflnum('l')
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001835endfunc
Bram Moolenaar049cba92016-06-26 14:38:04 +02001836
1837" Tests for the :grep/:lgrep and :grepadd/:lgrepadd commands
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001838func s:test_xgrep(cchar)
Bram Moolenaar049cba92016-06-26 14:38:04 +02001839 call s:setup_commands(a:cchar)
1840
1841 " The following lines are used for the grep test. Don't remove.
1842 " Grep_Test_Text: Match 1
1843 " Grep_Test_Text: Match 2
1844 " GrepAdd_Test_Text: Match 1
1845 " GrepAdd_Test_Text: Match 2
1846 enew! | only
1847 set makeef&vim
1848 silent Xgrep Grep_Test_Text: test_quickfix.vim
Bram Moolenaarf9ae1542019-11-18 22:02:16 +01001849 call assert_true(len(g:Xgetlist()) == 4)
Bram Moolenaar049cba92016-06-26 14:38:04 +02001850 Xopen
1851 call assert_true(w:quickfix_title =~ '^:grep')
1852 Xclose
1853 enew
1854 set makeef=Temp_File_##
1855 silent Xgrepadd GrepAdd_Test_Text: test_quickfix.vim
Bram Moolenaarf9ae1542019-11-18 22:02:16 +01001856 call assert_true(len(g:Xgetlist()) == 7)
1857
1858 call writefile(['Vim'], 'XtestTempFile')
1859 set makeef=XtestTempFile
1860 silent Xgrep Grep_Test_Text: test_quickfix.vim
1861 call assert_equal(4, len(g:Xgetlist()))
1862 call assert_false(filereadable('XtestTempFile'))
1863 set makeef&vim
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001864endfunc
Bram Moolenaar049cba92016-06-26 14:38:04 +02001865
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001866func Test_grep()
Bram Moolenaar049cba92016-06-26 14:38:04 +02001867 if !has('unix')
1868 " The grepprg may not be set on non-Unix systems
1869 return
1870 endif
1871
1872 call s:test_xgrep('c')
1873 call s:test_xgrep('l')
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001874endfunc
Bram Moolenaar361c8f02016-07-02 15:41:47 +02001875
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001876func Test_two_windows()
Bram Moolenaar361c8f02016-07-02 15:41:47 +02001877 " Use one 'errorformat' for two windows. Add an expression to each of them,
1878 " make sure they each keep their own state.
1879 set efm=%DEntering\ dir\ '%f',%f:%l:%m,%XLeaving\ dir\ '%f'
1880 call mkdir('Xone/a', 'p')
1881 call mkdir('Xtwo/a', 'p')
1882 let lines = ['1', '2', 'one one one', '4', 'two two two', '6', '7']
1883 call writefile(lines, 'Xone/a/one.txt')
1884 call writefile(lines, 'Xtwo/a/two.txt')
1885
1886 new one
1887 let one_id = win_getid()
1888 lexpr ""
1889 new two
1890 let two_id = win_getid()
1891 lexpr ""
1892
1893 laddexpr "Entering dir 'Xtwo/a'"
1894 call win_gotoid(one_id)
1895 laddexpr "Entering dir 'Xone/a'"
1896 call win_gotoid(two_id)
1897 laddexpr 'two.txt:5:two two two'
1898 call win_gotoid(one_id)
1899 laddexpr 'one.txt:3:one one one'
1900
1901 let loc_one = getloclist(one_id)
Bram Moolenaar361c8f02016-07-02 15:41:47 +02001902 call assert_equal('Xone/a/one.txt', bufname(loc_one[1].bufnr))
1903 call assert_equal(3, loc_one[1].lnum)
1904
1905 let loc_two = getloclist(two_id)
Bram Moolenaar361c8f02016-07-02 15:41:47 +02001906 call assert_equal('Xtwo/a/two.txt', bufname(loc_two[1].bufnr))
1907 call assert_equal(5, loc_two[1].lnum)
1908
1909 call win_gotoid(one_id)
1910 bwipe!
1911 call win_gotoid(two_id)
1912 bwipe!
1913 call delete('Xone', 'rf')
1914 call delete('Xtwo', 'rf')
1915endfunc
Bram Moolenaardcb17002016-07-07 18:58:59 +02001916
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001917func XbottomTests(cchar)
Bram Moolenaar537ef082016-07-09 17:56:19 +02001918 call s:setup_commands(a:cchar)
1919
Bram Moolenaarb6fa30c2017-03-29 14:19:25 +02001920 " Calling lbottom without any errors should fail
1921 if a:cchar == 'l'
1922 call assert_fails('lbottom', 'E776:')
1923 endif
1924
Bram Moolenaar875feea2017-06-11 16:07:51 +02001925 call g:Xsetlist([{'filename': 'foo', 'lnum': 42}])
Bram Moolenaar537ef082016-07-09 17:56:19 +02001926 Xopen
Bram Moolenaardcb17002016-07-07 18:58:59 +02001927 let wid = win_getid()
1928 call assert_equal(1, line('.'))
1929 wincmd w
Bram Moolenaar875feea2017-06-11 16:07:51 +02001930 call g:Xsetlist([{'filename': 'var', 'lnum': 24}], 'a')
Bram Moolenaar537ef082016-07-09 17:56:19 +02001931 Xbottom
Bram Moolenaardcb17002016-07-07 18:58:59 +02001932 call win_gotoid(wid)
1933 call assert_equal(2, line('.'))
Bram Moolenaar537ef082016-07-09 17:56:19 +02001934 Xclose
Bram Moolenaardcb17002016-07-07 18:58:59 +02001935endfunc
Bram Moolenaar537ef082016-07-09 17:56:19 +02001936
1937" Tests for the :cbottom and :lbottom commands
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001938func Test_cbottom()
Bram Moolenaar537ef082016-07-09 17:56:19 +02001939 call XbottomTests('c')
1940 call XbottomTests('l')
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001941endfunc
Bram Moolenaarf6acffb2016-07-16 16:54:24 +02001942
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001943func HistoryTest(cchar)
Bram Moolenaarf6acffb2016-07-16 16:54:24 +02001944 call s:setup_commands(a:cchar)
1945
Bram Moolenaarf6acffb2016-07-16 16:54:24 +02001946 " clear all lists after the first one, then replace the first one.
1947 call g:Xsetlist([])
Bram Moolenaarb6fa30c2017-03-29 14:19:25 +02001948 call assert_fails('Xolder 99', 'E380:')
Bram Moolenaarf6acffb2016-07-16 16:54:24 +02001949 let entry = {'filename': 'foo', 'lnum': 42}
1950 call g:Xsetlist([entry], 'r')
1951 call g:Xsetlist([entry, entry])
1952 call g:Xsetlist([entry, entry, entry])
1953 let res = split(execute(a:cchar . 'hist'), "\n")
1954 call assert_equal(3, len(res))
1955 let common = 'errors :set' . (a:cchar == 'c' ? 'qf' : 'loc') . 'list()'
1956 call assert_equal(' error list 1 of 3; 1 ' . common, res[0])
1957 call assert_equal(' error list 2 of 3; 2 ' . common, res[1])
1958 call assert_equal('> error list 3 of 3; 3 ' . common, res[2])
Bram Moolenaarb4d5fba2017-09-11 19:31:28 +02001959
Bram Moolenaar8ffc7c82019-05-05 21:00:26 +02001960 " Test for changing the quickfix lists
1961 call assert_equal(3, g:Xgetlist({'nr' : 0}).nr)
1962 exe '1' . a:cchar . 'hist'
1963 call assert_equal(1, g:Xgetlist({'nr' : 0}).nr)
1964 exe '3' . a:cchar . 'hist'
1965 call assert_equal(3, g:Xgetlist({'nr' : 0}).nr)
1966 call assert_fails('-2' . a:cchar . 'hist', 'E16:')
1967 call assert_fails('4' . a:cchar . 'hist', 'E16:')
1968
Bram Moolenaarb4d5fba2017-09-11 19:31:28 +02001969 call g:Xsetlist([], 'f')
1970 let l = split(execute(a:cchar . 'hist'), "\n")
1971 call assert_equal('No entries', l[0])
Bram Moolenaar8ffc7c82019-05-05 21:00:26 +02001972 if a:cchar == 'c'
1973 call assert_fails('4chist', 'E16:')
1974 else
1975 call assert_fails('4lhist', 'E776:')
1976 endif
Bram Moolenaar5b69c222019-01-11 14:50:06 +01001977
1978 " An empty list should still show the stack history
1979 call g:Xsetlist([])
1980 let res = split(execute(a:cchar . 'hist'), "\n")
1981 call assert_equal('> error list 1 of 1; 0 ' . common, res[0])
1982
1983 call g:Xsetlist([], 'f')
Bram Moolenaarf6acffb2016-07-16 16:54:24 +02001984endfunc
1985
1986func Test_history()
1987 call HistoryTest('c')
1988 call HistoryTest('l')
1989endfunc
Bram Moolenaar015102e2016-07-16 18:24:56 +02001990
1991func Test_duplicate_buf()
1992 " make sure we can get the highest buffer number
1993 edit DoesNotExist
1994 edit DoesNotExist2
1995 let last_buffer = bufnr("$")
1996
1997 " make sure only one buffer is created
1998 call writefile(['this one', 'that one'], 'Xgrepthis')
1999 vimgrep one Xgrepthis
2000 vimgrep one Xgrepthis
2001 call assert_equal(last_buffer + 1, bufnr("$"))
2002
2003 call delete('Xgrepthis')
2004endfunc
Bram Moolenaard823fa92016-08-12 16:29:27 +02002005
2006" Quickfix/Location list set/get properties tests
Bram Moolenaar2b946c92016-11-12 18:14:44 +01002007func Xproperty_tests(cchar)
Bram Moolenaard823fa92016-08-12 16:29:27 +02002008 call s:setup_commands(a:cchar)
2009
2010 " Error cases
2011 call assert_fails('call g:Xgetlist(99)', 'E715:')
2012 call assert_fails('call g:Xsetlist(99)', 'E714:')
2013 call assert_fails('call g:Xsetlist([], "a", [])', 'E715:')
2014
2015 " Set and get the title
Bram Moolenaarb6fa30c2017-03-29 14:19:25 +02002016 call g:Xsetlist([])
Bram Moolenaard823fa92016-08-12 16:29:27 +02002017 Xopen
2018 wincmd p
2019 call g:Xsetlist([{'filename':'foo', 'lnum':27}])
Bram Moolenaar86f100dc2017-06-28 21:26:27 +02002020 let s = g:Xsetlist([], 'a', {'title' : 'Sample'})
2021 call assert_equal(0, s)
Bram Moolenaard823fa92016-08-12 16:29:27 +02002022 let d = g:Xgetlist({"title":1})
2023 call assert_equal('Sample', d.title)
Bram Moolenaara2aa8a22018-04-24 13:55:00 +02002024 " Try setting title to a non-string value
2025 call assert_equal(-1, g:Xsetlist([], 'a', {'title' : ['Test']}))
2026 call assert_equal('Sample', g:Xgetlist({"title":1}).title)
Bram Moolenaard823fa92016-08-12 16:29:27 +02002027
2028 Xopen
2029 call assert_equal('Sample', w:quickfix_title)
2030 Xclose
2031
Bram Moolenaar2b529bb2016-08-27 13:35:35 +02002032 " Tests for action argument
2033 silent! Xolder 999
2034 let qfnr = g:Xgetlist({'all':1}).nr
2035 call g:Xsetlist([], 'r', {'title' : 'N1'})
2036 call assert_equal('N1', g:Xgetlist({'all':1}).title)
2037 call g:Xsetlist([], ' ', {'title' : 'N2'})
2038 call assert_equal(qfnr + 1, g:Xgetlist({'all':1}).nr)
Bram Moolenaar890680c2016-09-27 21:28:56 +02002039
2040 let res = g:Xgetlist({'nr': 0})
2041 call assert_equal(qfnr + 1, res.nr)
2042 call assert_equal(['nr'], keys(res))
2043
Bram Moolenaar2b529bb2016-08-27 13:35:35 +02002044 call g:Xsetlist([], ' ', {'title' : 'N3'})
2045 call assert_equal('N2', g:Xgetlist({'nr':2, 'title':1}).title)
2046
Bram Moolenaaree85df32017-03-19 14:19:50 +01002047 " Changing the title of an earlier quickfix list
Bram Moolenaar55b69262017-08-13 13:42:01 +02002048 call g:Xsetlist([], 'r', {'title' : 'NewTitle', 'nr' : 2})
Bram Moolenaaree85df32017-03-19 14:19:50 +01002049 call assert_equal('NewTitle', g:Xgetlist({'nr':2, 'title':1}).title)
2050
2051 " Changing the title of an invalid quickfix list
2052 call assert_equal(-1, g:Xsetlist([], ' ',
2053 \ {'title' : 'SomeTitle', 'nr' : 99}))
2054 call assert_equal(-1, g:Xsetlist([], ' ',
2055 \ {'title' : 'SomeTitle', 'nr' : 'abc'}))
2056
2057 if a:cchar == 'c'
2058 copen
2059 call assert_equal({'winid':win_getid()}, getqflist({'winid':1}))
2060 cclose
2061 endif
2062
Bram Moolenaard823fa92016-08-12 16:29:27 +02002063 " Invalid arguments
2064 call assert_fails('call g:Xgetlist([])', 'E715')
2065 call assert_fails('call g:Xsetlist([], "a", [])', 'E715')
2066 let s = g:Xsetlist([], 'a', {'abc':1})
2067 call assert_equal(-1, s)
2068
2069 call assert_equal({}, g:Xgetlist({'abc':1}))
Bram Moolenaara6d48492017-12-12 22:45:31 +01002070 call assert_equal('', g:Xgetlist({'nr':99, 'title':1}).title)
2071 call assert_equal('', g:Xgetlist({'nr':[], 'title':1}).title)
Bram Moolenaard823fa92016-08-12 16:29:27 +02002072
2073 if a:cchar == 'l'
Bram Moolenaar890680c2016-09-27 21:28:56 +02002074 call assert_equal({}, getloclist(99, {'title': 1}))
Bram Moolenaard823fa92016-08-12 16:29:27 +02002075 endif
Bram Moolenaar8f77c5a2017-04-30 14:21:00 +02002076
2077 " Context related tests
Bram Moolenaar86f100dc2017-06-28 21:26:27 +02002078 let s = g:Xsetlist([], 'a', {'context':[1,2,3]})
2079 call assert_equal(0, s)
Bram Moolenaar8f77c5a2017-04-30 14:21:00 +02002080 call test_garbagecollect_now()
2081 let d = g:Xgetlist({'context':1})
2082 call assert_equal([1,2,3], d.context)
2083 call g:Xsetlist([], 'a', {'context':{'color':'green'}})
2084 let d = g:Xgetlist({'context':1})
2085 call assert_equal({'color':'green'}, d.context)
2086 call g:Xsetlist([], 'a', {'context':"Context info"})
2087 let d = g:Xgetlist({'context':1})
2088 call assert_equal("Context info", d.context)
2089 call g:Xsetlist([], 'a', {'context':246})
2090 let d = g:Xgetlist({'context':1})
2091 call assert_equal(246, d.context)
2092 if a:cchar == 'l'
2093 " Test for copying context across two different location lists
2094 new | only
2095 let w1_id = win_getid()
2096 let l = [1]
2097 call setloclist(0, [], 'a', {'context':l})
2098 new
2099 let w2_id = win_getid()
2100 call add(l, 2)
2101 call assert_equal([1, 2], getloclist(w1_id, {'context':1}).context)
2102 call assert_equal([1, 2], getloclist(w2_id, {'context':1}).context)
2103 unlet! l
2104 call assert_equal([1, 2], getloclist(w2_id, {'context':1}).context)
2105 only
2106 call setloclist(0, [], 'f')
Bram Moolenaara6d48492017-12-12 22:45:31 +01002107 call assert_equal('', getloclist(0, {'context':1}).context)
Bram Moolenaar8f77c5a2017-04-30 14:21:00 +02002108 endif
Bram Moolenaar6e62da32017-05-28 08:16:25 +02002109
2110 " Test for changing the context of previous quickfix lists
2111 call g:Xsetlist([], 'f')
2112 Xexpr "One"
2113 Xexpr "Two"
2114 Xexpr "Three"
Bram Moolenaar55b69262017-08-13 13:42:01 +02002115 call g:Xsetlist([], 'r', {'context' : [1], 'nr' : 1})
2116 call g:Xsetlist([], 'a', {'context' : [2], 'nr' : 2})
Bram Moolenaar6e62da32017-05-28 08:16:25 +02002117 " Also, check for setting the context using quickfix list number zero.
Bram Moolenaar55b69262017-08-13 13:42:01 +02002118 call g:Xsetlist([], 'r', {'context' : [3], 'nr' : 0})
Bram Moolenaar6e62da32017-05-28 08:16:25 +02002119 call test_garbagecollect_now()
2120 let l = g:Xgetlist({'nr' : 1, 'context' : 1})
2121 call assert_equal([1], l.context)
2122 let l = g:Xgetlist({'nr' : 2, 'context' : 1})
2123 call assert_equal([2], l.context)
2124 let l = g:Xgetlist({'nr' : 3, 'context' : 1})
2125 call assert_equal([3], l.context)
2126
2127 " Test for changing the context through reference and for garbage
2128 " collection of quickfix context
2129 let l = ["red"]
2130 call g:Xsetlist([], ' ', {'context' : l})
2131 call add(l, "blue")
2132 let x = g:Xgetlist({'context' : 1})
2133 call add(x.context, "green")
2134 call assert_equal(["red", "blue", "green"], l)
2135 call assert_equal(["red", "blue", "green"], x.context)
2136 unlet l
2137 call test_garbagecollect_now()
2138 let m = g:Xgetlist({'context' : 1})
2139 call assert_equal(["red", "blue", "green"], m.context)
Bram Moolenaar6a8958d2017-06-22 21:33:20 +02002140
2141 " Test for setting/getting items
2142 Xexpr ""
2143 let qfprev = g:Xgetlist({'nr':0})
Bram Moolenaar86f100dc2017-06-28 21:26:27 +02002144 let s = g:Xsetlist([], ' ', {'title':'Green',
Bram Moolenaar6a8958d2017-06-22 21:33:20 +02002145 \ 'items' : [{'filename':'F1', 'lnum':10}]})
Bram Moolenaar86f100dc2017-06-28 21:26:27 +02002146 call assert_equal(0, s)
Bram Moolenaar6a8958d2017-06-22 21:33:20 +02002147 let qfcur = g:Xgetlist({'nr':0})
2148 call assert_true(qfcur.nr == qfprev.nr + 1)
2149 let l = g:Xgetlist({'items':1})
2150 call assert_equal('F1', bufname(l.items[0].bufnr))
2151 call assert_equal(10, l.items[0].lnum)
2152 call g:Xsetlist([], 'a', {'items' : [{'filename':'F2', 'lnum':20},
2153 \ {'filename':'F2', 'lnum':30}]})
2154 let l = g:Xgetlist({'items':1})
2155 call assert_equal('F2', bufname(l.items[2].bufnr))
2156 call assert_equal(30, l.items[2].lnum)
2157 call g:Xsetlist([], 'r', {'items' : [{'filename':'F3', 'lnum':40}]})
2158 let l = g:Xgetlist({'items':1})
2159 call assert_equal('F3', bufname(l.items[0].bufnr))
2160 call assert_equal(40, l.items[0].lnum)
2161 call g:Xsetlist([], 'r', {'items' : []})
2162 let l = g:Xgetlist({'items':1})
2163 call assert_equal(0, len(l.items))
2164
Bram Moolenaarb4d5fba2017-09-11 19:31:28 +02002165 call g:Xsetlist([], 'r', {'title' : 'TestTitle'})
2166 call g:Xsetlist([], 'r', {'items' : [{'filename' : 'F1', 'lnum' : 10, 'text' : 'L10'}]})
2167 call g:Xsetlist([], 'r', {'items' : [{'filename' : 'F1', 'lnum' : 10, 'text' : 'L10'}]})
2168 call assert_equal('TestTitle', g:Xgetlist({'title' : 1}).title)
2169
Bram Moolenaarc9cc9c72018-09-02 15:18:42 +02002170 " Test for getting id of window associated with a location list window
2171 if a:cchar == 'l'
2172 only
2173 call assert_equal(0, g:Xgetlist({'all' : 1}).filewinid)
2174 let wid = win_getid()
2175 Xopen
2176 call assert_equal(wid, g:Xgetlist({'filewinid' : 1}).filewinid)
2177 wincmd w
2178 call assert_equal(0, g:Xgetlist({'filewinid' : 1}).filewinid)
2179 only
2180 endif
2181
Bram Moolenaarae338332017-08-11 20:25:26 +02002182 " The following used to crash Vim with address sanitizer
2183 call g:Xsetlist([], 'f')
2184 call g:Xsetlist([], 'a', {'items' : [{'filename':'F1', 'lnum':10}]})
2185 call assert_equal(10, g:Xgetlist({'items':1}).items[0].lnum)
2186
Bram Moolenaara2aa8a22018-04-24 13:55:00 +02002187 " Try setting the items using a string
2188 call assert_equal(-1, g:Xsetlist([], ' ', {'items' : 'Test'}))
2189
Bram Moolenaar6a8958d2017-06-22 21:33:20 +02002190 " Save and restore the quickfix stack
2191 call g:Xsetlist([], 'f')
2192 call assert_equal(0, g:Xgetlist({'nr':'$'}).nr)
2193 Xexpr "File1:10:Line1"
2194 Xexpr "File2:20:Line2"
2195 Xexpr "File3:30:Line3"
2196 let last_qf = g:Xgetlist({'nr':'$'}).nr
2197 call assert_equal(3, last_qf)
2198 let qstack = []
2199 for i in range(1, last_qf)
2200 let qstack = add(qstack, g:Xgetlist({'nr':i, 'all':1}))
2201 endfor
2202 call g:Xsetlist([], 'f')
2203 for i in range(len(qstack))
2204 call g:Xsetlist([], ' ', qstack[i])
2205 endfor
2206 call assert_equal(3, g:Xgetlist({'nr':'$'}).nr)
2207 call assert_equal(10, g:Xgetlist({'nr':1, 'items':1}).items[0].lnum)
2208 call assert_equal(20, g:Xgetlist({'nr':2, 'items':1}).items[0].lnum)
2209 call assert_equal(30, g:Xgetlist({'nr':3, 'items':1}).items[0].lnum)
2210 call g:Xsetlist([], 'f')
2211
2212 " Swap two quickfix lists
2213 Xexpr "File1:10:Line10"
2214 Xexpr "File2:20:Line20"
2215 Xexpr "File3:30:Line30"
2216 call g:Xsetlist([], 'r', {'nr':1,'title':'Colors','context':['Colors']})
2217 call g:Xsetlist([], 'r', {'nr':2,'title':'Fruits','context':['Fruits']})
2218 let l1=g:Xgetlist({'nr':1,'all':1})
2219 let l2=g:Xgetlist({'nr':2,'all':1})
Bram Moolenaara539f4f2017-08-30 20:33:55 +02002220 let save_id = l1.id
2221 let l1.id=l2.id
2222 let l2.id=save_id
Bram Moolenaar6a8958d2017-06-22 21:33:20 +02002223 call g:Xsetlist([], 'r', l1)
2224 call g:Xsetlist([], 'r', l2)
2225 let newl1=g:Xgetlist({'nr':1,'all':1})
2226 let newl2=g:Xgetlist({'nr':2,'all':1})
Bram Moolenaarb4d5fba2017-09-11 19:31:28 +02002227 call assert_equal('Fruits', newl1.title)
Bram Moolenaar6a8958d2017-06-22 21:33:20 +02002228 call assert_equal(['Fruits'], newl1.context)
2229 call assert_equal('Line20', newl1.items[0].text)
Bram Moolenaarb4d5fba2017-09-11 19:31:28 +02002230 call assert_equal('Colors', newl2.title)
Bram Moolenaar6a8958d2017-06-22 21:33:20 +02002231 call assert_equal(['Colors'], newl2.context)
2232 call assert_equal('Line10', newl2.items[0].text)
2233 call g:Xsetlist([], 'f')
Bram Moolenaaree85df32017-03-19 14:19:50 +01002234endfunc
Bram Moolenaard823fa92016-08-12 16:29:27 +02002235
Bram Moolenaar2b946c92016-11-12 18:14:44 +01002236func Test_qf_property()
Bram Moolenaard823fa92016-08-12 16:29:27 +02002237 call Xproperty_tests('c')
2238 call Xproperty_tests('l')
Bram Moolenaaree85df32017-03-19 14:19:50 +01002239endfunc
Bram Moolenaar04c4ce62016-09-01 15:45:58 +02002240
Bram Moolenaar5b69c222019-01-11 14:50:06 +01002241" Test for setting the current index in the location/quickfix list
2242func Xtest_setqfidx(cchar)
2243 call s:setup_commands(a:cchar)
2244
2245 Xgetexpr "F1:10:1:Line1\nF2:20:2:Line2\nF3:30:3:Line3"
2246 Xgetexpr "F4:10:1:Line1\nF5:20:2:Line2\nF6:30:3:Line3"
2247 Xgetexpr "F7:10:1:Line1\nF8:20:2:Line2\nF9:30:3:Line3"
2248
2249 call g:Xsetlist([], 'a', {'nr' : 3, 'idx' : 2})
2250 call g:Xsetlist([], 'a', {'nr' : 2, 'idx' : 2})
2251 call g:Xsetlist([], 'a', {'nr' : 1, 'idx' : 3})
2252 Xolder 2
2253 Xopen
2254 call assert_equal(3, line('.'))
2255 Xnewer
2256 call assert_equal(2, line('.'))
2257 Xnewer
2258 call assert_equal(2, line('.'))
2259 " Update the current index with the quickfix window open
2260 wincmd w
2261 call g:Xsetlist([], 'a', {'nr' : 3, 'idx' : 3})
2262 Xopen
2263 call assert_equal(3, line('.'))
2264 Xclose
2265
2266 " Set the current index to the last entry
2267 call g:Xsetlist([], 'a', {'nr' : 1, 'idx' : '$'})
2268 call assert_equal(3, g:Xgetlist({'nr' : 1, 'idx' : 0}).idx)
2269 " A large value should set the index to the last index
2270 call g:Xsetlist([], 'a', {'nr' : 1, 'idx' : 1})
2271 call g:Xsetlist([], 'a', {'nr' : 1, 'idx' : 999})
2272 call assert_equal(3, g:Xgetlist({'nr' : 1, 'idx' : 0}).idx)
2273 " Invalid index values
2274 call g:Xsetlist([], 'a', {'nr' : 1, 'idx' : -1})
2275 call assert_equal(3, g:Xgetlist({'nr' : 1, 'idx' : 0}).idx)
2276 call g:Xsetlist([], 'a', {'nr' : 1, 'idx' : 0})
2277 call assert_equal(3, g:Xgetlist({'nr' : 1, 'idx' : 0}).idx)
2278 call g:Xsetlist([], 'a', {'nr' : 1, 'idx' : 'xx'})
2279 call assert_equal(3, g:Xgetlist({'nr' : 1, 'idx' : 0}).idx)
2280 call assert_fails("call g:Xsetlist([], 'a', {'nr':1, 'idx':[]})", 'E745:')
2281
2282 call g:Xsetlist([], 'f')
2283 new | only
2284endfunc
2285
2286func Test_setqfidx()
2287 call Xtest_setqfidx('c')
2288 call Xtest_setqfidx('l')
2289endfunc
2290
Bram Moolenaar04c4ce62016-09-01 15:45:58 +02002291" Tests for the QuickFixCmdPre/QuickFixCmdPost autocommands
Bram Moolenaar2b946c92016-11-12 18:14:44 +01002292func QfAutoCmdHandler(loc, cmd)
Bram Moolenaar04c4ce62016-09-01 15:45:58 +02002293 call add(g:acmds, a:loc . a:cmd)
Bram Moolenaar2b946c92016-11-12 18:14:44 +01002294endfunc
Bram Moolenaar04c4ce62016-09-01 15:45:58 +02002295
Bram Moolenaar2b946c92016-11-12 18:14:44 +01002296func Test_Autocmd()
Bram Moolenaar04c4ce62016-09-01 15:45:58 +02002297 autocmd QuickFixCmdPre * call QfAutoCmdHandler('pre', expand('<amatch>'))
2298 autocmd QuickFixCmdPost * call QfAutoCmdHandler('post', expand('<amatch>'))
2299
2300 let g:acmds = []
2301 cexpr "F1:10:Line 10"
2302 caddexpr "F1:20:Line 20"
2303 cgetexpr "F1:30:Line 30"
Bram Moolenaar1ed22762017-11-28 18:03:44 +01002304 cexpr ""
2305 caddexpr ""
2306 cgetexpr ""
2307 silent! cexpr non_existing_func()
2308 silent! caddexpr non_existing_func()
2309 silent! cgetexpr non_existing_func()
Bram Moolenaar04c4ce62016-09-01 15:45:58 +02002310 let l = ['precexpr',
2311 \ 'postcexpr',
2312 \ 'precaddexpr',
2313 \ 'postcaddexpr',
2314 \ 'precgetexpr',
2315 \ 'postcgetexpr',
Bram Moolenaar1ed22762017-11-28 18:03:44 +01002316 \ 'precexpr',
2317 \ 'postcexpr',
2318 \ 'precaddexpr',
2319 \ 'postcaddexpr',
2320 \ 'precgetexpr',
2321 \ 'postcgetexpr',
2322 \ 'precexpr',
2323 \ 'precaddexpr',
2324 \ 'precgetexpr']
2325 call assert_equal(l, g:acmds)
2326
2327 let g:acmds = []
2328 enew! | call append(0, "F2:10:Line 10")
2329 cbuffer!
2330 enew! | call append(0, "F2:20:Line 20")
2331 cgetbuffer
2332 enew! | call append(0, "F2:30:Line 30")
2333 caddbuffer
2334 new
2335 let bnum = bufnr('%')
2336 bunload
2337 exe 'silent! cbuffer! ' . bnum
2338 exe 'silent! cgetbuffer ' . bnum
2339 exe 'silent! caddbuffer ' . bnum
2340 enew!
2341 let l = ['precbuffer',
Bram Moolenaar04c4ce62016-09-01 15:45:58 +02002342 \ 'postcbuffer',
2343 \ 'precgetbuffer',
2344 \ 'postcgetbuffer',
2345 \ 'precaddbuffer',
Bram Moolenaar1ed22762017-11-28 18:03:44 +01002346 \ 'postcaddbuffer',
2347 \ 'precbuffer',
2348 \ 'precgetbuffer',
2349 \ 'precaddbuffer']
Bram Moolenaar04c4ce62016-09-01 15:45:58 +02002350 call assert_equal(l, g:acmds)
Bram Moolenaar1ed22762017-11-28 18:03:44 +01002351
2352 call writefile(['Xtest:1:Line1'], 'Xtest')
2353 call writefile([], 'Xempty')
2354 let g:acmds = []
2355 cfile Xtest
2356 caddfile Xtest
2357 cgetfile Xtest
2358 cfile Xempty
2359 caddfile Xempty
2360 cgetfile Xempty
2361 silent! cfile do_not_exist
2362 silent! caddfile do_not_exist
2363 silent! cgetfile do_not_exist
2364 let l = ['precfile',
2365 \ 'postcfile',
2366 \ 'precaddfile',
2367 \ 'postcaddfile',
2368 \ 'precgetfile',
2369 \ 'postcgetfile',
2370 \ 'precfile',
2371 \ 'postcfile',
2372 \ 'precaddfile',
2373 \ 'postcaddfile',
2374 \ 'precgetfile',
2375 \ 'postcgetfile',
2376 \ 'precfile',
2377 \ 'postcfile',
2378 \ 'precaddfile',
2379 \ 'postcaddfile',
2380 \ 'precgetfile',
2381 \ 'postcgetfile']
2382 call assert_equal(l, g:acmds)
2383
2384 let g:acmds = []
2385 helpgrep quickfix
2386 silent! helpgrep non_existing_help_topic
2387 vimgrep test Xtest
2388 vimgrepadd test Xtest
2389 silent! vimgrep non_existing_test Xtest
2390 silent! vimgrepadd non_existing_test Xtest
2391 set makeprg=
2392 silent! make
2393 set makeprg&
2394 let l = ['prehelpgrep',
2395 \ 'posthelpgrep',
2396 \ 'prehelpgrep',
2397 \ 'posthelpgrep',
2398 \ 'previmgrep',
2399 \ 'postvimgrep',
2400 \ 'previmgrepadd',
2401 \ 'postvimgrepadd',
2402 \ 'previmgrep',
2403 \ 'postvimgrep',
2404 \ 'previmgrepadd',
2405 \ 'postvimgrepadd',
2406 \ 'premake',
2407 \ 'postmake']
2408 call assert_equal(l, g:acmds)
2409
2410 if has('unix')
2411 " Run this test only on Unix-like systems. The grepprg may not be set on
2412 " non-Unix systems.
2413 " The following lines are used for the grep test. Don't remove.
2414 " Grep_Autocmd_Text: Match 1
2415 " GrepAdd_Autocmd_Text: Match 2
2416 let g:acmds = []
2417 silent grep Grep_Autocmd_Text test_quickfix.vim
2418 silent grepadd GrepAdd_Autocmd_Text test_quickfix.vim
2419 silent grep abc123def Xtest
2420 silent grepadd abc123def Xtest
2421 let l = ['pregrep',
2422 \ 'postgrep',
2423 \ 'pregrepadd',
2424 \ 'postgrepadd',
2425 \ 'pregrep',
2426 \ 'postgrep',
2427 \ 'pregrepadd',
2428 \ 'postgrepadd']
2429 call assert_equal(l, g:acmds)
2430 endif
2431
2432 call delete('Xtest')
2433 call delete('Xempty')
Bram Moolenaarb254af32017-12-18 19:48:58 +01002434 au! QuickFixCmdPre
2435 au! QuickFixCmdPost
Bram Moolenaar2b946c92016-11-12 18:14:44 +01002436endfunc
Bram Moolenaar21662be2016-11-06 14:46:44 +01002437
Bram Moolenaar2b946c92016-11-12 18:14:44 +01002438func Test_Autocmd_Exception()
Bram Moolenaar21662be2016-11-06 14:46:44 +01002439 set efm=%m
2440 lgetexpr '?'
2441
2442 try
2443 call DoesNotExit()
2444 catch
2445 lgetexpr '1'
2446 finally
2447 lgetexpr '1'
2448 endtry
2449
2450 call assert_equal('1', getloclist(0)[0].text)
2451
2452 set efm&vim
Bram Moolenaar2b946c92016-11-12 18:14:44 +01002453endfunc
Bram Moolenaar63bed3d2016-11-12 15:36:54 +01002454
Bram Moolenaar2b946c92016-11-12 18:14:44 +01002455func Test_caddbuffer_wrong()
2456 " This used to cause a memory access in freed memory.
Bram Moolenaar63bed3d2016-11-12 15:36:54 +01002457 let save_efm = &efm
2458 set efm=%EEEE%m,%WWWW,%+CCCC%>%#,%GGGG%.#
2459 cgetexpr ['WWWW', 'EEEE', 'CCCC']
2460 let &efm = save_efm
Bram Moolenaar2b946c92016-11-12 18:14:44 +01002461 caddbuffer
Bram Moolenaar63bed3d2016-11-12 15:36:54 +01002462 bwipe!
2463endfunc
Bram Moolenaar2b946c92016-11-12 18:14:44 +01002464
2465func Test_caddexpr_wrong()
2466 " This used to cause a memory access in freed memory.
2467 cbuffer
2468 cbuffer
2469 copen
2470 let save_efm = &efm
2471 set efm=%
2472 call assert_fails('caddexpr ""', 'E376:')
2473 let &efm = save_efm
2474endfunc
Bram Moolenaar7618e002016-11-13 15:09:26 +01002475
2476func Test_dirstack_cleanup()
2477 " This used to cause a memory access in freed memory.
2478 let save_efm = &efm
2479 lexpr '0'
2480 lopen
2481 fun X(c)
2482 let save_efm=&efm
2483 set efm=%D%f
2484 if a:c == 'c'
2485 caddexpr '::'
2486 else
2487 laddexpr ':0:0'
2488 endif
2489 let &efm=save_efm
2490 endfun
2491 call X('c')
2492 call X('l')
2493 call setqflist([], 'r')
2494 caddbuffer
2495 let &efm = save_efm
2496endfunc
Bram Moolenaar391b1dd2017-03-04 13:47:11 +01002497
2498" Tests for jumping to entries from the location list window and quickfix
2499" window
2500func Test_cwindow_jump()
2501 set efm=%f%%%l%%%m
2502 lgetexpr ["F1%10%Line 10", "F2%20%Line 20", "F3%30%Line 30"]
2503 lopen | only
2504 lfirst
2505 call assert_true(winnr('$') == 2)
2506 call assert_true(winnr() == 1)
2507 " Location list for the new window should be set
2508 call assert_true(getloclist(0)[2].text == 'Line 30')
2509
2510 " Open a scratch buffer
2511 " Open a new window and create a location list
2512 " Open the location list window and close the other window
2513 " Jump to an entry.
Bram Moolenaareeb1b9c2019-02-10 22:59:04 +01002514 " Should create a new window and jump to the entry. The scratch buffer
Bram Moolenaar391b1dd2017-03-04 13:47:11 +01002515 " should not be used.
2516 enew | only
2517 set buftype=nofile
2518 below new
2519 lgetexpr ["F1%10%Line 10", "F2%20%Line 20", "F3%30%Line 30"]
2520 lopen
2521 2wincmd c
2522 lnext
2523 call assert_true(winnr('$') == 3)
2524 call assert_true(winnr() == 2)
2525
2526 " Open two windows with two different location lists
2527 " Open the location list window and close the previous window
2528 " Jump to an entry in the location list window
2529 " Should open the file in the first window and not set the location list.
2530 enew | only
2531 lgetexpr ["F1%5%Line 5"]
2532 below new
2533 lgetexpr ["F1%10%Line 10", "F2%20%Line 20", "F3%30%Line 30"]
2534 lopen
2535 2wincmd c
2536 lnext
2537 call assert_true(winnr() == 1)
2538 call assert_true(getloclist(0)[0].text == 'Line 5')
2539
2540 enew | only
2541 cgetexpr ["F1%10%Line 10", "F2%20%Line 20", "F3%30%Line 30"]
2542 copen
2543 cnext
2544 call assert_true(winnr('$') == 2)
2545 call assert_true(winnr() == 1)
2546
Bram Moolenaarf9ae1542019-11-18 22:02:16 +01002547 " open the quickfix buffer in two windows and jump to an entry. Should open
2548 " the file in the first quickfix window.
2549 enew | only
2550 copen
2551 let bnum = bufnr('')
2552 exe 'sbuffer ' . bnum
2553 wincmd b
2554 cfirst
2555 call assert_equal(2, winnr())
2556 call assert_equal('F1', bufname(''))
2557 enew | only
2558 exe 'sb' bnum
2559 exe 'botright sb' bnum
2560 wincmd t
2561 clast
2562 call assert_equal(2, winnr())
2563 call assert_equal('quickfix', getwinvar(1, '&buftype'))
2564 call assert_equal('quickfix', getwinvar(3, '&buftype'))
2565
Bram Moolenaar391b1dd2017-03-04 13:47:11 +01002566 enew | only
2567 set efm&vim
2568endfunc
Bram Moolenaaree85df32017-03-19 14:19:50 +01002569
Bram Moolenaare00fdf32019-09-15 19:09:42 +02002570func Test_cwindow_highlight()
2571 CheckScreendump
2572
2573 let lines =<< trim END
2574 set t_u7=
2575 call setline(1, ['some', 'text', 'with', 'matches'])
2576 write XCwindow
2577 vimgrep e XCwindow
2578 redraw
2579 cwindow 4
2580 END
2581 call writefile(lines, 'XtestCwindow')
2582 let buf = RunVimInTerminal('-S XtestCwindow', #{rows: 12})
2583 call VerifyScreenDump(buf, 'Test_quickfix_cwindow_1', {})
2584
2585 call term_sendkeys(buf, ":cnext\<CR>")
2586 call VerifyScreenDump(buf, 'Test_quickfix_cwindow_2', {})
2587
2588 " clean up
2589 call StopVimInTerminal(buf)
2590 call delete('XtestCwindow')
2591 call delete('XCwindow')
2592endfunc
2593
Bram Moolenaaree85df32017-03-19 14:19:50 +01002594func XvimgrepTests(cchar)
2595 call s:setup_commands(a:cchar)
2596
2597 call writefile(['Editor:VIM vim',
2598 \ 'Editor:Emacs EmAcS',
2599 \ 'Editor:Notepad NOTEPAD'], 'Xtestfile1')
2600 call writefile(['Linux', 'MacOS', 'MS-Windows'], 'Xtestfile2')
2601
2602 " Error cases
2603 call assert_fails('Xvimgrep /abc *', 'E682:')
2604
2605 let @/=''
2606 call assert_fails('Xvimgrep // *', 'E35:')
2607
2608 call assert_fails('Xvimgrep abc', 'E683:')
2609 call assert_fails('Xvimgrep a1b2c3 Xtestfile1', 'E480:')
2610 call assert_fails('Xvimgrep pat Xa1b2c3', 'E480:')
2611
2612 Xexpr ""
2613 Xvimgrepadd Notepad Xtestfile1
2614 Xvimgrepadd MacOS Xtestfile2
2615 let l = g:Xgetlist()
2616 call assert_equal(2, len(l))
2617 call assert_equal('Editor:Notepad NOTEPAD', l[0].text)
2618
Bram Moolenaarf9ae1542019-11-18 22:02:16 +01002619 10Xvimgrep #\cvim#g Xtestfile?
Bram Moolenaaree85df32017-03-19 14:19:50 +01002620 let l = g:Xgetlist()
2621 call assert_equal(2, len(l))
2622 call assert_equal(8, l[0].col)
2623 call assert_equal(12, l[1].col)
2624
2625 1Xvimgrep ?Editor? Xtestfile*
2626 let l = g:Xgetlist()
2627 call assert_equal(1, len(l))
2628 call assert_equal('Editor:VIM vim', l[0].text)
2629
2630 edit +3 Xtestfile2
2631 Xvimgrep +\cemacs+j Xtestfile1
2632 let l = g:Xgetlist()
2633 call assert_equal('Xtestfile2', bufname(''))
2634 call assert_equal('Editor:Emacs EmAcS', l[0].text)
2635
Bram Moolenaar2225ebb2018-04-24 15:48:11 +02002636 " Test for unloading a buffer after vimgrep searched the buffer
2637 %bwipe
2638 Xvimgrep /Editor/j Xtestfile*
2639 call assert_equal(0, getbufinfo('Xtestfile1')[0].loaded)
2640 call assert_equal([], getbufinfo('Xtestfile2'))
2641
Bram Moolenaaree85df32017-03-19 14:19:50 +01002642 call delete('Xtestfile1')
2643 call delete('Xtestfile2')
2644endfunc
2645
2646" Tests for the :vimgrep command
2647func Test_vimgrep()
2648 call XvimgrepTests('c')
2649 call XvimgrepTests('l')
2650endfunc
Bram Moolenaar69f40be2017-04-02 15:15:49 +02002651
Bram Moolenaar1c299432018-10-28 14:36:09 +01002652" Test for incsearch highlighting of the :vimgrep pattern
2653" This test used to cause "E315: ml_get: invalid lnum" errors.
2654func Test_vimgrep_incsearch()
2655 enew
2656 set incsearch
2657 call test_override("char_avail", 1)
2658
2659 call feedkeys(":2vimgrep assert test_quickfix.vim test_cdo.vim\<CR>", "ntx")
2660 let l = getqflist()
2661 call assert_equal(2, len(l))
2662
2663 call test_override("ALL", 0)
2664 set noincsearch
2665endfunc
2666
Bram Moolenaar69f40be2017-04-02 15:15:49 +02002667func XfreeTests(cchar)
2668 call s:setup_commands(a:cchar)
2669
2670 enew | only
2671
2672 " Deleting the quickfix stack should work even When the current list is
2673 " somewhere in the middle of the stack
2674 Xexpr ['Xfile1:10:10:Line 10', 'Xfile1:15:15:Line 15']
2675 Xexpr ['Xfile2:20:20:Line 20', 'Xfile2:25:25:Line 25']
2676 Xexpr ['Xfile3:30:30:Line 30', 'Xfile3:35:35:Line 35']
2677 Xolder
2678 call g:Xsetlist([], 'f')
2679 call assert_equal(0, len(g:Xgetlist()))
2680
2681 " After deleting the stack, adding a new list should create a stack with a
2682 " single list.
2683 Xexpr ['Xfile1:10:10:Line 10', 'Xfile1:15:15:Line 15']
2684 call assert_equal(1, g:Xgetlist({'all':1}).nr)
2685
2686 " Deleting the stack from a quickfix window should update/clear the
2687 " quickfix/location list window.
2688 Xexpr ['Xfile1:10:10:Line 10', 'Xfile1:15:15:Line 15']
2689 Xexpr ['Xfile2:20:20:Line 20', 'Xfile2:25:25:Line 25']
2690 Xexpr ['Xfile3:30:30:Line 30', 'Xfile3:35:35:Line 35']
2691 Xolder
2692 Xwindow
2693 call g:Xsetlist([], 'f')
2694 call assert_equal(2, winnr('$'))
2695 call assert_equal(1, line('$'))
2696 Xclose
2697
2698 " Deleting the stack from a non-quickfix window should update/clear the
2699 " quickfix/location list window.
2700 Xexpr ['Xfile1:10:10:Line 10', 'Xfile1:15:15:Line 15']
2701 Xexpr ['Xfile2:20:20:Line 20', 'Xfile2:25:25:Line 25']
2702 Xexpr ['Xfile3:30:30:Line 30', 'Xfile3:35:35:Line 35']
2703 Xolder
2704 Xwindow
2705 wincmd p
2706 call g:Xsetlist([], 'f')
2707 call assert_equal(0, len(g:Xgetlist()))
2708 wincmd p
2709 call assert_equal(2, winnr('$'))
2710 call assert_equal(1, line('$'))
2711
2712 " After deleting the location list stack, if the location list window is
2713 " opened, then a new location list should be created. So opening the
2714 " location list window again should not create a new window.
2715 if a:cchar == 'l'
2716 lexpr ['Xfile1:10:10:Line 10', 'Xfile1:15:15:Line 15']
2717 wincmd p
2718 lopen
2719 call assert_equal(2, winnr('$'))
2720 endif
2721 Xclose
2722endfunc
2723
Bram Moolenaar74240d32017-12-10 15:26:15 +01002724" Tests for the quickfix free functionality
Bram Moolenaar69f40be2017-04-02 15:15:49 +02002725func Test_qf_free()
2726 call XfreeTests('c')
2727 call XfreeTests('l')
2728endfunc
Bram Moolenaar6e62da32017-05-28 08:16:25 +02002729
2730" Test for buffer overflow when parsing lines and adding new entries to
2731" the quickfix list.
2732func Test_bufoverflow()
2733 set efm=%f:%l:%m
2734 cgetexpr ['File1:100:' . repeat('x', 1025)]
2735
2736 set efm=%+GCompiler:\ %.%#,%f:%l:%m
2737 cgetexpr ['Compiler: ' . repeat('a', 1015), 'File1:10:Hello World']
2738
2739 set efm=%DEntering\ directory\ %f,%f:%l:%m
2740 cgetexpr ['Entering directory ' . repeat('a', 1006),
2741 \ 'File1:10:Hello World']
2742 set efm&vim
2743endfunc
2744
Bram Moolenaar875feea2017-06-11 16:07:51 +02002745" Tests for getting the quickfix stack size
2746func XsizeTests(cchar)
2747 call s:setup_commands(a:cchar)
2748
2749 call g:Xsetlist([], 'f')
2750 call assert_equal(0, g:Xgetlist({'nr':'$'}).nr)
Bram Moolenaara6d48492017-12-12 22:45:31 +01002751 call assert_equal('', g:Xgetlist({'nr':'$', 'all':1}).title)
2752 call assert_equal(0, g:Xgetlist({'nr':0}).nr)
Bram Moolenaar875feea2017-06-11 16:07:51 +02002753
2754 Xexpr "File1:10:Line1"
2755 Xexpr "File2:20:Line2"
2756 Xexpr "File3:30:Line3"
2757 Xolder | Xolder
2758 call assert_equal(3, g:Xgetlist({'nr':'$'}).nr)
2759 call g:Xsetlist([], 'f')
2760
2761 Xexpr "File1:10:Line1"
2762 Xexpr "File2:20:Line2"
2763 Xexpr "File3:30:Line3"
2764 Xolder | Xolder
2765 call g:Xsetlist([], 'a', {'nr':'$', 'title':'Compiler'})
2766 call assert_equal('Compiler', g:Xgetlist({'nr':3, 'all':1}).title)
2767endfunc
2768
2769func Test_Qf_Size()
2770 call XsizeTests('c')
2771 call XsizeTests('l')
2772endfunc
Bram Moolenaar18141832017-06-25 21:17:25 +02002773
Bram Moolenaar9c4feff2017-06-28 22:26:54 +02002774func Test_cclose_from_copen()
2775 augroup QF_Test
2776 au!
2777 au FileType qf :call assert_fails(':cclose', 'E788')
2778 augroup END
2779 copen
2780 augroup QF_Test
2781 au!
2782 augroup END
2783 augroup! QF_Test
2784endfunc
2785
Bram Moolenaar18141832017-06-25 21:17:25 +02002786func Test_cclose_in_autocmd()
2787 " Problem is only triggered if "starting" is zero, so that the OptionsSet
2788 " event will be triggered.
2789 call test_override('starting', 1)
2790 augroup QF_Test
2791 au!
2792 au FileType qf :call assert_fails(':cclose', 'E788')
2793 augroup END
2794 copen
2795 augroup QF_Test
2796 au!
2797 augroup END
2798 augroup! QF_Test
2799 call test_override('starting', 0)
2800endfunc
Bram Moolenaar9c4feff2017-06-28 22:26:54 +02002801
Bram Moolenaar379fb762018-08-30 15:58:28 +02002802" Check that ":file" without an argument is possible even when "curbuf_lock"
2803" is set.
2804func Test_file_from_copen()
2805 " Works without argument.
2806 augroup QF_Test
2807 au!
2808 au FileType qf file
2809 augroup END
2810 copen
2811
2812 augroup QF_Test
2813 au!
2814 augroup END
2815 cclose
2816
2817 " Fails with argument.
2818 augroup QF_Test
2819 au!
2820 au FileType qf call assert_fails(':file foo', 'E788')
2821 augroup END
2822 copen
2823 augroup QF_Test
2824 au!
2825 augroup END
2826 cclose
2827
2828 augroup! QF_Test
Bram Moolenaar6a0cc912019-10-26 16:48:44 +02002829endfunc
Bram Moolenaar379fb762018-08-30 15:58:28 +02002830
Bram Moolenaar9c4feff2017-06-28 22:26:54 +02002831func Test_resize_from_copen()
2832 augroup QF_Test
2833 au!
2834 au FileType qf resize 5
2835 augroup END
2836 try
2837 " This should succeed without any exception. No other buffers are
2838 " involved in the autocmd.
2839 copen
2840 finally
2841 augroup QF_Test
2842 au!
2843 augroup END
2844 augroup! QF_Test
2845 endtry
2846endfunc
Bram Moolenaara8788f42017-07-19 17:06:20 +02002847
2848" Tests for the quickfix buffer b:changedtick variable
2849func Xchangedtick_tests(cchar)
2850 call s:setup_commands(a:cchar)
2851
2852 new | only
2853
2854 Xexpr "" | Xexpr "" | Xexpr ""
2855
2856 Xopen
2857 Xolder
2858 Xolder
2859 Xaddexpr "F1:10:Line10"
2860 Xaddexpr "F2:20:Line20"
2861 call g:Xsetlist([{"filename":"F3", "lnum":30, "text":"Line30"}], 'a')
2862 call g:Xsetlist([], 'f')
2863 call assert_equal(8, getbufvar('%', 'changedtick'))
2864 Xclose
2865endfunc
2866
2867func Test_changedtick()
Bram Moolenaarae338332017-08-11 20:25:26 +02002868 call Xchangedtick_tests('c')
2869 call Xchangedtick_tests('l')
2870endfunc
2871
2872" Tests for parsing an expression using setqflist()
2873func Xsetexpr_tests(cchar)
2874 call s:setup_commands(a:cchar)
2875
2876 let t = ["File1:10:Line10", "File1:20:Line20"]
Bram Moolenaar2c809b72017-09-01 18:34:02 +02002877 call g:Xsetlist([], ' ', {'lines' : t})
2878 call g:Xsetlist([], 'a', {'lines' : ["File1:30:Line30"]})
Bram Moolenaarae338332017-08-11 20:25:26 +02002879
2880 let l = g:Xgetlist()
2881 call assert_equal(3, len(l))
2882 call assert_equal(20, l[1].lnum)
2883 call assert_equal('Line30', l[2].text)
Bram Moolenaar2c809b72017-09-01 18:34:02 +02002884 call g:Xsetlist([], 'r', {'lines' : ["File2:5:Line5"]})
Bram Moolenaarae338332017-08-11 20:25:26 +02002885 let l = g:Xgetlist()
2886 call assert_equal(1, len(l))
2887 call assert_equal('Line5', l[0].text)
Bram Moolenaar2c809b72017-09-01 18:34:02 +02002888 call assert_equal(-1, g:Xsetlist([], 'a', {'lines' : 10}))
2889 call assert_equal(-1, g:Xsetlist([], 'a', {'lines' : "F1:10:L10"}))
Bram Moolenaarae338332017-08-11 20:25:26 +02002890
2891 call g:Xsetlist([], 'f')
2892 " Add entries to multiple lists
Bram Moolenaar2c809b72017-09-01 18:34:02 +02002893 call g:Xsetlist([], 'a', {'nr' : 1, 'lines' : ["File1:10:Line10"]})
2894 call g:Xsetlist([], 'a', {'nr' : 2, 'lines' : ["File2:20:Line20"]})
2895 call g:Xsetlist([], 'a', {'nr' : 1, 'lines' : ["File1:15:Line15"]})
2896 call g:Xsetlist([], 'a', {'nr' : 2, 'lines' : ["File2:25:Line25"]})
Bram Moolenaarae338332017-08-11 20:25:26 +02002897 call assert_equal('Line15', g:Xgetlist({'nr':1, 'items':1}).items[1].text)
2898 call assert_equal('Line25', g:Xgetlist({'nr':2, 'items':1}).items[1].text)
Bram Moolenaar36538222017-09-02 19:51:44 +02002899
2900 " Adding entries using a custom efm
2901 set efm&
2902 call g:Xsetlist([], ' ', {'efm' : '%f#%l#%m',
2903 \ 'lines' : ["F1#10#L10", "F2#20#L20"]})
2904 call assert_equal(20, g:Xgetlist({'items':1}).items[1].lnum)
2905 call g:Xsetlist([], 'a', {'efm' : '%f#%l#%m', 'lines' : ["F3:30:L30"]})
2906 call assert_equal('F3:30:L30', g:Xgetlist({'items':1}).items[2].text)
2907 call assert_equal(20, g:Xgetlist({'items':1}).items[1].lnum)
2908 call assert_equal(-1, g:Xsetlist([], 'a', {'efm' : [],
2909 \ 'lines' : ['F1:10:L10']}))
Bram Moolenaarae338332017-08-11 20:25:26 +02002910endfunc
2911
2912func Test_setexpr()
2913 call Xsetexpr_tests('c')
2914 call Xsetexpr_tests('l')
2915endfunc
2916
2917" Tests for per quickfix/location list directory stack
2918func Xmultidirstack_tests(cchar)
2919 call s:setup_commands(a:cchar)
2920
2921 call g:Xsetlist([], 'f')
2922 Xexpr "" | Xexpr ""
2923
Bram Moolenaar2c809b72017-09-01 18:34:02 +02002924 call g:Xsetlist([], 'a', {'nr' : 1, 'lines' : ["Entering dir 'Xone/a'"]})
2925 call g:Xsetlist([], 'a', {'nr' : 2, 'lines' : ["Entering dir 'Xtwo/a'"]})
2926 call g:Xsetlist([], 'a', {'nr' : 1, 'lines' : ["one.txt:3:one one one"]})
2927 call g:Xsetlist([], 'a', {'nr' : 2, 'lines' : ["two.txt:5:two two two"]})
Bram Moolenaarae338332017-08-11 20:25:26 +02002928
2929 let l1 = g:Xgetlist({'nr':1, 'items':1})
2930 let l2 = g:Xgetlist({'nr':2, 'items':1})
2931 call assert_equal('Xone/a/one.txt', bufname(l1.items[1].bufnr))
2932 call assert_equal(3, l1.items[1].lnum)
2933 call assert_equal('Xtwo/a/two.txt', bufname(l2.items[1].bufnr))
2934 call assert_equal(5, l2.items[1].lnum)
2935endfunc
2936
2937func Test_multidirstack()
2938 call mkdir('Xone/a', 'p')
2939 call mkdir('Xtwo/a', 'p')
2940 let lines = ['1', '2', 'one one one', '4', 'two two two', '6', '7']
2941 call writefile(lines, 'Xone/a/one.txt')
2942 call writefile(lines, 'Xtwo/a/two.txt')
2943 let save_efm = &efm
2944 set efm=%DEntering\ dir\ '%f',%f:%l:%m,%XLeaving\ dir\ '%f'
2945
2946 call Xmultidirstack_tests('c')
2947 call Xmultidirstack_tests('l')
2948
2949 let &efm = save_efm
2950 call delete('Xone', 'rf')
2951 call delete('Xtwo', 'rf')
2952endfunc
2953
2954" Tests for per quickfix/location list file stack
2955func Xmultifilestack_tests(cchar)
2956 call s:setup_commands(a:cchar)
2957
2958 call g:Xsetlist([], 'f')
2959 Xexpr "" | Xexpr ""
2960
Bram Moolenaar2c809b72017-09-01 18:34:02 +02002961 call g:Xsetlist([], 'a', {'nr' : 1, 'lines' : ["[one.txt]"]})
2962 call g:Xsetlist([], 'a', {'nr' : 2, 'lines' : ["[two.txt]"]})
2963 call g:Xsetlist([], 'a', {'nr' : 1, 'lines' : ["(3,5) one one one"]})
2964 call g:Xsetlist([], 'a', {'nr' : 2, 'lines' : ["(5,9) two two two"]})
Bram Moolenaarae338332017-08-11 20:25:26 +02002965
2966 let l1 = g:Xgetlist({'nr':1, 'items':1})
2967 let l2 = g:Xgetlist({'nr':2, 'items':1})
2968 call assert_equal('one.txt', bufname(l1.items[1].bufnr))
2969 call assert_equal(3, l1.items[1].lnum)
2970 call assert_equal('two.txt', bufname(l2.items[1].bufnr))
2971 call assert_equal(5, l2.items[1].lnum)
Bram Moolenaare333e792018-04-08 13:27:39 +02002972
2973 " Test for start of a new error line in the same line where a previous
2974 " error line ends with a file stack.
2975 let efm_val = 'Error\ l%l\ in\ %f,'
2976 let efm_val .= '%-P%>(%f%r,Error\ l%l\ in\ %m,%-Q)%r'
2977 let l = g:Xgetlist({'lines' : [
2978 \ '(one.txt',
2979 \ 'Error l4 in one.txt',
2980 \ ') (two.txt',
2981 \ 'Error l6 in two.txt',
2982 \ ')',
2983 \ 'Error l8 in one.txt'
2984 \ ], 'efm' : efm_val})
2985 call assert_equal(3, len(l.items))
2986 call assert_equal('one.txt', bufname(l.items[0].bufnr))
2987 call assert_equal(4, l.items[0].lnum)
2988 call assert_equal('one.txt', l.items[0].text)
2989 call assert_equal('two.txt', bufname(l.items[1].bufnr))
2990 call assert_equal(6, l.items[1].lnum)
2991 call assert_equal('two.txt', l.items[1].text)
2992 call assert_equal('one.txt', bufname(l.items[2].bufnr))
2993 call assert_equal(8, l.items[2].lnum)
2994 call assert_equal('', l.items[2].text)
Bram Moolenaarae338332017-08-11 20:25:26 +02002995endfunc
2996
2997func Test_multifilestack()
2998 let lines = ['1', '2', 'one one one', '4', 'two two two', '6', '7']
2999 call writefile(lines, 'one.txt')
3000 call writefile(lines, 'two.txt')
3001 let save_efm = &efm
3002 set efm=%+P[%f],(%l\\,%c)\ %m,%-Q
3003
3004 call Xmultifilestack_tests('c')
3005 call Xmultifilestack_tests('l')
3006
3007 let &efm = save_efm
3008 call delete('one.txt')
3009 call delete('two.txt')
3010endfunc
3011
3012" Tests for per buffer 'efm' setting
3013func Test_perbuf_efm()
3014 call writefile(["File1-10-Line10"], 'one.txt')
3015 call writefile(["File2#20#Line20"], 'two.txt')
3016 set efm=%f#%l#%m
3017 new | only
3018 new
3019 setlocal efm=%f-%l-%m
3020 cfile one.txt
3021 wincmd w
3022 caddfile two.txt
3023
3024 let l = getqflist()
3025 call assert_equal(10, l[0].lnum)
3026 call assert_equal('Line20', l[1].text)
3027
3028 set efm&
3029 new | only
3030 call delete('one.txt')
3031 call delete('two.txt')
Bram Moolenaara8788f42017-07-19 17:06:20 +02003032endfunc
Bram Moolenaard28cc3f2017-07-27 22:03:50 +02003033
3034" Open multiple help windows using ":lhelpgrep
3035" This test used to crash Vim
3036func Test_Multi_LL_Help()
3037 new | only
3038 lhelpgrep window
3039 lopen
3040 e#
3041 lhelpgrep buffer
3042 call assert_equal(3, winnr('$'))
3043 call assert_true(len(getloclist(1)) != 0)
3044 call assert_true(len(getloclist(2)) != 0)
3045 new | only
3046endfunc
Bram Moolenaar55b69262017-08-13 13:42:01 +02003047
3048" Tests for adding new quickfix lists using setqflist()
3049func XaddQf_tests(cchar)
3050 call s:setup_commands(a:cchar)
3051
3052 " Create a new list using ' ' for action
3053 call g:Xsetlist([], 'f')
3054 call g:Xsetlist([], ' ', {'title' : 'Test1'})
3055 let l = g:Xgetlist({'nr' : '$', 'all' : 1})
3056 call assert_equal(1, l.nr)
3057 call assert_equal('Test1', l.title)
3058
3059 " Create a new list using ' ' for action and '$' for 'nr'
3060 call g:Xsetlist([], 'f')
3061 call g:Xsetlist([], ' ', {'title' : 'Test2', 'nr' : '$'})
3062 let l = g:Xgetlist({'nr' : '$', 'all' : 1})
3063 call assert_equal(1, l.nr)
3064 call assert_equal('Test2', l.title)
3065
3066 " Create a new list using 'a' for action
3067 call g:Xsetlist([], 'f')
3068 call g:Xsetlist([], 'a', {'title' : 'Test3'})
3069 let l = g:Xgetlist({'nr' : '$', 'all' : 1})
3070 call assert_equal(1, l.nr)
3071 call assert_equal('Test3', l.title)
3072
3073 " Create a new list using 'a' for action and '$' for 'nr'
3074 call g:Xsetlist([], 'f')
3075 call g:Xsetlist([], 'a', {'title' : 'Test3', 'nr' : '$'})
3076 call g:Xsetlist([], 'a', {'title' : 'Test4'})
3077 let l = g:Xgetlist({'nr' : '$', 'all' : 1})
3078 call assert_equal(1, l.nr)
3079 call assert_equal('Test4', l.title)
3080
3081 " Adding a quickfix list should remove all the lists following the current
3082 " list.
3083 Xexpr "" | Xexpr "" | Xexpr ""
3084 silent! 10Xolder
3085 call g:Xsetlist([], ' ', {'title' : 'Test5'})
3086 let l = g:Xgetlist({'nr' : '$', 'all' : 1})
3087 call assert_equal(2, l.nr)
3088 call assert_equal('Test5', l.title)
3089
3090 " Add a quickfix list using '$' as the list number.
3091 let lastqf = g:Xgetlist({'nr':'$'}).nr
3092 silent! 99Xolder
3093 call g:Xsetlist([], ' ', {'nr' : '$', 'title' : 'Test6'})
3094 let l = g:Xgetlist({'nr' : '$', 'all' : 1})
3095 call assert_equal(lastqf + 1, l.nr)
3096 call assert_equal('Test6', l.title)
3097
3098 " Add a quickfix list using 'nr' set to one more than the quickfix
3099 " list size.
3100 let lastqf = g:Xgetlist({'nr':'$'}).nr
3101 silent! 99Xolder
3102 call g:Xsetlist([], ' ', {'nr' : lastqf + 1, 'title' : 'Test7'})
3103 let l = g:Xgetlist({'nr' : '$', 'all' : 1})
3104 call assert_equal(lastqf + 1, l.nr)
3105 call assert_equal('Test7', l.title)
3106
3107 " Add a quickfix list to a stack with 10 lists using 'nr' set to '$'
3108 exe repeat('Xexpr "" |', 9) . 'Xexpr ""'
3109 silent! 99Xolder
3110 call g:Xsetlist([], ' ', {'nr' : '$', 'title' : 'Test8'})
3111 let l = g:Xgetlist({'nr' : '$', 'all' : 1})
3112 call assert_equal(10, l.nr)
3113 call assert_equal('Test8', l.title)
3114
3115 " Add a quickfix list using 'nr' set to a value greater than 10
3116 call assert_equal(-1, g:Xsetlist([], ' ', {'nr' : 12, 'title' : 'Test9'}))
3117
3118 " Try adding a quickfix list with 'nr' set to a value greater than the
3119 " quickfix list size but less than 10.
3120 call g:Xsetlist([], 'f')
3121 Xexpr "" | Xexpr "" | Xexpr ""
3122 silent! 99Xolder
3123 call assert_equal(-1, g:Xsetlist([], ' ', {'nr' : 8, 'title' : 'Test10'}))
3124
3125 " Add a quickfix list using 'nr' set to a some string or list
3126 call assert_equal(-1, g:Xsetlist([], ' ', {'nr' : [1,2], 'title' : 'Test11'}))
3127endfunc
3128
3129func Test_add_qf()
3130 call XaddQf_tests('c')
3131 call XaddQf_tests('l')
3132endfunc
Bram Moolenaar7adf06f2017-08-27 15:23:41 +02003133
3134" Test for getting the quickfix list items from some text without modifying
3135" the quickfix stack
Bram Moolenaar2c809b72017-09-01 18:34:02 +02003136func XgetListFromLines(cchar)
Bram Moolenaar7adf06f2017-08-27 15:23:41 +02003137 call s:setup_commands(a:cchar)
3138 call g:Xsetlist([], 'f')
3139
Bram Moolenaar2c809b72017-09-01 18:34:02 +02003140 let l = g:Xgetlist({'lines' : ["File2:20:Line20", "File2:30:Line30"]}).items
Bram Moolenaar7adf06f2017-08-27 15:23:41 +02003141 call assert_equal(2, len(l))
3142 call assert_equal(30, l[1].lnum)
3143
Bram Moolenaar2c809b72017-09-01 18:34:02 +02003144 call assert_equal({}, g:Xgetlist({'lines' : 10}))
3145 call assert_equal({}, g:Xgetlist({'lines' : 'File1:10:Line10'}))
3146 call assert_equal([], g:Xgetlist({'lines' : []}).items)
3147 call assert_equal([], g:Xgetlist({'lines' : [10, 20]}).items)
Bram Moolenaar7adf06f2017-08-27 15:23:41 +02003148
Bram Moolenaar36538222017-09-02 19:51:44 +02003149 " Parse text using a custom efm
3150 set efm&
3151 let l = g:Xgetlist({'lines':['File3#30#Line30'], 'efm' : '%f#%l#%m'}).items
3152 call assert_equal('Line30', l[0].text)
3153 let l = g:Xgetlist({'lines':['File3:30:Line30'], 'efm' : '%f-%l-%m'}).items
3154 call assert_equal('File3:30:Line30', l[0].text)
3155 let l = g:Xgetlist({'lines':['File3:30:Line30'], 'efm' : [1,2]})
3156 call assert_equal({}, l)
3157 call assert_fails("call g:Xgetlist({'lines':['abc'], 'efm':'%2'})", 'E376:')
3158 call assert_fails("call g:Xgetlist({'lines':['abc'], 'efm':''})", 'E378:')
3159
Bram Moolenaar7adf06f2017-08-27 15:23:41 +02003160 " Make sure that the quickfix stack is not modified
3161 call assert_equal(0, g:Xgetlist({'nr' : '$'}).nr)
3162endfunc
3163
Bram Moolenaar2c809b72017-09-01 18:34:02 +02003164func Test_get_list_from_lines()
3165 call XgetListFromLines('c')
3166 call XgetListFromLines('l')
Bram Moolenaar7adf06f2017-08-27 15:23:41 +02003167endfunc
Bram Moolenaara539f4f2017-08-30 20:33:55 +02003168
3169" Tests for the quickfix list id
3170func Xqfid_tests(cchar)
3171 call s:setup_commands(a:cchar)
3172
3173 call g:Xsetlist([], 'f')
Bram Moolenaara6d48492017-12-12 22:45:31 +01003174 call assert_equal(0, g:Xgetlist({'id':0}).id)
Bram Moolenaara539f4f2017-08-30 20:33:55 +02003175 Xexpr ''
3176 let start_id = g:Xgetlist({'id' : 0}).id
3177 Xexpr '' | Xexpr ''
3178 Xolder
3179 call assert_equal(start_id, g:Xgetlist({'id':0, 'nr':1}).id)
3180 call assert_equal(start_id + 1, g:Xgetlist({'id':0, 'nr':0}).id)
3181 call assert_equal(start_id + 2, g:Xgetlist({'id':0, 'nr':'$'}).id)
Bram Moolenaara6d48492017-12-12 22:45:31 +01003182 call assert_equal(0, g:Xgetlist({'id':0, 'nr':99}).id)
Bram Moolenaara539f4f2017-08-30 20:33:55 +02003183 call assert_equal(2, g:Xgetlist({'id':start_id + 1, 'nr':0}).nr)
Bram Moolenaara6d48492017-12-12 22:45:31 +01003184 call assert_equal(0, g:Xgetlist({'id':99, 'nr':0}).id)
3185 call assert_equal(0, g:Xgetlist({'id':"abc", 'nr':0}).id)
Bram Moolenaara539f4f2017-08-30 20:33:55 +02003186
3187 call g:Xsetlist([], 'a', {'id':start_id, 'context':[1,2]})
3188 call assert_equal([1,2], g:Xgetlist({'nr':1, 'context':1}).context)
Bram Moolenaar2c809b72017-09-01 18:34:02 +02003189 call g:Xsetlist([], 'a', {'id':start_id+1, 'lines':['F1:10:L10']})
Bram Moolenaara539f4f2017-08-30 20:33:55 +02003190 call assert_equal('L10', g:Xgetlist({'nr':2, 'items':1}).items[0].text)
3191 call assert_equal(-1, g:Xsetlist([], 'a', {'id':999, 'title':'Vim'}))
3192 call assert_equal(-1, g:Xsetlist([], 'a', {'id':'abc', 'title':'Vim'}))
3193
3194 let qfid = g:Xgetlist({'id':0, 'nr':0})
3195 call g:Xsetlist([], 'f')
Bram Moolenaara6d48492017-12-12 22:45:31 +01003196 call assert_equal(0, g:Xgetlist({'id':qfid, 'nr':0}).id)
Bram Moolenaara539f4f2017-08-30 20:33:55 +02003197endfunc
3198
3199func Test_qf_id()
3200 call Xqfid_tests('c')
3201 call Xqfid_tests('l')
3202endfunc
Bram Moolenaar74240d32017-12-10 15:26:15 +01003203
3204func Xqfjump_tests(cchar)
3205 call s:setup_commands(a:cchar)
3206
3207 call writefile(["Line1\tFoo", "Line2"], 'F1')
3208 call writefile(["Line1\tBar", "Line2"], 'F2')
3209 call writefile(["Line1\tBaz", "Line2"], 'F3')
3210
3211 call g:Xsetlist([], 'f')
3212
3213 " Tests for
3214 " Jumping to a line using a pattern
3215 " Jumping to a column greater than the last column in a line
3216 " Jumping to a line greater than the last line in the file
3217 let l = []
3218 for i in range(1, 7)
3219 call add(l, {})
3220 endfor
3221 let l[0].filename='F1'
3222 let l[0].pattern='Line1'
3223 let l[1].filename='F2'
3224 let l[1].pattern='Line1'
3225 let l[2].filename='F3'
3226 let l[2].pattern='Line1'
3227 let l[3].filename='F3'
3228 let l[3].lnum=1
3229 let l[3].col=9
3230 let l[3].vcol=1
3231 let l[4].filename='F3'
3232 let l[4].lnum=99
3233 let l[5].filename='F3'
3234 let l[5].lnum=1
3235 let l[5].col=99
3236 let l[5].vcol=1
3237 let l[6].filename='F3'
3238 let l[6].pattern='abcxyz'
3239
3240 call g:Xsetlist([], ' ', {'items' : l})
3241 Xopen | only
3242 2Xnext
3243 call assert_equal(3, g:Xgetlist({'idx' : 0}).idx)
3244 call assert_equal('F3', bufname('%'))
3245 Xnext
3246 call assert_equal(7, col('.'))
3247 Xnext
3248 call assert_equal(2, line('.'))
3249 Xnext
3250 call assert_equal(9, col('.'))
3251 2
3252 Xnext
3253 call assert_equal(2, line('.'))
3254
3255 if a:cchar == 'l'
3256 " When jumping to a location list entry in the location list window and
3257 " no usable windows are available, then a new window should be opened.
3258 enew! | new | only
3259 call g:Xsetlist([], 'f')
3260 setlocal buftype=nofile
3261 new
3262 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']})
3263 Xopen
3264 let winid = win_getid()
3265 wincmd p
3266 close
3267 call win_gotoid(winid)
3268 Xnext
3269 call assert_equal(3, winnr('$'))
3270 call assert_equal(1, winnr())
3271 call assert_equal(2, line('.'))
3272
3273 " When jumping to an entry in the location list window and the window
3274 " associated with the location list is not present and a window containing
3275 " the file is already present, then that window should be used.
3276 close
3277 belowright new
3278 call g:Xsetlist([], 'f')
3279 edit F3
3280 call win_gotoid(winid)
3281 Xlast
3282 call assert_equal(3, winnr())
3283 call assert_equal(6, g:Xgetlist({'size' : 1}).size)
3284 call assert_equal(winid, g:Xgetlist({'winid' : 1}).winid)
3285 endif
3286
3287 " Cleanup
3288 enew!
3289 new | only
3290
3291 call delete('F1')
3292 call delete('F2')
3293 call delete('F3')
3294endfunc
3295
3296func Test_qfjump()
3297 call Xqfjump_tests('c')
3298 call Xqfjump_tests('l')
3299endfunc
Bram Moolenaara6d48492017-12-12 22:45:31 +01003300
3301" Tests for the getqflist() and getloclist() functions when the list is not
3302" present or is empty
3303func Xgetlist_empty_tests(cchar)
3304 call s:setup_commands(a:cchar)
3305
3306 " Empty quickfix stack
3307 call g:Xsetlist([], 'f')
3308 call assert_equal('', g:Xgetlist({'context' : 0}).context)
3309 call assert_equal(0, g:Xgetlist({'id' : 0}).id)
3310 call assert_equal(0, g:Xgetlist({'idx' : 0}).idx)
3311 call assert_equal([], g:Xgetlist({'items' : 0}).items)
3312 call assert_equal(0, g:Xgetlist({'nr' : 0}).nr)
3313 call assert_equal(0, g:Xgetlist({'size' : 0}).size)
3314 call assert_equal('', g:Xgetlist({'title' : 0}).title)
3315 call assert_equal(0, g:Xgetlist({'winid' : 0}).winid)
Bram Moolenaarb254af32017-12-18 19:48:58 +01003316 call assert_equal(0, g:Xgetlist({'changedtick' : 0}).changedtick)
Bram Moolenaarc9cc9c72018-09-02 15:18:42 +02003317 if a:cchar == 'c'
3318 call assert_equal({'context' : '', 'id' : 0, 'idx' : 0,
Bram Moolenaar647e24b2019-03-17 16:39:46 +01003319 \ 'items' : [], 'nr' : 0, 'size' : 0, 'qfbufnr' : 0,
Bram Moolenaarc9cc9c72018-09-02 15:18:42 +02003320 \ 'title' : '', 'winid' : 0, 'changedtick': 0},
3321 \ g:Xgetlist({'all' : 0}))
3322 else
3323 call assert_equal({'context' : '', 'id' : 0, 'idx' : 0,
3324 \ 'items' : [], 'nr' : 0, 'size' : 0, 'title' : '',
Bram Moolenaar647e24b2019-03-17 16:39:46 +01003325 \ 'winid' : 0, 'changedtick': 0, 'filewinid' : 0,
3326 \ 'qfbufnr' : 0},
Bram Moolenaarc9cc9c72018-09-02 15:18:42 +02003327 \ g:Xgetlist({'all' : 0}))
3328 endif
Bram Moolenaara6d48492017-12-12 22:45:31 +01003329
Bram Moolenaar2ec364e2018-01-27 11:52:13 +01003330 " Quickfix window with empty stack
3331 silent! Xopen
3332 let qfwinid = (a:cchar == 'c') ? win_getid() : 0
Bram Moolenaar647e24b2019-03-17 16:39:46 +01003333 let qfbufnr = (a:cchar == 'c') ? bufnr('') : 0
Bram Moolenaar2ec364e2018-01-27 11:52:13 +01003334 call assert_equal(qfwinid, g:Xgetlist({'winid' : 0}).winid)
3335 Xclose
3336
Bram Moolenaara6d48492017-12-12 22:45:31 +01003337 " Empty quickfix list
3338 Xexpr ""
3339 call assert_equal('', g:Xgetlist({'context' : 0}).context)
3340 call assert_notequal(0, g:Xgetlist({'id' : 0}).id)
3341 call assert_equal(0, g:Xgetlist({'idx' : 0}).idx)
3342 call assert_equal([], g:Xgetlist({'items' : 0}).items)
3343 call assert_notequal(0, g:Xgetlist({'nr' : 0}).nr)
3344 call assert_equal(0, g:Xgetlist({'size' : 0}).size)
3345 call assert_notequal('', g:Xgetlist({'title' : 0}).title)
3346 call assert_equal(0, g:Xgetlist({'winid' : 0}).winid)
Bram Moolenaarb254af32017-12-18 19:48:58 +01003347 call assert_equal(1, g:Xgetlist({'changedtick' : 0}).changedtick)
Bram Moolenaara6d48492017-12-12 22:45:31 +01003348
3349 let qfid = g:Xgetlist({'id' : 0}).id
3350 call g:Xsetlist([], 'f')
3351
3352 " Non-existing quickfix identifier
3353 call assert_equal('', g:Xgetlist({'id' : qfid, 'context' : 0}).context)
3354 call assert_equal(0, g:Xgetlist({'id' : qfid}).id)
3355 call assert_equal(0, g:Xgetlist({'id' : qfid, 'idx' : 0}).idx)
3356 call assert_equal([], g:Xgetlist({'id' : qfid, 'items' : 0}).items)
3357 call assert_equal(0, g:Xgetlist({'id' : qfid, 'nr' : 0}).nr)
3358 call assert_equal(0, g:Xgetlist({'id' : qfid, 'size' : 0}).size)
3359 call assert_equal('', g:Xgetlist({'id' : qfid, 'title' : 0}).title)
3360 call assert_equal(0, g:Xgetlist({'id' : qfid, 'winid' : 0}).winid)
Bram Moolenaarb254af32017-12-18 19:48:58 +01003361 call assert_equal(0, g:Xgetlist({'id' : qfid, 'changedtick' : 0}).changedtick)
Bram Moolenaarc9cc9c72018-09-02 15:18:42 +02003362 if a:cchar == 'c'
3363 call assert_equal({'context' : '', 'id' : 0, 'idx' : 0, 'items' : [],
3364 \ 'nr' : 0, 'size' : 0, 'title' : '', 'winid' : 0,
Bram Moolenaar647e24b2019-03-17 16:39:46 +01003365 \ 'qfbufnr' : qfbufnr,
Bram Moolenaarc9cc9c72018-09-02 15:18:42 +02003366 \ 'changedtick' : 0}, g:Xgetlist({'id' : qfid, 'all' : 0}))
3367 else
3368 call assert_equal({'context' : '', 'id' : 0, 'idx' : 0, 'items' : [],
3369 \ 'nr' : 0, 'size' : 0, 'title' : '', 'winid' : 0,
Bram Moolenaar647e24b2019-03-17 16:39:46 +01003370 \ 'changedtick' : 0, 'filewinid' : 0, 'qfbufnr' : 0},
Bram Moolenaarc9cc9c72018-09-02 15:18:42 +02003371 \ g:Xgetlist({'id' : qfid, 'all' : 0}))
3372 endif
Bram Moolenaara6d48492017-12-12 22:45:31 +01003373
3374 " Non-existing quickfix list number
3375 call assert_equal('', g:Xgetlist({'nr' : 5, 'context' : 0}).context)
3376 call assert_equal(0, g:Xgetlist({'nr' : 5}).nr)
3377 call assert_equal(0, g:Xgetlist({'nr' : 5, 'idx' : 0}).idx)
3378 call assert_equal([], g:Xgetlist({'nr' : 5, 'items' : 0}).items)
3379 call assert_equal(0, g:Xgetlist({'nr' : 5, 'id' : 0}).id)
3380 call assert_equal(0, g:Xgetlist({'nr' : 5, 'size' : 0}).size)
3381 call assert_equal('', g:Xgetlist({'nr' : 5, 'title' : 0}).title)
3382 call assert_equal(0, g:Xgetlist({'nr' : 5, 'winid' : 0}).winid)
Bram Moolenaarb254af32017-12-18 19:48:58 +01003383 call assert_equal(0, g:Xgetlist({'nr' : 5, 'changedtick' : 0}).changedtick)
Bram Moolenaarc9cc9c72018-09-02 15:18:42 +02003384 if a:cchar == 'c'
3385 call assert_equal({'context' : '', 'id' : 0, 'idx' : 0, 'items' : [],
3386 \ 'nr' : 0, 'size' : 0, 'title' : '', 'winid' : 0,
Bram Moolenaar647e24b2019-03-17 16:39:46 +01003387 \ 'changedtick' : 0, 'qfbufnr' : qfbufnr},
3388 \ g:Xgetlist({'nr' : 5, 'all' : 0}))
Bram Moolenaarc9cc9c72018-09-02 15:18:42 +02003389 else
3390 call assert_equal({'context' : '', 'id' : 0, 'idx' : 0, 'items' : [],
3391 \ 'nr' : 0, 'size' : 0, 'title' : '', 'winid' : 0,
Bram Moolenaar647e24b2019-03-17 16:39:46 +01003392 \ 'changedtick' : 0, 'filewinid' : 0, 'qfbufnr' : 0},
Bram Moolenaarc9cc9c72018-09-02 15:18:42 +02003393 \ g:Xgetlist({'nr' : 5, 'all' : 0}))
3394 endif
Bram Moolenaara6d48492017-12-12 22:45:31 +01003395endfunc
3396
3397func Test_getqflist()
3398 call Xgetlist_empty_tests('c')
3399 call Xgetlist_empty_tests('l')
3400endfunc
Bram Moolenaarb254af32017-12-18 19:48:58 +01003401
Bram Moolenaara0ca7d02017-12-19 10:22:19 +01003402func Test_getqflist_invalid_nr()
3403 " The following commands used to crash Vim
3404 cexpr ""
3405 call getqflist({'nr' : $XXX_DOES_NOT_EXIST_XXX})
3406
3407 " Cleanup
3408 call setqflist([], 'r')
3409endfunc
3410
Bram Moolenaarb254af32017-12-18 19:48:58 +01003411" Tests for the quickfix/location list changedtick
3412func Xqftick_tests(cchar)
3413 call s:setup_commands(a:cchar)
3414
3415 call g:Xsetlist([], 'f')
3416
3417 Xexpr "F1:10:Line10"
3418 let qfid = g:Xgetlist({'id' : 0}).id
3419 call assert_equal(1, g:Xgetlist({'changedtick' : 0}).changedtick)
3420 Xaddexpr "F2:20:Line20\nF2:21:Line21"
3421 call assert_equal(2, g:Xgetlist({'changedtick' : 0}).changedtick)
3422 call g:Xsetlist([], 'a', {'lines' : ["F3:30:Line30", "F3:31:Line31"]})
3423 call assert_equal(3, g:Xgetlist({'changedtick' : 0}).changedtick)
3424 call g:Xsetlist([], 'r', {'lines' : ["F4:40:Line40"]})
3425 call assert_equal(4, g:Xgetlist({'changedtick' : 0}).changedtick)
3426 call g:Xsetlist([], 'a', {'title' : 'New Title'})
3427 call assert_equal(5, g:Xgetlist({'changedtick' : 0}).changedtick)
3428
3429 enew!
3430 call append(0, ["F5:50:L50", "F6:60:L60"])
3431 Xaddbuffer
3432 call assert_equal(6, g:Xgetlist({'changedtick' : 0}).changedtick)
3433 enew!
3434
3435 call g:Xsetlist([], 'a', {'context' : {'bus' : 'pci'}})
3436 call assert_equal(7, g:Xgetlist({'changedtick' : 0}).changedtick)
3437 call g:Xsetlist([{'filename' : 'F7', 'lnum' : 10, 'text' : 'L7'},
3438 \ {'filename' : 'F7', 'lnum' : 11, 'text' : 'L11'}], 'a')
3439 call assert_equal(8, g:Xgetlist({'changedtick' : 0}).changedtick)
3440 call g:Xsetlist([{'filename' : 'F7', 'lnum' : 10, 'text' : 'L7'},
3441 \ {'filename' : 'F7', 'lnum' : 11, 'text' : 'L11'}], ' ')
3442 call assert_equal(1, g:Xgetlist({'changedtick' : 0}).changedtick)
3443 call g:Xsetlist([{'filename' : 'F7', 'lnum' : 10, 'text' : 'L7'},
3444 \ {'filename' : 'F7', 'lnum' : 11, 'text' : 'L11'}], 'r')
3445 call assert_equal(2, g:Xgetlist({'changedtick' : 0}).changedtick)
3446
3447 call writefile(["F8:80:L80", "F8:81:L81"], "Xone")
3448 Xfile Xone
3449 call assert_equal(1, g:Xgetlist({'changedtick' : 0}).changedtick)
3450 Xaddfile Xone
3451 call assert_equal(2, g:Xgetlist({'changedtick' : 0}).changedtick)
3452
3453 " Test case for updating a non-current quickfix list
3454 call g:Xsetlist([], 'f')
3455 Xexpr "F1:1:L1"
3456 Xexpr "F2:2:L2"
3457 call g:Xsetlist([], 'a', {'nr' : 1, "lines" : ["F10:10:L10"]})
3458 call assert_equal(1, g:Xgetlist({'changedtick' : 0}).changedtick)
3459 call assert_equal(2, g:Xgetlist({'nr' : 1, 'changedtick' : 0}).changedtick)
3460
3461 call delete("Xone")
3462endfunc
3463
3464func Test_qf_tick()
3465 call Xqftick_tests('c')
3466 call Xqftick_tests('l')
3467endfunc
Bram Moolenaar12237442017-12-19 12:38:52 +01003468
Bram Moolenaarc631f2d2018-08-21 21:58:13 +02003469" Test helpgrep with lang specifier
3470func Xtest_helpgrep_with_lang_specifier(cchar)
3471 call s:setup_commands(a:cchar)
3472 Xhelpgrep Vim@en
3473 call assert_equal('help', &filetype)
3474 call assert_notequal(0, g:Xgetlist({'nr' : '$'}).nr)
3475 new | only
3476endfunc
3477
3478func Test_helpgrep_with_lang_specifier()
3479 call Xtest_helpgrep_with_lang_specifier('c')
3480 call Xtest_helpgrep_with_lang_specifier('l')
3481endfunc
3482
Bram Moolenaar12237442017-12-19 12:38:52 +01003483" The following test used to crash Vim.
3484" Open the location list window and close the regular window associated with
3485" the location list. When the garbage collection runs now, it incorrectly
3486" marks the location list context as not in use and frees the context.
3487func Test_ll_window_ctx()
3488 call setloclist(0, [], 'f')
3489 call setloclist(0, [], 'a', {'context' : []})
3490 lopen | only
3491 call test_garbagecollect_now()
3492 echo getloclist(0, {'context' : 1}).context
3493 enew | only
3494endfunc
3495
Bram Moolenaar14a4deb2017-12-19 16:48:55 +01003496" The following test used to crash vim
3497func Test_lfile_crash()
3498 sp Xtest
3499 au QuickFixCmdPre * bw
3500 call assert_fails('lfile', 'E40')
3501 au! QuickFixCmdPre
3502endfunc
Bram Moolenaar3c097222017-12-21 20:54:49 +01003503
3504" The following test used to crash vim
3505func Test_lbuffer_crash()
3506 sv Xtest
3507 augroup QF_Test
3508 au!
3509 au * * bw
3510 augroup END
3511 lbuffer
3512 augroup QF_Test
3513 au!
3514 augroup END
3515endfunc
3516
3517" The following test used to crash vim
3518func Test_lexpr_crash()
3519 augroup QF_Test
3520 au!
3521 au * * call setloclist(0, [], 'f')
3522 augroup END
3523 lexpr ""
3524 augroup QF_Test
3525 au!
3526 augroup END
Bram Moolenaar9f84ded2018-10-20 20:54:02 +02003527
Bram Moolenaar3c097222017-12-21 20:54:49 +01003528 enew | only
Bram Moolenaar9f84ded2018-10-20 20:54:02 +02003529 augroup QF_Test
3530 au!
3531 au BufNew * call setloclist(0, [], 'f')
3532 augroup END
3533 lexpr 'x:1:x'
3534 augroup QF_Test
3535 au!
3536 augroup END
3537
3538 enew | only
3539 lexpr ''
3540 lopen
3541 augroup QF_Test
3542 au!
3543 au FileType * call setloclist(0, [], 'f')
3544 augroup END
3545 lexpr ''
3546 augroup QF_Test
3547 au!
3548 augroup END
Bram Moolenaar3c097222017-12-21 20:54:49 +01003549endfunc
3550
3551" The following test used to crash Vim
3552func Test_lvimgrep_crash()
3553 sv Xtest
3554 augroup QF_Test
3555 au!
3556 au * * call setloclist(0, [], 'f')
3557 augroup END
3558 lvimgrep quickfix test_quickfix.vim
3559 augroup QF_Test
3560 au!
3561 augroup END
Bram Moolenaarb6f14802018-10-21 18:47:43 +02003562
3563 new | only
3564 augroup QF_Test
3565 au!
3566 au BufEnter * call setloclist(0, [], 'r')
3567 augroup END
3568 call assert_fails('lvimgrep Test_lvimgrep_crash *', 'E926:')
3569 augroup QF_Test
3570 au!
3571 augroup END
3572
Bram Moolenaar3c097222017-12-21 20:54:49 +01003573 enew | only
3574endfunc
Bram Moolenaarde046542017-12-26 13:53:11 +01003575
3576" Test for the position of the quickfix and location list window
3577func Test_qfwin_pos()
3578 " Open two windows
3579 new | only
3580 new
3581 cexpr ['F1:10:L10']
3582 copen
3583 " Quickfix window should be the bottom most window
3584 call assert_equal(3, winnr())
3585 close
3586 " Open at the very top
3587 wincmd t
3588 topleft copen
3589 call assert_equal(1, winnr())
3590 close
3591 " open left of the current window
3592 wincmd t
3593 below new
3594 leftabove copen
3595 call assert_equal(2, winnr())
3596 close
3597 " open right of the current window
3598 rightbelow copen
3599 call assert_equal(3, winnr())
3600 close
3601endfunc
Bram Moolenaare1bb8792018-04-06 22:58:23 +02003602
3603" Tests for quickfix/location lists changed by autocommands when
3604" :vimgrep/:lvimgrep commands are running.
3605func Test_vimgrep_autocmd()
3606 call setqflist([], 'f')
3607 call writefile(['stars'], 'Xtest1.txt')
3608 call writefile(['stars'], 'Xtest2.txt')
3609
3610 " Test 1:
3611 " When searching for a pattern using :vimgrep, if the quickfix list is
3612 " changed by an autocmd, the results should be added to the correct quickfix
3613 " list.
3614 autocmd BufRead Xtest2.txt cexpr '' | cexpr ''
3615 silent vimgrep stars Xtest*.txt
3616 call assert_equal(1, getqflist({'nr' : 0}).nr)
3617 call assert_equal(3, getqflist({'nr' : '$'}).nr)
3618 call assert_equal('Xtest2.txt', bufname(getqflist()[1].bufnr))
3619 au! BufRead Xtest2.txt
3620
3621 " Test 2:
3622 " When searching for a pattern using :vimgrep, if the quickfix list is
3623 " freed, then a error should be given.
3624 silent! %bwipe!
3625 call setqflist([], 'f')
3626 autocmd BufRead Xtest2.txt for i in range(10) | cexpr '' | endfor
3627 call assert_fails('vimgrep stars Xtest*.txt', 'E925:')
3628 au! BufRead Xtest2.txt
3629
3630 " Test 3:
3631 " When searching for a pattern using :lvimgrep, if the location list is
3632 " freed, then the command should error out.
3633 silent! %bwipe!
3634 let g:save_winid = win_getid()
3635 autocmd BufRead Xtest2.txt call setloclist(g:save_winid, [], 'f')
3636 call assert_fails('lvimgrep stars Xtest*.txt', 'E926:')
3637 au! BufRead Xtest2.txt
3638
3639 call delete('Xtest1.txt')
3640 call delete('Xtest2.txt')
3641 call setqflist([], 'f')
3642endfunc
Bram Moolenaar3b9474b2018-04-23 21:29:48 +02003643
Bram Moolenaarf9ae1542019-11-18 22:02:16 +01003644" Test for an autocmd changing the current directory when running vimgrep
3645func Xvimgrep_autocmd_cd(cchar)
3646 call s:setup_commands(a:cchar)
3647
3648 %bwipe
3649 let save_cwd = getcwd()
3650
3651 augroup QF_Test
3652 au!
3653 autocmd BufRead * silent cd %:p:h
3654 augroup END
3655
3656 10Xvimgrep /vim/ Xdir/**
3657 let l = g:Xgetlist()
3658 call assert_equal('f1.txt', bufname(l[0].bufnr))
3659 call assert_equal('f2.txt', fnamemodify(bufname(l[2].bufnr), ':t'))
3660
3661 augroup QF_Test
3662 au!
3663 augroup END
3664
3665 exe 'cd ' . save_cwd
3666endfunc
3667
3668func Test_vimgrep_autocmd_cd()
3669 call mkdir('Xdir/a', 'p')
3670 call mkdir('Xdir/b', 'p')
3671 call writefile(['a_L1_vim', 'a_L2_vim'], 'Xdir/a/f1.txt')
3672 call writefile(['b_L1_vim', 'b_L2_vim'], 'Xdir/b/f2.txt')
3673 call Xvimgrep_autocmd_cd('c')
3674 call Xvimgrep_autocmd_cd('l')
3675 %bwipe
3676 call delete('Xdir', 'rf')
3677endfunc
3678
Bram Moolenaar3b9474b2018-04-23 21:29:48 +02003679" The following test used to crash Vim
3680func Test_lhelpgrep_autocmd()
3681 lhelpgrep quickfix
3682 autocmd QuickFixCmdPost * call setloclist(0, [], 'f')
3683 lhelpgrep buffer
3684 call assert_equal('help', &filetype)
3685 call assert_equal(0, getloclist(0, {'nr' : '$'}).nr)
3686 lhelpgrep tabpage
3687 call assert_equal('help', &filetype)
3688 call assert_equal(1, getloclist(0, {'nr' : '$'}).nr)
3689 au! QuickFixCmdPost
Bram Moolenaarb6f14802018-10-21 18:47:43 +02003690
3691 new | only
3692 augroup QF_Test
3693 au!
3694 au BufEnter * call setqflist([], 'f')
3695 augroup END
3696 call assert_fails('helpgrep quickfix', 'E925:')
3697 augroup QF_Test
3698 au! BufEnter
3699 augroup END
3700
3701 new | only
3702 augroup QF_Test
3703 au!
3704 au BufEnter * call setqflist([], 'r')
3705 augroup END
3706 call assert_fails('helpgrep quickfix', 'E925:')
3707 augroup QF_Test
3708 au! BufEnter
3709 augroup END
3710
3711 new | only
3712 augroup QF_Test
3713 au!
3714 au BufEnter * call setloclist(0, [], 'r')
3715 augroup END
3716 call assert_fails('lhelpgrep quickfix', 'E926:')
3717 augroup QF_Test
3718 au! BufEnter
3719 augroup END
3720
Bram Moolenaar3b9474b2018-04-23 21:29:48 +02003721 new | only
3722endfunc
Bram Moolenaara796d462018-05-01 14:30:36 +02003723
3724" Test for shortening/simplifying the file name when opening the
3725" quickfix window or when displaying the quickfix list
3726func Test_shorten_fname()
3727 if !has('unix')
3728 return
3729 endif
3730 %bwipe
3731 " Create a quickfix list with a absolute path filename
3732 let fname = getcwd() . '/test_quickfix.vim'
3733 call setqflist([], ' ', {'lines':[fname . ":20:Line20"], 'efm':'%f:%l:%m'})
3734 call assert_equal(fname, bufname('test_quickfix.vim'))
3735 " Opening the quickfix window should simplify the file path
3736 cwindow
3737 call assert_equal('test_quickfix.vim', bufname('test_quickfix.vim'))
3738 cclose
3739 %bwipe
3740 " Create a quickfix list with a absolute path filename
3741 call setqflist([], ' ', {'lines':[fname . ":20:Line20"], 'efm':'%f:%l:%m'})
3742 call assert_equal(fname, bufname('test_quickfix.vim'))
3743 " Displaying the quickfix list should simplify the file path
3744 silent! clist
3745 call assert_equal('test_quickfix.vim', bufname('test_quickfix.vim'))
3746endfunc
Bram Moolenaar8b62e312018-05-13 15:29:04 +02003747
3748" Quickfix title tests
3749" In the below tests, 'exe "cmd"' is used to invoke the quickfix commands.
3750" Otherwise due to indentation, the title is set with spaces at the beginning
3751" of the command.
3752func Test_qftitle()
3753 call writefile(["F1:1:Line1"], 'Xerr')
3754
3755 " :cexpr
3756 exe "cexpr readfile('Xerr')"
3757 call assert_equal(":cexpr readfile('Xerr')", getqflist({'title' : 1}).title)
3758
3759 " :cgetexpr
3760 exe "cgetexpr readfile('Xerr')"
3761 call assert_equal(":cgetexpr readfile('Xerr')",
3762 \ getqflist({'title' : 1}).title)
3763
3764 " :caddexpr
3765 call setqflist([], 'f')
3766 exe "caddexpr readfile('Xerr')"
3767 call assert_equal(":caddexpr readfile('Xerr')",
3768 \ getqflist({'title' : 1}).title)
3769
3770 " :cbuffer
3771 new Xerr
3772 exe "cbuffer"
3773 call assert_equal(':cbuffer (Xerr)', getqflist({'title' : 1}).title)
3774
3775 " :cgetbuffer
3776 edit Xerr
3777 exe "cgetbuffer"
3778 call assert_equal(':cgetbuffer (Xerr)', getqflist({'title' : 1}).title)
3779
3780 " :caddbuffer
3781 call setqflist([], 'f')
3782 edit Xerr
3783 exe "caddbuffer"
3784 call assert_equal(':caddbuffer (Xerr)', getqflist({'title' : 1}).title)
3785
3786 " :cfile
3787 exe "cfile Xerr"
3788 call assert_equal(':cfile Xerr', getqflist({'title' : 1}).title)
3789
3790 " :cgetfile
3791 exe "cgetfile Xerr"
3792 call assert_equal(':cgetfile Xerr', getqflist({'title' : 1}).title)
3793
3794 " :caddfile
3795 call setqflist([], 'f')
3796 exe "caddfile Xerr"
3797 call assert_equal(':caddfile Xerr', getqflist({'title' : 1}).title)
3798
3799 " :grep
3800 set grepprg=internal
3801 exe "grep F1 Xerr"
3802 call assert_equal(':grep F1 Xerr', getqflist({'title' : 1}).title)
3803
3804 " :grepadd
3805 call setqflist([], 'f')
3806 exe "grepadd F1 Xerr"
3807 call assert_equal(':grepadd F1 Xerr', getqflist({'title' : 1}).title)
3808 set grepprg&vim
3809
3810 " :vimgrep
3811 exe "vimgrep F1 Xerr"
3812 call assert_equal(':vimgrep F1 Xerr', getqflist({'title' : 1}).title)
3813
3814 " :vimgrepadd
3815 call setqflist([], 'f')
3816 exe "vimgrepadd F1 Xerr"
3817 call assert_equal(':vimgrepadd F1 Xerr', getqflist({'title' : 1}).title)
3818
3819 call setqflist(['F1:10:L10'], ' ')
3820 call assert_equal(':setqflist()', getqflist({'title' : 1}).title)
3821
3822 call setqflist([], 'f')
3823 call setqflist(['F1:10:L10'], 'a')
3824 call assert_equal(':setqflist()', getqflist({'title' : 1}).title)
3825
3826 call setqflist([], 'f')
3827 call setqflist(['F1:10:L10'], 'r')
3828 call assert_equal(':setqflist()', getqflist({'title' : 1}).title)
3829
3830 close
3831 call delete('Xerr')
3832
3833 call setqflist([], ' ', {'title' : 'Errors'})
3834 copen
3835 call assert_equal('Errors', w:quickfix_title)
3836 call setqflist([], 'r', {'items' : [{'filename' : 'a.c', 'lnum' : 10}]})
3837 call assert_equal('Errors', w:quickfix_title)
3838 cclose
3839endfunc
Bram Moolenaar600323b2018-06-16 22:16:47 +02003840
3841func Test_lbuffer_with_bwipe()
3842 new
3843 new
3844 augroup nasty
3845 au * * bwipe
3846 augroup END
3847 lbuffer
3848 augroup nasty
3849 au!
3850 augroup END
3851endfunc
Bram Moolenaar0366c012018-06-18 20:52:13 +02003852
Bram Moolenaar531b9a32018-07-03 16:54:23 +02003853" Test for an autocmd freeing the quickfix/location list when cexpr/lexpr is
3854" running
3855func Xexpr_acmd_freelist(cchar)
3856 call s:setup_commands(a:cchar)
3857
Bram Moolenaar0366c012018-06-18 20:52:13 +02003858 " This was using freed memory.
3859 augroup nasty
Bram Moolenaar531b9a32018-07-03 16:54:23 +02003860 au * * call g:Xsetlist([], 'f')
Bram Moolenaar0366c012018-06-18 20:52:13 +02003861 augroup END
Bram Moolenaar531b9a32018-07-03 16:54:23 +02003862 Xexpr "x"
Bram Moolenaar0366c012018-06-18 20:52:13 +02003863 augroup nasty
3864 au!
3865 augroup END
3866endfunc
Bram Moolenaar531b9a32018-07-03 16:54:23 +02003867
3868func Test_cexpr_acmd_freelist()
3869 call Xexpr_acmd_freelist('c')
3870 call Xexpr_acmd_freelist('l')
3871endfunc
3872
3873" Test for commands that create a new quickfix/location list and jump to the
3874" first error automatically.
3875func Xjumpto_first_error_test(cchar)
3876 call s:setup_commands(a:cchar)
3877
3878 call s:create_test_file('Xtestfile1')
3879 call s:create_test_file('Xtestfile2')
3880 let l = ['Xtestfile1:2:Line2', 'Xtestfile2:4:Line4']
3881
3882 " Test for cexpr/lexpr
3883 enew
3884 Xexpr l
3885 call assert_equal('Xtestfile1', bufname(''))
3886 call assert_equal(2, line('.'))
3887
3888 " Test for cfile/lfile
3889 enew
3890 call writefile(l, 'Xerr')
3891 Xfile Xerr
3892 call assert_equal('Xtestfile1', bufname(''))
3893 call assert_equal(2, line('.'))
3894
3895 " Test for cbuffer/lbuffer
3896 edit Xerr
3897 Xbuffer
3898 call assert_equal('Xtestfile1', bufname(''))
3899 call assert_equal(2, line('.'))
3900
3901 call delete('Xerr')
3902 call delete('Xtestfile1')
3903 call delete('Xtestfile2')
3904endfunc
3905
3906func Test_jumpto_first_error()
3907 call Xjumpto_first_error_test('c')
3908 call Xjumpto_first_error_test('l')
3909endfunc
3910
3911" Test for a quickfix autocmd changing the quickfix/location list before
3912" jumping to the first error in the new list.
3913func Xautocmd_changelist(cchar)
3914 call s:setup_commands(a:cchar)
3915
3916 " Test for cfile/lfile
3917 call s:create_test_file('Xtestfile1')
3918 call s:create_test_file('Xtestfile2')
3919 Xexpr 'Xtestfile1:2:Line2'
3920 autocmd QuickFixCmdPost * Xolder
3921 call writefile(['Xtestfile2:4:Line4'], 'Xerr')
3922 Xfile Xerr
3923 call assert_equal('Xtestfile2', bufname(''))
3924 call assert_equal(4, line('.'))
3925 autocmd! QuickFixCmdPost
3926
3927 " Test for cbuffer/lbuffer
3928 call g:Xsetlist([], 'f')
3929 Xexpr 'Xtestfile1:2:Line2'
3930 autocmd QuickFixCmdPost * Xolder
3931 call writefile(['Xtestfile2:4:Line4'], 'Xerr')
3932 edit Xerr
3933 Xbuffer
3934 call assert_equal('Xtestfile2', bufname(''))
3935 call assert_equal(4, line('.'))
3936 autocmd! QuickFixCmdPost
3937
3938 " Test for cexpr/lexpr
3939 call g:Xsetlist([], 'f')
3940 Xexpr 'Xtestfile1:2:Line2'
3941 autocmd QuickFixCmdPost * Xolder
3942 Xexpr 'Xtestfile2:4:Line4'
3943 call assert_equal('Xtestfile2', bufname(''))
3944 call assert_equal(4, line('.'))
3945 autocmd! QuickFixCmdPost
3946
Bram Moolenaar851332e2018-07-03 19:16:00 +02003947 " The grepprg may not be set on non-Unix systems
3948 if has('unix')
3949 " Test for grep/lgrep
3950 call g:Xsetlist([], 'f')
3951 Xexpr 'Xtestfile1:2:Line2'
3952 autocmd QuickFixCmdPost * Xolder
3953 silent Xgrep Line5 Xtestfile2
3954 call assert_equal('Xtestfile2', bufname(''))
3955 call assert_equal(5, line('.'))
3956 autocmd! QuickFixCmdPost
3957 endif
Bram Moolenaar531b9a32018-07-03 16:54:23 +02003958
3959 " Test for vimgrep/lvimgrep
3960 call g:Xsetlist([], 'f')
3961 Xexpr 'Xtestfile1:2:Line2'
3962 autocmd QuickFixCmdPost * Xolder
3963 silent Xvimgrep Line5 Xtestfile2
3964 call assert_equal('Xtestfile2', bufname(''))
3965 call assert_equal(5, line('.'))
3966 autocmd! QuickFixCmdPost
3967
Bram Moolenaar3f347e42018-08-09 21:19:20 +02003968 " Test for autocommands clearing the quickfix list before jumping to the
3969 " first error. This should not result in an error
3970 autocmd QuickFixCmdPost * call g:Xsetlist([], 'r')
3971 let v:errmsg = ''
3972 " Test for cfile/lfile
3973 Xfile Xerr
3974 call assert_true(v:errmsg !~# 'E42:')
3975 " Test for cbuffer/lbuffer
3976 edit Xerr
3977 Xbuffer
3978 call assert_true(v:errmsg !~# 'E42:')
3979 " Test for cexpr/lexpr
3980 Xexpr 'Xtestfile2:4:Line4'
3981 call assert_true(v:errmsg !~# 'E42:')
3982 " Test for grep/lgrep
3983 " The grepprg may not be set on non-Unix systems
3984 if has('unix')
3985 silent Xgrep Line5 Xtestfile2
3986 call assert_true(v:errmsg !~# 'E42:')
3987 endif
3988 " Test for vimgrep/lvimgrep
3989 call assert_fails('silent Xvimgrep Line5 Xtestfile2', 'E480:')
3990 autocmd! QuickFixCmdPost
3991
Bram Moolenaar531b9a32018-07-03 16:54:23 +02003992 call delete('Xerr')
3993 call delete('Xtestfile1')
3994 call delete('Xtestfile2')
3995endfunc
3996
3997func Test_autocmd_changelist()
3998 call Xautocmd_changelist('c')
3999 call Xautocmd_changelist('l')
4000endfunc
Bram Moolenaar4cde86c2018-07-08 16:01:08 +02004001
4002" Tests for the ':filter /pat/ clist' command
4003func Test_filter_clist()
4004 cexpr ['Xfile1:10:10:Line 10', 'Xfile2:15:15:Line 15']
4005 call assert_equal([' 2 Xfile2:15 col 15: Line 15'],
4006 \ split(execute('filter /Line 15/ clist'), "\n"))
4007 call assert_equal([' 1 Xfile1:10 col 10: Line 10'],
4008 \ split(execute('filter /Xfile1/ clist'), "\n"))
4009 call assert_equal([], split(execute('filter /abc/ clist'), "\n"))
4010
4011 call setqflist([{'module' : 'abc', 'pattern' : 'pat1'},
4012 \ {'module' : 'pqr', 'pattern' : 'pat2'}], ' ')
4013 call assert_equal([' 2 pqr:pat2: '],
4014 \ split(execute('filter /pqr/ clist'), "\n"))
4015 call assert_equal([' 1 abc:pat1: '],
4016 \ split(execute('filter /pat1/ clist'), "\n"))
4017endfunc
Bram Moolenaar0a08c632018-07-25 22:36:52 +02004018
4019" Tests for the "CTRL-W <CR>" command.
4020func Xview_result_split_tests(cchar)
4021 call s:setup_commands(a:cchar)
4022
4023 " Test that "CTRL-W <CR>" in a qf/ll window fails with empty list.
4024 call g:Xsetlist([])
4025 Xopen
4026 let l:win_count = winnr('$')
4027 call assert_fails('execute "normal! \<C-W>\<CR>"', 'E42')
4028 call assert_equal(l:win_count, winnr('$'))
4029 Xclose
4030endfunc
4031
4032func Test_view_result_split()
4033 call Xview_result_split_tests('c')
4034 call Xview_result_split_tests('l')
4035endfunc
Bram Moolenaar2dfcef42018-08-15 22:29:51 +02004036
4037" Test that :cc sets curswant
4038func Test_curswant()
4039 helpgrep quickfix
4040 normal! llll
4041 1cc
4042 call assert_equal(getcurpos()[4], virtcol('.'))
4043 cclose | helpclose
4044endfunc
Bram Moolenaarb2443732018-11-11 22:50:27 +01004045
4046" Test for opening a file from the quickfix window using CTRL-W <Enter>
4047" doesn't leave an empty buffer around.
4048func Test_splitview()
4049 call s:create_test_file('Xtestfile1')
4050 call s:create_test_file('Xtestfile2')
4051 new | only
4052 let last_bufnr = bufnr('Test_sv_1', 1)
4053 let l = ['Xtestfile1:2:Line2', 'Xtestfile2:4:Line4']
4054 cgetexpr l
4055 copen
4056 let numbufs = len(getbufinfo())
4057 exe "normal \<C-W>\<CR>"
4058 copen
4059 exe "normal j\<C-W>\<CR>"
4060 " Make sure new empty buffers are not created
4061 call assert_equal(numbufs, len(getbufinfo()))
4062 " Creating a new buffer should use the next available buffer number
4063 call assert_equal(last_bufnr + 4, bufnr("Test_sv_2", 1))
4064 bwipe Test_sv_1
4065 bwipe Test_sv_2
4066 new | only
4067
4068 " When split opening files from location list window, make sure that two
4069 " windows doesn't refer to the same location list
4070 lgetexpr l
4071 let locid = getloclist(0, {'id' : 0}).id
4072 lopen
4073 exe "normal \<C-W>\<CR>"
4074 call assert_notequal(locid, getloclist(0, {'id' : 0}).id)
4075 call assert_equal(0, getloclist(0, {'winid' : 0}).winid)
4076 new | only
4077
4078 " When split opening files from a helpgrep location list window, a new help
Bram Moolenaareeb1b9c2019-02-10 22:59:04 +01004079 " window should be opened with a copy of the location list.
Bram Moolenaarb2443732018-11-11 22:50:27 +01004080 lhelpgrep window
4081 let locid = getloclist(0, {'id' : 0}).id
4082 lwindow
4083 exe "normal j\<C-W>\<CR>"
4084 call assert_notequal(locid, getloclist(0, {'id' : 0}).id)
4085 call assert_equal(0, getloclist(0, {'winid' : 0}).winid)
4086 new | only
4087
4088 call delete('Xtestfile1')
4089 call delete('Xtestfile2')
4090endfunc
Bram Moolenaarc45eb772019-01-31 14:27:04 +01004091
4092" Test for parsing entries using visual screen column
4093func Test_viscol()
4094 enew
4095 call writefile(["Col1\tCol2\tCol3"], 'Xfile1')
4096 edit Xfile1
4097
4098 " Use byte offset for column number
4099 set efm&
4100 cexpr "Xfile1:1:5:XX\nXfile1:1:9:YY\nXfile1:1:20:ZZ"
4101 call assert_equal([5, 8], [col('.'), virtcol('.')])
4102 cnext
4103 call assert_equal([9, 12], [col('.'), virtcol('.')])
4104 cnext
4105 call assert_equal([14, 20], [col('.'), virtcol('.')])
4106
4107 " Use screen column offset for column number
4108 set efm=%f:%l:%v:%m
4109 cexpr "Xfile1:1:8:XX\nXfile1:1:12:YY\nXfile1:1:20:ZZ"
4110 call assert_equal([5, 8], [col('.'), virtcol('.')])
4111 cnext
4112 call assert_equal([9, 12], [col('.'), virtcol('.')])
4113 cnext
4114 call assert_equal([14, 20], [col('.'), virtcol('.')])
4115 cexpr "Xfile1:1:6:XX\nXfile1:1:15:YY\nXfile1:1:24:ZZ"
4116 call assert_equal([5, 8], [col('.'), virtcol('.')])
4117 cnext
4118 call assert_equal([10, 16], [col('.'), virtcol('.')])
4119 cnext
4120 call assert_equal([14, 20], [col('.'), virtcol('.')])
4121
4122 enew
4123 call writefile(["Col1\täü\töß\tCol4"], 'Xfile1')
4124
4125 " Use byte offset for column number
4126 set efm&
4127 cexpr "Xfile1:1:8:XX\nXfile1:1:11:YY\nXfile1:1:16:ZZ"
4128 call assert_equal([8, 10], [col('.'), virtcol('.')])
4129 cnext
4130 call assert_equal([11, 17], [col('.'), virtcol('.')])
4131 cnext
4132 call assert_equal([16, 25], [col('.'), virtcol('.')])
4133
4134 " Use screen column offset for column number
4135 set efm=%f:%l:%v:%m
4136 cexpr "Xfile1:1:10:XX\nXfile1:1:17:YY\nXfile1:1:25:ZZ"
4137 call assert_equal([8, 10], [col('.'), virtcol('.')])
4138 cnext
4139 call assert_equal([11, 17], [col('.'), virtcol('.')])
4140 cnext
4141 call assert_equal([16, 25], [col('.'), virtcol('.')])
4142
4143 enew | only
4144 set efm&
4145 call delete('Xfile1')
4146endfunc
Bram Moolenaaree8188f2019-02-05 21:23:04 +01004147
4148" Test for the quickfix window buffer
4149func Xqfbuf_test(cchar)
4150 call s:setup_commands(a:cchar)
4151
4152 " Quickfix buffer should be reused across closing and opening a quickfix
4153 " window
4154 Xexpr "F1:10:Line10"
4155 Xopen
4156 let qfbnum = bufnr('')
4157 Xclose
4158 " Even after the quickfix window is closed, the buffer should be loaded
4159 call assert_true(bufloaded(qfbnum))
Bram Moolenaar647e24b2019-03-17 16:39:46 +01004160 call assert_true(qfbnum, g:Xgetlist({'qfbufnr' : 0}).qfbufnr)
Bram Moolenaaree8188f2019-02-05 21:23:04 +01004161 Xopen
4162 " Buffer should be reused when opening the window again
4163 call assert_equal(qfbnum, bufnr(''))
4164 Xclose
4165
4166 if a:cchar == 'l'
4167 %bwipe
4168 " For a location list, when both the file window and the location list
4169 " window for the list are closed, then the buffer should be freed.
4170 new | only
4171 lexpr "F1:10:Line10"
4172 let wid = win_getid()
4173 lopen
4174 let qfbnum = bufnr('')
4175 call assert_match(qfbnum . ' %a- "\[Location List]"', execute('ls'))
4176 close
4177 " When the location list window is closed, the buffer name should not
4178 " change to 'Quickfix List'
Bram Moolenaar647e24b2019-03-17 16:39:46 +01004179 call assert_match(qfbnum . 'u h- "\[Location List]"', execute('ls!'))
Bram Moolenaaree8188f2019-02-05 21:23:04 +01004180 call assert_true(bufloaded(qfbnum))
4181
Bram Moolenaard82a81c2019-03-02 07:57:18 +01004182 " After deleting a location list buffer using ":bdelete", opening the
4183 " location list window should mark the buffer as a location list buffer.
4184 exe "bdelete " . qfbnum
4185 lopen
4186 call assert_equal("quickfix", &buftype)
4187 call assert_equal(1, getwininfo(win_getid(winnr()))[0].loclist)
4188 call assert_equal(wid, getloclist(0, {'filewinid' : 0}).filewinid)
4189 call assert_false(&swapfile)
4190 lclose
4191
Bram Moolenaareeb1b9c2019-02-10 22:59:04 +01004192 " When the location list is cleared for the window, the buffer should be
4193 " removed
4194 call setloclist(0, [], 'f')
4195 call assert_false(bufexists(qfbnum))
Bram Moolenaar647e24b2019-03-17 16:39:46 +01004196 call assert_equal(0, getloclist(0, {'qfbufnr' : 0}).qfbufnr)
Bram Moolenaareeb1b9c2019-02-10 22:59:04 +01004197
4198 " When the location list is freed with the location list window open, the
4199 " location list buffer should not be lost. It should be reused when the
4200 " location list is again populated.
4201 lexpr "F1:10:Line10"
4202 lopen
4203 let wid = win_getid()
4204 let qfbnum = bufnr('')
4205 wincmd p
4206 call setloclist(0, [], 'f')
4207 lexpr "F1:10:Line10"
4208 lopen
4209 call assert_equal(wid, win_getid())
4210 call assert_equal(qfbnum, bufnr(''))
4211 lclose
4212
4213 " When the window with the location list is closed, the buffer should be
4214 " removed
Bram Moolenaaree8188f2019-02-05 21:23:04 +01004215 new | only
Bram Moolenaareeb1b9c2019-02-10 22:59:04 +01004216 call assert_false(bufexists(qfbnum))
Bram Moolenaaree8188f2019-02-05 21:23:04 +01004217 endif
4218endfunc
4219
4220func Test_qfbuf()
4221 call Xqfbuf_test('c')
4222 call Xqfbuf_test('l')
4223endfunc
Bram Moolenaareeb1b9c2019-02-10 22:59:04 +01004224
4225" If there is an autocmd to use only one window, then opening the location
4226" list window used to crash Vim.
4227func Test_winonly_autocmd()
4228 call s:create_test_file('Xtest1')
4229 " Autocmd to show only one Vim window at a time
4230 autocmd WinEnter * only
4231 new
4232 " Load the location list
4233 lexpr "Xtest1:5:Line5\nXtest1:10:Line10\nXtest1:15:Line15"
4234 let loclistid = getloclist(0, {'id' : 0}).id
4235 " Open the location list window. Only this window will be shown and the file
4236 " window is closed.
4237 lopen
4238 call assert_equal(loclistid, getloclist(0, {'id' : 0}).id)
4239 " Jump to an entry in the location list and make sure that the cursor is
4240 " positioned correctly.
4241 ll 3
4242 call assert_equal(loclistid, getloclist(0, {'id' : 0}).id)
4243 call assert_equal('Xtest1', bufname(''))
4244 call assert_equal(15, line('.'))
4245 " Cleanup
4246 autocmd! WinEnter
4247 new | only
4248 call delete('Xtest1')
4249endfunc
Bram Moolenaar39803d82019-04-07 12:04:51 +02004250
4251" Test to make sure that an empty quickfix buffer is not reused for loading
4252" a normal buffer.
4253func Test_empty_qfbuf()
4254 enew | only
4255 call writefile(["Test"], 'Xfile1')
4256 call setqflist([], 'f')
4257 copen | only
4258 let qfbuf = bufnr('')
4259 edit Xfile1
4260 call assert_notequal(qfbuf, bufnr(''))
4261 enew
4262 call delete('Xfile1')
4263endfunc
Bram Moolenaar3ff33112019-05-03 21:56:35 +02004264
4265" Test for the :cbelow, :cabove, :lbelow and :labove commands.
Bram Moolenaarcf6a55c2019-05-05 15:02:30 +02004266" And for the :cafter, :cbefore, :lafter and :lbefore commands.
Bram Moolenaar3ff33112019-05-03 21:56:35 +02004267func Xtest_below(cchar)
4268 call s:setup_commands(a:cchar)
4269
4270 " No quickfix/location list
4271 call assert_fails('Xbelow', 'E42:')
4272 call assert_fails('Xabove', 'E42:')
Bram Moolenaarcf6a55c2019-05-05 15:02:30 +02004273 call assert_fails('Xbefore', 'E42:')
4274 call assert_fails('Xafter', 'E42:')
Bram Moolenaar3ff33112019-05-03 21:56:35 +02004275
4276 " Empty quickfix/location list
4277 call g:Xsetlist([])
4278 call assert_fails('Xbelow', 'E42:')
4279 call assert_fails('Xabove', 'E42:')
Bram Moolenaarcf6a55c2019-05-05 15:02:30 +02004280 call assert_fails('Xbefore', 'E42:')
4281 call assert_fails('Xafter', 'E42:')
Bram Moolenaar3ff33112019-05-03 21:56:35 +02004282
4283 call s:create_test_file('X1')
4284 call s:create_test_file('X2')
4285 call s:create_test_file('X3')
4286 call s:create_test_file('X4')
4287
4288 " Invalid entries
4289 edit X1
4290 call g:Xsetlist(["E1", "E2"])
4291 call assert_fails('Xbelow', 'E42:')
4292 call assert_fails('Xabove', 'E42:')
4293 call assert_fails('3Xbelow', 'E42:')
4294 call assert_fails('4Xabove', 'E42:')
Bram Moolenaarcf6a55c2019-05-05 15:02:30 +02004295 call assert_fails('Xbefore', 'E42:')
4296 call assert_fails('Xafter', 'E42:')
4297 call assert_fails('3Xbefore', 'E42:')
4298 call assert_fails('4Xafter', 'E42:')
Bram Moolenaar3ff33112019-05-03 21:56:35 +02004299
4300 " Test the commands with various arguments
Bram Moolenaarcf6a55c2019-05-05 15:02:30 +02004301 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 +02004302 edit +7 X2
4303 Xabove
4304 call assert_equal(['X2', 5], [bufname(''), line('.')])
4305 call assert_fails('Xabove', 'E553:')
Bram Moolenaarcf6a55c2019-05-05 15:02:30 +02004306 normal 7G
4307 Xbefore
4308 call assert_equal(['X2', 5, 2], [bufname(''), line('.'), col('.')])
4309 call assert_fails('Xbefore', 'E553:')
4310
Bram Moolenaar3ff33112019-05-03 21:56:35 +02004311 normal 2j
4312 Xbelow
4313 call assert_equal(['X2', 10], [bufname(''), line('.')])
Bram Moolenaarcf6a55c2019-05-05 15:02:30 +02004314 normal 7G
4315 Xafter
4316 call assert_equal(['X2', 10, 3], [bufname(''), line('.'), col('.')])
4317
Bram Moolenaar3ff33112019-05-03 21:56:35 +02004318 " Last error in this file
4319 Xbelow 99
4320 call assert_equal(['X2', 15], [bufname(''), line('.')])
4321 call assert_fails('Xbelow', 'E553:')
Bram Moolenaarcf6a55c2019-05-05 15:02:30 +02004322 normal gg
4323 Xafter 99
4324 call assert_equal(['X2', 15, 4], [bufname(''), line('.'), col('.')])
4325 call assert_fails('Xafter', 'E553:')
4326
Bram Moolenaar3ff33112019-05-03 21:56:35 +02004327 " First error in this file
4328 Xabove 99
4329 call assert_equal(['X2', 5], [bufname(''), line('.')])
4330 call assert_fails('Xabove', 'E553:')
Bram Moolenaarcf6a55c2019-05-05 15:02:30 +02004331 normal G
4332 Xbefore 99
4333 call assert_equal(['X2', 5, 2], [bufname(''), line('.'), col('.')])
4334 call assert_fails('Xbefore', 'E553:')
4335
Bram Moolenaar3ff33112019-05-03 21:56:35 +02004336 normal gg
4337 Xbelow 2
4338 call assert_equal(['X2', 10], [bufname(''), line('.')])
Bram Moolenaarcf6a55c2019-05-05 15:02:30 +02004339 normal gg
4340 Xafter 2
4341 call assert_equal(['X2', 10, 3], [bufname(''), line('.'), col('.')])
4342
Bram Moolenaar3ff33112019-05-03 21:56:35 +02004343 normal G
4344 Xabove 2
4345 call assert_equal(['X2', 10], [bufname(''), line('.')])
Bram Moolenaarcf6a55c2019-05-05 15:02:30 +02004346 normal G
4347 Xbefore 2
4348 call assert_equal(['X2', 10, 3], [bufname(''), line('.'), col('.')])
4349
Bram Moolenaar3ff33112019-05-03 21:56:35 +02004350 edit X4
4351 call assert_fails('Xabove', 'E42:')
4352 call assert_fails('Xbelow', 'E42:')
Bram Moolenaarcf6a55c2019-05-05 15:02:30 +02004353 call assert_fails('Xbefore', 'E42:')
4354 call assert_fails('Xafter', 'E42:')
Bram Moolenaar3ff33112019-05-03 21:56:35 +02004355 if a:cchar == 'l'
4356 " If a buffer has location list entries from some other window but not
4357 " from the current window, then the commands should fail.
4358 edit X1 | split | call setloclist(0, [], 'f')
4359 call assert_fails('Xabove', 'E776:')
4360 call assert_fails('Xbelow', 'E776:')
Bram Moolenaarcf6a55c2019-05-05 15:02:30 +02004361 call assert_fails('Xbefore', 'E776:')
4362 call assert_fails('Xafter', 'E776:')
Bram Moolenaar3ff33112019-05-03 21:56:35 +02004363 close
4364 endif
4365
4366 " Test for lines with multiple quickfix entries
4367 Xexpr ["X1:5:L5", "X2:5:1:L5_1", "X2:5:2:L5_2", "X2:5:3:L5_3",
4368 \ "X2:10:1:L10_1", "X2:10:2:L10_2", "X2:10:3:L10_3",
4369 \ "X2:15:1:L15_1", "X2:15:2:L15_2", "X2:15:3:L15_3", "X3:3:L3"]
4370 edit +1 X2
4371 Xbelow 2
4372 call assert_equal(['X2', 10, 1], [bufname(''), line('.'), col('.')])
Bram Moolenaarcf6a55c2019-05-05 15:02:30 +02004373 normal 1G
4374 Xafter 2
4375 call assert_equal(['X2', 5, 2], [bufname(''), line('.'), col('.')])
4376
Bram Moolenaar3ff33112019-05-03 21:56:35 +02004377 normal gg
4378 Xbelow 99
4379 call assert_equal(['X2', 15, 1], [bufname(''), line('.'), col('.')])
Bram Moolenaarcf6a55c2019-05-05 15:02:30 +02004380 normal gg
4381 Xafter 99
4382 call assert_equal(['X2', 15, 3], [bufname(''), line('.'), col('.')])
4383
Bram Moolenaar3ff33112019-05-03 21:56:35 +02004384 normal G
4385 Xabove 2
4386 call assert_equal(['X2', 10, 1], [bufname(''), line('.'), col('.')])
4387 normal G
Bram Moolenaarcf6a55c2019-05-05 15:02:30 +02004388 Xbefore 2
4389 call assert_equal(['X2', 15, 2], [bufname(''), line('.'), col('.')])
4390
4391 normal G
Bram Moolenaar3ff33112019-05-03 21:56:35 +02004392 Xabove 99
4393 call assert_equal(['X2', 5, 1], [bufname(''), line('.'), col('.')])
Bram Moolenaarcf6a55c2019-05-05 15:02:30 +02004394 normal G
4395 Xbefore 99
4396 call assert_equal(['X2', 5, 1], [bufname(''), line('.'), col('.')])
4397
Bram Moolenaar3ff33112019-05-03 21:56:35 +02004398 normal 10G
4399 Xabove
4400 call assert_equal(['X2', 5, 1], [bufname(''), line('.'), col('.')])
Bram Moolenaarcf6a55c2019-05-05 15:02:30 +02004401 normal 10G$
4402 2Xbefore
4403 call assert_equal(['X2', 10, 2], [bufname(''), line('.'), col('.')])
4404
Bram Moolenaar3ff33112019-05-03 21:56:35 +02004405 normal 10G
4406 Xbelow
4407 call assert_equal(['X2', 15, 1], [bufname(''), line('.'), col('.')])
Bram Moolenaarcf6a55c2019-05-05 15:02:30 +02004408 normal 9G
4409 5Xafter
4410 call assert_equal(['X2', 15, 2], [bufname(''), line('.'), col('.')])
Bram Moolenaar3ff33112019-05-03 21:56:35 +02004411
4412 " Invalid range
4413 if a:cchar == 'c'
Bram Moolenaar25190db2019-05-04 15:05:28 +02004414 call assert_fails('-2cbelow', 'E16:')
Bram Moolenaarcf6a55c2019-05-05 15:02:30 +02004415 call assert_fails('-2cafter', 'E16:')
Bram Moolenaar3ff33112019-05-03 21:56:35 +02004416 else
Bram Moolenaar25190db2019-05-04 15:05:28 +02004417 call assert_fails('-2lbelow', 'E16:')
Bram Moolenaarcf6a55c2019-05-05 15:02:30 +02004418 call assert_fails('-2lafter', 'E16:')
Bram Moolenaar3ff33112019-05-03 21:56:35 +02004419 endif
4420
4421 call delete('X1')
4422 call delete('X2')
4423 call delete('X3')
4424 call delete('X4')
4425endfunc
4426
4427func Test_cbelow()
4428 call Xtest_below('c')
4429 call Xtest_below('l')
4430endfunc
Bram Moolenaar25190db2019-05-04 15:05:28 +02004431
4432func Test_quickfix_count()
4433 let commands = [
4434 \ 'cNext',
4435 \ 'cNfile',
4436 \ 'cabove',
4437 \ 'cbelow',
4438 \ 'cfirst',
4439 \ 'clast',
4440 \ 'cnewer',
4441 \ 'cnext',
4442 \ 'cnfile',
4443 \ 'colder',
4444 \ 'cprevious',
4445 \ 'crewind',
4446 \
4447 \ 'lNext',
4448 \ 'lNfile',
4449 \ 'labove',
4450 \ 'lbelow',
4451 \ 'lfirst',
4452 \ 'llast',
4453 \ 'lnewer',
4454 \ 'lnext',
4455 \ 'lnfile',
4456 \ 'lolder',
4457 \ 'lprevious',
4458 \ 'lrewind',
4459 \ ]
4460 for cmd in commands
4461 call assert_fails('-1' .. cmd, 'E16:')
4462 call assert_fails('.' .. cmd, 'E16:')
4463 call assert_fails('%' .. cmd, 'E16:')
4464 call assert_fails('$' .. cmd, 'E16:')
4465 endfor
4466endfunc
Bram Moolenaar6a0cc912019-10-26 16:48:44 +02004467
4468" Test for aborting quickfix commands using QuickFixCmdPre
4469func Xtest_qfcmd_abort(cchar)
4470 call s:setup_commands(a:cchar)
4471
4472 call g:Xsetlist([], 'f')
4473
4474 " cexpr/lexpr
4475 let e = ''
4476 try
4477 Xexpr ["F1:10:Line10", "F2:20:Line20"]
4478 catch /.*/
4479 let e = v:exception
4480 endtry
4481 call assert_equal('AbortCmd', e)
4482 call assert_equal(0, g:Xgetlist({'nr' : '$'}).nr)
4483
4484 " cfile/lfile
4485 call writefile(["F1:10:Line10", "F2:20:Line20"], 'Xfile1')
4486 let e = ''
4487 try
4488 Xfile Xfile1
4489 catch /.*/
4490 let e = v:exception
4491 endtry
4492 call assert_equal('AbortCmd', e)
4493 call assert_equal(0, g:Xgetlist({'nr' : '$'}).nr)
4494 call delete('Xfile1')
4495
4496 " cgetbuffer/lgetbuffer
4497 enew!
4498 call append(0, ["F1:10:Line10", "F2:20:Line20"])
4499 let e = ''
4500 try
4501 Xgetbuffer
4502 catch /.*/
4503 let e = v:exception
4504 endtry
4505 call assert_equal('AbortCmd', e)
4506 call assert_equal(0, g:Xgetlist({'nr' : '$'}).nr)
4507 enew!
4508
4509 " vimgrep/lvimgrep
4510 let e = ''
4511 try
4512 Xvimgrep /func/ test_quickfix.vim
4513 catch /.*/
4514 let e = v:exception
4515 endtry
4516 call assert_equal('AbortCmd', e)
4517 call assert_equal(0, g:Xgetlist({'nr' : '$'}).nr)
4518
4519 " helpgrep/lhelpgrep
4520 let e = ''
4521 try
4522 Xhelpgrep quickfix
4523 catch /.*/
4524 let e = v:exception
4525 endtry
4526 call assert_equal('AbortCmd', e)
4527 call assert_equal(0, g:Xgetlist({'nr' : '$'}).nr)
4528
4529 " grep/lgrep
4530 if has('unix')
4531 let e = ''
4532 try
4533 silent Xgrep func test_quickfix.vim
4534 catch /.*/
4535 let e = v:exception
4536 endtry
4537 call assert_equal('AbortCmd', e)
4538 call assert_equal(0, g:Xgetlist({'nr' : '$'}).nr)
4539 endif
4540endfunc
4541
4542func Test_qfcmd_abort()
4543 augroup QF_Test
4544 au!
4545 autocmd QuickFixCmdPre * throw "AbortCmd"
4546 augroup END
4547
4548 call Xtest_qfcmd_abort('c')
4549 call Xtest_qfcmd_abort('l')
4550
4551 augroup QF_Test
4552 au!
4553 augroup END
4554endfunc
4555
Bram Moolenaard8a8c4c2019-11-16 21:04:57 +01004556" Test for using a file in one of the parent directories.
4557func Test_search_in_dirstack()
4558 call mkdir('Xtestdir/a/b/c', 'p')
4559 let save_cwd = getcwd()
4560 call writefile(["X1_L1", "X1_L2"], 'Xtestdir/Xfile1')
4561 call writefile(["X2_L1", "X2_L2"], 'Xtestdir/a/Xfile2')
4562 call writefile(["X3_L1", "X3_L2"], 'Xtestdir/a/b/Xfile3')
4563 call writefile(["X4_L1", "X4_L2"], 'Xtestdir/a/b/c/Xfile4')
4564
4565 let lines = "Entering dir Xtestdir\n" .
4566 \ "Entering dir a\n" .
4567 \ "Entering dir b\n" .
4568 \ "Xfile2:2:X2_L2\n" .
4569 \ "Leaving dir a\n" .
4570 \ "Xfile1:2:X1_L2\n" .
4571 \ "Xfile3:1:X3_L1\n" .
4572 \ "Entering dir c\n" .
4573 \ "Xfile4:2:X4_L2\n" .
4574 \ "Leaving dir c\n" .
4575 \ "Leaving dir Xtestdir\n"
4576 set efm=%DEntering\ dir\ %f,%XLeaving\ dir\ %f,%f:%l:%m
4577 cexpr lines
4578 call assert_equal(11, getqflist({'size' : 0}).size)
4579 call assert_equal(4, getqflist({'idx' : 0}).idx)
4580 call assert_equal('X2_L2', getline('.'))
4581 cnext
4582 call assert_equal(6, getqflist({'idx' : 0}).idx)
4583 call assert_equal('X1_L2', getline('.'))
4584 cnext
4585 call assert_equal(7, getqflist({'idx' : 0}).idx)
4586 call assert_equal(1, line('$'))
4587 call assert_equal('', getline(1))
4588 cnext
4589 call assert_equal(9, getqflist({'idx' : 0}).idx)
4590 call assert_equal(1, line('$'))
4591 call assert_equal('', getline(1))
4592
4593 set efm&
4594 exe 'cd ' . save_cwd
4595 call delete('Xtestdir', 'rf')
4596endfunc
4597
Bram Moolenaar6a0cc912019-10-26 16:48:44 +02004598" vim: shiftwidth=2 sts=2 expandtab