From 1551d8fb0da07f2fb03e74ae2c2300b44dd02b75 Mon Sep 17 00:00:00 2001 From: Aidan Date: Sat, 17 Aug 2024 09:57:59 -0400 Subject: [PATCH] preserve multiline string trailing whitespace --- crates/compiler/fmt/src/expr.rs | 4 ++-- crates/compiler/test_syntax/tests/test_fmt.rs | 7 +++++++ 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/crates/compiler/fmt/src/expr.rs b/crates/compiler/fmt/src/expr.rs index f937a2c7e3..97f5b3f45a 100644 --- a/crates/compiler/fmt/src/expr.rs +++ b/crates/compiler/fmt/src/expr.rs @@ -627,8 +627,8 @@ fn fmt_str_body(body: &str, buf: &mut Buf) { '\u{200c}' => buf.push_str("\\u(200c)"), '\u{feff}' => buf.push_str("\\u(feff)"), // Don't change anything else in the string - ' ' => buf.spaces(1), - '\n' => buf.newline(), + ' ' => buf.push_str_allow_spaces(" "), + '\n' => buf.push_str_allow_spaces("\n"), _ => buf.push(c), } } diff --git a/crates/compiler/test_syntax/tests/test_fmt.rs b/crates/compiler/test_syntax/tests/test_fmt.rs index 519bcbd551..807825319f 100644 --- a/crates/compiler/test_syntax/tests/test_fmt.rs +++ b/crates/compiler/test_syntax/tests/test_fmt.rs @@ -6379,6 +6379,13 @@ mod test_fmt { ); } + #[test] + fn preserve_multiline_string_trailing_whitespace() { + expr_formats_same(indoc!( + "x =\n \"\"\"\n foo\n bar \n baz\n \"\"\"\nx" + )); + } + // this is a parse error atm // #[test] // fn multiline_apply() {