|
| 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