Skip to content

Commit bec248b

Browse files
cushongoogle-java-format Team
authored and
google-java-format Team
committed
Add a test for trailing unicode escaped whitespace in text blocks
PiperOrigin-RevId: 629785894
1 parent fdf4b29 commit bec248b

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

core/src/test/java/com/google/googlejavaformat/java/StringWrapperTest.java

+29
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,35 @@ public void textBlockTrailingWhitespace() throws Exception {
119119
assertThat(actual).isEqualTo(expected);
120120
}
121121

122+
// It would be neat if the formatter could remove the trailing whitespace here, but in general
123+
// it preserves unicode escapes from the original text.
124+
@Test
125+
public void textBlockTrailingWhitespaceUnicodeEscape() throws Exception {
126+
assumeTrue(Runtime.version().feature() >= 15);
127+
// We want a unicode escape in the Java source being formatted, so it needs to be escaped
128+
// in the string literal in this test.
129+
String input =
130+
lines(
131+
"public class T {",
132+
" String s =",
133+
" \"\"\"",
134+
" lorem\\u0020",
135+
" ipsum",
136+
" \"\"\";",
137+
"}");
138+
String expected =
139+
lines(
140+
"public class T {",
141+
" String s =",
142+
" \"\"\"",
143+
" lorem\\u0020",
144+
" ipsum",
145+
" \"\"\";",
146+
"}");
147+
String actual = StringWrapper.wrap(100, input, new Formatter());
148+
assertThat(actual).isEqualTo(expected);
149+
}
150+
122151
@Test
123152
public void textBlockSpaceTabMix() throws Exception {
124153
assumeTrue(Runtime.version().feature() >= 15);

0 commit comments

Comments
 (0)