forked from xonsh/xonsh
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_bashisms.py
50 lines (44 loc) · 1.62 KB
/
test_bashisms.py
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
"""Tests bashisms xontrib."""
import pytest
import sys
@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