Skip to content

Commit

Permalink
test(_comp_get_first_arg): add unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
akinomyoga committed Sep 1, 2023
1 parent ecfa347 commit 9fee0e8
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 1 deletion.
3 changes: 2 additions & 1 deletion test/t/unit/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,9 @@ EXTRA_DIST = \
test_unit_expand_tilde_by_ref.py \
test_unit_filedir.py \
test_unit_find_unique_completion_pair.py \
test_unit_get_words.py \
test_unit_get_first_arg.py \
test_unit_get_cword.py \
test_unit_get_words.py \
test_unit_initialize.py \
test_unit_ip_addresses.py \
test_unit_known_hosts_real.py \
Expand Down
50 changes: 50 additions & 0 deletions test/t/unit/test_unit_get_first_arg.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import pytest

from conftest import assert_bash_exec


@pytest.mark.bashcomp(cmd=None)
class TestUnitGetFirstArg:
@pytest.fixture(scope="class")
def functions(self, bash):
assert_bash_exec(
bash,
'_comp__test_unit() { local -a "words=$1"; local cword=$2 arg=; shift 2; _comp_get_first_arg "$@" && printf "%s\\n" "$arg"; return 0; }',
)

def test_1(self, bash, functions):
assert_bash_exec(bash, "_comp__test_unit '()' 0")

def test_2(self, bash, functions):
output = assert_bash_exec(
bash, '_comp__test_unit "(a b)" 2', want_output=None
).strip()
assert output == "b"

def test_3(self, bash, functions):
output = assert_bash_exec(
bash, '_comp__test_unit "(a bc)" 2', want_output=None
).strip()
assert output == "bc"

def test_4(self, bash, functions):
output = assert_bash_exec(
bash, '_comp__test_unit "(a b c)" 2', want_output=None
).strip()
assert output == "b"

def test_5(self, bash, functions):
"""Neither of the current word and the command name should be picked
as the first argument"""
output = assert_bash_exec(
bash, '_comp__test_unit "(a b c)" 1', want_output=None
).strip()
assert output == ""

def test_6(self, bash, functions):
"""Options starting with - should not be picked as the first
argument"""
output = assert_bash_exec(
bash, '_comp__test_unit "(a -b -c d e)" 4', want_output=None
).strip()
assert output == "d"

0 comments on commit 9fee0e8

Please sign in to comment.