in junit-jupiter-api/src/main/java/org/junit/jupiter/api/AssertLinesMatch.java [116:183]
void assertLinesMatchWithFastForward() {
Deque<String> expectedDeque = new ArrayDeque<>(expectedLines);
Deque<String> actualDeque = new ArrayDeque<>(actualLines);
main: while (!expectedDeque.isEmpty()) {
String expectedLine = expectedDeque.pop();
int expectedLineNumber = expectedLines.size() - expectedDeque.size(); // 1-based line number
// trivial case: no more actual lines available
if (actualDeque.isEmpty()) {
fail("expected line #%d:`%s` not found - actual lines depleted", expectedLineNumber,
snippet(expectedLine));
}
String actualLine = actualDeque.peek();
// trivial case: take the fast path when they simply match
if (matches(expectedLine, actualLine)) {
actualDeque.pop();
continue; // main
}
// fast-forward marker found in expected line: fast-forward actual line...
if (isFastForwardLine(expectedLine)) {
int fastForwardLimit = parseFastForwardLimit(expectedLine);
// trivial case: fast-forward marker was in last expected line
if (expectedDeque.isEmpty()) {
int actualRemaining = actualDeque.size();
// no limit given or perfect match? we're done.
if (fastForwardLimit == Integer.MAX_VALUE || fastForwardLimit == actualRemaining) {
return;
}
fail("terminal fast-forward(%d) error: fast-forward(%d) expected", fastForwardLimit,
actualRemaining);
}
// fast-forward limit was given: use it
if (fastForwardLimit != Integer.MAX_VALUE) {
// fast-forward now: actualDeque.pop(fastForwardLimit)
for (int i = 0; i < fastForwardLimit; i++) {
actualDeque.pop();
}
continue; // main
}
// peek next expected line
expectedLine = expectedDeque.peek();
// fast-forward "unlimited": until next match
while (true) {
if (actualDeque.isEmpty()) {
fail("fast-forward(∞) didn't find: `%s`", snippet(expectedLine));
}
if (matches(expectedLine, actualDeque.peek())) {
continue main;
}
actualDeque.pop();
}
}
int actualLineNumber = actualLines.size() - actualDeque.size() + 1; // 1-based line number
fail("expected line #%d doesn't match actual line #%d%n" + "\texpected: `%s`%n" + "\t actual: `%s`",
expectedLineNumber, actualLineNumber, expectedLine, actualLine);
}
// after math
if (!actualDeque.isEmpty()) {
fail("more actual lines than expected: %d", actualDeque.size());
}
}