001: /*
002: * Copyright 2001 Sun Microsystems, Inc. All rights reserved.
003: * PROPRIETARY/CONFIDENTIAL. Use of this product is subject to license terms.
004: */
005: package com.sun.portal.rewriter.util.re.test;
006:
007: import com.sun.portal.rewriter.RewriterModule;
008: import com.sun.portal.rewriter.test.util.BasicTestCase;
009: import com.sun.portal.rewriter.util.re.Pattern;
010: import junit.framework.TestSuite;
011:
012: public class TestPattern extends BasicTestCase {
013: public TestPattern(String aName) {
014: super (aName);
015: }//constuctor
016:
017: public void testEscapedSemiColonBugNo4929669CapturesNormalBehaviour() {
018: Object[][] lData = { { "\\\\*abc;", //Escaped Pattern
019: new String[] { "\\*abc;" } //tokenized
020: },
021:
022: { "\\\\*abc\\;", //Escaped Pattern
023: new String[] { "\\*abc\\;" } //tokenized
024: }, };
025:
026: for (int i = 0; i < lData.length; i++) {
027: String[] lExpectation = (String[]) lData[i][1];
028:
029: Pattern p = new Pattern(lData[i][0].toString());
030: String[] lResult = p.getSubStrings();
031: assertEquals("Expected no of substrings does not match i="
032: + i, lExpectation.length, lResult.length);
033:
034: for (int j = 0; j < lExpectation.length; j++) {
035: assertEquals("Failed at pattern=" + i + ",token=," + j,
036: lExpectation[j], lResult[j]);
037: }
038: }
039: }//testEscapedSemiColonBugNo4929669CapturesNormalBehaviour()
040:
041: public void testSubStrings() throws Exception {
042: Object[][] lData = { { "\\\\*abc", //Escaped Pattern
043: new String[] { "\\*abc" } //tokenized
044: },
045:
046: { "\\\\ab*c", //Escaped Pattern
047: new String[] { "\\\\ab", "c" } //tokenized
048: },
049:
050: // Escaped Sequences
051: { "\\*abcdef", //source
052: new String[] { "*abcdef" } //tokenized
053: }, //5
054:
055: { "abcdef", //source
056: new String[] { "abcdef" } //tokenized
057: }, //0
058:
059: { "abc*def", //source
060: new String[] { "abc", "def" } //tokenized
061: }, //1
062:
063: { "abc**def", //source
064: new String[] { "abc", "def" } //tokenized
065: }, //2
066:
067: { "ab*cd*ef", //source
068: new String[] { "ab", "cd", "ef" } //tokenized
069: }, //3
070:
071: { "*abcdef", //source
072: new String[] { "abcdef" } //tokenized
073: }, //4
074:
075: { "abc\\*def", //source
076: new String[] { "abc*def" } //tokenized
077: }, //6
078:
079: { "abcd\\*", //source
080: new String[] { "abcd*" } //tokenized
081: }, //7
082:
083: { "ab\\**cd", //source
084: new String[] { "ab*", "cd" } //tokenized
085: }, //8
086:
087: { "ab\\*cd\\*ef", //source
088: new String[] { "ab*cd*ef" } //tokenized
089: }, //9
090:
091: { "ab\\*cd\\ef\\*gh*", //source
092: new String[] { "ab*cd\\ef*gh" } //tokenized
093: }, //10
094:
095: { "ab\\*cdef\\ghij*klmn\\*op", //source
096: new String[] { "ab*cdef\\ghij", "klmn*op" } //tokenized
097: }, //11
098:
099: };
100:
101: for (int i = 0; i < lData.length; i++) {
102: Pattern p = new Pattern(lData[i][0].toString());
103: String[] lExpectation = (String[]) lData[i][1];
104:
105: String[] lResult = p.getSubStrings();
106:
107: assertEquals("Expected no of substrings does not match i="
108: + i, lExpectation.length, lResult.length);
109:
110: for (int j = 0; j < lExpectation.length; j++) {
111: assertEquals("Failed at pattern=" + i + ",token=," + j,
112: lExpectation[j], lResult[j]);
113: }
114: }
115: }//testSubStrings()
116:
117: public void testConver2Patterns() throws Exception {
118: Object[][] lData = { { new String[] { "ab", "cd" }, "2" },
119: { new String[] { "cd" }, "1" }, };
120:
121: for (int i = 0; i < lData.length; i++) {
122: Pattern[] bResult = Pattern.convert2Patterns(
123: (String[]) lData[i][0], true);
124: assertEquals((new Integer(lData[i][1].toString()))
125: .intValue(), bResult.length);
126: }
127: }//testConver2Patterns()
128:
129: public void testConver2PatternsCornerCases() {
130: Object[][] lData = { { null, Pattern.EMPTY_PATTERN_ARRAY },
131: { new String[] {}, Pattern.EMPTY_PATTERN_ARRAY }, };
132:
133: for (int i = 0; i < lData.length; i++) {
134: Pattern[] bResult = Pattern
135: .convert2Patterns((String[]) lData[i][0]);
136: assertEquals(lData[i][1], bResult);
137: }
138: }//testConver2PatternsCornerCases()
139:
140: public static void main(String[] args) {
141: RewriterModule.initFile();
142: BasicTestCase.run(TestPattern.class);
143: TestSuite testSuite = new TestSuite();
144: testSuite
145: .addTest(new TestPattern(
146: "testEscapedSemiColonBugNo4929669CapturesNormalBehaviour"));
147: //BasicTestCase.run( testSuite );
148: }//main()
149:
150: }//class TestPattern
|