Skip to content

Commit dbcdaaf

Browse files
committed
Add more AST tests
1 parent 957ab89 commit dbcdaaf

File tree

5 files changed

+67
-3
lines changed

5 files changed

+67
-3
lines changed

test_main.py

+5-3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import pytest
12
from typer.testing import CliRunner
23
from main import app
34

@@ -27,9 +28,10 @@ def test_parser_error():
2728
assert result.stdout.count("line") == 5
2829

2930

30-
def test_ast():
31-
result = runner.invoke(app, ["ast", "tests/ast/input_1.txt"])
31+
@pytest.mark.parametrize("n", [1, 2, 3])
32+
def test_ast(n):
33+
result = runner.invoke(app, ["ast", f"tests/ast/input_{n}.txt"])
3234
assert result.exit_code == 0
33-
with open("tests/ast/output_1.txt", encoding="utf-8") as f:
35+
with open(f"tests/ast/output_{n}.txt", encoding="utf-8") as f:
3436
output = f.read()
3537
assert result.stdout == output

tests/ast/input_2.txt

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
n = 10;
2+
for i = 0:n {
3+
j = i;
4+
while (i > 0)
5+
i -= 1;
6+
if (i == 0)
7+
print "OK";
8+
}

tests/ast/input_3.txt

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
a = 2 * (2 + 2) + 2 * 2;
2+
b = 3 * -3;
3+
C = 2 .+ 2 .* ones(3)';

tests/ast/output_2.txt

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
=
2+
| n
3+
| 10
4+
for
5+
| i
6+
| range
7+
| | 0
8+
| | n
9+
| =
10+
| | j
11+
| | i
12+
| while
13+
| | >
14+
| | | i
15+
| | | 0
16+
| | -=
17+
| | | i
18+
| | | 1
19+
| if
20+
| | ==
21+
| | | i
22+
| | | 0
23+
| then
24+
| | print
25+
| | | "OK"

tests/ast/output_3.txt

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
=
2+
| a
3+
| +
4+
| | *
5+
| | | 2
6+
| | | +
7+
| | | | 2
8+
| | | | 2
9+
| | *
10+
| | | 2
11+
| | | 2
12+
=
13+
| b
14+
| *
15+
| | 3
16+
| | -
17+
| | | 3
18+
=
19+
| C
20+
| .+
21+
| | 2
22+
| | .*
23+
| | | 2
24+
| | | transpose
25+
| | | | ones
26+
| | | | | 3

0 commit comments

Comments
 (0)