use of kalang.util.TokenNavigator in project kalang by kasonyang.
the class KalangCompilerTest method testTokenNavigator.
private void testTokenNavigator(Token[] tokens, ParseTree tree) {
TokenNavigator tokenNav = new TokenNavigator(tokens);
ParseTreeNavigator treeNav = new ParseTreeNavigator(tree);
assertEquals(0, tokenNav.getCurrentTokenIndex());
assertEquals("class", treeNav.getParseTree(tokenNav.getCurrentToken()).getText());
tokenNav.move(5);
assertEquals("{", tokenNav.getCurrentToken().getText());
assertEquals(1, tokenNav.getCurrentTokenIndex());
tokenNav.next(KalangLexer.DEFAULT_TOKEN_CHANNEL);
assertEquals("}", tokenNav.getCurrentToken().getText());
tokenNav.move(8);
assertEquals("}", tokenNav.getCurrentToken().getText());
assertEquals("}", treeNav.getParseTree(tokenNav.getCurrentToken()).getText());
assertEquals(3, tokenNav.getCurrentTokenIndex());
}
Aggregations