aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLiam Miller-Cushon <cushon@google.com>2024-05-01 11:39:18 -0700
committergoogle-java-format Team <google-java-format-dev+copybara@google.com>2024-05-01 11:40:07 -0700
commitbec248bb39e6abd8b79e8f9900135d263b6f7ad9 (patch)
tree4748d1ecff0c39d1e98e1f825ef92dec0408f6e5
parentfdf4b29a6e1206f451bd96ed7967f4061921881a (diff)
downloadgoogle-java-format-upstream-master.tar.gz
Add a test for trailing unicode escaped whitespace in text blocksupstream-master
PiperOrigin-RevId: 629785894
-rw-r--r--core/src/test/java/com/google/googlejavaformat/java/StringWrapperTest.java29
1 files changed, 29 insertions, 0 deletions
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 5ef7cb5..fd176ed 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 class StringWrapperTest {
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);