Source Code Cross Referenced for LanguageTest.java in  » IDE-Netbeans » languages » org » netbeans » modules » languages » 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 » IDE Netbeans » languages » org.netbeans.modules.languages 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * LanguageTest.java
003:         * JUnit based test
004:         *
005:         * Created on March 19, 2007, 9:26 AM
006:         */
007:
008:        package org.netbeans.modules.languages;
009:
010:        import java.util.ArrayList;
011:        import java.util.Arrays;
012:        import java.util.Collections;
013:        import java.util.HashMap;
014:        import java.util.HashSet;
015:        import java.util.List;
016:        import java.util.Map;
017:        import java.util.Set;
018:        import junit.framework.TestCase;
019:        import org.netbeans.api.languages.ASTItem;
020:        import org.netbeans.api.languages.ASTNode;
021:        import org.netbeans.api.languages.ASTToken;
022:        import org.netbeans.api.languages.ParseException;
023:        import org.netbeans.modules.languages.parser.Parser;
024:        import org.netbeans.modules.languages.parser.Parser.Cookie;
025:        import org.netbeans.modules.languages.parser.Pattern;
026:        import org.netbeans.modules.languages.parser.StringInput;
027:
028:        /**
029:         *
030:         * @author Jan Jancura
031:         */
032:        public class LanguageTest extends TestCase {
033:
034:            public LanguageTest(String testName) {
035:                super (testName);
036:            }
037:
038:            public void testFeatures1() {
039:                TestLanguage language = new TestLanguage();
040:                language.addFeature(Feature.create("feature", Selector
041:                        .create("selector")));
042:                assertEquals("selector", language.getFeatureList().getFeature(
043:                        "feature").getSelector().getAsString());
044:                assertEquals(1, language.getFeatureList()
045:                        .getFeatures("feature").size());
046:            }
047:
048:            public void testFeatures2() {
049:                TestLanguage language = new TestLanguage();
050:                language.addFeature(Feature.create("feature", Selector
051:                        .create("selector")));
052:                language.addFeature(Feature.create("feature", Selector
053:                        .create("selector2")));
054:                assertEquals(2, language.getFeatureList()
055:                        .getFeatures("feature").size());
056:                Feature feature = language.getFeatureList().getFeature(
057:                        "feature");
058:                assertTrue(feature.getSelector().toString().equals("selector")
059:                        || feature.getSelector().toString().equals("selector2"));
060:            }
061:
062:            public void testFeatures3() {
063:                TestLanguage language = new TestLanguage();
064:                language.addToken(0, "a");
065:                language.addToken(1, "b");
066:                language.addToken(2, "c");
067:                language.addFeature(Feature.create("feature", Selector
068:                        .create("a")));
069:                language.addFeature(Feature.create("feature", Selector
070:                        .create("a.b")));
071:                language.addFeature(Feature.create("feature", Selector
072:                        .create("c.a")));
073:                assertEquals("a", language.getFeatureList().getFeature(
074:                        "feature", "a").getSelector().getAsString());
075:                assertNull(language.getFeatureList().getFeature("feature", "b"));
076:                assertNull(language.getFeatureList().getFeature("feature", "c"));
077:
078:                ASTNode n = ASTNode.create(language, "x", Arrays
079:                        .asList(new ASTItem[] {
080:                                ASTNode.create(language, "a", Arrays
081:                                        .asList(new ASTItem[] {
082:                                                ASTToken.create(language, "b",
083:                                                        "bbb", 0, 3, null),
084:                                                ASTToken.create(language, "a",
085:                                                        "aaa", 3, 3, null), }),
086:                                        0),
087:                                ASTNode.create(language, "c", Arrays
088:                                        .asList(new ASTItem[] {
089:                                                ASTToken.create(language, "b",
090:                                                        "bbb", 6, 3, null),
091:                                                ASTToken.create(language, "a",
092:                                                        "aaa", 9, 3, null), }),
093:                                        6) }), 0);
094:                List<Feature> fs = language.getFeatureList().getFeatures(
095:                        "feature", n.findPath(1));
096:                assertEquals(1, fs.size());
097:                assertEquals("a.b", fs.get(0).getSelector().getAsString());
098:                fs = language.getFeatureList().getFeatures("feature",
099:                        n.findPath(4));
100:                assertEquals(1, fs.size());
101:                assertEquals("a", fs.get(0).getSelector().getAsString());
102:                fs = language.getFeatureList().getFeatures("feature",
103:                        n.findPath(7));
104:                assertEquals(0, fs.size());
105:                fs = language.getFeatureList().getFeatures("feature",
106:                        n.findPath(10));
107:                assertEquals(2, fs.size());
108:                Set<String> s = new HashSet<String>();
109:                s.add(fs.get(0).getSelector().getAsString());
110:                s.add(fs.get(1).getSelector().getAsString());
111:                assertTrue(s.contains("a"));
112:                assertTrue(s.contains("c.a"));
113:            }
114:
115:            public void testTokens1() throws ParseException {
116:                TestLanguage language = new TestLanguage();
117:                language.addToken(1, "jedna", Pattern.create("['0'-'9']+"),
118:                        null, "number", 0, Feature.create("cislo", Selector
119:                                .create("a")));
120:                language.addToken(2, "dve", Pattern.create("['a'-'z']+"),
121:                        "number", "number and character", 1, Feature.create(
122:                                "cislo a pismeno", Selector.create("b")));
123:                language.addToken(3, "tri", Pattern.create("'$'"),
124:                        "number and character", null, 2, Feature.create(
125:                                "prachy", Selector.create("c")));
126:                language.addToken(4, "ctyri", Pattern.create("['A'-'Z']+"),
127:                        null, "big character", 3, Feature.create(
128:                                "velke pismeno", Selector.create("d")));
129:                language.addToken(5, "pet", Pattern.create("'+'"),
130:                        "big character", null, 4, Feature.create("plus",
131:                                Selector.create("e")));
132:                language.addFeature(Feature.create("feature", Selector
133:                        .create("a")));
134:                language.addFeature(Feature.create("feature", Selector
135:                        .create("a.b")));
136:                language.addFeature(Feature.create("feature", Selector
137:                        .create("c.a")));
138:
139:                assertEquals(5, language.getParser().getTokenTypes().size());
140:                Parser p = language.getParser();
141:                MyCookie cookie = new MyCookie();
142:                StringInput input = new StringInput("10090aas$AAQ+");
143:                ASTToken t = p.read(cookie, input, language);
144:                assertEquals("jedna", t.getTypeName());
145:                assertEquals("10090", t.getIdentifier());
146:                assertEquals(cookie.getState(), p.getState("number"));
147:                t = p.read(cookie, input, language);
148:                assertEquals("dve", t.getTypeName());
149:                assertEquals("aas", t.getIdentifier());
150:                assertEquals(cookie.getState(), p
151:                        .getState("number and character"));
152:                t = p.read(cookie, input, language);
153:                assertEquals("tri", t.getTypeName());
154:                assertEquals("$", t.getIdentifier());
155:                assertEquals(cookie.getState(), -1);
156:                t = p.read(cookie, input, language);
157:                assertEquals("ctyri", t.getTypeName());
158:                assertEquals("AAQ", t.getIdentifier());
159:                assertEquals(cookie.getState(), p.getState("big character"));
160:                t = p.read(cookie, input, language);
161:                assertEquals("pet", t.getTypeName());
162:                assertEquals("+", t.getIdentifier());
163:                assertEquals(cookie.getState(), -1);
164:                assertTrue(input.eof());
165:            }
166:
167:            private static class MyCookie implements  Cookie {
168:
169:                private int state = -1;
170:
171:                public int getState() {
172:                    return state;
173:                }
174:
175:                public void setState(int state) {
176:                    this .state = state;
177:                }
178:
179:                public void setProperties(Feature tokenProperties) {
180:                }
181:            }
182:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.