aboutsummaryrefslogtreecommitdiff
path: root/test/functional/lua/fs_spec.lua
diff options
context:
space:
mode:
authorGregory Anders <8965202+gpanders@users.noreply.github.com>2024-05-24 10:48:32 -0500
committerGitHub <noreply@github.com>2024-05-24 10:48:32 -0500
commit206f8f24a2470f961cfe7e7c177443c0f199231c (patch)
treefa4f59e706ba64b511a105135be5312bd21e37b0 /test/functional/lua/fs_spec.lua
parente71713ba2b5cb4e3b725d162b2dd43e35975eead (diff)
downloadrneovim-206f8f24a2470f961cfe7e7c177443c0f199231c.tar.gz
rneovim-206f8f24a2470f961cfe7e7c177443c0f199231c.tar.bz2
rneovim-206f8f24a2470f961cfe7e7c177443c0f199231c.zip
fix(fs): make vim.fs.root work for relative paths and unnamed buffers (#28964)
If a buffer does not have a backing file then fall back to the current working directory.
Diffstat (limited to 'test/functional/lua/fs_spec.lua')
-rw-r--r--test/functional/lua/fs_spec.lua19
1 files changed, 19 insertions, 0 deletions
diff --git a/test/functional/lua/fs_spec.lua b/test/functional/lua/fs_spec.lua
index b651297db3..aba02ab01b 100644
--- a/test/functional/lua/fs_spec.lua
+++ b/test/functional/lua/fs_spec.lua
@@ -310,6 +310,25 @@ describe('vim.fs', function()
it('works with a filename argument', function()
eq(test_source_path, exec_lua([[return vim.fs.root(..., '.git')]], nvim_prog))
end)
+
+ it('works with a relative path', function()
+ eq(
+ test_source_path,
+ exec_lua([[return vim.fs.root(..., '.git')]], vim.fs.basename(nvim_prog))
+ )
+ end)
+
+ it('uses cwd for unnamed buffers', function()
+ command('new')
+ eq(test_source_path, exec_lua([[return vim.fs.root(0, '.git')]]))
+ end)
+
+ it("uses cwd for buffers with non-empty 'buftype'", function()
+ command('new')
+ command('set buftype=nofile')
+ command('file lua://')
+ eq(test_source_path, exec_lua([[return vim.fs.root(0, '.git')]]))
+ end)
end)
describe('joinpath()', function()