Skip to content

Commit c89a769

Browse files
committed
[PortsPy] Adds test runner for semantic tests
1 parent e18d1aa commit c89a769

1 file changed

Lines changed: 27 additions & 0 deletions

File tree

ports-py/semantic-tests.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import json
2+
import lispy
3+
import numbers
4+
5+
testTable = []
6+
with open("ports/lispy-tests.json") as file:
7+
testTable.extend(json.load(file))
8+
9+
with open("ports/lispy-tests2.json") as file:
10+
testTable.extend(json.load(file))
11+
12+
def matches(structure, target):
13+
if(isinstance(target, dict) and "type" in target):
14+
return isinstance(structure, Exception)
15+
return structure == target
16+
17+
for entry in testTable:
18+
input = entry["input"]
19+
try:
20+
evalResult = lispy.eval(lispy.parse(input))
21+
except Exception as e:
22+
evalResult = e
23+
if matches(evalResult, entry["expected"]):
24+
print(f"✅: {input}")
25+
else:
26+
print(f"❌: {input} got {evalResult} instead")
27+

0 commit comments

Comments
 (0)