blob: 291e2231722571101f63f0095d29bc6873e69a9a [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
Bram Moolenaar70077dd2019-11-24 12:12:42 +0100366 " Test for a file with a long line and without a newline at the end
367 let text = repeat('x', 1024)
368 let t = 'a.txt:18:' . text
369 call writefile([t], 'Xqftestfile1', 'b')
370 silent! Xfile Xqftestfile1
371 call assert_equal(text, g:Xgetlist()[0].text)
372
Bram Moolenaarda59dd52016-01-05 21:59:58 +0100373 call delete('Xqftestfile1')
Bram Moolenaar2b946c92016-11-12 18:14:44 +0100374endfunc
Bram Moolenaarda59dd52016-01-05 21:59:58 +0100375
Bram Moolenaar2b946c92016-11-12 18:14:44 +0100376func Test_cfile()
Bram Moolenaarda59dd52016-01-05 21:59:58 +0100377 call XfileTests('c')
378 call XfileTests('l')
Bram Moolenaar2b946c92016-11-12 18:14:44 +0100379endfunc
Bram Moolenaarda59dd52016-01-05 21:59:58 +0100380
381" Tests for the :cbuffer, :lbuffer, :caddbuffer, :laddbuffer, :cgetbuffer and
382" :lgetbuffer commands.
Bram Moolenaar2b946c92016-11-12 18:14:44 +0100383func XbufferTests(cchar)
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +0200384 call s:setup_commands(a:cchar)
Bram Moolenaarda59dd52016-01-05 21:59:58 +0100385
386 enew!
387 silent! call setline(1, ['Xtestfile7:700:10:Line 700',
388 \ 'Xtestfile8:800:15:Line 800'])
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +0200389 Xbuffer!
390 let l = g:Xgetlist()
Bram Moolenaarda59dd52016-01-05 21:59:58 +0100391 call assert_true(len(l) == 2 &&
392 \ l[0].lnum == 700 && l[0].col == 10 && l[0].text ==# 'Line 700' &&
393 \ l[1].lnum == 800 && l[1].col == 15 && l[1].text ==# 'Line 800')
394
395 enew!
396 silent! call setline(1, ['Xtestfile9:900:55:Line 900',
397 \ 'Xtestfile10:950:66:Line 950'])
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +0200398 Xgetbuffer
399 let l = g:Xgetlist()
Bram Moolenaarda59dd52016-01-05 21:59:58 +0100400 call assert_true(len(l) == 2 &&
401 \ l[0].lnum == 900 && l[0].col == 55 && l[0].text ==# 'Line 900' &&
402 \ l[1].lnum == 950 && l[1].col == 66 && l[1].text ==# 'Line 950')
403
404 enew!
405 silent! call setline(1, ['Xtestfile11:700:20:Line 700',
406 \ 'Xtestfile12:750:25:Line 750'])
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +0200407 Xaddbuffer
408 let l = g:Xgetlist()
Bram Moolenaarda59dd52016-01-05 21:59:58 +0100409 call assert_true(len(l) == 4 &&
410 \ l[1].lnum == 950 && l[1].col == 66 && l[1].text ==# 'Line 950' &&
411 \ l[2].lnum == 700 && l[2].col == 20 && l[2].text ==# 'Line 700' &&
412 \ l[3].lnum == 750 && l[3].col == 25 && l[3].text ==# 'Line 750')
Bram Moolenaarab47c612016-06-14 22:02:26 +0200413 enew!
Bram Moolenaarda59dd52016-01-05 21:59:58 +0100414
Bram Moolenaaree85df32017-03-19 14:19:50 +0100415 " Check for invalid buffer
416 call assert_fails('Xbuffer 199', 'E474:')
417
418 " Check for unloaded buffer
419 edit Xtestfile1
420 let bnr = bufnr('%')
421 enew!
422 call assert_fails('Xbuffer ' . bnr, 'E681:')
423
424 " Check for invalid range
425 " Using Xbuffer will not run the range check in the cbuffer/lbuffer
426 " commands. So directly call the commands.
427 if (a:cchar == 'c')
428 call assert_fails('900,999cbuffer', 'E16:')
429 else
430 call assert_fails('900,999lbuffer', 'E16:')
431 endif
Bram Moolenaar2b946c92016-11-12 18:14:44 +0100432endfunc
Bram Moolenaarda59dd52016-01-05 21:59:58 +0100433
Bram Moolenaar2b946c92016-11-12 18:14:44 +0100434func Test_cbuffer()
Bram Moolenaarda59dd52016-01-05 21:59:58 +0100435 call XbufferTests('c')
436 call XbufferTests('l')
Bram Moolenaar2b946c92016-11-12 18:14:44 +0100437endfunc
Bram Moolenaarda59dd52016-01-05 21:59:58 +0100438
Bram Moolenaar2b946c92016-11-12 18:14:44 +0100439func XexprTests(cchar)
Bram Moolenaar0fcc7c62016-07-02 21:22:52 +0200440 call s:setup_commands(a:cchar)
441
442 call assert_fails('Xexpr 10', 'E777:')
Bram Moolenaar2b946c92016-11-12 18:14:44 +0100443endfunc
Bram Moolenaar0fcc7c62016-07-02 21:22:52 +0200444
Bram Moolenaar2b946c92016-11-12 18:14:44 +0100445func Test_cexpr()
Bram Moolenaar0fcc7c62016-07-02 21:22:52 +0200446 call XexprTests('c')
447 call XexprTests('l')
Bram Moolenaar2b946c92016-11-12 18:14:44 +0100448endfunc
Bram Moolenaar0fcc7c62016-07-02 21:22:52 +0200449
450" Tests for :cnext, :cprev, :cfirst, :clast commands
Bram Moolenaar2b946c92016-11-12 18:14:44 +0100451func Xtest_browse(cchar)
Bram Moolenaar0fcc7c62016-07-02 21:22:52 +0200452 call s:setup_commands(a:cchar)
453
Bram Moolenaar74240d32017-12-10 15:26:15 +0100454 call g:Xsetlist([], 'f')
Bram Moolenaarb6fa30c2017-03-29 14:19:25 +0200455 " Jumping to first or next location list entry without any error should
456 " result in failure
Bram Moolenaar74240d32017-12-10 15:26:15 +0100457 if a:cchar == 'c'
458 let err = 'E42:'
459 else
460 let err = 'E776:'
Bram Moolenaarb6fa30c2017-03-29 14:19:25 +0200461 endif
Bram Moolenaar74240d32017-12-10 15:26:15 +0100462 call assert_fails('Xnext', err)
463 call assert_fails('Xprev', err)
464 call assert_fails('Xnfile', err)
465 call assert_fails('Xpfile', err)
Bram Moolenaarb6fa30c2017-03-29 14:19:25 +0200466
Bram Moolenaarf9ae1542019-11-18 22:02:16 +0100467 Xexpr ''
468 let cmd = (a:cchar == 'c') ? '$cc' : '$ll'
469 call assert_fails(cmd, 'E42:')
470
Bram Moolenaar0fcc7c62016-07-02 21:22:52 +0200471 call s:create_test_file('Xqftestfile1')
472 call s:create_test_file('Xqftestfile2')
473
474 Xgetexpr ['Xqftestfile1:5:Line5',
475 \ 'Xqftestfile1:6:Line6',
476 \ 'Xqftestfile2:10:Line10',
Bram Moolenaar99895ea2017-04-20 22:44:47 +0200477 \ 'Xqftestfile2:11:Line11',
478 \ 'RegularLine1',
479 \ 'RegularLine2']
Bram Moolenaar0fcc7c62016-07-02 21:22:52 +0200480
481 Xfirst
482 call assert_fails('Xprev', 'E553')
483 call assert_fails('Xpfile', 'E553')
484 Xnfile
485 call assert_equal('Xqftestfile2', bufname('%'))
486 call assert_equal(10, line('.'))
487 Xpfile
488 call assert_equal('Xqftestfile1', bufname('%'))
489 call assert_equal(6, line('.'))
Bram Moolenaar74240d32017-12-10 15:26:15 +0100490 5Xcc
491 call assert_equal(5, g:Xgetlist({'idx':0}).idx)
492 2Xcc
493 call assert_equal(2, g:Xgetlist({'idx':0}).idx)
Bram Moolenaarf9ae1542019-11-18 22:02:16 +0100494 if a:cchar == 'c'
495 cc
496 else
497 ll
498 endif
499 call assert_equal(2, g:Xgetlist({'idx':0}).idx)
Bram Moolenaar74240d32017-12-10 15:26:15 +0100500 10Xcc
501 call assert_equal(6, g:Xgetlist({'idx':0}).idx)
Bram Moolenaar0fcc7c62016-07-02 21:22:52 +0200502 Xlast
Bram Moolenaar99895ea2017-04-20 22:44:47 +0200503 Xprev
Bram Moolenaar0fcc7c62016-07-02 21:22:52 +0200504 call assert_equal('Xqftestfile2', bufname('%'))
505 call assert_equal(11, line('.'))
506 call assert_fails('Xnext', 'E553')
507 call assert_fails('Xnfile', 'E553')
Bram Moolenaarf9ae1542019-11-18 22:02:16 +0100508 " To process the range using quickfix list entries, directly use the
509 " quickfix commands (don't use the user defined commands)
510 if a:cchar == 'c'
511 $cc
512 else
513 $ll
514 endif
515 call assert_equal(6, g:Xgetlist({'idx':0}).idx)
Bram Moolenaar0fcc7c62016-07-02 21:22:52 +0200516 Xrewind
517 call assert_equal('Xqftestfile1', bufname('%'))
518 call assert_equal(5, line('.'))
519
Bram Moolenaar99895ea2017-04-20 22:44:47 +0200520 10Xnext
521 call assert_equal('Xqftestfile2', bufname('%'))
522 call assert_equal(11, line('.'))
523 10Xprev
524 call assert_equal('Xqftestfile1', bufname('%'))
525 call assert_equal(5, line('.'))
526
Bram Moolenaar74240d32017-12-10 15:26:15 +0100527 " Jumping to an error from the error window using cc command
528 Xgetexpr ['Xqftestfile1:5:Line5',
529 \ 'Xqftestfile1:6:Line6',
530 \ 'Xqftestfile2:10:Line10',
531 \ 'Xqftestfile2:11:Line11']
532 Xopen
533 10Xcc
534 call assert_equal(11, line('.'))
535 call assert_equal('Xqftestfile2', bufname('%'))
536
537 " Jumping to an error from the error window (when only the error window is
538 " present)
539 Xopen | only
540 Xlast 1
541 call assert_equal(5, line('.'))
542 call assert_equal('Xqftestfile1', bufname('%'))
543
Bram Moolenaaree85df32017-03-19 14:19:50 +0100544 Xexpr ""
545 call assert_fails('Xnext', 'E42:')
546
Bram Moolenaar0fcc7c62016-07-02 21:22:52 +0200547 call delete('Xqftestfile1')
548 call delete('Xqftestfile2')
Bram Moolenaarfc2b2702017-09-15 22:43:07 +0200549
550 " Should be able to use next/prev with invalid entries
551 Xexpr ""
552 call assert_equal(0, g:Xgetlist({'idx' : 0}).idx)
553 call assert_equal(0, g:Xgetlist({'size' : 0}).size)
554 Xaddexpr ['foo', 'bar', 'baz', 'quux', 'shmoo']
555 call assert_equal(5, g:Xgetlist({'size' : 0}).size)
556 Xlast
557 call assert_equal(5, g:Xgetlist({'idx' : 0}).idx)
558 Xfirst
559 call assert_equal(1, g:Xgetlist({'idx' : 0}).idx)
560 2Xnext
561 call assert_equal(3, g:Xgetlist({'idx' : 0}).idx)
Bram Moolenaar2b946c92016-11-12 18:14:44 +0100562endfunc
Bram Moolenaar0fcc7c62016-07-02 21:22:52 +0200563
Bram Moolenaar2b946c92016-11-12 18:14:44 +0100564func Test_browse()
Bram Moolenaar0fcc7c62016-07-02 21:22:52 +0200565 call Xtest_browse('c')
566 call Xtest_browse('l')
Bram Moolenaar2b946c92016-11-12 18:14:44 +0100567endfunc
Bram Moolenaar0fcc7c62016-07-02 21:22:52 +0200568
Bram Moolenaar2b946c92016-11-12 18:14:44 +0100569func Test_nomem()
Bram Moolenaar8e8df252016-05-25 21:23:21 +0200570 call test_alloc_fail(GetAllocId('qf_dirname_start'), 0, 0)
Bram Moolenaara260b872016-01-15 20:48:22 +0100571 call assert_fails('vimgrep vim runtest.vim', 'E342:')
Bram Moolenaar75bdf6a2016-01-07 21:25:08 +0100572
Bram Moolenaarce90e362019-09-08 18:58:44 +0200573 call GetAllocId('qf_dirname_now')->test_alloc_fail(0, 0)
Bram Moolenaara260b872016-01-15 20:48:22 +0100574 call assert_fails('vimgrep vim runtest.vim', 'E342:')
Bram Moolenaar75bdf6a2016-01-07 21:25:08 +0100575
Bram Moolenaar8e8df252016-05-25 21:23:21 +0200576 call test_alloc_fail(GetAllocId('qf_namebuf'), 0, 0)
Bram Moolenaara260b872016-01-15 20:48:22 +0100577 call assert_fails('cfile runtest.vim', 'E342:')
Bram Moolenaar75bdf6a2016-01-07 21:25:08 +0100578
Bram Moolenaar8e8df252016-05-25 21:23:21 +0200579 call test_alloc_fail(GetAllocId('qf_errmsg'), 0, 0)
Bram Moolenaara260b872016-01-15 20:48:22 +0100580 call assert_fails('cfile runtest.vim', 'E342:')
Bram Moolenaar75bdf6a2016-01-07 21:25:08 +0100581
Bram Moolenaar8e8df252016-05-25 21:23:21 +0200582 call test_alloc_fail(GetAllocId('qf_pattern'), 0, 0)
Bram Moolenaara260b872016-01-15 20:48:22 +0100583 call assert_fails('cfile runtest.vim', 'E342:')
Bram Moolenaar75bdf6a2016-01-07 21:25:08 +0100584
585endfunc
586
Bram Moolenaar2b946c92016-11-12 18:14:44 +0100587func s:test_xhelpgrep(cchar)
Bram Moolenaar049cba92016-06-26 14:38:04 +0200588 call s:setup_commands(a:cchar)
589 Xhelpgrep quickfix
590 Xopen
591 if a:cchar == 'c'
592 let title_text = ':helpgrep quickfix'
593 else
594 let title_text = ':lhelpgrep quickfix'
595 endif
596 call assert_true(w:quickfix_title =~ title_text, w:quickfix_title)
Bram Moolenaar99895ea2017-04-20 22:44:47 +0200597
598 " Jumping to a help topic should open the help window
599 only
600 Xnext
601 call assert_true(&buftype == 'help')
602 call assert_true(winnr('$') == 2)
603 " Jumping to the next match should reuse the help window
604 Xnext
605 call assert_true(&buftype == 'help')
606 call assert_true(winnr() == 1)
607 call assert_true(winnr('$') == 2)
608 " Jumping to the next match from the quickfix window should reuse the help
609 " window
610 Xopen
611 Xnext
612 call assert_true(&buftype == 'help')
613 call assert_true(winnr() == 1)
614 call assert_true(winnr('$') == 2)
615
Bram Moolenaar62ef7972016-01-19 14:51:54 +0100616 " This wipes out the buffer, make sure that doesn't cause trouble.
Bram Moolenaar049cba92016-06-26 14:38:04 +0200617 Xclose
Bram Moolenaaree85df32017-03-19 14:19:50 +0100618
Bram Moolenaarf9ae1542019-11-18 22:02:16 +0100619 " When the current window is vertically split, jumping to a help match
620 " should open the help window at the top.
621 only | enew
622 let w1 = win_getid()
623 vert new
624 let w2 = win_getid()
625 Xnext
626 let w3 = win_getid()
627 call assert_true(&buftype == 'help')
628 call assert_true(winnr() == 1)
Bram Moolenaar70077dd2019-11-24 12:12:42 +0100629 call win_gotoid(w1)
630 call assert_equal(w3, win_getid(winnr('k')))
631 call win_gotoid(w2)
632 call assert_equal(w3, win_getid(winnr('k')))
Bram Moolenaarf9ae1542019-11-18 22:02:16 +0100633
634 new | only
635 set buftype=help
636 set modified
637 call assert_fails('Xnext', 'E37:')
638 set nomodified
639 new | only
640
Bram Moolenaarb4d5fba2017-09-11 19:31:28 +0200641 if a:cchar == 'l'
642 " When a help window is present, running :lhelpgrep should reuse the
643 " help window and not the current window
644 new | only
645 call g:Xsetlist([], 'f')
646 help index.txt
647 wincmd w
648 lhelpgrep quickfix
649 call assert_equal(1, winnr())
650 call assert_notequal([], getloclist(1))
651 call assert_equal([], getloclist(2))
652 endif
653
Bram Moolenaar99895ea2017-04-20 22:44:47 +0200654 new | only
655
Bram Moolenaaree85df32017-03-19 14:19:50 +0100656 " Search for non existing help string
657 call assert_fails('Xhelpgrep a1b2c3', 'E480:')
Bram Moolenaar108e7b42018-10-11 17:39:12 +0200658 " Invalid regular expression
659 call assert_fails('Xhelpgrep \@<!', 'E480:')
Bram Moolenaar2b946c92016-11-12 18:14:44 +0100660endfunc
Bram Moolenaar049cba92016-06-26 14:38:04 +0200661
Bram Moolenaar2b946c92016-11-12 18:14:44 +0100662func Test_helpgrep()
Bram Moolenaar049cba92016-06-26 14:38:04 +0200663 call s:test_xhelpgrep('c')
Bram Moolenaarcf25fdb2016-08-03 21:04:53 +0200664 helpclose
Bram Moolenaar049cba92016-06-26 14:38:04 +0200665 call s:test_xhelpgrep('l')
Bram Moolenaar62ef7972016-01-19 14:51:54 +0100666endfunc
Bram Moolenaar75bdf6a2016-01-07 21:25:08 +0100667
Bram Moolenaar6920c722016-01-22 22:44:10 +0100668func Test_errortitle()
669 augroup QfBufWinEnter
670 au!
671 au BufWinEnter * :let g:a=get(w:, 'quickfix_title', 'NONE')
672 augroup END
673 copen
674 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'')'}]
675 call setqflist(a)
676 call assert_equal(':setqflist()', g:a)
677 augroup QfBufWinEnter
678 au!
679 augroup END
680 augroup! QfBufWinEnter
681endfunc
Bram Moolenaare27dba42016-03-15 14:11:10 +0100682
Bram Moolenaar5584df62016-03-18 21:00:51 +0100683func Test_vimgreptitle()
684 augroup QfBufWinEnter
685 au!
686 au BufWinEnter * :let g:a=get(w:, 'quickfix_title', 'NONE')
687 augroup END
688 try
689 vimgrep /pattern/j file
690 catch /E480/
691 endtry
692 copen
693 call assert_equal(': vimgrep /pattern/j file', g:a)
694 augroup QfBufWinEnter
695 au!
696 augroup END
697 augroup! QfBufWinEnter
698endfunc
699
Bram Moolenaar2b946c92016-11-12 18:14:44 +0100700func XqfTitleTests(cchar)
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +0200701 call s:setup_commands(a:cchar)
Bram Moolenaare27dba42016-03-15 14:11:10 +0100702
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +0200703 Xgetexpr ['file:1:1:message']
704 let l = g:Xgetlist()
Bram Moolenaare27dba42016-03-15 14:11:10 +0100705 if a:cchar == 'c'
706 call setqflist(l, 'r')
707 else
708 call setloclist(0, l, 'r')
709 endif
710
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +0200711 Xopen
Bram Moolenaare27dba42016-03-15 14:11:10 +0100712 if a:cchar == 'c'
713 let title = ':setqflist()'
714 else
715 let title = ':setloclist()'
716 endif
717 call assert_equal(title, w:quickfix_title)
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +0200718 Xclose
Bram Moolenaar2b946c92016-11-12 18:14:44 +0100719endfunc
Bram Moolenaare27dba42016-03-15 14:11:10 +0100720
721" Tests for quickfix window's title
Bram Moolenaar2b946c92016-11-12 18:14:44 +0100722func Test_qf_title()
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +0200723 call XqfTitleTests('c')
724 call XqfTitleTests('l')
Bram Moolenaar2b946c92016-11-12 18:14:44 +0100725endfunc
Bram Moolenaare27dba42016-03-15 14:11:10 +0100726
727" Tests for 'errorformat'
Bram Moolenaar2b946c92016-11-12 18:14:44 +0100728func Test_efm()
Bram Moolenaare27dba42016-03-15 14:11:10 +0100729 let save_efm = &efm
730 set efm=%EEEE%m,%WWWW%m,%+CCCC%.%#,%-GGGG%.%#
731 cgetexpr ['WWWW', 'EEEE', 'CCCC']
732 let l = strtrans(string(map(getqflist(), '[v:val.text, v:val.valid]')))
733 call assert_equal("[['W', 1], ['E^@CCCC', 1]]", l)
734 cgetexpr ['WWWW', 'GGGG', 'EEEE', 'CCCC']
735 let l = strtrans(string(map(getqflist(), '[v:val.text, v:val.valid]')))
736 call assert_equal("[['W', 1], ['E^@CCCC', 1]]", l)
737 cgetexpr ['WWWW', 'GGGG', 'ZZZZ', 'EEEE', 'CCCC', 'YYYY']
738 let l = strtrans(string(map(getqflist(), '[v:val.text, v:val.valid]')))
739 call assert_equal("[['W', 1], ['ZZZZ', 0], ['E^@CCCC', 1], ['YYYY', 0]]", l)
740 let &efm = save_efm
Bram Moolenaar2b946c92016-11-12 18:14:44 +0100741endfunc
Bram Moolenaar1ff2b642016-03-17 22:07:02 +0100742
743" This will test for problems in quickfix:
744" A. incorrectly copying location lists which caused the location list to show
745" a different name than the file that was actually being displayed.
746" B. not reusing the window for which the location list window is opened but
747" instead creating new windows.
748" C. make sure that the location list window is not reused instead of the
749" window it belongs to.
750"
751" Set up the test environment:
Bram Moolenaar2b946c92016-11-12 18:14:44 +0100752func ReadTestProtocol(name)
Bram Moolenaar1ff2b642016-03-17 22:07:02 +0100753 let base = substitute(a:name, '\v^test://(.*)%(\.[^.]+)?', '\1', '')
754 let word = substitute(base, '\v(.*)\..*', '\1', '')
755
756 setl modifiable
757 setl noreadonly
758 setl noswapfile
759 setl bufhidden=delete
760 %del _
761 " For problem 2:
762 " 'buftype' has to be set to reproduce the constant opening of new windows
763 setl buftype=nofile
764
765 call setline(1, word)
766
767 setl nomodified
768 setl nomodifiable
769 setl readonly
770 exe 'doautocmd BufRead ' . substitute(a:name, '\v^test://(.*)', '\1', '')
Bram Moolenaar2b946c92016-11-12 18:14:44 +0100771endfunc
Bram Moolenaar1ff2b642016-03-17 22:07:02 +0100772
Bram Moolenaar2b946c92016-11-12 18:14:44 +0100773func Test_locationlist()
Bram Moolenaar1ff2b642016-03-17 22:07:02 +0100774 enew
775
776 augroup testgroup
777 au!
778 autocmd BufReadCmd test://* call ReadTestProtocol(expand("<amatch>"))
779 augroup END
780
781 let words = [ "foo", "bar", "baz", "quux", "shmoo", "spam", "eggs" ]
782
783 let qflist = []
784 for word in words
785 call add(qflist, {'filename': 'test://' . word . '.txt', 'text': 'file ' . word . '.txt', })
786 " NOTE: problem 1:
787 " intentionally not setting 'lnum' so that the quickfix entries are not
788 " valid
Bram Moolenaaraad222c2019-09-06 22:46:09 +0200789 eval qflist->setloclist(0, ' ')
Bram Moolenaar1ff2b642016-03-17 22:07:02 +0100790 endfor
791
792 " Test A
793 lrewind
794 enew
795 lopen
Bram Moolenaar99895ea2017-04-20 22:44:47 +0200796 4lnext
Bram Moolenaar1ff2b642016-03-17 22:07:02 +0100797 vert split
798 wincmd L
799 lopen
800 wincmd p
801 lnext
802 let fileName = expand("%")
803 wincmd p
804 let locationListFileName = substitute(getline(line('.')), '\([^|]*\)|.*', '\1', '')
805 let fileName = substitute(fileName, '\\', '/', 'g')
806 let locationListFileName = substitute(locationListFileName, '\\', '/', 'g')
807 call assert_equal("test://bar.txt", fileName)
808 call assert_equal("test://bar.txt", locationListFileName)
809
810 wincmd n | only
811
812 " Test B:
813 lrewind
814 lopen
815 2
816 exe "normal \<CR>"
817 wincmd p
818 3
819 exe "normal \<CR>"
820 wincmd p
821 4
822 exe "normal \<CR>"
823 call assert_equal(2, winnr('$'))
824 wincmd n | only
825
826 " Test C:
827 lrewind
828 lopen
829 " Let's move the location list window to the top to check whether it (the
830 " first window found) will be reused when we try to open new windows:
831 wincmd K
832 2
833 exe "normal \<CR>"
834 wincmd p
835 3
836 exe "normal \<CR>"
837 wincmd p
838 4
839 exe "normal \<CR>"
840 1wincmd w
841 call assert_equal('quickfix', &buftype)
842 2wincmd w
843 let bufferName = expand("%")
844 let bufferName = substitute(bufferName, '\\', '/', 'g')
845 call assert_equal('test://quux.txt', bufferName)
846
847 wincmd n | only
848
849 augroup! testgroup
Bram Moolenaaree85df32017-03-19 14:19:50 +0100850endfunc
Bram Moolenaar0899d692016-03-19 13:35:03 +0100851
Bram Moolenaar2b946c92016-11-12 18:14:44 +0100852func Test_locationlist_curwin_was_closed()
Bram Moolenaar0899d692016-03-19 13:35:03 +0100853 augroup testgroup
854 au!
Bram Moolenaard106e5b2016-04-21 19:38:07 +0200855 autocmd BufReadCmd test_curwin.txt call R(expand("<amatch>"))
Bram Moolenaar0899d692016-03-19 13:35:03 +0100856 augroup END
857
Bram Moolenaar2b946c92016-11-12 18:14:44 +0100858 func! R(n)
Bram Moolenaar0899d692016-03-19 13:35:03 +0100859 quit
860 endfunc
861
862 new
863 let q = []
Bram Moolenaard106e5b2016-04-21 19:38:07 +0200864 call add(q, {'filename': 'test_curwin.txt' })
Bram Moolenaar0899d692016-03-19 13:35:03 +0100865 call setloclist(0, q)
866 call assert_fails('lrewind', 'E924:')
867
868 augroup! testgroup
Bram Moolenaaree85df32017-03-19 14:19:50 +0100869endfunc
Bram Moolenaar7eba3d22016-03-19 22:54:09 +0100870
Bram Moolenaar2b946c92016-11-12 18:14:44 +0100871func Test_locationlist_cross_tab_jump()
Bram Moolenaar0a9046f2016-10-15 19:28:13 +0200872 call writefile(['loclistfoo'], 'loclistfoo')
873 call writefile(['loclistbar'], 'loclistbar')
874 set switchbuf=usetab
875
876 edit loclistfoo
877 tabedit loclistbar
878 silent lgrep loclistfoo loclist*
879 call assert_equal(1, tabpagenr())
880
881 enew | only | tabonly
882 set switchbuf&vim
883 call delete('loclistfoo')
884 call delete('loclistbar')
Bram Moolenaar2b946c92016-11-12 18:14:44 +0100885endfunc
Bram Moolenaar0a9046f2016-10-15 19:28:13 +0200886
Bram Moolenaar7eba3d22016-03-19 22:54:09 +0100887" More tests for 'errorformat'
Bram Moolenaar2b946c92016-11-12 18:14:44 +0100888func Test_efm1()
Bram Moolenaar7eba3d22016-03-19 22:54:09 +0100889 if !has('unix')
890 " The 'errorformat' setting is different on non-Unix systems.
891 " This test works only on Unix-like systems.
892 return
893 endif
894
Bram Moolenaarc79745a2019-05-20 22:12:34 +0200895 let l =<< trim [DATA]
Bram Moolenaare7eb9272019-06-24 00:58:07 +0200896 "Xtestfile", line 4.12: 1506-045 (S) Undeclared identifier fd_set.
897 "Xtestfile", line 6 col 19; this is an error
898 gcc -c -DHAVE_CONFIsing-prototypes -I/usr/X11R6/include version.c
899 Xtestfile:9: parse error before `asd'
900 make: *** [vim] Error 1
901 in file "Xtestfile" linenr 10: there is an error
902
903 2 returned
904 "Xtestfile", line 11 col 1; this is an error
905 "Xtestfile", line 12 col 2; this is another error
906 "Xtestfile", line 14:10; this is an error in column 10
907 =Xtestfile=, line 15:10; this is another error, but in vcol 10 this time
908 "Xtestfile", linenr 16: yet another problem
909 Error in "Xtestfile" at line 17:
910 x should be a dot
911 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 17
912 ^
913 Error in "Xtestfile" at line 18:
914 x should be a dot
915 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 18
916 .............^
917 Error in "Xtestfile" at line 19:
918 x should be a dot
919 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 19
920 --------------^
921 Error in "Xtestfile" at line 20:
922 x should be a dot
923 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 20
924 ^
925
926 Does anyone know what is the problem and how to correction it?
927 "Xtestfile", line 21 col 9: What is the title of the quickfix window?
928 "Xtestfile", line 22 col 9: What is the title of the quickfix window?
Bram Moolenaarc79745a2019-05-20 22:12:34 +0200929 [DATA]
Bram Moolenaar7eba3d22016-03-19 22:54:09 +0100930
931 call writefile(l, 'Xerrorfile1')
932 call writefile(l[:-2], 'Xerrorfile2')
933
Bram Moolenaare7eb9272019-06-24 00:58:07 +0200934 let m =<< [DATA]
935 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 2
936 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 3
937 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 4
938 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 5
939 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 6
940 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 7
941 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 8
942 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 9
943 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 10
944 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 11
945 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 12
946 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 13
947 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 14
948 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 15
949 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 16
950 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 17
951 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 18
952 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 19
953 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 20
954 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 21
955 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 22
956[DATA]
Bram Moolenaar7eba3d22016-03-19 22:54:09 +0100957 call writefile(m, 'Xtestfile')
958
959 let save_efm = &efm
960 set efm+==%f=\\,\ line\ %l%*\\D%v%*[^\ ]\ %m
961 set efm^=%AError\ in\ \"%f\"\ at\ line\ %l:,%Z%p^,%C%m
962
963 exe 'cf Xerrorfile2'
964 clast
965 copen
966 call assert_equal(':cf Xerrorfile2', w:quickfix_title)
967 wincmd p
968
969 exe 'cf Xerrorfile1'
970 call assert_equal([4, 12], [line('.'), col('.')])
971 cn
972 call assert_equal([6, 19], [line('.'), col('.')])
973 cn
974 call assert_equal([9, 2], [line('.'), col('.')])
975 cn
976 call assert_equal([10, 2], [line('.'), col('.')])
977 cn
978 call assert_equal([11, 1], [line('.'), col('.')])
979 cn
980 call assert_equal([12, 2], [line('.'), col('.')])
981 cn
982 call assert_equal([14, 10], [line('.'), col('.')])
983 cn
984 call assert_equal([15, 3, 10], [line('.'), col('.'), virtcol('.')])
985 cn
986 call assert_equal([16, 2], [line('.'), col('.')])
987 cn
988 call assert_equal([17, 6], [line('.'), col('.')])
989 cn
990 call assert_equal([18, 7], [line('.'), col('.')])
991 cn
992 call assert_equal([19, 8], [line('.'), col('.')])
993 cn
994 call assert_equal([20, 9], [line('.'), col('.')])
995 clast
996 cprev
997 cprev
998 wincmd w
999 call assert_equal(':cf Xerrorfile1', w:quickfix_title)
1000 wincmd p
1001
1002 let &efm = save_efm
1003 call delete('Xerrorfile1')
1004 call delete('Xerrorfile2')
1005 call delete('Xtestfile')
Bram Moolenaaree85df32017-03-19 14:19:50 +01001006endfunc
Bram Moolenaarffec3c52016-03-23 20:55:42 +01001007
Bram Moolenaarab47c612016-06-14 22:02:26 +02001008" Test for quickfix directory stack support
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001009func s:dir_stack_tests(cchar)
Bram Moolenaar38df43b2016-06-20 21:41:12 +02001010 call s:setup_commands(a:cchar)
1011
Bram Moolenaarab47c612016-06-14 22:02:26 +02001012 let save_efm=&efm
1013 set efm=%DEntering\ dir\ '%f',%f:%l:%m,%XLeaving\ dir\ '%f'
1014
Bram Moolenaar361c8f02016-07-02 15:41:47 +02001015 let lines = ["Entering dir 'dir1/a'",
1016 \ 'habits2.txt:1:Nine Healthy Habits',
1017 \ "Entering dir 'b'",
1018 \ 'habits3.txt:2:0 Hours of television',
1019 \ 'habits2.txt:7:5 Small meals',
1020 \ "Entering dir 'dir1/c'",
1021 \ 'habits4.txt:3:1 Hour of exercise',
1022 \ "Leaving dir 'dir1/c'",
1023 \ "Leaving dir 'dir1/a'",
1024 \ 'habits1.txt:4:2 Liters of water',
1025 \ "Entering dir 'dir2'",
1026 \ 'habits5.txt:5:3 Cups of hot green tea',
1027 \ "Leaving dir 'dir2'"
1028 \]
Bram Moolenaarab47c612016-06-14 22:02:26 +02001029
Bram Moolenaar361c8f02016-07-02 15:41:47 +02001030 Xexpr ""
1031 for l in lines
1032 Xaddexpr l
1033 endfor
Bram Moolenaarab47c612016-06-14 22:02:26 +02001034
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001035 let qf = g:Xgetlist()
Bram Moolenaarab47c612016-06-14 22:02:26 +02001036
1037 call assert_equal('dir1/a/habits2.txt', bufname(qf[1].bufnr))
1038 call assert_equal(1, qf[1].lnum)
1039 call assert_equal('dir1/a/b/habits3.txt', bufname(qf[3].bufnr))
1040 call assert_equal(2, qf[3].lnum)
1041 call assert_equal('dir1/a/habits2.txt', bufname(qf[4].bufnr))
1042 call assert_equal(7, qf[4].lnum)
1043 call assert_equal('dir1/c/habits4.txt', bufname(qf[6].bufnr))
1044 call assert_equal(3, qf[6].lnum)
1045 call assert_equal('habits1.txt', bufname(qf[9].bufnr))
1046 call assert_equal(4, qf[9].lnum)
1047 call assert_equal('dir2/habits5.txt', bufname(qf[11].bufnr))
1048 call assert_equal(5, qf[11].lnum)
1049
1050 let &efm=save_efm
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001051endfunc
Bram Moolenaarab47c612016-06-14 22:02:26 +02001052
1053" Tests for %D and %X errorformat options
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001054func Test_efm_dirstack()
Bram Moolenaarab47c612016-06-14 22:02:26 +02001055 " Create the directory stack and files
1056 call mkdir('dir1')
1057 call mkdir('dir1/a')
1058 call mkdir('dir1/a/b')
1059 call mkdir('dir1/c')
1060 call mkdir('dir2')
1061
1062 let lines = ["Nine Healthy Habits",
1063 \ "0 Hours of television",
1064 \ "1 Hour of exercise",
1065 \ "2 Liters of water",
1066 \ "3 Cups of hot green tea",
1067 \ "4 Short mental breaks",
1068 \ "5 Small meals",
1069 \ "6 AM wake up time",
1070 \ "7 Minutes of laughter",
1071 \ "8 Hours of sleep (at least)",
1072 \ "9 PM end of the day and off to bed"
1073 \ ]
1074 call writefile(lines, 'habits1.txt')
1075 call writefile(lines, 'dir1/a/habits2.txt')
1076 call writefile(lines, 'dir1/a/b/habits3.txt')
1077 call writefile(lines, 'dir1/c/habits4.txt')
1078 call writefile(lines, 'dir2/habits5.txt')
1079
1080 call s:dir_stack_tests('c')
1081 call s:dir_stack_tests('l')
1082
1083 call delete('dir1', 'rf')
1084 call delete('dir2', 'rf')
1085 call delete('habits1.txt')
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001086endfunc
Bram Moolenaarab47c612016-06-14 22:02:26 +02001087
Bram Moolenaar9b457942016-10-09 16:10:05 +02001088" Test for resync after continuing an ignored message
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001089func Xefm_ignore_continuations(cchar)
Bram Moolenaar9b457942016-10-09 16:10:05 +02001090 call s:setup_commands(a:cchar)
1091
1092 let save_efm = &efm
1093
1094 let &efm =
1095 \ '%Eerror %m %l,' .
1096 \ '%-Wignored %m %l,' .
1097 \ '%+Cmore ignored %m %l,' .
1098 \ '%Zignored end'
1099 Xgetexpr ['ignored warning 1', 'more ignored continuation 2', 'ignored end', 'error resync 4']
1100 let l = map(g:Xgetlist(), '[v:val.text, v:val.valid, v:val.lnum, v:val.type]')
1101 call assert_equal([['resync', 1, 4, 'E']], l)
1102
1103 let &efm = save_efm
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001104endfunc
Bram Moolenaar9b457942016-10-09 16:10:05 +02001105
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001106func Test_efm_ignore_continuations()
Bram Moolenaar9b457942016-10-09 16:10:05 +02001107 call Xefm_ignore_continuations('c')
1108 call Xefm_ignore_continuations('l')
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001109endfunc
Bram Moolenaar9b457942016-10-09 16:10:05 +02001110
Bram Moolenaar0fcc7c62016-07-02 21:22:52 +02001111" Tests for invalid error format specifies
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001112func Xinvalid_efm_Tests(cchar)
Bram Moolenaar0fcc7c62016-07-02 21:22:52 +02001113 call s:setup_commands(a:cchar)
1114
Bram Moolenaar049cba92016-06-26 14:38:04 +02001115 let save_efm = &efm
1116
Bram Moolenaar0fcc7c62016-07-02 21:22:52 +02001117 set efm=%f:%l:%m,%f:%f:%l:%m
1118 call assert_fails('Xexpr "abc.txt:1:Hello world"', 'E372:')
1119
1120 set efm=%f:%l:%m,%f:%l:%r:%m
1121 call assert_fails('Xexpr "abc.txt:1:Hello world"', 'E373:')
1122
1123 set efm=%f:%l:%m,%O:%f:%l:%m
1124 call assert_fails('Xexpr "abc.txt:1:Hello world"', 'E373:')
1125
1126 set efm=%f:%l:%m,%f:%l:%*[^a-z
1127 call assert_fails('Xexpr "abc.txt:1:Hello world"', 'E374:')
1128
1129 set efm=%f:%l:%m,%f:%l:%*c
1130 call assert_fails('Xexpr "abc.txt:1:Hello world"', 'E375:')
1131
1132 set efm=%f:%l:%m,%L%M%N
1133 call assert_fails('Xexpr "abc.txt:1:Hello world"', 'E376:')
1134
1135 set efm=%f:%l:%m,%f:%l:%m:%R
1136 call assert_fails('Xexpr "abc.txt:1:Hello world"', 'E377:')
1137
Bram Moolenaar70077dd2019-11-24 12:12:42 +01001138 " Invalid regular expression
1139 set efm=%\\%%k
1140 call assert_fails('Xexpr "abc.txt:1:Hello world"', 'E867:')
1141
Bram Moolenaar0fcc7c62016-07-02 21:22:52 +02001142 set efm=
1143 call assert_fails('Xexpr "abc.txt:1:Hello world"', 'E378:')
1144
1145 set efm=%DEntering\ dir\ abc,%f:%l:%m
1146 call assert_fails('Xexpr ["Entering dir abc", "abc.txt:1:Hello world"]', 'E379:')
1147
1148 let &efm = save_efm
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001149endfunc
Bram Moolenaar0fcc7c62016-07-02 21:22:52 +02001150
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001151func Test_invalid_efm()
Bram Moolenaar0fcc7c62016-07-02 21:22:52 +02001152 call Xinvalid_efm_Tests('c')
1153 call Xinvalid_efm_Tests('l')
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001154endfunc
Bram Moolenaar0fcc7c62016-07-02 21:22:52 +02001155
1156" TODO:
1157" Add tests for the following formats in 'errorformat'
1158" %r %O
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001159func Test_efm2()
Bram Moolenaar0fcc7c62016-07-02 21:22:52 +02001160 let save_efm = &efm
Bram Moolenaar049cba92016-06-26 14:38:04 +02001161
1162 " Test for %s format in efm
1163 set efm=%f:%s
1164 cexpr 'Xtestfile:Line search text'
Bram Moolenaar049cba92016-06-26 14:38:04 +02001165 let l = getqflist()
Bram Moolenaar70077dd2019-11-24 12:12:42 +01001166 call assert_equal('^\VLine search text\$', l[0].pattern)
1167 call assert_equal(0, l[0].lnum)
Bram Moolenaar049cba92016-06-26 14:38:04 +02001168
Bram Moolenaaree85df32017-03-19 14:19:50 +01001169 let l = split(execute('clist', ''), "\n")
1170 call assert_equal([' 1 Xtestfile:^\VLine search text\$: '], l)
1171
Bram Moolenaar70077dd2019-11-24 12:12:42 +01001172 " Test for a long line
1173 cexpr 'Xtestfile:' . repeat('a', 1026)
1174 let l = getqflist()
1175 call assert_equal('^\V' . repeat('a', 1019) . '\$', l[0].pattern)
1176
Bram Moolenaar0fcc7c62016-07-02 21:22:52 +02001177 " Test for %P, %Q and %t format specifiers
Bram Moolenaarc79745a2019-05-20 22:12:34 +02001178 let lines =<< trim [DATA]
Bram Moolenaare7eb9272019-06-24 00:58:07 +02001179 [Xtestfile1]
1180 (1,17) error: ';' missing
1181 (21,2) warning: variable 'z' not defined
1182 (67,3) error: end of file found before string ended
1183 --
Bram Moolenaarc79745a2019-05-20 22:12:34 +02001184
Bram Moolenaare7eb9272019-06-24 00:58:07 +02001185 [Xtestfile2]
1186 --
Bram Moolenaarc79745a2019-05-20 22:12:34 +02001187
Bram Moolenaare7eb9272019-06-24 00:58:07 +02001188 [Xtestfile3]
1189 NEW compiler v1.1
1190 (2,2) warning: variable 'x' not defined
1191 (67,3) warning: 's' already defined
1192 --
Bram Moolenaarc79745a2019-05-20 22:12:34 +02001193 [DATA]
1194
Bram Moolenaaree85df32017-03-19 14:19:50 +01001195 set efm=%+P[%f]%r,(%l\\,%c)%*[\ ]%t%*[^:]:\ %m,%+Q--%r
Bram Moolenaar391b1dd2017-03-04 13:47:11 +01001196 " To exercise the push/pop file functionality in quickfix, the test files
1197 " need to be created.
1198 call writefile(['Line1'], 'Xtestfile1')
1199 call writefile(['Line2'], 'Xtestfile2')
1200 call writefile(['Line3'], 'Xtestfile3')
Bram Moolenaar361c8f02016-07-02 15:41:47 +02001201 cexpr ""
1202 for l in lines
1203 caddexpr l
1204 endfor
Bram Moolenaar049cba92016-06-26 14:38:04 +02001205 let l = getqflist()
Bram Moolenaaree85df32017-03-19 14:19:50 +01001206 call assert_equal(12, len(l))
Bram Moolenaar049cba92016-06-26 14:38:04 +02001207 call assert_equal(21, l[2].lnum)
1208 call assert_equal(2, l[2].col)
Bram Moolenaar0fcc7c62016-07-02 21:22:52 +02001209 call assert_equal('w', l[2].type)
1210 call assert_equal('e', l[3].type)
Bram Moolenaar391b1dd2017-03-04 13:47:11 +01001211 call delete('Xtestfile1')
1212 call delete('Xtestfile2')
1213 call delete('Xtestfile3')
Bram Moolenaar0fcc7c62016-07-02 21:22:52 +02001214
Bram Moolenaar70077dd2019-11-24 12:12:42 +01001215 " Test for %P, %Q with non-existing files
1216 cexpr lines
1217 let l = getqflist()
1218 call assert_equal(14, len(l))
1219 call assert_equal('[Xtestfile1]', l[0].text)
1220 call assert_equal('[Xtestfile2]', l[6].text)
1221 call assert_equal('[Xtestfile3]', l[9].text)
1222
Bram Moolenaar0fcc7c62016-07-02 21:22:52 +02001223 " Tests for %E, %C and %Z format specifiers
Bram Moolenaarc79745a2019-05-20 22:12:34 +02001224 let lines =<< trim [DATA]
Bram Moolenaare7eb9272019-06-24 00:58:07 +02001225 Error 275
1226 line 42
1227 column 3
1228 ' ' expected after '--'
Bram Moolenaarc79745a2019-05-20 22:12:34 +02001229 [DATA]
1230
Bram Moolenaar0fcc7c62016-07-02 21:22:52 +02001231 set efm=%EError\ %n,%Cline\ %l,%Ccolumn\ %c,%Z%m
1232 cgetexpr lines
1233 let l = getqflist()
1234 call assert_equal(275, l[0].nr)
1235 call assert_equal(42, l[0].lnum)
1236 call assert_equal(3, l[0].col)
1237 call assert_equal('E', l[0].type)
1238 call assert_equal("\n' ' expected after '--'", l[0].text)
1239
1240 " Test for %>
Bram Moolenaarc79745a2019-05-20 22:12:34 +02001241 let lines =<< trim [DATA]
Bram Moolenaare7eb9272019-06-24 00:58:07 +02001242 Error in line 147 of foo.c:
1243 unknown variable 'i'
Bram Moolenaarc79745a2019-05-20 22:12:34 +02001244 [DATA]
1245
Bram Moolenaar0fcc7c62016-07-02 21:22:52 +02001246 set efm=unknown\ variable\ %m,%E%>Error\ in\ line\ %l\ of\ %f:,%Z%m
1247 cgetexpr lines
1248 let l = getqflist()
1249 call assert_equal(147, l[0].lnum)
1250 call assert_equal('E', l[0].type)
1251 call assert_equal("\nunknown variable 'i'", l[0].text)
Bram Moolenaar049cba92016-06-26 14:38:04 +02001252
Bram Moolenaare87e6dd2016-07-17 19:25:04 +02001253 " Test for %A, %C and other formats
Bram Moolenaarc79745a2019-05-20 22:12:34 +02001254 let lines =<< trim [DATA]
Bram Moolenaare7eb9272019-06-24 00:58:07 +02001255 ==============================================================
1256 FAIL: testGetTypeIdCachesResult (dbfacadeTest.DjsDBFacadeTest)
1257 --------------------------------------------------------------
1258 Traceback (most recent call last):
1259 File "unittests/dbfacadeTest.py", line 89, in testFoo
1260 self.assertEquals(34, dtid)
1261 File "/usr/lib/python2.2/unittest.py", line 286, in
1262 failUnlessEqual
1263 raise self.failureException, \\
Bram Moolenaar70077dd2019-11-24 12:12:42 +01001264 W:AssertionError: 34 != 33
Bram Moolenaare7eb9272019-06-24 00:58:07 +02001265
1266 --------------------------------------------------------------
1267 Ran 27 tests in 0.063s
Bram Moolenaarc79745a2019-05-20 22:12:34 +02001268 [DATA]
1269
Bram Moolenaar70077dd2019-11-24 12:12:42 +01001270 set efm=%C\ %.%#,%A\ \ File\ \"%f\"\\,\ line\ %l%.%#,%Z%[%^\ ]%\\@=%t:%m
Bram Moolenaare87e6dd2016-07-17 19:25:04 +02001271 cgetexpr lines
1272 let l = getqflist()
1273 call assert_equal(8, len(l))
1274 call assert_equal(89, l[4].lnum)
1275 call assert_equal(1, l[4].valid)
1276 call assert_equal('unittests/dbfacadeTest.py', bufname(l[4].bufnr))
Bram Moolenaar70077dd2019-11-24 12:12:42 +01001277 call assert_equal('W', l[4].type)
Bram Moolenaare87e6dd2016-07-17 19:25:04 +02001278
Bram Moolenaard76ce852018-05-01 15:02:04 +02001279 " Test for %o
1280 set efm=%f(%o):%l\ %m
Bram Moolenaarbc7845d2018-05-01 16:26:48 +02001281 cgetexpr ['Xotestfile(Language.PureScript.Types):20 Error']
1282 call writefile(['Line1'], 'Xotestfile')
Bram Moolenaard76ce852018-05-01 15:02:04 +02001283 let l = getqflist()
1284 call assert_equal(1, len(l), string(l))
1285 call assert_equal('Language.PureScript.Types', l[0].module)
1286 copen
1287 call assert_equal('Language.PureScript.Types|20| Error', getline(1))
1288 call feedkeys("\<CR>", 'xn')
Bram Moolenaarbc7845d2018-05-01 16:26:48 +02001289 call assert_equal('Xotestfile', expand('%:t'))
Bram Moolenaard76ce852018-05-01 15:02:04 +02001290 cclose
1291 bd
Bram Moolenaarbc7845d2018-05-01 16:26:48 +02001292 call delete("Xotestfile")
Bram Moolenaard76ce852018-05-01 15:02:04 +02001293
Bram Moolenaar70077dd2019-11-24 12:12:42 +01001294 " Test for a long module name
1295 cexpr 'Xtest(' . repeat('m', 1026) . '):15 message'
1296 let l = getqflist()
1297 call assert_equal(repeat('m', 1024), l[0].module)
1298 call assert_equal(15, l[0].lnum)
1299 call assert_equal('message', l[0].text)
1300
Bram Moolenaar99895ea2017-04-20 22:44:47 +02001301 " The following sequence of commands used to crash Vim
1302 set efm=%W%m
1303 cgetexpr ['msg1']
1304 let l = getqflist()
1305 call assert_equal(1, len(l), string(l))
1306 call assert_equal('msg1', l[0].text)
1307 set efm=%C%m
1308 lexpr 'msg2'
1309 let l = getloclist(0)
1310 call assert_equal(1, len(l), string(l))
1311 call assert_equal('msg2', l[0].text)
1312 lopen
1313 call setqflist([], 'r')
1314 caddbuf
1315 let l = getqflist()
1316 call assert_equal(1, len(l), string(l))
1317 call assert_equal('|| msg2', l[0].text)
1318
Bram Moolenaar78ddc062018-05-15 21:56:34 +02001319 " When matching error lines, case should be ignored. Test for this.
1320 set noignorecase
1321 let l=getqflist({'lines' : ['Xtest:FOO10:Line 20'], 'efm':'%f:foo%l:%m'})
1322 call assert_equal(10, l.items[0].lnum)
1323 call assert_equal('Line 20', l.items[0].text)
1324 set ignorecase&
1325
Bram Moolenaar99895ea2017-04-20 22:44:47 +02001326 new | only
Bram Moolenaar049cba92016-06-26 14:38:04 +02001327 let &efm = save_efm
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001328endfunc
Bram Moolenaar049cba92016-06-26 14:38:04 +02001329
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001330func XquickfixChangedByAutocmd(cchar)
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001331 call s:setup_commands(a:cchar)
Bram Moolenaarffec3c52016-03-23 20:55:42 +01001332 if a:cchar == 'c'
Bram Moolenaarffec3c52016-03-23 20:55:42 +01001333 let ErrorNr = 'E925'
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001334 func! ReadFunc()
Bram Moolenaarffec3c52016-03-23 20:55:42 +01001335 colder
1336 cgetexpr []
1337 endfunc
1338 else
Bram Moolenaarffec3c52016-03-23 20:55:42 +01001339 let ErrorNr = 'E926'
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001340 func! ReadFunc()
Bram Moolenaarffec3c52016-03-23 20:55:42 +01001341 lolder
1342 lgetexpr []
1343 endfunc
1344 endif
1345
1346 augroup testgroup
1347 au!
Bram Moolenaard106e5b2016-04-21 19:38:07 +02001348 autocmd BufReadCmd test_changed.txt call ReadFunc()
Bram Moolenaarffec3c52016-03-23 20:55:42 +01001349 augroup END
1350
Bram Moolenaard106e5b2016-04-21 19:38:07 +02001351 new | only
Bram Moolenaarffec3c52016-03-23 20:55:42 +01001352 let words = [ "a", "b" ]
1353 let qflist = []
1354 for word in words
Bram Moolenaard106e5b2016-04-21 19:38:07 +02001355 call add(qflist, {'filename': 'test_changed.txt'})
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001356 call g:Xsetlist(qflist, ' ')
Bram Moolenaarffec3c52016-03-23 20:55:42 +01001357 endfor
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001358 call assert_fails('Xrewind', ErrorNr . ':')
Bram Moolenaarffec3c52016-03-23 20:55:42 +01001359
1360 augroup! testgroup
1361endfunc
1362
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001363func Test_quickfix_was_changed_by_autocmd()
Bram Moolenaarffec3c52016-03-23 20:55:42 +01001364 call XquickfixChangedByAutocmd('c')
1365 call XquickfixChangedByAutocmd('l')
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001366endfunc
Bram Moolenaar8b201792016-03-25 15:01:10 +01001367
1368func Test_caddbuffer_to_empty()
1369 helpgr quickfix
1370 call setqflist([], 'r')
1371 cad
Bram Moolenaarf68f1d72016-03-25 17:14:06 +01001372 try
1373 cn
1374 catch
1375 " number of matches is unknown
1376 call assert_true(v:exception =~ 'E553:')
1377 endtry
Bram Moolenaar8b201792016-03-25 15:01:10 +01001378 quit!
1379endfunc
Bram Moolenaar89c64d52016-03-27 18:44:40 +02001380
1381func Test_cgetexpr_works()
1382 " this must not crash Vim
1383 cgetexpr [$x]
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001384 lgetexpr [$x]
Bram Moolenaar89c64d52016-03-27 18:44:40 +02001385endfunc
Bram Moolenaarc1808d52016-04-18 20:04:00 +02001386
1387" Tests for the setqflist() and setloclist() functions
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001388func SetXlistTests(cchar, bnum)
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001389 call s:setup_commands(a:cchar)
Bram Moolenaarc1808d52016-04-18 20:04:00 +02001390
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001391 call g:Xsetlist([{'bufnr': a:bnum, 'lnum': 1},
Bram Moolenaarc1808d52016-04-18 20:04:00 +02001392 \ {'bufnr': a:bnum, 'lnum': 2}])
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001393 let l = g:Xgetlist()
Bram Moolenaarc1808d52016-04-18 20:04:00 +02001394 call assert_equal(2, len(l))
1395 call assert_equal(2, l[1].lnum)
1396
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001397 Xnext
1398 call g:Xsetlist([{'bufnr': a:bnum, 'lnum': 3}], 'a')
1399 let l = g:Xgetlist()
Bram Moolenaarc1808d52016-04-18 20:04:00 +02001400 call assert_equal(3, len(l))
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001401 Xnext
Bram Moolenaarc1808d52016-04-18 20:04:00 +02001402 call assert_equal(3, line('.'))
1403
Bram Moolenaar2b2b8ae2016-05-24 19:59:51 +02001404 " Appending entries to the list should not change the cursor position
1405 " in the quickfix window
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001406 Xwindow
Bram Moolenaar2b2b8ae2016-05-24 19:59:51 +02001407 1
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001408 call g:Xsetlist([{'bufnr': a:bnum, 'lnum': 4},
Bram Moolenaar2b2b8ae2016-05-24 19:59:51 +02001409 \ {'bufnr': a:bnum, 'lnum': 5}], 'a')
1410 call assert_equal(1, line('.'))
1411 close
1412
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001413 call g:Xsetlist([{'bufnr': a:bnum, 'lnum': 3},
Bram Moolenaarc1808d52016-04-18 20:04:00 +02001414 \ {'bufnr': a:bnum, 'lnum': 4},
1415 \ {'bufnr': a:bnum, 'lnum': 5}], 'r')
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001416 let l = g:Xgetlist()
Bram Moolenaarc1808d52016-04-18 20:04:00 +02001417 call assert_equal(3, len(l))
1418 call assert_equal(5, l[2].lnum)
1419
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001420 call g:Xsetlist([])
1421 let l = g:Xgetlist()
Bram Moolenaarc1808d52016-04-18 20:04:00 +02001422 call assert_equal(0, len(l))
Bram Moolenaaree85df32017-03-19 14:19:50 +01001423
Bram Moolenaarf1d21c82017-04-22 21:20:46 +02001424 " Tests for setting the 'valid' flag
1425 call g:Xsetlist([{'bufnr':a:bnum, 'lnum':4, 'valid':0}])
1426 Xwindow
1427 call assert_equal(1, winnr('$'))
1428 let l = g:Xgetlist()
1429 call g:Xsetlist(l)
1430 call assert_equal(0, g:Xgetlist()[0].valid)
Bram Moolenaar9752c722018-12-22 16:49:34 +01001431 " Adding a non-valid entry should not mark the list as having valid entries
1432 call g:Xsetlist([{'bufnr':a:bnum, 'lnum':5, 'valid':0}], 'a')
1433 Xwindow
1434 call assert_equal(1, winnr('$'))
1435
1436 " :cnext/:cprev should still work even with invalid entries in the list
1437 let l = [{'bufnr' : a:bnum, 'lnum' : 1, 'text' : '1', 'valid' : 0},
1438 \ {'bufnr' : a:bnum, 'lnum' : 2, 'text' : '2', 'valid' : 0}]
1439 call g:Xsetlist(l)
1440 Xnext
1441 call assert_equal(2, g:Xgetlist({'idx' : 0}).idx)
1442 Xprev
1443 call assert_equal(1, g:Xgetlist({'idx' : 0}).idx)
1444 " :cnext/:cprev should still work after appending invalid entries to an
1445 " empty list
1446 call g:Xsetlist([])
1447 call g:Xsetlist(l, 'a')
1448 Xnext
1449 call assert_equal(2, g:Xgetlist({'idx' : 0}).idx)
1450 Xprev
1451 call assert_equal(1, g:Xgetlist({'idx' : 0}).idx)
1452
Bram Moolenaarf1d21c82017-04-22 21:20:46 +02001453 call g:Xsetlist([{'text':'Text1', 'valid':1}])
1454 Xwindow
1455 call assert_equal(2, winnr('$'))
1456 Xclose
1457 let save_efm = &efm
1458 set efm=%m
1459 Xgetexpr 'TestMessage'
1460 let l = g:Xgetlist()
1461 call g:Xsetlist(l)
1462 call assert_equal(1, g:Xgetlist()[0].valid)
1463 let &efm = save_efm
1464
Bram Moolenaaree85df32017-03-19 14:19:50 +01001465 " Error cases:
1466 " Refer to a non-existing buffer and pass a non-dictionary type
1467 call assert_fails("call g:Xsetlist([{'bufnr':998, 'lnum':4}," .
1468 \ " {'bufnr':999, 'lnum':5}])", 'E92:')
1469 call g:Xsetlist([[1, 2,3]])
1470 call assert_equal(0, len(g:Xgetlist()))
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001471endfunc
Bram Moolenaarc1808d52016-04-18 20:04:00 +02001472
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001473func Test_setqflist()
Bram Moolenaarc1808d52016-04-18 20:04:00 +02001474 new Xtestfile | only
1475 let bnum = bufnr('%')
1476 call setline(1, range(1,5))
1477
1478 call SetXlistTests('c', bnum)
1479 call SetXlistTests('l', bnum)
1480
Bram Moolenaar1cee6932016-06-09 22:17:22 +02001481 enew!
Bram Moolenaarc1808d52016-04-18 20:04:00 +02001482 call delete('Xtestfile')
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001483endfunc
Bram Moolenaard106e5b2016-04-21 19:38:07 +02001484
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001485func Xlist_empty_middle(cchar)
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001486 call s:setup_commands(a:cchar)
1487
Bram Moolenaar1cee6932016-06-09 22:17:22 +02001488 " create three quickfix lists
Bram Moolenaaree85df32017-03-19 14:19:50 +01001489 let @/ = 'Test_'
1490 Xvimgrep // test_quickfix.vim
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001491 let testlen = len(g:Xgetlist())
Bram Moolenaar1cee6932016-06-09 22:17:22 +02001492 call assert_true(testlen > 0)
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001493 Xvimgrep empty test_quickfix.vim
1494 call assert_true(len(g:Xgetlist()) > 0)
1495 Xvimgrep matches test_quickfix.vim
1496 let matchlen = len(g:Xgetlist())
Bram Moolenaar1cee6932016-06-09 22:17:22 +02001497 call assert_true(matchlen > 0)
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001498 Xolder
Bram Moolenaar1cee6932016-06-09 22:17:22 +02001499 " make the middle list empty
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001500 call g:Xsetlist([], 'r')
1501 call assert_true(len(g:Xgetlist()) == 0)
1502 Xolder
1503 call assert_equal(testlen, len(g:Xgetlist()))
1504 Xnewer
1505 Xnewer
1506 call assert_equal(matchlen, len(g:Xgetlist()))
Bram Moolenaar1cee6932016-06-09 22:17:22 +02001507endfunc
1508
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001509func Test_setqflist_empty_middle()
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001510 call Xlist_empty_middle('c')
1511 call Xlist_empty_middle('l')
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001512endfunc
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001513
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001514func Xlist_empty_older(cchar)
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001515 call s:setup_commands(a:cchar)
1516
Bram Moolenaar1cee6932016-06-09 22:17:22 +02001517 " create three quickfix lists
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001518 Xvimgrep one test_quickfix.vim
1519 let onelen = len(g:Xgetlist())
Bram Moolenaar1cee6932016-06-09 22:17:22 +02001520 call assert_true(onelen > 0)
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001521 Xvimgrep two test_quickfix.vim
1522 let twolen = len(g:Xgetlist())
Bram Moolenaar1cee6932016-06-09 22:17:22 +02001523 call assert_true(twolen > 0)
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001524 Xvimgrep three test_quickfix.vim
1525 let threelen = len(g:Xgetlist())
Bram Moolenaar1cee6932016-06-09 22:17:22 +02001526 call assert_true(threelen > 0)
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001527 Xolder 2
Bram Moolenaar1cee6932016-06-09 22:17:22 +02001528 " make the first list empty, check the others didn't change
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001529 call g:Xsetlist([], 'r')
1530 call assert_true(len(g:Xgetlist()) == 0)
1531 Xnewer
1532 call assert_equal(twolen, len(g:Xgetlist()))
1533 Xnewer
1534 call assert_equal(threelen, len(g:Xgetlist()))
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001535endfunc
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001536
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001537func Test_setqflist_empty_older()
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001538 call Xlist_empty_older('c')
1539 call Xlist_empty_older('l')
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001540endfunc
Bram Moolenaar1cee6932016-06-09 22:17:22 +02001541
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001542func XquickfixSetListWithAct(cchar)
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001543 call s:setup_commands(a:cchar)
1544
Bram Moolenaard106e5b2016-04-21 19:38:07 +02001545 let list1 = [{'filename': 'fnameA', 'text': 'A'},
1546 \ {'filename': 'fnameB', 'text': 'B'}]
1547 let list2 = [{'filename': 'fnameC', 'text': 'C'},
1548 \ {'filename': 'fnameD', 'text': 'D'},
1549 \ {'filename': 'fnameE', 'text': 'E'}]
1550
Bram Moolenaareeb1b9c2019-02-10 22:59:04 +01001551 " {action} is unspecified. Same as specifying ' '.
Bram Moolenaard106e5b2016-04-21 19:38:07 +02001552 new | only
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001553 silent! Xnewer 99
1554 call g:Xsetlist(list1)
1555 call g:Xsetlist(list2)
1556 let li = g:Xgetlist()
Bram Moolenaard106e5b2016-04-21 19:38:07 +02001557 call assert_equal(3, len(li))
1558 call assert_equal('C', li[0]['text'])
1559 call assert_equal('D', li[1]['text'])
1560 call assert_equal('E', li[2]['text'])
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001561 silent! Xolder
1562 let li = g:Xgetlist()
Bram Moolenaard106e5b2016-04-21 19:38:07 +02001563 call assert_equal(2, len(li))
1564 call assert_equal('A', li[0]['text'])
1565 call assert_equal('B', li[1]['text'])
1566
1567 " {action} is specified ' '.
1568 new | only
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001569 silent! Xnewer 99
1570 call g:Xsetlist(list1)
1571 call g:Xsetlist(list2, ' ')
1572 let li = g:Xgetlist()
Bram Moolenaard106e5b2016-04-21 19:38:07 +02001573 call assert_equal(3, len(li))
1574 call assert_equal('C', li[0]['text'])
1575 call assert_equal('D', li[1]['text'])
1576 call assert_equal('E', li[2]['text'])
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001577 silent! Xolder
1578 let li = g:Xgetlist()
Bram Moolenaard106e5b2016-04-21 19:38:07 +02001579 call assert_equal(2, len(li))
1580 call assert_equal('A', li[0]['text'])
1581 call assert_equal('B', li[1]['text'])
1582
1583 " {action} is specified 'a'.
1584 new | only
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001585 silent! Xnewer 99
1586 call g:Xsetlist(list1)
1587 call g:Xsetlist(list2, 'a')
1588 let li = g:Xgetlist()
Bram Moolenaard106e5b2016-04-21 19:38:07 +02001589 call assert_equal(5, len(li))
1590 call assert_equal('A', li[0]['text'])
1591 call assert_equal('B', li[1]['text'])
1592 call assert_equal('C', li[2]['text'])
1593 call assert_equal('D', li[3]['text'])
1594 call assert_equal('E', li[4]['text'])
1595
1596 " {action} is specified 'r'.
1597 new | only
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001598 silent! Xnewer 99
1599 call g:Xsetlist(list1)
1600 call g:Xsetlist(list2, 'r')
1601 let li = g:Xgetlist()
Bram Moolenaard106e5b2016-04-21 19:38:07 +02001602 call assert_equal(3, len(li))
1603 call assert_equal('C', li[0]['text'])
1604 call assert_equal('D', li[1]['text'])
1605 call assert_equal('E', li[2]['text'])
1606
1607 " Test for wrong value.
1608 new | only
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001609 call assert_fails("call g:Xsetlist(0)", 'E714:')
1610 call assert_fails("call g:Xsetlist(list1, '')", 'E927:')
1611 call assert_fails("call g:Xsetlist(list1, 'aa')", 'E927:')
1612 call assert_fails("call g:Xsetlist(list1, ' a')", 'E927:')
1613 call assert_fails("call g:Xsetlist(list1, 0)", 'E928:')
Bram Moolenaard106e5b2016-04-21 19:38:07 +02001614endfunc
1615
Bram Moolenaara0ca7d02017-12-19 10:22:19 +01001616func Test_setqflist_invalid_nr()
1617 " The following command used to crash Vim
Bram Moolenaaraad222c2019-09-06 22:46:09 +02001618 eval []->setqflist(' ', {'nr' : $XXX_DOES_NOT_EXIST})
Bram Moolenaara0ca7d02017-12-19 10:22:19 +01001619endfunc
1620
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001621func Test_quickfix_set_list_with_act()
Bram Moolenaard106e5b2016-04-21 19:38:07 +02001622 call XquickfixSetListWithAct('c')
1623 call XquickfixSetListWithAct('l')
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001624endfunc
Bram Moolenaar6be8c8e2016-04-30 13:17:09 +02001625
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001626func XLongLinesTests(cchar)
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001627 let l = g:Xgetlist()
Bram Moolenaar6be8c8e2016-04-30 13:17:09 +02001628
Bram Moolenaar049cba92016-06-26 14:38:04 +02001629 call assert_equal(4, len(l))
Bram Moolenaar6be8c8e2016-04-30 13:17:09 +02001630 call assert_equal(1, l[0].lnum)
1631 call assert_equal(1, l[0].col)
Bram Moolenaar049cba92016-06-26 14:38:04 +02001632 call assert_equal(1975, len(l[0].text))
Bram Moolenaar6be8c8e2016-04-30 13:17:09 +02001633 call assert_equal(2, l[1].lnum)
1634 call assert_equal(1, l[1].col)
1635 call assert_equal(4070, len(l[1].text))
1636 call assert_equal(3, l[2].lnum)
1637 call assert_equal(1, l[2].col)
Bram Moolenaar049cba92016-06-26 14:38:04 +02001638 call assert_equal(4070, len(l[2].text))
1639 call assert_equal(4, l[3].lnum)
1640 call assert_equal(1, l[3].col)
1641 call assert_equal(10, len(l[3].text))
Bram Moolenaar6be8c8e2016-04-30 13:17:09 +02001642
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001643 call g:Xsetlist([], 'r')
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001644endfunc
Bram Moolenaar6be8c8e2016-04-30 13:17:09 +02001645
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001646func s:long_lines_tests(cchar)
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001647 call s:setup_commands(a:cchar)
1648
Bram Moolenaar6be8c8e2016-04-30 13:17:09 +02001649 let testfile = 'samples/quickfix.txt'
1650
1651 " file
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001652 exe 'Xgetfile' testfile
1653 call XLongLinesTests(a:cchar)
Bram Moolenaar6be8c8e2016-04-30 13:17:09 +02001654
1655 " list
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001656 Xexpr readfile(testfile)
1657 call XLongLinesTests(a:cchar)
Bram Moolenaar6be8c8e2016-04-30 13:17:09 +02001658
1659 " string
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001660 Xexpr join(readfile(testfile), "\n")
1661 call XLongLinesTests(a:cchar)
Bram Moolenaar6be8c8e2016-04-30 13:17:09 +02001662
1663 " buffer
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001664 exe 'edit' testfile
1665 exe 'Xbuffer' bufnr('%')
Bram Moolenaarf50df392016-06-21 21:33:34 +02001666 call XLongLinesTests(a:cchar)
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001667endfunc
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001668
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001669func Test_long_lines()
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001670 call s:long_lines_tests('c')
1671 call s:long_lines_tests('l')
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001672endfunc
Bram Moolenaar049cba92016-06-26 14:38:04 +02001673
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001674func s:create_test_file(filename)
Bram Moolenaar049cba92016-06-26 14:38:04 +02001675 let l = []
1676 for i in range(1, 20)
1677 call add(l, 'Line' . i)
1678 endfor
1679 call writefile(l, a:filename)
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001680endfunc
Bram Moolenaar049cba92016-06-26 14:38:04 +02001681
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001682func Test_switchbuf()
Bram Moolenaar049cba92016-06-26 14:38:04 +02001683 call s:create_test_file('Xqftestfile1')
1684 call s:create_test_file('Xqftestfile2')
1685 call s:create_test_file('Xqftestfile3')
1686
1687 new | only
1688 edit Xqftestfile1
1689 let file1_winid = win_getid()
1690 new Xqftestfile2
1691 let file2_winid = win_getid()
1692 cgetexpr ['Xqftestfile1:5:Line5',
1693 \ 'Xqftestfile1:6:Line6',
1694 \ 'Xqftestfile2:10:Line10',
1695 \ 'Xqftestfile2:11:Line11',
1696 \ 'Xqftestfile3:15:Line15',
1697 \ 'Xqftestfile3:16:Line16']
1698
1699 new
1700 let winid = win_getid()
1701 cfirst | cnext
1702 call assert_equal(winid, win_getid())
Bram Moolenaar99895ea2017-04-20 22:44:47 +02001703 2cnext
Bram Moolenaar049cba92016-06-26 14:38:04 +02001704 call assert_equal(winid, win_getid())
Bram Moolenaar99895ea2017-04-20 22:44:47 +02001705 2cnext
Bram Moolenaar049cba92016-06-26 14:38:04 +02001706 call assert_equal(winid, win_getid())
Bram Moolenaar049cba92016-06-26 14:38:04 +02001707
Bram Moolenaarf9ae1542019-11-18 22:02:16 +01001708 " Test for 'switchbuf' set to search for files in windows in the current
1709 " tabpage and jump to an existing window (if present)
Bram Moolenaar049cba92016-06-26 14:38:04 +02001710 set switchbuf=useopen
Bram Moolenaarf9ae1542019-11-18 22:02:16 +01001711 enew
Bram Moolenaar049cba92016-06-26 14:38:04 +02001712 cfirst | cnext
1713 call assert_equal(file1_winid, win_getid())
Bram Moolenaar99895ea2017-04-20 22:44:47 +02001714 2cnext
Bram Moolenaar049cba92016-06-26 14:38:04 +02001715 call assert_equal(file2_winid, win_getid())
Bram Moolenaar99895ea2017-04-20 22:44:47 +02001716 2cnext
Bram Moolenaar049cba92016-06-26 14:38:04 +02001717 call assert_equal(file2_winid, win_getid())
1718
Bram Moolenaarf9ae1542019-11-18 22:02:16 +01001719 " Test for 'switchbuf' set to search for files in tabpages and jump to an
1720 " existing tabpage (if present)
Bram Moolenaar049cba92016-06-26 14:38:04 +02001721 enew | only
1722 set switchbuf=usetab
1723 tabedit Xqftestfile1
1724 tabedit Xqftestfile2
Bram Moolenaar74240d32017-12-10 15:26:15 +01001725 tabedit Xqftestfile3
Bram Moolenaar049cba92016-06-26 14:38:04 +02001726 tabfirst
1727 cfirst | cnext
1728 call assert_equal(2, tabpagenr())
Bram Moolenaar99895ea2017-04-20 22:44:47 +02001729 2cnext
Bram Moolenaar049cba92016-06-26 14:38:04 +02001730 call assert_equal(3, tabpagenr())
Bram Moolenaar74240d32017-12-10 15:26:15 +01001731 6cnext
1732 call assert_equal(4, tabpagenr())
1733 2cpfile
1734 call assert_equal(2, tabpagenr())
1735 2cnfile
1736 call assert_equal(4, tabpagenr())
Bram Moolenaar049cba92016-06-26 14:38:04 +02001737 tabfirst | tabonly | enew
1738
Bram Moolenaarf9ae1542019-11-18 22:02:16 +01001739 " Test for 'switchbuf' set to open a new window for every file
Bram Moolenaar049cba92016-06-26 14:38:04 +02001740 set switchbuf=split
1741 cfirst | cnext
1742 call assert_equal(1, winnr('$'))
1743 cnext | cnext
1744 call assert_equal(2, winnr('$'))
1745 cnext | cnext
1746 call assert_equal(3, winnr('$'))
Bram Moolenaar049cba92016-06-26 14:38:04 +02001747
Bram Moolenaarf9ae1542019-11-18 22:02:16 +01001748 " Test for 'switchbuf' set to open a new tabpage for every file
Bram Moolenaar049cba92016-06-26 14:38:04 +02001749 set switchbuf=newtab
Bram Moolenaarf9ae1542019-11-18 22:02:16 +01001750 enew | only
Bram Moolenaar049cba92016-06-26 14:38:04 +02001751 cfirst | cnext
1752 call assert_equal(1, tabpagenr('$'))
1753 cnext | cnext
1754 call assert_equal(2, tabpagenr('$'))
1755 cnext | cnext
1756 call assert_equal(3, tabpagenr('$'))
1757 tabfirst | enew | tabonly | only
1758
Bram Moolenaar539aa6b2019-11-17 18:09:38 +01001759 set switchbuf=uselast
1760 split
1761 let last_winid = win_getid()
1762 copen
1763 exe "normal 1G\<CR>"
1764 call assert_equal(last_winid, win_getid())
1765 enew | only
1766
Bram Moolenaarf9ae1542019-11-18 22:02:16 +01001767 " With an empty 'switchbuf', jumping to a quickfix entry should open the
1768 " file in an existing window (if present)
Bram Moolenaar049cba92016-06-26 14:38:04 +02001769 set switchbuf=
1770 edit Xqftestfile1
1771 let file1_winid = win_getid()
1772 new Xqftestfile2
1773 let file2_winid = win_getid()
1774 copen
1775 exe "normal 1G\<CR>"
1776 call assert_equal(file1_winid, win_getid())
1777 copen
1778 exe "normal 3G\<CR>"
1779 call assert_equal(file2_winid, win_getid())
1780 copen | only
1781 exe "normal 5G\<CR>"
1782 call assert_equal(2, winnr('$'))
1783 call assert_equal(1, bufwinnr('Xqftestfile3'))
1784
Bram Moolenaar391b1dd2017-03-04 13:47:11 +01001785 " If only quickfix window is open in the current tabpage, jumping to an
Bram Moolenaar1bc353b2019-09-01 14:45:28 +02001786 " entry with 'switchbuf' set to 'usetab' should search in other tabpages.
Bram Moolenaar049cba92016-06-26 14:38:04 +02001787 enew | only
Bram Moolenaar391b1dd2017-03-04 13:47:11 +01001788 set switchbuf=usetab
1789 tabedit Xqftestfile1
1790 tabedit Xqftestfile2
1791 tabedit Xqftestfile3
1792 tabfirst
1793 copen | only
1794 clast
1795 call assert_equal(4, tabpagenr())
1796 tabfirst | tabonly | enew | only
Bram Moolenaar049cba92016-06-26 14:38:04 +02001797
Bram Moolenaarf9ae1542019-11-18 22:02:16 +01001798 " Jumping to a file that is not present in any of the tabpages and the
1799 " current tabpage doesn't have any usable windows, should open it in a new
1800 " window in the current tabpage.
1801 copen | only
1802 cfirst
1803 call assert_equal(1, tabpagenr())
1804 call assert_equal('Xqftestfile1', bufname(''))
1805
1806 " If opening a file changes 'switchbuf', then the new value should be
1807 " retained.
1808 call writefile(["vim: switchbuf=split"], 'Xqftestfile1')
1809 enew | only
1810 set switchbuf&vim
1811 cexpr "Xqftestfile1:1:10"
1812 call assert_equal('split', &switchbuf)
1813 call writefile(["vim: switchbuf=usetab"], 'Xqftestfile1')
1814 enew | only
1815 set switchbuf=useopen
1816 cexpr "Xqftestfile1:1:10"
1817 call assert_equal('usetab', &switchbuf)
1818 call writefile(["vim: switchbuf&vim"], 'Xqftestfile1')
1819 enew | only
1820 set switchbuf=useopen
1821 cexpr "Xqftestfile1:1:10"
1822 call assert_equal('', &switchbuf)
1823
Bram Moolenaar049cba92016-06-26 14:38:04 +02001824 call delete('Xqftestfile1')
1825 call delete('Xqftestfile2')
1826 call delete('Xqftestfile3')
Bram Moolenaar391b1dd2017-03-04 13:47:11 +01001827 set switchbuf&vim
1828
1829 enew | only
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001830endfunc
Bram Moolenaar049cba92016-06-26 14:38:04 +02001831
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001832func Xadjust_qflnum(cchar)
Bram Moolenaar049cba92016-06-26 14:38:04 +02001833 call s:setup_commands(a:cchar)
1834
1835 enew | only
1836
Bram Moolenaarc1542742016-07-20 21:44:37 +02001837 let fname = 'Xqftestfile' . a:cchar
1838 call s:create_test_file(fname)
1839 exe 'edit ' . fname
Bram Moolenaar049cba92016-06-26 14:38:04 +02001840
Bram Moolenaarc1542742016-07-20 21:44:37 +02001841 Xgetexpr [fname . ':5:Line5',
1842 \ fname . ':10:Line10',
1843 \ fname . ':15:Line15',
1844 \ fname . ':20:Line20']
Bram Moolenaar049cba92016-06-26 14:38:04 +02001845
1846 6,14delete
1847 call append(6, ['Buffer', 'Window'])
1848
1849 let l = g:Xgetlist()
Bram Moolenaar049cba92016-06-26 14:38:04 +02001850 call assert_equal(5, l[0].lnum)
1851 call assert_equal(6, l[2].lnum)
1852 call assert_equal(13, l[3].lnum)
1853
Bram Moolenaarf9ae1542019-11-18 22:02:16 +01001854 " If a file doesn't have any quickfix entries, then deleting lines in the
1855 " file should not update the quickfix list
1856 call g:Xsetlist([], 'f')
1857 1,2delete
1858 call assert_equal([], g:Xgetlist())
1859
Bram Moolenaar049cba92016-06-26 14:38:04 +02001860 enew!
Bram Moolenaarc1542742016-07-20 21:44:37 +02001861 call delete(fname)
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001862endfunc
Bram Moolenaar049cba92016-06-26 14:38:04 +02001863
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001864func Test_adjust_lnum()
Bram Moolenaarc1542742016-07-20 21:44:37 +02001865 call setloclist(0, [])
Bram Moolenaar049cba92016-06-26 14:38:04 +02001866 call Xadjust_qflnum('c')
Bram Moolenaarc1542742016-07-20 21:44:37 +02001867 call setqflist([])
Bram Moolenaar049cba92016-06-26 14:38:04 +02001868 call Xadjust_qflnum('l')
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001869endfunc
Bram Moolenaar049cba92016-06-26 14:38:04 +02001870
1871" Tests for the :grep/:lgrep and :grepadd/:lgrepadd commands
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001872func s:test_xgrep(cchar)
Bram Moolenaar049cba92016-06-26 14:38:04 +02001873 call s:setup_commands(a:cchar)
1874
1875 " The following lines are used for the grep test. Don't remove.
1876 " Grep_Test_Text: Match 1
1877 " Grep_Test_Text: Match 2
1878 " GrepAdd_Test_Text: Match 1
1879 " GrepAdd_Test_Text: Match 2
1880 enew! | only
1881 set makeef&vim
1882 silent Xgrep Grep_Test_Text: test_quickfix.vim
Bram Moolenaarf9ae1542019-11-18 22:02:16 +01001883 call assert_true(len(g:Xgetlist()) == 4)
Bram Moolenaar049cba92016-06-26 14:38:04 +02001884 Xopen
1885 call assert_true(w:quickfix_title =~ '^:grep')
1886 Xclose
1887 enew
1888 set makeef=Temp_File_##
1889 silent Xgrepadd GrepAdd_Test_Text: test_quickfix.vim
Bram Moolenaarf9ae1542019-11-18 22:02:16 +01001890 call assert_true(len(g:Xgetlist()) == 7)
1891
1892 call writefile(['Vim'], 'XtestTempFile')
1893 set makeef=XtestTempFile
1894 silent Xgrep Grep_Test_Text: test_quickfix.vim
1895 call assert_equal(4, len(g:Xgetlist()))
1896 call assert_false(filereadable('XtestTempFile'))
1897 set makeef&vim
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001898endfunc
Bram Moolenaar049cba92016-06-26 14:38:04 +02001899
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001900func Test_grep()
Bram Moolenaar049cba92016-06-26 14:38:04 +02001901 if !has('unix')
1902 " The grepprg may not be set on non-Unix systems
1903 return
1904 endif
1905
1906 call s:test_xgrep('c')
1907 call s:test_xgrep('l')
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001908endfunc
Bram Moolenaar361c8f02016-07-02 15:41:47 +02001909
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001910func Test_two_windows()
Bram Moolenaar361c8f02016-07-02 15:41:47 +02001911 " Use one 'errorformat' for two windows. Add an expression to each of them,
1912 " make sure they each keep their own state.
1913 set efm=%DEntering\ dir\ '%f',%f:%l:%m,%XLeaving\ dir\ '%f'
1914 call mkdir('Xone/a', 'p')
1915 call mkdir('Xtwo/a', 'p')
1916 let lines = ['1', '2', 'one one one', '4', 'two two two', '6', '7']
1917 call writefile(lines, 'Xone/a/one.txt')
1918 call writefile(lines, 'Xtwo/a/two.txt')
1919
1920 new one
1921 let one_id = win_getid()
1922 lexpr ""
1923 new two
1924 let two_id = win_getid()
1925 lexpr ""
1926
1927 laddexpr "Entering dir 'Xtwo/a'"
1928 call win_gotoid(one_id)
1929 laddexpr "Entering dir 'Xone/a'"
1930 call win_gotoid(two_id)
1931 laddexpr 'two.txt:5:two two two'
1932 call win_gotoid(one_id)
1933 laddexpr 'one.txt:3:one one one'
1934
1935 let loc_one = getloclist(one_id)
Bram Moolenaar361c8f02016-07-02 15:41:47 +02001936 call assert_equal('Xone/a/one.txt', bufname(loc_one[1].bufnr))
1937 call assert_equal(3, loc_one[1].lnum)
1938
1939 let loc_two = getloclist(two_id)
Bram Moolenaar361c8f02016-07-02 15:41:47 +02001940 call assert_equal('Xtwo/a/two.txt', bufname(loc_two[1].bufnr))
1941 call assert_equal(5, loc_two[1].lnum)
1942
1943 call win_gotoid(one_id)
1944 bwipe!
1945 call win_gotoid(two_id)
1946 bwipe!
1947 call delete('Xone', 'rf')
1948 call delete('Xtwo', 'rf')
1949endfunc
Bram Moolenaardcb17002016-07-07 18:58:59 +02001950
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001951func XbottomTests(cchar)
Bram Moolenaar537ef082016-07-09 17:56:19 +02001952 call s:setup_commands(a:cchar)
1953
Bram Moolenaarb6fa30c2017-03-29 14:19:25 +02001954 " Calling lbottom without any errors should fail
1955 if a:cchar == 'l'
1956 call assert_fails('lbottom', 'E776:')
1957 endif
1958
Bram Moolenaar875feea2017-06-11 16:07:51 +02001959 call g:Xsetlist([{'filename': 'foo', 'lnum': 42}])
Bram Moolenaar537ef082016-07-09 17:56:19 +02001960 Xopen
Bram Moolenaardcb17002016-07-07 18:58:59 +02001961 let wid = win_getid()
1962 call assert_equal(1, line('.'))
1963 wincmd w
Bram Moolenaar875feea2017-06-11 16:07:51 +02001964 call g:Xsetlist([{'filename': 'var', 'lnum': 24}], 'a')
Bram Moolenaar537ef082016-07-09 17:56:19 +02001965 Xbottom
Bram Moolenaardcb17002016-07-07 18:58:59 +02001966 call win_gotoid(wid)
1967 call assert_equal(2, line('.'))
Bram Moolenaar537ef082016-07-09 17:56:19 +02001968 Xclose
Bram Moolenaardcb17002016-07-07 18:58:59 +02001969endfunc
Bram Moolenaar537ef082016-07-09 17:56:19 +02001970
1971" Tests for the :cbottom and :lbottom commands
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001972func Test_cbottom()
Bram Moolenaar537ef082016-07-09 17:56:19 +02001973 call XbottomTests('c')
1974 call XbottomTests('l')
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001975endfunc
Bram Moolenaarf6acffb2016-07-16 16:54:24 +02001976
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001977func HistoryTest(cchar)
Bram Moolenaarf6acffb2016-07-16 16:54:24 +02001978 call s:setup_commands(a:cchar)
1979
Bram Moolenaarf6acffb2016-07-16 16:54:24 +02001980 " clear all lists after the first one, then replace the first one.
1981 call g:Xsetlist([])
Bram Moolenaarb6fa30c2017-03-29 14:19:25 +02001982 call assert_fails('Xolder 99', 'E380:')
Bram Moolenaarf6acffb2016-07-16 16:54:24 +02001983 let entry = {'filename': 'foo', 'lnum': 42}
1984 call g:Xsetlist([entry], 'r')
1985 call g:Xsetlist([entry, entry])
1986 call g:Xsetlist([entry, entry, entry])
1987 let res = split(execute(a:cchar . 'hist'), "\n")
1988 call assert_equal(3, len(res))
1989 let common = 'errors :set' . (a:cchar == 'c' ? 'qf' : 'loc') . 'list()'
1990 call assert_equal(' error list 1 of 3; 1 ' . common, res[0])
1991 call assert_equal(' error list 2 of 3; 2 ' . common, res[1])
1992 call assert_equal('> error list 3 of 3; 3 ' . common, res[2])
Bram Moolenaarb4d5fba2017-09-11 19:31:28 +02001993
Bram Moolenaar8ffc7c82019-05-05 21:00:26 +02001994 " Test for changing the quickfix lists
1995 call assert_equal(3, g:Xgetlist({'nr' : 0}).nr)
1996 exe '1' . a:cchar . 'hist'
1997 call assert_equal(1, g:Xgetlist({'nr' : 0}).nr)
1998 exe '3' . a:cchar . 'hist'
1999 call assert_equal(3, g:Xgetlist({'nr' : 0}).nr)
2000 call assert_fails('-2' . a:cchar . 'hist', 'E16:')
2001 call assert_fails('4' . a:cchar . 'hist', 'E16:')
2002
Bram Moolenaarb4d5fba2017-09-11 19:31:28 +02002003 call g:Xsetlist([], 'f')
2004 let l = split(execute(a:cchar . 'hist'), "\n")
2005 call assert_equal('No entries', l[0])
Bram Moolenaar8ffc7c82019-05-05 21:00:26 +02002006 if a:cchar == 'c'
2007 call assert_fails('4chist', 'E16:')
2008 else
2009 call assert_fails('4lhist', 'E776:')
2010 endif
Bram Moolenaar5b69c222019-01-11 14:50:06 +01002011
2012 " An empty list should still show the stack history
2013 call g:Xsetlist([])
2014 let res = split(execute(a:cchar . 'hist'), "\n")
2015 call assert_equal('> error list 1 of 1; 0 ' . common, res[0])
2016
2017 call g:Xsetlist([], 'f')
Bram Moolenaarf6acffb2016-07-16 16:54:24 +02002018endfunc
2019
2020func Test_history()
2021 call HistoryTest('c')
2022 call HistoryTest('l')
2023endfunc
Bram Moolenaar015102e2016-07-16 18:24:56 +02002024
2025func Test_duplicate_buf()
2026 " make sure we can get the highest buffer number
2027 edit DoesNotExist
2028 edit DoesNotExist2
2029 let last_buffer = bufnr("$")
2030
2031 " make sure only one buffer is created
2032 call writefile(['this one', 'that one'], 'Xgrepthis')
2033 vimgrep one Xgrepthis
2034 vimgrep one Xgrepthis
2035 call assert_equal(last_buffer + 1, bufnr("$"))
2036
2037 call delete('Xgrepthis')
2038endfunc
Bram Moolenaard823fa92016-08-12 16:29:27 +02002039
2040" Quickfix/Location list set/get properties tests
Bram Moolenaar2b946c92016-11-12 18:14:44 +01002041func Xproperty_tests(cchar)
Bram Moolenaard823fa92016-08-12 16:29:27 +02002042 call s:setup_commands(a:cchar)
2043
2044 " Error cases
2045 call assert_fails('call g:Xgetlist(99)', 'E715:')
2046 call assert_fails('call g:Xsetlist(99)', 'E714:')
2047 call assert_fails('call g:Xsetlist([], "a", [])', 'E715:')
2048
2049 " Set and get the title
Bram Moolenaarb6fa30c2017-03-29 14:19:25 +02002050 call g:Xsetlist([])
Bram Moolenaard823fa92016-08-12 16:29:27 +02002051 Xopen
2052 wincmd p
2053 call g:Xsetlist([{'filename':'foo', 'lnum':27}])
Bram Moolenaar86f100dc2017-06-28 21:26:27 +02002054 let s = g:Xsetlist([], 'a', {'title' : 'Sample'})
2055 call assert_equal(0, s)
Bram Moolenaard823fa92016-08-12 16:29:27 +02002056 let d = g:Xgetlist({"title":1})
2057 call assert_equal('Sample', d.title)
Bram Moolenaara2aa8a22018-04-24 13:55:00 +02002058 " Try setting title to a non-string value
2059 call assert_equal(-1, g:Xsetlist([], 'a', {'title' : ['Test']}))
2060 call assert_equal('Sample', g:Xgetlist({"title":1}).title)
Bram Moolenaard823fa92016-08-12 16:29:27 +02002061
2062 Xopen
2063 call assert_equal('Sample', w:quickfix_title)
2064 Xclose
2065
Bram Moolenaar2b529bb2016-08-27 13:35:35 +02002066 " Tests for action argument
2067 silent! Xolder 999
2068 let qfnr = g:Xgetlist({'all':1}).nr
2069 call g:Xsetlist([], 'r', {'title' : 'N1'})
2070 call assert_equal('N1', g:Xgetlist({'all':1}).title)
2071 call g:Xsetlist([], ' ', {'title' : 'N2'})
2072 call assert_equal(qfnr + 1, g:Xgetlist({'all':1}).nr)
Bram Moolenaar890680c2016-09-27 21:28:56 +02002073
2074 let res = g:Xgetlist({'nr': 0})
2075 call assert_equal(qfnr + 1, res.nr)
2076 call assert_equal(['nr'], keys(res))
2077
Bram Moolenaar2b529bb2016-08-27 13:35:35 +02002078 call g:Xsetlist([], ' ', {'title' : 'N3'})
2079 call assert_equal('N2', g:Xgetlist({'nr':2, 'title':1}).title)
2080
Bram Moolenaaree85df32017-03-19 14:19:50 +01002081 " Changing the title of an earlier quickfix list
Bram Moolenaar55b69262017-08-13 13:42:01 +02002082 call g:Xsetlist([], 'r', {'title' : 'NewTitle', 'nr' : 2})
Bram Moolenaaree85df32017-03-19 14:19:50 +01002083 call assert_equal('NewTitle', g:Xgetlist({'nr':2, 'title':1}).title)
2084
2085 " Changing the title of an invalid quickfix list
2086 call assert_equal(-1, g:Xsetlist([], ' ',
2087 \ {'title' : 'SomeTitle', 'nr' : 99}))
2088 call assert_equal(-1, g:Xsetlist([], ' ',
2089 \ {'title' : 'SomeTitle', 'nr' : 'abc'}))
2090
2091 if a:cchar == 'c'
2092 copen
2093 call assert_equal({'winid':win_getid()}, getqflist({'winid':1}))
2094 cclose
2095 endif
2096
Bram Moolenaard823fa92016-08-12 16:29:27 +02002097 " Invalid arguments
2098 call assert_fails('call g:Xgetlist([])', 'E715')
2099 call assert_fails('call g:Xsetlist([], "a", [])', 'E715')
2100 let s = g:Xsetlist([], 'a', {'abc':1})
2101 call assert_equal(-1, s)
2102
2103 call assert_equal({}, g:Xgetlist({'abc':1}))
Bram Moolenaara6d48492017-12-12 22:45:31 +01002104 call assert_equal('', g:Xgetlist({'nr':99, 'title':1}).title)
2105 call assert_equal('', g:Xgetlist({'nr':[], 'title':1}).title)
Bram Moolenaard823fa92016-08-12 16:29:27 +02002106
2107 if a:cchar == 'l'
Bram Moolenaar890680c2016-09-27 21:28:56 +02002108 call assert_equal({}, getloclist(99, {'title': 1}))
Bram Moolenaard823fa92016-08-12 16:29:27 +02002109 endif
Bram Moolenaar8f77c5a2017-04-30 14:21:00 +02002110
2111 " Context related tests
Bram Moolenaar86f100dc2017-06-28 21:26:27 +02002112 let s = g:Xsetlist([], 'a', {'context':[1,2,3]})
2113 call assert_equal(0, s)
Bram Moolenaar8f77c5a2017-04-30 14:21:00 +02002114 call test_garbagecollect_now()
2115 let d = g:Xgetlist({'context':1})
2116 call assert_equal([1,2,3], d.context)
2117 call g:Xsetlist([], 'a', {'context':{'color':'green'}})
2118 let d = g:Xgetlist({'context':1})
2119 call assert_equal({'color':'green'}, d.context)
2120 call g:Xsetlist([], 'a', {'context':"Context info"})
2121 let d = g:Xgetlist({'context':1})
2122 call assert_equal("Context info", d.context)
2123 call g:Xsetlist([], 'a', {'context':246})
2124 let d = g:Xgetlist({'context':1})
2125 call assert_equal(246, d.context)
2126 if a:cchar == 'l'
2127 " Test for copying context across two different location lists
2128 new | only
2129 let w1_id = win_getid()
2130 let l = [1]
2131 call setloclist(0, [], 'a', {'context':l})
2132 new
2133 let w2_id = win_getid()
2134 call add(l, 2)
2135 call assert_equal([1, 2], getloclist(w1_id, {'context':1}).context)
2136 call assert_equal([1, 2], getloclist(w2_id, {'context':1}).context)
2137 unlet! l
2138 call assert_equal([1, 2], getloclist(w2_id, {'context':1}).context)
2139 only
2140 call setloclist(0, [], 'f')
Bram Moolenaara6d48492017-12-12 22:45:31 +01002141 call assert_equal('', getloclist(0, {'context':1}).context)
Bram Moolenaar8f77c5a2017-04-30 14:21:00 +02002142 endif
Bram Moolenaar6e62da32017-05-28 08:16:25 +02002143
2144 " Test for changing the context of previous quickfix lists
2145 call g:Xsetlist([], 'f')
2146 Xexpr "One"
2147 Xexpr "Two"
2148 Xexpr "Three"
Bram Moolenaar55b69262017-08-13 13:42:01 +02002149 call g:Xsetlist([], 'r', {'context' : [1], 'nr' : 1})
2150 call g:Xsetlist([], 'a', {'context' : [2], 'nr' : 2})
Bram Moolenaar6e62da32017-05-28 08:16:25 +02002151 " Also, check for setting the context using quickfix list number zero.
Bram Moolenaar55b69262017-08-13 13:42:01 +02002152 call g:Xsetlist([], 'r', {'context' : [3], 'nr' : 0})
Bram Moolenaar6e62da32017-05-28 08:16:25 +02002153 call test_garbagecollect_now()
2154 let l = g:Xgetlist({'nr' : 1, 'context' : 1})
2155 call assert_equal([1], l.context)
2156 let l = g:Xgetlist({'nr' : 2, 'context' : 1})
2157 call assert_equal([2], l.context)
2158 let l = g:Xgetlist({'nr' : 3, 'context' : 1})
2159 call assert_equal([3], l.context)
2160
2161 " Test for changing the context through reference and for garbage
2162 " collection of quickfix context
2163 let l = ["red"]
2164 call g:Xsetlist([], ' ', {'context' : l})
2165 call add(l, "blue")
2166 let x = g:Xgetlist({'context' : 1})
2167 call add(x.context, "green")
2168 call assert_equal(["red", "blue", "green"], l)
2169 call assert_equal(["red", "blue", "green"], x.context)
2170 unlet l
2171 call test_garbagecollect_now()
2172 let m = g:Xgetlist({'context' : 1})
2173 call assert_equal(["red", "blue", "green"], m.context)
Bram Moolenaar6a8958d2017-06-22 21:33:20 +02002174
2175 " Test for setting/getting items
2176 Xexpr ""
2177 let qfprev = g:Xgetlist({'nr':0})
Bram Moolenaar86f100dc2017-06-28 21:26:27 +02002178 let s = g:Xsetlist([], ' ', {'title':'Green',
Bram Moolenaar6a8958d2017-06-22 21:33:20 +02002179 \ 'items' : [{'filename':'F1', 'lnum':10}]})
Bram Moolenaar86f100dc2017-06-28 21:26:27 +02002180 call assert_equal(0, s)
Bram Moolenaar6a8958d2017-06-22 21:33:20 +02002181 let qfcur = g:Xgetlist({'nr':0})
2182 call assert_true(qfcur.nr == qfprev.nr + 1)
2183 let l = g:Xgetlist({'items':1})
2184 call assert_equal('F1', bufname(l.items[0].bufnr))
2185 call assert_equal(10, l.items[0].lnum)
2186 call g:Xsetlist([], 'a', {'items' : [{'filename':'F2', 'lnum':20},
2187 \ {'filename':'F2', 'lnum':30}]})
2188 let l = g:Xgetlist({'items':1})
2189 call assert_equal('F2', bufname(l.items[2].bufnr))
2190 call assert_equal(30, l.items[2].lnum)
2191 call g:Xsetlist([], 'r', {'items' : [{'filename':'F3', 'lnum':40}]})
2192 let l = g:Xgetlist({'items':1})
2193 call assert_equal('F3', bufname(l.items[0].bufnr))
2194 call assert_equal(40, l.items[0].lnum)
2195 call g:Xsetlist([], 'r', {'items' : []})
2196 let l = g:Xgetlist({'items':1})
2197 call assert_equal(0, len(l.items))
2198
Bram Moolenaarb4d5fba2017-09-11 19:31:28 +02002199 call g:Xsetlist([], 'r', {'title' : 'TestTitle'})
2200 call g:Xsetlist([], 'r', {'items' : [{'filename' : 'F1', 'lnum' : 10, 'text' : 'L10'}]})
2201 call g:Xsetlist([], 'r', {'items' : [{'filename' : 'F1', 'lnum' : 10, 'text' : 'L10'}]})
2202 call assert_equal('TestTitle', g:Xgetlist({'title' : 1}).title)
2203
Bram Moolenaarc9cc9c72018-09-02 15:18:42 +02002204 " Test for getting id of window associated with a location list window
2205 if a:cchar == 'l'
2206 only
2207 call assert_equal(0, g:Xgetlist({'all' : 1}).filewinid)
2208 let wid = win_getid()
2209 Xopen
2210 call assert_equal(wid, g:Xgetlist({'filewinid' : 1}).filewinid)
2211 wincmd w
2212 call assert_equal(0, g:Xgetlist({'filewinid' : 1}).filewinid)
2213 only
2214 endif
2215
Bram Moolenaarae338332017-08-11 20:25:26 +02002216 " The following used to crash Vim with address sanitizer
2217 call g:Xsetlist([], 'f')
2218 call g:Xsetlist([], 'a', {'items' : [{'filename':'F1', 'lnum':10}]})
2219 call assert_equal(10, g:Xgetlist({'items':1}).items[0].lnum)
2220
Bram Moolenaara2aa8a22018-04-24 13:55:00 +02002221 " Try setting the items using a string
2222 call assert_equal(-1, g:Xsetlist([], ' ', {'items' : 'Test'}))
2223
Bram Moolenaar6a8958d2017-06-22 21:33:20 +02002224 " Save and restore the quickfix stack
2225 call g:Xsetlist([], 'f')
2226 call assert_equal(0, g:Xgetlist({'nr':'$'}).nr)
2227 Xexpr "File1:10:Line1"
2228 Xexpr "File2:20:Line2"
2229 Xexpr "File3:30:Line3"
2230 let last_qf = g:Xgetlist({'nr':'$'}).nr
2231 call assert_equal(3, last_qf)
2232 let qstack = []
2233 for i in range(1, last_qf)
2234 let qstack = add(qstack, g:Xgetlist({'nr':i, 'all':1}))
2235 endfor
2236 call g:Xsetlist([], 'f')
2237 for i in range(len(qstack))
2238 call g:Xsetlist([], ' ', qstack[i])
2239 endfor
2240 call assert_equal(3, g:Xgetlist({'nr':'$'}).nr)
2241 call assert_equal(10, g:Xgetlist({'nr':1, 'items':1}).items[0].lnum)
2242 call assert_equal(20, g:Xgetlist({'nr':2, 'items':1}).items[0].lnum)
2243 call assert_equal(30, g:Xgetlist({'nr':3, 'items':1}).items[0].lnum)
2244 call g:Xsetlist([], 'f')
2245
2246 " Swap two quickfix lists
2247 Xexpr "File1:10:Line10"
2248 Xexpr "File2:20:Line20"
2249 Xexpr "File3:30:Line30"
2250 call g:Xsetlist([], 'r', {'nr':1,'title':'Colors','context':['Colors']})
2251 call g:Xsetlist([], 'r', {'nr':2,'title':'Fruits','context':['Fruits']})
2252 let l1=g:Xgetlist({'nr':1,'all':1})
2253 let l2=g:Xgetlist({'nr':2,'all':1})
Bram Moolenaara539f4f2017-08-30 20:33:55 +02002254 let save_id = l1.id
2255 let l1.id=l2.id
2256 let l2.id=save_id
Bram Moolenaar6a8958d2017-06-22 21:33:20 +02002257 call g:Xsetlist([], 'r', l1)
2258 call g:Xsetlist([], 'r', l2)
2259 let newl1=g:Xgetlist({'nr':1,'all':1})
2260 let newl2=g:Xgetlist({'nr':2,'all':1})
Bram Moolenaarb4d5fba2017-09-11 19:31:28 +02002261 call assert_equal('Fruits', newl1.title)
Bram Moolenaar6a8958d2017-06-22 21:33:20 +02002262 call assert_equal(['Fruits'], newl1.context)
2263 call assert_equal('Line20', newl1.items[0].text)
Bram Moolenaarb4d5fba2017-09-11 19:31:28 +02002264 call assert_equal('Colors', newl2.title)
Bram Moolenaar6a8958d2017-06-22 21:33:20 +02002265 call assert_equal(['Colors'], newl2.context)
2266 call assert_equal('Line10', newl2.items[0].text)
2267 call g:Xsetlist([], 'f')
Bram Moolenaaree85df32017-03-19 14:19:50 +01002268endfunc
Bram Moolenaard823fa92016-08-12 16:29:27 +02002269
Bram Moolenaar2b946c92016-11-12 18:14:44 +01002270func Test_qf_property()
Bram Moolenaard823fa92016-08-12 16:29:27 +02002271 call Xproperty_tests('c')
2272 call Xproperty_tests('l')
Bram Moolenaaree85df32017-03-19 14:19:50 +01002273endfunc
Bram Moolenaar04c4ce62016-09-01 15:45:58 +02002274
Bram Moolenaar5b69c222019-01-11 14:50:06 +01002275" Test for setting the current index in the location/quickfix list
2276func Xtest_setqfidx(cchar)
2277 call s:setup_commands(a:cchar)
2278
2279 Xgetexpr "F1:10:1:Line1\nF2:20:2:Line2\nF3:30:3:Line3"
2280 Xgetexpr "F4:10:1:Line1\nF5:20:2:Line2\nF6:30:3:Line3"
2281 Xgetexpr "F7:10:1:Line1\nF8:20:2:Line2\nF9:30:3:Line3"
2282
2283 call g:Xsetlist([], 'a', {'nr' : 3, 'idx' : 2})
2284 call g:Xsetlist([], 'a', {'nr' : 2, 'idx' : 2})
2285 call g:Xsetlist([], 'a', {'nr' : 1, 'idx' : 3})
2286 Xolder 2
2287 Xopen
2288 call assert_equal(3, line('.'))
2289 Xnewer
2290 call assert_equal(2, line('.'))
2291 Xnewer
2292 call assert_equal(2, line('.'))
2293 " Update the current index with the quickfix window open
2294 wincmd w
2295 call g:Xsetlist([], 'a', {'nr' : 3, 'idx' : 3})
2296 Xopen
2297 call assert_equal(3, line('.'))
2298 Xclose
2299
2300 " Set the current index to the last entry
2301 call g:Xsetlist([], 'a', {'nr' : 1, 'idx' : '$'})
2302 call assert_equal(3, g:Xgetlist({'nr' : 1, 'idx' : 0}).idx)
2303 " A large value should set the index to the last index
2304 call g:Xsetlist([], 'a', {'nr' : 1, 'idx' : 1})
2305 call g:Xsetlist([], 'a', {'nr' : 1, 'idx' : 999})
2306 call assert_equal(3, g:Xgetlist({'nr' : 1, 'idx' : 0}).idx)
2307 " Invalid index values
2308 call g:Xsetlist([], 'a', {'nr' : 1, 'idx' : -1})
2309 call assert_equal(3, g:Xgetlist({'nr' : 1, 'idx' : 0}).idx)
2310 call g:Xsetlist([], 'a', {'nr' : 1, 'idx' : 0})
2311 call assert_equal(3, g:Xgetlist({'nr' : 1, 'idx' : 0}).idx)
2312 call g:Xsetlist([], 'a', {'nr' : 1, 'idx' : 'xx'})
2313 call assert_equal(3, g:Xgetlist({'nr' : 1, 'idx' : 0}).idx)
2314 call assert_fails("call g:Xsetlist([], 'a', {'nr':1, 'idx':[]})", 'E745:')
2315
2316 call g:Xsetlist([], 'f')
2317 new | only
2318endfunc
2319
2320func Test_setqfidx()
2321 call Xtest_setqfidx('c')
2322 call Xtest_setqfidx('l')
2323endfunc
2324
Bram Moolenaar04c4ce62016-09-01 15:45:58 +02002325" Tests for the QuickFixCmdPre/QuickFixCmdPost autocommands
Bram Moolenaar2b946c92016-11-12 18:14:44 +01002326func QfAutoCmdHandler(loc, cmd)
Bram Moolenaar04c4ce62016-09-01 15:45:58 +02002327 call add(g:acmds, a:loc . a:cmd)
Bram Moolenaar2b946c92016-11-12 18:14:44 +01002328endfunc
Bram Moolenaar04c4ce62016-09-01 15:45:58 +02002329
Bram Moolenaar2b946c92016-11-12 18:14:44 +01002330func Test_Autocmd()
Bram Moolenaar04c4ce62016-09-01 15:45:58 +02002331 autocmd QuickFixCmdPre * call QfAutoCmdHandler('pre', expand('<amatch>'))
2332 autocmd QuickFixCmdPost * call QfAutoCmdHandler('post', expand('<amatch>'))
2333
2334 let g:acmds = []
2335 cexpr "F1:10:Line 10"
2336 caddexpr "F1:20:Line 20"
2337 cgetexpr "F1:30:Line 30"
Bram Moolenaar1ed22762017-11-28 18:03:44 +01002338 cexpr ""
2339 caddexpr ""
2340 cgetexpr ""
2341 silent! cexpr non_existing_func()
2342 silent! caddexpr non_existing_func()
2343 silent! cgetexpr non_existing_func()
Bram Moolenaar04c4ce62016-09-01 15:45:58 +02002344 let l = ['precexpr',
2345 \ 'postcexpr',
2346 \ 'precaddexpr',
2347 \ 'postcaddexpr',
2348 \ 'precgetexpr',
2349 \ 'postcgetexpr',
Bram Moolenaar1ed22762017-11-28 18:03:44 +01002350 \ 'precexpr',
2351 \ 'postcexpr',
2352 \ 'precaddexpr',
2353 \ 'postcaddexpr',
2354 \ 'precgetexpr',
2355 \ 'postcgetexpr',
2356 \ 'precexpr',
2357 \ 'precaddexpr',
2358 \ 'precgetexpr']
2359 call assert_equal(l, g:acmds)
2360
2361 let g:acmds = []
2362 enew! | call append(0, "F2:10:Line 10")
2363 cbuffer!
2364 enew! | call append(0, "F2:20:Line 20")
2365 cgetbuffer
2366 enew! | call append(0, "F2:30:Line 30")
2367 caddbuffer
2368 new
2369 let bnum = bufnr('%')
2370 bunload
2371 exe 'silent! cbuffer! ' . bnum
2372 exe 'silent! cgetbuffer ' . bnum
2373 exe 'silent! caddbuffer ' . bnum
2374 enew!
2375 let l = ['precbuffer',
Bram Moolenaar04c4ce62016-09-01 15:45:58 +02002376 \ 'postcbuffer',
2377 \ 'precgetbuffer',
2378 \ 'postcgetbuffer',
2379 \ 'precaddbuffer',
Bram Moolenaar1ed22762017-11-28 18:03:44 +01002380 \ 'postcaddbuffer',
2381 \ 'precbuffer',
2382 \ 'precgetbuffer',
2383 \ 'precaddbuffer']
Bram Moolenaar04c4ce62016-09-01 15:45:58 +02002384 call assert_equal(l, g:acmds)
Bram Moolenaar1ed22762017-11-28 18:03:44 +01002385
2386 call writefile(['Xtest:1:Line1'], 'Xtest')
2387 call writefile([], 'Xempty')
2388 let g:acmds = []
2389 cfile Xtest
2390 caddfile Xtest
2391 cgetfile Xtest
2392 cfile Xempty
2393 caddfile Xempty
2394 cgetfile Xempty
2395 silent! cfile do_not_exist
2396 silent! caddfile do_not_exist
2397 silent! cgetfile do_not_exist
2398 let l = ['precfile',
2399 \ 'postcfile',
2400 \ 'precaddfile',
2401 \ 'postcaddfile',
2402 \ 'precgetfile',
2403 \ 'postcgetfile',
2404 \ 'precfile',
2405 \ 'postcfile',
2406 \ 'precaddfile',
2407 \ 'postcaddfile',
2408 \ 'precgetfile',
2409 \ 'postcgetfile',
2410 \ 'precfile',
2411 \ 'postcfile',
2412 \ 'precaddfile',
2413 \ 'postcaddfile',
2414 \ 'precgetfile',
2415 \ 'postcgetfile']
2416 call assert_equal(l, g:acmds)
2417
2418 let g:acmds = []
2419 helpgrep quickfix
2420 silent! helpgrep non_existing_help_topic
2421 vimgrep test Xtest
2422 vimgrepadd test Xtest
2423 silent! vimgrep non_existing_test Xtest
2424 silent! vimgrepadd non_existing_test Xtest
2425 set makeprg=
2426 silent! make
2427 set makeprg&
2428 let l = ['prehelpgrep',
2429 \ 'posthelpgrep',
2430 \ 'prehelpgrep',
2431 \ 'posthelpgrep',
2432 \ 'previmgrep',
2433 \ 'postvimgrep',
2434 \ 'previmgrepadd',
2435 \ 'postvimgrepadd',
2436 \ 'previmgrep',
2437 \ 'postvimgrep',
2438 \ 'previmgrepadd',
2439 \ 'postvimgrepadd',
2440 \ 'premake',
2441 \ 'postmake']
2442 call assert_equal(l, g:acmds)
2443
2444 if has('unix')
2445 " Run this test only on Unix-like systems. The grepprg may not be set on
2446 " non-Unix systems.
2447 " The following lines are used for the grep test. Don't remove.
2448 " Grep_Autocmd_Text: Match 1
2449 " GrepAdd_Autocmd_Text: Match 2
2450 let g:acmds = []
2451 silent grep Grep_Autocmd_Text test_quickfix.vim
2452 silent grepadd GrepAdd_Autocmd_Text test_quickfix.vim
2453 silent grep abc123def Xtest
2454 silent grepadd abc123def Xtest
2455 let l = ['pregrep',
2456 \ 'postgrep',
2457 \ 'pregrepadd',
2458 \ 'postgrepadd',
2459 \ 'pregrep',
2460 \ 'postgrep',
2461 \ 'pregrepadd',
2462 \ 'postgrepadd']
2463 call assert_equal(l, g:acmds)
2464 endif
2465
2466 call delete('Xtest')
2467 call delete('Xempty')
Bram Moolenaarb254af32017-12-18 19:48:58 +01002468 au! QuickFixCmdPre
2469 au! QuickFixCmdPost
Bram Moolenaar2b946c92016-11-12 18:14:44 +01002470endfunc
Bram Moolenaar21662be2016-11-06 14:46:44 +01002471
Bram Moolenaar2b946c92016-11-12 18:14:44 +01002472func Test_Autocmd_Exception()
Bram Moolenaar21662be2016-11-06 14:46:44 +01002473 set efm=%m
2474 lgetexpr '?'
2475
2476 try
2477 call DoesNotExit()
2478 catch
2479 lgetexpr '1'
2480 finally
2481 lgetexpr '1'
2482 endtry
2483
2484 call assert_equal('1', getloclist(0)[0].text)
2485
2486 set efm&vim
Bram Moolenaar2b946c92016-11-12 18:14:44 +01002487endfunc
Bram Moolenaar63bed3d2016-11-12 15:36:54 +01002488
Bram Moolenaar2b946c92016-11-12 18:14:44 +01002489func Test_caddbuffer_wrong()
2490 " This used to cause a memory access in freed memory.
Bram Moolenaar63bed3d2016-11-12 15:36:54 +01002491 let save_efm = &efm
2492 set efm=%EEEE%m,%WWWW,%+CCCC%>%#,%GGGG%.#
2493 cgetexpr ['WWWW', 'EEEE', 'CCCC']
2494 let &efm = save_efm
Bram Moolenaar2b946c92016-11-12 18:14:44 +01002495 caddbuffer
Bram Moolenaar63bed3d2016-11-12 15:36:54 +01002496 bwipe!
2497endfunc
Bram Moolenaar2b946c92016-11-12 18:14:44 +01002498
2499func Test_caddexpr_wrong()
2500 " This used to cause a memory access in freed memory.
2501 cbuffer
2502 cbuffer
2503 copen
2504 let save_efm = &efm
2505 set efm=%
2506 call assert_fails('caddexpr ""', 'E376:')
2507 let &efm = save_efm
2508endfunc
Bram Moolenaar7618e002016-11-13 15:09:26 +01002509
2510func Test_dirstack_cleanup()
2511 " This used to cause a memory access in freed memory.
2512 let save_efm = &efm
2513 lexpr '0'
2514 lopen
2515 fun X(c)
2516 let save_efm=&efm
2517 set efm=%D%f
2518 if a:c == 'c'
2519 caddexpr '::'
2520 else
2521 laddexpr ':0:0'
2522 endif
2523 let &efm=save_efm
2524 endfun
2525 call X('c')
2526 call X('l')
2527 call setqflist([], 'r')
2528 caddbuffer
2529 let &efm = save_efm
2530endfunc
Bram Moolenaar391b1dd2017-03-04 13:47:11 +01002531
2532" Tests for jumping to entries from the location list window and quickfix
2533" window
2534func Test_cwindow_jump()
2535 set efm=%f%%%l%%%m
2536 lgetexpr ["F1%10%Line 10", "F2%20%Line 20", "F3%30%Line 30"]
2537 lopen | only
2538 lfirst
2539 call assert_true(winnr('$') == 2)
2540 call assert_true(winnr() == 1)
2541 " Location list for the new window should be set
2542 call assert_true(getloclist(0)[2].text == 'Line 30')
2543
2544 " Open a scratch buffer
2545 " Open a new window and create a location list
2546 " Open the location list window and close the other window
2547 " Jump to an entry.
Bram Moolenaareeb1b9c2019-02-10 22:59:04 +01002548 " Should create a new window and jump to the entry. The scratch buffer
Bram Moolenaar391b1dd2017-03-04 13:47:11 +01002549 " should not be used.
2550 enew | only
2551 set buftype=nofile
2552 below new
2553 lgetexpr ["F1%10%Line 10", "F2%20%Line 20", "F3%30%Line 30"]
2554 lopen
2555 2wincmd c
2556 lnext
2557 call assert_true(winnr('$') == 3)
2558 call assert_true(winnr() == 2)
2559
2560 " Open two windows with two different location lists
2561 " Open the location list window and close the previous window
2562 " Jump to an entry in the location list window
2563 " Should open the file in the first window and not set the location list.
2564 enew | only
2565 lgetexpr ["F1%5%Line 5"]
2566 below new
2567 lgetexpr ["F1%10%Line 10", "F2%20%Line 20", "F3%30%Line 30"]
2568 lopen
2569 2wincmd c
2570 lnext
2571 call assert_true(winnr() == 1)
2572 call assert_true(getloclist(0)[0].text == 'Line 5')
2573
2574 enew | only
2575 cgetexpr ["F1%10%Line 10", "F2%20%Line 20", "F3%30%Line 30"]
2576 copen
2577 cnext
2578 call assert_true(winnr('$') == 2)
2579 call assert_true(winnr() == 1)
2580
Bram Moolenaarf9ae1542019-11-18 22:02:16 +01002581 " open the quickfix buffer in two windows and jump to an entry. Should open
2582 " the file in the first quickfix window.
2583 enew | only
2584 copen
2585 let bnum = bufnr('')
2586 exe 'sbuffer ' . bnum
2587 wincmd b
2588 cfirst
2589 call assert_equal(2, winnr())
2590 call assert_equal('F1', bufname(''))
2591 enew | only
2592 exe 'sb' bnum
2593 exe 'botright sb' bnum
2594 wincmd t
2595 clast
2596 call assert_equal(2, winnr())
2597 call assert_equal('quickfix', getwinvar(1, '&buftype'))
2598 call assert_equal('quickfix', getwinvar(3, '&buftype'))
2599
Bram Moolenaar391b1dd2017-03-04 13:47:11 +01002600 enew | only
2601 set efm&vim
2602endfunc
Bram Moolenaaree85df32017-03-19 14:19:50 +01002603
Bram Moolenaare00fdf32019-09-15 19:09:42 +02002604func Test_cwindow_highlight()
2605 CheckScreendump
2606
2607 let lines =<< trim END
2608 set t_u7=
2609 call setline(1, ['some', 'text', 'with', 'matches'])
2610 write XCwindow
2611 vimgrep e XCwindow
2612 redraw
2613 cwindow 4
2614 END
2615 call writefile(lines, 'XtestCwindow')
2616 let buf = RunVimInTerminal('-S XtestCwindow', #{rows: 12})
2617 call VerifyScreenDump(buf, 'Test_quickfix_cwindow_1', {})
2618
2619 call term_sendkeys(buf, ":cnext\<CR>")
2620 call VerifyScreenDump(buf, 'Test_quickfix_cwindow_2', {})
2621
2622 " clean up
2623 call StopVimInTerminal(buf)
2624 call delete('XtestCwindow')
2625 call delete('XCwindow')
2626endfunc
2627
Bram Moolenaaree85df32017-03-19 14:19:50 +01002628func XvimgrepTests(cchar)
2629 call s:setup_commands(a:cchar)
2630
2631 call writefile(['Editor:VIM vim',
2632 \ 'Editor:Emacs EmAcS',
2633 \ 'Editor:Notepad NOTEPAD'], 'Xtestfile1')
2634 call writefile(['Linux', 'MacOS', 'MS-Windows'], 'Xtestfile2')
2635
2636 " Error cases
2637 call assert_fails('Xvimgrep /abc *', 'E682:')
2638
2639 let @/=''
2640 call assert_fails('Xvimgrep // *', 'E35:')
2641
2642 call assert_fails('Xvimgrep abc', 'E683:')
2643 call assert_fails('Xvimgrep a1b2c3 Xtestfile1', 'E480:')
2644 call assert_fails('Xvimgrep pat Xa1b2c3', 'E480:')
2645
2646 Xexpr ""
2647 Xvimgrepadd Notepad Xtestfile1
2648 Xvimgrepadd MacOS Xtestfile2
2649 let l = g:Xgetlist()
2650 call assert_equal(2, len(l))
2651 call assert_equal('Editor:Notepad NOTEPAD', l[0].text)
2652
Bram Moolenaarf9ae1542019-11-18 22:02:16 +01002653 10Xvimgrep #\cvim#g Xtestfile?
Bram Moolenaaree85df32017-03-19 14:19:50 +01002654 let l = g:Xgetlist()
2655 call assert_equal(2, len(l))
2656 call assert_equal(8, l[0].col)
2657 call assert_equal(12, l[1].col)
2658
2659 1Xvimgrep ?Editor? Xtestfile*
2660 let l = g:Xgetlist()
2661 call assert_equal(1, len(l))
2662 call assert_equal('Editor:VIM vim', l[0].text)
2663
2664 edit +3 Xtestfile2
2665 Xvimgrep +\cemacs+j Xtestfile1
2666 let l = g:Xgetlist()
2667 call assert_equal('Xtestfile2', bufname(''))
2668 call assert_equal('Editor:Emacs EmAcS', l[0].text)
2669
Bram Moolenaar2225ebb2018-04-24 15:48:11 +02002670 " Test for unloading a buffer after vimgrep searched the buffer
2671 %bwipe
2672 Xvimgrep /Editor/j Xtestfile*
2673 call assert_equal(0, getbufinfo('Xtestfile1')[0].loaded)
2674 call assert_equal([], getbufinfo('Xtestfile2'))
2675
Bram Moolenaaree85df32017-03-19 14:19:50 +01002676 call delete('Xtestfile1')
2677 call delete('Xtestfile2')
2678endfunc
2679
2680" Tests for the :vimgrep command
2681func Test_vimgrep()
2682 call XvimgrepTests('c')
2683 call XvimgrepTests('l')
2684endfunc
Bram Moolenaar69f40be2017-04-02 15:15:49 +02002685
Bram Moolenaar1c299432018-10-28 14:36:09 +01002686" Test for incsearch highlighting of the :vimgrep pattern
2687" This test used to cause "E315: ml_get: invalid lnum" errors.
2688func Test_vimgrep_incsearch()
2689 enew
2690 set incsearch
2691 call test_override("char_avail", 1)
2692
2693 call feedkeys(":2vimgrep assert test_quickfix.vim test_cdo.vim\<CR>", "ntx")
2694 let l = getqflist()
2695 call assert_equal(2, len(l))
2696
2697 call test_override("ALL", 0)
2698 set noincsearch
2699endfunc
2700
Bram Moolenaar69f40be2017-04-02 15:15:49 +02002701func XfreeTests(cchar)
2702 call s:setup_commands(a:cchar)
2703
2704 enew | only
2705
2706 " Deleting the quickfix stack should work even When the current list is
2707 " somewhere in the middle of the stack
2708 Xexpr ['Xfile1:10:10:Line 10', 'Xfile1:15:15:Line 15']
2709 Xexpr ['Xfile2:20:20:Line 20', 'Xfile2:25:25:Line 25']
2710 Xexpr ['Xfile3:30:30:Line 30', 'Xfile3:35:35:Line 35']
2711 Xolder
2712 call g:Xsetlist([], 'f')
2713 call assert_equal(0, len(g:Xgetlist()))
2714
2715 " After deleting the stack, adding a new list should create a stack with a
2716 " single list.
2717 Xexpr ['Xfile1:10:10:Line 10', 'Xfile1:15:15:Line 15']
2718 call assert_equal(1, g:Xgetlist({'all':1}).nr)
2719
2720 " Deleting the stack from a quickfix window should update/clear the
2721 " quickfix/location list window.
2722 Xexpr ['Xfile1:10:10:Line 10', 'Xfile1:15:15:Line 15']
2723 Xexpr ['Xfile2:20:20:Line 20', 'Xfile2:25:25:Line 25']
2724 Xexpr ['Xfile3:30:30:Line 30', 'Xfile3:35:35:Line 35']
2725 Xolder
2726 Xwindow
2727 call g:Xsetlist([], 'f')
2728 call assert_equal(2, winnr('$'))
2729 call assert_equal(1, line('$'))
2730 Xclose
2731
2732 " Deleting the stack from a non-quickfix window should update/clear the
2733 " quickfix/location list window.
2734 Xexpr ['Xfile1:10:10:Line 10', 'Xfile1:15:15:Line 15']
2735 Xexpr ['Xfile2:20:20:Line 20', 'Xfile2:25:25:Line 25']
2736 Xexpr ['Xfile3:30:30:Line 30', 'Xfile3:35:35:Line 35']
2737 Xolder
2738 Xwindow
2739 wincmd p
2740 call g:Xsetlist([], 'f')
2741 call assert_equal(0, len(g:Xgetlist()))
2742 wincmd p
2743 call assert_equal(2, winnr('$'))
2744 call assert_equal(1, line('$'))
2745
2746 " After deleting the location list stack, if the location list window is
2747 " opened, then a new location list should be created. So opening the
2748 " location list window again should not create a new window.
2749 if a:cchar == 'l'
2750 lexpr ['Xfile1:10:10:Line 10', 'Xfile1:15:15:Line 15']
2751 wincmd p
2752 lopen
2753 call assert_equal(2, winnr('$'))
2754 endif
2755 Xclose
2756endfunc
2757
Bram Moolenaar74240d32017-12-10 15:26:15 +01002758" Tests for the quickfix free functionality
Bram Moolenaar69f40be2017-04-02 15:15:49 +02002759func Test_qf_free()
2760 call XfreeTests('c')
2761 call XfreeTests('l')
2762endfunc
Bram Moolenaar6e62da32017-05-28 08:16:25 +02002763
2764" Test for buffer overflow when parsing lines and adding new entries to
2765" the quickfix list.
2766func Test_bufoverflow()
2767 set efm=%f:%l:%m
2768 cgetexpr ['File1:100:' . repeat('x', 1025)]
2769
2770 set efm=%+GCompiler:\ %.%#,%f:%l:%m
2771 cgetexpr ['Compiler: ' . repeat('a', 1015), 'File1:10:Hello World']
2772
2773 set efm=%DEntering\ directory\ %f,%f:%l:%m
2774 cgetexpr ['Entering directory ' . repeat('a', 1006),
2775 \ 'File1:10:Hello World']
2776 set efm&vim
2777endfunc
2778
Bram Moolenaar875feea2017-06-11 16:07:51 +02002779" Tests for getting the quickfix stack size
2780func XsizeTests(cchar)
2781 call s:setup_commands(a:cchar)
2782
2783 call g:Xsetlist([], 'f')
2784 call assert_equal(0, g:Xgetlist({'nr':'$'}).nr)
Bram Moolenaara6d48492017-12-12 22:45:31 +01002785 call assert_equal('', g:Xgetlist({'nr':'$', 'all':1}).title)
2786 call assert_equal(0, g:Xgetlist({'nr':0}).nr)
Bram Moolenaar875feea2017-06-11 16:07:51 +02002787
2788 Xexpr "File1:10:Line1"
2789 Xexpr "File2:20:Line2"
2790 Xexpr "File3:30:Line3"
2791 Xolder | Xolder
2792 call assert_equal(3, g:Xgetlist({'nr':'$'}).nr)
2793 call g:Xsetlist([], 'f')
2794
2795 Xexpr "File1:10:Line1"
2796 Xexpr "File2:20:Line2"
2797 Xexpr "File3:30:Line3"
2798 Xolder | Xolder
2799 call g:Xsetlist([], 'a', {'nr':'$', 'title':'Compiler'})
2800 call assert_equal('Compiler', g:Xgetlist({'nr':3, 'all':1}).title)
2801endfunc
2802
2803func Test_Qf_Size()
2804 call XsizeTests('c')
2805 call XsizeTests('l')
2806endfunc
Bram Moolenaar18141832017-06-25 21:17:25 +02002807
Bram Moolenaar9c4feff2017-06-28 22:26:54 +02002808func Test_cclose_from_copen()
2809 augroup QF_Test
2810 au!
2811 au FileType qf :call assert_fails(':cclose', 'E788')
2812 augroup END
2813 copen
2814 augroup QF_Test
2815 au!
2816 augroup END
2817 augroup! QF_Test
2818endfunc
2819
Bram Moolenaar18141832017-06-25 21:17:25 +02002820func Test_cclose_in_autocmd()
2821 " Problem is only triggered if "starting" is zero, so that the OptionsSet
2822 " event will be triggered.
2823 call test_override('starting', 1)
2824 augroup QF_Test
2825 au!
2826 au FileType qf :call assert_fails(':cclose', 'E788')
2827 augroup END
2828 copen
2829 augroup QF_Test
2830 au!
2831 augroup END
2832 augroup! QF_Test
2833 call test_override('starting', 0)
2834endfunc
Bram Moolenaar9c4feff2017-06-28 22:26:54 +02002835
Bram Moolenaar379fb762018-08-30 15:58:28 +02002836" Check that ":file" without an argument is possible even when "curbuf_lock"
2837" is set.
2838func Test_file_from_copen()
2839 " Works without argument.
2840 augroup QF_Test
2841 au!
2842 au FileType qf file
2843 augroup END
2844 copen
2845
2846 augroup QF_Test
2847 au!
2848 augroup END
2849 cclose
2850
2851 " Fails with argument.
2852 augroup QF_Test
2853 au!
2854 au FileType qf call assert_fails(':file foo', 'E788')
2855 augroup END
2856 copen
2857 augroup QF_Test
2858 au!
2859 augroup END
2860 cclose
2861
2862 augroup! QF_Test
Bram Moolenaar6a0cc912019-10-26 16:48:44 +02002863endfunc
Bram Moolenaar379fb762018-08-30 15:58:28 +02002864
Bram Moolenaar9c4feff2017-06-28 22:26:54 +02002865func Test_resize_from_copen()
2866 augroup QF_Test
2867 au!
2868 au FileType qf resize 5
2869 augroup END
2870 try
2871 " This should succeed without any exception. No other buffers are
2872 " involved in the autocmd.
2873 copen
2874 finally
2875 augroup QF_Test
2876 au!
2877 augroup END
2878 augroup! QF_Test
2879 endtry
2880endfunc
Bram Moolenaara8788f42017-07-19 17:06:20 +02002881
2882" Tests for the quickfix buffer b:changedtick variable
2883func Xchangedtick_tests(cchar)
2884 call s:setup_commands(a:cchar)
2885
2886 new | only
2887
2888 Xexpr "" | Xexpr "" | Xexpr ""
2889
2890 Xopen
2891 Xolder
2892 Xolder
2893 Xaddexpr "F1:10:Line10"
2894 Xaddexpr "F2:20:Line20"
2895 call g:Xsetlist([{"filename":"F3", "lnum":30, "text":"Line30"}], 'a')
2896 call g:Xsetlist([], 'f')
2897 call assert_equal(8, getbufvar('%', 'changedtick'))
2898 Xclose
2899endfunc
2900
2901func Test_changedtick()
Bram Moolenaarae338332017-08-11 20:25:26 +02002902 call Xchangedtick_tests('c')
2903 call Xchangedtick_tests('l')
2904endfunc
2905
2906" Tests for parsing an expression using setqflist()
2907func Xsetexpr_tests(cchar)
2908 call s:setup_commands(a:cchar)
2909
2910 let t = ["File1:10:Line10", "File1:20:Line20"]
Bram Moolenaar2c809b72017-09-01 18:34:02 +02002911 call g:Xsetlist([], ' ', {'lines' : t})
2912 call g:Xsetlist([], 'a', {'lines' : ["File1:30:Line30"]})
Bram Moolenaarae338332017-08-11 20:25:26 +02002913
2914 let l = g:Xgetlist()
2915 call assert_equal(3, len(l))
2916 call assert_equal(20, l[1].lnum)
2917 call assert_equal('Line30', l[2].text)
Bram Moolenaar2c809b72017-09-01 18:34:02 +02002918 call g:Xsetlist([], 'r', {'lines' : ["File2:5:Line5"]})
Bram Moolenaarae338332017-08-11 20:25:26 +02002919 let l = g:Xgetlist()
2920 call assert_equal(1, len(l))
2921 call assert_equal('Line5', l[0].text)
Bram Moolenaar2c809b72017-09-01 18:34:02 +02002922 call assert_equal(-1, g:Xsetlist([], 'a', {'lines' : 10}))
2923 call assert_equal(-1, g:Xsetlist([], 'a', {'lines' : "F1:10:L10"}))
Bram Moolenaarae338332017-08-11 20:25:26 +02002924
2925 call g:Xsetlist([], 'f')
2926 " Add entries to multiple lists
Bram Moolenaar2c809b72017-09-01 18:34:02 +02002927 call g:Xsetlist([], 'a', {'nr' : 1, 'lines' : ["File1:10:Line10"]})
2928 call g:Xsetlist([], 'a', {'nr' : 2, 'lines' : ["File2:20:Line20"]})
2929 call g:Xsetlist([], 'a', {'nr' : 1, 'lines' : ["File1:15:Line15"]})
2930 call g:Xsetlist([], 'a', {'nr' : 2, 'lines' : ["File2:25:Line25"]})
Bram Moolenaarae338332017-08-11 20:25:26 +02002931 call assert_equal('Line15', g:Xgetlist({'nr':1, 'items':1}).items[1].text)
2932 call assert_equal('Line25', g:Xgetlist({'nr':2, 'items':1}).items[1].text)
Bram Moolenaar36538222017-09-02 19:51:44 +02002933
2934 " Adding entries using a custom efm
2935 set efm&
2936 call g:Xsetlist([], ' ', {'efm' : '%f#%l#%m',
2937 \ 'lines' : ["F1#10#L10", "F2#20#L20"]})
2938 call assert_equal(20, g:Xgetlist({'items':1}).items[1].lnum)
2939 call g:Xsetlist([], 'a', {'efm' : '%f#%l#%m', 'lines' : ["F3:30:L30"]})
2940 call assert_equal('F3:30:L30', g:Xgetlist({'items':1}).items[2].text)
2941 call assert_equal(20, g:Xgetlist({'items':1}).items[1].lnum)
2942 call assert_equal(-1, g:Xsetlist([], 'a', {'efm' : [],
2943 \ 'lines' : ['F1:10:L10']}))
Bram Moolenaarae338332017-08-11 20:25:26 +02002944endfunc
2945
2946func Test_setexpr()
2947 call Xsetexpr_tests('c')
2948 call Xsetexpr_tests('l')
2949endfunc
2950
2951" Tests for per quickfix/location list directory stack
2952func Xmultidirstack_tests(cchar)
2953 call s:setup_commands(a:cchar)
2954
2955 call g:Xsetlist([], 'f')
2956 Xexpr "" | Xexpr ""
2957
Bram Moolenaar2c809b72017-09-01 18:34:02 +02002958 call g:Xsetlist([], 'a', {'nr' : 1, 'lines' : ["Entering dir 'Xone/a'"]})
2959 call g:Xsetlist([], 'a', {'nr' : 2, 'lines' : ["Entering dir 'Xtwo/a'"]})
2960 call g:Xsetlist([], 'a', {'nr' : 1, 'lines' : ["one.txt:3:one one one"]})
2961 call g:Xsetlist([], 'a', {'nr' : 2, 'lines' : ["two.txt:5:two two two"]})
Bram Moolenaarae338332017-08-11 20:25:26 +02002962
2963 let l1 = g:Xgetlist({'nr':1, 'items':1})
2964 let l2 = g:Xgetlist({'nr':2, 'items':1})
2965 call assert_equal('Xone/a/one.txt', bufname(l1.items[1].bufnr))
2966 call assert_equal(3, l1.items[1].lnum)
2967 call assert_equal('Xtwo/a/two.txt', bufname(l2.items[1].bufnr))
2968 call assert_equal(5, l2.items[1].lnum)
2969endfunc
2970
2971func Test_multidirstack()
2972 call mkdir('Xone/a', 'p')
2973 call mkdir('Xtwo/a', 'p')
2974 let lines = ['1', '2', 'one one one', '4', 'two two two', '6', '7']
2975 call writefile(lines, 'Xone/a/one.txt')
2976 call writefile(lines, 'Xtwo/a/two.txt')
2977 let save_efm = &efm
2978 set efm=%DEntering\ dir\ '%f',%f:%l:%m,%XLeaving\ dir\ '%f'
2979
2980 call Xmultidirstack_tests('c')
2981 call Xmultidirstack_tests('l')
2982
2983 let &efm = save_efm
2984 call delete('Xone', 'rf')
2985 call delete('Xtwo', 'rf')
2986endfunc
2987
2988" Tests for per quickfix/location list file stack
2989func Xmultifilestack_tests(cchar)
2990 call s:setup_commands(a:cchar)
2991
2992 call g:Xsetlist([], 'f')
2993 Xexpr "" | Xexpr ""
2994
Bram Moolenaar2c809b72017-09-01 18:34:02 +02002995 call g:Xsetlist([], 'a', {'nr' : 1, 'lines' : ["[one.txt]"]})
2996 call g:Xsetlist([], 'a', {'nr' : 2, 'lines' : ["[two.txt]"]})
2997 call g:Xsetlist([], 'a', {'nr' : 1, 'lines' : ["(3,5) one one one"]})
2998 call g:Xsetlist([], 'a', {'nr' : 2, 'lines' : ["(5,9) two two two"]})
Bram Moolenaarae338332017-08-11 20:25:26 +02002999
3000 let l1 = g:Xgetlist({'nr':1, 'items':1})
3001 let l2 = g:Xgetlist({'nr':2, 'items':1})
3002 call assert_equal('one.txt', bufname(l1.items[1].bufnr))
3003 call assert_equal(3, l1.items[1].lnum)
3004 call assert_equal('two.txt', bufname(l2.items[1].bufnr))
3005 call assert_equal(5, l2.items[1].lnum)
Bram Moolenaare333e792018-04-08 13:27:39 +02003006
3007 " Test for start of a new error line in the same line where a previous
3008 " error line ends with a file stack.
3009 let efm_val = 'Error\ l%l\ in\ %f,'
3010 let efm_val .= '%-P%>(%f%r,Error\ l%l\ in\ %m,%-Q)%r'
3011 let l = g:Xgetlist({'lines' : [
3012 \ '(one.txt',
3013 \ 'Error l4 in one.txt',
3014 \ ') (two.txt',
3015 \ 'Error l6 in two.txt',
3016 \ ')',
3017 \ 'Error l8 in one.txt'
3018 \ ], 'efm' : efm_val})
3019 call assert_equal(3, len(l.items))
3020 call assert_equal('one.txt', bufname(l.items[0].bufnr))
3021 call assert_equal(4, l.items[0].lnum)
3022 call assert_equal('one.txt', l.items[0].text)
3023 call assert_equal('two.txt', bufname(l.items[1].bufnr))
3024 call assert_equal(6, l.items[1].lnum)
3025 call assert_equal('two.txt', l.items[1].text)
3026 call assert_equal('one.txt', bufname(l.items[2].bufnr))
3027 call assert_equal(8, l.items[2].lnum)
3028 call assert_equal('', l.items[2].text)
Bram Moolenaarae338332017-08-11 20:25:26 +02003029endfunc
3030
3031func Test_multifilestack()
3032 let lines = ['1', '2', 'one one one', '4', 'two two two', '6', '7']
3033 call writefile(lines, 'one.txt')
3034 call writefile(lines, 'two.txt')
3035 let save_efm = &efm
3036 set efm=%+P[%f],(%l\\,%c)\ %m,%-Q
3037
3038 call Xmultifilestack_tests('c')
3039 call Xmultifilestack_tests('l')
3040
3041 let &efm = save_efm
3042 call delete('one.txt')
3043 call delete('two.txt')
3044endfunc
3045
3046" Tests for per buffer 'efm' setting
3047func Test_perbuf_efm()
3048 call writefile(["File1-10-Line10"], 'one.txt')
3049 call writefile(["File2#20#Line20"], 'two.txt')
3050 set efm=%f#%l#%m
3051 new | only
3052 new
3053 setlocal efm=%f-%l-%m
3054 cfile one.txt
3055 wincmd w
3056 caddfile two.txt
3057
3058 let l = getqflist()
3059 call assert_equal(10, l[0].lnum)
3060 call assert_equal('Line20', l[1].text)
3061
3062 set efm&
3063 new | only
3064 call delete('one.txt')
3065 call delete('two.txt')
Bram Moolenaara8788f42017-07-19 17:06:20 +02003066endfunc
Bram Moolenaard28cc3f2017-07-27 22:03:50 +02003067
3068" Open multiple help windows using ":lhelpgrep
3069" This test used to crash Vim
3070func Test_Multi_LL_Help()
3071 new | only
3072 lhelpgrep window
3073 lopen
3074 e#
3075 lhelpgrep buffer
3076 call assert_equal(3, winnr('$'))
3077 call assert_true(len(getloclist(1)) != 0)
3078 call assert_true(len(getloclist(2)) != 0)
3079 new | only
3080endfunc
Bram Moolenaar55b69262017-08-13 13:42:01 +02003081
3082" Tests for adding new quickfix lists using setqflist()
3083func XaddQf_tests(cchar)
3084 call s:setup_commands(a:cchar)
3085
3086 " Create a new list using ' ' for action
3087 call g:Xsetlist([], 'f')
3088 call g:Xsetlist([], ' ', {'title' : 'Test1'})
3089 let l = g:Xgetlist({'nr' : '$', 'all' : 1})
3090 call assert_equal(1, l.nr)
3091 call assert_equal('Test1', l.title)
3092
3093 " Create a new list using ' ' for action and '$' for 'nr'
3094 call g:Xsetlist([], 'f')
3095 call g:Xsetlist([], ' ', {'title' : 'Test2', 'nr' : '$'})
3096 let l = g:Xgetlist({'nr' : '$', 'all' : 1})
3097 call assert_equal(1, l.nr)
3098 call assert_equal('Test2', l.title)
3099
3100 " Create a new list using 'a' for action
3101 call g:Xsetlist([], 'f')
3102 call g:Xsetlist([], 'a', {'title' : 'Test3'})
3103 let l = g:Xgetlist({'nr' : '$', 'all' : 1})
3104 call assert_equal(1, l.nr)
3105 call assert_equal('Test3', l.title)
3106
3107 " Create a new list using 'a' for action and '$' for 'nr'
3108 call g:Xsetlist([], 'f')
3109 call g:Xsetlist([], 'a', {'title' : 'Test3', 'nr' : '$'})
3110 call g:Xsetlist([], 'a', {'title' : 'Test4'})
3111 let l = g:Xgetlist({'nr' : '$', 'all' : 1})
3112 call assert_equal(1, l.nr)
3113 call assert_equal('Test4', l.title)
3114
3115 " Adding a quickfix list should remove all the lists following the current
3116 " list.
3117 Xexpr "" | Xexpr "" | Xexpr ""
3118 silent! 10Xolder
3119 call g:Xsetlist([], ' ', {'title' : 'Test5'})
3120 let l = g:Xgetlist({'nr' : '$', 'all' : 1})
3121 call assert_equal(2, l.nr)
3122 call assert_equal('Test5', l.title)
3123
3124 " Add a quickfix list using '$' as the list number.
3125 let lastqf = g:Xgetlist({'nr':'$'}).nr
3126 silent! 99Xolder
3127 call g:Xsetlist([], ' ', {'nr' : '$', 'title' : 'Test6'})
3128 let l = g:Xgetlist({'nr' : '$', 'all' : 1})
3129 call assert_equal(lastqf + 1, l.nr)
3130 call assert_equal('Test6', l.title)
3131
3132 " Add a quickfix list using 'nr' set to one more than the quickfix
3133 " list size.
3134 let lastqf = g:Xgetlist({'nr':'$'}).nr
3135 silent! 99Xolder
3136 call g:Xsetlist([], ' ', {'nr' : lastqf + 1, 'title' : 'Test7'})
3137 let l = g:Xgetlist({'nr' : '$', 'all' : 1})
3138 call assert_equal(lastqf + 1, l.nr)
3139 call assert_equal('Test7', l.title)
3140
3141 " Add a quickfix list to a stack with 10 lists using 'nr' set to '$'
3142 exe repeat('Xexpr "" |', 9) . 'Xexpr ""'
3143 silent! 99Xolder
3144 call g:Xsetlist([], ' ', {'nr' : '$', 'title' : 'Test8'})
3145 let l = g:Xgetlist({'nr' : '$', 'all' : 1})
3146 call assert_equal(10, l.nr)
3147 call assert_equal('Test8', l.title)
3148
3149 " Add a quickfix list using 'nr' set to a value greater than 10
3150 call assert_equal(-1, g:Xsetlist([], ' ', {'nr' : 12, 'title' : 'Test9'}))
3151
3152 " Try adding a quickfix list with 'nr' set to a value greater than the
3153 " quickfix list size but less than 10.
3154 call g:Xsetlist([], 'f')
3155 Xexpr "" | Xexpr "" | Xexpr ""
3156 silent! 99Xolder
3157 call assert_equal(-1, g:Xsetlist([], ' ', {'nr' : 8, 'title' : 'Test10'}))
3158
3159 " Add a quickfix list using 'nr' set to a some string or list
3160 call assert_equal(-1, g:Xsetlist([], ' ', {'nr' : [1,2], 'title' : 'Test11'}))
3161endfunc
3162
3163func Test_add_qf()
3164 call XaddQf_tests('c')
3165 call XaddQf_tests('l')
3166endfunc
Bram Moolenaar7adf06f2017-08-27 15:23:41 +02003167
3168" Test for getting the quickfix list items from some text without modifying
3169" the quickfix stack
Bram Moolenaar2c809b72017-09-01 18:34:02 +02003170func XgetListFromLines(cchar)
Bram Moolenaar7adf06f2017-08-27 15:23:41 +02003171 call s:setup_commands(a:cchar)
3172 call g:Xsetlist([], 'f')
3173
Bram Moolenaar2c809b72017-09-01 18:34:02 +02003174 let l = g:Xgetlist({'lines' : ["File2:20:Line20", "File2:30:Line30"]}).items
Bram Moolenaar7adf06f2017-08-27 15:23:41 +02003175 call assert_equal(2, len(l))
3176 call assert_equal(30, l[1].lnum)
3177
Bram Moolenaar2c809b72017-09-01 18:34:02 +02003178 call assert_equal({}, g:Xgetlist({'lines' : 10}))
3179 call assert_equal({}, g:Xgetlist({'lines' : 'File1:10:Line10'}))
3180 call assert_equal([], g:Xgetlist({'lines' : []}).items)
3181 call assert_equal([], g:Xgetlist({'lines' : [10, 20]}).items)
Bram Moolenaar7adf06f2017-08-27 15:23:41 +02003182
Bram Moolenaar36538222017-09-02 19:51:44 +02003183 " Parse text using a custom efm
3184 set efm&
3185 let l = g:Xgetlist({'lines':['File3#30#Line30'], 'efm' : '%f#%l#%m'}).items
3186 call assert_equal('Line30', l[0].text)
3187 let l = g:Xgetlist({'lines':['File3:30:Line30'], 'efm' : '%f-%l-%m'}).items
3188 call assert_equal('File3:30:Line30', l[0].text)
3189 let l = g:Xgetlist({'lines':['File3:30:Line30'], 'efm' : [1,2]})
3190 call assert_equal({}, l)
3191 call assert_fails("call g:Xgetlist({'lines':['abc'], 'efm':'%2'})", 'E376:')
3192 call assert_fails("call g:Xgetlist({'lines':['abc'], 'efm':''})", 'E378:')
3193
Bram Moolenaar7adf06f2017-08-27 15:23:41 +02003194 " Make sure that the quickfix stack is not modified
3195 call assert_equal(0, g:Xgetlist({'nr' : '$'}).nr)
3196endfunc
3197
Bram Moolenaar2c809b72017-09-01 18:34:02 +02003198func Test_get_list_from_lines()
3199 call XgetListFromLines('c')
3200 call XgetListFromLines('l')
Bram Moolenaar7adf06f2017-08-27 15:23:41 +02003201endfunc
Bram Moolenaara539f4f2017-08-30 20:33:55 +02003202
3203" Tests for the quickfix list id
3204func Xqfid_tests(cchar)
3205 call s:setup_commands(a:cchar)
3206
3207 call g:Xsetlist([], 'f')
Bram Moolenaara6d48492017-12-12 22:45:31 +01003208 call assert_equal(0, g:Xgetlist({'id':0}).id)
Bram Moolenaara539f4f2017-08-30 20:33:55 +02003209 Xexpr ''
3210 let start_id = g:Xgetlist({'id' : 0}).id
3211 Xexpr '' | Xexpr ''
3212 Xolder
3213 call assert_equal(start_id, g:Xgetlist({'id':0, 'nr':1}).id)
3214 call assert_equal(start_id + 1, g:Xgetlist({'id':0, 'nr':0}).id)
3215 call assert_equal(start_id + 2, g:Xgetlist({'id':0, 'nr':'$'}).id)
Bram Moolenaara6d48492017-12-12 22:45:31 +01003216 call assert_equal(0, g:Xgetlist({'id':0, 'nr':99}).id)
Bram Moolenaara539f4f2017-08-30 20:33:55 +02003217 call assert_equal(2, g:Xgetlist({'id':start_id + 1, 'nr':0}).nr)
Bram Moolenaara6d48492017-12-12 22:45:31 +01003218 call assert_equal(0, g:Xgetlist({'id':99, 'nr':0}).id)
3219 call assert_equal(0, g:Xgetlist({'id':"abc", 'nr':0}).id)
Bram Moolenaara539f4f2017-08-30 20:33:55 +02003220
3221 call g:Xsetlist([], 'a', {'id':start_id, 'context':[1,2]})
3222 call assert_equal([1,2], g:Xgetlist({'nr':1, 'context':1}).context)
Bram Moolenaar2c809b72017-09-01 18:34:02 +02003223 call g:Xsetlist([], 'a', {'id':start_id+1, 'lines':['F1:10:L10']})
Bram Moolenaara539f4f2017-08-30 20:33:55 +02003224 call assert_equal('L10', g:Xgetlist({'nr':2, 'items':1}).items[0].text)
3225 call assert_equal(-1, g:Xsetlist([], 'a', {'id':999, 'title':'Vim'}))
3226 call assert_equal(-1, g:Xsetlist([], 'a', {'id':'abc', 'title':'Vim'}))
3227
3228 let qfid = g:Xgetlist({'id':0, 'nr':0})
3229 call g:Xsetlist([], 'f')
Bram Moolenaara6d48492017-12-12 22:45:31 +01003230 call assert_equal(0, g:Xgetlist({'id':qfid, 'nr':0}).id)
Bram Moolenaara539f4f2017-08-30 20:33:55 +02003231endfunc
3232
3233func Test_qf_id()
3234 call Xqfid_tests('c')
3235 call Xqfid_tests('l')
3236endfunc
Bram Moolenaar74240d32017-12-10 15:26:15 +01003237
3238func Xqfjump_tests(cchar)
3239 call s:setup_commands(a:cchar)
3240
3241 call writefile(["Line1\tFoo", "Line2"], 'F1')
3242 call writefile(["Line1\tBar", "Line2"], 'F2')
3243 call writefile(["Line1\tBaz", "Line2"], 'F3')
3244
3245 call g:Xsetlist([], 'f')
3246
3247 " Tests for
3248 " Jumping to a line using a pattern
3249 " Jumping to a column greater than the last column in a line
3250 " Jumping to a line greater than the last line in the file
3251 let l = []
3252 for i in range(1, 7)
3253 call add(l, {})
3254 endfor
3255 let l[0].filename='F1'
3256 let l[0].pattern='Line1'
3257 let l[1].filename='F2'
3258 let l[1].pattern='Line1'
3259 let l[2].filename='F3'
3260 let l[2].pattern='Line1'
3261 let l[3].filename='F3'
3262 let l[3].lnum=1
3263 let l[3].col=9
3264 let l[3].vcol=1
3265 let l[4].filename='F3'
3266 let l[4].lnum=99
3267 let l[5].filename='F3'
3268 let l[5].lnum=1
3269 let l[5].col=99
3270 let l[5].vcol=1
3271 let l[6].filename='F3'
3272 let l[6].pattern='abcxyz'
3273
3274 call g:Xsetlist([], ' ', {'items' : l})
3275 Xopen | only
3276 2Xnext
3277 call assert_equal(3, g:Xgetlist({'idx' : 0}).idx)
3278 call assert_equal('F3', bufname('%'))
3279 Xnext
3280 call assert_equal(7, col('.'))
3281 Xnext
3282 call assert_equal(2, line('.'))
3283 Xnext
3284 call assert_equal(9, col('.'))
3285 2
3286 Xnext
3287 call assert_equal(2, line('.'))
3288
3289 if a:cchar == 'l'
3290 " When jumping to a location list entry in the location list window and
3291 " no usable windows are available, then a new window should be opened.
3292 enew! | new | only
3293 call g:Xsetlist([], 'f')
3294 setlocal buftype=nofile
3295 new
3296 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']})
3297 Xopen
3298 let winid = win_getid()
3299 wincmd p
3300 close
3301 call win_gotoid(winid)
3302 Xnext
3303 call assert_equal(3, winnr('$'))
3304 call assert_equal(1, winnr())
3305 call assert_equal(2, line('.'))
3306
3307 " When jumping to an entry in the location list window and the window
3308 " associated with the location list is not present and a window containing
3309 " the file is already present, then that window should be used.
3310 close
3311 belowright new
3312 call g:Xsetlist([], 'f')
3313 edit F3
3314 call win_gotoid(winid)
3315 Xlast
3316 call assert_equal(3, winnr())
3317 call assert_equal(6, g:Xgetlist({'size' : 1}).size)
3318 call assert_equal(winid, g:Xgetlist({'winid' : 1}).winid)
3319 endif
3320
3321 " Cleanup
3322 enew!
3323 new | only
3324
3325 call delete('F1')
3326 call delete('F2')
3327 call delete('F3')
3328endfunc
3329
3330func Test_qfjump()
3331 call Xqfjump_tests('c')
3332 call Xqfjump_tests('l')
3333endfunc
Bram Moolenaara6d48492017-12-12 22:45:31 +01003334
3335" Tests for the getqflist() and getloclist() functions when the list is not
3336" present or is empty
3337func Xgetlist_empty_tests(cchar)
3338 call s:setup_commands(a:cchar)
3339
3340 " Empty quickfix stack
3341 call g:Xsetlist([], 'f')
3342 call assert_equal('', g:Xgetlist({'context' : 0}).context)
3343 call assert_equal(0, g:Xgetlist({'id' : 0}).id)
3344 call assert_equal(0, g:Xgetlist({'idx' : 0}).idx)
3345 call assert_equal([], g:Xgetlist({'items' : 0}).items)
3346 call assert_equal(0, g:Xgetlist({'nr' : 0}).nr)
3347 call assert_equal(0, g:Xgetlist({'size' : 0}).size)
3348 call assert_equal('', g:Xgetlist({'title' : 0}).title)
3349 call assert_equal(0, g:Xgetlist({'winid' : 0}).winid)
Bram Moolenaarb254af32017-12-18 19:48:58 +01003350 call assert_equal(0, g:Xgetlist({'changedtick' : 0}).changedtick)
Bram Moolenaarc9cc9c72018-09-02 15:18:42 +02003351 if a:cchar == 'c'
3352 call assert_equal({'context' : '', 'id' : 0, 'idx' : 0,
Bram Moolenaar647e24b2019-03-17 16:39:46 +01003353 \ 'items' : [], 'nr' : 0, 'size' : 0, 'qfbufnr' : 0,
Bram Moolenaarc9cc9c72018-09-02 15:18:42 +02003354 \ 'title' : '', 'winid' : 0, 'changedtick': 0},
3355 \ g:Xgetlist({'all' : 0}))
3356 else
3357 call assert_equal({'context' : '', 'id' : 0, 'idx' : 0,
3358 \ 'items' : [], 'nr' : 0, 'size' : 0, 'title' : '',
Bram Moolenaar647e24b2019-03-17 16:39:46 +01003359 \ 'winid' : 0, 'changedtick': 0, 'filewinid' : 0,
3360 \ 'qfbufnr' : 0},
Bram Moolenaarc9cc9c72018-09-02 15:18:42 +02003361 \ g:Xgetlist({'all' : 0}))
3362 endif
Bram Moolenaara6d48492017-12-12 22:45:31 +01003363
Bram Moolenaar2ec364e2018-01-27 11:52:13 +01003364 " Quickfix window with empty stack
3365 silent! Xopen
3366 let qfwinid = (a:cchar == 'c') ? win_getid() : 0
Bram Moolenaar647e24b2019-03-17 16:39:46 +01003367 let qfbufnr = (a:cchar == 'c') ? bufnr('') : 0
Bram Moolenaar2ec364e2018-01-27 11:52:13 +01003368 call assert_equal(qfwinid, g:Xgetlist({'winid' : 0}).winid)
3369 Xclose
3370
Bram Moolenaara6d48492017-12-12 22:45:31 +01003371 " Empty quickfix list
3372 Xexpr ""
3373 call assert_equal('', g:Xgetlist({'context' : 0}).context)
3374 call assert_notequal(0, g:Xgetlist({'id' : 0}).id)
3375 call assert_equal(0, g:Xgetlist({'idx' : 0}).idx)
3376 call assert_equal([], g:Xgetlist({'items' : 0}).items)
3377 call assert_notequal(0, g:Xgetlist({'nr' : 0}).nr)
3378 call assert_equal(0, g:Xgetlist({'size' : 0}).size)
3379 call assert_notequal('', g:Xgetlist({'title' : 0}).title)
3380 call assert_equal(0, g:Xgetlist({'winid' : 0}).winid)
Bram Moolenaarb254af32017-12-18 19:48:58 +01003381 call assert_equal(1, g:Xgetlist({'changedtick' : 0}).changedtick)
Bram Moolenaara6d48492017-12-12 22:45:31 +01003382
3383 let qfid = g:Xgetlist({'id' : 0}).id
3384 call g:Xsetlist([], 'f')
3385
3386 " Non-existing quickfix identifier
3387 call assert_equal('', g:Xgetlist({'id' : qfid, 'context' : 0}).context)
3388 call assert_equal(0, g:Xgetlist({'id' : qfid}).id)
3389 call assert_equal(0, g:Xgetlist({'id' : qfid, 'idx' : 0}).idx)
3390 call assert_equal([], g:Xgetlist({'id' : qfid, 'items' : 0}).items)
3391 call assert_equal(0, g:Xgetlist({'id' : qfid, 'nr' : 0}).nr)
3392 call assert_equal(0, g:Xgetlist({'id' : qfid, 'size' : 0}).size)
3393 call assert_equal('', g:Xgetlist({'id' : qfid, 'title' : 0}).title)
3394 call assert_equal(0, g:Xgetlist({'id' : qfid, 'winid' : 0}).winid)
Bram Moolenaarb254af32017-12-18 19:48:58 +01003395 call assert_equal(0, g:Xgetlist({'id' : qfid, 'changedtick' : 0}).changedtick)
Bram Moolenaarc9cc9c72018-09-02 15:18:42 +02003396 if a:cchar == 'c'
3397 call assert_equal({'context' : '', 'id' : 0, 'idx' : 0, 'items' : [],
3398 \ 'nr' : 0, 'size' : 0, 'title' : '', 'winid' : 0,
Bram Moolenaar647e24b2019-03-17 16:39:46 +01003399 \ 'qfbufnr' : qfbufnr,
Bram Moolenaarc9cc9c72018-09-02 15:18:42 +02003400 \ 'changedtick' : 0}, g:Xgetlist({'id' : qfid, 'all' : 0}))
3401 else
3402 call assert_equal({'context' : '', 'id' : 0, 'idx' : 0, 'items' : [],
3403 \ 'nr' : 0, 'size' : 0, 'title' : '', 'winid' : 0,
Bram Moolenaar647e24b2019-03-17 16:39:46 +01003404 \ 'changedtick' : 0, 'filewinid' : 0, 'qfbufnr' : 0},
Bram Moolenaarc9cc9c72018-09-02 15:18:42 +02003405 \ g:Xgetlist({'id' : qfid, 'all' : 0}))
3406 endif
Bram Moolenaara6d48492017-12-12 22:45:31 +01003407
3408 " Non-existing quickfix list number
3409 call assert_equal('', g:Xgetlist({'nr' : 5, 'context' : 0}).context)
3410 call assert_equal(0, g:Xgetlist({'nr' : 5}).nr)
3411 call assert_equal(0, g:Xgetlist({'nr' : 5, 'idx' : 0}).idx)
3412 call assert_equal([], g:Xgetlist({'nr' : 5, 'items' : 0}).items)
3413 call assert_equal(0, g:Xgetlist({'nr' : 5, 'id' : 0}).id)
3414 call assert_equal(0, g:Xgetlist({'nr' : 5, 'size' : 0}).size)
3415 call assert_equal('', g:Xgetlist({'nr' : 5, 'title' : 0}).title)
3416 call assert_equal(0, g:Xgetlist({'nr' : 5, 'winid' : 0}).winid)
Bram Moolenaarb254af32017-12-18 19:48:58 +01003417 call assert_equal(0, g:Xgetlist({'nr' : 5, 'changedtick' : 0}).changedtick)
Bram Moolenaarc9cc9c72018-09-02 15:18:42 +02003418 if a:cchar == 'c'
3419 call assert_equal({'context' : '', 'id' : 0, 'idx' : 0, 'items' : [],
3420 \ 'nr' : 0, 'size' : 0, 'title' : '', 'winid' : 0,
Bram Moolenaar647e24b2019-03-17 16:39:46 +01003421 \ 'changedtick' : 0, 'qfbufnr' : qfbufnr},
3422 \ g:Xgetlist({'nr' : 5, 'all' : 0}))
Bram Moolenaarc9cc9c72018-09-02 15:18:42 +02003423 else
3424 call assert_equal({'context' : '', 'id' : 0, 'idx' : 0, 'items' : [],
3425 \ 'nr' : 0, 'size' : 0, 'title' : '', 'winid' : 0,
Bram Moolenaar647e24b2019-03-17 16:39:46 +01003426 \ 'changedtick' : 0, 'filewinid' : 0, 'qfbufnr' : 0},
Bram Moolenaarc9cc9c72018-09-02 15:18:42 +02003427 \ g:Xgetlist({'nr' : 5, 'all' : 0}))
3428 endif
Bram Moolenaara6d48492017-12-12 22:45:31 +01003429endfunc
3430
3431func Test_getqflist()
3432 call Xgetlist_empty_tests('c')
3433 call Xgetlist_empty_tests('l')
3434endfunc
Bram Moolenaarb254af32017-12-18 19:48:58 +01003435
Bram Moolenaara0ca7d02017-12-19 10:22:19 +01003436func Test_getqflist_invalid_nr()
3437 " The following commands used to crash Vim
3438 cexpr ""
3439 call getqflist({'nr' : $XXX_DOES_NOT_EXIST_XXX})
3440
3441 " Cleanup
3442 call setqflist([], 'r')
3443endfunc
3444
Bram Moolenaarb254af32017-12-18 19:48:58 +01003445" Tests for the quickfix/location list changedtick
3446func Xqftick_tests(cchar)
3447 call s:setup_commands(a:cchar)
3448
3449 call g:Xsetlist([], 'f')
3450
3451 Xexpr "F1:10:Line10"
3452 let qfid = g:Xgetlist({'id' : 0}).id
3453 call assert_equal(1, g:Xgetlist({'changedtick' : 0}).changedtick)
3454 Xaddexpr "F2:20:Line20\nF2:21:Line21"
3455 call assert_equal(2, g:Xgetlist({'changedtick' : 0}).changedtick)
3456 call g:Xsetlist([], 'a', {'lines' : ["F3:30:Line30", "F3:31:Line31"]})
3457 call assert_equal(3, g:Xgetlist({'changedtick' : 0}).changedtick)
3458 call g:Xsetlist([], 'r', {'lines' : ["F4:40:Line40"]})
3459 call assert_equal(4, g:Xgetlist({'changedtick' : 0}).changedtick)
3460 call g:Xsetlist([], 'a', {'title' : 'New Title'})
3461 call assert_equal(5, g:Xgetlist({'changedtick' : 0}).changedtick)
3462
3463 enew!
3464 call append(0, ["F5:50:L50", "F6:60:L60"])
3465 Xaddbuffer
3466 call assert_equal(6, g:Xgetlist({'changedtick' : 0}).changedtick)
3467 enew!
3468
3469 call g:Xsetlist([], 'a', {'context' : {'bus' : 'pci'}})
3470 call assert_equal(7, g:Xgetlist({'changedtick' : 0}).changedtick)
3471 call g:Xsetlist([{'filename' : 'F7', 'lnum' : 10, 'text' : 'L7'},
3472 \ {'filename' : 'F7', 'lnum' : 11, 'text' : 'L11'}], 'a')
3473 call assert_equal(8, g:Xgetlist({'changedtick' : 0}).changedtick)
3474 call g:Xsetlist([{'filename' : 'F7', 'lnum' : 10, 'text' : 'L7'},
3475 \ {'filename' : 'F7', 'lnum' : 11, 'text' : 'L11'}], ' ')
3476 call assert_equal(1, g:Xgetlist({'changedtick' : 0}).changedtick)
3477 call g:Xsetlist([{'filename' : 'F7', 'lnum' : 10, 'text' : 'L7'},
3478 \ {'filename' : 'F7', 'lnum' : 11, 'text' : 'L11'}], 'r')
3479 call assert_equal(2, g:Xgetlist({'changedtick' : 0}).changedtick)
3480
3481 call writefile(["F8:80:L80", "F8:81:L81"], "Xone")
3482 Xfile Xone
3483 call assert_equal(1, g:Xgetlist({'changedtick' : 0}).changedtick)
3484 Xaddfile Xone
3485 call assert_equal(2, g:Xgetlist({'changedtick' : 0}).changedtick)
3486
3487 " Test case for updating a non-current quickfix list
3488 call g:Xsetlist([], 'f')
3489 Xexpr "F1:1:L1"
3490 Xexpr "F2:2:L2"
3491 call g:Xsetlist([], 'a', {'nr' : 1, "lines" : ["F10:10:L10"]})
3492 call assert_equal(1, g:Xgetlist({'changedtick' : 0}).changedtick)
3493 call assert_equal(2, g:Xgetlist({'nr' : 1, 'changedtick' : 0}).changedtick)
3494
3495 call delete("Xone")
3496endfunc
3497
3498func Test_qf_tick()
3499 call Xqftick_tests('c')
3500 call Xqftick_tests('l')
3501endfunc
Bram Moolenaar12237442017-12-19 12:38:52 +01003502
Bram Moolenaarc631f2d2018-08-21 21:58:13 +02003503" Test helpgrep with lang specifier
3504func Xtest_helpgrep_with_lang_specifier(cchar)
3505 call s:setup_commands(a:cchar)
3506 Xhelpgrep Vim@en
3507 call assert_equal('help', &filetype)
3508 call assert_notequal(0, g:Xgetlist({'nr' : '$'}).nr)
3509 new | only
3510endfunc
3511
3512func Test_helpgrep_with_lang_specifier()
3513 call Xtest_helpgrep_with_lang_specifier('c')
3514 call Xtest_helpgrep_with_lang_specifier('l')
3515endfunc
3516
Bram Moolenaar12237442017-12-19 12:38:52 +01003517" The following test used to crash Vim.
3518" Open the location list window and close the regular window associated with
3519" the location list. When the garbage collection runs now, it incorrectly
3520" marks the location list context as not in use and frees the context.
3521func Test_ll_window_ctx()
3522 call setloclist(0, [], 'f')
3523 call setloclist(0, [], 'a', {'context' : []})
3524 lopen | only
3525 call test_garbagecollect_now()
3526 echo getloclist(0, {'context' : 1}).context
3527 enew | only
3528endfunc
3529
Bram Moolenaar14a4deb2017-12-19 16:48:55 +01003530" The following test used to crash vim
3531func Test_lfile_crash()
3532 sp Xtest
3533 au QuickFixCmdPre * bw
3534 call assert_fails('lfile', 'E40')
3535 au! QuickFixCmdPre
3536endfunc
Bram Moolenaar3c097222017-12-21 20:54:49 +01003537
3538" The following test used to crash vim
3539func Test_lbuffer_crash()
3540 sv Xtest
3541 augroup QF_Test
3542 au!
3543 au * * bw
3544 augroup END
3545 lbuffer
3546 augroup QF_Test
3547 au!
3548 augroup END
3549endfunc
3550
3551" The following test used to crash vim
3552func Test_lexpr_crash()
3553 augroup QF_Test
3554 au!
3555 au * * call setloclist(0, [], 'f')
3556 augroup END
3557 lexpr ""
3558 augroup QF_Test
3559 au!
3560 augroup END
Bram Moolenaar9f84ded2018-10-20 20:54:02 +02003561
Bram Moolenaar3c097222017-12-21 20:54:49 +01003562 enew | only
Bram Moolenaar9f84ded2018-10-20 20:54:02 +02003563 augroup QF_Test
3564 au!
3565 au BufNew * call setloclist(0, [], 'f')
3566 augroup END
3567 lexpr 'x:1:x'
3568 augroup QF_Test
3569 au!
3570 augroup END
3571
3572 enew | only
3573 lexpr ''
3574 lopen
3575 augroup QF_Test
3576 au!
3577 au FileType * call setloclist(0, [], 'f')
3578 augroup END
3579 lexpr ''
3580 augroup QF_Test
3581 au!
3582 augroup END
Bram Moolenaar3c097222017-12-21 20:54:49 +01003583endfunc
3584
3585" The following test used to crash Vim
3586func Test_lvimgrep_crash()
3587 sv Xtest
3588 augroup QF_Test
3589 au!
3590 au * * call setloclist(0, [], 'f')
3591 augroup END
3592 lvimgrep quickfix test_quickfix.vim
3593 augroup QF_Test
3594 au!
3595 augroup END
Bram Moolenaarb6f14802018-10-21 18:47:43 +02003596
3597 new | only
3598 augroup QF_Test
3599 au!
3600 au BufEnter * call setloclist(0, [], 'r')
3601 augroup END
3602 call assert_fails('lvimgrep Test_lvimgrep_crash *', 'E926:')
3603 augroup QF_Test
3604 au!
3605 augroup END
3606
Bram Moolenaar3c097222017-12-21 20:54:49 +01003607 enew | only
3608endfunc
Bram Moolenaarde046542017-12-26 13:53:11 +01003609
3610" Test for the position of the quickfix and location list window
3611func Test_qfwin_pos()
3612 " Open two windows
3613 new | only
3614 new
3615 cexpr ['F1:10:L10']
3616 copen
3617 " Quickfix window should be the bottom most window
3618 call assert_equal(3, winnr())
3619 close
3620 " Open at the very top
3621 wincmd t
3622 topleft copen
3623 call assert_equal(1, winnr())
3624 close
3625 " open left of the current window
3626 wincmd t
3627 below new
3628 leftabove copen
3629 call assert_equal(2, winnr())
3630 close
3631 " open right of the current window
3632 rightbelow copen
3633 call assert_equal(3, winnr())
3634 close
3635endfunc
Bram Moolenaare1bb8792018-04-06 22:58:23 +02003636
3637" Tests for quickfix/location lists changed by autocommands when
3638" :vimgrep/:lvimgrep commands are running.
3639func Test_vimgrep_autocmd()
3640 call setqflist([], 'f')
3641 call writefile(['stars'], 'Xtest1.txt')
3642 call writefile(['stars'], 'Xtest2.txt')
3643
3644 " Test 1:
3645 " When searching for a pattern using :vimgrep, if the quickfix list is
3646 " changed by an autocmd, the results should be added to the correct quickfix
3647 " list.
3648 autocmd BufRead Xtest2.txt cexpr '' | cexpr ''
3649 silent vimgrep stars Xtest*.txt
3650 call assert_equal(1, getqflist({'nr' : 0}).nr)
3651 call assert_equal(3, getqflist({'nr' : '$'}).nr)
3652 call assert_equal('Xtest2.txt', bufname(getqflist()[1].bufnr))
3653 au! BufRead Xtest2.txt
3654
3655 " Test 2:
3656 " When searching for a pattern using :vimgrep, if the quickfix list is
3657 " freed, then a error should be given.
3658 silent! %bwipe!
3659 call setqflist([], 'f')
3660 autocmd BufRead Xtest2.txt for i in range(10) | cexpr '' | endfor
3661 call assert_fails('vimgrep stars Xtest*.txt', 'E925:')
3662 au! BufRead Xtest2.txt
3663
3664 " Test 3:
3665 " When searching for a pattern using :lvimgrep, if the location list is
3666 " freed, then the command should error out.
3667 silent! %bwipe!
3668 let g:save_winid = win_getid()
3669 autocmd BufRead Xtest2.txt call setloclist(g:save_winid, [], 'f')
3670 call assert_fails('lvimgrep stars Xtest*.txt', 'E926:')
3671 au! BufRead Xtest2.txt
3672
3673 call delete('Xtest1.txt')
3674 call delete('Xtest2.txt')
3675 call setqflist([], 'f')
3676endfunc
Bram Moolenaar3b9474b2018-04-23 21:29:48 +02003677
Bram Moolenaarf9ae1542019-11-18 22:02:16 +01003678" Test for an autocmd changing the current directory when running vimgrep
3679func Xvimgrep_autocmd_cd(cchar)
3680 call s:setup_commands(a:cchar)
3681
3682 %bwipe
3683 let save_cwd = getcwd()
3684
3685 augroup QF_Test
3686 au!
3687 autocmd BufRead * silent cd %:p:h
3688 augroup END
3689
3690 10Xvimgrep /vim/ Xdir/**
3691 let l = g:Xgetlist()
3692 call assert_equal('f1.txt', bufname(l[0].bufnr))
3693 call assert_equal('f2.txt', fnamemodify(bufname(l[2].bufnr), ':t'))
3694
3695 augroup QF_Test
3696 au!
3697 augroup END
3698
3699 exe 'cd ' . save_cwd
3700endfunc
3701
3702func Test_vimgrep_autocmd_cd()
3703 call mkdir('Xdir/a', 'p')
3704 call mkdir('Xdir/b', 'p')
3705 call writefile(['a_L1_vim', 'a_L2_vim'], 'Xdir/a/f1.txt')
3706 call writefile(['b_L1_vim', 'b_L2_vim'], 'Xdir/b/f2.txt')
3707 call Xvimgrep_autocmd_cd('c')
3708 call Xvimgrep_autocmd_cd('l')
3709 %bwipe
3710 call delete('Xdir', 'rf')
3711endfunc
3712
Bram Moolenaar3b9474b2018-04-23 21:29:48 +02003713" The following test used to crash Vim
3714func Test_lhelpgrep_autocmd()
3715 lhelpgrep quickfix
3716 autocmd QuickFixCmdPost * call setloclist(0, [], 'f')
3717 lhelpgrep buffer
3718 call assert_equal('help', &filetype)
3719 call assert_equal(0, getloclist(0, {'nr' : '$'}).nr)
3720 lhelpgrep tabpage
3721 call assert_equal('help', &filetype)
3722 call assert_equal(1, getloclist(0, {'nr' : '$'}).nr)
3723 au! QuickFixCmdPost
Bram Moolenaarb6f14802018-10-21 18:47:43 +02003724
3725 new | only
3726 augroup QF_Test
3727 au!
3728 au BufEnter * call setqflist([], 'f')
3729 augroup END
3730 call assert_fails('helpgrep quickfix', 'E925:')
3731 augroup QF_Test
3732 au! BufEnter
3733 augroup END
3734
3735 new | only
3736 augroup QF_Test
3737 au!
3738 au BufEnter * call setqflist([], 'r')
3739 augroup END
3740 call assert_fails('helpgrep quickfix', 'E925:')
3741 augroup QF_Test
3742 au! BufEnter
3743 augroup END
3744
3745 new | only
3746 augroup QF_Test
3747 au!
3748 au BufEnter * call setloclist(0, [], 'r')
3749 augroup END
3750 call assert_fails('lhelpgrep quickfix', 'E926:')
3751 augroup QF_Test
3752 au! BufEnter
3753 augroup END
3754
Bram Moolenaar3b9474b2018-04-23 21:29:48 +02003755 new | only
3756endfunc
Bram Moolenaara796d462018-05-01 14:30:36 +02003757
3758" Test for shortening/simplifying the file name when opening the
3759" quickfix window or when displaying the quickfix list
3760func Test_shorten_fname()
3761 if !has('unix')
3762 return
3763 endif
3764 %bwipe
3765 " Create a quickfix list with a absolute path filename
3766 let fname = getcwd() . '/test_quickfix.vim'
3767 call setqflist([], ' ', {'lines':[fname . ":20:Line20"], 'efm':'%f:%l:%m'})
3768 call assert_equal(fname, bufname('test_quickfix.vim'))
3769 " Opening the quickfix window should simplify the file path
3770 cwindow
3771 call assert_equal('test_quickfix.vim', bufname('test_quickfix.vim'))
3772 cclose
3773 %bwipe
3774 " Create a quickfix list with a absolute path filename
3775 call setqflist([], ' ', {'lines':[fname . ":20:Line20"], 'efm':'%f:%l:%m'})
3776 call assert_equal(fname, bufname('test_quickfix.vim'))
3777 " Displaying the quickfix list should simplify the file path
3778 silent! clist
3779 call assert_equal('test_quickfix.vim', bufname('test_quickfix.vim'))
3780endfunc
Bram Moolenaar8b62e312018-05-13 15:29:04 +02003781
3782" Quickfix title tests
3783" In the below tests, 'exe "cmd"' is used to invoke the quickfix commands.
3784" Otherwise due to indentation, the title is set with spaces at the beginning
3785" of the command.
3786func Test_qftitle()
3787 call writefile(["F1:1:Line1"], 'Xerr')
3788
3789 " :cexpr
3790 exe "cexpr readfile('Xerr')"
3791 call assert_equal(":cexpr readfile('Xerr')", getqflist({'title' : 1}).title)
3792
3793 " :cgetexpr
3794 exe "cgetexpr readfile('Xerr')"
3795 call assert_equal(":cgetexpr readfile('Xerr')",
3796 \ getqflist({'title' : 1}).title)
3797
3798 " :caddexpr
3799 call setqflist([], 'f')
3800 exe "caddexpr readfile('Xerr')"
3801 call assert_equal(":caddexpr readfile('Xerr')",
3802 \ getqflist({'title' : 1}).title)
3803
3804 " :cbuffer
3805 new Xerr
3806 exe "cbuffer"
3807 call assert_equal(':cbuffer (Xerr)', getqflist({'title' : 1}).title)
3808
3809 " :cgetbuffer
3810 edit Xerr
3811 exe "cgetbuffer"
3812 call assert_equal(':cgetbuffer (Xerr)', getqflist({'title' : 1}).title)
3813
3814 " :caddbuffer
3815 call setqflist([], 'f')
3816 edit Xerr
3817 exe "caddbuffer"
3818 call assert_equal(':caddbuffer (Xerr)', getqflist({'title' : 1}).title)
3819
3820 " :cfile
3821 exe "cfile Xerr"
3822 call assert_equal(':cfile Xerr', getqflist({'title' : 1}).title)
3823
3824 " :cgetfile
3825 exe "cgetfile Xerr"
3826 call assert_equal(':cgetfile Xerr', getqflist({'title' : 1}).title)
3827
3828 " :caddfile
3829 call setqflist([], 'f')
3830 exe "caddfile Xerr"
3831 call assert_equal(':caddfile Xerr', getqflist({'title' : 1}).title)
3832
3833 " :grep
3834 set grepprg=internal
3835 exe "grep F1 Xerr"
3836 call assert_equal(':grep F1 Xerr', getqflist({'title' : 1}).title)
3837
3838 " :grepadd
3839 call setqflist([], 'f')
3840 exe "grepadd F1 Xerr"
3841 call assert_equal(':grepadd F1 Xerr', getqflist({'title' : 1}).title)
3842 set grepprg&vim
3843
3844 " :vimgrep
3845 exe "vimgrep F1 Xerr"
3846 call assert_equal(':vimgrep F1 Xerr', getqflist({'title' : 1}).title)
3847
3848 " :vimgrepadd
3849 call setqflist([], 'f')
3850 exe "vimgrepadd F1 Xerr"
3851 call assert_equal(':vimgrepadd F1 Xerr', getqflist({'title' : 1}).title)
3852
3853 call setqflist(['F1:10:L10'], ' ')
3854 call assert_equal(':setqflist()', getqflist({'title' : 1}).title)
3855
3856 call setqflist([], 'f')
3857 call setqflist(['F1:10:L10'], 'a')
3858 call assert_equal(':setqflist()', getqflist({'title' : 1}).title)
3859
3860 call setqflist([], 'f')
3861 call setqflist(['F1:10:L10'], 'r')
3862 call assert_equal(':setqflist()', getqflist({'title' : 1}).title)
3863
3864 close
3865 call delete('Xerr')
3866
3867 call setqflist([], ' ', {'title' : 'Errors'})
3868 copen
3869 call assert_equal('Errors', w:quickfix_title)
3870 call setqflist([], 'r', {'items' : [{'filename' : 'a.c', 'lnum' : 10}]})
3871 call assert_equal('Errors', w:quickfix_title)
3872 cclose
3873endfunc
Bram Moolenaar600323b2018-06-16 22:16:47 +02003874
3875func Test_lbuffer_with_bwipe()
3876 new
3877 new
3878 augroup nasty
3879 au * * bwipe
3880 augroup END
3881 lbuffer
3882 augroup nasty
3883 au!
3884 augroup END
3885endfunc
Bram Moolenaar0366c012018-06-18 20:52:13 +02003886
Bram Moolenaar531b9a32018-07-03 16:54:23 +02003887" Test for an autocmd freeing the quickfix/location list when cexpr/lexpr is
3888" running
3889func Xexpr_acmd_freelist(cchar)
3890 call s:setup_commands(a:cchar)
3891
Bram Moolenaar0366c012018-06-18 20:52:13 +02003892 " This was using freed memory.
3893 augroup nasty
Bram Moolenaar531b9a32018-07-03 16:54:23 +02003894 au * * call g:Xsetlist([], 'f')
Bram Moolenaar0366c012018-06-18 20:52:13 +02003895 augroup END
Bram Moolenaar531b9a32018-07-03 16:54:23 +02003896 Xexpr "x"
Bram Moolenaar0366c012018-06-18 20:52:13 +02003897 augroup nasty
3898 au!
3899 augroup END
3900endfunc
Bram Moolenaar531b9a32018-07-03 16:54:23 +02003901
3902func Test_cexpr_acmd_freelist()
3903 call Xexpr_acmd_freelist('c')
3904 call Xexpr_acmd_freelist('l')
3905endfunc
3906
3907" Test for commands that create a new quickfix/location list and jump to the
3908" first error automatically.
3909func Xjumpto_first_error_test(cchar)
3910 call s:setup_commands(a:cchar)
3911
3912 call s:create_test_file('Xtestfile1')
3913 call s:create_test_file('Xtestfile2')
3914 let l = ['Xtestfile1:2:Line2', 'Xtestfile2:4:Line4']
3915
3916 " Test for cexpr/lexpr
3917 enew
3918 Xexpr l
3919 call assert_equal('Xtestfile1', bufname(''))
3920 call assert_equal(2, line('.'))
3921
3922 " Test for cfile/lfile
3923 enew
3924 call writefile(l, 'Xerr')
3925 Xfile Xerr
3926 call assert_equal('Xtestfile1', bufname(''))
3927 call assert_equal(2, line('.'))
3928
3929 " Test for cbuffer/lbuffer
3930 edit Xerr
3931 Xbuffer
3932 call assert_equal('Xtestfile1', bufname(''))
3933 call assert_equal(2, line('.'))
3934
3935 call delete('Xerr')
3936 call delete('Xtestfile1')
3937 call delete('Xtestfile2')
3938endfunc
3939
3940func Test_jumpto_first_error()
3941 call Xjumpto_first_error_test('c')
3942 call Xjumpto_first_error_test('l')
3943endfunc
3944
3945" Test for a quickfix autocmd changing the quickfix/location list before
3946" jumping to the first error in the new list.
3947func Xautocmd_changelist(cchar)
3948 call s:setup_commands(a:cchar)
3949
3950 " Test for cfile/lfile
3951 call s:create_test_file('Xtestfile1')
3952 call s:create_test_file('Xtestfile2')
3953 Xexpr 'Xtestfile1:2:Line2'
3954 autocmd QuickFixCmdPost * Xolder
3955 call writefile(['Xtestfile2:4:Line4'], 'Xerr')
3956 Xfile Xerr
3957 call assert_equal('Xtestfile2', bufname(''))
3958 call assert_equal(4, line('.'))
3959 autocmd! QuickFixCmdPost
3960
3961 " Test for cbuffer/lbuffer
3962 call g:Xsetlist([], 'f')
3963 Xexpr 'Xtestfile1:2:Line2'
3964 autocmd QuickFixCmdPost * Xolder
3965 call writefile(['Xtestfile2:4:Line4'], 'Xerr')
3966 edit Xerr
3967 Xbuffer
3968 call assert_equal('Xtestfile2', bufname(''))
3969 call assert_equal(4, line('.'))
3970 autocmd! QuickFixCmdPost
3971
3972 " Test for cexpr/lexpr
3973 call g:Xsetlist([], 'f')
3974 Xexpr 'Xtestfile1:2:Line2'
3975 autocmd QuickFixCmdPost * Xolder
3976 Xexpr 'Xtestfile2:4:Line4'
3977 call assert_equal('Xtestfile2', bufname(''))
3978 call assert_equal(4, line('.'))
3979 autocmd! QuickFixCmdPost
3980
Bram Moolenaar851332e2018-07-03 19:16:00 +02003981 " The grepprg may not be set on non-Unix systems
3982 if has('unix')
3983 " Test for grep/lgrep
3984 call g:Xsetlist([], 'f')
3985 Xexpr 'Xtestfile1:2:Line2'
3986 autocmd QuickFixCmdPost * Xolder
3987 silent Xgrep Line5 Xtestfile2
3988 call assert_equal('Xtestfile2', bufname(''))
3989 call assert_equal(5, line('.'))
3990 autocmd! QuickFixCmdPost
3991 endif
Bram Moolenaar531b9a32018-07-03 16:54:23 +02003992
3993 " Test for vimgrep/lvimgrep
3994 call g:Xsetlist([], 'f')
3995 Xexpr 'Xtestfile1:2:Line2'
3996 autocmd QuickFixCmdPost * Xolder
3997 silent Xvimgrep Line5 Xtestfile2
3998 call assert_equal('Xtestfile2', bufname(''))
3999 call assert_equal(5, line('.'))
4000 autocmd! QuickFixCmdPost
4001
Bram Moolenaar3f347e42018-08-09 21:19:20 +02004002 " Test for autocommands clearing the quickfix list before jumping to the
4003 " first error. This should not result in an error
4004 autocmd QuickFixCmdPost * call g:Xsetlist([], 'r')
4005 let v:errmsg = ''
4006 " Test for cfile/lfile
4007 Xfile Xerr
4008 call assert_true(v:errmsg !~# 'E42:')
4009 " Test for cbuffer/lbuffer
4010 edit Xerr
4011 Xbuffer
4012 call assert_true(v:errmsg !~# 'E42:')
4013 " Test for cexpr/lexpr
4014 Xexpr 'Xtestfile2:4:Line4'
4015 call assert_true(v:errmsg !~# 'E42:')
4016 " Test for grep/lgrep
4017 " The grepprg may not be set on non-Unix systems
4018 if has('unix')
4019 silent Xgrep Line5 Xtestfile2
4020 call assert_true(v:errmsg !~# 'E42:')
4021 endif
4022 " Test for vimgrep/lvimgrep
4023 call assert_fails('silent Xvimgrep Line5 Xtestfile2', 'E480:')
4024 autocmd! QuickFixCmdPost
4025
Bram Moolenaar531b9a32018-07-03 16:54:23 +02004026 call delete('Xerr')
4027 call delete('Xtestfile1')
4028 call delete('Xtestfile2')
4029endfunc
4030
4031func Test_autocmd_changelist()
4032 call Xautocmd_changelist('c')
4033 call Xautocmd_changelist('l')
4034endfunc
Bram Moolenaar4cde86c2018-07-08 16:01:08 +02004035
4036" Tests for the ':filter /pat/ clist' command
4037func Test_filter_clist()
4038 cexpr ['Xfile1:10:10:Line 10', 'Xfile2:15:15:Line 15']
4039 call assert_equal([' 2 Xfile2:15 col 15: Line 15'],
4040 \ split(execute('filter /Line 15/ clist'), "\n"))
4041 call assert_equal([' 1 Xfile1:10 col 10: Line 10'],
4042 \ split(execute('filter /Xfile1/ clist'), "\n"))
4043 call assert_equal([], split(execute('filter /abc/ clist'), "\n"))
4044
4045 call setqflist([{'module' : 'abc', 'pattern' : 'pat1'},
4046 \ {'module' : 'pqr', 'pattern' : 'pat2'}], ' ')
4047 call assert_equal([' 2 pqr:pat2: '],
4048 \ split(execute('filter /pqr/ clist'), "\n"))
4049 call assert_equal([' 1 abc:pat1: '],
4050 \ split(execute('filter /pat1/ clist'), "\n"))
4051endfunc
Bram Moolenaar0a08c632018-07-25 22:36:52 +02004052
4053" Tests for the "CTRL-W <CR>" command.
4054func Xview_result_split_tests(cchar)
4055 call s:setup_commands(a:cchar)
4056
4057 " Test that "CTRL-W <CR>" in a qf/ll window fails with empty list.
4058 call g:Xsetlist([])
4059 Xopen
4060 let l:win_count = winnr('$')
4061 call assert_fails('execute "normal! \<C-W>\<CR>"', 'E42')
4062 call assert_equal(l:win_count, winnr('$'))
4063 Xclose
4064endfunc
4065
4066func Test_view_result_split()
4067 call Xview_result_split_tests('c')
4068 call Xview_result_split_tests('l')
4069endfunc
Bram Moolenaar2dfcef42018-08-15 22:29:51 +02004070
4071" Test that :cc sets curswant
4072func Test_curswant()
4073 helpgrep quickfix
4074 normal! llll
4075 1cc
4076 call assert_equal(getcurpos()[4], virtcol('.'))
4077 cclose | helpclose
4078endfunc
Bram Moolenaarb2443732018-11-11 22:50:27 +01004079
4080" Test for opening a file from the quickfix window using CTRL-W <Enter>
4081" doesn't leave an empty buffer around.
4082func Test_splitview()
4083 call s:create_test_file('Xtestfile1')
4084 call s:create_test_file('Xtestfile2')
4085 new | only
4086 let last_bufnr = bufnr('Test_sv_1', 1)
4087 let l = ['Xtestfile1:2:Line2', 'Xtestfile2:4:Line4']
4088 cgetexpr l
4089 copen
4090 let numbufs = len(getbufinfo())
4091 exe "normal \<C-W>\<CR>"
4092 copen
4093 exe "normal j\<C-W>\<CR>"
4094 " Make sure new empty buffers are not created
4095 call assert_equal(numbufs, len(getbufinfo()))
4096 " Creating a new buffer should use the next available buffer number
4097 call assert_equal(last_bufnr + 4, bufnr("Test_sv_2", 1))
4098 bwipe Test_sv_1
4099 bwipe Test_sv_2
4100 new | only
4101
4102 " When split opening files from location list window, make sure that two
4103 " windows doesn't refer to the same location list
4104 lgetexpr l
4105 let locid = getloclist(0, {'id' : 0}).id
4106 lopen
4107 exe "normal \<C-W>\<CR>"
4108 call assert_notequal(locid, getloclist(0, {'id' : 0}).id)
4109 call assert_equal(0, getloclist(0, {'winid' : 0}).winid)
4110 new | only
4111
4112 " When split opening files from a helpgrep location list window, a new help
Bram Moolenaareeb1b9c2019-02-10 22:59:04 +01004113 " window should be opened with a copy of the location list.
Bram Moolenaarb2443732018-11-11 22:50:27 +01004114 lhelpgrep window
4115 let locid = getloclist(0, {'id' : 0}).id
4116 lwindow
4117 exe "normal j\<C-W>\<CR>"
4118 call assert_notequal(locid, getloclist(0, {'id' : 0}).id)
4119 call assert_equal(0, getloclist(0, {'winid' : 0}).winid)
4120 new | only
4121
4122 call delete('Xtestfile1')
4123 call delete('Xtestfile2')
4124endfunc
Bram Moolenaarc45eb772019-01-31 14:27:04 +01004125
4126" Test for parsing entries using visual screen column
4127func Test_viscol()
4128 enew
4129 call writefile(["Col1\tCol2\tCol3"], 'Xfile1')
4130 edit Xfile1
4131
4132 " Use byte offset for column number
4133 set efm&
4134 cexpr "Xfile1:1:5:XX\nXfile1:1:9:YY\nXfile1:1:20:ZZ"
4135 call assert_equal([5, 8], [col('.'), virtcol('.')])
4136 cnext
4137 call assert_equal([9, 12], [col('.'), virtcol('.')])
4138 cnext
4139 call assert_equal([14, 20], [col('.'), virtcol('.')])
4140
4141 " Use screen column offset for column number
4142 set efm=%f:%l:%v:%m
4143 cexpr "Xfile1:1:8:XX\nXfile1:1:12:YY\nXfile1:1:20:ZZ"
4144 call assert_equal([5, 8], [col('.'), virtcol('.')])
4145 cnext
4146 call assert_equal([9, 12], [col('.'), virtcol('.')])
4147 cnext
4148 call assert_equal([14, 20], [col('.'), virtcol('.')])
4149 cexpr "Xfile1:1:6:XX\nXfile1:1:15:YY\nXfile1:1:24:ZZ"
4150 call assert_equal([5, 8], [col('.'), virtcol('.')])
4151 cnext
4152 call assert_equal([10, 16], [col('.'), virtcol('.')])
4153 cnext
4154 call assert_equal([14, 20], [col('.'), virtcol('.')])
4155
4156 enew
4157 call writefile(["Col1\täü\töß\tCol4"], 'Xfile1')
4158
4159 " Use byte offset for column number
4160 set efm&
4161 cexpr "Xfile1:1:8:XX\nXfile1:1:11:YY\nXfile1:1:16:ZZ"
4162 call assert_equal([8, 10], [col('.'), virtcol('.')])
4163 cnext
4164 call assert_equal([11, 17], [col('.'), virtcol('.')])
4165 cnext
4166 call assert_equal([16, 25], [col('.'), virtcol('.')])
4167
4168 " Use screen column offset for column number
4169 set efm=%f:%l:%v:%m
4170 cexpr "Xfile1:1:10:XX\nXfile1:1:17:YY\nXfile1:1:25:ZZ"
4171 call assert_equal([8, 10], [col('.'), virtcol('.')])
4172 cnext
4173 call assert_equal([11, 17], [col('.'), virtcol('.')])
4174 cnext
4175 call assert_equal([16, 25], [col('.'), virtcol('.')])
4176
4177 enew | only
4178 set efm&
4179 call delete('Xfile1')
4180endfunc
Bram Moolenaaree8188f2019-02-05 21:23:04 +01004181
4182" Test for the quickfix window buffer
4183func Xqfbuf_test(cchar)
4184 call s:setup_commands(a:cchar)
4185
4186 " Quickfix buffer should be reused across closing and opening a quickfix
4187 " window
4188 Xexpr "F1:10:Line10"
4189 Xopen
4190 let qfbnum = bufnr('')
4191 Xclose
4192 " Even after the quickfix window is closed, the buffer should be loaded
4193 call assert_true(bufloaded(qfbnum))
Bram Moolenaar647e24b2019-03-17 16:39:46 +01004194 call assert_true(qfbnum, g:Xgetlist({'qfbufnr' : 0}).qfbufnr)
Bram Moolenaaree8188f2019-02-05 21:23:04 +01004195 Xopen
4196 " Buffer should be reused when opening the window again
4197 call assert_equal(qfbnum, bufnr(''))
4198 Xclose
4199
4200 if a:cchar == 'l'
4201 %bwipe
4202 " For a location list, when both the file window and the location list
4203 " window for the list are closed, then the buffer should be freed.
4204 new | only
4205 lexpr "F1:10:Line10"
4206 let wid = win_getid()
4207 lopen
4208 let qfbnum = bufnr('')
4209 call assert_match(qfbnum . ' %a- "\[Location List]"', execute('ls'))
4210 close
4211 " When the location list window is closed, the buffer name should not
4212 " change to 'Quickfix List'
Bram Moolenaar647e24b2019-03-17 16:39:46 +01004213 call assert_match(qfbnum . 'u h- "\[Location List]"', execute('ls!'))
Bram Moolenaaree8188f2019-02-05 21:23:04 +01004214 call assert_true(bufloaded(qfbnum))
4215
Bram Moolenaard82a81c2019-03-02 07:57:18 +01004216 " After deleting a location list buffer using ":bdelete", opening the
4217 " location list window should mark the buffer as a location list buffer.
4218 exe "bdelete " . qfbnum
4219 lopen
4220 call assert_equal("quickfix", &buftype)
4221 call assert_equal(1, getwininfo(win_getid(winnr()))[0].loclist)
4222 call assert_equal(wid, getloclist(0, {'filewinid' : 0}).filewinid)
4223 call assert_false(&swapfile)
4224 lclose
4225
Bram Moolenaareeb1b9c2019-02-10 22:59:04 +01004226 " When the location list is cleared for the window, the buffer should be
4227 " removed
4228 call setloclist(0, [], 'f')
4229 call assert_false(bufexists(qfbnum))
Bram Moolenaar647e24b2019-03-17 16:39:46 +01004230 call assert_equal(0, getloclist(0, {'qfbufnr' : 0}).qfbufnr)
Bram Moolenaareeb1b9c2019-02-10 22:59:04 +01004231
4232 " When the location list is freed with the location list window open, the
4233 " location list buffer should not be lost. It should be reused when the
4234 " location list is again populated.
4235 lexpr "F1:10:Line10"
4236 lopen
4237 let wid = win_getid()
4238 let qfbnum = bufnr('')
4239 wincmd p
4240 call setloclist(0, [], 'f')
4241 lexpr "F1:10:Line10"
4242 lopen
4243 call assert_equal(wid, win_getid())
4244 call assert_equal(qfbnum, bufnr(''))
4245 lclose
4246
4247 " When the window with the location list is closed, the buffer should be
4248 " removed
Bram Moolenaaree8188f2019-02-05 21:23:04 +01004249 new | only
Bram Moolenaareeb1b9c2019-02-10 22:59:04 +01004250 call assert_false(bufexists(qfbnum))
Bram Moolenaaree8188f2019-02-05 21:23:04 +01004251 endif
4252endfunc
4253
4254func Test_qfbuf()
4255 call Xqfbuf_test('c')
4256 call Xqfbuf_test('l')
4257endfunc
Bram Moolenaareeb1b9c2019-02-10 22:59:04 +01004258
4259" If there is an autocmd to use only one window, then opening the location
4260" list window used to crash Vim.
4261func Test_winonly_autocmd()
4262 call s:create_test_file('Xtest1')
4263 " Autocmd to show only one Vim window at a time
4264 autocmd WinEnter * only
4265 new
4266 " Load the location list
4267 lexpr "Xtest1:5:Line5\nXtest1:10:Line10\nXtest1:15:Line15"
4268 let loclistid = getloclist(0, {'id' : 0}).id
4269 " Open the location list window. Only this window will be shown and the file
4270 " window is closed.
4271 lopen
4272 call assert_equal(loclistid, getloclist(0, {'id' : 0}).id)
4273 " Jump to an entry in the location list and make sure that the cursor is
4274 " positioned correctly.
4275 ll 3
4276 call assert_equal(loclistid, getloclist(0, {'id' : 0}).id)
4277 call assert_equal('Xtest1', bufname(''))
4278 call assert_equal(15, line('.'))
4279 " Cleanup
4280 autocmd! WinEnter
4281 new | only
4282 call delete('Xtest1')
4283endfunc
Bram Moolenaar39803d82019-04-07 12:04:51 +02004284
4285" Test to make sure that an empty quickfix buffer is not reused for loading
4286" a normal buffer.
4287func Test_empty_qfbuf()
4288 enew | only
4289 call writefile(["Test"], 'Xfile1')
4290 call setqflist([], 'f')
4291 copen | only
4292 let qfbuf = bufnr('')
4293 edit Xfile1
4294 call assert_notequal(qfbuf, bufnr(''))
4295 enew
4296 call delete('Xfile1')
4297endfunc
Bram Moolenaar3ff33112019-05-03 21:56:35 +02004298
4299" Test for the :cbelow, :cabove, :lbelow and :labove commands.
Bram Moolenaarcf6a55c2019-05-05 15:02:30 +02004300" And for the :cafter, :cbefore, :lafter and :lbefore commands.
Bram Moolenaar3ff33112019-05-03 21:56:35 +02004301func Xtest_below(cchar)
4302 call s:setup_commands(a:cchar)
4303
4304 " No quickfix/location list
4305 call assert_fails('Xbelow', 'E42:')
4306 call assert_fails('Xabove', 'E42:')
Bram Moolenaarcf6a55c2019-05-05 15:02:30 +02004307 call assert_fails('Xbefore', 'E42:')
4308 call assert_fails('Xafter', 'E42:')
Bram Moolenaar3ff33112019-05-03 21:56:35 +02004309
4310 " Empty quickfix/location list
4311 call g:Xsetlist([])
4312 call assert_fails('Xbelow', 'E42:')
4313 call assert_fails('Xabove', 'E42:')
Bram Moolenaarcf6a55c2019-05-05 15:02:30 +02004314 call assert_fails('Xbefore', 'E42:')
4315 call assert_fails('Xafter', 'E42:')
Bram Moolenaar3ff33112019-05-03 21:56:35 +02004316
4317 call s:create_test_file('X1')
4318 call s:create_test_file('X2')
4319 call s:create_test_file('X3')
4320 call s:create_test_file('X4')
4321
4322 " Invalid entries
4323 edit X1
4324 call g:Xsetlist(["E1", "E2"])
4325 call assert_fails('Xbelow', 'E42:')
4326 call assert_fails('Xabove', 'E42:')
4327 call assert_fails('3Xbelow', 'E42:')
4328 call assert_fails('4Xabove', 'E42:')
Bram Moolenaarcf6a55c2019-05-05 15:02:30 +02004329 call assert_fails('Xbefore', 'E42:')
4330 call assert_fails('Xafter', 'E42:')
4331 call assert_fails('3Xbefore', 'E42:')
4332 call assert_fails('4Xafter', 'E42:')
Bram Moolenaar3ff33112019-05-03 21:56:35 +02004333
4334 " Test the commands with various arguments
Bram Moolenaarcf6a55c2019-05-05 15:02:30 +02004335 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 +02004336 edit +7 X2
4337 Xabove
4338 call assert_equal(['X2', 5], [bufname(''), line('.')])
4339 call assert_fails('Xabove', 'E553:')
Bram Moolenaarcf6a55c2019-05-05 15:02:30 +02004340 normal 7G
4341 Xbefore
4342 call assert_equal(['X2', 5, 2], [bufname(''), line('.'), col('.')])
4343 call assert_fails('Xbefore', 'E553:')
4344
Bram Moolenaar3ff33112019-05-03 21:56:35 +02004345 normal 2j
4346 Xbelow
4347 call assert_equal(['X2', 10], [bufname(''), line('.')])
Bram Moolenaarcf6a55c2019-05-05 15:02:30 +02004348 normal 7G
4349 Xafter
4350 call assert_equal(['X2', 10, 3], [bufname(''), line('.'), col('.')])
4351
Bram Moolenaar3ff33112019-05-03 21:56:35 +02004352 " Last error in this file
4353 Xbelow 99
4354 call assert_equal(['X2', 15], [bufname(''), line('.')])
4355 call assert_fails('Xbelow', 'E553:')
Bram Moolenaarcf6a55c2019-05-05 15:02:30 +02004356 normal gg
4357 Xafter 99
4358 call assert_equal(['X2', 15, 4], [bufname(''), line('.'), col('.')])
4359 call assert_fails('Xafter', 'E553:')
4360
Bram Moolenaar3ff33112019-05-03 21:56:35 +02004361 " First error in this file
4362 Xabove 99
4363 call assert_equal(['X2', 5], [bufname(''), line('.')])
4364 call assert_fails('Xabove', 'E553:')
Bram Moolenaarcf6a55c2019-05-05 15:02:30 +02004365 normal G
4366 Xbefore 99
4367 call assert_equal(['X2', 5, 2], [bufname(''), line('.'), col('.')])
4368 call assert_fails('Xbefore', 'E553:')
4369
Bram Moolenaar3ff33112019-05-03 21:56:35 +02004370 normal gg
4371 Xbelow 2
4372 call assert_equal(['X2', 10], [bufname(''), line('.')])
Bram Moolenaarcf6a55c2019-05-05 15:02:30 +02004373 normal gg
4374 Xafter 2
4375 call assert_equal(['X2', 10, 3], [bufname(''), line('.'), col('.')])
4376
Bram Moolenaar3ff33112019-05-03 21:56:35 +02004377 normal G
4378 Xabove 2
4379 call assert_equal(['X2', 10], [bufname(''), line('.')])
Bram Moolenaarcf6a55c2019-05-05 15:02:30 +02004380 normal G
4381 Xbefore 2
4382 call assert_equal(['X2', 10, 3], [bufname(''), line('.'), col('.')])
4383
Bram Moolenaar3ff33112019-05-03 21:56:35 +02004384 edit X4
4385 call assert_fails('Xabove', 'E42:')
4386 call assert_fails('Xbelow', 'E42:')
Bram Moolenaarcf6a55c2019-05-05 15:02:30 +02004387 call assert_fails('Xbefore', 'E42:')
4388 call assert_fails('Xafter', 'E42:')
Bram Moolenaar3ff33112019-05-03 21:56:35 +02004389 if a:cchar == 'l'
4390 " If a buffer has location list entries from some other window but not
4391 " from the current window, then the commands should fail.
4392 edit X1 | split | call setloclist(0, [], 'f')
4393 call assert_fails('Xabove', 'E776:')
4394 call assert_fails('Xbelow', 'E776:')
Bram Moolenaarcf6a55c2019-05-05 15:02:30 +02004395 call assert_fails('Xbefore', 'E776:')
4396 call assert_fails('Xafter', 'E776:')
Bram Moolenaar3ff33112019-05-03 21:56:35 +02004397 close
4398 endif
4399
4400 " Test for lines with multiple quickfix entries
4401 Xexpr ["X1:5:L5", "X2:5:1:L5_1", "X2:5:2:L5_2", "X2:5:3:L5_3",
4402 \ "X2:10:1:L10_1", "X2:10:2:L10_2", "X2:10:3:L10_3",
4403 \ "X2:15:1:L15_1", "X2:15:2:L15_2", "X2:15:3:L15_3", "X3:3:L3"]
4404 edit +1 X2
4405 Xbelow 2
4406 call assert_equal(['X2', 10, 1], [bufname(''), line('.'), col('.')])
Bram Moolenaarcf6a55c2019-05-05 15:02:30 +02004407 normal 1G
4408 Xafter 2
4409 call assert_equal(['X2', 5, 2], [bufname(''), line('.'), col('.')])
4410
Bram Moolenaar3ff33112019-05-03 21:56:35 +02004411 normal gg
4412 Xbelow 99
4413 call assert_equal(['X2', 15, 1], [bufname(''), line('.'), col('.')])
Bram Moolenaarcf6a55c2019-05-05 15:02:30 +02004414 normal gg
4415 Xafter 99
4416 call assert_equal(['X2', 15, 3], [bufname(''), line('.'), col('.')])
4417
Bram Moolenaar3ff33112019-05-03 21:56:35 +02004418 normal G
4419 Xabove 2
4420 call assert_equal(['X2', 10, 1], [bufname(''), line('.'), col('.')])
4421 normal G
Bram Moolenaarcf6a55c2019-05-05 15:02:30 +02004422 Xbefore 2
4423 call assert_equal(['X2', 15, 2], [bufname(''), line('.'), col('.')])
4424
4425 normal G
Bram Moolenaar3ff33112019-05-03 21:56:35 +02004426 Xabove 99
4427 call assert_equal(['X2', 5, 1], [bufname(''), line('.'), col('.')])
Bram Moolenaarcf6a55c2019-05-05 15:02:30 +02004428 normal G
4429 Xbefore 99
4430 call assert_equal(['X2', 5, 1], [bufname(''), line('.'), col('.')])
4431
Bram Moolenaar3ff33112019-05-03 21:56:35 +02004432 normal 10G
4433 Xabove
4434 call assert_equal(['X2', 5, 1], [bufname(''), line('.'), col('.')])
Bram Moolenaarcf6a55c2019-05-05 15:02:30 +02004435 normal 10G$
4436 2Xbefore
4437 call assert_equal(['X2', 10, 2], [bufname(''), line('.'), col('.')])
4438
Bram Moolenaar3ff33112019-05-03 21:56:35 +02004439 normal 10G
4440 Xbelow
4441 call assert_equal(['X2', 15, 1], [bufname(''), line('.'), col('.')])
Bram Moolenaarcf6a55c2019-05-05 15:02:30 +02004442 normal 9G
4443 5Xafter
4444 call assert_equal(['X2', 15, 2], [bufname(''), line('.'), col('.')])
Bram Moolenaar3ff33112019-05-03 21:56:35 +02004445
4446 " Invalid range
4447 if a:cchar == 'c'
Bram Moolenaar25190db2019-05-04 15:05:28 +02004448 call assert_fails('-2cbelow', 'E16:')
Bram Moolenaarcf6a55c2019-05-05 15:02:30 +02004449 call assert_fails('-2cafter', 'E16:')
Bram Moolenaar3ff33112019-05-03 21:56:35 +02004450 else
Bram Moolenaar25190db2019-05-04 15:05:28 +02004451 call assert_fails('-2lbelow', 'E16:')
Bram Moolenaarcf6a55c2019-05-05 15:02:30 +02004452 call assert_fails('-2lafter', 'E16:')
Bram Moolenaar3ff33112019-05-03 21:56:35 +02004453 endif
4454
4455 call delete('X1')
4456 call delete('X2')
4457 call delete('X3')
4458 call delete('X4')
4459endfunc
4460
4461func Test_cbelow()
4462 call Xtest_below('c')
4463 call Xtest_below('l')
4464endfunc
Bram Moolenaar25190db2019-05-04 15:05:28 +02004465
4466func Test_quickfix_count()
4467 let commands = [
4468 \ 'cNext',
4469 \ 'cNfile',
4470 \ 'cabove',
4471 \ 'cbelow',
4472 \ 'cfirst',
4473 \ 'clast',
4474 \ 'cnewer',
4475 \ 'cnext',
4476 \ 'cnfile',
4477 \ 'colder',
4478 \ 'cprevious',
4479 \ 'crewind',
4480 \
4481 \ 'lNext',
4482 \ 'lNfile',
4483 \ 'labove',
4484 \ 'lbelow',
4485 \ 'lfirst',
4486 \ 'llast',
4487 \ 'lnewer',
4488 \ 'lnext',
4489 \ 'lnfile',
4490 \ 'lolder',
4491 \ 'lprevious',
4492 \ 'lrewind',
4493 \ ]
4494 for cmd in commands
4495 call assert_fails('-1' .. cmd, 'E16:')
4496 call assert_fails('.' .. cmd, 'E16:')
4497 call assert_fails('%' .. cmd, 'E16:')
4498 call assert_fails('$' .. cmd, 'E16:')
4499 endfor
4500endfunc
Bram Moolenaar6a0cc912019-10-26 16:48:44 +02004501
4502" Test for aborting quickfix commands using QuickFixCmdPre
4503func Xtest_qfcmd_abort(cchar)
4504 call s:setup_commands(a:cchar)
4505
4506 call g:Xsetlist([], 'f')
4507
4508 " cexpr/lexpr
4509 let e = ''
4510 try
4511 Xexpr ["F1:10:Line10", "F2:20:Line20"]
4512 catch /.*/
4513 let e = v:exception
4514 endtry
4515 call assert_equal('AbortCmd', e)
4516 call assert_equal(0, g:Xgetlist({'nr' : '$'}).nr)
4517
4518 " cfile/lfile
4519 call writefile(["F1:10:Line10", "F2:20:Line20"], 'Xfile1')
4520 let e = ''
4521 try
4522 Xfile Xfile1
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 call delete('Xfile1')
4529
4530 " cgetbuffer/lgetbuffer
4531 enew!
4532 call append(0, ["F1:10:Line10", "F2:20:Line20"])
4533 let e = ''
4534 try
4535 Xgetbuffer
4536 catch /.*/
4537 let e = v:exception
4538 endtry
4539 call assert_equal('AbortCmd', e)
4540 call assert_equal(0, g:Xgetlist({'nr' : '$'}).nr)
4541 enew!
4542
4543 " vimgrep/lvimgrep
4544 let e = ''
4545 try
4546 Xvimgrep /func/ test_quickfix.vim
4547 catch /.*/
4548 let e = v:exception
4549 endtry
4550 call assert_equal('AbortCmd', e)
4551 call assert_equal(0, g:Xgetlist({'nr' : '$'}).nr)
4552
4553 " helpgrep/lhelpgrep
4554 let e = ''
4555 try
4556 Xhelpgrep quickfix
4557 catch /.*/
4558 let e = v:exception
4559 endtry
4560 call assert_equal('AbortCmd', e)
4561 call assert_equal(0, g:Xgetlist({'nr' : '$'}).nr)
4562
4563 " grep/lgrep
4564 if has('unix')
4565 let e = ''
4566 try
4567 silent Xgrep func test_quickfix.vim
4568 catch /.*/
4569 let e = v:exception
4570 endtry
4571 call assert_equal('AbortCmd', e)
4572 call assert_equal(0, g:Xgetlist({'nr' : '$'}).nr)
4573 endif
4574endfunc
4575
4576func Test_qfcmd_abort()
4577 augroup QF_Test
4578 au!
4579 autocmd QuickFixCmdPre * throw "AbortCmd"
4580 augroup END
4581
4582 call Xtest_qfcmd_abort('c')
4583 call Xtest_qfcmd_abort('l')
4584
4585 augroup QF_Test
4586 au!
4587 augroup END
4588endfunc
4589
Bram Moolenaard8a8c4c2019-11-16 21:04:57 +01004590" Test for using a file in one of the parent directories.
4591func Test_search_in_dirstack()
4592 call mkdir('Xtestdir/a/b/c', 'p')
4593 let save_cwd = getcwd()
4594 call writefile(["X1_L1", "X1_L2"], 'Xtestdir/Xfile1')
4595 call writefile(["X2_L1", "X2_L2"], 'Xtestdir/a/Xfile2')
4596 call writefile(["X3_L1", "X3_L2"], 'Xtestdir/a/b/Xfile3')
4597 call writefile(["X4_L1", "X4_L2"], 'Xtestdir/a/b/c/Xfile4')
4598
4599 let lines = "Entering dir Xtestdir\n" .
4600 \ "Entering dir a\n" .
4601 \ "Entering dir b\n" .
4602 \ "Xfile2:2:X2_L2\n" .
4603 \ "Leaving dir a\n" .
4604 \ "Xfile1:2:X1_L2\n" .
4605 \ "Xfile3:1:X3_L1\n" .
4606 \ "Entering dir c\n" .
4607 \ "Xfile4:2:X4_L2\n" .
4608 \ "Leaving dir c\n" .
4609 \ "Leaving dir Xtestdir\n"
4610 set efm=%DEntering\ dir\ %f,%XLeaving\ dir\ %f,%f:%l:%m
4611 cexpr lines
4612 call assert_equal(11, getqflist({'size' : 0}).size)
4613 call assert_equal(4, getqflist({'idx' : 0}).idx)
4614 call assert_equal('X2_L2', getline('.'))
4615 cnext
4616 call assert_equal(6, getqflist({'idx' : 0}).idx)
4617 call assert_equal('X1_L2', getline('.'))
4618 cnext
4619 call assert_equal(7, getqflist({'idx' : 0}).idx)
4620 call assert_equal(1, line('$'))
4621 call assert_equal('', getline(1))
4622 cnext
4623 call assert_equal(9, getqflist({'idx' : 0}).idx)
4624 call assert_equal(1, line('$'))
4625 call assert_equal('', getline(1))
4626
4627 set efm&
4628 exe 'cd ' . save_cwd
4629 call delete('Xtestdir', 'rf')
4630endfunc
4631
Bram Moolenaar6a0cc912019-10-26 16:48:44 +02004632" vim: shiftwidth=2 sts=2 expandtab