From ce08d8fd9bd44b5abd05f919124fe7f85f7f039b Mon Sep 17 00:00:00 2001 From: ThrawnCA Date: Sat, 15 Nov 2025 09:28:28 +1000 Subject: [PATCH] add unit tests showing 'abbreviate' contract violations --- .../apache/commons/lang3/StringUtilsAbbreviateTest.java | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/test/java/org/apache/commons/lang3/StringUtilsAbbreviateTest.java b/src/test/java/org/apache/commons/lang3/StringUtilsAbbreviateTest.java index 49a188d06de..ca9033c5bc8 100644 --- a/src/test/java/org/apache/commons/lang3/StringUtilsAbbreviateTest.java +++ b/src/test/java/org/apache/commons/lang3/StringUtilsAbbreviateTest.java @@ -101,6 +101,9 @@ void testAbbreviate_StringIntInt() { assertAbbreviateWithOffset("...ijklmno", 15, 10); assertAbbreviateWithOffset("...ijklmno", 16, 10); assertAbbreviateWithOffset("...ijklmno", Integer.MAX_VALUE, 10); + + // abbreviating a shorter string allows maxWidth < 7 + assertEquals("...efg", StringUtils.abbreviate("abcdefg", 5, 6)); } @Test @@ -157,6 +160,10 @@ void testAbbreviate_StringStringIntInt() { assertAbbreviateWithAbbrevMarkerAndOffset("999ijklmno", "999", 15, 10); assertAbbreviateWithAbbrevMarkerAndOffset("_ghijklmno", "_", 16, 10); assertAbbreviateWithAbbrevMarkerAndOffset("+ghijklmno", "+", Integer.MAX_VALUE, 10); + + // abbreviating a shorter string allows maxWidth < abbrevMarker.length * 2 + 1 + assertEquals("..de", StringUtils.abbreviate("abcde", "..", 4, 4)); + assertEquals("....fg", StringUtils.abbreviate("abcdefg", "....", 5, 6)); } // Fixed LANG-1463