File: test_bashisms.py

package info (click to toggle)
xonsh 0.13.4%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 4,024 kB
  • sloc: python: 46,350; makefile: 136; sh: 41; xml: 17
file content (51 lines) | stat: -rw-r--r-- 1,661 bytes parent folder | download
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
"""Tests bashisms xontrib."""
import sys

import pytest


@pytest.fixture(name="bash_preproc", scope="module")
def _bash_preproc():
    from xontrib.bashisms import bash_preproc

    yield bash_preproc
    del sys.modules["xontrib.bashisms"]


@pytest.mark.parametrize(
    "history, inp, exp",
    [
        # No history:
        ([], "!!", ""),
        ([], "!$", ""),
        ([], "!^", ""),
        ([], "!*", ""),
        ([], "!echo", ""),
        # No substitution:
        (["aa 1 2", "ab 3 4"], "ls", "ls"),
        (["aa 1 2", "ab 3 4"], "x = 42", "x = 42"),
        (["aa 1 2", "ab 3 4"], "!", "!"),
        # Bang command only:
        (["aa 1 2", "ab 3 4"], "!!", "ab 3 4"),
        (["aa 1 2", "ab 3 4"], "!$", "4"),
        (["aa 1 2", "ab 3 4"], "!^", "ab"),
        (["aa 1 2", "ab 3 4"], "!*", "3 4"),
        (["aa 1 2", "ab 3 4"], "!a", "ab 3 4"),
        (["aa 1 2", "ab 3 4"], "!aa", "aa 1 2"),
        (["aa 1 2", "ab 3 4"], "!ab", "ab 3 4"),
        # Bang command with others:
        (["aa 1 2", "ab 3 4"], "echo !! >log", "echo ab 3 4 >log"),
        (["aa 1 2", "ab 3 4"], "echo !$ >log", "echo 4 >log"),
        (["aa 1 2", "ab 3 4"], "echo !^ >log", "echo ab >log"),
        (["aa 1 2", "ab 3 4"], "echo !* >log", "echo 3 4 >log"),
        (["aa 1 2", "ab 3 4"], "echo !a >log", "echo ab 3 4 >log"),
        (["aa 1 2", "ab 3 4"], "echo !aa >log", "echo aa 1 2 >log"),
        (["aa 1 2", "ab 3 4"], "echo !ab >log", "echo ab 3 4 >log"),
    ],
)
def test_preproc(history, inp, exp, xession, bash_preproc):
    """Test the bash preprocessor."""

    xession.history.inps = history
    obs = bash_preproc(inp)
    assert exp == obs