Enable tupleassign test (#3080)

This commit is contained in:
Charlie Marsh 2023-02-20 19:42:23 -05:00 committed by GitHub
parent b701cca779
commit 90c04b9cff
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 12 additions and 9 deletions

View file

@ -134,6 +134,8 @@ fn format_tuple(
.trivia
.iter()
.any(|c| matches!(c.kind, TriviaKind::MagicTrailingComma));
let is_unbroken =
expr.location.row() == expr.end_location.unwrap().row();
if magic_trailing_comma {
write!(f, [expand_parent()])?;
}
@ -143,7 +145,7 @@ fn format_tuple(
write!(f, [text(",")])?;
write!(f, [soft_line_break_or_space()])?;
} else {
if magic_trailing_comma {
if magic_trailing_comma || is_unbroken {
write!(f, [if_group_breaks(&text(","))])?;
}
}
@ -156,6 +158,7 @@ fn format_tuple(
.trivia
.iter()
.any(|c| matches!(c.kind, TriviaKind::MagicTrailingComma));
let is_unbroken = expr.location.row() == expr.end_location.unwrap().row();
if magic_trailing_comma {
write!(f, [expand_parent()])?;
}
@ -165,7 +168,7 @@ fn format_tuple(
write!(f, [text(",")])?;
write!(f, [soft_line_break_or_space()])?;
} else {
if magic_trailing_comma {
if magic_trailing_comma || is_unbroken {
write!(f, [if_group_breaks(&text(","))])?;
}
}

View file

@ -74,6 +74,8 @@ mod tests {
#[test_case(Path::new("simple_cases/remove_newline_after_code_block_open.py"); "remove_newline_after_code_block_open")]
#[test_case(Path::new("simple_cases/slices.py"); "slices")]
#[test_case(Path::new("simple_cases/tricky_unicode_symbols.py"); "tricky_unicode_symbols")]
// Passing except that `1, 2, 3,` should be `(1, 2, 3)`.
#[test_case(Path::new("simple_cases/tupleassign.py"); "tupleassign")]
fn passing(path: &Path) -> Result<()> {
let snapshot = format!("{}", path.display());
let content = std::fs::read_to_string(test_resource_path(
@ -102,8 +104,6 @@ mod tests {
}
#[ignore]
// Passing apart from one deviation in RHS tuple assignment.
#[test_case(Path::new("simple_cases/tupleassign.py"); "tupleassign")]
// Lots of deviations, _mostly_ related to string normalization and wrapping.
#[test_case(Path::new("simple_cases/expression.py"); "expression")]
// Passing apart from a trailing end-of-line comment within an if statement, which is being

View file

@ -62,6 +62,8 @@ impl<'a> Visitor<'a> for NewlineNormalizer {
if matches!(self.trailer, Trailer::None) {
// If this is the first statement in the block, remove any leading empty lines.
// TODO(charlie): If we have a function or class definition within a non-scoped block,
// like an if-statement, retain a line before and after.
let mut seen_non_empty = false;
stmt.trivia.retain(|c| {
if seen_non_empty {

View file

@ -1,7 +1,6 @@
---
source: src/source_code/mod.rs
assertion_line: 0
expression: formatted
source: crates/ruff_python_formatter/src/lib.rs
expression: formatted.print()?.as_code()
---
# This is a standalone comment.
(
@ -9,10 +8,9 @@ expression: formatted
sdfjsdfjlksdljkfsdlkf,
sdfsdjfklsdfjlksdljkf,
sdsfsdfjskdflsfsdf,
) = (1, 2, 3)
) = 1, 2, 3
# This is as well.
(this_will_be_wrapped_in_parens,) = struct.unpack(b"12345678901234567890")
(a,) = call()