mirror of
https://github.com/neovim/neovim.git
synced 2026-08-29 18:41:48 +00:00
feat(vim.fs): abspath({cwd, plain}) #40597
Adds optional parameters to `vim.fs.abspath`: 1. `cwd` to specify directory akin to `--relative-from` in `realpath(1)`. 2. `plain` disables expansion of tilde (~) in paths.
This commit is contained in:
@@ -852,17 +852,31 @@ describe('vim.fs', function()
|
||||
eq([[C:/foo]], vim.fs.abspath([[C:\foo]]))
|
||||
eq([[C:/foo/../.]], vim.fs.abspath([[C:\foo\..\.]]))
|
||||
eq('//foo/bar', vim.fs.abspath('\\\\foo\\bar'))
|
||||
eq('//foo/bar', vim.fs.abspath('\\\\foo\\bar'))
|
||||
else
|
||||
eq('/foo/../.', vim.fs.abspath('/foo/../.'))
|
||||
eq('/foo/bar', vim.fs.abspath('/foo/bar'))
|
||||
end
|
||||
end)
|
||||
|
||||
it('with `cwd`', function()
|
||||
local parent_cwd = vim.fs.dirname(cwd)
|
||||
eq(parent_cwd, vim.fs.abspath('.', { cwd = parent_cwd }))
|
||||
eq(parent_cwd .. '/foo', vim.fs.abspath('foo', { cwd = parent_cwd }))
|
||||
eq(parent_cwd .. '/.././../foo', vim.fs.abspath('.././../foo', { cwd = parent_cwd }))
|
||||
eq('/foo/bar', vim.fs.abspath('/foo/bar', { cwd = parent_cwd }))
|
||||
end)
|
||||
|
||||
it('expands ~', function()
|
||||
eq(home .. '/foo', vim.fs.abspath('~/foo'))
|
||||
eq(home .. '/./.././foo', vim.fs.abspath('~/./.././foo'))
|
||||
end)
|
||||
|
||||
it('does not expand ~ if plain=true', function()
|
||||
eq(cwd .. '/~/foo', vim.fs.abspath('~/foo', { plain = true }))
|
||||
eq(cwd .. '/~/./.././foo', vim.fs.abspath('~/./.././foo', { plain = true }))
|
||||
end)
|
||||
|
||||
if is_os('win') then
|
||||
it('works with drive-specific cwd on Windows', function()
|
||||
local cwd_drive = cwd:match('^%w:')
|
||||
|
||||
Reference in New Issue
Block a user