Source Code Cross Referenced for Tests.java in  » Database-DBMS » mckoi » gnu » regexp » util » 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 » Database DBMS » mckoi » gnu.regexp.util 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * gnu/regexp/util/Tests.java -- Simple testsuite for gnu.regexp package
003:         * Copyright (C) 1998-2001 Wes Biggs
004:         *
005:         * This file is in the public domain.  However, the gnu.regexp library
006:         * proper is licensed under the terms of the GNU Lesser General Public
007:         * License (see the file COPYING.LIB for details).
008:         */
009:
010:        package gnu.regexp.util;
011:
012:        import gnu.regexp.*;
013:        import java.io.StringBufferInputStream;
014:        import java.io.StringReader;
015:
016:        /**
017:         * This is a very basic testsuite application for gnu.regexp.
018:         *
019:         * @author <A HREF="mailto:wes@cacas.org">Wes Biggs</A>
020:         * @version 1.1.1
021:         */
022:        public class Tests {
023:            private Tests() {
024:            }
025:
026:            private static void check(RE expr, String input, String expect,
027:                    int id) {
028:                // Test it using all possible input types
029:                check(expr.getMatch(input), expect, id, "String");
030:                check(expr.getMatch(new StringBuffer(input)), expect, id,
031:                        "StringBuffer");
032:                check(expr.getMatch(input.toCharArray()), expect, id, "char[]");
033:                check(expr.getMatch(new StringReader(input)), expect, id,
034:                        "Reader");
035:                check(expr.getMatch(new StringBufferInputStream(input)),
036:                        expect, id, "InputStream");
037:            }
038:
039:            private static void check(REMatch m, String expect, int x,
040:                    String type) {
041:                if ((m == null) || !m.toString().equals(expect))
042:                    System.out.print("*** Failed");
043:                else
044:                    System.out.print("Passed");
045:                System.out.println(" test #" + x + " (" + type + ")");
046:            }
047:
048:            /**
049:             * Runs the testsuite.  No command line arguments are necessary. 
050:             *
051:             * @exception REException An error occurred compiling a regular expression.
052:             */
053:            public static void main(String[] argv) throws REException {
054:                RE e;
055:
056:                e = new RE("(.*)z");
057:                check(e, ("xxz"), "xxz", 1);
058:
059:                e = new RE(".*z");
060:                check(e, ("xxz"), "xxz", 2);
061:
062:                e = new RE("(x|xy)z");
063:                check(e, ("xz"), "xz", 3);
064:                check(e, ("xyz"), "xyz", 4);
065:
066:                e = new RE("(x)+z");
067:                check(e, ("xxz"), "xxz", 5);
068:
069:                e = new RE("abc");
070:                check(e, ("xyzabcdef"), "abc", 6);
071:
072:                e = new RE("^start.*end$");
073:                check(e, ("start here and go to the end"),
074:                        "start here and go to the end", 7);
075:
076:                e = new RE("(x|xy)+z");
077:                check(e, ("xxyz"), "xxyz", 8);
078:
079:                e = new RE("type=([^ \t]+)[ \t]+exts=([^ \t\n\r]+)");
080:                check(e, ("type=text/html	exts=htm,html"),
081:                        "type=text/html	exts=htm,html", 9);
082:
083:                e = new RE("(x)\\1");
084:                check(e, ("zxxz"), "xx", 10);
085:
086:                e = new RE("(x*)(y)\\2\\1");
087:                check(e, ("xxxyyxx"), "xxyyxx", 11);
088:
089:                e = new RE("[-go]+");
090:                check(e, ("go-go"), "go-go", 12);
091:
092:                e = new RE("[\\w-]+");
093:                check(e, ("go-go"), "go-go", 13);
094:
095:                e = new RE("^start.*?end");
096:                check(e,
097:                        ("start here and end in the middle, not the very end"),
098:                        "start here and end", 14);
099:
100:                e = new RE("\\d\\s\\w\\n\\r");
101:                check(e, ("  9\tX\n\r  "), "9\tX\n\r", 15);
102:
103:                e = new RE("zow", RE.REG_ICASE);
104:                check(e, ("ZoW"), "ZoW", 16);
105:
106:                e = new RE("(\\d+)\\D*(\\d+)\\D*(\\d)+");
107:                check(e, ("size--10 by 20 by 30 feet"), "10 by 20 by 30", 17);
108:
109:                e = new RE("(ab)(.*?)(d)");
110:                REMatch m = e.getMatch("abcd");
111:                check(m, "abcd", 18, "String");
112:                System.out.println(((m.toString(2).equals("c")) ? "Pass"
113:                        : "*** Fail")
114:                        + "ed test #19");
115:
116:                e = new RE("^$");
117:                check(e, (""), "", 20);
118:
119:                e = new RE("a*");
120:                check(e, (""), "", 21);
121:                check(e, ("a"), "a", 22);
122:                check(e, ("aa"), "aa", 23);
123:
124:                e = new RE("(([12]))?");
125:                check(e, ("12"), "1", 24);
126:
127:                e = new RE("(.*)?b");
128:                check(e, ("ab"), "ab", 25);
129:
130:                e = new RE("(.*)?-(.*)");
131:                check(e, ("a-b"), "a-b", 26);
132:
133:                e = new RE("(a)b");
134:                check(e, ("aab"), "ab", 27);
135:
136:                e = new RE("[M]iss");
137:                check(e, ("one Mississippi"), "Miss", 28);
138:
139:                e = new RE("\\S Miss");
140:                check(e, ("one Mississippi"), "e Miss", 29);
141:
142:                e = new RE("a*");
143:                check(e, ("b"), "", 30);
144:                check(e, ("ab"), "a", 31);
145:                check(e, ("aab"), "aa", 32);
146:
147:                // Single character should match anywhere in String
148:                e = new RE("a");
149:                check(e, ("a"), "a", 33);
150:                check(e, ("ab"), "a", 34);
151:                check(e, ("ba"), "a", 35);
152:                check(e, ("bab"), "a", 36);
153:
154:            }
155:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.