From adec9e94fa4fe84109a6c510bae9fff3b678b5e1 Mon Sep 17 00:00:00 2001 From: harupy Date: Sun, 4 Dec 2022 05:45:15 +0900 Subject: [PATCH 1/3] Fix location --- compiler/parser/python.lalrpop | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/compiler/parser/python.lalrpop b/compiler/parser/python.lalrpop index ee108edc52..442a5ed887 100644 --- a/compiler/parser/python.lalrpop +++ b/compiler/parser/python.lalrpop @@ -756,7 +756,7 @@ LambdaDef: ast::Expr = { } OrTest: ast::Expr = { - => { + => { if e2.is_empty() { e1 } else { @@ -773,7 +773,7 @@ OrTest: ast::Expr = { }; AndTest: ast::Expr = { - => { + => { if e2.is_empty() { e1 } else { From 5c63109f4ade0f98a928beae50efad9d7cfe1d90 Mon Sep 17 00:00:00 2001 From: harupy Date: Sun, 4 Dec 2022 05:59:51 +0900 Subject: [PATCH 2/3] add tests --- compiler/parser/src/parser.rs | 14 +++++ ...rser__parser__tests__parse_boolop_and.snap | 56 +++++++++++++++++++ ...arser__parser__tests__parse_boolop_or.snap | 56 +++++++++++++++++++ 3 files changed, 126 insertions(+) create mode 100644 compiler/parser/src/snapshots/rustpython_parser__parser__tests__parse_boolop_and.snap create mode 100644 compiler/parser/src/snapshots/rustpython_parser__parser__tests__parse_boolop_or.snap diff --git a/compiler/parser/src/parser.rs b/compiler/parser/src/parser.rs index d0f71fc80e..f120dae705 100644 --- a/compiler/parser/src/parser.rs +++ b/compiler/parser/src/parser.rs @@ -218,4 +218,18 @@ class Foo(A, B): let parse_ast = parse_expression(&source, "").unwrap(); insta::assert_debug_snapshot!(parse_ast); } + + #[test] + fn test_parse_boolop_or() { + let source = String::from("x or y"); + let parse_ast = parse_expression(&source, "").unwrap(); + insta::assert_debug_snapshot!(parse_ast); + } + + #[test] + fn test_parse_boolop_and() { + let source = String::from("x and y"); + let parse_ast = parse_expression(&source, "").unwrap(); + insta::assert_debug_snapshot!(parse_ast); + } } diff --git a/compiler/parser/src/snapshots/rustpython_parser__parser__tests__parse_boolop_and.snap b/compiler/parser/src/snapshots/rustpython_parser__parser__tests__parse_boolop_and.snap new file mode 100644 index 0000000000..f0e856205c --- /dev/null +++ b/compiler/parser/src/snapshots/rustpython_parser__parser__tests__parse_boolop_and.snap @@ -0,0 +1,56 @@ +--- +source: compiler/parser/src/parser.rs +expression: parse_ast +--- +Located { + location: Location { + row: 1, + column: 0, + }, + end_location: Some( + Location { + row: 1, + column: 7, + }, + ), + custom: (), + node: BoolOp { + op: And, + values: [ + Located { + location: Location { + row: 1, + column: 0, + }, + end_location: Some( + Location { + row: 1, + column: 1, + }, + ), + custom: (), + node: Name { + id: "x", + ctx: Load, + }, + }, + Located { + location: Location { + row: 1, + column: 6, + }, + end_location: Some( + Location { + row: 1, + column: 7, + }, + ), + custom: (), + node: Name { + id: "y", + ctx: Load, + }, + }, + ], + }, +} diff --git a/compiler/parser/src/snapshots/rustpython_parser__parser__tests__parse_boolop_or.snap b/compiler/parser/src/snapshots/rustpython_parser__parser__tests__parse_boolop_or.snap new file mode 100644 index 0000000000..5d5abad36d --- /dev/null +++ b/compiler/parser/src/snapshots/rustpython_parser__parser__tests__parse_boolop_or.snap @@ -0,0 +1,56 @@ +--- +source: compiler/parser/src/parser.rs +expression: parse_ast +--- +Located { + location: Location { + row: 1, + column: 0, + }, + end_location: Some( + Location { + row: 1, + column: 6, + }, + ), + custom: (), + node: BoolOp { + op: Or, + values: [ + Located { + location: Location { + row: 1, + column: 0, + }, + end_location: Some( + Location { + row: 1, + column: 1, + }, + ), + custom: (), + node: Name { + id: "x", + ctx: Load, + }, + }, + Located { + location: Location { + row: 1, + column: 5, + }, + end_location: Some( + Location { + row: 1, + column: 6, + }, + ), + custom: (), + node: Name { + id: "y", + ctx: Load, + }, + }, + ], + }, +} From 18293dc80c2cc304d0c4a496d9ab3fd42d564fee Mon Sep 17 00:00:00 2001 From: harupy Date: Mon, 5 Dec 2022 08:23:07 +0900 Subject: [PATCH 3/3] Remove decorator on test_boolop --- Lib/test/test_ast.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/Lib/test/test_ast.py b/Lib/test/test_ast.py index 2fe400b3b8..1b6025e364 100644 --- a/Lib/test/test_ast.py +++ b/Lib/test/test_ast.py @@ -2100,8 +2100,6 @@ def test_binop(self): self._check_content(s, binop.left, '1 * 2 + (3 )') self._check_content(s, binop.left.right, '3') - # TODO: RUSTPYTHON - @unittest.expectedFailure def test_boolop(self): s = dedent(''' if (one_condition and