Place comments of left and right binary expression operands (#4751)

This commit is contained in:
Micha Reiser 2023-06-01 09:01:32 +02:00 committed by GitHub
parent 0945803427
commit 59148344be
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 362 additions and 18 deletions

View file

@ -802,4 +802,58 @@ def test(a=10,/, # trailing positional argument comment.
assert_debug_snapshot!(comments.debug(test_case.source_code));
}
#[test]
fn binary_expression_left_operand_comment() {
let source = r#"
a = (
5
# trailing left comment
+
# leading right comment
3
)
"#;
let test_case = CommentsTestCase::from_code(source);
let comments = test_case.to_comments();
assert_debug_snapshot!(comments.debug(test_case.source_code));
}
#[test]
fn binary_expression_left_operand_trailing_end_of_line_comment() {
let source = r#"
a = (
5 # trailing left comment
+ # trailing operator comment
# leading right comment
3
)
"#;
let test_case = CommentsTestCase::from_code(source);
let comments = test_case.to_comments();
assert_debug_snapshot!(comments.debug(test_case.source_code));
}
#[test]
fn nested_binary_expression() {
let source = r#"
a = (
(5 # trailing left comment
*
2)
+ # trailing operator comment
# leading right comment
3
)
"#;
let test_case = CommentsTestCase::from_code(source);
let comments = test_case.to_comments();
assert_debug_snapshot!(comments.debug(test_case.source_code));
}
}