1 19 20 package org.netbeans.api.lexer; 21 22 import junit.framework.TestCase; 23 import org.netbeans.lib.lexer.test.LexerTestUtilities; 24 import org.netbeans.lib.lexer.test.simple.*; 25 26 31 public class InputAttributesTest extends TestCase { 32 33 public InputAttributesTest(String testName) { 34 super(testName); 35 } 36 37 protected void setUp() throws java.lang.Exception { 38 } 39 40 protected void tearDown() throws java.lang.Exception { 41 } 42 43 LanguagePath simpleLP = LanguagePath.get(SimpleTokenId.language()); 44 LanguagePath jdLP = LanguagePath.get(SimpleJavadocTokenId.language()); 45 LanguagePath nestedJDLP = LanguagePath.get(simpleLP, SimpleJavadocTokenId.language()); 46 47 public void testGetSetValue() { 48 InputAttributes attrs = new InputAttributes(); 49 assertNull(attrs.getValue(simpleLP, "version")); 50 attrs.setValue(simpleLP, "version", Integer.valueOf(1), false); 51 assertEquals(attrs.getValue(simpleLP, "version"), Integer.valueOf(1)); 52 53 attrs = new InputAttributes(); 54 attrs.setValue(simpleLP, "version", Integer.valueOf(1), true); 55 assertEquals(attrs.getValue(simpleLP, "version"), Integer.valueOf(1)); 56 } 57 58 public void testInheritance() { 59 InputAttributes attrs = new InputAttributes(); 60 attrs.setValue(jdLP, "version", Integer.valueOf(1), false); 61 assertNull(attrs.getValue(nestedJDLP, "version")); 62 63 attrs = new InputAttributes(); 64 attrs.setValue(jdLP, "version", Integer.valueOf(1), true); 65 assertEquals(attrs.getValue(nestedJDLP, "version"), Integer.valueOf(1)); 66 } 67 68 public void testLexerInputAttributes() { 69 String text = "public static private"; 70 71 TokenHierarchy<?> hi = TokenHierarchy.create(text, SimpleTokenId.language()); 73 TokenSequence<? extends TokenId> ts = hi.tokenSequence(); 74 assertTrue(ts.moveNext()); 75 LexerTestUtilities.assertTokenEquals(ts, SimpleTokenId.PUBLIC, "public", 0); 76 assertTrue(ts.moveNext()); 77 LexerTestUtilities.assertTokenEquals(ts, SimpleTokenId.WHITESPACE, " ", 6); 78 assertTrue(ts.moveNext()); 79 LexerTestUtilities.assertTokenEquals(ts, SimpleTokenId.STATIC, "static", 7); 80 assertTrue(ts.moveNext()); 81 LexerTestUtilities.assertTokenEquals(ts, SimpleTokenId.WHITESPACE, " ", 13); 82 assertTrue(ts.moveNext()); 83 LexerTestUtilities.assertTokenEquals(ts, SimpleTokenId.PRIVATE, "private", 14); 84 assertFalse(ts.moveNext()); 85 86 InputAttributes attrs = new InputAttributes(); 88 attrs.setValue(SimpleTokenId.language(), "version", Integer.valueOf(1), false); 89 hi = TokenHierarchy.create(text, false, SimpleTokenId.language(), null, attrs); 90 ts = hi.tokenSequence(); 91 assertTrue(ts.moveNext()); 92 LexerTestUtilities.assertTokenEquals(ts, SimpleTokenId.PUBLIC, "public", 0); 93 assertTrue(ts.moveNext()); 94 LexerTestUtilities.assertTokenEquals(ts, SimpleTokenId.WHITESPACE, " ", 6); 95 assertTrue(ts.moveNext()); 96 LexerTestUtilities.assertTokenEquals(ts, SimpleTokenId.IDENTIFIER, "static", 7); 97 assertTrue(ts.moveNext()); 98 LexerTestUtilities.assertTokenEquals(ts, SimpleTokenId.WHITESPACE, " ", 13); 99 assertTrue(ts.moveNext()); 100 LexerTestUtilities.assertTokenEquals(ts, SimpleTokenId.PRIVATE, "private", 14); 101 assertFalse(ts.moveNext()); 102 } 103 104 } 105 | Popular Tags |