Source Code Cross Referenced for RegexpMatcherTest.java in  » Build » ANT » org » apache » tools » ant » util » regexp » 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 » Build » ANT » org.apache.tools.ant.util.regexp 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         *  Licensed to the Apache Software Foundation (ASF) under one or more
003:         *  contributor license agreements.  See the NOTICE file distributed with
004:         *  this work for additional information regarding copyright ownership.
005:         *  The ASF licenses this file to You under the Apache License, Version 2.0
006:         *  (the "License"); you may not use this file except in compliance with
007:         *  the License.  You may obtain a copy of the License at
008:         *
009:         *      http://www.apache.org/licenses/LICENSE-2.0
010:         *
011:         *  Unless required by applicable law or agreed to in writing, software
012:         *  distributed under the License is distributed on an "AS IS" BASIS,
013:         *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014:         *  See the License for the specific language governing permissions and
015:         *  limitations under the License.
016:         *
017:         */
018:
019:        package org.apache.tools.ant.util.regexp;
020:
021:        import java.io.IOException;
022:        import java.util.Vector;
023:
024:        import junit.framework.TestCase;
025:
026:        /**
027:         * Tests for all implementations of the RegexpMatcher interface.
028:         *
029:         */
030:        public abstract class RegexpMatcherTest extends TestCase {
031:
032:            public final static String UNIX_LINE = "\n";
033:
034:            private RegexpMatcher reg;
035:
036:            public abstract RegexpMatcher getImplementation();
037:
038:            protected final RegexpMatcher getReg() {
039:                return reg;
040:            }
041:
042:            public RegexpMatcherTest(String name) {
043:                super (name);
044:            }
045:
046:            public void setUp() {
047:                reg = getImplementation();
048:            }
049:
050:            public void testMatches() {
051:                reg.setPattern("aaaa");
052:                assertTrue("aaaa should match itself", reg.matches("aaaa"));
053:                assertTrue("aaaa should match xaaaa", reg.matches("xaaaa"));
054:                assertTrue("aaaa shouldn\'t match xaaa", !reg.matches("xaaa"));
055:                reg.setPattern("^aaaa");
056:                assertTrue("^aaaa shouldn\'t match xaaaa", !reg
057:                        .matches("xaaaa"));
058:                assertTrue("^aaaa should match aaaax", reg.matches("aaaax"));
059:                reg.setPattern("aaaa$");
060:                assertTrue("aaaa$ shouldn\'t match aaaax", !reg
061:                        .matches("aaaax"));
062:                assertTrue("aaaa$ should match xaaaa", reg.matches("xaaaa"));
063:                reg.setPattern("[0-9]+");
064:                assertTrue("[0-9]+ should match 123", reg.matches("123"));
065:                assertTrue("[0-9]+ should match 1", reg.matches("1"));
066:                assertTrue("[0-9]+ shouldn\'t match \'\'", !reg.matches(""));
067:                assertTrue("[0-9]+ shouldn\'t match a", !reg.matches("a"));
068:                reg.setPattern("[0-9]*");
069:                assertTrue("[0-9]* should match 123", reg.matches("123"));
070:                assertTrue("[0-9]* should match 1", reg.matches("1"));
071:                assertTrue("[0-9]* should match \'\'", reg.matches(""));
072:                assertTrue("[0-9]* should match a", reg.matches("a"));
073:                reg.setPattern("([0-9]+)=\\1");
074:                assertTrue("([0-9]+)=\\1 should match 1=1", reg.matches("1=1"));
075:                assertTrue("([0-9]+)=\\1 shouldn\'t match 1=2", !reg
076:                        .matches("1=2"));
077:            }
078:
079:            public void testGroups() {
080:                reg.setPattern("aaaa");
081:                Vector v = reg.getGroups("xaaaa");
082:                assertEquals("No parens -> no extra groups", 1, v.size());
083:                assertEquals("Trivial match with no parens", "aaaa", (String) v
084:                        .elementAt(0));
085:
086:                reg.setPattern("(aaaa)");
087:                v = reg.getGroups("xaaaa");
088:                assertEquals("Trivial match with single paren", 2, v.size());
089:                assertEquals("Trivial match with single paren, full match",
090:                        "aaaa", (String) v.elementAt(0));
091:                assertEquals("Trivial match with single paren, matched paren",
092:                        "aaaa", (String) v.elementAt(0));
093:
094:                reg.setPattern("(a+)b(b+)");
095:                v = reg.getGroups("xaabb");
096:                assertEquals(3, v.size());
097:                assertEquals("aabb", (String) v.elementAt(0));
098:                assertEquals("aa", (String) v.elementAt(1));
099:                assertEquals("b", (String) v.elementAt(2));
100:            }
101:
102:            public void testBugzillaReport14619() {
103:                reg.setPattern("^(.*)/src/((.*/)*)([a-zA-Z0-9_\\.]+)\\.java$");
104:                Vector v = reg.getGroups("de/tom/src/Google.java");
105:                assertEquals(5, v.size());
106:                assertEquals("de/tom", v.elementAt(1));
107:                assertEquals("", v.elementAt(2));
108:                assertEquals("", v.elementAt(3));
109:                assertEquals("Google", v.elementAt(4));
110:            }
111:
112:            public void testCaseInsensitiveMatch() {
113:                reg.setPattern("aaaa");
114:                assertTrue("aaaa doesn't match AAaa", !reg.matches("AAaa"));
115:                assertTrue("aaaa matches AAaa ignoring case", reg.matches(
116:                        "AAaa", RegexpMatcher.MATCH_CASE_INSENSITIVE));
117:            }
118:
119:            // make sure there are no issues concerning line separator interpretation
120:            // a line separator for regex (perl) is always a unix line (ie \n)
121:
122:            public void testParagraphCharacter() throws IOException {
123:                reg.setPattern("end of text$");
124:                assertTrue("paragraph character", !reg
125:                        .matches("end of text\u2029"));
126:            }
127:
128:            public void testLineSeparatorCharacter() throws IOException {
129:                reg.setPattern("end of text$");
130:                assertTrue("line-separator character", !reg
131:                        .matches("end of text\u2028"));
132:            }
133:
134:            public void testNextLineCharacter() throws IOException {
135:                reg.setPattern("end of text$");
136:                assertTrue("next-line character", !reg
137:                        .matches("end of text\u0085"));
138:            }
139:
140:            public void testStandaloneCR() throws IOException {
141:                reg.setPattern("end of text$");
142:                assertTrue("standalone CR", !reg.matches("end of text\r"));
143:            }
144:
145:            public void testWindowsLineSeparator() throws IOException {
146:                reg.setPattern("end of text$");
147:                assertTrue("Windows line separator", !reg
148:                        .matches("end of text\r\n"));
149:            }
150:
151:            public void testWindowsLineSeparator2() throws IOException {
152:                reg.setPattern("end of text\r$");
153:                assertTrue("Windows line separator", reg
154:                        .matches("end of text\r\n"));
155:            }
156:
157:            public void testUnixLineSeparator() throws IOException {
158:                reg.setPattern("end of text$");
159:                assertTrue("Unix line separator", reg.matches("end of text\n"));
160:            }
161:
162:            public void testMultiVersusSingleLine() throws IOException {
163:                StringBuffer buf = new StringBuffer();
164:                buf.append("Line1").append(UNIX_LINE);
165:                buf.append("starttest Line2").append(UNIX_LINE);
166:                buf.append("Line3 endtest").append(UNIX_LINE);
167:                buf.append("Line4").append(UNIX_LINE);
168:                String text = buf.toString();
169:
170:                doStartTest1(text);
171:                doStartTest2(text);
172:                doEndTest1(text);
173:                doEndTest2(text);
174:            }
175:
176:            protected void doStartTest1(String text) {
177:                reg.setPattern("^starttest");
178:                assertTrue("^starttest in default mode", !reg.matches(text));
179:                assertTrue("^starttest in single line mode", !reg.matches(text,
180:                        RegexpMatcher.MATCH_SINGLELINE));
181:                assertTrue("^starttest in multi line mode", reg.matches(text,
182:                        RegexpMatcher.MATCH_MULTILINE));
183:            }
184:
185:            protected void doStartTest2(String text) {
186:                reg.setPattern("^Line1");
187:                assertTrue("^Line1 in default mode", reg.matches(text));
188:                assertTrue("^Line1 in single line mode", reg.matches(text,
189:                        RegexpMatcher.MATCH_SINGLELINE));
190:                assertTrue("^Line1 in multi line mode", reg.matches(text,
191:                        RegexpMatcher.MATCH_MULTILINE));
192:            }
193:
194:            protected void doEndTest1(String text) {
195:                reg.setPattern("endtest$");
196:                assertTrue("endtest$ in default mode", !reg.matches(text));
197:                assertTrue("endtest$ in single line mode", !reg.matches(text,
198:                        RegexpMatcher.MATCH_SINGLELINE));
199:                assertTrue("endtest$ in multi line mode", reg.matches(text,
200:                        RegexpMatcher.MATCH_MULTILINE));
201:            }
202:
203:            protected void doEndTest2(String text) {
204:                reg.setPattern("Line4$");
205:                assertTrue("Line4$ in default mode", reg.matches(text));
206:                assertTrue("Line4$ in single line mode", reg.matches(text,
207:                        RegexpMatcher.MATCH_SINGLELINE));
208:                assertTrue("Line4$ in multi line mode", reg.matches(text,
209:                        RegexpMatcher.MATCH_MULTILINE));
210:            }
211:
212:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.