From bec248bb39e6abd8b79e8f9900135d263b6f7ad9 Mon Sep 17 00:00:00 2001 From: Liam Miller-Cushon Date: Wed, 1 May 2024 11:39:18 -0700 Subject: [PATCH] Add a test for trailing unicode escaped whitespace in text blocks PiperOrigin-RevId: 629785894 --- .../java/StringWrapperTest.java | 29 +++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/core/src/test/java/com/google/googlejavaformat/java/StringWrapperTest.java b/core/src/test/java/com/google/googlejavaformat/java/StringWrapperTest.java index 5ef7cb51a..fd176ed4e 100644 --- a/core/src/test/java/com/google/googlejavaformat/java/StringWrapperTest.java +++ b/core/src/test/java/com/google/googlejavaformat/java/StringWrapperTest.java @@ -119,6 +119,35 @@ public void textBlockTrailingWhitespace() throws Exception { assertThat(actual).isEqualTo(expected); } + // It would be neat if the formatter could remove the trailing whitespace here, but in general + // it preserves unicode escapes from the original text. + @Test + public void textBlockTrailingWhitespaceUnicodeEscape() throws Exception { + assumeTrue(Runtime.version().feature() >= 15); + // We want a unicode escape in the Java source being formatted, so it needs to be escaped + // in the string literal in this test. + String input = + lines( + "public class T {", + " String s =", + " \"\"\"", + " lorem\\u0020", + " ipsum", + " \"\"\";", + "}"); + String expected = + lines( + "public class T {", + " String s =", + " \"\"\"", + " lorem\\u0020", + " ipsum", + " \"\"\";", + "}"); + String actual = StringWrapper.wrap(100, input, new Formatter()); + assertThat(actual).isEqualTo(expected); + } + @Test public void textBlockSpaceTabMix() throws Exception { assumeTrue(Runtime.version().feature() >= 15);