void (String text, String[] expectedTokens,Lexer lexer) { lexer.start(text); int idx = 0; while (lexer.getTokenType() != null) { if (idx >= expectedTokens.length) fail("Too many tokens"); String tokenName = lexer.getTokenType().toString(); String expectedTokenType = expectedTokens[idx++]; String expectedTokenText = expectedTokens[idx++]; String tokenText = lexer.getBufferSequence().subSequence(lexer.getTokenStart(), lexer.getTokenEnd()).toString(); assertEquals(tokenText, expectedTokenType, tokenName); assertEquals("Token type: " + expectedTokenType, expectedTokenText, tokenText); lexer.advance(); } if (idx < expectedTokens.length) fail("Not enough tokens"); }