Return-Path: Delivered-To: apmail-jakarta-commons-dev-archive@www.apache.org Received: (qmail 54539 invoked from network); 23 Nov 2003 20:44:44 -0000 Received: from daedalus.apache.org (HELO mail.apache.org) (208.185.179.12) by minotaur-2.apache.org with SMTP; 23 Nov 2003 20:44:44 -0000 Received: (qmail 72278 invoked by uid 500); 23 Nov 2003 20:44:29 -0000 Delivered-To: apmail-jakarta-commons-dev-archive@jakarta.apache.org Received: (qmail 72213 invoked by uid 500); 23 Nov 2003 20:44:29 -0000 Mailing-List: contact commons-dev-help@jakarta.apache.org; run by ezmlm Precedence: bulk List-Unsubscribe: List-Subscribe: List-Help: List-Post: List-Id: "Jakarta Commons Developers List" Reply-To: "Jakarta Commons Developers List" Delivered-To: mailing list commons-dev@jakarta.apache.org Received: (qmail 72200 invoked by uid 500); 23 Nov 2003 20:44:29 -0000 Received: (qmail 72197 invoked from network); 23 Nov 2003 20:44:29 -0000 Received: from unknown (HELO minotaur.apache.org) (209.237.227.194) by daedalus.apache.org with SMTP; 23 Nov 2003 20:44:29 -0000 Received: (qmail 54519 invoked by uid 1718); 23 Nov 2003 20:44:39 -0000 Date: 23 Nov 2003 20:44:39 -0000 Message-ID: <20031123204439.54518.qmail@minotaur.apache.org> From: psteitz@apache.org To: jakarta-commons-cvs@apache.org Subject: cvs commit: jakarta-commons/lang/src/test/org/apache/commons/lang StringUtilsTest.java X-Spam-Rating: daedalus.apache.org 1.6.2 0/1000/N X-Spam-Rating: minotaur-2.apache.org 1.6.2 0/1000/N 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 @@ } /** - *

Splits the provided text into an array, separators specified. - * This is an alternative to using StringTokenizer.

+ *

Splits the provided text into an array with a maximum length, + * separators specified.

* *

The separator is not included in the returned String array. * Adjacent separators are treated as one separator.

* *

A null input String returns null. * A null separatorChars splits on whitespace.

- * + * + *

If more than max delimited substrings are found, the last + * returned string includes all characters after the first max - 1 + * returned strings (including separator characters).

+ * *
        * 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"]
        * 
* * @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 Henning P. Schmiedehausen * @author Phil Steitz * @author Gary Gregory + * @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