commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From pste...@apache.org
Subject cvs commit: jakarta-commons/lang/src/test/org/apache/commons/lang StringUtilsTest.java
Date Sun, 23 Nov 2003 20:44:39 GMT
psteitz     2003/11/23 12:44:39

  Modified:    lang/src/java/org/apache/commons/lang StringUtils.java
               lang/src/test/org/apache/commons/lang StringUtilsTest.java
  Log:
  Fixed error in javadoc for StringUtils.split and improved tests.
  Pr: 24911
  Submitted by Al Chou.
  
  Revision  Changes    Path
  1.118     +9 -5      jakarta-commons/lang/src/java/org/apache/commons/lang/StringUtils.java
  
  Index: StringUtils.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/lang/src/java/org/apache/commons/lang/StringUtils.java,v
  retrieving revision 1.117
  retrieving revision 1.118
  diff -u -r1.117 -r1.118
  --- StringUtils.java	4 Nov 2003 21:00:22 -0000	1.117
  +++ StringUtils.java	23 Nov 2003 20:44:39 -0000	1.118
  @@ -2087,22 +2087,26 @@
       }
   
       /**
  -     * <p>Splits the provided text into an array, separators specified.
  -     * This is an alternative to using StringTokenizer.</p>
  +     * <p>Splits the provided text into an array with a maximum length, 
  +     * separators specified.</p>
        *
        * <p>The separator is not included in the returned String array.
        * Adjacent separators are treated as one separator.</p>
        *
        * <p>A <code>null</code> input String returns <code>null</code>.
        * A <code>null</code> separatorChars splits on whitespace.</p>
  -     * 
  +     *
  +     * <p>If more than <code>max</code> delimited substrings are found,
the last 
  +     * returned string includes all characters after the first <code>max - 1</code>
  +     * returned strings (including separator characters).</p>
  +     *
        * <pre>
        * StringUtils.split(null, *, *)            = null
        * StringUtils.split("", *, *)              = []
        * StringUtils.split("ab de fg", null, 0)   = ["ab", "cd", "ef"]
        * StringUtils.split("ab   de fg", null, 0) = ["ab", "cd", "ef"]
        * StringUtils.split("ab:cd:ef", ":", 0)    = ["ab", "cd", "ef"]
  -     * StringUtils.split("ab:cd:ef", ":", 2)    = ["ab", "cdef"]
  +     * StringUtils.split("ab:cd:ef", ":", 2)    = ["ab", "cd:ef"]
        * </pre>
        * 
        * @param str  the String to parse, may be null
  
  
  
  1.56      +20 -4     jakarta-commons/lang/src/test/org/apache/commons/lang/StringUtilsTest.java
  
  Index: StringUtilsTest.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/lang/src/test/org/apache/commons/lang/StringUtilsTest.java,v
  retrieving revision 1.55
  retrieving revision 1.56
  diff -u -r1.55 -r1.56
  --- StringUtilsTest.java	1 Nov 2003 19:20:35 -0000	1.55
  +++ StringUtilsTest.java	23 Nov 2003 20:44:39 -0000	1.56
  @@ -75,6 +75,7 @@
    * @author <a href="hps@intermeta.de">Henning P. Schmiedehausen</a>
    * @author Phil Steitz
    * @author <a href="mailto:ggregory@seagullsw.com">Gary Gregory</a>
  + * @author Al Chou
    * @version $Id$
    */
   public class StringUtilsTest extends TestCase {
  @@ -280,14 +281,14 @@
       public void testSplit_String() {
           assertEquals(null, StringUtils.split(null));
           assertEquals(0, StringUtils.split("").length);
  -
  +        
           String str = "a b  .c";
           String[] res = StringUtils.split(str);
           assertEquals(3, res.length);
           assertEquals("a", res[0]);
           assertEquals("b", res[1]);
           assertEquals(".c", res[2]);
  -            
  +        
           str = " a ";
           res = StringUtils.split(str);
           assertEquals(1, res.length);
  @@ -297,7 +298,7 @@
           res = StringUtils.split(str);
           assertEquals(2, res.length);
           assertEquals("a", res[0]);
  -        assertEquals("b" + NON_WHITESPACE + "c", res[1]);
  +        assertEquals("b" + NON_WHITESPACE + "c", res[1]);                       
       }
       
       public void testSplit_StringChar() {
  @@ -339,6 +340,21 @@
                   innerTestSplit(WHITESPACE.charAt(i), null, NON_WHITESPACE.charAt(j));
                   innerTestSplit(WHITESPACE.charAt(i), String.valueOf(WHITESPACE.charAt(i)),
NON_WHITESPACE.charAt(j));
               }
  +        }
  +        
  +        String[] results = null;
  +        String[] expectedResults = {"ab", "de fg"};
  +        results = StringUtils.split("ab   de fg", null, 2);
  +        assertEquals(expectedResults.length, results.length);
  +        for (int i = 0; i < expectedResults.length; i++) {
  +            assertEquals(expectedResults[i], results[i]);
  +        }
  +        
  +        String[] expectedResults2 = {"ab", "cd:ef"};
  +        results = StringUtils.split("ab:cd:ef",":", 2);
  +        assertEquals(expectedResults2.length, results.length);
  +        for (int i = 0; i < expectedResults2.length; i++) {
  +            assertEquals(expectedResults2[i], results[i]);
           }
       }
       
  
  
  

---------------------------------------------------------------------
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