aboutsummaryrefslogtreecommitdiff
path: root/test/functional/lua/fs_spec.lua
diff options
context:
space:
mode:
Diffstat (limited to 'test/functional/lua/fs_spec.lua')
-rw-r--r--test/functional/lua/fs_spec.lua188
1 files changed, 96 insertions, 92 deletions
diff --git a/test/functional/lua/fs_spec.lua b/test/functional/lua/fs_spec.lua
index 6bdb9ed79d..6821fe3c5e 100644
--- a/test/functional/lua/fs_spec.lua
+++ b/test/functional/lua/fs_spec.lua
@@ -1,5 +1,4 @@
local helpers = require('test.functional.helpers')(after_each)
-local uv = require('luv')
local clear = helpers.clear
local exec_lua = helpers.exec_lua
@@ -7,8 +6,8 @@ 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
-local test_source_path = helpers.test_source_path
+local test_build_dir = helpers.paths.test_build_dir
+local test_source_path = helpers.paths.test_source_path
local nvim_prog = helpers.nvim_prog
local is_os = helpers.is_os
local mkdir = helpers.mkdir
@@ -55,40 +54,33 @@ describe('vim.fs', 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
+ 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
- return dirs
- ]], test_dir, test_build_dir)
- eq({test_dir, nvim_dir, test_build_dir}, dirs)
+ end
+ eq({ test_dir, nvim_dir, test_build_dir }, dirs)
rmdir(test_dir)
end)
end)
describe('dirname()', function()
it('works', function()
- eq(test_build_dir, exec_lua([[
- local nvim_dir = ...
- return vim.fs.dirname(nvim_dir)
- ]], nvim_dir))
+ eq(test_build_dir, vim.fs.dirname(nvim_dir))
local function test_paths(paths)
for _, path in ipairs(paths) do
eq(
- exec_lua([[
+ exec_lua(
+ [[
local path = ...
return vim.fn.fnamemodify(path,':h'):gsub('\\', '/')
- ]], path),
- exec_lua([[
- local path = ...
- return vim.fs.dirname(path)
- ]], path),
+ ]],
+ path
+ ),
+ vim.fs.dirname(path),
path
)
end
@@ -103,23 +95,19 @@ describe('vim.fs', function()
describe('basename()', function()
it('works', function()
-
- eq(nvim_prog_basename, exec_lua([[
- local nvim_prog = ...
- return vim.fs.basename(nvim_prog)
- ]], nvim_prog))
+ eq(nvim_prog_basename, vim.fs.basename(nvim_prog))
local function test_paths(paths)
for _, path in ipairs(paths) do
eq(
- exec_lua([[
+ exec_lua(
+ [[
local path = ...
return vim.fn.fnamemodify(path,':t'):gsub('\\', '/')
- ]], path),
- exec_lua([[
- local path = ...
- return vim.fs.basename(path)
- ]], path),
+ ]],
+ path
+ ),
+ vim.fs.basename(path),
path
)
end
@@ -145,7 +133,10 @@ describe('vim.fs', function()
end)
it('works', function()
- eq(true, exec_lua([[
+ eq(
+ true,
+ exec_lua(
+ [[
local dir, nvim = ...
for name, type in vim.fs.dir(dir) do
if name == nvim and type == 'file' then
@@ -153,7 +144,11 @@ describe('vim.fs', function()
end
end
return false
- ]], nvim_dir, nvim_prog_basename))
+ ]],
+ nvim_dir,
+ nvim_prog_basename
+ )
+ )
end)
it('works with opts.depth and opts.skip', function()
@@ -171,7 +166,8 @@ describe('vim.fs', function()
io.open('testd/a/b/c/c4', 'w'):close()
local function run(dir, depth, skip)
- local r = exec_lua([[
+ local r = exec_lua(
+ [[
local dir, depth, skip = ...
local r = {}
local skip_f
@@ -186,7 +182,11 @@ describe('vim.fs', function()
r[name] = type_
end
return r
- ]], dir, depth, skip)
+ ]],
+ dir,
+ depth,
+ skip
+ )
return r
end
@@ -212,7 +212,7 @@ describe('vim.fs', function()
exp['a/b/c'] = 'directory'
eq(exp, run('testd', 3))
- eq(exp, run('testd', 999, {'a/b/c'}))
+ eq(exp, run('testd', 999, { 'a/b/c' }))
exp['a/b/c/a4'] = 'file'
exp['a/b/c/b4'] = 'file'
@@ -224,88 +224,92 @@ describe('vim.fs', function()
describe('find()', function()
it('works', function()
- eq({test_build_dir .. "/build"}, exec_lua([[
- local dir = ...
- return vim.fs.find('build', { path = dir, upward = true, type = 'directory' })
- ]], nvim_dir))
- eq({nvim_prog}, exec_lua([[
- local dir, nvim = ...
- return vim.fs.find(nvim, { path = dir, type = 'file' })
- ]], test_build_dir, nvim_prog_basename))
- eq({nvim_dir}, exec_lua([[
- local dir = ...
- local parent, name = dir:match('^(.*/)([^/]+)$')
- return vim.fs.find(name, { path = parent, upward = true, type = 'directory' })
- ]], nvim_dir))
+ eq(
+ { test_build_dir .. '/build' },
+ vim.fs.find('build', { path = nvim_dir, upward = true, type = 'directory' })
+ )
+ eq({ nvim_prog }, vim.fs.find(nvim_prog_basename, { path = test_build_dir, type = 'file' }))
+
+ local parent, name = nvim_dir:match('^(.*/)([^/]+)$')
+ eq({ nvim_dir }, vim.fs.find(name, { path = parent, upward = true, type = 'directory' }))
end)
it('accepts predicate as names', function()
- eq({test_build_dir .. "/build"}, exec_lua([[
- local dir = ...
- local opts = { path = dir, upward = true, type = 'directory' }
- return vim.fs.find(function(x) return x == 'build' end, opts)
- ]], nvim_dir))
- eq({nvim_prog}, exec_lua([[
- local dir, nvim = ...
- return vim.fs.find(function(x) return x == nvim end, { path = dir, type = 'file' })
- ]], test_build_dir, nvim_prog_basename))
- eq({}, exec_lua([[
- local dir = ...
- local opts = { path = dir, upward = true, type = 'directory' }
- return vim.fs.find(function(x) return x == 'no-match' end, opts)
- ]], nvim_dir))
+ local opts = { path = nvim_dir, upward = true, type = 'directory' }
+ eq(
+ { test_build_dir .. '/build' },
+ vim.fs.find(function(x)
+ return x == 'build'
+ end, opts)
+ )
+ eq(
+ { nvim_prog },
+ vim.fs.find(function(x)
+ return x == nvim_prog_basename
+ end, { path = test_build_dir, type = 'file' })
+ )
+ eq(
+ {},
+ vim.fs.find(function(x)
+ return x == 'no-match'
+ end, opts)
+ )
+
+ opts = { path = test_source_path .. '/contrib', limit = math.huge }
eq(
- exec_lua([[
+ exec_lua(
+ [[
local dir = ...
return vim.tbl_map(vim.fs.basename, vim.fn.glob(dir..'/contrib/*', false, true))
- ]], test_source_path),
- exec_lua([[
- local dir = ...
- local opts = { path = dir .. "/contrib", limit = math.huge }
- return vim.tbl_map(vim.fs.basename, vim.fs.find(function(_, d) return d:match('[\\/]contrib$') end, opts))
- ]], test_source_path))
+ ]],
+ test_source_path
+ ),
+ vim.tbl_map(
+ vim.fs.basename,
+ vim.fs.find(function(_, d)
+ return d:match('[\\/]contrib$')
+ end, opts)
+ )
+ )
end)
end)
describe('joinpath()', function()
it('works', function()
- eq('foo/bar/baz', exec_lua([[
- return vim.fs.joinpath('foo', 'bar', 'baz')
- ]], nvim_dir))
- eq('foo/bar/baz', exec_lua([[
- return vim.fs.joinpath('foo', '/bar/', '/baz')
- ]], nvim_dir))
+ eq('foo/bar/baz', vim.fs.joinpath('foo', 'bar', 'baz'))
+ eq('foo/bar/baz', vim.fs.joinpath('foo', '/bar/', '/baz'))
end)
end)
describe('normalize()', function()
it('works with backward slashes', function()
- eq('C:/Users/jdoe', exec_lua [[ return vim.fs.normalize('C:\\Users\\jdoe') ]])
+ eq('C:/Users/jdoe', vim.fs.normalize('C:\\Users\\jdoe'))
end)
it('removes trailing /', function()
- eq('/home/user', exec_lua [[ return vim.fs.normalize('/home/user/') ]])
+ eq('/home/user', vim.fs.normalize('/home/user/'))
end)
it('works with /', function()
- eq('/', exec_lua [[ return vim.fs.normalize('/') ]])
+ eq('/', vim.fs.normalize('/'))
end)
it('works with ~', function()
- eq(
- exec_lua([[
- local home = ...
- return home .. '/src/foo'
- ]], vim.fs.normalize(uv.os_homedir())),
- exec_lua [[ return vim.fs.normalize('~/src/foo') ]])
+ eq(vim.fs.normalize(vim.uv.os_homedir()) .. '/src/foo', vim.fs.normalize('~/src/foo'))
end)
it('works with environment variables', function()
local xdg_config_home = test_build_dir .. '/.config'
- eq(xdg_config_home .. '/nvim', exec_lua([[
+ eq(
+ xdg_config_home .. '/nvim',
+ exec_lua(
+ [[
vim.env.XDG_CONFIG_HOME = ...
return vim.fs.normalize('$XDG_CONFIG_HOME/nvim')
- ]], xdg_config_home))
+ ]],
+ xdg_config_home
+ )
+ )
end)
if is_os('win') then
it('Last slash is not truncated from root drive', function()
- eq('C:/', exec_lua [[ return vim.fs.normalize('C:/') ]])
+ eq('C:/', vim.fs.normalize('C:/'))
end)
end
end)