Skip to content

Commit

Permalink
Update test_evaluation to include utterly invalid nodes
Browse files Browse the repository at this point in the history
This assures that `true ? 6 : invalid` and `false ? invalid : 7` never evaluate the invalid nodes.
  • Loading branch information
slott56 committed May 23, 2024
1 parent 59e902d commit bd2a68f
Showing 1 changed file with 6 additions and 12 deletions.
18 changes: 6 additions & 12 deletions tests/test_evaluation.py
Original file line number Diff line number Diff line change
Expand Up @@ -501,25 +501,22 @@ def mock_left_expr_tree():
lark.Token(type_="INT_LIT", value="6"),
]
),
lark.Tree(
data='literal',
children=[
lark.Token(type_="INT_LIT", value="7"),
]
),
sentinel.DO_NOT_EVALUATE # Test will crash if this is evaluated
],
meta=Mock(line=1, column=1)
)
return tree


def test_eval_expr_3_left_good(mock_left_expr_tree):
"""Assert ``true ? 6 : invalid`` does not execute the invalid expression."""
activation = Mock()
evaluator = Evaluator(
mock_left_expr_tree,
activation
)
assert evaluator.evaluate() == celtypes.IntType(6)
# assert did not crash; therefore, invalid node not touched


def test_eval_expr_3_bad_override(mock_left_expr_tree):
Expand All @@ -545,12 +542,7 @@ def mock_right_expr_tree():
lark.Token(type_="BOOL_LIT", value="false"),
]
),
lark.Tree(
data='literal',
children=[
lark.Token(type_="INT_LIT", value="6"),
]
),
sentinel.DO_NOT_EVALUATE, # Test will crash if this is evaluated
lark.Tree(
data='literal',
children=[
Expand All @@ -563,12 +555,14 @@ def mock_right_expr_tree():
return tree

def test_eval_expr_3_right_good(mock_right_expr_tree):
"""Assert ``false ? invalid : 7`` does not execute the invalid expression."""
activation = Mock()
evaluator = Evaluator(
mock_right_expr_tree,
activation
)
assert evaluator.evaluate() == celtypes.IntType(7)
# assert did not crash; therefore, invalid node not touched


def test_eval_expr_0():
Expand Down

0 comments on commit bd2a68f

Please sign in to comment.