Skip to content

Commit a7ea5e5

Browse files
Add loop tests and enable wasm_x86 tests in CMakeLists
1 parent 580c1f3 commit a7ea5e5

File tree

6 files changed

+59
-18
lines changed

6 files changed

+59
-18
lines changed

integration_tests/CMakeLists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,9 @@ RUN(NAME expr_13 LABELS llvm c
210210
EXTRAFILES expr_13b.c)
211211
RUN(NAME expr_14 LABELS cpython llvm c)
212212
RUN(NAME loop_01 LABELS cpython llvm c)
213+
RUN(NAME loop_02 LABELS cpython llvm wasm wasm_x86)
214+
RUN(NAME if_01 LABELS cpython llvm wasm wasm_x86)
215+
RUN(NAME if_02 LABELS cpython llvm wasm wasm_x86)
213216
RUN(NAME print_02 LABELS cpython llvm)
214217
RUN(NAME test_types_01 LABELS cpython llvm c)
215218
RUN(NAME test_str_01 LABELS cpython llvm c)

integration_tests/if_01.py

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,46 @@
11
def Test_if_01():
2+
z: i32 = 0
23
if True:
3-
print(1)
4+
assert True
45

56
if False:
6-
print(0)
7+
assert False
78

89
if 1 < 0:
9-
print(0)
10+
assert False
1011
else:
11-
print(1)
12+
assert True
1213

1314
if 1 > 0:
14-
print(1)
15+
assert True
1516
else:
16-
print(0)
17+
assert False
1718

1819
if 1 < 0:
19-
print(1)
20+
assert False
2021
elif 1 > 0:
21-
print(1)
22+
assert True
2223
else:
23-
print(0)
24+
assert False
2425

2526
def Test_if_02():
2627
if True:
2728
print(1)
2829
if True:
2930
print(2)
3031
if False:
31-
print(3)
32+
assert False
3233
elif True:
3334
print(4)
3435
else:
35-
print(5)
36+
assert False
3637
else:
37-
print(6)
38+
assert False
3839

3940
if True:
4041
print(7)
4142
if False:
42-
print(8)
43+
assert False
4344
if False:
4445
print(9)
4546
else:
@@ -48,7 +49,7 @@ def Test_if_02():
4849
if True:
4950
print(11)
5051
else:
51-
print(12)
52+
assert False
5253
print(13)
5354
print(14)
5455

integration_tests/if_02.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from ltypes import bool, i32
1+
from ltypes import i32
22

33
def test_if_01():
44
x: bool = True
@@ -33,8 +33,7 @@ def test_if_01():
3333
if y >= 2:
3434
z += 1
3535

36-
# TODO: replace this an assert statement
37-
print(z)
36+
assert z == 9
3837

3938
def verify():
4039
test_if_01()

integration_tests/loop_02.py

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
from ltypes import i32
2+
def test_loop_01():
3+
i: i32 = 0
4+
j: i32 = 0
5+
6+
while False:
7+
assert False
8+
9+
while i < 0:
10+
assert False
11+
12+
while i < 10:
13+
i += 1
14+
assert i == 10
15+
16+
while i < 20:
17+
while i < 15:
18+
i += 1
19+
i += 1
20+
assert i == 20
21+
22+
for i in range(5):
23+
assert i == j
24+
j += 1
25+
26+
j = 0
27+
for i in range(10, 0, -1):
28+
j = j + i
29+
assert j == 55
30+
31+
32+
def verify():
33+
test_loop_01()
34+
35+
verify()

tests/reference/wat-loop1-e0046d4.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"outfile": null,
77
"outfile_hash": null,
88
"stdout": "wat-loop1-e0046d4.stdout",
9-
"stdout_hash": "72c18793b437f96f1f96c9f8fc8cc253601fb360929216a4de1cb2f1",
9+
"stdout_hash": "f2518c3df21a94fba3afb27274ecfae56de7beaaaa8b54b4c1fd84fa",
1010
"stderr": null,
1111
"stderr_hash": null,
1212
"returncode": 0

tests/reference/wat-loop1-e0046d4.stdout

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848
i32.sub
4949
local.set 0
5050
br 1
51+
else
5152
end
5253
end
5354
local.get 2
@@ -83,6 +84,7 @@
8384
i32.mul
8485
local.set 3
8586
br 1
87+
else
8688
end
8789
end
8890
local.get 3
@@ -121,6 +123,7 @@
121123
i32.sub
122124
local.set 0
123125
br 1
126+
else
124127
end
125128
end
126129
local.get 2

0 commit comments

Comments
 (0)