forked from Rust-related/RustPython
Merge pull request #4306 from harupy/fix-boolop-location
Fix `ExprKind::BoolOp` location
This commit is contained in:
2
Lib/test/test_ast.py
vendored
2
Lib/test/test_ast.py
vendored
@@ -2100,8 +2100,6 @@ class EndPositionTests(unittest.TestCase):
|
||||
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
|
||||
|
||||
@@ -756,7 +756,7 @@ LambdaDef: ast::Expr = {
|
||||
}
|
||||
|
||||
OrTest: ast::Expr = {
|
||||
<e1:AndTest> <location:@L> <e2:("or" AndTest)*> <end_location:@R> => {
|
||||
<location:@L> <e1:AndTest> <e2:("or" AndTest)*> <end_location:@R> => {
|
||||
if e2.is_empty() {
|
||||
e1
|
||||
} else {
|
||||
@@ -773,7 +773,7 @@ OrTest: ast::Expr = {
|
||||
};
|
||||
|
||||
AndTest: ast::Expr = {
|
||||
<e1:NotTest> <location:@L> <e2:("and" NotTest)*> <end_location:@R> => {
|
||||
<location:@L> <e1:NotTest> <e2:("and" NotTest)*> <end_location:@R> => {
|
||||
if e2.is_empty() {
|
||||
e1
|
||||
} else {
|
||||
|
||||
@@ -218,4 +218,18 @@ class Foo(A, B):
|
||||
let parse_ast = parse_expression(&source, "<test>").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, "<test>").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, "<test>").unwrap();
|
||||
insta::assert_debug_snapshot!(parse_ast);
|
||||
}
|
||||
}
|
||||
|
||||
56
compiler/parser/src/snapshots/rustpython_parser__parser__tests__parse_boolop_and.snap
generated
Normal file
56
compiler/parser/src/snapshots/rustpython_parser__parser__tests__parse_boolop_and.snap
generated
Normal file
@@ -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,
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
}
|
||||
56
compiler/parser/src/snapshots/rustpython_parser__parser__tests__parse_boolop_or.snap
generated
Normal file
56
compiler/parser/src/snapshots/rustpython_parser__parser__tests__parse_boolop_or.snap
generated
Normal file
@@ -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,
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
}
|
||||
Reference in New Issue
Block a user