Skip to content

Commit 87fee4e

Browse files
committed
test(_comp_get_first_arg): add unit tests
1 parent ecfa347 commit 87fee4e

File tree

2 files changed

+53
-1
lines changed

2 files changed

+53
-1
lines changed

test/t/unit/Makefile.am

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,9 @@ EXTRA_DIST = \
1212
test_unit_expand_tilde_by_ref.py \
1313
test_unit_filedir.py \
1414
test_unit_find_unique_completion_pair.py \
15-
test_unit_get_words.py \
15+
test_unit_get_first_arg.py \
1616
test_unit_get_cword.py \
17+
test_unit_get_words.py \
1718
test_unit_initialize.py \
1819
test_unit_ip_addresses.py \
1920
test_unit_known_hosts_real.py \
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
import pytest
2+
3+
from conftest import assert_bash_exec
4+
5+
6+
@pytest.mark.bashcomp(cmd=None)
7+
class TestUnitGetFirstArg:
8+
@pytest.fixture(scope="class")
9+
def functions(self, bash):
10+
assert_bash_exec(
11+
bash,
12+
'_comp__test_unit() { local -a "words=$1"; local cword=$2 arg=; shift 2; _comp_get_first_arg "$@" && printf "%s\\n" "$arg"; return 0; }',
13+
)
14+
15+
def test_1(self, bash, functions):
16+
assert_bash_exec(bash, "_comp__test_unit '()' 0")
17+
18+
def test_2(self, bash, functions):
19+
"""a b| should set args to 1"""
20+
output = assert_bash_exec(
21+
bash, '_comp__test_unit "(a b)" 2', want_output=None
22+
).strip()
23+
assert output == "b"
24+
25+
def test_3(self, bash, functions):
26+
"""a b|c should set args to 1"""
27+
output = assert_bash_exec(
28+
bash, '_comp__test_unit "(a bc)" 2', want_output=None
29+
).strip()
30+
assert output == "bc"
31+
32+
def test_4(self, bash, functions):
33+
"""a b c| should set args to 2"""
34+
output = assert_bash_exec(
35+
bash, '_comp__test_unit "(a b c)" 2', want_output=None
36+
).strip()
37+
assert output == "b"
38+
39+
def test_5(self, bash, functions):
40+
"""a b| c should set args to 1"""
41+
output = assert_bash_exec(
42+
bash, '_comp__test_unit "(a b c)" 1', want_output=None
43+
).strip()
44+
assert output == ""
45+
46+
def test_6(self, bash, functions):
47+
"""a b -c| d should set args to 2"""
48+
output = assert_bash_exec(
49+
bash, '_comp__test_unit "(a -b -c d e)" 4', want_output=None
50+
).strip()
51+
assert output == "d"

0 commit comments

Comments
 (0)