diff options
author | Lewis Russell <lewis6991@gmail.com> | 2022-12-13 13:59:31 +0000 |
---|---|---|
committer | Lewis Russell <lewis6991@gmail.com> | 2022-12-20 16:39:34 +0000 |
commit | fb5576c2d36464b55c2c639aec9259a6f2461970 (patch) | |
tree | 669e81b97c9dba5597b710b1279726607718cf76 /test/functional/lua/fs_spec.lua | |
parent | a6b05cb75d330dd995d3ad21ee08bb0a2cfcae74 (diff) | |
download | rneovim-fb5576c2d36464b55c2c639aec9259a6f2461970.tar.gz rneovim-fb5576c2d36464b55c2c639aec9259a6f2461970.tar.bz2 rneovim-fb5576c2d36464b55c2c639aec9259a6f2461970.zip |
feat(fs): add opts argument to vim.fs.dir()
Added option depth to allow recursively searching a directory tree.
Diffstat (limited to 'test/functional/lua/fs_spec.lua')
-rw-r--r-- | test/functional/lua/fs_spec.lua | 68 |
1 files changed, 68 insertions, 0 deletions
diff --git a/test/functional/lua/fs_spec.lua b/test/functional/lua/fs_spec.lua index 88ad6ba24a..5db92ca174 100644 --- a/test/functional/lua/fs_spec.lua +++ b/test/functional/lua/fs_spec.lua @@ -141,6 +141,74 @@ describe('vim.fs', function() return false ]], nvim_dir, nvim_prog_basename)) end) + + it('works with opts.depth and opts.skip', function() + helpers.funcs.system 'mkdir -p testd/a/b/c' + helpers.funcs.system('touch '..table.concat({ + 'testd/a1', + 'testd/b1', + 'testd/c1', + 'testd/a/a2', + 'testd/a/b2', + 'testd/a/c2', + 'testd/a/b/a3', + 'testd/a/b/b3', + 'testd/a/b/c3', + 'testd/a/b/c/a4', + 'testd/a/b/c/b4', + 'testd/a/b/c/c4', + }, ' ')) + + local function run(dir, depth, skip) + local r = exec_lua([[ + local dir, depth, skip = ... + local r = {} + local skip_f + if skip then + skip_f = function(n) + if vim.tbl_contains(skip or {}, n) then + return false + end + end + end + for name, type_ in vim.fs.dir(dir, { depth = depth, skip = skip_f }) do + r[name] = type_ + end + return r + ]], dir, depth, skip) + return r + end + + local exp = {} + + exp['a1'] = 'file' + exp['b1'] = 'file' + exp['c1'] = 'file' + exp['a'] = 'directory' + + eq(exp, run('testd', 1)) + + exp['a/a2'] = 'file' + exp['a/b2'] = 'file' + exp['a/c2'] = 'file' + exp['a/b'] = 'directory' + + eq(exp, run('testd', 2)) + + exp['a/b/a3'] = 'file' + exp['a/b/b3'] = 'file' + exp['a/b/c3'] = 'file' + exp['a/b/c'] = 'directory' + + eq(exp, run('testd', 3)) + eq(exp, run('testd', 999, {'a/b/c'})) + + exp['a/b/c/a4'] = 'file' + exp['a/b/c/b4'] = 'file' + exp['a/b/c/c4'] = 'file' + + eq(exp, run('testd', 999)) + end) end) describe('find()', function() |