void (@NotNull String text) { Lexer mainLexer = createLexer(); List<Trinity<IElementType, Integer, Integer>> allTokens = tokenize(text, 0, 0, mainLexer); Lexer auxLexer = createLexer(); auxLexer.start(text); int index = 0; while (true) { IElementType type = auxLexer.getTokenType(); if (type == null) { break; } int state = auxLexer.getState(); if (state == 0 || (auxLexer instanceof RestartableLexer && ((RestartableLexer)auxLexer).isRestartableState(state))) { int tokenStart = auxLexer.getTokenStart(); List<Trinity<IElementType, Integer, Integer>> expectedTokens = allTokens.subList(index, allTokens.size()); List<Trinity<IElementType, Integer, Integer>> restartedTokens = tokenize(text, tokenStart, state, mainLexer); assertEquals( "Restarting impossible from offset " + tokenStart + " - " + auxLexer.getTokenText() + "\n" + "All tokens <type, offset, lexer state>: " + allTokens + "\n", expectedTokens.stream().map(Objects::toString).collect(Collectors.joining("\n")), restartedTokens.stream().map(Objects::toString).collect(Collectors.joining("\n")) ); } index++; auxLexer.advance(); } }