@@ -101,13 +101,16 @@ 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
107110 void testAbbreviate_StringStringInt () {
108111 assertNull (StringUtils .abbreviate (null , null , 10 ));
109112 assertNull (StringUtils .abbreviate (null , "..." , 10 ));
110- assertEquals ("paranaguacu " , StringUtils .abbreviate ("paranaguacu" , null , 10 ));
113+ assertEquals ("paranaguac " , StringUtils .abbreviate ("paranaguacu" , null , 10 ));
111114 assertEquals ("" , StringUtils .abbreviate ("" , "..." , 2 ));
112115 assertEquals ("wai**" , StringUtils .abbreviate ("waiheke" , "**" , 5 ));
113116 assertEquals ("And af,,,," , StringUtils .abbreviate ("And after a long time, he finally met his son." , ",,,," , 10 ));
@@ -130,6 +133,12 @@ void testAbbreviate_StringStringIntInt() {
130133 assertNull (StringUtils .abbreviate (null , "..." , 10 , 12 ));
131134 assertEquals ("" , StringUtils .abbreviate ("" , null , 0 , 10 ));
132135 assertEquals ("" , StringUtils .abbreviate ("" , "..." , 2 , 10 ));
136+ assertEquals ("abcdefg" , StringUtils .abbreviate ("abcdefg" , null , 2 , 10 ));
137+ assertEquals ("abcdefg" , StringUtils .abbreviate ("abcdefg" , "" , 2 , 10 ));
138+ assertEquals ("abc" , StringUtils .abbreviate ("abcdefg" , null , 0 , 3 ));
139+ assertEquals ("cde" , StringUtils .abbreviate ("abcdefg" , null , 2 , 3 ));
140+ assertEquals ("abc" , StringUtils .abbreviate ("abcdefg" , "" , 0 , 3 ));
141+ assertEquals ("cde" , StringUtils .abbreviate ("abcdefg" , "" , 2 , 3 ));
133142 assertIllegalArgumentException (() -> StringUtils .abbreviate ("abcdefghij" , "::" , 0 , 2 ),
134143 "StringUtils.abbreviate expecting IllegalArgumentException" );
135144 assertIllegalArgumentException (() -> StringUtils .abbreviate ("abcdefghij" , "!!!" , 5 , 6 ),
@@ -157,6 +166,10 @@ void testAbbreviate_StringStringIntInt() {
157166 assertAbbreviateWithAbbrevMarkerAndOffset ("999ijklmno" , "999" , 15 , 10 );
158167 assertAbbreviateWithAbbrevMarkerAndOffset ("_ghijklmno" , "_" , 16 , 10 );
159168 assertAbbreviateWithAbbrevMarkerAndOffset ("+ghijklmno" , "+" , Integer .MAX_VALUE , 10 );
169+
170+ // abbreviating a shorter string allows maxWidth < abbrevMarker.length * 2 + 1
171+ assertEquals ("..de" , StringUtils .abbreviate ("abcde" , ".." , 4 , 4 ));
172+ assertEquals ("....fg" , StringUtils .abbreviate ("abcdefg" , "...." , 5 , 6 ));
160173 }
161174
162175 // Fixed LANG-1463
0 commit comments