From c451b4648c04c6a03824353cff61e5786be0a0e6 Mon Sep 17 00:00:00 2001 From: Eliott Dumeix Date: Sun, 27 Oct 2024 11:24:38 +0100 Subject: [PATCH] Add a test for failure to parse chained comparisons, fix #56 --- luaparser/tests/test_integration.py | 36 ++++++++++++++++++++++------- 1 file changed, 28 insertions(+), 8 deletions(-) diff --git a/luaparser/tests/test_integration.py b/luaparser/tests/test_integration.py index 76c4636..e8b5594 100644 --- a/luaparser/tests/test_integration.py +++ b/luaparser/tests/test_integration.py @@ -194,13 +194,13 @@ def test_cont_int_5(self): tree = ast.parse( textwrap.dedent( """ - function table.pack(...) - repeat - print("value of a:", a) - a = a + 1; - until( a > 15 ) - end - """ + function table.pack(...) + repeat + print("value of a:", a) + a = a + 1; + until( a > 15 ) + end + """ ) ) nodes = ast.walk(tree) @@ -291,4 +291,24 @@ def test_cont_int_7(self): # Brackets are absent in output of AST->source_code conversion #57 def test_cont_int_8(self): source = r"result = (a + b) / (c + d)" - self.assertEqual(source, ast.to_lua_source(ast.parse(source))) \ No newline at end of file + self.assertEqual(source, ast.to_lua_source(ast.parse(source))) + + # Failure to parse chained comparisons #56 + def test_cont_int_9(self): + tree = ast.parse(textwrap.dedent(""" + if false == false == false then + x = 2 + end + """)) + exp = Chunk( + Block([ + If( + test=EqToOp(left=EqToOp(left=FalseExpr(), right=FalseExpr()), right=FalseExpr()), + body=Block([ + Assign([Name("x")], [Number(2)]) + ]), + orelse=None, + ) + ]) + ) + self.assertEqual(exp, tree)