|
| 1 | +import pytest |
| 2 | + |
| 3 | +from conftest import assert_bash_exec |
| 4 | + |
| 5 | + |
| 6 | +@pytest.mark.bashcomp( |
| 7 | + cmd=None, |
| 8 | + cwd="_filedir", |
| 9 | + ignore_env=r"^\+declare -f __tester$", |
| 10 | +) |
| 11 | +class TestDequoteIncomplete: |
| 12 | + @pytest.fixture |
| 13 | + def functions(self, bash): |
| 14 | + assert_bash_exec( |
| 15 | + bash, |
| 16 | + '__tester() { local REPLY=dummy v=var;_comp_dequote_incomplete "$1";local ext=$?;((${#REPLY[@]}))&&printf \'<%s>\' "${REPLY[@]}";echo;return $ext;}', |
| 17 | + ) |
| 18 | + |
| 19 | + def test_basic_1(self, bash, functions): |
| 20 | + output = assert_bash_exec(bash, "__tester a", want_output=True) |
| 21 | + assert output.strip() == "<a>" |
| 22 | + |
| 23 | + def test_basic_2(self, bash, functions): |
| 24 | + output = assert_bash_exec(bash, "__tester abc", want_output=True) |
| 25 | + assert output.strip() == "<abc>" |
| 26 | + |
| 27 | + def test_basic_3_null(self, bash, functions): |
| 28 | + output = assert_bash_exec(bash, "! __tester ''", want_output=True) |
| 29 | + assert output.strip() == "" |
| 30 | + |
| 31 | + def test_basic_4_empty(self, bash, functions): |
| 32 | + output = assert_bash_exec(bash, "__tester \"''\"", want_output=True) |
| 33 | + assert output.strip() == "<>" |
| 34 | + |
| 35 | + def test_basic_5_brace(self, bash, functions): |
| 36 | + output = assert_bash_exec(bash, "__tester 'a{1..3}'", want_output=True) |
| 37 | + assert output.strip() == "<a1><a2><a3>" |
| 38 | + |
| 39 | + def test_basic_6_glob(self, bash, functions): |
| 40 | + output = assert_bash_exec(bash, "__tester 'a?b'", want_output=True) |
| 41 | + assert output.strip() == "<a b><a$b><a&b><a'b>" |
| 42 | + |
| 43 | + def test_quote_1(self, bash, functions): |
| 44 | + output = assert_bash_exec( |
| 45 | + bash, "__tester '\"a\"'\\'b\\'\\$\\'c\\'", want_output=True |
| 46 | + ) |
| 47 | + assert output.strip() == "<abc>" |
| 48 | + |
| 49 | + def test_quote_2(self, bash, functions): |
| 50 | + output = assert_bash_exec( |
| 51 | + bash, "__tester '\\\"\\'\\''\\$\\`'", want_output=True |
| 52 | + ) |
| 53 | + assert output.strip() == "<\"'$`>" |
| 54 | + |
| 55 | + def test_quote_3(self, bash, functions): |
| 56 | + output = assert_bash_exec( |
| 57 | + bash, "__tester \\$\\'a\\\\tb\\'", want_output=True |
| 58 | + ) |
| 59 | + assert output.strip() == "<a\tb>" |
| 60 | + |
| 61 | + def test_quote_4(self, bash, functions): |
| 62 | + output = assert_bash_exec( |
| 63 | + bash, '__tester \'"abc\\"def"\'', want_output=True |
| 64 | + ) |
| 65 | + assert output.strip() == '<abc"def>' |
| 66 | + |
| 67 | + def test_quote_5(self, bash, functions): |
| 68 | + output = assert_bash_exec( |
| 69 | + bash, "__tester \\'abc\\'\\\\\\'\\'def\\'", want_output=True |
| 70 | + ) |
| 71 | + assert output.strip() == "<abc'def>" |
| 72 | + |
| 73 | + def test_incomplete_1(self, bash, functions): |
| 74 | + output = assert_bash_exec(bash, "__tester 'a\\'", want_output=True) |
| 75 | + assert output.strip() == "<a>" |
| 76 | + |
| 77 | + def test_incomplete_2(self, bash, functions): |
| 78 | + output = assert_bash_exec(bash, '__tester "\'a b "', want_output=True) |
| 79 | + assert output.strip() == "<a b >" |
| 80 | + |
| 81 | + def test_incomplete_3(self, bash, functions): |
| 82 | + output = assert_bash_exec(bash, "__tester '\"a b '", want_output=True) |
| 83 | + assert output.strip() == "<a b >" |
0 commit comments