1 | /*
|
---|
2 | * Copyright 2001,2004 The Apache Software Foundation
|
---|
3 | *
|
---|
4 | * Licensed under the Apache License, Version 2.0 (the "License");
|
---|
5 | * you may not use this file except in compliance with the License.
|
---|
6 | * You may obtain a copy of the License at
|
---|
7 | *
|
---|
8 | * http://www.apache.org/licenses/LICENSE-2.0
|
---|
9 | *
|
---|
10 | * Unless required by applicable law or agreed to in writing, software
|
---|
11 | * distributed under the License is distributed on an "AS IS" BASIS,
|
---|
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
---|
13 | * See the License for the specific language governing permissions and
|
---|
14 | * limitations under the License.
|
---|
15 | *
|
---|
16 | */
|
---|
17 | package org.apache.tools.ant.util;
|
---|
18 |
|
---|
19 | import java.util.Vector;
|
---|
20 |
|
---|
21 | import junit.framework.TestCase;
|
---|
22 |
|
---|
23 | /**
|
---|
24 | * Test for StringUtils
|
---|
25 | */
|
---|
26 | public class StringUtilsTest extends TestCase {
|
---|
27 | public StringUtilsTest(String s) {
|
---|
28 | super(s);
|
---|
29 | }
|
---|
30 |
|
---|
31 | public void testSplit(){
|
---|
32 | final String data = "a,b,,";
|
---|
33 | Vector res = StringUtils.split(data, ',');
|
---|
34 | assertEquals(4, res.size());
|
---|
35 | assertEquals("a", res.elementAt(0));
|
---|
36 | assertEquals("b", res.elementAt(1));
|
---|
37 | assertEquals("", res.elementAt(2));
|
---|
38 | assertEquals("", res.elementAt(3));
|
---|
39 | }
|
---|
40 |
|
---|
41 | public void testSplitLines(){
|
---|
42 | final String data = "a\r\nb\nc\nd\ne";
|
---|
43 | Vector res = StringUtils.lineSplit(data);
|
---|
44 | assertEquals(5, res.size());
|
---|
45 | assertEquals("a\r", res.elementAt(0));
|
---|
46 | assertEquals("b", res.elementAt(1));
|
---|
47 | assertEquals("c", res.elementAt(2));
|
---|
48 | assertEquals("d", res.elementAt(3));
|
---|
49 | assertEquals("e", res.elementAt(4));
|
---|
50 | }
|
---|
51 |
|
---|
52 | public void testReplace() {
|
---|
53 | final String data = "abcabcabca";
|
---|
54 | String res = StringUtils.replace(data, "a", "");
|
---|
55 | assertEquals("bcbcbc", res);
|
---|
56 | }
|
---|
57 |
|
---|
58 | }
|
---|