File: test_unit_init_completion.py

package info (click to toggle)
bash-completion 1%3A2.11-6
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 6,560 kB
  • sloc: python: 8,228; makefile: 1,766; sh: 275; perl: 85; xml: 29; ansic: 7; ruby: 2
file content (34 lines) | stat: -rw-r--r-- 1,065 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import pytest

from conftest import TestUnitBase, assert_bash_exec, assert_complete


@pytest.mark.bashcomp(
    cmd=None,
    ignore_env=r"^[+-](COMP(_(WORDS|CWORD|LINE|POINT)|REPLY)|"
    r"cur|cword|words)=",
)
class TestUnitInitCompletion(TestUnitBase):
    def test_1(self, bash):
        """Test environment non-pollution, detected at teardown."""
        assert_bash_exec(
            bash,
            "foo() { "
            "local cur prev words cword "
            "COMP_WORDS=() COMP_CWORD=0 COMP_LINE= COMP_POINT=0; "
            "_init_completion; }; "
            "foo; unset foo",
        )

    def test_2(self, bash):
        output = self._test_unit(
            "_init_completion %s; echo $cur,${prev-}", bash, "(a)", 0, "a", 0
        )
        assert output == ","

    @pytest.mark.parametrize("redirect", "> >> 2> < &>".split())
    def test_redirect(self, bash, redirect):
        completion = assert_complete(
            bash, "%s " % redirect, cwd="shared/default"
        )
        assert all(x in completion for x in "foo bar".split())