-
Notifications
You must be signed in to change notification settings - Fork 389
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test(_comp_get_first_arg): add unit tests
- Loading branch information
1 parent
ecfa347
commit 9fee0e8
Showing
2 changed files
with
52 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" |