refactor(path): path_has_wildcard() #40893

Problem:
Redundant code.

Solution:
Combine path_has_wildcard() and path_has_exp_wildcard(). They have similar logic.
Also, the latter operates on whatever wildcards remain after shell/env/backtick
expansion, so the two felt somewhat related.

Also drop some unnecessary MB_PTR_ADV calls.
This commit is contained in:
tao
2026-07-22 22:39:29 +08:00
committed by GitHub
parent 47e97c1ad6
commit e397b2c2ca
7 changed files with 64 additions and 64 deletions

View File

@@ -4,6 +4,7 @@ local n = require('test.functional.testnvim')()
local describe, it, before_each, after_each = t.describe, t.it, t.before_each, t.after_each
local clear, command, eval, eq = n.clear, n.command, n.eval, t.eq
local mkdir = t.mkdir
local fn = n.fn
before_each(function()
clear()
@@ -29,3 +30,33 @@ describe('glob()', function()
eq({}, eval("glob('*', 0, 1)"))
end)
end)
describe('glob() with $ and ~ mixed with wildcards', function()
before_each(function()
clear()
mkdir('test-wild')
command('silent cd test-wild')
-- Names containing literal '$' and '~'.
command([[call writefile([], 'a$b.txt')]])
command([[call writefile([], 'a$c.txt')]])
mkdir('test-wild/d~e')
command([[call writefile([], 'd~e/f.txt')]])
end)
after_each(function()
n.rmdir('test-wild')
end)
it('$VAR is expanded before the trailing wildcard is globbed', function()
command('let $WILDDIR = "d~e"')
eq({ 'd~e/f.txt' }, eval([[glob('$WILDDIR/*', 0, 1)]]))
end)
it("wildcard descends through a component containing '~'", function()
eq({ 'd~e/f.txt' }, eval([[glob('d~e/*', 0, 1)]]))
end)
it("'~' mid-component combined with a wildcard", function()
eq({ 'd~e' }, eval([[glob('d~*', 0, 1)]]))
end)
end)