blob: 3a1066bf313b26ae308c7d7c401f9591da9bf806 [file] [log] [blame]
Bram Moolenaared71ed32019-01-30 22:13:35 +01001" Test findfile() and finddir()
2
Yegappan Lakshmananaeb1c972024-10-22 23:42:20 +02003source check.vim
4
Bram Moolenaar3b0d70f2022-08-29 22:31:20 +01005let s:files = [ 'Xfinddir1/foo',
6 \ 'Xfinddir1/bar',
7 \ 'Xfinddir1/Xdir2/foo',
8 \ 'Xfinddir1/Xdir2/foobar',
9 \ 'Xfinddir1/Xdir2/Xdir3/bar',
10 \ 'Xfinddir1/Xdir2/Xdir3/barfoo' ]
Bram Moolenaared71ed32019-01-30 22:13:35 +010011
12func CreateFiles()
Bram Moolenaar3b0d70f2022-08-29 22:31:20 +010013 call mkdir('Xfinddir1/Xdir2/Xdir3/Xdir2', 'p')
Bram Moolenaared71ed32019-01-30 22:13:35 +010014 for f in s:files
15 call writefile([], f)
16 endfor
17endfunc
18
19func CleanFiles()
20 " Safer to delete each file even if it's more verbose
Bram Moolenaar3b0d70f2022-08-29 22:31:20 +010021 " than doing a recursive delete('Xfinddir1', 'rf').
Bram Moolenaared71ed32019-01-30 22:13:35 +010022 for f in s:files
23 call delete(f)
24 endfor
25
Bram Moolenaar3b0d70f2022-08-29 22:31:20 +010026 call delete('Xfinddir1/Xdir2/Xdir3/Xdir2', 'd')
27 call delete('Xfinddir1/Xdir2/Xdir3', 'd')
28 call delete('Xfinddir1/Xdir2', 'd')
29 call delete('Xfinddir1', 'd')
Bram Moolenaared71ed32019-01-30 22:13:35 +010030endfunc
31
32" Test findfile({name} [, {path} [, {count}]])
Bram Moolenaardc9a0812017-02-23 18:46:50 +010033func Test_findfile()
Bram Moolenaared71ed32019-01-30 22:13:35 +010034 let save_path = &path
35 let save_shellslash = &shellslash
36 let save_dir = getcwd()
37 set shellslash
38 call CreateFiles()
Bram Moolenaar3b0d70f2022-08-29 22:31:20 +010039 cd Xfinddir1
Bram Moolenaared71ed32019-01-30 22:13:35 +010040 e Xdir2/foo
41
42 " With ,, in path, findfile() searches in current directory.
43 set path=,,
44 call assert_equal('foo', findfile('foo'))
45 call assert_equal('bar', findfile('bar'))
46 call assert_equal('', findfile('foobar'))
47
48 " Directories should not be found (finddir() finds them).
49 call assert_equal('', findfile('Xdir2'))
50
51 " With . in 'path', findfile() searches relatively to current file.
52 set path=.
53 call assert_equal('Xdir2/foo', findfile('foo'))
54 call assert_equal('', findfile('bar'))
Bram Moolenaara4208962019-08-24 20:50:19 +020055 call assert_equal('Xdir2/foobar', 'foobar'->findfile())
Bram Moolenaared71ed32019-01-30 22:13:35 +010056
57 " Empty {path} 2nd argument is the same as no 2nd argument.
58 call assert_equal('Xdir2/foo', findfile('foo', ''))
59 call assert_equal('', findfile('bar', ''))
60
61 " Test with *
62 call assert_equal('Xdir2/foo', findfile('foo', '*'))
63 call assert_equal('', findfile('bar', '*'))
64 call assert_equal('Xdir2/Xdir3/bar', findfile('bar', '*/*'))
65 call assert_equal('Xdir2/Xdir3/bar', findfile('bar', 'Xdir2/*'))
66 call assert_equal('Xdir2/Xdir3/bar', findfile('bar', 'Xdir*/Xdir3'))
67 call assert_equal('Xdir2/Xdir3/bar', findfile('bar', '*2/*3'))
68
69 " Test with **
70 call assert_equal('bar', findfile('bar', '**'))
71 call assert_equal('Xdir2/Xdir3/bar', findfile('bar', '**/Xdir3'))
72 call assert_equal('Xdir2/Xdir3/bar', findfile('bar', 'Xdir2/**'))
73
74 call assert_equal('Xdir2/Xdir3/barfoo', findfile('barfoo', '**2'))
75 call assert_equal('', findfile('barfoo', '**1'))
76 call assert_equal('Xdir2/foobar', findfile('foobar', '**1'))
77
78 " Test with {count} 3rd argument.
79 call assert_equal('bar', findfile('bar', '**', 0))
80 call assert_equal('bar', findfile('bar', '**', 1))
81 call assert_equal('Xdir2/Xdir3/bar', findfile('bar', '**', 2))
82 call assert_equal('', findfile('bar', '**', 3))
83 call assert_equal(['bar', 'Xdir2/Xdir3/bar'], findfile('bar', '**', -1))
84
85 " Test upwards search.
86 cd Xdir2/Xdir3
87 call assert_equal('bar', findfile('bar', ';'))
Bram Moolenaar3b0d70f2022-08-29 22:31:20 +010088 call assert_match('.*/Xfinddir1/Xdir2/foo', findfile('foo', ';'))
89 call assert_match('.*/Xfinddir1/Xdir2/foo', findfile('foo', ';', 1))
90 call assert_match('.*/Xfinddir1/foo', findfile('foo', ';', 2))
91 call assert_match('.*/Xfinddir1/foo', findfile('foo', ';', 2))
92 call assert_match('.*/Xfinddir1/Xdir2/foo', findfile('foo', 'Xdir2;', 1))
Bram Moolenaared71ed32019-01-30 22:13:35 +010093 call assert_equal('', findfile('foo', 'Xdir2;', 2))
94
95 " List l should have at least 2 values (possibly more if foo file
Bram Moolenaar3b0d70f2022-08-29 22:31:20 +010096 " happens to be found upwards above Xfinddir1).
Bram Moolenaared71ed32019-01-30 22:13:35 +010097 let l = findfile('foo', ';', -1)
Bram Moolenaar3b0d70f2022-08-29 22:31:20 +010098 call assert_match('.*/Xfinddir1/Xdir2/foo', l[0])
99 call assert_match('.*/Xfinddir1/foo', l[1])
Bram Moolenaared71ed32019-01-30 22:13:35 +0100100
101 " Test upwards search with stop-directory.
102 cd Xdir2
zeertzjq764526e2024-07-11 22:24:15 +0200103 let l = findfile('bar', ';' . save_dir . '/Xfinddir1/Xdir2/Xdir3/', -1)
104 call assert_equal(1, len(l))
105 call assert_match('.*/Xfinddir1/Xdir2/Xdir3/bar', l[0])
106 let l = findfile('bar', ';' . save_dir . '/Xfinddir1/Xdir2/Xdir3', -1)
107 call assert_equal(1, len(l))
108 call assert_match('.*/Xfinddir1/Xdir2/Xdir3/bar', l[0])
109 let l = findfile('bar', ';../', -1)
110 call assert_equal(1, len(l))
111 call assert_match('.*/Xfinddir1/Xdir2/Xdir3/bar', l[0])
zeertzjq1ee74202024-07-12 07:29:14 +0200112 let l = findfile('bar', ';..', -1)
113 call assert_equal(1, len(l))
114 call assert_match('.*/Xfinddir1/Xdir2/Xdir3/bar', l[0])
zeertzjq764526e2024-07-11 22:24:15 +0200115
Bram Moolenaar3b0d70f2022-08-29 22:31:20 +0100116 let l = findfile('bar', ';' . save_dir . '/Xfinddir1/Xdir2/', -1)
Bram Moolenaared71ed32019-01-30 22:13:35 +0100117 call assert_equal(1, len(l))
Bram Moolenaar3b0d70f2022-08-29 22:31:20 +0100118 call assert_match('.*/Xfinddir1/Xdir2/Xdir3/bar', l[0])
zeertzjqe6ab23b2024-07-11 22:22:26 +0200119 let l = findfile('bar', ';' . save_dir . '/Xfinddir1/Xdir2', -1)
120 call assert_equal(1, len(l))
121 call assert_match('.*/Xfinddir1/Xdir2/Xdir3/bar', l[0])
zeertzjq764526e2024-07-11 22:24:15 +0200122 let l = findfile('bar', ';../../', -1)
123 call assert_equal(1, len(l))
124 call assert_match('.*/Xfinddir1/Xdir2/Xdir3/bar', l[0])
zeertzjq1ee74202024-07-12 07:29:14 +0200125 let l = findfile('bar', ';../..', -1)
126 call assert_equal(1, len(l))
127 call assert_match('.*/Xfinddir1/Xdir2/Xdir3/bar', l[0])
Bram Moolenaared71ed32019-01-30 22:13:35 +0100128
Bram Moolenaar3b0d70f2022-08-29 22:31:20 +0100129 let l = findfile('bar', ';' . save_dir . '/Xfinddir1/', -1)
Bram Moolenaared71ed32019-01-30 22:13:35 +0100130 call assert_equal(2, len(l))
Bram Moolenaar3b0d70f2022-08-29 22:31:20 +0100131 call assert_match('.*/Xfinddir1/Xdir2/Xdir3/bar', l[0])
132 call assert_match('.*/Xfinddir1/bar', l[1])
zeertzjqe6ab23b2024-07-11 22:22:26 +0200133 let l = findfile('bar', ';' . save_dir . '/Xfinddir1', -1)
134 call assert_equal(2, len(l))
135 call assert_match('.*/Xfinddir1/Xdir2/Xdir3/bar', l[0])
136 call assert_match('.*/Xfinddir1/bar', l[1])
zeertzjq764526e2024-07-11 22:24:15 +0200137 let l = findfile('bar', ';../../../', -1)
138 call assert_equal(2, len(l))
139 call assert_match('.*/Xfinddir1/Xdir2/Xdir3/bar', l[0])
140 call assert_match('.*/Xfinddir1/bar', l[1])
zeertzjq1ee74202024-07-12 07:29:14 +0200141 let l = findfile('bar', ';../../..', -1)
142 call assert_equal(2, len(l))
143 call assert_match('.*/Xfinddir1/Xdir2/Xdir3/bar', l[0])
144 call assert_match('.*/Xfinddir1/bar', l[1])
Bram Moolenaared71ed32019-01-30 22:13:35 +0100145
146 " Test combined downwards and upwards search from Xdir2/.
147 cd ../..
148 call assert_equal('Xdir3/bar', findfile('bar', '**;', 1))
Bram Moolenaar3b0d70f2022-08-29 22:31:20 +0100149 call assert_match('.*/Xfinddir1/bar', findfile('bar', '**;', 2))
Bram Moolenaared71ed32019-01-30 22:13:35 +0100150
151 bwipe!
Bram Moolenaar3503d7c2019-11-09 20:10:17 +0100152 call chdir(save_dir)
Bram Moolenaared71ed32019-01-30 22:13:35 +0100153 call CleanFiles()
154 let &path = save_path
155 let &shellslash = save_shellslash
156endfunc
157
Bram Moolenaar71b13e92019-02-04 21:14:45 +0100158func Test_findfile_error()
159 call assert_fails('call findfile([])', 'E730:')
160 call assert_fails('call findfile("x", [])', 'E730:')
161 call assert_fails('call findfile("x", "", [])', 'E745:')
162 call assert_fails('call findfile("x", "**x")', 'E343:')
163 call assert_fails('call findfile("x", repeat("x", 5000))', 'E854:')
164endfunc
165
Bram Moolenaared71ed32019-01-30 22:13:35 +0100166" Test finddir({name} [, {path} [, {count}]])
167func Test_finddir()
168 let save_path = &path
169 let save_shellslash = &shellslash
170 let save_dir = getcwd()
171 set path=,,
zeertzjqe7b98ab2024-07-11 21:48:09 +0200172 set shellslash
Bram Moolenaared71ed32019-01-30 22:13:35 +0100173 call CreateFiles()
Bram Moolenaar3b0d70f2022-08-29 22:31:20 +0100174 cd Xfinddir1
Bram Moolenaared71ed32019-01-30 22:13:35 +0100175
176 call assert_equal('Xdir2', finddir('Xdir2'))
Bram Moolenaara4208962019-08-24 20:50:19 +0200177 call assert_equal('', 'Xdir3'->finddir())
Bram Moolenaared71ed32019-01-30 22:13:35 +0100178
179 " Files should not be found (findfile() finds them).
180 call assert_equal('', finddir('foo'))
181
182 call assert_equal('Xdir2', finddir('Xdir2', '**'))
183 call assert_equal('Xdir2/Xdir3', finddir('Xdir3', '**'))
184
185 call assert_equal('Xdir2', finddir('Xdir2', '**', 1))
186 call assert_equal('Xdir2/Xdir3/Xdir2', finddir('Xdir2', '**', 2))
187 call assert_equal(['Xdir2',
188 \ 'Xdir2/Xdir3/Xdir2'], finddir('Xdir2', '**', -1))
189
190 call assert_equal('Xdir2', finddir('Xdir2', '**1'))
191 call assert_equal('Xdir2', finddir('Xdir2', '**0'))
192 call assert_equal('Xdir2/Xdir3', finddir('Xdir3', '**1'))
193 call assert_equal('', finddir('Xdir3', '**0'))
194
195 " Test upwards dir search.
196 cd Xdir2/Xdir3
Bram Moolenaar3b0d70f2022-08-29 22:31:20 +0100197 call assert_match('.*/Xfinddir1', finddir('Xfinddir1', ';'))
Bram Moolenaared71ed32019-01-30 22:13:35 +0100198
199 " Test upwards search with stop-directory.
Bram Moolenaar3b0d70f2022-08-29 22:31:20 +0100200 call assert_match('.*/Xfinddir1', finddir('Xfinddir1', ';' . save_dir . '/'))
201 call assert_equal('', finddir('Xfinddir1', ';' . save_dir . '/Xfinddir1/'))
Bram Moolenaared71ed32019-01-30 22:13:35 +0100202
203 " Test combined downwards and upwards dir search from Xdir2/.
Bram Moolenaardc9a0812017-02-23 18:46:50 +0100204 cd ..
Bram Moolenaar3b0d70f2022-08-29 22:31:20 +0100205 call assert_match('.*/Xfinddir1', finddir('Xfinddir1', '**;', 1))
Bram Moolenaared71ed32019-01-30 22:13:35 +0100206 call assert_equal('Xdir3/Xdir2', finddir('Xdir2', '**;', 1))
Bram Moolenaar3b0d70f2022-08-29 22:31:20 +0100207 call assert_match('.*/Xfinddir1/Xdir2', finddir('Xdir2', '**;', 2))
Bram Moolenaared71ed32019-01-30 22:13:35 +0100208 call assert_equal('Xdir3', finddir('Xdir3', '**;', 1))
Bram Moolenaardc9a0812017-02-23 18:46:50 +0100209
Bram Moolenaar3503d7c2019-11-09 20:10:17 +0100210 call chdir(save_dir)
Bram Moolenaared71ed32019-01-30 22:13:35 +0100211 call CleanFiles()
212 let &path = save_path
213 let &shellslash = save_shellslash
Bram Moolenaardc9a0812017-02-23 18:46:50 +0100214endfunc
Bram Moolenaar71b13e92019-02-04 21:14:45 +0100215
216func Test_finddir_error()
217 call assert_fails('call finddir([])', 'E730:')
218 call assert_fails('call finddir("x", [])', 'E730:')
219 call assert_fails('call finddir("x", "", [])', 'E745:')
220 call assert_fails('call finddir("x", "**x")', 'E343:')
221 call assert_fails('call finddir("x", repeat("x", 5000))', 'E854:')
222endfunc
Bram Moolenaarbc2b71d2020-02-17 21:33:30 +0100223
224" Test for the :find, :sfind and :tabfind commands
225func Test_find_cmd()
226 new
227 let save_path = &path
228 let save_dir = getcwd()
229 set path=.,./**/*
230 call CreateFiles()
Bram Moolenaar3b0d70f2022-08-29 22:31:20 +0100231 cd Xfinddir1
Bram Moolenaarbc2b71d2020-02-17 21:33:30 +0100232
233 " Test for :find
234 find foo
235 call assert_equal('foo', expand('%:.'))
236 2find foo
237 call assert_equal('Xdir2/foo', expand('%:.'))
238 call assert_fails('3find foo', 'E347:')
239
240 " Test for :sfind
241 enew
242 sfind barfoo
243 call assert_equal('Xdir2/Xdir3/barfoo', expand('%:.'))
244 call assert_equal(3, winnr('$'))
245 close
246 call assert_fails('sfind baz', 'E345:')
247 call assert_equal(2, winnr('$'))
248
249 " Test for :tabfind
250 enew
251 tabfind foobar
252 call assert_equal('Xdir2/foobar', expand('%:.'))
253 call assert_equal(2, tabpagenr('$'))
254 tabclose
255 call assert_fails('tabfind baz', 'E345:')
256 call assert_equal(1, tabpagenr('$'))
257
258 call chdir(save_dir)
259 call CleanFiles()
260 let &path = save_path
261 close
Bram Moolenaar2d10cd42020-03-19 14:37:30 +0100262
263 call assert_fails('find', 'E471:')
264 call assert_fails('sfind', 'E471:')
265 call assert_fails('tabfind', 'E471:')
Bram Moolenaarbc2b71d2020-02-17 21:33:30 +0100266endfunc
Bram Moolenaar6d91bcb2020-08-12 18:50:36 +0200267
Christian Brabandt7a4ca322021-07-25 15:08:05 +0200268func Test_find_non_existing_path()
269 new
270 let save_path = &path
271 let save_dir = getcwd()
Bram Moolenaar70e67252022-09-27 19:34:35 +0100272 call mkdir('dir1/dir2', 'pR')
Christian Brabandt7a4ca322021-07-25 15:08:05 +0200273 call writefile([], 'dir1/file.txt')
274 call writefile([], 'dir1/dir2/base.txt')
275 call chdir('dir1/dir2')
276 e base.txt
277 set path=../include
278
279 call assert_fails(':find file.txt', 'E345:')
280
281 call chdir(save_dir)
282 bw!
Christian Brabandt7a4ca322021-07-25 15:08:05 +0200283 let &path = save_path
284endfunc
285
Yegappan Lakshmananaeb1c972024-10-22 23:42:20 +0200286" Test for 'findexpr'
287func Test_findexpr()
288 CheckUnix
289 call assert_equal('', &findexpr)
290 call writefile(['aFile'], 'Xfindexpr1.c', 'D')
291 call writefile(['bFile'], 'Xfindexpr2.c', 'D')
292 call writefile(['cFile'], 'Xfindexpr3.c', 'D')
293
294 " basic tests
295 func FindExpr1()
296 let fnames = ['Xfindexpr1.c', 'Xfindexpr2.c', 'Xfindexpr3.c']
Yegappan Lakshmananaeb1c972024-10-22 23:42:20 +0200297 return fnames->copy()->filter('v:val =~? v:fname')
298 endfunc
299
300 set findexpr=FindExpr1()
301 find Xfindexpr3
302 call assert_match('Xfindexpr3.c', @%)
303 bw!
304 2find Xfind
305 call assert_match('Xfindexpr2.c', @%)
306 bw!
307 call assert_fails('4find Xfind', 'E347: No more file "Xfind" found in path')
308 call assert_fails('find foobar', 'E345: Can''t find file "foobar" in path')
309
310 sfind Xfindexpr2.c
311 call assert_match('Xfindexpr2.c', @%)
312 call assert_equal(2, winnr('$'))
313 %bw!
314 call assert_fails('sfind foobar', 'E345: Can''t find file "foobar" in path')
315
316 tabfind Xfindexpr3.c
317 call assert_match('Xfindexpr3.c', @%)
318 call assert_equal(2, tabpagenr())
319 %bw!
320 call assert_fails('tabfind foobar', 'E345: Can''t find file "foobar" in path')
321
322 " Buffer-local option
323 set findexpr=['abc']
324 new
325 setlocal findexpr=['def']
326 find xxxx
327 call assert_equal('def', @%)
328 wincmd w
329 find xxxx
330 call assert_equal('abc', @%)
331 aboveleft new
332 call assert_equal("['abc']", &findexpr)
333 wincmd k
334 aboveleft new
335 call assert_equal("['abc']", &findexpr)
336 %bw!
337
338 " Empty list
339 set findexpr=[]
340 call assert_fails('find xxxx', 'E345: Can''t find file "xxxx" in path')
341
342 " Error cases
343
344 " Syntax error in the expression
345 set findexpr=FindExpr1{}
346 call assert_fails('find Xfindexpr1.c', 'E15: Invalid expression')
347
348 " Find expression throws an error
349 func FindExpr2()
350 throw 'find error'
351 endfunc
352 set findexpr=FindExpr2()
353 call assert_fails('find Xfindexpr1.c', 'find error')
354
Yegappan Lakshmanan2f6efac2024-10-23 21:06:10 +0200355 " Try using a null List as the expression
356 set findexpr=test_null_list()
Yegappan Lakshmananaeb1c972024-10-22 23:42:20 +0200357 call assert_fails('find Xfindexpr1.c', 'E345: Can''t find file "Xfindexpr1.c" in path')
358
359 " Try to create a new window from the find expression
360 func FindExpr3()
361 new
362 return ["foo"]
363 endfunc
364 set findexpr=FindExpr3()
365 call assert_fails('find Xfindexpr1.c', 'E565: Not allowed to change text or change window')
366
367 " Try to modify the current buffer from the find expression
368 func FindExpr4()
369 call setline(1, ['abc'])
370 return ["foo"]
371 endfunc
372 set findexpr=FindExpr4()
373 call assert_fails('find Xfindexpr1.c', 'E565: Not allowed to change text or change window')
374
Yegappan Lakshmanan2f6efac2024-10-23 21:06:10 +0200375 " Expression returning a string
376 set findexpr='abc'
377 call assert_fails('find Xfindexpr1.c', 'E1514: findexpr did not return a List type')
378
Yegappan Lakshmananaeb1c972024-10-22 23:42:20 +0200379 set findexpr&
380 delfunc! FindExpr1
381 delfunc! FindExpr2
382 delfunc! FindExpr3
383 delfunc! FindExpr4
384endfunc
385
386" Test for using a script-local function for 'findexpr'
387func Test_findexpr_scriptlocal_func()
388 func! s:FindExprScript()
389 let g:FindExprArg = v:fname
390 return ['xxx']
391 endfunc
392
393 set findexpr=s:FindExprScript()
394 call assert_equal(expand('<SID>') .. 'FindExprScript()', &findexpr)
395 call assert_equal(expand('<SID>') .. 'FindExprScript()', &g:findexpr)
396 new | only
397 let g:FindExprArg = ''
398 find abc
399 call assert_equal('abc', g:FindExprArg)
400 bw!
401
402 set findexpr=<SID>FindExprScript()
403 call assert_equal(expand('<SID>') .. 'FindExprScript()', &findexpr)
404 call assert_equal(expand('<SID>') .. 'FindExprScript()', &g:findexpr)
405 new | only
406 let g:FindExprArg = ''
407 find abc
408 call assert_equal('abc', g:FindExprArg)
409 bw!
410
411 let &findexpr = 's:FindExprScript()'
412 call assert_equal(expand('<SID>') .. 'FindExprScript()', &g:findexpr)
413 new | only
414 let g:FindExprArg = ''
415 find abc
416 call assert_equal('abc', g:FindExprArg)
417 bw!
418
419 let &findexpr = '<SID>FindExprScript()'
420 call assert_equal(expand('<SID>') .. 'FindExprScript()', &g:findexpr)
421 new | only
422 let g:FindExprArg = ''
423 find abc
424 call assert_equal('abc', g:FindExprArg)
425 bw!
426
427 set findexpr=
428 setglobal findexpr=s:FindExprScript()
429 setlocal findexpr=
430 call assert_equal(expand('<SID>') .. 'FindExprScript()', &findexpr)
431 call assert_equal(expand('<SID>') .. 'FindExprScript()', &g:findexpr)
432 call assert_equal('', &l:findexpr)
433 new | only
434 let g:FindExprArg = ''
435 find abc
436 call assert_equal('abc', g:FindExprArg)
437 bw!
438
439 new | only
440 set findexpr=
441 setglobal findexpr=
442 setlocal findexpr=s:FindExprScript()
443 call assert_equal(expand('<SID>') .. 'FindExprScript()', &findexpr)
444 call assert_equal(expand('<SID>') .. 'FindExprScript()', &l:findexpr)
445 call assert_equal('', &g:findexpr)
446 let g:FindExprArg = ''
447 find abc
448 call assert_equal('abc', g:FindExprArg)
449 bw!
450
451 set findexpr=
452 delfunc s:FindExprScript
453endfunc
454
Yegappan Lakshmanan2f6efac2024-10-23 21:06:10 +0200455" Test for expanding the argument to the :find command using 'findexpr'
456func Test_findexpr_expand_arg()
457 func FindExpr1()
458 let fnames = ['Xfindexpr1.c', 'Xfindexpr2.c', 'Xfindexpr3.c']
459 return fnames->copy()->filter('v:val =~? v:fname')
460 endfunc
461 set findexpr=FindExpr1()
462
463 call feedkeys(":find \<Tab>\<C-B>\"\<CR>", "xt")
464 call assert_equal('"find Xfindexpr1.c', @:)
465
466 call feedkeys(":find Xfind\<Tab>\<Tab>\<C-B>\"\<CR>", "xt")
467 call assert_equal('"find Xfindexpr2.c', @:)
468
469 call feedkeys(":find *3*\<Tab>\<C-B>\"\<CR>", "xt")
470 call assert_equal('"find Xfindexpr3.c', @:)
471
472 call feedkeys(":find Xfind\<C-A>\<C-B>\"\<CR>", "xt")
473 call assert_equal('"find Xfindexpr1.c Xfindexpr2.c Xfindexpr3.c', @:)
474
475 call feedkeys(":find abc\<Tab>\<C-B>\"\<CR>", "xt")
476 call assert_equal('"find abc', @:)
477
478 set findexpr&
479 delfunc! FindExpr1
480endfunc
481
Bram Moolenaar6d91bcb2020-08-12 18:50:36 +0200482" vim: shiftwidth=2 sts=2 expandtab