1 19 20 package org.netbeans.api.lexer; 21 22 import java.util.Collection ; 23 import java.util.EnumSet ; 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 33 public class LanguagePathTest extends NbTestCase { 34 35 36 public LanguagePathTest(String 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 67 70 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 primaryCategory() { 93 return null; 94 } 95 } 97 private static final class Lang extends LanguageHierarchy<TestTokenId> { 98 private String mimeType; 99 100 public Lang(String mimeType) { 101 this.mimeType = mimeType; 102 } 103 104 protected Lexer<TestTokenId> createLexer(LexerRestartInfo<TestTokenId> info) { 105 return null; 106 } 107 108 protected Collection <TestTokenId> createTokenIds() { 109 return EnumSet.allOf(TestTokenId.class); 110 } 111 112 public String mimeType() { 113 return mimeType; 114 } 115 } } 117 | Popular Tags |