Skip to content

Commit bee4eee

Browse files
committed
Add parser tests
1 parent fe57ec7 commit bee4eee

File tree

4 files changed

+80
-0
lines changed

4 files changed

+80
-0
lines changed

test_main.py

+23
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,29 @@
44
runner = CliRunner()
55

66

7+
def test_parser_basic():
8+
result = runner.invoke(app, ["parse", "tests/parser/input_1.txt"])
9+
assert result.exit_code == 0
10+
assert result.stdout == ""
11+
12+
13+
def test_parser_loops():
14+
result = runner.invoke(app, ["parse", "tests/parser/input_2.txt"])
15+
assert result.exit_code == 0
16+
assert result.stdout == ""
17+
18+
19+
def test_parser_error():
20+
result = runner.invoke(app, ["parse", "tests/parser/invalid_input_1.txt"])
21+
assert result.exit_code == 0
22+
assert "line 1" in result.stdout
23+
assert "line 3" in result.stdout
24+
assert "line 7" in result.stdout
25+
assert "line 10" in result.stdout
26+
assert "line 12" in result.stdout
27+
assert result.stdout.count("line") == 5
28+
29+
730
def test_ast():
831
result = runner.invoke(app, ["ast", "tests/ast/input_1.txt"])
932
assert result.exit_code == 0

tests/parser/input_1.txt

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
A = zeros(5); # 3x3 matrix filled with zeros
2+
B = ones(7); # 3x3 matrix filled with ones
3+
C = eye(10); # 3x3 diagonal matrix filled with ones
4+
D = A.+B; # add element-wise
5+
E -= A.-B; # substract element-wise
6+
F *= A.*B; # multiply element-wise
7+
G /= A./B; # divide element-wise
8+
9+
H = [ [ 1, 2, 3], [ 4, 5, 6], [ 7, 8, 9] ];
10+
11+
print H[1, 2];
12+
13+
float_1 = 3.14;
14+
float_2 = 3.;
15+
float_3 = .14;
16+
float_4 = 3.14e-2;
17+
string_1 = "#Hello!";
18+
19+
H *= H';
20+
21+
a = 1;
22+
b = 2;
23+
24+
a += b;
25+
a /= b;
26+
a *= b;
27+
a -= b;

tests/parser/input_2.txt

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
k = 42;
2+
3+
while(k>1) {
4+
if(k<5)
5+
k = k + 1;
6+
else if(k<10)
7+
i = 5;
8+
else
9+
i = 10;
10+
k = k - 2;
11+
}
12+
13+
for i = 1:10
14+
for j = i:k
15+
print i, j;
16+
17+
18+
{ ok = 4; }

tests/parser/invalid_input_1.txt

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
a == 2;
2+
3+
if(a=2) {
4+
a = 3;
5+
}
6+
7+
5;
8+
9+
a = 4;
10+
8 = a;
11+
12+
b = 4 * (2 + 2;

0 commit comments

Comments
 (0)