blob: 84cdb6c916aea747cbe357d0623f0f61b52a2e29 [file] [log] [blame]
Bram Moolenaareeb1b9c2019-02-10 22:59:04 +01001" Test for the quickfix feature.
Bram Moolenaarda59dd52016-01-05 21:59:58 +01002
Bram Moolenaarb46fecd2019-06-15 17:58:09 +02003source check.vim
4CheckFeature quickfix
Bram Moolenaarda59dd52016-01-05 21:59:58 +01005
Bram Moolenaare00fdf32019-09-15 19:09:42 +02006source screendump.vim
7
Bram Moolenaar7eba3d22016-03-19 22:54:09 +01008set encoding=utf-8
9
Bram Moolenaar2b946c92016-11-12 18:14:44 +010010func s:setup_commands(cchar)
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +020011 if a:cchar == 'c'
12 command! -nargs=* -bang Xlist <mods>clist<bang> <args>
13 command! -nargs=* Xgetexpr <mods>cgetexpr <args>
Bram Moolenaar361c8f02016-07-02 15:41:47 +020014 command! -nargs=* Xaddexpr <mods>caddexpr <args>
Bram Moolenaar55b69262017-08-13 13:42:01 +020015 command! -nargs=* -count Xolder <mods><count>colder <args>
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +020016 command! -nargs=* Xnewer <mods>cnewer <args>
17 command! -nargs=* Xopen <mods>copen <args>
18 command! -nargs=* Xwindow <mods>cwindow <args>
Bram Moolenaar537ef082016-07-09 17:56:19 +020019 command! -nargs=* Xbottom <mods>cbottom <args>
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +020020 command! -nargs=* Xclose <mods>cclose <args>
21 command! -nargs=* -bang Xfile <mods>cfile<bang> <args>
22 command! -nargs=* Xgetfile <mods>cgetfile <args>
23 command! -nargs=* Xaddfile <mods>caddfile <args>
24 command! -nargs=* -bang Xbuffer <mods>cbuffer<bang> <args>
25 command! -nargs=* Xgetbuffer <mods>cgetbuffer <args>
26 command! -nargs=* Xaddbuffer <mods>caddbuffer <args>
27 command! -nargs=* Xrewind <mods>crewind <args>
Bram Moolenaar99895ea2017-04-20 22:44:47 +020028 command! -count -nargs=* -bang Xnext <mods><count>cnext<bang> <args>
29 command! -count -nargs=* -bang Xprev <mods><count>cprev<bang> <args>
Bram Moolenaar0fcc7c62016-07-02 21:22:52 +020030 command! -nargs=* -bang Xfirst <mods>cfirst<bang> <args>
31 command! -nargs=* -bang Xlast <mods>clast<bang> <args>
Bram Moolenaar25190db2019-05-04 15:05:28 +020032 command! -count -nargs=* -bang Xnfile <mods><count>cnfile<bang> <args>
Bram Moolenaar0fcc7c62016-07-02 21:22:52 +020033 command! -nargs=* -bang Xpfile <mods>cpfile<bang> <args>
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +020034 command! -nargs=* Xexpr <mods>cexpr <args>
Bram Moolenaaree85df32017-03-19 14:19:50 +010035 command! -range -nargs=* Xvimgrep <mods><count>vimgrep <args>
36 command! -nargs=* Xvimgrepadd <mods>vimgrepadd <args>
Bram Moolenaar049cba92016-06-26 14:38:04 +020037 command! -nargs=* Xgrep <mods> grep <args>
38 command! -nargs=* Xgrepadd <mods> grepadd <args>
39 command! -nargs=* Xhelpgrep helpgrep <args>
Bram Moolenaar74240d32017-12-10 15:26:15 +010040 command! -nargs=0 -count Xcc <count>cc
Bram Moolenaar3ff33112019-05-03 21:56:35 +020041 command! -count=1 -nargs=0 Xbelow <mods><count>cbelow
42 command! -count=1 -nargs=0 Xabove <mods><count>cabove
Bram Moolenaarcf6a55c2019-05-05 15:02:30 +020043 command! -count=1 -nargs=0 Xbefore <mods><count>cbefore
44 command! -count=1 -nargs=0 Xafter <mods><count>cafter
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +020045 let g:Xgetlist = function('getqflist')
46 let g:Xsetlist = function('setqflist')
Bram Moolenaarb6fa30c2017-03-29 14:19:25 +020047 call setqflist([], 'f')
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +020048 else
49 command! -nargs=* -bang Xlist <mods>llist<bang> <args>
50 command! -nargs=* Xgetexpr <mods>lgetexpr <args>
Bram Moolenaar361c8f02016-07-02 15:41:47 +020051 command! -nargs=* Xaddexpr <mods>laddexpr <args>
Bram Moolenaar55b69262017-08-13 13:42:01 +020052 command! -nargs=* -count Xolder <mods><count>lolder <args>
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +020053 command! -nargs=* Xnewer <mods>lnewer <args>
54 command! -nargs=* Xopen <mods>lopen <args>
55 command! -nargs=* Xwindow <mods>lwindow <args>
Bram Moolenaar537ef082016-07-09 17:56:19 +020056 command! -nargs=* Xbottom <mods>lbottom <args>
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +020057 command! -nargs=* Xclose <mods>lclose <args>
58 command! -nargs=* -bang Xfile <mods>lfile<bang> <args>
59 command! -nargs=* Xgetfile <mods>lgetfile <args>
60 command! -nargs=* Xaddfile <mods>laddfile <args>
61 command! -nargs=* -bang Xbuffer <mods>lbuffer<bang> <args>
62 command! -nargs=* Xgetbuffer <mods>lgetbuffer <args>
63 command! -nargs=* Xaddbuffer <mods>laddbuffer <args>
64 command! -nargs=* Xrewind <mods>lrewind <args>
Bram Moolenaar99895ea2017-04-20 22:44:47 +020065 command! -count -nargs=* -bang Xnext <mods><count>lnext<bang> <args>
66 command! -count -nargs=* -bang Xprev <mods><count>lprev<bang> <args>
Bram Moolenaar0fcc7c62016-07-02 21:22:52 +020067 command! -nargs=* -bang Xfirst <mods>lfirst<bang> <args>
68 command! -nargs=* -bang Xlast <mods>llast<bang> <args>
Bram Moolenaar25190db2019-05-04 15:05:28 +020069 command! -count -nargs=* -bang Xnfile <mods><count>lnfile<bang> <args>
Bram Moolenaar0fcc7c62016-07-02 21:22:52 +020070 command! -nargs=* -bang Xpfile <mods>lpfile<bang> <args>
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +020071 command! -nargs=* Xexpr <mods>lexpr <args>
Bram Moolenaaree85df32017-03-19 14:19:50 +010072 command! -range -nargs=* Xvimgrep <mods><count>lvimgrep <args>
73 command! -nargs=* Xvimgrepadd <mods>lvimgrepadd <args>
Bram Moolenaar049cba92016-06-26 14:38:04 +020074 command! -nargs=* Xgrep <mods> lgrep <args>
75 command! -nargs=* Xgrepadd <mods> lgrepadd <args>
76 command! -nargs=* Xhelpgrep lhelpgrep <args>
Bram Moolenaar74240d32017-12-10 15:26:15 +010077 command! -nargs=0 -count Xcc <count>ll
Bram Moolenaar3ff33112019-05-03 21:56:35 +020078 command! -count=1 -nargs=0 Xbelow <mods><count>lbelow
79 command! -count=1 -nargs=0 Xabove <mods><count>labove
Bram Moolenaarcf6a55c2019-05-05 15:02:30 +020080 command! -count=1 -nargs=0 Xbefore <mods><count>lbefore
81 command! -count=1 -nargs=0 Xafter <mods><count>lafter
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +020082 let g:Xgetlist = function('getloclist', [0])
83 let g:Xsetlist = function('setloclist', [0])
Bram Moolenaarb6fa30c2017-03-29 14:19:25 +020084 call setloclist(0, [], 'f')
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +020085 endif
Bram Moolenaar2b946c92016-11-12 18:14:44 +010086endfunc
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +020087
Bram Moolenaarda59dd52016-01-05 21:59:58 +010088" Tests for the :clist and :llist commands
Bram Moolenaar2b946c92016-11-12 18:14:44 +010089func XlistTests(cchar)
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +020090 call s:setup_commands(a:cchar)
Bram Moolenaarda59dd52016-01-05 21:59:58 +010091
Bram Moolenaarb6fa30c2017-03-29 14:19:25 +020092 if a:cchar == 'l'
93 call assert_fails('llist', 'E776:')
94 endif
Bram Moolenaarda59dd52016-01-05 21:59:58 +010095 " With an empty list, command should return error
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +020096 Xgetexpr []
97 silent! Xlist
Bram Moolenaarda59dd52016-01-05 21:59:58 +010098 call assert_true(v:errmsg ==# 'E42: No Errors')
99
100 " Populate the list and then try
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +0200101 Xgetexpr ['non-error 1', 'Xtestfile1:1:3:Line1',
Bram Moolenaarda59dd52016-01-05 21:59:58 +0100102 \ 'non-error 2', 'Xtestfile2:2:2:Line2',
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +0200103 \ 'non-error 3', 'Xtestfile3:3:1:Line3']
Bram Moolenaarda59dd52016-01-05 21:59:58 +0100104
105 " List only valid entries
Bram Moolenaaree85df32017-03-19 14:19:50 +0100106 let l = split(execute('Xlist', ''), "\n")
Bram Moolenaarda59dd52016-01-05 21:59:58 +0100107 call assert_equal([' 2 Xtestfile1:1 col 3: Line1',
108 \ ' 4 Xtestfile2:2 col 2: Line2',
109 \ ' 6 Xtestfile3:3 col 1: Line3'], l)
110
111 " List all the entries
Bram Moolenaaree85df32017-03-19 14:19:50 +0100112 let l = split(execute('Xlist!', ''), "\n")
Bram Moolenaarda59dd52016-01-05 21:59:58 +0100113 call assert_equal([' 1: non-error 1', ' 2 Xtestfile1:1 col 3: Line1',
114 \ ' 3: non-error 2', ' 4 Xtestfile2:2 col 2: Line2',
115 \ ' 5: non-error 3', ' 6 Xtestfile3:3 col 1: Line3'], l)
116
117 " List a range of errors
Bram Moolenaaree85df32017-03-19 14:19:50 +0100118 let l = split(execute('Xlist 3,6', ''), "\n")
Bram Moolenaarda59dd52016-01-05 21:59:58 +0100119 call assert_equal([' 4 Xtestfile2:2 col 2: Line2',
120 \ ' 6 Xtestfile3:3 col 1: Line3'], l)
121
Bram Moolenaaree85df32017-03-19 14:19:50 +0100122 let l = split(execute('Xlist! 3,4', ''), "\n")
Bram Moolenaarda59dd52016-01-05 21:59:58 +0100123 call assert_equal([' 3: non-error 2', ' 4 Xtestfile2:2 col 2: Line2'], l)
124
Bram Moolenaaree85df32017-03-19 14:19:50 +0100125 let l = split(execute('Xlist -6,-4', ''), "\n")
Bram Moolenaarda59dd52016-01-05 21:59:58 +0100126 call assert_equal([' 2 Xtestfile1:1 col 3: Line1'], l)
127
Bram Moolenaaree85df32017-03-19 14:19:50 +0100128 let l = split(execute('Xlist! -5,-3', ''), "\n")
Bram Moolenaarda59dd52016-01-05 21:59:58 +0100129 call assert_equal([' 2 Xtestfile1:1 col 3: Line1',
130 \ ' 3: non-error 2', ' 4 Xtestfile2:2 col 2: Line2'], l)
Bram Moolenaar391b1dd2017-03-04 13:47:11 +0100131
132 " Test for '+'
Bram Moolenaaree85df32017-03-19 14:19:50 +0100133 let l = split(execute('Xlist! +2', ''), "\n")
Bram Moolenaar391b1dd2017-03-04 13:47:11 +0100134 call assert_equal([' 2 Xtestfile1:1 col 3: Line1',
135 \ ' 3: non-error 2', ' 4 Xtestfile2:2 col 2: Line2'], l)
Bram Moolenaaree85df32017-03-19 14:19:50 +0100136
137 " Different types of errors
138 call g:Xsetlist([{'lnum':10,'col':5,'type':'W', 'text':'Warning','nr':11},
139 \ {'lnum':20,'col':10,'type':'e','text':'Error','nr':22},
140 \ {'lnum':30,'col':15,'type':'i','text':'Info','nr':33},
141 \ {'lnum':40,'col':20,'type':'x', 'text':'Other','nr':44},
142 \ {'lnum':50,'col':25,'type':"\<C-A>",'text':'one','nr':55}])
143 let l = split(execute('Xlist', ""), "\n")
144 call assert_equal([' 1:10 col 5 warning 11: Warning',
145 \ ' 2:20 col 10 error 22: Error',
146 \ ' 3:30 col 15 info 33: Info',
147 \ ' 4:40 col 20 x 44: Other',
148 \ ' 5:50 col 25 55: one'], l)
149
Bram Moolenaard76ce852018-05-01 15:02:04 +0200150 " Test for module names, one needs to explicitly set `'valid':v:true` so
151 call g:Xsetlist([
152 \ {'lnum':10,'col':5,'type':'W','module':'Data.Text','text':'ModuleWarning','nr':11,'valid':v:true},
153 \ {'lnum':20,'col':10,'type':'W','module':'Data.Text','filename':'Data/Text.hs','text':'ModuleWarning','nr':22,'valid':v:true},
154 \ {'lnum':30,'col':15,'type':'W','filename':'Data/Text.hs','text':'FileWarning','nr':33,'valid':v:true}])
155 let l = split(execute('Xlist', ""), "\n")
156 call assert_equal([' 1 Data.Text:10 col 5 warning 11: ModuleWarning',
157 \ ' 2 Data.Text:20 col 10 warning 22: ModuleWarning',
158 \ ' 3 Data/Text.hs:30 col 15 warning 33: FileWarning'], l)
159
Bram Moolenaaree85df32017-03-19 14:19:50 +0100160 " Error cases
161 call assert_fails('Xlist abc', 'E488:')
Bram Moolenaar2b946c92016-11-12 18:14:44 +0100162endfunc
Bram Moolenaarda59dd52016-01-05 21:59:58 +0100163
Bram Moolenaar2b946c92016-11-12 18:14:44 +0100164func Test_clist()
Bram Moolenaarda59dd52016-01-05 21:59:58 +0100165 call XlistTests('c')
166 call XlistTests('l')
Bram Moolenaar2b946c92016-11-12 18:14:44 +0100167endfunc
Bram Moolenaarda59dd52016-01-05 21:59:58 +0100168
169" Tests for the :colder, :cnewer, :lolder and :lnewer commands
170" Note that this test assumes that a quickfix/location list is
Bram Moolenaarcfc0a352016-01-09 20:23:00 +0100171" already set by the caller.
Bram Moolenaar2b946c92016-11-12 18:14:44 +0100172func XageTests(cchar)
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +0200173 call s:setup_commands(a:cchar)
Bram Moolenaarda59dd52016-01-05 21:59:58 +0100174
Bram Moolenaar87f59b02019-04-04 14:04:11 +0200175 if a:cchar == 'l'
176 " No location list for the current window
177 call assert_fails('lolder', 'E776:')
178 call assert_fails('lnewer', 'E776:')
179 endif
180
Bram Moolenaarcf1ba352017-10-27 00:55:04 +0200181 let list = [{'bufnr': bufnr('%'), 'lnum': 1}]
Bram Moolenaarb6fa30c2017-03-29 14:19:25 +0200182 call g:Xsetlist(list)
183
Bram Moolenaarda59dd52016-01-05 21:59:58 +0100184 " Jumping to a non existent list should return error
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +0200185 silent! Xolder 99
Bram Moolenaarda59dd52016-01-05 21:59:58 +0100186 call assert_true(v:errmsg ==# 'E380: At bottom of quickfix stack')
187
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +0200188 silent! Xnewer 99
Bram Moolenaarda59dd52016-01-05 21:59:58 +0100189 call assert_true(v:errmsg ==# 'E381: At top of quickfix stack')
190
191 " Add three quickfix/location lists
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +0200192 Xgetexpr ['Xtestfile1:1:3:Line1']
193 Xgetexpr ['Xtestfile2:2:2:Line2']
194 Xgetexpr ['Xtestfile3:3:1:Line3']
Bram Moolenaarda59dd52016-01-05 21:59:58 +0100195
196 " Go back two lists
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +0200197 Xolder
198 let l = g:Xgetlist()
Bram Moolenaarda59dd52016-01-05 21:59:58 +0100199 call assert_equal('Line2', l[0].text)
200
201 " Go forward two lists
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +0200202 Xnewer
203 let l = g:Xgetlist()
Bram Moolenaarda59dd52016-01-05 21:59:58 +0100204 call assert_equal('Line3', l[0].text)
205
206 " Test for the optional count argument
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +0200207 Xolder 2
208 let l = g:Xgetlist()
Bram Moolenaarda59dd52016-01-05 21:59:58 +0100209 call assert_equal('Line1', l[0].text)
210
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +0200211 Xnewer 2
212 let l = g:Xgetlist()
Bram Moolenaarda59dd52016-01-05 21:59:58 +0100213 call assert_equal('Line3', l[0].text)
Bram Moolenaar2b946c92016-11-12 18:14:44 +0100214endfunc
Bram Moolenaarda59dd52016-01-05 21:59:58 +0100215
Bram Moolenaar2b946c92016-11-12 18:14:44 +0100216func Test_cage()
Bram Moolenaarda59dd52016-01-05 21:59:58 +0100217 call XageTests('c')
218 call XageTests('l')
Bram Moolenaar2b946c92016-11-12 18:14:44 +0100219endfunc
Bram Moolenaarda59dd52016-01-05 21:59:58 +0100220
221" Tests for the :cwindow, :lwindow :cclose, :lclose, :copen and :lopen
222" commands
Bram Moolenaar2b946c92016-11-12 18:14:44 +0100223func XwindowTests(cchar)
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +0200224 call s:setup_commands(a:cchar)
Bram Moolenaarda59dd52016-01-05 21:59:58 +0100225
Bram Moolenaarb6fa30c2017-03-29 14:19:25 +0200226 " Opening the location list window without any errors should fail
227 if a:cchar == 'l'
228 call assert_fails('lopen', 'E776:')
229 endif
230
Bram Moolenaarda59dd52016-01-05 21:59:58 +0100231 " Create a list with no valid entries
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +0200232 Xgetexpr ['non-error 1', 'non-error 2', 'non-error 3']
Bram Moolenaarda59dd52016-01-05 21:59:58 +0100233
234 " Quickfix/Location window should not open with no valid errors
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +0200235 Xwindow
Bram Moolenaarda59dd52016-01-05 21:59:58 +0100236 call assert_true(winnr('$') == 1)
237
238 " Create a list with valid entries
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +0200239 Xgetexpr ['Xtestfile1:1:3:Line1', 'Xtestfile2:2:2:Line2',
240 \ 'Xtestfile3:3:1:Line3']
Bram Moolenaarda59dd52016-01-05 21:59:58 +0100241
242 " Open the window
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +0200243 Xwindow
Bram Moolenaarda59dd52016-01-05 21:59:58 +0100244 call assert_true(winnr('$') == 2 && winnr() == 2 &&
245 \ getline('.') ==# 'Xtestfile1|1 col 3| Line1')
Bram Moolenaar537ef082016-07-09 17:56:19 +0200246 redraw!
Bram Moolenaarda59dd52016-01-05 21:59:58 +0100247
248 " Close the window
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +0200249 Xclose
Bram Moolenaarda59dd52016-01-05 21:59:58 +0100250 call assert_true(winnr('$') == 1)
251
252 " Create a list with no valid entries
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +0200253 Xgetexpr ['non-error 1', 'non-error 2', 'non-error 3']
Bram Moolenaarda59dd52016-01-05 21:59:58 +0100254
255 " Open the window
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +0200256 Xopen 5
Bram Moolenaarda59dd52016-01-05 21:59:58 +0100257 call assert_true(winnr('$') == 2 && getline('.') ==# '|| non-error 1'
258 \ && winheight('.') == 5)
259
260 " Opening the window again, should move the cursor to that window
261 wincmd t
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +0200262 Xopen 7
Bram Moolenaarda59dd52016-01-05 21:59:58 +0100263 call assert_true(winnr('$') == 2 && winnr() == 2 &&
264 \ winheight('.') == 7 &&
265 \ getline('.') ==# '|| non-error 1')
266
267
268 " Calling cwindow should close the quickfix window with no valid errors
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +0200269 Xwindow
Bram Moolenaarda59dd52016-01-05 21:59:58 +0100270 call assert_true(winnr('$') == 1)
Bram Moolenaarb6fa30c2017-03-29 14:19:25 +0200271
272 if a:cchar == 'c'
273 " Opening the quickfix window in multiple tab pages should reuse the
274 " quickfix buffer
275 Xgetexpr ['Xtestfile1:1:3:Line1', 'Xtestfile2:2:2:Line2',
276 \ 'Xtestfile3:3:1:Line3']
277 Xopen
278 let qfbufnum = bufnr('%')
279 tabnew
280 Xopen
281 call assert_equal(qfbufnum, bufnr('%'))
282 new | only | tabonly
283 endif
Bram Moolenaar2b946c92016-11-12 18:14:44 +0100284endfunc
Bram Moolenaarda59dd52016-01-05 21:59:58 +0100285
Bram Moolenaar2b946c92016-11-12 18:14:44 +0100286func Test_cwindow()
Bram Moolenaarda59dd52016-01-05 21:59:58 +0100287 call XwindowTests('c')
288 call XwindowTests('l')
Bram Moolenaar2b946c92016-11-12 18:14:44 +0100289endfunc
Bram Moolenaarda59dd52016-01-05 21:59:58 +0100290
Bram Moolenaar36d50222019-05-02 20:17:40 +0200291func Test_copenHeight()
292 copen
293 wincmd H
294 let height = winheight(0)
295 copen 10
296 call assert_equal(height, winheight(0))
297 quit
298endfunc
299
Bram Moolenaar1142a312019-10-16 14:51:39 +0200300func Test_copenHeight_tabline()
301 set tabline=foo showtabline=2
302 copen
303 wincmd H
304 let height = winheight(0)
305 copen 10
306 call assert_equal(height, winheight(0))
307 quit
308 set tabline& showtabline&
309endfunc
310
311
Bram Moolenaarda59dd52016-01-05 21:59:58 +0100312" Tests for the :cfile, :lfile, :caddfile, :laddfile, :cgetfile and :lgetfile
313" commands.
Bram Moolenaar2b946c92016-11-12 18:14:44 +0100314func XfileTests(cchar)
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +0200315 call s:setup_commands(a:cchar)
Bram Moolenaarda59dd52016-01-05 21:59:58 +0100316
317 call writefile(['Xtestfile1:700:10:Line 700',
318 \ 'Xtestfile2:800:15:Line 800'], 'Xqftestfile1')
319
320 enew!
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +0200321 Xfile Xqftestfile1
322 let l = g:Xgetlist()
Bram Moolenaarda59dd52016-01-05 21:59:58 +0100323 call assert_true(len(l) == 2 &&
324 \ l[0].lnum == 700 && l[0].col == 10 && l[0].text ==# 'Line 700' &&
325 \ l[1].lnum == 800 && l[1].col == 15 && l[1].text ==# 'Line 800')
326
Bram Moolenaar049cba92016-06-26 14:38:04 +0200327 " Test with a non existent file
328 call assert_fails('Xfile non_existent_file', 'E40')
329
Bram Moolenaarda59dd52016-01-05 21:59:58 +0100330 " Run cfile/lfile from a modified buffer
331 enew!
332 silent! put ='Quickfix'
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +0200333 silent! Xfile Xqftestfile1
Bram Moolenaarda59dd52016-01-05 21:59:58 +0100334 call assert_true(v:errmsg ==# 'E37: No write since last change (add ! to override)')
335
336 call writefile(['Xtestfile3:900:30:Line 900'], 'Xqftestfile1')
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +0200337 Xaddfile Xqftestfile1
338 let l = g:Xgetlist()
Bram Moolenaarda59dd52016-01-05 21:59:58 +0100339 call assert_true(len(l) == 3 &&
340 \ l[2].lnum == 900 && l[2].col == 30 && l[2].text ==# 'Line 900')
341
342 call writefile(['Xtestfile1:222:77:Line 222',
343 \ 'Xtestfile2:333:88:Line 333'], 'Xqftestfile1')
344
345 enew!
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +0200346 Xgetfile Xqftestfile1
347 let l = g:Xgetlist()
Bram Moolenaarda59dd52016-01-05 21:59:58 +0100348 call assert_true(len(l) == 2 &&
349 \ l[0].lnum == 222 && l[0].col == 77 && l[0].text ==# 'Line 222' &&
350 \ l[1].lnum == 333 && l[1].col == 88 && l[1].text ==# 'Line 333')
351
352 call delete('Xqftestfile1')
Bram Moolenaar2b946c92016-11-12 18:14:44 +0100353endfunc
Bram Moolenaarda59dd52016-01-05 21:59:58 +0100354
Bram Moolenaar2b946c92016-11-12 18:14:44 +0100355func Test_cfile()
Bram Moolenaarda59dd52016-01-05 21:59:58 +0100356 call XfileTests('c')
357 call XfileTests('l')
Bram Moolenaar2b946c92016-11-12 18:14:44 +0100358endfunc
Bram Moolenaarda59dd52016-01-05 21:59:58 +0100359
360" Tests for the :cbuffer, :lbuffer, :caddbuffer, :laddbuffer, :cgetbuffer and
361" :lgetbuffer commands.
Bram Moolenaar2b946c92016-11-12 18:14:44 +0100362func XbufferTests(cchar)
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +0200363 call s:setup_commands(a:cchar)
Bram Moolenaarda59dd52016-01-05 21:59:58 +0100364
365 enew!
366 silent! call setline(1, ['Xtestfile7:700:10:Line 700',
367 \ 'Xtestfile8:800:15:Line 800'])
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +0200368 Xbuffer!
369 let l = g:Xgetlist()
Bram Moolenaarda59dd52016-01-05 21:59:58 +0100370 call assert_true(len(l) == 2 &&
371 \ l[0].lnum == 700 && l[0].col == 10 && l[0].text ==# 'Line 700' &&
372 \ l[1].lnum == 800 && l[1].col == 15 && l[1].text ==# 'Line 800')
373
374 enew!
375 silent! call setline(1, ['Xtestfile9:900:55:Line 900',
376 \ 'Xtestfile10:950:66:Line 950'])
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +0200377 Xgetbuffer
378 let l = g:Xgetlist()
Bram Moolenaarda59dd52016-01-05 21:59:58 +0100379 call assert_true(len(l) == 2 &&
380 \ l[0].lnum == 900 && l[0].col == 55 && l[0].text ==# 'Line 900' &&
381 \ l[1].lnum == 950 && l[1].col == 66 && l[1].text ==# 'Line 950')
382
383 enew!
384 silent! call setline(1, ['Xtestfile11:700:20:Line 700',
385 \ 'Xtestfile12:750:25:Line 750'])
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +0200386 Xaddbuffer
387 let l = g:Xgetlist()
Bram Moolenaarda59dd52016-01-05 21:59:58 +0100388 call assert_true(len(l) == 4 &&
389 \ l[1].lnum == 950 && l[1].col == 66 && l[1].text ==# 'Line 950' &&
390 \ l[2].lnum == 700 && l[2].col == 20 && l[2].text ==# 'Line 700' &&
391 \ l[3].lnum == 750 && l[3].col == 25 && l[3].text ==# 'Line 750')
Bram Moolenaarab47c612016-06-14 22:02:26 +0200392 enew!
Bram Moolenaarda59dd52016-01-05 21:59:58 +0100393
Bram Moolenaaree85df32017-03-19 14:19:50 +0100394 " Check for invalid buffer
395 call assert_fails('Xbuffer 199', 'E474:')
396
397 " Check for unloaded buffer
398 edit Xtestfile1
399 let bnr = bufnr('%')
400 enew!
401 call assert_fails('Xbuffer ' . bnr, 'E681:')
402
403 " Check for invalid range
404 " Using Xbuffer will not run the range check in the cbuffer/lbuffer
405 " commands. So directly call the commands.
406 if (a:cchar == 'c')
407 call assert_fails('900,999cbuffer', 'E16:')
408 else
409 call assert_fails('900,999lbuffer', 'E16:')
410 endif
Bram Moolenaar2b946c92016-11-12 18:14:44 +0100411endfunc
Bram Moolenaarda59dd52016-01-05 21:59:58 +0100412
Bram Moolenaar2b946c92016-11-12 18:14:44 +0100413func Test_cbuffer()
Bram Moolenaarda59dd52016-01-05 21:59:58 +0100414 call XbufferTests('c')
415 call XbufferTests('l')
Bram Moolenaar2b946c92016-11-12 18:14:44 +0100416endfunc
Bram Moolenaarda59dd52016-01-05 21:59:58 +0100417
Bram Moolenaar2b946c92016-11-12 18:14:44 +0100418func XexprTests(cchar)
Bram Moolenaar0fcc7c62016-07-02 21:22:52 +0200419 call s:setup_commands(a:cchar)
420
421 call assert_fails('Xexpr 10', 'E777:')
Bram Moolenaar2b946c92016-11-12 18:14:44 +0100422endfunc
Bram Moolenaar0fcc7c62016-07-02 21:22:52 +0200423
Bram Moolenaar2b946c92016-11-12 18:14:44 +0100424func Test_cexpr()
Bram Moolenaar0fcc7c62016-07-02 21:22:52 +0200425 call XexprTests('c')
426 call XexprTests('l')
Bram Moolenaar2b946c92016-11-12 18:14:44 +0100427endfunc
Bram Moolenaar0fcc7c62016-07-02 21:22:52 +0200428
429" Tests for :cnext, :cprev, :cfirst, :clast commands
Bram Moolenaar2b946c92016-11-12 18:14:44 +0100430func Xtest_browse(cchar)
Bram Moolenaar0fcc7c62016-07-02 21:22:52 +0200431 call s:setup_commands(a:cchar)
432
Bram Moolenaar74240d32017-12-10 15:26:15 +0100433 call g:Xsetlist([], 'f')
Bram Moolenaarb6fa30c2017-03-29 14:19:25 +0200434 " Jumping to first or next location list entry without any error should
435 " result in failure
Bram Moolenaar74240d32017-12-10 15:26:15 +0100436 if a:cchar == 'c'
437 let err = 'E42:'
438 else
439 let err = 'E776:'
Bram Moolenaarb6fa30c2017-03-29 14:19:25 +0200440 endif
Bram Moolenaar74240d32017-12-10 15:26:15 +0100441 call assert_fails('Xnext', err)
442 call assert_fails('Xprev', err)
443 call assert_fails('Xnfile', err)
444 call assert_fails('Xpfile', err)
Bram Moolenaarb6fa30c2017-03-29 14:19:25 +0200445
Bram Moolenaar0fcc7c62016-07-02 21:22:52 +0200446 call s:create_test_file('Xqftestfile1')
447 call s:create_test_file('Xqftestfile2')
448
449 Xgetexpr ['Xqftestfile1:5:Line5',
450 \ 'Xqftestfile1:6:Line6',
451 \ 'Xqftestfile2:10:Line10',
Bram Moolenaar99895ea2017-04-20 22:44:47 +0200452 \ 'Xqftestfile2:11:Line11',
453 \ 'RegularLine1',
454 \ 'RegularLine2']
Bram Moolenaar0fcc7c62016-07-02 21:22:52 +0200455
456 Xfirst
457 call assert_fails('Xprev', 'E553')
458 call assert_fails('Xpfile', 'E553')
459 Xnfile
460 call assert_equal('Xqftestfile2', bufname('%'))
461 call assert_equal(10, line('.'))
462 Xpfile
463 call assert_equal('Xqftestfile1', bufname('%'))
464 call assert_equal(6, line('.'))
Bram Moolenaar74240d32017-12-10 15:26:15 +0100465 5Xcc
466 call assert_equal(5, g:Xgetlist({'idx':0}).idx)
467 2Xcc
468 call assert_equal(2, g:Xgetlist({'idx':0}).idx)
469 10Xcc
470 call assert_equal(6, g:Xgetlist({'idx':0}).idx)
Bram Moolenaar0fcc7c62016-07-02 21:22:52 +0200471 Xlast
Bram Moolenaar99895ea2017-04-20 22:44:47 +0200472 Xprev
Bram Moolenaar0fcc7c62016-07-02 21:22:52 +0200473 call assert_equal('Xqftestfile2', bufname('%'))
474 call assert_equal(11, line('.'))
475 call assert_fails('Xnext', 'E553')
476 call assert_fails('Xnfile', 'E553')
477 Xrewind
478 call assert_equal('Xqftestfile1', bufname('%'))
479 call assert_equal(5, line('.'))
480
Bram Moolenaar99895ea2017-04-20 22:44:47 +0200481 10Xnext
482 call assert_equal('Xqftestfile2', bufname('%'))
483 call assert_equal(11, line('.'))
484 10Xprev
485 call assert_equal('Xqftestfile1', bufname('%'))
486 call assert_equal(5, line('.'))
487
Bram Moolenaar74240d32017-12-10 15:26:15 +0100488 " Jumping to an error from the error window using cc command
489 Xgetexpr ['Xqftestfile1:5:Line5',
490 \ 'Xqftestfile1:6:Line6',
491 \ 'Xqftestfile2:10:Line10',
492 \ 'Xqftestfile2:11:Line11']
493 Xopen
494 10Xcc
495 call assert_equal(11, line('.'))
496 call assert_equal('Xqftestfile2', bufname('%'))
497
498 " Jumping to an error from the error window (when only the error window is
499 " present)
500 Xopen | only
501 Xlast 1
502 call assert_equal(5, line('.'))
503 call assert_equal('Xqftestfile1', bufname('%'))
504
Bram Moolenaaree85df32017-03-19 14:19:50 +0100505 Xexpr ""
506 call assert_fails('Xnext', 'E42:')
507
Bram Moolenaar0fcc7c62016-07-02 21:22:52 +0200508 call delete('Xqftestfile1')
509 call delete('Xqftestfile2')
Bram Moolenaarfc2b2702017-09-15 22:43:07 +0200510
511 " Should be able to use next/prev with invalid entries
512 Xexpr ""
513 call assert_equal(0, g:Xgetlist({'idx' : 0}).idx)
514 call assert_equal(0, g:Xgetlist({'size' : 0}).size)
515 Xaddexpr ['foo', 'bar', 'baz', 'quux', 'shmoo']
516 call assert_equal(5, g:Xgetlist({'size' : 0}).size)
517 Xlast
518 call assert_equal(5, g:Xgetlist({'idx' : 0}).idx)
519 Xfirst
520 call assert_equal(1, g:Xgetlist({'idx' : 0}).idx)
521 2Xnext
522 call assert_equal(3, g:Xgetlist({'idx' : 0}).idx)
Bram Moolenaar2b946c92016-11-12 18:14:44 +0100523endfunc
Bram Moolenaar0fcc7c62016-07-02 21:22:52 +0200524
Bram Moolenaar2b946c92016-11-12 18:14:44 +0100525func Test_browse()
Bram Moolenaar0fcc7c62016-07-02 21:22:52 +0200526 call Xtest_browse('c')
527 call Xtest_browse('l')
Bram Moolenaar2b946c92016-11-12 18:14:44 +0100528endfunc
Bram Moolenaar0fcc7c62016-07-02 21:22:52 +0200529
Bram Moolenaar2b946c92016-11-12 18:14:44 +0100530func Test_nomem()
Bram Moolenaar8e8df252016-05-25 21:23:21 +0200531 call test_alloc_fail(GetAllocId('qf_dirname_start'), 0, 0)
Bram Moolenaara260b872016-01-15 20:48:22 +0100532 call assert_fails('vimgrep vim runtest.vim', 'E342:')
Bram Moolenaar75bdf6a2016-01-07 21:25:08 +0100533
Bram Moolenaarce90e362019-09-08 18:58:44 +0200534 call GetAllocId('qf_dirname_now')->test_alloc_fail(0, 0)
Bram Moolenaara260b872016-01-15 20:48:22 +0100535 call assert_fails('vimgrep vim runtest.vim', 'E342:')
Bram Moolenaar75bdf6a2016-01-07 21:25:08 +0100536
Bram Moolenaar8e8df252016-05-25 21:23:21 +0200537 call test_alloc_fail(GetAllocId('qf_namebuf'), 0, 0)
Bram Moolenaara260b872016-01-15 20:48:22 +0100538 call assert_fails('cfile runtest.vim', 'E342:')
Bram Moolenaar75bdf6a2016-01-07 21:25:08 +0100539
Bram Moolenaar8e8df252016-05-25 21:23:21 +0200540 call test_alloc_fail(GetAllocId('qf_errmsg'), 0, 0)
Bram Moolenaara260b872016-01-15 20:48:22 +0100541 call assert_fails('cfile runtest.vim', 'E342:')
Bram Moolenaar75bdf6a2016-01-07 21:25:08 +0100542
Bram Moolenaar8e8df252016-05-25 21:23:21 +0200543 call test_alloc_fail(GetAllocId('qf_pattern'), 0, 0)
Bram Moolenaara260b872016-01-15 20:48:22 +0100544 call assert_fails('cfile runtest.vim', 'E342:')
Bram Moolenaar75bdf6a2016-01-07 21:25:08 +0100545
546endfunc
547
Bram Moolenaar2b946c92016-11-12 18:14:44 +0100548func s:test_xhelpgrep(cchar)
Bram Moolenaar049cba92016-06-26 14:38:04 +0200549 call s:setup_commands(a:cchar)
550 Xhelpgrep quickfix
551 Xopen
552 if a:cchar == 'c'
553 let title_text = ':helpgrep quickfix'
554 else
555 let title_text = ':lhelpgrep quickfix'
556 endif
557 call assert_true(w:quickfix_title =~ title_text, w:quickfix_title)
Bram Moolenaar99895ea2017-04-20 22:44:47 +0200558
559 " Jumping to a help topic should open the help window
560 only
561 Xnext
562 call assert_true(&buftype == 'help')
563 call assert_true(winnr('$') == 2)
564 " Jumping to the next match should reuse the help window
565 Xnext
566 call assert_true(&buftype == 'help')
567 call assert_true(winnr() == 1)
568 call assert_true(winnr('$') == 2)
569 " Jumping to the next match from the quickfix window should reuse the help
570 " window
571 Xopen
572 Xnext
573 call assert_true(&buftype == 'help')
574 call assert_true(winnr() == 1)
575 call assert_true(winnr('$') == 2)
576
Bram Moolenaar62ef7972016-01-19 14:51:54 +0100577 " This wipes out the buffer, make sure that doesn't cause trouble.
Bram Moolenaar049cba92016-06-26 14:38:04 +0200578 Xclose
Bram Moolenaaree85df32017-03-19 14:19:50 +0100579
Bram Moolenaarb4d5fba2017-09-11 19:31:28 +0200580 if a:cchar == 'l'
581 " When a help window is present, running :lhelpgrep should reuse the
582 " help window and not the current window
583 new | only
584 call g:Xsetlist([], 'f')
585 help index.txt
586 wincmd w
587 lhelpgrep quickfix
588 call assert_equal(1, winnr())
589 call assert_notequal([], getloclist(1))
590 call assert_equal([], getloclist(2))
591 endif
592
Bram Moolenaar99895ea2017-04-20 22:44:47 +0200593 new | only
594
Bram Moolenaaree85df32017-03-19 14:19:50 +0100595 " Search for non existing help string
596 call assert_fails('Xhelpgrep a1b2c3', 'E480:')
Bram Moolenaar108e7b42018-10-11 17:39:12 +0200597 " Invalid regular expression
598 call assert_fails('Xhelpgrep \@<!', 'E480:')
Bram Moolenaar2b946c92016-11-12 18:14:44 +0100599endfunc
Bram Moolenaar049cba92016-06-26 14:38:04 +0200600
Bram Moolenaar2b946c92016-11-12 18:14:44 +0100601func Test_helpgrep()
Bram Moolenaar049cba92016-06-26 14:38:04 +0200602 call s:test_xhelpgrep('c')
Bram Moolenaarcf25fdb2016-08-03 21:04:53 +0200603 helpclose
Bram Moolenaar049cba92016-06-26 14:38:04 +0200604 call s:test_xhelpgrep('l')
Bram Moolenaar62ef7972016-01-19 14:51:54 +0100605endfunc
Bram Moolenaar75bdf6a2016-01-07 21:25:08 +0100606
Bram Moolenaar6920c722016-01-22 22:44:10 +0100607func Test_errortitle()
608 augroup QfBufWinEnter
609 au!
610 au BufWinEnter * :let g:a=get(w:, 'quickfix_title', 'NONE')
611 augroup END
612 copen
613 let a=[{'lnum': 308, 'bufnr': bufnr(''), 'col': 58, 'valid': 1, 'vcol': 0, 'nr': 0, 'type': '', 'pattern': '', 'text': ' au BufWinEnter * :let g:a=get(w:, ''quickfix_title'', ''NONE'')'}]
614 call setqflist(a)
615 call assert_equal(':setqflist()', g:a)
616 augroup QfBufWinEnter
617 au!
618 augroup END
619 augroup! QfBufWinEnter
620endfunc
Bram Moolenaare27dba42016-03-15 14:11:10 +0100621
Bram Moolenaar5584df62016-03-18 21:00:51 +0100622func Test_vimgreptitle()
623 augroup QfBufWinEnter
624 au!
625 au BufWinEnter * :let g:a=get(w:, 'quickfix_title', 'NONE')
626 augroup END
627 try
628 vimgrep /pattern/j file
629 catch /E480/
630 endtry
631 copen
632 call assert_equal(': vimgrep /pattern/j file', g:a)
633 augroup QfBufWinEnter
634 au!
635 augroup END
636 augroup! QfBufWinEnter
637endfunc
638
Bram Moolenaar2b946c92016-11-12 18:14:44 +0100639func XqfTitleTests(cchar)
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +0200640 call s:setup_commands(a:cchar)
Bram Moolenaare27dba42016-03-15 14:11:10 +0100641
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +0200642 Xgetexpr ['file:1:1:message']
643 let l = g:Xgetlist()
Bram Moolenaare27dba42016-03-15 14:11:10 +0100644 if a:cchar == 'c'
645 call setqflist(l, 'r')
646 else
647 call setloclist(0, l, 'r')
648 endif
649
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +0200650 Xopen
Bram Moolenaare27dba42016-03-15 14:11:10 +0100651 if a:cchar == 'c'
652 let title = ':setqflist()'
653 else
654 let title = ':setloclist()'
655 endif
656 call assert_equal(title, w:quickfix_title)
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +0200657 Xclose
Bram Moolenaar2b946c92016-11-12 18:14:44 +0100658endfunc
Bram Moolenaare27dba42016-03-15 14:11:10 +0100659
660" Tests for quickfix window's title
Bram Moolenaar2b946c92016-11-12 18:14:44 +0100661func Test_qf_title()
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +0200662 call XqfTitleTests('c')
663 call XqfTitleTests('l')
Bram Moolenaar2b946c92016-11-12 18:14:44 +0100664endfunc
Bram Moolenaare27dba42016-03-15 14:11:10 +0100665
666" Tests for 'errorformat'
Bram Moolenaar2b946c92016-11-12 18:14:44 +0100667func Test_efm()
Bram Moolenaare27dba42016-03-15 14:11:10 +0100668 let save_efm = &efm
669 set efm=%EEEE%m,%WWWW%m,%+CCCC%.%#,%-GGGG%.%#
670 cgetexpr ['WWWW', 'EEEE', 'CCCC']
671 let l = strtrans(string(map(getqflist(), '[v:val.text, v:val.valid]')))
672 call assert_equal("[['W', 1], ['E^@CCCC', 1]]", l)
673 cgetexpr ['WWWW', 'GGGG', 'EEEE', 'CCCC']
674 let l = strtrans(string(map(getqflist(), '[v:val.text, v:val.valid]')))
675 call assert_equal("[['W', 1], ['E^@CCCC', 1]]", l)
676 cgetexpr ['WWWW', 'GGGG', 'ZZZZ', 'EEEE', 'CCCC', 'YYYY']
677 let l = strtrans(string(map(getqflist(), '[v:val.text, v:val.valid]')))
678 call assert_equal("[['W', 1], ['ZZZZ', 0], ['E^@CCCC', 1], ['YYYY', 0]]", l)
679 let &efm = save_efm
Bram Moolenaar2b946c92016-11-12 18:14:44 +0100680endfunc
Bram Moolenaar1ff2b642016-03-17 22:07:02 +0100681
682" This will test for problems in quickfix:
683" A. incorrectly copying location lists which caused the location list to show
684" a different name than the file that was actually being displayed.
685" B. not reusing the window for which the location list window is opened but
686" instead creating new windows.
687" C. make sure that the location list window is not reused instead of the
688" window it belongs to.
689"
690" Set up the test environment:
Bram Moolenaar2b946c92016-11-12 18:14:44 +0100691func ReadTestProtocol(name)
Bram Moolenaar1ff2b642016-03-17 22:07:02 +0100692 let base = substitute(a:name, '\v^test://(.*)%(\.[^.]+)?', '\1', '')
693 let word = substitute(base, '\v(.*)\..*', '\1', '')
694
695 setl modifiable
696 setl noreadonly
697 setl noswapfile
698 setl bufhidden=delete
699 %del _
700 " For problem 2:
701 " 'buftype' has to be set to reproduce the constant opening of new windows
702 setl buftype=nofile
703
704 call setline(1, word)
705
706 setl nomodified
707 setl nomodifiable
708 setl readonly
709 exe 'doautocmd BufRead ' . substitute(a:name, '\v^test://(.*)', '\1', '')
Bram Moolenaar2b946c92016-11-12 18:14:44 +0100710endfunc
Bram Moolenaar1ff2b642016-03-17 22:07:02 +0100711
Bram Moolenaar2b946c92016-11-12 18:14:44 +0100712func Test_locationlist()
Bram Moolenaar1ff2b642016-03-17 22:07:02 +0100713 enew
714
715 augroup testgroup
716 au!
717 autocmd BufReadCmd test://* call ReadTestProtocol(expand("<amatch>"))
718 augroup END
719
720 let words = [ "foo", "bar", "baz", "quux", "shmoo", "spam", "eggs" ]
721
722 let qflist = []
723 for word in words
724 call add(qflist, {'filename': 'test://' . word . '.txt', 'text': 'file ' . word . '.txt', })
725 " NOTE: problem 1:
726 " intentionally not setting 'lnum' so that the quickfix entries are not
727 " valid
Bram Moolenaaraad222c2019-09-06 22:46:09 +0200728 eval qflist->setloclist(0, ' ')
Bram Moolenaar1ff2b642016-03-17 22:07:02 +0100729 endfor
730
731 " Test A
732 lrewind
733 enew
734 lopen
Bram Moolenaar99895ea2017-04-20 22:44:47 +0200735 4lnext
Bram Moolenaar1ff2b642016-03-17 22:07:02 +0100736 vert split
737 wincmd L
738 lopen
739 wincmd p
740 lnext
741 let fileName = expand("%")
742 wincmd p
743 let locationListFileName = substitute(getline(line('.')), '\([^|]*\)|.*', '\1', '')
744 let fileName = substitute(fileName, '\\', '/', 'g')
745 let locationListFileName = substitute(locationListFileName, '\\', '/', 'g')
746 call assert_equal("test://bar.txt", fileName)
747 call assert_equal("test://bar.txt", locationListFileName)
748
749 wincmd n | only
750
751 " Test B:
752 lrewind
753 lopen
754 2
755 exe "normal \<CR>"
756 wincmd p
757 3
758 exe "normal \<CR>"
759 wincmd p
760 4
761 exe "normal \<CR>"
762 call assert_equal(2, winnr('$'))
763 wincmd n | only
764
765 " Test C:
766 lrewind
767 lopen
768 " Let's move the location list window to the top to check whether it (the
769 " first window found) will be reused when we try to open new windows:
770 wincmd K
771 2
772 exe "normal \<CR>"
773 wincmd p
774 3
775 exe "normal \<CR>"
776 wincmd p
777 4
778 exe "normal \<CR>"
779 1wincmd w
780 call assert_equal('quickfix', &buftype)
781 2wincmd w
782 let bufferName = expand("%")
783 let bufferName = substitute(bufferName, '\\', '/', 'g')
784 call assert_equal('test://quux.txt', bufferName)
785
786 wincmd n | only
787
788 augroup! testgroup
Bram Moolenaaree85df32017-03-19 14:19:50 +0100789endfunc
Bram Moolenaar0899d692016-03-19 13:35:03 +0100790
Bram Moolenaar2b946c92016-11-12 18:14:44 +0100791func Test_locationlist_curwin_was_closed()
Bram Moolenaar0899d692016-03-19 13:35:03 +0100792 augroup testgroup
793 au!
Bram Moolenaard106e5b2016-04-21 19:38:07 +0200794 autocmd BufReadCmd test_curwin.txt call R(expand("<amatch>"))
Bram Moolenaar0899d692016-03-19 13:35:03 +0100795 augroup END
796
Bram Moolenaar2b946c92016-11-12 18:14:44 +0100797 func! R(n)
Bram Moolenaar0899d692016-03-19 13:35:03 +0100798 quit
799 endfunc
800
801 new
802 let q = []
Bram Moolenaard106e5b2016-04-21 19:38:07 +0200803 call add(q, {'filename': 'test_curwin.txt' })
Bram Moolenaar0899d692016-03-19 13:35:03 +0100804 call setloclist(0, q)
805 call assert_fails('lrewind', 'E924:')
806
807 augroup! testgroup
Bram Moolenaaree85df32017-03-19 14:19:50 +0100808endfunc
Bram Moolenaar7eba3d22016-03-19 22:54:09 +0100809
Bram Moolenaar2b946c92016-11-12 18:14:44 +0100810func Test_locationlist_cross_tab_jump()
Bram Moolenaar0a9046f2016-10-15 19:28:13 +0200811 call writefile(['loclistfoo'], 'loclistfoo')
812 call writefile(['loclistbar'], 'loclistbar')
813 set switchbuf=usetab
814
815 edit loclistfoo
816 tabedit loclistbar
817 silent lgrep loclistfoo loclist*
818 call assert_equal(1, tabpagenr())
819
820 enew | only | tabonly
821 set switchbuf&vim
822 call delete('loclistfoo')
823 call delete('loclistbar')
Bram Moolenaar2b946c92016-11-12 18:14:44 +0100824endfunc
Bram Moolenaar0a9046f2016-10-15 19:28:13 +0200825
Bram Moolenaar7eba3d22016-03-19 22:54:09 +0100826" More tests for 'errorformat'
Bram Moolenaar2b946c92016-11-12 18:14:44 +0100827func Test_efm1()
Bram Moolenaar7eba3d22016-03-19 22:54:09 +0100828 if !has('unix')
829 " The 'errorformat' setting is different on non-Unix systems.
830 " This test works only on Unix-like systems.
831 return
832 endif
833
Bram Moolenaarc79745a2019-05-20 22:12:34 +0200834 let l =<< trim [DATA]
Bram Moolenaare7eb9272019-06-24 00:58:07 +0200835 "Xtestfile", line 4.12: 1506-045 (S) Undeclared identifier fd_set.
836 "Xtestfile", line 6 col 19; this is an error
837 gcc -c -DHAVE_CONFIsing-prototypes -I/usr/X11R6/include version.c
838 Xtestfile:9: parse error before `asd'
839 make: *** [vim] Error 1
840 in file "Xtestfile" linenr 10: there is an error
841
842 2 returned
843 "Xtestfile", line 11 col 1; this is an error
844 "Xtestfile", line 12 col 2; this is another error
845 "Xtestfile", line 14:10; this is an error in column 10
846 =Xtestfile=, line 15:10; this is another error, but in vcol 10 this time
847 "Xtestfile", linenr 16: yet another problem
848 Error in "Xtestfile" at line 17:
849 x should be a dot
850 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 17
851 ^
852 Error in "Xtestfile" at line 18:
853 x should be a dot
854 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 18
855 .............^
856 Error in "Xtestfile" at line 19:
857 x should be a dot
858 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 19
859 --------------^
860 Error in "Xtestfile" at line 20:
861 x should be a dot
862 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 20
863 ^
864
865 Does anyone know what is the problem and how to correction it?
866 "Xtestfile", line 21 col 9: What is the title of the quickfix window?
867 "Xtestfile", line 22 col 9: What is the title of the quickfix window?
Bram Moolenaarc79745a2019-05-20 22:12:34 +0200868 [DATA]
Bram Moolenaar7eba3d22016-03-19 22:54:09 +0100869
870 call writefile(l, 'Xerrorfile1')
871 call writefile(l[:-2], 'Xerrorfile2')
872
Bram Moolenaare7eb9272019-06-24 00:58:07 +0200873 let m =<< [DATA]
874 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 2
875 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 3
876 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 4
877 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 5
878 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 6
879 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 7
880 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 8
881 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 9
882 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 10
883 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 11
884 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 12
885 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 13
886 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 14
887 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 15
888 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 16
889 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 17
890 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 18
891 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 19
892 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 20
893 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 21
894 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 22
895[DATA]
Bram Moolenaar7eba3d22016-03-19 22:54:09 +0100896 call writefile(m, 'Xtestfile')
897
898 let save_efm = &efm
899 set efm+==%f=\\,\ line\ %l%*\\D%v%*[^\ ]\ %m
900 set efm^=%AError\ in\ \"%f\"\ at\ line\ %l:,%Z%p^,%C%m
901
902 exe 'cf Xerrorfile2'
903 clast
904 copen
905 call assert_equal(':cf Xerrorfile2', w:quickfix_title)
906 wincmd p
907
908 exe 'cf Xerrorfile1'
909 call assert_equal([4, 12], [line('.'), col('.')])
910 cn
911 call assert_equal([6, 19], [line('.'), col('.')])
912 cn
913 call assert_equal([9, 2], [line('.'), col('.')])
914 cn
915 call assert_equal([10, 2], [line('.'), col('.')])
916 cn
917 call assert_equal([11, 1], [line('.'), col('.')])
918 cn
919 call assert_equal([12, 2], [line('.'), col('.')])
920 cn
921 call assert_equal([14, 10], [line('.'), col('.')])
922 cn
923 call assert_equal([15, 3, 10], [line('.'), col('.'), virtcol('.')])
924 cn
925 call assert_equal([16, 2], [line('.'), col('.')])
926 cn
927 call assert_equal([17, 6], [line('.'), col('.')])
928 cn
929 call assert_equal([18, 7], [line('.'), col('.')])
930 cn
931 call assert_equal([19, 8], [line('.'), col('.')])
932 cn
933 call assert_equal([20, 9], [line('.'), col('.')])
934 clast
935 cprev
936 cprev
937 wincmd w
938 call assert_equal(':cf Xerrorfile1', w:quickfix_title)
939 wincmd p
940
941 let &efm = save_efm
942 call delete('Xerrorfile1')
943 call delete('Xerrorfile2')
944 call delete('Xtestfile')
Bram Moolenaaree85df32017-03-19 14:19:50 +0100945endfunc
Bram Moolenaarffec3c52016-03-23 20:55:42 +0100946
Bram Moolenaarab47c612016-06-14 22:02:26 +0200947" Test for quickfix directory stack support
Bram Moolenaar2b946c92016-11-12 18:14:44 +0100948func s:dir_stack_tests(cchar)
Bram Moolenaar38df43b2016-06-20 21:41:12 +0200949 call s:setup_commands(a:cchar)
950
Bram Moolenaarab47c612016-06-14 22:02:26 +0200951 let save_efm=&efm
952 set efm=%DEntering\ dir\ '%f',%f:%l:%m,%XLeaving\ dir\ '%f'
953
Bram Moolenaar361c8f02016-07-02 15:41:47 +0200954 let lines = ["Entering dir 'dir1/a'",
955 \ 'habits2.txt:1:Nine Healthy Habits',
956 \ "Entering dir 'b'",
957 \ 'habits3.txt:2:0 Hours of television',
958 \ 'habits2.txt:7:5 Small meals',
959 \ "Entering dir 'dir1/c'",
960 \ 'habits4.txt:3:1 Hour of exercise',
961 \ "Leaving dir 'dir1/c'",
962 \ "Leaving dir 'dir1/a'",
963 \ 'habits1.txt:4:2 Liters of water',
964 \ "Entering dir 'dir2'",
965 \ 'habits5.txt:5:3 Cups of hot green tea',
966 \ "Leaving dir 'dir2'"
967 \]
Bram Moolenaarab47c612016-06-14 22:02:26 +0200968
Bram Moolenaar361c8f02016-07-02 15:41:47 +0200969 Xexpr ""
970 for l in lines
971 Xaddexpr l
972 endfor
Bram Moolenaarab47c612016-06-14 22:02:26 +0200973
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +0200974 let qf = g:Xgetlist()
Bram Moolenaarab47c612016-06-14 22:02:26 +0200975
976 call assert_equal('dir1/a/habits2.txt', bufname(qf[1].bufnr))
977 call assert_equal(1, qf[1].lnum)
978 call assert_equal('dir1/a/b/habits3.txt', bufname(qf[3].bufnr))
979 call assert_equal(2, qf[3].lnum)
980 call assert_equal('dir1/a/habits2.txt', bufname(qf[4].bufnr))
981 call assert_equal(7, qf[4].lnum)
982 call assert_equal('dir1/c/habits4.txt', bufname(qf[6].bufnr))
983 call assert_equal(3, qf[6].lnum)
984 call assert_equal('habits1.txt', bufname(qf[9].bufnr))
985 call assert_equal(4, qf[9].lnum)
986 call assert_equal('dir2/habits5.txt', bufname(qf[11].bufnr))
987 call assert_equal(5, qf[11].lnum)
988
989 let &efm=save_efm
Bram Moolenaar2b946c92016-11-12 18:14:44 +0100990endfunc
Bram Moolenaarab47c612016-06-14 22:02:26 +0200991
992" Tests for %D and %X errorformat options
Bram Moolenaar2b946c92016-11-12 18:14:44 +0100993func Test_efm_dirstack()
Bram Moolenaarab47c612016-06-14 22:02:26 +0200994 " Create the directory stack and files
995 call mkdir('dir1')
996 call mkdir('dir1/a')
997 call mkdir('dir1/a/b')
998 call mkdir('dir1/c')
999 call mkdir('dir2')
1000
1001 let lines = ["Nine Healthy Habits",
1002 \ "0 Hours of television",
1003 \ "1 Hour of exercise",
1004 \ "2 Liters of water",
1005 \ "3 Cups of hot green tea",
1006 \ "4 Short mental breaks",
1007 \ "5 Small meals",
1008 \ "6 AM wake up time",
1009 \ "7 Minutes of laughter",
1010 \ "8 Hours of sleep (at least)",
1011 \ "9 PM end of the day and off to bed"
1012 \ ]
1013 call writefile(lines, 'habits1.txt')
1014 call writefile(lines, 'dir1/a/habits2.txt')
1015 call writefile(lines, 'dir1/a/b/habits3.txt')
1016 call writefile(lines, 'dir1/c/habits4.txt')
1017 call writefile(lines, 'dir2/habits5.txt')
1018
1019 call s:dir_stack_tests('c')
1020 call s:dir_stack_tests('l')
1021
1022 call delete('dir1', 'rf')
1023 call delete('dir2', 'rf')
1024 call delete('habits1.txt')
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001025endfunc
Bram Moolenaarab47c612016-06-14 22:02:26 +02001026
Bram Moolenaar9b457942016-10-09 16:10:05 +02001027" Test for resync after continuing an ignored message
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001028func Xefm_ignore_continuations(cchar)
Bram Moolenaar9b457942016-10-09 16:10:05 +02001029 call s:setup_commands(a:cchar)
1030
1031 let save_efm = &efm
1032
1033 let &efm =
1034 \ '%Eerror %m %l,' .
1035 \ '%-Wignored %m %l,' .
1036 \ '%+Cmore ignored %m %l,' .
1037 \ '%Zignored end'
1038 Xgetexpr ['ignored warning 1', 'more ignored continuation 2', 'ignored end', 'error resync 4']
1039 let l = map(g:Xgetlist(), '[v:val.text, v:val.valid, v:val.lnum, v:val.type]')
1040 call assert_equal([['resync', 1, 4, 'E']], l)
1041
1042 let &efm = save_efm
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001043endfunc
Bram Moolenaar9b457942016-10-09 16:10:05 +02001044
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001045func Test_efm_ignore_continuations()
Bram Moolenaar9b457942016-10-09 16:10:05 +02001046 call Xefm_ignore_continuations('c')
1047 call Xefm_ignore_continuations('l')
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001048endfunc
Bram Moolenaar9b457942016-10-09 16:10:05 +02001049
Bram Moolenaar0fcc7c62016-07-02 21:22:52 +02001050" Tests for invalid error format specifies
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001051func Xinvalid_efm_Tests(cchar)
Bram Moolenaar0fcc7c62016-07-02 21:22:52 +02001052 call s:setup_commands(a:cchar)
1053
Bram Moolenaar049cba92016-06-26 14:38:04 +02001054 let save_efm = &efm
1055
Bram Moolenaar0fcc7c62016-07-02 21:22:52 +02001056 set efm=%f:%l:%m,%f:%f:%l:%m
1057 call assert_fails('Xexpr "abc.txt:1:Hello world"', 'E372:')
1058
1059 set efm=%f:%l:%m,%f:%l:%r:%m
1060 call assert_fails('Xexpr "abc.txt:1:Hello world"', 'E373:')
1061
1062 set efm=%f:%l:%m,%O:%f:%l:%m
1063 call assert_fails('Xexpr "abc.txt:1:Hello world"', 'E373:')
1064
1065 set efm=%f:%l:%m,%f:%l:%*[^a-z
1066 call assert_fails('Xexpr "abc.txt:1:Hello world"', 'E374:')
1067
1068 set efm=%f:%l:%m,%f:%l:%*c
1069 call assert_fails('Xexpr "abc.txt:1:Hello world"', 'E375:')
1070
1071 set efm=%f:%l:%m,%L%M%N
1072 call assert_fails('Xexpr "abc.txt:1:Hello world"', 'E376:')
1073
1074 set efm=%f:%l:%m,%f:%l:%m:%R
1075 call assert_fails('Xexpr "abc.txt:1:Hello world"', 'E377:')
1076
1077 set efm=
1078 call assert_fails('Xexpr "abc.txt:1:Hello world"', 'E378:')
1079
1080 set efm=%DEntering\ dir\ abc,%f:%l:%m
1081 call assert_fails('Xexpr ["Entering dir abc", "abc.txt:1:Hello world"]', 'E379:')
1082
1083 let &efm = save_efm
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001084endfunc
Bram Moolenaar0fcc7c62016-07-02 21:22:52 +02001085
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001086func Test_invalid_efm()
Bram Moolenaar0fcc7c62016-07-02 21:22:52 +02001087 call Xinvalid_efm_Tests('c')
1088 call Xinvalid_efm_Tests('l')
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001089endfunc
Bram Moolenaar0fcc7c62016-07-02 21:22:52 +02001090
1091" TODO:
1092" Add tests for the following formats in 'errorformat'
1093" %r %O
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001094func Test_efm2()
Bram Moolenaar0fcc7c62016-07-02 21:22:52 +02001095 let save_efm = &efm
Bram Moolenaar049cba92016-06-26 14:38:04 +02001096
1097 " Test for %s format in efm
1098 set efm=%f:%s
1099 cexpr 'Xtestfile:Line search text'
Bram Moolenaar049cba92016-06-26 14:38:04 +02001100 let l = getqflist()
1101 call assert_equal(l[0].pattern, '^\VLine search text\$')
1102 call assert_equal(l[0].lnum, 0)
1103
Bram Moolenaaree85df32017-03-19 14:19:50 +01001104 let l = split(execute('clist', ''), "\n")
1105 call assert_equal([' 1 Xtestfile:^\VLine search text\$: '], l)
1106
Bram Moolenaar0fcc7c62016-07-02 21:22:52 +02001107 " Test for %P, %Q and %t format specifiers
Bram Moolenaarc79745a2019-05-20 22:12:34 +02001108 let lines =<< trim [DATA]
Bram Moolenaare7eb9272019-06-24 00:58:07 +02001109 [Xtestfile1]
1110 (1,17) error: ';' missing
1111 (21,2) warning: variable 'z' not defined
1112 (67,3) error: end of file found before string ended
1113 --
Bram Moolenaarc79745a2019-05-20 22:12:34 +02001114
Bram Moolenaare7eb9272019-06-24 00:58:07 +02001115 [Xtestfile2]
1116 --
Bram Moolenaarc79745a2019-05-20 22:12:34 +02001117
Bram Moolenaare7eb9272019-06-24 00:58:07 +02001118 [Xtestfile3]
1119 NEW compiler v1.1
1120 (2,2) warning: variable 'x' not defined
1121 (67,3) warning: 's' already defined
1122 --
Bram Moolenaarc79745a2019-05-20 22:12:34 +02001123 [DATA]
1124
Bram Moolenaaree85df32017-03-19 14:19:50 +01001125 set efm=%+P[%f]%r,(%l\\,%c)%*[\ ]%t%*[^:]:\ %m,%+Q--%r
Bram Moolenaar391b1dd2017-03-04 13:47:11 +01001126 " To exercise the push/pop file functionality in quickfix, the test files
1127 " need to be created.
1128 call writefile(['Line1'], 'Xtestfile1')
1129 call writefile(['Line2'], 'Xtestfile2')
1130 call writefile(['Line3'], 'Xtestfile3')
Bram Moolenaar361c8f02016-07-02 15:41:47 +02001131 cexpr ""
1132 for l in lines
1133 caddexpr l
1134 endfor
Bram Moolenaar049cba92016-06-26 14:38:04 +02001135 let l = getqflist()
Bram Moolenaaree85df32017-03-19 14:19:50 +01001136 call assert_equal(12, len(l))
Bram Moolenaar049cba92016-06-26 14:38:04 +02001137 call assert_equal(21, l[2].lnum)
1138 call assert_equal(2, l[2].col)
Bram Moolenaar0fcc7c62016-07-02 21:22:52 +02001139 call assert_equal('w', l[2].type)
1140 call assert_equal('e', l[3].type)
Bram Moolenaar391b1dd2017-03-04 13:47:11 +01001141 call delete('Xtestfile1')
1142 call delete('Xtestfile2')
1143 call delete('Xtestfile3')
Bram Moolenaar0fcc7c62016-07-02 21:22:52 +02001144
1145 " Tests for %E, %C and %Z format specifiers
Bram Moolenaarc79745a2019-05-20 22:12:34 +02001146 let lines =<< trim [DATA]
Bram Moolenaare7eb9272019-06-24 00:58:07 +02001147 Error 275
1148 line 42
1149 column 3
1150 ' ' expected after '--'
Bram Moolenaarc79745a2019-05-20 22:12:34 +02001151 [DATA]
1152
Bram Moolenaar0fcc7c62016-07-02 21:22:52 +02001153 set efm=%EError\ %n,%Cline\ %l,%Ccolumn\ %c,%Z%m
1154 cgetexpr lines
1155 let l = getqflist()
1156 call assert_equal(275, l[0].nr)
1157 call assert_equal(42, l[0].lnum)
1158 call assert_equal(3, l[0].col)
1159 call assert_equal('E', l[0].type)
1160 call assert_equal("\n' ' expected after '--'", l[0].text)
1161
1162 " Test for %>
Bram Moolenaarc79745a2019-05-20 22:12:34 +02001163 let lines =<< trim [DATA]
Bram Moolenaare7eb9272019-06-24 00:58:07 +02001164 Error in line 147 of foo.c:
1165 unknown variable 'i'
Bram Moolenaarc79745a2019-05-20 22:12:34 +02001166 [DATA]
1167
Bram Moolenaar0fcc7c62016-07-02 21:22:52 +02001168 set efm=unknown\ variable\ %m,%E%>Error\ in\ line\ %l\ of\ %f:,%Z%m
1169 cgetexpr lines
1170 let l = getqflist()
1171 call assert_equal(147, l[0].lnum)
1172 call assert_equal('E', l[0].type)
1173 call assert_equal("\nunknown variable 'i'", l[0].text)
Bram Moolenaar049cba92016-06-26 14:38:04 +02001174
Bram Moolenaare87e6dd2016-07-17 19:25:04 +02001175 " Test for %A, %C and other formats
Bram Moolenaarc79745a2019-05-20 22:12:34 +02001176 let lines =<< trim [DATA]
Bram Moolenaare7eb9272019-06-24 00:58:07 +02001177 ==============================================================
1178 FAIL: testGetTypeIdCachesResult (dbfacadeTest.DjsDBFacadeTest)
1179 --------------------------------------------------------------
1180 Traceback (most recent call last):
1181 File "unittests/dbfacadeTest.py", line 89, in testFoo
1182 self.assertEquals(34, dtid)
1183 File "/usr/lib/python2.2/unittest.py", line 286, in
1184 failUnlessEqual
1185 raise self.failureException, \\
1186 AssertionError: 34 != 33
1187
1188 --------------------------------------------------------------
1189 Ran 27 tests in 0.063s
Bram Moolenaarc79745a2019-05-20 22:12:34 +02001190 [DATA]
1191
Bram Moolenaare87e6dd2016-07-17 19:25:04 +02001192 set efm=%C\ %.%#,%A\ \ File\ \"%f\"\\,\ line\ %l%.%#,%Z%[%^\ ]%\\@=%m
1193 cgetexpr lines
1194 let l = getqflist()
1195 call assert_equal(8, len(l))
1196 call assert_equal(89, l[4].lnum)
1197 call assert_equal(1, l[4].valid)
1198 call assert_equal('unittests/dbfacadeTest.py', bufname(l[4].bufnr))
1199
Bram Moolenaard76ce852018-05-01 15:02:04 +02001200 " Test for %o
1201 set efm=%f(%o):%l\ %m
Bram Moolenaarbc7845d2018-05-01 16:26:48 +02001202 cgetexpr ['Xotestfile(Language.PureScript.Types):20 Error']
1203 call writefile(['Line1'], 'Xotestfile')
Bram Moolenaard76ce852018-05-01 15:02:04 +02001204 let l = getqflist()
1205 call assert_equal(1, len(l), string(l))
1206 call assert_equal('Language.PureScript.Types', l[0].module)
1207 copen
1208 call assert_equal('Language.PureScript.Types|20| Error', getline(1))
1209 call feedkeys("\<CR>", 'xn')
Bram Moolenaarbc7845d2018-05-01 16:26:48 +02001210 call assert_equal('Xotestfile', expand('%:t'))
Bram Moolenaard76ce852018-05-01 15:02:04 +02001211 cclose
1212 bd
Bram Moolenaarbc7845d2018-05-01 16:26:48 +02001213 call delete("Xotestfile")
Bram Moolenaard76ce852018-05-01 15:02:04 +02001214
Bram Moolenaar99895ea2017-04-20 22:44:47 +02001215 " The following sequence of commands used to crash Vim
1216 set efm=%W%m
1217 cgetexpr ['msg1']
1218 let l = getqflist()
1219 call assert_equal(1, len(l), string(l))
1220 call assert_equal('msg1', l[0].text)
1221 set efm=%C%m
1222 lexpr 'msg2'
1223 let l = getloclist(0)
1224 call assert_equal(1, len(l), string(l))
1225 call assert_equal('msg2', l[0].text)
1226 lopen
1227 call setqflist([], 'r')
1228 caddbuf
1229 let l = getqflist()
1230 call assert_equal(1, len(l), string(l))
1231 call assert_equal('|| msg2', l[0].text)
1232
Bram Moolenaar78ddc062018-05-15 21:56:34 +02001233 " When matching error lines, case should be ignored. Test for this.
1234 set noignorecase
1235 let l=getqflist({'lines' : ['Xtest:FOO10:Line 20'], 'efm':'%f:foo%l:%m'})
1236 call assert_equal(10, l.items[0].lnum)
1237 call assert_equal('Line 20', l.items[0].text)
1238 set ignorecase&
1239
Bram Moolenaar99895ea2017-04-20 22:44:47 +02001240 new | only
Bram Moolenaar049cba92016-06-26 14:38:04 +02001241 let &efm = save_efm
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001242endfunc
Bram Moolenaar049cba92016-06-26 14:38:04 +02001243
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001244func XquickfixChangedByAutocmd(cchar)
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001245 call s:setup_commands(a:cchar)
Bram Moolenaarffec3c52016-03-23 20:55:42 +01001246 if a:cchar == 'c'
Bram Moolenaarffec3c52016-03-23 20:55:42 +01001247 let ErrorNr = 'E925'
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001248 func! ReadFunc()
Bram Moolenaarffec3c52016-03-23 20:55:42 +01001249 colder
1250 cgetexpr []
1251 endfunc
1252 else
Bram Moolenaarffec3c52016-03-23 20:55:42 +01001253 let ErrorNr = 'E926'
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001254 func! ReadFunc()
Bram Moolenaarffec3c52016-03-23 20:55:42 +01001255 lolder
1256 lgetexpr []
1257 endfunc
1258 endif
1259
1260 augroup testgroup
1261 au!
Bram Moolenaard106e5b2016-04-21 19:38:07 +02001262 autocmd BufReadCmd test_changed.txt call ReadFunc()
Bram Moolenaarffec3c52016-03-23 20:55:42 +01001263 augroup END
1264
Bram Moolenaard106e5b2016-04-21 19:38:07 +02001265 new | only
Bram Moolenaarffec3c52016-03-23 20:55:42 +01001266 let words = [ "a", "b" ]
1267 let qflist = []
1268 for word in words
Bram Moolenaard106e5b2016-04-21 19:38:07 +02001269 call add(qflist, {'filename': 'test_changed.txt'})
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001270 call g:Xsetlist(qflist, ' ')
Bram Moolenaarffec3c52016-03-23 20:55:42 +01001271 endfor
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001272 call assert_fails('Xrewind', ErrorNr . ':')
Bram Moolenaarffec3c52016-03-23 20:55:42 +01001273
1274 augroup! testgroup
1275endfunc
1276
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001277func Test_quickfix_was_changed_by_autocmd()
Bram Moolenaarffec3c52016-03-23 20:55:42 +01001278 call XquickfixChangedByAutocmd('c')
1279 call XquickfixChangedByAutocmd('l')
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001280endfunc
Bram Moolenaar8b201792016-03-25 15:01:10 +01001281
1282func Test_caddbuffer_to_empty()
1283 helpgr quickfix
1284 call setqflist([], 'r')
1285 cad
Bram Moolenaarf68f1d72016-03-25 17:14:06 +01001286 try
1287 cn
1288 catch
1289 " number of matches is unknown
1290 call assert_true(v:exception =~ 'E553:')
1291 endtry
Bram Moolenaar8b201792016-03-25 15:01:10 +01001292 quit!
1293endfunc
Bram Moolenaar89c64d52016-03-27 18:44:40 +02001294
1295func Test_cgetexpr_works()
1296 " this must not crash Vim
1297 cgetexpr [$x]
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001298 lgetexpr [$x]
Bram Moolenaar89c64d52016-03-27 18:44:40 +02001299endfunc
Bram Moolenaarc1808d52016-04-18 20:04:00 +02001300
1301" Tests for the setqflist() and setloclist() functions
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001302func SetXlistTests(cchar, bnum)
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001303 call s:setup_commands(a:cchar)
Bram Moolenaarc1808d52016-04-18 20:04:00 +02001304
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001305 call g:Xsetlist([{'bufnr': a:bnum, 'lnum': 1},
Bram Moolenaarc1808d52016-04-18 20:04:00 +02001306 \ {'bufnr': a:bnum, 'lnum': 2}])
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001307 let l = g:Xgetlist()
Bram Moolenaarc1808d52016-04-18 20:04:00 +02001308 call assert_equal(2, len(l))
1309 call assert_equal(2, l[1].lnum)
1310
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001311 Xnext
1312 call g:Xsetlist([{'bufnr': a:bnum, 'lnum': 3}], 'a')
1313 let l = g:Xgetlist()
Bram Moolenaarc1808d52016-04-18 20:04:00 +02001314 call assert_equal(3, len(l))
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001315 Xnext
Bram Moolenaarc1808d52016-04-18 20:04:00 +02001316 call assert_equal(3, line('.'))
1317
Bram Moolenaar2b2b8ae2016-05-24 19:59:51 +02001318 " Appending entries to the list should not change the cursor position
1319 " in the quickfix window
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001320 Xwindow
Bram Moolenaar2b2b8ae2016-05-24 19:59:51 +02001321 1
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001322 call g:Xsetlist([{'bufnr': a:bnum, 'lnum': 4},
Bram Moolenaar2b2b8ae2016-05-24 19:59:51 +02001323 \ {'bufnr': a:bnum, 'lnum': 5}], 'a')
1324 call assert_equal(1, line('.'))
1325 close
1326
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001327 call g:Xsetlist([{'bufnr': a:bnum, 'lnum': 3},
Bram Moolenaarc1808d52016-04-18 20:04:00 +02001328 \ {'bufnr': a:bnum, 'lnum': 4},
1329 \ {'bufnr': a:bnum, 'lnum': 5}], 'r')
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001330 let l = g:Xgetlist()
Bram Moolenaarc1808d52016-04-18 20:04:00 +02001331 call assert_equal(3, len(l))
1332 call assert_equal(5, l[2].lnum)
1333
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001334 call g:Xsetlist([])
1335 let l = g:Xgetlist()
Bram Moolenaarc1808d52016-04-18 20:04:00 +02001336 call assert_equal(0, len(l))
Bram Moolenaaree85df32017-03-19 14:19:50 +01001337
Bram Moolenaarf1d21c82017-04-22 21:20:46 +02001338 " Tests for setting the 'valid' flag
1339 call g:Xsetlist([{'bufnr':a:bnum, 'lnum':4, 'valid':0}])
1340 Xwindow
1341 call assert_equal(1, winnr('$'))
1342 let l = g:Xgetlist()
1343 call g:Xsetlist(l)
1344 call assert_equal(0, g:Xgetlist()[0].valid)
Bram Moolenaar9752c722018-12-22 16:49:34 +01001345 " Adding a non-valid entry should not mark the list as having valid entries
1346 call g:Xsetlist([{'bufnr':a:bnum, 'lnum':5, 'valid':0}], 'a')
1347 Xwindow
1348 call assert_equal(1, winnr('$'))
1349
1350 " :cnext/:cprev should still work even with invalid entries in the list
1351 let l = [{'bufnr' : a:bnum, 'lnum' : 1, 'text' : '1', 'valid' : 0},
1352 \ {'bufnr' : a:bnum, 'lnum' : 2, 'text' : '2', 'valid' : 0}]
1353 call g:Xsetlist(l)
1354 Xnext
1355 call assert_equal(2, g:Xgetlist({'idx' : 0}).idx)
1356 Xprev
1357 call assert_equal(1, g:Xgetlist({'idx' : 0}).idx)
1358 " :cnext/:cprev should still work after appending invalid entries to an
1359 " empty list
1360 call g:Xsetlist([])
1361 call g:Xsetlist(l, 'a')
1362 Xnext
1363 call assert_equal(2, g:Xgetlist({'idx' : 0}).idx)
1364 Xprev
1365 call assert_equal(1, g:Xgetlist({'idx' : 0}).idx)
1366
Bram Moolenaarf1d21c82017-04-22 21:20:46 +02001367 call g:Xsetlist([{'text':'Text1', 'valid':1}])
1368 Xwindow
1369 call assert_equal(2, winnr('$'))
1370 Xclose
1371 let save_efm = &efm
1372 set efm=%m
1373 Xgetexpr 'TestMessage'
1374 let l = g:Xgetlist()
1375 call g:Xsetlist(l)
1376 call assert_equal(1, g:Xgetlist()[0].valid)
1377 let &efm = save_efm
1378
Bram Moolenaaree85df32017-03-19 14:19:50 +01001379 " Error cases:
1380 " Refer to a non-existing buffer and pass a non-dictionary type
1381 call assert_fails("call g:Xsetlist([{'bufnr':998, 'lnum':4}," .
1382 \ " {'bufnr':999, 'lnum':5}])", 'E92:')
1383 call g:Xsetlist([[1, 2,3]])
1384 call assert_equal(0, len(g:Xgetlist()))
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001385endfunc
Bram Moolenaarc1808d52016-04-18 20:04:00 +02001386
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001387func Test_setqflist()
Bram Moolenaarc1808d52016-04-18 20:04:00 +02001388 new Xtestfile | only
1389 let bnum = bufnr('%')
1390 call setline(1, range(1,5))
1391
1392 call SetXlistTests('c', bnum)
1393 call SetXlistTests('l', bnum)
1394
Bram Moolenaar1cee6932016-06-09 22:17:22 +02001395 enew!
Bram Moolenaarc1808d52016-04-18 20:04:00 +02001396 call delete('Xtestfile')
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001397endfunc
Bram Moolenaard106e5b2016-04-21 19:38:07 +02001398
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001399func Xlist_empty_middle(cchar)
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001400 call s:setup_commands(a:cchar)
1401
Bram Moolenaar1cee6932016-06-09 22:17:22 +02001402 " create three quickfix lists
Bram Moolenaaree85df32017-03-19 14:19:50 +01001403 let @/ = 'Test_'
1404 Xvimgrep // test_quickfix.vim
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001405 let testlen = len(g:Xgetlist())
Bram Moolenaar1cee6932016-06-09 22:17:22 +02001406 call assert_true(testlen > 0)
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001407 Xvimgrep empty test_quickfix.vim
1408 call assert_true(len(g:Xgetlist()) > 0)
1409 Xvimgrep matches test_quickfix.vim
1410 let matchlen = len(g:Xgetlist())
Bram Moolenaar1cee6932016-06-09 22:17:22 +02001411 call assert_true(matchlen > 0)
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001412 Xolder
Bram Moolenaar1cee6932016-06-09 22:17:22 +02001413 " make the middle list empty
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001414 call g:Xsetlist([], 'r')
1415 call assert_true(len(g:Xgetlist()) == 0)
1416 Xolder
1417 call assert_equal(testlen, len(g:Xgetlist()))
1418 Xnewer
1419 Xnewer
1420 call assert_equal(matchlen, len(g:Xgetlist()))
Bram Moolenaar1cee6932016-06-09 22:17:22 +02001421endfunc
1422
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001423func Test_setqflist_empty_middle()
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001424 call Xlist_empty_middle('c')
1425 call Xlist_empty_middle('l')
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001426endfunc
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001427
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001428func Xlist_empty_older(cchar)
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001429 call s:setup_commands(a:cchar)
1430
Bram Moolenaar1cee6932016-06-09 22:17:22 +02001431 " create three quickfix lists
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001432 Xvimgrep one test_quickfix.vim
1433 let onelen = len(g:Xgetlist())
Bram Moolenaar1cee6932016-06-09 22:17:22 +02001434 call assert_true(onelen > 0)
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001435 Xvimgrep two test_quickfix.vim
1436 let twolen = len(g:Xgetlist())
Bram Moolenaar1cee6932016-06-09 22:17:22 +02001437 call assert_true(twolen > 0)
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001438 Xvimgrep three test_quickfix.vim
1439 let threelen = len(g:Xgetlist())
Bram Moolenaar1cee6932016-06-09 22:17:22 +02001440 call assert_true(threelen > 0)
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001441 Xolder 2
Bram Moolenaar1cee6932016-06-09 22:17:22 +02001442 " make the first list empty, check the others didn't change
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001443 call g:Xsetlist([], 'r')
1444 call assert_true(len(g:Xgetlist()) == 0)
1445 Xnewer
1446 call assert_equal(twolen, len(g:Xgetlist()))
1447 Xnewer
1448 call assert_equal(threelen, len(g:Xgetlist()))
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001449endfunc
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001450
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001451func Test_setqflist_empty_older()
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001452 call Xlist_empty_older('c')
1453 call Xlist_empty_older('l')
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001454endfunc
Bram Moolenaar1cee6932016-06-09 22:17:22 +02001455
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001456func XquickfixSetListWithAct(cchar)
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001457 call s:setup_commands(a:cchar)
1458
Bram Moolenaard106e5b2016-04-21 19:38:07 +02001459 let list1 = [{'filename': 'fnameA', 'text': 'A'},
1460 \ {'filename': 'fnameB', 'text': 'B'}]
1461 let list2 = [{'filename': 'fnameC', 'text': 'C'},
1462 \ {'filename': 'fnameD', 'text': 'D'},
1463 \ {'filename': 'fnameE', 'text': 'E'}]
1464
Bram Moolenaareeb1b9c2019-02-10 22:59:04 +01001465 " {action} is unspecified. Same as specifying ' '.
Bram Moolenaard106e5b2016-04-21 19:38:07 +02001466 new | only
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001467 silent! Xnewer 99
1468 call g:Xsetlist(list1)
1469 call g:Xsetlist(list2)
1470 let li = g:Xgetlist()
Bram Moolenaard106e5b2016-04-21 19:38:07 +02001471 call assert_equal(3, len(li))
1472 call assert_equal('C', li[0]['text'])
1473 call assert_equal('D', li[1]['text'])
1474 call assert_equal('E', li[2]['text'])
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001475 silent! Xolder
1476 let li = g:Xgetlist()
Bram Moolenaard106e5b2016-04-21 19:38:07 +02001477 call assert_equal(2, len(li))
1478 call assert_equal('A', li[0]['text'])
1479 call assert_equal('B', li[1]['text'])
1480
1481 " {action} is specified ' '.
1482 new | only
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001483 silent! Xnewer 99
1484 call g:Xsetlist(list1)
1485 call g:Xsetlist(list2, ' ')
1486 let li = g:Xgetlist()
Bram Moolenaard106e5b2016-04-21 19:38:07 +02001487 call assert_equal(3, len(li))
1488 call assert_equal('C', li[0]['text'])
1489 call assert_equal('D', li[1]['text'])
1490 call assert_equal('E', li[2]['text'])
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001491 silent! Xolder
1492 let li = g:Xgetlist()
Bram Moolenaard106e5b2016-04-21 19:38:07 +02001493 call assert_equal(2, len(li))
1494 call assert_equal('A', li[0]['text'])
1495 call assert_equal('B', li[1]['text'])
1496
1497 " {action} is specified 'a'.
1498 new | only
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001499 silent! Xnewer 99
1500 call g:Xsetlist(list1)
1501 call g:Xsetlist(list2, 'a')
1502 let li = g:Xgetlist()
Bram Moolenaard106e5b2016-04-21 19:38:07 +02001503 call assert_equal(5, len(li))
1504 call assert_equal('A', li[0]['text'])
1505 call assert_equal('B', li[1]['text'])
1506 call assert_equal('C', li[2]['text'])
1507 call assert_equal('D', li[3]['text'])
1508 call assert_equal('E', li[4]['text'])
1509
1510 " {action} is specified 'r'.
1511 new | only
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001512 silent! Xnewer 99
1513 call g:Xsetlist(list1)
1514 call g:Xsetlist(list2, 'r')
1515 let li = g:Xgetlist()
Bram Moolenaard106e5b2016-04-21 19:38:07 +02001516 call assert_equal(3, len(li))
1517 call assert_equal('C', li[0]['text'])
1518 call assert_equal('D', li[1]['text'])
1519 call assert_equal('E', li[2]['text'])
1520
1521 " Test for wrong value.
1522 new | only
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001523 call assert_fails("call g:Xsetlist(0)", 'E714:')
1524 call assert_fails("call g:Xsetlist(list1, '')", 'E927:')
1525 call assert_fails("call g:Xsetlist(list1, 'aa')", 'E927:')
1526 call assert_fails("call g:Xsetlist(list1, ' a')", 'E927:')
1527 call assert_fails("call g:Xsetlist(list1, 0)", 'E928:')
Bram Moolenaard106e5b2016-04-21 19:38:07 +02001528endfunc
1529
Bram Moolenaara0ca7d02017-12-19 10:22:19 +01001530func Test_setqflist_invalid_nr()
1531 " The following command used to crash Vim
Bram Moolenaaraad222c2019-09-06 22:46:09 +02001532 eval []->setqflist(' ', {'nr' : $XXX_DOES_NOT_EXIST})
Bram Moolenaara0ca7d02017-12-19 10:22:19 +01001533endfunc
1534
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001535func Test_quickfix_set_list_with_act()
Bram Moolenaard106e5b2016-04-21 19:38:07 +02001536 call XquickfixSetListWithAct('c')
1537 call XquickfixSetListWithAct('l')
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001538endfunc
Bram Moolenaar6be8c8e2016-04-30 13:17:09 +02001539
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001540func XLongLinesTests(cchar)
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001541 let l = g:Xgetlist()
Bram Moolenaar6be8c8e2016-04-30 13:17:09 +02001542
Bram Moolenaar049cba92016-06-26 14:38:04 +02001543 call assert_equal(4, len(l))
Bram Moolenaar6be8c8e2016-04-30 13:17:09 +02001544 call assert_equal(1, l[0].lnum)
1545 call assert_equal(1, l[0].col)
Bram Moolenaar049cba92016-06-26 14:38:04 +02001546 call assert_equal(1975, len(l[0].text))
Bram Moolenaar6be8c8e2016-04-30 13:17:09 +02001547 call assert_equal(2, l[1].lnum)
1548 call assert_equal(1, l[1].col)
1549 call assert_equal(4070, len(l[1].text))
1550 call assert_equal(3, l[2].lnum)
1551 call assert_equal(1, l[2].col)
Bram Moolenaar049cba92016-06-26 14:38:04 +02001552 call assert_equal(4070, len(l[2].text))
1553 call assert_equal(4, l[3].lnum)
1554 call assert_equal(1, l[3].col)
1555 call assert_equal(10, len(l[3].text))
Bram Moolenaar6be8c8e2016-04-30 13:17:09 +02001556
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001557 call g:Xsetlist([], 'r')
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001558endfunc
Bram Moolenaar6be8c8e2016-04-30 13:17:09 +02001559
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001560func s:long_lines_tests(cchar)
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001561 call s:setup_commands(a:cchar)
1562
Bram Moolenaar6be8c8e2016-04-30 13:17:09 +02001563 let testfile = 'samples/quickfix.txt'
1564
1565 " file
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001566 exe 'Xgetfile' testfile
1567 call XLongLinesTests(a:cchar)
Bram Moolenaar6be8c8e2016-04-30 13:17:09 +02001568
1569 " list
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001570 Xexpr readfile(testfile)
1571 call XLongLinesTests(a:cchar)
Bram Moolenaar6be8c8e2016-04-30 13:17:09 +02001572
1573 " string
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001574 Xexpr join(readfile(testfile), "\n")
1575 call XLongLinesTests(a:cchar)
Bram Moolenaar6be8c8e2016-04-30 13:17:09 +02001576
1577 " buffer
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001578 exe 'edit' testfile
1579 exe 'Xbuffer' bufnr('%')
Bram Moolenaarf50df392016-06-21 21:33:34 +02001580 call XLongLinesTests(a:cchar)
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001581endfunc
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001582
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001583func Test_long_lines()
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001584 call s:long_lines_tests('c')
1585 call s:long_lines_tests('l')
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001586endfunc
Bram Moolenaar049cba92016-06-26 14:38:04 +02001587
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001588func s:create_test_file(filename)
Bram Moolenaar049cba92016-06-26 14:38:04 +02001589 let l = []
1590 for i in range(1, 20)
1591 call add(l, 'Line' . i)
1592 endfor
1593 call writefile(l, a:filename)
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001594endfunc
Bram Moolenaar049cba92016-06-26 14:38:04 +02001595
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001596func Test_switchbuf()
Bram Moolenaar049cba92016-06-26 14:38:04 +02001597 call s:create_test_file('Xqftestfile1')
1598 call s:create_test_file('Xqftestfile2')
1599 call s:create_test_file('Xqftestfile3')
1600
1601 new | only
1602 edit Xqftestfile1
1603 let file1_winid = win_getid()
1604 new Xqftestfile2
1605 let file2_winid = win_getid()
1606 cgetexpr ['Xqftestfile1:5:Line5',
1607 \ 'Xqftestfile1:6:Line6',
1608 \ 'Xqftestfile2:10:Line10',
1609 \ 'Xqftestfile2:11:Line11',
1610 \ 'Xqftestfile3:15:Line15',
1611 \ 'Xqftestfile3:16:Line16']
1612
1613 new
1614 let winid = win_getid()
1615 cfirst | cnext
1616 call assert_equal(winid, win_getid())
Bram Moolenaar99895ea2017-04-20 22:44:47 +02001617 2cnext
Bram Moolenaar049cba92016-06-26 14:38:04 +02001618 call assert_equal(winid, win_getid())
Bram Moolenaar99895ea2017-04-20 22:44:47 +02001619 2cnext
Bram Moolenaar049cba92016-06-26 14:38:04 +02001620 call assert_equal(winid, win_getid())
1621 enew
1622
1623 set switchbuf=useopen
1624 cfirst | cnext
1625 call assert_equal(file1_winid, win_getid())
Bram Moolenaar99895ea2017-04-20 22:44:47 +02001626 2cnext
Bram Moolenaar049cba92016-06-26 14:38:04 +02001627 call assert_equal(file2_winid, win_getid())
Bram Moolenaar99895ea2017-04-20 22:44:47 +02001628 2cnext
Bram Moolenaar049cba92016-06-26 14:38:04 +02001629 call assert_equal(file2_winid, win_getid())
1630
1631 enew | only
1632 set switchbuf=usetab
1633 tabedit Xqftestfile1
1634 tabedit Xqftestfile2
Bram Moolenaar74240d32017-12-10 15:26:15 +01001635 tabedit Xqftestfile3
Bram Moolenaar049cba92016-06-26 14:38:04 +02001636 tabfirst
1637 cfirst | cnext
1638 call assert_equal(2, tabpagenr())
Bram Moolenaar99895ea2017-04-20 22:44:47 +02001639 2cnext
Bram Moolenaar049cba92016-06-26 14:38:04 +02001640 call assert_equal(3, tabpagenr())
Bram Moolenaar74240d32017-12-10 15:26:15 +01001641 6cnext
1642 call assert_equal(4, tabpagenr())
1643 2cpfile
1644 call assert_equal(2, tabpagenr())
1645 2cnfile
1646 call assert_equal(4, tabpagenr())
Bram Moolenaar049cba92016-06-26 14:38:04 +02001647 tabfirst | tabonly | enew
1648
1649 set switchbuf=split
1650 cfirst | cnext
1651 call assert_equal(1, winnr('$'))
1652 cnext | cnext
1653 call assert_equal(2, winnr('$'))
1654 cnext | cnext
1655 call assert_equal(3, winnr('$'))
1656 enew | only
1657
1658 set switchbuf=newtab
1659 cfirst | cnext
1660 call assert_equal(1, tabpagenr('$'))
1661 cnext | cnext
1662 call assert_equal(2, tabpagenr('$'))
1663 cnext | cnext
1664 call assert_equal(3, tabpagenr('$'))
1665 tabfirst | enew | tabonly | only
1666
1667 set switchbuf=
1668 edit Xqftestfile1
1669 let file1_winid = win_getid()
1670 new Xqftestfile2
1671 let file2_winid = win_getid()
1672 copen
1673 exe "normal 1G\<CR>"
1674 call assert_equal(file1_winid, win_getid())
1675 copen
1676 exe "normal 3G\<CR>"
1677 call assert_equal(file2_winid, win_getid())
1678 copen | only
1679 exe "normal 5G\<CR>"
1680 call assert_equal(2, winnr('$'))
1681 call assert_equal(1, bufwinnr('Xqftestfile3'))
1682
Bram Moolenaar391b1dd2017-03-04 13:47:11 +01001683 " If only quickfix window is open in the current tabpage, jumping to an
Bram Moolenaar1bc353b2019-09-01 14:45:28 +02001684 " entry with 'switchbuf' set to 'usetab' should search in other tabpages.
Bram Moolenaar049cba92016-06-26 14:38:04 +02001685 enew | only
Bram Moolenaar391b1dd2017-03-04 13:47:11 +01001686 set switchbuf=usetab
1687 tabedit Xqftestfile1
1688 tabedit Xqftestfile2
1689 tabedit Xqftestfile3
1690 tabfirst
1691 copen | only
1692 clast
1693 call assert_equal(4, tabpagenr())
1694 tabfirst | tabonly | enew | only
Bram Moolenaar049cba92016-06-26 14:38:04 +02001695
1696 call delete('Xqftestfile1')
1697 call delete('Xqftestfile2')
1698 call delete('Xqftestfile3')
Bram Moolenaar391b1dd2017-03-04 13:47:11 +01001699 set switchbuf&vim
1700
1701 enew | only
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001702endfunc
Bram Moolenaar049cba92016-06-26 14:38:04 +02001703
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001704func Xadjust_qflnum(cchar)
Bram Moolenaar049cba92016-06-26 14:38:04 +02001705 call s:setup_commands(a:cchar)
1706
1707 enew | only
1708
Bram Moolenaarc1542742016-07-20 21:44:37 +02001709 let fname = 'Xqftestfile' . a:cchar
1710 call s:create_test_file(fname)
1711 exe 'edit ' . fname
Bram Moolenaar049cba92016-06-26 14:38:04 +02001712
Bram Moolenaarc1542742016-07-20 21:44:37 +02001713 Xgetexpr [fname . ':5:Line5',
1714 \ fname . ':10:Line10',
1715 \ fname . ':15:Line15',
1716 \ fname . ':20:Line20']
Bram Moolenaar049cba92016-06-26 14:38:04 +02001717
1718 6,14delete
1719 call append(6, ['Buffer', 'Window'])
1720
1721 let l = g:Xgetlist()
1722
1723 call assert_equal(5, l[0].lnum)
1724 call assert_equal(6, l[2].lnum)
1725 call assert_equal(13, l[3].lnum)
1726
1727 enew!
Bram Moolenaarc1542742016-07-20 21:44:37 +02001728 call delete(fname)
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001729endfunc
Bram Moolenaar049cba92016-06-26 14:38:04 +02001730
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001731func Test_adjust_lnum()
Bram Moolenaarc1542742016-07-20 21:44:37 +02001732 call setloclist(0, [])
Bram Moolenaar049cba92016-06-26 14:38:04 +02001733 call Xadjust_qflnum('c')
Bram Moolenaarc1542742016-07-20 21:44:37 +02001734 call setqflist([])
Bram Moolenaar049cba92016-06-26 14:38:04 +02001735 call Xadjust_qflnum('l')
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001736endfunc
Bram Moolenaar049cba92016-06-26 14:38:04 +02001737
1738" Tests for the :grep/:lgrep and :grepadd/:lgrepadd commands
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001739func s:test_xgrep(cchar)
Bram Moolenaar049cba92016-06-26 14:38:04 +02001740 call s:setup_commands(a:cchar)
1741
1742 " The following lines are used for the grep test. Don't remove.
1743 " Grep_Test_Text: Match 1
1744 " Grep_Test_Text: Match 2
1745 " GrepAdd_Test_Text: Match 1
1746 " GrepAdd_Test_Text: Match 2
1747 enew! | only
1748 set makeef&vim
1749 silent Xgrep Grep_Test_Text: test_quickfix.vim
1750 call assert_true(len(g:Xgetlist()) == 3)
1751 Xopen
1752 call assert_true(w:quickfix_title =~ '^:grep')
1753 Xclose
1754 enew
1755 set makeef=Temp_File_##
1756 silent Xgrepadd GrepAdd_Test_Text: test_quickfix.vim
1757 call assert_true(len(g:Xgetlist()) == 6)
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001758endfunc
Bram Moolenaar049cba92016-06-26 14:38:04 +02001759
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001760func Test_grep()
Bram Moolenaar049cba92016-06-26 14:38:04 +02001761 if !has('unix')
1762 " The grepprg may not be set on non-Unix systems
1763 return
1764 endif
1765
1766 call s:test_xgrep('c')
1767 call s:test_xgrep('l')
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001768endfunc
Bram Moolenaar361c8f02016-07-02 15:41:47 +02001769
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001770func Test_two_windows()
Bram Moolenaar361c8f02016-07-02 15:41:47 +02001771 " Use one 'errorformat' for two windows. Add an expression to each of them,
1772 " make sure they each keep their own state.
1773 set efm=%DEntering\ dir\ '%f',%f:%l:%m,%XLeaving\ dir\ '%f'
1774 call mkdir('Xone/a', 'p')
1775 call mkdir('Xtwo/a', 'p')
1776 let lines = ['1', '2', 'one one one', '4', 'two two two', '6', '7']
1777 call writefile(lines, 'Xone/a/one.txt')
1778 call writefile(lines, 'Xtwo/a/two.txt')
1779
1780 new one
1781 let one_id = win_getid()
1782 lexpr ""
1783 new two
1784 let two_id = win_getid()
1785 lexpr ""
1786
1787 laddexpr "Entering dir 'Xtwo/a'"
1788 call win_gotoid(one_id)
1789 laddexpr "Entering dir 'Xone/a'"
1790 call win_gotoid(two_id)
1791 laddexpr 'two.txt:5:two two two'
1792 call win_gotoid(one_id)
1793 laddexpr 'one.txt:3:one one one'
1794
1795 let loc_one = getloclist(one_id)
Bram Moolenaar361c8f02016-07-02 15:41:47 +02001796 call assert_equal('Xone/a/one.txt', bufname(loc_one[1].bufnr))
1797 call assert_equal(3, loc_one[1].lnum)
1798
1799 let loc_two = getloclist(two_id)
Bram Moolenaar361c8f02016-07-02 15:41:47 +02001800 call assert_equal('Xtwo/a/two.txt', bufname(loc_two[1].bufnr))
1801 call assert_equal(5, loc_two[1].lnum)
1802
1803 call win_gotoid(one_id)
1804 bwipe!
1805 call win_gotoid(two_id)
1806 bwipe!
1807 call delete('Xone', 'rf')
1808 call delete('Xtwo', 'rf')
1809endfunc
Bram Moolenaardcb17002016-07-07 18:58:59 +02001810
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001811func XbottomTests(cchar)
Bram Moolenaar537ef082016-07-09 17:56:19 +02001812 call s:setup_commands(a:cchar)
1813
Bram Moolenaarb6fa30c2017-03-29 14:19:25 +02001814 " Calling lbottom without any errors should fail
1815 if a:cchar == 'l'
1816 call assert_fails('lbottom', 'E776:')
1817 endif
1818
Bram Moolenaar875feea2017-06-11 16:07:51 +02001819 call g:Xsetlist([{'filename': 'foo', 'lnum': 42}])
Bram Moolenaar537ef082016-07-09 17:56:19 +02001820 Xopen
Bram Moolenaardcb17002016-07-07 18:58:59 +02001821 let wid = win_getid()
1822 call assert_equal(1, line('.'))
1823 wincmd w
Bram Moolenaar875feea2017-06-11 16:07:51 +02001824 call g:Xsetlist([{'filename': 'var', 'lnum': 24}], 'a')
Bram Moolenaar537ef082016-07-09 17:56:19 +02001825 Xbottom
Bram Moolenaardcb17002016-07-07 18:58:59 +02001826 call win_gotoid(wid)
1827 call assert_equal(2, line('.'))
Bram Moolenaar537ef082016-07-09 17:56:19 +02001828 Xclose
Bram Moolenaardcb17002016-07-07 18:58:59 +02001829endfunc
Bram Moolenaar537ef082016-07-09 17:56:19 +02001830
1831" Tests for the :cbottom and :lbottom commands
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001832func Test_cbottom()
Bram Moolenaar537ef082016-07-09 17:56:19 +02001833 call XbottomTests('c')
1834 call XbottomTests('l')
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001835endfunc
Bram Moolenaarf6acffb2016-07-16 16:54:24 +02001836
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001837func HistoryTest(cchar)
Bram Moolenaarf6acffb2016-07-16 16:54:24 +02001838 call s:setup_commands(a:cchar)
1839
Bram Moolenaarf6acffb2016-07-16 16:54:24 +02001840 " clear all lists after the first one, then replace the first one.
1841 call g:Xsetlist([])
Bram Moolenaarb6fa30c2017-03-29 14:19:25 +02001842 call assert_fails('Xolder 99', 'E380:')
Bram Moolenaarf6acffb2016-07-16 16:54:24 +02001843 let entry = {'filename': 'foo', 'lnum': 42}
1844 call g:Xsetlist([entry], 'r')
1845 call g:Xsetlist([entry, entry])
1846 call g:Xsetlist([entry, entry, entry])
1847 let res = split(execute(a:cchar . 'hist'), "\n")
1848 call assert_equal(3, len(res))
1849 let common = 'errors :set' . (a:cchar == 'c' ? 'qf' : 'loc') . 'list()'
1850 call assert_equal(' error list 1 of 3; 1 ' . common, res[0])
1851 call assert_equal(' error list 2 of 3; 2 ' . common, res[1])
1852 call assert_equal('> error list 3 of 3; 3 ' . common, res[2])
Bram Moolenaarb4d5fba2017-09-11 19:31:28 +02001853
Bram Moolenaar8ffc7c82019-05-05 21:00:26 +02001854 " Test for changing the quickfix lists
1855 call assert_equal(3, g:Xgetlist({'nr' : 0}).nr)
1856 exe '1' . a:cchar . 'hist'
1857 call assert_equal(1, g:Xgetlist({'nr' : 0}).nr)
1858 exe '3' . a:cchar . 'hist'
1859 call assert_equal(3, g:Xgetlist({'nr' : 0}).nr)
1860 call assert_fails('-2' . a:cchar . 'hist', 'E16:')
1861 call assert_fails('4' . a:cchar . 'hist', 'E16:')
1862
Bram Moolenaarb4d5fba2017-09-11 19:31:28 +02001863 call g:Xsetlist([], 'f')
1864 let l = split(execute(a:cchar . 'hist'), "\n")
1865 call assert_equal('No entries', l[0])
Bram Moolenaar8ffc7c82019-05-05 21:00:26 +02001866 if a:cchar == 'c'
1867 call assert_fails('4chist', 'E16:')
1868 else
1869 call assert_fails('4lhist', 'E776:')
1870 endif
Bram Moolenaar5b69c222019-01-11 14:50:06 +01001871
1872 " An empty list should still show the stack history
1873 call g:Xsetlist([])
1874 let res = split(execute(a:cchar . 'hist'), "\n")
1875 call assert_equal('> error list 1 of 1; 0 ' . common, res[0])
1876
1877 call g:Xsetlist([], 'f')
Bram Moolenaarf6acffb2016-07-16 16:54:24 +02001878endfunc
1879
1880func Test_history()
1881 call HistoryTest('c')
1882 call HistoryTest('l')
1883endfunc
Bram Moolenaar015102e2016-07-16 18:24:56 +02001884
1885func Test_duplicate_buf()
1886 " make sure we can get the highest buffer number
1887 edit DoesNotExist
1888 edit DoesNotExist2
1889 let last_buffer = bufnr("$")
1890
1891 " make sure only one buffer is created
1892 call writefile(['this one', 'that one'], 'Xgrepthis')
1893 vimgrep one Xgrepthis
1894 vimgrep one Xgrepthis
1895 call assert_equal(last_buffer + 1, bufnr("$"))
1896
1897 call delete('Xgrepthis')
1898endfunc
Bram Moolenaard823fa92016-08-12 16:29:27 +02001899
1900" Quickfix/Location list set/get properties tests
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001901func Xproperty_tests(cchar)
Bram Moolenaard823fa92016-08-12 16:29:27 +02001902 call s:setup_commands(a:cchar)
1903
1904 " Error cases
1905 call assert_fails('call g:Xgetlist(99)', 'E715:')
1906 call assert_fails('call g:Xsetlist(99)', 'E714:')
1907 call assert_fails('call g:Xsetlist([], "a", [])', 'E715:')
1908
1909 " Set and get the title
Bram Moolenaarb6fa30c2017-03-29 14:19:25 +02001910 call g:Xsetlist([])
Bram Moolenaard823fa92016-08-12 16:29:27 +02001911 Xopen
1912 wincmd p
1913 call g:Xsetlist([{'filename':'foo', 'lnum':27}])
Bram Moolenaar86f100dc2017-06-28 21:26:27 +02001914 let s = g:Xsetlist([], 'a', {'title' : 'Sample'})
1915 call assert_equal(0, s)
Bram Moolenaard823fa92016-08-12 16:29:27 +02001916 let d = g:Xgetlist({"title":1})
1917 call assert_equal('Sample', d.title)
Bram Moolenaara2aa8a22018-04-24 13:55:00 +02001918 " Try setting title to a non-string value
1919 call assert_equal(-1, g:Xsetlist([], 'a', {'title' : ['Test']}))
1920 call assert_equal('Sample', g:Xgetlist({"title":1}).title)
Bram Moolenaard823fa92016-08-12 16:29:27 +02001921
1922 Xopen
1923 call assert_equal('Sample', w:quickfix_title)
1924 Xclose
1925
Bram Moolenaar2b529bb2016-08-27 13:35:35 +02001926 " Tests for action argument
1927 silent! Xolder 999
1928 let qfnr = g:Xgetlist({'all':1}).nr
1929 call g:Xsetlist([], 'r', {'title' : 'N1'})
1930 call assert_equal('N1', g:Xgetlist({'all':1}).title)
1931 call g:Xsetlist([], ' ', {'title' : 'N2'})
1932 call assert_equal(qfnr + 1, g:Xgetlist({'all':1}).nr)
Bram Moolenaar890680c2016-09-27 21:28:56 +02001933
1934 let res = g:Xgetlist({'nr': 0})
1935 call assert_equal(qfnr + 1, res.nr)
1936 call assert_equal(['nr'], keys(res))
1937
Bram Moolenaar2b529bb2016-08-27 13:35:35 +02001938 call g:Xsetlist([], ' ', {'title' : 'N3'})
1939 call assert_equal('N2', g:Xgetlist({'nr':2, 'title':1}).title)
1940
Bram Moolenaaree85df32017-03-19 14:19:50 +01001941 " Changing the title of an earlier quickfix list
Bram Moolenaar55b69262017-08-13 13:42:01 +02001942 call g:Xsetlist([], 'r', {'title' : 'NewTitle', 'nr' : 2})
Bram Moolenaaree85df32017-03-19 14:19:50 +01001943 call assert_equal('NewTitle', g:Xgetlist({'nr':2, 'title':1}).title)
1944
1945 " Changing the title of an invalid quickfix list
1946 call assert_equal(-1, g:Xsetlist([], ' ',
1947 \ {'title' : 'SomeTitle', 'nr' : 99}))
1948 call assert_equal(-1, g:Xsetlist([], ' ',
1949 \ {'title' : 'SomeTitle', 'nr' : 'abc'}))
1950
1951 if a:cchar == 'c'
1952 copen
1953 call assert_equal({'winid':win_getid()}, getqflist({'winid':1}))
1954 cclose
1955 endif
1956
Bram Moolenaard823fa92016-08-12 16:29:27 +02001957 " Invalid arguments
1958 call assert_fails('call g:Xgetlist([])', 'E715')
1959 call assert_fails('call g:Xsetlist([], "a", [])', 'E715')
1960 let s = g:Xsetlist([], 'a', {'abc':1})
1961 call assert_equal(-1, s)
1962
1963 call assert_equal({}, g:Xgetlist({'abc':1}))
Bram Moolenaara6d48492017-12-12 22:45:31 +01001964 call assert_equal('', g:Xgetlist({'nr':99, 'title':1}).title)
1965 call assert_equal('', g:Xgetlist({'nr':[], 'title':1}).title)
Bram Moolenaard823fa92016-08-12 16:29:27 +02001966
1967 if a:cchar == 'l'
Bram Moolenaar890680c2016-09-27 21:28:56 +02001968 call assert_equal({}, getloclist(99, {'title': 1}))
Bram Moolenaard823fa92016-08-12 16:29:27 +02001969 endif
Bram Moolenaar8f77c5a2017-04-30 14:21:00 +02001970
1971 " Context related tests
Bram Moolenaar86f100dc2017-06-28 21:26:27 +02001972 let s = g:Xsetlist([], 'a', {'context':[1,2,3]})
1973 call assert_equal(0, s)
Bram Moolenaar8f77c5a2017-04-30 14:21:00 +02001974 call test_garbagecollect_now()
1975 let d = g:Xgetlist({'context':1})
1976 call assert_equal([1,2,3], d.context)
1977 call g:Xsetlist([], 'a', {'context':{'color':'green'}})
1978 let d = g:Xgetlist({'context':1})
1979 call assert_equal({'color':'green'}, d.context)
1980 call g:Xsetlist([], 'a', {'context':"Context info"})
1981 let d = g:Xgetlist({'context':1})
1982 call assert_equal("Context info", d.context)
1983 call g:Xsetlist([], 'a', {'context':246})
1984 let d = g:Xgetlist({'context':1})
1985 call assert_equal(246, d.context)
1986 if a:cchar == 'l'
1987 " Test for copying context across two different location lists
1988 new | only
1989 let w1_id = win_getid()
1990 let l = [1]
1991 call setloclist(0, [], 'a', {'context':l})
1992 new
1993 let w2_id = win_getid()
1994 call add(l, 2)
1995 call assert_equal([1, 2], getloclist(w1_id, {'context':1}).context)
1996 call assert_equal([1, 2], getloclist(w2_id, {'context':1}).context)
1997 unlet! l
1998 call assert_equal([1, 2], getloclist(w2_id, {'context':1}).context)
1999 only
2000 call setloclist(0, [], 'f')
Bram Moolenaara6d48492017-12-12 22:45:31 +01002001 call assert_equal('', getloclist(0, {'context':1}).context)
Bram Moolenaar8f77c5a2017-04-30 14:21:00 +02002002 endif
Bram Moolenaar6e62da32017-05-28 08:16:25 +02002003
2004 " Test for changing the context of previous quickfix lists
2005 call g:Xsetlist([], 'f')
2006 Xexpr "One"
2007 Xexpr "Two"
2008 Xexpr "Three"
Bram Moolenaar55b69262017-08-13 13:42:01 +02002009 call g:Xsetlist([], 'r', {'context' : [1], 'nr' : 1})
2010 call g:Xsetlist([], 'a', {'context' : [2], 'nr' : 2})
Bram Moolenaar6e62da32017-05-28 08:16:25 +02002011 " Also, check for setting the context using quickfix list number zero.
Bram Moolenaar55b69262017-08-13 13:42:01 +02002012 call g:Xsetlist([], 'r', {'context' : [3], 'nr' : 0})
Bram Moolenaar6e62da32017-05-28 08:16:25 +02002013 call test_garbagecollect_now()
2014 let l = g:Xgetlist({'nr' : 1, 'context' : 1})
2015 call assert_equal([1], l.context)
2016 let l = g:Xgetlist({'nr' : 2, 'context' : 1})
2017 call assert_equal([2], l.context)
2018 let l = g:Xgetlist({'nr' : 3, 'context' : 1})
2019 call assert_equal([3], l.context)
2020
2021 " Test for changing the context through reference and for garbage
2022 " collection of quickfix context
2023 let l = ["red"]
2024 call g:Xsetlist([], ' ', {'context' : l})
2025 call add(l, "blue")
2026 let x = g:Xgetlist({'context' : 1})
2027 call add(x.context, "green")
2028 call assert_equal(["red", "blue", "green"], l)
2029 call assert_equal(["red", "blue", "green"], x.context)
2030 unlet l
2031 call test_garbagecollect_now()
2032 let m = g:Xgetlist({'context' : 1})
2033 call assert_equal(["red", "blue", "green"], m.context)
Bram Moolenaar6a8958d2017-06-22 21:33:20 +02002034
2035 " Test for setting/getting items
2036 Xexpr ""
2037 let qfprev = g:Xgetlist({'nr':0})
Bram Moolenaar86f100dc2017-06-28 21:26:27 +02002038 let s = g:Xsetlist([], ' ', {'title':'Green',
Bram Moolenaar6a8958d2017-06-22 21:33:20 +02002039 \ 'items' : [{'filename':'F1', 'lnum':10}]})
Bram Moolenaar86f100dc2017-06-28 21:26:27 +02002040 call assert_equal(0, s)
Bram Moolenaar6a8958d2017-06-22 21:33:20 +02002041 let qfcur = g:Xgetlist({'nr':0})
2042 call assert_true(qfcur.nr == qfprev.nr + 1)
2043 let l = g:Xgetlist({'items':1})
2044 call assert_equal('F1', bufname(l.items[0].bufnr))
2045 call assert_equal(10, l.items[0].lnum)
2046 call g:Xsetlist([], 'a', {'items' : [{'filename':'F2', 'lnum':20},
2047 \ {'filename':'F2', 'lnum':30}]})
2048 let l = g:Xgetlist({'items':1})
2049 call assert_equal('F2', bufname(l.items[2].bufnr))
2050 call assert_equal(30, l.items[2].lnum)
2051 call g:Xsetlist([], 'r', {'items' : [{'filename':'F3', 'lnum':40}]})
2052 let l = g:Xgetlist({'items':1})
2053 call assert_equal('F3', bufname(l.items[0].bufnr))
2054 call assert_equal(40, l.items[0].lnum)
2055 call g:Xsetlist([], 'r', {'items' : []})
2056 let l = g:Xgetlist({'items':1})
2057 call assert_equal(0, len(l.items))
2058
Bram Moolenaarb4d5fba2017-09-11 19:31:28 +02002059 call g:Xsetlist([], 'r', {'title' : 'TestTitle'})
2060 call g:Xsetlist([], 'r', {'items' : [{'filename' : 'F1', 'lnum' : 10, 'text' : 'L10'}]})
2061 call g:Xsetlist([], 'r', {'items' : [{'filename' : 'F1', 'lnum' : 10, 'text' : 'L10'}]})
2062 call assert_equal('TestTitle', g:Xgetlist({'title' : 1}).title)
2063
Bram Moolenaarc9cc9c72018-09-02 15:18:42 +02002064 " Test for getting id of window associated with a location list window
2065 if a:cchar == 'l'
2066 only
2067 call assert_equal(0, g:Xgetlist({'all' : 1}).filewinid)
2068 let wid = win_getid()
2069 Xopen
2070 call assert_equal(wid, g:Xgetlist({'filewinid' : 1}).filewinid)
2071 wincmd w
2072 call assert_equal(0, g:Xgetlist({'filewinid' : 1}).filewinid)
2073 only
2074 endif
2075
Bram Moolenaarae338332017-08-11 20:25:26 +02002076 " The following used to crash Vim with address sanitizer
2077 call g:Xsetlist([], 'f')
2078 call g:Xsetlist([], 'a', {'items' : [{'filename':'F1', 'lnum':10}]})
2079 call assert_equal(10, g:Xgetlist({'items':1}).items[0].lnum)
2080
Bram Moolenaara2aa8a22018-04-24 13:55:00 +02002081 " Try setting the items using a string
2082 call assert_equal(-1, g:Xsetlist([], ' ', {'items' : 'Test'}))
2083
Bram Moolenaar6a8958d2017-06-22 21:33:20 +02002084 " Save and restore the quickfix stack
2085 call g:Xsetlist([], 'f')
2086 call assert_equal(0, g:Xgetlist({'nr':'$'}).nr)
2087 Xexpr "File1:10:Line1"
2088 Xexpr "File2:20:Line2"
2089 Xexpr "File3:30:Line3"
2090 let last_qf = g:Xgetlist({'nr':'$'}).nr
2091 call assert_equal(3, last_qf)
2092 let qstack = []
2093 for i in range(1, last_qf)
2094 let qstack = add(qstack, g:Xgetlist({'nr':i, 'all':1}))
2095 endfor
2096 call g:Xsetlist([], 'f')
2097 for i in range(len(qstack))
2098 call g:Xsetlist([], ' ', qstack[i])
2099 endfor
2100 call assert_equal(3, g:Xgetlist({'nr':'$'}).nr)
2101 call assert_equal(10, g:Xgetlist({'nr':1, 'items':1}).items[0].lnum)
2102 call assert_equal(20, g:Xgetlist({'nr':2, 'items':1}).items[0].lnum)
2103 call assert_equal(30, g:Xgetlist({'nr':3, 'items':1}).items[0].lnum)
2104 call g:Xsetlist([], 'f')
2105
2106 " Swap two quickfix lists
2107 Xexpr "File1:10:Line10"
2108 Xexpr "File2:20:Line20"
2109 Xexpr "File3:30:Line30"
2110 call g:Xsetlist([], 'r', {'nr':1,'title':'Colors','context':['Colors']})
2111 call g:Xsetlist([], 'r', {'nr':2,'title':'Fruits','context':['Fruits']})
2112 let l1=g:Xgetlist({'nr':1,'all':1})
2113 let l2=g:Xgetlist({'nr':2,'all':1})
Bram Moolenaara539f4f2017-08-30 20:33:55 +02002114 let save_id = l1.id
2115 let l1.id=l2.id
2116 let l2.id=save_id
Bram Moolenaar6a8958d2017-06-22 21:33:20 +02002117 call g:Xsetlist([], 'r', l1)
2118 call g:Xsetlist([], 'r', l2)
2119 let newl1=g:Xgetlist({'nr':1,'all':1})
2120 let newl2=g:Xgetlist({'nr':2,'all':1})
Bram Moolenaarb4d5fba2017-09-11 19:31:28 +02002121 call assert_equal('Fruits', newl1.title)
Bram Moolenaar6a8958d2017-06-22 21:33:20 +02002122 call assert_equal(['Fruits'], newl1.context)
2123 call assert_equal('Line20', newl1.items[0].text)
Bram Moolenaarb4d5fba2017-09-11 19:31:28 +02002124 call assert_equal('Colors', newl2.title)
Bram Moolenaar6a8958d2017-06-22 21:33:20 +02002125 call assert_equal(['Colors'], newl2.context)
2126 call assert_equal('Line10', newl2.items[0].text)
2127 call g:Xsetlist([], 'f')
Bram Moolenaaree85df32017-03-19 14:19:50 +01002128endfunc
Bram Moolenaard823fa92016-08-12 16:29:27 +02002129
Bram Moolenaar2b946c92016-11-12 18:14:44 +01002130func Test_qf_property()
Bram Moolenaard823fa92016-08-12 16:29:27 +02002131 call Xproperty_tests('c')
2132 call Xproperty_tests('l')
Bram Moolenaaree85df32017-03-19 14:19:50 +01002133endfunc
Bram Moolenaar04c4ce62016-09-01 15:45:58 +02002134
Bram Moolenaar5b69c222019-01-11 14:50:06 +01002135" Test for setting the current index in the location/quickfix list
2136func Xtest_setqfidx(cchar)
2137 call s:setup_commands(a:cchar)
2138
2139 Xgetexpr "F1:10:1:Line1\nF2:20:2:Line2\nF3:30:3:Line3"
2140 Xgetexpr "F4:10:1:Line1\nF5:20:2:Line2\nF6:30:3:Line3"
2141 Xgetexpr "F7:10:1:Line1\nF8:20:2:Line2\nF9:30:3:Line3"
2142
2143 call g:Xsetlist([], 'a', {'nr' : 3, 'idx' : 2})
2144 call g:Xsetlist([], 'a', {'nr' : 2, 'idx' : 2})
2145 call g:Xsetlist([], 'a', {'nr' : 1, 'idx' : 3})
2146 Xolder 2
2147 Xopen
2148 call assert_equal(3, line('.'))
2149 Xnewer
2150 call assert_equal(2, line('.'))
2151 Xnewer
2152 call assert_equal(2, line('.'))
2153 " Update the current index with the quickfix window open
2154 wincmd w
2155 call g:Xsetlist([], 'a', {'nr' : 3, 'idx' : 3})
2156 Xopen
2157 call assert_equal(3, line('.'))
2158 Xclose
2159
2160 " Set the current index to the last entry
2161 call g:Xsetlist([], 'a', {'nr' : 1, 'idx' : '$'})
2162 call assert_equal(3, g:Xgetlist({'nr' : 1, 'idx' : 0}).idx)
2163 " A large value should set the index to the last index
2164 call g:Xsetlist([], 'a', {'nr' : 1, 'idx' : 1})
2165 call g:Xsetlist([], 'a', {'nr' : 1, 'idx' : 999})
2166 call assert_equal(3, g:Xgetlist({'nr' : 1, 'idx' : 0}).idx)
2167 " Invalid index values
2168 call g:Xsetlist([], 'a', {'nr' : 1, 'idx' : -1})
2169 call assert_equal(3, g:Xgetlist({'nr' : 1, 'idx' : 0}).idx)
2170 call g:Xsetlist([], 'a', {'nr' : 1, 'idx' : 0})
2171 call assert_equal(3, g:Xgetlist({'nr' : 1, 'idx' : 0}).idx)
2172 call g:Xsetlist([], 'a', {'nr' : 1, 'idx' : 'xx'})
2173 call assert_equal(3, g:Xgetlist({'nr' : 1, 'idx' : 0}).idx)
2174 call assert_fails("call g:Xsetlist([], 'a', {'nr':1, 'idx':[]})", 'E745:')
2175
2176 call g:Xsetlist([], 'f')
2177 new | only
2178endfunc
2179
2180func Test_setqfidx()
2181 call Xtest_setqfidx('c')
2182 call Xtest_setqfidx('l')
2183endfunc
2184
Bram Moolenaar04c4ce62016-09-01 15:45:58 +02002185" Tests for the QuickFixCmdPre/QuickFixCmdPost autocommands
Bram Moolenaar2b946c92016-11-12 18:14:44 +01002186func QfAutoCmdHandler(loc, cmd)
Bram Moolenaar04c4ce62016-09-01 15:45:58 +02002187 call add(g:acmds, a:loc . a:cmd)
Bram Moolenaar2b946c92016-11-12 18:14:44 +01002188endfunc
Bram Moolenaar04c4ce62016-09-01 15:45:58 +02002189
Bram Moolenaar2b946c92016-11-12 18:14:44 +01002190func Test_Autocmd()
Bram Moolenaar04c4ce62016-09-01 15:45:58 +02002191 autocmd QuickFixCmdPre * call QfAutoCmdHandler('pre', expand('<amatch>'))
2192 autocmd QuickFixCmdPost * call QfAutoCmdHandler('post', expand('<amatch>'))
2193
2194 let g:acmds = []
2195 cexpr "F1:10:Line 10"
2196 caddexpr "F1:20:Line 20"
2197 cgetexpr "F1:30:Line 30"
Bram Moolenaar1ed22762017-11-28 18:03:44 +01002198 cexpr ""
2199 caddexpr ""
2200 cgetexpr ""
2201 silent! cexpr non_existing_func()
2202 silent! caddexpr non_existing_func()
2203 silent! cgetexpr non_existing_func()
Bram Moolenaar04c4ce62016-09-01 15:45:58 +02002204 let l = ['precexpr',
2205 \ 'postcexpr',
2206 \ 'precaddexpr',
2207 \ 'postcaddexpr',
2208 \ 'precgetexpr',
2209 \ 'postcgetexpr',
Bram Moolenaar1ed22762017-11-28 18:03:44 +01002210 \ 'precexpr',
2211 \ 'postcexpr',
2212 \ 'precaddexpr',
2213 \ 'postcaddexpr',
2214 \ 'precgetexpr',
2215 \ 'postcgetexpr',
2216 \ 'precexpr',
2217 \ 'precaddexpr',
2218 \ 'precgetexpr']
2219 call assert_equal(l, g:acmds)
2220
2221 let g:acmds = []
2222 enew! | call append(0, "F2:10:Line 10")
2223 cbuffer!
2224 enew! | call append(0, "F2:20:Line 20")
2225 cgetbuffer
2226 enew! | call append(0, "F2:30:Line 30")
2227 caddbuffer
2228 new
2229 let bnum = bufnr('%')
2230 bunload
2231 exe 'silent! cbuffer! ' . bnum
2232 exe 'silent! cgetbuffer ' . bnum
2233 exe 'silent! caddbuffer ' . bnum
2234 enew!
2235 let l = ['precbuffer',
Bram Moolenaar04c4ce62016-09-01 15:45:58 +02002236 \ 'postcbuffer',
2237 \ 'precgetbuffer',
2238 \ 'postcgetbuffer',
2239 \ 'precaddbuffer',
Bram Moolenaar1ed22762017-11-28 18:03:44 +01002240 \ 'postcaddbuffer',
2241 \ 'precbuffer',
2242 \ 'precgetbuffer',
2243 \ 'precaddbuffer']
Bram Moolenaar04c4ce62016-09-01 15:45:58 +02002244 call assert_equal(l, g:acmds)
Bram Moolenaar1ed22762017-11-28 18:03:44 +01002245
2246 call writefile(['Xtest:1:Line1'], 'Xtest')
2247 call writefile([], 'Xempty')
2248 let g:acmds = []
2249 cfile Xtest
2250 caddfile Xtest
2251 cgetfile Xtest
2252 cfile Xempty
2253 caddfile Xempty
2254 cgetfile Xempty
2255 silent! cfile do_not_exist
2256 silent! caddfile do_not_exist
2257 silent! cgetfile do_not_exist
2258 let l = ['precfile',
2259 \ 'postcfile',
2260 \ 'precaddfile',
2261 \ 'postcaddfile',
2262 \ 'precgetfile',
2263 \ 'postcgetfile',
2264 \ 'precfile',
2265 \ 'postcfile',
2266 \ 'precaddfile',
2267 \ 'postcaddfile',
2268 \ 'precgetfile',
2269 \ 'postcgetfile',
2270 \ 'precfile',
2271 \ 'postcfile',
2272 \ 'precaddfile',
2273 \ 'postcaddfile',
2274 \ 'precgetfile',
2275 \ 'postcgetfile']
2276 call assert_equal(l, g:acmds)
2277
2278 let g:acmds = []
2279 helpgrep quickfix
2280 silent! helpgrep non_existing_help_topic
2281 vimgrep test Xtest
2282 vimgrepadd test Xtest
2283 silent! vimgrep non_existing_test Xtest
2284 silent! vimgrepadd non_existing_test Xtest
2285 set makeprg=
2286 silent! make
2287 set makeprg&
2288 let l = ['prehelpgrep',
2289 \ 'posthelpgrep',
2290 \ 'prehelpgrep',
2291 \ 'posthelpgrep',
2292 \ 'previmgrep',
2293 \ 'postvimgrep',
2294 \ 'previmgrepadd',
2295 \ 'postvimgrepadd',
2296 \ 'previmgrep',
2297 \ 'postvimgrep',
2298 \ 'previmgrepadd',
2299 \ 'postvimgrepadd',
2300 \ 'premake',
2301 \ 'postmake']
2302 call assert_equal(l, g:acmds)
2303
2304 if has('unix')
2305 " Run this test only on Unix-like systems. The grepprg may not be set on
2306 " non-Unix systems.
2307 " The following lines are used for the grep test. Don't remove.
2308 " Grep_Autocmd_Text: Match 1
2309 " GrepAdd_Autocmd_Text: Match 2
2310 let g:acmds = []
2311 silent grep Grep_Autocmd_Text test_quickfix.vim
2312 silent grepadd GrepAdd_Autocmd_Text test_quickfix.vim
2313 silent grep abc123def Xtest
2314 silent grepadd abc123def Xtest
2315 let l = ['pregrep',
2316 \ 'postgrep',
2317 \ 'pregrepadd',
2318 \ 'postgrepadd',
2319 \ 'pregrep',
2320 \ 'postgrep',
2321 \ 'pregrepadd',
2322 \ 'postgrepadd']
2323 call assert_equal(l, g:acmds)
2324 endif
2325
2326 call delete('Xtest')
2327 call delete('Xempty')
Bram Moolenaarb254af32017-12-18 19:48:58 +01002328 au! QuickFixCmdPre
2329 au! QuickFixCmdPost
Bram Moolenaar2b946c92016-11-12 18:14:44 +01002330endfunc
Bram Moolenaar21662be2016-11-06 14:46:44 +01002331
Bram Moolenaar2b946c92016-11-12 18:14:44 +01002332func Test_Autocmd_Exception()
Bram Moolenaar21662be2016-11-06 14:46:44 +01002333 set efm=%m
2334 lgetexpr '?'
2335
2336 try
2337 call DoesNotExit()
2338 catch
2339 lgetexpr '1'
2340 finally
2341 lgetexpr '1'
2342 endtry
2343
2344 call assert_equal('1', getloclist(0)[0].text)
2345
2346 set efm&vim
Bram Moolenaar2b946c92016-11-12 18:14:44 +01002347endfunc
Bram Moolenaar63bed3d2016-11-12 15:36:54 +01002348
Bram Moolenaar2b946c92016-11-12 18:14:44 +01002349func Test_caddbuffer_wrong()
2350 " This used to cause a memory access in freed memory.
Bram Moolenaar63bed3d2016-11-12 15:36:54 +01002351 let save_efm = &efm
2352 set efm=%EEEE%m,%WWWW,%+CCCC%>%#,%GGGG%.#
2353 cgetexpr ['WWWW', 'EEEE', 'CCCC']
2354 let &efm = save_efm
Bram Moolenaar2b946c92016-11-12 18:14:44 +01002355 caddbuffer
Bram Moolenaar63bed3d2016-11-12 15:36:54 +01002356 bwipe!
2357endfunc
Bram Moolenaar2b946c92016-11-12 18:14:44 +01002358
2359func Test_caddexpr_wrong()
2360 " This used to cause a memory access in freed memory.
2361 cbuffer
2362 cbuffer
2363 copen
2364 let save_efm = &efm
2365 set efm=%
2366 call assert_fails('caddexpr ""', 'E376:')
2367 let &efm = save_efm
2368endfunc
Bram Moolenaar7618e002016-11-13 15:09:26 +01002369
2370func Test_dirstack_cleanup()
2371 " This used to cause a memory access in freed memory.
2372 let save_efm = &efm
2373 lexpr '0'
2374 lopen
2375 fun X(c)
2376 let save_efm=&efm
2377 set efm=%D%f
2378 if a:c == 'c'
2379 caddexpr '::'
2380 else
2381 laddexpr ':0:0'
2382 endif
2383 let &efm=save_efm
2384 endfun
2385 call X('c')
2386 call X('l')
2387 call setqflist([], 'r')
2388 caddbuffer
2389 let &efm = save_efm
2390endfunc
Bram Moolenaar391b1dd2017-03-04 13:47:11 +01002391
2392" Tests for jumping to entries from the location list window and quickfix
2393" window
2394func Test_cwindow_jump()
2395 set efm=%f%%%l%%%m
2396 lgetexpr ["F1%10%Line 10", "F2%20%Line 20", "F3%30%Line 30"]
2397 lopen | only
2398 lfirst
2399 call assert_true(winnr('$') == 2)
2400 call assert_true(winnr() == 1)
2401 " Location list for the new window should be set
2402 call assert_true(getloclist(0)[2].text == 'Line 30')
2403
2404 " Open a scratch buffer
2405 " Open a new window and create a location list
2406 " Open the location list window and close the other window
2407 " Jump to an entry.
Bram Moolenaareeb1b9c2019-02-10 22:59:04 +01002408 " Should create a new window and jump to the entry. The scratch buffer
Bram Moolenaar391b1dd2017-03-04 13:47:11 +01002409 " should not be used.
2410 enew | only
2411 set buftype=nofile
2412 below new
2413 lgetexpr ["F1%10%Line 10", "F2%20%Line 20", "F3%30%Line 30"]
2414 lopen
2415 2wincmd c
2416 lnext
2417 call assert_true(winnr('$') == 3)
2418 call assert_true(winnr() == 2)
2419
2420 " Open two windows with two different location lists
2421 " Open the location list window and close the previous window
2422 " Jump to an entry in the location list window
2423 " Should open the file in the first window and not set the location list.
2424 enew | only
2425 lgetexpr ["F1%5%Line 5"]
2426 below new
2427 lgetexpr ["F1%10%Line 10", "F2%20%Line 20", "F3%30%Line 30"]
2428 lopen
2429 2wincmd c
2430 lnext
2431 call assert_true(winnr() == 1)
2432 call assert_true(getloclist(0)[0].text == 'Line 5')
2433
2434 enew | only
2435 cgetexpr ["F1%10%Line 10", "F2%20%Line 20", "F3%30%Line 30"]
2436 copen
2437 cnext
2438 call assert_true(winnr('$') == 2)
2439 call assert_true(winnr() == 1)
2440
2441 enew | only
2442 set efm&vim
2443endfunc
Bram Moolenaaree85df32017-03-19 14:19:50 +01002444
Bram Moolenaare00fdf32019-09-15 19:09:42 +02002445func Test_cwindow_highlight()
2446 CheckScreendump
2447
2448 let lines =<< trim END
2449 set t_u7=
2450 call setline(1, ['some', 'text', 'with', 'matches'])
2451 write XCwindow
2452 vimgrep e XCwindow
2453 redraw
2454 cwindow 4
2455 END
2456 call writefile(lines, 'XtestCwindow')
2457 let buf = RunVimInTerminal('-S XtestCwindow', #{rows: 12})
2458 call VerifyScreenDump(buf, 'Test_quickfix_cwindow_1', {})
2459
2460 call term_sendkeys(buf, ":cnext\<CR>")
2461 call VerifyScreenDump(buf, 'Test_quickfix_cwindow_2', {})
2462
2463 " clean up
2464 call StopVimInTerminal(buf)
2465 call delete('XtestCwindow')
2466 call delete('XCwindow')
2467endfunc
2468
Bram Moolenaaree85df32017-03-19 14:19:50 +01002469func XvimgrepTests(cchar)
2470 call s:setup_commands(a:cchar)
2471
2472 call writefile(['Editor:VIM vim',
2473 \ 'Editor:Emacs EmAcS',
2474 \ 'Editor:Notepad NOTEPAD'], 'Xtestfile1')
2475 call writefile(['Linux', 'MacOS', 'MS-Windows'], 'Xtestfile2')
2476
2477 " Error cases
2478 call assert_fails('Xvimgrep /abc *', 'E682:')
2479
2480 let @/=''
2481 call assert_fails('Xvimgrep // *', 'E35:')
2482
2483 call assert_fails('Xvimgrep abc', 'E683:')
2484 call assert_fails('Xvimgrep a1b2c3 Xtestfile1', 'E480:')
2485 call assert_fails('Xvimgrep pat Xa1b2c3', 'E480:')
2486
2487 Xexpr ""
2488 Xvimgrepadd Notepad Xtestfile1
2489 Xvimgrepadd MacOS Xtestfile2
2490 let l = g:Xgetlist()
2491 call assert_equal(2, len(l))
2492 call assert_equal('Editor:Notepad NOTEPAD', l[0].text)
2493
2494 Xvimgrep #\cvim#g Xtestfile?
2495 let l = g:Xgetlist()
2496 call assert_equal(2, len(l))
2497 call assert_equal(8, l[0].col)
2498 call assert_equal(12, l[1].col)
2499
2500 1Xvimgrep ?Editor? Xtestfile*
2501 let l = g:Xgetlist()
2502 call assert_equal(1, len(l))
2503 call assert_equal('Editor:VIM vim', l[0].text)
2504
2505 edit +3 Xtestfile2
2506 Xvimgrep +\cemacs+j Xtestfile1
2507 let l = g:Xgetlist()
2508 call assert_equal('Xtestfile2', bufname(''))
2509 call assert_equal('Editor:Emacs EmAcS', l[0].text)
2510
Bram Moolenaar2225ebb2018-04-24 15:48:11 +02002511 " Test for unloading a buffer after vimgrep searched the buffer
2512 %bwipe
2513 Xvimgrep /Editor/j Xtestfile*
2514 call assert_equal(0, getbufinfo('Xtestfile1')[0].loaded)
2515 call assert_equal([], getbufinfo('Xtestfile2'))
2516
Bram Moolenaaree85df32017-03-19 14:19:50 +01002517 call delete('Xtestfile1')
2518 call delete('Xtestfile2')
2519endfunc
2520
2521" Tests for the :vimgrep command
2522func Test_vimgrep()
2523 call XvimgrepTests('c')
2524 call XvimgrepTests('l')
2525endfunc
Bram Moolenaar69f40be2017-04-02 15:15:49 +02002526
Bram Moolenaar1c299432018-10-28 14:36:09 +01002527" Test for incsearch highlighting of the :vimgrep pattern
2528" This test used to cause "E315: ml_get: invalid lnum" errors.
2529func Test_vimgrep_incsearch()
2530 enew
2531 set incsearch
2532 call test_override("char_avail", 1)
2533
2534 call feedkeys(":2vimgrep assert test_quickfix.vim test_cdo.vim\<CR>", "ntx")
2535 let l = getqflist()
2536 call assert_equal(2, len(l))
2537
2538 call test_override("ALL", 0)
2539 set noincsearch
2540endfunc
2541
Bram Moolenaar69f40be2017-04-02 15:15:49 +02002542func XfreeTests(cchar)
2543 call s:setup_commands(a:cchar)
2544
2545 enew | only
2546
2547 " Deleting the quickfix stack should work even When the current list is
2548 " somewhere in the middle of the stack
2549 Xexpr ['Xfile1:10:10:Line 10', 'Xfile1:15:15:Line 15']
2550 Xexpr ['Xfile2:20:20:Line 20', 'Xfile2:25:25:Line 25']
2551 Xexpr ['Xfile3:30:30:Line 30', 'Xfile3:35:35:Line 35']
2552 Xolder
2553 call g:Xsetlist([], 'f')
2554 call assert_equal(0, len(g:Xgetlist()))
2555
2556 " After deleting the stack, adding a new list should create a stack with a
2557 " single list.
2558 Xexpr ['Xfile1:10:10:Line 10', 'Xfile1:15:15:Line 15']
2559 call assert_equal(1, g:Xgetlist({'all':1}).nr)
2560
2561 " Deleting the stack from a quickfix window should update/clear the
2562 " quickfix/location list window.
2563 Xexpr ['Xfile1:10:10:Line 10', 'Xfile1:15:15:Line 15']
2564 Xexpr ['Xfile2:20:20:Line 20', 'Xfile2:25:25:Line 25']
2565 Xexpr ['Xfile3:30:30:Line 30', 'Xfile3:35:35:Line 35']
2566 Xolder
2567 Xwindow
2568 call g:Xsetlist([], 'f')
2569 call assert_equal(2, winnr('$'))
2570 call assert_equal(1, line('$'))
2571 Xclose
2572
2573 " Deleting the stack from a non-quickfix window should update/clear the
2574 " quickfix/location list window.
2575 Xexpr ['Xfile1:10:10:Line 10', 'Xfile1:15:15:Line 15']
2576 Xexpr ['Xfile2:20:20:Line 20', 'Xfile2:25:25:Line 25']
2577 Xexpr ['Xfile3:30:30:Line 30', 'Xfile3:35:35:Line 35']
2578 Xolder
2579 Xwindow
2580 wincmd p
2581 call g:Xsetlist([], 'f')
2582 call assert_equal(0, len(g:Xgetlist()))
2583 wincmd p
2584 call assert_equal(2, winnr('$'))
2585 call assert_equal(1, line('$'))
2586
2587 " After deleting the location list stack, if the location list window is
2588 " opened, then a new location list should be created. So opening the
2589 " location list window again should not create a new window.
2590 if a:cchar == 'l'
2591 lexpr ['Xfile1:10:10:Line 10', 'Xfile1:15:15:Line 15']
2592 wincmd p
2593 lopen
2594 call assert_equal(2, winnr('$'))
2595 endif
2596 Xclose
2597endfunc
2598
Bram Moolenaar74240d32017-12-10 15:26:15 +01002599" Tests for the quickfix free functionality
Bram Moolenaar69f40be2017-04-02 15:15:49 +02002600func Test_qf_free()
2601 call XfreeTests('c')
2602 call XfreeTests('l')
2603endfunc
Bram Moolenaar6e62da32017-05-28 08:16:25 +02002604
2605" Test for buffer overflow when parsing lines and adding new entries to
2606" the quickfix list.
2607func Test_bufoverflow()
2608 set efm=%f:%l:%m
2609 cgetexpr ['File1:100:' . repeat('x', 1025)]
2610
2611 set efm=%+GCompiler:\ %.%#,%f:%l:%m
2612 cgetexpr ['Compiler: ' . repeat('a', 1015), 'File1:10:Hello World']
2613
2614 set efm=%DEntering\ directory\ %f,%f:%l:%m
2615 cgetexpr ['Entering directory ' . repeat('a', 1006),
2616 \ 'File1:10:Hello World']
2617 set efm&vim
2618endfunc
2619
Bram Moolenaar875feea2017-06-11 16:07:51 +02002620" Tests for getting the quickfix stack size
2621func XsizeTests(cchar)
2622 call s:setup_commands(a:cchar)
2623
2624 call g:Xsetlist([], 'f')
2625 call assert_equal(0, g:Xgetlist({'nr':'$'}).nr)
Bram Moolenaara6d48492017-12-12 22:45:31 +01002626 call assert_equal('', g:Xgetlist({'nr':'$', 'all':1}).title)
2627 call assert_equal(0, g:Xgetlist({'nr':0}).nr)
Bram Moolenaar875feea2017-06-11 16:07:51 +02002628
2629 Xexpr "File1:10:Line1"
2630 Xexpr "File2:20:Line2"
2631 Xexpr "File3:30:Line3"
2632 Xolder | Xolder
2633 call assert_equal(3, g:Xgetlist({'nr':'$'}).nr)
2634 call g:Xsetlist([], 'f')
2635
2636 Xexpr "File1:10:Line1"
2637 Xexpr "File2:20:Line2"
2638 Xexpr "File3:30:Line3"
2639 Xolder | Xolder
2640 call g:Xsetlist([], 'a', {'nr':'$', 'title':'Compiler'})
2641 call assert_equal('Compiler', g:Xgetlist({'nr':3, 'all':1}).title)
2642endfunc
2643
2644func Test_Qf_Size()
2645 call XsizeTests('c')
2646 call XsizeTests('l')
2647endfunc
Bram Moolenaar18141832017-06-25 21:17:25 +02002648
Bram Moolenaar9c4feff2017-06-28 22:26:54 +02002649func Test_cclose_from_copen()
2650 augroup QF_Test
2651 au!
2652 au FileType qf :call assert_fails(':cclose', 'E788')
2653 augroup END
2654 copen
2655 augroup QF_Test
2656 au!
2657 augroup END
2658 augroup! QF_Test
2659endfunc
2660
Bram Moolenaar18141832017-06-25 21:17:25 +02002661func Test_cclose_in_autocmd()
2662 " Problem is only triggered if "starting" is zero, so that the OptionsSet
2663 " event will be triggered.
2664 call test_override('starting', 1)
2665 augroup QF_Test
2666 au!
2667 au FileType qf :call assert_fails(':cclose', 'E788')
2668 augroup END
2669 copen
2670 augroup QF_Test
2671 au!
2672 augroup END
2673 augroup! QF_Test
2674 call test_override('starting', 0)
2675endfunc
Bram Moolenaar9c4feff2017-06-28 22:26:54 +02002676
Bram Moolenaar379fb762018-08-30 15:58:28 +02002677" Check that ":file" without an argument is possible even when "curbuf_lock"
2678" is set.
2679func Test_file_from_copen()
2680 " Works without argument.
2681 augroup QF_Test
2682 au!
2683 au FileType qf file
2684 augroup END
2685 copen
2686
2687 augroup QF_Test
2688 au!
2689 augroup END
2690 cclose
2691
2692 " Fails with argument.
2693 augroup QF_Test
2694 au!
2695 au FileType qf call assert_fails(':file foo', 'E788')
2696 augroup END
2697 copen
2698 augroup QF_Test
2699 au!
2700 augroup END
2701 cclose
2702
2703 augroup! QF_Test
2704endfunction
2705
Bram Moolenaar9c4feff2017-06-28 22:26:54 +02002706func Test_resize_from_copen()
2707 augroup QF_Test
2708 au!
2709 au FileType qf resize 5
2710 augroup END
2711 try
2712 " This should succeed without any exception. No other buffers are
2713 " involved in the autocmd.
2714 copen
2715 finally
2716 augroup QF_Test
2717 au!
2718 augroup END
2719 augroup! QF_Test
2720 endtry
2721endfunc
Bram Moolenaara8788f42017-07-19 17:06:20 +02002722
2723" Tests for the quickfix buffer b:changedtick variable
2724func Xchangedtick_tests(cchar)
2725 call s:setup_commands(a:cchar)
2726
2727 new | only
2728
2729 Xexpr "" | Xexpr "" | Xexpr ""
2730
2731 Xopen
2732 Xolder
2733 Xolder
2734 Xaddexpr "F1:10:Line10"
2735 Xaddexpr "F2:20:Line20"
2736 call g:Xsetlist([{"filename":"F3", "lnum":30, "text":"Line30"}], 'a')
2737 call g:Xsetlist([], 'f')
2738 call assert_equal(8, getbufvar('%', 'changedtick'))
2739 Xclose
2740endfunc
2741
2742func Test_changedtick()
Bram Moolenaarae338332017-08-11 20:25:26 +02002743 call Xchangedtick_tests('c')
2744 call Xchangedtick_tests('l')
2745endfunc
2746
2747" Tests for parsing an expression using setqflist()
2748func Xsetexpr_tests(cchar)
2749 call s:setup_commands(a:cchar)
2750
2751 let t = ["File1:10:Line10", "File1:20:Line20"]
Bram Moolenaar2c809b72017-09-01 18:34:02 +02002752 call g:Xsetlist([], ' ', {'lines' : t})
2753 call g:Xsetlist([], 'a', {'lines' : ["File1:30:Line30"]})
Bram Moolenaarae338332017-08-11 20:25:26 +02002754
2755 let l = g:Xgetlist()
2756 call assert_equal(3, len(l))
2757 call assert_equal(20, l[1].lnum)
2758 call assert_equal('Line30', l[2].text)
Bram Moolenaar2c809b72017-09-01 18:34:02 +02002759 call g:Xsetlist([], 'r', {'lines' : ["File2:5:Line5"]})
Bram Moolenaarae338332017-08-11 20:25:26 +02002760 let l = g:Xgetlist()
2761 call assert_equal(1, len(l))
2762 call assert_equal('Line5', l[0].text)
Bram Moolenaar2c809b72017-09-01 18:34:02 +02002763 call assert_equal(-1, g:Xsetlist([], 'a', {'lines' : 10}))
2764 call assert_equal(-1, g:Xsetlist([], 'a', {'lines' : "F1:10:L10"}))
Bram Moolenaarae338332017-08-11 20:25:26 +02002765
2766 call g:Xsetlist([], 'f')
2767 " Add entries to multiple lists
Bram Moolenaar2c809b72017-09-01 18:34:02 +02002768 call g:Xsetlist([], 'a', {'nr' : 1, 'lines' : ["File1:10:Line10"]})
2769 call g:Xsetlist([], 'a', {'nr' : 2, 'lines' : ["File2:20:Line20"]})
2770 call g:Xsetlist([], 'a', {'nr' : 1, 'lines' : ["File1:15:Line15"]})
2771 call g:Xsetlist([], 'a', {'nr' : 2, 'lines' : ["File2:25:Line25"]})
Bram Moolenaarae338332017-08-11 20:25:26 +02002772 call assert_equal('Line15', g:Xgetlist({'nr':1, 'items':1}).items[1].text)
2773 call assert_equal('Line25', g:Xgetlist({'nr':2, 'items':1}).items[1].text)
Bram Moolenaar36538222017-09-02 19:51:44 +02002774
2775 " Adding entries using a custom efm
2776 set efm&
2777 call g:Xsetlist([], ' ', {'efm' : '%f#%l#%m',
2778 \ 'lines' : ["F1#10#L10", "F2#20#L20"]})
2779 call assert_equal(20, g:Xgetlist({'items':1}).items[1].lnum)
2780 call g:Xsetlist([], 'a', {'efm' : '%f#%l#%m', 'lines' : ["F3:30:L30"]})
2781 call assert_equal('F3:30:L30', g:Xgetlist({'items':1}).items[2].text)
2782 call assert_equal(20, g:Xgetlist({'items':1}).items[1].lnum)
2783 call assert_equal(-1, g:Xsetlist([], 'a', {'efm' : [],
2784 \ 'lines' : ['F1:10:L10']}))
Bram Moolenaarae338332017-08-11 20:25:26 +02002785endfunc
2786
2787func Test_setexpr()
2788 call Xsetexpr_tests('c')
2789 call Xsetexpr_tests('l')
2790endfunc
2791
2792" Tests for per quickfix/location list directory stack
2793func Xmultidirstack_tests(cchar)
2794 call s:setup_commands(a:cchar)
2795
2796 call g:Xsetlist([], 'f')
2797 Xexpr "" | Xexpr ""
2798
Bram Moolenaar2c809b72017-09-01 18:34:02 +02002799 call g:Xsetlist([], 'a', {'nr' : 1, 'lines' : ["Entering dir 'Xone/a'"]})
2800 call g:Xsetlist([], 'a', {'nr' : 2, 'lines' : ["Entering dir 'Xtwo/a'"]})
2801 call g:Xsetlist([], 'a', {'nr' : 1, 'lines' : ["one.txt:3:one one one"]})
2802 call g:Xsetlist([], 'a', {'nr' : 2, 'lines' : ["two.txt:5:two two two"]})
Bram Moolenaarae338332017-08-11 20:25:26 +02002803
2804 let l1 = g:Xgetlist({'nr':1, 'items':1})
2805 let l2 = g:Xgetlist({'nr':2, 'items':1})
2806 call assert_equal('Xone/a/one.txt', bufname(l1.items[1].bufnr))
2807 call assert_equal(3, l1.items[1].lnum)
2808 call assert_equal('Xtwo/a/two.txt', bufname(l2.items[1].bufnr))
2809 call assert_equal(5, l2.items[1].lnum)
2810endfunc
2811
2812func Test_multidirstack()
2813 call mkdir('Xone/a', 'p')
2814 call mkdir('Xtwo/a', 'p')
2815 let lines = ['1', '2', 'one one one', '4', 'two two two', '6', '7']
2816 call writefile(lines, 'Xone/a/one.txt')
2817 call writefile(lines, 'Xtwo/a/two.txt')
2818 let save_efm = &efm
2819 set efm=%DEntering\ dir\ '%f',%f:%l:%m,%XLeaving\ dir\ '%f'
2820
2821 call Xmultidirstack_tests('c')
2822 call Xmultidirstack_tests('l')
2823
2824 let &efm = save_efm
2825 call delete('Xone', 'rf')
2826 call delete('Xtwo', 'rf')
2827endfunc
2828
2829" Tests for per quickfix/location list file stack
2830func Xmultifilestack_tests(cchar)
2831 call s:setup_commands(a:cchar)
2832
2833 call g:Xsetlist([], 'f')
2834 Xexpr "" | Xexpr ""
2835
Bram Moolenaar2c809b72017-09-01 18:34:02 +02002836 call g:Xsetlist([], 'a', {'nr' : 1, 'lines' : ["[one.txt]"]})
2837 call g:Xsetlist([], 'a', {'nr' : 2, 'lines' : ["[two.txt]"]})
2838 call g:Xsetlist([], 'a', {'nr' : 1, 'lines' : ["(3,5) one one one"]})
2839 call g:Xsetlist([], 'a', {'nr' : 2, 'lines' : ["(5,9) two two two"]})
Bram Moolenaarae338332017-08-11 20:25:26 +02002840
2841 let l1 = g:Xgetlist({'nr':1, 'items':1})
2842 let l2 = g:Xgetlist({'nr':2, 'items':1})
2843 call assert_equal('one.txt', bufname(l1.items[1].bufnr))
2844 call assert_equal(3, l1.items[1].lnum)
2845 call assert_equal('two.txt', bufname(l2.items[1].bufnr))
2846 call assert_equal(5, l2.items[1].lnum)
Bram Moolenaare333e792018-04-08 13:27:39 +02002847
2848 " Test for start of a new error line in the same line where a previous
2849 " error line ends with a file stack.
2850 let efm_val = 'Error\ l%l\ in\ %f,'
2851 let efm_val .= '%-P%>(%f%r,Error\ l%l\ in\ %m,%-Q)%r'
2852 let l = g:Xgetlist({'lines' : [
2853 \ '(one.txt',
2854 \ 'Error l4 in one.txt',
2855 \ ') (two.txt',
2856 \ 'Error l6 in two.txt',
2857 \ ')',
2858 \ 'Error l8 in one.txt'
2859 \ ], 'efm' : efm_val})
2860 call assert_equal(3, len(l.items))
2861 call assert_equal('one.txt', bufname(l.items[0].bufnr))
2862 call assert_equal(4, l.items[0].lnum)
2863 call assert_equal('one.txt', l.items[0].text)
2864 call assert_equal('two.txt', bufname(l.items[1].bufnr))
2865 call assert_equal(6, l.items[1].lnum)
2866 call assert_equal('two.txt', l.items[1].text)
2867 call assert_equal('one.txt', bufname(l.items[2].bufnr))
2868 call assert_equal(8, l.items[2].lnum)
2869 call assert_equal('', l.items[2].text)
Bram Moolenaarae338332017-08-11 20:25:26 +02002870endfunc
2871
2872func Test_multifilestack()
2873 let lines = ['1', '2', 'one one one', '4', 'two two two', '6', '7']
2874 call writefile(lines, 'one.txt')
2875 call writefile(lines, 'two.txt')
2876 let save_efm = &efm
2877 set efm=%+P[%f],(%l\\,%c)\ %m,%-Q
2878
2879 call Xmultifilestack_tests('c')
2880 call Xmultifilestack_tests('l')
2881
2882 let &efm = save_efm
2883 call delete('one.txt')
2884 call delete('two.txt')
2885endfunc
2886
2887" Tests for per buffer 'efm' setting
2888func Test_perbuf_efm()
2889 call writefile(["File1-10-Line10"], 'one.txt')
2890 call writefile(["File2#20#Line20"], 'two.txt')
2891 set efm=%f#%l#%m
2892 new | only
2893 new
2894 setlocal efm=%f-%l-%m
2895 cfile one.txt
2896 wincmd w
2897 caddfile two.txt
2898
2899 let l = getqflist()
2900 call assert_equal(10, l[0].lnum)
2901 call assert_equal('Line20', l[1].text)
2902
2903 set efm&
2904 new | only
2905 call delete('one.txt')
2906 call delete('two.txt')
Bram Moolenaara8788f42017-07-19 17:06:20 +02002907endfunc
Bram Moolenaard28cc3f2017-07-27 22:03:50 +02002908
2909" Open multiple help windows using ":lhelpgrep
2910" This test used to crash Vim
2911func Test_Multi_LL_Help()
2912 new | only
2913 lhelpgrep window
2914 lopen
2915 e#
2916 lhelpgrep buffer
2917 call assert_equal(3, winnr('$'))
2918 call assert_true(len(getloclist(1)) != 0)
2919 call assert_true(len(getloclist(2)) != 0)
2920 new | only
2921endfunc
Bram Moolenaar55b69262017-08-13 13:42:01 +02002922
2923" Tests for adding new quickfix lists using setqflist()
2924func XaddQf_tests(cchar)
2925 call s:setup_commands(a:cchar)
2926
2927 " Create a new list using ' ' for action
2928 call g:Xsetlist([], 'f')
2929 call g:Xsetlist([], ' ', {'title' : 'Test1'})
2930 let l = g:Xgetlist({'nr' : '$', 'all' : 1})
2931 call assert_equal(1, l.nr)
2932 call assert_equal('Test1', l.title)
2933
2934 " Create a new list using ' ' for action and '$' for 'nr'
2935 call g:Xsetlist([], 'f')
2936 call g:Xsetlist([], ' ', {'title' : 'Test2', 'nr' : '$'})
2937 let l = g:Xgetlist({'nr' : '$', 'all' : 1})
2938 call assert_equal(1, l.nr)
2939 call assert_equal('Test2', l.title)
2940
2941 " Create a new list using 'a' for action
2942 call g:Xsetlist([], 'f')
2943 call g:Xsetlist([], 'a', {'title' : 'Test3'})
2944 let l = g:Xgetlist({'nr' : '$', 'all' : 1})
2945 call assert_equal(1, l.nr)
2946 call assert_equal('Test3', l.title)
2947
2948 " Create a new list using 'a' for action and '$' for 'nr'
2949 call g:Xsetlist([], 'f')
2950 call g:Xsetlist([], 'a', {'title' : 'Test3', 'nr' : '$'})
2951 call g:Xsetlist([], 'a', {'title' : 'Test4'})
2952 let l = g:Xgetlist({'nr' : '$', 'all' : 1})
2953 call assert_equal(1, l.nr)
2954 call assert_equal('Test4', l.title)
2955
2956 " Adding a quickfix list should remove all the lists following the current
2957 " list.
2958 Xexpr "" | Xexpr "" | Xexpr ""
2959 silent! 10Xolder
2960 call g:Xsetlist([], ' ', {'title' : 'Test5'})
2961 let l = g:Xgetlist({'nr' : '$', 'all' : 1})
2962 call assert_equal(2, l.nr)
2963 call assert_equal('Test5', l.title)
2964
2965 " Add a quickfix list using '$' as the list number.
2966 let lastqf = g:Xgetlist({'nr':'$'}).nr
2967 silent! 99Xolder
2968 call g:Xsetlist([], ' ', {'nr' : '$', 'title' : 'Test6'})
2969 let l = g:Xgetlist({'nr' : '$', 'all' : 1})
2970 call assert_equal(lastqf + 1, l.nr)
2971 call assert_equal('Test6', l.title)
2972
2973 " Add a quickfix list using 'nr' set to one more than the quickfix
2974 " list size.
2975 let lastqf = g:Xgetlist({'nr':'$'}).nr
2976 silent! 99Xolder
2977 call g:Xsetlist([], ' ', {'nr' : lastqf + 1, 'title' : 'Test7'})
2978 let l = g:Xgetlist({'nr' : '$', 'all' : 1})
2979 call assert_equal(lastqf + 1, l.nr)
2980 call assert_equal('Test7', l.title)
2981
2982 " Add a quickfix list to a stack with 10 lists using 'nr' set to '$'
2983 exe repeat('Xexpr "" |', 9) . 'Xexpr ""'
2984 silent! 99Xolder
2985 call g:Xsetlist([], ' ', {'nr' : '$', 'title' : 'Test8'})
2986 let l = g:Xgetlist({'nr' : '$', 'all' : 1})
2987 call assert_equal(10, l.nr)
2988 call assert_equal('Test8', l.title)
2989
2990 " Add a quickfix list using 'nr' set to a value greater than 10
2991 call assert_equal(-1, g:Xsetlist([], ' ', {'nr' : 12, 'title' : 'Test9'}))
2992
2993 " Try adding a quickfix list with 'nr' set to a value greater than the
2994 " quickfix list size but less than 10.
2995 call g:Xsetlist([], 'f')
2996 Xexpr "" | Xexpr "" | Xexpr ""
2997 silent! 99Xolder
2998 call assert_equal(-1, g:Xsetlist([], ' ', {'nr' : 8, 'title' : 'Test10'}))
2999
3000 " Add a quickfix list using 'nr' set to a some string or list
3001 call assert_equal(-1, g:Xsetlist([], ' ', {'nr' : [1,2], 'title' : 'Test11'}))
3002endfunc
3003
3004func Test_add_qf()
3005 call XaddQf_tests('c')
3006 call XaddQf_tests('l')
3007endfunc
Bram Moolenaar7adf06f2017-08-27 15:23:41 +02003008
3009" Test for getting the quickfix list items from some text without modifying
3010" the quickfix stack
Bram Moolenaar2c809b72017-09-01 18:34:02 +02003011func XgetListFromLines(cchar)
Bram Moolenaar7adf06f2017-08-27 15:23:41 +02003012 call s:setup_commands(a:cchar)
3013 call g:Xsetlist([], 'f')
3014
Bram Moolenaar2c809b72017-09-01 18:34:02 +02003015 let l = g:Xgetlist({'lines' : ["File2:20:Line20", "File2:30:Line30"]}).items
Bram Moolenaar7adf06f2017-08-27 15:23:41 +02003016 call assert_equal(2, len(l))
3017 call assert_equal(30, l[1].lnum)
3018
Bram Moolenaar2c809b72017-09-01 18:34:02 +02003019 call assert_equal({}, g:Xgetlist({'lines' : 10}))
3020 call assert_equal({}, g:Xgetlist({'lines' : 'File1:10:Line10'}))
3021 call assert_equal([], g:Xgetlist({'lines' : []}).items)
3022 call assert_equal([], g:Xgetlist({'lines' : [10, 20]}).items)
Bram Moolenaar7adf06f2017-08-27 15:23:41 +02003023
Bram Moolenaar36538222017-09-02 19:51:44 +02003024 " Parse text using a custom efm
3025 set efm&
3026 let l = g:Xgetlist({'lines':['File3#30#Line30'], 'efm' : '%f#%l#%m'}).items
3027 call assert_equal('Line30', l[0].text)
3028 let l = g:Xgetlist({'lines':['File3:30:Line30'], 'efm' : '%f-%l-%m'}).items
3029 call assert_equal('File3:30:Line30', l[0].text)
3030 let l = g:Xgetlist({'lines':['File3:30:Line30'], 'efm' : [1,2]})
3031 call assert_equal({}, l)
3032 call assert_fails("call g:Xgetlist({'lines':['abc'], 'efm':'%2'})", 'E376:')
3033 call assert_fails("call g:Xgetlist({'lines':['abc'], 'efm':''})", 'E378:')
3034
Bram Moolenaar7adf06f2017-08-27 15:23:41 +02003035 " Make sure that the quickfix stack is not modified
3036 call assert_equal(0, g:Xgetlist({'nr' : '$'}).nr)
3037endfunc
3038
Bram Moolenaar2c809b72017-09-01 18:34:02 +02003039func Test_get_list_from_lines()
3040 call XgetListFromLines('c')
3041 call XgetListFromLines('l')
Bram Moolenaar7adf06f2017-08-27 15:23:41 +02003042endfunc
Bram Moolenaara539f4f2017-08-30 20:33:55 +02003043
3044" Tests for the quickfix list id
3045func Xqfid_tests(cchar)
3046 call s:setup_commands(a:cchar)
3047
3048 call g:Xsetlist([], 'f')
Bram Moolenaara6d48492017-12-12 22:45:31 +01003049 call assert_equal(0, g:Xgetlist({'id':0}).id)
Bram Moolenaara539f4f2017-08-30 20:33:55 +02003050 Xexpr ''
3051 let start_id = g:Xgetlist({'id' : 0}).id
3052 Xexpr '' | Xexpr ''
3053 Xolder
3054 call assert_equal(start_id, g:Xgetlist({'id':0, 'nr':1}).id)
3055 call assert_equal(start_id + 1, g:Xgetlist({'id':0, 'nr':0}).id)
3056 call assert_equal(start_id + 2, g:Xgetlist({'id':0, 'nr':'$'}).id)
Bram Moolenaara6d48492017-12-12 22:45:31 +01003057 call assert_equal(0, g:Xgetlist({'id':0, 'nr':99}).id)
Bram Moolenaara539f4f2017-08-30 20:33:55 +02003058 call assert_equal(2, g:Xgetlist({'id':start_id + 1, 'nr':0}).nr)
Bram Moolenaara6d48492017-12-12 22:45:31 +01003059 call assert_equal(0, g:Xgetlist({'id':99, 'nr':0}).id)
3060 call assert_equal(0, g:Xgetlist({'id':"abc", 'nr':0}).id)
Bram Moolenaara539f4f2017-08-30 20:33:55 +02003061
3062 call g:Xsetlist([], 'a', {'id':start_id, 'context':[1,2]})
3063 call assert_equal([1,2], g:Xgetlist({'nr':1, 'context':1}).context)
Bram Moolenaar2c809b72017-09-01 18:34:02 +02003064 call g:Xsetlist([], 'a', {'id':start_id+1, 'lines':['F1:10:L10']})
Bram Moolenaara539f4f2017-08-30 20:33:55 +02003065 call assert_equal('L10', g:Xgetlist({'nr':2, 'items':1}).items[0].text)
3066 call assert_equal(-1, g:Xsetlist([], 'a', {'id':999, 'title':'Vim'}))
3067 call assert_equal(-1, g:Xsetlist([], 'a', {'id':'abc', 'title':'Vim'}))
3068
3069 let qfid = g:Xgetlist({'id':0, 'nr':0})
3070 call g:Xsetlist([], 'f')
Bram Moolenaara6d48492017-12-12 22:45:31 +01003071 call assert_equal(0, g:Xgetlist({'id':qfid, 'nr':0}).id)
Bram Moolenaara539f4f2017-08-30 20:33:55 +02003072endfunc
3073
3074func Test_qf_id()
3075 call Xqfid_tests('c')
3076 call Xqfid_tests('l')
3077endfunc
Bram Moolenaar74240d32017-12-10 15:26:15 +01003078
3079func Xqfjump_tests(cchar)
3080 call s:setup_commands(a:cchar)
3081
3082 call writefile(["Line1\tFoo", "Line2"], 'F1')
3083 call writefile(["Line1\tBar", "Line2"], 'F2')
3084 call writefile(["Line1\tBaz", "Line2"], 'F3')
3085
3086 call g:Xsetlist([], 'f')
3087
3088 " Tests for
3089 " Jumping to a line using a pattern
3090 " Jumping to a column greater than the last column in a line
3091 " Jumping to a line greater than the last line in the file
3092 let l = []
3093 for i in range(1, 7)
3094 call add(l, {})
3095 endfor
3096 let l[0].filename='F1'
3097 let l[0].pattern='Line1'
3098 let l[1].filename='F2'
3099 let l[1].pattern='Line1'
3100 let l[2].filename='F3'
3101 let l[2].pattern='Line1'
3102 let l[3].filename='F3'
3103 let l[3].lnum=1
3104 let l[3].col=9
3105 let l[3].vcol=1
3106 let l[4].filename='F3'
3107 let l[4].lnum=99
3108 let l[5].filename='F3'
3109 let l[5].lnum=1
3110 let l[5].col=99
3111 let l[5].vcol=1
3112 let l[6].filename='F3'
3113 let l[6].pattern='abcxyz'
3114
3115 call g:Xsetlist([], ' ', {'items' : l})
3116 Xopen | only
3117 2Xnext
3118 call assert_equal(3, g:Xgetlist({'idx' : 0}).idx)
3119 call assert_equal('F3', bufname('%'))
3120 Xnext
3121 call assert_equal(7, col('.'))
3122 Xnext
3123 call assert_equal(2, line('.'))
3124 Xnext
3125 call assert_equal(9, col('.'))
3126 2
3127 Xnext
3128 call assert_equal(2, line('.'))
3129
3130 if a:cchar == 'l'
3131 " When jumping to a location list entry in the location list window and
3132 " no usable windows are available, then a new window should be opened.
3133 enew! | new | only
3134 call g:Xsetlist([], 'f')
3135 setlocal buftype=nofile
3136 new
3137 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']})
3138 Xopen
3139 let winid = win_getid()
3140 wincmd p
3141 close
3142 call win_gotoid(winid)
3143 Xnext
3144 call assert_equal(3, winnr('$'))
3145 call assert_equal(1, winnr())
3146 call assert_equal(2, line('.'))
3147
3148 " When jumping to an entry in the location list window and the window
3149 " associated with the location list is not present and a window containing
3150 " the file is already present, then that window should be used.
3151 close
3152 belowright new
3153 call g:Xsetlist([], 'f')
3154 edit F3
3155 call win_gotoid(winid)
3156 Xlast
3157 call assert_equal(3, winnr())
3158 call assert_equal(6, g:Xgetlist({'size' : 1}).size)
3159 call assert_equal(winid, g:Xgetlist({'winid' : 1}).winid)
3160 endif
3161
3162 " Cleanup
3163 enew!
3164 new | only
3165
3166 call delete('F1')
3167 call delete('F2')
3168 call delete('F3')
3169endfunc
3170
3171func Test_qfjump()
3172 call Xqfjump_tests('c')
3173 call Xqfjump_tests('l')
3174endfunc
Bram Moolenaara6d48492017-12-12 22:45:31 +01003175
3176" Tests for the getqflist() and getloclist() functions when the list is not
3177" present or is empty
3178func Xgetlist_empty_tests(cchar)
3179 call s:setup_commands(a:cchar)
3180
3181 " Empty quickfix stack
3182 call g:Xsetlist([], 'f')
3183 call assert_equal('', g:Xgetlist({'context' : 0}).context)
3184 call assert_equal(0, g:Xgetlist({'id' : 0}).id)
3185 call assert_equal(0, g:Xgetlist({'idx' : 0}).idx)
3186 call assert_equal([], g:Xgetlist({'items' : 0}).items)
3187 call assert_equal(0, g:Xgetlist({'nr' : 0}).nr)
3188 call assert_equal(0, g:Xgetlist({'size' : 0}).size)
3189 call assert_equal('', g:Xgetlist({'title' : 0}).title)
3190 call assert_equal(0, g:Xgetlist({'winid' : 0}).winid)
Bram Moolenaarb254af32017-12-18 19:48:58 +01003191 call assert_equal(0, g:Xgetlist({'changedtick' : 0}).changedtick)
Bram Moolenaarc9cc9c72018-09-02 15:18:42 +02003192 if a:cchar == 'c'
3193 call assert_equal({'context' : '', 'id' : 0, 'idx' : 0,
Bram Moolenaar647e24b2019-03-17 16:39:46 +01003194 \ 'items' : [], 'nr' : 0, 'size' : 0, 'qfbufnr' : 0,
Bram Moolenaarc9cc9c72018-09-02 15:18:42 +02003195 \ 'title' : '', 'winid' : 0, 'changedtick': 0},
3196 \ g:Xgetlist({'all' : 0}))
3197 else
3198 call assert_equal({'context' : '', 'id' : 0, 'idx' : 0,
3199 \ 'items' : [], 'nr' : 0, 'size' : 0, 'title' : '',
Bram Moolenaar647e24b2019-03-17 16:39:46 +01003200 \ 'winid' : 0, 'changedtick': 0, 'filewinid' : 0,
3201 \ 'qfbufnr' : 0},
Bram Moolenaarc9cc9c72018-09-02 15:18:42 +02003202 \ g:Xgetlist({'all' : 0}))
3203 endif
Bram Moolenaara6d48492017-12-12 22:45:31 +01003204
Bram Moolenaar2ec364e2018-01-27 11:52:13 +01003205 " Quickfix window with empty stack
3206 silent! Xopen
3207 let qfwinid = (a:cchar == 'c') ? win_getid() : 0
Bram Moolenaar647e24b2019-03-17 16:39:46 +01003208 let qfbufnr = (a:cchar == 'c') ? bufnr('') : 0
Bram Moolenaar2ec364e2018-01-27 11:52:13 +01003209 call assert_equal(qfwinid, g:Xgetlist({'winid' : 0}).winid)
3210 Xclose
3211
Bram Moolenaara6d48492017-12-12 22:45:31 +01003212 " Empty quickfix list
3213 Xexpr ""
3214 call assert_equal('', g:Xgetlist({'context' : 0}).context)
3215 call assert_notequal(0, g:Xgetlist({'id' : 0}).id)
3216 call assert_equal(0, g:Xgetlist({'idx' : 0}).idx)
3217 call assert_equal([], g:Xgetlist({'items' : 0}).items)
3218 call assert_notequal(0, g:Xgetlist({'nr' : 0}).nr)
3219 call assert_equal(0, g:Xgetlist({'size' : 0}).size)
3220 call assert_notequal('', g:Xgetlist({'title' : 0}).title)
3221 call assert_equal(0, g:Xgetlist({'winid' : 0}).winid)
Bram Moolenaarb254af32017-12-18 19:48:58 +01003222 call assert_equal(1, g:Xgetlist({'changedtick' : 0}).changedtick)
Bram Moolenaara6d48492017-12-12 22:45:31 +01003223
3224 let qfid = g:Xgetlist({'id' : 0}).id
3225 call g:Xsetlist([], 'f')
3226
3227 " Non-existing quickfix identifier
3228 call assert_equal('', g:Xgetlist({'id' : qfid, 'context' : 0}).context)
3229 call assert_equal(0, g:Xgetlist({'id' : qfid}).id)
3230 call assert_equal(0, g:Xgetlist({'id' : qfid, 'idx' : 0}).idx)
3231 call assert_equal([], g:Xgetlist({'id' : qfid, 'items' : 0}).items)
3232 call assert_equal(0, g:Xgetlist({'id' : qfid, 'nr' : 0}).nr)
3233 call assert_equal(0, g:Xgetlist({'id' : qfid, 'size' : 0}).size)
3234 call assert_equal('', g:Xgetlist({'id' : qfid, 'title' : 0}).title)
3235 call assert_equal(0, g:Xgetlist({'id' : qfid, 'winid' : 0}).winid)
Bram Moolenaarb254af32017-12-18 19:48:58 +01003236 call assert_equal(0, g:Xgetlist({'id' : qfid, 'changedtick' : 0}).changedtick)
Bram Moolenaarc9cc9c72018-09-02 15:18:42 +02003237 if a:cchar == 'c'
3238 call assert_equal({'context' : '', 'id' : 0, 'idx' : 0, 'items' : [],
3239 \ 'nr' : 0, 'size' : 0, 'title' : '', 'winid' : 0,
Bram Moolenaar647e24b2019-03-17 16:39:46 +01003240 \ 'qfbufnr' : qfbufnr,
Bram Moolenaarc9cc9c72018-09-02 15:18:42 +02003241 \ 'changedtick' : 0}, g:Xgetlist({'id' : qfid, 'all' : 0}))
3242 else
3243 call assert_equal({'context' : '', 'id' : 0, 'idx' : 0, 'items' : [],
3244 \ 'nr' : 0, 'size' : 0, 'title' : '', 'winid' : 0,
Bram Moolenaar647e24b2019-03-17 16:39:46 +01003245 \ 'changedtick' : 0, 'filewinid' : 0, 'qfbufnr' : 0},
Bram Moolenaarc9cc9c72018-09-02 15:18:42 +02003246 \ g:Xgetlist({'id' : qfid, 'all' : 0}))
3247 endif
Bram Moolenaara6d48492017-12-12 22:45:31 +01003248
3249 " Non-existing quickfix list number
3250 call assert_equal('', g:Xgetlist({'nr' : 5, 'context' : 0}).context)
3251 call assert_equal(0, g:Xgetlist({'nr' : 5}).nr)
3252 call assert_equal(0, g:Xgetlist({'nr' : 5, 'idx' : 0}).idx)
3253 call assert_equal([], g:Xgetlist({'nr' : 5, 'items' : 0}).items)
3254 call assert_equal(0, g:Xgetlist({'nr' : 5, 'id' : 0}).id)
3255 call assert_equal(0, g:Xgetlist({'nr' : 5, 'size' : 0}).size)
3256 call assert_equal('', g:Xgetlist({'nr' : 5, 'title' : 0}).title)
3257 call assert_equal(0, g:Xgetlist({'nr' : 5, 'winid' : 0}).winid)
Bram Moolenaarb254af32017-12-18 19:48:58 +01003258 call assert_equal(0, g:Xgetlist({'nr' : 5, 'changedtick' : 0}).changedtick)
Bram Moolenaarc9cc9c72018-09-02 15:18:42 +02003259 if a:cchar == 'c'
3260 call assert_equal({'context' : '', 'id' : 0, 'idx' : 0, 'items' : [],
3261 \ 'nr' : 0, 'size' : 0, 'title' : '', 'winid' : 0,
Bram Moolenaar647e24b2019-03-17 16:39:46 +01003262 \ 'changedtick' : 0, 'qfbufnr' : qfbufnr},
3263 \ g:Xgetlist({'nr' : 5, 'all' : 0}))
Bram Moolenaarc9cc9c72018-09-02 15:18:42 +02003264 else
3265 call assert_equal({'context' : '', 'id' : 0, 'idx' : 0, 'items' : [],
3266 \ 'nr' : 0, 'size' : 0, 'title' : '', 'winid' : 0,
Bram Moolenaar647e24b2019-03-17 16:39:46 +01003267 \ 'changedtick' : 0, 'filewinid' : 0, 'qfbufnr' : 0},
Bram Moolenaarc9cc9c72018-09-02 15:18:42 +02003268 \ g:Xgetlist({'nr' : 5, 'all' : 0}))
3269 endif
Bram Moolenaara6d48492017-12-12 22:45:31 +01003270endfunc
3271
3272func Test_getqflist()
3273 call Xgetlist_empty_tests('c')
3274 call Xgetlist_empty_tests('l')
3275endfunc
Bram Moolenaarb254af32017-12-18 19:48:58 +01003276
Bram Moolenaara0ca7d02017-12-19 10:22:19 +01003277func Test_getqflist_invalid_nr()
3278 " The following commands used to crash Vim
3279 cexpr ""
3280 call getqflist({'nr' : $XXX_DOES_NOT_EXIST_XXX})
3281
3282 " Cleanup
3283 call setqflist([], 'r')
3284endfunc
3285
Bram Moolenaarb254af32017-12-18 19:48:58 +01003286" Tests for the quickfix/location list changedtick
3287func Xqftick_tests(cchar)
3288 call s:setup_commands(a:cchar)
3289
3290 call g:Xsetlist([], 'f')
3291
3292 Xexpr "F1:10:Line10"
3293 let qfid = g:Xgetlist({'id' : 0}).id
3294 call assert_equal(1, g:Xgetlist({'changedtick' : 0}).changedtick)
3295 Xaddexpr "F2:20:Line20\nF2:21:Line21"
3296 call assert_equal(2, g:Xgetlist({'changedtick' : 0}).changedtick)
3297 call g:Xsetlist([], 'a', {'lines' : ["F3:30:Line30", "F3:31:Line31"]})
3298 call assert_equal(3, g:Xgetlist({'changedtick' : 0}).changedtick)
3299 call g:Xsetlist([], 'r', {'lines' : ["F4:40:Line40"]})
3300 call assert_equal(4, g:Xgetlist({'changedtick' : 0}).changedtick)
3301 call g:Xsetlist([], 'a', {'title' : 'New Title'})
3302 call assert_equal(5, g:Xgetlist({'changedtick' : 0}).changedtick)
3303
3304 enew!
3305 call append(0, ["F5:50:L50", "F6:60:L60"])
3306 Xaddbuffer
3307 call assert_equal(6, g:Xgetlist({'changedtick' : 0}).changedtick)
3308 enew!
3309
3310 call g:Xsetlist([], 'a', {'context' : {'bus' : 'pci'}})
3311 call assert_equal(7, g:Xgetlist({'changedtick' : 0}).changedtick)
3312 call g:Xsetlist([{'filename' : 'F7', 'lnum' : 10, 'text' : 'L7'},
3313 \ {'filename' : 'F7', 'lnum' : 11, 'text' : 'L11'}], 'a')
3314 call assert_equal(8, g:Xgetlist({'changedtick' : 0}).changedtick)
3315 call g:Xsetlist([{'filename' : 'F7', 'lnum' : 10, 'text' : 'L7'},
3316 \ {'filename' : 'F7', 'lnum' : 11, 'text' : 'L11'}], ' ')
3317 call assert_equal(1, g:Xgetlist({'changedtick' : 0}).changedtick)
3318 call g:Xsetlist([{'filename' : 'F7', 'lnum' : 10, 'text' : 'L7'},
3319 \ {'filename' : 'F7', 'lnum' : 11, 'text' : 'L11'}], 'r')
3320 call assert_equal(2, g:Xgetlist({'changedtick' : 0}).changedtick)
3321
3322 call writefile(["F8:80:L80", "F8:81:L81"], "Xone")
3323 Xfile Xone
3324 call assert_equal(1, g:Xgetlist({'changedtick' : 0}).changedtick)
3325 Xaddfile Xone
3326 call assert_equal(2, g:Xgetlist({'changedtick' : 0}).changedtick)
3327
3328 " Test case for updating a non-current quickfix list
3329 call g:Xsetlist([], 'f')
3330 Xexpr "F1:1:L1"
3331 Xexpr "F2:2:L2"
3332 call g:Xsetlist([], 'a', {'nr' : 1, "lines" : ["F10:10:L10"]})
3333 call assert_equal(1, g:Xgetlist({'changedtick' : 0}).changedtick)
3334 call assert_equal(2, g:Xgetlist({'nr' : 1, 'changedtick' : 0}).changedtick)
3335
3336 call delete("Xone")
3337endfunc
3338
3339func Test_qf_tick()
3340 call Xqftick_tests('c')
3341 call Xqftick_tests('l')
3342endfunc
Bram Moolenaar12237442017-12-19 12:38:52 +01003343
Bram Moolenaarc631f2d2018-08-21 21:58:13 +02003344" Test helpgrep with lang specifier
3345func Xtest_helpgrep_with_lang_specifier(cchar)
3346 call s:setup_commands(a:cchar)
3347 Xhelpgrep Vim@en
3348 call assert_equal('help', &filetype)
3349 call assert_notequal(0, g:Xgetlist({'nr' : '$'}).nr)
3350 new | only
3351endfunc
3352
3353func Test_helpgrep_with_lang_specifier()
3354 call Xtest_helpgrep_with_lang_specifier('c')
3355 call Xtest_helpgrep_with_lang_specifier('l')
3356endfunc
3357
Bram Moolenaar12237442017-12-19 12:38:52 +01003358" The following test used to crash Vim.
3359" Open the location list window and close the regular window associated with
3360" the location list. When the garbage collection runs now, it incorrectly
3361" marks the location list context as not in use and frees the context.
3362func Test_ll_window_ctx()
3363 call setloclist(0, [], 'f')
3364 call setloclist(0, [], 'a', {'context' : []})
3365 lopen | only
3366 call test_garbagecollect_now()
3367 echo getloclist(0, {'context' : 1}).context
3368 enew | only
3369endfunc
3370
Bram Moolenaar14a4deb2017-12-19 16:48:55 +01003371" The following test used to crash vim
3372func Test_lfile_crash()
3373 sp Xtest
3374 au QuickFixCmdPre * bw
3375 call assert_fails('lfile', 'E40')
3376 au! QuickFixCmdPre
3377endfunc
Bram Moolenaar3c097222017-12-21 20:54:49 +01003378
3379" The following test used to crash vim
3380func Test_lbuffer_crash()
3381 sv Xtest
3382 augroup QF_Test
3383 au!
3384 au * * bw
3385 augroup END
3386 lbuffer
3387 augroup QF_Test
3388 au!
3389 augroup END
3390endfunc
3391
3392" The following test used to crash vim
3393func Test_lexpr_crash()
3394 augroup QF_Test
3395 au!
3396 au * * call setloclist(0, [], 'f')
3397 augroup END
3398 lexpr ""
3399 augroup QF_Test
3400 au!
3401 augroup END
Bram Moolenaar9f84ded2018-10-20 20:54:02 +02003402
Bram Moolenaar3c097222017-12-21 20:54:49 +01003403 enew | only
Bram Moolenaar9f84ded2018-10-20 20:54:02 +02003404 augroup QF_Test
3405 au!
3406 au BufNew * call setloclist(0, [], 'f')
3407 augroup END
3408 lexpr 'x:1:x'
3409 augroup QF_Test
3410 au!
3411 augroup END
3412
3413 enew | only
3414 lexpr ''
3415 lopen
3416 augroup QF_Test
3417 au!
3418 au FileType * call setloclist(0, [], 'f')
3419 augroup END
3420 lexpr ''
3421 augroup QF_Test
3422 au!
3423 augroup END
Bram Moolenaar3c097222017-12-21 20:54:49 +01003424endfunc
3425
3426" The following test used to crash Vim
3427func Test_lvimgrep_crash()
3428 sv Xtest
3429 augroup QF_Test
3430 au!
3431 au * * call setloclist(0, [], 'f')
3432 augroup END
3433 lvimgrep quickfix test_quickfix.vim
3434 augroup QF_Test
3435 au!
3436 augroup END
Bram Moolenaarb6f14802018-10-21 18:47:43 +02003437
3438 new | only
3439 augroup QF_Test
3440 au!
3441 au BufEnter * call setloclist(0, [], 'r')
3442 augroup END
3443 call assert_fails('lvimgrep Test_lvimgrep_crash *', 'E926:')
3444 augroup QF_Test
3445 au!
3446 augroup END
3447
Bram Moolenaar3c097222017-12-21 20:54:49 +01003448 enew | only
3449endfunc
Bram Moolenaarde046542017-12-26 13:53:11 +01003450
3451" Test for the position of the quickfix and location list window
3452func Test_qfwin_pos()
3453 " Open two windows
3454 new | only
3455 new
3456 cexpr ['F1:10:L10']
3457 copen
3458 " Quickfix window should be the bottom most window
3459 call assert_equal(3, winnr())
3460 close
3461 " Open at the very top
3462 wincmd t
3463 topleft copen
3464 call assert_equal(1, winnr())
3465 close
3466 " open left of the current window
3467 wincmd t
3468 below new
3469 leftabove copen
3470 call assert_equal(2, winnr())
3471 close
3472 " open right of the current window
3473 rightbelow copen
3474 call assert_equal(3, winnr())
3475 close
3476endfunc
Bram Moolenaare1bb8792018-04-06 22:58:23 +02003477
3478" Tests for quickfix/location lists changed by autocommands when
3479" :vimgrep/:lvimgrep commands are running.
3480func Test_vimgrep_autocmd()
3481 call setqflist([], 'f')
3482 call writefile(['stars'], 'Xtest1.txt')
3483 call writefile(['stars'], 'Xtest2.txt')
3484
3485 " Test 1:
3486 " When searching for a pattern using :vimgrep, if the quickfix list is
3487 " changed by an autocmd, the results should be added to the correct quickfix
3488 " list.
3489 autocmd BufRead Xtest2.txt cexpr '' | cexpr ''
3490 silent vimgrep stars Xtest*.txt
3491 call assert_equal(1, getqflist({'nr' : 0}).nr)
3492 call assert_equal(3, getqflist({'nr' : '$'}).nr)
3493 call assert_equal('Xtest2.txt', bufname(getqflist()[1].bufnr))
3494 au! BufRead Xtest2.txt
3495
3496 " Test 2:
3497 " When searching for a pattern using :vimgrep, if the quickfix list is
3498 " freed, then a error should be given.
3499 silent! %bwipe!
3500 call setqflist([], 'f')
3501 autocmd BufRead Xtest2.txt for i in range(10) | cexpr '' | endfor
3502 call assert_fails('vimgrep stars Xtest*.txt', 'E925:')
3503 au! BufRead Xtest2.txt
3504
3505 " Test 3:
3506 " When searching for a pattern using :lvimgrep, if the location list is
3507 " freed, then the command should error out.
3508 silent! %bwipe!
3509 let g:save_winid = win_getid()
3510 autocmd BufRead Xtest2.txt call setloclist(g:save_winid, [], 'f')
3511 call assert_fails('lvimgrep stars Xtest*.txt', 'E926:')
3512 au! BufRead Xtest2.txt
3513
3514 call delete('Xtest1.txt')
3515 call delete('Xtest2.txt')
3516 call setqflist([], 'f')
3517endfunc
Bram Moolenaar3b9474b2018-04-23 21:29:48 +02003518
3519" The following test used to crash Vim
3520func Test_lhelpgrep_autocmd()
3521 lhelpgrep quickfix
3522 autocmd QuickFixCmdPost * call setloclist(0, [], 'f')
3523 lhelpgrep buffer
3524 call assert_equal('help', &filetype)
3525 call assert_equal(0, getloclist(0, {'nr' : '$'}).nr)
3526 lhelpgrep tabpage
3527 call assert_equal('help', &filetype)
3528 call assert_equal(1, getloclist(0, {'nr' : '$'}).nr)
3529 au! QuickFixCmdPost
Bram Moolenaarb6f14802018-10-21 18:47:43 +02003530
3531 new | only
3532 augroup QF_Test
3533 au!
3534 au BufEnter * call setqflist([], 'f')
3535 augroup END
3536 call assert_fails('helpgrep quickfix', 'E925:')
3537 augroup QF_Test
3538 au! BufEnter
3539 augroup END
3540
3541 new | only
3542 augroup QF_Test
3543 au!
3544 au BufEnter * call setqflist([], 'r')
3545 augroup END
3546 call assert_fails('helpgrep quickfix', 'E925:')
3547 augroup QF_Test
3548 au! BufEnter
3549 augroup END
3550
3551 new | only
3552 augroup QF_Test
3553 au!
3554 au BufEnter * call setloclist(0, [], 'r')
3555 augroup END
3556 call assert_fails('lhelpgrep quickfix', 'E926:')
3557 augroup QF_Test
3558 au! BufEnter
3559 augroup END
3560
Bram Moolenaar3b9474b2018-04-23 21:29:48 +02003561 new | only
3562endfunc
Bram Moolenaara796d462018-05-01 14:30:36 +02003563
3564" Test for shortening/simplifying the file name when opening the
3565" quickfix window or when displaying the quickfix list
3566func Test_shorten_fname()
3567 if !has('unix')
3568 return
3569 endif
3570 %bwipe
3571 " Create a quickfix list with a absolute path filename
3572 let fname = getcwd() . '/test_quickfix.vim'
3573 call setqflist([], ' ', {'lines':[fname . ":20:Line20"], 'efm':'%f:%l:%m'})
3574 call assert_equal(fname, bufname('test_quickfix.vim'))
3575 " Opening the quickfix window should simplify the file path
3576 cwindow
3577 call assert_equal('test_quickfix.vim', bufname('test_quickfix.vim'))
3578 cclose
3579 %bwipe
3580 " Create a quickfix list with a absolute path filename
3581 call setqflist([], ' ', {'lines':[fname . ":20:Line20"], 'efm':'%f:%l:%m'})
3582 call assert_equal(fname, bufname('test_quickfix.vim'))
3583 " Displaying the quickfix list should simplify the file path
3584 silent! clist
3585 call assert_equal('test_quickfix.vim', bufname('test_quickfix.vim'))
3586endfunc
Bram Moolenaar8b62e312018-05-13 15:29:04 +02003587
3588" Quickfix title tests
3589" In the below tests, 'exe "cmd"' is used to invoke the quickfix commands.
3590" Otherwise due to indentation, the title is set with spaces at the beginning
3591" of the command.
3592func Test_qftitle()
3593 call writefile(["F1:1:Line1"], 'Xerr')
3594
3595 " :cexpr
3596 exe "cexpr readfile('Xerr')"
3597 call assert_equal(":cexpr readfile('Xerr')", getqflist({'title' : 1}).title)
3598
3599 " :cgetexpr
3600 exe "cgetexpr readfile('Xerr')"
3601 call assert_equal(":cgetexpr readfile('Xerr')",
3602 \ getqflist({'title' : 1}).title)
3603
3604 " :caddexpr
3605 call setqflist([], 'f')
3606 exe "caddexpr readfile('Xerr')"
3607 call assert_equal(":caddexpr readfile('Xerr')",
3608 \ getqflist({'title' : 1}).title)
3609
3610 " :cbuffer
3611 new Xerr
3612 exe "cbuffer"
3613 call assert_equal(':cbuffer (Xerr)', getqflist({'title' : 1}).title)
3614
3615 " :cgetbuffer
3616 edit Xerr
3617 exe "cgetbuffer"
3618 call assert_equal(':cgetbuffer (Xerr)', getqflist({'title' : 1}).title)
3619
3620 " :caddbuffer
3621 call setqflist([], 'f')
3622 edit Xerr
3623 exe "caddbuffer"
3624 call assert_equal(':caddbuffer (Xerr)', getqflist({'title' : 1}).title)
3625
3626 " :cfile
3627 exe "cfile Xerr"
3628 call assert_equal(':cfile Xerr', getqflist({'title' : 1}).title)
3629
3630 " :cgetfile
3631 exe "cgetfile Xerr"
3632 call assert_equal(':cgetfile Xerr', getqflist({'title' : 1}).title)
3633
3634 " :caddfile
3635 call setqflist([], 'f')
3636 exe "caddfile Xerr"
3637 call assert_equal(':caddfile Xerr', getqflist({'title' : 1}).title)
3638
3639 " :grep
3640 set grepprg=internal
3641 exe "grep F1 Xerr"
3642 call assert_equal(':grep F1 Xerr', getqflist({'title' : 1}).title)
3643
3644 " :grepadd
3645 call setqflist([], 'f')
3646 exe "grepadd F1 Xerr"
3647 call assert_equal(':grepadd F1 Xerr', getqflist({'title' : 1}).title)
3648 set grepprg&vim
3649
3650 " :vimgrep
3651 exe "vimgrep F1 Xerr"
3652 call assert_equal(':vimgrep F1 Xerr', getqflist({'title' : 1}).title)
3653
3654 " :vimgrepadd
3655 call setqflist([], 'f')
3656 exe "vimgrepadd F1 Xerr"
3657 call assert_equal(':vimgrepadd F1 Xerr', getqflist({'title' : 1}).title)
3658
3659 call setqflist(['F1:10:L10'], ' ')
3660 call assert_equal(':setqflist()', getqflist({'title' : 1}).title)
3661
3662 call setqflist([], 'f')
3663 call setqflist(['F1:10:L10'], 'a')
3664 call assert_equal(':setqflist()', getqflist({'title' : 1}).title)
3665
3666 call setqflist([], 'f')
3667 call setqflist(['F1:10:L10'], 'r')
3668 call assert_equal(':setqflist()', getqflist({'title' : 1}).title)
3669
3670 close
3671 call delete('Xerr')
3672
3673 call setqflist([], ' ', {'title' : 'Errors'})
3674 copen
3675 call assert_equal('Errors', w:quickfix_title)
3676 call setqflist([], 'r', {'items' : [{'filename' : 'a.c', 'lnum' : 10}]})
3677 call assert_equal('Errors', w:quickfix_title)
3678 cclose
3679endfunc
Bram Moolenaar600323b2018-06-16 22:16:47 +02003680
3681func Test_lbuffer_with_bwipe()
3682 new
3683 new
3684 augroup nasty
3685 au * * bwipe
3686 augroup END
3687 lbuffer
3688 augroup nasty
3689 au!
3690 augroup END
3691endfunc
Bram Moolenaar0366c012018-06-18 20:52:13 +02003692
Bram Moolenaar531b9a32018-07-03 16:54:23 +02003693" Test for an autocmd freeing the quickfix/location list when cexpr/lexpr is
3694" running
3695func Xexpr_acmd_freelist(cchar)
3696 call s:setup_commands(a:cchar)
3697
Bram Moolenaar0366c012018-06-18 20:52:13 +02003698 " This was using freed memory.
3699 augroup nasty
Bram Moolenaar531b9a32018-07-03 16:54:23 +02003700 au * * call g:Xsetlist([], 'f')
Bram Moolenaar0366c012018-06-18 20:52:13 +02003701 augroup END
Bram Moolenaar531b9a32018-07-03 16:54:23 +02003702 Xexpr "x"
Bram Moolenaar0366c012018-06-18 20:52:13 +02003703 augroup nasty
3704 au!
3705 augroup END
3706endfunc
Bram Moolenaar531b9a32018-07-03 16:54:23 +02003707
3708func Test_cexpr_acmd_freelist()
3709 call Xexpr_acmd_freelist('c')
3710 call Xexpr_acmd_freelist('l')
3711endfunc
3712
3713" Test for commands that create a new quickfix/location list and jump to the
3714" first error automatically.
3715func Xjumpto_first_error_test(cchar)
3716 call s:setup_commands(a:cchar)
3717
3718 call s:create_test_file('Xtestfile1')
3719 call s:create_test_file('Xtestfile2')
3720 let l = ['Xtestfile1:2:Line2', 'Xtestfile2:4:Line4']
3721
3722 " Test for cexpr/lexpr
3723 enew
3724 Xexpr l
3725 call assert_equal('Xtestfile1', bufname(''))
3726 call assert_equal(2, line('.'))
3727
3728 " Test for cfile/lfile
3729 enew
3730 call writefile(l, 'Xerr')
3731 Xfile Xerr
3732 call assert_equal('Xtestfile1', bufname(''))
3733 call assert_equal(2, line('.'))
3734
3735 " Test for cbuffer/lbuffer
3736 edit Xerr
3737 Xbuffer
3738 call assert_equal('Xtestfile1', bufname(''))
3739 call assert_equal(2, line('.'))
3740
3741 call delete('Xerr')
3742 call delete('Xtestfile1')
3743 call delete('Xtestfile2')
3744endfunc
3745
3746func Test_jumpto_first_error()
3747 call Xjumpto_first_error_test('c')
3748 call Xjumpto_first_error_test('l')
3749endfunc
3750
3751" Test for a quickfix autocmd changing the quickfix/location list before
3752" jumping to the first error in the new list.
3753func Xautocmd_changelist(cchar)
3754 call s:setup_commands(a:cchar)
3755
3756 " Test for cfile/lfile
3757 call s:create_test_file('Xtestfile1')
3758 call s:create_test_file('Xtestfile2')
3759 Xexpr 'Xtestfile1:2:Line2'
3760 autocmd QuickFixCmdPost * Xolder
3761 call writefile(['Xtestfile2:4:Line4'], 'Xerr')
3762 Xfile Xerr
3763 call assert_equal('Xtestfile2', bufname(''))
3764 call assert_equal(4, line('.'))
3765 autocmd! QuickFixCmdPost
3766
3767 " Test for cbuffer/lbuffer
3768 call g:Xsetlist([], 'f')
3769 Xexpr 'Xtestfile1:2:Line2'
3770 autocmd QuickFixCmdPost * Xolder
3771 call writefile(['Xtestfile2:4:Line4'], 'Xerr')
3772 edit Xerr
3773 Xbuffer
3774 call assert_equal('Xtestfile2', bufname(''))
3775 call assert_equal(4, line('.'))
3776 autocmd! QuickFixCmdPost
3777
3778 " Test for cexpr/lexpr
3779 call g:Xsetlist([], 'f')
3780 Xexpr 'Xtestfile1:2:Line2'
3781 autocmd QuickFixCmdPost * Xolder
3782 Xexpr 'Xtestfile2:4:Line4'
3783 call assert_equal('Xtestfile2', bufname(''))
3784 call assert_equal(4, line('.'))
3785 autocmd! QuickFixCmdPost
3786
Bram Moolenaar851332e2018-07-03 19:16:00 +02003787 " The grepprg may not be set on non-Unix systems
3788 if has('unix')
3789 " Test for grep/lgrep
3790 call g:Xsetlist([], 'f')
3791 Xexpr 'Xtestfile1:2:Line2'
3792 autocmd QuickFixCmdPost * Xolder
3793 silent Xgrep Line5 Xtestfile2
3794 call assert_equal('Xtestfile2', bufname(''))
3795 call assert_equal(5, line('.'))
3796 autocmd! QuickFixCmdPost
3797 endif
Bram Moolenaar531b9a32018-07-03 16:54:23 +02003798
3799 " Test for vimgrep/lvimgrep
3800 call g:Xsetlist([], 'f')
3801 Xexpr 'Xtestfile1:2:Line2'
3802 autocmd QuickFixCmdPost * Xolder
3803 silent Xvimgrep Line5 Xtestfile2
3804 call assert_equal('Xtestfile2', bufname(''))
3805 call assert_equal(5, line('.'))
3806 autocmd! QuickFixCmdPost
3807
Bram Moolenaar3f347e42018-08-09 21:19:20 +02003808 " Test for autocommands clearing the quickfix list before jumping to the
3809 " first error. This should not result in an error
3810 autocmd QuickFixCmdPost * call g:Xsetlist([], 'r')
3811 let v:errmsg = ''
3812 " Test for cfile/lfile
3813 Xfile Xerr
3814 call assert_true(v:errmsg !~# 'E42:')
3815 " Test for cbuffer/lbuffer
3816 edit Xerr
3817 Xbuffer
3818 call assert_true(v:errmsg !~# 'E42:')
3819 " Test for cexpr/lexpr
3820 Xexpr 'Xtestfile2:4:Line4'
3821 call assert_true(v:errmsg !~# 'E42:')
3822 " Test for grep/lgrep
3823 " The grepprg may not be set on non-Unix systems
3824 if has('unix')
3825 silent Xgrep Line5 Xtestfile2
3826 call assert_true(v:errmsg !~# 'E42:')
3827 endif
3828 " Test for vimgrep/lvimgrep
3829 call assert_fails('silent Xvimgrep Line5 Xtestfile2', 'E480:')
3830 autocmd! QuickFixCmdPost
3831
Bram Moolenaar531b9a32018-07-03 16:54:23 +02003832 call delete('Xerr')
3833 call delete('Xtestfile1')
3834 call delete('Xtestfile2')
3835endfunc
3836
3837func Test_autocmd_changelist()
3838 call Xautocmd_changelist('c')
3839 call Xautocmd_changelist('l')
3840endfunc
Bram Moolenaar4cde86c2018-07-08 16:01:08 +02003841
3842" Tests for the ':filter /pat/ clist' command
3843func Test_filter_clist()
3844 cexpr ['Xfile1:10:10:Line 10', 'Xfile2:15:15:Line 15']
3845 call assert_equal([' 2 Xfile2:15 col 15: Line 15'],
3846 \ split(execute('filter /Line 15/ clist'), "\n"))
3847 call assert_equal([' 1 Xfile1:10 col 10: Line 10'],
3848 \ split(execute('filter /Xfile1/ clist'), "\n"))
3849 call assert_equal([], split(execute('filter /abc/ clist'), "\n"))
3850
3851 call setqflist([{'module' : 'abc', 'pattern' : 'pat1'},
3852 \ {'module' : 'pqr', 'pattern' : 'pat2'}], ' ')
3853 call assert_equal([' 2 pqr:pat2: '],
3854 \ split(execute('filter /pqr/ clist'), "\n"))
3855 call assert_equal([' 1 abc:pat1: '],
3856 \ split(execute('filter /pat1/ clist'), "\n"))
3857endfunc
Bram Moolenaar0a08c632018-07-25 22:36:52 +02003858
3859" Tests for the "CTRL-W <CR>" command.
3860func Xview_result_split_tests(cchar)
3861 call s:setup_commands(a:cchar)
3862
3863 " Test that "CTRL-W <CR>" in a qf/ll window fails with empty list.
3864 call g:Xsetlist([])
3865 Xopen
3866 let l:win_count = winnr('$')
3867 call assert_fails('execute "normal! \<C-W>\<CR>"', 'E42')
3868 call assert_equal(l:win_count, winnr('$'))
3869 Xclose
3870endfunc
3871
3872func Test_view_result_split()
3873 call Xview_result_split_tests('c')
3874 call Xview_result_split_tests('l')
3875endfunc
Bram Moolenaar2dfcef42018-08-15 22:29:51 +02003876
3877" Test that :cc sets curswant
3878func Test_curswant()
3879 helpgrep quickfix
3880 normal! llll
3881 1cc
3882 call assert_equal(getcurpos()[4], virtcol('.'))
3883 cclose | helpclose
3884endfunc
Bram Moolenaarb2443732018-11-11 22:50:27 +01003885
3886" Test for opening a file from the quickfix window using CTRL-W <Enter>
3887" doesn't leave an empty buffer around.
3888func Test_splitview()
3889 call s:create_test_file('Xtestfile1')
3890 call s:create_test_file('Xtestfile2')
3891 new | only
3892 let last_bufnr = bufnr('Test_sv_1', 1)
3893 let l = ['Xtestfile1:2:Line2', 'Xtestfile2:4:Line4']
3894 cgetexpr l
3895 copen
3896 let numbufs = len(getbufinfo())
3897 exe "normal \<C-W>\<CR>"
3898 copen
3899 exe "normal j\<C-W>\<CR>"
3900 " Make sure new empty buffers are not created
3901 call assert_equal(numbufs, len(getbufinfo()))
3902 " Creating a new buffer should use the next available buffer number
3903 call assert_equal(last_bufnr + 4, bufnr("Test_sv_2", 1))
3904 bwipe Test_sv_1
3905 bwipe Test_sv_2
3906 new | only
3907
3908 " When split opening files from location list window, make sure that two
3909 " windows doesn't refer to the same location list
3910 lgetexpr l
3911 let locid = getloclist(0, {'id' : 0}).id
3912 lopen
3913 exe "normal \<C-W>\<CR>"
3914 call assert_notequal(locid, getloclist(0, {'id' : 0}).id)
3915 call assert_equal(0, getloclist(0, {'winid' : 0}).winid)
3916 new | only
3917
3918 " When split opening files from a helpgrep location list window, a new help
Bram Moolenaareeb1b9c2019-02-10 22:59:04 +01003919 " window should be opened with a copy of the location list.
Bram Moolenaarb2443732018-11-11 22:50:27 +01003920 lhelpgrep window
3921 let locid = getloclist(0, {'id' : 0}).id
3922 lwindow
3923 exe "normal j\<C-W>\<CR>"
3924 call assert_notequal(locid, getloclist(0, {'id' : 0}).id)
3925 call assert_equal(0, getloclist(0, {'winid' : 0}).winid)
3926 new | only
3927
3928 call delete('Xtestfile1')
3929 call delete('Xtestfile2')
3930endfunc
Bram Moolenaarc45eb772019-01-31 14:27:04 +01003931
3932" Test for parsing entries using visual screen column
3933func Test_viscol()
3934 enew
3935 call writefile(["Col1\tCol2\tCol3"], 'Xfile1')
3936 edit Xfile1
3937
3938 " Use byte offset for column number
3939 set efm&
3940 cexpr "Xfile1:1:5:XX\nXfile1:1:9:YY\nXfile1:1:20:ZZ"
3941 call assert_equal([5, 8], [col('.'), virtcol('.')])
3942 cnext
3943 call assert_equal([9, 12], [col('.'), virtcol('.')])
3944 cnext
3945 call assert_equal([14, 20], [col('.'), virtcol('.')])
3946
3947 " Use screen column offset for column number
3948 set efm=%f:%l:%v:%m
3949 cexpr "Xfile1:1:8:XX\nXfile1:1:12:YY\nXfile1:1:20:ZZ"
3950 call assert_equal([5, 8], [col('.'), virtcol('.')])
3951 cnext
3952 call assert_equal([9, 12], [col('.'), virtcol('.')])
3953 cnext
3954 call assert_equal([14, 20], [col('.'), virtcol('.')])
3955 cexpr "Xfile1:1:6:XX\nXfile1:1:15:YY\nXfile1:1:24:ZZ"
3956 call assert_equal([5, 8], [col('.'), virtcol('.')])
3957 cnext
3958 call assert_equal([10, 16], [col('.'), virtcol('.')])
3959 cnext
3960 call assert_equal([14, 20], [col('.'), virtcol('.')])
3961
3962 enew
3963 call writefile(["Col1\täü\töß\tCol4"], 'Xfile1')
3964
3965 " Use byte offset for column number
3966 set efm&
3967 cexpr "Xfile1:1:8:XX\nXfile1:1:11:YY\nXfile1:1:16:ZZ"
3968 call assert_equal([8, 10], [col('.'), virtcol('.')])
3969 cnext
3970 call assert_equal([11, 17], [col('.'), virtcol('.')])
3971 cnext
3972 call assert_equal([16, 25], [col('.'), virtcol('.')])
3973
3974 " Use screen column offset for column number
3975 set efm=%f:%l:%v:%m
3976 cexpr "Xfile1:1:10:XX\nXfile1:1:17:YY\nXfile1:1:25:ZZ"
3977 call assert_equal([8, 10], [col('.'), virtcol('.')])
3978 cnext
3979 call assert_equal([11, 17], [col('.'), virtcol('.')])
3980 cnext
3981 call assert_equal([16, 25], [col('.'), virtcol('.')])
3982
3983 enew | only
3984 set efm&
3985 call delete('Xfile1')
3986endfunc
Bram Moolenaaree8188f2019-02-05 21:23:04 +01003987
3988" Test for the quickfix window buffer
3989func Xqfbuf_test(cchar)
3990 call s:setup_commands(a:cchar)
3991
3992 " Quickfix buffer should be reused across closing and opening a quickfix
3993 " window
3994 Xexpr "F1:10:Line10"
3995 Xopen
3996 let qfbnum = bufnr('')
3997 Xclose
3998 " Even after the quickfix window is closed, the buffer should be loaded
3999 call assert_true(bufloaded(qfbnum))
Bram Moolenaar647e24b2019-03-17 16:39:46 +01004000 call assert_true(qfbnum, g:Xgetlist({'qfbufnr' : 0}).qfbufnr)
Bram Moolenaaree8188f2019-02-05 21:23:04 +01004001 Xopen
4002 " Buffer should be reused when opening the window again
4003 call assert_equal(qfbnum, bufnr(''))
4004 Xclose
4005
4006 if a:cchar == 'l'
4007 %bwipe
4008 " For a location list, when both the file window and the location list
4009 " window for the list are closed, then the buffer should be freed.
4010 new | only
4011 lexpr "F1:10:Line10"
4012 let wid = win_getid()
4013 lopen
4014 let qfbnum = bufnr('')
4015 call assert_match(qfbnum . ' %a- "\[Location List]"', execute('ls'))
4016 close
4017 " When the location list window is closed, the buffer name should not
4018 " change to 'Quickfix List'
Bram Moolenaar647e24b2019-03-17 16:39:46 +01004019 call assert_match(qfbnum . 'u h- "\[Location List]"', execute('ls!'))
Bram Moolenaaree8188f2019-02-05 21:23:04 +01004020 call assert_true(bufloaded(qfbnum))
4021
Bram Moolenaard82a81c2019-03-02 07:57:18 +01004022 " After deleting a location list buffer using ":bdelete", opening the
4023 " location list window should mark the buffer as a location list buffer.
4024 exe "bdelete " . qfbnum
4025 lopen
4026 call assert_equal("quickfix", &buftype)
4027 call assert_equal(1, getwininfo(win_getid(winnr()))[0].loclist)
4028 call assert_equal(wid, getloclist(0, {'filewinid' : 0}).filewinid)
4029 call assert_false(&swapfile)
4030 lclose
4031
Bram Moolenaareeb1b9c2019-02-10 22:59:04 +01004032 " When the location list is cleared for the window, the buffer should be
4033 " removed
4034 call setloclist(0, [], 'f')
4035 call assert_false(bufexists(qfbnum))
Bram Moolenaar647e24b2019-03-17 16:39:46 +01004036 call assert_equal(0, getloclist(0, {'qfbufnr' : 0}).qfbufnr)
Bram Moolenaareeb1b9c2019-02-10 22:59:04 +01004037
4038 " When the location list is freed with the location list window open, the
4039 " location list buffer should not be lost. It should be reused when the
4040 " location list is again populated.
4041 lexpr "F1:10:Line10"
4042 lopen
4043 let wid = win_getid()
4044 let qfbnum = bufnr('')
4045 wincmd p
4046 call setloclist(0, [], 'f')
4047 lexpr "F1:10:Line10"
4048 lopen
4049 call assert_equal(wid, win_getid())
4050 call assert_equal(qfbnum, bufnr(''))
4051 lclose
4052
4053 " When the window with the location list is closed, the buffer should be
4054 " removed
Bram Moolenaaree8188f2019-02-05 21:23:04 +01004055 new | only
Bram Moolenaareeb1b9c2019-02-10 22:59:04 +01004056 call assert_false(bufexists(qfbnum))
Bram Moolenaaree8188f2019-02-05 21:23:04 +01004057 endif
4058endfunc
4059
4060func Test_qfbuf()
4061 call Xqfbuf_test('c')
4062 call Xqfbuf_test('l')
4063endfunc
Bram Moolenaareeb1b9c2019-02-10 22:59:04 +01004064
4065" If there is an autocmd to use only one window, then opening the location
4066" list window used to crash Vim.
4067func Test_winonly_autocmd()
4068 call s:create_test_file('Xtest1')
4069 " Autocmd to show only one Vim window at a time
4070 autocmd WinEnter * only
4071 new
4072 " Load the location list
4073 lexpr "Xtest1:5:Line5\nXtest1:10:Line10\nXtest1:15:Line15"
4074 let loclistid = getloclist(0, {'id' : 0}).id
4075 " Open the location list window. Only this window will be shown and the file
4076 " window is closed.
4077 lopen
4078 call assert_equal(loclistid, getloclist(0, {'id' : 0}).id)
4079 " Jump to an entry in the location list and make sure that the cursor is
4080 " positioned correctly.
4081 ll 3
4082 call assert_equal(loclistid, getloclist(0, {'id' : 0}).id)
4083 call assert_equal('Xtest1', bufname(''))
4084 call assert_equal(15, line('.'))
4085 " Cleanup
4086 autocmd! WinEnter
4087 new | only
4088 call delete('Xtest1')
4089endfunc
Bram Moolenaar39803d82019-04-07 12:04:51 +02004090
4091" Test to make sure that an empty quickfix buffer is not reused for loading
4092" a normal buffer.
4093func Test_empty_qfbuf()
4094 enew | only
4095 call writefile(["Test"], 'Xfile1')
4096 call setqflist([], 'f')
4097 copen | only
4098 let qfbuf = bufnr('')
4099 edit Xfile1
4100 call assert_notequal(qfbuf, bufnr(''))
4101 enew
4102 call delete('Xfile1')
4103endfunc
Bram Moolenaar3ff33112019-05-03 21:56:35 +02004104
4105" Test for the :cbelow, :cabove, :lbelow and :labove commands.
Bram Moolenaarcf6a55c2019-05-05 15:02:30 +02004106" And for the :cafter, :cbefore, :lafter and :lbefore commands.
Bram Moolenaar3ff33112019-05-03 21:56:35 +02004107func Xtest_below(cchar)
4108 call s:setup_commands(a:cchar)
4109
4110 " No quickfix/location list
4111 call assert_fails('Xbelow', 'E42:')
4112 call assert_fails('Xabove', 'E42:')
Bram Moolenaarcf6a55c2019-05-05 15:02:30 +02004113 call assert_fails('Xbefore', 'E42:')
4114 call assert_fails('Xafter', 'E42:')
Bram Moolenaar3ff33112019-05-03 21:56:35 +02004115
4116 " Empty quickfix/location list
4117 call g:Xsetlist([])
4118 call assert_fails('Xbelow', 'E42:')
4119 call assert_fails('Xabove', 'E42:')
Bram Moolenaarcf6a55c2019-05-05 15:02:30 +02004120 call assert_fails('Xbefore', 'E42:')
4121 call assert_fails('Xafter', 'E42:')
Bram Moolenaar3ff33112019-05-03 21:56:35 +02004122
4123 call s:create_test_file('X1')
4124 call s:create_test_file('X2')
4125 call s:create_test_file('X3')
4126 call s:create_test_file('X4')
4127
4128 " Invalid entries
4129 edit X1
4130 call g:Xsetlist(["E1", "E2"])
4131 call assert_fails('Xbelow', 'E42:')
4132 call assert_fails('Xabove', 'E42:')
4133 call assert_fails('3Xbelow', 'E42:')
4134 call assert_fails('4Xabove', 'E42:')
Bram Moolenaarcf6a55c2019-05-05 15:02:30 +02004135 call assert_fails('Xbefore', 'E42:')
4136 call assert_fails('Xafter', 'E42:')
4137 call assert_fails('3Xbefore', 'E42:')
4138 call assert_fails('4Xafter', 'E42:')
Bram Moolenaar3ff33112019-05-03 21:56:35 +02004139
4140 " Test the commands with various arguments
Bram Moolenaarcf6a55c2019-05-05 15:02:30 +02004141 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 +02004142 edit +7 X2
4143 Xabove
4144 call assert_equal(['X2', 5], [bufname(''), line('.')])
4145 call assert_fails('Xabove', 'E553:')
Bram Moolenaarcf6a55c2019-05-05 15:02:30 +02004146 normal 7G
4147 Xbefore
4148 call assert_equal(['X2', 5, 2], [bufname(''), line('.'), col('.')])
4149 call assert_fails('Xbefore', 'E553:')
4150
Bram Moolenaar3ff33112019-05-03 21:56:35 +02004151 normal 2j
4152 Xbelow
4153 call assert_equal(['X2', 10], [bufname(''), line('.')])
Bram Moolenaarcf6a55c2019-05-05 15:02:30 +02004154 normal 7G
4155 Xafter
4156 call assert_equal(['X2', 10, 3], [bufname(''), line('.'), col('.')])
4157
Bram Moolenaar3ff33112019-05-03 21:56:35 +02004158 " Last error in this file
4159 Xbelow 99
4160 call assert_equal(['X2', 15], [bufname(''), line('.')])
4161 call assert_fails('Xbelow', 'E553:')
Bram Moolenaarcf6a55c2019-05-05 15:02:30 +02004162 normal gg
4163 Xafter 99
4164 call assert_equal(['X2', 15, 4], [bufname(''), line('.'), col('.')])
4165 call assert_fails('Xafter', 'E553:')
4166
Bram Moolenaar3ff33112019-05-03 21:56:35 +02004167 " First error in this file
4168 Xabove 99
4169 call assert_equal(['X2', 5], [bufname(''), line('.')])
4170 call assert_fails('Xabove', 'E553:')
Bram Moolenaarcf6a55c2019-05-05 15:02:30 +02004171 normal G
4172 Xbefore 99
4173 call assert_equal(['X2', 5, 2], [bufname(''), line('.'), col('.')])
4174 call assert_fails('Xbefore', 'E553:')
4175
Bram Moolenaar3ff33112019-05-03 21:56:35 +02004176 normal gg
4177 Xbelow 2
4178 call assert_equal(['X2', 10], [bufname(''), line('.')])
Bram Moolenaarcf6a55c2019-05-05 15:02:30 +02004179 normal gg
4180 Xafter 2
4181 call assert_equal(['X2', 10, 3], [bufname(''), line('.'), col('.')])
4182
Bram Moolenaar3ff33112019-05-03 21:56:35 +02004183 normal G
4184 Xabove 2
4185 call assert_equal(['X2', 10], [bufname(''), line('.')])
Bram Moolenaarcf6a55c2019-05-05 15:02:30 +02004186 normal G
4187 Xbefore 2
4188 call assert_equal(['X2', 10, 3], [bufname(''), line('.'), col('.')])
4189
Bram Moolenaar3ff33112019-05-03 21:56:35 +02004190 edit X4
4191 call assert_fails('Xabove', 'E42:')
4192 call assert_fails('Xbelow', 'E42:')
Bram Moolenaarcf6a55c2019-05-05 15:02:30 +02004193 call assert_fails('Xbefore', 'E42:')
4194 call assert_fails('Xafter', 'E42:')
Bram Moolenaar3ff33112019-05-03 21:56:35 +02004195 if a:cchar == 'l'
4196 " If a buffer has location list entries from some other window but not
4197 " from the current window, then the commands should fail.
4198 edit X1 | split | call setloclist(0, [], 'f')
4199 call assert_fails('Xabove', 'E776:')
4200 call assert_fails('Xbelow', 'E776:')
Bram Moolenaarcf6a55c2019-05-05 15:02:30 +02004201 call assert_fails('Xbefore', 'E776:')
4202 call assert_fails('Xafter', 'E776:')
Bram Moolenaar3ff33112019-05-03 21:56:35 +02004203 close
4204 endif
4205
4206 " Test for lines with multiple quickfix entries
4207 Xexpr ["X1:5:L5", "X2:5:1:L5_1", "X2:5:2:L5_2", "X2:5:3:L5_3",
4208 \ "X2:10:1:L10_1", "X2:10:2:L10_2", "X2:10:3:L10_3",
4209 \ "X2:15:1:L15_1", "X2:15:2:L15_2", "X2:15:3:L15_3", "X3:3:L3"]
4210 edit +1 X2
4211 Xbelow 2
4212 call assert_equal(['X2', 10, 1], [bufname(''), line('.'), col('.')])
Bram Moolenaarcf6a55c2019-05-05 15:02:30 +02004213 normal 1G
4214 Xafter 2
4215 call assert_equal(['X2', 5, 2], [bufname(''), line('.'), col('.')])
4216
Bram Moolenaar3ff33112019-05-03 21:56:35 +02004217 normal gg
4218 Xbelow 99
4219 call assert_equal(['X2', 15, 1], [bufname(''), line('.'), col('.')])
Bram Moolenaarcf6a55c2019-05-05 15:02:30 +02004220 normal gg
4221 Xafter 99
4222 call assert_equal(['X2', 15, 3], [bufname(''), line('.'), col('.')])
4223
Bram Moolenaar3ff33112019-05-03 21:56:35 +02004224 normal G
4225 Xabove 2
4226 call assert_equal(['X2', 10, 1], [bufname(''), line('.'), col('.')])
4227 normal G
Bram Moolenaarcf6a55c2019-05-05 15:02:30 +02004228 Xbefore 2
4229 call assert_equal(['X2', 15, 2], [bufname(''), line('.'), col('.')])
4230
4231 normal G
Bram Moolenaar3ff33112019-05-03 21:56:35 +02004232 Xabove 99
4233 call assert_equal(['X2', 5, 1], [bufname(''), line('.'), col('.')])
Bram Moolenaarcf6a55c2019-05-05 15:02:30 +02004234 normal G
4235 Xbefore 99
4236 call assert_equal(['X2', 5, 1], [bufname(''), line('.'), col('.')])
4237
Bram Moolenaar3ff33112019-05-03 21:56:35 +02004238 normal 10G
4239 Xabove
4240 call assert_equal(['X2', 5, 1], [bufname(''), line('.'), col('.')])
Bram Moolenaarcf6a55c2019-05-05 15:02:30 +02004241 normal 10G$
4242 2Xbefore
4243 call assert_equal(['X2', 10, 2], [bufname(''), line('.'), col('.')])
4244
Bram Moolenaar3ff33112019-05-03 21:56:35 +02004245 normal 10G
4246 Xbelow
4247 call assert_equal(['X2', 15, 1], [bufname(''), line('.'), col('.')])
Bram Moolenaarcf6a55c2019-05-05 15:02:30 +02004248 normal 9G
4249 5Xafter
4250 call assert_equal(['X2', 15, 2], [bufname(''), line('.'), col('.')])
Bram Moolenaar3ff33112019-05-03 21:56:35 +02004251
4252 " Invalid range
4253 if a:cchar == 'c'
Bram Moolenaar25190db2019-05-04 15:05:28 +02004254 call assert_fails('-2cbelow', 'E16:')
Bram Moolenaarcf6a55c2019-05-05 15:02:30 +02004255 call assert_fails('-2cafter', 'E16:')
Bram Moolenaar3ff33112019-05-03 21:56:35 +02004256 else
Bram Moolenaar25190db2019-05-04 15:05:28 +02004257 call assert_fails('-2lbelow', 'E16:')
Bram Moolenaarcf6a55c2019-05-05 15:02:30 +02004258 call assert_fails('-2lafter', 'E16:')
Bram Moolenaar3ff33112019-05-03 21:56:35 +02004259 endif
4260
4261 call delete('X1')
4262 call delete('X2')
4263 call delete('X3')
4264 call delete('X4')
4265endfunc
4266
4267func Test_cbelow()
4268 call Xtest_below('c')
4269 call Xtest_below('l')
4270endfunc
Bram Moolenaar25190db2019-05-04 15:05:28 +02004271
4272func Test_quickfix_count()
4273 let commands = [
4274 \ 'cNext',
4275 \ 'cNfile',
4276 \ 'cabove',
4277 \ 'cbelow',
4278 \ 'cfirst',
4279 \ 'clast',
4280 \ 'cnewer',
4281 \ 'cnext',
4282 \ 'cnfile',
4283 \ 'colder',
4284 \ 'cprevious',
4285 \ 'crewind',
4286 \
4287 \ 'lNext',
4288 \ 'lNfile',
4289 \ 'labove',
4290 \ 'lbelow',
4291 \ 'lfirst',
4292 \ 'llast',
4293 \ 'lnewer',
4294 \ 'lnext',
4295 \ 'lnfile',
4296 \ 'lolder',
4297 \ 'lprevious',
4298 \ 'lrewind',
4299 \ ]
4300 for cmd in commands
4301 call assert_fails('-1' .. cmd, 'E16:')
4302 call assert_fails('.' .. cmd, 'E16:')
4303 call assert_fails('%' .. cmd, 'E16:')
4304 call assert_fails('$' .. cmd, 'E16:')
4305 endfor
4306endfunc