01: package net.sourceforge.squirrel_sql.fw.util;
02:
03: /*
04: * Copyright (C) 2007 Rob Manning
05: * manningr@users.sourceforge.net
06: *
07: * This library is free software; you can redistribute it and/or
08: * modify it under the terms of the GNU Lesser General Public
09: * License as published by the Free Software Foundation; either
10: * version 2.1 of the License, or (at your option) any later version.
11: *
12: * This library is distributed in the hope that it will be useful,
13: * but WITHOUT ANY WARRANTY; without even the implied warranty of
14: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15: * Lesser General Public License for more details.
16: *
17: * You should have received a copy of the GNU Lesser General Public
18: * License along with this library; if not, write to the Free Software
19: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20: */
21: import junit.framework.TestCase;
22:
23: public class StringUtilitiesTest extends TestCase {
24:
25: protected void setUp() throws Exception {
26: super .setUp();
27: }
28:
29: protected void tearDown() throws Exception {
30: super .tearDown();
31: }
32:
33: public void testJoin() {
34: String[] parts = new String[] { "foo", "bar", "baz" };
35:
36: String joinedParts = StringUtilities.join(parts, null);
37:
38: assertEquals("foobarbaz", joinedParts);
39:
40: joinedParts = StringUtilities.join(parts, "|");
41:
42: assertEquals("foo|bar|baz", joinedParts);
43:
44: joinedParts = StringUtilities.join(parts, "");
45:
46: assertEquals("foobarbaz", joinedParts);
47: }
48:
49: public void testSegment() {
50: String[] segments = null;
51: String longString = "part1part2part3part4";
52: segments = StringUtilities.segment(longString, 1);
53: assertEquals(segments.length, 20);
54: segments = StringUtilities.segment(longString, 5);
55: assertEquals(segments.length, 4);
56: segments = StringUtilities.segment(longString, 9);
57: assertEquals(segments.length, 3);
58: segments = StringUtilities.segment(longString, 11);
59: assertEquals(segments.length, 2);
60: segments = StringUtilities.segment(longString, 20);
61: assertEquals(segments.length, 1);
62: /*
63: for (int i = 0; i < segments.length; i++) {
64: String string = segments[i];
65: System.out.println("segment: |"+string+"|");
66: }
67: */
68: }
69:
70: public void testGetTokenBeginIndex() {
71: String sql = "select valid_from from dealer";
72: int idx = StringUtilities.getTokenBeginIndex(sql, "from");
73: assertEquals(18, idx);
74: sql = "select from_date from dealer";
75: idx = StringUtilities.getTokenBeginIndex(sql, "from");
76: assertEquals(17, idx);
77: }
78:
79: public void testChop() {
80: String toChop = "(1,2,3)";
81: String expAfterChop = "(1,2,3";
82:
83: String afterChop = StringUtilities.chop(toChop);
84: assertEquals(expAfterChop, afterChop);
85: }
86: }
|