Skip to content

Commit f40a0ca

Browse files
committed
test(filedir_xspec): add tests
1 parent 7ce6c62 commit f40a0ca

6 files changed

Lines changed: 37 additions & 0 deletions

File tree

test/fixtures/_filedir_xspec/a.txt

Whitespace-only changes.

test/fixtures/_filedir_xspec/b.TXT

Whitespace-only changes.

test/fixtures/_filedir_xspec/c.dat

Whitespace-only changes.

test/fixtures/_filedir_xspec/d.bin

Whitespace-only changes.

test/t/unit/Makefile.am

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ EXTRA_DIST = \
55
test_unit_compgen_available_interfaces.py \
66
test_unit_compgen_commands.py \
77
test_unit_compgen_filedir.py \
8+
test_unit_compgen_filedir_xspec.py \
89
test_unit_compgen_ip_addresses.py \
910
test_unit_compgen_known_hosts.py \
1011
test_unit_compgen_pgids.py \
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
import pytest
2+
3+
from conftest import assert_bash_exec, assert_complete
4+
5+
6+
@pytest.mark.bashcomp(cmd=None, ignore_env=r"^\+COMPREPLY=|^[-+]_comp_xspecs=")
7+
class TestUnitFiledirXspec:
8+
@pytest.fixture(scope="class")
9+
def functions(self, request, bash):
10+
assert_bash_exec(
11+
bash,
12+
"_comp_xspecs[xspec1]='!*.txt'; "
13+
"_comp_xspecs[xspec2]=; "
14+
"_comp_xspecs[xspec4]='*.txt'; "
15+
"complete -F _filedir_xspec xspec{1..4}",
16+
)
17+
18+
def test_1(self, bash, functions):
19+
"""Test the pattern for an extension"""
20+
completion = assert_complete(bash, "xspec1 ", cwd="_filedir_xspec")
21+
assert completion == sorted("a.txt b.TXT".split())
22+
23+
def test_2(self, bash, functions):
24+
"""Test an empty _comp_xspecs entry"""
25+
completion = assert_complete(bash, "xspec2 ", cwd="_filedir_xspec")
26+
assert completion == sorted("a.txt b.TXT c.dat d.bin".split())
27+
28+
def test_3(self, bash, functions):
29+
"""Test an unset _comp_xspecs entry"""
30+
completion = assert_complete(bash, "xspec3 ", cwd="_filedir_xspec")
31+
assert completion == sorted("a.txt b.TXT c.dat d.bin".split())
32+
33+
def test_4(self, bash, functions):
34+
"""Test an exclusion pattern"""
35+
completion = assert_complete(bash, "xspec4 ", cwd="_filedir_xspec")
36+
assert completion == sorted("c.dat d.bin".split())

0 commit comments

Comments
 (0)