KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > lib > lexer > inc > SnapshotTokenListTest


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.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.SimpleJavadocTokenId;
30 import org.netbeans.lib.lexer.test.simple.SimpleTokenId;
31
32 /**
33  *
34  * @author Jan Lahoda
35  */

36 public class SnapshotTokenListTest extends NbTestCase {
37     
38     public SnapshotTokenListTest(String JavaDoc testName) {
39         super(testName);
40     }
41
42     protected void setUp() throws Exception JavaDoc {
43     }
44
45     public void testInputAttributes() throws Exception JavaDoc {
46         Document JavaDoc 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