mirror of
https://github.com/neovim/neovim.git
synced 2026-08-27 01:21:48 +00:00
refactor(path): pathcmp() #41035
Problem: Redudant code Solution: Add `path_fold_char()` to normalize path sep. Refactor `pathcmp()` and `path_fnamencmp()` into `path_cmp`. | feature | pathcmp | path_fnamencmp | path_cmp(now) | | ------------------------ | -------------- | -------------- | ------------- | | case folding | `mb_toupper()` | `utf_fold()` | `utf_fold()` | | consults fileignorecase | ✅ | ✅ | `ic` param | | `maxlen` | ✅ | ✅ | ✅ | | `/` == `\` | ✅ | ✅ | ✅ | | MSWIN drive letter | ❌ | ✅ | ✅ | | sep affects sorting | ✅ | ❌ | ✅ | | ignores a trailing slash | ✅ | ❌ | ✅ | Refactor `path_fnamecmp` and `path_full_compare` into `path_equal`, with flags controlling "no filesystem" comparison (i.e. `path_cmp`), env variables expansion, absolute path resolution and filesystem access.
This commit is contained in:
@@ -205,6 +205,18 @@ describe('fnamemodify()', function()
|
||||
eq('txt', fnamemodify('path/to/hello.txt', ':e'))
|
||||
end)
|
||||
|
||||
it(':~', function()
|
||||
local cwd = vim.fs.normalize(fnamemodify('.', ':p'))
|
||||
local full_path = ('%s/foo'):format(cwd)
|
||||
|
||||
command(([[let $HOME='%s']]):format(cwd))
|
||||
eq('~/foo', fnamemodify(full_path, ':~'))
|
||||
|
||||
command(([[let $HOME='%s/']]):format(cwd)) -- a trailing slash
|
||||
-- `init_home` calls `os_realpath` on Unix, which removes the trailing slash
|
||||
eq(is_os('win') and full_path or '~/foo', fnamemodify(full_path, ':~'))
|
||||
end)
|
||||
|
||||
it('regex replacements', function()
|
||||
eq('content-there-here.txt', fnamemodify('content-here-here.txt', ':s/here/there/'))
|
||||
eq('content-there-there.txt', fnamemodify('content-here-here.txt', ':gs/here/there/'))
|
||||
|
||||
Reference in New Issue
Block a user