blob: cd7126a9dbadaf95f395daacd5120329cbbd8bf8 [file] [log] [blame]
Bram Moolenaarf3654822016-03-04 22:12:23 +01001" Tests for 'packpath' and :packadd
Bram Moolenaar863c1a92016-03-03 15:47:06 +01002
Bram Moolenaar91715872016-03-03 17:13:03 +01003func SetUp()
Bram Moolenaar3b0d70f2022-08-29 22:31:20 +01004 let s:topdir = getcwd() . '/Xppdir'
Bram Moolenaar91715872016-03-03 17:13:03 +01005 exe 'set packpath=' . s:topdir
6 let s:plugdir = s:topdir . '/pack/mine/opt/mytest'
7endfunc
8
9func TearDown()
10 call delete(s:topdir, 'rf')
11endfunc
12
Bram Moolenaarf3654822016-03-04 22:12:23 +010013func Test_packadd()
Bram Moolenaar99396d42018-09-08 18:21:16 +020014 if !exists('s:plugdir')
15 echomsg 'when running this test manually, call SetUp() first'
16 return
17 endif
18
Bram Moolenaar71fb0c12016-04-02 22:44:16 +020019 call mkdir(s:plugdir . '/plugin/also', 'p')
Bram Moolenaar91715872016-03-03 17:13:03 +010020 call mkdir(s:plugdir . '/ftdetect', 'p')
Bram Moolenaara5702442016-05-24 19:37:29 +020021 call mkdir(s:plugdir . '/after', 'p')
zeertzjq39c9ec12023-04-01 13:52:03 +010022
23 " This used to crash Vim
24 let &rtp = 'nosuchdir,' . s:plugdir . '/after'
25 packadd mytest
26 " plugdir should be inserted before plugdir/after
27 call assert_match('^nosuchdir,' . s:plugdir . ',', &rtp)
28
Bram Moolenaar91715872016-03-03 17:13:03 +010029 set rtp&
30 let rtp = &rtp
Bram Moolenaar863c1a92016-03-03 15:47:06 +010031 filetype on
Bram Moolenaar863c1a92016-03-03 15:47:06 +010032
Bram Moolenaar99396d42018-09-08 18:21:16 +020033 let rtp_entries = split(rtp, ',')
34 for entry in rtp_entries
zeertzjqb0d45ec2023-01-25 15:04:22 +000035 if entry =~? '\<after\>'
Bram Moolenaar99396d42018-09-08 18:21:16 +020036 let first_after_entry = entry
37 break
38 endif
39 endfor
40
Bram Moolenaar91715872016-03-03 17:13:03 +010041 exe 'split ' . s:plugdir . '/plugin/test.vim'
42 call setline(1, 'let g:plugin_works = 42')
43 wq
Bram Moolenaar863c1a92016-03-03 15:47:06 +010044
Bram Moolenaar71fb0c12016-04-02 22:44:16 +020045 exe 'split ' . s:plugdir . '/plugin/also/loaded.vim'
46 call setline(1, 'let g:plugin_also_works = 77')
47 wq
48
Bram Moolenaar91715872016-03-03 17:13:03 +010049 exe 'split ' . s:plugdir . '/ftdetect/test.vim'
50 call setline(1, 'let g:ftdetect_works = 17')
51 wq
52
Bram Moolenaarf3654822016-03-04 22:12:23 +010053 packadd mytest
Bram Moolenaar91715872016-03-03 17:13:03 +010054
55 call assert_equal(42, g:plugin_works)
Bram Moolenaar71fb0c12016-04-02 22:44:16 +020056 call assert_equal(77, g:plugin_also_works)
Bram Moolenaar91715872016-03-03 17:13:03 +010057 call assert_equal(17, g:ftdetect_works)
58 call assert_true(len(&rtp) > len(rtp))
Bram Moolenaar3b0d70f2022-08-29 22:31:20 +010059 call assert_match('/testdir/Xppdir/pack/mine/opt/mytest\($\|,\)', &rtp)
Bram Moolenaar99396d42018-09-08 18:21:16 +020060
Bram Moolenaar3b0d70f2022-08-29 22:31:20 +010061 let new_after = match(&rtp, '/testdir/Xppdir/pack/mine/opt/mytest/after,')
Bram Moolenaar53c8a472018-09-08 19:12:12 +020062 let forwarded = substitute(first_after_entry, '\\', '[/\\\\]', 'g')
63 let old_after = match(&rtp, ',' . forwarded . '\>')
Bram Moolenaar99396d42018-09-08 18:21:16 +020064 call assert_true(new_after > 0, 'rtp is ' . &rtp)
Bram Moolenaar53c8a472018-09-08 19:12:12 +020065 call assert_true(old_after > 0, 'match ' . forwarded . ' in ' . &rtp)
Bram Moolenaar99396d42018-09-08 18:21:16 +020066 call assert_true(new_after < old_after, 'rtp is ' . &rtp)
Bram Moolenaarbe82c252016-03-06 14:44:08 +010067
Bram Moolenaarf98a39c2018-04-18 22:18:23 +020068 " NOTE: '/.../opt/myte' forwardly matches with '/.../opt/mytest'
69 call mkdir(fnamemodify(s:plugdir, ':h') . '/myte', 'p')
70 let rtp = &rtp
71 packadd myte
72
73 " Check the path of 'myte' is added
74 call assert_true(len(&rtp) > len(rtp))
Bram Moolenaar3b0d70f2022-08-29 22:31:20 +010075 call assert_match('/testdir/Xppdir/pack/mine/opt/myte\($\|,\)', &rtp)
Bram Moolenaarf98a39c2018-04-18 22:18:23 +020076
Bram Moolenaarbe82c252016-03-06 14:44:08 +010077 " Check exception
78 call assert_fails("packadd directorynotfound", 'E919:')
79 call assert_fails("packadd", 'E471:')
Bram Moolenaar91715872016-03-03 17:13:03 +010080endfunc
81
Bram Moolenaar9e1d3992017-12-17 14:26:46 +010082func Test_packadd_start()
83 let plugdir = s:topdir . '/pack/mine/start/other'
84 call mkdir(plugdir . '/plugin', 'p')
85 set rtp&
86 let rtp = &rtp
87 filetype on
88
89 exe 'split ' . plugdir . '/plugin/test.vim'
90 call setline(1, 'let g:plugin_works = 24')
91 wq
92
93 packadd other
94
95 call assert_equal(24, g:plugin_works)
96 call assert_true(len(&rtp) > len(rtp))
Bram Moolenaar3b0d70f2022-08-29 22:31:20 +010097 call assert_match('/testdir/Xppdir/pack/mine/start/other\($\|,\)', &rtp)
Bram Moolenaar9e1d3992017-12-17 14:26:46 +010098endfunc
99
Bram Moolenaarf3654822016-03-04 22:12:23 +0100100func Test_packadd_noload()
101 call mkdir(s:plugdir . '/plugin', 'p')
Bram Moolenaar91715872016-03-03 17:13:03 +0100102 call mkdir(s:plugdir . '/syntax', 'p')
103 set rtp&
104 let rtp = &rtp
Bram Moolenaarf3654822016-03-04 22:12:23 +0100105
106 exe 'split ' . s:plugdir . '/plugin/test.vim'
107 call setline(1, 'let g:plugin_works = 42')
108 wq
109 let g:plugin_works = 0
110
111 packadd! mytest
112
Bram Moolenaar91715872016-03-03 17:13:03 +0100113 call assert_true(len(&rtp) > len(rtp))
Bram Moolenaar3b0d70f2022-08-29 22:31:20 +0100114 call assert_match('testdir/Xppdir/pack/mine/opt/mytest\($\|,\)', &rtp)
Bram Moolenaarf3654822016-03-04 22:12:23 +0100115 call assert_equal(0, g:plugin_works)
Bram Moolenaar91715872016-03-03 17:13:03 +0100116
117 " check the path is not added twice
118 let new_rtp = &rtp
Bram Moolenaarf3654822016-03-04 22:12:23 +0100119 packadd! mytest
Bram Moolenaar91715872016-03-03 17:13:03 +0100120 call assert_equal(new_rtp, &rtp)
Bram Moolenaar863c1a92016-03-03 15:47:06 +0100121endfunc
Bram Moolenaar35ca0e72016-03-05 17:41:49 +0100122
Bram Moolenaar2f9e5752017-02-05 16:07:54 +0100123func Test_packadd_symlink_dir()
Bram Moolenaar6d91bcb2020-08-12 18:50:36 +0200124 CheckUnix
Bram Moolenaar2f9e5752017-02-05 16:07:54 +0100125 let top2_dir = s:topdir . '/Xdir2'
126 let real_dir = s:topdir . '/Xsym'
Bram Moolenaar644df412017-03-09 13:58:02 +0100127 call mkdir(real_dir, 'p')
128 exec "silent !ln -s Xsym" top2_dir
Bram Moolenaar2f9e5752017-02-05 16:07:54 +0100129 let &rtp = top2_dir . ',' . top2_dir . '/after'
130 let &packpath = &rtp
131
132 let s:plugdir = top2_dir . '/pack/mine/opt/mytest'
133 call mkdir(s:plugdir . '/plugin', 'p')
134
135 exe 'split ' . s:plugdir . '/plugin/test.vim'
136 call setline(1, 'let g:plugin_works = 44')
137 wq
138 let g:plugin_works = 0
139
140 packadd mytest
141
142 " Must have been inserted in the middle, not at the end
Bram Moolenaar2374faa2018-02-04 17:47:42 +0100143 call assert_match('/pack/mine/opt/mytest,', &rtp)
Bram Moolenaar2f9e5752017-02-05 16:07:54 +0100144 call assert_equal(44, g:plugin_works)
145
146 " No change when doing it again.
147 let rtp_before = &rtp
148 packadd mytest
149 call assert_equal(rtp_before, &rtp)
150
151 set rtp&
152 let rtp = &rtp
Bram Moolenaar24f8f542017-02-11 23:00:36 +0100153 exec "silent !rm" top2_dir
Bram Moolenaar2f9e5752017-02-05 16:07:54 +0100154endfunc
155
Bram Moolenaar2374faa2018-02-04 17:47:42 +0100156func Test_packadd_symlink_dir2()
Bram Moolenaar6d91bcb2020-08-12 18:50:36 +0200157 CheckUnix
Bram Moolenaar2374faa2018-02-04 17:47:42 +0100158 let top2_dir = s:topdir . '/Xdir2'
159 let real_dir = s:topdir . '/Xsym/pack'
160 call mkdir(top2_dir, 'p')
161 call mkdir(real_dir, 'p')
162 let &rtp = top2_dir . ',' . top2_dir . '/after'
163 let &packpath = &rtp
164
165 exec "silent !ln -s ../Xsym/pack" top2_dir . '/pack'
166 let s:plugdir = top2_dir . '/pack/mine/opt/mytest'
167 call mkdir(s:plugdir . '/plugin', 'p')
168
169 exe 'split ' . s:plugdir . '/plugin/test.vim'
170 call setline(1, 'let g:plugin_works = 48')
171 wq
172 let g:plugin_works = 0
173
174 packadd mytest
175
176 " Must have been inserted in the middle, not at the end
177 call assert_match('/Xdir2/pack/mine/opt/mytest,', &rtp)
178 call assert_equal(48, g:plugin_works)
179
180 " No change when doing it again.
181 let rtp_before = &rtp
182 packadd mytest
183 call assert_equal(rtp_before, &rtp)
184
185 set rtp&
186 let rtp = &rtp
187 exec "silent !rm" top2_dir . '/pack'
188 exec "silent !rmdir" top2_dir
189endfunc
190
zeertzjqb0d45ec2023-01-25 15:04:22 +0000191" Check command-line completion for :packadd
Bram Moolenaar35ca0e72016-03-05 17:41:49 +0100192func Test_packadd_completion()
193 let optdir1 = &packpath . '/pack/mine/opt'
194 let optdir2 = &packpath . '/pack/candidate/opt'
195
196 call mkdir(optdir1 . '/pluginA', 'p')
197 call mkdir(optdir1 . '/pluginC', 'p')
zeertzjq3770f4c2023-01-22 18:38:51 +0000198 call writefile([], optdir1 . '/unrelated')
Bram Moolenaar35ca0e72016-03-05 17:41:49 +0100199 call mkdir(optdir2 . '/pluginB', 'p')
200 call mkdir(optdir2 . '/pluginC', 'p')
zeertzjq3770f4c2023-01-22 18:38:51 +0000201 call writefile([], optdir2 . '/unrelated')
Bram Moolenaar35ca0e72016-03-05 17:41:49 +0100202
203 let li = []
204 call feedkeys(":packadd \<Tab>')\<C-B>call add(li, '\<CR>", 't')
205 call feedkeys(":packadd " . repeat("\<Tab>", 2) . "')\<C-B>call add(li, '\<CR>", 't')
206 call feedkeys(":packadd " . repeat("\<Tab>", 3) . "')\<C-B>call add(li, '\<CR>", 't')
207 call feedkeys(":packadd " . repeat("\<Tab>", 4) . "')\<C-B>call add(li, '\<CR>", 'tx')
208 call assert_equal("packadd pluginA", li[0])
209 call assert_equal("packadd pluginB", li[1])
210 call assert_equal("packadd pluginC", li[2])
211 call assert_equal("packadd ", li[3])
212endfunc
Bram Moolenaar2d8f56a2016-03-12 20:34:27 +0100213
214func Test_packloadall()
Bram Moolenaar49b27322016-04-05 21:13:00 +0200215 " plugin foo with an autoload directory
216 let fooplugindir = &packpath . '/pack/mine/start/foo/plugin'
217 call mkdir(fooplugindir, 'p')
218 call writefile(['let g:plugin_foo_number = 1234',
219 \ 'let g:plugin_foo_auto = bbb#value',
220 \ 'let g:plugin_extra_auto = extra#value'], fooplugindir . '/bar.vim')
221 let fooautodir = &packpath . '/pack/mine/start/foo/autoload'
222 call mkdir(fooautodir, 'p')
223 call writefile(['let bar#value = 77'], fooautodir . '/bar.vim')
224
225 " plugin aaa with an autoload directory
226 let aaaplugindir = &packpath . '/pack/mine/start/aaa/plugin'
227 call mkdir(aaaplugindir, 'p')
228 call writefile(['let g:plugin_aaa_number = 333',
229 \ 'let g:plugin_aaa_auto = bar#value'], aaaplugindir . '/bbb.vim')
230 let aaaautodir = &packpath . '/pack/mine/start/aaa/autoload'
231 call mkdir(aaaautodir, 'p')
232 call writefile(['let bbb#value = 55'], aaaautodir . '/bbb.vim')
233
234 " plugin extra with only an autoload directory
235 let extraautodir = &packpath . '/pack/mine/start/extra/autoload'
236 call mkdir(extraautodir, 'p')
237 call writefile(['let extra#value = 99'], extraautodir . '/extra.vim')
238
Bram Moolenaar2d8f56a2016-03-12 20:34:27 +0100239 packloadall
240 call assert_equal(1234, g:plugin_foo_number)
Bram Moolenaar49b27322016-04-05 21:13:00 +0200241 call assert_equal(55, g:plugin_foo_auto)
242 call assert_equal(99, g:plugin_extra_auto)
243 call assert_equal(333, g:plugin_aaa_number)
244 call assert_equal(77, g:plugin_aaa_auto)
Bram Moolenaar2d8f56a2016-03-12 20:34:27 +0100245
246 " only works once
Bram Moolenaar49b27322016-04-05 21:13:00 +0200247 call writefile(['let g:plugin_bar_number = 4321'], fooplugindir . '/bar2.vim')
Bram Moolenaar2d8f56a2016-03-12 20:34:27 +0100248 packloadall
249 call assert_false(exists('g:plugin_bar_number'))
250
251 " works when ! used
252 packloadall!
253 call assert_equal(4321, g:plugin_bar_number)
254endfunc
Bram Moolenaar6bef5302016-03-12 21:28:26 +0100255
=?UTF-8?q?Bj=C3=B6rn=20Linse?=223a9502022-01-31 17:26:05 +0000256func Test_start_autoload()
257 " plugin foo with an autoload directory
258 let autodir = &packpath .. '/pack/mine/start/foo/autoload'
259 call mkdir(autodir, 'p')
260 let fname = autodir .. '/foobar.vim'
261 call writefile(['func foobar#test()',
262 \ ' return 1666',
263 \ 'endfunc'], fname)
264
265 call assert_equal(1666, foobar#test())
=?UTF-8?q?Bj=C3=B6rn=20Linse?=223a9502022-01-31 17:26:05 +0000266endfunc
267
Bram Moolenaar6bef5302016-03-12 21:28:26 +0100268func Test_helptags()
269 let docdir1 = &packpath . '/pack/mine/start/foo/doc'
270 let docdir2 = &packpath . '/pack/mine/start/bar/doc'
271 call mkdir(docdir1, 'p')
272 call mkdir(docdir2, 'p')
273 call writefile(['look here: *look-here*'], docdir1 . '/bar.txt')
274 call writefile(['look away: *look-away*'], docdir2 . '/foo.txt')
275 exe 'set rtp=' . &packpath . '/pack/mine/start/foo,' . &packpath . '/pack/mine/start/bar'
276
277 helptags ALL
278
zeertzjqb0d45ec2023-01-25 15:04:22 +0000279 let tags1 = readfile(docdir1 . '/tags')
Bram Moolenaar2374faa2018-02-04 17:47:42 +0100280 call assert_match('look-here', tags1[0])
zeertzjqb0d45ec2023-01-25 15:04:22 +0000281 let tags2 = readfile(docdir2 . '/tags')
Bram Moolenaar2374faa2018-02-04 17:47:42 +0100282 call assert_match('look-away', tags2[0])
Bram Moolenaar5d98dc22020-01-29 21:57:34 +0100283
284 call assert_fails('helptags abcxyz', 'E150:')
Bram Moolenaar6bef5302016-03-12 21:28:26 +0100285endfunc
Bram Moolenaar7f8989d2016-03-12 22:11:39 +0100286
287func Test_colorscheme()
288 let colordirrun = &packpath . '/runtime/colors'
289 let colordirstart = &packpath . '/pack/mine/start/foo/colors'
290 let colordiropt = &packpath . '/pack/mine/opt/bar/colors'
291 call mkdir(colordirrun, 'p')
292 call mkdir(colordirstart, 'p')
293 call mkdir(colordiropt, 'p')
294 call writefile(['let g:found_one = 1'], colordirrun . '/one.vim')
295 call writefile(['let g:found_two = 1'], colordirstart . '/two.vim')
296 call writefile(['let g:found_three = 1'], colordiropt . '/three.vim')
297 exe 'set rtp=' . &packpath . '/runtime'
298
299 colorscheme one
300 call assert_equal(1, g:found_one)
301 colorscheme two
302 call assert_equal(1, g:found_two)
303 colorscheme three
304 call assert_equal(1, g:found_three)
305endfunc
Bram Moolenaar8dcf2592016-03-12 22:47:14 +0100306
Bram Moolenaar52f9c192016-03-13 13:24:45 +0100307func Test_colorscheme_completion()
308 let colordirrun = &packpath . '/runtime/colors'
309 let colordirstart = &packpath . '/pack/mine/start/foo/colors'
310 let colordiropt = &packpath . '/pack/mine/opt/bar/colors'
311 call mkdir(colordirrun, 'p')
312 call mkdir(colordirstart, 'p')
313 call mkdir(colordiropt, 'p')
314 call writefile(['let g:found_one = 1'], colordirrun . '/one.vim')
315 call writefile(['let g:found_two = 1'], colordirstart . '/two.vim')
316 call writefile(['let g:found_three = 1'], colordiropt . '/three.vim')
317 exe 'set rtp=' . &packpath . '/runtime'
318
319 let li=[]
320 call feedkeys(":colorscheme " . repeat("\<Tab>", 1) . "')\<C-B>call add(li, '\<CR>", 't')
321 call feedkeys(":colorscheme " . repeat("\<Tab>", 2) . "')\<C-B>call add(li, '\<CR>", 't')
322 call feedkeys(":colorscheme " . repeat("\<Tab>", 3) . "')\<C-B>call add(li, '\<CR>", 't')
323 call feedkeys(":colorscheme " . repeat("\<Tab>", 4) . "')\<C-B>call add(li, '\<CR>", 'tx')
324 call assert_equal("colorscheme one", li[0])
325 call assert_equal("colorscheme three", li[1])
326 call assert_equal("colorscheme two", li[2])
327 call assert_equal("colorscheme ", li[3])
328endfunc
329
Bram Moolenaar8dcf2592016-03-12 22:47:14 +0100330func Test_runtime()
331 let rundir = &packpath . '/runtime/extra'
332 let startdir = &packpath . '/pack/mine/start/foo/extra'
333 let optdir = &packpath . '/pack/mine/opt/bar/extra'
334 call mkdir(rundir, 'p')
335 call mkdir(startdir, 'p')
336 call mkdir(optdir, 'p')
337 call writefile(['let g:sequence .= "run"'], rundir . '/bar.vim')
338 call writefile(['let g:sequence .= "start"'], startdir . '/bar.vim')
339 call writefile(['let g:sequence .= "foostart"'], startdir . '/foo.vim')
340 call writefile(['let g:sequence .= "opt"'], optdir . '/bar.vim')
341 call writefile(['let g:sequence .= "xxxopt"'], optdir . '/xxx.vim')
342 exe 'set rtp=' . &packpath . '/runtime'
343
344 let g:sequence = ''
345 runtime extra/bar.vim
346 call assert_equal('run', g:sequence)
347 let g:sequence = ''
zeertzjq008c9152023-08-17 23:08:53 +0200348 runtime NoSuchFile extra/bar.vim
349 call assert_equal('run', g:sequence)
350
351 let g:sequence = ''
Bram Moolenaar8dcf2592016-03-12 22:47:14 +0100352 runtime START extra/bar.vim
353 call assert_equal('start', g:sequence)
354 let g:sequence = ''
zeertzjq008c9152023-08-17 23:08:53 +0200355 runtime START NoSuchFile extra/bar.vim extra/foo.vim
356 call assert_equal('start', g:sequence)
357 let g:sequence = ''
358 runtime START NoSuchFile extra/foo.vim extra/bar.vim
359 call assert_equal('foostart', g:sequence)
360 let g:sequence = ''
361 runtime! START NoSuchFile extra/bar.vim extra/foo.vim
362 call assert_equal('startfoostart', g:sequence)
363
364 let g:sequence = ''
Bram Moolenaar8dcf2592016-03-12 22:47:14 +0100365 runtime OPT extra/bar.vim
366 call assert_equal('opt', g:sequence)
367 let g:sequence = ''
zeertzjq008c9152023-08-17 23:08:53 +0200368 runtime OPT NoSuchFile extra/bar.vim extra/xxx.vim
369 call assert_equal('opt', g:sequence)
370 let g:sequence = ''
371 runtime OPT NoSuchFile extra/xxx.vim extra/bar.vim
372 call assert_equal('xxxopt', g:sequence)
373 let g:sequence = ''
374 runtime! OPT NoSuchFile extra/bar.vim extra/xxx.vim
375 call assert_equal('optxxxopt', g:sequence)
376
377 let g:sequence = ''
Bram Moolenaar8dcf2592016-03-12 22:47:14 +0100378 runtime PACK extra/bar.vim
379 call assert_equal('start', g:sequence)
380 let g:sequence = ''
381 runtime! PACK extra/bar.vim
382 call assert_equal('startopt', g:sequence)
383 let g:sequence = ''
384 runtime PACK extra/xxx.vim
385 call assert_equal('xxxopt', g:sequence)
zeertzjq008c9152023-08-17 23:08:53 +0200386 let g:sequence = ''
387 runtime PACK extra/xxx.vim extra/foo.vim extra/bar.vim
388 call assert_equal('foostart', g:sequence)
389 let g:sequence = ''
390 runtime! PACK extra/bar.vim extra/xxx.vim extra/foo.vim
391 call assert_equal('startfoostartoptxxxopt', g:sequence)
Bram Moolenaar8dcf2592016-03-12 22:47:14 +0100392
393 let g:sequence = ''
394 runtime ALL extra/bar.vim
395 call assert_equal('run', g:sequence)
396 let g:sequence = ''
397 runtime ALL extra/foo.vim
398 call assert_equal('foostart', g:sequence)
399 let g:sequence = ''
400 runtime! ALL extra/xxx.vim
401 call assert_equal('xxxopt', g:sequence)
402 let g:sequence = ''
403 runtime! ALL extra/bar.vim
404 call assert_equal('runstartopt', g:sequence)
zeertzjq008c9152023-08-17 23:08:53 +0200405 let g:sequence = ''
406 runtime ALL extra/xxx.vim extra/foo.vim extra/bar.vim
407 call assert_equal('run', g:sequence)
408 let g:sequence = ''
409 runtime! ALL extra/bar.vim extra/xxx.vim extra/foo.vim
410 call assert_equal('runstartfoostartoptxxxopt', g:sequence)
Bram Moolenaar8dcf2592016-03-12 22:47:14 +0100411endfunc
Bram Moolenaar5d98dc22020-01-29 21:57:34 +0100412
zeertzjq3770f4c2023-01-22 18:38:51 +0000413func Test_runtime_completion()
zeertzjq5c8771b2023-01-24 12:34:03 +0000414 let rundir = &packpath . '/runtime/Aextra'
415 let startdir = &packpath . '/pack/mine/start/foo/Aextra'
416 let optdir = &packpath . '/pack/mine/opt/bar/Aextra'
417 call mkdir(rundir . '/Arunbaz', 'p')
418 call mkdir(startdir . '/Astartbaz', 'p')
419 call mkdir(optdir . '/Aoptbaz', 'p')
420 call writefile([], rundir . '/../Arunfoo.vim')
421 call writefile([], rundir . '/Arunbar.vim')
422 call writefile([], rundir . '/Aunrelated')
423 call writefile([], rundir . '/../Aunrelated')
424 call writefile([], startdir . '/../Astartfoo.vim')
425 call writefile([], startdir . '/Astartbar.vim')
426 call writefile([], startdir . '/Aunrelated')
427 call writefile([], startdir . '/../Aunrelated')
428 call writefile([], optdir . '/../Aoptfoo.vim')
429 call writefile([], optdir . '/Aoptbar.vim')
430 call writefile([], optdir . '/Aunrelated')
431 call writefile([], optdir . '/../Aunrelated')
zeertzjq3770f4c2023-01-22 18:38:51 +0000432 exe 'set rtp=' . &packpath . '/runtime'
433
zeertzjqbe5cdd12023-08-17 23:48:58 +0200434 func Check_runtime_completion(arg, arg_prev, res)
zeertzjq3770f4c2023-01-22 18:38:51 +0000435 call feedkeys(':runtime ' .. a:arg .. "\<C-A>\<C-B>\"\<CR>", 'xt')
zeertzjqbe5cdd12023-08-17 23:48:58 +0200436 call assert_equal('"runtime ' .. a:arg_prev .. join(a:res), @:)
zeertzjq3770f4c2023-01-22 18:38:51 +0000437 call assert_equal(a:res, getcompletion(a:arg, 'runtime'))
zeertzjq3770f4c2023-01-22 18:38:51 +0000438 endfunc
439
440 call Check_runtime_completion('', '',
zeertzjq5c8771b2023-01-24 12:34:03 +0000441 \ ['Aextra/', 'Arunfoo.vim', 'START', 'OPT', 'PACK', 'ALL'])
442 call Check_runtime_completion('S', '',
443 \ ['START'])
444 call Check_runtime_completion('O', '',
445 \ ['OPT'])
446 call Check_runtime_completion('P', '',
447 \ ['PACK'])
448 call Check_runtime_completion('A', '',
449 \ ['Aextra/', 'Arunfoo.vim', 'ALL'])
zeertzjqbe5cdd12023-08-17 23:48:58 +0200450 call Check_runtime_completion('Other.vim ', 'Other.vim ',
451 \ ['Aextra/', 'Arunfoo.vim'])
zeertzjq5c8771b2023-01-24 12:34:03 +0000452 call Check_runtime_completion('Aextra/', '',
453 \ ['Aextra/Arunbar.vim', 'Aextra/Arunbaz/'])
zeertzjqbe5cdd12023-08-17 23:48:58 +0200454 call Check_runtime_completion('Other.vim Aextra/', 'Other.vim ',
455 \ ['Aextra/Arunbar.vim', 'Aextra/Arunbaz/'])
zeertzjq3770f4c2023-01-22 18:38:51 +0000456
457 call Check_runtime_completion('START ', 'START ',
zeertzjq5c8771b2023-01-24 12:34:03 +0000458 \ ['Aextra/', 'Astartfoo.vim'])
zeertzjqbe5cdd12023-08-17 23:48:58 +0200459 call Check_runtime_completion('START Other.vim ', 'START Other.vim ',
460 \ ['Aextra/', 'Astartfoo.vim'])
zeertzjq5c8771b2023-01-24 12:34:03 +0000461 call Check_runtime_completion('START A', 'START ',
462 \ ['Aextra/', 'Astartfoo.vim'])
zeertzjqbe5cdd12023-08-17 23:48:58 +0200463 call Check_runtime_completion('START Other.vim A', 'START Other.vim ',
464 \ ['Aextra/', 'Astartfoo.vim'])
zeertzjq5c8771b2023-01-24 12:34:03 +0000465 call Check_runtime_completion('START Aextra/', 'START ',
466 \ ['Aextra/Astartbar.vim', 'Aextra/Astartbaz/'])
zeertzjqbe5cdd12023-08-17 23:48:58 +0200467 call Check_runtime_completion('START Other.vim Aextra/', 'START Other.vim ',
468 \ ['Aextra/Astartbar.vim', 'Aextra/Astartbaz/'])
zeertzjq3770f4c2023-01-22 18:38:51 +0000469
470 call Check_runtime_completion('OPT ', 'OPT ',
zeertzjq5c8771b2023-01-24 12:34:03 +0000471 \ ['Aextra/', 'Aoptfoo.vim'])
zeertzjqbe5cdd12023-08-17 23:48:58 +0200472 call Check_runtime_completion('OPT Other.vim ', 'OPT Other.vim ',
473 \ ['Aextra/', 'Aoptfoo.vim'])
zeertzjq5c8771b2023-01-24 12:34:03 +0000474 call Check_runtime_completion('OPT A', 'OPT ',
475 \ ['Aextra/', 'Aoptfoo.vim'])
zeertzjqbe5cdd12023-08-17 23:48:58 +0200476 call Check_runtime_completion('OPT Other.vim A', 'OPT Other.vim ',
477 \ ['Aextra/', 'Aoptfoo.vim'])
zeertzjq5c8771b2023-01-24 12:34:03 +0000478 call Check_runtime_completion('OPT Aextra/', 'OPT ',
479 \ ['Aextra/Aoptbar.vim', 'Aextra/Aoptbaz/'])
zeertzjqbe5cdd12023-08-17 23:48:58 +0200480 call Check_runtime_completion('OPT Other.vim Aextra/', 'OPT Other.vim ',
481 \ ['Aextra/Aoptbar.vim', 'Aextra/Aoptbaz/'])
zeertzjq3770f4c2023-01-22 18:38:51 +0000482
483 call Check_runtime_completion('PACK ', 'PACK ',
zeertzjq5c8771b2023-01-24 12:34:03 +0000484 \ ['Aextra/', 'Aoptfoo.vim', 'Astartfoo.vim'])
zeertzjqbe5cdd12023-08-17 23:48:58 +0200485 call Check_runtime_completion('PACK Other.vim ', 'PACK Other.vim ',
486 \ ['Aextra/', 'Aoptfoo.vim', 'Astartfoo.vim'])
zeertzjq5c8771b2023-01-24 12:34:03 +0000487 call Check_runtime_completion('PACK A', 'PACK ',
488 \ ['Aextra/', 'Aoptfoo.vim', 'Astartfoo.vim'])
zeertzjqbe5cdd12023-08-17 23:48:58 +0200489 call Check_runtime_completion('PACK Other.vim A', 'PACK Other.vim ',
490 \ ['Aextra/', 'Aoptfoo.vim', 'Astartfoo.vim'])
zeertzjq5c8771b2023-01-24 12:34:03 +0000491 call Check_runtime_completion('PACK Aextra/', 'PACK ',
492 \ ['Aextra/Aoptbar.vim', 'Aextra/Aoptbaz/',
493 \ 'Aextra/Astartbar.vim', 'Aextra/Astartbaz/'])
zeertzjqbe5cdd12023-08-17 23:48:58 +0200494 call Check_runtime_completion('PACK Other.vim Aextra/', 'PACK Other.vim ',
495 \ ['Aextra/Aoptbar.vim', 'Aextra/Aoptbaz/',
496 \ 'Aextra/Astartbar.vim', 'Aextra/Astartbaz/'])
zeertzjq3770f4c2023-01-22 18:38:51 +0000497
498 call Check_runtime_completion('ALL ', 'ALL ',
zeertzjq5c8771b2023-01-24 12:34:03 +0000499 \ ['Aextra/', 'Aoptfoo.vim', 'Arunfoo.vim', 'Astartfoo.vim'])
zeertzjqbe5cdd12023-08-17 23:48:58 +0200500 call Check_runtime_completion('ALL Other.vim ', 'ALL Other.vim ',
501 \ ['Aextra/', 'Aoptfoo.vim', 'Arunfoo.vim', 'Astartfoo.vim'])
zeertzjq5c8771b2023-01-24 12:34:03 +0000502 call Check_runtime_completion('ALL A', 'ALL ',
503 \ ['Aextra/', 'Aoptfoo.vim', 'Arunfoo.vim', 'Astartfoo.vim'])
zeertzjqbe5cdd12023-08-17 23:48:58 +0200504 call Check_runtime_completion('ALL Other.vim A', 'ALL Other.vim ',
505 \ ['Aextra/', 'Aoptfoo.vim', 'Arunfoo.vim', 'Astartfoo.vim'])
zeertzjq5c8771b2023-01-24 12:34:03 +0000506 call Check_runtime_completion('ALL Aextra/', 'ALL ',
507 \ ['Aextra/Aoptbar.vim', 'Aextra/Aoptbaz/',
508 \ 'Aextra/Arunbar.vim', 'Aextra/Arunbaz/',
509 \ 'Aextra/Astartbar.vim', 'Aextra/Astartbaz/'])
zeertzjqbe5cdd12023-08-17 23:48:58 +0200510 call Check_runtime_completion('ALL Other.vim Aextra/', 'ALL Other.vim ',
511 \ ['Aextra/Aoptbar.vim', 'Aextra/Aoptbaz/',
512 \ 'Aextra/Arunbar.vim', 'Aextra/Arunbaz/',
513 \ 'Aextra/Astartbar.vim', 'Aextra/Astartbaz/'])
zeertzjq3770f4c2023-01-22 18:38:51 +0000514
515 delfunc Check_runtime_completion
516endfunc
517
Bram Moolenaar5d98dc22020-01-29 21:57:34 +0100518" vim: shiftwidth=2 sts=2 expandtab