예제 #1
0
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"]'))
예제 #2
0
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']"))
예제 #3
0
def test_int_explicit_literal_repr():
    assert "int(4)" == str(parse_expression("int(4)", debug=True))
    assert "4" == str(parse_expression("(4)", debug=True))
예제 #4
0
def test_int():
    assert 10 == parse_and_visit("10")
    assert isinstance(parse_expression("10"), ept.Int)
예제 #5
0
def test_method_call_any_star():
    parsed = parse_expression("a = any(* )")
    assert "(a = any(*))" == str(parsed)
예제 #6
0
def test_or():
    parsed = parse_expression("3==5 or (1<4)")
    assert str(parsed) == "((3 == 5) or (1 < 4))"
    assert True == parsed.evaluate(None)
예제 #7
0
def test_var():
    parsed = parse_expression("x + 1")
    assert str(parsed) == "(x + 1)"
    assert 3 == parsed.evaluate({"x": 2})
예제 #8
0
def test_and():
    parsed = parse_expression("3>5 and (1<4)")
    assert str(parsed) == "((3 > 5) and (1 < 4))"
    assert False == parsed.evaluate(None)
예제 #9
0
def parse_and_visit(input, vars=None):
    expression_tree = parse_expression(input, debug=True)
    result = expression_tree.evaluate(vars)
    return result
예제 #10
0
def test_ne_lt():
    parsed = parse_expression("(3>5)!=(1<4)")
    assert str(parsed) == "((3 > 5) != (1 < 4))"
    assert True == parsed.evaluate(None)
예제 #11
0
def test_lt_add():
    parsed = parse_expression("1 < 5 - 6 ")
    assert str(parsed) == "(1 < (5 - 6))"
    assert False == parsed.evaluate(None)
예제 #12
0
def test_parse_parentheses_lt():
    parsed = parse_expression("1 < (6 - 4) ")
    assert str(parsed) == "(1 < (6 - 4))"
    assert True == parsed.evaluate(None)