aboutsummaryrefslogtreecommitdiff
path: root/test/functional/lua/fs_spec.lua
diff options
context:
space:
mode:
authorGregory Anders <greg@gpanders.com>2022-05-15 14:38:19 -0600
committerGregory Anders <greg@gpanders.com>2022-05-31 13:04:40 -0600
commit67cbaf58c41a3db19c5014587e72d06be9e3d58e (patch)
tree49fa85e672d6637ef38a9e910a1323224ca653ab /test/functional/lua/fs_spec.lua
parente6652821bd32e4ff8d62a0b67fc2041a5f41e252 (diff)
downloadrneovim-67cbaf58c41a3db19c5014587e72d06be9e3d58e.tar.gz
rneovim-67cbaf58c41a3db19c5014587e72d06be9e3d58e.tar.bz2
rneovim-67cbaf58c41a3db19c5014587e72d06be9e3d58e.zip
feat(fs): add vim.fs.parents()
vim.fs.parents() is a Lua iterator that returns the next parent directory of the given file or directory on each iteration.
Diffstat (limited to 'test/functional/lua/fs_spec.lua')
-rw-r--r--test/functional/lua/fs_spec.lua33
1 files changed, 33 insertions, 0 deletions
diff --git a/test/functional/lua/fs_spec.lua b/test/functional/lua/fs_spec.lua
new file mode 100644
index 0000000000..69eb8cd539
--- /dev/null
+++ b/test/functional/lua/fs_spec.lua
@@ -0,0 +1,33 @@
+local helpers = require('test.functional.helpers')(after_each)
+
+local clear = helpers.clear
+local exec_lua = helpers.exec_lua
+local eq = helpers.eq
+local mkdir_p = helpers.mkdir_p
+local rmdir = helpers.rmdir
+local nvim_dir = helpers.nvim_dir
+local test_build_dir = helpers.test_build_dir
+
+before_each(clear)
+
+describe('vim.fs', function()
+ describe('parents()', function()
+ it('works', function()
+ local test_dir = nvim_dir .. '/test'
+ mkdir_p(test_dir)
+ local dirs = exec_lua([[
+ local test_dir, test_build_dir = ...
+ local dirs = {}
+ for dir in vim.fs.parents(test_dir .. "/foo.txt") do
+ dirs[#dirs + 1] = dir
+ if dir == test_build_dir then
+ break
+ end
+ end
+ return dirs
+ ]], test_dir, test_build_dir)
+ eq({test_dir, nvim_dir, test_build_dir}, dirs)
+ rmdir(test_dir)
+ end)
+ end)
+end)