diff options
author | Gregory Anders <8965202+gpanders@users.noreply.github.com> | 2024-04-24 21:43:46 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-04-24 21:43:46 -0500 |
commit | 38b9c322c97b63f53caef7a651211fc9312d055e (patch) | |
tree | af8804460c04d3bd4b2965d7583252506a066cf1 /test/functional/lua/fs_spec.lua | |
parent | 16513b30337523dc64707309ee7fe3dd2247266d (diff) | |
download | rneovim-38b9c322c97b63f53caef7a651211fc9312d055e.tar.gz rneovim-38b9c322c97b63f53caef7a651211fc9312d055e.tar.bz2 rneovim-38b9c322c97b63f53caef7a651211fc9312d055e.zip |
feat(fs): add vim.fs.root (#28477)
vim.fs.root() is a function for finding a project root relative to a
buffer using one or more "root markers". This is useful for LSP and
could be useful for other "projects" designs, as well as for any plugins
which work with a "projects" concept.
Diffstat (limited to 'test/functional/lua/fs_spec.lua')
-rw-r--r-- | test/functional/lua/fs_spec.lua | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/test/functional/lua/fs_spec.lua b/test/functional/lua/fs_spec.lua index db6ff60e9a..b651297db3 100644 --- a/test/functional/lua/fs_spec.lua +++ b/test/functional/lua/fs_spec.lua @@ -7,6 +7,8 @@ local eq = t.eq local mkdir_p = n.mkdir_p local rmdir = n.rmdir local nvim_dir = n.nvim_dir +local command = n.command +local api = n.api local test_build_dir = t.paths.test_build_dir local test_source_path = t.paths.test_source_path local nvim_prog = n.nvim_prog @@ -278,6 +280,38 @@ describe('vim.fs', function() end) end) + describe('root()', function() + before_each(function() + command('edit test/functional/fixtures/tty-test.c') + end) + + it('works with a single marker', function() + eq(test_source_path, exec_lua([[return vim.fs.root(0, '.git')]])) + end) + + it('works with multiple markers', function() + local bufnr = api.nvim_get_current_buf() + eq( + vim.fs.joinpath(test_source_path, 'test/functional/fixtures'), + exec_lua([[return vim.fs.root(..., {'CMakeLists.txt', '.git'})]], bufnr) + ) + end) + + it('works with a function', function() + ---@type string + local result = exec_lua([[ + return vim.fs.root(0, function(name, path) + return name:match('%.txt$') + end) + ]]) + eq(vim.fs.joinpath(test_source_path, 'test/functional/fixtures'), result) + end) + + it('works with a filename argument', function() + eq(test_source_path, exec_lua([[return vim.fs.root(..., '.git')]], nvim_prog)) + end) + end) + describe('joinpath()', function() it('works', function() eq('foo/bar/baz', vim.fs.joinpath('foo', 'bar', 'baz')) |