1 19 package org.netbeans.lib.lexer.inc; 20 21 import javax.swing.text.Document ; 22 import org.netbeans.api.lexer.Language; 23 import org.netbeans.api.lexer.TokenHierarchy; 24 import org.netbeans.api.lexer.TokenId; 25 import org.netbeans.api.lexer.TokenSequence; 26 import org.netbeans.junit.NbTestCase; 27 import org.netbeans.lib.lexer.test.LexerTestUtilities; 28 import org.netbeans.lib.lexer.test.ModificationTextDocument; 29 import org.netbeans.lib.lexer.test.simple.SimpleJavadocTokenId; 30 import org.netbeans.lib.lexer.test.simple.SimpleTokenId; 31 32 36 public class SnapshotTokenListTest extends NbTestCase { 37 38 public SnapshotTokenListTest(String testName) { 39 super(testName); 40 } 41 42 protected void setUp() throws Exception { 43 } 44 45 public void testInputAttributes() throws Exception { 46 Document d = new ModificationTextDocument(); 47 48 d.putProperty(Language.class, SimpleTokenId.language()); 49 50 d.insertString(0, "ident ident /** @see X */", null); 51 52 TokenHierarchy<?> h = TokenHierarchy.get(d).createSnapshot(); 53 TokenSequence<? extends TokenId> ts = h.tokenSequence(); 54 55 LexerTestUtilities.assertNextTokenEquals(ts, SimpleTokenId.IDENTIFIER, "ident"); 56 assertEquals(0, ts.offset()); 57 58 LexerTestUtilities.assertNextTokenEquals(ts, SimpleTokenId.WHITESPACE, " "); 59 assertEquals(5, ts.offset()); 60 61 LexerTestUtilities.assertNextTokenEquals(ts, SimpleTokenId.IDENTIFIER, "ident"); 62 assertEquals(6, ts.offset()); 63 64 LexerTestUtilities.assertNextTokenEquals(ts, SimpleTokenId.WHITESPACE, " "); 65 assertEquals(11, ts.offset()); 66 67 LexerTestUtilities.assertNextTokenEquals(ts, SimpleTokenId.JAVADOC_COMMENT, "/** @see X */"); 68 assertEquals(12, ts.offset()); 69 70 TokenSequence<? extends TokenId> inner = ts.embedded(); 71 72 assertNotNull(inner); 73 74 LexerTestUtilities.assertNextTokenEquals(inner, SimpleJavadocTokenId.OTHER_TEXT, " "); 75 assertEquals(15, inner.offset()); 76 77 LexerTestUtilities.assertNextTokenEquals(inner, SimpleJavadocTokenId.TAG, "@see"); 78 assertEquals(16, inner.offset()); 79 80 LexerTestUtilities.assertNextTokenEquals(inner, SimpleJavadocTokenId.OTHER_TEXT, " "); 81 assertEquals(20, inner.offset()); 82 83 LexerTestUtilities.assertNextTokenEquals(inner, SimpleJavadocTokenId.IDENT, "X"); 84 assertEquals(21, inner.offset()); 85 86 LexerTestUtilities.assertNextTokenEquals(inner, SimpleJavadocTokenId.OTHER_TEXT, " "); 87 assertEquals(22, inner.offset()); 88 } 89 } 90 | Popular Tags |