blob: d31650f2632aaf09db3385e4f65dc5446aabc3a5 [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 Moolenaara106e6c2019-11-24 22:13:58 +0100629 " See jump_to_help_window() for details
630 let w2_width = winwidth(w2)
631 if w2_width != &columns && w2_width < 80
632 call assert_equal(['col', [['leaf', w3],
633 \ ['row', [['leaf', w2], ['leaf', w1]]]]], winlayout())
634 else
635 call assert_equal(['row', [['col', [['leaf', w3], ['leaf', w2]]],
636 \ ['leaf', w1]]] , winlayout())
637 endif
Bram Moolenaarf9ae1542019-11-18 22:02:16 +0100638
639 new | only
640 set buftype=help
641 set modified
642 call assert_fails('Xnext', 'E37:')
643 set nomodified
644 new | only
645
Bram Moolenaarb4d5fba2017-09-11 19:31:28 +0200646 if a:cchar == 'l'
647 " When a help window is present, running :lhelpgrep should reuse the
648 " help window and not the current window
649 new | only
650 call g:Xsetlist([], 'f')
651 help index.txt
652 wincmd w
653 lhelpgrep quickfix
654 call assert_equal(1, winnr())
655 call assert_notequal([], getloclist(1))
656 call assert_equal([], getloclist(2))
657 endif
658
Bram Moolenaar99895ea2017-04-20 22:44:47 +0200659 new | only
660
Bram Moolenaaree85df32017-03-19 14:19:50 +0100661 " Search for non existing help string
662 call assert_fails('Xhelpgrep a1b2c3', 'E480:')
Bram Moolenaar108e7b42018-10-11 17:39:12 +0200663 " Invalid regular expression
664 call assert_fails('Xhelpgrep \@<!', 'E480:')
Bram Moolenaar2b946c92016-11-12 18:14:44 +0100665endfunc
Bram Moolenaar049cba92016-06-26 14:38:04 +0200666
Bram Moolenaar2b946c92016-11-12 18:14:44 +0100667func Test_helpgrep()
Bram Moolenaar049cba92016-06-26 14:38:04 +0200668 call s:test_xhelpgrep('c')
Bram Moolenaarcf25fdb2016-08-03 21:04:53 +0200669 helpclose
Bram Moolenaar049cba92016-06-26 14:38:04 +0200670 call s:test_xhelpgrep('l')
Bram Moolenaar62ef7972016-01-19 14:51:54 +0100671endfunc
Bram Moolenaar75bdf6a2016-01-07 21:25:08 +0100672
Bram Moolenaar6920c722016-01-22 22:44:10 +0100673func Test_errortitle()
674 augroup QfBufWinEnter
675 au!
676 au BufWinEnter * :let g:a=get(w:, 'quickfix_title', 'NONE')
677 augroup END
678 copen
679 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'')'}]
680 call setqflist(a)
681 call assert_equal(':setqflist()', g:a)
682 augroup QfBufWinEnter
683 au!
684 augroup END
685 augroup! QfBufWinEnter
686endfunc
Bram Moolenaare27dba42016-03-15 14:11:10 +0100687
Bram Moolenaar5584df62016-03-18 21:00:51 +0100688func Test_vimgreptitle()
689 augroup QfBufWinEnter
690 au!
691 au BufWinEnter * :let g:a=get(w:, 'quickfix_title', 'NONE')
692 augroup END
693 try
694 vimgrep /pattern/j file
695 catch /E480/
696 endtry
697 copen
698 call assert_equal(': vimgrep /pattern/j file', g:a)
699 augroup QfBufWinEnter
700 au!
701 augroup END
702 augroup! QfBufWinEnter
703endfunc
704
Bram Moolenaar2b946c92016-11-12 18:14:44 +0100705func XqfTitleTests(cchar)
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +0200706 call s:setup_commands(a:cchar)
Bram Moolenaare27dba42016-03-15 14:11:10 +0100707
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +0200708 Xgetexpr ['file:1:1:message']
709 let l = g:Xgetlist()
Bram Moolenaare27dba42016-03-15 14:11:10 +0100710 if a:cchar == 'c'
711 call setqflist(l, 'r')
712 else
713 call setloclist(0, l, 'r')
714 endif
715
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +0200716 Xopen
Bram Moolenaare27dba42016-03-15 14:11:10 +0100717 if a:cchar == 'c'
718 let title = ':setqflist()'
719 else
720 let title = ':setloclist()'
721 endif
722 call assert_equal(title, w:quickfix_title)
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +0200723 Xclose
Bram Moolenaar2b946c92016-11-12 18:14:44 +0100724endfunc
Bram Moolenaare27dba42016-03-15 14:11:10 +0100725
726" Tests for quickfix window's title
Bram Moolenaar2b946c92016-11-12 18:14:44 +0100727func Test_qf_title()
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +0200728 call XqfTitleTests('c')
729 call XqfTitleTests('l')
Bram Moolenaar2b946c92016-11-12 18:14:44 +0100730endfunc
Bram Moolenaare27dba42016-03-15 14:11:10 +0100731
732" Tests for 'errorformat'
Bram Moolenaar2b946c92016-11-12 18:14:44 +0100733func Test_efm()
Bram Moolenaare27dba42016-03-15 14:11:10 +0100734 let save_efm = &efm
735 set efm=%EEEE%m,%WWWW%m,%+CCCC%.%#,%-GGGG%.%#
736 cgetexpr ['WWWW', 'EEEE', 'CCCC']
737 let l = strtrans(string(map(getqflist(), '[v:val.text, v:val.valid]')))
738 call assert_equal("[['W', 1], ['E^@CCCC', 1]]", l)
739 cgetexpr ['WWWW', 'GGGG', 'EEEE', 'CCCC']
740 let l = strtrans(string(map(getqflist(), '[v:val.text, v:val.valid]')))
741 call assert_equal("[['W', 1], ['E^@CCCC', 1]]", l)
742 cgetexpr ['WWWW', 'GGGG', 'ZZZZ', 'EEEE', 'CCCC', 'YYYY']
743 let l = strtrans(string(map(getqflist(), '[v:val.text, v:val.valid]')))
744 call assert_equal("[['W', 1], ['ZZZZ', 0], ['E^@CCCC', 1], ['YYYY', 0]]", l)
745 let &efm = save_efm
Bram Moolenaar2b946c92016-11-12 18:14:44 +0100746endfunc
Bram Moolenaar1ff2b642016-03-17 22:07:02 +0100747
748" This will test for problems in quickfix:
749" A. incorrectly copying location lists which caused the location list to show
750" a different name than the file that was actually being displayed.
751" B. not reusing the window for which the location list window is opened but
752" instead creating new windows.
753" C. make sure that the location list window is not reused instead of the
754" window it belongs to.
755"
756" Set up the test environment:
Bram Moolenaar2b946c92016-11-12 18:14:44 +0100757func ReadTestProtocol(name)
Bram Moolenaar1ff2b642016-03-17 22:07:02 +0100758 let base = substitute(a:name, '\v^test://(.*)%(\.[^.]+)?', '\1', '')
759 let word = substitute(base, '\v(.*)\..*', '\1', '')
760
761 setl modifiable
762 setl noreadonly
763 setl noswapfile
764 setl bufhidden=delete
765 %del _
766 " For problem 2:
767 " 'buftype' has to be set to reproduce the constant opening of new windows
768 setl buftype=nofile
769
770 call setline(1, word)
771
772 setl nomodified
773 setl nomodifiable
774 setl readonly
775 exe 'doautocmd BufRead ' . substitute(a:name, '\v^test://(.*)', '\1', '')
Bram Moolenaar2b946c92016-11-12 18:14:44 +0100776endfunc
Bram Moolenaar1ff2b642016-03-17 22:07:02 +0100777
Bram Moolenaar2b946c92016-11-12 18:14:44 +0100778func Test_locationlist()
Bram Moolenaar1ff2b642016-03-17 22:07:02 +0100779 enew
780
781 augroup testgroup
782 au!
783 autocmd BufReadCmd test://* call ReadTestProtocol(expand("<amatch>"))
784 augroup END
785
786 let words = [ "foo", "bar", "baz", "quux", "shmoo", "spam", "eggs" ]
787
788 let qflist = []
789 for word in words
790 call add(qflist, {'filename': 'test://' . word . '.txt', 'text': 'file ' . word . '.txt', })
791 " NOTE: problem 1:
792 " intentionally not setting 'lnum' so that the quickfix entries are not
793 " valid
Bram Moolenaaraad222c2019-09-06 22:46:09 +0200794 eval qflist->setloclist(0, ' ')
Bram Moolenaar1ff2b642016-03-17 22:07:02 +0100795 endfor
796
797 " Test A
798 lrewind
799 enew
800 lopen
Bram Moolenaar99895ea2017-04-20 22:44:47 +0200801 4lnext
Bram Moolenaar1ff2b642016-03-17 22:07:02 +0100802 vert split
803 wincmd L
804 lopen
805 wincmd p
806 lnext
807 let fileName = expand("%")
808 wincmd p
809 let locationListFileName = substitute(getline(line('.')), '\([^|]*\)|.*', '\1', '')
810 let fileName = substitute(fileName, '\\', '/', 'g')
811 let locationListFileName = substitute(locationListFileName, '\\', '/', 'g')
812 call assert_equal("test://bar.txt", fileName)
813 call assert_equal("test://bar.txt", locationListFileName)
814
815 wincmd n | only
816
817 " Test B:
818 lrewind
819 lopen
820 2
821 exe "normal \<CR>"
822 wincmd p
823 3
824 exe "normal \<CR>"
825 wincmd p
826 4
827 exe "normal \<CR>"
828 call assert_equal(2, winnr('$'))
829 wincmd n | only
830
831 " Test C:
832 lrewind
833 lopen
834 " Let's move the location list window to the top to check whether it (the
835 " first window found) will be reused when we try to open new windows:
836 wincmd K
837 2
838 exe "normal \<CR>"
839 wincmd p
840 3
841 exe "normal \<CR>"
842 wincmd p
843 4
844 exe "normal \<CR>"
845 1wincmd w
846 call assert_equal('quickfix', &buftype)
847 2wincmd w
848 let bufferName = expand("%")
849 let bufferName = substitute(bufferName, '\\', '/', 'g')
850 call assert_equal('test://quux.txt', bufferName)
851
852 wincmd n | only
853
854 augroup! testgroup
Bram Moolenaaree85df32017-03-19 14:19:50 +0100855endfunc
Bram Moolenaar0899d692016-03-19 13:35:03 +0100856
Bram Moolenaar2b946c92016-11-12 18:14:44 +0100857func Test_locationlist_curwin_was_closed()
Bram Moolenaar0899d692016-03-19 13:35:03 +0100858 augroup testgroup
859 au!
Bram Moolenaard106e5b2016-04-21 19:38:07 +0200860 autocmd BufReadCmd test_curwin.txt call R(expand("<amatch>"))
Bram Moolenaar0899d692016-03-19 13:35:03 +0100861 augroup END
862
Bram Moolenaar2b946c92016-11-12 18:14:44 +0100863 func! R(n)
Bram Moolenaar0899d692016-03-19 13:35:03 +0100864 quit
865 endfunc
866
867 new
868 let q = []
Bram Moolenaard106e5b2016-04-21 19:38:07 +0200869 call add(q, {'filename': 'test_curwin.txt' })
Bram Moolenaar0899d692016-03-19 13:35:03 +0100870 call setloclist(0, q)
871 call assert_fails('lrewind', 'E924:')
872
873 augroup! testgroup
Bram Moolenaaree85df32017-03-19 14:19:50 +0100874endfunc
Bram Moolenaar7eba3d22016-03-19 22:54:09 +0100875
Bram Moolenaar2b946c92016-11-12 18:14:44 +0100876func Test_locationlist_cross_tab_jump()
Bram Moolenaar0a9046f2016-10-15 19:28:13 +0200877 call writefile(['loclistfoo'], 'loclistfoo')
878 call writefile(['loclistbar'], 'loclistbar')
879 set switchbuf=usetab
880
881 edit loclistfoo
882 tabedit loclistbar
883 silent lgrep loclistfoo loclist*
884 call assert_equal(1, tabpagenr())
885
886 enew | only | tabonly
887 set switchbuf&vim
888 call delete('loclistfoo')
889 call delete('loclistbar')
Bram Moolenaar2b946c92016-11-12 18:14:44 +0100890endfunc
Bram Moolenaar0a9046f2016-10-15 19:28:13 +0200891
Bram Moolenaar7eba3d22016-03-19 22:54:09 +0100892" More tests for 'errorformat'
Bram Moolenaar2b946c92016-11-12 18:14:44 +0100893func Test_efm1()
Bram Moolenaar7eba3d22016-03-19 22:54:09 +0100894 if !has('unix')
895 " The 'errorformat' setting is different on non-Unix systems.
896 " This test works only on Unix-like systems.
897 return
898 endif
899
Bram Moolenaarc79745a2019-05-20 22:12:34 +0200900 let l =<< trim [DATA]
Bram Moolenaare7eb9272019-06-24 00:58:07 +0200901 "Xtestfile", line 4.12: 1506-045 (S) Undeclared identifier fd_set.
902 "Xtestfile", line 6 col 19; this is an error
903 gcc -c -DHAVE_CONFIsing-prototypes -I/usr/X11R6/include version.c
904 Xtestfile:9: parse error before `asd'
905 make: *** [vim] Error 1
906 in file "Xtestfile" linenr 10: there is an error
907
908 2 returned
909 "Xtestfile", line 11 col 1; this is an error
910 "Xtestfile", line 12 col 2; this is another error
911 "Xtestfile", line 14:10; this is an error in column 10
912 =Xtestfile=, line 15:10; this is another error, but in vcol 10 this time
913 "Xtestfile", linenr 16: yet another problem
914 Error in "Xtestfile" at line 17:
915 x should be a dot
916 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 17
917 ^
918 Error in "Xtestfile" at line 18:
919 x should be a dot
920 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 18
921 .............^
922 Error in "Xtestfile" at line 19:
923 x should be a dot
924 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 19
925 --------------^
926 Error in "Xtestfile" at line 20:
927 x should be a dot
928 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 20
929 ^
930
931 Does anyone know what is the problem and how to correction it?
932 "Xtestfile", line 21 col 9: What is the title of the quickfix window?
933 "Xtestfile", line 22 col 9: What is the title of the quickfix window?
Bram Moolenaarc79745a2019-05-20 22:12:34 +0200934 [DATA]
Bram Moolenaar7eba3d22016-03-19 22:54:09 +0100935
936 call writefile(l, 'Xerrorfile1')
937 call writefile(l[:-2], 'Xerrorfile2')
938
Bram Moolenaare7eb9272019-06-24 00:58:07 +0200939 let m =<< [DATA]
940 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 2
941 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 3
942 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 4
943 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 5
944 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 6
945 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 7
946 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 8
947 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 9
948 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 10
949 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 11
950 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 12
951 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 13
952 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 14
953 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 15
954 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 16
955 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 17
956 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 18
957 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 19
958 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 20
959 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 21
960 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 22
961[DATA]
Bram Moolenaar7eba3d22016-03-19 22:54:09 +0100962 call writefile(m, 'Xtestfile')
963
964 let save_efm = &efm
965 set efm+==%f=\\,\ line\ %l%*\\D%v%*[^\ ]\ %m
966 set efm^=%AError\ in\ \"%f\"\ at\ line\ %l:,%Z%p^,%C%m
967
968 exe 'cf Xerrorfile2'
969 clast
970 copen
971 call assert_equal(':cf Xerrorfile2', w:quickfix_title)
972 wincmd p
973
974 exe 'cf Xerrorfile1'
975 call assert_equal([4, 12], [line('.'), col('.')])
976 cn
977 call assert_equal([6, 19], [line('.'), col('.')])
978 cn
979 call assert_equal([9, 2], [line('.'), col('.')])
980 cn
981 call assert_equal([10, 2], [line('.'), col('.')])
982 cn
983 call assert_equal([11, 1], [line('.'), col('.')])
984 cn
985 call assert_equal([12, 2], [line('.'), col('.')])
986 cn
987 call assert_equal([14, 10], [line('.'), col('.')])
988 cn
989 call assert_equal([15, 3, 10], [line('.'), col('.'), virtcol('.')])
990 cn
991 call assert_equal([16, 2], [line('.'), col('.')])
992 cn
993 call assert_equal([17, 6], [line('.'), col('.')])
994 cn
995 call assert_equal([18, 7], [line('.'), col('.')])
996 cn
997 call assert_equal([19, 8], [line('.'), col('.')])
998 cn
999 call assert_equal([20, 9], [line('.'), col('.')])
1000 clast
1001 cprev
1002 cprev
1003 wincmd w
1004 call assert_equal(':cf Xerrorfile1', w:quickfix_title)
1005 wincmd p
1006
1007 let &efm = save_efm
1008 call delete('Xerrorfile1')
1009 call delete('Xerrorfile2')
1010 call delete('Xtestfile')
Bram Moolenaaree85df32017-03-19 14:19:50 +01001011endfunc
Bram Moolenaarffec3c52016-03-23 20:55:42 +01001012
Bram Moolenaarab47c612016-06-14 22:02:26 +02001013" Test for quickfix directory stack support
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001014func s:dir_stack_tests(cchar)
Bram Moolenaar38df43b2016-06-20 21:41:12 +02001015 call s:setup_commands(a:cchar)
1016
Bram Moolenaarab47c612016-06-14 22:02:26 +02001017 let save_efm=&efm
1018 set efm=%DEntering\ dir\ '%f',%f:%l:%m,%XLeaving\ dir\ '%f'
1019
Bram Moolenaar361c8f02016-07-02 15:41:47 +02001020 let lines = ["Entering dir 'dir1/a'",
1021 \ 'habits2.txt:1:Nine Healthy Habits',
1022 \ "Entering dir 'b'",
1023 \ 'habits3.txt:2:0 Hours of television',
1024 \ 'habits2.txt:7:5 Small meals',
1025 \ "Entering dir 'dir1/c'",
1026 \ 'habits4.txt:3:1 Hour of exercise',
1027 \ "Leaving dir 'dir1/c'",
1028 \ "Leaving dir 'dir1/a'",
1029 \ 'habits1.txt:4:2 Liters of water',
1030 \ "Entering dir 'dir2'",
1031 \ 'habits5.txt:5:3 Cups of hot green tea',
1032 \ "Leaving dir 'dir2'"
1033 \]
Bram Moolenaarab47c612016-06-14 22:02:26 +02001034
Bram Moolenaar361c8f02016-07-02 15:41:47 +02001035 Xexpr ""
1036 for l in lines
1037 Xaddexpr l
1038 endfor
Bram Moolenaarab47c612016-06-14 22:02:26 +02001039
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001040 let qf = g:Xgetlist()
Bram Moolenaarab47c612016-06-14 22:02:26 +02001041
1042 call assert_equal('dir1/a/habits2.txt', bufname(qf[1].bufnr))
1043 call assert_equal(1, qf[1].lnum)
1044 call assert_equal('dir1/a/b/habits3.txt', bufname(qf[3].bufnr))
1045 call assert_equal(2, qf[3].lnum)
1046 call assert_equal('dir1/a/habits2.txt', bufname(qf[4].bufnr))
1047 call assert_equal(7, qf[4].lnum)
1048 call assert_equal('dir1/c/habits4.txt', bufname(qf[6].bufnr))
1049 call assert_equal(3, qf[6].lnum)
1050 call assert_equal('habits1.txt', bufname(qf[9].bufnr))
1051 call assert_equal(4, qf[9].lnum)
1052 call assert_equal('dir2/habits5.txt', bufname(qf[11].bufnr))
1053 call assert_equal(5, qf[11].lnum)
1054
1055 let &efm=save_efm
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001056endfunc
Bram Moolenaarab47c612016-06-14 22:02:26 +02001057
1058" Tests for %D and %X errorformat options
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001059func Test_efm_dirstack()
Bram Moolenaarab47c612016-06-14 22:02:26 +02001060 " Create the directory stack and files
1061 call mkdir('dir1')
1062 call mkdir('dir1/a')
1063 call mkdir('dir1/a/b')
1064 call mkdir('dir1/c')
1065 call mkdir('dir2')
1066
1067 let lines = ["Nine Healthy Habits",
1068 \ "0 Hours of television",
1069 \ "1 Hour of exercise",
1070 \ "2 Liters of water",
1071 \ "3 Cups of hot green tea",
1072 \ "4 Short mental breaks",
1073 \ "5 Small meals",
1074 \ "6 AM wake up time",
1075 \ "7 Minutes of laughter",
1076 \ "8 Hours of sleep (at least)",
1077 \ "9 PM end of the day and off to bed"
1078 \ ]
1079 call writefile(lines, 'habits1.txt')
1080 call writefile(lines, 'dir1/a/habits2.txt')
1081 call writefile(lines, 'dir1/a/b/habits3.txt')
1082 call writefile(lines, 'dir1/c/habits4.txt')
1083 call writefile(lines, 'dir2/habits5.txt')
1084
1085 call s:dir_stack_tests('c')
1086 call s:dir_stack_tests('l')
1087
1088 call delete('dir1', 'rf')
1089 call delete('dir2', 'rf')
1090 call delete('habits1.txt')
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001091endfunc
Bram Moolenaarab47c612016-06-14 22:02:26 +02001092
Bram Moolenaar9b457942016-10-09 16:10:05 +02001093" Test for resync after continuing an ignored message
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001094func Xefm_ignore_continuations(cchar)
Bram Moolenaar9b457942016-10-09 16:10:05 +02001095 call s:setup_commands(a:cchar)
1096
1097 let save_efm = &efm
1098
1099 let &efm =
1100 \ '%Eerror %m %l,' .
1101 \ '%-Wignored %m %l,' .
1102 \ '%+Cmore ignored %m %l,' .
1103 \ '%Zignored end'
1104 Xgetexpr ['ignored warning 1', 'more ignored continuation 2', 'ignored end', 'error resync 4']
1105 let l = map(g:Xgetlist(), '[v:val.text, v:val.valid, v:val.lnum, v:val.type]')
1106 call assert_equal([['resync', 1, 4, 'E']], l)
1107
1108 let &efm = save_efm
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001109endfunc
Bram Moolenaar9b457942016-10-09 16:10:05 +02001110
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001111func Test_efm_ignore_continuations()
Bram Moolenaar9b457942016-10-09 16:10:05 +02001112 call Xefm_ignore_continuations('c')
1113 call Xefm_ignore_continuations('l')
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001114endfunc
Bram Moolenaar9b457942016-10-09 16:10:05 +02001115
Bram Moolenaar0fcc7c62016-07-02 21:22:52 +02001116" Tests for invalid error format specifies
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001117func Xinvalid_efm_Tests(cchar)
Bram Moolenaar0fcc7c62016-07-02 21:22:52 +02001118 call s:setup_commands(a:cchar)
1119
Bram Moolenaar049cba92016-06-26 14:38:04 +02001120 let save_efm = &efm
1121
Bram Moolenaar0fcc7c62016-07-02 21:22:52 +02001122 set efm=%f:%l:%m,%f:%f:%l:%m
1123 call assert_fails('Xexpr "abc.txt:1:Hello world"', 'E372:')
1124
1125 set efm=%f:%l:%m,%f:%l:%r:%m
1126 call assert_fails('Xexpr "abc.txt:1:Hello world"', 'E373:')
1127
1128 set efm=%f:%l:%m,%O:%f:%l:%m
1129 call assert_fails('Xexpr "abc.txt:1:Hello world"', 'E373:')
1130
1131 set efm=%f:%l:%m,%f:%l:%*[^a-z
1132 call assert_fails('Xexpr "abc.txt:1:Hello world"', 'E374:')
1133
1134 set efm=%f:%l:%m,%f:%l:%*c
1135 call assert_fails('Xexpr "abc.txt:1:Hello world"', 'E375:')
1136
1137 set efm=%f:%l:%m,%L%M%N
1138 call assert_fails('Xexpr "abc.txt:1:Hello world"', 'E376:')
1139
1140 set efm=%f:%l:%m,%f:%l:%m:%R
1141 call assert_fails('Xexpr "abc.txt:1:Hello world"', 'E377:')
1142
Bram Moolenaar70077dd2019-11-24 12:12:42 +01001143 " Invalid regular expression
1144 set efm=%\\%%k
1145 call assert_fails('Xexpr "abc.txt:1:Hello world"', 'E867:')
1146
Bram Moolenaar0fcc7c62016-07-02 21:22:52 +02001147 set efm=
1148 call assert_fails('Xexpr "abc.txt:1:Hello world"', 'E378:')
1149
1150 set efm=%DEntering\ dir\ abc,%f:%l:%m
1151 call assert_fails('Xexpr ["Entering dir abc", "abc.txt:1:Hello world"]', 'E379:')
1152
1153 let &efm = save_efm
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001154endfunc
Bram Moolenaar0fcc7c62016-07-02 21:22:52 +02001155
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001156func Test_invalid_efm()
Bram Moolenaar0fcc7c62016-07-02 21:22:52 +02001157 call Xinvalid_efm_Tests('c')
1158 call Xinvalid_efm_Tests('l')
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001159endfunc
Bram Moolenaar0fcc7c62016-07-02 21:22:52 +02001160
1161" TODO:
1162" Add tests for the following formats in 'errorformat'
1163" %r %O
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001164func Test_efm2()
Bram Moolenaar0fcc7c62016-07-02 21:22:52 +02001165 let save_efm = &efm
Bram Moolenaar049cba92016-06-26 14:38:04 +02001166
1167 " Test for %s format in efm
1168 set efm=%f:%s
1169 cexpr 'Xtestfile:Line search text'
Bram Moolenaar049cba92016-06-26 14:38:04 +02001170 let l = getqflist()
Bram Moolenaar70077dd2019-11-24 12:12:42 +01001171 call assert_equal('^\VLine search text\$', l[0].pattern)
1172 call assert_equal(0, l[0].lnum)
Bram Moolenaar049cba92016-06-26 14:38:04 +02001173
Bram Moolenaaree85df32017-03-19 14:19:50 +01001174 let l = split(execute('clist', ''), "\n")
1175 call assert_equal([' 1 Xtestfile:^\VLine search text\$: '], l)
1176
Bram Moolenaar70077dd2019-11-24 12:12:42 +01001177 " Test for a long line
1178 cexpr 'Xtestfile:' . repeat('a', 1026)
1179 let l = getqflist()
1180 call assert_equal('^\V' . repeat('a', 1019) . '\$', l[0].pattern)
1181
Bram Moolenaar0fcc7c62016-07-02 21:22:52 +02001182 " Test for %P, %Q and %t format specifiers
Bram Moolenaarc79745a2019-05-20 22:12:34 +02001183 let lines =<< trim [DATA]
Bram Moolenaare7eb9272019-06-24 00:58:07 +02001184 [Xtestfile1]
1185 (1,17) error: ';' missing
1186 (21,2) warning: variable 'z' not defined
1187 (67,3) error: end of file found before string ended
1188 --
Bram Moolenaarc79745a2019-05-20 22:12:34 +02001189
Bram Moolenaare7eb9272019-06-24 00:58:07 +02001190 [Xtestfile2]
1191 --
Bram Moolenaarc79745a2019-05-20 22:12:34 +02001192
Bram Moolenaare7eb9272019-06-24 00:58:07 +02001193 [Xtestfile3]
1194 NEW compiler v1.1
1195 (2,2) warning: variable 'x' not defined
1196 (67,3) warning: 's' already defined
1197 --
Bram Moolenaarc79745a2019-05-20 22:12:34 +02001198 [DATA]
1199
Bram Moolenaaree85df32017-03-19 14:19:50 +01001200 set efm=%+P[%f]%r,(%l\\,%c)%*[\ ]%t%*[^:]:\ %m,%+Q--%r
Bram Moolenaar391b1dd2017-03-04 13:47:11 +01001201 " To exercise the push/pop file functionality in quickfix, the test files
1202 " need to be created.
1203 call writefile(['Line1'], 'Xtestfile1')
1204 call writefile(['Line2'], 'Xtestfile2')
1205 call writefile(['Line3'], 'Xtestfile3')
Bram Moolenaar361c8f02016-07-02 15:41:47 +02001206 cexpr ""
1207 for l in lines
1208 caddexpr l
1209 endfor
Bram Moolenaar049cba92016-06-26 14:38:04 +02001210 let l = getqflist()
Bram Moolenaaree85df32017-03-19 14:19:50 +01001211 call assert_equal(12, len(l))
Bram Moolenaar049cba92016-06-26 14:38:04 +02001212 call assert_equal(21, l[2].lnum)
1213 call assert_equal(2, l[2].col)
Bram Moolenaar0fcc7c62016-07-02 21:22:52 +02001214 call assert_equal('w', l[2].type)
1215 call assert_equal('e', l[3].type)
Bram Moolenaar391b1dd2017-03-04 13:47:11 +01001216 call delete('Xtestfile1')
1217 call delete('Xtestfile2')
1218 call delete('Xtestfile3')
Bram Moolenaar0fcc7c62016-07-02 21:22:52 +02001219
Bram Moolenaar70077dd2019-11-24 12:12:42 +01001220 " Test for %P, %Q with non-existing files
1221 cexpr lines
1222 let l = getqflist()
1223 call assert_equal(14, len(l))
1224 call assert_equal('[Xtestfile1]', l[0].text)
1225 call assert_equal('[Xtestfile2]', l[6].text)
1226 call assert_equal('[Xtestfile3]', l[9].text)
1227
Bram Moolenaar0fcc7c62016-07-02 21:22:52 +02001228 " Tests for %E, %C and %Z format specifiers
Bram Moolenaarc79745a2019-05-20 22:12:34 +02001229 let lines =<< trim [DATA]
Bram Moolenaare7eb9272019-06-24 00:58:07 +02001230 Error 275
1231 line 42
1232 column 3
1233 ' ' expected after '--'
Bram Moolenaarc79745a2019-05-20 22:12:34 +02001234 [DATA]
1235
Bram Moolenaar0fcc7c62016-07-02 21:22:52 +02001236 set efm=%EError\ %n,%Cline\ %l,%Ccolumn\ %c,%Z%m
1237 cgetexpr lines
1238 let l = getqflist()
1239 call assert_equal(275, l[0].nr)
1240 call assert_equal(42, l[0].lnum)
1241 call assert_equal(3, l[0].col)
1242 call assert_equal('E', l[0].type)
1243 call assert_equal("\n' ' expected after '--'", l[0].text)
1244
1245 " Test for %>
Bram Moolenaarc79745a2019-05-20 22:12:34 +02001246 let lines =<< trim [DATA]
Bram Moolenaare7eb9272019-06-24 00:58:07 +02001247 Error in line 147 of foo.c:
1248 unknown variable 'i'
Bram Moolenaarc79745a2019-05-20 22:12:34 +02001249 [DATA]
1250
Bram Moolenaar0fcc7c62016-07-02 21:22:52 +02001251 set efm=unknown\ variable\ %m,%E%>Error\ in\ line\ %l\ of\ %f:,%Z%m
1252 cgetexpr lines
1253 let l = getqflist()
1254 call assert_equal(147, l[0].lnum)
1255 call assert_equal('E', l[0].type)
1256 call assert_equal("\nunknown variable 'i'", l[0].text)
Bram Moolenaar049cba92016-06-26 14:38:04 +02001257
Bram Moolenaare87e6dd2016-07-17 19:25:04 +02001258 " Test for %A, %C and other formats
Bram Moolenaarc79745a2019-05-20 22:12:34 +02001259 let lines =<< trim [DATA]
Bram Moolenaare7eb9272019-06-24 00:58:07 +02001260 ==============================================================
1261 FAIL: testGetTypeIdCachesResult (dbfacadeTest.DjsDBFacadeTest)
1262 --------------------------------------------------------------
1263 Traceback (most recent call last):
1264 File "unittests/dbfacadeTest.py", line 89, in testFoo
1265 self.assertEquals(34, dtid)
1266 File "/usr/lib/python2.2/unittest.py", line 286, in
1267 failUnlessEqual
1268 raise self.failureException, \\
Bram Moolenaar70077dd2019-11-24 12:12:42 +01001269 W:AssertionError: 34 != 33
Bram Moolenaare7eb9272019-06-24 00:58:07 +02001270
1271 --------------------------------------------------------------
1272 Ran 27 tests in 0.063s
Bram Moolenaarc79745a2019-05-20 22:12:34 +02001273 [DATA]
1274
Bram Moolenaar70077dd2019-11-24 12:12:42 +01001275 set efm=%C\ %.%#,%A\ \ File\ \"%f\"\\,\ line\ %l%.%#,%Z%[%^\ ]%\\@=%t:%m
Bram Moolenaare87e6dd2016-07-17 19:25:04 +02001276 cgetexpr lines
1277 let l = getqflist()
1278 call assert_equal(8, len(l))
1279 call assert_equal(89, l[4].lnum)
1280 call assert_equal(1, l[4].valid)
1281 call assert_equal('unittests/dbfacadeTest.py', bufname(l[4].bufnr))
Bram Moolenaar70077dd2019-11-24 12:12:42 +01001282 call assert_equal('W', l[4].type)
Bram Moolenaare87e6dd2016-07-17 19:25:04 +02001283
Bram Moolenaard76ce852018-05-01 15:02:04 +02001284 " Test for %o
1285 set efm=%f(%o):%l\ %m
Bram Moolenaarbc7845d2018-05-01 16:26:48 +02001286 cgetexpr ['Xotestfile(Language.PureScript.Types):20 Error']
1287 call writefile(['Line1'], 'Xotestfile')
Bram Moolenaard76ce852018-05-01 15:02:04 +02001288 let l = getqflist()
1289 call assert_equal(1, len(l), string(l))
1290 call assert_equal('Language.PureScript.Types', l[0].module)
1291 copen
1292 call assert_equal('Language.PureScript.Types|20| Error', getline(1))
1293 call feedkeys("\<CR>", 'xn')
Bram Moolenaarbc7845d2018-05-01 16:26:48 +02001294 call assert_equal('Xotestfile', expand('%:t'))
Bram Moolenaard76ce852018-05-01 15:02:04 +02001295 cclose
1296 bd
Bram Moolenaarbc7845d2018-05-01 16:26:48 +02001297 call delete("Xotestfile")
Bram Moolenaard76ce852018-05-01 15:02:04 +02001298
Bram Moolenaar70077dd2019-11-24 12:12:42 +01001299 " Test for a long module name
1300 cexpr 'Xtest(' . repeat('m', 1026) . '):15 message'
1301 let l = getqflist()
1302 call assert_equal(repeat('m', 1024), l[0].module)
1303 call assert_equal(15, l[0].lnum)
1304 call assert_equal('message', l[0].text)
1305
Bram Moolenaar99895ea2017-04-20 22:44:47 +02001306 " The following sequence of commands used to crash Vim
1307 set efm=%W%m
1308 cgetexpr ['msg1']
1309 let l = getqflist()
1310 call assert_equal(1, len(l), string(l))
1311 call assert_equal('msg1', l[0].text)
1312 set efm=%C%m
1313 lexpr 'msg2'
1314 let l = getloclist(0)
1315 call assert_equal(1, len(l), string(l))
1316 call assert_equal('msg2', l[0].text)
1317 lopen
1318 call setqflist([], 'r')
1319 caddbuf
1320 let l = getqflist()
1321 call assert_equal(1, len(l), string(l))
1322 call assert_equal('|| msg2', l[0].text)
1323
Bram Moolenaar78ddc062018-05-15 21:56:34 +02001324 " When matching error lines, case should be ignored. Test for this.
1325 set noignorecase
1326 let l=getqflist({'lines' : ['Xtest:FOO10:Line 20'], 'efm':'%f:foo%l:%m'})
1327 call assert_equal(10, l.items[0].lnum)
1328 call assert_equal('Line 20', l.items[0].text)
1329 set ignorecase&
1330
Bram Moolenaar99895ea2017-04-20 22:44:47 +02001331 new | only
Bram Moolenaar049cba92016-06-26 14:38:04 +02001332 let &efm = save_efm
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001333endfunc
Bram Moolenaar049cba92016-06-26 14:38:04 +02001334
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001335func XquickfixChangedByAutocmd(cchar)
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001336 call s:setup_commands(a:cchar)
Bram Moolenaarffec3c52016-03-23 20:55:42 +01001337 if a:cchar == 'c'
Bram Moolenaarffec3c52016-03-23 20:55:42 +01001338 let ErrorNr = 'E925'
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001339 func! ReadFunc()
Bram Moolenaarffec3c52016-03-23 20:55:42 +01001340 colder
1341 cgetexpr []
1342 endfunc
1343 else
Bram Moolenaarffec3c52016-03-23 20:55:42 +01001344 let ErrorNr = 'E926'
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001345 func! ReadFunc()
Bram Moolenaarffec3c52016-03-23 20:55:42 +01001346 lolder
1347 lgetexpr []
1348 endfunc
1349 endif
1350
1351 augroup testgroup
1352 au!
Bram Moolenaard106e5b2016-04-21 19:38:07 +02001353 autocmd BufReadCmd test_changed.txt call ReadFunc()
Bram Moolenaarffec3c52016-03-23 20:55:42 +01001354 augroup END
1355
Bram Moolenaard106e5b2016-04-21 19:38:07 +02001356 new | only
Bram Moolenaarffec3c52016-03-23 20:55:42 +01001357 let words = [ "a", "b" ]
1358 let qflist = []
1359 for word in words
Bram Moolenaard106e5b2016-04-21 19:38:07 +02001360 call add(qflist, {'filename': 'test_changed.txt'})
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001361 call g:Xsetlist(qflist, ' ')
Bram Moolenaarffec3c52016-03-23 20:55:42 +01001362 endfor
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001363 call assert_fails('Xrewind', ErrorNr . ':')
Bram Moolenaarffec3c52016-03-23 20:55:42 +01001364
1365 augroup! testgroup
1366endfunc
1367
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001368func Test_quickfix_was_changed_by_autocmd()
Bram Moolenaarffec3c52016-03-23 20:55:42 +01001369 call XquickfixChangedByAutocmd('c')
1370 call XquickfixChangedByAutocmd('l')
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001371endfunc
Bram Moolenaar8b201792016-03-25 15:01:10 +01001372
1373func Test_caddbuffer_to_empty()
1374 helpgr quickfix
1375 call setqflist([], 'r')
1376 cad
Bram Moolenaarf68f1d72016-03-25 17:14:06 +01001377 try
1378 cn
1379 catch
1380 " number of matches is unknown
1381 call assert_true(v:exception =~ 'E553:')
1382 endtry
Bram Moolenaar8b201792016-03-25 15:01:10 +01001383 quit!
1384endfunc
Bram Moolenaar89c64d52016-03-27 18:44:40 +02001385
1386func Test_cgetexpr_works()
1387 " this must not crash Vim
1388 cgetexpr [$x]
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001389 lgetexpr [$x]
Bram Moolenaar89c64d52016-03-27 18:44:40 +02001390endfunc
Bram Moolenaarc1808d52016-04-18 20:04:00 +02001391
1392" Tests for the setqflist() and setloclist() functions
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001393func SetXlistTests(cchar, bnum)
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001394 call s:setup_commands(a:cchar)
Bram Moolenaarc1808d52016-04-18 20:04:00 +02001395
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001396 call g:Xsetlist([{'bufnr': a:bnum, 'lnum': 1},
Bram Moolenaarc1808d52016-04-18 20:04:00 +02001397 \ {'bufnr': a:bnum, 'lnum': 2}])
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001398 let l = g:Xgetlist()
Bram Moolenaarc1808d52016-04-18 20:04:00 +02001399 call assert_equal(2, len(l))
1400 call assert_equal(2, l[1].lnum)
1401
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001402 Xnext
1403 call g:Xsetlist([{'bufnr': a:bnum, 'lnum': 3}], 'a')
1404 let l = g:Xgetlist()
Bram Moolenaarc1808d52016-04-18 20:04:00 +02001405 call assert_equal(3, len(l))
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001406 Xnext
Bram Moolenaarc1808d52016-04-18 20:04:00 +02001407 call assert_equal(3, line('.'))
1408
Bram Moolenaar2b2b8ae2016-05-24 19:59:51 +02001409 " Appending entries to the list should not change the cursor position
1410 " in the quickfix window
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001411 Xwindow
Bram Moolenaar2b2b8ae2016-05-24 19:59:51 +02001412 1
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001413 call g:Xsetlist([{'bufnr': a:bnum, 'lnum': 4},
Bram Moolenaar2b2b8ae2016-05-24 19:59:51 +02001414 \ {'bufnr': a:bnum, 'lnum': 5}], 'a')
1415 call assert_equal(1, line('.'))
1416 close
1417
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001418 call g:Xsetlist([{'bufnr': a:bnum, 'lnum': 3},
Bram Moolenaarc1808d52016-04-18 20:04:00 +02001419 \ {'bufnr': a:bnum, 'lnum': 4},
1420 \ {'bufnr': a:bnum, 'lnum': 5}], 'r')
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001421 let l = g:Xgetlist()
Bram Moolenaarc1808d52016-04-18 20:04:00 +02001422 call assert_equal(3, len(l))
1423 call assert_equal(5, l[2].lnum)
1424
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001425 call g:Xsetlist([])
1426 let l = g:Xgetlist()
Bram Moolenaarc1808d52016-04-18 20:04:00 +02001427 call assert_equal(0, len(l))
Bram Moolenaaree85df32017-03-19 14:19:50 +01001428
Bram Moolenaarf1d21c82017-04-22 21:20:46 +02001429 " Tests for setting the 'valid' flag
1430 call g:Xsetlist([{'bufnr':a:bnum, 'lnum':4, 'valid':0}])
1431 Xwindow
1432 call assert_equal(1, winnr('$'))
1433 let l = g:Xgetlist()
1434 call g:Xsetlist(l)
1435 call assert_equal(0, g:Xgetlist()[0].valid)
Bram Moolenaar9752c722018-12-22 16:49:34 +01001436 " Adding a non-valid entry should not mark the list as having valid entries
1437 call g:Xsetlist([{'bufnr':a:bnum, 'lnum':5, 'valid':0}], 'a')
1438 Xwindow
1439 call assert_equal(1, winnr('$'))
1440
1441 " :cnext/:cprev should still work even with invalid entries in the list
1442 let l = [{'bufnr' : a:bnum, 'lnum' : 1, 'text' : '1', 'valid' : 0},
1443 \ {'bufnr' : a:bnum, 'lnum' : 2, 'text' : '2', 'valid' : 0}]
1444 call g:Xsetlist(l)
1445 Xnext
1446 call assert_equal(2, g:Xgetlist({'idx' : 0}).idx)
1447 Xprev
1448 call assert_equal(1, g:Xgetlist({'idx' : 0}).idx)
1449 " :cnext/:cprev should still work after appending invalid entries to an
1450 " empty list
1451 call g:Xsetlist([])
1452 call g:Xsetlist(l, 'a')
1453 Xnext
1454 call assert_equal(2, g:Xgetlist({'idx' : 0}).idx)
1455 Xprev
1456 call assert_equal(1, g:Xgetlist({'idx' : 0}).idx)
1457
Bram Moolenaarf1d21c82017-04-22 21:20:46 +02001458 call g:Xsetlist([{'text':'Text1', 'valid':1}])
1459 Xwindow
1460 call assert_equal(2, winnr('$'))
1461 Xclose
1462 let save_efm = &efm
1463 set efm=%m
1464 Xgetexpr 'TestMessage'
1465 let l = g:Xgetlist()
1466 call g:Xsetlist(l)
1467 call assert_equal(1, g:Xgetlist()[0].valid)
1468 let &efm = save_efm
1469
Bram Moolenaaree85df32017-03-19 14:19:50 +01001470 " Error cases:
1471 " Refer to a non-existing buffer and pass a non-dictionary type
1472 call assert_fails("call g:Xsetlist([{'bufnr':998, 'lnum':4}," .
1473 \ " {'bufnr':999, 'lnum':5}])", 'E92:')
1474 call g:Xsetlist([[1, 2,3]])
1475 call assert_equal(0, len(g:Xgetlist()))
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001476endfunc
Bram Moolenaarc1808d52016-04-18 20:04:00 +02001477
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001478func Test_setqflist()
Bram Moolenaarc1808d52016-04-18 20:04:00 +02001479 new Xtestfile | only
1480 let bnum = bufnr('%')
1481 call setline(1, range(1,5))
1482
1483 call SetXlistTests('c', bnum)
1484 call SetXlistTests('l', bnum)
1485
Bram Moolenaar1cee6932016-06-09 22:17:22 +02001486 enew!
Bram Moolenaarc1808d52016-04-18 20:04:00 +02001487 call delete('Xtestfile')
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001488endfunc
Bram Moolenaard106e5b2016-04-21 19:38:07 +02001489
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001490func Xlist_empty_middle(cchar)
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001491 call s:setup_commands(a:cchar)
1492
Bram Moolenaar1cee6932016-06-09 22:17:22 +02001493 " create three quickfix lists
Bram Moolenaaree85df32017-03-19 14:19:50 +01001494 let @/ = 'Test_'
1495 Xvimgrep // test_quickfix.vim
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001496 let testlen = len(g:Xgetlist())
Bram Moolenaar1cee6932016-06-09 22:17:22 +02001497 call assert_true(testlen > 0)
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001498 Xvimgrep empty test_quickfix.vim
1499 call assert_true(len(g:Xgetlist()) > 0)
1500 Xvimgrep matches test_quickfix.vim
1501 let matchlen = len(g:Xgetlist())
Bram Moolenaar1cee6932016-06-09 22:17:22 +02001502 call assert_true(matchlen > 0)
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001503 Xolder
Bram Moolenaar1cee6932016-06-09 22:17:22 +02001504 " make the middle list empty
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001505 call g:Xsetlist([], 'r')
1506 call assert_true(len(g:Xgetlist()) == 0)
1507 Xolder
1508 call assert_equal(testlen, len(g:Xgetlist()))
1509 Xnewer
1510 Xnewer
1511 call assert_equal(matchlen, len(g:Xgetlist()))
Bram Moolenaar1cee6932016-06-09 22:17:22 +02001512endfunc
1513
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001514func Test_setqflist_empty_middle()
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001515 call Xlist_empty_middle('c')
1516 call Xlist_empty_middle('l')
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001517endfunc
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001518
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001519func Xlist_empty_older(cchar)
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001520 call s:setup_commands(a:cchar)
1521
Bram Moolenaar1cee6932016-06-09 22:17:22 +02001522 " create three quickfix lists
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001523 Xvimgrep one test_quickfix.vim
1524 let onelen = len(g:Xgetlist())
Bram Moolenaar1cee6932016-06-09 22:17:22 +02001525 call assert_true(onelen > 0)
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001526 Xvimgrep two test_quickfix.vim
1527 let twolen = len(g:Xgetlist())
Bram Moolenaar1cee6932016-06-09 22:17:22 +02001528 call assert_true(twolen > 0)
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001529 Xvimgrep three test_quickfix.vim
1530 let threelen = len(g:Xgetlist())
Bram Moolenaar1cee6932016-06-09 22:17:22 +02001531 call assert_true(threelen > 0)
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001532 Xolder 2
Bram Moolenaar1cee6932016-06-09 22:17:22 +02001533 " make the first list empty, check the others didn't change
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001534 call g:Xsetlist([], 'r')
1535 call assert_true(len(g:Xgetlist()) == 0)
1536 Xnewer
1537 call assert_equal(twolen, len(g:Xgetlist()))
1538 Xnewer
1539 call assert_equal(threelen, len(g:Xgetlist()))
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001540endfunc
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001541
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001542func Test_setqflist_empty_older()
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001543 call Xlist_empty_older('c')
1544 call Xlist_empty_older('l')
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001545endfunc
Bram Moolenaar1cee6932016-06-09 22:17:22 +02001546
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001547func XquickfixSetListWithAct(cchar)
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001548 call s:setup_commands(a:cchar)
1549
Bram Moolenaard106e5b2016-04-21 19:38:07 +02001550 let list1 = [{'filename': 'fnameA', 'text': 'A'},
1551 \ {'filename': 'fnameB', 'text': 'B'}]
1552 let list2 = [{'filename': 'fnameC', 'text': 'C'},
1553 \ {'filename': 'fnameD', 'text': 'D'},
1554 \ {'filename': 'fnameE', 'text': 'E'}]
1555
Bram Moolenaareeb1b9c2019-02-10 22:59:04 +01001556 " {action} is unspecified. Same as specifying ' '.
Bram Moolenaard106e5b2016-04-21 19:38:07 +02001557 new | only
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001558 silent! Xnewer 99
1559 call g:Xsetlist(list1)
1560 call g:Xsetlist(list2)
1561 let li = g:Xgetlist()
Bram Moolenaard106e5b2016-04-21 19:38:07 +02001562 call assert_equal(3, len(li))
1563 call assert_equal('C', li[0]['text'])
1564 call assert_equal('D', li[1]['text'])
1565 call assert_equal('E', li[2]['text'])
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001566 silent! Xolder
1567 let li = g:Xgetlist()
Bram Moolenaard106e5b2016-04-21 19:38:07 +02001568 call assert_equal(2, len(li))
1569 call assert_equal('A', li[0]['text'])
1570 call assert_equal('B', li[1]['text'])
1571
1572 " {action} is specified ' '.
1573 new | only
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001574 silent! Xnewer 99
1575 call g:Xsetlist(list1)
1576 call g:Xsetlist(list2, ' ')
1577 let li = g:Xgetlist()
Bram Moolenaard106e5b2016-04-21 19:38:07 +02001578 call assert_equal(3, len(li))
1579 call assert_equal('C', li[0]['text'])
1580 call assert_equal('D', li[1]['text'])
1581 call assert_equal('E', li[2]['text'])
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001582 silent! Xolder
1583 let li = g:Xgetlist()
Bram Moolenaard106e5b2016-04-21 19:38:07 +02001584 call assert_equal(2, len(li))
1585 call assert_equal('A', li[0]['text'])
1586 call assert_equal('B', li[1]['text'])
1587
1588 " {action} is specified 'a'.
1589 new | only
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001590 silent! Xnewer 99
1591 call g:Xsetlist(list1)
1592 call g:Xsetlist(list2, 'a')
1593 let li = g:Xgetlist()
Bram Moolenaard106e5b2016-04-21 19:38:07 +02001594 call assert_equal(5, len(li))
1595 call assert_equal('A', li[0]['text'])
1596 call assert_equal('B', li[1]['text'])
1597 call assert_equal('C', li[2]['text'])
1598 call assert_equal('D', li[3]['text'])
1599 call assert_equal('E', li[4]['text'])
1600
1601 " {action} is specified 'r'.
1602 new | only
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001603 silent! Xnewer 99
1604 call g:Xsetlist(list1)
1605 call g:Xsetlist(list2, 'r')
1606 let li = g:Xgetlist()
Bram Moolenaard106e5b2016-04-21 19:38:07 +02001607 call assert_equal(3, len(li))
1608 call assert_equal('C', li[0]['text'])
1609 call assert_equal('D', li[1]['text'])
1610 call assert_equal('E', li[2]['text'])
1611
1612 " Test for wrong value.
1613 new | only
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001614 call assert_fails("call g:Xsetlist(0)", 'E714:')
1615 call assert_fails("call g:Xsetlist(list1, '')", 'E927:')
1616 call assert_fails("call g:Xsetlist(list1, 'aa')", 'E927:')
1617 call assert_fails("call g:Xsetlist(list1, ' a')", 'E927:')
1618 call assert_fails("call g:Xsetlist(list1, 0)", 'E928:')
Bram Moolenaard106e5b2016-04-21 19:38:07 +02001619endfunc
1620
Bram Moolenaara0ca7d02017-12-19 10:22:19 +01001621func Test_setqflist_invalid_nr()
1622 " The following command used to crash Vim
Bram Moolenaaraad222c2019-09-06 22:46:09 +02001623 eval []->setqflist(' ', {'nr' : $XXX_DOES_NOT_EXIST})
Bram Moolenaara0ca7d02017-12-19 10:22:19 +01001624endfunc
1625
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001626func Test_quickfix_set_list_with_act()
Bram Moolenaard106e5b2016-04-21 19:38:07 +02001627 call XquickfixSetListWithAct('c')
1628 call XquickfixSetListWithAct('l')
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001629endfunc
Bram Moolenaar6be8c8e2016-04-30 13:17:09 +02001630
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001631func XLongLinesTests(cchar)
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001632 let l = g:Xgetlist()
Bram Moolenaar6be8c8e2016-04-30 13:17:09 +02001633
Bram Moolenaar049cba92016-06-26 14:38:04 +02001634 call assert_equal(4, len(l))
Bram Moolenaar6be8c8e2016-04-30 13:17:09 +02001635 call assert_equal(1, l[0].lnum)
1636 call assert_equal(1, l[0].col)
Bram Moolenaar049cba92016-06-26 14:38:04 +02001637 call assert_equal(1975, len(l[0].text))
Bram Moolenaar6be8c8e2016-04-30 13:17:09 +02001638 call assert_equal(2, l[1].lnum)
1639 call assert_equal(1, l[1].col)
1640 call assert_equal(4070, len(l[1].text))
1641 call assert_equal(3, l[2].lnum)
1642 call assert_equal(1, l[2].col)
Bram Moolenaar049cba92016-06-26 14:38:04 +02001643 call assert_equal(4070, len(l[2].text))
1644 call assert_equal(4, l[3].lnum)
1645 call assert_equal(1, l[3].col)
1646 call assert_equal(10, len(l[3].text))
Bram Moolenaar6be8c8e2016-04-30 13:17:09 +02001647
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001648 call g:Xsetlist([], 'r')
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001649endfunc
Bram Moolenaar6be8c8e2016-04-30 13:17:09 +02001650
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001651func s:long_lines_tests(cchar)
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001652 call s:setup_commands(a:cchar)
1653
Bram Moolenaar6be8c8e2016-04-30 13:17:09 +02001654 let testfile = 'samples/quickfix.txt'
1655
1656 " file
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001657 exe 'Xgetfile' testfile
1658 call XLongLinesTests(a:cchar)
Bram Moolenaar6be8c8e2016-04-30 13:17:09 +02001659
1660 " list
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001661 Xexpr readfile(testfile)
1662 call XLongLinesTests(a:cchar)
Bram Moolenaar6be8c8e2016-04-30 13:17:09 +02001663
1664 " string
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001665 Xexpr join(readfile(testfile), "\n")
1666 call XLongLinesTests(a:cchar)
Bram Moolenaar6be8c8e2016-04-30 13:17:09 +02001667
1668 " buffer
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001669 exe 'edit' testfile
1670 exe 'Xbuffer' bufnr('%')
Bram Moolenaarf50df392016-06-21 21:33:34 +02001671 call XLongLinesTests(a:cchar)
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001672endfunc
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001673
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001674func Test_long_lines()
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001675 call s:long_lines_tests('c')
1676 call s:long_lines_tests('l')
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001677endfunc
Bram Moolenaar049cba92016-06-26 14:38:04 +02001678
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001679func s:create_test_file(filename)
Bram Moolenaar049cba92016-06-26 14:38:04 +02001680 let l = []
1681 for i in range(1, 20)
1682 call add(l, 'Line' . i)
1683 endfor
1684 call writefile(l, a:filename)
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001685endfunc
Bram Moolenaar049cba92016-06-26 14:38:04 +02001686
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001687func Test_switchbuf()
Bram Moolenaar9134f1e2019-11-29 20:26:13 +01001688 CheckNotBSD
Bram Moolenaar049cba92016-06-26 14:38:04 +02001689 call s:create_test_file('Xqftestfile1')
1690 call s:create_test_file('Xqftestfile2')
1691 call s:create_test_file('Xqftestfile3')
1692
1693 new | only
1694 edit Xqftestfile1
1695 let file1_winid = win_getid()
1696 new Xqftestfile2
1697 let file2_winid = win_getid()
1698 cgetexpr ['Xqftestfile1:5:Line5',
1699 \ 'Xqftestfile1:6:Line6',
1700 \ 'Xqftestfile2:10:Line10',
1701 \ 'Xqftestfile2:11:Line11',
1702 \ 'Xqftestfile3:15:Line15',
1703 \ 'Xqftestfile3:16:Line16']
1704
1705 new
1706 let winid = win_getid()
1707 cfirst | cnext
1708 call assert_equal(winid, win_getid())
Bram Moolenaar99895ea2017-04-20 22:44:47 +02001709 2cnext
Bram Moolenaar049cba92016-06-26 14:38:04 +02001710 call assert_equal(winid, win_getid())
Bram Moolenaar99895ea2017-04-20 22:44:47 +02001711 2cnext
Bram Moolenaar049cba92016-06-26 14:38:04 +02001712 call assert_equal(winid, win_getid())
Bram Moolenaar049cba92016-06-26 14:38:04 +02001713
Bram Moolenaarf9ae1542019-11-18 22:02:16 +01001714 " Test for 'switchbuf' set to search for files in windows in the current
1715 " tabpage and jump to an existing window (if present)
Bram Moolenaar049cba92016-06-26 14:38:04 +02001716 set switchbuf=useopen
Bram Moolenaarf9ae1542019-11-18 22:02:16 +01001717 enew
Bram Moolenaar049cba92016-06-26 14:38:04 +02001718 cfirst | cnext
1719 call assert_equal(file1_winid, win_getid())
Bram Moolenaar99895ea2017-04-20 22:44:47 +02001720 2cnext
Bram Moolenaar049cba92016-06-26 14:38:04 +02001721 call assert_equal(file2_winid, win_getid())
Bram Moolenaar99895ea2017-04-20 22:44:47 +02001722 2cnext
Bram Moolenaar049cba92016-06-26 14:38:04 +02001723 call assert_equal(file2_winid, win_getid())
1724
Bram Moolenaarf9ae1542019-11-18 22:02:16 +01001725 " Test for 'switchbuf' set to search for files in tabpages and jump to an
1726 " existing tabpage (if present)
Bram Moolenaar049cba92016-06-26 14:38:04 +02001727 enew | only
1728 set switchbuf=usetab
1729 tabedit Xqftestfile1
1730 tabedit Xqftestfile2
Bram Moolenaar74240d32017-12-10 15:26:15 +01001731 tabedit Xqftestfile3
Bram Moolenaar049cba92016-06-26 14:38:04 +02001732 tabfirst
1733 cfirst | cnext
1734 call assert_equal(2, tabpagenr())
Bram Moolenaar99895ea2017-04-20 22:44:47 +02001735 2cnext
Bram Moolenaar049cba92016-06-26 14:38:04 +02001736 call assert_equal(3, tabpagenr())
Bram Moolenaar74240d32017-12-10 15:26:15 +01001737 6cnext
1738 call assert_equal(4, tabpagenr())
1739 2cpfile
1740 call assert_equal(2, tabpagenr())
1741 2cnfile
1742 call assert_equal(4, tabpagenr())
Bram Moolenaar049cba92016-06-26 14:38:04 +02001743 tabfirst | tabonly | enew
1744
Bram Moolenaarf9ae1542019-11-18 22:02:16 +01001745 " Test for 'switchbuf' set to open a new window for every file
Bram Moolenaar049cba92016-06-26 14:38:04 +02001746 set switchbuf=split
1747 cfirst | cnext
1748 call assert_equal(1, winnr('$'))
1749 cnext | cnext
1750 call assert_equal(2, winnr('$'))
1751 cnext | cnext
1752 call assert_equal(3, winnr('$'))
Bram Moolenaar049cba92016-06-26 14:38:04 +02001753
Bram Moolenaarf9ae1542019-11-18 22:02:16 +01001754 " Test for 'switchbuf' set to open a new tabpage for every file
Bram Moolenaar049cba92016-06-26 14:38:04 +02001755 set switchbuf=newtab
Bram Moolenaarf9ae1542019-11-18 22:02:16 +01001756 enew | only
Bram Moolenaar049cba92016-06-26 14:38:04 +02001757 cfirst | cnext
1758 call assert_equal(1, tabpagenr('$'))
1759 cnext | cnext
1760 call assert_equal(2, tabpagenr('$'))
1761 cnext | cnext
1762 call assert_equal(3, tabpagenr('$'))
1763 tabfirst | enew | tabonly | only
1764
Bram Moolenaar539aa6b2019-11-17 18:09:38 +01001765 set switchbuf=uselast
1766 split
1767 let last_winid = win_getid()
1768 copen
1769 exe "normal 1G\<CR>"
1770 call assert_equal(last_winid, win_getid())
1771 enew | only
1772
Bram Moolenaarf9ae1542019-11-18 22:02:16 +01001773 " With an empty 'switchbuf', jumping to a quickfix entry should open the
1774 " file in an existing window (if present)
Bram Moolenaar049cba92016-06-26 14:38:04 +02001775 set switchbuf=
1776 edit Xqftestfile1
1777 let file1_winid = win_getid()
1778 new Xqftestfile2
1779 let file2_winid = win_getid()
1780 copen
1781 exe "normal 1G\<CR>"
1782 call assert_equal(file1_winid, win_getid())
1783 copen
1784 exe "normal 3G\<CR>"
1785 call assert_equal(file2_winid, win_getid())
1786 copen | only
1787 exe "normal 5G\<CR>"
1788 call assert_equal(2, winnr('$'))
1789 call assert_equal(1, bufwinnr('Xqftestfile3'))
1790
Bram Moolenaar391b1dd2017-03-04 13:47:11 +01001791 " If only quickfix window is open in the current tabpage, jumping to an
Bram Moolenaar1bc353b2019-09-01 14:45:28 +02001792 " entry with 'switchbuf' set to 'usetab' should search in other tabpages.
Bram Moolenaar049cba92016-06-26 14:38:04 +02001793 enew | only
Bram Moolenaar391b1dd2017-03-04 13:47:11 +01001794 set switchbuf=usetab
1795 tabedit Xqftestfile1
1796 tabedit Xqftestfile2
1797 tabedit Xqftestfile3
1798 tabfirst
1799 copen | only
1800 clast
1801 call assert_equal(4, tabpagenr())
1802 tabfirst | tabonly | enew | only
Bram Moolenaar049cba92016-06-26 14:38:04 +02001803
Bram Moolenaarf9ae1542019-11-18 22:02:16 +01001804 " Jumping to a file that is not present in any of the tabpages and the
1805 " current tabpage doesn't have any usable windows, should open it in a new
1806 " window in the current tabpage.
1807 copen | only
1808 cfirst
1809 call assert_equal(1, tabpagenr())
1810 call assert_equal('Xqftestfile1', bufname(''))
1811
1812 " If opening a file changes 'switchbuf', then the new value should be
1813 " retained.
1814 call writefile(["vim: switchbuf=split"], 'Xqftestfile1')
1815 enew | only
1816 set switchbuf&vim
1817 cexpr "Xqftestfile1:1:10"
1818 call assert_equal('split', &switchbuf)
1819 call writefile(["vim: switchbuf=usetab"], 'Xqftestfile1')
1820 enew | only
1821 set switchbuf=useopen
1822 cexpr "Xqftestfile1:1:10"
1823 call assert_equal('usetab', &switchbuf)
1824 call writefile(["vim: switchbuf&vim"], 'Xqftestfile1')
1825 enew | only
1826 set switchbuf=useopen
1827 cexpr "Xqftestfile1:1:10"
1828 call assert_equal('', &switchbuf)
1829
Bram Moolenaar049cba92016-06-26 14:38:04 +02001830 call delete('Xqftestfile1')
1831 call delete('Xqftestfile2')
1832 call delete('Xqftestfile3')
Bram Moolenaar391b1dd2017-03-04 13:47:11 +01001833 set switchbuf&vim
1834
1835 enew | only
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001836endfunc
Bram Moolenaar049cba92016-06-26 14:38:04 +02001837
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001838func Xadjust_qflnum(cchar)
Bram Moolenaar049cba92016-06-26 14:38:04 +02001839 call s:setup_commands(a:cchar)
1840
1841 enew | only
1842
Bram Moolenaarc1542742016-07-20 21:44:37 +02001843 let fname = 'Xqftestfile' . a:cchar
1844 call s:create_test_file(fname)
1845 exe 'edit ' . fname
Bram Moolenaar049cba92016-06-26 14:38:04 +02001846
Bram Moolenaarc1542742016-07-20 21:44:37 +02001847 Xgetexpr [fname . ':5:Line5',
1848 \ fname . ':10:Line10',
1849 \ fname . ':15:Line15',
1850 \ fname . ':20:Line20']
Bram Moolenaar049cba92016-06-26 14:38:04 +02001851
1852 6,14delete
1853 call append(6, ['Buffer', 'Window'])
1854
1855 let l = g:Xgetlist()
Bram Moolenaar049cba92016-06-26 14:38:04 +02001856 call assert_equal(5, l[0].lnum)
1857 call assert_equal(6, l[2].lnum)
1858 call assert_equal(13, l[3].lnum)
1859
Bram Moolenaarf9ae1542019-11-18 22:02:16 +01001860 " If a file doesn't have any quickfix entries, then deleting lines in the
1861 " file should not update the quickfix list
1862 call g:Xsetlist([], 'f')
1863 1,2delete
1864 call assert_equal([], g:Xgetlist())
1865
Bram Moolenaar049cba92016-06-26 14:38:04 +02001866 enew!
Bram Moolenaarc1542742016-07-20 21:44:37 +02001867 call delete(fname)
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001868endfunc
Bram Moolenaar049cba92016-06-26 14:38:04 +02001869
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001870func Test_adjust_lnum()
Bram Moolenaarc1542742016-07-20 21:44:37 +02001871 call setloclist(0, [])
Bram Moolenaar049cba92016-06-26 14:38:04 +02001872 call Xadjust_qflnum('c')
Bram Moolenaarc1542742016-07-20 21:44:37 +02001873 call setqflist([])
Bram Moolenaar049cba92016-06-26 14:38:04 +02001874 call Xadjust_qflnum('l')
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001875endfunc
Bram Moolenaar049cba92016-06-26 14:38:04 +02001876
1877" Tests for the :grep/:lgrep and :grepadd/:lgrepadd commands
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001878func s:test_xgrep(cchar)
Bram Moolenaar049cba92016-06-26 14:38:04 +02001879 call s:setup_commands(a:cchar)
1880
1881 " The following lines are used for the grep test. Don't remove.
1882 " Grep_Test_Text: Match 1
1883 " Grep_Test_Text: Match 2
1884 " GrepAdd_Test_Text: Match 1
1885 " GrepAdd_Test_Text: Match 2
1886 enew! | only
1887 set makeef&vim
1888 silent Xgrep Grep_Test_Text: test_quickfix.vim
Bram Moolenaarf9ae1542019-11-18 22:02:16 +01001889 call assert_true(len(g:Xgetlist()) == 4)
Bram Moolenaar049cba92016-06-26 14:38:04 +02001890 Xopen
1891 call assert_true(w:quickfix_title =~ '^:grep')
1892 Xclose
1893 enew
1894 set makeef=Temp_File_##
1895 silent Xgrepadd GrepAdd_Test_Text: test_quickfix.vim
Bram Moolenaarf9ae1542019-11-18 22:02:16 +01001896 call assert_true(len(g:Xgetlist()) == 7)
1897
1898 call writefile(['Vim'], 'XtestTempFile')
1899 set makeef=XtestTempFile
1900 silent Xgrep Grep_Test_Text: test_quickfix.vim
1901 call assert_equal(4, len(g:Xgetlist()))
1902 call assert_false(filereadable('XtestTempFile'))
1903 set makeef&vim
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001904endfunc
Bram Moolenaar049cba92016-06-26 14:38:04 +02001905
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001906func Test_grep()
Bram Moolenaar049cba92016-06-26 14:38:04 +02001907 if !has('unix')
1908 " The grepprg may not be set on non-Unix systems
1909 return
1910 endif
1911
1912 call s:test_xgrep('c')
1913 call s:test_xgrep('l')
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001914endfunc
Bram Moolenaar361c8f02016-07-02 15:41:47 +02001915
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001916func Test_two_windows()
Bram Moolenaar361c8f02016-07-02 15:41:47 +02001917 " Use one 'errorformat' for two windows. Add an expression to each of them,
1918 " make sure they each keep their own state.
1919 set efm=%DEntering\ dir\ '%f',%f:%l:%m,%XLeaving\ dir\ '%f'
1920 call mkdir('Xone/a', 'p')
1921 call mkdir('Xtwo/a', 'p')
1922 let lines = ['1', '2', 'one one one', '4', 'two two two', '6', '7']
1923 call writefile(lines, 'Xone/a/one.txt')
1924 call writefile(lines, 'Xtwo/a/two.txt')
1925
1926 new one
1927 let one_id = win_getid()
1928 lexpr ""
1929 new two
1930 let two_id = win_getid()
1931 lexpr ""
1932
1933 laddexpr "Entering dir 'Xtwo/a'"
1934 call win_gotoid(one_id)
1935 laddexpr "Entering dir 'Xone/a'"
1936 call win_gotoid(two_id)
1937 laddexpr 'two.txt:5:two two two'
1938 call win_gotoid(one_id)
1939 laddexpr 'one.txt:3:one one one'
1940
1941 let loc_one = getloclist(one_id)
Bram Moolenaar361c8f02016-07-02 15:41:47 +02001942 call assert_equal('Xone/a/one.txt', bufname(loc_one[1].bufnr))
1943 call assert_equal(3, loc_one[1].lnum)
1944
1945 let loc_two = getloclist(two_id)
Bram Moolenaar361c8f02016-07-02 15:41:47 +02001946 call assert_equal('Xtwo/a/two.txt', bufname(loc_two[1].bufnr))
1947 call assert_equal(5, loc_two[1].lnum)
1948
1949 call win_gotoid(one_id)
1950 bwipe!
1951 call win_gotoid(two_id)
1952 bwipe!
1953 call delete('Xone', 'rf')
1954 call delete('Xtwo', 'rf')
1955endfunc
Bram Moolenaardcb17002016-07-07 18:58:59 +02001956
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001957func XbottomTests(cchar)
Bram Moolenaar537ef082016-07-09 17:56:19 +02001958 call s:setup_commands(a:cchar)
1959
Bram Moolenaarb6fa30c2017-03-29 14:19:25 +02001960 " Calling lbottom without any errors should fail
1961 if a:cchar == 'l'
1962 call assert_fails('lbottom', 'E776:')
1963 endif
1964
Bram Moolenaar875feea2017-06-11 16:07:51 +02001965 call g:Xsetlist([{'filename': 'foo', 'lnum': 42}])
Bram Moolenaar537ef082016-07-09 17:56:19 +02001966 Xopen
Bram Moolenaardcb17002016-07-07 18:58:59 +02001967 let wid = win_getid()
1968 call assert_equal(1, line('.'))
1969 wincmd w
Bram Moolenaar875feea2017-06-11 16:07:51 +02001970 call g:Xsetlist([{'filename': 'var', 'lnum': 24}], 'a')
Bram Moolenaar537ef082016-07-09 17:56:19 +02001971 Xbottom
Bram Moolenaardcb17002016-07-07 18:58:59 +02001972 call win_gotoid(wid)
1973 call assert_equal(2, line('.'))
Bram Moolenaar537ef082016-07-09 17:56:19 +02001974 Xclose
Bram Moolenaardcb17002016-07-07 18:58:59 +02001975endfunc
Bram Moolenaar537ef082016-07-09 17:56:19 +02001976
1977" Tests for the :cbottom and :lbottom commands
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001978func Test_cbottom()
Bram Moolenaar537ef082016-07-09 17:56:19 +02001979 call XbottomTests('c')
1980 call XbottomTests('l')
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001981endfunc
Bram Moolenaarf6acffb2016-07-16 16:54:24 +02001982
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001983func HistoryTest(cchar)
Bram Moolenaarf6acffb2016-07-16 16:54:24 +02001984 call s:setup_commands(a:cchar)
1985
Bram Moolenaarf6acffb2016-07-16 16:54:24 +02001986 " clear all lists after the first one, then replace the first one.
1987 call g:Xsetlist([])
Bram Moolenaarb6fa30c2017-03-29 14:19:25 +02001988 call assert_fails('Xolder 99', 'E380:')
Bram Moolenaarf6acffb2016-07-16 16:54:24 +02001989 let entry = {'filename': 'foo', 'lnum': 42}
1990 call g:Xsetlist([entry], 'r')
1991 call g:Xsetlist([entry, entry])
1992 call g:Xsetlist([entry, entry, entry])
1993 let res = split(execute(a:cchar . 'hist'), "\n")
1994 call assert_equal(3, len(res))
1995 let common = 'errors :set' . (a:cchar == 'c' ? 'qf' : 'loc') . 'list()'
1996 call assert_equal(' error list 1 of 3; 1 ' . common, res[0])
1997 call assert_equal(' error list 2 of 3; 2 ' . common, res[1])
1998 call assert_equal('> error list 3 of 3; 3 ' . common, res[2])
Bram Moolenaarb4d5fba2017-09-11 19:31:28 +02001999
Bram Moolenaar8ffc7c82019-05-05 21:00:26 +02002000 " Test for changing the quickfix lists
2001 call assert_equal(3, g:Xgetlist({'nr' : 0}).nr)
2002 exe '1' . a:cchar . 'hist'
2003 call assert_equal(1, g:Xgetlist({'nr' : 0}).nr)
2004 exe '3' . a:cchar . 'hist'
2005 call assert_equal(3, g:Xgetlist({'nr' : 0}).nr)
2006 call assert_fails('-2' . a:cchar . 'hist', 'E16:')
2007 call assert_fails('4' . a:cchar . 'hist', 'E16:')
2008
Bram Moolenaarb4d5fba2017-09-11 19:31:28 +02002009 call g:Xsetlist([], 'f')
2010 let l = split(execute(a:cchar . 'hist'), "\n")
2011 call assert_equal('No entries', l[0])
Bram Moolenaar8ffc7c82019-05-05 21:00:26 +02002012 if a:cchar == 'c'
2013 call assert_fails('4chist', 'E16:')
2014 else
2015 call assert_fails('4lhist', 'E776:')
2016 endif
Bram Moolenaar5b69c222019-01-11 14:50:06 +01002017
2018 " An empty list should still show the stack history
2019 call g:Xsetlist([])
2020 let res = split(execute(a:cchar . 'hist'), "\n")
2021 call assert_equal('> error list 1 of 1; 0 ' . common, res[0])
2022
2023 call g:Xsetlist([], 'f')
Bram Moolenaarf6acffb2016-07-16 16:54:24 +02002024endfunc
2025
2026func Test_history()
2027 call HistoryTest('c')
2028 call HistoryTest('l')
2029endfunc
Bram Moolenaar015102e2016-07-16 18:24:56 +02002030
2031func Test_duplicate_buf()
2032 " make sure we can get the highest buffer number
2033 edit DoesNotExist
2034 edit DoesNotExist2
2035 let last_buffer = bufnr("$")
2036
2037 " make sure only one buffer is created
2038 call writefile(['this one', 'that one'], 'Xgrepthis')
2039 vimgrep one Xgrepthis
2040 vimgrep one Xgrepthis
2041 call assert_equal(last_buffer + 1, bufnr("$"))
2042
2043 call delete('Xgrepthis')
2044endfunc
Bram Moolenaard823fa92016-08-12 16:29:27 +02002045
2046" Quickfix/Location list set/get properties tests
Bram Moolenaar2b946c92016-11-12 18:14:44 +01002047func Xproperty_tests(cchar)
Bram Moolenaard823fa92016-08-12 16:29:27 +02002048 call s:setup_commands(a:cchar)
2049
2050 " Error cases
2051 call assert_fails('call g:Xgetlist(99)', 'E715:')
2052 call assert_fails('call g:Xsetlist(99)', 'E714:')
2053 call assert_fails('call g:Xsetlist([], "a", [])', 'E715:')
2054
2055 " Set and get the title
Bram Moolenaarb6fa30c2017-03-29 14:19:25 +02002056 call g:Xsetlist([])
Bram Moolenaard823fa92016-08-12 16:29:27 +02002057 Xopen
2058 wincmd p
2059 call g:Xsetlist([{'filename':'foo', 'lnum':27}])
Bram Moolenaar86f100dc2017-06-28 21:26:27 +02002060 let s = g:Xsetlist([], 'a', {'title' : 'Sample'})
2061 call assert_equal(0, s)
Bram Moolenaard823fa92016-08-12 16:29:27 +02002062 let d = g:Xgetlist({"title":1})
2063 call assert_equal('Sample', d.title)
Bram Moolenaara2aa8a22018-04-24 13:55:00 +02002064 " Try setting title to a non-string value
2065 call assert_equal(-1, g:Xsetlist([], 'a', {'title' : ['Test']}))
2066 call assert_equal('Sample', g:Xgetlist({"title":1}).title)
Bram Moolenaard823fa92016-08-12 16:29:27 +02002067
2068 Xopen
2069 call assert_equal('Sample', w:quickfix_title)
2070 Xclose
2071
Bram Moolenaar2b529bb2016-08-27 13:35:35 +02002072 " Tests for action argument
2073 silent! Xolder 999
2074 let qfnr = g:Xgetlist({'all':1}).nr
2075 call g:Xsetlist([], 'r', {'title' : 'N1'})
2076 call assert_equal('N1', g:Xgetlist({'all':1}).title)
2077 call g:Xsetlist([], ' ', {'title' : 'N2'})
2078 call assert_equal(qfnr + 1, g:Xgetlist({'all':1}).nr)
Bram Moolenaar890680c2016-09-27 21:28:56 +02002079
2080 let res = g:Xgetlist({'nr': 0})
2081 call assert_equal(qfnr + 1, res.nr)
2082 call assert_equal(['nr'], keys(res))
2083
Bram Moolenaar2b529bb2016-08-27 13:35:35 +02002084 call g:Xsetlist([], ' ', {'title' : 'N3'})
2085 call assert_equal('N2', g:Xgetlist({'nr':2, 'title':1}).title)
2086
Bram Moolenaaree85df32017-03-19 14:19:50 +01002087 " Changing the title of an earlier quickfix list
Bram Moolenaar55b69262017-08-13 13:42:01 +02002088 call g:Xsetlist([], 'r', {'title' : 'NewTitle', 'nr' : 2})
Bram Moolenaaree85df32017-03-19 14:19:50 +01002089 call assert_equal('NewTitle', g:Xgetlist({'nr':2, 'title':1}).title)
2090
2091 " Changing the title of an invalid quickfix list
2092 call assert_equal(-1, g:Xsetlist([], ' ',
2093 \ {'title' : 'SomeTitle', 'nr' : 99}))
2094 call assert_equal(-1, g:Xsetlist([], ' ',
2095 \ {'title' : 'SomeTitle', 'nr' : 'abc'}))
2096
2097 if a:cchar == 'c'
2098 copen
2099 call assert_equal({'winid':win_getid()}, getqflist({'winid':1}))
2100 cclose
2101 endif
2102
Bram Moolenaard823fa92016-08-12 16:29:27 +02002103 " Invalid arguments
2104 call assert_fails('call g:Xgetlist([])', 'E715')
2105 call assert_fails('call g:Xsetlist([], "a", [])', 'E715')
2106 let s = g:Xsetlist([], 'a', {'abc':1})
2107 call assert_equal(-1, s)
2108
2109 call assert_equal({}, g:Xgetlist({'abc':1}))
Bram Moolenaara6d48492017-12-12 22:45:31 +01002110 call assert_equal('', g:Xgetlist({'nr':99, 'title':1}).title)
2111 call assert_equal('', g:Xgetlist({'nr':[], 'title':1}).title)
Bram Moolenaard823fa92016-08-12 16:29:27 +02002112
2113 if a:cchar == 'l'
Bram Moolenaar890680c2016-09-27 21:28:56 +02002114 call assert_equal({}, getloclist(99, {'title': 1}))
Bram Moolenaard823fa92016-08-12 16:29:27 +02002115 endif
Bram Moolenaar8f77c5a2017-04-30 14:21:00 +02002116
2117 " Context related tests
Bram Moolenaar86f100dc2017-06-28 21:26:27 +02002118 let s = g:Xsetlist([], 'a', {'context':[1,2,3]})
2119 call assert_equal(0, s)
Bram Moolenaar8f77c5a2017-04-30 14:21:00 +02002120 call test_garbagecollect_now()
2121 let d = g:Xgetlist({'context':1})
2122 call assert_equal([1,2,3], d.context)
2123 call g:Xsetlist([], 'a', {'context':{'color':'green'}})
2124 let d = g:Xgetlist({'context':1})
2125 call assert_equal({'color':'green'}, d.context)
2126 call g:Xsetlist([], 'a', {'context':"Context info"})
2127 let d = g:Xgetlist({'context':1})
2128 call assert_equal("Context info", d.context)
2129 call g:Xsetlist([], 'a', {'context':246})
2130 let d = g:Xgetlist({'context':1})
2131 call assert_equal(246, d.context)
2132 if a:cchar == 'l'
2133 " Test for copying context across two different location lists
2134 new | only
2135 let w1_id = win_getid()
2136 let l = [1]
2137 call setloclist(0, [], 'a', {'context':l})
2138 new
2139 let w2_id = win_getid()
2140 call add(l, 2)
2141 call assert_equal([1, 2], getloclist(w1_id, {'context':1}).context)
2142 call assert_equal([1, 2], getloclist(w2_id, {'context':1}).context)
2143 unlet! l
2144 call assert_equal([1, 2], getloclist(w2_id, {'context':1}).context)
2145 only
2146 call setloclist(0, [], 'f')
Bram Moolenaara6d48492017-12-12 22:45:31 +01002147 call assert_equal('', getloclist(0, {'context':1}).context)
Bram Moolenaar8f77c5a2017-04-30 14:21:00 +02002148 endif
Bram Moolenaar6e62da32017-05-28 08:16:25 +02002149
2150 " Test for changing the context of previous quickfix lists
2151 call g:Xsetlist([], 'f')
2152 Xexpr "One"
2153 Xexpr "Two"
2154 Xexpr "Three"
Bram Moolenaar55b69262017-08-13 13:42:01 +02002155 call g:Xsetlist([], 'r', {'context' : [1], 'nr' : 1})
2156 call g:Xsetlist([], 'a', {'context' : [2], 'nr' : 2})
Bram Moolenaar6e62da32017-05-28 08:16:25 +02002157 " Also, check for setting the context using quickfix list number zero.
Bram Moolenaar55b69262017-08-13 13:42:01 +02002158 call g:Xsetlist([], 'r', {'context' : [3], 'nr' : 0})
Bram Moolenaar6e62da32017-05-28 08:16:25 +02002159 call test_garbagecollect_now()
2160 let l = g:Xgetlist({'nr' : 1, 'context' : 1})
2161 call assert_equal([1], l.context)
2162 let l = g:Xgetlist({'nr' : 2, 'context' : 1})
2163 call assert_equal([2], l.context)
2164 let l = g:Xgetlist({'nr' : 3, 'context' : 1})
2165 call assert_equal([3], l.context)
2166
2167 " Test for changing the context through reference and for garbage
2168 " collection of quickfix context
2169 let l = ["red"]
2170 call g:Xsetlist([], ' ', {'context' : l})
2171 call add(l, "blue")
2172 let x = g:Xgetlist({'context' : 1})
2173 call add(x.context, "green")
2174 call assert_equal(["red", "blue", "green"], l)
2175 call assert_equal(["red", "blue", "green"], x.context)
2176 unlet l
2177 call test_garbagecollect_now()
2178 let m = g:Xgetlist({'context' : 1})
2179 call assert_equal(["red", "blue", "green"], m.context)
Bram Moolenaar6a8958d2017-06-22 21:33:20 +02002180
2181 " Test for setting/getting items
2182 Xexpr ""
2183 let qfprev = g:Xgetlist({'nr':0})
Bram Moolenaar86f100dc2017-06-28 21:26:27 +02002184 let s = g:Xsetlist([], ' ', {'title':'Green',
Bram Moolenaar6a8958d2017-06-22 21:33:20 +02002185 \ 'items' : [{'filename':'F1', 'lnum':10}]})
Bram Moolenaar86f100dc2017-06-28 21:26:27 +02002186 call assert_equal(0, s)
Bram Moolenaar6a8958d2017-06-22 21:33:20 +02002187 let qfcur = g:Xgetlist({'nr':0})
2188 call assert_true(qfcur.nr == qfprev.nr + 1)
2189 let l = g:Xgetlist({'items':1})
2190 call assert_equal('F1', bufname(l.items[0].bufnr))
2191 call assert_equal(10, l.items[0].lnum)
2192 call g:Xsetlist([], 'a', {'items' : [{'filename':'F2', 'lnum':20},
2193 \ {'filename':'F2', 'lnum':30}]})
2194 let l = g:Xgetlist({'items':1})
2195 call assert_equal('F2', bufname(l.items[2].bufnr))
2196 call assert_equal(30, l.items[2].lnum)
2197 call g:Xsetlist([], 'r', {'items' : [{'filename':'F3', 'lnum':40}]})
2198 let l = g:Xgetlist({'items':1})
2199 call assert_equal('F3', bufname(l.items[0].bufnr))
2200 call assert_equal(40, l.items[0].lnum)
2201 call g:Xsetlist([], 'r', {'items' : []})
2202 let l = g:Xgetlist({'items':1})
2203 call assert_equal(0, len(l.items))
2204
Bram Moolenaarb4d5fba2017-09-11 19:31:28 +02002205 call g:Xsetlist([], 'r', {'title' : 'TestTitle'})
2206 call g:Xsetlist([], 'r', {'items' : [{'filename' : 'F1', 'lnum' : 10, 'text' : 'L10'}]})
2207 call g:Xsetlist([], 'r', {'items' : [{'filename' : 'F1', 'lnum' : 10, 'text' : 'L10'}]})
2208 call assert_equal('TestTitle', g:Xgetlist({'title' : 1}).title)
2209
Bram Moolenaarc9cc9c72018-09-02 15:18:42 +02002210 " Test for getting id of window associated with a location list window
2211 if a:cchar == 'l'
2212 only
2213 call assert_equal(0, g:Xgetlist({'all' : 1}).filewinid)
2214 let wid = win_getid()
2215 Xopen
2216 call assert_equal(wid, g:Xgetlist({'filewinid' : 1}).filewinid)
2217 wincmd w
2218 call assert_equal(0, g:Xgetlist({'filewinid' : 1}).filewinid)
2219 only
2220 endif
2221
Bram Moolenaarae338332017-08-11 20:25:26 +02002222 " The following used to crash Vim with address sanitizer
2223 call g:Xsetlist([], 'f')
2224 call g:Xsetlist([], 'a', {'items' : [{'filename':'F1', 'lnum':10}]})
2225 call assert_equal(10, g:Xgetlist({'items':1}).items[0].lnum)
2226
Bram Moolenaara2aa8a22018-04-24 13:55:00 +02002227 " Try setting the items using a string
2228 call assert_equal(-1, g:Xsetlist([], ' ', {'items' : 'Test'}))
2229
Bram Moolenaar6a8958d2017-06-22 21:33:20 +02002230 " Save and restore the quickfix stack
2231 call g:Xsetlist([], 'f')
2232 call assert_equal(0, g:Xgetlist({'nr':'$'}).nr)
2233 Xexpr "File1:10:Line1"
2234 Xexpr "File2:20:Line2"
2235 Xexpr "File3:30:Line3"
2236 let last_qf = g:Xgetlist({'nr':'$'}).nr
2237 call assert_equal(3, last_qf)
2238 let qstack = []
2239 for i in range(1, last_qf)
2240 let qstack = add(qstack, g:Xgetlist({'nr':i, 'all':1}))
2241 endfor
2242 call g:Xsetlist([], 'f')
2243 for i in range(len(qstack))
2244 call g:Xsetlist([], ' ', qstack[i])
2245 endfor
2246 call assert_equal(3, g:Xgetlist({'nr':'$'}).nr)
2247 call assert_equal(10, g:Xgetlist({'nr':1, 'items':1}).items[0].lnum)
2248 call assert_equal(20, g:Xgetlist({'nr':2, 'items':1}).items[0].lnum)
2249 call assert_equal(30, g:Xgetlist({'nr':3, 'items':1}).items[0].lnum)
2250 call g:Xsetlist([], 'f')
2251
2252 " Swap two quickfix lists
2253 Xexpr "File1:10:Line10"
2254 Xexpr "File2:20:Line20"
2255 Xexpr "File3:30:Line30"
2256 call g:Xsetlist([], 'r', {'nr':1,'title':'Colors','context':['Colors']})
2257 call g:Xsetlist([], 'r', {'nr':2,'title':'Fruits','context':['Fruits']})
2258 let l1=g:Xgetlist({'nr':1,'all':1})
2259 let l2=g:Xgetlist({'nr':2,'all':1})
Bram Moolenaara539f4f2017-08-30 20:33:55 +02002260 let save_id = l1.id
2261 let l1.id=l2.id
2262 let l2.id=save_id
Bram Moolenaar6a8958d2017-06-22 21:33:20 +02002263 call g:Xsetlist([], 'r', l1)
2264 call g:Xsetlist([], 'r', l2)
2265 let newl1=g:Xgetlist({'nr':1,'all':1})
2266 let newl2=g:Xgetlist({'nr':2,'all':1})
Bram Moolenaarb4d5fba2017-09-11 19:31:28 +02002267 call assert_equal('Fruits', newl1.title)
Bram Moolenaar6a8958d2017-06-22 21:33:20 +02002268 call assert_equal(['Fruits'], newl1.context)
2269 call assert_equal('Line20', newl1.items[0].text)
Bram Moolenaarb4d5fba2017-09-11 19:31:28 +02002270 call assert_equal('Colors', newl2.title)
Bram Moolenaar6a8958d2017-06-22 21:33:20 +02002271 call assert_equal(['Colors'], newl2.context)
2272 call assert_equal('Line10', newl2.items[0].text)
2273 call g:Xsetlist([], 'f')
Bram Moolenaaree85df32017-03-19 14:19:50 +01002274endfunc
Bram Moolenaard823fa92016-08-12 16:29:27 +02002275
Bram Moolenaar2b946c92016-11-12 18:14:44 +01002276func Test_qf_property()
Bram Moolenaard823fa92016-08-12 16:29:27 +02002277 call Xproperty_tests('c')
2278 call Xproperty_tests('l')
Bram Moolenaaree85df32017-03-19 14:19:50 +01002279endfunc
Bram Moolenaar04c4ce62016-09-01 15:45:58 +02002280
Bram Moolenaar5b69c222019-01-11 14:50:06 +01002281" Test for setting the current index in the location/quickfix list
2282func Xtest_setqfidx(cchar)
2283 call s:setup_commands(a:cchar)
2284
2285 Xgetexpr "F1:10:1:Line1\nF2:20:2:Line2\nF3:30:3:Line3"
2286 Xgetexpr "F4:10:1:Line1\nF5:20:2:Line2\nF6:30:3:Line3"
2287 Xgetexpr "F7:10:1:Line1\nF8:20:2:Line2\nF9:30:3:Line3"
2288
2289 call g:Xsetlist([], 'a', {'nr' : 3, 'idx' : 2})
2290 call g:Xsetlist([], 'a', {'nr' : 2, 'idx' : 2})
2291 call g:Xsetlist([], 'a', {'nr' : 1, 'idx' : 3})
2292 Xolder 2
2293 Xopen
2294 call assert_equal(3, line('.'))
2295 Xnewer
2296 call assert_equal(2, line('.'))
2297 Xnewer
2298 call assert_equal(2, line('.'))
2299 " Update the current index with the quickfix window open
2300 wincmd w
2301 call g:Xsetlist([], 'a', {'nr' : 3, 'idx' : 3})
2302 Xopen
2303 call assert_equal(3, line('.'))
2304 Xclose
2305
2306 " Set the current index to the last entry
2307 call g:Xsetlist([], 'a', {'nr' : 1, 'idx' : '$'})
2308 call assert_equal(3, g:Xgetlist({'nr' : 1, 'idx' : 0}).idx)
2309 " A large value should set the index to the last index
2310 call g:Xsetlist([], 'a', {'nr' : 1, 'idx' : 1})
2311 call g:Xsetlist([], 'a', {'nr' : 1, 'idx' : 999})
2312 call assert_equal(3, g:Xgetlist({'nr' : 1, 'idx' : 0}).idx)
2313 " Invalid index values
2314 call g:Xsetlist([], 'a', {'nr' : 1, 'idx' : -1})
2315 call assert_equal(3, g:Xgetlist({'nr' : 1, 'idx' : 0}).idx)
2316 call g:Xsetlist([], 'a', {'nr' : 1, 'idx' : 0})
2317 call assert_equal(3, g:Xgetlist({'nr' : 1, 'idx' : 0}).idx)
2318 call g:Xsetlist([], 'a', {'nr' : 1, 'idx' : 'xx'})
2319 call assert_equal(3, g:Xgetlist({'nr' : 1, 'idx' : 0}).idx)
2320 call assert_fails("call g:Xsetlist([], 'a', {'nr':1, 'idx':[]})", 'E745:')
2321
2322 call g:Xsetlist([], 'f')
2323 new | only
2324endfunc
2325
2326func Test_setqfidx()
2327 call Xtest_setqfidx('c')
2328 call Xtest_setqfidx('l')
2329endfunc
2330
Bram Moolenaar04c4ce62016-09-01 15:45:58 +02002331" Tests for the QuickFixCmdPre/QuickFixCmdPost autocommands
Bram Moolenaar2b946c92016-11-12 18:14:44 +01002332func QfAutoCmdHandler(loc, cmd)
Bram Moolenaar04c4ce62016-09-01 15:45:58 +02002333 call add(g:acmds, a:loc . a:cmd)
Bram Moolenaar2b946c92016-11-12 18:14:44 +01002334endfunc
Bram Moolenaar04c4ce62016-09-01 15:45:58 +02002335
Bram Moolenaar2b946c92016-11-12 18:14:44 +01002336func Test_Autocmd()
Bram Moolenaar04c4ce62016-09-01 15:45:58 +02002337 autocmd QuickFixCmdPre * call QfAutoCmdHandler('pre', expand('<amatch>'))
2338 autocmd QuickFixCmdPost * call QfAutoCmdHandler('post', expand('<amatch>'))
2339
2340 let g:acmds = []
2341 cexpr "F1:10:Line 10"
2342 caddexpr "F1:20:Line 20"
2343 cgetexpr "F1:30:Line 30"
Bram Moolenaar1ed22762017-11-28 18:03:44 +01002344 cexpr ""
2345 caddexpr ""
2346 cgetexpr ""
2347 silent! cexpr non_existing_func()
2348 silent! caddexpr non_existing_func()
2349 silent! cgetexpr non_existing_func()
Bram Moolenaar04c4ce62016-09-01 15:45:58 +02002350 let l = ['precexpr',
2351 \ 'postcexpr',
2352 \ 'precaddexpr',
2353 \ 'postcaddexpr',
2354 \ 'precgetexpr',
2355 \ 'postcgetexpr',
Bram Moolenaar1ed22762017-11-28 18:03:44 +01002356 \ 'precexpr',
2357 \ 'postcexpr',
2358 \ 'precaddexpr',
2359 \ 'postcaddexpr',
2360 \ 'precgetexpr',
2361 \ 'postcgetexpr',
2362 \ 'precexpr',
2363 \ 'precaddexpr',
2364 \ 'precgetexpr']
2365 call assert_equal(l, g:acmds)
2366
2367 let g:acmds = []
2368 enew! | call append(0, "F2:10:Line 10")
2369 cbuffer!
2370 enew! | call append(0, "F2:20:Line 20")
2371 cgetbuffer
2372 enew! | call append(0, "F2:30:Line 30")
2373 caddbuffer
2374 new
2375 let bnum = bufnr('%')
2376 bunload
2377 exe 'silent! cbuffer! ' . bnum
2378 exe 'silent! cgetbuffer ' . bnum
2379 exe 'silent! caddbuffer ' . bnum
2380 enew!
2381 let l = ['precbuffer',
Bram Moolenaar04c4ce62016-09-01 15:45:58 +02002382 \ 'postcbuffer',
2383 \ 'precgetbuffer',
2384 \ 'postcgetbuffer',
2385 \ 'precaddbuffer',
Bram Moolenaar1ed22762017-11-28 18:03:44 +01002386 \ 'postcaddbuffer',
2387 \ 'precbuffer',
2388 \ 'precgetbuffer',
2389 \ 'precaddbuffer']
Bram Moolenaar04c4ce62016-09-01 15:45:58 +02002390 call assert_equal(l, g:acmds)
Bram Moolenaar1ed22762017-11-28 18:03:44 +01002391
2392 call writefile(['Xtest:1:Line1'], 'Xtest')
2393 call writefile([], 'Xempty')
2394 let g:acmds = []
2395 cfile Xtest
2396 caddfile Xtest
2397 cgetfile Xtest
2398 cfile Xempty
2399 caddfile Xempty
2400 cgetfile Xempty
2401 silent! cfile do_not_exist
2402 silent! caddfile do_not_exist
2403 silent! cgetfile do_not_exist
2404 let l = ['precfile',
2405 \ 'postcfile',
2406 \ 'precaddfile',
2407 \ 'postcaddfile',
2408 \ 'precgetfile',
2409 \ 'postcgetfile',
2410 \ 'precfile',
2411 \ 'postcfile',
2412 \ 'precaddfile',
2413 \ 'postcaddfile',
2414 \ 'precgetfile',
2415 \ 'postcgetfile',
2416 \ 'precfile',
2417 \ 'postcfile',
2418 \ 'precaddfile',
2419 \ 'postcaddfile',
2420 \ 'precgetfile',
2421 \ 'postcgetfile']
2422 call assert_equal(l, g:acmds)
2423
2424 let g:acmds = []
2425 helpgrep quickfix
2426 silent! helpgrep non_existing_help_topic
2427 vimgrep test Xtest
2428 vimgrepadd test Xtest
2429 silent! vimgrep non_existing_test Xtest
2430 silent! vimgrepadd non_existing_test Xtest
2431 set makeprg=
2432 silent! make
2433 set makeprg&
2434 let l = ['prehelpgrep',
2435 \ 'posthelpgrep',
2436 \ 'prehelpgrep',
2437 \ 'posthelpgrep',
2438 \ 'previmgrep',
2439 \ 'postvimgrep',
2440 \ 'previmgrepadd',
2441 \ 'postvimgrepadd',
2442 \ 'previmgrep',
2443 \ 'postvimgrep',
2444 \ 'previmgrepadd',
2445 \ 'postvimgrepadd',
2446 \ 'premake',
2447 \ 'postmake']
2448 call assert_equal(l, g:acmds)
2449
2450 if has('unix')
2451 " Run this test only on Unix-like systems. The grepprg may not be set on
2452 " non-Unix systems.
2453 " The following lines are used for the grep test. Don't remove.
2454 " Grep_Autocmd_Text: Match 1
2455 " GrepAdd_Autocmd_Text: Match 2
2456 let g:acmds = []
2457 silent grep Grep_Autocmd_Text test_quickfix.vim
2458 silent grepadd GrepAdd_Autocmd_Text test_quickfix.vim
2459 silent grep abc123def Xtest
2460 silent grepadd abc123def Xtest
2461 let l = ['pregrep',
2462 \ 'postgrep',
2463 \ 'pregrepadd',
2464 \ 'postgrepadd',
2465 \ 'pregrep',
2466 \ 'postgrep',
2467 \ 'pregrepadd',
2468 \ 'postgrepadd']
2469 call assert_equal(l, g:acmds)
2470 endif
2471
2472 call delete('Xtest')
2473 call delete('Xempty')
Bram Moolenaarb254af32017-12-18 19:48:58 +01002474 au! QuickFixCmdPre
2475 au! QuickFixCmdPost
Bram Moolenaar2b946c92016-11-12 18:14:44 +01002476endfunc
Bram Moolenaar21662be2016-11-06 14:46:44 +01002477
Bram Moolenaar2b946c92016-11-12 18:14:44 +01002478func Test_Autocmd_Exception()
Bram Moolenaar21662be2016-11-06 14:46:44 +01002479 set efm=%m
2480 lgetexpr '?'
2481
2482 try
2483 call DoesNotExit()
2484 catch
2485 lgetexpr '1'
2486 finally
2487 lgetexpr '1'
2488 endtry
2489
2490 call assert_equal('1', getloclist(0)[0].text)
2491
2492 set efm&vim
Bram Moolenaar2b946c92016-11-12 18:14:44 +01002493endfunc
Bram Moolenaar63bed3d2016-11-12 15:36:54 +01002494
Bram Moolenaar2b946c92016-11-12 18:14:44 +01002495func Test_caddbuffer_wrong()
2496 " This used to cause a memory access in freed memory.
Bram Moolenaar63bed3d2016-11-12 15:36:54 +01002497 let save_efm = &efm
2498 set efm=%EEEE%m,%WWWW,%+CCCC%>%#,%GGGG%.#
2499 cgetexpr ['WWWW', 'EEEE', 'CCCC']
2500 let &efm = save_efm
Bram Moolenaar2b946c92016-11-12 18:14:44 +01002501 caddbuffer
Bram Moolenaar63bed3d2016-11-12 15:36:54 +01002502 bwipe!
2503endfunc
Bram Moolenaar2b946c92016-11-12 18:14:44 +01002504
2505func Test_caddexpr_wrong()
2506 " This used to cause a memory access in freed memory.
2507 cbuffer
2508 cbuffer
2509 copen
2510 let save_efm = &efm
2511 set efm=%
2512 call assert_fails('caddexpr ""', 'E376:')
2513 let &efm = save_efm
2514endfunc
Bram Moolenaar7618e002016-11-13 15:09:26 +01002515
2516func Test_dirstack_cleanup()
2517 " This used to cause a memory access in freed memory.
2518 let save_efm = &efm
2519 lexpr '0'
2520 lopen
2521 fun X(c)
2522 let save_efm=&efm
2523 set efm=%D%f
2524 if a:c == 'c'
2525 caddexpr '::'
2526 else
2527 laddexpr ':0:0'
2528 endif
2529 let &efm=save_efm
2530 endfun
2531 call X('c')
2532 call X('l')
2533 call setqflist([], 'r')
2534 caddbuffer
2535 let &efm = save_efm
2536endfunc
Bram Moolenaar391b1dd2017-03-04 13:47:11 +01002537
2538" Tests for jumping to entries from the location list window and quickfix
2539" window
2540func Test_cwindow_jump()
2541 set efm=%f%%%l%%%m
2542 lgetexpr ["F1%10%Line 10", "F2%20%Line 20", "F3%30%Line 30"]
2543 lopen | only
2544 lfirst
2545 call assert_true(winnr('$') == 2)
2546 call assert_true(winnr() == 1)
2547 " Location list for the new window should be set
2548 call assert_true(getloclist(0)[2].text == 'Line 30')
2549
2550 " Open a scratch buffer
2551 " Open a new window and create a location list
2552 " Open the location list window and close the other window
2553 " Jump to an entry.
Bram Moolenaareeb1b9c2019-02-10 22:59:04 +01002554 " Should create a new window and jump to the entry. The scratch buffer
Bram Moolenaar391b1dd2017-03-04 13:47:11 +01002555 " should not be used.
2556 enew | only
2557 set buftype=nofile
2558 below new
2559 lgetexpr ["F1%10%Line 10", "F2%20%Line 20", "F3%30%Line 30"]
2560 lopen
2561 2wincmd c
2562 lnext
2563 call assert_true(winnr('$') == 3)
2564 call assert_true(winnr() == 2)
2565
2566 " Open two windows with two different location lists
2567 " Open the location list window and close the previous window
2568 " Jump to an entry in the location list window
2569 " Should open the file in the first window and not set the location list.
2570 enew | only
2571 lgetexpr ["F1%5%Line 5"]
2572 below new
2573 lgetexpr ["F1%10%Line 10", "F2%20%Line 20", "F3%30%Line 30"]
2574 lopen
2575 2wincmd c
2576 lnext
2577 call assert_true(winnr() == 1)
2578 call assert_true(getloclist(0)[0].text == 'Line 5')
2579
2580 enew | only
2581 cgetexpr ["F1%10%Line 10", "F2%20%Line 20", "F3%30%Line 30"]
2582 copen
2583 cnext
2584 call assert_true(winnr('$') == 2)
2585 call assert_true(winnr() == 1)
2586
Bram Moolenaarf9ae1542019-11-18 22:02:16 +01002587 " open the quickfix buffer in two windows and jump to an entry. Should open
2588 " the file in the first quickfix window.
2589 enew | only
2590 copen
2591 let bnum = bufnr('')
2592 exe 'sbuffer ' . bnum
2593 wincmd b
2594 cfirst
2595 call assert_equal(2, winnr())
2596 call assert_equal('F1', bufname(''))
2597 enew | only
2598 exe 'sb' bnum
2599 exe 'botright sb' bnum
2600 wincmd t
2601 clast
2602 call assert_equal(2, winnr())
2603 call assert_equal('quickfix', getwinvar(1, '&buftype'))
2604 call assert_equal('quickfix', getwinvar(3, '&buftype'))
2605
Bram Moolenaar391b1dd2017-03-04 13:47:11 +01002606 enew | only
2607 set efm&vim
2608endfunc
Bram Moolenaaree85df32017-03-19 14:19:50 +01002609
Bram Moolenaare00fdf32019-09-15 19:09:42 +02002610func Test_cwindow_highlight()
2611 CheckScreendump
2612
2613 let lines =<< trim END
2614 set t_u7=
2615 call setline(1, ['some', 'text', 'with', 'matches'])
2616 write XCwindow
2617 vimgrep e XCwindow
2618 redraw
2619 cwindow 4
2620 END
2621 call writefile(lines, 'XtestCwindow')
2622 let buf = RunVimInTerminal('-S XtestCwindow', #{rows: 12})
2623 call VerifyScreenDump(buf, 'Test_quickfix_cwindow_1', {})
2624
2625 call term_sendkeys(buf, ":cnext\<CR>")
2626 call VerifyScreenDump(buf, 'Test_quickfix_cwindow_2', {})
2627
2628 " clean up
2629 call StopVimInTerminal(buf)
2630 call delete('XtestCwindow')
2631 call delete('XCwindow')
2632endfunc
2633
Bram Moolenaaree85df32017-03-19 14:19:50 +01002634func XvimgrepTests(cchar)
2635 call s:setup_commands(a:cchar)
2636
2637 call writefile(['Editor:VIM vim',
2638 \ 'Editor:Emacs EmAcS',
2639 \ 'Editor:Notepad NOTEPAD'], 'Xtestfile1')
2640 call writefile(['Linux', 'MacOS', 'MS-Windows'], 'Xtestfile2')
2641
2642 " Error cases
2643 call assert_fails('Xvimgrep /abc *', 'E682:')
2644
2645 let @/=''
2646 call assert_fails('Xvimgrep // *', 'E35:')
2647
2648 call assert_fails('Xvimgrep abc', 'E683:')
2649 call assert_fails('Xvimgrep a1b2c3 Xtestfile1', 'E480:')
2650 call assert_fails('Xvimgrep pat Xa1b2c3', 'E480:')
2651
2652 Xexpr ""
2653 Xvimgrepadd Notepad Xtestfile1
2654 Xvimgrepadd MacOS Xtestfile2
2655 let l = g:Xgetlist()
2656 call assert_equal(2, len(l))
2657 call assert_equal('Editor:Notepad NOTEPAD', l[0].text)
2658
Bram Moolenaarf9ae1542019-11-18 22:02:16 +01002659 10Xvimgrep #\cvim#g Xtestfile?
Bram Moolenaaree85df32017-03-19 14:19:50 +01002660 let l = g:Xgetlist()
2661 call assert_equal(2, len(l))
2662 call assert_equal(8, l[0].col)
2663 call assert_equal(12, l[1].col)
2664
2665 1Xvimgrep ?Editor? Xtestfile*
2666 let l = g:Xgetlist()
2667 call assert_equal(1, len(l))
2668 call assert_equal('Editor:VIM vim', l[0].text)
2669
2670 edit +3 Xtestfile2
2671 Xvimgrep +\cemacs+j Xtestfile1
2672 let l = g:Xgetlist()
2673 call assert_equal('Xtestfile2', bufname(''))
2674 call assert_equal('Editor:Emacs EmAcS', l[0].text)
2675
Bram Moolenaar2225ebb2018-04-24 15:48:11 +02002676 " Test for unloading a buffer after vimgrep searched the buffer
2677 %bwipe
2678 Xvimgrep /Editor/j Xtestfile*
2679 call assert_equal(0, getbufinfo('Xtestfile1')[0].loaded)
2680 call assert_equal([], getbufinfo('Xtestfile2'))
2681
Bram Moolenaaree85df32017-03-19 14:19:50 +01002682 call delete('Xtestfile1')
2683 call delete('Xtestfile2')
2684endfunc
2685
2686" Tests for the :vimgrep command
2687func Test_vimgrep()
2688 call XvimgrepTests('c')
2689 call XvimgrepTests('l')
2690endfunc
Bram Moolenaar69f40be2017-04-02 15:15:49 +02002691
Bram Moolenaar1c299432018-10-28 14:36:09 +01002692" Test for incsearch highlighting of the :vimgrep pattern
2693" This test used to cause "E315: ml_get: invalid lnum" errors.
2694func Test_vimgrep_incsearch()
2695 enew
2696 set incsearch
2697 call test_override("char_avail", 1)
2698
2699 call feedkeys(":2vimgrep assert test_quickfix.vim test_cdo.vim\<CR>", "ntx")
2700 let l = getqflist()
2701 call assert_equal(2, len(l))
2702
2703 call test_override("ALL", 0)
2704 set noincsearch
2705endfunc
2706
Bram Moolenaar69f40be2017-04-02 15:15:49 +02002707func XfreeTests(cchar)
2708 call s:setup_commands(a:cchar)
2709
2710 enew | only
2711
2712 " Deleting the quickfix stack should work even When the current list is
2713 " somewhere in the middle of the stack
2714 Xexpr ['Xfile1:10:10:Line 10', 'Xfile1:15:15:Line 15']
2715 Xexpr ['Xfile2:20:20:Line 20', 'Xfile2:25:25:Line 25']
2716 Xexpr ['Xfile3:30:30:Line 30', 'Xfile3:35:35:Line 35']
2717 Xolder
2718 call g:Xsetlist([], 'f')
2719 call assert_equal(0, len(g:Xgetlist()))
2720
2721 " After deleting the stack, adding a new list should create a stack with a
2722 " single list.
2723 Xexpr ['Xfile1:10:10:Line 10', 'Xfile1:15:15:Line 15']
2724 call assert_equal(1, g:Xgetlist({'all':1}).nr)
2725
2726 " Deleting the stack from a quickfix window should update/clear the
2727 " quickfix/location list window.
2728 Xexpr ['Xfile1:10:10:Line 10', 'Xfile1:15:15:Line 15']
2729 Xexpr ['Xfile2:20:20:Line 20', 'Xfile2:25:25:Line 25']
2730 Xexpr ['Xfile3:30:30:Line 30', 'Xfile3:35:35:Line 35']
2731 Xolder
2732 Xwindow
2733 call g:Xsetlist([], 'f')
2734 call assert_equal(2, winnr('$'))
2735 call assert_equal(1, line('$'))
2736 Xclose
2737
2738 " Deleting the stack from a non-quickfix window should update/clear the
2739 " quickfix/location list window.
2740 Xexpr ['Xfile1:10:10:Line 10', 'Xfile1:15:15:Line 15']
2741 Xexpr ['Xfile2:20:20:Line 20', 'Xfile2:25:25:Line 25']
2742 Xexpr ['Xfile3:30:30:Line 30', 'Xfile3:35:35:Line 35']
2743 Xolder
2744 Xwindow
2745 wincmd p
2746 call g:Xsetlist([], 'f')
2747 call assert_equal(0, len(g:Xgetlist()))
2748 wincmd p
2749 call assert_equal(2, winnr('$'))
2750 call assert_equal(1, line('$'))
2751
2752 " After deleting the location list stack, if the location list window is
2753 " opened, then a new location list should be created. So opening the
2754 " location list window again should not create a new window.
2755 if a:cchar == 'l'
2756 lexpr ['Xfile1:10:10:Line 10', 'Xfile1:15:15:Line 15']
2757 wincmd p
2758 lopen
2759 call assert_equal(2, winnr('$'))
2760 endif
2761 Xclose
2762endfunc
2763
Bram Moolenaar74240d32017-12-10 15:26:15 +01002764" Tests for the quickfix free functionality
Bram Moolenaar69f40be2017-04-02 15:15:49 +02002765func Test_qf_free()
2766 call XfreeTests('c')
2767 call XfreeTests('l')
2768endfunc
Bram Moolenaar6e62da32017-05-28 08:16:25 +02002769
2770" Test for buffer overflow when parsing lines and adding new entries to
2771" the quickfix list.
2772func Test_bufoverflow()
2773 set efm=%f:%l:%m
2774 cgetexpr ['File1:100:' . repeat('x', 1025)]
2775
2776 set efm=%+GCompiler:\ %.%#,%f:%l:%m
2777 cgetexpr ['Compiler: ' . repeat('a', 1015), 'File1:10:Hello World']
2778
2779 set efm=%DEntering\ directory\ %f,%f:%l:%m
2780 cgetexpr ['Entering directory ' . repeat('a', 1006),
2781 \ 'File1:10:Hello World']
2782 set efm&vim
2783endfunc
2784
Bram Moolenaar875feea2017-06-11 16:07:51 +02002785" Tests for getting the quickfix stack size
2786func XsizeTests(cchar)
2787 call s:setup_commands(a:cchar)
2788
2789 call g:Xsetlist([], 'f')
2790 call assert_equal(0, g:Xgetlist({'nr':'$'}).nr)
Bram Moolenaara6d48492017-12-12 22:45:31 +01002791 call assert_equal('', g:Xgetlist({'nr':'$', 'all':1}).title)
2792 call assert_equal(0, g:Xgetlist({'nr':0}).nr)
Bram Moolenaar875feea2017-06-11 16:07:51 +02002793
2794 Xexpr "File1:10:Line1"
2795 Xexpr "File2:20:Line2"
2796 Xexpr "File3:30:Line3"
2797 Xolder | Xolder
2798 call assert_equal(3, g:Xgetlist({'nr':'$'}).nr)
2799 call g:Xsetlist([], 'f')
2800
2801 Xexpr "File1:10:Line1"
2802 Xexpr "File2:20:Line2"
2803 Xexpr "File3:30:Line3"
2804 Xolder | Xolder
2805 call g:Xsetlist([], 'a', {'nr':'$', 'title':'Compiler'})
2806 call assert_equal('Compiler', g:Xgetlist({'nr':3, 'all':1}).title)
2807endfunc
2808
2809func Test_Qf_Size()
2810 call XsizeTests('c')
2811 call XsizeTests('l')
2812endfunc
Bram Moolenaar18141832017-06-25 21:17:25 +02002813
Bram Moolenaar9c4feff2017-06-28 22:26:54 +02002814func Test_cclose_from_copen()
2815 augroup QF_Test
2816 au!
2817 au FileType qf :call assert_fails(':cclose', 'E788')
2818 augroup END
2819 copen
2820 augroup QF_Test
2821 au!
2822 augroup END
2823 augroup! QF_Test
2824endfunc
2825
Bram Moolenaar18141832017-06-25 21:17:25 +02002826func Test_cclose_in_autocmd()
2827 " Problem is only triggered if "starting" is zero, so that the OptionsSet
2828 " event will be triggered.
2829 call test_override('starting', 1)
2830 augroup QF_Test
2831 au!
2832 au FileType qf :call assert_fails(':cclose', 'E788')
2833 augroup END
2834 copen
2835 augroup QF_Test
2836 au!
2837 augroup END
2838 augroup! QF_Test
2839 call test_override('starting', 0)
2840endfunc
Bram Moolenaar9c4feff2017-06-28 22:26:54 +02002841
Bram Moolenaar379fb762018-08-30 15:58:28 +02002842" Check that ":file" without an argument is possible even when "curbuf_lock"
2843" is set.
2844func Test_file_from_copen()
2845 " Works without argument.
2846 augroup QF_Test
2847 au!
2848 au FileType qf file
2849 augroup END
2850 copen
2851
2852 augroup QF_Test
2853 au!
2854 augroup END
2855 cclose
2856
2857 " Fails with argument.
2858 augroup QF_Test
2859 au!
2860 au FileType qf call assert_fails(':file foo', 'E788')
2861 augroup END
2862 copen
2863 augroup QF_Test
2864 au!
2865 augroup END
2866 cclose
2867
2868 augroup! QF_Test
Bram Moolenaar6a0cc912019-10-26 16:48:44 +02002869endfunc
Bram Moolenaar379fb762018-08-30 15:58:28 +02002870
Bram Moolenaar9c4feff2017-06-28 22:26:54 +02002871func Test_resize_from_copen()
2872 augroup QF_Test
2873 au!
2874 au FileType qf resize 5
2875 augroup END
2876 try
2877 " This should succeed without any exception. No other buffers are
2878 " involved in the autocmd.
2879 copen
2880 finally
2881 augroup QF_Test
2882 au!
2883 augroup END
2884 augroup! QF_Test
2885 endtry
2886endfunc
Bram Moolenaara8788f42017-07-19 17:06:20 +02002887
2888" Tests for the quickfix buffer b:changedtick variable
2889func Xchangedtick_tests(cchar)
2890 call s:setup_commands(a:cchar)
2891
2892 new | only
2893
2894 Xexpr "" | Xexpr "" | Xexpr ""
2895
2896 Xopen
2897 Xolder
2898 Xolder
2899 Xaddexpr "F1:10:Line10"
2900 Xaddexpr "F2:20:Line20"
2901 call g:Xsetlist([{"filename":"F3", "lnum":30, "text":"Line30"}], 'a')
2902 call g:Xsetlist([], 'f')
2903 call assert_equal(8, getbufvar('%', 'changedtick'))
2904 Xclose
2905endfunc
2906
2907func Test_changedtick()
Bram Moolenaarae338332017-08-11 20:25:26 +02002908 call Xchangedtick_tests('c')
2909 call Xchangedtick_tests('l')
2910endfunc
2911
2912" Tests for parsing an expression using setqflist()
2913func Xsetexpr_tests(cchar)
2914 call s:setup_commands(a:cchar)
2915
2916 let t = ["File1:10:Line10", "File1:20:Line20"]
Bram Moolenaar2c809b72017-09-01 18:34:02 +02002917 call g:Xsetlist([], ' ', {'lines' : t})
2918 call g:Xsetlist([], 'a', {'lines' : ["File1:30:Line30"]})
Bram Moolenaarae338332017-08-11 20:25:26 +02002919
2920 let l = g:Xgetlist()
2921 call assert_equal(3, len(l))
2922 call assert_equal(20, l[1].lnum)
2923 call assert_equal('Line30', l[2].text)
Bram Moolenaar2c809b72017-09-01 18:34:02 +02002924 call g:Xsetlist([], 'r', {'lines' : ["File2:5:Line5"]})
Bram Moolenaarae338332017-08-11 20:25:26 +02002925 let l = g:Xgetlist()
2926 call assert_equal(1, len(l))
2927 call assert_equal('Line5', l[0].text)
Bram Moolenaar2c809b72017-09-01 18:34:02 +02002928 call assert_equal(-1, g:Xsetlist([], 'a', {'lines' : 10}))
2929 call assert_equal(-1, g:Xsetlist([], 'a', {'lines' : "F1:10:L10"}))
Bram Moolenaarae338332017-08-11 20:25:26 +02002930
2931 call g:Xsetlist([], 'f')
2932 " Add entries to multiple lists
Bram Moolenaar2c809b72017-09-01 18:34:02 +02002933 call g:Xsetlist([], 'a', {'nr' : 1, 'lines' : ["File1:10:Line10"]})
2934 call g:Xsetlist([], 'a', {'nr' : 2, 'lines' : ["File2:20:Line20"]})
2935 call g:Xsetlist([], 'a', {'nr' : 1, 'lines' : ["File1:15:Line15"]})
2936 call g:Xsetlist([], 'a', {'nr' : 2, 'lines' : ["File2:25:Line25"]})
Bram Moolenaarae338332017-08-11 20:25:26 +02002937 call assert_equal('Line15', g:Xgetlist({'nr':1, 'items':1}).items[1].text)
2938 call assert_equal('Line25', g:Xgetlist({'nr':2, 'items':1}).items[1].text)
Bram Moolenaar36538222017-09-02 19:51:44 +02002939
2940 " Adding entries using a custom efm
2941 set efm&
2942 call g:Xsetlist([], ' ', {'efm' : '%f#%l#%m',
2943 \ 'lines' : ["F1#10#L10", "F2#20#L20"]})
2944 call assert_equal(20, g:Xgetlist({'items':1}).items[1].lnum)
2945 call g:Xsetlist([], 'a', {'efm' : '%f#%l#%m', 'lines' : ["F3:30:L30"]})
2946 call assert_equal('F3:30:L30', g:Xgetlist({'items':1}).items[2].text)
2947 call assert_equal(20, g:Xgetlist({'items':1}).items[1].lnum)
2948 call assert_equal(-1, g:Xsetlist([], 'a', {'efm' : [],
2949 \ 'lines' : ['F1:10:L10']}))
Bram Moolenaarae338332017-08-11 20:25:26 +02002950endfunc
2951
2952func Test_setexpr()
2953 call Xsetexpr_tests('c')
2954 call Xsetexpr_tests('l')
2955endfunc
2956
2957" Tests for per quickfix/location list directory stack
2958func Xmultidirstack_tests(cchar)
2959 call s:setup_commands(a:cchar)
2960
2961 call g:Xsetlist([], 'f')
2962 Xexpr "" | Xexpr ""
2963
Bram Moolenaar2c809b72017-09-01 18:34:02 +02002964 call g:Xsetlist([], 'a', {'nr' : 1, 'lines' : ["Entering dir 'Xone/a'"]})
2965 call g:Xsetlist([], 'a', {'nr' : 2, 'lines' : ["Entering dir 'Xtwo/a'"]})
2966 call g:Xsetlist([], 'a', {'nr' : 1, 'lines' : ["one.txt:3:one one one"]})
2967 call g:Xsetlist([], 'a', {'nr' : 2, 'lines' : ["two.txt:5:two two two"]})
Bram Moolenaarae338332017-08-11 20:25:26 +02002968
2969 let l1 = g:Xgetlist({'nr':1, 'items':1})
2970 let l2 = g:Xgetlist({'nr':2, 'items':1})
2971 call assert_equal('Xone/a/one.txt', bufname(l1.items[1].bufnr))
2972 call assert_equal(3, l1.items[1].lnum)
2973 call assert_equal('Xtwo/a/two.txt', bufname(l2.items[1].bufnr))
2974 call assert_equal(5, l2.items[1].lnum)
2975endfunc
2976
2977func Test_multidirstack()
2978 call mkdir('Xone/a', 'p')
2979 call mkdir('Xtwo/a', 'p')
2980 let lines = ['1', '2', 'one one one', '4', 'two two two', '6', '7']
2981 call writefile(lines, 'Xone/a/one.txt')
2982 call writefile(lines, 'Xtwo/a/two.txt')
2983 let save_efm = &efm
2984 set efm=%DEntering\ dir\ '%f',%f:%l:%m,%XLeaving\ dir\ '%f'
2985
2986 call Xmultidirstack_tests('c')
2987 call Xmultidirstack_tests('l')
2988
2989 let &efm = save_efm
2990 call delete('Xone', 'rf')
2991 call delete('Xtwo', 'rf')
2992endfunc
2993
2994" Tests for per quickfix/location list file stack
2995func Xmultifilestack_tests(cchar)
2996 call s:setup_commands(a:cchar)
2997
2998 call g:Xsetlist([], 'f')
2999 Xexpr "" | Xexpr ""
3000
Bram Moolenaar2c809b72017-09-01 18:34:02 +02003001 call g:Xsetlist([], 'a', {'nr' : 1, 'lines' : ["[one.txt]"]})
3002 call g:Xsetlist([], 'a', {'nr' : 2, 'lines' : ["[two.txt]"]})
3003 call g:Xsetlist([], 'a', {'nr' : 1, 'lines' : ["(3,5) one one one"]})
3004 call g:Xsetlist([], 'a', {'nr' : 2, 'lines' : ["(5,9) two two two"]})
Bram Moolenaarae338332017-08-11 20:25:26 +02003005
3006 let l1 = g:Xgetlist({'nr':1, 'items':1})
3007 let l2 = g:Xgetlist({'nr':2, 'items':1})
3008 call assert_equal('one.txt', bufname(l1.items[1].bufnr))
3009 call assert_equal(3, l1.items[1].lnum)
3010 call assert_equal('two.txt', bufname(l2.items[1].bufnr))
3011 call assert_equal(5, l2.items[1].lnum)
Bram Moolenaare333e792018-04-08 13:27:39 +02003012
3013 " Test for start of a new error line in the same line where a previous
3014 " error line ends with a file stack.
3015 let efm_val = 'Error\ l%l\ in\ %f,'
3016 let efm_val .= '%-P%>(%f%r,Error\ l%l\ in\ %m,%-Q)%r'
3017 let l = g:Xgetlist({'lines' : [
3018 \ '(one.txt',
3019 \ 'Error l4 in one.txt',
3020 \ ') (two.txt',
3021 \ 'Error l6 in two.txt',
3022 \ ')',
3023 \ 'Error l8 in one.txt'
3024 \ ], 'efm' : efm_val})
3025 call assert_equal(3, len(l.items))
3026 call assert_equal('one.txt', bufname(l.items[0].bufnr))
3027 call assert_equal(4, l.items[0].lnum)
3028 call assert_equal('one.txt', l.items[0].text)
3029 call assert_equal('two.txt', bufname(l.items[1].bufnr))
3030 call assert_equal(6, l.items[1].lnum)
3031 call assert_equal('two.txt', l.items[1].text)
3032 call assert_equal('one.txt', bufname(l.items[2].bufnr))
3033 call assert_equal(8, l.items[2].lnum)
3034 call assert_equal('', l.items[2].text)
Bram Moolenaarae338332017-08-11 20:25:26 +02003035endfunc
3036
3037func Test_multifilestack()
3038 let lines = ['1', '2', 'one one one', '4', 'two two two', '6', '7']
3039 call writefile(lines, 'one.txt')
3040 call writefile(lines, 'two.txt')
3041 let save_efm = &efm
3042 set efm=%+P[%f],(%l\\,%c)\ %m,%-Q
3043
3044 call Xmultifilestack_tests('c')
3045 call Xmultifilestack_tests('l')
3046
3047 let &efm = save_efm
3048 call delete('one.txt')
3049 call delete('two.txt')
3050endfunc
3051
3052" Tests for per buffer 'efm' setting
3053func Test_perbuf_efm()
3054 call writefile(["File1-10-Line10"], 'one.txt')
3055 call writefile(["File2#20#Line20"], 'two.txt')
3056 set efm=%f#%l#%m
3057 new | only
3058 new
3059 setlocal efm=%f-%l-%m
3060 cfile one.txt
3061 wincmd w
3062 caddfile two.txt
3063
3064 let l = getqflist()
3065 call assert_equal(10, l[0].lnum)
3066 call assert_equal('Line20', l[1].text)
3067
3068 set efm&
3069 new | only
3070 call delete('one.txt')
3071 call delete('two.txt')
Bram Moolenaara8788f42017-07-19 17:06:20 +02003072endfunc
Bram Moolenaard28cc3f2017-07-27 22:03:50 +02003073
3074" Open multiple help windows using ":lhelpgrep
3075" This test used to crash Vim
3076func Test_Multi_LL_Help()
3077 new | only
3078 lhelpgrep window
3079 lopen
3080 e#
3081 lhelpgrep buffer
3082 call assert_equal(3, winnr('$'))
3083 call assert_true(len(getloclist(1)) != 0)
3084 call assert_true(len(getloclist(2)) != 0)
3085 new | only
3086endfunc
Bram Moolenaar55b69262017-08-13 13:42:01 +02003087
3088" Tests for adding new quickfix lists using setqflist()
3089func XaddQf_tests(cchar)
3090 call s:setup_commands(a:cchar)
3091
3092 " Create a new list using ' ' for action
3093 call g:Xsetlist([], 'f')
3094 call g:Xsetlist([], ' ', {'title' : 'Test1'})
3095 let l = g:Xgetlist({'nr' : '$', 'all' : 1})
3096 call assert_equal(1, l.nr)
3097 call assert_equal('Test1', l.title)
3098
3099 " Create a new list using ' ' for action and '$' for 'nr'
3100 call g:Xsetlist([], 'f')
3101 call g:Xsetlist([], ' ', {'title' : 'Test2', 'nr' : '$'})
3102 let l = g:Xgetlist({'nr' : '$', 'all' : 1})
3103 call assert_equal(1, l.nr)
3104 call assert_equal('Test2', l.title)
3105
3106 " Create a new list using 'a' for action
3107 call g:Xsetlist([], 'f')
3108 call g:Xsetlist([], 'a', {'title' : 'Test3'})
3109 let l = g:Xgetlist({'nr' : '$', 'all' : 1})
3110 call assert_equal(1, l.nr)
3111 call assert_equal('Test3', l.title)
3112
3113 " Create a new list using 'a' for action and '$' for 'nr'
3114 call g:Xsetlist([], 'f')
3115 call g:Xsetlist([], 'a', {'title' : 'Test3', 'nr' : '$'})
3116 call g:Xsetlist([], 'a', {'title' : 'Test4'})
3117 let l = g:Xgetlist({'nr' : '$', 'all' : 1})
3118 call assert_equal(1, l.nr)
3119 call assert_equal('Test4', l.title)
3120
3121 " Adding a quickfix list should remove all the lists following the current
3122 " list.
3123 Xexpr "" | Xexpr "" | Xexpr ""
3124 silent! 10Xolder
3125 call g:Xsetlist([], ' ', {'title' : 'Test5'})
3126 let l = g:Xgetlist({'nr' : '$', 'all' : 1})
3127 call assert_equal(2, l.nr)
3128 call assert_equal('Test5', l.title)
3129
3130 " Add a quickfix list using '$' as the list number.
3131 let lastqf = g:Xgetlist({'nr':'$'}).nr
3132 silent! 99Xolder
3133 call g:Xsetlist([], ' ', {'nr' : '$', 'title' : 'Test6'})
3134 let l = g:Xgetlist({'nr' : '$', 'all' : 1})
3135 call assert_equal(lastqf + 1, l.nr)
3136 call assert_equal('Test6', l.title)
3137
3138 " Add a quickfix list using 'nr' set to one more than the quickfix
3139 " list size.
3140 let lastqf = g:Xgetlist({'nr':'$'}).nr
3141 silent! 99Xolder
3142 call g:Xsetlist([], ' ', {'nr' : lastqf + 1, 'title' : 'Test7'})
3143 let l = g:Xgetlist({'nr' : '$', 'all' : 1})
3144 call assert_equal(lastqf + 1, l.nr)
3145 call assert_equal('Test7', l.title)
3146
3147 " Add a quickfix list to a stack with 10 lists using 'nr' set to '$'
3148 exe repeat('Xexpr "" |', 9) . 'Xexpr ""'
3149 silent! 99Xolder
3150 call g:Xsetlist([], ' ', {'nr' : '$', 'title' : 'Test8'})
3151 let l = g:Xgetlist({'nr' : '$', 'all' : 1})
3152 call assert_equal(10, l.nr)
3153 call assert_equal('Test8', l.title)
3154
3155 " Add a quickfix list using 'nr' set to a value greater than 10
3156 call assert_equal(-1, g:Xsetlist([], ' ', {'nr' : 12, 'title' : 'Test9'}))
3157
3158 " Try adding a quickfix list with 'nr' set to a value greater than the
3159 " quickfix list size but less than 10.
3160 call g:Xsetlist([], 'f')
3161 Xexpr "" | Xexpr "" | Xexpr ""
3162 silent! 99Xolder
3163 call assert_equal(-1, g:Xsetlist([], ' ', {'nr' : 8, 'title' : 'Test10'}))
3164
3165 " Add a quickfix list using 'nr' set to a some string or list
3166 call assert_equal(-1, g:Xsetlist([], ' ', {'nr' : [1,2], 'title' : 'Test11'}))
3167endfunc
3168
3169func Test_add_qf()
3170 call XaddQf_tests('c')
3171 call XaddQf_tests('l')
3172endfunc
Bram Moolenaar7adf06f2017-08-27 15:23:41 +02003173
3174" Test for getting the quickfix list items from some text without modifying
3175" the quickfix stack
Bram Moolenaar2c809b72017-09-01 18:34:02 +02003176func XgetListFromLines(cchar)
Bram Moolenaar7adf06f2017-08-27 15:23:41 +02003177 call s:setup_commands(a:cchar)
3178 call g:Xsetlist([], 'f')
3179
Bram Moolenaar2c809b72017-09-01 18:34:02 +02003180 let l = g:Xgetlist({'lines' : ["File2:20:Line20", "File2:30:Line30"]}).items
Bram Moolenaar7adf06f2017-08-27 15:23:41 +02003181 call assert_equal(2, len(l))
3182 call assert_equal(30, l[1].lnum)
3183
Bram Moolenaar2c809b72017-09-01 18:34:02 +02003184 call assert_equal({}, g:Xgetlist({'lines' : 10}))
3185 call assert_equal({}, g:Xgetlist({'lines' : 'File1:10:Line10'}))
3186 call assert_equal([], g:Xgetlist({'lines' : []}).items)
3187 call assert_equal([], g:Xgetlist({'lines' : [10, 20]}).items)
Bram Moolenaar7adf06f2017-08-27 15:23:41 +02003188
Bram Moolenaar36538222017-09-02 19:51:44 +02003189 " Parse text using a custom efm
3190 set efm&
3191 let l = g:Xgetlist({'lines':['File3#30#Line30'], 'efm' : '%f#%l#%m'}).items
3192 call assert_equal('Line30', l[0].text)
3193 let l = g:Xgetlist({'lines':['File3:30:Line30'], 'efm' : '%f-%l-%m'}).items
3194 call assert_equal('File3:30:Line30', l[0].text)
3195 let l = g:Xgetlist({'lines':['File3:30:Line30'], 'efm' : [1,2]})
3196 call assert_equal({}, l)
3197 call assert_fails("call g:Xgetlist({'lines':['abc'], 'efm':'%2'})", 'E376:')
3198 call assert_fails("call g:Xgetlist({'lines':['abc'], 'efm':''})", 'E378:')
3199
Bram Moolenaar7adf06f2017-08-27 15:23:41 +02003200 " Make sure that the quickfix stack is not modified
3201 call assert_equal(0, g:Xgetlist({'nr' : '$'}).nr)
3202endfunc
3203
Bram Moolenaar2c809b72017-09-01 18:34:02 +02003204func Test_get_list_from_lines()
3205 call XgetListFromLines('c')
3206 call XgetListFromLines('l')
Bram Moolenaar7adf06f2017-08-27 15:23:41 +02003207endfunc
Bram Moolenaara539f4f2017-08-30 20:33:55 +02003208
3209" Tests for the quickfix list id
3210func Xqfid_tests(cchar)
3211 call s:setup_commands(a:cchar)
3212
3213 call g:Xsetlist([], 'f')
Bram Moolenaara6d48492017-12-12 22:45:31 +01003214 call assert_equal(0, g:Xgetlist({'id':0}).id)
Bram Moolenaara539f4f2017-08-30 20:33:55 +02003215 Xexpr ''
3216 let start_id = g:Xgetlist({'id' : 0}).id
3217 Xexpr '' | Xexpr ''
3218 Xolder
3219 call assert_equal(start_id, g:Xgetlist({'id':0, 'nr':1}).id)
3220 call assert_equal(start_id + 1, g:Xgetlist({'id':0, 'nr':0}).id)
3221 call assert_equal(start_id + 2, g:Xgetlist({'id':0, 'nr':'$'}).id)
Bram Moolenaara6d48492017-12-12 22:45:31 +01003222 call assert_equal(0, g:Xgetlist({'id':0, 'nr':99}).id)
Bram Moolenaara539f4f2017-08-30 20:33:55 +02003223 call assert_equal(2, g:Xgetlist({'id':start_id + 1, 'nr':0}).nr)
Bram Moolenaara6d48492017-12-12 22:45:31 +01003224 call assert_equal(0, g:Xgetlist({'id':99, 'nr':0}).id)
3225 call assert_equal(0, g:Xgetlist({'id':"abc", 'nr':0}).id)
Bram Moolenaara539f4f2017-08-30 20:33:55 +02003226
3227 call g:Xsetlist([], 'a', {'id':start_id, 'context':[1,2]})
3228 call assert_equal([1,2], g:Xgetlist({'nr':1, 'context':1}).context)
Bram Moolenaar2c809b72017-09-01 18:34:02 +02003229 call g:Xsetlist([], 'a', {'id':start_id+1, 'lines':['F1:10:L10']})
Bram Moolenaara539f4f2017-08-30 20:33:55 +02003230 call assert_equal('L10', g:Xgetlist({'nr':2, 'items':1}).items[0].text)
3231 call assert_equal(-1, g:Xsetlist([], 'a', {'id':999, 'title':'Vim'}))
3232 call assert_equal(-1, g:Xsetlist([], 'a', {'id':'abc', 'title':'Vim'}))
3233
3234 let qfid = g:Xgetlist({'id':0, 'nr':0})
3235 call g:Xsetlist([], 'f')
Bram Moolenaara6d48492017-12-12 22:45:31 +01003236 call assert_equal(0, g:Xgetlist({'id':qfid, 'nr':0}).id)
Bram Moolenaara539f4f2017-08-30 20:33:55 +02003237endfunc
3238
3239func Test_qf_id()
3240 call Xqfid_tests('c')
3241 call Xqfid_tests('l')
3242endfunc
Bram Moolenaar74240d32017-12-10 15:26:15 +01003243
3244func Xqfjump_tests(cchar)
3245 call s:setup_commands(a:cchar)
3246
3247 call writefile(["Line1\tFoo", "Line2"], 'F1')
3248 call writefile(["Line1\tBar", "Line2"], 'F2')
3249 call writefile(["Line1\tBaz", "Line2"], 'F3')
3250
3251 call g:Xsetlist([], 'f')
3252
3253 " Tests for
3254 " Jumping to a line using a pattern
3255 " Jumping to a column greater than the last column in a line
3256 " Jumping to a line greater than the last line in the file
3257 let l = []
3258 for i in range(1, 7)
3259 call add(l, {})
3260 endfor
3261 let l[0].filename='F1'
3262 let l[0].pattern='Line1'
3263 let l[1].filename='F2'
3264 let l[1].pattern='Line1'
3265 let l[2].filename='F3'
3266 let l[2].pattern='Line1'
3267 let l[3].filename='F3'
3268 let l[3].lnum=1
3269 let l[3].col=9
3270 let l[3].vcol=1
3271 let l[4].filename='F3'
3272 let l[4].lnum=99
3273 let l[5].filename='F3'
3274 let l[5].lnum=1
3275 let l[5].col=99
3276 let l[5].vcol=1
3277 let l[6].filename='F3'
3278 let l[6].pattern='abcxyz'
3279
3280 call g:Xsetlist([], ' ', {'items' : l})
3281 Xopen | only
3282 2Xnext
3283 call assert_equal(3, g:Xgetlist({'idx' : 0}).idx)
3284 call assert_equal('F3', bufname('%'))
3285 Xnext
3286 call assert_equal(7, col('.'))
3287 Xnext
3288 call assert_equal(2, line('.'))
3289 Xnext
3290 call assert_equal(9, col('.'))
3291 2
3292 Xnext
3293 call assert_equal(2, line('.'))
3294
3295 if a:cchar == 'l'
3296 " When jumping to a location list entry in the location list window and
3297 " no usable windows are available, then a new window should be opened.
3298 enew! | new | only
3299 call g:Xsetlist([], 'f')
3300 setlocal buftype=nofile
3301 new
3302 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']})
3303 Xopen
3304 let winid = win_getid()
3305 wincmd p
3306 close
3307 call win_gotoid(winid)
3308 Xnext
3309 call assert_equal(3, winnr('$'))
3310 call assert_equal(1, winnr())
3311 call assert_equal(2, line('.'))
3312
3313 " When jumping to an entry in the location list window and the window
3314 " associated with the location list is not present and a window containing
3315 " the file is already present, then that window should be used.
3316 close
3317 belowright new
3318 call g:Xsetlist([], 'f')
3319 edit F3
3320 call win_gotoid(winid)
3321 Xlast
3322 call assert_equal(3, winnr())
3323 call assert_equal(6, g:Xgetlist({'size' : 1}).size)
3324 call assert_equal(winid, g:Xgetlist({'winid' : 1}).winid)
3325 endif
3326
3327 " Cleanup
3328 enew!
3329 new | only
3330
3331 call delete('F1')
3332 call delete('F2')
3333 call delete('F3')
3334endfunc
3335
3336func Test_qfjump()
3337 call Xqfjump_tests('c')
3338 call Xqfjump_tests('l')
3339endfunc
Bram Moolenaara6d48492017-12-12 22:45:31 +01003340
3341" Tests for the getqflist() and getloclist() functions when the list is not
3342" present or is empty
3343func Xgetlist_empty_tests(cchar)
3344 call s:setup_commands(a:cchar)
3345
3346 " Empty quickfix stack
3347 call g:Xsetlist([], 'f')
3348 call assert_equal('', g:Xgetlist({'context' : 0}).context)
3349 call assert_equal(0, g:Xgetlist({'id' : 0}).id)
3350 call assert_equal(0, g:Xgetlist({'idx' : 0}).idx)
3351 call assert_equal([], g:Xgetlist({'items' : 0}).items)
3352 call assert_equal(0, g:Xgetlist({'nr' : 0}).nr)
3353 call assert_equal(0, g:Xgetlist({'size' : 0}).size)
3354 call assert_equal('', g:Xgetlist({'title' : 0}).title)
3355 call assert_equal(0, g:Xgetlist({'winid' : 0}).winid)
Bram Moolenaarb254af32017-12-18 19:48:58 +01003356 call assert_equal(0, g:Xgetlist({'changedtick' : 0}).changedtick)
Bram Moolenaarc9cc9c72018-09-02 15:18:42 +02003357 if a:cchar == 'c'
3358 call assert_equal({'context' : '', 'id' : 0, 'idx' : 0,
Bram Moolenaar647e24b2019-03-17 16:39:46 +01003359 \ 'items' : [], 'nr' : 0, 'size' : 0, 'qfbufnr' : 0,
Bram Moolenaarc9cc9c72018-09-02 15:18:42 +02003360 \ 'title' : '', 'winid' : 0, 'changedtick': 0},
3361 \ g:Xgetlist({'all' : 0}))
3362 else
3363 call assert_equal({'context' : '', 'id' : 0, 'idx' : 0,
3364 \ 'items' : [], 'nr' : 0, 'size' : 0, 'title' : '',
Bram Moolenaar647e24b2019-03-17 16:39:46 +01003365 \ 'winid' : 0, 'changedtick': 0, 'filewinid' : 0,
3366 \ 'qfbufnr' : 0},
Bram Moolenaarc9cc9c72018-09-02 15:18:42 +02003367 \ g:Xgetlist({'all' : 0}))
3368 endif
Bram Moolenaara6d48492017-12-12 22:45:31 +01003369
Bram Moolenaar2ec364e2018-01-27 11:52:13 +01003370 " Quickfix window with empty stack
3371 silent! Xopen
3372 let qfwinid = (a:cchar == 'c') ? win_getid() : 0
Bram Moolenaar647e24b2019-03-17 16:39:46 +01003373 let qfbufnr = (a:cchar == 'c') ? bufnr('') : 0
Bram Moolenaar2ec364e2018-01-27 11:52:13 +01003374 call assert_equal(qfwinid, g:Xgetlist({'winid' : 0}).winid)
3375 Xclose
3376
Bram Moolenaara6d48492017-12-12 22:45:31 +01003377 " Empty quickfix list
3378 Xexpr ""
3379 call assert_equal('', g:Xgetlist({'context' : 0}).context)
3380 call assert_notequal(0, g:Xgetlist({'id' : 0}).id)
3381 call assert_equal(0, g:Xgetlist({'idx' : 0}).idx)
3382 call assert_equal([], g:Xgetlist({'items' : 0}).items)
3383 call assert_notequal(0, g:Xgetlist({'nr' : 0}).nr)
3384 call assert_equal(0, g:Xgetlist({'size' : 0}).size)
3385 call assert_notequal('', g:Xgetlist({'title' : 0}).title)
3386 call assert_equal(0, g:Xgetlist({'winid' : 0}).winid)
Bram Moolenaarb254af32017-12-18 19:48:58 +01003387 call assert_equal(1, g:Xgetlist({'changedtick' : 0}).changedtick)
Bram Moolenaara6d48492017-12-12 22:45:31 +01003388
3389 let qfid = g:Xgetlist({'id' : 0}).id
3390 call g:Xsetlist([], 'f')
3391
3392 " Non-existing quickfix identifier
3393 call assert_equal('', g:Xgetlist({'id' : qfid, 'context' : 0}).context)
3394 call assert_equal(0, g:Xgetlist({'id' : qfid}).id)
3395 call assert_equal(0, g:Xgetlist({'id' : qfid, 'idx' : 0}).idx)
3396 call assert_equal([], g:Xgetlist({'id' : qfid, 'items' : 0}).items)
3397 call assert_equal(0, g:Xgetlist({'id' : qfid, 'nr' : 0}).nr)
3398 call assert_equal(0, g:Xgetlist({'id' : qfid, 'size' : 0}).size)
3399 call assert_equal('', g:Xgetlist({'id' : qfid, 'title' : 0}).title)
3400 call assert_equal(0, g:Xgetlist({'id' : qfid, 'winid' : 0}).winid)
Bram Moolenaarb254af32017-12-18 19:48:58 +01003401 call assert_equal(0, g:Xgetlist({'id' : qfid, 'changedtick' : 0}).changedtick)
Bram Moolenaarc9cc9c72018-09-02 15:18:42 +02003402 if a:cchar == 'c'
3403 call assert_equal({'context' : '', 'id' : 0, 'idx' : 0, 'items' : [],
3404 \ 'nr' : 0, 'size' : 0, 'title' : '', 'winid' : 0,
Bram Moolenaar647e24b2019-03-17 16:39:46 +01003405 \ 'qfbufnr' : qfbufnr,
Bram Moolenaarc9cc9c72018-09-02 15:18:42 +02003406 \ 'changedtick' : 0}, g:Xgetlist({'id' : qfid, 'all' : 0}))
3407 else
3408 call assert_equal({'context' : '', 'id' : 0, 'idx' : 0, 'items' : [],
3409 \ 'nr' : 0, 'size' : 0, 'title' : '', 'winid' : 0,
Bram Moolenaar647e24b2019-03-17 16:39:46 +01003410 \ 'changedtick' : 0, 'filewinid' : 0, 'qfbufnr' : 0},
Bram Moolenaarc9cc9c72018-09-02 15:18:42 +02003411 \ g:Xgetlist({'id' : qfid, 'all' : 0}))
3412 endif
Bram Moolenaara6d48492017-12-12 22:45:31 +01003413
3414 " Non-existing quickfix list number
3415 call assert_equal('', g:Xgetlist({'nr' : 5, 'context' : 0}).context)
3416 call assert_equal(0, g:Xgetlist({'nr' : 5}).nr)
3417 call assert_equal(0, g:Xgetlist({'nr' : 5, 'idx' : 0}).idx)
3418 call assert_equal([], g:Xgetlist({'nr' : 5, 'items' : 0}).items)
3419 call assert_equal(0, g:Xgetlist({'nr' : 5, 'id' : 0}).id)
3420 call assert_equal(0, g:Xgetlist({'nr' : 5, 'size' : 0}).size)
3421 call assert_equal('', g:Xgetlist({'nr' : 5, 'title' : 0}).title)
3422 call assert_equal(0, g:Xgetlist({'nr' : 5, 'winid' : 0}).winid)
Bram Moolenaarb254af32017-12-18 19:48:58 +01003423 call assert_equal(0, g:Xgetlist({'nr' : 5, 'changedtick' : 0}).changedtick)
Bram Moolenaarc9cc9c72018-09-02 15:18:42 +02003424 if a:cchar == 'c'
3425 call assert_equal({'context' : '', 'id' : 0, 'idx' : 0, 'items' : [],
3426 \ 'nr' : 0, 'size' : 0, 'title' : '', 'winid' : 0,
Bram Moolenaar647e24b2019-03-17 16:39:46 +01003427 \ 'changedtick' : 0, 'qfbufnr' : qfbufnr},
3428 \ g:Xgetlist({'nr' : 5, 'all' : 0}))
Bram Moolenaarc9cc9c72018-09-02 15:18:42 +02003429 else
3430 call assert_equal({'context' : '', 'id' : 0, 'idx' : 0, 'items' : [],
3431 \ 'nr' : 0, 'size' : 0, 'title' : '', 'winid' : 0,
Bram Moolenaar647e24b2019-03-17 16:39:46 +01003432 \ 'changedtick' : 0, 'filewinid' : 0, 'qfbufnr' : 0},
Bram Moolenaarc9cc9c72018-09-02 15:18:42 +02003433 \ g:Xgetlist({'nr' : 5, 'all' : 0}))
3434 endif
Bram Moolenaara6d48492017-12-12 22:45:31 +01003435endfunc
3436
3437func Test_getqflist()
3438 call Xgetlist_empty_tests('c')
3439 call Xgetlist_empty_tests('l')
3440endfunc
Bram Moolenaarb254af32017-12-18 19:48:58 +01003441
Bram Moolenaara0ca7d02017-12-19 10:22:19 +01003442func Test_getqflist_invalid_nr()
3443 " The following commands used to crash Vim
3444 cexpr ""
3445 call getqflist({'nr' : $XXX_DOES_NOT_EXIST_XXX})
3446
3447 " Cleanup
3448 call setqflist([], 'r')
3449endfunc
3450
Bram Moolenaarb254af32017-12-18 19:48:58 +01003451" Tests for the quickfix/location list changedtick
3452func Xqftick_tests(cchar)
3453 call s:setup_commands(a:cchar)
3454
3455 call g:Xsetlist([], 'f')
3456
3457 Xexpr "F1:10:Line10"
3458 let qfid = g:Xgetlist({'id' : 0}).id
3459 call assert_equal(1, g:Xgetlist({'changedtick' : 0}).changedtick)
3460 Xaddexpr "F2:20:Line20\nF2:21:Line21"
3461 call assert_equal(2, g:Xgetlist({'changedtick' : 0}).changedtick)
3462 call g:Xsetlist([], 'a', {'lines' : ["F3:30:Line30", "F3:31:Line31"]})
3463 call assert_equal(3, g:Xgetlist({'changedtick' : 0}).changedtick)
3464 call g:Xsetlist([], 'r', {'lines' : ["F4:40:Line40"]})
3465 call assert_equal(4, g:Xgetlist({'changedtick' : 0}).changedtick)
3466 call g:Xsetlist([], 'a', {'title' : 'New Title'})
3467 call assert_equal(5, g:Xgetlist({'changedtick' : 0}).changedtick)
3468
3469 enew!
3470 call append(0, ["F5:50:L50", "F6:60:L60"])
3471 Xaddbuffer
3472 call assert_equal(6, g:Xgetlist({'changedtick' : 0}).changedtick)
3473 enew!
3474
3475 call g:Xsetlist([], 'a', {'context' : {'bus' : 'pci'}})
3476 call assert_equal(7, g:Xgetlist({'changedtick' : 0}).changedtick)
3477 call g:Xsetlist([{'filename' : 'F7', 'lnum' : 10, 'text' : 'L7'},
3478 \ {'filename' : 'F7', 'lnum' : 11, 'text' : 'L11'}], 'a')
3479 call assert_equal(8, g:Xgetlist({'changedtick' : 0}).changedtick)
3480 call g:Xsetlist([{'filename' : 'F7', 'lnum' : 10, 'text' : 'L7'},
3481 \ {'filename' : 'F7', 'lnum' : 11, 'text' : 'L11'}], ' ')
3482 call assert_equal(1, g:Xgetlist({'changedtick' : 0}).changedtick)
3483 call g:Xsetlist([{'filename' : 'F7', 'lnum' : 10, 'text' : 'L7'},
3484 \ {'filename' : 'F7', 'lnum' : 11, 'text' : 'L11'}], 'r')
3485 call assert_equal(2, g:Xgetlist({'changedtick' : 0}).changedtick)
3486
3487 call writefile(["F8:80:L80", "F8:81:L81"], "Xone")
3488 Xfile Xone
3489 call assert_equal(1, g:Xgetlist({'changedtick' : 0}).changedtick)
3490 Xaddfile Xone
3491 call assert_equal(2, g:Xgetlist({'changedtick' : 0}).changedtick)
3492
3493 " Test case for updating a non-current quickfix list
3494 call g:Xsetlist([], 'f')
3495 Xexpr "F1:1:L1"
3496 Xexpr "F2:2:L2"
3497 call g:Xsetlist([], 'a', {'nr' : 1, "lines" : ["F10:10:L10"]})
3498 call assert_equal(1, g:Xgetlist({'changedtick' : 0}).changedtick)
3499 call assert_equal(2, g:Xgetlist({'nr' : 1, 'changedtick' : 0}).changedtick)
3500
3501 call delete("Xone")
3502endfunc
3503
3504func Test_qf_tick()
3505 call Xqftick_tests('c')
3506 call Xqftick_tests('l')
3507endfunc
Bram Moolenaar12237442017-12-19 12:38:52 +01003508
Bram Moolenaarc631f2d2018-08-21 21:58:13 +02003509" Test helpgrep with lang specifier
3510func Xtest_helpgrep_with_lang_specifier(cchar)
3511 call s:setup_commands(a:cchar)
3512 Xhelpgrep Vim@en
3513 call assert_equal('help', &filetype)
3514 call assert_notequal(0, g:Xgetlist({'nr' : '$'}).nr)
3515 new | only
3516endfunc
3517
3518func Test_helpgrep_with_lang_specifier()
3519 call Xtest_helpgrep_with_lang_specifier('c')
3520 call Xtest_helpgrep_with_lang_specifier('l')
3521endfunc
3522
Bram Moolenaar12237442017-12-19 12:38:52 +01003523" The following test used to crash Vim.
3524" Open the location list window and close the regular window associated with
3525" the location list. When the garbage collection runs now, it incorrectly
3526" marks the location list context as not in use and frees the context.
3527func Test_ll_window_ctx()
3528 call setloclist(0, [], 'f')
3529 call setloclist(0, [], 'a', {'context' : []})
3530 lopen | only
3531 call test_garbagecollect_now()
3532 echo getloclist(0, {'context' : 1}).context
3533 enew | only
3534endfunc
3535
Bram Moolenaar14a4deb2017-12-19 16:48:55 +01003536" The following test used to crash vim
3537func Test_lfile_crash()
3538 sp Xtest
3539 au QuickFixCmdPre * bw
3540 call assert_fails('lfile', 'E40')
3541 au! QuickFixCmdPre
3542endfunc
Bram Moolenaar3c097222017-12-21 20:54:49 +01003543
3544" The following test used to crash vim
3545func Test_lbuffer_crash()
3546 sv Xtest
3547 augroup QF_Test
3548 au!
3549 au * * bw
3550 augroup END
3551 lbuffer
3552 augroup QF_Test
3553 au!
3554 augroup END
3555endfunc
3556
3557" The following test used to crash vim
3558func Test_lexpr_crash()
3559 augroup QF_Test
3560 au!
3561 au * * call setloclist(0, [], 'f')
3562 augroup END
3563 lexpr ""
3564 augroup QF_Test
3565 au!
3566 augroup END
Bram Moolenaar9f84ded2018-10-20 20:54:02 +02003567
Bram Moolenaar3c097222017-12-21 20:54:49 +01003568 enew | only
Bram Moolenaar9f84ded2018-10-20 20:54:02 +02003569 augroup QF_Test
3570 au!
3571 au BufNew * call setloclist(0, [], 'f')
3572 augroup END
3573 lexpr 'x:1:x'
3574 augroup QF_Test
3575 au!
3576 augroup END
3577
3578 enew | only
3579 lexpr ''
3580 lopen
3581 augroup QF_Test
3582 au!
3583 au FileType * call setloclist(0, [], 'f')
3584 augroup END
3585 lexpr ''
3586 augroup QF_Test
3587 au!
3588 augroup END
Bram Moolenaar3c097222017-12-21 20:54:49 +01003589endfunc
3590
3591" The following test used to crash Vim
3592func Test_lvimgrep_crash()
3593 sv Xtest
3594 augroup QF_Test
3595 au!
3596 au * * call setloclist(0, [], 'f')
3597 augroup END
3598 lvimgrep quickfix test_quickfix.vim
3599 augroup QF_Test
3600 au!
3601 augroup END
Bram Moolenaarb6f14802018-10-21 18:47:43 +02003602
3603 new | only
3604 augroup QF_Test
3605 au!
3606 au BufEnter * call setloclist(0, [], 'r')
3607 augroup END
3608 call assert_fails('lvimgrep Test_lvimgrep_crash *', 'E926:')
3609 augroup QF_Test
3610 au!
3611 augroup END
3612
Bram Moolenaar3c097222017-12-21 20:54:49 +01003613 enew | only
3614endfunc
Bram Moolenaarde046542017-12-26 13:53:11 +01003615
3616" Test for the position of the quickfix and location list window
3617func Test_qfwin_pos()
3618 " Open two windows
3619 new | only
3620 new
3621 cexpr ['F1:10:L10']
3622 copen
3623 " Quickfix window should be the bottom most window
3624 call assert_equal(3, winnr())
3625 close
3626 " Open at the very top
3627 wincmd t
3628 topleft copen
3629 call assert_equal(1, winnr())
3630 close
3631 " open left of the current window
3632 wincmd t
3633 below new
3634 leftabove copen
3635 call assert_equal(2, winnr())
3636 close
3637 " open right of the current window
3638 rightbelow copen
3639 call assert_equal(3, winnr())
3640 close
3641endfunc
Bram Moolenaare1bb8792018-04-06 22:58:23 +02003642
3643" Tests for quickfix/location lists changed by autocommands when
3644" :vimgrep/:lvimgrep commands are running.
3645func Test_vimgrep_autocmd()
3646 call setqflist([], 'f')
3647 call writefile(['stars'], 'Xtest1.txt')
3648 call writefile(['stars'], 'Xtest2.txt')
3649
3650 " Test 1:
3651 " When searching for a pattern using :vimgrep, if the quickfix list is
3652 " changed by an autocmd, the results should be added to the correct quickfix
3653 " list.
3654 autocmd BufRead Xtest2.txt cexpr '' | cexpr ''
3655 silent vimgrep stars Xtest*.txt
3656 call assert_equal(1, getqflist({'nr' : 0}).nr)
3657 call assert_equal(3, getqflist({'nr' : '$'}).nr)
3658 call assert_equal('Xtest2.txt', bufname(getqflist()[1].bufnr))
3659 au! BufRead Xtest2.txt
3660
3661 " Test 2:
3662 " When searching for a pattern using :vimgrep, if the quickfix list is
3663 " freed, then a error should be given.
3664 silent! %bwipe!
3665 call setqflist([], 'f')
3666 autocmd BufRead Xtest2.txt for i in range(10) | cexpr '' | endfor
3667 call assert_fails('vimgrep stars Xtest*.txt', 'E925:')
3668 au! BufRead Xtest2.txt
3669
3670 " Test 3:
3671 " When searching for a pattern using :lvimgrep, if the location list is
3672 " freed, then the command should error out.
3673 silent! %bwipe!
3674 let g:save_winid = win_getid()
3675 autocmd BufRead Xtest2.txt call setloclist(g:save_winid, [], 'f')
3676 call assert_fails('lvimgrep stars Xtest*.txt', 'E926:')
3677 au! BufRead Xtest2.txt
3678
3679 call delete('Xtest1.txt')
3680 call delete('Xtest2.txt')
3681 call setqflist([], 'f')
3682endfunc
Bram Moolenaar3b9474b2018-04-23 21:29:48 +02003683
Bram Moolenaarf9ae1542019-11-18 22:02:16 +01003684" Test for an autocmd changing the current directory when running vimgrep
3685func Xvimgrep_autocmd_cd(cchar)
3686 call s:setup_commands(a:cchar)
3687
3688 %bwipe
3689 let save_cwd = getcwd()
3690
3691 augroup QF_Test
3692 au!
3693 autocmd BufRead * silent cd %:p:h
3694 augroup END
3695
3696 10Xvimgrep /vim/ Xdir/**
3697 let l = g:Xgetlist()
3698 call assert_equal('f1.txt', bufname(l[0].bufnr))
3699 call assert_equal('f2.txt', fnamemodify(bufname(l[2].bufnr), ':t'))
3700
3701 augroup QF_Test
3702 au!
3703 augroup END
3704
3705 exe 'cd ' . save_cwd
3706endfunc
3707
3708func Test_vimgrep_autocmd_cd()
3709 call mkdir('Xdir/a', 'p')
3710 call mkdir('Xdir/b', 'p')
3711 call writefile(['a_L1_vim', 'a_L2_vim'], 'Xdir/a/f1.txt')
3712 call writefile(['b_L1_vim', 'b_L2_vim'], 'Xdir/b/f2.txt')
3713 call Xvimgrep_autocmd_cd('c')
3714 call Xvimgrep_autocmd_cd('l')
3715 %bwipe
3716 call delete('Xdir', 'rf')
3717endfunc
3718
Bram Moolenaar3b9474b2018-04-23 21:29:48 +02003719" The following test used to crash Vim
3720func Test_lhelpgrep_autocmd()
3721 lhelpgrep quickfix
3722 autocmd QuickFixCmdPost * call setloclist(0, [], 'f')
3723 lhelpgrep buffer
3724 call assert_equal('help', &filetype)
3725 call assert_equal(0, getloclist(0, {'nr' : '$'}).nr)
3726 lhelpgrep tabpage
3727 call assert_equal('help', &filetype)
3728 call assert_equal(1, getloclist(0, {'nr' : '$'}).nr)
3729 au! QuickFixCmdPost
Bram Moolenaarb6f14802018-10-21 18:47:43 +02003730
3731 new | only
3732 augroup QF_Test
3733 au!
3734 au BufEnter * call setqflist([], 'f')
3735 augroup END
3736 call assert_fails('helpgrep quickfix', 'E925:')
3737 augroup QF_Test
3738 au! BufEnter
3739 augroup END
3740
3741 new | only
3742 augroup QF_Test
3743 au!
3744 au BufEnter * call setqflist([], 'r')
3745 augroup END
3746 call assert_fails('helpgrep quickfix', 'E925:')
3747 augroup QF_Test
3748 au! BufEnter
3749 augroup END
3750
3751 new | only
3752 augroup QF_Test
3753 au!
3754 au BufEnter * call setloclist(0, [], 'r')
3755 augroup END
3756 call assert_fails('lhelpgrep quickfix', 'E926:')
3757 augroup QF_Test
3758 au! BufEnter
3759 augroup END
3760
Bram Moolenaar3b9474b2018-04-23 21:29:48 +02003761 new | only
3762endfunc
Bram Moolenaara796d462018-05-01 14:30:36 +02003763
3764" Test for shortening/simplifying the file name when opening the
3765" quickfix window or when displaying the quickfix list
3766func Test_shorten_fname()
3767 if !has('unix')
3768 return
3769 endif
3770 %bwipe
3771 " Create a quickfix list with a absolute path filename
3772 let fname = getcwd() . '/test_quickfix.vim'
3773 call setqflist([], ' ', {'lines':[fname . ":20:Line20"], 'efm':'%f:%l:%m'})
3774 call assert_equal(fname, bufname('test_quickfix.vim'))
3775 " Opening the quickfix window should simplify the file path
3776 cwindow
3777 call assert_equal('test_quickfix.vim', bufname('test_quickfix.vim'))
3778 cclose
3779 %bwipe
3780 " Create a quickfix list with a absolute path filename
3781 call setqflist([], ' ', {'lines':[fname . ":20:Line20"], 'efm':'%f:%l:%m'})
3782 call assert_equal(fname, bufname('test_quickfix.vim'))
3783 " Displaying the quickfix list should simplify the file path
3784 silent! clist
3785 call assert_equal('test_quickfix.vim', bufname('test_quickfix.vim'))
3786endfunc
Bram Moolenaar8b62e312018-05-13 15:29:04 +02003787
3788" Quickfix title tests
3789" In the below tests, 'exe "cmd"' is used to invoke the quickfix commands.
3790" Otherwise due to indentation, the title is set with spaces at the beginning
3791" of the command.
3792func Test_qftitle()
3793 call writefile(["F1:1:Line1"], 'Xerr')
3794
3795 " :cexpr
3796 exe "cexpr readfile('Xerr')"
3797 call assert_equal(":cexpr readfile('Xerr')", getqflist({'title' : 1}).title)
3798
3799 " :cgetexpr
3800 exe "cgetexpr readfile('Xerr')"
3801 call assert_equal(":cgetexpr readfile('Xerr')",
3802 \ getqflist({'title' : 1}).title)
3803
3804 " :caddexpr
3805 call setqflist([], 'f')
3806 exe "caddexpr readfile('Xerr')"
3807 call assert_equal(":caddexpr readfile('Xerr')",
3808 \ getqflist({'title' : 1}).title)
3809
3810 " :cbuffer
3811 new Xerr
3812 exe "cbuffer"
3813 call assert_equal(':cbuffer (Xerr)', getqflist({'title' : 1}).title)
3814
3815 " :cgetbuffer
3816 edit Xerr
3817 exe "cgetbuffer"
3818 call assert_equal(':cgetbuffer (Xerr)', getqflist({'title' : 1}).title)
3819
3820 " :caddbuffer
3821 call setqflist([], 'f')
3822 edit Xerr
3823 exe "caddbuffer"
3824 call assert_equal(':caddbuffer (Xerr)', getqflist({'title' : 1}).title)
3825
3826 " :cfile
3827 exe "cfile Xerr"
3828 call assert_equal(':cfile Xerr', getqflist({'title' : 1}).title)
3829
3830 " :cgetfile
3831 exe "cgetfile Xerr"
3832 call assert_equal(':cgetfile Xerr', getqflist({'title' : 1}).title)
3833
3834 " :caddfile
3835 call setqflist([], 'f')
3836 exe "caddfile Xerr"
3837 call assert_equal(':caddfile Xerr', getqflist({'title' : 1}).title)
3838
3839 " :grep
3840 set grepprg=internal
3841 exe "grep F1 Xerr"
3842 call assert_equal(':grep F1 Xerr', getqflist({'title' : 1}).title)
3843
3844 " :grepadd
3845 call setqflist([], 'f')
3846 exe "grepadd F1 Xerr"
3847 call assert_equal(':grepadd F1 Xerr', getqflist({'title' : 1}).title)
3848 set grepprg&vim
3849
3850 " :vimgrep
3851 exe "vimgrep F1 Xerr"
3852 call assert_equal(':vimgrep F1 Xerr', getqflist({'title' : 1}).title)
3853
3854 " :vimgrepadd
3855 call setqflist([], 'f')
3856 exe "vimgrepadd F1 Xerr"
3857 call assert_equal(':vimgrepadd F1 Xerr', getqflist({'title' : 1}).title)
3858
3859 call setqflist(['F1:10:L10'], ' ')
3860 call assert_equal(':setqflist()', getqflist({'title' : 1}).title)
3861
3862 call setqflist([], 'f')
3863 call setqflist(['F1:10:L10'], 'a')
3864 call assert_equal(':setqflist()', getqflist({'title' : 1}).title)
3865
3866 call setqflist([], 'f')
3867 call setqflist(['F1:10:L10'], 'r')
3868 call assert_equal(':setqflist()', getqflist({'title' : 1}).title)
3869
3870 close
3871 call delete('Xerr')
3872
3873 call setqflist([], ' ', {'title' : 'Errors'})
3874 copen
3875 call assert_equal('Errors', w:quickfix_title)
3876 call setqflist([], 'r', {'items' : [{'filename' : 'a.c', 'lnum' : 10}]})
3877 call assert_equal('Errors', w:quickfix_title)
3878 cclose
3879endfunc
Bram Moolenaar600323b2018-06-16 22:16:47 +02003880
3881func Test_lbuffer_with_bwipe()
3882 new
3883 new
3884 augroup nasty
3885 au * * bwipe
3886 augroup END
3887 lbuffer
3888 augroup nasty
3889 au!
3890 augroup END
3891endfunc
Bram Moolenaar0366c012018-06-18 20:52:13 +02003892
Bram Moolenaar531b9a32018-07-03 16:54:23 +02003893" Test for an autocmd freeing the quickfix/location list when cexpr/lexpr is
3894" running
3895func Xexpr_acmd_freelist(cchar)
3896 call s:setup_commands(a:cchar)
3897
Bram Moolenaar0366c012018-06-18 20:52:13 +02003898 " This was using freed memory.
3899 augroup nasty
Bram Moolenaar531b9a32018-07-03 16:54:23 +02003900 au * * call g:Xsetlist([], 'f')
Bram Moolenaar0366c012018-06-18 20:52:13 +02003901 augroup END
Bram Moolenaar531b9a32018-07-03 16:54:23 +02003902 Xexpr "x"
Bram Moolenaar0366c012018-06-18 20:52:13 +02003903 augroup nasty
3904 au!
3905 augroup END
3906endfunc
Bram Moolenaar531b9a32018-07-03 16:54:23 +02003907
3908func Test_cexpr_acmd_freelist()
3909 call Xexpr_acmd_freelist('c')
3910 call Xexpr_acmd_freelist('l')
3911endfunc
3912
3913" Test for commands that create a new quickfix/location list and jump to the
3914" first error automatically.
3915func Xjumpto_first_error_test(cchar)
3916 call s:setup_commands(a:cchar)
3917
3918 call s:create_test_file('Xtestfile1')
3919 call s:create_test_file('Xtestfile2')
3920 let l = ['Xtestfile1:2:Line2', 'Xtestfile2:4:Line4']
3921
3922 " Test for cexpr/lexpr
3923 enew
3924 Xexpr l
3925 call assert_equal('Xtestfile1', bufname(''))
3926 call assert_equal(2, line('.'))
3927
3928 " Test for cfile/lfile
3929 enew
3930 call writefile(l, 'Xerr')
3931 Xfile Xerr
3932 call assert_equal('Xtestfile1', bufname(''))
3933 call assert_equal(2, line('.'))
3934
3935 " Test for cbuffer/lbuffer
3936 edit Xerr
3937 Xbuffer
3938 call assert_equal('Xtestfile1', bufname(''))
3939 call assert_equal(2, line('.'))
3940
3941 call delete('Xerr')
3942 call delete('Xtestfile1')
3943 call delete('Xtestfile2')
3944endfunc
3945
3946func Test_jumpto_first_error()
3947 call Xjumpto_first_error_test('c')
3948 call Xjumpto_first_error_test('l')
3949endfunc
3950
3951" Test for a quickfix autocmd changing the quickfix/location list before
3952" jumping to the first error in the new list.
3953func Xautocmd_changelist(cchar)
3954 call s:setup_commands(a:cchar)
3955
3956 " Test for cfile/lfile
3957 call s:create_test_file('Xtestfile1')
3958 call s:create_test_file('Xtestfile2')
3959 Xexpr 'Xtestfile1:2:Line2'
3960 autocmd QuickFixCmdPost * Xolder
3961 call writefile(['Xtestfile2:4:Line4'], 'Xerr')
3962 Xfile Xerr
3963 call assert_equal('Xtestfile2', bufname(''))
3964 call assert_equal(4, line('.'))
3965 autocmd! QuickFixCmdPost
3966
3967 " Test for cbuffer/lbuffer
3968 call g:Xsetlist([], 'f')
3969 Xexpr 'Xtestfile1:2:Line2'
3970 autocmd QuickFixCmdPost * Xolder
3971 call writefile(['Xtestfile2:4:Line4'], 'Xerr')
3972 edit Xerr
3973 Xbuffer
3974 call assert_equal('Xtestfile2', bufname(''))
3975 call assert_equal(4, line('.'))
3976 autocmd! QuickFixCmdPost
3977
3978 " Test for cexpr/lexpr
3979 call g:Xsetlist([], 'f')
3980 Xexpr 'Xtestfile1:2:Line2'
3981 autocmd QuickFixCmdPost * Xolder
3982 Xexpr 'Xtestfile2:4:Line4'
3983 call assert_equal('Xtestfile2', bufname(''))
3984 call assert_equal(4, line('.'))
3985 autocmd! QuickFixCmdPost
3986
Bram Moolenaar851332e2018-07-03 19:16:00 +02003987 " The grepprg may not be set on non-Unix systems
3988 if has('unix')
3989 " Test for grep/lgrep
3990 call g:Xsetlist([], 'f')
3991 Xexpr 'Xtestfile1:2:Line2'
3992 autocmd QuickFixCmdPost * Xolder
3993 silent Xgrep Line5 Xtestfile2
3994 call assert_equal('Xtestfile2', bufname(''))
3995 call assert_equal(5, line('.'))
3996 autocmd! QuickFixCmdPost
3997 endif
Bram Moolenaar531b9a32018-07-03 16:54:23 +02003998
3999 " Test for vimgrep/lvimgrep
4000 call g:Xsetlist([], 'f')
4001 Xexpr 'Xtestfile1:2:Line2'
4002 autocmd QuickFixCmdPost * Xolder
4003 silent Xvimgrep Line5 Xtestfile2
4004 call assert_equal('Xtestfile2', bufname(''))
4005 call assert_equal(5, line('.'))
4006 autocmd! QuickFixCmdPost
4007
Bram Moolenaar3f347e42018-08-09 21:19:20 +02004008 " Test for autocommands clearing the quickfix list before jumping to the
4009 " first error. This should not result in an error
4010 autocmd QuickFixCmdPost * call g:Xsetlist([], 'r')
4011 let v:errmsg = ''
4012 " Test for cfile/lfile
4013 Xfile Xerr
4014 call assert_true(v:errmsg !~# 'E42:')
4015 " Test for cbuffer/lbuffer
4016 edit Xerr
4017 Xbuffer
4018 call assert_true(v:errmsg !~# 'E42:')
4019 " Test for cexpr/lexpr
4020 Xexpr 'Xtestfile2:4:Line4'
4021 call assert_true(v:errmsg !~# 'E42:')
4022 " Test for grep/lgrep
4023 " The grepprg may not be set on non-Unix systems
4024 if has('unix')
4025 silent Xgrep Line5 Xtestfile2
4026 call assert_true(v:errmsg !~# 'E42:')
4027 endif
4028 " Test for vimgrep/lvimgrep
4029 call assert_fails('silent Xvimgrep Line5 Xtestfile2', 'E480:')
4030 autocmd! QuickFixCmdPost
4031
Bram Moolenaar531b9a32018-07-03 16:54:23 +02004032 call delete('Xerr')
4033 call delete('Xtestfile1')
4034 call delete('Xtestfile2')
4035endfunc
4036
4037func Test_autocmd_changelist()
4038 call Xautocmd_changelist('c')
4039 call Xautocmd_changelist('l')
4040endfunc
Bram Moolenaar4cde86c2018-07-08 16:01:08 +02004041
4042" Tests for the ':filter /pat/ clist' command
4043func Test_filter_clist()
4044 cexpr ['Xfile1:10:10:Line 10', 'Xfile2:15:15:Line 15']
4045 call assert_equal([' 2 Xfile2:15 col 15: Line 15'],
4046 \ split(execute('filter /Line 15/ clist'), "\n"))
4047 call assert_equal([' 1 Xfile1:10 col 10: Line 10'],
4048 \ split(execute('filter /Xfile1/ clist'), "\n"))
4049 call assert_equal([], split(execute('filter /abc/ clist'), "\n"))
4050
4051 call setqflist([{'module' : 'abc', 'pattern' : 'pat1'},
4052 \ {'module' : 'pqr', 'pattern' : 'pat2'}], ' ')
4053 call assert_equal([' 2 pqr:pat2: '],
4054 \ split(execute('filter /pqr/ clist'), "\n"))
4055 call assert_equal([' 1 abc:pat1: '],
4056 \ split(execute('filter /pat1/ clist'), "\n"))
4057endfunc
Bram Moolenaar0a08c632018-07-25 22:36:52 +02004058
4059" Tests for the "CTRL-W <CR>" command.
4060func Xview_result_split_tests(cchar)
4061 call s:setup_commands(a:cchar)
4062
4063 " Test that "CTRL-W <CR>" in a qf/ll window fails with empty list.
4064 call g:Xsetlist([])
4065 Xopen
4066 let l:win_count = winnr('$')
4067 call assert_fails('execute "normal! \<C-W>\<CR>"', 'E42')
4068 call assert_equal(l:win_count, winnr('$'))
4069 Xclose
4070endfunc
4071
4072func Test_view_result_split()
4073 call Xview_result_split_tests('c')
4074 call Xview_result_split_tests('l')
4075endfunc
Bram Moolenaar2dfcef42018-08-15 22:29:51 +02004076
4077" Test that :cc sets curswant
4078func Test_curswant()
4079 helpgrep quickfix
4080 normal! llll
4081 1cc
4082 call assert_equal(getcurpos()[4], virtcol('.'))
4083 cclose | helpclose
4084endfunc
Bram Moolenaarb2443732018-11-11 22:50:27 +01004085
4086" Test for opening a file from the quickfix window using CTRL-W <Enter>
4087" doesn't leave an empty buffer around.
4088func Test_splitview()
4089 call s:create_test_file('Xtestfile1')
4090 call s:create_test_file('Xtestfile2')
4091 new | only
4092 let last_bufnr = bufnr('Test_sv_1', 1)
4093 let l = ['Xtestfile1:2:Line2', 'Xtestfile2:4:Line4']
4094 cgetexpr l
4095 copen
4096 let numbufs = len(getbufinfo())
4097 exe "normal \<C-W>\<CR>"
4098 copen
4099 exe "normal j\<C-W>\<CR>"
4100 " Make sure new empty buffers are not created
4101 call assert_equal(numbufs, len(getbufinfo()))
4102 " Creating a new buffer should use the next available buffer number
4103 call assert_equal(last_bufnr + 4, bufnr("Test_sv_2", 1))
4104 bwipe Test_sv_1
4105 bwipe Test_sv_2
4106 new | only
4107
4108 " When split opening files from location list window, make sure that two
4109 " windows doesn't refer to the same location list
4110 lgetexpr l
4111 let locid = getloclist(0, {'id' : 0}).id
4112 lopen
4113 exe "normal \<C-W>\<CR>"
4114 call assert_notequal(locid, getloclist(0, {'id' : 0}).id)
4115 call assert_equal(0, getloclist(0, {'winid' : 0}).winid)
4116 new | only
4117
4118 " When split opening files from a helpgrep location list window, a new help
Bram Moolenaareeb1b9c2019-02-10 22:59:04 +01004119 " window should be opened with a copy of the location list.
Bram Moolenaarb2443732018-11-11 22:50:27 +01004120 lhelpgrep window
4121 let locid = getloclist(0, {'id' : 0}).id
4122 lwindow
4123 exe "normal j\<C-W>\<CR>"
4124 call assert_notequal(locid, getloclist(0, {'id' : 0}).id)
4125 call assert_equal(0, getloclist(0, {'winid' : 0}).winid)
4126 new | only
4127
4128 call delete('Xtestfile1')
4129 call delete('Xtestfile2')
4130endfunc
Bram Moolenaarc45eb772019-01-31 14:27:04 +01004131
4132" Test for parsing entries using visual screen column
4133func Test_viscol()
4134 enew
4135 call writefile(["Col1\tCol2\tCol3"], 'Xfile1')
4136 edit Xfile1
4137
4138 " Use byte offset for column number
4139 set efm&
4140 cexpr "Xfile1:1:5:XX\nXfile1:1:9:YY\nXfile1:1:20:ZZ"
4141 call assert_equal([5, 8], [col('.'), virtcol('.')])
4142 cnext
4143 call assert_equal([9, 12], [col('.'), virtcol('.')])
4144 cnext
4145 call assert_equal([14, 20], [col('.'), virtcol('.')])
4146
4147 " Use screen column offset for column number
4148 set efm=%f:%l:%v:%m
4149 cexpr "Xfile1:1:8:XX\nXfile1:1:12:YY\nXfile1:1:20:ZZ"
4150 call assert_equal([5, 8], [col('.'), virtcol('.')])
4151 cnext
4152 call assert_equal([9, 12], [col('.'), virtcol('.')])
4153 cnext
4154 call assert_equal([14, 20], [col('.'), virtcol('.')])
4155 cexpr "Xfile1:1:6:XX\nXfile1:1:15:YY\nXfile1:1:24:ZZ"
4156 call assert_equal([5, 8], [col('.'), virtcol('.')])
4157 cnext
4158 call assert_equal([10, 16], [col('.'), virtcol('.')])
4159 cnext
4160 call assert_equal([14, 20], [col('.'), virtcol('.')])
4161
4162 enew
4163 call writefile(["Col1\täü\töß\tCol4"], 'Xfile1')
4164
4165 " Use byte offset for column number
4166 set efm&
4167 cexpr "Xfile1:1:8:XX\nXfile1:1:11:YY\nXfile1:1:16:ZZ"
4168 call assert_equal([8, 10], [col('.'), virtcol('.')])
4169 cnext
4170 call assert_equal([11, 17], [col('.'), virtcol('.')])
4171 cnext
4172 call assert_equal([16, 25], [col('.'), virtcol('.')])
4173
4174 " Use screen column offset for column number
4175 set efm=%f:%l:%v:%m
4176 cexpr "Xfile1:1:10:XX\nXfile1:1:17:YY\nXfile1:1:25:ZZ"
4177 call assert_equal([8, 10], [col('.'), virtcol('.')])
4178 cnext
4179 call assert_equal([11, 17], [col('.'), virtcol('.')])
4180 cnext
4181 call assert_equal([16, 25], [col('.'), virtcol('.')])
4182
4183 enew | only
4184 set efm&
4185 call delete('Xfile1')
4186endfunc
Bram Moolenaaree8188f2019-02-05 21:23:04 +01004187
4188" Test for the quickfix window buffer
4189func Xqfbuf_test(cchar)
4190 call s:setup_commands(a:cchar)
4191
4192 " Quickfix buffer should be reused across closing and opening a quickfix
4193 " window
4194 Xexpr "F1:10:Line10"
4195 Xopen
4196 let qfbnum = bufnr('')
4197 Xclose
4198 " Even after the quickfix window is closed, the buffer should be loaded
4199 call assert_true(bufloaded(qfbnum))
Bram Moolenaar647e24b2019-03-17 16:39:46 +01004200 call assert_true(qfbnum, g:Xgetlist({'qfbufnr' : 0}).qfbufnr)
Bram Moolenaaree8188f2019-02-05 21:23:04 +01004201 Xopen
4202 " Buffer should be reused when opening the window again
4203 call assert_equal(qfbnum, bufnr(''))
4204 Xclose
4205
4206 if a:cchar == 'l'
4207 %bwipe
4208 " For a location list, when both the file window and the location list
4209 " window for the list are closed, then the buffer should be freed.
4210 new | only
4211 lexpr "F1:10:Line10"
4212 let wid = win_getid()
4213 lopen
4214 let qfbnum = bufnr('')
4215 call assert_match(qfbnum . ' %a- "\[Location List]"', execute('ls'))
4216 close
4217 " When the location list window is closed, the buffer name should not
4218 " change to 'Quickfix List'
Bram Moolenaar647e24b2019-03-17 16:39:46 +01004219 call assert_match(qfbnum . 'u h- "\[Location List]"', execute('ls!'))
Bram Moolenaaree8188f2019-02-05 21:23:04 +01004220 call assert_true(bufloaded(qfbnum))
4221
Bram Moolenaard82a81c2019-03-02 07:57:18 +01004222 " After deleting a location list buffer using ":bdelete", opening the
4223 " location list window should mark the buffer as a location list buffer.
4224 exe "bdelete " . qfbnum
4225 lopen
4226 call assert_equal("quickfix", &buftype)
4227 call assert_equal(1, getwininfo(win_getid(winnr()))[0].loclist)
4228 call assert_equal(wid, getloclist(0, {'filewinid' : 0}).filewinid)
4229 call assert_false(&swapfile)
4230 lclose
4231
Bram Moolenaareeb1b9c2019-02-10 22:59:04 +01004232 " When the location list is cleared for the window, the buffer should be
4233 " removed
4234 call setloclist(0, [], 'f')
4235 call assert_false(bufexists(qfbnum))
Bram Moolenaar647e24b2019-03-17 16:39:46 +01004236 call assert_equal(0, getloclist(0, {'qfbufnr' : 0}).qfbufnr)
Bram Moolenaareeb1b9c2019-02-10 22:59:04 +01004237
4238 " When the location list is freed with the location list window open, the
4239 " location list buffer should not be lost. It should be reused when the
4240 " location list is again populated.
4241 lexpr "F1:10:Line10"
4242 lopen
4243 let wid = win_getid()
4244 let qfbnum = bufnr('')
4245 wincmd p
4246 call setloclist(0, [], 'f')
4247 lexpr "F1:10:Line10"
4248 lopen
4249 call assert_equal(wid, win_getid())
4250 call assert_equal(qfbnum, bufnr(''))
4251 lclose
4252
4253 " When the window with the location list is closed, the buffer should be
4254 " removed
Bram Moolenaaree8188f2019-02-05 21:23:04 +01004255 new | only
Bram Moolenaareeb1b9c2019-02-10 22:59:04 +01004256 call assert_false(bufexists(qfbnum))
Bram Moolenaaree8188f2019-02-05 21:23:04 +01004257 endif
4258endfunc
4259
4260func Test_qfbuf()
4261 call Xqfbuf_test('c')
4262 call Xqfbuf_test('l')
4263endfunc
Bram Moolenaareeb1b9c2019-02-10 22:59:04 +01004264
4265" If there is an autocmd to use only one window, then opening the location
4266" list window used to crash Vim.
4267func Test_winonly_autocmd()
4268 call s:create_test_file('Xtest1')
4269 " Autocmd to show only one Vim window at a time
4270 autocmd WinEnter * only
4271 new
4272 " Load the location list
4273 lexpr "Xtest1:5:Line5\nXtest1:10:Line10\nXtest1:15:Line15"
4274 let loclistid = getloclist(0, {'id' : 0}).id
4275 " Open the location list window. Only this window will be shown and the file
4276 " window is closed.
4277 lopen
4278 call assert_equal(loclistid, getloclist(0, {'id' : 0}).id)
4279 " Jump to an entry in the location list and make sure that the cursor is
4280 " positioned correctly.
4281 ll 3
4282 call assert_equal(loclistid, getloclist(0, {'id' : 0}).id)
4283 call assert_equal('Xtest1', bufname(''))
4284 call assert_equal(15, line('.'))
4285 " Cleanup
4286 autocmd! WinEnter
4287 new | only
4288 call delete('Xtest1')
4289endfunc
Bram Moolenaar39803d82019-04-07 12:04:51 +02004290
4291" Test to make sure that an empty quickfix buffer is not reused for loading
4292" a normal buffer.
4293func Test_empty_qfbuf()
4294 enew | only
4295 call writefile(["Test"], 'Xfile1')
4296 call setqflist([], 'f')
4297 copen | only
4298 let qfbuf = bufnr('')
4299 edit Xfile1
4300 call assert_notequal(qfbuf, bufnr(''))
4301 enew
4302 call delete('Xfile1')
4303endfunc
Bram Moolenaar3ff33112019-05-03 21:56:35 +02004304
4305" Test for the :cbelow, :cabove, :lbelow and :labove commands.
Bram Moolenaarcf6a55c2019-05-05 15:02:30 +02004306" And for the :cafter, :cbefore, :lafter and :lbefore commands.
Bram Moolenaar3ff33112019-05-03 21:56:35 +02004307func Xtest_below(cchar)
4308 call s:setup_commands(a:cchar)
4309
4310 " No quickfix/location list
4311 call assert_fails('Xbelow', 'E42:')
4312 call assert_fails('Xabove', 'E42:')
Bram Moolenaarcf6a55c2019-05-05 15:02:30 +02004313 call assert_fails('Xbefore', 'E42:')
4314 call assert_fails('Xafter', 'E42:')
Bram Moolenaar3ff33112019-05-03 21:56:35 +02004315
4316 " Empty quickfix/location list
4317 call g:Xsetlist([])
4318 call assert_fails('Xbelow', 'E42:')
4319 call assert_fails('Xabove', 'E42:')
Bram Moolenaarcf6a55c2019-05-05 15:02:30 +02004320 call assert_fails('Xbefore', 'E42:')
4321 call assert_fails('Xafter', 'E42:')
Bram Moolenaar3ff33112019-05-03 21:56:35 +02004322
4323 call s:create_test_file('X1')
4324 call s:create_test_file('X2')
4325 call s:create_test_file('X3')
4326 call s:create_test_file('X4')
4327
4328 " Invalid entries
4329 edit X1
4330 call g:Xsetlist(["E1", "E2"])
4331 call assert_fails('Xbelow', 'E42:')
4332 call assert_fails('Xabove', 'E42:')
4333 call assert_fails('3Xbelow', 'E42:')
4334 call assert_fails('4Xabove', 'E42:')
Bram Moolenaarcf6a55c2019-05-05 15:02:30 +02004335 call assert_fails('Xbefore', 'E42:')
4336 call assert_fails('Xafter', 'E42:')
4337 call assert_fails('3Xbefore', 'E42:')
4338 call assert_fails('4Xafter', 'E42:')
Bram Moolenaar3ff33112019-05-03 21:56:35 +02004339
4340 " Test the commands with various arguments
Bram Moolenaarcf6a55c2019-05-05 15:02:30 +02004341 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 +02004342 edit +7 X2
4343 Xabove
4344 call assert_equal(['X2', 5], [bufname(''), line('.')])
4345 call assert_fails('Xabove', 'E553:')
Bram Moolenaarcf6a55c2019-05-05 15:02:30 +02004346 normal 7G
4347 Xbefore
4348 call assert_equal(['X2', 5, 2], [bufname(''), line('.'), col('.')])
4349 call assert_fails('Xbefore', 'E553:')
4350
Bram Moolenaar3ff33112019-05-03 21:56:35 +02004351 normal 2j
4352 Xbelow
4353 call assert_equal(['X2', 10], [bufname(''), line('.')])
Bram Moolenaarcf6a55c2019-05-05 15:02:30 +02004354 normal 7G
4355 Xafter
4356 call assert_equal(['X2', 10, 3], [bufname(''), line('.'), col('.')])
4357
Bram Moolenaar3ff33112019-05-03 21:56:35 +02004358 " Last error in this file
4359 Xbelow 99
4360 call assert_equal(['X2', 15], [bufname(''), line('.')])
4361 call assert_fails('Xbelow', 'E553:')
Bram Moolenaarcf6a55c2019-05-05 15:02:30 +02004362 normal gg
4363 Xafter 99
4364 call assert_equal(['X2', 15, 4], [bufname(''), line('.'), col('.')])
4365 call assert_fails('Xafter', 'E553:')
4366
Bram Moolenaar3ff33112019-05-03 21:56:35 +02004367 " First error in this file
4368 Xabove 99
4369 call assert_equal(['X2', 5], [bufname(''), line('.')])
4370 call assert_fails('Xabove', 'E553:')
Bram Moolenaarcf6a55c2019-05-05 15:02:30 +02004371 normal G
4372 Xbefore 99
4373 call assert_equal(['X2', 5, 2], [bufname(''), line('.'), col('.')])
4374 call assert_fails('Xbefore', 'E553:')
4375
Bram Moolenaar3ff33112019-05-03 21:56:35 +02004376 normal gg
4377 Xbelow 2
4378 call assert_equal(['X2', 10], [bufname(''), line('.')])
Bram Moolenaarcf6a55c2019-05-05 15:02:30 +02004379 normal gg
4380 Xafter 2
4381 call assert_equal(['X2', 10, 3], [bufname(''), line('.'), col('.')])
4382
Bram Moolenaar3ff33112019-05-03 21:56:35 +02004383 normal G
4384 Xabove 2
4385 call assert_equal(['X2', 10], [bufname(''), line('.')])
Bram Moolenaarcf6a55c2019-05-05 15:02:30 +02004386 normal G
4387 Xbefore 2
4388 call assert_equal(['X2', 10, 3], [bufname(''), line('.'), col('.')])
4389
Bram Moolenaar3ff33112019-05-03 21:56:35 +02004390 edit X4
4391 call assert_fails('Xabove', 'E42:')
4392 call assert_fails('Xbelow', 'E42:')
Bram Moolenaarcf6a55c2019-05-05 15:02:30 +02004393 call assert_fails('Xbefore', 'E42:')
4394 call assert_fails('Xafter', 'E42:')
Bram Moolenaar3ff33112019-05-03 21:56:35 +02004395 if a:cchar == 'l'
4396 " If a buffer has location list entries from some other window but not
4397 " from the current window, then the commands should fail.
4398 edit X1 | split | call setloclist(0, [], 'f')
4399 call assert_fails('Xabove', 'E776:')
4400 call assert_fails('Xbelow', 'E776:')
Bram Moolenaarcf6a55c2019-05-05 15:02:30 +02004401 call assert_fails('Xbefore', 'E776:')
4402 call assert_fails('Xafter', 'E776:')
Bram Moolenaar3ff33112019-05-03 21:56:35 +02004403 close
4404 endif
4405
4406 " Test for lines with multiple quickfix entries
4407 Xexpr ["X1:5:L5", "X2:5:1:L5_1", "X2:5:2:L5_2", "X2:5:3:L5_3",
4408 \ "X2:10:1:L10_1", "X2:10:2:L10_2", "X2:10:3:L10_3",
4409 \ "X2:15:1:L15_1", "X2:15:2:L15_2", "X2:15:3:L15_3", "X3:3:L3"]
4410 edit +1 X2
4411 Xbelow 2
4412 call assert_equal(['X2', 10, 1], [bufname(''), line('.'), col('.')])
Bram Moolenaarcf6a55c2019-05-05 15:02:30 +02004413 normal 1G
4414 Xafter 2
4415 call assert_equal(['X2', 5, 2], [bufname(''), line('.'), col('.')])
4416
Bram Moolenaar3ff33112019-05-03 21:56:35 +02004417 normal gg
4418 Xbelow 99
4419 call assert_equal(['X2', 15, 1], [bufname(''), line('.'), col('.')])
Bram Moolenaarcf6a55c2019-05-05 15:02:30 +02004420 normal gg
4421 Xafter 99
4422 call assert_equal(['X2', 15, 3], [bufname(''), line('.'), col('.')])
4423
Bram Moolenaar3ff33112019-05-03 21:56:35 +02004424 normal G
4425 Xabove 2
4426 call assert_equal(['X2', 10, 1], [bufname(''), line('.'), col('.')])
4427 normal G
Bram Moolenaarcf6a55c2019-05-05 15:02:30 +02004428 Xbefore 2
4429 call assert_equal(['X2', 15, 2], [bufname(''), line('.'), col('.')])
4430
4431 normal G
Bram Moolenaar3ff33112019-05-03 21:56:35 +02004432 Xabove 99
4433 call assert_equal(['X2', 5, 1], [bufname(''), line('.'), col('.')])
Bram Moolenaarcf6a55c2019-05-05 15:02:30 +02004434 normal G
4435 Xbefore 99
4436 call assert_equal(['X2', 5, 1], [bufname(''), line('.'), col('.')])
4437
Bram Moolenaar3ff33112019-05-03 21:56:35 +02004438 normal 10G
4439 Xabove
4440 call assert_equal(['X2', 5, 1], [bufname(''), line('.'), col('.')])
Bram Moolenaarcf6a55c2019-05-05 15:02:30 +02004441 normal 10G$
4442 2Xbefore
4443 call assert_equal(['X2', 10, 2], [bufname(''), line('.'), col('.')])
4444
Bram Moolenaar3ff33112019-05-03 21:56:35 +02004445 normal 10G
4446 Xbelow
4447 call assert_equal(['X2', 15, 1], [bufname(''), line('.'), col('.')])
Bram Moolenaarcf6a55c2019-05-05 15:02:30 +02004448 normal 9G
4449 5Xafter
4450 call assert_equal(['X2', 15, 2], [bufname(''), line('.'), col('.')])
Bram Moolenaar3ff33112019-05-03 21:56:35 +02004451
4452 " Invalid range
4453 if a:cchar == 'c'
Bram Moolenaar25190db2019-05-04 15:05:28 +02004454 call assert_fails('-2cbelow', 'E16:')
Bram Moolenaarcf6a55c2019-05-05 15:02:30 +02004455 call assert_fails('-2cafter', 'E16:')
Bram Moolenaar3ff33112019-05-03 21:56:35 +02004456 else
Bram Moolenaar25190db2019-05-04 15:05:28 +02004457 call assert_fails('-2lbelow', 'E16:')
Bram Moolenaarcf6a55c2019-05-05 15:02:30 +02004458 call assert_fails('-2lafter', 'E16:')
Bram Moolenaar3ff33112019-05-03 21:56:35 +02004459 endif
4460
4461 call delete('X1')
4462 call delete('X2')
4463 call delete('X3')
4464 call delete('X4')
4465endfunc
4466
4467func Test_cbelow()
4468 call Xtest_below('c')
4469 call Xtest_below('l')
4470endfunc
Bram Moolenaar25190db2019-05-04 15:05:28 +02004471
4472func Test_quickfix_count()
4473 let commands = [
4474 \ 'cNext',
4475 \ 'cNfile',
4476 \ 'cabove',
4477 \ 'cbelow',
4478 \ 'cfirst',
4479 \ 'clast',
4480 \ 'cnewer',
4481 \ 'cnext',
4482 \ 'cnfile',
4483 \ 'colder',
4484 \ 'cprevious',
4485 \ 'crewind',
4486 \
4487 \ 'lNext',
4488 \ 'lNfile',
4489 \ 'labove',
4490 \ 'lbelow',
4491 \ 'lfirst',
4492 \ 'llast',
4493 \ 'lnewer',
4494 \ 'lnext',
4495 \ 'lnfile',
4496 \ 'lolder',
4497 \ 'lprevious',
4498 \ 'lrewind',
4499 \ ]
4500 for cmd in commands
4501 call assert_fails('-1' .. cmd, 'E16:')
4502 call assert_fails('.' .. cmd, 'E16:')
4503 call assert_fails('%' .. cmd, 'E16:')
4504 call assert_fails('$' .. cmd, 'E16:')
4505 endfor
4506endfunc
Bram Moolenaar6a0cc912019-10-26 16:48:44 +02004507
4508" Test for aborting quickfix commands using QuickFixCmdPre
4509func Xtest_qfcmd_abort(cchar)
4510 call s:setup_commands(a:cchar)
4511
4512 call g:Xsetlist([], 'f')
4513
4514 " cexpr/lexpr
4515 let e = ''
4516 try
4517 Xexpr ["F1:10:Line10", "F2:20:Line20"]
4518 catch /.*/
4519 let e = v:exception
4520 endtry
4521 call assert_equal('AbortCmd', e)
4522 call assert_equal(0, g:Xgetlist({'nr' : '$'}).nr)
4523
4524 " cfile/lfile
4525 call writefile(["F1:10:Line10", "F2:20:Line20"], 'Xfile1')
4526 let e = ''
4527 try
4528 Xfile Xfile1
4529 catch /.*/
4530 let e = v:exception
4531 endtry
4532 call assert_equal('AbortCmd', e)
4533 call assert_equal(0, g:Xgetlist({'nr' : '$'}).nr)
4534 call delete('Xfile1')
4535
4536 " cgetbuffer/lgetbuffer
4537 enew!
4538 call append(0, ["F1:10:Line10", "F2:20:Line20"])
4539 let e = ''
4540 try
4541 Xgetbuffer
4542 catch /.*/
4543 let e = v:exception
4544 endtry
4545 call assert_equal('AbortCmd', e)
4546 call assert_equal(0, g:Xgetlist({'nr' : '$'}).nr)
4547 enew!
4548
4549 " vimgrep/lvimgrep
4550 let e = ''
4551 try
4552 Xvimgrep /func/ test_quickfix.vim
4553 catch /.*/
4554 let e = v:exception
4555 endtry
4556 call assert_equal('AbortCmd', e)
4557 call assert_equal(0, g:Xgetlist({'nr' : '$'}).nr)
4558
4559 " helpgrep/lhelpgrep
4560 let e = ''
4561 try
4562 Xhelpgrep quickfix
4563 catch /.*/
4564 let e = v:exception
4565 endtry
4566 call assert_equal('AbortCmd', e)
4567 call assert_equal(0, g:Xgetlist({'nr' : '$'}).nr)
4568
4569 " grep/lgrep
4570 if has('unix')
4571 let e = ''
4572 try
4573 silent Xgrep func test_quickfix.vim
4574 catch /.*/
4575 let e = v:exception
4576 endtry
4577 call assert_equal('AbortCmd', e)
4578 call assert_equal(0, g:Xgetlist({'nr' : '$'}).nr)
4579 endif
4580endfunc
4581
4582func Test_qfcmd_abort()
4583 augroup QF_Test
4584 au!
4585 autocmd QuickFixCmdPre * throw "AbortCmd"
4586 augroup END
4587
4588 call Xtest_qfcmd_abort('c')
4589 call Xtest_qfcmd_abort('l')
4590
4591 augroup QF_Test
4592 au!
4593 augroup END
4594endfunc
4595
Bram Moolenaard8a8c4c2019-11-16 21:04:57 +01004596" Test for using a file in one of the parent directories.
4597func Test_search_in_dirstack()
4598 call mkdir('Xtestdir/a/b/c', 'p')
4599 let save_cwd = getcwd()
4600 call writefile(["X1_L1", "X1_L2"], 'Xtestdir/Xfile1')
4601 call writefile(["X2_L1", "X2_L2"], 'Xtestdir/a/Xfile2')
4602 call writefile(["X3_L1", "X3_L2"], 'Xtestdir/a/b/Xfile3')
4603 call writefile(["X4_L1", "X4_L2"], 'Xtestdir/a/b/c/Xfile4')
4604
4605 let lines = "Entering dir Xtestdir\n" .
4606 \ "Entering dir a\n" .
4607 \ "Entering dir b\n" .
4608 \ "Xfile2:2:X2_L2\n" .
4609 \ "Leaving dir a\n" .
4610 \ "Xfile1:2:X1_L2\n" .
4611 \ "Xfile3:1:X3_L1\n" .
4612 \ "Entering dir c\n" .
4613 \ "Xfile4:2:X4_L2\n" .
4614 \ "Leaving dir c\n" .
4615 \ "Leaving dir Xtestdir\n"
4616 set efm=%DEntering\ dir\ %f,%XLeaving\ dir\ %f,%f:%l:%m
4617 cexpr lines
4618 call assert_equal(11, getqflist({'size' : 0}).size)
4619 call assert_equal(4, getqflist({'idx' : 0}).idx)
4620 call assert_equal('X2_L2', getline('.'))
4621 cnext
4622 call assert_equal(6, getqflist({'idx' : 0}).idx)
4623 call assert_equal('X1_L2', getline('.'))
4624 cnext
4625 call assert_equal(7, getqflist({'idx' : 0}).idx)
4626 call assert_equal(1, line('$'))
4627 call assert_equal('', getline(1))
4628 cnext
4629 call assert_equal(9, getqflist({'idx' : 0}).idx)
4630 call assert_equal(1, line('$'))
4631 call assert_equal('', getline(1))
4632
4633 set efm&
4634 exe 'cd ' . save_cwd
4635 call delete('Xtestdir', 'rf')
4636endfunc
4637
Bram Moolenaar6a0cc912019-10-26 16:48:44 +02004638" vim: shiftwidth=2 sts=2 expandtab