1import pytest 2 3from conftest import TestUnitBase, assert_bash_exec 4 5 6@pytest.mark.bashcomp( 7 cmd=None, ignore_env=r"^[+-](args|COMP_(WORDS|CWORD|LINE|POINT))=" 8) 9class TestUnitCountArgs(TestUnitBase): 10 def _test(self, *args, **kwargs): 11 return self._test_unit("_count_args %s; echo $args", *args, **kwargs) 12 13 def test_1(self, bash): 14 assert_bash_exec(bash, "COMP_CWORD= _count_args >/dev/null") 15 16 def test_2(self, bash): 17 """a b| should set args to 1""" 18 output = self._test(bash, "(a b)", 1, "a b", 3) 19 assert output == "1" 20 21 def test_3(self, bash): 22 """a b|c should set args to 1""" 23 output = self._test(bash, "(a bc)", 1, "a bc", 3) 24 assert output == "1" 25 26 def test_4(self, bash): 27 """a b c| should set args to 2""" 28 output = self._test(bash, "(a b c)", 2, "a b c", 4) 29 assert output == "2" 30 31 def test_5(self, bash): 32 """a b| c should set args to 1""" 33 output = self._test(bash, "(a b c)", 1, "a b c", 3) 34 assert output == "1" 35 36 def test_6(self, bash): 37 """a b -c| d should set args to 2""" 38 output = self._test(bash, "(a b -c d)", 2, "a b -c d", 6) 39 assert output == "2" 40 41 def test_7(self, bash): 42 """a b -c d e| with -c arg excluded should set args to 2""" 43 output = self._test( 44 bash, "(a b -c d e)", 4, "a b -c d e", 10, arg='"" "@(-c|--foo)"' 45 ) 46 assert output == "2" 47 48 def test_8(self, bash): 49 """a -b -c d e| with -c arg excluded 50 and -b included should set args to 1""" 51 output = self._test( 52 bash, 53 "(a -b -c d e)", 54 4, 55 "a -b -c d e", 56 11, 57 arg='"" "@(-c|--foo)" "-[b]"', 58 ) 59 assert output == "2" 60 61 def test_9(self, bash): 62 """a -b -c d e| with -b included should set args to 3""" 63 output = self._test( 64 bash, "(a -b -c d e)", 4, "a -b -c d e", 11, arg='"" "" "-b"' 65 ) 66 assert output == "3" 67