Mercurial > vim
comparison src/testdir/test_functions.vim @ 16231:0761a4c111a7 v8.1.1120
patch 8.1.1120: cannot easily get directory entry matches
commit https://github.com/vim/vim/commit/543c9b1921d7605498b54afdef518e312f1b4515
Author: Bram Moolenaar <Bram@vim.org>
Date: Fri Apr 5 22:50:40 2019 +0200
patch 8.1.1120: cannot easily get directory entry matches
Problem: Cannot easily get directory entry matches.
Solution: Add the readdir() function. (Yasuhiro Matsumoto, closes https://github.com/vim/vim/issues/2439)
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Fri, 05 Apr 2019 23:00:06 +0200 |
parents | 1eaaa82ececf |
children | 81be817c9d9a |
comparison
equal
deleted
inserted
replaced
16230:55efca92c30f | 16231:0761a4c111a7 |
---|---|
1399 call assert_equal(uname =~? 'QNX', has('qnx')) | 1399 call assert_equal(uname =~? 'QNX', has('qnx')) |
1400 call assert_equal(uname =~? 'SunOS', has('sun')) | 1400 call assert_equal(uname =~? 'SunOS', has('sun')) |
1401 call assert_equal(uname =~? 'CYGWIN\|MSYS', has('win32unix')) | 1401 call assert_equal(uname =~? 'CYGWIN\|MSYS', has('win32unix')) |
1402 endif | 1402 endif |
1403 endfunc | 1403 endfunc |
1404 | |
1405 func Test_readdir() | |
1406 call mkdir('Xdir') | |
1407 call writefile([], 'Xdir/foo.txt') | |
1408 call writefile([], 'Xdir/bar.txt') | |
1409 call mkdir('Xdir/dir') | |
1410 | |
1411 " All results | |
1412 let files = readdir('Xdir') | |
1413 call assert_equal(['bar.txt', 'dir', 'foo.txt'], sort(files)) | |
1414 | |
1415 " Only results containing "f" | |
1416 let files = readdir('Xdir', { x -> stridx(x, 'f') !=- 1 }) | |
1417 call assert_equal(['foo.txt'], sort(files)) | |
1418 | |
1419 " Only .txt files | |
1420 let files = readdir('Xdir', { x -> x =~ '.txt$' }) | |
1421 call assert_equal(['bar.txt', 'foo.txt'], sort(files)) | |
1422 | |
1423 " Only .txt files with string | |
1424 let files = readdir('Xdir', 'v:val =~ ".txt$"') | |
1425 call assert_equal(['bar.txt', 'foo.txt'], sort(files)) | |
1426 | |
1427 " Limit to 1 result. | |
1428 let l = [] | |
1429 let files = readdir('Xdir', {x -> len(add(l, x)) == 2 ? -1 : 1}) | |
1430 call assert_equal(1, len(files)) | |
1431 | |
1432 call delete('Xdir', 'rf') | |
1433 endfunc |