commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From scolebou...@apache.org
Subject cvs commit: jakarta-commons-sandbox/lang/src/test/org/apache/commons/lang StringsTest.java
Date Tue, 02 Jul 2002 00:00:36 GMT
scolebourne    2002/07/01 17:00:36

  Modified:    lang/src/test/org/apache/commons/lang StringsTest.java
  Log:
  Test left, right and mid methods
  
  Revision  Changes    Path
  1.4       +375 -274  jakarta-commons-sandbox/lang/src/test/org/apache/commons/lang/StringsTest.java
  
  Index: StringsTest.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/lang/src/test/org/apache/commons/lang/StringsTest.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- StringsTest.java	21 Jun 2002 05:20:36 -0000	1.3
  +++ StringsTest.java	2 Jul 2002 00:00:35 -0000	1.4
  @@ -1,274 +1,375 @@
  -package org.apache.commons.lang;
  -
  -/* ====================================================================
  - * The Apache Software License, Version 1.1
  - *
  - * Copyright (c) 2001 The Apache Software Foundation.  All rights
  - * reserved.
  - *
  - * Redistribution and use in source and binary forms, with or without
  - * modification, are permitted provided that the following conditions
  - * are met:
  - *
  - * 1. Redistributions of source code must retain the above copyright
  - *    notice, this list of conditions and the following disclaimer.
  - *
  - * 2. Redistributions in binary form must reproduce the above copyright
  - *    notice, this list of conditions and the following disclaimer in
  - *    the documentation and/or other materials provided with the
  - *    distribution.
  - *
  - * 3. The end-user documentation included with the redistribution,
  - *    if any, must include the following acknowledgment:
  - *       "This product includes software developed by the
  - *        Apache Software Foundation (http://www.apache.org/)."
  - *    Alternately, this acknowledgment may appear in the software itself,
  - *    if and wherever such third-party acknowledgments normally appear.
  - *
  - * 4. The names "Apache" and "Apache Software Foundation" and
  - *    "Apache Turbine" must not be used to endorse or promote products
  - *    derived from this software without prior written permission. For
  - *    written permission, please contact apache@apache.org.
  - *
  - * 5. Products derived from this software may not be called "Apache",
  - *    "Apache Turbine", nor may "Apache" appear in their name, without
  - *    prior written permission of the Apache Software Foundation.
  - *
  - * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
  - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  - * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
  - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
  - * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
  - * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  - * SUCH DAMAGE.
  - * ====================================================================
  - *
  - * This software consists of voluntary contributions made by many
  - * individuals on behalf of the Apache Software Foundation.  For more
  - * information on the Apache Software Foundation, please see
  - * <http://www.apache.org/>.
  - */
  -
  -import java.util.Arrays;
  -
  -import junit.framework.Test;
  -import junit.framework.TestCase;
  -import junit.framework.TestSuite;
  -
  -/**
  - * Unit tests {@link org.apache.commons.lang.Strings}.
  - *
  - * @author <a href="mailto:dlr@collab.net">Daniel Rall</a>
  - * @author <a href="mailto:bayard@generationjava.com">Henri Yandell</a>
  - */
  -public class StringsTest extends TestCase
  -{
  -    private static final String[] ARRAY_LIST = { "foo", "bar", "baz" };
  -
  -    private static final String SEPARATOR = ",";
  -
  -    private static final String TEXT_LIST = "foo,bar,baz";
  -
  -    private static final String FOO = "foo";
  -    private static final String CAP_FOO = "Foo";
  -    private static final String UPPER_FOO = "FOO";
  -
  -    private static final String SENTENCE = "foo bar baz";
  -
  -    public StringsTest(String name)
  -    {
  -        super(name);
  -    }
  -
  -    public void testClean()
  -    {
  -        assertEquals("clean(String) failed",
  -                     FOO, Strings.clean(FOO + " "));
  -        assertEquals("clean(String) failed", "", Strings.clean(null));
  -    }
  -
  -    public void testTrim()
  -    {
  -        assertEquals("trim(String) failed", FOO, Strings.trim(FOO + " "));
  -        assertTrue("trim(String) failed", Strings.trim(null) == null);
  -    }
  -
  -    public void testIsValid()
  -    {
  -        assertTrue("isValid(String) failed",
  -                   Strings.isValid(FOO) && !Strings.isValid(""));
  -    }
  -
  -    public void testIsEmpty()
  -    {
  -        assertTrue("isEmpty(String) failed",
  -                   Strings.isEmpty("   ") && !Strings.isEmpty(FOO));
  -    }
  -
  -    public void testEquals()
  -    {
  -        assertTrue("equals(String, String) failed",
  -                   Strings.equals(null, null) &&
  -                   !Strings.equals(null, FOO) &&
  -                   Strings.equals(FOO, FOO));
  -    }
  -
  -    public void testCapitalizeFunctions()
  -    {
  -        assertEquals("firstLetterCaps(String) failed",
  -                     CAP_FOO, Strings.firstLetterCaps(FOO));
  -
  -        assertEquals("capitalise(String) failed",
  -                     CAP_FOO, Strings.capitalise(FOO) );
  -        assertEquals("capitaliseAllWords(String) failed",
  -                     "Foo Bar Baz", Strings.capitaliseAllWords(SENTENCE) );
  -        assertEquals("uncapitalise(String) failed",
  -                     FOO, Strings.uncapitalise(CAP_FOO) );
  -    }
  -
  -    public void testJoin()
  -    {
  -        assertEquals("join(Object[], String) failed", TEXT_LIST,
  -                     Strings.join(ARRAY_LIST, SEPARATOR));
  -        assertEquals("join(Iterator, String) failed", TEXT_LIST,
  -                     Strings.join(Arrays.asList(ARRAY_LIST).iterator(),
  -                                      SEPARATOR));
  -    }
  -
  -    public void testSplit()
  -    {
  -        String[] result = Strings.split(TEXT_LIST, SEPARATOR, 2);
  -        String[] expected = { "foo", "bar,baz" };
  -        assertEquals("split(Object[], String, int) yielded unexpected length",
  -                     expected.length, result.length);
  -        for (int i = 0; i < result.length; i++)
  -        {
  -            assertEquals("split(Object[], String, int) failed", expected[i],
  -                         result[i]);
  -        }
  -
  -        result = Strings.split(TEXT_LIST, SEPARATOR, 0);
  -        expected = ARRAY_LIST;
  -        assertEquals("split(Object[], String, int) yielded unexpected length",
  -                     expected.length, result.length);
  -        for (int i = 0; i < result.length; i++)
  -        {
  -            assertEquals("split(Object[], String, int) failed", expected[i],
  -                         result[i]);
  -        }
  -
  -        result = Strings.split(TEXT_LIST, SEPARATOR, -1);
  -        expected = ARRAY_LIST;
  -        assertEquals("split(Object[], String, int) yielded unexpected length",
  -                     expected.length, result.length);
  -        for (int i = 0; i < result.length; i++)
  -        {
  -            assertEquals("split(Object[], String, int) failed", expected[i],
  -                         result[i]);
  -        }
  -    }
  -
  -    public void testReplaceFunctions()
  -    {
  -        assertEquals("replace(String, String, String, int) failed",
  -                     FOO, Strings.replace("oo" + FOO, "o", "", 2));
  -        // removed the 4th argument of -1.
  -        assertEquals("replace(String, String, String) failed",
  -                     "", Strings.replace(FOO + FOO + FOO, FOO, ""));
  -        assertEquals("replaceOnce(String, String, String) failed",
  -                     FOO, Strings.replaceOnce(FOO + FOO, FOO, ""));
  -    }
  -
  -    public void testOverlayString()
  -    {
  -        assertEquals("overlayString(String, String, int, int) failed",
  -                     "foo foor baz", Strings.overlayString(SENTENCE, FOO, 4, 6) );
  -    }
  -
  -    public void testRepeat()
  -    {
  -        assertEquals("repeat(String, int) failed",
  -                     FOO + FOO + FOO, Strings.repeat(FOO, 3) );
  -    }
  -
  -    public void testCenter()
  -    {
  -        assertEquals("center(String, int) failed",
  -                     "   "+FOO+"   ", Strings.center(FOO, 9) );
  -    }
  -
  -    public void testChompFunctions()
  -    {
  -
  -        assertEquals("chomp(String) failed",
  -                     FOO, Strings.chomp(FOO + "\n" + FOO) );
  -
  -        assertEquals("chompLast(String) failed",
  -                     FOO, Strings.chompLast(FOO + "\n") );
  -
  -        assertEquals("getChomp(String, String) failed",
  -                     "\n" + FOO, Strings.getChomp(FOO + "\n" + FOO, "\n") );
  -
  -        assertEquals("prechomp(String, String) failed",
  -                     FOO, Strings.prechomp(FOO + "\n" + FOO, "\n") );
  -
  -        assertEquals("getPrechomp(String, String) failed",
  -                     FOO + "\n", Strings.getPrechomp(FOO + "\n" + FOO, "\n") );
  -
  -        assertEquals("chop(String, String) failed",
  -                     FOO, Strings.chop(FOO + "\r\n") );
  -
  -        assertEquals("chopNewline(String, String) failed",
  -                     FOO, Strings.chopNewline(FOO + "\r\n") );
  -    }
  -
  -    public void testPadFunctions()
  -    {
  -        assertEquals("rightPad(String, int) failed",
  -                     "1234    ", Strings.rightPad ("1234", 8) );
  -
  -        assertEquals("rightPad(String, int, String) failed",
  -                     "1234-+-+", Strings.rightPad ("1234", 8, "-+") );
  -
  -        assertEquals("rightPad(String, int, String) failed",
  -                     "123456-+~", Strings.rightPad ("123456", 9, "-+~") );
  -
  -        assertEquals("leftPad(String, int) failed",
  -                     "    1234", Strings.leftPad("1234", 8) );
  -
  -        assertEquals("leftPad(String, int, String) failed",
  -                     "-+-+1234", Strings.leftPad("1234", 8, "-+") );
  -
  -        assertEquals("leftPad(String, int, String) failed",
  -                     "-+~123456", Strings.leftPad("123456", 9, "-+~") );
  -    }
  -
  -    public void testUnicodeFunctions() throws java.io.IOException
  -    {
  -        /* this test fails on my window box with an Sun english JDK 1.3.1
  -           I think that the input string is not right
  -        */
  -/* Kept out for the moment.
  -        String input = "これは日本楔譴離謄好箸任后#";
  -        String unicode = Strings.convertNativeToUnicode(input, "iso-2022-jp");
  -        String iso = Strings.convertUnicodeToNative(unicode, "iso-2022-jp");
  -        assertEquals("Unicode conversions failed", input, iso);
  -*/
  -    }
  -
  -    public void testSubstring()
  -    {
  -        assertEquals("substring(String, int, int) failed",
  -                     FOO, Strings.substring(SENTENCE, 0, 3));
  -        assertEquals("substring(String, int, negative int) failed",
  -                     FOO, Strings.substring(SENTENCE, 0, -8));
  -        assertEquals("substring(String, int, overflow int) failed",
  -                     SENTENCE, Strings.substring(SENTENCE, 0, 80));
  -    }
  -}
  -
  +package org.apache.commons.lang;
  +
  +/* ====================================================================
  + * The Apache Software License, Version 1.1
  + *
  + * Copyright (c) 2001 The Apache Software Foundation.  All rights
  + * reserved.
  + *
  + * Redistribution and use in source and binary forms, with or without
  + * modification, are permitted provided that the following conditions
  + * are met:
  + *
  + * 1. Redistributions of source code must retain the above copyright
  + *    notice, this list of conditions and the following disclaimer.
  + *
  + * 2. Redistributions in binary form must reproduce the above copyright
  + *    notice, this list of conditions and the following disclaimer in
  + *    the documentation and/or other materials provided with the
  + *    distribution.
  + *
  + * 3. The end-user documentation included with the redistribution,
  + *    if any, must include the following acknowledgment:
  + *       "This product includes software developed by the
  + *        Apache Software Foundation (http://www.apache.org/)."
  + *    Alternately, this acknowledgment may appear in the software itself,
  + *    if and wherever such third-party acknowledgments normally appear.
  + *
  + * 4. The names "Apache" and "Apache Software Foundation" and
  + *    "Apache Turbine" must not be used to endorse or promote products
  + *    derived from this software without prior written permission. For
  + *    written permission, please contact apache@apache.org.
  + *
  + * 5. Products derived from this software may not be called "Apache",
  + *    "Apache Turbine", nor may "Apache" appear in their name, without
  + *    prior written permission of the Apache Software Foundation.
  + *
  + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
  + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  + * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
  + * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
  + * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
  + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  + * SUCH DAMAGE.
  + * ====================================================================
  + *
  + * This software consists of voluntary contributions made by many
  + * individuals on behalf of the Apache Software Foundation.  For more
  + * information on the Apache Software Foundation, please see
  + * <http://www.apache.org/>.
  + */
  +
  +import java.util.Arrays;
  +
  +import junit.framework.Test;
  +import junit.framework.TestCase;
  +import junit.framework.TestSuite;
  +import junit.textui.TestRunner;
  +
  +/**
  + * Unit tests {@link org.apache.commons.lang.Strings}.
  + *
  + * @author <a href="mailto:dlr@collab.net">Daniel Rall</a>
  + * @author <a href="mailto:bayard@generationjava.com">Henri Yandell</a>
  + */
  +public class StringsTest extends TestCase
  +{
  +    private static final String[] ARRAY_LIST = { "foo", "bar", "baz" };
  +
  +    private static final String SEPARATOR = ",";
  +
  +    private static final String TEXT_LIST = "foo,bar,baz";
  +
  +    private static final String FOO = "foo";
  +    private static final String CAP_FOO = "Foo";
  +    private static final String UPPER_FOO = "FOO";
  +
  +    private static final String SENTENCE = "foo bar baz";
  +
  +    public StringsTest(String name) {
  +        super(name);
  +    }
  +
  +    public static void main(String[] args) {
  +        TestRunner.run(suite());
  +    }
  +
  +    public static TestSuite suite() {
  +        return new TestSuite(StringsTest.class);
  +    }
  +
  +    protected void setUp() throws Exception {
  +        super.setUp();
  +    }
  +
  +    protected void tearDown() throws Exception {
  +        super.tearDown();
  +    }
  +
  +    //-----------------------------------------------------------------------
  +
  +    public void testClean()
  +    {
  +        assertEquals("clean(String) failed",
  +                     FOO, Strings.clean(FOO + " "));
  +        assertEquals("clean(String) failed", "", Strings.clean(null));
  +    }
  +
  +    public void testTrim()
  +    {
  +        assertEquals("trim(String) failed", FOO, Strings.trim(FOO + " "));
  +        assertTrue("trim(String) failed", Strings.trim(null) == null);
  +    }
  +
  +    public void testIsValid()
  +    {
  +        assertTrue("isValid(String) failed",
  +                   Strings.isValid(FOO) && !Strings.isValid(""));
  +    }
  +
  +    public void testIsEmpty()
  +    {
  +        assertTrue("isEmpty(String) failed",
  +                   Strings.isEmpty("   ") && !Strings.isEmpty(FOO));
  +    }
  +
  +    public void testLeft()
  +    {
  +        assertSame(null, Strings.left(null, 0));
  +        assertSame(null, Strings.left(null, 2));
  +        assertSame("", Strings.left("", 0));
  +        assertSame("", Strings.left("", 2));
  +        assertEquals("", Strings.left("foobar", 0));
  +        assertEquals("foo", Strings.left("foobar", 3));
  +        assertSame("foobar", Strings.left("foobar", 80));
  +    }
  +    public void testLeftEx()
  +    {
  +        try {
  +            Strings.left("foobar", -1);
  +        } catch (IllegalArgumentException ex) {
  +            return;
  +        }
  +        fail();
  +    }
  +
  +    public void testRight()
  +    {
  +        assertSame(null, Strings.right(null, 0));
  +        assertSame(null, Strings.right(null, 2));
  +        assertSame("", Strings.right("", 0));
  +        assertSame("", Strings.right("", 2));
  +        assertEquals("", Strings.right("foobar", 0));
  +        assertEquals("bar", Strings.right("foobar", 3));
  +        assertSame("foobar", Strings.right("foobar", 80));
  +    }
  +    public void testRightEx()
  +    {
  +        try {
  +            Strings.right("foobar", -1);
  +        } catch (IllegalArgumentException ex) {
  +            return;
  +        }
  +        fail();
  +    }
  +
  +    public void testMid()
  +    {
  +        assertSame(null, Strings.mid(null, 3, 0));
  +        assertSame(null, Strings.mid(null, 3, 2));
  +        assertSame("", Strings.mid("", 0, 0));
  +        assertSame("", Strings.mid("", 0, 2));
  +        assertEquals("", Strings.mid("foobar", 3, 0));
  +        assertEquals("b", Strings.mid("foobar", 3, 1));
  +        assertEquals("foo", Strings.mid("foobar", 0, 3));
  +        assertEquals("bar", Strings.mid("foobar", 3, 3));
  +        assertEquals("foobar", Strings.mid("foobar", 0, 80));
  +        assertEquals("bar", Strings.mid("foobar", 3, 80));
  +    }
  +    public void testMidEx1()
  +    {
  +        try {
  +            Strings.mid("foobar", 0, -1);
  +        } catch (IllegalArgumentException ex) {
  +            return;
  +        }
  +        fail();
  +    }
  +
  +    public void testMidEx2()
  +    {
  +        try {
  +            Strings.mid("foobar", -1, 3);
  +        } catch (IndexOutOfBoundsException ex) {
  +            return;
  +        }
  +        fail();
  +    }
  +
  +    public void testMidEx3()
  +    {
  +        try {
  +            Strings.mid("foobar", 7, 3);
  +        } catch (IndexOutOfBoundsException ex) {
  +            return;
  +        }
  +        fail();
  +    }
  +
  +    public void testEquals()
  +    {
  +        assertTrue("equals(String, String) failed",
  +                   Strings.equals(null, null) &&
  +                   !Strings.equals(null, FOO) &&
  +                   Strings.equals(FOO, FOO));
  +    }
  +
  +    public void testCapitalizeFunctions()
  +    {
  +        assertEquals("firstLetterCaps(String) failed",
  +                     CAP_FOO, Strings.firstLetterCaps(FOO));
  +
  +        assertEquals("capitalise(String) failed",
  +                     CAP_FOO, Strings.capitalise(FOO) );
  +        assertEquals("capitaliseAllWords(String) failed",
  +                     "Foo Bar Baz", Strings.capitaliseAllWords(SENTENCE) );
  +        assertEquals("uncapitalise(String) failed",
  +                     FOO, Strings.uncapitalise(CAP_FOO) );
  +    }
  +
  +    public void testJoin()
  +    {
  +        assertEquals("join(Object[], String) failed", TEXT_LIST,
  +                     Strings.join(ARRAY_LIST, SEPARATOR));
  +        assertEquals("join(Iterator, String) failed", TEXT_LIST,
  +                     Strings.join(Arrays.asList(ARRAY_LIST).iterator(),
  +                                      SEPARATOR));
  +    }
  +
  +    public void testSplit()
  +    {
  +        String[] result = Strings.split(TEXT_LIST, SEPARATOR, 2);
  +        String[] expected = { "foo", "bar,baz" };
  +        assertEquals("split(Object[], String, int) yielded unexpected length",
  +                     expected.length, result.length);
  +        for (int i = 0; i < result.length; i++)
  +        {
  +            assertEquals("split(Object[], String, int) failed", expected[i],
  +                         result[i]);
  +        }
  +
  +        result = Strings.split(TEXT_LIST, SEPARATOR, 0);
  +        expected = ARRAY_LIST;
  +        assertEquals("split(Object[], String, int) yielded unexpected length",
  +                     expected.length, result.length);
  +        for (int i = 0; i < result.length; i++)
  +        {
  +            assertEquals("split(Object[], String, int) failed", expected[i],
  +                         result[i]);
  +        }
  +
  +        result = Strings.split(TEXT_LIST, SEPARATOR, -1);
  +        expected = ARRAY_LIST;
  +        assertEquals("split(Object[], String, int) yielded unexpected length",
  +                     expected.length, result.length);
  +        for (int i = 0; i < result.length; i++)
  +        {
  +            assertEquals("split(Object[], String, int) failed", expected[i],
  +                         result[i]);
  +        }
  +    }
  +
  +    public void testReplaceFunctions()
  +    {
  +        assertEquals("replace(String, String, String, int) failed",
  +                     FOO, Strings.replace("oo" + FOO, "o", "", 2));
  +        // removed the 4th argument of -1.
  +        assertEquals("replace(String, String, String) failed",
  +                     "", Strings.replace(FOO + FOO + FOO, FOO, ""));
  +        assertEquals("replaceOnce(String, String, String) failed",
  +                     FOO, Strings.replaceOnce(FOO + FOO, FOO, ""));
  +    }
  +
  +    public void testOverlayString()
  +    {
  +        assertEquals("overlayString(String, String, int, int) failed",
  +                     "foo foor baz", Strings.overlayString(SENTENCE, FOO, 4, 6) );
  +    }
  +
  +    public void testRepeat()
  +    {
  +        assertEquals("repeat(String, int) failed",
  +                     FOO + FOO + FOO, Strings.repeat(FOO, 3) );
  +    }
  +
  +    public void testCenter()
  +    {
  +        assertEquals("center(String, int) failed",
  +                     "   "+FOO+"   ", Strings.center(FOO, 9) );
  +    }
  +
  +    public void testChompFunctions()
  +    {
  +
  +        assertEquals("chomp(String) failed",
  +                     FOO, Strings.chomp(FOO + "\n" + FOO) );
  +
  +        assertEquals("chompLast(String) failed",
  +                     FOO, Strings.chompLast(FOO + "\n") );
  +
  +        assertEquals("getChomp(String, String) failed",
  +                     "\n" + FOO, Strings.getChomp(FOO + "\n" + FOO, "\n") );
  +
  +        assertEquals("prechomp(String, String) failed",
  +                     FOO, Strings.prechomp(FOO + "\n" + FOO, "\n") );
  +
  +        assertEquals("getPrechomp(String, String) failed",
  +                     FOO + "\n", Strings.getPrechomp(FOO + "\n" + FOO, "\n") );
  +
  +        assertEquals("chop(String, String) failed",
  +                     FOO, Strings.chop(FOO + "\r\n") );
  +
  +        assertEquals("chopNewline(String, String) failed",
  +                     FOO, Strings.chopNewline(FOO + "\r\n") );
  +    }
  +
  +    public void testPadFunctions()
  +    {
  +        assertEquals("rightPad(String, int) failed",
  +                     "1234    ", Strings.rightPad ("1234", 8) );
  +
  +        assertEquals("rightPad(String, int, String) failed",
  +                     "1234-+-+", Strings.rightPad ("1234", 8, "-+") );
  +
  +        assertEquals("rightPad(String, int, String) failed",
  +                     "123456-+~", Strings.rightPad ("123456", 9, "-+~") );
  +
  +        assertEquals("leftPad(String, int) failed",
  +                     "    1234", Strings.leftPad("1234", 8) );
  +
  +        assertEquals("leftPad(String, int, String) failed",
  +                     "-+-+1234", Strings.leftPad("1234", 8, "-+") );
  +
  +        assertEquals("leftPad(String, int, String) failed",
  +                     "-+~123456", Strings.leftPad("123456", 9, "-+~") );
  +    }
  +
  +    public void testUnicodeFunctions() throws java.io.IOException
  +    {
  +        /* this test fails on my window box with an Sun english JDK 1.3.1
  +           I think that the input string is not right
  +        */
  +/* Kept out for the moment.
  +        String input = "これは日本楔譴離謄好箸任后#";
  +        String unicode = Strings.convertNativeToUnicode(input, "iso-2022-jp");
  +        String iso = Strings.convertUnicodeToNative(unicode, "iso-2022-jp");
  +        assertEquals("Unicode conversions failed", input, iso);
  +*/
  +    }
  +
  +    public void testSubstring()
  +    {
  +        assertEquals("substring(String, int, int) failed",
  +                     FOO, Strings.substring(SENTENCE, 0, 3));
  +        assertEquals("substring(String, int, negative int) failed",
  +                     FOO, Strings.substring(SENTENCE, 0, -8));
  +        assertEquals("substring(String, int, overflow int) failed",
  +                     SENTENCE, Strings.substring(SENTENCE, 0, 80));
  +    }
  +}
  +
  
  
  

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


Mime
View raw message