Skip to content

Commit ce08d8f

Browse files
committed
add unit tests showing 'abbreviate' contract violations
1 parent 09b30e3 commit ce08d8f

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

src/test/java/org/apache/commons/lang3/StringUtilsAbbreviateTest.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,9 @@ void testAbbreviate_StringIntInt() {
101101
assertAbbreviateWithOffset("...ijklmno", 15, 10);
102102
assertAbbreviateWithOffset("...ijklmno", 16, 10);
103103
assertAbbreviateWithOffset("...ijklmno", Integer.MAX_VALUE, 10);
104+
105+
// abbreviating a shorter string allows maxWidth < 7
106+
assertEquals("...efg", StringUtils.abbreviate("abcdefg", 5, 6));
104107
}
105108

106109
@Test
@@ -157,6 +160,10 @@ void testAbbreviate_StringStringIntInt() {
157160
assertAbbreviateWithAbbrevMarkerAndOffset("999ijklmno", "999", 15, 10);
158161
assertAbbreviateWithAbbrevMarkerAndOffset("_ghijklmno", "_", 16, 10);
159162
assertAbbreviateWithAbbrevMarkerAndOffset("+ghijklmno", "+", Integer.MAX_VALUE, 10);
163+
164+
// abbreviating a shorter string allows maxWidth < abbrevMarker.length * 2 + 1
165+
assertEquals("..de", StringUtils.abbreviate("abcde", "..", 4, 4));
166+
assertEquals("....fg", StringUtils.abbreviate("abcdefg", "....", 5, 6));
160167
}
161168

162169
// Fixed LANG-1463

0 commit comments

Comments
 (0)