Source Code Cross Referenced for TestRegExp.java in  » Portal » Open-Portal » com » sun » portal » rewriter » util » re » test » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Portal » Open Portal » com.sun.portal.rewriter.util.re.test 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


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.test.util.BasicTestCase;
008:        import com.sun.portal.rewriter.util.re.Pattern;
009:        import com.sun.portal.rewriter.util.re.RegExp;
010:        import junit.framework.TestSuite;
011:
012:        public class TestRegExp extends BasicTestCase {
013:            public TestRegExp(String aName) {
014:                super (aName);
015:            }//constuctor
016:
017:            public void testIndexOf() {
018:                Object[][] lData = { {
019:                        //check the greedy ness of the *
020:                        "a*b",
021:                        Boolean.TRUE,
022:                        new String[][] { { "ab", "2" }, { "acb", "3" },
023:                                { "ACB", "3" }, { "abb", "2" },
024:                                { "ACBBBDECB", "3" }, { "EEWWE", "-1" },
025:                                { "-1", "-1" }, }, }, };
026:
027:                for (int i = 0; i < lData.length; i++) {
028:                    Pattern p = new Pattern(lData[i][0].toString(),
029:                            ((Boolean) lData[i][1]).booleanValue());
030:
031:                    {
032:                        String[][] bInput = (String[][]) lData[i][2];
033:                        for (int j = 0; j < bInput.length; j++) {
034:                            assertEquals("Failed for value" + bInput[j][0],
035:                                    new Integer(bInput[j][1]).intValue(),
036:                                    RegExp.indexOf(p, bInput[j][0]));
037:                        }
038:                    }
039:                }
040:
041:            }//testIndexOf()
042:
043:            public void testSimpleMatch() {
044:                Object[][] lData = {
045:                        { "#",
046:                                Boolean.FALSE, //Case sensitive Match or not
047:                                new String[] { "#", }, //Positive Input
048:                                new String[] { null, "#test", "#123", "##",
049:                                        "##", "abc#", "abc#ab" }, //Negative Input
050:                        },
051:
052:                        { "#",
053:                                Boolean.TRUE, //Case sensitive Match or not
054:                                new String[] { "#", }, //Positive Input
055:                                new String[] { null, "#test", "#123", "##",
056:                                        "##", "abc#", "abc#ab" }, //Negative Input
057:                        },
058:
059:                        { "#*",
060:                                Boolean.FALSE, //Case sensitive Match or not
061:                                new String[] { "#test", "#", "#123", "##", "##" }, //Positive Input
062:                                new String[] { null, "abc#", "abc#ab" }, //Negative Input
063:                        },
064:
065:                        { "#*",
066:                                Boolean.TRUE, //Case sensitive Match or not
067:                                new String[] { "#test", "#", "#123", "##", "##" }, //Positive Input
068:                                new String[] { null, "abc#", "abc#ab" }, //Negative Input
069:                        },
070:
071:                        // Boundary case test
072:                        { "*",
073:                                Boolean.FALSE, //Case sensitive Match or not
074:                                new String[] { "", "tobeornottobe", "*",
075:                                        "ab*cd", "***" }, //Positive Input
076:                                new String[] { null }, //Negative Input
077:                        }, //1
078:
079:                        {
080:                                //check the greedy ness of the *
081:                                "a*b", Boolean.TRUE,
082:                                new String[] { "ab", "acb", "ACB" },
083:                                new String[] { "abb", "ACBBBDECB" }, },
084:
085:                        {
086:                                "*abc",
087:                                Boolean.FALSE, //Case sensitive Match or not
088:                                new String[] { "abc", ".abc", "xyzabc",
089:                                        "123xyzabc", "xYzabc", "parsabc" }, //Positive Input
090:                                new String[] { "abC", ".Abc", "xYzaBc",
091:                                        "parsABC" }, //Negative Input
092:                        },
093:
094:                        { "a*b", Boolean.FALSE, //Case sensitive Match or not
095:                                new String[] { "axyzb", "aaaab", "aAAAAb" }, //Positive Input
096:                                new String[] { "xyz", "abxyzb", "Aaabbab" }, //Negative Input
097:                        }, //0
098:
099:                        // Boundary case test
100:                        // Note: Cant have a boundary case with pattern = null
101:                        { "", Boolean.FALSE, //Case sensitive Match or not
102:                                new String[] { "" }, //Positive Input
103:                                new String[] { "abcdef", "xxxyyy", null }, //Negative Input
104:                        },
105:
106:                        { "", Boolean.TRUE, //Case sensitive Match or not
107:                                new String[] { "" }, //Positive Input
108:                                new String[] { "abcdef", "xxxyyy", null }, //Negative Input
109:                        }, };
110:
111:                for (int i = 0; i < lData.length; i++) {
112:                    Pattern p = new Pattern(lData[i][0].toString(),
113:                            ((Boolean) lData[i][1]).booleanValue());
114:
115:                    {
116:                        String[] lPostiveInput = (String[]) lData[i][2];
117:                        for (int j = 0; j < lPostiveInput.length; j++) {
118:                            assertTrue(
119:                                    "i=" + i + " value: " + lPostiveInput[j],
120:                                    RegExp.match(p, lPostiveInput[j]));
121:                        }
122:                    }
123:
124:                    {
125:                        String[] lNegativeInput = (String[]) lData[i][3];
126:                        for (int j = 0; j < lNegativeInput.length; j++) {
127:                            assertTrue(!RegExp.match(p, lNegativeInput[j]));
128:                        }
129:                    }
130:                }
131:            }//testSimpleMatch()
132:
133:            public void testSimpleNegateMatch() {
134:                Object[][] lData = {
135:                        {
136:                                "!*",
137:                                Boolean.FALSE, //Case sensitive Match or not
138:                                new String[] { null },
139:                                new String[] { "", "tobeornottobe", "*",
140:                                        "ab*cd", "***" }, }, //3
141:
142:                        { "!a*b", Boolean.TRUE,
143:                                new String[] { "abb", "ACBBBDECB" },
144:                                new String[] { "ab", "acb", "ACB" }, }, //0
145:
146:                        {
147:                                "!*abc",
148:                                Boolean.FALSE, //Case sensitive Match or not
149:                                new String[] { "abC", ".Abc", "xYzaBc",
150:                                        "parsABC" },
151:                                new String[] { "abc", ".abc", "xyzabc",
152:                                        "123xyzabc", "xYzabc", "parsabc" }, }, //1
153:
154:                        { "!a*b", Boolean.FALSE, //Case sensitive Match or not
155:                                new String[] { "xyz", "abxyzb", "Aaabbab" }, //Positive Input
156:                                new String[] { "axyzb", "aaaab", "aAAAAb" }, //Negative Input
157:                        }, //2
158:
159:                        { "!", Boolean.FALSE,
160:                                new String[] { "abcdef", "xxxyyy", null },
161:                                new String[] { "" }, },
162:
163:                        { "!", Boolean.TRUE,
164:                                new String[] { "abcdef", "xxxyyy", null },
165:                                new String[] { "" }, }, };
166:
167:                for (int i = 0; i < lData.length; i++) {
168:                    Pattern p = new Pattern(lData[i][0].toString(),
169:                            ((Boolean) lData[i][1]).booleanValue());
170:
171:                    {
172:                        String[] lPostiveInput = (String[]) lData[i][2];
173:                        for (int j = 0; j < lPostiveInput.length; j++) {
174:                            assertTrue(
175:                                    "i=" + i + " value: " + lPostiveInput[j],
176:                                    RegExp.match(p, lPostiveInput[j]));
177:                        }
178:                    }
179:
180:                    {
181:                        String[] lNegativeInput = (String[]) lData[i][3];
182:                        for (int j = 0; j < lNegativeInput.length; j++) {
183:                            assertTrue("i=" + i + " value: "
184:                                    + lNegativeInput[j], !RegExp.match(p,
185:                                    lNegativeInput[j]));
186:                        }
187:                    }
188:                }
189:            }//testSimpleNegateMatch()
190:
191:            public void testEscapeMatch() {
192:                Object[][] lData = {
193:                        { "#\\*",
194:                                Boolean.FALSE, //Case sensitive Match or not
195:                                new String[] { "#*" }, //Positive Input
196:                                new String[] { "#test", "#", "#123", "##",
197:                                        "##", null, "abc#", "abc#ab" }, //Negative Input
198:                        },
199:
200:                        {
201:                                "#\\**",
202:                                Boolean.TRUE, //Case sensitive Match or not
203:                                new String[] { "#*test", "#*", "#*123", "#*#",
204:                                        "#*#" }, //Positive Input
205:                                new String[] { "#test", "#", "#123", "##",
206:                                        "##", null, "abc#", "abc#ab" }, //Negative Input
207:                        },
208:
209:                        {
210:                                "\\\\ab*c", //Escaped Pattern
211:                                Boolean.FALSE, //Case sensitive Match or not
212:                                new String[] { "\\\\abc", "\\\\abc", "\\\\ab*c" }, //Positive Input
213:                                new String[] { "abC", ".Abc", "xYzaBc",
214:                                        "parsABC", "abc", ".abc", "xyzabc",
215:                                        "123xyzabc", "xYzabc", "parsabc" }, //Negative Input
216:                        }, //0
217:
218:                        {
219:                                "\\\\*abc", //Escaped Pattern
220:                                Boolean.FALSE, //Case sensitive Match or not
221:                                new String[] { "\\*abc", }, //Positive Input
222:                                new String[] { "\\\\*abc", "abC", ".Abc",
223:                                        "xYzaBc", "parsABC", "abc", ".abc",
224:                                        "xyzabc", "123xyzabc", "xYzabc",
225:                                        "parsabc" }, //Negative Input
226:                        }, //1
227:
228:                        {
229:                                "\\*abc", //Escaped Pattern
230:                                Boolean.FALSE, //Case sensitive Match or not
231:                                new String[] { "*abc", }, //Positive Input
232:                                new String[] { "abC", "\\*abc", ".Abc",
233:                                        "xYzaBc", "parsABC", "abc", ".abc",
234:                                        "xyzabc", "123xyzabc", "xYzabc",
235:                                        "parsabc" }, //Negative Input
236:                        }, //2
237:
238:                        {
239:                                "*abc", //Escaped Pattern
240:                                Boolean.FALSE, //Case sensitive Match or not
241:                                new String[] { "*abc", "\\*abc", "\\\\*abc",
242:                                        "abc", ".abc", "xyzabc", "123xyzabc",
243:                                        "xYzabc", "parsabc", }, //Positive Input
244:                                new String[] { "abC", ".Abc", "xYzaBc",
245:                                        "parsABC", }, //Negative Input
246:                        }, //3
247:
248:                        {
249:                                "\\*\\*abc", //Escaped Pattern
250:                                Boolean.FALSE, //Case sensitive Match or not
251:                                new String[] { "**abc", }, //Positive Input
252:                                new String[] { "\\*\\*abc", "\\*abc", "abC",
253:                                        ".Abc", "xYzaBc", "parsABC", "abc",
254:                                        ".abc", "xyzabc", "123xyzabc",
255:                                        "xYzabc", "parsabc" }, //Negative Input
256:                        }, //4
257:
258:                        {
259:                                "\\*\\*abc\\*\\*", //Escaped Pattern
260:                                Boolean.FALSE, //Case sensitive Match or not
261:                                new String[] { "**abc**", }, //Positive Input
262:                                new String[] { "\\*\\*abc\\*\\*", "\\*abc",
263:                                        "*abc*", "abc", "**abc*", "abC",
264:                                        ".Abc", "xYzaBc", "parsABC", "abc",
265:                                        ".abc", "xyzabc", "123xyzabc",
266:                                        "xYzabc", "parsabc" }, //Negative Input
267:                        }, //5
268:
269:                        {
270:                                "\\*abc\\*", //Escaped Pattern
271:                                Boolean.FALSE, //Case sensitive Match or not
272:                                new String[] { "*abc*", }, //Positive Input
273:                                new String[] { "\\*abc\\*", "\\*abc", "abC",
274:                                        ".Abc", "xYzaBc", "parsABC", "abc",
275:                                        ".abc", "xyzabc", "123xyzabc",
276:                                        "xYzabc", "parsabc" }, //Negative Input
277:                        }, //6
278:
279:                        {
280:                                "\\*abc", //Escaped Pattern
281:                                Boolean.TRUE, //Case sensitive Match or not
282:                                new String[] { "*abc", "*aBC", "*aBc", }, //Positive Input
283:                                new String[] { "\\*abc", "\\*ABC", "\\*aBC",
284:                                        "abC", ".Abc", "xYzaBc", "parsABC",
285:                                        "abc", ".abc", "xyzabc", "123xyzabc",
286:                                        "xYzabc", "parsabc" }, //Negative Input
287:                        }, //7
288:
289:                        {
290:                                "\\*abc\\*", //Escaped Pattern
291:                                Boolean.TRUE, //Case sensitive Match or not
292:                                new String[] { "*abc*", "*ABC*", "*aBC*", }, //Positive Input
293:                                new String[] { "*abc", "\\*abc\\*",
294:                                        "\\*ABC\\*", "\\*aBC\\*", "\\*abc",
295:                                        "abC", ".Abc", "xYzaBc", "parsABC",
296:                                        "abc", ".abc", "xyzabc", "123xyzabc",
297:                                        "xYzabc", "parsabc" }, //Negative Input
298:                        }, //8
299:
300:                        {
301:                                "abc\\*", //Escaped Pattern
302:                                Boolean.TRUE, //Case sensitive Match or not
303:                                new String[] { "abc*", "ABC*", "aBC*" }, //Positive Input
304:                                new String[] { "abc\\*", "ABC\\*", "aBC\\*",
305:                                        "\\*abc", "abC", ".Abc", "xYzaBc",
306:                                        "parsABC", "abc", ".abc", "xyzabc",
307:                                        "123xyzabc", "xYzabc", "parsabc" }, //Negative Input
308:                        }, //9
309:
310:                        {
311:                                "abc\\*", //Escaped Pattern
312:                                Boolean.FALSE, //Case sensitive Match or not
313:                                new String[] { "abc*" }, //Positive Input
314:                                new String[] { "\\*abc", "abc\\*", "abC",
315:                                        ".Abc", "xYzaBc", "parsABC", "abc",
316:                                        ".abc", "xyzabc", "123xyzabc",
317:                                        "xYzabc", "parsabc" }, //Negative Input
318:                        }, //10
319:
320:                        {
321:                                "*abc",
322:                                Boolean.FALSE, //Case sensitive Match or not
323:                                new String[] { "abc", ".abc", "xyzabc",
324:                                        "123xyzabc", "xYzabc", "parsabc" }, //Positive Input
325:                                new String[] { "abC", ".Abc", "xYzaBc",
326:                                        "parsABC" }, //Negative Input
327:                        }, //11
328:
329:                        {
330:                                "*abc\\*", //Escaped Pattern
331:                                Boolean.FALSE, //Case sensitive Match or not
332:                                new String[] { "*abc*", "abc*", "\\*abc*",
333:                                        "*abc*", ".abc*", "xyzabc*",
334:                                        "123xyzabc*", "xYzabc*", "parsabc*" }, //Positive Input
335:                                new String[] { "\\*abc", "abC", "abC*", ".Abc",
336:                                        "xYzaBc", "parsABC" }, //Negative Input
337:                        }, //12
338:
339:                        {
340:                                "*abc\\*", //Escaped Pattern
341:                                Boolean.TRUE, //Case sensitive Match or not
342:                                new String[] { "\\*abc*", "*abc*", "abC*",
343:                                        ".Abc*", "xYzaBc*", "parsABC*", "abc*",
344:                                        ".abc*", "xyzabc*", "123xyzabc*",
345:                                        "xYzabc*", "parsabc*" }, //Positive Input
346:                                new String[] { "\\*abc", }, //Negative Input
347:                        }, //13
348:
349:                };
350:
351:                for (int i = 0; i < lData.length; i++) {
352:                    Pattern p = new Pattern(lData[i][0].toString(),
353:                            ((Boolean) lData[i][1]).booleanValue());
354:
355:                    {
356:                        String[] lPostiveInput = (String[]) lData[i][2];
357:                        for (int j = 0; j < lPostiveInput.length; j++) {
358:                            assertTrue("Positive Input: i=" + i + " Data:"
359:                                    + lPostiveInput[j], RegExp.match(p,
360:                                    lPostiveInput[j]));
361:                        }
362:                    }
363:
364:                    {
365:                        String[] lNegativeInput = (String[]) lData[i][3];
366:                        for (int j = 0; j < lNegativeInput.length; j++) {
367:                            assertTrue("Negative Input:i=" + i + " Data:"
368:                                    + lNegativeInput[j], !RegExp.match(p,
369:                                    lNegativeInput[j]));
370:                        }
371:                    }
372:                }
373:            }//testEscapeMatch()
374:
375:            public static void main(String[] args) {
376:                BasicTestCase.run(TestRegExp.class);
377:
378:                TestSuite testSuite = new TestSuite();
379:                testSuite.addTest(new TestRegExp("testSimpleMatch"));
380:                //BasicTestCase.run( testSuite );
381:            }//main()
382:
383:        }//class TestRegExp
w__ww._ja___v___a__2_s__.___c___o_m__ | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.