2024-04-20 08:44:13 -07:00
|
|
|
|
local t = require('test.testutil')
|
|
|
|
|
local n = require('test.functional.testnvim')()
|
|
|
|
|
|
|
|
|
|
local clear = n.clear
|
|
|
|
|
local command = n.command
|
2024-04-08 02:03:20 -07:00
|
|
|
|
local eq = t.eq
|
2024-04-20 08:44:13 -07:00
|
|
|
|
local eval = n.eval
|
|
|
|
|
local feed = n.feed
|
|
|
|
|
local fn = n.fn
|
|
|
|
|
local insert = n.insert
|
2024-04-08 02:03:20 -07:00
|
|
|
|
local is_os = t.is_os
|
|
|
|
|
local mkdir = t.mkdir
|
2024-04-20 08:44:13 -07:00
|
|
|
|
local rmdir = n.rmdir
|
2024-04-08 02:03:20 -07:00
|
|
|
|
local write_file = t.write_file
|
2023-10-03 15:04:19 -07:00
|
|
|
|
|
|
|
|
|
local function join_path(...)
|
|
|
|
|
local pathsep = (is_os('win') and '\\' or '/')
|
|
|
|
|
return table.concat({ ... }, pathsep)
|
|
|
|
|
end
|
2017-09-18 11:06:55 -07:00
|
|
|
|
|
2017-10-01 15:24:19 -07:00
|
|
|
|
describe('path collapse', function()
|
2017-09-18 11:06:55 -07:00
|
|
|
|
local targetdir
|
|
|
|
|
local expected_path
|
|
|
|
|
|
|
|
|
|
before_each(function()
|
|
|
|
|
targetdir = join_path('test', 'functional', 'fixtures')
|
2017-10-01 15:24:19 -07:00
|
|
|
|
clear()
|
|
|
|
|
command('edit ' .. join_path(targetdir, 'tty-test.c'))
|
|
|
|
|
expected_path = eval('expand("%:p")')
|
2017-09-18 11:06:55 -07:00
|
|
|
|
end)
|
|
|
|
|
|
2017-10-01 15:24:19 -07:00
|
|
|
|
it('with /./ segment #7117', function()
|
|
|
|
|
command('edit ' .. join_path(targetdir, '.', 'tty-test.c'))
|
|
|
|
|
eq(expected_path, eval('expand("%:p")'))
|
2017-09-18 11:06:55 -07:00
|
|
|
|
end)
|
|
|
|
|
|
2017-10-01 15:24:19 -07:00
|
|
|
|
it('with ./ prefix #7117', function()
|
|
|
|
|
command('edit ' .. join_path('.', targetdir, 'tty-test.c'))
|
|
|
|
|
eq(expected_path, eval('expand("%:p")'))
|
2017-09-18 11:06:55 -07:00
|
|
|
|
end)
|
|
|
|
|
|
2017-10-01 15:24:19 -07:00
|
|
|
|
it('with ./ prefix, after directory change #7117', function()
|
|
|
|
|
command('edit ' .. join_path('.', targetdir, 'tty-test.c'))
|
2017-09-18 11:06:55 -07:00
|
|
|
|
command('cd test')
|
2017-10-01 15:24:19 -07:00
|
|
|
|
eq(expected_path, eval('expand("%:p")'))
|
2017-09-18 11:06:55 -07:00
|
|
|
|
end)
|
|
|
|
|
|
2017-10-01 15:24:19 -07:00
|
|
|
|
it('with /../ segment #7117', function()
|
|
|
|
|
command('edit ' .. join_path(targetdir, '..', 'fixtures', 'tty-test.c'))
|
|
|
|
|
eq(expected_path, eval('expand("%:p")'))
|
2017-09-18 11:06:55 -07:00
|
|
|
|
end)
|
|
|
|
|
|
2017-10-01 15:24:19 -07:00
|
|
|
|
it('with ../ and different starting directory #7117', function()
|
2017-09-18 11:06:55 -07:00
|
|
|
|
command('cd test')
|
2017-10-01 15:24:19 -07:00
|
|
|
|
command('edit ' .. join_path('..', targetdir, 'tty-test.c'))
|
|
|
|
|
eq(expected_path, eval('expand("%:p")'))
|
2017-09-18 11:06:55 -07:00
|
|
|
|
end)
|
|
|
|
|
|
2017-10-01 15:24:19 -07:00
|
|
|
|
it('with ./../ and different starting directory #7117', function()
|
2017-09-18 11:06:55 -07:00
|
|
|
|
command('cd test')
|
2017-10-01 15:24:19 -07:00
|
|
|
|
command('edit ' .. join_path('.', '..', targetdir, 'tty-test.c'))
|
|
|
|
|
eq(expected_path, eval('expand("%:p")'))
|
2017-09-18 11:06:55 -07:00
|
|
|
|
end)
|
|
|
|
|
end)
|
2022-10-06 18:43:16 -07:00
|
|
|
|
|
2023-10-03 15:04:19 -07:00
|
|
|
|
describe('expand wildcard', function()
|
|
|
|
|
before_each(clear)
|
|
|
|
|
|
|
|
|
|
it('with special characters #24421', function()
|
|
|
|
|
local folders = is_os('win') and {
|
|
|
|
|
'{folder}',
|
|
|
|
|
'folder$name',
|
|
|
|
|
} or {
|
|
|
|
|
'folder-name',
|
|
|
|
|
'folder#name',
|
|
|
|
|
}
|
|
|
|
|
for _, folder in ipairs(folders) do
|
|
|
|
|
mkdir(folder)
|
|
|
|
|
local file = join_path(folder, 'file.txt')
|
|
|
|
|
write_file(file, '')
|
|
|
|
|
eq(file, eval('expand("' .. folder .. '/*")'))
|
|
|
|
|
rmdir(folder)
|
|
|
|
|
end
|
|
|
|
|
end)
|
|
|
|
|
end)
|
|
|
|
|
|
2023-10-12 07:04:16 -07:00
|
|
|
|
describe('file search', function()
|
|
|
|
|
local testdir = 'Xtest_path_spec'
|
|
|
|
|
|
2022-10-06 18:43:16 -07:00
|
|
|
|
before_each(clear)
|
|
|
|
|
|
2023-10-12 07:04:16 -07:00
|
|
|
|
setup(function()
|
|
|
|
|
mkdir(testdir)
|
|
|
|
|
end)
|
|
|
|
|
|
|
|
|
|
teardown(function()
|
|
|
|
|
rmdir(testdir)
|
|
|
|
|
end)
|
|
|
|
|
|
|
|
|
|
it('gf finds multibyte filename in line #20517', function()
|
2022-10-06 18:43:16 -07:00
|
|
|
|
command('cd test/functional/fixtures')
|
|
|
|
|
insert('filename_with_unicode_ααα')
|
|
|
|
|
eq('', eval('expand("%")'))
|
|
|
|
|
feed('gf')
|
|
|
|
|
eq('filename_with_unicode_ααα', eval('expand("%:t")'))
|
|
|
|
|
end)
|
2023-09-18 12:50:47 -07:00
|
|
|
|
|
2023-10-12 07:04:16 -07:00
|
|
|
|
it('gf/<cfile> matches Windows drive-letter filepaths (without ":" in &isfname)', function()
|
2023-10-06 03:59:39 -07:00
|
|
|
|
local iswin = is_os('win')
|
|
|
|
|
local function test_cfile(input, expected, expected_win)
|
|
|
|
|
expected = (iswin and expected_win or expected) or input
|
|
|
|
|
command('%delete')
|
|
|
|
|
insert(input)
|
|
|
|
|
command('norm! 0')
|
|
|
|
|
eq(expected, eval('expand("<cfile>")'))
|
|
|
|
|
end
|
2023-09-18 12:50:47 -07:00
|
|
|
|
|
2023-10-06 03:59:39 -07:00
|
|
|
|
test_cfile([[c:/d:/foo/bar.txt]]) -- TODO(justinmk): should return "d:/foo/bar.txt" ?
|
|
|
|
|
test_cfile([[//share/c:/foo/bar/]])
|
|
|
|
|
test_cfile([[file://c:/foo/bar]])
|
|
|
|
|
test_cfile([[file://c:/foo/bar:42]])
|
|
|
|
|
test_cfile([[file://c:/foo/bar:42:666]])
|
|
|
|
|
test_cfile([[https://c:/foo/bar]])
|
|
|
|
|
test_cfile([[\foo\bar]], [[foo]], [[\foo\bar]])
|
|
|
|
|
test_cfile([[/foo/bar]], [[/foo/bar]])
|
|
|
|
|
test_cfile([[c:\foo\bar]], [[c:]], [[c:\foo\bar]])
|
|
|
|
|
test_cfile([[c:\foo\bar:42:666]], [[c:]], [[c:\foo\bar]])
|
|
|
|
|
test_cfile([[c:/foo/bar]])
|
|
|
|
|
test_cfile([[c:/foo/bar:42]], [[c:/foo/bar]])
|
|
|
|
|
test_cfile([[c:/foo/bar:42:666]], [[c:/foo/bar]])
|
|
|
|
|
test_cfile([[c:foo\bar]], [[c]])
|
|
|
|
|
test_cfile([[c:foo/bar]], [[c]])
|
|
|
|
|
test_cfile([[c:foo]], [[c]])
|
2023-09-18 12:50:47 -07:00
|
|
|
|
-- Examples from: https://learn.microsoft.com/en-us/dotnet/standard/io/file-path-formats#example-ways-to-refer-to-the-same-file
|
2023-10-06 03:59:39 -07:00
|
|
|
|
test_cfile([[c:\temp\test-file.txt]], [[c:]], [[c:\temp\test-file.txt]])
|
|
|
|
|
test_cfile(
|
|
|
|
|
[[\\127.0.0.1\c$\temp\test-file.txt]],
|
|
|
|
|
[[127.0.0.1]],
|
|
|
|
|
[[\\127.0.0.1\c$\temp\test-file.txt]]
|
|
|
|
|
)
|
|
|
|
|
test_cfile(
|
|
|
|
|
[[\\LOCALHOST\c$\temp\test-file.txt]],
|
|
|
|
|
[[LOCALHOST]],
|
|
|
|
|
[[\\LOCALHOST\c$\temp\test-file.txt]]
|
|
|
|
|
)
|
|
|
|
|
-- not supported yet
|
|
|
|
|
test_cfile([[\\.\c:\temp\test-file.txt]], [[.]], [[\\.\c]])
|
|
|
|
|
-- not supported yet
|
|
|
|
|
test_cfile([[\\?\c:\temp\test-file.txt]], [[c:]], [[\\]])
|
|
|
|
|
test_cfile(
|
|
|
|
|
[[\\.\UNC\LOCALHOST\c$\temp\test-file.txt]],
|
|
|
|
|
[[.]],
|
|
|
|
|
[[\\.\UNC\LOCALHOST\c$\temp\test-file.txt]]
|
|
|
|
|
)
|
|
|
|
|
test_cfile(
|
|
|
|
|
[[\\127.0.0.1\c$\temp\test-file.txt]],
|
|
|
|
|
[[127.0.0.1]],
|
|
|
|
|
[[\\127.0.0.1\c$\temp\test-file.txt]]
|
|
|
|
|
)
|
2023-09-18 12:50:47 -07:00
|
|
|
|
end)
|
2023-10-09 15:08:58 -07:00
|
|
|
|
|
2023-10-12 07:04:16 -07:00
|
|
|
|
---@param funcname 'finddir' | 'findfile'
|
|
|
|
|
local function test_find_func(funcname, folder, item)
|
|
|
|
|
local d = join_path(testdir, folder)
|
|
|
|
|
mkdir(d)
|
|
|
|
|
local expected = join_path(d, item)
|
|
|
|
|
if funcname == 'finddir' then
|
2023-10-09 15:08:58 -07:00
|
|
|
|
mkdir(expected)
|
|
|
|
|
else
|
|
|
|
|
write_file(expected, '')
|
|
|
|
|
end
|
2024-01-12 10:59:57 -07:00
|
|
|
|
eq(expected, fn[funcname](item, d:gsub(' ', [[\ ]])))
|
2023-10-09 15:08:58 -07:00
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
it('finddir()', function()
|
2023-10-12 07:04:16 -07:00
|
|
|
|
test_find_func('finddir', 'directory', 'folder')
|
|
|
|
|
test_find_func('finddir', 'directory', 'folder name')
|
|
|
|
|
test_find_func('finddir', 'fold#er name', 'directory')
|
2023-10-09 15:08:58 -07:00
|
|
|
|
end)
|
|
|
|
|
|
|
|
|
|
it('findfile()', function()
|
2023-10-12 07:04:16 -07:00
|
|
|
|
test_find_func('findfile', 'directory', 'file.txt')
|
|
|
|
|
test_find_func('findfile', 'directory', 'file name.txt')
|
|
|
|
|
test_find_func('findfile', 'fold#er name', 'file.txt')
|
2023-10-09 15:08:58 -07:00
|
|
|
|
end)
|
|
|
|
|
end)
|