Handle positional-only-arguments separator comments (#4748)

This commit is contained in:
Micha Reiser 2023-06-01 08:22:49 +02:00 committed by GitHub
parent be31d71849
commit b7294b48e7
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 442 additions and 0 deletions

View file

@ -716,4 +716,90 @@ def test(
assert_debug_snapshot!(comments.debug(test_case.source_code));
}
#[test]
fn positional_argument_only_comment() {
let source = r#"
def test(
a, # trailing positional comment
# Positional arguments only after here
/, # trailing positional argument comment.
# leading b comment
b,
): pass
"#;
let test_case = CommentsTestCase::from_code(source);
let comments = test_case.to_comments();
assert_debug_snapshot!(comments.debug(test_case.source_code));
}
#[test]
fn positional_argument_only_leading_comma_comment() {
let source = r#"
def test(
a # trailing positional comment
# Positional arguments only after here
,/, # trailing positional argument comment.
# leading b comment
b,
): pass
"#;
let test_case = CommentsTestCase::from_code(source);
let comments = test_case.to_comments();
assert_debug_snapshot!(comments.debug(test_case.source_code));
}
#[test]
fn positional_argument_only_comment_without_following_node() {
let source = r#"
def test(
a, # trailing positional comment
# Positional arguments only after here
/, # trailing positional argument comment.
# Trailing on new line
): pass
"#;
let test_case = CommentsTestCase::from_code(source);
let comments = test_case.to_comments();
assert_debug_snapshot!(comments.debug(test_case.source_code));
}
#[test]
fn non_positional_arguments_with_defaults() {
let source = r#"
def test(
a=10 # trailing positional comment
# Positional arguments only after here
,/, # trailing positional argument comment.
# leading comment for b
b=20
): pass
"#;
let test_case = CommentsTestCase::from_code(source);
let comments = test_case.to_comments();
assert_debug_snapshot!(comments.debug(test_case.source_code));
}
#[test]
fn non_positional_arguments_slash_on_same_line() {
let source = r#"
def test(a=10,/, # trailing positional argument comment.
# leading comment for b
b=20
): pass
"#;
let test_case = CommentsTestCase::from_code(source);
let comments = test_case.to_comments();
assert_debug_snapshot!(comments.debug(test_case.source_code));
}
}