def test_identifier_quoted(): assert 13 == parse_and_visit('["my id"]', vars={"my id": 13}) assert 20 == parse_and_visit('["my id"] + ["my id2"]', vars={ "my id": 13, "my id2": 7 }) assert 'Var(my id)' == str(parse_expression('["my id"]'))
def test_identifier_quoted_sq(): assert 13 == parse_and_visit("['my id']", vars={"my id": 13}) assert 20 == parse_and_visit("['my id'] + ['my id2']", vars={ "my id": 13, "my id2": 7 }) assert 20 == parse_and_visit("['my id'] + [\"my id2\"]", vars={ "my id": 13, "my id2": 7 }) assert 'Var(my id)' == str(parse_expression("['my id']"))
def test_int_explicit_literal_repr(): assert "int(4)" == str(parse_expression("int(4)", debug=True)) assert "4" == str(parse_expression("(4)", debug=True))
def test_int(): assert 10 == parse_and_visit("10") assert isinstance(parse_expression("10"), ept.Int)
def test_method_call_any_star(): parsed = parse_expression("a = any(* )") assert "(a = any(*))" == str(parsed)
def test_or(): parsed = parse_expression("3==5 or (1<4)") assert str(parsed) == "((3 == 5) or (1 < 4))" assert True == parsed.evaluate(None)
def test_var(): parsed = parse_expression("x + 1") assert str(parsed) == "(x + 1)" assert 3 == parsed.evaluate({"x": 2})
def test_and(): parsed = parse_expression("3>5 and (1<4)") assert str(parsed) == "((3 > 5) and (1 < 4))" assert False == parsed.evaluate(None)
def parse_and_visit(input, vars=None): expression_tree = parse_expression(input, debug=True) result = expression_tree.evaluate(vars) return result
def test_ne_lt(): parsed = parse_expression("(3>5)!=(1<4)") assert str(parsed) == "((3 > 5) != (1 < 4))" assert True == parsed.evaluate(None)
def test_lt_add(): parsed = parse_expression("1 < 5 - 6 ") assert str(parsed) == "(1 < (5 - 6))" assert False == parsed.evaluate(None)
def test_parse_parentheses_lt(): parsed = parse_expression("1 < (6 - 4) ") assert str(parsed) == "(1 < (6 - 4))" assert True == parsed.evaluate(None)