API: Add tests for UnicodeUtil - #17528
Open
uros-b wants to merge 2 commits into
Open
Conversation
uros-b
force-pushed
the
test-add-unicodeutil-coverage
branch
from
August 5, 2026 10:08
a8d5383 to
e591870
Compare
uros-b
commented
Aug 5, 2026
Cover isCharHighSurrogate, truncateString (including surrogate pairs and the non-positive length guard), and truncateStringMin/Max, including the overflow case where no greater bound exists.
uros-b
force-pushed
the
test-add-unicodeutil-coverage
branch
from
August 5, 2026 16:15
e591870 to
84b4161
Compare
szehon-ho
approved these changes
Aug 6, 2026
szehon-ho
left a comment
Member
There was a problem hiding this comment.
Looks good — test-only coverage for UnicodeUtil in the owning module, assertions match the implementation, and CI is green. Approving.
Optional follow-ups (not blocking): the String overload of truncateStringMax could also cover two paths that are already exercised for the Literal overload in TestMetricsTruncation:
- No truncation needed (early return when the input already fits):
assertThat(UnicodeUtil.truncateStringMax("abc", 5)).isEqualTo("abc");- Carry when the last retained code point overflows:
String input =
new StringBuilder()
.append('a')
.appendCodePoint(Character.MAX_CODE_POINT)
.append('c')
.toString();
assertThat(UnicodeUtil.truncateStringMax(input, 2)).isEqualTo("b");
ebyhr
approved these changes
Aug 6, 2026
ebyhr
left a comment
Member
There was a problem hiding this comment.
I think there is one more uncovered path in UnicodeUtil.incrementCodePoint L127. When the last retained code point is \uD7FF (one below MIN_SURROGATE), the method skips over the surrogate block and returns \uE000.
@Test
void truncateStringMaxSkipsSurrogateRange() {
// \uD7FF + 1 must skip the surrogate block (U+D800..U+DFFF) and return U+E000
String input = "\uD7FF" + "extra";
assertThat(UnicodeUtil.truncateStringMax(input, 1)).isEqualTo("\uE000");
}
nastra
reviewed
Aug 6, 2026
nastra
reviewed
Aug 6, 2026
nastra
approved these changes
Aug 7, 2026
Member
Author
|
Thank you folks @szehon-ho @ebyhr @nastra! |
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
UnicodeUtilhad no dedicated test class. This adds tests covering its public surface:isCharHighSurrogateat both ends of the high-surrogate range (0xD800-0xDBFF), plus a low surrogate and an ASCII char;truncateStringwhen no truncation is needed, when truncating by code points, and that a surrogate pair (emoji) is not split; theIllegalArgumentExceptionguard for a non-positive truncate length;truncateStringMin/truncateStringMax, including the overflow case where every retained code point is the maximum and no greater bound exists (returns null). Test-only changes.