Source Code Cross Referenced for TestLexer.java in  » Wiki-Engine » VeryQuickWiki » vqwiki » lex » 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 » Wiki Engine » VeryQuickWiki » vqwiki.lex 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /**
002:         * Note that this only applies to the default format and link lexers
003:         *
004:         * @author garethc
005:         *  29/10/2002 16:23:39
006:         */package vqwiki.lex;
007:
008:        import junit.framework.TestCase;
009:        import org.apache.log4j.Logger;
010:
011:        import java.io.StringReader;
012:
013:        public class TestLexer extends TestCase {
014:            private static final Logger logger = Logger
015:                    .getLogger(TestLexer.class);
016:
017:            public TestLexer(String s) {
018:                super (s);
019:            }
020:
021:            public void testFormat() throws Exception {
022:                StringBuffer inputBuffer = new StringBuffer();
023:                inputBuffer.append("Here '''is''' ''the'' '''first''' line");
024:                inputBuffer.append("\n");
025:                inputBuffer.append("Here is the second line");
026:                inputBuffer.append("\n");
027:                inputBuffer.append("\n");
028:                inputBuffer.append("Here is the third line following a break");
029:
030:                StringBuffer expected = new StringBuffer();
031:                expected
032:                        .append("Here <strong>is</strong> <em>the</em> <strong>first</strong> line<br/><br/>\nHere is the second line<br/><br/>\n<br/><br/>\nHere is the third line following a break");
033:
034:                formatLexify(inputBuffer, expected);
035:
036:                inputBuffer = new StringBuffer();
037:                inputBuffer.append("Here is the first line");
038:                inputBuffer.append("@@@@\n");
039:                inputBuffer.append("this is preformatted");
040:                inputBuffer.append("\n");
041:                inputBuffer.append("so is this");
042:                inputBuffer.append("\n");
043:                inputBuffer.append("\n");
044:                inputBuffer.append("this isn't");
045:
046:                expected = new StringBuffer();
047:                expected.append("Here is the first line<pre>");
048:                expected.append("this is preformatted\n");
049:                expected.append("so is this</pre>\n");
050:                expected.append("this isn't");
051:
052:                formatLexify(inputBuffer, expected);
053:
054:            }
055:
056:            public void testUnformat() throws Exception {
057:                StringBuffer inputBuffer = new StringBuffer();
058:                inputBuffer
059:                        .append("__Here '''is'''__ ''the'' __'''first'''__ line");
060:
061:                StringBuffer expected = new StringBuffer();
062:                expected.append("Here '''is''' <em>the</em> '''first''' line");
063:
064:                formatLexify(inputBuffer, expected);
065:            }
066:
067:            public void testList() throws Exception {
068:                StringBuffer inputBuffer = new StringBuffer();
069:                inputBuffer.append("No list here");
070:                inputBuffer.append("\n");
071:                inputBuffer.append("\t*item one");
072:                inputBuffer.append("\n");
073:                inputBuffer.append("\t*item two");
074:                inputBuffer.append("\n");
075:                inputBuffer.append("\t\t*subitem two-one");
076:                inputBuffer.append("\n");
077:                inputBuffer.append("\t\t*subitem two-two");
078:                inputBuffer.append("\n");
079:                inputBuffer.append("\t*item three");
080:                inputBuffer.append("\n");
081:                inputBuffer.append("\n");
082:                inputBuffer.append("No list here");
083:                inputBuffer.append("\n");
084:
085:                StringBuffer expected = new StringBuffer();
086:                expected.append("No list here<br/><br/>\n<ul><li>item one");
087:                expected.append("</li>\n");
088:                expected.append("<li>item two\n");
089:                expected.append("<ul><li>subitem two-one");
090:                expected.append("</li>\n");
091:                expected.append("<li>subitem two-two");
092:                expected.append("</li></ul>\n");
093:                expected.append("<li>item three");
094:                expected.append("</li></ul>\n");
095:                expected.append("No list here<br/><br/>\n");
096:
097:                formatLexify(inputBuffer, expected);
098:            }
099:
100:            public void testTables() throws Exception {
101:                StringBuffer inputBuffer = new StringBuffer();
102:                inputBuffer.append("No table here");
103:                inputBuffer.append("\n");
104:                inputBuffer.append("####");
105:                inputBuffer.append("\n");
106:                inputBuffer.append("0,0");
107:                inputBuffer.append("##");
108:                inputBuffer.append("0,1");
109:                inputBuffer.append("##");
110:                inputBuffer.append("\n");
111:                inputBuffer.append("1,0");
112:                inputBuffer.append("##");
113:                inputBuffer.append("1,1");
114:                inputBuffer.append("##");
115:                inputBuffer.append("####");
116:                inputBuffer.append("\n");
117:
118:                StringBuffer expected = new StringBuffer();
119:                expected
120:                        .append("No table here<br/><br/>\n<table border=\"1\"><tr><td>0,0</td><td>0,1</td></tr><tr><td>1,0</td><td>1,1</td></tr></table>");
121:
122:                formatLexify(inputBuffer, expected);
123:            }
124:
125:            public void testWikiNames() throws Exception {
126:                StringBuffer inputBuffer = new StringBuffer();
127:                inputBuffer
128:                        .append("Here is a line with a standard WikiName in it");
129:                inputBuffer.append("\n");
130:                inputBuffer
131:                        .append("Here is a line with a broken Wiki2Name in it");
132:                inputBuffer.append("\n");
133:                inputBuffer.append("Here is a `backtick` WikiName");
134:
135:                StringBuffer expected = new StringBuffer();
136:                expected
137:                        .append("Here is a line with a standard WikiName<a href=\"Wiki?topic=WikiName&action=action_edit\">?</a> in it");
138:                expected.append("\n");
139:                expected.append("Here is a line with a broken Wiki2Name in it");
140:                expected.append("\n");
141:                expected
142:                        .append("Here is a backtick<a href=\"Wiki?topic=backtick&action=action_edit\">?</a> WikiName<a href=\"Wiki?topic=WikiName&action=action_edit\">?</a>");
143:                linkLexify(inputBuffer, expected);
144:            }
145:
146:            public void testHyperlinks() throws Exception {
147:                StringBuffer inputBuffer = new StringBuffer();
148:                inputBuffer
149:                        .append("Here is a link: http://www.www.com/something and the end");
150:                inputBuffer.append("\n");
151:                inputBuffer
152:                        .append("link: (http://www.www.com/something) and the end");
153:                inputBuffer.append("\n");
154:                inputBuffer
155:                        .append("link: (http://www.www.com/something/) and the end");
156:                inputBuffer.append("\n");
157:                inputBuffer
158:                        .append("link: <b>http://www.www.com/something/</b> and the end");
159:                inputBuffer.append("\n");
160:                inputBuffer
161:                        .append("image: http://www.www.com/something/2.jpg and the end");
162:                inputBuffer.append("\n");
163:                inputBuffer
164:                        .append("c2:SomeTopic and mskb:Q1234567 and other:Thing");
165:
166:                StringBuffer expected = new StringBuffer();
167:                expected
168:                        .append("Here is a link: <a href=\"http://www.www.com/something\">http://www.www.com/something</a> and the end");
169:                expected.append("\n");
170:                expected
171:                        .append("link: (<a href=\"http://www.www.com/something\">http://www.www.com/something</a>) and the end");
172:                expected.append("\n");
173:                expected
174:                        .append("link: (<a href=\"http://www.www.com/something/\">http://www.www.com/something/</a>) and the end");
175:                expected.append("\n");
176:                expected
177:                        .append("link: <b><a href=\"http://www.www.com/something/\">http://www.www.com/something/</a></b> and the end");
178:                expected.append("\n");
179:                expected
180:                        .append("image: <img src=\"http://www.www.com/something/2.jpg\"/> and the end");
181:                expected.append("\n");
182:                expected
183:                        .append("<a href=\"http://c2.com/cgi/wiki?SomeTopic\">c2:SomeTopic</a> and <a href=\"http://support.microsoft.com/default.aspx?scid=KB;EN-US;Q1234567\">mskb:Q1234567</a> and other:Thing");
184:                linkLexify(inputBuffer, expected);
185:            }
186:
187:            private void linkLexify(StringBuffer inputBuffer,
188:                    StringBuffer expected) throws Exception {
189:                String text = inputBuffer.toString();
190:                StringReader in = new StringReader(text);
191:                LinkLex lex = new LinkLex(in);
192:                lex.setVirtualWiki("jsp");
193:                StringBuffer outputBuffer = new StringBuffer();
194:                while (true) {
195:                    String out = lex.yylex();
196:                    if (out == null)
197:                        break;
198:                    outputBuffer.append(out);
199:                    System.out.print(out);
200:                }
201:                System.out.println();
202:                assertEquals(expected.toString(), outputBuffer.toString());
203:                in.close();
204:            }
205:
206:            private void formatLexify(StringBuffer inputBuffer,
207:                    StringBuffer expected) throws Exception {
208:                String text = inputBuffer.toString();
209:                StringReader in = new StringReader(text);
210:                FormatLex lex = new FormatLex(in);
211:                StringBuffer outputBuffer = new StringBuffer();
212:                while (true) {
213:                    String out = lex.yylex();
214:                    if (out == null)
215:                        break;
216:                    outputBuffer.append(out);
217:                    System.out.print(out);
218:                }
219:                System.out.println();
220:                assertEquals(expected.toString(), outputBuffer.toString());
221:                in.close();
222:            }
223:
224:            public static void main(String[] args) throws Exception {
225:                TestLexer test = new TestLexer("lexer");
226:                test.testFormat();
227:                test.testUnformat();
228:                test.testList();
229:                test.testTables();
230:                test.testWikiNames();
231:                test.testHyperlinks();
232:                System.exit(0);
233:            }
234:        }
235:
236:        // $Log$
237:        // Revision 1.3  2003/10/05 05:07:31  garethc
238:        // fixes and admin file encoding option + merge with contributions
239:        //
240:        // Revision 1.2  2003/04/15 23:11:03  garethc
241:        // lucene fixes
242:        //
243:        // Revision 1.1  2003/04/09 20:44:25  garethc
244:        // package org
245:        //
246:        // Revision 1.7  2003/01/07 03:11:53  garethc
247:        // beginning of big cleanup, taglibs etc
248:        //
249:        // Revision 1.6  2002/12/08 20:58:58  garethc
250:        // 2.3.6 almost ready
251:        //
252:        // Revision 1.5  2002/11/15 03:31:44  garethc
253:        // small fixes
254:        //
255:        // Revision 1.4  2002/11/07 23:18:14  garethc
256:        // lex unit test update
257:        //
258:        // Revision 1.3  2002/11/07 22:51:31  garethc
259:        // new two pass lexer working
260:        //
261:        // Revision 1.2  2002/11/07 21:47:45  garethc
262:        // part way through 2 part lex
263:        //
264:        // Revision 1.1  2002/11/01 03:12:43  garethc
265:        // starting work on new two pass lexer
266:        //
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.