Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix logic for checking if text blocks are already deindented #1191

Merged
merged 1 commit into from
Nov 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,8 @@ private void indentTextBlocks(
String stripped = stripIndent(initialLines.stream().skip(1).collect(joining(separator)));
ImmutableList<String> lines = stripped.lines().collect(toImmutableList());
int deindent =
initialLines.get(1).stripTrailing().length() - lines.get(0).stripTrailing().length();
getLast(initialLines).stripTrailing().length()
- getLast(lines).stripTrailing().length();

String prefix =
(deindent == 0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,33 @@ public void textBlockSpaceTabMix() throws Exception {
assertThat(actual).isEqualTo(expected);
}

@Test
public void leadingBlankLine() throws Exception {
assumeTrue(Runtime.version().feature() >= 15);
String input =
lines(
"public class T {",
" String s =",
" \"\"\"",
"",
" lorem",
" ipsum",
" \"\"\";",
"}");
String expected =
lines(
"public class T {",
" String s =",
" \"\"\"",
"",
" lorem",
" ipsum",
" \"\"\";",
"}");
String actual = StringWrapper.wrap(100, input, new Formatter());
assertThat(actual).isEqualTo(expected);
}

private static String lines(String... line) {
return Joiner.on('\n').join(line) + '\n';
}
Expand Down
Loading