Skip to content

Commit 69b406f

Browse files
committed
test: split different parse options into separate unparse tests
1 parent 84e5eab commit 69b406f

1 file changed

Lines changed: 24 additions & 31 deletions

File tree

src/test/java/VariationUnparserTest.java

Lines changed: 24 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import java.nio.file.Path;
44
import java.util.stream.Stream;
55
import org.junit.jupiter.params.ParameterizedTest;
6+
import org.junit.jupiter.params.provider.Arguments;
67
import org.junit.jupiter.params.provider.MethodSource;
78
import org.variantsync.diffdetective.diff.result.DiffParseException;
89
import org.variantsync.diffdetective.variation.DiffLinesLabel;
@@ -20,49 +21,41 @@ public class VariationUnparserTest {
2021
private final static Path parserTestCaseDir = Constants.RESOURCE_DIR.resolve("diffs").resolve("parser");
2122
private final static String parserTestCaseSuffix = ".diff";
2223

23-
public static Stream<Path> treeTestCases() throws IOException {
24-
return Files.list(unparserTestCaseDir.resolve("trees"));
24+
public static Stream<Arguments> treeTestCases() throws IOException {
25+
return withParseOptions(Files.list(unparserTestCaseDir.resolve("trees")));
2526
}
2627

27-
public static Stream<Path> diffTestCases() throws IOException {
28-
return Stream.concat(
28+
public static Stream<Arguments> diffTestCases() throws IOException {
29+
return withParseOptions(Stream.concat(
2930
Files.list(unparserTestCaseDir.resolve("diffs")),
3031
Files.list(parserTestCaseDir)
31-
.filter(filename -> filename.getFileName().toString().endsWith(parserTestCaseSuffix)));
32+
.filter(filename -> filename.getFileName().toString().endsWith(parserTestCaseSuffix))));
33+
}
34+
35+
private static Stream<Arguments> withParseOptions(Stream<Path> paths) {
36+
// Build a Cartesian product of all paths and parse options.
37+
return
38+
paths.flatMap(path -> Stream.of(
39+
Arguments.of(path, new VariationDiffParseOptions(false, false)),
40+
Arguments.of(path, new VariationDiffParseOptions(false, true)),
41+
Arguments.of(path, new VariationDiffParseOptions(true, false)),
42+
Arguments.of(path, new VariationDiffParseOptions(true, true))));
3243
}
3344

3445
@ParameterizedTest
3546
@MethodSource("treeTestCases")
36-
public void testTreeUnparse(Path testCasePath) throws IOException, DiffParseException {
37-
String unparsed1 = parseUnparseTree(testCasePath, new VariationDiffParseOptions(false, false));
38-
String unparsed2 = parseUnparseTree(testCasePath, new VariationDiffParseOptions(false, true));
39-
String unparsed3 = parseUnparseTree(testCasePath, new VariationDiffParseOptions(true, false));
40-
String unparsed4 = parseUnparseTree(testCasePath, new VariationDiffParseOptions(true, true));
41-
42-
String original = Files.readString(testCasePath);
43-
original = original.replaceAll("\\r\\n", "\n");
44-
45-
assertEqualTree(original, unparsed1);
46-
assertEqualTree(original, unparsed2);
47-
assertEqualTree(original, unparsed3);
48-
assertEqualTree(original, unparsed4);
47+
public void testTreeUnparse(Path testCasePath, VariationDiffParseOptions parseOptions) throws IOException, DiffParseException {
48+
assertEqualTree(
49+
Files.readString(testCasePath).replaceAll("\\r\\n", "\n"),
50+
parseUnparseTree(testCasePath, parseOptions));
4951
}
5052

5153
@ParameterizedTest
5254
@MethodSource("diffTestCases")
53-
public void testDiffUnparse(Path testCasePath) throws IOException, DiffParseException {
54-
String unparsed1 = parseUnparseDiff(testCasePath, new VariationDiffParseOptions(false, false));
55-
String unparsed2 = parseUnparseDiff(testCasePath, new VariationDiffParseOptions(false, true));
56-
String unparsed3 = parseUnparseDiff(testCasePath, new VariationDiffParseOptions(true, false));
57-
String unparsed4 = parseUnparseDiff(testCasePath, new VariationDiffParseOptions(true, true));
58-
59-
String original = Files.readString(testCasePath);
60-
original = original.replaceAll("\\r\\n", "\n");
61-
62-
assertEqualDiff(original, unparsed1);
63-
assertEqualDiff(original, unparsed2);
64-
assertEqualDiff(original, unparsed3);
65-
assertEqualDiff(original, unparsed4);
55+
public void testDiffUnparse(Path testCasePath, VariationDiffParseOptions parseOptions) throws IOException, DiffParseException {
56+
assertEqualDiff(
57+
Files.readString(testCasePath).replaceAll("\\r\\n", "\n"),
58+
parseUnparseDiff(testCasePath, parseOptions));
6659
}
6760

6861
private static String parseUnparseTree(Path path, VariationDiffParseOptions option) throws IOException, DiffParseException {

0 commit comments

Comments
 (0)