Increase test coverage
git-svn-id: https://svn.apache.org/repos/asf/jakarta/commons/proper/lang/trunk@232876 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
922d48ed40
commit
eea36f49f6
|
@ -1692,10 +1692,15 @@ public class StrBuilder implements Cloneable {
|
|||
return -1;
|
||||
}
|
||||
int strLen = str.length();
|
||||
if (strLen > 0 && strLen <= size) {
|
||||
if (strLen == 1) {
|
||||
return indexOf(str.charAt(0), startIndex);
|
||||
}
|
||||
if (strLen == 0) {
|
||||
return startIndex;
|
||||
}
|
||||
if (strLen > size) {
|
||||
return -1;
|
||||
}
|
||||
char[] thisBuf = buffer;
|
||||
outer:
|
||||
for (int i = startIndex; i < thisBuf.length - strLen; i++) {
|
||||
|
@ -1706,10 +1711,6 @@ public class StrBuilder implements Cloneable {
|
|||
}
|
||||
return i;
|
||||
}
|
||||
|
||||
} else if (strLen == 0) {
|
||||
return 0;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
@ -1745,14 +1746,12 @@ public class StrBuilder implements Cloneable {
|
|||
return -1;
|
||||
}
|
||||
int len = size;
|
||||
if (len > 0) {
|
||||
char[] buf = buffer;
|
||||
for (int i = startIndex; i < len; i++) {
|
||||
if (matcher.isMatch(buf, i, startIndex, len) > 0) {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
@ -1867,8 +1866,6 @@ public class StrBuilder implements Cloneable {
|
|||
if (matcher == null || startIndex < 0) {
|
||||
return -1;
|
||||
}
|
||||
int len = size;
|
||||
if (len > 0) {
|
||||
char[] buf = buffer;
|
||||
int endIndex = startIndex + 1;
|
||||
for (int i = startIndex; i >= 0; i--) {
|
||||
|
@ -1876,7 +1873,6 @@ public class StrBuilder implements Cloneable {
|
|||
return i;
|
||||
}
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
|
|
@ -689,6 +689,8 @@ public class StrBuilderTest extends TestCase {
|
|||
assertEquals("dececced", sb.toString());
|
||||
sb.replaceAll('c', 'f');
|
||||
assertEquals("defeffed", sb.toString());
|
||||
sb.replaceAll('d', 'd');
|
||||
assertEquals("defeffed", sb.toString());
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
@ -702,6 +704,8 @@ public class StrBuilderTest extends TestCase {
|
|||
assertEquals("decbccba", sb.toString());
|
||||
sb.replaceFirst('c', 'f');
|
||||
assertEquals("defbccba", sb.toString());
|
||||
sb.replaceAll('d', 'd');
|
||||
assertEquals("defbccba", sb.toString());
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
@ -1102,6 +1106,7 @@ public class StrBuilderTest extends TestCase {
|
|||
assertEquals("hello", sb.midString(-5, 5));
|
||||
assertEquals("", sb.midString(0, -1));
|
||||
assertEquals("", sb.midString(20, 2));
|
||||
assertEquals("hello", sb.midString(14, 22));
|
||||
}
|
||||
|
||||
public void testRightString() {
|
||||
|
@ -1155,8 +1160,8 @@ public class StrBuilderTest extends TestCase {
|
|||
// -----------------------------------------------------------------------
|
||||
public void testIndexOf_char() {
|
||||
StrBuilder sb = new StrBuilder("abab");
|
||||
|
||||
assertEquals(0, sb.indexOf('a'));
|
||||
|
||||
// should work like String#indexOf
|
||||
assertEquals("abab".indexOf('a'), sb.indexOf('a'));
|
||||
|
||||
|
@ -1168,8 +1173,12 @@ public class StrBuilderTest extends TestCase {
|
|||
|
||||
public void testIndexOf_char_int() {
|
||||
StrBuilder sb = new StrBuilder("abab");
|
||||
|
||||
assertEquals(0, sb.indexOf('a', -1));
|
||||
assertEquals(0, sb.indexOf('a', 0));
|
||||
assertEquals(2, sb.indexOf('a', 1));
|
||||
assertEquals(-1, sb.indexOf('a', 4));
|
||||
assertEquals(-1, sb.indexOf('a', 5));
|
||||
|
||||
// should work like String#indexOf
|
||||
assertEquals("abab".indexOf('a', 1), sb.indexOf('a', 1));
|
||||
|
||||
|
@ -1198,8 +1207,10 @@ public class StrBuilderTest extends TestCase {
|
|||
|
||||
public void testLastIndexOf_char_int() {
|
||||
StrBuilder sb = new StrBuilder("abab");
|
||||
|
||||
assertEquals(-1, sb.lastIndexOf('a', -1));
|
||||
assertEquals(0, sb.lastIndexOf('a', 0));
|
||||
assertEquals(0, sb.lastIndexOf('a', 1));
|
||||
|
||||
// should work like String#lastIndexOf
|
||||
assertEquals("abab".lastIndexOf('a', 1), sb.lastIndexOf('a', 1));
|
||||
|
||||
|
@ -1238,8 +1249,18 @@ public class StrBuilderTest extends TestCase {
|
|||
|
||||
public void testIndexOf_String_int() {
|
||||
StrBuilder sb = new StrBuilder("abab");
|
||||
|
||||
assertEquals(0, sb.indexOf("a", -1));
|
||||
assertEquals(0, sb.indexOf("a", 0));
|
||||
assertEquals(2, sb.indexOf("a", 1));
|
||||
assertEquals(2, sb.indexOf("a", 2));
|
||||
assertEquals(-1, sb.indexOf("a", 3));
|
||||
assertEquals(-1, sb.indexOf("a", 4));
|
||||
assertEquals(-1, sb.indexOf("a", 5));
|
||||
|
||||
assertEquals(-1, sb.indexOf("abcdef", 0));
|
||||
assertEquals(0, sb.indexOf("", 0));
|
||||
assertEquals(1, sb.indexOf("", 1));
|
||||
|
||||
//should work like String#indexOf
|
||||
assertEquals ("abab".indexOf("a", 1), sb.indexOf("a", 1));
|
||||
|
||||
|
@ -1286,8 +1307,18 @@ public class StrBuilderTest extends TestCase {
|
|||
|
||||
public void testLastIndexOf_String_int() {
|
||||
StrBuilder sb = new StrBuilder("abab");
|
||||
|
||||
assertEquals(-1, sb.lastIndexOf("a", -1));
|
||||
assertEquals(0, sb.lastIndexOf("a", 0));
|
||||
assertEquals(0, sb.lastIndexOf("a", 1));
|
||||
assertEquals(2, sb.lastIndexOf("a", 2));
|
||||
assertEquals(2, sb.lastIndexOf("a", 3));
|
||||
assertEquals(2, sb.lastIndexOf("a", 4));
|
||||
assertEquals(2, sb.lastIndexOf("a", 5));
|
||||
|
||||
assertEquals(-1, sb.lastIndexOf("abcdef", 3));
|
||||
assertEquals("abab".lastIndexOf("", 3), sb.lastIndexOf("", 3));
|
||||
assertEquals("abab".lastIndexOf("", 1), sb.lastIndexOf("", 1));
|
||||
|
||||
//should work like String#lastIndexOf
|
||||
assertEquals("abab".lastIndexOf("a", 1), sb.lastIndexOf("a", 1));
|
||||
|
||||
|
@ -1332,6 +1363,7 @@ public class StrBuilderTest extends TestCase {
|
|||
StrBuilder sb = new StrBuilder();
|
||||
assertEquals(-1, sb.indexOf((StrMatcher) null, 2));
|
||||
assertEquals(-1, sb.indexOf(StrMatcher.charMatcher('a'), 2));
|
||||
assertEquals(-1, sb.indexOf(StrMatcher.charMatcher('a'), 0));
|
||||
|
||||
sb.append("ab bd");
|
||||
assertEquals(0, sb.indexOf(StrMatcher.charMatcher('a'), -2));
|
||||
|
@ -1387,6 +1419,8 @@ public class StrBuilderTest extends TestCase {
|
|||
StrBuilder sb = new StrBuilder();
|
||||
assertEquals(-1, sb.lastIndexOf((StrMatcher) null, 2));
|
||||
assertEquals(-1, sb.lastIndexOf(StrMatcher.charMatcher('a'), 2));
|
||||
assertEquals(-1, sb.lastIndexOf(StrMatcher.charMatcher('a'), 0));
|
||||
assertEquals(-1, sb.lastIndexOf(StrMatcher.charMatcher('a'), -1));
|
||||
|
||||
sb.append("ab bd");
|
||||
assertEquals(-1, sb.lastIndexOf(StrMatcher.charMatcher('a'), -2));
|
||||
|
|
Loading…
Reference in New Issue