Fixed #131 : Implement ExprToConditions
Fixed #130 : ArithmeticOperatorParser Fixed #129 : python_wrapper : create_namespace Fixed #128 : ExpressionParser: Cannot parse func(x) infixed concept 'xxx'
This commit is contained in:
@@ -58,10 +58,20 @@ class TestListComprehensionParser(TestUsingMemoryBasedSheerka):
|
||||
error = res.body.body[0]
|
||||
assert isinstance(error, UnexpectedTokenParsingError)
|
||||
|
||||
def test_i_can_parse_a_simple_expression(self):
|
||||
@pytest.mark.parametrize("expression, expected_generator", [
|
||||
("[x for x in ['a', 'b'] if x == 'a']", [(("x", 1), "['a', 'b']", "x == 'a'")]),
|
||||
("[x for x in ('a', 'b') if x == 'a']", [(("x", 1), "('a', 'b')", "x == 'a'")]),
|
||||
("[x for x in {'a', 'b'} if x == 'a']", [(("x", 1), "{'a', 'b'}", "x == 'a'")]),
|
||||
("(x for x in ['a', 'b'] if x == 'a')", [(("x", 1), "['a', 'b']", "x == 'a'")]),
|
||||
("(x for x in ('a', 'b') if x == 'a')", [(("x", 1), "('a', 'b')", "x == 'a'")]),
|
||||
("(x for x in {'a', 'b'} if x == 'a')", [(("x", 1), "{'a', 'b'}", "x == 'a'")]),
|
||||
("{x for x in ['a', 'b'] if x == 'a'}", [(("x", 1), "['a', 'b']", "x == 'a'")]),
|
||||
("{x for x in ('a', 'b') if x == 'a'}", [(("x", 1), "('a', 'b')", "x == 'a'")]),
|
||||
("{x for x in {'a', 'b'} if x == 'a'}", [(("x", 1), "{'a', 'b'}", "x == 'a'")]),
|
||||
])
|
||||
def test_i_can_parse_a_simple_expression(self, expression, expected_generator):
|
||||
sheerka, context, parser = self.init_parser()
|
||||
|
||||
expression = "[x for x in ['a', 'b'] if x == 'a']"
|
||||
res = parser.parse(context, ParserInput(expression))
|
||||
wrapper = res.body
|
||||
lc_node = res.body.body
|
||||
@@ -69,7 +79,7 @@ class TestListComprehensionParser(TestUsingMemoryBasedSheerka):
|
||||
assert res.status
|
||||
assert sheerka.isinstance(wrapper, BuiltinConcepts.PARSER_RESULT)
|
||||
|
||||
expected = LC(L_EXPR(None, None, "x", source="x "), [(("x", 1), "['a', 'b']", "x == 'a'")], source=expression)
|
||||
expected = LC(L_EXPR(None, None, "x", source="x "), expected_generator, source=expression)
|
||||
to_compare_to = get_expr_node_from_test_node(expression, expected)
|
||||
assert lc_node == to_compare_to
|
||||
|
||||
|
||||
Reference in New Issue
Block a user