diff options
author | Hennadii Chernyshchyk <genaloner@gmail.com> | 2020-05-05 18:15:45 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-05-05 08:15:45 -0700 |
commit | d2766b06c8fc50d06765c5c607744cc6b5f5ef0a (patch) | |
tree | 1b3b1a46c44a9c33163d0ef111d70e3bb3fd5784 /src/nvim/testdir | |
parent | 48c219829786c14b6e511229a59e2fda32ffe352 (diff) | |
download | rneovim-d2766b06c8fc50d06765c5c607744cc6b5f5ef0a.tar.gz rneovim-d2766b06c8fc50d06765c5c607744cc6b5f5ef0a.tar.bz2 rneovim-d2766b06c8fc50d06765c5c607744cc6b5f5ef0a.zip |
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)
https://github.com/vim/vim/commit/543c9b1921d7605498b54afdef518e312f1b4515
closes #12212
Diffstat (limited to 'src/nvim/testdir')
-rw-r--r-- | src/nvim/testdir/test_functions.vim | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/src/nvim/testdir/test_functions.vim b/src/nvim/testdir/test_functions.vim index bd5cb6ad19..51689db9c4 100644 --- a/src/nvim/testdir/test_functions.vim +++ b/src/nvim/testdir/test_functions.vim @@ -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 |