1 19 20 package org.netbeans.lib.java.lexer; 21 22 import java.io.File ; 23 import java.io.FileReader ; 24 import java.nio.ByteOrder ; 25 import java.nio.CharBuffer ; 26 import org.netbeans.api.java.lexer.JavaTokenId; 27 import org.netbeans.api.lexer.TokenHierarchy; 28 import org.netbeans.api.lexer.TokenId; 29 import org.netbeans.api.lexer.TokenSequence; 30 import org.netbeans.junit.NbTestCase; 31 import org.netbeans.lib.lexer.test.LexerTestUtilities; 32 33 39 public class JavaFlyTokensTest extends NbTestCase { 40 41 public JavaFlyTokensTest(String testName) { 42 super(testName); 43 } 44 45 protected void setUp() throws java.lang.Exception { 46 LexerTestUtilities.setTesting(true); 48 } 49 50 protected void tearDown() throws java.lang.Exception { 51 } 52 53 public void test() throws Exception { 54 File testJComponentFile = new File (getDataDir() + "/testfiles/JComponent.java.txt"); 55 FileReader r = new FileReader (testJComponentFile); 56 int fileLen = (int)testJComponentFile.length(); 57 CharBuffer cb = CharBuffer.allocate(fileLen); 58 r.read(cb); 59 cb.rewind(); 60 String text = cb.toString(); 61 TokenHierarchy<?> hi = TokenHierarchy.create(text, JavaTokenId.language()); 62 TokenSequence<? extends TokenId> ts = hi.tokenSequence(); 63 64 System.err.println("Flyweight tokens: " + LexerTestUtilities.flyweightTokenCount(ts) 65 + "\nTotal tokens: " + ts.tokenCount() 66 + "\nFlyweight text length: " + LexerTestUtilities.flyweightTextLength(ts) 67 + "\nTotal text length: " + fileLen 68 + "\nDistribution: " + LexerTestUtilities.flyweightDistribution(ts) 69 ); 70 71 assertEquals(LexerTestUtilities.flyweightTokenCount(ts), 13884); 72 assertEquals(LexerTestUtilities.flyweightTextLength(ts), 21741); 73 assertEquals(ts.tokenCount(), 21481); 74 75 } 76 77 } 78 | Popular Tags |