void (final String text, String... expectedTokens) { Lexer lexer = new PyDocstringParserDefinition().createLexer(myFixture.getProject()); lexer.start(text); int idx = 0; while (lexer.getTokenType() != null) { if (idx >= expectedTokens.length) { StringBuilder remainingTokens = new StringBuilder("\"" + lexer.getTokenType().toString() + "\""); lexer.advance(); while (lexer.getTokenType() != null) { remainingTokens.append(","); remainingTokens.append(" \"").append(lexer.getTokenType().toString()).append("\""); lexer.advance(); } fail("Too many tokens. Following tokens: " + remainingTokens); } String tokenName = lexer.getTokenType().toString(); assertEquals("Token mismatch at position " + idx, expectedTokens[idx], tokenName); idx++; lexer.advance(); } if (idx < expectedTokens.length) fail("Not enough tokens"); }