mirror of
https://github.com/astral-sh/ruff.git
synced 2025-10-01 06:11:43 +00:00
Place comments of left and right binary expression operands (#4751)
This commit is contained in:
parent
0945803427
commit
59148344be
7 changed files with 362 additions and 18 deletions
|
@ -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));
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue