KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > lib > lexer > test > inc > DocumentUpdateTest


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19 package org.netbeans.lib.lexer.test.inc;
20
21 import javax.swing.text.Document JavaDoc;
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 /**
33  *
34  * @author Jan Lahoda
35  */

36 public class DocumentUpdateTest extends NbTestCase {
37     
38     /** Creates a new instance of DocumentUpdateTest */
39     public DocumentUpdateTest(String JavaDoc name) {
40         super(name);
41     }
42     
43     public void testUpdate1() throws Exception JavaDoc {
44         Document JavaDoc 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 JavaDoc {
64         Document JavaDoc 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 JavaDoc {
84         Document JavaDoc 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