commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From scolebou...@apache.org
Subject svn commit: r232876 - in /jakarta/commons/proper/lang/trunk/src: java/org/apache/commons/lang/text/StrBuilder.java test/org/apache/commons/lang/text/StrBuilderTest.java
Date Mon, 15 Aug 2005 20:57:12 GMT
Author: scolebourne
Date: Mon Aug 15 13:57:06 2005
New Revision: 232876

URL: http://svn.apache.org/viewcvs?rev=232876&view=rev
Log:
Increase test coverage

Modified:
    jakarta/commons/proper/lang/trunk/src/java/org/apache/commons/lang/text/StrBuilder.java
    jakarta/commons/proper/lang/trunk/src/test/org/apache/commons/lang/text/StrBuilderTest.java

Modified: jakarta/commons/proper/lang/trunk/src/java/org/apache/commons/lang/text/StrBuilder.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/lang/trunk/src/java/org/apache/commons/lang/text/StrBuilder.java?rev=232876&r1=232875&r2=232876&view=diff
==============================================================================
--- jakarta/commons/proper/lang/trunk/src/java/org/apache/commons/lang/text/StrBuilder.java
(original)
+++ jakarta/commons/proper/lang/trunk/src/java/org/apache/commons/lang/text/StrBuilder.java
Mon Aug 15 13:57:06 2005
@@ -1692,23 +1692,24 @@
             return -1;
         }
         int strLen = str.length();
-        if (strLen > 0 && strLen <= size) {
-            if (strLen == 1) {
-                return indexOf(str.charAt(0), startIndex);
-            }
-            char[] thisBuf = buffer;
-            outer:
-            for (int i = startIndex; i < thisBuf.length - strLen; i++) {
-                for (int j = 0; j < strLen; j++) {
-                    if (str.charAt(j) != thisBuf[i + j]) {
-                        continue outer;
-                    }
+        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++) {
+            for (int j = 0; j < strLen; j++) {
+                if (str.charAt(j) != thisBuf[i + j]) {
+                    continue outer;
                 }
-                return i;
             }
-            
-        } else if (strLen == 0) {
-            return 0;
+            return i;
         }
         return -1;
     }
@@ -1745,12 +1746,10 @@
             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;
-                }
+        char[] buf = buffer;
+        for (int i = startIndex; i < len; i++) {
+            if (matcher.isMatch(buf, i, startIndex, len) > 0) {
+                return i;
             }
         }
         return -1;
@@ -1867,14 +1866,11 @@
         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--) {
-                if (matcher.isMatch(buf, i, 0, endIndex) > 0) {
-                    return i;
-                }
+        char[] buf = buffer;
+        int endIndex = startIndex + 1;
+        for (int i = startIndex; i >= 0; i--) {
+            if (matcher.isMatch(buf, i, 0, endIndex) > 0) {
+                return i;
             }
         }
         return -1;

Modified: jakarta/commons/proper/lang/trunk/src/test/org/apache/commons/lang/text/StrBuilderTest.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/lang/trunk/src/test/org/apache/commons/lang/text/StrBuilderTest.java?rev=232876&r1=232875&r2=232876&view=diff
==============================================================================
--- jakarta/commons/proper/lang/trunk/src/test/org/apache/commons/lang/text/StrBuilderTest.java
(original)
+++ jakarta/commons/proper/lang/trunk/src/test/org/apache/commons/lang/text/StrBuilderTest.java
Mon Aug 15 13:57:06 2005
@@ -689,6 +689,8 @@
         assertEquals("dececced", sb.toString());
         sb.replaceAll('c', 'f');
         assertEquals("defeffed", sb.toString());
+        sb.replaceAll('d', 'd');
+        assertEquals("defeffed", sb.toString());
     }
 
     //-----------------------------------------------------------------------
@@ -702,6 +704,8 @@
         assertEquals("decbccba", sb.toString());
         sb.replaceFirst('c', 'f');
         assertEquals("defbccba", sb.toString());
+        sb.replaceAll('d', 'd');
+        assertEquals("defbccba", sb.toString());
     }
 
     //-----------------------------------------------------------------------
@@ -1102,6 +1106,7 @@
         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,32 +1160,36 @@
     // -----------------------------------------------------------------------
     public void testIndexOf_char() {
         StrBuilder sb = new StrBuilder("abab");
+        assertEquals(0, sb.indexOf('a'));
         
-        assertEquals (0, sb.indexOf('a'));
-        //should work like String#indexOf
-        assertEquals ("abab".indexOf('a'), sb.indexOf('a'));
-        
+        // should work like String#indexOf
+        assertEquals("abab".indexOf('a'), sb.indexOf('a'));
+
         assertEquals(1, sb.indexOf('b'));
-        assertEquals ("abab".indexOf('b'), sb.indexOf('b'));
-        
-        assertEquals (-1, sb.indexOf('z'));
+        assertEquals("abab".indexOf('b'), sb.indexOf('b'));
+
+        assertEquals(-1, sb.indexOf('z'));
     }
 
     public void testIndexOf_char_int() {
         StrBuilder sb = new StrBuilder("abab");
-        
-        assertEquals (2, sb.indexOf('a', 1));
-        //should work like String#indexOf
-        assertEquals ("abab".indexOf('a', 1), sb.indexOf('a', 1));
-        
+        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));
+
         assertEquals(3, sb.indexOf('b', 2));
-        assertEquals ("abab".indexOf('b', 2), sb.indexOf('b', 2));
-        
-        assertEquals (-1, sb.indexOf('z', 2));
-        
+        assertEquals("abab".indexOf('b', 2), sb.indexOf('b', 2));
+
+        assertEquals(-1, sb.indexOf('z', 2));
+
         sb = new StrBuilder("xyzabc");
-        assertEquals (2, sb.indexOf('z', 0));
-        assertEquals (-1, sb.indexOf('z', 3));
+        assertEquals(2, sb.indexOf('z', 0));
+        assertEquals(-1, sb.indexOf('z', 3));
     }
 
     public void testLastIndexOf_char() {
@@ -1198,22 +1207,24 @@
 
     public void testLastIndexOf_char_int() {
         StrBuilder sb = new StrBuilder("abab");
-        
-        assertEquals (0, sb.lastIndexOf('a', 1));
-        //should work like String#lastIndexOf
-        assertEquals ("abab".lastIndexOf('a', 1), sb.lastIndexOf('a', 1));
-        
+        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));
+
         assertEquals(1, sb.lastIndexOf('b', 2));
-        assertEquals ("abab".lastIndexOf('b', 2), sb.lastIndexOf('b', 2));
-        
-        assertEquals (-1, sb.lastIndexOf('z', 2));
-        
+        assertEquals("abab".lastIndexOf('b', 2), sb.lastIndexOf('b', 2));
+
+        assertEquals(-1, sb.lastIndexOf('z', 2));
+
         sb = new StrBuilder("xyzabc");
-        assertEquals (2, sb.lastIndexOf('z', sb.length()));
-        assertEquals (-1, sb.lastIndexOf('z', 1));
+        assertEquals(2, sb.lastIndexOf('z', sb.length()));
+        assertEquals(-1, sb.lastIndexOf('z', 1));
     }
 
-    //-----------------------------------------------------------------------
+    // -----------------------------------------------------------------------
     public void testIndexOf_String() {
         StrBuilder sb = new StrBuilder("abab");
         
@@ -1238,8 +1249,18 @@
 
     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 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 @@
         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 @@
         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));



---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org


Mime
View raw message