Quellcode durchsuchen

add some basic tests

SirYwell vor 4 Jahren
Ursprung
Commit
96927671e5
1 geänderte Dateien mit 32 neuen und 0 gelöschten Zeilen
  1. 32 0
      jplag.frontend.text/src/test/java/jplag/text/TextFrontendTest.java

+ 32 - 0
jplag.frontend.text/src/test/java/jplag/text/TextFrontendTest.java

@@ -4,12 +4,18 @@ import static org.junit.jupiter.api.Assertions.assertEquals;
 import static org.junit.jupiter.api.Assertions.assertTrue;
 
 import java.io.File;
+import java.io.IOException;
+import java.nio.file.Files;
 import java.nio.file.Path;
 import java.util.HashMap;
 import java.util.Map;
 
 import org.junit.jupiter.api.BeforeEach;
 import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.io.CleanupMode;
+import org.junit.jupiter.api.io.TempDir;
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.ValueSource;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -49,4 +55,30 @@ class TextFrontendTest {
         assertEquals(156, tokenTypes.values().size());
     }
 
+    @ParameterizedTest
+    @ValueSource(strings = {
+        "\n",
+        "\r",
+        "\r\n",
+    })
+    void testLineBreakInputs(String input, @TempDir Path tempDir) throws IOException {
+        Path file = tempDir.resolve("input.txt");
+        Files.writeString(file, input);
+        TokenList result = frontend.parse(tempDir.toFile(), new String[]{"input.txt"});
+        assertEquals(1, result.size());
+    }
+
+    @ParameterizedTest
+    @ValueSource(strings = {
+        "\ntoken",
+        "\rtoken",
+        "\r\ntoken",
+    })
+    void testTokenAfterLineBreak(String input, @TempDir Path tempDir) throws IOException {
+        Path file = tempDir.resolve("input.txt");
+        Files.writeString(file, input);
+        TokenList result = frontend.parse(tempDir.toFile(), new String[]{"input.txt"});
+        assertEquals(2, result.getToken(0).getLine());
+    }
+
 }