Source Code Cross Referenced for SQLLexerTest.java in  » Database-Client » SQL-Workbench » workbench » sql » formatter » 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 Client » SQL Workbench » workbench.sql.formatter 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * SQLLexerTest.java
003:         *
004:         * This file is part of SQL Workbench/J, http://www.sql-workbench.net
005:         *
006:         * Copyright 2002-2008, Thomas Kellerer
007:         * No part of this code maybe reused without the permission of the author
008:         *
009:         * To contact the author please send an email to: support@sql-workbench.net
010:         *
011:         */
012:        package workbench.sql.formatter;
013:
014:        import java.util.ArrayList;
015:        import java.util.List;
016:        import junit.framework.TestCase;
017:
018:        /**
019:         *
020:         * @author support@sql-workbench.net
021:         */
022:        public class SQLLexerTest extends TestCase {
023:
024:            public SQLLexerTest(String testName) {
025:                super (testName);
026:            }
027:
028:            private List getTokenList(String sql) {
029:                ArrayList result = new ArrayList();
030:
031:                SQLLexer l = new SQLLexer(sql);
032:                SQLToken t = l.getNextToken(false, false);
033:                while (t != null) {
034:                    result.add(t);
035:                    t = l.getNextToken(false, false);
036:                }
037:                return result;
038:            }
039:
040:            public void testQuotedIdentifier() {
041:                try {
042:                    String sql = "Select \"one AND two\" from thetable;";
043:                    SQLLexer l = new SQLLexer(sql);
044:                    SQLToken select = l.getNextToken(false, false);
045:
046:                    assertEquals(select.getContents(), "SELECT");
047:                    SQLToken col = l.getNextToken(false, false);
048:                    assertEquals("\"one AND two\"", col.getContents());
049:
050:                    sql = "WbExport -file=\"c:\\Documents and Settings\\test.txt\" -type=text";
051:                    l = new SQLLexer(sql);
052:                    SQLToken t = l.getNextToken(false, false);
053:                    assertEquals("WBEXPORT", t.getText().toUpperCase());
054:                    t = l.getNextToken(false, false);
055:                    assertEquals("-", t.getText());
056:                    t = l.getNextToken(false, false);
057:                    assertEquals("file", t.getText());
058:                    t = l.getNextToken(false, false);
059:                    assertEquals("=", t.getText());
060:                    t = l.getNextToken(false, false);
061:                    assertEquals("\"c:\\Documents and Settings\\test.txt\"", t
062:                            .getContents());
063:                } catch (Exception e) {
064:                    e.printStackTrace();
065:                    fail(e.getMessage());
066:                }
067:            }
068:
069:            public void testLexer() {
070:                // Test if the multi-word keywords are detected properly
071:
072:                String sql = "-- create a view\nCREATE\nOR\nREPLACE view my_view as (SELECT * FROM bal);";
073:
074:                List tokens = getTokenList(sql);
075:
076:                SQLToken t = (SQLToken) tokens.get(0);
077:
078:                assertEquals("CREATE OR REPLACE", t.getContents());
079:                assertEquals(true, t.isReservedWord());
080:
081:                sql = "SELECT * FROM bla INNER JOIN blub ON (x = y)";
082:
083:                tokens = getTokenList(sql);
084:                t = (SQLToken) tokens.get(0);
085:                assertEquals("SELECT", t.getContents());
086:
087:                t = (SQLToken) tokens.get(4);
088:                assertEquals("INNER JOIN", t.getContents());
089:                assertEquals(true, t.isReservedWord());
090:
091:                sql = "SELECT * FROM bla INNER JOIN blub ON (x = y)\nOUTER JOIN blub2 on (y = y)";
092:
093:                tokens = getTokenList(sql);
094:                t = (SQLToken) tokens.get(0);
095:                assertEquals("SELECT", t.getContents());
096:
097:                t = (SQLToken) tokens.get(4);
098:                assertEquals("INNER JOIN", t.getContents());
099:                assertEquals(true, t.isReservedWord());
100:
101:                t = (SQLToken) tokens.get(12);
102:                assertEquals("OUTER JOIN", t.getContents());
103:                assertEquals(true, t.isReservedWord());
104:
105:                sql = "is null\nnot null\n--next\nunion\nall\n--next\n"
106:                        + "group    by\n" + "order\tby\n"
107:                        + "create or replace package body \n"
108:                        + "materialized view\n" + "start  with\n"
109:                        + "outer \t join\n"
110:                        + "cross join  full join \t full\touter join\n"
111:                        + "inner join\n" + "left join\n"
112:                        + "left        outer join\n" + "right join\n"
113:                        + "right \nouter\n\n join\njoin\n" + "is not null";
114:                tokens = getTokenList(sql);
115:                for (int i = 0; i < tokens.size(); i++) {
116:                    t = (SQLToken) tokens.get(i);
117:                    String v = t.getContents();
118:                    //System.out.println(i  + ": " + v);
119:                    switch (i) {
120:                    case 0:
121:                        assertEquals("IS NULL", v);
122:                        break;
123:                    case 1:
124:                        assertEquals("NOT NULL", v);
125:                        break;
126:                    case 2:
127:                        assertEquals("UNION ALL", v);
128:                        break;
129:                    case 3:
130:                        assertEquals("GROUP BY", v);
131:                        break;
132:                    case 4:
133:                        assertEquals("ORDER BY", v);
134:                        break;
135:                    case 5:
136:                        assertEquals("CREATE OR REPLACE", v);
137:                        break;
138:                    case 6:
139:                        assertEquals("PACKAGE BODY", v);
140:                        break;
141:                    case 7:
142:                        assertEquals("MATERIALIZED VIEW", v);
143:                        break;
144:                    case 8:
145:                        assertEquals("START WITH", v);
146:                        break;
147:                    case 9:
148:                        assertEquals("OUTER JOIN", v);
149:                        break;
150:                    case 10:
151:                        assertEquals("CROSS JOIN", v);
152:                        break;
153:                    case 11:
154:                        assertEquals("FULL JOIN", v);
155:                        break;
156:                    case 12:
157:                        assertEquals("FULL OUTER JOIN", v);
158:                        break;
159:                    case 13:
160:                        assertEquals("INNER JOIN", v);
161:                        break;
162:                    case 14:
163:                        assertEquals("LEFT JOIN", v);
164:                        break;
165:                    case 15:
166:                        assertEquals("LEFT OUTER JOIN", v);
167:                        break;
168:                    case 16:
169:                        assertEquals("RIGHT JOIN", v);
170:                        break;
171:                    case 17:
172:                        assertEquals("RIGHT OUTER JOIN", v);
173:                        break;
174:                    case 18:
175:                        assertEquals("JOIN", v);
176:                        break;
177:                    case 19:
178:                        assertEquals("IS NOT NULL", v);
179:                        break;
180:                    }
181:
182:                }
183:            }
184:
185:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.