diff options
author | Lewis Russell <lewis6991@gmail.com> | 2022-12-22 10:23:19 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-12-22 10:23:19 +0000 |
commit | ceb533181ca828364d0ed4e1b31293f81780fa2c (patch) | |
tree | 27c4b96c7b0aca454d912e6ebe575d6fdcca206f /test/functional/lua/fs_spec.lua | |
parent | ff45a142b6a776f3ff11bdabac1a72d735ceca82 (diff) | |
parent | fb5576c2d36464b55c2c639aec9259a6f2461970 (diff) | |
download | rneovim-ceb533181ca828364d0ed4e1b31293f81780fa2c.tar.gz rneovim-ceb533181ca828364d0ed4e1b31293f81780fa2c.tar.bz2 rneovim-ceb533181ca828364d0ed4e1b31293f81780fa2c.zip |
Merge pull request #21402 from lewis6991/feat/fs_ls
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() |