-
Notifications
You must be signed in to change notification settings - Fork 863
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix an off-by-one issue on the reflowing of string literals.
During the initial width calculation, it seems we are off by one. The existing tests where actually also wrong (wrapped at 99). PiperOrigin-RevId: 356697501
- Loading branch information
1 parent
69ba30f
commit b9fd8d2
Showing
7 changed files
with
130 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 8 additions & 0 deletions
8
core/src/test/resources/com/google/googlejavaformat/java/testdata/B173808510.input
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
class B173808510 { | ||
// b/173808510 | ||
@FlagSpec( | ||
name = "myFlag", | ||
help = | ||
"areallyreallyreallyreallyreallyreallyreallyreallyreallyreallyreallyreallyloongword word1 word2") | ||
Flag<Integer> dummy = null; | ||
} |
9 changes: 9 additions & 0 deletions
9
core/src/test/resources/com/google/googlejavaformat/java/testdata/B173808510.output
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
class B173808510 { | ||
// b/173808510 | ||
@FlagSpec( | ||
name = "myFlag", | ||
help = | ||
"areallyreallyreallyreallyreallyreallyreallyreallyreallyreallyreallyreallyloongword word1" | ||
+ " word2") | ||
Flag<Integer> dummy = null; | ||
} |
44 changes: 44 additions & 0 deletions
44
core/src/test/resources/com/google/googlejavaformat/java/testdata/LiteralReflow.input
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
class LiteralReflow { | ||
static class TestLineBreak { | ||
String doesNotBreakAt100 = "A very long long long long long long long long long loong sentence"; | ||
String breaksAt101 = "A very long long long long long long long long long long loooong sentence"; | ||
} | ||
|
||
static class TestReflowLimit { | ||
String doesNotReflowAt100 = | ||
"A very long long long long long long long long long long long long long looooong sentence"; | ||
String reflowsWhenLongerThan100 = | ||
"A very long long long long long long long long long long long long long long long sentence"; | ||
} | ||
|
||
static class TestReflowLocation { | ||
String accommodatesWordsUpTo100 = | ||
"A very long long long long long long long long long long long long long long long looooong sentence"; | ||
String breaksBeforeWordsReach101 = | ||
"A very long long long long long long long long long long long long long long long loooooong sentence"; | ||
} | ||
|
||
static class Test2LineReflowLimit { | ||
String doesNotReflowEitherLinesAt100 = | ||
"A very long long long long long long long long long long long long long looooong sentence. And a second very long long long long long long long long long long loong sentence"; | ||
String reflowsLastLineAt101 = | ||
"A very long long long long long long long long long long long long long looooong sentence. And a second very long long long long long long long long long long looong sentence"; | ||
} | ||
|
||
static class TestWithTrailingCharacters { | ||
String fitsLastLineUpTo100WithTrailingCharacters = | ||
f( | ||
f( | ||
"A very long long long long long long long long long long long long loong sentence. And a second very long long long long long long long long loong sentence")); | ||
String reflowsLastLineToAccommodateTrailingCharacters = | ||
f( | ||
f( | ||
"A very long long long long long long long long long long long long loong sentence. And a second very long long long long long long long long looong sentence")); | ||
// Tests an off-by-one issue, but see b/179561701 for a similar issue that is not yet fixed | ||
String doesNotOverTriggerLastLineReflow = | ||
f( | ||
f( | ||
"A very long long long long long long long long long long long long loong sentence." | ||
+ " And a second very loong sentence with trailing a a a a a a a a a a a a a a a")); | ||
} | ||
} |
55 changes: 55 additions & 0 deletions
55
core/src/test/resources/com/google/googlejavaformat/java/testdata/LiteralReflow.output
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
class LiteralReflow { | ||
static class TestLineBreak { | ||
String doesNotBreakAt100 = "A very long long long long long long long long long loong sentence"; | ||
String breaksAt101 = | ||
"A very long long long long long long long long long long loooong sentence"; | ||
} | ||
|
||
static class TestReflowLimit { | ||
String doesNotReflowAt100 = | ||
"A very long long long long long long long long long long long long long looooong sentence"; | ||
String reflowsWhenLongerThan100 = | ||
"A very long long long long long long long long long long long long long long long" | ||
+ " sentence"; | ||
} | ||
|
||
static class TestReflowLocation { | ||
String accommodatesWordsUpTo100 = | ||
"A very long long long long long long long long long long long long long long long looooong" | ||
+ " sentence"; | ||
String breaksBeforeWordsReach101 = | ||
"A very long long long long long long long long long long long long long long long" | ||
+ " loooooong sentence"; | ||
} | ||
|
||
static class Test2LineReflowLimit { | ||
String doesNotReflowEitherLinesAt100 = | ||
"A very long long long long long long long long long long long long long looooong sentence." | ||
+ " And a second very long long long long long long long long long long loong sentence"; | ||
String reflowsLastLineAt101 = | ||
"A very long long long long long long long long long long long long long looooong sentence." | ||
+ " And a second very long long long long long long long long long long looong" | ||
+ " sentence"; | ||
} | ||
|
||
static class TestWithTrailingCharacters { | ||
String fitsLastLineUpTo100WithTrailingCharacters = | ||
f( | ||
f( | ||
"A very long long long long long long long long long long long long loong sentence." | ||
+ " And a second very long long long long long long long long loong sentence")); | ||
String reflowsLastLineToAccommodateTrailingCharacters = | ||
f( | ||
f( | ||
"A very long long long long long long long long long long long long loong sentence." | ||
+ " And a second very long long long long long long long long looong" | ||
+ " sentence")); | ||
// Tests an off-by-one issue, but see b/179561701 for a similar issue that is not yet fixed | ||
String doesNotOverTriggerLastLineReflow = | ||
f( | ||
f( | ||
"A very long long long long long long long long long long long long loong sentence." | ||
+ " And a second very loong sentence with trailing a a a a a a a a a a a a a a" | ||
+ " a")); | ||
} | ||
} |