aboutsummaryrefslogtreecommitdiff
path: root/test/functional/lua/fs_spec.lua
diff options
context:
space:
mode:
authorMike <Mike325@users.noreply.github.com>2022-12-01 09:15:05 -0600
committerGitHub <noreply@github.com>2022-12-01 08:15:05 -0700
commit61e99217e68498e757b9f8b0c70978a9635ccbfa (patch)
treecdb02906ae6c7a5d2d5bb89225252e79e8e0f43c /test/functional/lua/fs_spec.lua
parentadda751407df6d9fcb9f2cf1dade0c713924e20a (diff)
downloadrneovim-61e99217e68498e757b9f8b0c70978a9635ccbfa.tar.gz
rneovim-61e99217e68498e757b9f8b0c70978a9635ccbfa.tar.bz2
rneovim-61e99217e68498e757b9f8b0c70978a9635ccbfa.zip
refactor(fs): replace vim.fn/vim.env in vim.fs (#20379)
Avoid using vim.env and vim.fn in vim.fs functions so that they can be used in "fast" contexts.
Diffstat (limited to 'test/functional/lua/fs_spec.lua')
-rw-r--r--test/functional/lua/fs_spec.lua76
1 files changed, 76 insertions, 0 deletions
diff --git a/test/functional/lua/fs_spec.lua b/test/functional/lua/fs_spec.lua
index fc228e54bc..88ad6ba24a 100644
--- a/test/functional/lua/fs_spec.lua
+++ b/test/functional/lua/fs_spec.lua
@@ -12,6 +12,39 @@ local is_os = helpers.is_os
local nvim_prog_basename = is_os('win') and 'nvim.exe' or 'nvim'
+local test_basename_dirname_eq = {
+ '~/foo/',
+ '~/foo',
+ '~/foo/bar.lua',
+ 'foo.lua',
+ ' ',
+ '',
+ '.',
+ '..',
+ '../',
+ '~',
+ '/usr/bin',
+ '/usr/bin/gcc',
+ '/',
+ '/usr/',
+ '/usr',
+ 'c:/usr',
+ 'c:/',
+ 'c:',
+ 'c:/users/foo',
+ 'c:/users/foo/bar.lua',
+ 'c:/users/foo/bar/../',
+}
+
+local tests_windows_paths = {
+ 'c:\\usr',
+ 'c:\\',
+ 'c:',
+ 'c:\\users\\foo',
+ 'c:\\users\\foo\\bar.lua',
+ 'c:\\users\\foo\\bar\\..\\',
+}
+
before_each(clear)
describe('vim.fs', function()
@@ -41,15 +74,58 @@ describe('vim.fs', function()
local nvim_dir = ...
return vim.fs.dirname(nvim_dir)
]], nvim_dir))
+
+ local function test_paths(paths)
+ for _, path in ipairs(paths) do
+ eq(
+ exec_lua([[
+ local path = ...
+ return vim.fn.fnamemodify(path,':h'):gsub('\\', '/')
+ ]], path),
+ exec_lua([[
+ local path = ...
+ return vim.fs.dirname(path)
+ ]], path),
+ path
+ )
+ end
+ end
+
+ test_paths(test_basename_dirname_eq)
+ if is_os('win') then
+ test_paths(tests_windows_paths)
+ end
end)
end)
describe('basename()', function()
it('works', function()
+
eq(nvim_prog_basename, exec_lua([[
local nvim_prog = ...
return vim.fs.basename(nvim_prog)
]], nvim_prog))
+
+ local function test_paths(paths)
+ for _, path in ipairs(paths) do
+ eq(
+ exec_lua([[
+ local path = ...
+ return vim.fn.fnamemodify(path,':t'):gsub('\\', '/')
+ ]], path),
+ exec_lua([[
+ local path = ...
+ return vim.fs.basename(path)
+ ]], path),
+ path
+ )
+ end
+ end
+
+ test_paths(test_basename_dirname_eq)
+ if is_os('win') then
+ test_paths(tests_windows_paths)
+ end
end)
end)