2024-04-20 08:44:13 -07:00
|
|
|
local t = require('test.testutil')
|
|
|
|
local n = require('test.functional.testnvim')()
|
2022-05-15 13:38:19 -07:00
|
|
|
|
2024-04-20 08:44:13 -07:00
|
|
|
local clear = n.clear
|
|
|
|
local exec_lua = n.exec_lua
|
2024-04-08 02:03:20 -07:00
|
|
|
local eq = t.eq
|
2024-04-20 08:44:13 -07:00
|
|
|
local mkdir_p = n.mkdir_p
|
|
|
|
local rmdir = n.rmdir
|
|
|
|
local nvim_dir = n.nvim_dir
|
2024-04-24 19:43:46 -07:00
|
|
|
local command = n.command
|
|
|
|
local api = n.api
|
2024-04-08 02:03:20 -07:00
|
|
|
local test_build_dir = t.paths.test_build_dir
|
|
|
|
local test_source_path = t.paths.test_source_path
|
2024-04-20 08:44:13 -07:00
|
|
|
local nvim_prog = n.nvim_prog
|
2024-04-08 02:03:20 -07:00
|
|
|
local is_os = t.is_os
|
|
|
|
local mkdir = t.mkdir
|
2022-05-15 18:55:18 -07:00
|
|
|
|
2022-11-21 17:13:30 -07:00
|
|
|
local nvim_prog_basename = is_os('win') and 'nvim.exe' or 'nvim'
|
2022-05-15 13:38:19 -07:00
|
|
|
|
2022-12-01 08:15:05 -07:00
|
|
|
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/../',
|
2024-03-29 09:23:01 -07:00
|
|
|
'~/foo/bar\\baz',
|
2022-12-01 08:15:05 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
local tests_windows_paths = {
|
|
|
|
'c:\\usr',
|
|
|
|
'c:\\',
|
|
|
|
'c:',
|
|
|
|
'c:\\users\\foo',
|
|
|
|
'c:\\users\\foo\\bar.lua',
|
|
|
|
'c:\\users\\foo\\bar\\..\\',
|
|
|
|
}
|
|
|
|
|
2022-05-15 13:38:19 -07:00
|
|
|
before_each(clear)
|
|
|
|
|
|
|
|
describe('vim.fs', function()
|
|
|
|
describe('parents()', function()
|
|
|
|
it('works', function()
|
|
|
|
local test_dir = nvim_dir .. '/test'
|
|
|
|
mkdir_p(test_dir)
|
2024-03-25 12:06:28 -07:00
|
|
|
local dirs = {} --- @type string[]
|
2023-12-25 12:52:49 -07:00
|
|
|
for dir in vim.fs.parents(test_dir .. '/foo.txt') do
|
|
|
|
dirs[#dirs + 1] = dir
|
|
|
|
if dir == test_build_dir then
|
|
|
|
break
|
2022-05-15 13:38:19 -07:00
|
|
|
end
|
2023-12-25 12:52:49 -07:00
|
|
|
end
|
2022-05-15 13:38:19 -07:00
|
|
|
eq({ test_dir, nvim_dir, test_build_dir }, dirs)
|
|
|
|
rmdir(test_dir)
|
|
|
|
end)
|
|
|
|
end)
|
2022-05-15 18:53:23 -07:00
|
|
|
|
|
|
|
describe('dirname()', function()
|
|
|
|
it('works', function()
|
2023-12-25 12:52:49 -07:00
|
|
|
eq(test_build_dir, vim.fs.dirname(nvim_dir))
|
2022-12-01 08:15:05 -07:00
|
|
|
|
2024-03-29 09:23:01 -07:00
|
|
|
---@param paths string[]
|
|
|
|
---@param is_win? boolean
|
|
|
|
local function test_paths(paths, is_win)
|
|
|
|
local gsub = is_win and [[:gsub('\\', '/')]] or ''
|
|
|
|
local code = string.format(
|
|
|
|
[[
|
|
|
|
local path = ...
|
|
|
|
return vim.fn.fnamemodify(path,':h')%s
|
|
|
|
]],
|
|
|
|
gsub
|
|
|
|
)
|
|
|
|
|
2022-12-01 08:15:05 -07:00
|
|
|
for _, path in ipairs(paths) do
|
2024-03-29 09:23:01 -07:00
|
|
|
eq(exec_lua(code, path), vim.fs.dirname(path), path)
|
2022-12-01 08:15:05 -07:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
test_paths(test_basename_dirname_eq)
|
|
|
|
if is_os('win') then
|
2024-03-29 09:23:01 -07:00
|
|
|
test_paths(tests_windows_paths, true)
|
2022-12-01 08:15:05 -07:00
|
|
|
end
|
2022-05-15 18:53:23 -07:00
|
|
|
end)
|
|
|
|
end)
|
2022-05-15 18:55:18 -07:00
|
|
|
|
|
|
|
describe('basename()', function()
|
|
|
|
it('works', function()
|
2023-12-25 12:52:49 -07:00
|
|
|
eq(nvim_prog_basename, vim.fs.basename(nvim_prog))
|
2022-12-01 08:15:05 -07:00
|
|
|
|
2024-03-29 09:23:01 -07:00
|
|
|
---@param paths string[]
|
|
|
|
---@param is_win? boolean
|
|
|
|
local function test_paths(paths, is_win)
|
|
|
|
local gsub = is_win and [[:gsub('\\', '/')]] or ''
|
|
|
|
local code = string.format(
|
|
|
|
[[
|
|
|
|
local path = ...
|
|
|
|
return vim.fn.fnamemodify(path,':t')%s
|
|
|
|
]],
|
|
|
|
gsub
|
|
|
|
)
|
|
|
|
|
2022-12-01 08:15:05 -07:00
|
|
|
for _, path in ipairs(paths) do
|
2024-03-29 09:23:01 -07:00
|
|
|
eq(exec_lua(code, path), vim.fs.basename(path), path)
|
2022-12-01 08:15:05 -07:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
test_paths(test_basename_dirname_eq)
|
|
|
|
if is_os('win') then
|
2024-03-29 09:23:01 -07:00
|
|
|
test_paths(tests_windows_paths, true)
|
2022-12-01 08:15:05 -07:00
|
|
|
end
|
2022-05-15 18:55:18 -07:00
|
|
|
end)
|
|
|
|
end)
|
2022-05-15 19:10:12 -07:00
|
|
|
|
|
|
|
describe('dir()', function()
|
2022-12-22 07:46:07 -07:00
|
|
|
before_each(function()
|
2023-04-04 12:59:06 -07:00
|
|
|
mkdir('testd')
|
|
|
|
mkdir('testd/a')
|
|
|
|
mkdir('testd/a/b')
|
|
|
|
mkdir('testd/a/b/c')
|
2022-12-22 07:46:07 -07:00
|
|
|
end)
|
|
|
|
|
|
|
|
after_each(function()
|
|
|
|
rmdir('testd')
|
|
|
|
end)
|
|
|
|
|
2022-05-15 19:10:12 -07:00
|
|
|
it('works', function()
|
|
|
|
eq(
|
|
|
|
true,
|
|
|
|
exec_lua(
|
|
|
|
[[
|
|
|
|
local dir, nvim = ...
|
|
|
|
for name, type in vim.fs.dir(dir) do
|
|
|
|
if name == nvim and type == 'file' then
|
|
|
|
return true
|
|
|
|
end
|
|
|
|
end
|
|
|
|
return false
|
|
|
|
]],
|
|
|
|
nvim_dir,
|
|
|
|
nvim_prog_basename
|
|
|
|
)
|
2024-01-02 18:09:18 -07:00
|
|
|
)
|
2022-05-15 19:10:12 -07:00
|
|
|
end)
|
2022-12-13 06:59:31 -07:00
|
|
|
|
|
|
|
it('works with opts.depth and opts.skip', function()
|
2022-12-22 07:46:07 -07:00
|
|
|
io.open('testd/a1', 'w'):close()
|
|
|
|
io.open('testd/b1', 'w'):close()
|
|
|
|
io.open('testd/c1', 'w'):close()
|
|
|
|
io.open('testd/a/a2', 'w'):close()
|
|
|
|
io.open('testd/a/b2', 'w'):close()
|
|
|
|
io.open('testd/a/c2', 'w'):close()
|
|
|
|
io.open('testd/a/b/a3', 'w'):close()
|
|
|
|
io.open('testd/a/b/b3', 'w'):close()
|
|
|
|
io.open('testd/a/b/c3', 'w'):close()
|
|
|
|
io.open('testd/a/b/c/a4', 'w'):close()
|
|
|
|
io.open('testd/a/b/c/b4', 'w'):close()
|
|
|
|
io.open('testd/a/b/c/c4', 'w'):close()
|
2022-12-13 06:59:31 -07:00
|
|
|
|
|
|
|
local function run(dir, depth, skip)
|
|
|
|
local r = exec_lua(
|
|
|
|
[[
|
|
|
|
local dir, depth, skip = ...
|
|
|
|
local r = {}
|
|
|
|
local skip_f
|
|
|
|
if skip then
|
|
|
|
skip_f = function(n)
|
|
|
|
if vim.tbl_contains(skip or {}, n) then
|
|
|
|
return false
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
for name, type_ in vim.fs.dir(dir, { depth = depth, skip = skip_f }) do
|
|
|
|
r[name] = type_
|
|
|
|
end
|
|
|
|
return r
|
|
|
|
]],
|
|
|
|
dir,
|
|
|
|
depth,
|
|
|
|
skip
|
|
|
|
)
|
|
|
|
return r
|
|
|
|
end
|
|
|
|
|
|
|
|
local exp = {}
|
|
|
|
|
|
|
|
exp['a1'] = 'file'
|
|
|
|
exp['b1'] = 'file'
|
|
|
|
exp['c1'] = 'file'
|
|
|
|
exp['a'] = 'directory'
|
|
|
|
|
|
|
|
eq(exp, run('testd', 1))
|
|
|
|
|
|
|
|
exp['a/a2'] = 'file'
|
|
|
|
exp['a/b2'] = 'file'
|
|
|
|
exp['a/c2'] = 'file'
|
|
|
|
exp['a/b'] = 'directory'
|
|
|
|
|
|
|
|
eq(exp, run('testd', 2))
|
|
|
|
|
|
|
|
exp['a/b/a3'] = 'file'
|
|
|
|
exp['a/b/b3'] = 'file'
|
|
|
|
exp['a/b/c3'] = 'file'
|
|
|
|
exp['a/b/c'] = 'directory'
|
|
|
|
|
|
|
|
eq(exp, run('testd', 3))
|
|
|
|
eq(exp, run('testd', 999, { 'a/b/c' }))
|
|
|
|
|
|
|
|
exp['a/b/c/a4'] = 'file'
|
|
|
|
exp['a/b/c/b4'] = 'file'
|
|
|
|
exp['a/b/c/c4'] = 'file'
|
|
|
|
|
|
|
|
eq(exp, run('testd', 999))
|
|
|
|
end)
|
2022-05-15 19:10:12 -07:00
|
|
|
end)
|
2022-05-15 19:37:35 -07:00
|
|
|
|
|
|
|
describe('find()', function()
|
|
|
|
it('works', function()
|
2023-12-25 12:52:49 -07:00
|
|
|
eq(
|
|
|
|
{ test_build_dir .. '/build' },
|
|
|
|
vim.fs.find('build', { path = nvim_dir, upward = true, type = 'directory' })
|
2024-01-02 18:09:18 -07:00
|
|
|
)
|
2023-12-25 12:52:49 -07:00
|
|
|
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' }))
|
2022-05-15 19:37:35 -07:00
|
|
|
end)
|
2022-09-13 13:16:20 -07:00
|
|
|
|
|
|
|
it('accepts predicate as names', function()
|
2023-12-25 12:52:49 -07:00
|
|
|
local opts = { path = nvim_dir, upward = true, type = 'directory' }
|
|
|
|
eq(
|
|
|
|
{ test_build_dir .. '/build' },
|
|
|
|
vim.fs.find(function(x)
|
|
|
|
return x == 'build'
|
|
|
|
end, opts)
|
2024-01-02 18:09:18 -07:00
|
|
|
)
|
2023-12-25 12:52:49 -07:00
|
|
|
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)
|
2024-01-02 18:09:18 -07:00
|
|
|
)
|
2023-12-25 12:52:49 -07:00
|
|
|
|
|
|
|
opts = { path = test_source_path .. '/contrib', limit = math.huge }
|
2023-03-01 09:51:22 -07:00
|
|
|
eq(
|
|
|
|
exec_lua(
|
|
|
|
[[
|
|
|
|
local dir = ...
|
|
|
|
return vim.tbl_map(vim.fs.basename, vim.fn.glob(dir..'/contrib/*', false, true))
|
|
|
|
]],
|
|
|
|
test_source_path
|
|
|
|
),
|
2023-12-25 12:52:49 -07:00
|
|
|
vim.tbl_map(
|
|
|
|
vim.fs.basename,
|
|
|
|
vim.fs.find(function(_, d)
|
|
|
|
return d:match('[\\/]contrib$')
|
|
|
|
end, opts)
|
|
|
|
)
|
2024-01-02 18:09:18 -07:00
|
|
|
)
|
2022-09-13 13:16:20 -07:00
|
|
|
end)
|
2022-05-15 19:37:35 -07:00
|
|
|
end)
|
2022-05-17 07:49:33 -07:00
|
|
|
|
2024-04-24 19:43:46 -07:00
|
|
|
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)
|
2024-05-24 08:48:32 -07:00
|
|
|
|
|
|
|
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)
|
2024-04-24 19:43:46 -07:00
|
|
|
end)
|
|
|
|
|
2023-05-20 08:30:48 -07:00
|
|
|
describe('joinpath()', function()
|
|
|
|
it('works', function()
|
2023-12-25 12:52:49 -07:00
|
|
|
eq('foo/bar/baz', vim.fs.joinpath('foo', 'bar', 'baz'))
|
|
|
|
eq('foo/bar/baz', vim.fs.joinpath('foo', '/bar/', '/baz'))
|
2023-05-20 08:30:48 -07:00
|
|
|
end)
|
|
|
|
end)
|
|
|
|
|
2022-05-17 07:49:33 -07:00
|
|
|
describe('normalize()', function()
|
2023-06-18 04:49:33 -07:00
|
|
|
it('removes trailing /', function()
|
2023-12-25 12:52:49 -07:00
|
|
|
eq('/home/user', vim.fs.normalize('/home/user/'))
|
2023-06-18 04:49:33 -07:00
|
|
|
end)
|
|
|
|
it('works with /', function()
|
2023-12-25 12:52:49 -07:00
|
|
|
eq('/', vim.fs.normalize('/'))
|
2023-06-18 04:49:33 -07:00
|
|
|
end)
|
2022-05-17 07:49:33 -07:00
|
|
|
it('works with ~', function()
|
2024-03-25 12:06:28 -07:00
|
|
|
eq(vim.fs.normalize(assert(vim.uv.os_homedir())) .. '/src/foo', vim.fs.normalize('~/src/foo'))
|
2022-05-17 07:49:33 -07:00
|
|
|
end)
|
|
|
|
it('works with environment variables', function()
|
|
|
|
local xdg_config_home = test_build_dir .. '/.config'
|
|
|
|
eq(
|
|
|
|
xdg_config_home .. '/nvim',
|
|
|
|
exec_lua(
|
|
|
|
[[
|
|
|
|
vim.env.XDG_CONFIG_HOME = ...
|
|
|
|
return vim.fs.normalize('$XDG_CONFIG_HOME/nvim')
|
|
|
|
]],
|
|
|
|
xdg_config_home
|
|
|
|
)
|
2024-01-02 18:09:18 -07:00
|
|
|
)
|
2022-05-17 07:49:33 -07:00
|
|
|
end)
|
2024-03-29 09:23:01 -07:00
|
|
|
|
2024-04-16 12:13:44 -07:00
|
|
|
-- Opts required for testing posix paths and win paths
|
|
|
|
local posix_opts = is_os('win') and { win = false } or {}
|
|
|
|
local win_opts = is_os('win') and {} or { win = true }
|
|
|
|
|
|
|
|
it('preserves leading double slashes in POSIX paths', function()
|
|
|
|
eq('//foo', vim.fs.normalize('//foo', posix_opts))
|
|
|
|
eq('//foo/bar', vim.fs.normalize('//foo//bar////', posix_opts))
|
|
|
|
eq('/foo', vim.fs.normalize('///foo', posix_opts))
|
|
|
|
eq('//', vim.fs.normalize('//', posix_opts))
|
|
|
|
eq('/', vim.fs.normalize('///', posix_opts))
|
|
|
|
eq('/foo/bar', vim.fs.normalize('/foo//bar////', posix_opts))
|
2024-03-29 10:05:02 -07:00
|
|
|
end)
|
|
|
|
|
2024-04-16 12:13:44 -07:00
|
|
|
it('allows backslashes on unix-based os', function()
|
|
|
|
eq('/home/user/hello\\world', vim.fs.normalize('/home/user/hello\\world', posix_opts))
|
|
|
|
end)
|
|
|
|
|
|
|
|
it('preserves / after drive letters', function()
|
|
|
|
eq('C:/', vim.fs.normalize([[C:\]], win_opts))
|
|
|
|
end)
|
|
|
|
|
|
|
|
it('works with UNC and DOS device paths', function()
|
|
|
|
eq('//server/share/foo/bar', vim.fs.normalize([[\\server\\share\\\foo\bar\\\]], win_opts))
|
|
|
|
eq('//system07/C$/', vim.fs.normalize([[\\system07\C$\\\\]], win_opts))
|
|
|
|
eq('//./C:/foo/bar', vim.fs.normalize([[\\.\\C:\foo\\\\bar]], win_opts))
|
|
|
|
eq('//?/C:/foo/bar', vim.fs.normalize([[\\?\C:\\\foo\bar\\\\]], win_opts))
|
|
|
|
eq(
|
|
|
|
'//?/UNC/server/share/foo/bar',
|
|
|
|
vim.fs.normalize([[\\?\UNC\server\\\share\\\\foo\\\bar]], win_opts)
|
|
|
|
)
|
|
|
|
eq('//./BootPartition/foo/bar', vim.fs.normalize([[\\.\BootPartition\\foo\bar]], win_opts))
|
|
|
|
eq(
|
|
|
|
'//./Volume{12345678-1234-1234-1234-1234567890AB}/foo/bar',
|
|
|
|
vim.fs.normalize([[\\.\Volume{12345678-1234-1234-1234-1234567890AB}\\\foo\bar\\]], win_opts)
|
|
|
|
)
|
|
|
|
end)
|
|
|
|
|
|
|
|
it('handles invalid UNC and DOS device paths', function()
|
|
|
|
eq('//server/share', vim.fs.normalize([[\\server\share]], win_opts))
|
|
|
|
eq('//server/', vim.fs.normalize([[\\server\]], win_opts))
|
|
|
|
eq('//./UNC/server/share', vim.fs.normalize([[\\.\UNC\server\share]], win_opts))
|
|
|
|
eq('//?/UNC/server/', vim.fs.normalize([[\\?\UNC\server\]], win_opts))
|
|
|
|
eq('//?/UNC/server/..', vim.fs.normalize([[\\?\UNC\server\..]], win_opts))
|
|
|
|
eq('//./', vim.fs.normalize([[\\.\]], win_opts))
|
|
|
|
eq('//./foo', vim.fs.normalize([[\\.\foo]], win_opts))
|
|
|
|
eq('//./BootPartition', vim.fs.normalize([[\\.\BootPartition]], win_opts))
|
|
|
|
end)
|
|
|
|
|
|
|
|
it('converts backward slashes', function()
|
|
|
|
eq('C:/Users/jdoe', vim.fs.normalize([[C:\Users\jdoe]], win_opts))
|
|
|
|
end)
|
|
|
|
|
|
|
|
describe('. and .. component resolving', function()
|
|
|
|
it('works', function()
|
|
|
|
-- Windows paths
|
|
|
|
eq('C:/Users', vim.fs.normalize([[C:\Users\jdoe\Downloads\.\..\..\]], win_opts))
|
|
|
|
eq('C:/Users/jdoe', vim.fs.normalize([[C:\Users\jdoe\Downloads\.\..\.\.\]], win_opts))
|
|
|
|
eq('C:/', vim.fs.normalize('C:/Users/jdoe/Downloads/./../../../', win_opts))
|
|
|
|
eq('C:foo', vim.fs.normalize([[C:foo\bar\.\..\.]], win_opts))
|
|
|
|
-- POSIX paths
|
|
|
|
eq('/home', vim.fs.normalize('/home/jdoe/Downloads/./../..', posix_opts))
|
|
|
|
eq('/home/jdoe', vim.fs.normalize('/home/jdoe/Downloads/./../././', posix_opts))
|
|
|
|
eq('/', vim.fs.normalize('/home/jdoe/Downloads/./../../../', posix_opts))
|
|
|
|
-- OS-agnostic relative paths
|
|
|
|
eq('foo/bar/baz', vim.fs.normalize('foo/bar/foobar/../baz/./'))
|
|
|
|
eq('foo/bar', vim.fs.normalize('foo/bar/foobar/../baz/./../../bar/./.'))
|
2023-07-17 23:36:04 -07:00
|
|
|
end)
|
2024-04-16 12:13:44 -07:00
|
|
|
|
|
|
|
it('works when relative path reaches current directory', function()
|
|
|
|
eq('C:', vim.fs.normalize('C:foo/bar/../../.', win_opts))
|
|
|
|
|
|
|
|
eq('.', vim.fs.normalize('.'))
|
|
|
|
eq('.', vim.fs.normalize('././././'))
|
|
|
|
eq('.', vim.fs.normalize('foo/bar/../../.'))
|
2024-03-29 09:23:01 -07:00
|
|
|
end)
|
2024-04-16 12:13:44 -07:00
|
|
|
|
|
|
|
it('works when relative path goes outside current directory', function()
|
|
|
|
eq('../../foo/bar', vim.fs.normalize('../../foo/bar'))
|
|
|
|
eq('../foo', vim.fs.normalize('foo/bar/../../../foo'))
|
|
|
|
|
|
|
|
eq('C:../foo', vim.fs.normalize('C:../foo', win_opts))
|
|
|
|
eq('C:../../foo/bar', vim.fs.normalize('C:foo/../../../foo/bar', win_opts))
|
2024-03-29 09:23:01 -07:00
|
|
|
end)
|
2024-04-16 12:13:44 -07:00
|
|
|
|
|
|
|
it('.. in root directory resolves to itself', function()
|
|
|
|
eq('C:/', vim.fs.normalize('C:/../../', win_opts))
|
|
|
|
eq('C:/foo', vim.fs.normalize('C:/foo/../../foo', win_opts))
|
|
|
|
|
|
|
|
eq('//server/share/', vim.fs.normalize([[\\server\share\..\..]], win_opts))
|
|
|
|
eq('//server/share/foo', vim.fs.normalize([[\\server\\share\foo\..\..\foo]], win_opts))
|
|
|
|
|
|
|
|
eq('//./C:/', vim.fs.normalize([[\\.\C:\..\..]], win_opts))
|
|
|
|
eq('//?/C:/foo', vim.fs.normalize([[\\?\C:\..\..\foo]], win_opts))
|
|
|
|
|
|
|
|
eq('//./UNC/server/share/', vim.fs.normalize([[\\.\UNC\\server\share\..\..\]], win_opts))
|
|
|
|
eq(
|
|
|
|
'//?/UNC/server/share/foo',
|
|
|
|
vim.fs.normalize([[\\?\UNC\server\\share\..\..\foo]], win_opts)
|
|
|
|
)
|
|
|
|
|
|
|
|
eq('//?/BootPartition/', vim.fs.normalize([[\\?\BootPartition\..\..]], win_opts))
|
|
|
|
eq('//./BootPartition/foo', vim.fs.normalize([[\\.\BootPartition\..\..\foo]], win_opts))
|
|
|
|
|
|
|
|
eq('/', vim.fs.normalize('/../../', posix_opts))
|
|
|
|
eq('/foo', vim.fs.normalize('/foo/../../foo', posix_opts))
|
|
|
|
end)
|
|
|
|
end)
|
2022-05-17 07:49:33 -07:00
|
|
|
end)
|
2022-05-15 13:38:19 -07:00
|
|
|
end)
|