blob: f2403986bf56a2cdf357c4805b69de488920d5cb [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 Moolenaar7eba3d22016-03-19 22:54:09 +01006set encoding=utf-8
7
Bram Moolenaar2b946c92016-11-12 18:14:44 +01008func s:setup_commands(cchar)
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02009 if a:cchar == 'c'
10 command! -nargs=* -bang Xlist <mods>clist<bang> <args>
11 command! -nargs=* Xgetexpr <mods>cgetexpr <args>
Bram Moolenaar361c8f02016-07-02 15:41:47 +020012 command! -nargs=* Xaddexpr <mods>caddexpr <args>
Bram Moolenaar55b69262017-08-13 13:42:01 +020013 command! -nargs=* -count Xolder <mods><count>colder <args>
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +020014 command! -nargs=* Xnewer <mods>cnewer <args>
15 command! -nargs=* Xopen <mods>copen <args>
16 command! -nargs=* Xwindow <mods>cwindow <args>
Bram Moolenaar537ef082016-07-09 17:56:19 +020017 command! -nargs=* Xbottom <mods>cbottom <args>
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +020018 command! -nargs=* Xclose <mods>cclose <args>
19 command! -nargs=* -bang Xfile <mods>cfile<bang> <args>
20 command! -nargs=* Xgetfile <mods>cgetfile <args>
21 command! -nargs=* Xaddfile <mods>caddfile <args>
22 command! -nargs=* -bang Xbuffer <mods>cbuffer<bang> <args>
23 command! -nargs=* Xgetbuffer <mods>cgetbuffer <args>
24 command! -nargs=* Xaddbuffer <mods>caddbuffer <args>
25 command! -nargs=* Xrewind <mods>crewind <args>
Bram Moolenaar99895ea2017-04-20 22:44:47 +020026 command! -count -nargs=* -bang Xnext <mods><count>cnext<bang> <args>
27 command! -count -nargs=* -bang Xprev <mods><count>cprev<bang> <args>
Bram Moolenaar0fcc7c62016-07-02 21:22:52 +020028 command! -nargs=* -bang Xfirst <mods>cfirst<bang> <args>
29 command! -nargs=* -bang Xlast <mods>clast<bang> <args>
Bram Moolenaar25190db2019-05-04 15:05:28 +020030 command! -count -nargs=* -bang Xnfile <mods><count>cnfile<bang> <args>
Bram Moolenaar0fcc7c62016-07-02 21:22:52 +020031 command! -nargs=* -bang Xpfile <mods>cpfile<bang> <args>
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +020032 command! -nargs=* Xexpr <mods>cexpr <args>
Bram Moolenaaree85df32017-03-19 14:19:50 +010033 command! -range -nargs=* Xvimgrep <mods><count>vimgrep <args>
34 command! -nargs=* Xvimgrepadd <mods>vimgrepadd <args>
Bram Moolenaar049cba92016-06-26 14:38:04 +020035 command! -nargs=* Xgrep <mods> grep <args>
36 command! -nargs=* Xgrepadd <mods> grepadd <args>
37 command! -nargs=* Xhelpgrep helpgrep <args>
Bram Moolenaar74240d32017-12-10 15:26:15 +010038 command! -nargs=0 -count Xcc <count>cc
Bram Moolenaar3ff33112019-05-03 21:56:35 +020039 command! -count=1 -nargs=0 Xbelow <mods><count>cbelow
40 command! -count=1 -nargs=0 Xabove <mods><count>cabove
Bram Moolenaarcf6a55c2019-05-05 15:02:30 +020041 command! -count=1 -nargs=0 Xbefore <mods><count>cbefore
42 command! -count=1 -nargs=0 Xafter <mods><count>cafter
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +020043 let g:Xgetlist = function('getqflist')
44 let g:Xsetlist = function('setqflist')
Bram Moolenaarb6fa30c2017-03-29 14:19:25 +020045 call setqflist([], 'f')
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +020046 else
47 command! -nargs=* -bang Xlist <mods>llist<bang> <args>
48 command! -nargs=* Xgetexpr <mods>lgetexpr <args>
Bram Moolenaar361c8f02016-07-02 15:41:47 +020049 command! -nargs=* Xaddexpr <mods>laddexpr <args>
Bram Moolenaar55b69262017-08-13 13:42:01 +020050 command! -nargs=* -count Xolder <mods><count>lolder <args>
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +020051 command! -nargs=* Xnewer <mods>lnewer <args>
52 command! -nargs=* Xopen <mods>lopen <args>
53 command! -nargs=* Xwindow <mods>lwindow <args>
Bram Moolenaar537ef082016-07-09 17:56:19 +020054 command! -nargs=* Xbottom <mods>lbottom <args>
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +020055 command! -nargs=* Xclose <mods>lclose <args>
56 command! -nargs=* -bang Xfile <mods>lfile<bang> <args>
57 command! -nargs=* Xgetfile <mods>lgetfile <args>
58 command! -nargs=* Xaddfile <mods>laddfile <args>
59 command! -nargs=* -bang Xbuffer <mods>lbuffer<bang> <args>
60 command! -nargs=* Xgetbuffer <mods>lgetbuffer <args>
61 command! -nargs=* Xaddbuffer <mods>laddbuffer <args>
62 command! -nargs=* Xrewind <mods>lrewind <args>
Bram Moolenaar99895ea2017-04-20 22:44:47 +020063 command! -count -nargs=* -bang Xnext <mods><count>lnext<bang> <args>
64 command! -count -nargs=* -bang Xprev <mods><count>lprev<bang> <args>
Bram Moolenaar0fcc7c62016-07-02 21:22:52 +020065 command! -nargs=* -bang Xfirst <mods>lfirst<bang> <args>
66 command! -nargs=* -bang Xlast <mods>llast<bang> <args>
Bram Moolenaar25190db2019-05-04 15:05:28 +020067 command! -count -nargs=* -bang Xnfile <mods><count>lnfile<bang> <args>
Bram Moolenaar0fcc7c62016-07-02 21:22:52 +020068 command! -nargs=* -bang Xpfile <mods>lpfile<bang> <args>
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +020069 command! -nargs=* Xexpr <mods>lexpr <args>
Bram Moolenaaree85df32017-03-19 14:19:50 +010070 command! -range -nargs=* Xvimgrep <mods><count>lvimgrep <args>
71 command! -nargs=* Xvimgrepadd <mods>lvimgrepadd <args>
Bram Moolenaar049cba92016-06-26 14:38:04 +020072 command! -nargs=* Xgrep <mods> lgrep <args>
73 command! -nargs=* Xgrepadd <mods> lgrepadd <args>
74 command! -nargs=* Xhelpgrep lhelpgrep <args>
Bram Moolenaar74240d32017-12-10 15:26:15 +010075 command! -nargs=0 -count Xcc <count>ll
Bram Moolenaar3ff33112019-05-03 21:56:35 +020076 command! -count=1 -nargs=0 Xbelow <mods><count>lbelow
77 command! -count=1 -nargs=0 Xabove <mods><count>labove
Bram Moolenaarcf6a55c2019-05-05 15:02:30 +020078 command! -count=1 -nargs=0 Xbefore <mods><count>lbefore
79 command! -count=1 -nargs=0 Xafter <mods><count>lafter
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +020080 let g:Xgetlist = function('getloclist', [0])
81 let g:Xsetlist = function('setloclist', [0])
Bram Moolenaarb6fa30c2017-03-29 14:19:25 +020082 call setloclist(0, [], 'f')
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +020083 endif
Bram Moolenaar2b946c92016-11-12 18:14:44 +010084endfunc
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +020085
Bram Moolenaarda59dd52016-01-05 21:59:58 +010086" Tests for the :clist and :llist commands
Bram Moolenaar2b946c92016-11-12 18:14:44 +010087func XlistTests(cchar)
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +020088 call s:setup_commands(a:cchar)
Bram Moolenaarda59dd52016-01-05 21:59:58 +010089
Bram Moolenaarb6fa30c2017-03-29 14:19:25 +020090 if a:cchar == 'l'
91 call assert_fails('llist', 'E776:')
92 endif
Bram Moolenaarda59dd52016-01-05 21:59:58 +010093 " With an empty list, command should return error
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +020094 Xgetexpr []
95 silent! Xlist
Bram Moolenaarda59dd52016-01-05 21:59:58 +010096 call assert_true(v:errmsg ==# 'E42: No Errors')
97
98 " Populate the list and then try
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +020099 Xgetexpr ['non-error 1', 'Xtestfile1:1:3:Line1',
Bram Moolenaarda59dd52016-01-05 21:59:58 +0100100 \ 'non-error 2', 'Xtestfile2:2:2:Line2',
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +0200101 \ 'non-error 3', 'Xtestfile3:3:1:Line3']
Bram Moolenaarda59dd52016-01-05 21:59:58 +0100102
103 " List only valid entries
Bram Moolenaaree85df32017-03-19 14:19:50 +0100104 let l = split(execute('Xlist', ''), "\n")
Bram Moolenaarda59dd52016-01-05 21:59:58 +0100105 call assert_equal([' 2 Xtestfile1:1 col 3: Line1',
106 \ ' 4 Xtestfile2:2 col 2: Line2',
107 \ ' 6 Xtestfile3:3 col 1: Line3'], l)
108
109 " List all the entries
Bram Moolenaaree85df32017-03-19 14:19:50 +0100110 let l = split(execute('Xlist!', ''), "\n")
Bram Moolenaarda59dd52016-01-05 21:59:58 +0100111 call assert_equal([' 1: non-error 1', ' 2 Xtestfile1:1 col 3: Line1',
112 \ ' 3: non-error 2', ' 4 Xtestfile2:2 col 2: Line2',
113 \ ' 5: non-error 3', ' 6 Xtestfile3:3 col 1: Line3'], l)
114
115 " List a range of errors
Bram Moolenaaree85df32017-03-19 14:19:50 +0100116 let l = split(execute('Xlist 3,6', ''), "\n")
Bram Moolenaarda59dd52016-01-05 21:59:58 +0100117 call assert_equal([' 4 Xtestfile2:2 col 2: Line2',
118 \ ' 6 Xtestfile3:3 col 1: Line3'], l)
119
Bram Moolenaaree85df32017-03-19 14:19:50 +0100120 let l = split(execute('Xlist! 3,4', ''), "\n")
Bram Moolenaarda59dd52016-01-05 21:59:58 +0100121 call assert_equal([' 3: non-error 2', ' 4 Xtestfile2:2 col 2: Line2'], l)
122
Bram Moolenaaree85df32017-03-19 14:19:50 +0100123 let l = split(execute('Xlist -6,-4', ''), "\n")
Bram Moolenaarda59dd52016-01-05 21:59:58 +0100124 call assert_equal([' 2 Xtestfile1:1 col 3: Line1'], l)
125
Bram Moolenaaree85df32017-03-19 14:19:50 +0100126 let l = split(execute('Xlist! -5,-3', ''), "\n")
Bram Moolenaarda59dd52016-01-05 21:59:58 +0100127 call assert_equal([' 2 Xtestfile1:1 col 3: Line1',
128 \ ' 3: non-error 2', ' 4 Xtestfile2:2 col 2: Line2'], l)
Bram Moolenaar391b1dd2017-03-04 13:47:11 +0100129
130 " Test for '+'
Bram Moolenaaree85df32017-03-19 14:19:50 +0100131 let l = split(execute('Xlist! +2', ''), "\n")
Bram Moolenaar391b1dd2017-03-04 13:47:11 +0100132 call assert_equal([' 2 Xtestfile1:1 col 3: Line1',
133 \ ' 3: non-error 2', ' 4 Xtestfile2:2 col 2: Line2'], l)
Bram Moolenaaree85df32017-03-19 14:19:50 +0100134
135 " Different types of errors
136 call g:Xsetlist([{'lnum':10,'col':5,'type':'W', 'text':'Warning','nr':11},
137 \ {'lnum':20,'col':10,'type':'e','text':'Error','nr':22},
138 \ {'lnum':30,'col':15,'type':'i','text':'Info','nr':33},
139 \ {'lnum':40,'col':20,'type':'x', 'text':'Other','nr':44},
140 \ {'lnum':50,'col':25,'type':"\<C-A>",'text':'one','nr':55}])
141 let l = split(execute('Xlist', ""), "\n")
142 call assert_equal([' 1:10 col 5 warning 11: Warning',
143 \ ' 2:20 col 10 error 22: Error',
144 \ ' 3:30 col 15 info 33: Info',
145 \ ' 4:40 col 20 x 44: Other',
146 \ ' 5:50 col 25 55: one'], l)
147
Bram Moolenaard76ce852018-05-01 15:02:04 +0200148 " Test for module names, one needs to explicitly set `'valid':v:true` so
149 call g:Xsetlist([
150 \ {'lnum':10,'col':5,'type':'W','module':'Data.Text','text':'ModuleWarning','nr':11,'valid':v:true},
151 \ {'lnum':20,'col':10,'type':'W','module':'Data.Text','filename':'Data/Text.hs','text':'ModuleWarning','nr':22,'valid':v:true},
152 \ {'lnum':30,'col':15,'type':'W','filename':'Data/Text.hs','text':'FileWarning','nr':33,'valid':v:true}])
153 let l = split(execute('Xlist', ""), "\n")
154 call assert_equal([' 1 Data.Text:10 col 5 warning 11: ModuleWarning',
155 \ ' 2 Data.Text:20 col 10 warning 22: ModuleWarning',
156 \ ' 3 Data/Text.hs:30 col 15 warning 33: FileWarning'], l)
157
Bram Moolenaaree85df32017-03-19 14:19:50 +0100158 " Error cases
159 call assert_fails('Xlist abc', 'E488:')
Bram Moolenaar2b946c92016-11-12 18:14:44 +0100160endfunc
Bram Moolenaarda59dd52016-01-05 21:59:58 +0100161
Bram Moolenaar2b946c92016-11-12 18:14:44 +0100162func Test_clist()
Bram Moolenaarda59dd52016-01-05 21:59:58 +0100163 call XlistTests('c')
164 call XlistTests('l')
Bram Moolenaar2b946c92016-11-12 18:14:44 +0100165endfunc
Bram Moolenaarda59dd52016-01-05 21:59:58 +0100166
167" Tests for the :colder, :cnewer, :lolder and :lnewer commands
168" Note that this test assumes that a quickfix/location list is
Bram Moolenaarcfc0a352016-01-09 20:23:00 +0100169" already set by the caller.
Bram Moolenaar2b946c92016-11-12 18:14:44 +0100170func XageTests(cchar)
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +0200171 call s:setup_commands(a:cchar)
Bram Moolenaarda59dd52016-01-05 21:59:58 +0100172
Bram Moolenaar87f59b02019-04-04 14:04:11 +0200173 if a:cchar == 'l'
174 " No location list for the current window
175 call assert_fails('lolder', 'E776:')
176 call assert_fails('lnewer', 'E776:')
177 endif
178
Bram Moolenaarcf1ba352017-10-27 00:55:04 +0200179 let list = [{'bufnr': bufnr('%'), 'lnum': 1}]
Bram Moolenaarb6fa30c2017-03-29 14:19:25 +0200180 call g:Xsetlist(list)
181
Bram Moolenaarda59dd52016-01-05 21:59:58 +0100182 " Jumping to a non existent list should return error
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +0200183 silent! Xolder 99
Bram Moolenaarda59dd52016-01-05 21:59:58 +0100184 call assert_true(v:errmsg ==# 'E380: At bottom of quickfix stack')
185
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +0200186 silent! Xnewer 99
Bram Moolenaarda59dd52016-01-05 21:59:58 +0100187 call assert_true(v:errmsg ==# 'E381: At top of quickfix stack')
188
189 " Add three quickfix/location lists
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +0200190 Xgetexpr ['Xtestfile1:1:3:Line1']
191 Xgetexpr ['Xtestfile2:2:2:Line2']
192 Xgetexpr ['Xtestfile3:3:1:Line3']
Bram Moolenaarda59dd52016-01-05 21:59:58 +0100193
194 " Go back two lists
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +0200195 Xolder
196 let l = g:Xgetlist()
Bram Moolenaarda59dd52016-01-05 21:59:58 +0100197 call assert_equal('Line2', l[0].text)
198
199 " Go forward two lists
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +0200200 Xnewer
201 let l = g:Xgetlist()
Bram Moolenaarda59dd52016-01-05 21:59:58 +0100202 call assert_equal('Line3', l[0].text)
203
204 " Test for the optional count argument
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +0200205 Xolder 2
206 let l = g:Xgetlist()
Bram Moolenaarda59dd52016-01-05 21:59:58 +0100207 call assert_equal('Line1', l[0].text)
208
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +0200209 Xnewer 2
210 let l = g:Xgetlist()
Bram Moolenaarda59dd52016-01-05 21:59:58 +0100211 call assert_equal('Line3', l[0].text)
Bram Moolenaar2b946c92016-11-12 18:14:44 +0100212endfunc
Bram Moolenaarda59dd52016-01-05 21:59:58 +0100213
Bram Moolenaar2b946c92016-11-12 18:14:44 +0100214func Test_cage()
Bram Moolenaarda59dd52016-01-05 21:59:58 +0100215 call XageTests('c')
216 call XageTests('l')
Bram Moolenaar2b946c92016-11-12 18:14:44 +0100217endfunc
Bram Moolenaarda59dd52016-01-05 21:59:58 +0100218
219" Tests for the :cwindow, :lwindow :cclose, :lclose, :copen and :lopen
220" commands
Bram Moolenaar2b946c92016-11-12 18:14:44 +0100221func XwindowTests(cchar)
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +0200222 call s:setup_commands(a:cchar)
Bram Moolenaarda59dd52016-01-05 21:59:58 +0100223
Bram Moolenaarb6fa30c2017-03-29 14:19:25 +0200224 " Opening the location list window without any errors should fail
225 if a:cchar == 'l'
226 call assert_fails('lopen', 'E776:')
227 endif
228
Bram Moolenaarda59dd52016-01-05 21:59:58 +0100229 " Create a list with no valid entries
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +0200230 Xgetexpr ['non-error 1', 'non-error 2', 'non-error 3']
Bram Moolenaarda59dd52016-01-05 21:59:58 +0100231
232 " Quickfix/Location window should not open with no valid errors
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +0200233 Xwindow
Bram Moolenaarda59dd52016-01-05 21:59:58 +0100234 call assert_true(winnr('$') == 1)
235
236 " Create a list with valid entries
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +0200237 Xgetexpr ['Xtestfile1:1:3:Line1', 'Xtestfile2:2:2:Line2',
238 \ 'Xtestfile3:3:1:Line3']
Bram Moolenaarda59dd52016-01-05 21:59:58 +0100239
240 " Open the window
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +0200241 Xwindow
Bram Moolenaarda59dd52016-01-05 21:59:58 +0100242 call assert_true(winnr('$') == 2 && winnr() == 2 &&
243 \ getline('.') ==# 'Xtestfile1|1 col 3| Line1')
Bram Moolenaar537ef082016-07-09 17:56:19 +0200244 redraw!
Bram Moolenaarda59dd52016-01-05 21:59:58 +0100245
246 " Close the window
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +0200247 Xclose
Bram Moolenaarda59dd52016-01-05 21:59:58 +0100248 call assert_true(winnr('$') == 1)
249
250 " Create a list with no valid entries
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +0200251 Xgetexpr ['non-error 1', 'non-error 2', 'non-error 3']
Bram Moolenaarda59dd52016-01-05 21:59:58 +0100252
253 " Open the window
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +0200254 Xopen 5
Bram Moolenaarda59dd52016-01-05 21:59:58 +0100255 call assert_true(winnr('$') == 2 && getline('.') ==# '|| non-error 1'
256 \ && winheight('.') == 5)
257
258 " Opening the window again, should move the cursor to that window
259 wincmd t
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +0200260 Xopen 7
Bram Moolenaarda59dd52016-01-05 21:59:58 +0100261 call assert_true(winnr('$') == 2 && winnr() == 2 &&
262 \ winheight('.') == 7 &&
263 \ getline('.') ==# '|| non-error 1')
264
265
266 " Calling cwindow should close the quickfix window with no valid errors
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +0200267 Xwindow
Bram Moolenaarda59dd52016-01-05 21:59:58 +0100268 call assert_true(winnr('$') == 1)
Bram Moolenaarb6fa30c2017-03-29 14:19:25 +0200269
270 if a:cchar == 'c'
271 " Opening the quickfix window in multiple tab pages should reuse the
272 " quickfix buffer
273 Xgetexpr ['Xtestfile1:1:3:Line1', 'Xtestfile2:2:2:Line2',
274 \ 'Xtestfile3:3:1:Line3']
275 Xopen
276 let qfbufnum = bufnr('%')
277 tabnew
278 Xopen
279 call assert_equal(qfbufnum, bufnr('%'))
280 new | only | tabonly
281 endif
Bram Moolenaar2b946c92016-11-12 18:14:44 +0100282endfunc
Bram Moolenaarda59dd52016-01-05 21:59:58 +0100283
Bram Moolenaar2b946c92016-11-12 18:14:44 +0100284func Test_cwindow()
Bram Moolenaarda59dd52016-01-05 21:59:58 +0100285 call XwindowTests('c')
286 call XwindowTests('l')
Bram Moolenaar2b946c92016-11-12 18:14:44 +0100287endfunc
Bram Moolenaarda59dd52016-01-05 21:59:58 +0100288
Bram Moolenaar36d50222019-05-02 20:17:40 +0200289func Test_copenHeight()
290 copen
291 wincmd H
292 let height = winheight(0)
293 copen 10
294 call assert_equal(height, winheight(0))
295 quit
296endfunc
297
Bram Moolenaarda59dd52016-01-05 21:59:58 +0100298" Tests for the :cfile, :lfile, :caddfile, :laddfile, :cgetfile and :lgetfile
299" commands.
Bram Moolenaar2b946c92016-11-12 18:14:44 +0100300func XfileTests(cchar)
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +0200301 call s:setup_commands(a:cchar)
Bram Moolenaarda59dd52016-01-05 21:59:58 +0100302
303 call writefile(['Xtestfile1:700:10:Line 700',
304 \ 'Xtestfile2:800:15:Line 800'], 'Xqftestfile1')
305
306 enew!
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +0200307 Xfile Xqftestfile1
308 let l = g:Xgetlist()
Bram Moolenaarda59dd52016-01-05 21:59:58 +0100309 call assert_true(len(l) == 2 &&
310 \ l[0].lnum == 700 && l[0].col == 10 && l[0].text ==# 'Line 700' &&
311 \ l[1].lnum == 800 && l[1].col == 15 && l[1].text ==# 'Line 800')
312
Bram Moolenaar049cba92016-06-26 14:38:04 +0200313 " Test with a non existent file
314 call assert_fails('Xfile non_existent_file', 'E40')
315
Bram Moolenaarda59dd52016-01-05 21:59:58 +0100316 " Run cfile/lfile from a modified buffer
317 enew!
318 silent! put ='Quickfix'
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +0200319 silent! Xfile Xqftestfile1
Bram Moolenaarda59dd52016-01-05 21:59:58 +0100320 call assert_true(v:errmsg ==# 'E37: No write since last change (add ! to override)')
321
322 call writefile(['Xtestfile3:900:30:Line 900'], 'Xqftestfile1')
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +0200323 Xaddfile Xqftestfile1
324 let l = g:Xgetlist()
Bram Moolenaarda59dd52016-01-05 21:59:58 +0100325 call assert_true(len(l) == 3 &&
326 \ l[2].lnum == 900 && l[2].col == 30 && l[2].text ==# 'Line 900')
327
328 call writefile(['Xtestfile1:222:77:Line 222',
329 \ 'Xtestfile2:333:88:Line 333'], 'Xqftestfile1')
330
331 enew!
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +0200332 Xgetfile Xqftestfile1
333 let l = g:Xgetlist()
Bram Moolenaarda59dd52016-01-05 21:59:58 +0100334 call assert_true(len(l) == 2 &&
335 \ l[0].lnum == 222 && l[0].col == 77 && l[0].text ==# 'Line 222' &&
336 \ l[1].lnum == 333 && l[1].col == 88 && l[1].text ==# 'Line 333')
337
338 call delete('Xqftestfile1')
Bram Moolenaar2b946c92016-11-12 18:14:44 +0100339endfunc
Bram Moolenaarda59dd52016-01-05 21:59:58 +0100340
Bram Moolenaar2b946c92016-11-12 18:14:44 +0100341func Test_cfile()
Bram Moolenaarda59dd52016-01-05 21:59:58 +0100342 call XfileTests('c')
343 call XfileTests('l')
Bram Moolenaar2b946c92016-11-12 18:14:44 +0100344endfunc
Bram Moolenaarda59dd52016-01-05 21:59:58 +0100345
346" Tests for the :cbuffer, :lbuffer, :caddbuffer, :laddbuffer, :cgetbuffer and
347" :lgetbuffer commands.
Bram Moolenaar2b946c92016-11-12 18:14:44 +0100348func XbufferTests(cchar)
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +0200349 call s:setup_commands(a:cchar)
Bram Moolenaarda59dd52016-01-05 21:59:58 +0100350
351 enew!
352 silent! call setline(1, ['Xtestfile7:700:10:Line 700',
353 \ 'Xtestfile8:800:15:Line 800'])
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +0200354 Xbuffer!
355 let l = g:Xgetlist()
Bram Moolenaarda59dd52016-01-05 21:59:58 +0100356 call assert_true(len(l) == 2 &&
357 \ l[0].lnum == 700 && l[0].col == 10 && l[0].text ==# 'Line 700' &&
358 \ l[1].lnum == 800 && l[1].col == 15 && l[1].text ==# 'Line 800')
359
360 enew!
361 silent! call setline(1, ['Xtestfile9:900:55:Line 900',
362 \ 'Xtestfile10:950:66:Line 950'])
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +0200363 Xgetbuffer
364 let l = g:Xgetlist()
Bram Moolenaarda59dd52016-01-05 21:59:58 +0100365 call assert_true(len(l) == 2 &&
366 \ l[0].lnum == 900 && l[0].col == 55 && l[0].text ==# 'Line 900' &&
367 \ l[1].lnum == 950 && l[1].col == 66 && l[1].text ==# 'Line 950')
368
369 enew!
370 silent! call setline(1, ['Xtestfile11:700:20:Line 700',
371 \ 'Xtestfile12:750:25:Line 750'])
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +0200372 Xaddbuffer
373 let l = g:Xgetlist()
Bram Moolenaarda59dd52016-01-05 21:59:58 +0100374 call assert_true(len(l) == 4 &&
375 \ l[1].lnum == 950 && l[1].col == 66 && l[1].text ==# 'Line 950' &&
376 \ l[2].lnum == 700 && l[2].col == 20 && l[2].text ==# 'Line 700' &&
377 \ l[3].lnum == 750 && l[3].col == 25 && l[3].text ==# 'Line 750')
Bram Moolenaarab47c612016-06-14 22:02:26 +0200378 enew!
Bram Moolenaarda59dd52016-01-05 21:59:58 +0100379
Bram Moolenaaree85df32017-03-19 14:19:50 +0100380 " Check for invalid buffer
381 call assert_fails('Xbuffer 199', 'E474:')
382
383 " Check for unloaded buffer
384 edit Xtestfile1
385 let bnr = bufnr('%')
386 enew!
387 call assert_fails('Xbuffer ' . bnr, 'E681:')
388
389 " Check for invalid range
390 " Using Xbuffer will not run the range check in the cbuffer/lbuffer
391 " commands. So directly call the commands.
392 if (a:cchar == 'c')
393 call assert_fails('900,999cbuffer', 'E16:')
394 else
395 call assert_fails('900,999lbuffer', 'E16:')
396 endif
Bram Moolenaar2b946c92016-11-12 18:14:44 +0100397endfunc
Bram Moolenaarda59dd52016-01-05 21:59:58 +0100398
Bram Moolenaar2b946c92016-11-12 18:14:44 +0100399func Test_cbuffer()
Bram Moolenaarda59dd52016-01-05 21:59:58 +0100400 call XbufferTests('c')
401 call XbufferTests('l')
Bram Moolenaar2b946c92016-11-12 18:14:44 +0100402endfunc
Bram Moolenaarda59dd52016-01-05 21:59:58 +0100403
Bram Moolenaar2b946c92016-11-12 18:14:44 +0100404func XexprTests(cchar)
Bram Moolenaar0fcc7c62016-07-02 21:22:52 +0200405 call s:setup_commands(a:cchar)
406
407 call assert_fails('Xexpr 10', 'E777:')
Bram Moolenaar2b946c92016-11-12 18:14:44 +0100408endfunc
Bram Moolenaar0fcc7c62016-07-02 21:22:52 +0200409
Bram Moolenaar2b946c92016-11-12 18:14:44 +0100410func Test_cexpr()
Bram Moolenaar0fcc7c62016-07-02 21:22:52 +0200411 call XexprTests('c')
412 call XexprTests('l')
Bram Moolenaar2b946c92016-11-12 18:14:44 +0100413endfunc
Bram Moolenaar0fcc7c62016-07-02 21:22:52 +0200414
415" Tests for :cnext, :cprev, :cfirst, :clast commands
Bram Moolenaar2b946c92016-11-12 18:14:44 +0100416func Xtest_browse(cchar)
Bram Moolenaar0fcc7c62016-07-02 21:22:52 +0200417 call s:setup_commands(a:cchar)
418
Bram Moolenaar74240d32017-12-10 15:26:15 +0100419 call g:Xsetlist([], 'f')
Bram Moolenaarb6fa30c2017-03-29 14:19:25 +0200420 " Jumping to first or next location list entry without any error should
421 " result in failure
Bram Moolenaar74240d32017-12-10 15:26:15 +0100422 if a:cchar == 'c'
423 let err = 'E42:'
424 else
425 let err = 'E776:'
Bram Moolenaarb6fa30c2017-03-29 14:19:25 +0200426 endif
Bram Moolenaar74240d32017-12-10 15:26:15 +0100427 call assert_fails('Xnext', err)
428 call assert_fails('Xprev', err)
429 call assert_fails('Xnfile', err)
430 call assert_fails('Xpfile', err)
Bram Moolenaarb6fa30c2017-03-29 14:19:25 +0200431
Bram Moolenaar0fcc7c62016-07-02 21:22:52 +0200432 call s:create_test_file('Xqftestfile1')
433 call s:create_test_file('Xqftestfile2')
434
435 Xgetexpr ['Xqftestfile1:5:Line5',
436 \ 'Xqftestfile1:6:Line6',
437 \ 'Xqftestfile2:10:Line10',
Bram Moolenaar99895ea2017-04-20 22:44:47 +0200438 \ 'Xqftestfile2:11:Line11',
439 \ 'RegularLine1',
440 \ 'RegularLine2']
Bram Moolenaar0fcc7c62016-07-02 21:22:52 +0200441
442 Xfirst
443 call assert_fails('Xprev', 'E553')
444 call assert_fails('Xpfile', 'E553')
445 Xnfile
446 call assert_equal('Xqftestfile2', bufname('%'))
447 call assert_equal(10, line('.'))
448 Xpfile
449 call assert_equal('Xqftestfile1', bufname('%'))
450 call assert_equal(6, line('.'))
Bram Moolenaar74240d32017-12-10 15:26:15 +0100451 5Xcc
452 call assert_equal(5, g:Xgetlist({'idx':0}).idx)
453 2Xcc
454 call assert_equal(2, g:Xgetlist({'idx':0}).idx)
455 10Xcc
456 call assert_equal(6, g:Xgetlist({'idx':0}).idx)
Bram Moolenaar0fcc7c62016-07-02 21:22:52 +0200457 Xlast
Bram Moolenaar99895ea2017-04-20 22:44:47 +0200458 Xprev
Bram Moolenaar0fcc7c62016-07-02 21:22:52 +0200459 call assert_equal('Xqftestfile2', bufname('%'))
460 call assert_equal(11, line('.'))
461 call assert_fails('Xnext', 'E553')
462 call assert_fails('Xnfile', 'E553')
463 Xrewind
464 call assert_equal('Xqftestfile1', bufname('%'))
465 call assert_equal(5, line('.'))
466
Bram Moolenaar99895ea2017-04-20 22:44:47 +0200467 10Xnext
468 call assert_equal('Xqftestfile2', bufname('%'))
469 call assert_equal(11, line('.'))
470 10Xprev
471 call assert_equal('Xqftestfile1', bufname('%'))
472 call assert_equal(5, line('.'))
473
Bram Moolenaar74240d32017-12-10 15:26:15 +0100474 " Jumping to an error from the error window using cc command
475 Xgetexpr ['Xqftestfile1:5:Line5',
476 \ 'Xqftestfile1:6:Line6',
477 \ 'Xqftestfile2:10:Line10',
478 \ 'Xqftestfile2:11:Line11']
479 Xopen
480 10Xcc
481 call assert_equal(11, line('.'))
482 call assert_equal('Xqftestfile2', bufname('%'))
483
484 " Jumping to an error from the error window (when only the error window is
485 " present)
486 Xopen | only
487 Xlast 1
488 call assert_equal(5, line('.'))
489 call assert_equal('Xqftestfile1', bufname('%'))
490
Bram Moolenaaree85df32017-03-19 14:19:50 +0100491 Xexpr ""
492 call assert_fails('Xnext', 'E42:')
493
Bram Moolenaar0fcc7c62016-07-02 21:22:52 +0200494 call delete('Xqftestfile1')
495 call delete('Xqftestfile2')
Bram Moolenaarfc2b2702017-09-15 22:43:07 +0200496
497 " Should be able to use next/prev with invalid entries
498 Xexpr ""
499 call assert_equal(0, g:Xgetlist({'idx' : 0}).idx)
500 call assert_equal(0, g:Xgetlist({'size' : 0}).size)
501 Xaddexpr ['foo', 'bar', 'baz', 'quux', 'shmoo']
502 call assert_equal(5, g:Xgetlist({'size' : 0}).size)
503 Xlast
504 call assert_equal(5, g:Xgetlist({'idx' : 0}).idx)
505 Xfirst
506 call assert_equal(1, g:Xgetlist({'idx' : 0}).idx)
507 2Xnext
508 call assert_equal(3, g:Xgetlist({'idx' : 0}).idx)
Bram Moolenaar2b946c92016-11-12 18:14:44 +0100509endfunc
Bram Moolenaar0fcc7c62016-07-02 21:22:52 +0200510
Bram Moolenaar2b946c92016-11-12 18:14:44 +0100511func Test_browse()
Bram Moolenaar0fcc7c62016-07-02 21:22:52 +0200512 call Xtest_browse('c')
513 call Xtest_browse('l')
Bram Moolenaar2b946c92016-11-12 18:14:44 +0100514endfunc
Bram Moolenaar0fcc7c62016-07-02 21:22:52 +0200515
Bram Moolenaar2b946c92016-11-12 18:14:44 +0100516func Test_nomem()
Bram Moolenaar8e8df252016-05-25 21:23:21 +0200517 call test_alloc_fail(GetAllocId('qf_dirname_start'), 0, 0)
Bram Moolenaara260b872016-01-15 20:48:22 +0100518 call assert_fails('vimgrep vim runtest.vim', 'E342:')
Bram Moolenaar75bdf6a2016-01-07 21:25:08 +0100519
Bram Moolenaarce90e362019-09-08 18:58:44 +0200520 call GetAllocId('qf_dirname_now')->test_alloc_fail(0, 0)
Bram Moolenaara260b872016-01-15 20:48:22 +0100521 call assert_fails('vimgrep vim runtest.vim', 'E342:')
Bram Moolenaar75bdf6a2016-01-07 21:25:08 +0100522
Bram Moolenaar8e8df252016-05-25 21:23:21 +0200523 call test_alloc_fail(GetAllocId('qf_namebuf'), 0, 0)
Bram Moolenaara260b872016-01-15 20:48:22 +0100524 call assert_fails('cfile runtest.vim', 'E342:')
Bram Moolenaar75bdf6a2016-01-07 21:25:08 +0100525
Bram Moolenaar8e8df252016-05-25 21:23:21 +0200526 call test_alloc_fail(GetAllocId('qf_errmsg'), 0, 0)
Bram Moolenaara260b872016-01-15 20:48:22 +0100527 call assert_fails('cfile runtest.vim', 'E342:')
Bram Moolenaar75bdf6a2016-01-07 21:25:08 +0100528
Bram Moolenaar8e8df252016-05-25 21:23:21 +0200529 call test_alloc_fail(GetAllocId('qf_pattern'), 0, 0)
Bram Moolenaara260b872016-01-15 20:48:22 +0100530 call assert_fails('cfile runtest.vim', 'E342:')
Bram Moolenaar75bdf6a2016-01-07 21:25:08 +0100531
532endfunc
533
Bram Moolenaar2b946c92016-11-12 18:14:44 +0100534func s:test_xhelpgrep(cchar)
Bram Moolenaar049cba92016-06-26 14:38:04 +0200535 call s:setup_commands(a:cchar)
536 Xhelpgrep quickfix
537 Xopen
538 if a:cchar == 'c'
539 let title_text = ':helpgrep quickfix'
540 else
541 let title_text = ':lhelpgrep quickfix'
542 endif
543 call assert_true(w:quickfix_title =~ title_text, w:quickfix_title)
Bram Moolenaar99895ea2017-04-20 22:44:47 +0200544
545 " Jumping to a help topic should open the help window
546 only
547 Xnext
548 call assert_true(&buftype == 'help')
549 call assert_true(winnr('$') == 2)
550 " Jumping to the next match should reuse the help window
551 Xnext
552 call assert_true(&buftype == 'help')
553 call assert_true(winnr() == 1)
554 call assert_true(winnr('$') == 2)
555 " Jumping to the next match from the quickfix window should reuse the help
556 " window
557 Xopen
558 Xnext
559 call assert_true(&buftype == 'help')
560 call assert_true(winnr() == 1)
561 call assert_true(winnr('$') == 2)
562
Bram Moolenaar62ef7972016-01-19 14:51:54 +0100563 " This wipes out the buffer, make sure that doesn't cause trouble.
Bram Moolenaar049cba92016-06-26 14:38:04 +0200564 Xclose
Bram Moolenaaree85df32017-03-19 14:19:50 +0100565
Bram Moolenaarb4d5fba2017-09-11 19:31:28 +0200566 if a:cchar == 'l'
567 " When a help window is present, running :lhelpgrep should reuse the
568 " help window and not the current window
569 new | only
570 call g:Xsetlist([], 'f')
571 help index.txt
572 wincmd w
573 lhelpgrep quickfix
574 call assert_equal(1, winnr())
575 call assert_notequal([], getloclist(1))
576 call assert_equal([], getloclist(2))
577 endif
578
Bram Moolenaar99895ea2017-04-20 22:44:47 +0200579 new | only
580
Bram Moolenaaree85df32017-03-19 14:19:50 +0100581 " Search for non existing help string
582 call assert_fails('Xhelpgrep a1b2c3', 'E480:')
Bram Moolenaar108e7b42018-10-11 17:39:12 +0200583 " Invalid regular expression
584 call assert_fails('Xhelpgrep \@<!', 'E480:')
Bram Moolenaar2b946c92016-11-12 18:14:44 +0100585endfunc
Bram Moolenaar049cba92016-06-26 14:38:04 +0200586
Bram Moolenaar2b946c92016-11-12 18:14:44 +0100587func Test_helpgrep()
Bram Moolenaar049cba92016-06-26 14:38:04 +0200588 call s:test_xhelpgrep('c')
Bram Moolenaarcf25fdb2016-08-03 21:04:53 +0200589 helpclose
Bram Moolenaar049cba92016-06-26 14:38:04 +0200590 call s:test_xhelpgrep('l')
Bram Moolenaar62ef7972016-01-19 14:51:54 +0100591endfunc
Bram Moolenaar75bdf6a2016-01-07 21:25:08 +0100592
Bram Moolenaar6920c722016-01-22 22:44:10 +0100593func Test_errortitle()
594 augroup QfBufWinEnter
595 au!
596 au BufWinEnter * :let g:a=get(w:, 'quickfix_title', 'NONE')
597 augroup END
598 copen
599 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'')'}]
600 call setqflist(a)
601 call assert_equal(':setqflist()', g:a)
602 augroup QfBufWinEnter
603 au!
604 augroup END
605 augroup! QfBufWinEnter
606endfunc
Bram Moolenaare27dba42016-03-15 14:11:10 +0100607
Bram Moolenaar5584df62016-03-18 21:00:51 +0100608func Test_vimgreptitle()
609 augroup QfBufWinEnter
610 au!
611 au BufWinEnter * :let g:a=get(w:, 'quickfix_title', 'NONE')
612 augroup END
613 try
614 vimgrep /pattern/j file
615 catch /E480/
616 endtry
617 copen
618 call assert_equal(': vimgrep /pattern/j file', g:a)
619 augroup QfBufWinEnter
620 au!
621 augroup END
622 augroup! QfBufWinEnter
623endfunc
624
Bram Moolenaar2b946c92016-11-12 18:14:44 +0100625func XqfTitleTests(cchar)
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +0200626 call s:setup_commands(a:cchar)
Bram Moolenaare27dba42016-03-15 14:11:10 +0100627
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +0200628 Xgetexpr ['file:1:1:message']
629 let l = g:Xgetlist()
Bram Moolenaare27dba42016-03-15 14:11:10 +0100630 if a:cchar == 'c'
631 call setqflist(l, 'r')
632 else
633 call setloclist(0, l, 'r')
634 endif
635
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +0200636 Xopen
Bram Moolenaare27dba42016-03-15 14:11:10 +0100637 if a:cchar == 'c'
638 let title = ':setqflist()'
639 else
640 let title = ':setloclist()'
641 endif
642 call assert_equal(title, w:quickfix_title)
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +0200643 Xclose
Bram Moolenaar2b946c92016-11-12 18:14:44 +0100644endfunc
Bram Moolenaare27dba42016-03-15 14:11:10 +0100645
646" Tests for quickfix window's title
Bram Moolenaar2b946c92016-11-12 18:14:44 +0100647func Test_qf_title()
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +0200648 call XqfTitleTests('c')
649 call XqfTitleTests('l')
Bram Moolenaar2b946c92016-11-12 18:14:44 +0100650endfunc
Bram Moolenaare27dba42016-03-15 14:11:10 +0100651
652" Tests for 'errorformat'
Bram Moolenaar2b946c92016-11-12 18:14:44 +0100653func Test_efm()
Bram Moolenaare27dba42016-03-15 14:11:10 +0100654 let save_efm = &efm
655 set efm=%EEEE%m,%WWWW%m,%+CCCC%.%#,%-GGGG%.%#
656 cgetexpr ['WWWW', 'EEEE', 'CCCC']
657 let l = strtrans(string(map(getqflist(), '[v:val.text, v:val.valid]')))
658 call assert_equal("[['W', 1], ['E^@CCCC', 1]]", l)
659 cgetexpr ['WWWW', 'GGGG', 'EEEE', 'CCCC']
660 let l = strtrans(string(map(getqflist(), '[v:val.text, v:val.valid]')))
661 call assert_equal("[['W', 1], ['E^@CCCC', 1]]", l)
662 cgetexpr ['WWWW', 'GGGG', 'ZZZZ', 'EEEE', 'CCCC', 'YYYY']
663 let l = strtrans(string(map(getqflist(), '[v:val.text, v:val.valid]')))
664 call assert_equal("[['W', 1], ['ZZZZ', 0], ['E^@CCCC', 1], ['YYYY', 0]]", l)
665 let &efm = save_efm
Bram Moolenaar2b946c92016-11-12 18:14:44 +0100666endfunc
Bram Moolenaar1ff2b642016-03-17 22:07:02 +0100667
668" This will test for problems in quickfix:
669" A. incorrectly copying location lists which caused the location list to show
670" a different name than the file that was actually being displayed.
671" B. not reusing the window for which the location list window is opened but
672" instead creating new windows.
673" C. make sure that the location list window is not reused instead of the
674" window it belongs to.
675"
676" Set up the test environment:
Bram Moolenaar2b946c92016-11-12 18:14:44 +0100677func ReadTestProtocol(name)
Bram Moolenaar1ff2b642016-03-17 22:07:02 +0100678 let base = substitute(a:name, '\v^test://(.*)%(\.[^.]+)?', '\1', '')
679 let word = substitute(base, '\v(.*)\..*', '\1', '')
680
681 setl modifiable
682 setl noreadonly
683 setl noswapfile
684 setl bufhidden=delete
685 %del _
686 " For problem 2:
687 " 'buftype' has to be set to reproduce the constant opening of new windows
688 setl buftype=nofile
689
690 call setline(1, word)
691
692 setl nomodified
693 setl nomodifiable
694 setl readonly
695 exe 'doautocmd BufRead ' . substitute(a:name, '\v^test://(.*)', '\1', '')
Bram Moolenaar2b946c92016-11-12 18:14:44 +0100696endfunc
Bram Moolenaar1ff2b642016-03-17 22:07:02 +0100697
Bram Moolenaar2b946c92016-11-12 18:14:44 +0100698func Test_locationlist()
Bram Moolenaar1ff2b642016-03-17 22:07:02 +0100699 enew
700
701 augroup testgroup
702 au!
703 autocmd BufReadCmd test://* call ReadTestProtocol(expand("<amatch>"))
704 augroup END
705
706 let words = [ "foo", "bar", "baz", "quux", "shmoo", "spam", "eggs" ]
707
708 let qflist = []
709 for word in words
710 call add(qflist, {'filename': 'test://' . word . '.txt', 'text': 'file ' . word . '.txt', })
711 " NOTE: problem 1:
712 " intentionally not setting 'lnum' so that the quickfix entries are not
713 " valid
Bram Moolenaaraad222c2019-09-06 22:46:09 +0200714 eval qflist->setloclist(0, ' ')
Bram Moolenaar1ff2b642016-03-17 22:07:02 +0100715 endfor
716
717 " Test A
718 lrewind
719 enew
720 lopen
Bram Moolenaar99895ea2017-04-20 22:44:47 +0200721 4lnext
Bram Moolenaar1ff2b642016-03-17 22:07:02 +0100722 vert split
723 wincmd L
724 lopen
725 wincmd p
726 lnext
727 let fileName = expand("%")
728 wincmd p
729 let locationListFileName = substitute(getline(line('.')), '\([^|]*\)|.*', '\1', '')
730 let fileName = substitute(fileName, '\\', '/', 'g')
731 let locationListFileName = substitute(locationListFileName, '\\', '/', 'g')
732 call assert_equal("test://bar.txt", fileName)
733 call assert_equal("test://bar.txt", locationListFileName)
734
735 wincmd n | only
736
737 " Test B:
738 lrewind
739 lopen
740 2
741 exe "normal \<CR>"
742 wincmd p
743 3
744 exe "normal \<CR>"
745 wincmd p
746 4
747 exe "normal \<CR>"
748 call assert_equal(2, winnr('$'))
749 wincmd n | only
750
751 " Test C:
752 lrewind
753 lopen
754 " Let's move the location list window to the top to check whether it (the
755 " first window found) will be reused when we try to open new windows:
756 wincmd K
757 2
758 exe "normal \<CR>"
759 wincmd p
760 3
761 exe "normal \<CR>"
762 wincmd p
763 4
764 exe "normal \<CR>"
765 1wincmd w
766 call assert_equal('quickfix', &buftype)
767 2wincmd w
768 let bufferName = expand("%")
769 let bufferName = substitute(bufferName, '\\', '/', 'g')
770 call assert_equal('test://quux.txt', bufferName)
771
772 wincmd n | only
773
774 augroup! testgroup
Bram Moolenaaree85df32017-03-19 14:19:50 +0100775endfunc
Bram Moolenaar0899d692016-03-19 13:35:03 +0100776
Bram Moolenaar2b946c92016-11-12 18:14:44 +0100777func Test_locationlist_curwin_was_closed()
Bram Moolenaar0899d692016-03-19 13:35:03 +0100778 augroup testgroup
779 au!
Bram Moolenaard106e5b2016-04-21 19:38:07 +0200780 autocmd BufReadCmd test_curwin.txt call R(expand("<amatch>"))
Bram Moolenaar0899d692016-03-19 13:35:03 +0100781 augroup END
782
Bram Moolenaar2b946c92016-11-12 18:14:44 +0100783 func! R(n)
Bram Moolenaar0899d692016-03-19 13:35:03 +0100784 quit
785 endfunc
786
787 new
788 let q = []
Bram Moolenaard106e5b2016-04-21 19:38:07 +0200789 call add(q, {'filename': 'test_curwin.txt' })
Bram Moolenaar0899d692016-03-19 13:35:03 +0100790 call setloclist(0, q)
791 call assert_fails('lrewind', 'E924:')
792
793 augroup! testgroup
Bram Moolenaaree85df32017-03-19 14:19:50 +0100794endfunc
Bram Moolenaar7eba3d22016-03-19 22:54:09 +0100795
Bram Moolenaar2b946c92016-11-12 18:14:44 +0100796func Test_locationlist_cross_tab_jump()
Bram Moolenaar0a9046f2016-10-15 19:28:13 +0200797 call writefile(['loclistfoo'], 'loclistfoo')
798 call writefile(['loclistbar'], 'loclistbar')
799 set switchbuf=usetab
800
801 edit loclistfoo
802 tabedit loclistbar
803 silent lgrep loclistfoo loclist*
804 call assert_equal(1, tabpagenr())
805
806 enew | only | tabonly
807 set switchbuf&vim
808 call delete('loclistfoo')
809 call delete('loclistbar')
Bram Moolenaar2b946c92016-11-12 18:14:44 +0100810endfunc
Bram Moolenaar0a9046f2016-10-15 19:28:13 +0200811
Bram Moolenaar7eba3d22016-03-19 22:54:09 +0100812" More tests for 'errorformat'
Bram Moolenaar2b946c92016-11-12 18:14:44 +0100813func Test_efm1()
Bram Moolenaar7eba3d22016-03-19 22:54:09 +0100814 if !has('unix')
815 " The 'errorformat' setting is different on non-Unix systems.
816 " This test works only on Unix-like systems.
817 return
818 endif
819
Bram Moolenaarc79745a2019-05-20 22:12:34 +0200820 let l =<< trim [DATA]
Bram Moolenaare7eb9272019-06-24 00:58:07 +0200821 "Xtestfile", line 4.12: 1506-045 (S) Undeclared identifier fd_set.
822 "Xtestfile", line 6 col 19; this is an error
823 gcc -c -DHAVE_CONFIsing-prototypes -I/usr/X11R6/include version.c
824 Xtestfile:9: parse error before `asd'
825 make: *** [vim] Error 1
826 in file "Xtestfile" linenr 10: there is an error
827
828 2 returned
829 "Xtestfile", line 11 col 1; this is an error
830 "Xtestfile", line 12 col 2; this is another error
831 "Xtestfile", line 14:10; this is an error in column 10
832 =Xtestfile=, line 15:10; this is another error, but in vcol 10 this time
833 "Xtestfile", linenr 16: yet another problem
834 Error in "Xtestfile" at line 17:
835 x should be a dot
836 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 17
837 ^
838 Error in "Xtestfile" at line 18:
839 x should be a dot
840 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 18
841 .............^
842 Error in "Xtestfile" at line 19:
843 x should be a dot
844 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 19
845 --------------^
846 Error in "Xtestfile" at line 20:
847 x should be a dot
848 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 20
849 ^
850
851 Does anyone know what is the problem and how to correction it?
852 "Xtestfile", line 21 col 9: What is the title of the quickfix window?
853 "Xtestfile", line 22 col 9: What is the title of the quickfix window?
Bram Moolenaarc79745a2019-05-20 22:12:34 +0200854 [DATA]
Bram Moolenaar7eba3d22016-03-19 22:54:09 +0100855
856 call writefile(l, 'Xerrorfile1')
857 call writefile(l[:-2], 'Xerrorfile2')
858
Bram Moolenaare7eb9272019-06-24 00:58:07 +0200859 let m =<< [DATA]
860 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 2
861 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 3
862 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 4
863 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 5
864 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 6
865 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 7
866 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 8
867 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 9
868 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 10
869 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 11
870 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 12
871 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 13
872 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 14
873 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 15
874 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 16
875 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 17
876 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 18
877 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 19
878 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 20
879 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 21
880 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 22
881[DATA]
Bram Moolenaar7eba3d22016-03-19 22:54:09 +0100882 call writefile(m, 'Xtestfile')
883
884 let save_efm = &efm
885 set efm+==%f=\\,\ line\ %l%*\\D%v%*[^\ ]\ %m
886 set efm^=%AError\ in\ \"%f\"\ at\ line\ %l:,%Z%p^,%C%m
887
888 exe 'cf Xerrorfile2'
889 clast
890 copen
891 call assert_equal(':cf Xerrorfile2', w:quickfix_title)
892 wincmd p
893
894 exe 'cf Xerrorfile1'
895 call assert_equal([4, 12], [line('.'), col('.')])
896 cn
897 call assert_equal([6, 19], [line('.'), col('.')])
898 cn
899 call assert_equal([9, 2], [line('.'), col('.')])
900 cn
901 call assert_equal([10, 2], [line('.'), col('.')])
902 cn
903 call assert_equal([11, 1], [line('.'), col('.')])
904 cn
905 call assert_equal([12, 2], [line('.'), col('.')])
906 cn
907 call assert_equal([14, 10], [line('.'), col('.')])
908 cn
909 call assert_equal([15, 3, 10], [line('.'), col('.'), virtcol('.')])
910 cn
911 call assert_equal([16, 2], [line('.'), col('.')])
912 cn
913 call assert_equal([17, 6], [line('.'), col('.')])
914 cn
915 call assert_equal([18, 7], [line('.'), col('.')])
916 cn
917 call assert_equal([19, 8], [line('.'), col('.')])
918 cn
919 call assert_equal([20, 9], [line('.'), col('.')])
920 clast
921 cprev
922 cprev
923 wincmd w
924 call assert_equal(':cf Xerrorfile1', w:quickfix_title)
925 wincmd p
926
927 let &efm = save_efm
928 call delete('Xerrorfile1')
929 call delete('Xerrorfile2')
930 call delete('Xtestfile')
Bram Moolenaaree85df32017-03-19 14:19:50 +0100931endfunc
Bram Moolenaarffec3c52016-03-23 20:55:42 +0100932
Bram Moolenaarab47c612016-06-14 22:02:26 +0200933" Test for quickfix directory stack support
Bram Moolenaar2b946c92016-11-12 18:14:44 +0100934func s:dir_stack_tests(cchar)
Bram Moolenaar38df43b2016-06-20 21:41:12 +0200935 call s:setup_commands(a:cchar)
936
Bram Moolenaarab47c612016-06-14 22:02:26 +0200937 let save_efm=&efm
938 set efm=%DEntering\ dir\ '%f',%f:%l:%m,%XLeaving\ dir\ '%f'
939
Bram Moolenaar361c8f02016-07-02 15:41:47 +0200940 let lines = ["Entering dir 'dir1/a'",
941 \ 'habits2.txt:1:Nine Healthy Habits',
942 \ "Entering dir 'b'",
943 \ 'habits3.txt:2:0 Hours of television',
944 \ 'habits2.txt:7:5 Small meals',
945 \ "Entering dir 'dir1/c'",
946 \ 'habits4.txt:3:1 Hour of exercise',
947 \ "Leaving dir 'dir1/c'",
948 \ "Leaving dir 'dir1/a'",
949 \ 'habits1.txt:4:2 Liters of water',
950 \ "Entering dir 'dir2'",
951 \ 'habits5.txt:5:3 Cups of hot green tea',
952 \ "Leaving dir 'dir2'"
953 \]
Bram Moolenaarab47c612016-06-14 22:02:26 +0200954
Bram Moolenaar361c8f02016-07-02 15:41:47 +0200955 Xexpr ""
956 for l in lines
957 Xaddexpr l
958 endfor
Bram Moolenaarab47c612016-06-14 22:02:26 +0200959
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +0200960 let qf = g:Xgetlist()
Bram Moolenaarab47c612016-06-14 22:02:26 +0200961
962 call assert_equal('dir1/a/habits2.txt', bufname(qf[1].bufnr))
963 call assert_equal(1, qf[1].lnum)
964 call assert_equal('dir1/a/b/habits3.txt', bufname(qf[3].bufnr))
965 call assert_equal(2, qf[3].lnum)
966 call assert_equal('dir1/a/habits2.txt', bufname(qf[4].bufnr))
967 call assert_equal(7, qf[4].lnum)
968 call assert_equal('dir1/c/habits4.txt', bufname(qf[6].bufnr))
969 call assert_equal(3, qf[6].lnum)
970 call assert_equal('habits1.txt', bufname(qf[9].bufnr))
971 call assert_equal(4, qf[9].lnum)
972 call assert_equal('dir2/habits5.txt', bufname(qf[11].bufnr))
973 call assert_equal(5, qf[11].lnum)
974
975 let &efm=save_efm
Bram Moolenaar2b946c92016-11-12 18:14:44 +0100976endfunc
Bram Moolenaarab47c612016-06-14 22:02:26 +0200977
978" Tests for %D and %X errorformat options
Bram Moolenaar2b946c92016-11-12 18:14:44 +0100979func Test_efm_dirstack()
Bram Moolenaarab47c612016-06-14 22:02:26 +0200980 " Create the directory stack and files
981 call mkdir('dir1')
982 call mkdir('dir1/a')
983 call mkdir('dir1/a/b')
984 call mkdir('dir1/c')
985 call mkdir('dir2')
986
987 let lines = ["Nine Healthy Habits",
988 \ "0 Hours of television",
989 \ "1 Hour of exercise",
990 \ "2 Liters of water",
991 \ "3 Cups of hot green tea",
992 \ "4 Short mental breaks",
993 \ "5 Small meals",
994 \ "6 AM wake up time",
995 \ "7 Minutes of laughter",
996 \ "8 Hours of sleep (at least)",
997 \ "9 PM end of the day and off to bed"
998 \ ]
999 call writefile(lines, 'habits1.txt')
1000 call writefile(lines, 'dir1/a/habits2.txt')
1001 call writefile(lines, 'dir1/a/b/habits3.txt')
1002 call writefile(lines, 'dir1/c/habits4.txt')
1003 call writefile(lines, 'dir2/habits5.txt')
1004
1005 call s:dir_stack_tests('c')
1006 call s:dir_stack_tests('l')
1007
1008 call delete('dir1', 'rf')
1009 call delete('dir2', 'rf')
1010 call delete('habits1.txt')
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001011endfunc
Bram Moolenaarab47c612016-06-14 22:02:26 +02001012
Bram Moolenaar9b457942016-10-09 16:10:05 +02001013" Test for resync after continuing an ignored message
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001014func Xefm_ignore_continuations(cchar)
Bram Moolenaar9b457942016-10-09 16:10:05 +02001015 call s:setup_commands(a:cchar)
1016
1017 let save_efm = &efm
1018
1019 let &efm =
1020 \ '%Eerror %m %l,' .
1021 \ '%-Wignored %m %l,' .
1022 \ '%+Cmore ignored %m %l,' .
1023 \ '%Zignored end'
1024 Xgetexpr ['ignored warning 1', 'more ignored continuation 2', 'ignored end', 'error resync 4']
1025 let l = map(g:Xgetlist(), '[v:val.text, v:val.valid, v:val.lnum, v:val.type]')
1026 call assert_equal([['resync', 1, 4, 'E']], l)
1027
1028 let &efm = save_efm
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001029endfunc
Bram Moolenaar9b457942016-10-09 16:10:05 +02001030
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001031func Test_efm_ignore_continuations()
Bram Moolenaar9b457942016-10-09 16:10:05 +02001032 call Xefm_ignore_continuations('c')
1033 call Xefm_ignore_continuations('l')
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001034endfunc
Bram Moolenaar9b457942016-10-09 16:10:05 +02001035
Bram Moolenaar0fcc7c62016-07-02 21:22:52 +02001036" Tests for invalid error format specifies
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001037func Xinvalid_efm_Tests(cchar)
Bram Moolenaar0fcc7c62016-07-02 21:22:52 +02001038 call s:setup_commands(a:cchar)
1039
Bram Moolenaar049cba92016-06-26 14:38:04 +02001040 let save_efm = &efm
1041
Bram Moolenaar0fcc7c62016-07-02 21:22:52 +02001042 set efm=%f:%l:%m,%f:%f:%l:%m
1043 call assert_fails('Xexpr "abc.txt:1:Hello world"', 'E372:')
1044
1045 set efm=%f:%l:%m,%f:%l:%r:%m
1046 call assert_fails('Xexpr "abc.txt:1:Hello world"', 'E373:')
1047
1048 set efm=%f:%l:%m,%O:%f:%l:%m
1049 call assert_fails('Xexpr "abc.txt:1:Hello world"', 'E373:')
1050
1051 set efm=%f:%l:%m,%f:%l:%*[^a-z
1052 call assert_fails('Xexpr "abc.txt:1:Hello world"', 'E374:')
1053
1054 set efm=%f:%l:%m,%f:%l:%*c
1055 call assert_fails('Xexpr "abc.txt:1:Hello world"', 'E375:')
1056
1057 set efm=%f:%l:%m,%L%M%N
1058 call assert_fails('Xexpr "abc.txt:1:Hello world"', 'E376:')
1059
1060 set efm=%f:%l:%m,%f:%l:%m:%R
1061 call assert_fails('Xexpr "abc.txt:1:Hello world"', 'E377:')
1062
1063 set efm=
1064 call assert_fails('Xexpr "abc.txt:1:Hello world"', 'E378:')
1065
1066 set efm=%DEntering\ dir\ abc,%f:%l:%m
1067 call assert_fails('Xexpr ["Entering dir abc", "abc.txt:1:Hello world"]', 'E379:')
1068
1069 let &efm = save_efm
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001070endfunc
Bram Moolenaar0fcc7c62016-07-02 21:22:52 +02001071
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001072func Test_invalid_efm()
Bram Moolenaar0fcc7c62016-07-02 21:22:52 +02001073 call Xinvalid_efm_Tests('c')
1074 call Xinvalid_efm_Tests('l')
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001075endfunc
Bram Moolenaar0fcc7c62016-07-02 21:22:52 +02001076
1077" TODO:
1078" Add tests for the following formats in 'errorformat'
1079" %r %O
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001080func Test_efm2()
Bram Moolenaar0fcc7c62016-07-02 21:22:52 +02001081 let save_efm = &efm
Bram Moolenaar049cba92016-06-26 14:38:04 +02001082
1083 " Test for %s format in efm
1084 set efm=%f:%s
1085 cexpr 'Xtestfile:Line search text'
Bram Moolenaar049cba92016-06-26 14:38:04 +02001086 let l = getqflist()
1087 call assert_equal(l[0].pattern, '^\VLine search text\$')
1088 call assert_equal(l[0].lnum, 0)
1089
Bram Moolenaaree85df32017-03-19 14:19:50 +01001090 let l = split(execute('clist', ''), "\n")
1091 call assert_equal([' 1 Xtestfile:^\VLine search text\$: '], l)
1092
Bram Moolenaar0fcc7c62016-07-02 21:22:52 +02001093 " Test for %P, %Q and %t format specifiers
Bram Moolenaarc79745a2019-05-20 22:12:34 +02001094 let lines =<< trim [DATA]
Bram Moolenaare7eb9272019-06-24 00:58:07 +02001095 [Xtestfile1]
1096 (1,17) error: ';' missing
1097 (21,2) warning: variable 'z' not defined
1098 (67,3) error: end of file found before string ended
1099 --
Bram Moolenaarc79745a2019-05-20 22:12:34 +02001100
Bram Moolenaare7eb9272019-06-24 00:58:07 +02001101 [Xtestfile2]
1102 --
Bram Moolenaarc79745a2019-05-20 22:12:34 +02001103
Bram Moolenaare7eb9272019-06-24 00:58:07 +02001104 [Xtestfile3]
1105 NEW compiler v1.1
1106 (2,2) warning: variable 'x' not defined
1107 (67,3) warning: 's' already defined
1108 --
Bram Moolenaarc79745a2019-05-20 22:12:34 +02001109 [DATA]
1110
Bram Moolenaaree85df32017-03-19 14:19:50 +01001111 set efm=%+P[%f]%r,(%l\\,%c)%*[\ ]%t%*[^:]:\ %m,%+Q--%r
Bram Moolenaar391b1dd2017-03-04 13:47:11 +01001112 " To exercise the push/pop file functionality in quickfix, the test files
1113 " need to be created.
1114 call writefile(['Line1'], 'Xtestfile1')
1115 call writefile(['Line2'], 'Xtestfile2')
1116 call writefile(['Line3'], 'Xtestfile3')
Bram Moolenaar361c8f02016-07-02 15:41:47 +02001117 cexpr ""
1118 for l in lines
1119 caddexpr l
1120 endfor
Bram Moolenaar049cba92016-06-26 14:38:04 +02001121 let l = getqflist()
Bram Moolenaaree85df32017-03-19 14:19:50 +01001122 call assert_equal(12, len(l))
Bram Moolenaar049cba92016-06-26 14:38:04 +02001123 call assert_equal(21, l[2].lnum)
1124 call assert_equal(2, l[2].col)
Bram Moolenaar0fcc7c62016-07-02 21:22:52 +02001125 call assert_equal('w', l[2].type)
1126 call assert_equal('e', l[3].type)
Bram Moolenaar391b1dd2017-03-04 13:47:11 +01001127 call delete('Xtestfile1')
1128 call delete('Xtestfile2')
1129 call delete('Xtestfile3')
Bram Moolenaar0fcc7c62016-07-02 21:22:52 +02001130
1131 " Tests for %E, %C and %Z format specifiers
Bram Moolenaarc79745a2019-05-20 22:12:34 +02001132 let lines =<< trim [DATA]
Bram Moolenaare7eb9272019-06-24 00:58:07 +02001133 Error 275
1134 line 42
1135 column 3
1136 ' ' expected after '--'
Bram Moolenaarc79745a2019-05-20 22:12:34 +02001137 [DATA]
1138
Bram Moolenaar0fcc7c62016-07-02 21:22:52 +02001139 set efm=%EError\ %n,%Cline\ %l,%Ccolumn\ %c,%Z%m
1140 cgetexpr lines
1141 let l = getqflist()
1142 call assert_equal(275, l[0].nr)
1143 call assert_equal(42, l[0].lnum)
1144 call assert_equal(3, l[0].col)
1145 call assert_equal('E', l[0].type)
1146 call assert_equal("\n' ' expected after '--'", l[0].text)
1147
1148 " Test for %>
Bram Moolenaarc79745a2019-05-20 22:12:34 +02001149 let lines =<< trim [DATA]
Bram Moolenaare7eb9272019-06-24 00:58:07 +02001150 Error in line 147 of foo.c:
1151 unknown variable 'i'
Bram Moolenaarc79745a2019-05-20 22:12:34 +02001152 [DATA]
1153
Bram Moolenaar0fcc7c62016-07-02 21:22:52 +02001154 set efm=unknown\ variable\ %m,%E%>Error\ in\ line\ %l\ of\ %f:,%Z%m
1155 cgetexpr lines
1156 let l = getqflist()
1157 call assert_equal(147, l[0].lnum)
1158 call assert_equal('E', l[0].type)
1159 call assert_equal("\nunknown variable 'i'", l[0].text)
Bram Moolenaar049cba92016-06-26 14:38:04 +02001160
Bram Moolenaare87e6dd2016-07-17 19:25:04 +02001161 " Test for %A, %C and other formats
Bram Moolenaarc79745a2019-05-20 22:12:34 +02001162 let lines =<< trim [DATA]
Bram Moolenaare7eb9272019-06-24 00:58:07 +02001163 ==============================================================
1164 FAIL: testGetTypeIdCachesResult (dbfacadeTest.DjsDBFacadeTest)
1165 --------------------------------------------------------------
1166 Traceback (most recent call last):
1167 File "unittests/dbfacadeTest.py", line 89, in testFoo
1168 self.assertEquals(34, dtid)
1169 File "/usr/lib/python2.2/unittest.py", line 286, in
1170 failUnlessEqual
1171 raise self.failureException, \\
1172 AssertionError: 34 != 33
1173
1174 --------------------------------------------------------------
1175 Ran 27 tests in 0.063s
Bram Moolenaarc79745a2019-05-20 22:12:34 +02001176 [DATA]
1177
Bram Moolenaare87e6dd2016-07-17 19:25:04 +02001178 set efm=%C\ %.%#,%A\ \ File\ \"%f\"\\,\ line\ %l%.%#,%Z%[%^\ ]%\\@=%m
1179 cgetexpr lines
1180 let l = getqflist()
1181 call assert_equal(8, len(l))
1182 call assert_equal(89, l[4].lnum)
1183 call assert_equal(1, l[4].valid)
1184 call assert_equal('unittests/dbfacadeTest.py', bufname(l[4].bufnr))
1185
Bram Moolenaard76ce852018-05-01 15:02:04 +02001186 " Test for %o
1187 set efm=%f(%o):%l\ %m
Bram Moolenaarbc7845d2018-05-01 16:26:48 +02001188 cgetexpr ['Xotestfile(Language.PureScript.Types):20 Error']
1189 call writefile(['Line1'], 'Xotestfile')
Bram Moolenaard76ce852018-05-01 15:02:04 +02001190 let l = getqflist()
1191 call assert_equal(1, len(l), string(l))
1192 call assert_equal('Language.PureScript.Types', l[0].module)
1193 copen
1194 call assert_equal('Language.PureScript.Types|20| Error', getline(1))
1195 call feedkeys("\<CR>", 'xn')
Bram Moolenaarbc7845d2018-05-01 16:26:48 +02001196 call assert_equal('Xotestfile', expand('%:t'))
Bram Moolenaard76ce852018-05-01 15:02:04 +02001197 cclose
1198 bd
Bram Moolenaarbc7845d2018-05-01 16:26:48 +02001199 call delete("Xotestfile")
Bram Moolenaard76ce852018-05-01 15:02:04 +02001200
Bram Moolenaar99895ea2017-04-20 22:44:47 +02001201 " The following sequence of commands used to crash Vim
1202 set efm=%W%m
1203 cgetexpr ['msg1']
1204 let l = getqflist()
1205 call assert_equal(1, len(l), string(l))
1206 call assert_equal('msg1', l[0].text)
1207 set efm=%C%m
1208 lexpr 'msg2'
1209 let l = getloclist(0)
1210 call assert_equal(1, len(l), string(l))
1211 call assert_equal('msg2', l[0].text)
1212 lopen
1213 call setqflist([], 'r')
1214 caddbuf
1215 let l = getqflist()
1216 call assert_equal(1, len(l), string(l))
1217 call assert_equal('|| msg2', l[0].text)
1218
Bram Moolenaar78ddc062018-05-15 21:56:34 +02001219 " When matching error lines, case should be ignored. Test for this.
1220 set noignorecase
1221 let l=getqflist({'lines' : ['Xtest:FOO10:Line 20'], 'efm':'%f:foo%l:%m'})
1222 call assert_equal(10, l.items[0].lnum)
1223 call assert_equal('Line 20', l.items[0].text)
1224 set ignorecase&
1225
Bram Moolenaar99895ea2017-04-20 22:44:47 +02001226 new | only
Bram Moolenaar049cba92016-06-26 14:38:04 +02001227 let &efm = save_efm
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001228endfunc
Bram Moolenaar049cba92016-06-26 14:38:04 +02001229
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001230func XquickfixChangedByAutocmd(cchar)
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001231 call s:setup_commands(a:cchar)
Bram Moolenaarffec3c52016-03-23 20:55:42 +01001232 if a:cchar == 'c'
Bram Moolenaarffec3c52016-03-23 20:55:42 +01001233 let ErrorNr = 'E925'
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001234 func! ReadFunc()
Bram Moolenaarffec3c52016-03-23 20:55:42 +01001235 colder
1236 cgetexpr []
1237 endfunc
1238 else
Bram Moolenaarffec3c52016-03-23 20:55:42 +01001239 let ErrorNr = 'E926'
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001240 func! ReadFunc()
Bram Moolenaarffec3c52016-03-23 20:55:42 +01001241 lolder
1242 lgetexpr []
1243 endfunc
1244 endif
1245
1246 augroup testgroup
1247 au!
Bram Moolenaard106e5b2016-04-21 19:38:07 +02001248 autocmd BufReadCmd test_changed.txt call ReadFunc()
Bram Moolenaarffec3c52016-03-23 20:55:42 +01001249 augroup END
1250
Bram Moolenaard106e5b2016-04-21 19:38:07 +02001251 new | only
Bram Moolenaarffec3c52016-03-23 20:55:42 +01001252 let words = [ "a", "b" ]
1253 let qflist = []
1254 for word in words
Bram Moolenaard106e5b2016-04-21 19:38:07 +02001255 call add(qflist, {'filename': 'test_changed.txt'})
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001256 call g:Xsetlist(qflist, ' ')
Bram Moolenaarffec3c52016-03-23 20:55:42 +01001257 endfor
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001258 call assert_fails('Xrewind', ErrorNr . ':')
Bram Moolenaarffec3c52016-03-23 20:55:42 +01001259
1260 augroup! testgroup
1261endfunc
1262
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001263func Test_quickfix_was_changed_by_autocmd()
Bram Moolenaarffec3c52016-03-23 20:55:42 +01001264 call XquickfixChangedByAutocmd('c')
1265 call XquickfixChangedByAutocmd('l')
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001266endfunc
Bram Moolenaar8b201792016-03-25 15:01:10 +01001267
1268func Test_caddbuffer_to_empty()
1269 helpgr quickfix
1270 call setqflist([], 'r')
1271 cad
Bram Moolenaarf68f1d72016-03-25 17:14:06 +01001272 try
1273 cn
1274 catch
1275 " number of matches is unknown
1276 call assert_true(v:exception =~ 'E553:')
1277 endtry
Bram Moolenaar8b201792016-03-25 15:01:10 +01001278 quit!
1279endfunc
Bram Moolenaar89c64d52016-03-27 18:44:40 +02001280
1281func Test_cgetexpr_works()
1282 " this must not crash Vim
1283 cgetexpr [$x]
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001284 lgetexpr [$x]
Bram Moolenaar89c64d52016-03-27 18:44:40 +02001285endfunc
Bram Moolenaarc1808d52016-04-18 20:04:00 +02001286
1287" Tests for the setqflist() and setloclist() functions
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001288func SetXlistTests(cchar, bnum)
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001289 call s:setup_commands(a:cchar)
Bram Moolenaarc1808d52016-04-18 20:04:00 +02001290
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001291 call g:Xsetlist([{'bufnr': a:bnum, 'lnum': 1},
Bram Moolenaarc1808d52016-04-18 20:04:00 +02001292 \ {'bufnr': a:bnum, 'lnum': 2}])
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001293 let l = g:Xgetlist()
Bram Moolenaarc1808d52016-04-18 20:04:00 +02001294 call assert_equal(2, len(l))
1295 call assert_equal(2, l[1].lnum)
1296
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001297 Xnext
1298 call g:Xsetlist([{'bufnr': a:bnum, 'lnum': 3}], 'a')
1299 let l = g:Xgetlist()
Bram Moolenaarc1808d52016-04-18 20:04:00 +02001300 call assert_equal(3, len(l))
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001301 Xnext
Bram Moolenaarc1808d52016-04-18 20:04:00 +02001302 call assert_equal(3, line('.'))
1303
Bram Moolenaar2b2b8ae2016-05-24 19:59:51 +02001304 " Appending entries to the list should not change the cursor position
1305 " in the quickfix window
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001306 Xwindow
Bram Moolenaar2b2b8ae2016-05-24 19:59:51 +02001307 1
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001308 call g:Xsetlist([{'bufnr': a:bnum, 'lnum': 4},
Bram Moolenaar2b2b8ae2016-05-24 19:59:51 +02001309 \ {'bufnr': a:bnum, 'lnum': 5}], 'a')
1310 call assert_equal(1, line('.'))
1311 close
1312
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001313 call g:Xsetlist([{'bufnr': a:bnum, 'lnum': 3},
Bram Moolenaarc1808d52016-04-18 20:04:00 +02001314 \ {'bufnr': a:bnum, 'lnum': 4},
1315 \ {'bufnr': a:bnum, 'lnum': 5}], 'r')
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001316 let l = g:Xgetlist()
Bram Moolenaarc1808d52016-04-18 20:04:00 +02001317 call assert_equal(3, len(l))
1318 call assert_equal(5, l[2].lnum)
1319
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001320 call g:Xsetlist([])
1321 let l = g:Xgetlist()
Bram Moolenaarc1808d52016-04-18 20:04:00 +02001322 call assert_equal(0, len(l))
Bram Moolenaaree85df32017-03-19 14:19:50 +01001323
Bram Moolenaarf1d21c82017-04-22 21:20:46 +02001324 " Tests for setting the 'valid' flag
1325 call g:Xsetlist([{'bufnr':a:bnum, 'lnum':4, 'valid':0}])
1326 Xwindow
1327 call assert_equal(1, winnr('$'))
1328 let l = g:Xgetlist()
1329 call g:Xsetlist(l)
1330 call assert_equal(0, g:Xgetlist()[0].valid)
Bram Moolenaar9752c722018-12-22 16:49:34 +01001331 " Adding a non-valid entry should not mark the list as having valid entries
1332 call g:Xsetlist([{'bufnr':a:bnum, 'lnum':5, 'valid':0}], 'a')
1333 Xwindow
1334 call assert_equal(1, winnr('$'))
1335
1336 " :cnext/:cprev should still work even with invalid entries in the list
1337 let l = [{'bufnr' : a:bnum, 'lnum' : 1, 'text' : '1', 'valid' : 0},
1338 \ {'bufnr' : a:bnum, 'lnum' : 2, 'text' : '2', 'valid' : 0}]
1339 call g:Xsetlist(l)
1340 Xnext
1341 call assert_equal(2, g:Xgetlist({'idx' : 0}).idx)
1342 Xprev
1343 call assert_equal(1, g:Xgetlist({'idx' : 0}).idx)
1344 " :cnext/:cprev should still work after appending invalid entries to an
1345 " empty list
1346 call g:Xsetlist([])
1347 call g:Xsetlist(l, 'a')
1348 Xnext
1349 call assert_equal(2, g:Xgetlist({'idx' : 0}).idx)
1350 Xprev
1351 call assert_equal(1, g:Xgetlist({'idx' : 0}).idx)
1352
Bram Moolenaarf1d21c82017-04-22 21:20:46 +02001353 call g:Xsetlist([{'text':'Text1', 'valid':1}])
1354 Xwindow
1355 call assert_equal(2, winnr('$'))
1356 Xclose
1357 let save_efm = &efm
1358 set efm=%m
1359 Xgetexpr 'TestMessage'
1360 let l = g:Xgetlist()
1361 call g:Xsetlist(l)
1362 call assert_equal(1, g:Xgetlist()[0].valid)
1363 let &efm = save_efm
1364
Bram Moolenaaree85df32017-03-19 14:19:50 +01001365 " Error cases:
1366 " Refer to a non-existing buffer and pass a non-dictionary type
1367 call assert_fails("call g:Xsetlist([{'bufnr':998, 'lnum':4}," .
1368 \ " {'bufnr':999, 'lnum':5}])", 'E92:')
1369 call g:Xsetlist([[1, 2,3]])
1370 call assert_equal(0, len(g:Xgetlist()))
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001371endfunc
Bram Moolenaarc1808d52016-04-18 20:04:00 +02001372
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001373func Test_setqflist()
Bram Moolenaarc1808d52016-04-18 20:04:00 +02001374 new Xtestfile | only
1375 let bnum = bufnr('%')
1376 call setline(1, range(1,5))
1377
1378 call SetXlistTests('c', bnum)
1379 call SetXlistTests('l', bnum)
1380
Bram Moolenaar1cee6932016-06-09 22:17:22 +02001381 enew!
Bram Moolenaarc1808d52016-04-18 20:04:00 +02001382 call delete('Xtestfile')
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001383endfunc
Bram Moolenaard106e5b2016-04-21 19:38:07 +02001384
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001385func Xlist_empty_middle(cchar)
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001386 call s:setup_commands(a:cchar)
1387
Bram Moolenaar1cee6932016-06-09 22:17:22 +02001388 " create three quickfix lists
Bram Moolenaaree85df32017-03-19 14:19:50 +01001389 let @/ = 'Test_'
1390 Xvimgrep // test_quickfix.vim
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001391 let testlen = len(g:Xgetlist())
Bram Moolenaar1cee6932016-06-09 22:17:22 +02001392 call assert_true(testlen > 0)
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001393 Xvimgrep empty test_quickfix.vim
1394 call assert_true(len(g:Xgetlist()) > 0)
1395 Xvimgrep matches test_quickfix.vim
1396 let matchlen = len(g:Xgetlist())
Bram Moolenaar1cee6932016-06-09 22:17:22 +02001397 call assert_true(matchlen > 0)
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001398 Xolder
Bram Moolenaar1cee6932016-06-09 22:17:22 +02001399 " make the middle list empty
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001400 call g:Xsetlist([], 'r')
1401 call assert_true(len(g:Xgetlist()) == 0)
1402 Xolder
1403 call assert_equal(testlen, len(g:Xgetlist()))
1404 Xnewer
1405 Xnewer
1406 call assert_equal(matchlen, len(g:Xgetlist()))
Bram Moolenaar1cee6932016-06-09 22:17:22 +02001407endfunc
1408
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001409func Test_setqflist_empty_middle()
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001410 call Xlist_empty_middle('c')
1411 call Xlist_empty_middle('l')
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001412endfunc
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001413
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001414func Xlist_empty_older(cchar)
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001415 call s:setup_commands(a:cchar)
1416
Bram Moolenaar1cee6932016-06-09 22:17:22 +02001417 " create three quickfix lists
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001418 Xvimgrep one test_quickfix.vim
1419 let onelen = len(g:Xgetlist())
Bram Moolenaar1cee6932016-06-09 22:17:22 +02001420 call assert_true(onelen > 0)
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001421 Xvimgrep two test_quickfix.vim
1422 let twolen = len(g:Xgetlist())
Bram Moolenaar1cee6932016-06-09 22:17:22 +02001423 call assert_true(twolen > 0)
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001424 Xvimgrep three test_quickfix.vim
1425 let threelen = len(g:Xgetlist())
Bram Moolenaar1cee6932016-06-09 22:17:22 +02001426 call assert_true(threelen > 0)
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001427 Xolder 2
Bram Moolenaar1cee6932016-06-09 22:17:22 +02001428 " make the first list empty, check the others didn't change
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001429 call g:Xsetlist([], 'r')
1430 call assert_true(len(g:Xgetlist()) == 0)
1431 Xnewer
1432 call assert_equal(twolen, len(g:Xgetlist()))
1433 Xnewer
1434 call assert_equal(threelen, len(g:Xgetlist()))
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001435endfunc
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001436
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001437func Test_setqflist_empty_older()
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001438 call Xlist_empty_older('c')
1439 call Xlist_empty_older('l')
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001440endfunc
Bram Moolenaar1cee6932016-06-09 22:17:22 +02001441
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001442func XquickfixSetListWithAct(cchar)
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001443 call s:setup_commands(a:cchar)
1444
Bram Moolenaard106e5b2016-04-21 19:38:07 +02001445 let list1 = [{'filename': 'fnameA', 'text': 'A'},
1446 \ {'filename': 'fnameB', 'text': 'B'}]
1447 let list2 = [{'filename': 'fnameC', 'text': 'C'},
1448 \ {'filename': 'fnameD', 'text': 'D'},
1449 \ {'filename': 'fnameE', 'text': 'E'}]
1450
Bram Moolenaareeb1b9c2019-02-10 22:59:04 +01001451 " {action} is unspecified. Same as specifying ' '.
Bram Moolenaard106e5b2016-04-21 19:38:07 +02001452 new | only
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001453 silent! Xnewer 99
1454 call g:Xsetlist(list1)
1455 call g:Xsetlist(list2)
1456 let li = g:Xgetlist()
Bram Moolenaard106e5b2016-04-21 19:38:07 +02001457 call assert_equal(3, len(li))
1458 call assert_equal('C', li[0]['text'])
1459 call assert_equal('D', li[1]['text'])
1460 call assert_equal('E', li[2]['text'])
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001461 silent! Xolder
1462 let li = g:Xgetlist()
Bram Moolenaard106e5b2016-04-21 19:38:07 +02001463 call assert_equal(2, len(li))
1464 call assert_equal('A', li[0]['text'])
1465 call assert_equal('B', li[1]['text'])
1466
1467 " {action} is specified ' '.
1468 new | only
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001469 silent! Xnewer 99
1470 call g:Xsetlist(list1)
1471 call g:Xsetlist(list2, ' ')
1472 let li = g:Xgetlist()
Bram Moolenaard106e5b2016-04-21 19:38:07 +02001473 call assert_equal(3, len(li))
1474 call assert_equal('C', li[0]['text'])
1475 call assert_equal('D', li[1]['text'])
1476 call assert_equal('E', li[2]['text'])
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001477 silent! Xolder
1478 let li = g:Xgetlist()
Bram Moolenaard106e5b2016-04-21 19:38:07 +02001479 call assert_equal(2, len(li))
1480 call assert_equal('A', li[0]['text'])
1481 call assert_equal('B', li[1]['text'])
1482
1483 " {action} is specified 'a'.
1484 new | only
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001485 silent! Xnewer 99
1486 call g:Xsetlist(list1)
1487 call g:Xsetlist(list2, 'a')
1488 let li = g:Xgetlist()
Bram Moolenaard106e5b2016-04-21 19:38:07 +02001489 call assert_equal(5, len(li))
1490 call assert_equal('A', li[0]['text'])
1491 call assert_equal('B', li[1]['text'])
1492 call assert_equal('C', li[2]['text'])
1493 call assert_equal('D', li[3]['text'])
1494 call assert_equal('E', li[4]['text'])
1495
1496 " {action} is specified 'r'.
1497 new | only
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001498 silent! Xnewer 99
1499 call g:Xsetlist(list1)
1500 call g:Xsetlist(list2, 'r')
1501 let li = g:Xgetlist()
Bram Moolenaard106e5b2016-04-21 19:38:07 +02001502 call assert_equal(3, len(li))
1503 call assert_equal('C', li[0]['text'])
1504 call assert_equal('D', li[1]['text'])
1505 call assert_equal('E', li[2]['text'])
1506
1507 " Test for wrong value.
1508 new | only
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001509 call assert_fails("call g:Xsetlist(0)", 'E714:')
1510 call assert_fails("call g:Xsetlist(list1, '')", 'E927:')
1511 call assert_fails("call g:Xsetlist(list1, 'aa')", 'E927:')
1512 call assert_fails("call g:Xsetlist(list1, ' a')", 'E927:')
1513 call assert_fails("call g:Xsetlist(list1, 0)", 'E928:')
Bram Moolenaard106e5b2016-04-21 19:38:07 +02001514endfunc
1515
Bram Moolenaara0ca7d02017-12-19 10:22:19 +01001516func Test_setqflist_invalid_nr()
1517 " The following command used to crash Vim
Bram Moolenaaraad222c2019-09-06 22:46:09 +02001518 eval []->setqflist(' ', {'nr' : $XXX_DOES_NOT_EXIST})
Bram Moolenaara0ca7d02017-12-19 10:22:19 +01001519endfunc
1520
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001521func Test_quickfix_set_list_with_act()
Bram Moolenaard106e5b2016-04-21 19:38:07 +02001522 call XquickfixSetListWithAct('c')
1523 call XquickfixSetListWithAct('l')
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001524endfunc
Bram Moolenaar6be8c8e2016-04-30 13:17:09 +02001525
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001526func XLongLinesTests(cchar)
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001527 let l = g:Xgetlist()
Bram Moolenaar6be8c8e2016-04-30 13:17:09 +02001528
Bram Moolenaar049cba92016-06-26 14:38:04 +02001529 call assert_equal(4, len(l))
Bram Moolenaar6be8c8e2016-04-30 13:17:09 +02001530 call assert_equal(1, l[0].lnum)
1531 call assert_equal(1, l[0].col)
Bram Moolenaar049cba92016-06-26 14:38:04 +02001532 call assert_equal(1975, len(l[0].text))
Bram Moolenaar6be8c8e2016-04-30 13:17:09 +02001533 call assert_equal(2, l[1].lnum)
1534 call assert_equal(1, l[1].col)
1535 call assert_equal(4070, len(l[1].text))
1536 call assert_equal(3, l[2].lnum)
1537 call assert_equal(1, l[2].col)
Bram Moolenaar049cba92016-06-26 14:38:04 +02001538 call assert_equal(4070, len(l[2].text))
1539 call assert_equal(4, l[3].lnum)
1540 call assert_equal(1, l[3].col)
1541 call assert_equal(10, len(l[3].text))
Bram Moolenaar6be8c8e2016-04-30 13:17:09 +02001542
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001543 call g:Xsetlist([], 'r')
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001544endfunc
Bram Moolenaar6be8c8e2016-04-30 13:17:09 +02001545
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001546func s:long_lines_tests(cchar)
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001547 call s:setup_commands(a:cchar)
1548
Bram Moolenaar6be8c8e2016-04-30 13:17:09 +02001549 let testfile = 'samples/quickfix.txt'
1550
1551 " file
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001552 exe 'Xgetfile' testfile
1553 call XLongLinesTests(a:cchar)
Bram Moolenaar6be8c8e2016-04-30 13:17:09 +02001554
1555 " list
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001556 Xexpr readfile(testfile)
1557 call XLongLinesTests(a:cchar)
Bram Moolenaar6be8c8e2016-04-30 13:17:09 +02001558
1559 " string
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001560 Xexpr join(readfile(testfile), "\n")
1561 call XLongLinesTests(a:cchar)
Bram Moolenaar6be8c8e2016-04-30 13:17:09 +02001562
1563 " buffer
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001564 exe 'edit' testfile
1565 exe 'Xbuffer' bufnr('%')
Bram Moolenaarf50df392016-06-21 21:33:34 +02001566 call XLongLinesTests(a:cchar)
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001567endfunc
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001568
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001569func Test_long_lines()
Bram Moolenaar3ef5bf72016-06-15 22:41:31 +02001570 call s:long_lines_tests('c')
1571 call s:long_lines_tests('l')
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001572endfunc
Bram Moolenaar049cba92016-06-26 14:38:04 +02001573
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001574func s:create_test_file(filename)
Bram Moolenaar049cba92016-06-26 14:38:04 +02001575 let l = []
1576 for i in range(1, 20)
1577 call add(l, 'Line' . i)
1578 endfor
1579 call writefile(l, a:filename)
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001580endfunc
Bram Moolenaar049cba92016-06-26 14:38:04 +02001581
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001582func Test_switchbuf()
Bram Moolenaar049cba92016-06-26 14:38:04 +02001583 call s:create_test_file('Xqftestfile1')
1584 call s:create_test_file('Xqftestfile2')
1585 call s:create_test_file('Xqftestfile3')
1586
1587 new | only
1588 edit Xqftestfile1
1589 let file1_winid = win_getid()
1590 new Xqftestfile2
1591 let file2_winid = win_getid()
1592 cgetexpr ['Xqftestfile1:5:Line5',
1593 \ 'Xqftestfile1:6:Line6',
1594 \ 'Xqftestfile2:10:Line10',
1595 \ 'Xqftestfile2:11:Line11',
1596 \ 'Xqftestfile3:15:Line15',
1597 \ 'Xqftestfile3:16:Line16']
1598
1599 new
1600 let winid = win_getid()
1601 cfirst | cnext
1602 call assert_equal(winid, win_getid())
Bram Moolenaar99895ea2017-04-20 22:44:47 +02001603 2cnext
Bram Moolenaar049cba92016-06-26 14:38:04 +02001604 call assert_equal(winid, win_getid())
Bram Moolenaar99895ea2017-04-20 22:44:47 +02001605 2cnext
Bram Moolenaar049cba92016-06-26 14:38:04 +02001606 call assert_equal(winid, win_getid())
1607 enew
1608
1609 set switchbuf=useopen
1610 cfirst | cnext
1611 call assert_equal(file1_winid, win_getid())
Bram Moolenaar99895ea2017-04-20 22:44:47 +02001612 2cnext
Bram Moolenaar049cba92016-06-26 14:38:04 +02001613 call assert_equal(file2_winid, win_getid())
Bram Moolenaar99895ea2017-04-20 22:44:47 +02001614 2cnext
Bram Moolenaar049cba92016-06-26 14:38:04 +02001615 call assert_equal(file2_winid, win_getid())
1616
1617 enew | only
1618 set switchbuf=usetab
1619 tabedit Xqftestfile1
1620 tabedit Xqftestfile2
Bram Moolenaar74240d32017-12-10 15:26:15 +01001621 tabedit Xqftestfile3
Bram Moolenaar049cba92016-06-26 14:38:04 +02001622 tabfirst
1623 cfirst | cnext
1624 call assert_equal(2, tabpagenr())
Bram Moolenaar99895ea2017-04-20 22:44:47 +02001625 2cnext
Bram Moolenaar049cba92016-06-26 14:38:04 +02001626 call assert_equal(3, tabpagenr())
Bram Moolenaar74240d32017-12-10 15:26:15 +01001627 6cnext
1628 call assert_equal(4, tabpagenr())
1629 2cpfile
1630 call assert_equal(2, tabpagenr())
1631 2cnfile
1632 call assert_equal(4, tabpagenr())
Bram Moolenaar049cba92016-06-26 14:38:04 +02001633 tabfirst | tabonly | enew
1634
1635 set switchbuf=split
1636 cfirst | cnext
1637 call assert_equal(1, winnr('$'))
1638 cnext | cnext
1639 call assert_equal(2, winnr('$'))
1640 cnext | cnext
1641 call assert_equal(3, winnr('$'))
1642 enew | only
1643
1644 set switchbuf=newtab
1645 cfirst | cnext
1646 call assert_equal(1, tabpagenr('$'))
1647 cnext | cnext
1648 call assert_equal(2, tabpagenr('$'))
1649 cnext | cnext
1650 call assert_equal(3, tabpagenr('$'))
1651 tabfirst | enew | tabonly | only
1652
1653 set switchbuf=
1654 edit Xqftestfile1
1655 let file1_winid = win_getid()
1656 new Xqftestfile2
1657 let file2_winid = win_getid()
1658 copen
1659 exe "normal 1G\<CR>"
1660 call assert_equal(file1_winid, win_getid())
1661 copen
1662 exe "normal 3G\<CR>"
1663 call assert_equal(file2_winid, win_getid())
1664 copen | only
1665 exe "normal 5G\<CR>"
1666 call assert_equal(2, winnr('$'))
1667 call assert_equal(1, bufwinnr('Xqftestfile3'))
1668
Bram Moolenaar391b1dd2017-03-04 13:47:11 +01001669 " If only quickfix window is open in the current tabpage, jumping to an
Bram Moolenaar1bc353b2019-09-01 14:45:28 +02001670 " entry with 'switchbuf' set to 'usetab' should search in other tabpages.
Bram Moolenaar049cba92016-06-26 14:38:04 +02001671 enew | only
Bram Moolenaar391b1dd2017-03-04 13:47:11 +01001672 set switchbuf=usetab
1673 tabedit Xqftestfile1
1674 tabedit Xqftestfile2
1675 tabedit Xqftestfile3
1676 tabfirst
1677 copen | only
1678 clast
1679 call assert_equal(4, tabpagenr())
1680 tabfirst | tabonly | enew | only
Bram Moolenaar049cba92016-06-26 14:38:04 +02001681
1682 call delete('Xqftestfile1')
1683 call delete('Xqftestfile2')
1684 call delete('Xqftestfile3')
Bram Moolenaar391b1dd2017-03-04 13:47:11 +01001685 set switchbuf&vim
1686
1687 enew | only
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001688endfunc
Bram Moolenaar049cba92016-06-26 14:38:04 +02001689
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001690func Xadjust_qflnum(cchar)
Bram Moolenaar049cba92016-06-26 14:38:04 +02001691 call s:setup_commands(a:cchar)
1692
1693 enew | only
1694
Bram Moolenaarc1542742016-07-20 21:44:37 +02001695 let fname = 'Xqftestfile' . a:cchar
1696 call s:create_test_file(fname)
1697 exe 'edit ' . fname
Bram Moolenaar049cba92016-06-26 14:38:04 +02001698
Bram Moolenaarc1542742016-07-20 21:44:37 +02001699 Xgetexpr [fname . ':5:Line5',
1700 \ fname . ':10:Line10',
1701 \ fname . ':15:Line15',
1702 \ fname . ':20:Line20']
Bram Moolenaar049cba92016-06-26 14:38:04 +02001703
1704 6,14delete
1705 call append(6, ['Buffer', 'Window'])
1706
1707 let l = g:Xgetlist()
1708
1709 call assert_equal(5, l[0].lnum)
1710 call assert_equal(6, l[2].lnum)
1711 call assert_equal(13, l[3].lnum)
1712
1713 enew!
Bram Moolenaarc1542742016-07-20 21:44:37 +02001714 call delete(fname)
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001715endfunc
Bram Moolenaar049cba92016-06-26 14:38:04 +02001716
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001717func Test_adjust_lnum()
Bram Moolenaarc1542742016-07-20 21:44:37 +02001718 call setloclist(0, [])
Bram Moolenaar049cba92016-06-26 14:38:04 +02001719 call Xadjust_qflnum('c')
Bram Moolenaarc1542742016-07-20 21:44:37 +02001720 call setqflist([])
Bram Moolenaar049cba92016-06-26 14:38:04 +02001721 call Xadjust_qflnum('l')
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001722endfunc
Bram Moolenaar049cba92016-06-26 14:38:04 +02001723
1724" Tests for the :grep/:lgrep and :grepadd/:lgrepadd commands
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001725func s:test_xgrep(cchar)
Bram Moolenaar049cba92016-06-26 14:38:04 +02001726 call s:setup_commands(a:cchar)
1727
1728 " The following lines are used for the grep test. Don't remove.
1729 " Grep_Test_Text: Match 1
1730 " Grep_Test_Text: Match 2
1731 " GrepAdd_Test_Text: Match 1
1732 " GrepAdd_Test_Text: Match 2
1733 enew! | only
1734 set makeef&vim
1735 silent Xgrep Grep_Test_Text: test_quickfix.vim
1736 call assert_true(len(g:Xgetlist()) == 3)
1737 Xopen
1738 call assert_true(w:quickfix_title =~ '^:grep')
1739 Xclose
1740 enew
1741 set makeef=Temp_File_##
1742 silent Xgrepadd GrepAdd_Test_Text: test_quickfix.vim
1743 call assert_true(len(g:Xgetlist()) == 6)
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001744endfunc
Bram Moolenaar049cba92016-06-26 14:38:04 +02001745
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001746func Test_grep()
Bram Moolenaar049cba92016-06-26 14:38:04 +02001747 if !has('unix')
1748 " The grepprg may not be set on non-Unix systems
1749 return
1750 endif
1751
1752 call s:test_xgrep('c')
1753 call s:test_xgrep('l')
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001754endfunc
Bram Moolenaar361c8f02016-07-02 15:41:47 +02001755
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001756func Test_two_windows()
Bram Moolenaar361c8f02016-07-02 15:41:47 +02001757 " Use one 'errorformat' for two windows. Add an expression to each of them,
1758 " make sure they each keep their own state.
1759 set efm=%DEntering\ dir\ '%f',%f:%l:%m,%XLeaving\ dir\ '%f'
1760 call mkdir('Xone/a', 'p')
1761 call mkdir('Xtwo/a', 'p')
1762 let lines = ['1', '2', 'one one one', '4', 'two two two', '6', '7']
1763 call writefile(lines, 'Xone/a/one.txt')
1764 call writefile(lines, 'Xtwo/a/two.txt')
1765
1766 new one
1767 let one_id = win_getid()
1768 lexpr ""
1769 new two
1770 let two_id = win_getid()
1771 lexpr ""
1772
1773 laddexpr "Entering dir 'Xtwo/a'"
1774 call win_gotoid(one_id)
1775 laddexpr "Entering dir 'Xone/a'"
1776 call win_gotoid(two_id)
1777 laddexpr 'two.txt:5:two two two'
1778 call win_gotoid(one_id)
1779 laddexpr 'one.txt:3:one one one'
1780
1781 let loc_one = getloclist(one_id)
Bram Moolenaar361c8f02016-07-02 15:41:47 +02001782 call assert_equal('Xone/a/one.txt', bufname(loc_one[1].bufnr))
1783 call assert_equal(3, loc_one[1].lnum)
1784
1785 let loc_two = getloclist(two_id)
Bram Moolenaar361c8f02016-07-02 15:41:47 +02001786 call assert_equal('Xtwo/a/two.txt', bufname(loc_two[1].bufnr))
1787 call assert_equal(5, loc_two[1].lnum)
1788
1789 call win_gotoid(one_id)
1790 bwipe!
1791 call win_gotoid(two_id)
1792 bwipe!
1793 call delete('Xone', 'rf')
1794 call delete('Xtwo', 'rf')
1795endfunc
Bram Moolenaardcb17002016-07-07 18:58:59 +02001796
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001797func XbottomTests(cchar)
Bram Moolenaar537ef082016-07-09 17:56:19 +02001798 call s:setup_commands(a:cchar)
1799
Bram Moolenaarb6fa30c2017-03-29 14:19:25 +02001800 " Calling lbottom without any errors should fail
1801 if a:cchar == 'l'
1802 call assert_fails('lbottom', 'E776:')
1803 endif
1804
Bram Moolenaar875feea2017-06-11 16:07:51 +02001805 call g:Xsetlist([{'filename': 'foo', 'lnum': 42}])
Bram Moolenaar537ef082016-07-09 17:56:19 +02001806 Xopen
Bram Moolenaardcb17002016-07-07 18:58:59 +02001807 let wid = win_getid()
1808 call assert_equal(1, line('.'))
1809 wincmd w
Bram Moolenaar875feea2017-06-11 16:07:51 +02001810 call g:Xsetlist([{'filename': 'var', 'lnum': 24}], 'a')
Bram Moolenaar537ef082016-07-09 17:56:19 +02001811 Xbottom
Bram Moolenaardcb17002016-07-07 18:58:59 +02001812 call win_gotoid(wid)
1813 call assert_equal(2, line('.'))
Bram Moolenaar537ef082016-07-09 17:56:19 +02001814 Xclose
Bram Moolenaardcb17002016-07-07 18:58:59 +02001815endfunc
Bram Moolenaar537ef082016-07-09 17:56:19 +02001816
1817" Tests for the :cbottom and :lbottom commands
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001818func Test_cbottom()
Bram Moolenaar537ef082016-07-09 17:56:19 +02001819 call XbottomTests('c')
1820 call XbottomTests('l')
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001821endfunc
Bram Moolenaarf6acffb2016-07-16 16:54:24 +02001822
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001823func HistoryTest(cchar)
Bram Moolenaarf6acffb2016-07-16 16:54:24 +02001824 call s:setup_commands(a:cchar)
1825
Bram Moolenaarf6acffb2016-07-16 16:54:24 +02001826 " clear all lists after the first one, then replace the first one.
1827 call g:Xsetlist([])
Bram Moolenaarb6fa30c2017-03-29 14:19:25 +02001828 call assert_fails('Xolder 99', 'E380:')
Bram Moolenaarf6acffb2016-07-16 16:54:24 +02001829 let entry = {'filename': 'foo', 'lnum': 42}
1830 call g:Xsetlist([entry], 'r')
1831 call g:Xsetlist([entry, entry])
1832 call g:Xsetlist([entry, entry, entry])
1833 let res = split(execute(a:cchar . 'hist'), "\n")
1834 call assert_equal(3, len(res))
1835 let common = 'errors :set' . (a:cchar == 'c' ? 'qf' : 'loc') . 'list()'
1836 call assert_equal(' error list 1 of 3; 1 ' . common, res[0])
1837 call assert_equal(' error list 2 of 3; 2 ' . common, res[1])
1838 call assert_equal('> error list 3 of 3; 3 ' . common, res[2])
Bram Moolenaarb4d5fba2017-09-11 19:31:28 +02001839
Bram Moolenaar8ffc7c82019-05-05 21:00:26 +02001840 " Test for changing the quickfix lists
1841 call assert_equal(3, g:Xgetlist({'nr' : 0}).nr)
1842 exe '1' . a:cchar . 'hist'
1843 call assert_equal(1, g:Xgetlist({'nr' : 0}).nr)
1844 exe '3' . a:cchar . 'hist'
1845 call assert_equal(3, g:Xgetlist({'nr' : 0}).nr)
1846 call assert_fails('-2' . a:cchar . 'hist', 'E16:')
1847 call assert_fails('4' . a:cchar . 'hist', 'E16:')
1848
Bram Moolenaarb4d5fba2017-09-11 19:31:28 +02001849 call g:Xsetlist([], 'f')
1850 let l = split(execute(a:cchar . 'hist'), "\n")
1851 call assert_equal('No entries', l[0])
Bram Moolenaar8ffc7c82019-05-05 21:00:26 +02001852 if a:cchar == 'c'
1853 call assert_fails('4chist', 'E16:')
1854 else
1855 call assert_fails('4lhist', 'E776:')
1856 endif
Bram Moolenaar5b69c222019-01-11 14:50:06 +01001857
1858 " An empty list should still show the stack history
1859 call g:Xsetlist([])
1860 let res = split(execute(a:cchar . 'hist'), "\n")
1861 call assert_equal('> error list 1 of 1; 0 ' . common, res[0])
1862
1863 call g:Xsetlist([], 'f')
Bram Moolenaarf6acffb2016-07-16 16:54:24 +02001864endfunc
1865
1866func Test_history()
1867 call HistoryTest('c')
1868 call HistoryTest('l')
1869endfunc
Bram Moolenaar015102e2016-07-16 18:24:56 +02001870
1871func Test_duplicate_buf()
1872 " make sure we can get the highest buffer number
1873 edit DoesNotExist
1874 edit DoesNotExist2
1875 let last_buffer = bufnr("$")
1876
1877 " make sure only one buffer is created
1878 call writefile(['this one', 'that one'], 'Xgrepthis')
1879 vimgrep one Xgrepthis
1880 vimgrep one Xgrepthis
1881 call assert_equal(last_buffer + 1, bufnr("$"))
1882
1883 call delete('Xgrepthis')
1884endfunc
Bram Moolenaard823fa92016-08-12 16:29:27 +02001885
1886" Quickfix/Location list set/get properties tests
Bram Moolenaar2b946c92016-11-12 18:14:44 +01001887func Xproperty_tests(cchar)
Bram Moolenaard823fa92016-08-12 16:29:27 +02001888 call s:setup_commands(a:cchar)
1889
1890 " Error cases
1891 call assert_fails('call g:Xgetlist(99)', 'E715:')
1892 call assert_fails('call g:Xsetlist(99)', 'E714:')
1893 call assert_fails('call g:Xsetlist([], "a", [])', 'E715:')
1894
1895 " Set and get the title
Bram Moolenaarb6fa30c2017-03-29 14:19:25 +02001896 call g:Xsetlist([])
Bram Moolenaard823fa92016-08-12 16:29:27 +02001897 Xopen
1898 wincmd p
1899 call g:Xsetlist([{'filename':'foo', 'lnum':27}])
Bram Moolenaar86f100dc2017-06-28 21:26:27 +02001900 let s = g:Xsetlist([], 'a', {'title' : 'Sample'})
1901 call assert_equal(0, s)
Bram Moolenaard823fa92016-08-12 16:29:27 +02001902 let d = g:Xgetlist({"title":1})
1903 call assert_equal('Sample', d.title)
Bram Moolenaara2aa8a22018-04-24 13:55:00 +02001904 " Try setting title to a non-string value
1905 call assert_equal(-1, g:Xsetlist([], 'a', {'title' : ['Test']}))
1906 call assert_equal('Sample', g:Xgetlist({"title":1}).title)
Bram Moolenaard823fa92016-08-12 16:29:27 +02001907
1908 Xopen
1909 call assert_equal('Sample', w:quickfix_title)
1910 Xclose
1911
Bram Moolenaar2b529bb2016-08-27 13:35:35 +02001912 " Tests for action argument
1913 silent! Xolder 999
1914 let qfnr = g:Xgetlist({'all':1}).nr
1915 call g:Xsetlist([], 'r', {'title' : 'N1'})
1916 call assert_equal('N1', g:Xgetlist({'all':1}).title)
1917 call g:Xsetlist([], ' ', {'title' : 'N2'})
1918 call assert_equal(qfnr + 1, g:Xgetlist({'all':1}).nr)
Bram Moolenaar890680c2016-09-27 21:28:56 +02001919
1920 let res = g:Xgetlist({'nr': 0})
1921 call assert_equal(qfnr + 1, res.nr)
1922 call assert_equal(['nr'], keys(res))
1923
Bram Moolenaar2b529bb2016-08-27 13:35:35 +02001924 call g:Xsetlist([], ' ', {'title' : 'N3'})
1925 call assert_equal('N2', g:Xgetlist({'nr':2, 'title':1}).title)
1926
Bram Moolenaaree85df32017-03-19 14:19:50 +01001927 " Changing the title of an earlier quickfix list
Bram Moolenaar55b69262017-08-13 13:42:01 +02001928 call g:Xsetlist([], 'r', {'title' : 'NewTitle', 'nr' : 2})
Bram Moolenaaree85df32017-03-19 14:19:50 +01001929 call assert_equal('NewTitle', g:Xgetlist({'nr':2, 'title':1}).title)
1930
1931 " Changing the title of an invalid quickfix list
1932 call assert_equal(-1, g:Xsetlist([], ' ',
1933 \ {'title' : 'SomeTitle', 'nr' : 99}))
1934 call assert_equal(-1, g:Xsetlist([], ' ',
1935 \ {'title' : 'SomeTitle', 'nr' : 'abc'}))
1936
1937 if a:cchar == 'c'
1938 copen
1939 call assert_equal({'winid':win_getid()}, getqflist({'winid':1}))
1940 cclose
1941 endif
1942
Bram Moolenaard823fa92016-08-12 16:29:27 +02001943 " Invalid arguments
1944 call assert_fails('call g:Xgetlist([])', 'E715')
1945 call assert_fails('call g:Xsetlist([], "a", [])', 'E715')
1946 let s = g:Xsetlist([], 'a', {'abc':1})
1947 call assert_equal(-1, s)
1948
1949 call assert_equal({}, g:Xgetlist({'abc':1}))
Bram Moolenaara6d48492017-12-12 22:45:31 +01001950 call assert_equal('', g:Xgetlist({'nr':99, 'title':1}).title)
1951 call assert_equal('', g:Xgetlist({'nr':[], 'title':1}).title)
Bram Moolenaard823fa92016-08-12 16:29:27 +02001952
1953 if a:cchar == 'l'
Bram Moolenaar890680c2016-09-27 21:28:56 +02001954 call assert_equal({}, getloclist(99, {'title': 1}))
Bram Moolenaard823fa92016-08-12 16:29:27 +02001955 endif
Bram Moolenaar8f77c5a2017-04-30 14:21:00 +02001956
1957 " Context related tests
Bram Moolenaar86f100dc2017-06-28 21:26:27 +02001958 let s = g:Xsetlist([], 'a', {'context':[1,2,3]})
1959 call assert_equal(0, s)
Bram Moolenaar8f77c5a2017-04-30 14:21:00 +02001960 call test_garbagecollect_now()
1961 let d = g:Xgetlist({'context':1})
1962 call assert_equal([1,2,3], d.context)
1963 call g:Xsetlist([], 'a', {'context':{'color':'green'}})
1964 let d = g:Xgetlist({'context':1})
1965 call assert_equal({'color':'green'}, d.context)
1966 call g:Xsetlist([], 'a', {'context':"Context info"})
1967 let d = g:Xgetlist({'context':1})
1968 call assert_equal("Context info", d.context)
1969 call g:Xsetlist([], 'a', {'context':246})
1970 let d = g:Xgetlist({'context':1})
1971 call assert_equal(246, d.context)
1972 if a:cchar == 'l'
1973 " Test for copying context across two different location lists
1974 new | only
1975 let w1_id = win_getid()
1976 let l = [1]
1977 call setloclist(0, [], 'a', {'context':l})
1978 new
1979 let w2_id = win_getid()
1980 call add(l, 2)
1981 call assert_equal([1, 2], getloclist(w1_id, {'context':1}).context)
1982 call assert_equal([1, 2], getloclist(w2_id, {'context':1}).context)
1983 unlet! l
1984 call assert_equal([1, 2], getloclist(w2_id, {'context':1}).context)
1985 only
1986 call setloclist(0, [], 'f')
Bram Moolenaara6d48492017-12-12 22:45:31 +01001987 call assert_equal('', getloclist(0, {'context':1}).context)
Bram Moolenaar8f77c5a2017-04-30 14:21:00 +02001988 endif
Bram Moolenaar6e62da32017-05-28 08:16:25 +02001989
1990 " Test for changing the context of previous quickfix lists
1991 call g:Xsetlist([], 'f')
1992 Xexpr "One"
1993 Xexpr "Two"
1994 Xexpr "Three"
Bram Moolenaar55b69262017-08-13 13:42:01 +02001995 call g:Xsetlist([], 'r', {'context' : [1], 'nr' : 1})
1996 call g:Xsetlist([], 'a', {'context' : [2], 'nr' : 2})
Bram Moolenaar6e62da32017-05-28 08:16:25 +02001997 " Also, check for setting the context using quickfix list number zero.
Bram Moolenaar55b69262017-08-13 13:42:01 +02001998 call g:Xsetlist([], 'r', {'context' : [3], 'nr' : 0})
Bram Moolenaar6e62da32017-05-28 08:16:25 +02001999 call test_garbagecollect_now()
2000 let l = g:Xgetlist({'nr' : 1, 'context' : 1})
2001 call assert_equal([1], l.context)
2002 let l = g:Xgetlist({'nr' : 2, 'context' : 1})
2003 call assert_equal([2], l.context)
2004 let l = g:Xgetlist({'nr' : 3, 'context' : 1})
2005 call assert_equal([3], l.context)
2006
2007 " Test for changing the context through reference and for garbage
2008 " collection of quickfix context
2009 let l = ["red"]
2010 call g:Xsetlist([], ' ', {'context' : l})
2011 call add(l, "blue")
2012 let x = g:Xgetlist({'context' : 1})
2013 call add(x.context, "green")
2014 call assert_equal(["red", "blue", "green"], l)
2015 call assert_equal(["red", "blue", "green"], x.context)
2016 unlet l
2017 call test_garbagecollect_now()
2018 let m = g:Xgetlist({'context' : 1})
2019 call assert_equal(["red", "blue", "green"], m.context)
Bram Moolenaar6a8958d2017-06-22 21:33:20 +02002020
2021 " Test for setting/getting items
2022 Xexpr ""
2023 let qfprev = g:Xgetlist({'nr':0})
Bram Moolenaar86f100dc2017-06-28 21:26:27 +02002024 let s = g:Xsetlist([], ' ', {'title':'Green',
Bram Moolenaar6a8958d2017-06-22 21:33:20 +02002025 \ 'items' : [{'filename':'F1', 'lnum':10}]})
Bram Moolenaar86f100dc2017-06-28 21:26:27 +02002026 call assert_equal(0, s)
Bram Moolenaar6a8958d2017-06-22 21:33:20 +02002027 let qfcur = g:Xgetlist({'nr':0})
2028 call assert_true(qfcur.nr == qfprev.nr + 1)
2029 let l = g:Xgetlist({'items':1})
2030 call assert_equal('F1', bufname(l.items[0].bufnr))
2031 call assert_equal(10, l.items[0].lnum)
2032 call g:Xsetlist([], 'a', {'items' : [{'filename':'F2', 'lnum':20},
2033 \ {'filename':'F2', 'lnum':30}]})
2034 let l = g:Xgetlist({'items':1})
2035 call assert_equal('F2', bufname(l.items[2].bufnr))
2036 call assert_equal(30, l.items[2].lnum)
2037 call g:Xsetlist([], 'r', {'items' : [{'filename':'F3', 'lnum':40}]})
2038 let l = g:Xgetlist({'items':1})
2039 call assert_equal('F3', bufname(l.items[0].bufnr))
2040 call assert_equal(40, l.items[0].lnum)
2041 call g:Xsetlist([], 'r', {'items' : []})
2042 let l = g:Xgetlist({'items':1})
2043 call assert_equal(0, len(l.items))
2044
Bram Moolenaarb4d5fba2017-09-11 19:31:28 +02002045 call g:Xsetlist([], 'r', {'title' : 'TestTitle'})
2046 call g:Xsetlist([], 'r', {'items' : [{'filename' : 'F1', 'lnum' : 10, 'text' : 'L10'}]})
2047 call g:Xsetlist([], 'r', {'items' : [{'filename' : 'F1', 'lnum' : 10, 'text' : 'L10'}]})
2048 call assert_equal('TestTitle', g:Xgetlist({'title' : 1}).title)
2049
Bram Moolenaarc9cc9c72018-09-02 15:18:42 +02002050 " Test for getting id of window associated with a location list window
2051 if a:cchar == 'l'
2052 only
2053 call assert_equal(0, g:Xgetlist({'all' : 1}).filewinid)
2054 let wid = win_getid()
2055 Xopen
2056 call assert_equal(wid, g:Xgetlist({'filewinid' : 1}).filewinid)
2057 wincmd w
2058 call assert_equal(0, g:Xgetlist({'filewinid' : 1}).filewinid)
2059 only
2060 endif
2061
Bram Moolenaarae338332017-08-11 20:25:26 +02002062 " The following used to crash Vim with address sanitizer
2063 call g:Xsetlist([], 'f')
2064 call g:Xsetlist([], 'a', {'items' : [{'filename':'F1', 'lnum':10}]})
2065 call assert_equal(10, g:Xgetlist({'items':1}).items[0].lnum)
2066
Bram Moolenaara2aa8a22018-04-24 13:55:00 +02002067 " Try setting the items using a string
2068 call assert_equal(-1, g:Xsetlist([], ' ', {'items' : 'Test'}))
2069
Bram Moolenaar6a8958d2017-06-22 21:33:20 +02002070 " Save and restore the quickfix stack
2071 call g:Xsetlist([], 'f')
2072 call assert_equal(0, g:Xgetlist({'nr':'$'}).nr)
2073 Xexpr "File1:10:Line1"
2074 Xexpr "File2:20:Line2"
2075 Xexpr "File3:30:Line3"
2076 let last_qf = g:Xgetlist({'nr':'$'}).nr
2077 call assert_equal(3, last_qf)
2078 let qstack = []
2079 for i in range(1, last_qf)
2080 let qstack = add(qstack, g:Xgetlist({'nr':i, 'all':1}))
2081 endfor
2082 call g:Xsetlist([], 'f')
2083 for i in range(len(qstack))
2084 call g:Xsetlist([], ' ', qstack[i])
2085 endfor
2086 call assert_equal(3, g:Xgetlist({'nr':'$'}).nr)
2087 call assert_equal(10, g:Xgetlist({'nr':1, 'items':1}).items[0].lnum)
2088 call assert_equal(20, g:Xgetlist({'nr':2, 'items':1}).items[0].lnum)
2089 call assert_equal(30, g:Xgetlist({'nr':3, 'items':1}).items[0].lnum)
2090 call g:Xsetlist([], 'f')
2091
2092 " Swap two quickfix lists
2093 Xexpr "File1:10:Line10"
2094 Xexpr "File2:20:Line20"
2095 Xexpr "File3:30:Line30"
2096 call g:Xsetlist([], 'r', {'nr':1,'title':'Colors','context':['Colors']})
2097 call g:Xsetlist([], 'r', {'nr':2,'title':'Fruits','context':['Fruits']})
2098 let l1=g:Xgetlist({'nr':1,'all':1})
2099 let l2=g:Xgetlist({'nr':2,'all':1})
Bram Moolenaara539f4f2017-08-30 20:33:55 +02002100 let save_id = l1.id
2101 let l1.id=l2.id
2102 let l2.id=save_id
Bram Moolenaar6a8958d2017-06-22 21:33:20 +02002103 call g:Xsetlist([], 'r', l1)
2104 call g:Xsetlist([], 'r', l2)
2105 let newl1=g:Xgetlist({'nr':1,'all':1})
2106 let newl2=g:Xgetlist({'nr':2,'all':1})
Bram Moolenaarb4d5fba2017-09-11 19:31:28 +02002107 call assert_equal('Fruits', newl1.title)
Bram Moolenaar6a8958d2017-06-22 21:33:20 +02002108 call assert_equal(['Fruits'], newl1.context)
2109 call assert_equal('Line20', newl1.items[0].text)
Bram Moolenaarb4d5fba2017-09-11 19:31:28 +02002110 call assert_equal('Colors', newl2.title)
Bram Moolenaar6a8958d2017-06-22 21:33:20 +02002111 call assert_equal(['Colors'], newl2.context)
2112 call assert_equal('Line10', newl2.items[0].text)
2113 call g:Xsetlist([], 'f')
Bram Moolenaaree85df32017-03-19 14:19:50 +01002114endfunc
Bram Moolenaard823fa92016-08-12 16:29:27 +02002115
Bram Moolenaar2b946c92016-11-12 18:14:44 +01002116func Test_qf_property()
Bram Moolenaard823fa92016-08-12 16:29:27 +02002117 call Xproperty_tests('c')
2118 call Xproperty_tests('l')
Bram Moolenaaree85df32017-03-19 14:19:50 +01002119endfunc
Bram Moolenaar04c4ce62016-09-01 15:45:58 +02002120
Bram Moolenaar5b69c222019-01-11 14:50:06 +01002121" Test for setting the current index in the location/quickfix list
2122func Xtest_setqfidx(cchar)
2123 call s:setup_commands(a:cchar)
2124
2125 Xgetexpr "F1:10:1:Line1\nF2:20:2:Line2\nF3:30:3:Line3"
2126 Xgetexpr "F4:10:1:Line1\nF5:20:2:Line2\nF6:30:3:Line3"
2127 Xgetexpr "F7:10:1:Line1\nF8:20:2:Line2\nF9:30:3:Line3"
2128
2129 call g:Xsetlist([], 'a', {'nr' : 3, 'idx' : 2})
2130 call g:Xsetlist([], 'a', {'nr' : 2, 'idx' : 2})
2131 call g:Xsetlist([], 'a', {'nr' : 1, 'idx' : 3})
2132 Xolder 2
2133 Xopen
2134 call assert_equal(3, line('.'))
2135 Xnewer
2136 call assert_equal(2, line('.'))
2137 Xnewer
2138 call assert_equal(2, line('.'))
2139 " Update the current index with the quickfix window open
2140 wincmd w
2141 call g:Xsetlist([], 'a', {'nr' : 3, 'idx' : 3})
2142 Xopen
2143 call assert_equal(3, line('.'))
2144 Xclose
2145
2146 " Set the current index to the last entry
2147 call g:Xsetlist([], 'a', {'nr' : 1, 'idx' : '$'})
2148 call assert_equal(3, g:Xgetlist({'nr' : 1, 'idx' : 0}).idx)
2149 " A large value should set the index to the last index
2150 call g:Xsetlist([], 'a', {'nr' : 1, 'idx' : 1})
2151 call g:Xsetlist([], 'a', {'nr' : 1, 'idx' : 999})
2152 call assert_equal(3, g:Xgetlist({'nr' : 1, 'idx' : 0}).idx)
2153 " Invalid index values
2154 call g:Xsetlist([], 'a', {'nr' : 1, 'idx' : -1})
2155 call assert_equal(3, g:Xgetlist({'nr' : 1, 'idx' : 0}).idx)
2156 call g:Xsetlist([], 'a', {'nr' : 1, 'idx' : 0})
2157 call assert_equal(3, g:Xgetlist({'nr' : 1, 'idx' : 0}).idx)
2158 call g:Xsetlist([], 'a', {'nr' : 1, 'idx' : 'xx'})
2159 call assert_equal(3, g:Xgetlist({'nr' : 1, 'idx' : 0}).idx)
2160 call assert_fails("call g:Xsetlist([], 'a', {'nr':1, 'idx':[]})", 'E745:')
2161
2162 call g:Xsetlist([], 'f')
2163 new | only
2164endfunc
2165
2166func Test_setqfidx()
2167 call Xtest_setqfidx('c')
2168 call Xtest_setqfidx('l')
2169endfunc
2170
Bram Moolenaar04c4ce62016-09-01 15:45:58 +02002171" Tests for the QuickFixCmdPre/QuickFixCmdPost autocommands
Bram Moolenaar2b946c92016-11-12 18:14:44 +01002172func QfAutoCmdHandler(loc, cmd)
Bram Moolenaar04c4ce62016-09-01 15:45:58 +02002173 call add(g:acmds, a:loc . a:cmd)
Bram Moolenaar2b946c92016-11-12 18:14:44 +01002174endfunc
Bram Moolenaar04c4ce62016-09-01 15:45:58 +02002175
Bram Moolenaar2b946c92016-11-12 18:14:44 +01002176func Test_Autocmd()
Bram Moolenaar04c4ce62016-09-01 15:45:58 +02002177 autocmd QuickFixCmdPre * call QfAutoCmdHandler('pre', expand('<amatch>'))
2178 autocmd QuickFixCmdPost * call QfAutoCmdHandler('post', expand('<amatch>'))
2179
2180 let g:acmds = []
2181 cexpr "F1:10:Line 10"
2182 caddexpr "F1:20:Line 20"
2183 cgetexpr "F1:30:Line 30"
Bram Moolenaar1ed22762017-11-28 18:03:44 +01002184 cexpr ""
2185 caddexpr ""
2186 cgetexpr ""
2187 silent! cexpr non_existing_func()
2188 silent! caddexpr non_existing_func()
2189 silent! cgetexpr non_existing_func()
Bram Moolenaar04c4ce62016-09-01 15:45:58 +02002190 let l = ['precexpr',
2191 \ 'postcexpr',
2192 \ 'precaddexpr',
2193 \ 'postcaddexpr',
2194 \ 'precgetexpr',
2195 \ 'postcgetexpr',
Bram Moolenaar1ed22762017-11-28 18:03:44 +01002196 \ 'precexpr',
2197 \ 'postcexpr',
2198 \ 'precaddexpr',
2199 \ 'postcaddexpr',
2200 \ 'precgetexpr',
2201 \ 'postcgetexpr',
2202 \ 'precexpr',
2203 \ 'precaddexpr',
2204 \ 'precgetexpr']
2205 call assert_equal(l, g:acmds)
2206
2207 let g:acmds = []
2208 enew! | call append(0, "F2:10:Line 10")
2209 cbuffer!
2210 enew! | call append(0, "F2:20:Line 20")
2211 cgetbuffer
2212 enew! | call append(0, "F2:30:Line 30")
2213 caddbuffer
2214 new
2215 let bnum = bufnr('%')
2216 bunload
2217 exe 'silent! cbuffer! ' . bnum
2218 exe 'silent! cgetbuffer ' . bnum
2219 exe 'silent! caddbuffer ' . bnum
2220 enew!
2221 let l = ['precbuffer',
Bram Moolenaar04c4ce62016-09-01 15:45:58 +02002222 \ 'postcbuffer',
2223 \ 'precgetbuffer',
2224 \ 'postcgetbuffer',
2225 \ 'precaddbuffer',
Bram Moolenaar1ed22762017-11-28 18:03:44 +01002226 \ 'postcaddbuffer',
2227 \ 'precbuffer',
2228 \ 'precgetbuffer',
2229 \ 'precaddbuffer']
Bram Moolenaar04c4ce62016-09-01 15:45:58 +02002230 call assert_equal(l, g:acmds)
Bram Moolenaar1ed22762017-11-28 18:03:44 +01002231
2232 call writefile(['Xtest:1:Line1'], 'Xtest')
2233 call writefile([], 'Xempty')
2234 let g:acmds = []
2235 cfile Xtest
2236 caddfile Xtest
2237 cgetfile Xtest
2238 cfile Xempty
2239 caddfile Xempty
2240 cgetfile Xempty
2241 silent! cfile do_not_exist
2242 silent! caddfile do_not_exist
2243 silent! cgetfile do_not_exist
2244 let l = ['precfile',
2245 \ 'postcfile',
2246 \ 'precaddfile',
2247 \ 'postcaddfile',
2248 \ 'precgetfile',
2249 \ 'postcgetfile',
2250 \ 'precfile',
2251 \ 'postcfile',
2252 \ 'precaddfile',
2253 \ 'postcaddfile',
2254 \ 'precgetfile',
2255 \ 'postcgetfile',
2256 \ 'precfile',
2257 \ 'postcfile',
2258 \ 'precaddfile',
2259 \ 'postcaddfile',
2260 \ 'precgetfile',
2261 \ 'postcgetfile']
2262 call assert_equal(l, g:acmds)
2263
2264 let g:acmds = []
2265 helpgrep quickfix
2266 silent! helpgrep non_existing_help_topic
2267 vimgrep test Xtest
2268 vimgrepadd test Xtest
2269 silent! vimgrep non_existing_test Xtest
2270 silent! vimgrepadd non_existing_test Xtest
2271 set makeprg=
2272 silent! make
2273 set makeprg&
2274 let l = ['prehelpgrep',
2275 \ 'posthelpgrep',
2276 \ 'prehelpgrep',
2277 \ 'posthelpgrep',
2278 \ 'previmgrep',
2279 \ 'postvimgrep',
2280 \ 'previmgrepadd',
2281 \ 'postvimgrepadd',
2282 \ 'previmgrep',
2283 \ 'postvimgrep',
2284 \ 'previmgrepadd',
2285 \ 'postvimgrepadd',
2286 \ 'premake',
2287 \ 'postmake']
2288 call assert_equal(l, g:acmds)
2289
2290 if has('unix')
2291 " Run this test only on Unix-like systems. The grepprg may not be set on
2292 " non-Unix systems.
2293 " The following lines are used for the grep test. Don't remove.
2294 " Grep_Autocmd_Text: Match 1
2295 " GrepAdd_Autocmd_Text: Match 2
2296 let g:acmds = []
2297 silent grep Grep_Autocmd_Text test_quickfix.vim
2298 silent grepadd GrepAdd_Autocmd_Text test_quickfix.vim
2299 silent grep abc123def Xtest
2300 silent grepadd abc123def Xtest
2301 let l = ['pregrep',
2302 \ 'postgrep',
2303 \ 'pregrepadd',
2304 \ 'postgrepadd',
2305 \ 'pregrep',
2306 \ 'postgrep',
2307 \ 'pregrepadd',
2308 \ 'postgrepadd']
2309 call assert_equal(l, g:acmds)
2310 endif
2311
2312 call delete('Xtest')
2313 call delete('Xempty')
Bram Moolenaarb254af32017-12-18 19:48:58 +01002314 au! QuickFixCmdPre
2315 au! QuickFixCmdPost
Bram Moolenaar2b946c92016-11-12 18:14:44 +01002316endfunc
Bram Moolenaar21662be2016-11-06 14:46:44 +01002317
Bram Moolenaar2b946c92016-11-12 18:14:44 +01002318func Test_Autocmd_Exception()
Bram Moolenaar21662be2016-11-06 14:46:44 +01002319 set efm=%m
2320 lgetexpr '?'
2321
2322 try
2323 call DoesNotExit()
2324 catch
2325 lgetexpr '1'
2326 finally
2327 lgetexpr '1'
2328 endtry
2329
2330 call assert_equal('1', getloclist(0)[0].text)
2331
2332 set efm&vim
Bram Moolenaar2b946c92016-11-12 18:14:44 +01002333endfunc
Bram Moolenaar63bed3d2016-11-12 15:36:54 +01002334
Bram Moolenaar2b946c92016-11-12 18:14:44 +01002335func Test_caddbuffer_wrong()
2336 " This used to cause a memory access in freed memory.
Bram Moolenaar63bed3d2016-11-12 15:36:54 +01002337 let save_efm = &efm
2338 set efm=%EEEE%m,%WWWW,%+CCCC%>%#,%GGGG%.#
2339 cgetexpr ['WWWW', 'EEEE', 'CCCC']
2340 let &efm = save_efm
Bram Moolenaar2b946c92016-11-12 18:14:44 +01002341 caddbuffer
Bram Moolenaar63bed3d2016-11-12 15:36:54 +01002342 bwipe!
2343endfunc
Bram Moolenaar2b946c92016-11-12 18:14:44 +01002344
2345func Test_caddexpr_wrong()
2346 " This used to cause a memory access in freed memory.
2347 cbuffer
2348 cbuffer
2349 copen
2350 let save_efm = &efm
2351 set efm=%
2352 call assert_fails('caddexpr ""', 'E376:')
2353 let &efm = save_efm
2354endfunc
Bram Moolenaar7618e002016-11-13 15:09:26 +01002355
2356func Test_dirstack_cleanup()
2357 " This used to cause a memory access in freed memory.
2358 let save_efm = &efm
2359 lexpr '0'
2360 lopen
2361 fun X(c)
2362 let save_efm=&efm
2363 set efm=%D%f
2364 if a:c == 'c'
2365 caddexpr '::'
2366 else
2367 laddexpr ':0:0'
2368 endif
2369 let &efm=save_efm
2370 endfun
2371 call X('c')
2372 call X('l')
2373 call setqflist([], 'r')
2374 caddbuffer
2375 let &efm = save_efm
2376endfunc
Bram Moolenaar391b1dd2017-03-04 13:47:11 +01002377
2378" Tests for jumping to entries from the location list window and quickfix
2379" window
2380func Test_cwindow_jump()
2381 set efm=%f%%%l%%%m
2382 lgetexpr ["F1%10%Line 10", "F2%20%Line 20", "F3%30%Line 30"]
2383 lopen | only
2384 lfirst
2385 call assert_true(winnr('$') == 2)
2386 call assert_true(winnr() == 1)
2387 " Location list for the new window should be set
2388 call assert_true(getloclist(0)[2].text == 'Line 30')
2389
2390 " Open a scratch buffer
2391 " Open a new window and create a location list
2392 " Open the location list window and close the other window
2393 " Jump to an entry.
Bram Moolenaareeb1b9c2019-02-10 22:59:04 +01002394 " Should create a new window and jump to the entry. The scratch buffer
Bram Moolenaar391b1dd2017-03-04 13:47:11 +01002395 " should not be used.
2396 enew | only
2397 set buftype=nofile
2398 below new
2399 lgetexpr ["F1%10%Line 10", "F2%20%Line 20", "F3%30%Line 30"]
2400 lopen
2401 2wincmd c
2402 lnext
2403 call assert_true(winnr('$') == 3)
2404 call assert_true(winnr() == 2)
2405
2406 " Open two windows with two different location lists
2407 " Open the location list window and close the previous window
2408 " Jump to an entry in the location list window
2409 " Should open the file in the first window and not set the location list.
2410 enew | only
2411 lgetexpr ["F1%5%Line 5"]
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() == 1)
2418 call assert_true(getloclist(0)[0].text == 'Line 5')
2419
2420 enew | only
2421 cgetexpr ["F1%10%Line 10", "F2%20%Line 20", "F3%30%Line 30"]
2422 copen
2423 cnext
2424 call assert_true(winnr('$') == 2)
2425 call assert_true(winnr() == 1)
2426
2427 enew | only
2428 set efm&vim
2429endfunc
Bram Moolenaaree85df32017-03-19 14:19:50 +01002430
2431func XvimgrepTests(cchar)
2432 call s:setup_commands(a:cchar)
2433
2434 call writefile(['Editor:VIM vim',
2435 \ 'Editor:Emacs EmAcS',
2436 \ 'Editor:Notepad NOTEPAD'], 'Xtestfile1')
2437 call writefile(['Linux', 'MacOS', 'MS-Windows'], 'Xtestfile2')
2438
2439 " Error cases
2440 call assert_fails('Xvimgrep /abc *', 'E682:')
2441
2442 let @/=''
2443 call assert_fails('Xvimgrep // *', 'E35:')
2444
2445 call assert_fails('Xvimgrep abc', 'E683:')
2446 call assert_fails('Xvimgrep a1b2c3 Xtestfile1', 'E480:')
2447 call assert_fails('Xvimgrep pat Xa1b2c3', 'E480:')
2448
2449 Xexpr ""
2450 Xvimgrepadd Notepad Xtestfile1
2451 Xvimgrepadd MacOS Xtestfile2
2452 let l = g:Xgetlist()
2453 call assert_equal(2, len(l))
2454 call assert_equal('Editor:Notepad NOTEPAD', l[0].text)
2455
2456 Xvimgrep #\cvim#g Xtestfile?
2457 let l = g:Xgetlist()
2458 call assert_equal(2, len(l))
2459 call assert_equal(8, l[0].col)
2460 call assert_equal(12, l[1].col)
2461
2462 1Xvimgrep ?Editor? Xtestfile*
2463 let l = g:Xgetlist()
2464 call assert_equal(1, len(l))
2465 call assert_equal('Editor:VIM vim', l[0].text)
2466
2467 edit +3 Xtestfile2
2468 Xvimgrep +\cemacs+j Xtestfile1
2469 let l = g:Xgetlist()
2470 call assert_equal('Xtestfile2', bufname(''))
2471 call assert_equal('Editor:Emacs EmAcS', l[0].text)
2472
Bram Moolenaar2225ebb2018-04-24 15:48:11 +02002473 " Test for unloading a buffer after vimgrep searched the buffer
2474 %bwipe
2475 Xvimgrep /Editor/j Xtestfile*
2476 call assert_equal(0, getbufinfo('Xtestfile1')[0].loaded)
2477 call assert_equal([], getbufinfo('Xtestfile2'))
2478
Bram Moolenaaree85df32017-03-19 14:19:50 +01002479 call delete('Xtestfile1')
2480 call delete('Xtestfile2')
2481endfunc
2482
2483" Tests for the :vimgrep command
2484func Test_vimgrep()
2485 call XvimgrepTests('c')
2486 call XvimgrepTests('l')
2487endfunc
Bram Moolenaar69f40be2017-04-02 15:15:49 +02002488
Bram Moolenaar1c299432018-10-28 14:36:09 +01002489" Test for incsearch highlighting of the :vimgrep pattern
2490" This test used to cause "E315: ml_get: invalid lnum" errors.
2491func Test_vimgrep_incsearch()
2492 enew
2493 set incsearch
2494 call test_override("char_avail", 1)
2495
2496 call feedkeys(":2vimgrep assert test_quickfix.vim test_cdo.vim\<CR>", "ntx")
2497 let l = getqflist()
2498 call assert_equal(2, len(l))
2499
2500 call test_override("ALL", 0)
2501 set noincsearch
2502endfunc
2503
Bram Moolenaar69f40be2017-04-02 15:15:49 +02002504func XfreeTests(cchar)
2505 call s:setup_commands(a:cchar)
2506
2507 enew | only
2508
2509 " Deleting the quickfix stack should work even When the current list is
2510 " somewhere in the middle of the stack
2511 Xexpr ['Xfile1:10:10:Line 10', 'Xfile1:15:15:Line 15']
2512 Xexpr ['Xfile2:20:20:Line 20', 'Xfile2:25:25:Line 25']
2513 Xexpr ['Xfile3:30:30:Line 30', 'Xfile3:35:35:Line 35']
2514 Xolder
2515 call g:Xsetlist([], 'f')
2516 call assert_equal(0, len(g:Xgetlist()))
2517
2518 " After deleting the stack, adding a new list should create a stack with a
2519 " single list.
2520 Xexpr ['Xfile1:10:10:Line 10', 'Xfile1:15:15:Line 15']
2521 call assert_equal(1, g:Xgetlist({'all':1}).nr)
2522
2523 " Deleting the stack from a quickfix window should update/clear the
2524 " quickfix/location list window.
2525 Xexpr ['Xfile1:10:10:Line 10', 'Xfile1:15:15:Line 15']
2526 Xexpr ['Xfile2:20:20:Line 20', 'Xfile2:25:25:Line 25']
2527 Xexpr ['Xfile3:30:30:Line 30', 'Xfile3:35:35:Line 35']
2528 Xolder
2529 Xwindow
2530 call g:Xsetlist([], 'f')
2531 call assert_equal(2, winnr('$'))
2532 call assert_equal(1, line('$'))
2533 Xclose
2534
2535 " Deleting the stack from a non-quickfix window should update/clear the
2536 " quickfix/location list window.
2537 Xexpr ['Xfile1:10:10:Line 10', 'Xfile1:15:15:Line 15']
2538 Xexpr ['Xfile2:20:20:Line 20', 'Xfile2:25:25:Line 25']
2539 Xexpr ['Xfile3:30:30:Line 30', 'Xfile3:35:35:Line 35']
2540 Xolder
2541 Xwindow
2542 wincmd p
2543 call g:Xsetlist([], 'f')
2544 call assert_equal(0, len(g:Xgetlist()))
2545 wincmd p
2546 call assert_equal(2, winnr('$'))
2547 call assert_equal(1, line('$'))
2548
2549 " After deleting the location list stack, if the location list window is
2550 " opened, then a new location list should be created. So opening the
2551 " location list window again should not create a new window.
2552 if a:cchar == 'l'
2553 lexpr ['Xfile1:10:10:Line 10', 'Xfile1:15:15:Line 15']
2554 wincmd p
2555 lopen
2556 call assert_equal(2, winnr('$'))
2557 endif
2558 Xclose
2559endfunc
2560
Bram Moolenaar74240d32017-12-10 15:26:15 +01002561" Tests for the quickfix free functionality
Bram Moolenaar69f40be2017-04-02 15:15:49 +02002562func Test_qf_free()
2563 call XfreeTests('c')
2564 call XfreeTests('l')
2565endfunc
Bram Moolenaar6e62da32017-05-28 08:16:25 +02002566
2567" Test for buffer overflow when parsing lines and adding new entries to
2568" the quickfix list.
2569func Test_bufoverflow()
2570 set efm=%f:%l:%m
2571 cgetexpr ['File1:100:' . repeat('x', 1025)]
2572
2573 set efm=%+GCompiler:\ %.%#,%f:%l:%m
2574 cgetexpr ['Compiler: ' . repeat('a', 1015), 'File1:10:Hello World']
2575
2576 set efm=%DEntering\ directory\ %f,%f:%l:%m
2577 cgetexpr ['Entering directory ' . repeat('a', 1006),
2578 \ 'File1:10:Hello World']
2579 set efm&vim
2580endfunc
2581
Bram Moolenaar875feea2017-06-11 16:07:51 +02002582" Tests for getting the quickfix stack size
2583func XsizeTests(cchar)
2584 call s:setup_commands(a:cchar)
2585
2586 call g:Xsetlist([], 'f')
2587 call assert_equal(0, g:Xgetlist({'nr':'$'}).nr)
Bram Moolenaara6d48492017-12-12 22:45:31 +01002588 call assert_equal('', g:Xgetlist({'nr':'$', 'all':1}).title)
2589 call assert_equal(0, g:Xgetlist({'nr':0}).nr)
Bram Moolenaar875feea2017-06-11 16:07:51 +02002590
2591 Xexpr "File1:10:Line1"
2592 Xexpr "File2:20:Line2"
2593 Xexpr "File3:30:Line3"
2594 Xolder | Xolder
2595 call assert_equal(3, g:Xgetlist({'nr':'$'}).nr)
2596 call g:Xsetlist([], 'f')
2597
2598 Xexpr "File1:10:Line1"
2599 Xexpr "File2:20:Line2"
2600 Xexpr "File3:30:Line3"
2601 Xolder | Xolder
2602 call g:Xsetlist([], 'a', {'nr':'$', 'title':'Compiler'})
2603 call assert_equal('Compiler', g:Xgetlist({'nr':3, 'all':1}).title)
2604endfunc
2605
2606func Test_Qf_Size()
2607 call XsizeTests('c')
2608 call XsizeTests('l')
2609endfunc
Bram Moolenaar18141832017-06-25 21:17:25 +02002610
Bram Moolenaar9c4feff2017-06-28 22:26:54 +02002611func Test_cclose_from_copen()
2612 augroup QF_Test
2613 au!
2614 au FileType qf :call assert_fails(':cclose', 'E788')
2615 augroup END
2616 copen
2617 augroup QF_Test
2618 au!
2619 augroup END
2620 augroup! QF_Test
2621endfunc
2622
Bram Moolenaar18141832017-06-25 21:17:25 +02002623func Test_cclose_in_autocmd()
2624 " Problem is only triggered if "starting" is zero, so that the OptionsSet
2625 " event will be triggered.
2626 call test_override('starting', 1)
2627 augroup QF_Test
2628 au!
2629 au FileType qf :call assert_fails(':cclose', 'E788')
2630 augroup END
2631 copen
2632 augroup QF_Test
2633 au!
2634 augroup END
2635 augroup! QF_Test
2636 call test_override('starting', 0)
2637endfunc
Bram Moolenaar9c4feff2017-06-28 22:26:54 +02002638
Bram Moolenaar379fb762018-08-30 15:58:28 +02002639" Check that ":file" without an argument is possible even when "curbuf_lock"
2640" is set.
2641func Test_file_from_copen()
2642 " Works without argument.
2643 augroup QF_Test
2644 au!
2645 au FileType qf file
2646 augroup END
2647 copen
2648
2649 augroup QF_Test
2650 au!
2651 augroup END
2652 cclose
2653
2654 " Fails with argument.
2655 augroup QF_Test
2656 au!
2657 au FileType qf call assert_fails(':file foo', 'E788')
2658 augroup END
2659 copen
2660 augroup QF_Test
2661 au!
2662 augroup END
2663 cclose
2664
2665 augroup! QF_Test
2666endfunction
2667
Bram Moolenaar9c4feff2017-06-28 22:26:54 +02002668func Test_resize_from_copen()
2669 augroup QF_Test
2670 au!
2671 au FileType qf resize 5
2672 augroup END
2673 try
2674 " This should succeed without any exception. No other buffers are
2675 " involved in the autocmd.
2676 copen
2677 finally
2678 augroup QF_Test
2679 au!
2680 augroup END
2681 augroup! QF_Test
2682 endtry
2683endfunc
Bram Moolenaara8788f42017-07-19 17:06:20 +02002684
2685" Tests for the quickfix buffer b:changedtick variable
2686func Xchangedtick_tests(cchar)
2687 call s:setup_commands(a:cchar)
2688
2689 new | only
2690
2691 Xexpr "" | Xexpr "" | Xexpr ""
2692
2693 Xopen
2694 Xolder
2695 Xolder
2696 Xaddexpr "F1:10:Line10"
2697 Xaddexpr "F2:20:Line20"
2698 call g:Xsetlist([{"filename":"F3", "lnum":30, "text":"Line30"}], 'a')
2699 call g:Xsetlist([], 'f')
2700 call assert_equal(8, getbufvar('%', 'changedtick'))
2701 Xclose
2702endfunc
2703
2704func Test_changedtick()
Bram Moolenaarae338332017-08-11 20:25:26 +02002705 call Xchangedtick_tests('c')
2706 call Xchangedtick_tests('l')
2707endfunc
2708
2709" Tests for parsing an expression using setqflist()
2710func Xsetexpr_tests(cchar)
2711 call s:setup_commands(a:cchar)
2712
2713 let t = ["File1:10:Line10", "File1:20:Line20"]
Bram Moolenaar2c809b72017-09-01 18:34:02 +02002714 call g:Xsetlist([], ' ', {'lines' : t})
2715 call g:Xsetlist([], 'a', {'lines' : ["File1:30:Line30"]})
Bram Moolenaarae338332017-08-11 20:25:26 +02002716
2717 let l = g:Xgetlist()
2718 call assert_equal(3, len(l))
2719 call assert_equal(20, l[1].lnum)
2720 call assert_equal('Line30', l[2].text)
Bram Moolenaar2c809b72017-09-01 18:34:02 +02002721 call g:Xsetlist([], 'r', {'lines' : ["File2:5:Line5"]})
Bram Moolenaarae338332017-08-11 20:25:26 +02002722 let l = g:Xgetlist()
2723 call assert_equal(1, len(l))
2724 call assert_equal('Line5', l[0].text)
Bram Moolenaar2c809b72017-09-01 18:34:02 +02002725 call assert_equal(-1, g:Xsetlist([], 'a', {'lines' : 10}))
2726 call assert_equal(-1, g:Xsetlist([], 'a', {'lines' : "F1:10:L10"}))
Bram Moolenaarae338332017-08-11 20:25:26 +02002727
2728 call g:Xsetlist([], 'f')
2729 " Add entries to multiple lists
Bram Moolenaar2c809b72017-09-01 18:34:02 +02002730 call g:Xsetlist([], 'a', {'nr' : 1, 'lines' : ["File1:10:Line10"]})
2731 call g:Xsetlist([], 'a', {'nr' : 2, 'lines' : ["File2:20:Line20"]})
2732 call g:Xsetlist([], 'a', {'nr' : 1, 'lines' : ["File1:15:Line15"]})
2733 call g:Xsetlist([], 'a', {'nr' : 2, 'lines' : ["File2:25:Line25"]})
Bram Moolenaarae338332017-08-11 20:25:26 +02002734 call assert_equal('Line15', g:Xgetlist({'nr':1, 'items':1}).items[1].text)
2735 call assert_equal('Line25', g:Xgetlist({'nr':2, 'items':1}).items[1].text)
Bram Moolenaar36538222017-09-02 19:51:44 +02002736
2737 " Adding entries using a custom efm
2738 set efm&
2739 call g:Xsetlist([], ' ', {'efm' : '%f#%l#%m',
2740 \ 'lines' : ["F1#10#L10", "F2#20#L20"]})
2741 call assert_equal(20, g:Xgetlist({'items':1}).items[1].lnum)
2742 call g:Xsetlist([], 'a', {'efm' : '%f#%l#%m', 'lines' : ["F3:30:L30"]})
2743 call assert_equal('F3:30:L30', g:Xgetlist({'items':1}).items[2].text)
2744 call assert_equal(20, g:Xgetlist({'items':1}).items[1].lnum)
2745 call assert_equal(-1, g:Xsetlist([], 'a', {'efm' : [],
2746 \ 'lines' : ['F1:10:L10']}))
Bram Moolenaarae338332017-08-11 20:25:26 +02002747endfunc
2748
2749func Test_setexpr()
2750 call Xsetexpr_tests('c')
2751 call Xsetexpr_tests('l')
2752endfunc
2753
2754" Tests for per quickfix/location list directory stack
2755func Xmultidirstack_tests(cchar)
2756 call s:setup_commands(a:cchar)
2757
2758 call g:Xsetlist([], 'f')
2759 Xexpr "" | Xexpr ""
2760
Bram Moolenaar2c809b72017-09-01 18:34:02 +02002761 call g:Xsetlist([], 'a', {'nr' : 1, 'lines' : ["Entering dir 'Xone/a'"]})
2762 call g:Xsetlist([], 'a', {'nr' : 2, 'lines' : ["Entering dir 'Xtwo/a'"]})
2763 call g:Xsetlist([], 'a', {'nr' : 1, 'lines' : ["one.txt:3:one one one"]})
2764 call g:Xsetlist([], 'a', {'nr' : 2, 'lines' : ["two.txt:5:two two two"]})
Bram Moolenaarae338332017-08-11 20:25:26 +02002765
2766 let l1 = g:Xgetlist({'nr':1, 'items':1})
2767 let l2 = g:Xgetlist({'nr':2, 'items':1})
2768 call assert_equal('Xone/a/one.txt', bufname(l1.items[1].bufnr))
2769 call assert_equal(3, l1.items[1].lnum)
2770 call assert_equal('Xtwo/a/two.txt', bufname(l2.items[1].bufnr))
2771 call assert_equal(5, l2.items[1].lnum)
2772endfunc
2773
2774func Test_multidirstack()
2775 call mkdir('Xone/a', 'p')
2776 call mkdir('Xtwo/a', 'p')
2777 let lines = ['1', '2', 'one one one', '4', 'two two two', '6', '7']
2778 call writefile(lines, 'Xone/a/one.txt')
2779 call writefile(lines, 'Xtwo/a/two.txt')
2780 let save_efm = &efm
2781 set efm=%DEntering\ dir\ '%f',%f:%l:%m,%XLeaving\ dir\ '%f'
2782
2783 call Xmultidirstack_tests('c')
2784 call Xmultidirstack_tests('l')
2785
2786 let &efm = save_efm
2787 call delete('Xone', 'rf')
2788 call delete('Xtwo', 'rf')
2789endfunc
2790
2791" Tests for per quickfix/location list file stack
2792func Xmultifilestack_tests(cchar)
2793 call s:setup_commands(a:cchar)
2794
2795 call g:Xsetlist([], 'f')
2796 Xexpr "" | Xexpr ""
2797
Bram Moolenaar2c809b72017-09-01 18:34:02 +02002798 call g:Xsetlist([], 'a', {'nr' : 1, 'lines' : ["[one.txt]"]})
2799 call g:Xsetlist([], 'a', {'nr' : 2, 'lines' : ["[two.txt]"]})
2800 call g:Xsetlist([], 'a', {'nr' : 1, 'lines' : ["(3,5) one one one"]})
2801 call g:Xsetlist([], 'a', {'nr' : 2, 'lines' : ["(5,9) two two two"]})
Bram Moolenaarae338332017-08-11 20:25:26 +02002802
2803 let l1 = g:Xgetlist({'nr':1, 'items':1})
2804 let l2 = g:Xgetlist({'nr':2, 'items':1})
2805 call assert_equal('one.txt', bufname(l1.items[1].bufnr))
2806 call assert_equal(3, l1.items[1].lnum)
2807 call assert_equal('two.txt', bufname(l2.items[1].bufnr))
2808 call assert_equal(5, l2.items[1].lnum)
Bram Moolenaare333e792018-04-08 13:27:39 +02002809
2810 " Test for start of a new error line in the same line where a previous
2811 " error line ends with a file stack.
2812 let efm_val = 'Error\ l%l\ in\ %f,'
2813 let efm_val .= '%-P%>(%f%r,Error\ l%l\ in\ %m,%-Q)%r'
2814 let l = g:Xgetlist({'lines' : [
2815 \ '(one.txt',
2816 \ 'Error l4 in one.txt',
2817 \ ') (two.txt',
2818 \ 'Error l6 in two.txt',
2819 \ ')',
2820 \ 'Error l8 in one.txt'
2821 \ ], 'efm' : efm_val})
2822 call assert_equal(3, len(l.items))
2823 call assert_equal('one.txt', bufname(l.items[0].bufnr))
2824 call assert_equal(4, l.items[0].lnum)
2825 call assert_equal('one.txt', l.items[0].text)
2826 call assert_equal('two.txt', bufname(l.items[1].bufnr))
2827 call assert_equal(6, l.items[1].lnum)
2828 call assert_equal('two.txt', l.items[1].text)
2829 call assert_equal('one.txt', bufname(l.items[2].bufnr))
2830 call assert_equal(8, l.items[2].lnum)
2831 call assert_equal('', l.items[2].text)
Bram Moolenaarae338332017-08-11 20:25:26 +02002832endfunc
2833
2834func Test_multifilestack()
2835 let lines = ['1', '2', 'one one one', '4', 'two two two', '6', '7']
2836 call writefile(lines, 'one.txt')
2837 call writefile(lines, 'two.txt')
2838 let save_efm = &efm
2839 set efm=%+P[%f],(%l\\,%c)\ %m,%-Q
2840
2841 call Xmultifilestack_tests('c')
2842 call Xmultifilestack_tests('l')
2843
2844 let &efm = save_efm
2845 call delete('one.txt')
2846 call delete('two.txt')
2847endfunc
2848
2849" Tests for per buffer 'efm' setting
2850func Test_perbuf_efm()
2851 call writefile(["File1-10-Line10"], 'one.txt')
2852 call writefile(["File2#20#Line20"], 'two.txt')
2853 set efm=%f#%l#%m
2854 new | only
2855 new
2856 setlocal efm=%f-%l-%m
2857 cfile one.txt
2858 wincmd w
2859 caddfile two.txt
2860
2861 let l = getqflist()
2862 call assert_equal(10, l[0].lnum)
2863 call assert_equal('Line20', l[1].text)
2864
2865 set efm&
2866 new | only
2867 call delete('one.txt')
2868 call delete('two.txt')
Bram Moolenaara8788f42017-07-19 17:06:20 +02002869endfunc
Bram Moolenaard28cc3f2017-07-27 22:03:50 +02002870
2871" Open multiple help windows using ":lhelpgrep
2872" This test used to crash Vim
2873func Test_Multi_LL_Help()
2874 new | only
2875 lhelpgrep window
2876 lopen
2877 e#
2878 lhelpgrep buffer
2879 call assert_equal(3, winnr('$'))
2880 call assert_true(len(getloclist(1)) != 0)
2881 call assert_true(len(getloclist(2)) != 0)
2882 new | only
2883endfunc
Bram Moolenaar55b69262017-08-13 13:42:01 +02002884
2885" Tests for adding new quickfix lists using setqflist()
2886func XaddQf_tests(cchar)
2887 call s:setup_commands(a:cchar)
2888
2889 " Create a new list using ' ' for action
2890 call g:Xsetlist([], 'f')
2891 call g:Xsetlist([], ' ', {'title' : 'Test1'})
2892 let l = g:Xgetlist({'nr' : '$', 'all' : 1})
2893 call assert_equal(1, l.nr)
2894 call assert_equal('Test1', l.title)
2895
2896 " Create a new list using ' ' for action and '$' for 'nr'
2897 call g:Xsetlist([], 'f')
2898 call g:Xsetlist([], ' ', {'title' : 'Test2', 'nr' : '$'})
2899 let l = g:Xgetlist({'nr' : '$', 'all' : 1})
2900 call assert_equal(1, l.nr)
2901 call assert_equal('Test2', l.title)
2902
2903 " Create a new list using 'a' for action
2904 call g:Xsetlist([], 'f')
2905 call g:Xsetlist([], 'a', {'title' : 'Test3'})
2906 let l = g:Xgetlist({'nr' : '$', 'all' : 1})
2907 call assert_equal(1, l.nr)
2908 call assert_equal('Test3', l.title)
2909
2910 " Create a new list using 'a' for action and '$' for 'nr'
2911 call g:Xsetlist([], 'f')
2912 call g:Xsetlist([], 'a', {'title' : 'Test3', 'nr' : '$'})
2913 call g:Xsetlist([], 'a', {'title' : 'Test4'})
2914 let l = g:Xgetlist({'nr' : '$', 'all' : 1})
2915 call assert_equal(1, l.nr)
2916 call assert_equal('Test4', l.title)
2917
2918 " Adding a quickfix list should remove all the lists following the current
2919 " list.
2920 Xexpr "" | Xexpr "" | Xexpr ""
2921 silent! 10Xolder
2922 call g:Xsetlist([], ' ', {'title' : 'Test5'})
2923 let l = g:Xgetlist({'nr' : '$', 'all' : 1})
2924 call assert_equal(2, l.nr)
2925 call assert_equal('Test5', l.title)
2926
2927 " Add a quickfix list using '$' as the list number.
2928 let lastqf = g:Xgetlist({'nr':'$'}).nr
2929 silent! 99Xolder
2930 call g:Xsetlist([], ' ', {'nr' : '$', 'title' : 'Test6'})
2931 let l = g:Xgetlist({'nr' : '$', 'all' : 1})
2932 call assert_equal(lastqf + 1, l.nr)
2933 call assert_equal('Test6', l.title)
2934
2935 " Add a quickfix list using 'nr' set to one more than the quickfix
2936 " list size.
2937 let lastqf = g:Xgetlist({'nr':'$'}).nr
2938 silent! 99Xolder
2939 call g:Xsetlist([], ' ', {'nr' : lastqf + 1, 'title' : 'Test7'})
2940 let l = g:Xgetlist({'nr' : '$', 'all' : 1})
2941 call assert_equal(lastqf + 1, l.nr)
2942 call assert_equal('Test7', l.title)
2943
2944 " Add a quickfix list to a stack with 10 lists using 'nr' set to '$'
2945 exe repeat('Xexpr "" |', 9) . 'Xexpr ""'
2946 silent! 99Xolder
2947 call g:Xsetlist([], ' ', {'nr' : '$', 'title' : 'Test8'})
2948 let l = g:Xgetlist({'nr' : '$', 'all' : 1})
2949 call assert_equal(10, l.nr)
2950 call assert_equal('Test8', l.title)
2951
2952 " Add a quickfix list using 'nr' set to a value greater than 10
2953 call assert_equal(-1, g:Xsetlist([], ' ', {'nr' : 12, 'title' : 'Test9'}))
2954
2955 " Try adding a quickfix list with 'nr' set to a value greater than the
2956 " quickfix list size but less than 10.
2957 call g:Xsetlist([], 'f')
2958 Xexpr "" | Xexpr "" | Xexpr ""
2959 silent! 99Xolder
2960 call assert_equal(-1, g:Xsetlist([], ' ', {'nr' : 8, 'title' : 'Test10'}))
2961
2962 " Add a quickfix list using 'nr' set to a some string or list
2963 call assert_equal(-1, g:Xsetlist([], ' ', {'nr' : [1,2], 'title' : 'Test11'}))
2964endfunc
2965
2966func Test_add_qf()
2967 call XaddQf_tests('c')
2968 call XaddQf_tests('l')
2969endfunc
Bram Moolenaar7adf06f2017-08-27 15:23:41 +02002970
2971" Test for getting the quickfix list items from some text without modifying
2972" the quickfix stack
Bram Moolenaar2c809b72017-09-01 18:34:02 +02002973func XgetListFromLines(cchar)
Bram Moolenaar7adf06f2017-08-27 15:23:41 +02002974 call s:setup_commands(a:cchar)
2975 call g:Xsetlist([], 'f')
2976
Bram Moolenaar2c809b72017-09-01 18:34:02 +02002977 let l = g:Xgetlist({'lines' : ["File2:20:Line20", "File2:30:Line30"]}).items
Bram Moolenaar7adf06f2017-08-27 15:23:41 +02002978 call assert_equal(2, len(l))
2979 call assert_equal(30, l[1].lnum)
2980
Bram Moolenaar2c809b72017-09-01 18:34:02 +02002981 call assert_equal({}, g:Xgetlist({'lines' : 10}))
2982 call assert_equal({}, g:Xgetlist({'lines' : 'File1:10:Line10'}))
2983 call assert_equal([], g:Xgetlist({'lines' : []}).items)
2984 call assert_equal([], g:Xgetlist({'lines' : [10, 20]}).items)
Bram Moolenaar7adf06f2017-08-27 15:23:41 +02002985
Bram Moolenaar36538222017-09-02 19:51:44 +02002986 " Parse text using a custom efm
2987 set efm&
2988 let l = g:Xgetlist({'lines':['File3#30#Line30'], 'efm' : '%f#%l#%m'}).items
2989 call assert_equal('Line30', l[0].text)
2990 let l = g:Xgetlist({'lines':['File3:30:Line30'], 'efm' : '%f-%l-%m'}).items
2991 call assert_equal('File3:30:Line30', l[0].text)
2992 let l = g:Xgetlist({'lines':['File3:30:Line30'], 'efm' : [1,2]})
2993 call assert_equal({}, l)
2994 call assert_fails("call g:Xgetlist({'lines':['abc'], 'efm':'%2'})", 'E376:')
2995 call assert_fails("call g:Xgetlist({'lines':['abc'], 'efm':''})", 'E378:')
2996
Bram Moolenaar7adf06f2017-08-27 15:23:41 +02002997 " Make sure that the quickfix stack is not modified
2998 call assert_equal(0, g:Xgetlist({'nr' : '$'}).nr)
2999endfunc
3000
Bram Moolenaar2c809b72017-09-01 18:34:02 +02003001func Test_get_list_from_lines()
3002 call XgetListFromLines('c')
3003 call XgetListFromLines('l')
Bram Moolenaar7adf06f2017-08-27 15:23:41 +02003004endfunc
Bram Moolenaara539f4f2017-08-30 20:33:55 +02003005
3006" Tests for the quickfix list id
3007func Xqfid_tests(cchar)
3008 call s:setup_commands(a:cchar)
3009
3010 call g:Xsetlist([], 'f')
Bram Moolenaara6d48492017-12-12 22:45:31 +01003011 call assert_equal(0, g:Xgetlist({'id':0}).id)
Bram Moolenaara539f4f2017-08-30 20:33:55 +02003012 Xexpr ''
3013 let start_id = g:Xgetlist({'id' : 0}).id
3014 Xexpr '' | Xexpr ''
3015 Xolder
3016 call assert_equal(start_id, g:Xgetlist({'id':0, 'nr':1}).id)
3017 call assert_equal(start_id + 1, g:Xgetlist({'id':0, 'nr':0}).id)
3018 call assert_equal(start_id + 2, g:Xgetlist({'id':0, 'nr':'$'}).id)
Bram Moolenaara6d48492017-12-12 22:45:31 +01003019 call assert_equal(0, g:Xgetlist({'id':0, 'nr':99}).id)
Bram Moolenaara539f4f2017-08-30 20:33:55 +02003020 call assert_equal(2, g:Xgetlist({'id':start_id + 1, 'nr':0}).nr)
Bram Moolenaara6d48492017-12-12 22:45:31 +01003021 call assert_equal(0, g:Xgetlist({'id':99, 'nr':0}).id)
3022 call assert_equal(0, g:Xgetlist({'id':"abc", 'nr':0}).id)
Bram Moolenaara539f4f2017-08-30 20:33:55 +02003023
3024 call g:Xsetlist([], 'a', {'id':start_id, 'context':[1,2]})
3025 call assert_equal([1,2], g:Xgetlist({'nr':1, 'context':1}).context)
Bram Moolenaar2c809b72017-09-01 18:34:02 +02003026 call g:Xsetlist([], 'a', {'id':start_id+1, 'lines':['F1:10:L10']})
Bram Moolenaara539f4f2017-08-30 20:33:55 +02003027 call assert_equal('L10', g:Xgetlist({'nr':2, 'items':1}).items[0].text)
3028 call assert_equal(-1, g:Xsetlist([], 'a', {'id':999, 'title':'Vim'}))
3029 call assert_equal(-1, g:Xsetlist([], 'a', {'id':'abc', 'title':'Vim'}))
3030
3031 let qfid = g:Xgetlist({'id':0, 'nr':0})
3032 call g:Xsetlist([], 'f')
Bram Moolenaara6d48492017-12-12 22:45:31 +01003033 call assert_equal(0, g:Xgetlist({'id':qfid, 'nr':0}).id)
Bram Moolenaara539f4f2017-08-30 20:33:55 +02003034endfunc
3035
3036func Test_qf_id()
3037 call Xqfid_tests('c')
3038 call Xqfid_tests('l')
3039endfunc
Bram Moolenaar74240d32017-12-10 15:26:15 +01003040
3041func Xqfjump_tests(cchar)
3042 call s:setup_commands(a:cchar)
3043
3044 call writefile(["Line1\tFoo", "Line2"], 'F1')
3045 call writefile(["Line1\tBar", "Line2"], 'F2')
3046 call writefile(["Line1\tBaz", "Line2"], 'F3')
3047
3048 call g:Xsetlist([], 'f')
3049
3050 " Tests for
3051 " Jumping to a line using a pattern
3052 " Jumping to a column greater than the last column in a line
3053 " Jumping to a line greater than the last line in the file
3054 let l = []
3055 for i in range(1, 7)
3056 call add(l, {})
3057 endfor
3058 let l[0].filename='F1'
3059 let l[0].pattern='Line1'
3060 let l[1].filename='F2'
3061 let l[1].pattern='Line1'
3062 let l[2].filename='F3'
3063 let l[2].pattern='Line1'
3064 let l[3].filename='F3'
3065 let l[3].lnum=1
3066 let l[3].col=9
3067 let l[3].vcol=1
3068 let l[4].filename='F3'
3069 let l[4].lnum=99
3070 let l[5].filename='F3'
3071 let l[5].lnum=1
3072 let l[5].col=99
3073 let l[5].vcol=1
3074 let l[6].filename='F3'
3075 let l[6].pattern='abcxyz'
3076
3077 call g:Xsetlist([], ' ', {'items' : l})
3078 Xopen | only
3079 2Xnext
3080 call assert_equal(3, g:Xgetlist({'idx' : 0}).idx)
3081 call assert_equal('F3', bufname('%'))
3082 Xnext
3083 call assert_equal(7, col('.'))
3084 Xnext
3085 call assert_equal(2, line('.'))
3086 Xnext
3087 call assert_equal(9, col('.'))
3088 2
3089 Xnext
3090 call assert_equal(2, line('.'))
3091
3092 if a:cchar == 'l'
3093 " When jumping to a location list entry in the location list window and
3094 " no usable windows are available, then a new window should be opened.
3095 enew! | new | only
3096 call g:Xsetlist([], 'f')
3097 setlocal buftype=nofile
3098 new
3099 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']})
3100 Xopen
3101 let winid = win_getid()
3102 wincmd p
3103 close
3104 call win_gotoid(winid)
3105 Xnext
3106 call assert_equal(3, winnr('$'))
3107 call assert_equal(1, winnr())
3108 call assert_equal(2, line('.'))
3109
3110 " When jumping to an entry in the location list window and the window
3111 " associated with the location list is not present and a window containing
3112 " the file is already present, then that window should be used.
3113 close
3114 belowright new
3115 call g:Xsetlist([], 'f')
3116 edit F3
3117 call win_gotoid(winid)
3118 Xlast
3119 call assert_equal(3, winnr())
3120 call assert_equal(6, g:Xgetlist({'size' : 1}).size)
3121 call assert_equal(winid, g:Xgetlist({'winid' : 1}).winid)
3122 endif
3123
3124 " Cleanup
3125 enew!
3126 new | only
3127
3128 call delete('F1')
3129 call delete('F2')
3130 call delete('F3')
3131endfunc
3132
3133func Test_qfjump()
3134 call Xqfjump_tests('c')
3135 call Xqfjump_tests('l')
3136endfunc
Bram Moolenaara6d48492017-12-12 22:45:31 +01003137
3138" Tests for the getqflist() and getloclist() functions when the list is not
3139" present or is empty
3140func Xgetlist_empty_tests(cchar)
3141 call s:setup_commands(a:cchar)
3142
3143 " Empty quickfix stack
3144 call g:Xsetlist([], 'f')
3145 call assert_equal('', g:Xgetlist({'context' : 0}).context)
3146 call assert_equal(0, g:Xgetlist({'id' : 0}).id)
3147 call assert_equal(0, g:Xgetlist({'idx' : 0}).idx)
3148 call assert_equal([], g:Xgetlist({'items' : 0}).items)
3149 call assert_equal(0, g:Xgetlist({'nr' : 0}).nr)
3150 call assert_equal(0, g:Xgetlist({'size' : 0}).size)
3151 call assert_equal('', g:Xgetlist({'title' : 0}).title)
3152 call assert_equal(0, g:Xgetlist({'winid' : 0}).winid)
Bram Moolenaarb254af32017-12-18 19:48:58 +01003153 call assert_equal(0, g:Xgetlist({'changedtick' : 0}).changedtick)
Bram Moolenaarc9cc9c72018-09-02 15:18:42 +02003154 if a:cchar == 'c'
3155 call assert_equal({'context' : '', 'id' : 0, 'idx' : 0,
Bram Moolenaar647e24b2019-03-17 16:39:46 +01003156 \ 'items' : [], 'nr' : 0, 'size' : 0, 'qfbufnr' : 0,
Bram Moolenaarc9cc9c72018-09-02 15:18:42 +02003157 \ 'title' : '', 'winid' : 0, 'changedtick': 0},
3158 \ g:Xgetlist({'all' : 0}))
3159 else
3160 call assert_equal({'context' : '', 'id' : 0, 'idx' : 0,
3161 \ 'items' : [], 'nr' : 0, 'size' : 0, 'title' : '',
Bram Moolenaar647e24b2019-03-17 16:39:46 +01003162 \ 'winid' : 0, 'changedtick': 0, 'filewinid' : 0,
3163 \ 'qfbufnr' : 0},
Bram Moolenaarc9cc9c72018-09-02 15:18:42 +02003164 \ g:Xgetlist({'all' : 0}))
3165 endif
Bram Moolenaara6d48492017-12-12 22:45:31 +01003166
Bram Moolenaar2ec364e2018-01-27 11:52:13 +01003167 " Quickfix window with empty stack
3168 silent! Xopen
3169 let qfwinid = (a:cchar == 'c') ? win_getid() : 0
Bram Moolenaar647e24b2019-03-17 16:39:46 +01003170 let qfbufnr = (a:cchar == 'c') ? bufnr('') : 0
Bram Moolenaar2ec364e2018-01-27 11:52:13 +01003171 call assert_equal(qfwinid, g:Xgetlist({'winid' : 0}).winid)
3172 Xclose
3173
Bram Moolenaara6d48492017-12-12 22:45:31 +01003174 " Empty quickfix list
3175 Xexpr ""
3176 call assert_equal('', g:Xgetlist({'context' : 0}).context)
3177 call assert_notequal(0, g:Xgetlist({'id' : 0}).id)
3178 call assert_equal(0, g:Xgetlist({'idx' : 0}).idx)
3179 call assert_equal([], g:Xgetlist({'items' : 0}).items)
3180 call assert_notequal(0, g:Xgetlist({'nr' : 0}).nr)
3181 call assert_equal(0, g:Xgetlist({'size' : 0}).size)
3182 call assert_notequal('', g:Xgetlist({'title' : 0}).title)
3183 call assert_equal(0, g:Xgetlist({'winid' : 0}).winid)
Bram Moolenaarb254af32017-12-18 19:48:58 +01003184 call assert_equal(1, g:Xgetlist({'changedtick' : 0}).changedtick)
Bram Moolenaara6d48492017-12-12 22:45:31 +01003185
3186 let qfid = g:Xgetlist({'id' : 0}).id
3187 call g:Xsetlist([], 'f')
3188
3189 " Non-existing quickfix identifier
3190 call assert_equal('', g:Xgetlist({'id' : qfid, 'context' : 0}).context)
3191 call assert_equal(0, g:Xgetlist({'id' : qfid}).id)
3192 call assert_equal(0, g:Xgetlist({'id' : qfid, 'idx' : 0}).idx)
3193 call assert_equal([], g:Xgetlist({'id' : qfid, 'items' : 0}).items)
3194 call assert_equal(0, g:Xgetlist({'id' : qfid, 'nr' : 0}).nr)
3195 call assert_equal(0, g:Xgetlist({'id' : qfid, 'size' : 0}).size)
3196 call assert_equal('', g:Xgetlist({'id' : qfid, 'title' : 0}).title)
3197 call assert_equal(0, g:Xgetlist({'id' : qfid, 'winid' : 0}).winid)
Bram Moolenaarb254af32017-12-18 19:48:58 +01003198 call assert_equal(0, g:Xgetlist({'id' : qfid, 'changedtick' : 0}).changedtick)
Bram Moolenaarc9cc9c72018-09-02 15:18:42 +02003199 if a:cchar == 'c'
3200 call assert_equal({'context' : '', 'id' : 0, 'idx' : 0, 'items' : [],
3201 \ 'nr' : 0, 'size' : 0, 'title' : '', 'winid' : 0,
Bram Moolenaar647e24b2019-03-17 16:39:46 +01003202 \ 'qfbufnr' : qfbufnr,
Bram Moolenaarc9cc9c72018-09-02 15:18:42 +02003203 \ 'changedtick' : 0}, g:Xgetlist({'id' : qfid, 'all' : 0}))
3204 else
3205 call assert_equal({'context' : '', 'id' : 0, 'idx' : 0, 'items' : [],
3206 \ 'nr' : 0, 'size' : 0, 'title' : '', 'winid' : 0,
Bram Moolenaar647e24b2019-03-17 16:39:46 +01003207 \ 'changedtick' : 0, 'filewinid' : 0, 'qfbufnr' : 0},
Bram Moolenaarc9cc9c72018-09-02 15:18:42 +02003208 \ g:Xgetlist({'id' : qfid, 'all' : 0}))
3209 endif
Bram Moolenaara6d48492017-12-12 22:45:31 +01003210
3211 " Non-existing quickfix list number
3212 call assert_equal('', g:Xgetlist({'nr' : 5, 'context' : 0}).context)
3213 call assert_equal(0, g:Xgetlist({'nr' : 5}).nr)
3214 call assert_equal(0, g:Xgetlist({'nr' : 5, 'idx' : 0}).idx)
3215 call assert_equal([], g:Xgetlist({'nr' : 5, 'items' : 0}).items)
3216 call assert_equal(0, g:Xgetlist({'nr' : 5, 'id' : 0}).id)
3217 call assert_equal(0, g:Xgetlist({'nr' : 5, 'size' : 0}).size)
3218 call assert_equal('', g:Xgetlist({'nr' : 5, 'title' : 0}).title)
3219 call assert_equal(0, g:Xgetlist({'nr' : 5, 'winid' : 0}).winid)
Bram Moolenaarb254af32017-12-18 19:48:58 +01003220 call assert_equal(0, g:Xgetlist({'nr' : 5, 'changedtick' : 0}).changedtick)
Bram Moolenaarc9cc9c72018-09-02 15:18:42 +02003221 if a:cchar == 'c'
3222 call assert_equal({'context' : '', 'id' : 0, 'idx' : 0, 'items' : [],
3223 \ 'nr' : 0, 'size' : 0, 'title' : '', 'winid' : 0,
Bram Moolenaar647e24b2019-03-17 16:39:46 +01003224 \ 'changedtick' : 0, 'qfbufnr' : qfbufnr},
3225 \ g:Xgetlist({'nr' : 5, 'all' : 0}))
Bram Moolenaarc9cc9c72018-09-02 15:18:42 +02003226 else
3227 call assert_equal({'context' : '', 'id' : 0, 'idx' : 0, 'items' : [],
3228 \ 'nr' : 0, 'size' : 0, 'title' : '', 'winid' : 0,
Bram Moolenaar647e24b2019-03-17 16:39:46 +01003229 \ 'changedtick' : 0, 'filewinid' : 0, 'qfbufnr' : 0},
Bram Moolenaarc9cc9c72018-09-02 15:18:42 +02003230 \ g:Xgetlist({'nr' : 5, 'all' : 0}))
3231 endif
Bram Moolenaara6d48492017-12-12 22:45:31 +01003232endfunc
3233
3234func Test_getqflist()
3235 call Xgetlist_empty_tests('c')
3236 call Xgetlist_empty_tests('l')
3237endfunc
Bram Moolenaarb254af32017-12-18 19:48:58 +01003238
Bram Moolenaara0ca7d02017-12-19 10:22:19 +01003239func Test_getqflist_invalid_nr()
3240 " The following commands used to crash Vim
3241 cexpr ""
3242 call getqflist({'nr' : $XXX_DOES_NOT_EXIST_XXX})
3243
3244 " Cleanup
3245 call setqflist([], 'r')
3246endfunc
3247
Bram Moolenaarb254af32017-12-18 19:48:58 +01003248" Tests for the quickfix/location list changedtick
3249func Xqftick_tests(cchar)
3250 call s:setup_commands(a:cchar)
3251
3252 call g:Xsetlist([], 'f')
3253
3254 Xexpr "F1:10:Line10"
3255 let qfid = g:Xgetlist({'id' : 0}).id
3256 call assert_equal(1, g:Xgetlist({'changedtick' : 0}).changedtick)
3257 Xaddexpr "F2:20:Line20\nF2:21:Line21"
3258 call assert_equal(2, g:Xgetlist({'changedtick' : 0}).changedtick)
3259 call g:Xsetlist([], 'a', {'lines' : ["F3:30:Line30", "F3:31:Line31"]})
3260 call assert_equal(3, g:Xgetlist({'changedtick' : 0}).changedtick)
3261 call g:Xsetlist([], 'r', {'lines' : ["F4:40:Line40"]})
3262 call assert_equal(4, g:Xgetlist({'changedtick' : 0}).changedtick)
3263 call g:Xsetlist([], 'a', {'title' : 'New Title'})
3264 call assert_equal(5, g:Xgetlist({'changedtick' : 0}).changedtick)
3265
3266 enew!
3267 call append(0, ["F5:50:L50", "F6:60:L60"])
3268 Xaddbuffer
3269 call assert_equal(6, g:Xgetlist({'changedtick' : 0}).changedtick)
3270 enew!
3271
3272 call g:Xsetlist([], 'a', {'context' : {'bus' : 'pci'}})
3273 call assert_equal(7, g:Xgetlist({'changedtick' : 0}).changedtick)
3274 call g:Xsetlist([{'filename' : 'F7', 'lnum' : 10, 'text' : 'L7'},
3275 \ {'filename' : 'F7', 'lnum' : 11, 'text' : 'L11'}], 'a')
3276 call assert_equal(8, g:Xgetlist({'changedtick' : 0}).changedtick)
3277 call g:Xsetlist([{'filename' : 'F7', 'lnum' : 10, 'text' : 'L7'},
3278 \ {'filename' : 'F7', 'lnum' : 11, 'text' : 'L11'}], ' ')
3279 call assert_equal(1, g:Xgetlist({'changedtick' : 0}).changedtick)
3280 call g:Xsetlist([{'filename' : 'F7', 'lnum' : 10, 'text' : 'L7'},
3281 \ {'filename' : 'F7', 'lnum' : 11, 'text' : 'L11'}], 'r')
3282 call assert_equal(2, g:Xgetlist({'changedtick' : 0}).changedtick)
3283
3284 call writefile(["F8:80:L80", "F8:81:L81"], "Xone")
3285 Xfile Xone
3286 call assert_equal(1, g:Xgetlist({'changedtick' : 0}).changedtick)
3287 Xaddfile Xone
3288 call assert_equal(2, g:Xgetlist({'changedtick' : 0}).changedtick)
3289
3290 " Test case for updating a non-current quickfix list
3291 call g:Xsetlist([], 'f')
3292 Xexpr "F1:1:L1"
3293 Xexpr "F2:2:L2"
3294 call g:Xsetlist([], 'a', {'nr' : 1, "lines" : ["F10:10:L10"]})
3295 call assert_equal(1, g:Xgetlist({'changedtick' : 0}).changedtick)
3296 call assert_equal(2, g:Xgetlist({'nr' : 1, 'changedtick' : 0}).changedtick)
3297
3298 call delete("Xone")
3299endfunc
3300
3301func Test_qf_tick()
3302 call Xqftick_tests('c')
3303 call Xqftick_tests('l')
3304endfunc
Bram Moolenaar12237442017-12-19 12:38:52 +01003305
Bram Moolenaarc631f2d2018-08-21 21:58:13 +02003306" Test helpgrep with lang specifier
3307func Xtest_helpgrep_with_lang_specifier(cchar)
3308 call s:setup_commands(a:cchar)
3309 Xhelpgrep Vim@en
3310 call assert_equal('help', &filetype)
3311 call assert_notequal(0, g:Xgetlist({'nr' : '$'}).nr)
3312 new | only
3313endfunc
3314
3315func Test_helpgrep_with_lang_specifier()
3316 call Xtest_helpgrep_with_lang_specifier('c')
3317 call Xtest_helpgrep_with_lang_specifier('l')
3318endfunc
3319
Bram Moolenaar12237442017-12-19 12:38:52 +01003320" The following test used to crash Vim.
3321" Open the location list window and close the regular window associated with
3322" the location list. When the garbage collection runs now, it incorrectly
3323" marks the location list context as not in use and frees the context.
3324func Test_ll_window_ctx()
3325 call setloclist(0, [], 'f')
3326 call setloclist(0, [], 'a', {'context' : []})
3327 lopen | only
3328 call test_garbagecollect_now()
3329 echo getloclist(0, {'context' : 1}).context
3330 enew | only
3331endfunc
3332
Bram Moolenaar14a4deb2017-12-19 16:48:55 +01003333" The following test used to crash vim
3334func Test_lfile_crash()
3335 sp Xtest
3336 au QuickFixCmdPre * bw
3337 call assert_fails('lfile', 'E40')
3338 au! QuickFixCmdPre
3339endfunc
Bram Moolenaar3c097222017-12-21 20:54:49 +01003340
3341" The following test used to crash vim
3342func Test_lbuffer_crash()
3343 sv Xtest
3344 augroup QF_Test
3345 au!
3346 au * * bw
3347 augroup END
3348 lbuffer
3349 augroup QF_Test
3350 au!
3351 augroup END
3352endfunc
3353
3354" The following test used to crash vim
3355func Test_lexpr_crash()
3356 augroup QF_Test
3357 au!
3358 au * * call setloclist(0, [], 'f')
3359 augroup END
3360 lexpr ""
3361 augroup QF_Test
3362 au!
3363 augroup END
Bram Moolenaar9f84ded2018-10-20 20:54:02 +02003364
Bram Moolenaar3c097222017-12-21 20:54:49 +01003365 enew | only
Bram Moolenaar9f84ded2018-10-20 20:54:02 +02003366 augroup QF_Test
3367 au!
3368 au BufNew * call setloclist(0, [], 'f')
3369 augroup END
3370 lexpr 'x:1:x'
3371 augroup QF_Test
3372 au!
3373 augroup END
3374
3375 enew | only
3376 lexpr ''
3377 lopen
3378 augroup QF_Test
3379 au!
3380 au FileType * call setloclist(0, [], 'f')
3381 augroup END
3382 lexpr ''
3383 augroup QF_Test
3384 au!
3385 augroup END
Bram Moolenaar3c097222017-12-21 20:54:49 +01003386endfunc
3387
3388" The following test used to crash Vim
3389func Test_lvimgrep_crash()
3390 sv Xtest
3391 augroup QF_Test
3392 au!
3393 au * * call setloclist(0, [], 'f')
3394 augroup END
3395 lvimgrep quickfix test_quickfix.vim
3396 augroup QF_Test
3397 au!
3398 augroup END
Bram Moolenaarb6f14802018-10-21 18:47:43 +02003399
3400 new | only
3401 augroup QF_Test
3402 au!
3403 au BufEnter * call setloclist(0, [], 'r')
3404 augroup END
3405 call assert_fails('lvimgrep Test_lvimgrep_crash *', 'E926:')
3406 augroup QF_Test
3407 au!
3408 augroup END
3409
Bram Moolenaar3c097222017-12-21 20:54:49 +01003410 enew | only
3411endfunc
Bram Moolenaarde046542017-12-26 13:53:11 +01003412
3413" Test for the position of the quickfix and location list window
3414func Test_qfwin_pos()
3415 " Open two windows
3416 new | only
3417 new
3418 cexpr ['F1:10:L10']
3419 copen
3420 " Quickfix window should be the bottom most window
3421 call assert_equal(3, winnr())
3422 close
3423 " Open at the very top
3424 wincmd t
3425 topleft copen
3426 call assert_equal(1, winnr())
3427 close
3428 " open left of the current window
3429 wincmd t
3430 below new
3431 leftabove copen
3432 call assert_equal(2, winnr())
3433 close
3434 " open right of the current window
3435 rightbelow copen
3436 call assert_equal(3, winnr())
3437 close
3438endfunc
Bram Moolenaare1bb8792018-04-06 22:58:23 +02003439
3440" Tests for quickfix/location lists changed by autocommands when
3441" :vimgrep/:lvimgrep commands are running.
3442func Test_vimgrep_autocmd()
3443 call setqflist([], 'f')
3444 call writefile(['stars'], 'Xtest1.txt')
3445 call writefile(['stars'], 'Xtest2.txt')
3446
3447 " Test 1:
3448 " When searching for a pattern using :vimgrep, if the quickfix list is
3449 " changed by an autocmd, the results should be added to the correct quickfix
3450 " list.
3451 autocmd BufRead Xtest2.txt cexpr '' | cexpr ''
3452 silent vimgrep stars Xtest*.txt
3453 call assert_equal(1, getqflist({'nr' : 0}).nr)
3454 call assert_equal(3, getqflist({'nr' : '$'}).nr)
3455 call assert_equal('Xtest2.txt', bufname(getqflist()[1].bufnr))
3456 au! BufRead Xtest2.txt
3457
3458 " Test 2:
3459 " When searching for a pattern using :vimgrep, if the quickfix list is
3460 " freed, then a error should be given.
3461 silent! %bwipe!
3462 call setqflist([], 'f')
3463 autocmd BufRead Xtest2.txt for i in range(10) | cexpr '' | endfor
3464 call assert_fails('vimgrep stars Xtest*.txt', 'E925:')
3465 au! BufRead Xtest2.txt
3466
3467 " Test 3:
3468 " When searching for a pattern using :lvimgrep, if the location list is
3469 " freed, then the command should error out.
3470 silent! %bwipe!
3471 let g:save_winid = win_getid()
3472 autocmd BufRead Xtest2.txt call setloclist(g:save_winid, [], 'f')
3473 call assert_fails('lvimgrep stars Xtest*.txt', 'E926:')
3474 au! BufRead Xtest2.txt
3475
3476 call delete('Xtest1.txt')
3477 call delete('Xtest2.txt')
3478 call setqflist([], 'f')
3479endfunc
Bram Moolenaar3b9474b2018-04-23 21:29:48 +02003480
3481" The following test used to crash Vim
3482func Test_lhelpgrep_autocmd()
3483 lhelpgrep quickfix
3484 autocmd QuickFixCmdPost * call setloclist(0, [], 'f')
3485 lhelpgrep buffer
3486 call assert_equal('help', &filetype)
3487 call assert_equal(0, getloclist(0, {'nr' : '$'}).nr)
3488 lhelpgrep tabpage
3489 call assert_equal('help', &filetype)
3490 call assert_equal(1, getloclist(0, {'nr' : '$'}).nr)
3491 au! QuickFixCmdPost
Bram Moolenaarb6f14802018-10-21 18:47:43 +02003492
3493 new | only
3494 augroup QF_Test
3495 au!
3496 au BufEnter * call setqflist([], 'f')
3497 augroup END
3498 call assert_fails('helpgrep quickfix', 'E925:')
3499 augroup QF_Test
3500 au! BufEnter
3501 augroup END
3502
3503 new | only
3504 augroup QF_Test
3505 au!
3506 au BufEnter * call setqflist([], 'r')
3507 augroup END
3508 call assert_fails('helpgrep quickfix', 'E925:')
3509 augroup QF_Test
3510 au! BufEnter
3511 augroup END
3512
3513 new | only
3514 augroup QF_Test
3515 au!
3516 au BufEnter * call setloclist(0, [], 'r')
3517 augroup END
3518 call assert_fails('lhelpgrep quickfix', 'E926:')
3519 augroup QF_Test
3520 au! BufEnter
3521 augroup END
3522
Bram Moolenaar3b9474b2018-04-23 21:29:48 +02003523 new | only
3524endfunc
Bram Moolenaara796d462018-05-01 14:30:36 +02003525
3526" Test for shortening/simplifying the file name when opening the
3527" quickfix window or when displaying the quickfix list
3528func Test_shorten_fname()
3529 if !has('unix')
3530 return
3531 endif
3532 %bwipe
3533 " Create a quickfix list with a absolute path filename
3534 let fname = getcwd() . '/test_quickfix.vim'
3535 call setqflist([], ' ', {'lines':[fname . ":20:Line20"], 'efm':'%f:%l:%m'})
3536 call assert_equal(fname, bufname('test_quickfix.vim'))
3537 " Opening the quickfix window should simplify the file path
3538 cwindow
3539 call assert_equal('test_quickfix.vim', bufname('test_quickfix.vim'))
3540 cclose
3541 %bwipe
3542 " Create a quickfix list with a absolute path filename
3543 call setqflist([], ' ', {'lines':[fname . ":20:Line20"], 'efm':'%f:%l:%m'})
3544 call assert_equal(fname, bufname('test_quickfix.vim'))
3545 " Displaying the quickfix list should simplify the file path
3546 silent! clist
3547 call assert_equal('test_quickfix.vim', bufname('test_quickfix.vim'))
3548endfunc
Bram Moolenaar8b62e312018-05-13 15:29:04 +02003549
3550" Quickfix title tests
3551" In the below tests, 'exe "cmd"' is used to invoke the quickfix commands.
3552" Otherwise due to indentation, the title is set with spaces at the beginning
3553" of the command.
3554func Test_qftitle()
3555 call writefile(["F1:1:Line1"], 'Xerr')
3556
3557 " :cexpr
3558 exe "cexpr readfile('Xerr')"
3559 call assert_equal(":cexpr readfile('Xerr')", getqflist({'title' : 1}).title)
3560
3561 " :cgetexpr
3562 exe "cgetexpr readfile('Xerr')"
3563 call assert_equal(":cgetexpr readfile('Xerr')",
3564 \ getqflist({'title' : 1}).title)
3565
3566 " :caddexpr
3567 call setqflist([], 'f')
3568 exe "caddexpr readfile('Xerr')"
3569 call assert_equal(":caddexpr readfile('Xerr')",
3570 \ getqflist({'title' : 1}).title)
3571
3572 " :cbuffer
3573 new Xerr
3574 exe "cbuffer"
3575 call assert_equal(':cbuffer (Xerr)', getqflist({'title' : 1}).title)
3576
3577 " :cgetbuffer
3578 edit Xerr
3579 exe "cgetbuffer"
3580 call assert_equal(':cgetbuffer (Xerr)', getqflist({'title' : 1}).title)
3581
3582 " :caddbuffer
3583 call setqflist([], 'f')
3584 edit Xerr
3585 exe "caddbuffer"
3586 call assert_equal(':caddbuffer (Xerr)', getqflist({'title' : 1}).title)
3587
3588 " :cfile
3589 exe "cfile Xerr"
3590 call assert_equal(':cfile Xerr', getqflist({'title' : 1}).title)
3591
3592 " :cgetfile
3593 exe "cgetfile Xerr"
3594 call assert_equal(':cgetfile Xerr', getqflist({'title' : 1}).title)
3595
3596 " :caddfile
3597 call setqflist([], 'f')
3598 exe "caddfile Xerr"
3599 call assert_equal(':caddfile Xerr', getqflist({'title' : 1}).title)
3600
3601 " :grep
3602 set grepprg=internal
3603 exe "grep F1 Xerr"
3604 call assert_equal(':grep F1 Xerr', getqflist({'title' : 1}).title)
3605
3606 " :grepadd
3607 call setqflist([], 'f')
3608 exe "grepadd F1 Xerr"
3609 call assert_equal(':grepadd F1 Xerr', getqflist({'title' : 1}).title)
3610 set grepprg&vim
3611
3612 " :vimgrep
3613 exe "vimgrep F1 Xerr"
3614 call assert_equal(':vimgrep F1 Xerr', getqflist({'title' : 1}).title)
3615
3616 " :vimgrepadd
3617 call setqflist([], 'f')
3618 exe "vimgrepadd F1 Xerr"
3619 call assert_equal(':vimgrepadd F1 Xerr', getqflist({'title' : 1}).title)
3620
3621 call setqflist(['F1:10:L10'], ' ')
3622 call assert_equal(':setqflist()', getqflist({'title' : 1}).title)
3623
3624 call setqflist([], 'f')
3625 call setqflist(['F1:10:L10'], 'a')
3626 call assert_equal(':setqflist()', getqflist({'title' : 1}).title)
3627
3628 call setqflist([], 'f')
3629 call setqflist(['F1:10:L10'], 'r')
3630 call assert_equal(':setqflist()', getqflist({'title' : 1}).title)
3631
3632 close
3633 call delete('Xerr')
3634
3635 call setqflist([], ' ', {'title' : 'Errors'})
3636 copen
3637 call assert_equal('Errors', w:quickfix_title)
3638 call setqflist([], 'r', {'items' : [{'filename' : 'a.c', 'lnum' : 10}]})
3639 call assert_equal('Errors', w:quickfix_title)
3640 cclose
3641endfunc
Bram Moolenaar600323b2018-06-16 22:16:47 +02003642
3643func Test_lbuffer_with_bwipe()
3644 new
3645 new
3646 augroup nasty
3647 au * * bwipe
3648 augroup END
3649 lbuffer
3650 augroup nasty
3651 au!
3652 augroup END
3653endfunc
Bram Moolenaar0366c012018-06-18 20:52:13 +02003654
Bram Moolenaar531b9a32018-07-03 16:54:23 +02003655" Test for an autocmd freeing the quickfix/location list when cexpr/lexpr is
3656" running
3657func Xexpr_acmd_freelist(cchar)
3658 call s:setup_commands(a:cchar)
3659
Bram Moolenaar0366c012018-06-18 20:52:13 +02003660 " This was using freed memory.
3661 augroup nasty
Bram Moolenaar531b9a32018-07-03 16:54:23 +02003662 au * * call g:Xsetlist([], 'f')
Bram Moolenaar0366c012018-06-18 20:52:13 +02003663 augroup END
Bram Moolenaar531b9a32018-07-03 16:54:23 +02003664 Xexpr "x"
Bram Moolenaar0366c012018-06-18 20:52:13 +02003665 augroup nasty
3666 au!
3667 augroup END
3668endfunc
Bram Moolenaar531b9a32018-07-03 16:54:23 +02003669
3670func Test_cexpr_acmd_freelist()
3671 call Xexpr_acmd_freelist('c')
3672 call Xexpr_acmd_freelist('l')
3673endfunc
3674
3675" Test for commands that create a new quickfix/location list and jump to the
3676" first error automatically.
3677func Xjumpto_first_error_test(cchar)
3678 call s:setup_commands(a:cchar)
3679
3680 call s:create_test_file('Xtestfile1')
3681 call s:create_test_file('Xtestfile2')
3682 let l = ['Xtestfile1:2:Line2', 'Xtestfile2:4:Line4']
3683
3684 " Test for cexpr/lexpr
3685 enew
3686 Xexpr l
3687 call assert_equal('Xtestfile1', bufname(''))
3688 call assert_equal(2, line('.'))
3689
3690 " Test for cfile/lfile
3691 enew
3692 call writefile(l, 'Xerr')
3693 Xfile Xerr
3694 call assert_equal('Xtestfile1', bufname(''))
3695 call assert_equal(2, line('.'))
3696
3697 " Test for cbuffer/lbuffer
3698 edit Xerr
3699 Xbuffer
3700 call assert_equal('Xtestfile1', bufname(''))
3701 call assert_equal(2, line('.'))
3702
3703 call delete('Xerr')
3704 call delete('Xtestfile1')
3705 call delete('Xtestfile2')
3706endfunc
3707
3708func Test_jumpto_first_error()
3709 call Xjumpto_first_error_test('c')
3710 call Xjumpto_first_error_test('l')
3711endfunc
3712
3713" Test for a quickfix autocmd changing the quickfix/location list before
3714" jumping to the first error in the new list.
3715func Xautocmd_changelist(cchar)
3716 call s:setup_commands(a:cchar)
3717
3718 " Test for cfile/lfile
3719 call s:create_test_file('Xtestfile1')
3720 call s:create_test_file('Xtestfile2')
3721 Xexpr 'Xtestfile1:2:Line2'
3722 autocmd QuickFixCmdPost * Xolder
3723 call writefile(['Xtestfile2:4:Line4'], 'Xerr')
3724 Xfile Xerr
3725 call assert_equal('Xtestfile2', bufname(''))
3726 call assert_equal(4, line('.'))
3727 autocmd! QuickFixCmdPost
3728
3729 " Test for cbuffer/lbuffer
3730 call g:Xsetlist([], 'f')
3731 Xexpr 'Xtestfile1:2:Line2'
3732 autocmd QuickFixCmdPost * Xolder
3733 call writefile(['Xtestfile2:4:Line4'], 'Xerr')
3734 edit Xerr
3735 Xbuffer
3736 call assert_equal('Xtestfile2', bufname(''))
3737 call assert_equal(4, line('.'))
3738 autocmd! QuickFixCmdPost
3739
3740 " Test for cexpr/lexpr
3741 call g:Xsetlist([], 'f')
3742 Xexpr 'Xtestfile1:2:Line2'
3743 autocmd QuickFixCmdPost * Xolder
3744 Xexpr 'Xtestfile2:4:Line4'
3745 call assert_equal('Xtestfile2', bufname(''))
3746 call assert_equal(4, line('.'))
3747 autocmd! QuickFixCmdPost
3748
Bram Moolenaar851332e2018-07-03 19:16:00 +02003749 " The grepprg may not be set on non-Unix systems
3750 if has('unix')
3751 " Test for grep/lgrep
3752 call g:Xsetlist([], 'f')
3753 Xexpr 'Xtestfile1:2:Line2'
3754 autocmd QuickFixCmdPost * Xolder
3755 silent Xgrep Line5 Xtestfile2
3756 call assert_equal('Xtestfile2', bufname(''))
3757 call assert_equal(5, line('.'))
3758 autocmd! QuickFixCmdPost
3759 endif
Bram Moolenaar531b9a32018-07-03 16:54:23 +02003760
3761 " Test for vimgrep/lvimgrep
3762 call g:Xsetlist([], 'f')
3763 Xexpr 'Xtestfile1:2:Line2'
3764 autocmd QuickFixCmdPost * Xolder
3765 silent Xvimgrep Line5 Xtestfile2
3766 call assert_equal('Xtestfile2', bufname(''))
3767 call assert_equal(5, line('.'))
3768 autocmd! QuickFixCmdPost
3769
Bram Moolenaar3f347e42018-08-09 21:19:20 +02003770 " Test for autocommands clearing the quickfix list before jumping to the
3771 " first error. This should not result in an error
3772 autocmd QuickFixCmdPost * call g:Xsetlist([], 'r')
3773 let v:errmsg = ''
3774 " Test for cfile/lfile
3775 Xfile Xerr
3776 call assert_true(v:errmsg !~# 'E42:')
3777 " Test for cbuffer/lbuffer
3778 edit Xerr
3779 Xbuffer
3780 call assert_true(v:errmsg !~# 'E42:')
3781 " Test for cexpr/lexpr
3782 Xexpr 'Xtestfile2:4:Line4'
3783 call assert_true(v:errmsg !~# 'E42:')
3784 " Test for grep/lgrep
3785 " The grepprg may not be set on non-Unix systems
3786 if has('unix')
3787 silent Xgrep Line5 Xtestfile2
3788 call assert_true(v:errmsg !~# 'E42:')
3789 endif
3790 " Test for vimgrep/lvimgrep
3791 call assert_fails('silent Xvimgrep Line5 Xtestfile2', 'E480:')
3792 autocmd! QuickFixCmdPost
3793
Bram Moolenaar531b9a32018-07-03 16:54:23 +02003794 call delete('Xerr')
3795 call delete('Xtestfile1')
3796 call delete('Xtestfile2')
3797endfunc
3798
3799func Test_autocmd_changelist()
3800 call Xautocmd_changelist('c')
3801 call Xautocmd_changelist('l')
3802endfunc
Bram Moolenaar4cde86c2018-07-08 16:01:08 +02003803
3804" Tests for the ':filter /pat/ clist' command
3805func Test_filter_clist()
3806 cexpr ['Xfile1:10:10:Line 10', 'Xfile2:15:15:Line 15']
3807 call assert_equal([' 2 Xfile2:15 col 15: Line 15'],
3808 \ split(execute('filter /Line 15/ clist'), "\n"))
3809 call assert_equal([' 1 Xfile1:10 col 10: Line 10'],
3810 \ split(execute('filter /Xfile1/ clist'), "\n"))
3811 call assert_equal([], split(execute('filter /abc/ clist'), "\n"))
3812
3813 call setqflist([{'module' : 'abc', 'pattern' : 'pat1'},
3814 \ {'module' : 'pqr', 'pattern' : 'pat2'}], ' ')
3815 call assert_equal([' 2 pqr:pat2: '],
3816 \ split(execute('filter /pqr/ clist'), "\n"))
3817 call assert_equal([' 1 abc:pat1: '],
3818 \ split(execute('filter /pat1/ clist'), "\n"))
3819endfunc
Bram Moolenaar0a08c632018-07-25 22:36:52 +02003820
3821" Tests for the "CTRL-W <CR>" command.
3822func Xview_result_split_tests(cchar)
3823 call s:setup_commands(a:cchar)
3824
3825 " Test that "CTRL-W <CR>" in a qf/ll window fails with empty list.
3826 call g:Xsetlist([])
3827 Xopen
3828 let l:win_count = winnr('$')
3829 call assert_fails('execute "normal! \<C-W>\<CR>"', 'E42')
3830 call assert_equal(l:win_count, winnr('$'))
3831 Xclose
3832endfunc
3833
3834func Test_view_result_split()
3835 call Xview_result_split_tests('c')
3836 call Xview_result_split_tests('l')
3837endfunc
Bram Moolenaar2dfcef42018-08-15 22:29:51 +02003838
3839" Test that :cc sets curswant
3840func Test_curswant()
3841 helpgrep quickfix
3842 normal! llll
3843 1cc
3844 call assert_equal(getcurpos()[4], virtcol('.'))
3845 cclose | helpclose
3846endfunc
Bram Moolenaarb2443732018-11-11 22:50:27 +01003847
3848" Test for opening a file from the quickfix window using CTRL-W <Enter>
3849" doesn't leave an empty buffer around.
3850func Test_splitview()
3851 call s:create_test_file('Xtestfile1')
3852 call s:create_test_file('Xtestfile2')
3853 new | only
3854 let last_bufnr = bufnr('Test_sv_1', 1)
3855 let l = ['Xtestfile1:2:Line2', 'Xtestfile2:4:Line4']
3856 cgetexpr l
3857 copen
3858 let numbufs = len(getbufinfo())
3859 exe "normal \<C-W>\<CR>"
3860 copen
3861 exe "normal j\<C-W>\<CR>"
3862 " Make sure new empty buffers are not created
3863 call assert_equal(numbufs, len(getbufinfo()))
3864 " Creating a new buffer should use the next available buffer number
3865 call assert_equal(last_bufnr + 4, bufnr("Test_sv_2", 1))
3866 bwipe Test_sv_1
3867 bwipe Test_sv_2
3868 new | only
3869
3870 " When split opening files from location list window, make sure that two
3871 " windows doesn't refer to the same location list
3872 lgetexpr l
3873 let locid = getloclist(0, {'id' : 0}).id
3874 lopen
3875 exe "normal \<C-W>\<CR>"
3876 call assert_notequal(locid, getloclist(0, {'id' : 0}).id)
3877 call assert_equal(0, getloclist(0, {'winid' : 0}).winid)
3878 new | only
3879
3880 " When split opening files from a helpgrep location list window, a new help
Bram Moolenaareeb1b9c2019-02-10 22:59:04 +01003881 " window should be opened with a copy of the location list.
Bram Moolenaarb2443732018-11-11 22:50:27 +01003882 lhelpgrep window
3883 let locid = getloclist(0, {'id' : 0}).id
3884 lwindow
3885 exe "normal j\<C-W>\<CR>"
3886 call assert_notequal(locid, getloclist(0, {'id' : 0}).id)
3887 call assert_equal(0, getloclist(0, {'winid' : 0}).winid)
3888 new | only
3889
3890 call delete('Xtestfile1')
3891 call delete('Xtestfile2')
3892endfunc
Bram Moolenaarc45eb772019-01-31 14:27:04 +01003893
3894" Test for parsing entries using visual screen column
3895func Test_viscol()
3896 enew
3897 call writefile(["Col1\tCol2\tCol3"], 'Xfile1')
3898 edit Xfile1
3899
3900 " Use byte offset for column number
3901 set efm&
3902 cexpr "Xfile1:1:5:XX\nXfile1:1:9:YY\nXfile1:1:20:ZZ"
3903 call assert_equal([5, 8], [col('.'), virtcol('.')])
3904 cnext
3905 call assert_equal([9, 12], [col('.'), virtcol('.')])
3906 cnext
3907 call assert_equal([14, 20], [col('.'), virtcol('.')])
3908
3909 " Use screen column offset for column number
3910 set efm=%f:%l:%v:%m
3911 cexpr "Xfile1:1:8:XX\nXfile1:1:12:YY\nXfile1:1:20:ZZ"
3912 call assert_equal([5, 8], [col('.'), virtcol('.')])
3913 cnext
3914 call assert_equal([9, 12], [col('.'), virtcol('.')])
3915 cnext
3916 call assert_equal([14, 20], [col('.'), virtcol('.')])
3917 cexpr "Xfile1:1:6:XX\nXfile1:1:15:YY\nXfile1:1:24:ZZ"
3918 call assert_equal([5, 8], [col('.'), virtcol('.')])
3919 cnext
3920 call assert_equal([10, 16], [col('.'), virtcol('.')])
3921 cnext
3922 call assert_equal([14, 20], [col('.'), virtcol('.')])
3923
3924 enew
3925 call writefile(["Col1\täü\töß\tCol4"], 'Xfile1')
3926
3927 " Use byte offset for column number
3928 set efm&
3929 cexpr "Xfile1:1:8:XX\nXfile1:1:11:YY\nXfile1:1:16:ZZ"
3930 call assert_equal([8, 10], [col('.'), virtcol('.')])
3931 cnext
3932 call assert_equal([11, 17], [col('.'), virtcol('.')])
3933 cnext
3934 call assert_equal([16, 25], [col('.'), virtcol('.')])
3935
3936 " Use screen column offset for column number
3937 set efm=%f:%l:%v:%m
3938 cexpr "Xfile1:1:10:XX\nXfile1:1:17:YY\nXfile1:1:25:ZZ"
3939 call assert_equal([8, 10], [col('.'), virtcol('.')])
3940 cnext
3941 call assert_equal([11, 17], [col('.'), virtcol('.')])
3942 cnext
3943 call assert_equal([16, 25], [col('.'), virtcol('.')])
3944
3945 enew | only
3946 set efm&
3947 call delete('Xfile1')
3948endfunc
Bram Moolenaaree8188f2019-02-05 21:23:04 +01003949
3950" Test for the quickfix window buffer
3951func Xqfbuf_test(cchar)
3952 call s:setup_commands(a:cchar)
3953
3954 " Quickfix buffer should be reused across closing and opening a quickfix
3955 " window
3956 Xexpr "F1:10:Line10"
3957 Xopen
3958 let qfbnum = bufnr('')
3959 Xclose
3960 " Even after the quickfix window is closed, the buffer should be loaded
3961 call assert_true(bufloaded(qfbnum))
Bram Moolenaar647e24b2019-03-17 16:39:46 +01003962 call assert_true(qfbnum, g:Xgetlist({'qfbufnr' : 0}).qfbufnr)
Bram Moolenaaree8188f2019-02-05 21:23:04 +01003963 Xopen
3964 " Buffer should be reused when opening the window again
3965 call assert_equal(qfbnum, bufnr(''))
3966 Xclose
3967
3968 if a:cchar == 'l'
3969 %bwipe
3970 " For a location list, when both the file window and the location list
3971 " window for the list are closed, then the buffer should be freed.
3972 new | only
3973 lexpr "F1:10:Line10"
3974 let wid = win_getid()
3975 lopen
3976 let qfbnum = bufnr('')
3977 call assert_match(qfbnum . ' %a- "\[Location List]"', execute('ls'))
3978 close
3979 " When the location list window is closed, the buffer name should not
3980 " change to 'Quickfix List'
Bram Moolenaar647e24b2019-03-17 16:39:46 +01003981 call assert_match(qfbnum . 'u h- "\[Location List]"', execute('ls!'))
Bram Moolenaaree8188f2019-02-05 21:23:04 +01003982 call assert_true(bufloaded(qfbnum))
3983
Bram Moolenaard82a81c2019-03-02 07:57:18 +01003984 " After deleting a location list buffer using ":bdelete", opening the
3985 " location list window should mark the buffer as a location list buffer.
3986 exe "bdelete " . qfbnum
3987 lopen
3988 call assert_equal("quickfix", &buftype)
3989 call assert_equal(1, getwininfo(win_getid(winnr()))[0].loclist)
3990 call assert_equal(wid, getloclist(0, {'filewinid' : 0}).filewinid)
3991 call assert_false(&swapfile)
3992 lclose
3993
Bram Moolenaareeb1b9c2019-02-10 22:59:04 +01003994 " When the location list is cleared for the window, the buffer should be
3995 " removed
3996 call setloclist(0, [], 'f')
3997 call assert_false(bufexists(qfbnum))
Bram Moolenaar647e24b2019-03-17 16:39:46 +01003998 call assert_equal(0, getloclist(0, {'qfbufnr' : 0}).qfbufnr)
Bram Moolenaareeb1b9c2019-02-10 22:59:04 +01003999
4000 " When the location list is freed with the location list window open, the
4001 " location list buffer should not be lost. It should be reused when the
4002 " location list is again populated.
4003 lexpr "F1:10:Line10"
4004 lopen
4005 let wid = win_getid()
4006 let qfbnum = bufnr('')
4007 wincmd p
4008 call setloclist(0, [], 'f')
4009 lexpr "F1:10:Line10"
4010 lopen
4011 call assert_equal(wid, win_getid())
4012 call assert_equal(qfbnum, bufnr(''))
4013 lclose
4014
4015 " When the window with the location list is closed, the buffer should be
4016 " removed
Bram Moolenaaree8188f2019-02-05 21:23:04 +01004017 new | only
Bram Moolenaareeb1b9c2019-02-10 22:59:04 +01004018 call assert_false(bufexists(qfbnum))
Bram Moolenaaree8188f2019-02-05 21:23:04 +01004019 endif
4020endfunc
4021
4022func Test_qfbuf()
4023 call Xqfbuf_test('c')
4024 call Xqfbuf_test('l')
4025endfunc
Bram Moolenaareeb1b9c2019-02-10 22:59:04 +01004026
4027" If there is an autocmd to use only one window, then opening the location
4028" list window used to crash Vim.
4029func Test_winonly_autocmd()
4030 call s:create_test_file('Xtest1')
4031 " Autocmd to show only one Vim window at a time
4032 autocmd WinEnter * only
4033 new
4034 " Load the location list
4035 lexpr "Xtest1:5:Line5\nXtest1:10:Line10\nXtest1:15:Line15"
4036 let loclistid = getloclist(0, {'id' : 0}).id
4037 " Open the location list window. Only this window will be shown and the file
4038 " window is closed.
4039 lopen
4040 call assert_equal(loclistid, getloclist(0, {'id' : 0}).id)
4041 " Jump to an entry in the location list and make sure that the cursor is
4042 " positioned correctly.
4043 ll 3
4044 call assert_equal(loclistid, getloclist(0, {'id' : 0}).id)
4045 call assert_equal('Xtest1', bufname(''))
4046 call assert_equal(15, line('.'))
4047 " Cleanup
4048 autocmd! WinEnter
4049 new | only
4050 call delete('Xtest1')
4051endfunc
Bram Moolenaar39803d82019-04-07 12:04:51 +02004052
4053" Test to make sure that an empty quickfix buffer is not reused for loading
4054" a normal buffer.
4055func Test_empty_qfbuf()
4056 enew | only
4057 call writefile(["Test"], 'Xfile1')
4058 call setqflist([], 'f')
4059 copen | only
4060 let qfbuf = bufnr('')
4061 edit Xfile1
4062 call assert_notequal(qfbuf, bufnr(''))
4063 enew
4064 call delete('Xfile1')
4065endfunc
Bram Moolenaar3ff33112019-05-03 21:56:35 +02004066
4067" Test for the :cbelow, :cabove, :lbelow and :labove commands.
Bram Moolenaarcf6a55c2019-05-05 15:02:30 +02004068" And for the :cafter, :cbefore, :lafter and :lbefore commands.
Bram Moolenaar3ff33112019-05-03 21:56:35 +02004069func Xtest_below(cchar)
4070 call s:setup_commands(a:cchar)
4071
4072 " No quickfix/location list
4073 call assert_fails('Xbelow', 'E42:')
4074 call assert_fails('Xabove', 'E42:')
Bram Moolenaarcf6a55c2019-05-05 15:02:30 +02004075 call assert_fails('Xbefore', 'E42:')
4076 call assert_fails('Xafter', 'E42:')
Bram Moolenaar3ff33112019-05-03 21:56:35 +02004077
4078 " Empty quickfix/location list
4079 call g:Xsetlist([])
4080 call assert_fails('Xbelow', 'E42:')
4081 call assert_fails('Xabove', 'E42:')
Bram Moolenaarcf6a55c2019-05-05 15:02:30 +02004082 call assert_fails('Xbefore', 'E42:')
4083 call assert_fails('Xafter', 'E42:')
Bram Moolenaar3ff33112019-05-03 21:56:35 +02004084
4085 call s:create_test_file('X1')
4086 call s:create_test_file('X2')
4087 call s:create_test_file('X3')
4088 call s:create_test_file('X4')
4089
4090 " Invalid entries
4091 edit X1
4092 call g:Xsetlist(["E1", "E2"])
4093 call assert_fails('Xbelow', 'E42:')
4094 call assert_fails('Xabove', 'E42:')
4095 call assert_fails('3Xbelow', 'E42:')
4096 call assert_fails('4Xabove', 'E42:')
Bram Moolenaarcf6a55c2019-05-05 15:02:30 +02004097 call assert_fails('Xbefore', 'E42:')
4098 call assert_fails('Xafter', 'E42:')
4099 call assert_fails('3Xbefore', 'E42:')
4100 call assert_fails('4Xafter', 'E42:')
Bram Moolenaar3ff33112019-05-03 21:56:35 +02004101
4102 " Test the commands with various arguments
Bram Moolenaarcf6a55c2019-05-05 15:02:30 +02004103 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 +02004104 edit +7 X2
4105 Xabove
4106 call assert_equal(['X2', 5], [bufname(''), line('.')])
4107 call assert_fails('Xabove', 'E553:')
Bram Moolenaarcf6a55c2019-05-05 15:02:30 +02004108 normal 7G
4109 Xbefore
4110 call assert_equal(['X2', 5, 2], [bufname(''), line('.'), col('.')])
4111 call assert_fails('Xbefore', 'E553:')
4112
Bram Moolenaar3ff33112019-05-03 21:56:35 +02004113 normal 2j
4114 Xbelow
4115 call assert_equal(['X2', 10], [bufname(''), line('.')])
Bram Moolenaarcf6a55c2019-05-05 15:02:30 +02004116 normal 7G
4117 Xafter
4118 call assert_equal(['X2', 10, 3], [bufname(''), line('.'), col('.')])
4119
Bram Moolenaar3ff33112019-05-03 21:56:35 +02004120 " Last error in this file
4121 Xbelow 99
4122 call assert_equal(['X2', 15], [bufname(''), line('.')])
4123 call assert_fails('Xbelow', 'E553:')
Bram Moolenaarcf6a55c2019-05-05 15:02:30 +02004124 normal gg
4125 Xafter 99
4126 call assert_equal(['X2', 15, 4], [bufname(''), line('.'), col('.')])
4127 call assert_fails('Xafter', 'E553:')
4128
Bram Moolenaar3ff33112019-05-03 21:56:35 +02004129 " First error in this file
4130 Xabove 99
4131 call assert_equal(['X2', 5], [bufname(''), line('.')])
4132 call assert_fails('Xabove', 'E553:')
Bram Moolenaarcf6a55c2019-05-05 15:02:30 +02004133 normal G
4134 Xbefore 99
4135 call assert_equal(['X2', 5, 2], [bufname(''), line('.'), col('.')])
4136 call assert_fails('Xbefore', 'E553:')
4137
Bram Moolenaar3ff33112019-05-03 21:56:35 +02004138 normal gg
4139 Xbelow 2
4140 call assert_equal(['X2', 10], [bufname(''), line('.')])
Bram Moolenaarcf6a55c2019-05-05 15:02:30 +02004141 normal gg
4142 Xafter 2
4143 call assert_equal(['X2', 10, 3], [bufname(''), line('.'), col('.')])
4144
Bram Moolenaar3ff33112019-05-03 21:56:35 +02004145 normal G
4146 Xabove 2
4147 call assert_equal(['X2', 10], [bufname(''), line('.')])
Bram Moolenaarcf6a55c2019-05-05 15:02:30 +02004148 normal G
4149 Xbefore 2
4150 call assert_equal(['X2', 10, 3], [bufname(''), line('.'), col('.')])
4151
Bram Moolenaar3ff33112019-05-03 21:56:35 +02004152 edit X4
4153 call assert_fails('Xabove', 'E42:')
4154 call assert_fails('Xbelow', 'E42:')
Bram Moolenaarcf6a55c2019-05-05 15:02:30 +02004155 call assert_fails('Xbefore', 'E42:')
4156 call assert_fails('Xafter', 'E42:')
Bram Moolenaar3ff33112019-05-03 21:56:35 +02004157 if a:cchar == 'l'
4158 " If a buffer has location list entries from some other window but not
4159 " from the current window, then the commands should fail.
4160 edit X1 | split | call setloclist(0, [], 'f')
4161 call assert_fails('Xabove', 'E776:')
4162 call assert_fails('Xbelow', 'E776:')
Bram Moolenaarcf6a55c2019-05-05 15:02:30 +02004163 call assert_fails('Xbefore', 'E776:')
4164 call assert_fails('Xafter', 'E776:')
Bram Moolenaar3ff33112019-05-03 21:56:35 +02004165 close
4166 endif
4167
4168 " Test for lines with multiple quickfix entries
4169 Xexpr ["X1:5:L5", "X2:5:1:L5_1", "X2:5:2:L5_2", "X2:5:3:L5_3",
4170 \ "X2:10:1:L10_1", "X2:10:2:L10_2", "X2:10:3:L10_3",
4171 \ "X2:15:1:L15_1", "X2:15:2:L15_2", "X2:15:3:L15_3", "X3:3:L3"]
4172 edit +1 X2
4173 Xbelow 2
4174 call assert_equal(['X2', 10, 1], [bufname(''), line('.'), col('.')])
Bram Moolenaarcf6a55c2019-05-05 15:02:30 +02004175 normal 1G
4176 Xafter 2
4177 call assert_equal(['X2', 5, 2], [bufname(''), line('.'), col('.')])
4178
Bram Moolenaar3ff33112019-05-03 21:56:35 +02004179 normal gg
4180 Xbelow 99
4181 call assert_equal(['X2', 15, 1], [bufname(''), line('.'), col('.')])
Bram Moolenaarcf6a55c2019-05-05 15:02:30 +02004182 normal gg
4183 Xafter 99
4184 call assert_equal(['X2', 15, 3], [bufname(''), line('.'), col('.')])
4185
Bram Moolenaar3ff33112019-05-03 21:56:35 +02004186 normal G
4187 Xabove 2
4188 call assert_equal(['X2', 10, 1], [bufname(''), line('.'), col('.')])
4189 normal G
Bram Moolenaarcf6a55c2019-05-05 15:02:30 +02004190 Xbefore 2
4191 call assert_equal(['X2', 15, 2], [bufname(''), line('.'), col('.')])
4192
4193 normal G
Bram Moolenaar3ff33112019-05-03 21:56:35 +02004194 Xabove 99
4195 call assert_equal(['X2', 5, 1], [bufname(''), line('.'), col('.')])
Bram Moolenaarcf6a55c2019-05-05 15:02:30 +02004196 normal G
4197 Xbefore 99
4198 call assert_equal(['X2', 5, 1], [bufname(''), line('.'), col('.')])
4199
Bram Moolenaar3ff33112019-05-03 21:56:35 +02004200 normal 10G
4201 Xabove
4202 call assert_equal(['X2', 5, 1], [bufname(''), line('.'), col('.')])
Bram Moolenaarcf6a55c2019-05-05 15:02:30 +02004203 normal 10G$
4204 2Xbefore
4205 call assert_equal(['X2', 10, 2], [bufname(''), line('.'), col('.')])
4206
Bram Moolenaar3ff33112019-05-03 21:56:35 +02004207 normal 10G
4208 Xbelow
4209 call assert_equal(['X2', 15, 1], [bufname(''), line('.'), col('.')])
Bram Moolenaarcf6a55c2019-05-05 15:02:30 +02004210 normal 9G
4211 5Xafter
4212 call assert_equal(['X2', 15, 2], [bufname(''), line('.'), col('.')])
Bram Moolenaar3ff33112019-05-03 21:56:35 +02004213
4214 " Invalid range
4215 if a:cchar == 'c'
Bram Moolenaar25190db2019-05-04 15:05:28 +02004216 call assert_fails('-2cbelow', 'E16:')
Bram Moolenaarcf6a55c2019-05-05 15:02:30 +02004217 call assert_fails('-2cafter', 'E16:')
Bram Moolenaar3ff33112019-05-03 21:56:35 +02004218 else
Bram Moolenaar25190db2019-05-04 15:05:28 +02004219 call assert_fails('-2lbelow', 'E16:')
Bram Moolenaarcf6a55c2019-05-05 15:02:30 +02004220 call assert_fails('-2lafter', 'E16:')
Bram Moolenaar3ff33112019-05-03 21:56:35 +02004221 endif
4222
4223 call delete('X1')
4224 call delete('X2')
4225 call delete('X3')
4226 call delete('X4')
4227endfunc
4228
4229func Test_cbelow()
4230 call Xtest_below('c')
4231 call Xtest_below('l')
4232endfunc
Bram Moolenaar25190db2019-05-04 15:05:28 +02004233
4234func Test_quickfix_count()
4235 let commands = [
4236 \ 'cNext',
4237 \ 'cNfile',
4238 \ 'cabove',
4239 \ 'cbelow',
4240 \ 'cfirst',
4241 \ 'clast',
4242 \ 'cnewer',
4243 \ 'cnext',
4244 \ 'cnfile',
4245 \ 'colder',
4246 \ 'cprevious',
4247 \ 'crewind',
4248 \
4249 \ 'lNext',
4250 \ 'lNfile',
4251 \ 'labove',
4252 \ 'lbelow',
4253 \ 'lfirst',
4254 \ 'llast',
4255 \ 'lnewer',
4256 \ 'lnext',
4257 \ 'lnfile',
4258 \ 'lolder',
4259 \ 'lprevious',
4260 \ 'lrewind',
4261 \ ]
4262 for cmd in commands
4263 call assert_fails('-1' .. cmd, 'E16:')
4264 call assert_fails('.' .. cmd, 'E16:')
4265 call assert_fails('%' .. cmd, 'E16:')
4266 call assert_fails('$' .. cmd, 'E16:')
4267 endfor
4268endfunc