Skip to content

Commit

Permalink
i want in main
Browse files Browse the repository at this point in the history
  • Loading branch information
LeopoldWichtel committed Oct 19, 2023
1 parent 4b4bbee commit 3cd2f9f
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions logics-py/tests/test_logics.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,37 +2,43 @@
import pytest
from logics import Logics


# This parameterized test case loads .lgx files from the "../tests/" directory
# and processes them one by one.
@pytest.mark.parametrize("input", glob.glob("../tests/*.lgx"))
def test_testcase(input):
# Read the content of the current .lgx file.
input = open(input, "r").read()
variables = {}
last_result = None
variables = {} # Initialize an empty dictionary to store variables
last_result = None # Initialize a variable to store the last result

for line in input.splitlines():
line = line.strip()

if not line:
continue
elif line[0] == "#":
# Split the line into components separated by ':'
cmd = line[1:].split(":", 2)

action = cmd[0].lower()

if action == "expect":
expect = cmd[1]

# Ensure that the last result is not None and compare it to the expected value
assert last_result is not None, "#EXPECT used before evaluation"

assert repr(last_result) == expect
last_result = None

elif action == "set":
var = cmd[1]
value = cmd[2]

# Use the Logics class to evaluate the value and update variables
variables[var] = Logics(value).run(variables)
else:
# Evaluate the current line using the Logics class and update last_result
last_result = Logics(line).run(variables)

# Ensure that last_result is None (unverified) at the end of the test case
assert last_result is None, f"{last_result=} unverified"


0 comments on commit 3cd2f9f

Please sign in to comment.