1 19 20 package org.netbeans.lib.lexer.test.state; 21 22 import javax.swing.text.Document ; 23 import junit.framework.TestCase; 24 import org.netbeans.api.lexer.InputAttributes; 25 import org.netbeans.api.lexer.Language; 26 import org.netbeans.api.lexer.TokenHierarchy; 27 import org.netbeans.api.lexer.TokenId; 28 import org.netbeans.api.lexer.TokenSequence; 29 import org.netbeans.lib.lexer.test.LexerTestUtilities; 30 import org.netbeans.lib.lexer.test.ModificationTextDocument; 31 32 37 public class StateLexerIncTest extends TestCase { 38 39 public StateLexerIncTest(String testName) { 40 super(testName); 41 } 42 43 protected void setUp() throws java.lang.Exception { 44 } 45 46 protected void tearDown() throws java.lang.Exception { 47 } 48 49 public void test() throws Exception { 50 Document doc = new ModificationTextDocument(); 51 InputAttributes attrs = new InputAttributes(); 53 doc.putProperty(InputAttributes.class, attrs); 54 doc.putProperty(Language.class, StateTokenId.language()); 55 TokenHierarchy<?> hi = TokenHierarchy.get(doc); 56 TokenSequence<? extends TokenId> ts = hi.tokenSequence(); 57 assertFalse(ts.moveNext()); 58 59 String text = "abc"; 61 doc.insertString(0, text, null); 62 63 ts = hi.tokenSequence(); 64 assertTrue(ts.moveNext()); 65 LexerTestUtilities.assertTokenEquals(ts, StateTokenId.A, "a", 0); 66 assertEquals(LexerTestUtilities.lookahead(ts), 0); 67 assertEquals(LexerTestUtilities.state(ts), StateLexer.AFTER_A); 68 assertTrue(ts.moveNext()); 69 LexerTestUtilities.assertTokenEquals(ts, StateTokenId.BMULTI, "b", 1); 70 assertEquals(LexerTestUtilities.state(ts), StateLexer.AFTER_B); 71 assertEquals(LexerTestUtilities.lookahead(ts), 1); 72 assertTrue(ts.moveNext()); 73 LexerTestUtilities.assertTokenEquals(ts, StateTokenId.ERROR, "c", 2); 74 assertEquals(LexerTestUtilities.state(ts), null); 75 assertFalse(ts.moveNext()); 76 77 LexerTestUtilities.incCheck(doc, false); 78 79 attrs.setValue(StateTokenId.language(), "restartState", StateLexer.AFTER_A, true); 81 doc.insertString(2, "b", null); 82 83 } 84 85 } 86 | Popular Tags |