Skip to content

Commit 6a5fb11

Browse files
committed
test: VariationDiff::computeAllFeatureNames()
1 parent f4fdaec commit 6a5fb11

4 files changed

Lines changed: 69 additions & 0 deletions

File tree

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
import static org.junit.jupiter.api.Assertions.assertEquals;
2+
3+
import java.io.IOException;
4+
import java.nio.file.Path;
5+
import java.util.LinkedHashSet;
6+
import java.util.List;
7+
8+
import org.junit.jupiter.params.ParameterizedTest;
9+
import org.junit.jupiter.params.provider.MethodSource;
10+
import org.variantsync.diffdetective.diff.result.DiffParseException;
11+
import org.variantsync.diffdetective.variation.DiffLinesLabel;
12+
import org.variantsync.diffdetective.variation.Label;
13+
import org.variantsync.diffdetective.variation.diff.VariationDiff;
14+
import org.variantsync.diffdetective.variation.diff.parse.VariationDiffParseOptions;
15+
16+
/**
17+
* Test for {@link VariationDiff#computeAllFeatureNames()}.
18+
*/
19+
public class FeatureNamesTest {
20+
private final static Path
21+
diffsDir = Constants.RESOURCE_DIR.resolve("diffs"),
22+
pctestDir = Constants.RESOURCE_DIR.resolve("pctest"),
23+
ourDir = Constants.RESOURCE_DIR.resolve("featurenames"),
24+
collapseDir = diffsDir.resolve("collapse"),
25+
moveDir = diffsDir.resolve("move");
26+
27+
public record TestCase<L extends Label>(String origin, VariationDiff<L> diff, LinkedHashSet<String> features) {
28+
public static TestCase<DiffLinesLabel> fromFile(Path p, String... features) throws IOException, DiffParseException {
29+
return new TestCase<>(
30+
p.toString(),
31+
VariationDiff.fromFile(p, VariationDiffParseOptions.Default),
32+
new LinkedHashSet<String>(List.of(features))
33+
);
34+
}
35+
};
36+
37+
private static List<TestCase<DiffLinesLabel>> diffFeatureNameTestCases() throws IOException, DiffParseException {
38+
return List.of(
39+
TestCase.fromFile(collapseDir.resolve("elif.txt"), "A", "B", "C", "D", "E"),
40+
TestCase.fromFile(collapseDir.resolve("simple.txt"), "A", "B", "C"),
41+
TestCase.fromFile(moveDir.resolve("simple.txt"), "X", "Y"),
42+
TestCase.fromFile(pctestDir.resolve("a.diff"), "A", "D", "E", "B", "C"),
43+
TestCase.fromFile(pctestDir.resolve("elif.diff"), "A", "B", "C", "D"),
44+
TestCase.fromFile(pctestDir.resolve("else.diff"), "A", "C", "B"),
45+
TestCase.fromFile(ourDir.resolve("empty.diff")),
46+
TestCase.fromFile(ourDir.resolve("a.diff"), "FIRST", "SECOND"),
47+
TestCase.fromFile(ourDir.resolve("b.diff"), "A")
48+
);
49+
}
50+
51+
@ParameterizedTest
52+
@MethodSource("diffFeatureNameTestCases")
53+
public void testComputeAllFeatureNames(TestCase<DiffLinesLabel> testCase) {
54+
assertEquals(testCase.features(), testCase.diff().computeAllFeatureNames(), testCase.origin());
55+
}
56+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#if FIRST
2+
foo
3+
#if SECOND
4+
bar
5+
#endif
6+
#endif
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
-#if A
2+
foo
3+
#if A
4+
bar
5+
#endif
6+
-#endif
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
foo

0 commit comments

Comments
 (0)