robin/laufey

git clone https://git.robinwobin.dev/robin/laufey

Justin M. Keyesdocs: misc #40847715d8887ec

master
1.8 KiB61 linesraw
1local t = require('test.testutil')
2local n = require('test.functional.testnvim')()
3
4local describe, it, before_each, after_each = t.describe, t.it, t.before_each, t.after_each
5local clear, command, eval, eq = n.clear, n.command, n.eval, t.eq
6local mkdir = t.mkdir
7
8describe('glob()', function()
9  before_each(function()
10    clear()
11    mkdir('test-glob')
12
13    -- Long path might cause "Press ENTER" prompt; use :silent to avoid it.
14    command('silent cd test-glob')
15  end)
16
17  after_each(function()
18    vim.uv.fs_rmdir('test-glob')
19  end)
20
21  it("glob('.*') returns . and .. ", function()
22    eq({ '.', '..' }, eval("glob('.*', 0, 1)"))
23    -- Do it again to verify scandir_next_with_dots() internal state.
24    eq({ '.', '..' }, eval("glob('.*', 0, 1)"))
25  end)
26  it("glob('*') returns an empty list ", function()
27    eq({}, eval("glob('*', 0, 1)"))
28    -- Do it again to verify scandir_next_with_dots() internal state.
29    eq({}, eval("glob('*', 0, 1)"))
30  end)
31end)
32
33describe('glob() with $ and ~ mixed with wildcards', function()
34  before_each(function()
35    clear()
36    mkdir('test-wild')
37    command('silent cd test-wild')
38    -- Names containing literal '$' and '~'.
39    command([[call writefile([], 'a$b.txt')]])
40    command([[call writefile([], 'a$c.txt')]])
41    mkdir('test-wild/d~e')
42    command([[call writefile([], 'd~e/f.txt')]])
43  end)
44
45  after_each(function()
46    n.rmdir('test-wild')
47  end)
48
49  it('$VAR is expanded before the trailing wildcard is globbed', function()
50    command('let $WILDDIR = "d~e"')
51    eq({ 'd~e/f.txt' }, eval([[glob('$WILDDIR/*', 0, 1)]]))
52  end)
53
54  it("wildcard descends through a component containing '~'", function()
55    eq({ 'd~e/f.txt' }, eval([[glob('d~e/*', 0, 1)]]))
56  end)
57
58  it("'~' mid-component combined with a wildcard", function()
59    eq({ 'd~e' }, eval([[glob('d~*', 0, 1)]]))
60  end)
61end)