|
|
@@ -2,7 +2,8 @@ package de.jplag;
|
|
|
|
|
|
import static de.jplag.TokenConstants.FILE_END;
|
|
|
import static de.jplag.simple.TestTokenConstants.STRING;
|
|
|
-import static org.junit.jupiter.api.Assertions.fail;
|
|
|
+import static org.junit.jupiter.api.Assertions.assertEquals;
|
|
|
+import static org.junit.jupiter.api.Assertions.assertTrue;
|
|
|
|
|
|
import java.nio.file.Path;
|
|
|
import java.util.ArrayList;
|
|
|
@@ -56,7 +57,7 @@ class TokenPrinterTest {
|
|
|
|
|
|
tokens.add(new TestToken(STRING, TEST_FILE_NAME, 22, 1, 100));
|
|
|
|
|
|
- tokens.add(new TestToken(FILE_END, TEST_FILE_NAME, 24, 1, -1));
|
|
|
+ tokens.add(new TestToken(FILE_END, TEST_FILE_NAME, Token.NO_VALUE, Token.NO_VALUE, Token.NO_VALUE));
|
|
|
|
|
|
tokens.add(new TestToken(STRING, TEST_FILE_NAME, 100, 1, 1));
|
|
|
|
|
|
@@ -67,15 +68,15 @@ class TokenPrinterTest {
|
|
|
}
|
|
|
|
|
|
private static void testOutputCorrectness(String fileName, List<Token> tokens, String output) {
|
|
|
- int lineIndex = 0;
|
|
|
+ int lineIndex = -1;
|
|
|
int tokenIndex = 0;
|
|
|
- boolean seenFileName = false;
|
|
|
for (String line : output.lines().toList()) {
|
|
|
if (line.isEmpty()) {
|
|
|
continue;
|
|
|
- } else if (lineIndex == 0 && line.equals(fileName)) {
|
|
|
- seenFileName = true;
|
|
|
- } else if (line.startsWith("" + (lineIndex + 1))) {
|
|
|
+ } else if (lineIndex == -1) {
|
|
|
+ assertEquals(fileName, line);
|
|
|
+ lineIndex = 0;
|
|
|
+ } else if (line.startsWith(String.valueOf(lineIndex + 1))) {
|
|
|
lineIndex++;
|
|
|
} else {
|
|
|
line = line.trim();
|
|
|
@@ -85,16 +86,14 @@ class TokenPrinterTest {
|
|
|
continue;
|
|
|
}
|
|
|
Token currentToken = tokens.get(tokenIndex);
|
|
|
- if (lineToken.equalsIgnoreCase(currentToken.toString()) && currentToken.getLine() == lineIndex) {
|
|
|
- tokenIndex++;
|
|
|
- } else {
|
|
|
- fail("Expected token %s, but found %s".formatted(currentToken, lineToken));
|
|
|
+ assertTrue(lineToken.equalsIgnoreCase(currentToken.toString()), "expected: %s, actual: %s".formatted(lineToken, currentToken));
|
|
|
+ if (currentToken.getLine() != Token.NO_VALUE) {
|
|
|
+ assertEquals(lineIndex, currentToken.getLine(), "invalid line for token " + currentToken);
|
|
|
}
|
|
|
+ tokenIndex++;
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
- if (!seenFileName) {
|
|
|
- fail("Expected file name");
|
|
|
- }
|
|
|
+ assertEquals(tokens.size() - 1, tokenIndex, "incorrect number of tokens printed");
|
|
|
}
|
|
|
}
|