mirror of
https://github.com/neovim/neovim.git
synced 2025-10-09 19:36:40 +00:00
vim-patch:8.1.1120: cannot easily get directory entry matches #12222
Problem: Cannot easily get directory entry matches.
Solution: Add the readdir() function. (Yasuhiro Matsumoto, closes vim/vim#2439)
543c9b1921
closes #12212
This commit is contained in:

committed by
GitHub

parent
48c2198297
commit
d2766b06c8
@@ -1307,3 +1307,33 @@ func Test_bufadd_bufload()
|
||||
bwipe otherName
|
||||
call assert_equal(0, bufexists('someName'))
|
||||
endfunc
|
||||
|
||||
func Test_readdir()
|
||||
call mkdir('Xdir')
|
||||
call writefile([], 'Xdir/foo.txt')
|
||||
call writefile([], 'Xdir/bar.txt')
|
||||
call mkdir('Xdir/dir')
|
||||
|
||||
" All results
|
||||
let files = readdir('Xdir')
|
||||
call assert_equal(['bar.txt', 'dir', 'foo.txt'], sort(files))
|
||||
|
||||
" Only results containing "f"
|
||||
let files = readdir('Xdir', { x -> stridx(x, 'f') !=- 1 })
|
||||
call assert_equal(['foo.txt'], sort(files))
|
||||
|
||||
" Only .txt files
|
||||
let files = readdir('Xdir', { x -> x =~ '.txt$' })
|
||||
call assert_equal(['bar.txt', 'foo.txt'], sort(files))
|
||||
|
||||
" Only .txt files with string
|
||||
let files = readdir('Xdir', 'v:val =~ ".txt$"')
|
||||
call assert_equal(['bar.txt', 'foo.txt'], sort(files))
|
||||
|
||||
" Limit to 1 result.
|
||||
let l = []
|
||||
let files = readdir('Xdir', {x -> len(add(l, x)) == 2 ? -1 : 1})
|
||||
call assert_equal(1, len(files))
|
||||
|
||||
call delete('Xdir', 'rf')
|
||||
endfunc
|
||||
|
Reference in New Issue
Block a user