Skip to content

Commit 84e5eab

Browse files
committed
test: refactor the unparser test case sources
1 parent 6bcde64 commit 84e5eab

11 files changed

Lines changed: 16 additions & 39 deletions

File tree

src/test/java/VariationUnparserTest.java

Lines changed: 12 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
import java.nio.file.Files;
33
import java.nio.file.Path;
44
import java.util.stream.Stream;
5-
import org.junit.jupiter.api.Test;
65
import org.junit.jupiter.params.ParameterizedTest;
76
import org.junit.jupiter.params.provider.MethodSource;
87
import org.variantsync.diffdetective.diff.result.DiffParseException;
@@ -17,45 +16,23 @@
1716
import static org.variantsync.diffdetective.experiments.thesis_es.UnparseAnalysis.removeWhitespace;
1817

1918
public class VariationUnparserTest {
20-
private final static Path treeDir = Constants.RESOURCE_DIR.resolve("unparser");
21-
private final static Path testDirDiff = Constants.RESOURCE_DIR.resolve("diffs").resolve("parser");
22-
private final static String treeSuffix = ".txt";
23-
private final static String diffSuffix = ".diff";
19+
private final static Path unparserTestCaseDir = Constants.RESOURCE_DIR.resolve("unparser");
20+
private final static Path parserTestCaseDir = Constants.RESOURCE_DIR.resolve("diffs").resolve("parser");
21+
private final static String parserTestCaseSuffix = ".diff";
2422

25-
private static Stream<Path> findTestCases(Path dir, String filenameSuffix) throws IOException {
26-
return Files
27-
.list(dir)
28-
.filter(filename -> filename.getFileName().toString().endsWith(filenameSuffix));
23+
public static Stream<Path> treeTestCases() throws IOException {
24+
return Files.list(unparserTestCaseDir.resolve("trees"));
2925
}
3026

31-
public static Stream<Path> testsTree() throws IOException {
32-
return findTestCases(treeDir, treeSuffix);
33-
}
34-
35-
public static Stream<Path> testsDiff() throws IOException {
36-
return findTestCases(testDirDiff, diffSuffix);
37-
}
38-
39-
@Test
40-
public void testTree() throws IOException, DiffParseException {
41-
Path file = treeDir.resolve("test8.txt");
42-
43-
assertEqualTree(
44-
Files.readString(file),
45-
parseUnparseTree(file, VariationDiffParseOptions.Default));
46-
}
47-
48-
@Test
49-
public void testDiffSemEq() throws IOException, DiffParseException {
50-
Path file = treeDir.resolve("diff").resolve("diff.diff");
51-
52-
assertEqualDiff(
53-
Files.readString(file),
54-
parseUnparseDiff(file, VariationDiffParseOptions.Default));
27+
public static Stream<Path> diffTestCases() throws IOException {
28+
return Stream.concat(
29+
Files.list(unparserTestCaseDir.resolve("diffs")),
30+
Files.list(parserTestCaseDir)
31+
.filter(filename -> filename.getFileName().toString().endsWith(parserTestCaseSuffix)));
5532
}
5633

5734
@ParameterizedTest
58-
@MethodSource("testsTree")
35+
@MethodSource("treeTestCases")
5936
public void testTreeUnparse(Path testCasePath) throws IOException, DiffParseException {
6037
String unparsed1 = parseUnparseTree(testCasePath, new VariationDiffParseOptions(false, false));
6138
String unparsed2 = parseUnparseTree(testCasePath, new VariationDiffParseOptions(false, true));
@@ -72,7 +49,7 @@ public void testTreeUnparse(Path testCasePath) throws IOException, DiffParseExce
7249
}
7350

7451
@ParameterizedTest
75-
@MethodSource("testsDiff")
52+
@MethodSource("diffTestCases")
7653
public void testDiffUnparse(Path testCasePath) throws IOException, DiffParseException {
7754
String unparsed1 = parseUnparseDiff(testCasePath, new VariationDiffParseOptions(false, false));
7855
String unparsed2 = parseUnparseDiff(testCasePath, new VariationDiffParseOptions(false, true));

src/test/resources/unparser/diff/diff.diff

Lines changed: 0 additions & 4 deletions
This file was deleted.
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#if A
2+
Code
3+
+#endif A
4+
-#endif B

0 commit comments

Comments
 (0)