1 19 package org.netbeans.lib.lexer.test.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.SimpleStringTokenId; 30 import org.netbeans.lib.lexer.test.simple.SimpleTokenId; 31 32 36 public class DocumentUpdateTest extends NbTestCase { 37 38 39 public DocumentUpdateTest(String name) { 40 super(name); 41 } 42 43 public void testUpdate1() throws Exception { 44 Document d = new ModificationTextDocument(); 45 46 d.putProperty(Language.class, SimpleTokenId.language()); 47 48 d.insertString(0, "\"\\t\\b\\t test\"", null); 49 50 TokenHierarchy<?> h = TokenHierarchy.get(d); 51 52 h.tokenSequence().tokenCount(); 53 54 TokenSequence<? extends TokenId> s = h.tokenSequence(); 55 56 assertTrue(s.moveNext()); 57 58 s.embedded(); 59 60 d.insertString(5, "t", null); 61 } 62 63 public void testUpdate2() throws Exception { 64 Document d = new ModificationTextDocument(); 65 66 d.putProperty(Language.class, SimpleTokenId.language()); 67 68 d.insertString(0, "\"\\t\\b\\b\\t sfdsffffffffff\"", null); 69 70 TokenHierarchy<?> h = TokenHierarchy.get(d); 71 72 h.tokenSequence().tokenCount(); 73 74 TokenSequence<? extends TokenId> s = h.tokenSequence(); 75 76 assertTrue(s.moveNext()); 77 78 s.embedded(); 79 80 d.insertString(10, "t", null); 81 } 82 83 public void testUpdate3() throws Exception { 84 Document d = new ModificationTextDocument(); 85 86 d.putProperty(Language.class, SimpleTokenId.language()); 87 88 d.insertString(0, "\"t\"", null); 89 90 TokenHierarchy<?> h = TokenHierarchy.get(d); 91 92 h.tokenSequence().tokenCount(); 93 94 TokenSequence<? extends TokenId> s = h.tokenSequence(); 95 96 assertTrue(s.moveNext()); 97 98 assertNotNull(s.embedded()); 99 100 d.insertString(1, "\\", null); 101 102 System.err.println("d=" + d.getText(0, d.getLength())); 103 104 LexerTestUtilities.assertNextTokenEquals(h.tokenSequence(), SimpleTokenId.STRING_LITERAL, "\"\\t\""); 105 106 s = h.tokenSequence(); 107 108 assertTrue(s.moveNext()); 109 110 TokenSequence<? extends TokenId> e = s.embedded(); 111 112 assertNotNull(e); 113 114 assertTrue(e.moveNext()); 115 116 assertEquals(e.token().id(), SimpleStringTokenId.TAB); 117 } 118 119 } 120 | Popular Tags |