KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > api > lexer > LanguagePathTest


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.netbeans.api.lexer;
21
22 import java.util.Collection JavaDoc;
23 import java.util.EnumSet JavaDoc;
24 import org.netbeans.junit.NbTestCase;
25 import org.netbeans.spi.lexer.LanguageHierarchy;
26 import org.netbeans.spi.lexer.Lexer;
27 import org.netbeans.spi.lexer.LexerRestartInfo;
28
29 /**
30  *
31  * @author vita
32  */

33 public class LanguagePathTest extends NbTestCase {
34
35     /** Creates a new instance of LanguagePathTest */
36     public LanguagePathTest(String JavaDoc name) {
37         super(name);
38     }
39
40     public void testMimePath() {
41         Language<TestTokenId> jspLang = new Lang("text/x-jsp").language();
42         Language<TestTokenId> javaLang = new Lang("text/x-java").language();
43         Language<TestTokenId> javadocLang = new Lang("text/x-javadoc").language();
44         
45         LanguagePath jspPath = LanguagePath.get(jspLang);
46         assertEquals("Invalid mime path for jspLang", "text/x-jsp", jspPath.mimePath());
47         
48         LanguagePath javaPath = LanguagePath.get(javaLang);
49         assertEquals("Invalid mime path for javaLang", "text/x-java", javaPath.mimePath());
50         
51         LanguagePath jspJavaPath = LanguagePath.get(LanguagePath.get(jspLang), javaLang);
52         assertEquals("Invalid mime path for jspLang",
53                 "text/x-jsp/text/x-java", jspJavaPath.mimePath());
54         
55         LanguagePath javaJavadocPath = LanguagePath.get(LanguagePath.get(javaLang), javadocLang);
56         assertEquals("Invalid mime path for javaLang/javadocLang",
57                 "text/x-java/text/x-javadoc", javaJavadocPath.mimePath());
58
59         LanguagePath jspJavaJavadocPath = LanguagePath.get(LanguagePath.get(jspPath, javaLang), javadocLang);
60         assertEquals("Invalid mime path for jspLang/javaLang/javadocLang",
61                 "text/x-jsp/text/x-java/text/x-javadoc", jspJavaJavadocPath.mimePath());
62
63 // LanguagePath jspJavaNullJavadocPath = LanguagePath.get(LanguagePath.get(LanguagePath.get(jspPath, javaLang), nullLang), javadocLang);
64
// assertEquals("Invalid mime path for jspLang/javaLang/nullLang/javadocLang",
65
// "text/x-jsp/text/x-java/text/x-javadoc", jspJavaNullJavadocPath.mimePath());
66

67 // LanguagePath nullPath = LanguagePath.get(nullLang);
68
// assertEquals("Invalid mime path for nullLang", "", nullPath.mimePath());
69

70         // Test endsWith()
71
assertTrue(jspPath.endsWith(jspPath));
72         assertTrue(jspJavaPath.endsWith(javaPath));
73         assertFalse(jspJavaPath.endsWith(jspPath));
74         assertFalse(javaPath.endsWith(jspJavaPath));
75         assertTrue(jspJavaJavadocPath.endsWith(javaJavadocPath));
76         
77         assertTrue(jspPath.subPath(0) == jspPath);
78         assertTrue(jspJavaPath.subPath(0) == jspJavaPath);
79         assertTrue(jspJavaPath.subPath(1) == javaPath);
80         assertTrue(jspJavaJavadocPath.subPath(1, 2) == javaPath);
81     }
82     
83     private static enum TestTokenId implements TokenId {
84         
85         TOKEN_ID1,
86         TOKEN_ID2;
87         
88         private TestTokenId() {
89             
90         }
91
92         public String JavaDoc primaryCategory() {
93             return null;
94         }
95     } // End of TestTokenId
96

97     private static final class Lang extends LanguageHierarchy<TestTokenId> {
98         private String JavaDoc mimeType;
99         
100         public Lang(String JavaDoc mimeType) {
101             this.mimeType = mimeType;
102         }
103         
104         protected Lexer<TestTokenId> createLexer(LexerRestartInfo<TestTokenId> info) {
105             return null;
106         }
107
108         protected Collection JavaDoc<TestTokenId> createTokenIds() {
109             return EnumSet.allOf(TestTokenId.class);
110         }
111         
112         public String JavaDoc mimeType() {
113             return mimeType;
114         }
115     } // End of Lang class
116
}
117
Popular Tags