void (String text, Lexer lexer, boolean checkTokenText, String... expectedTokens) { lexer.start(text); List<String> actualTokens = StreamEx.generate(() -> { IElementType nextTokenType = lexer.getTokenType(); if (nextTokenType == null) return null; String nextToken = checkTokenText ? lexer.getTokenText() : nextTokenType.toString(); lexer.advance(); return nextToken; }) .takeWhile(Objects::nonNull) .toList(); String expectedTokensInCode = StringUtil.join(actualTokens, t -> '"' + t + '"', ", "); assertEquals("Token mismatch. Actual values: " + expectedTokensInCode, List.of(expectedTokens), actualTokens); }