aboutsummaryrefslogtreecommitdiff
path: root/test/functional/plugin
diff options
context:
space:
mode:
authorEduard Baturin <trardone@gmail.com>2023-02-18 09:43:59 +0300
committerGitHub <noreply@github.com>2023-02-18 07:43:59 +0100
commitf43fa301c1a2817239e046a242902af65b7cac71 (patch)
treee6f5726770c297e2e4de71546d30f804b6708656 /test/functional/plugin
parent44da6a56ba228a97fa917e1ae76a46299b8db125 (diff)
downloadrneovim-f43fa301c1a2817239e046a242902af65b7cac71.tar.gz
rneovim-f43fa301c1a2817239e046a242902af65b7cac71.tar.bz2
rneovim-f43fa301c1a2817239e046a242902af65b7cac71.zip
fix(lsp): check if the buffer is a directory before w! it (#22289)
Diffstat (limited to 'test/functional/plugin')
-rw-r--r--test/functional/plugin/lsp_spec.lua28
1 files changed, 28 insertions, 0 deletions
diff --git a/test/functional/plugin/lsp_spec.lua b/test/functional/plugin/lsp_spec.lua
index fd162961ff..f1aad08140 100644
--- a/test/functional/plugin/lsp_spec.lua
+++ b/test/functional/plugin/lsp_spec.lua
@@ -2067,6 +2067,8 @@ describe('LSP', function()
end)
describe('lsp.util.rename', function()
+ local pathsep = helpers.get_pathsep()
+
it('Can rename an existing file', function()
local old = helpers.tmpname()
write_file(old, 'Test content')
@@ -2089,6 +2091,32 @@ describe('LSP', function()
eq(true, exists)
os.remove(new)
end)
+ it('Can rename a direcory', function()
+ -- only reserve the name, file must not exist for the test scenario
+ local old_dir = helpers.tmpname()
+ local new_dir = helpers.tmpname()
+ os.remove(old_dir)
+ os.remove(new_dir)
+
+ helpers.mkdir_p(old_dir)
+
+ local file = "file"
+ write_file(old_dir .. pathsep .. file, 'Test content')
+
+ exec_lua([[
+ local old_dir = select(1, ...)
+ local new_dir = select(2, ...)
+
+ vim.lsp.util.rename(old_dir, new_dir)
+ ]], old_dir, new_dir)
+
+ eq(false, exec_lua('return vim.loop.fs_stat(...) ~= nil', old_dir))
+ eq(true, exec_lua('return vim.loop.fs_stat(...) ~= nil', new_dir))
+ eq(true, exec_lua('return vim.loop.fs_stat(...) ~= nil', new_dir .. pathsep .. file))
+ eq('Test content', read_file(new_dir .. pathsep .. file))
+
+ os.remove(new_dir)
+ end)
it('Does not rename file if target exists and ignoreIfExists is set or overwrite is false', function()
local old = helpers.tmpname()
write_file(old, 'Old File')