Skip to content

[LANG-1770] Count abbreviation widths in Unicode code points - #1841

Closed
Mr-KnightCLI wants to merge 6 commits into
apache:masterfrom
Mr-KnightCLI:LANG-1770-codepoint-abbreviation
Closed

Mr-KnightCLI wants to merge 6 commits into
apache:masterfrom
Mr-KnightCLI:LANG-1770-codepoint-abbreviation

Conversation

@Mr-KnightCLI

Copy link
Copy Markdown

Summary

Completes the code-point-aware abbreviation work tracked by LANG-1770. The existing regression test records expected results for supplementary characters, but its assertions were disabled.

  • Count the source string and replacement marker in Unicode code points.
  • Interpret abbreviation offsets and widths as code-point counts, converting to UTF-16 indices only when slicing.
  • Update the Javadoc to describe the code-point behavior.
  • Enable the expected output assertions for supplementary characters and family sequences. Width is measured in code points; grapheme clusters remain separate code points by design.

This preserves existing results for BMP-only strings while preventing abbreviation boundaries from splitting supplementary characters.

Validation

The regression assertions are enabled. I have not run the default Maven build locally; CI will validate this pull request.

Contribution checklist

  • Read the contribution guidelines.
  • Read the ASF Generative Tooling Guidance.
  • AI tool and scope disclosed: OpenAI Codex generated the implementation and regression-test changes. No independent human review was performed before submission.
  • Run the default Maven build (mvn); not run locally.
  • Add regression assertions for the reported behavior.
  • Describe what changed, how, and why.
  • Use meaningful commit subjects with the LANG-1770 key and Generated-by provenance.

@garydgregory garydgregory left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Mr-KnightCLI
Thank you for the PR. Please see my comment.

"👩🏻‍👨🏻‍...",
"👩🏻‍👨🏻‍👦..."
};
final String[] expectedResultsFamilyWithGrapheme = {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't delete this, instead, use it in a test. This method should be converted into more than one parameterized test method.

@Mr-KnightCLI

Copy link
Copy Markdown
Author

I’ve corrected this in the PR. I kept the family-grapheme expected values and now use them in a parameterized test, with the emoji cases split into separate parameterized test methods. Thanks for the guidance.

@garydgregory

Copy link
Copy Markdown
Member

@Mr-KnightCLI
The build fails again, this time with:

[ERROR] Tests run: 29, Failures: 1, Errors: 0, Skipped: 0, Time elapsed: 0.024 s <<< FAILURE! -- in org.apache.commons.lang3.StringUtilsAbbreviateTest
[ERROR] org.apache.commons.lang3.StringUtilsAbbreviateTest.testAbbreviateSurrogatePair -- Time elapsed: 0.004 s <<< FAILURE!
org.opentest4j.AssertionFailedError: expected: <...?> but was: <...f?>
	at org.junit.jupiter.api.AssertionFailureBuilder.build(AssertionFailureBuilder.java:151)
	at org.junit.jupiter.api.AssertionFailureBuilder.buildAndThrow(AssertionFailureBuilder.java:132)
	at org.junit.jupiter.api.AssertEquals.failNotEqual(AssertEquals.java:197)
	at org.junit.jupiter.api.AssertEquals.assertEquals(AssertEquals.java:182)
	at org.junit.jupiter.api.AssertEquals.assertEquals(AssertEquals.java:177)
	at org.junit.jupiter.api.Assertions.assertEquals(Assertions.java:1145)
	at org.apache.commons.lang3.StringUtilsAbbreviateTest.testAbbreviateSurrogatePair(StringUtilsAbbreviateTest.java:253)
	at java.lang.reflect.Method.invoke(Method.java:498)
	at java.util.ArrayList.forEach(ArrayList.java:1259)
	at java.util.ArrayList.forEach(ArrayList.java:1259)

Please DO NOT push changes that you have not tested locally, this wastes our runner resources.

@garydgregory
garydgregory marked this pull request as draft October 26, 2026 14:45
@Mr-KnightCLI

Copy link
Copy Markdown
Author

Thanks for pointing out the failing expectations. I corrected them and ran mvn -pl . -Dtest=StringUtilsAbbreviateTest -Ddoclint=all test locally. The focused test passed: 29 tests, 0 failures.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants