Skip to content

Commit 6d9e315

Browse files
test: add test for parsing entire JPP diff
1 parent d239664 commit 6d9e315

4 files changed

Lines changed: 117 additions & 2 deletions

File tree

src/test/java/JPPParserTest.java

Lines changed: 60 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,28 @@
1+
import org.apache.commons.io.IOUtils;
12
import org.junit.jupiter.params.ParameterizedTest;
23
import org.junit.jupiter.params.provider.MethodSource;
4+
import org.variantsync.diffdetective.diff.result.DiffParseException;
35
import org.variantsync.diffdetective.error.UnparseableFormulaException;
6+
import org.variantsync.diffdetective.feature.PreprocessorAnnotationParser;
47
import org.variantsync.diffdetective.feature.jpp.JPPDiffLineFormulaExtractor;
8+
import org.variantsync.diffdetective.util.IO;
9+
import org.variantsync.diffdetective.variation.DiffLinesLabel;
10+
import org.variantsync.diffdetective.variation.diff.VariationDiff;
11+
import org.variantsync.diffdetective.variation.diff.parse.VariationDiffParseOptions;
12+
import org.variantsync.diffdetective.variation.diff.parse.VariationDiffParser;
13+
import org.variantsync.diffdetective.variation.diff.serialize.Format;
14+
import org.variantsync.diffdetective.variation.diff.serialize.LineGraphExporter;
15+
import org.variantsync.diffdetective.variation.diff.serialize.edgeformat.ChildOrderEdgeFormat;
16+
import org.variantsync.diffdetective.variation.diff.serialize.nodeformat.FullNodeFormat;
517

18+
import java.io.IOException;
19+
import java.nio.file.Files;
20+
import java.nio.file.Path;
621
import java.util.List;
722

823
import static org.junit.jupiter.api.Assertions.assertEquals;
924
import static org.junit.jupiter.api.Assertions.assertThrows;
25+
import static org.variantsync.diffdetective.util.Assert.fail;
1026

1127
// Test cases for a parser of https://www.slashdev.ca/javapp/
1228
public class JPPParserTest {
@@ -71,12 +87,19 @@ private static List<JPPParserTest.ThrowingTestCase> throwingTestCases() {
7187
);
7288
}
7389

90+
private static List<JPPParserTest.TestCase<Path, Path>> fullDiffTests() {
91+
final Path basePath = Path.of("src", "test", "resources", "diffs", "jpp");
92+
return List.of(
93+
new JPPParserTest.TestCase<>(basePath.resolve("basic_jpp.diff"), basePath.resolve("basic_jpp_expected.lg"))
94+
);
95+
}
96+
7497
@ParameterizedTest
7598
@MethodSource("abstractionTests")
76-
public void testCase(JPPParserTest.TestCase testCase) throws UnparseableFormulaException {
99+
public void testCase(JPPParserTest.TestCase<String, String> testCase) throws UnparseableFormulaException {
77100
assertEquals(
78101
testCase.expected,
79-
new JPPDiffLineFormulaExtractor().extractFormula((String) testCase.input())
102+
new JPPDiffLineFormulaExtractor().extractFormula(testCase.input())
80103
);
81104
}
82105

@@ -88,4 +111,39 @@ public void throwingTestCase(JPPParserTest.ThrowingTestCase testCase) {
88111
);
89112
}
90113

114+
@ParameterizedTest
115+
@MethodSource("fullDiffTests")
116+
public void fullDiffTestCase(JPPParserTest.TestCase<Path, Path> testCase) throws IOException, DiffParseException {
117+
VariationDiff<DiffLinesLabel> variationDiff;
118+
try (var inputFile = Files.newBufferedReader(testCase.input)) {
119+
variationDiff = VariationDiffParser.createVariationDiff(
120+
inputFile,
121+
new VariationDiffParseOptions(
122+
false,
123+
false
124+
).withAnnotationParser(PreprocessorAnnotationParser.JPPAnnotationParser)
125+
);
126+
}
127+
128+
Path actualPath = testCase.input.getParent().resolve(testCase.input.getFileName() + "_actual");
129+
try (var output = IO.newBufferedOutputStream(actualPath)) {
130+
new LineGraphExporter<>(new Format<>(new FullNodeFormat(), new ChildOrderEdgeFormat<>()))
131+
.exportVariationDiff(variationDiff, output);
132+
}
133+
134+
try (
135+
var expectedFile = Files.newBufferedReader(testCase.expected);
136+
var actualFile = Files.newBufferedReader(actualPath);
137+
) {
138+
if (IOUtils.contentEqualsIgnoreEOL(expectedFile, actualFile)) {
139+
// Delete output files if the test succeeded
140+
Files.delete(actualPath);
141+
} else {
142+
// Keep output files if the test failed
143+
fail("The VariationDiff in file " + testCase.input + " didn't parse correctly. "
144+
+ "Expected the content of " + testCase.expected + " but got the content of " + actualPath + ". ");
145+
}
146+
}
147+
}
148+
91149
}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
*_actual.lg
2+
/tex/
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
+package org.argouml.application;
2+
+
3+
+import javax.swing.UIManager;
4+
+//#if defined(LOGGING)
5+
+import org.apache.log4j.BasicConfigurator;
6+
+import org.apache.log4j.Level;
7+
+import org.apache.log4j.Logger;
8+
+//#endif
9+
+import org.argouml.application.api.CommandLineInterface;
10+
+import org.argouml.application.security.ArgoAwtExceptionHandler;
11+
+//#if defined(COGNITIVE)
12+
+//@#$LPS-COGNITIVE:GranularityType:Import
13+
+import org.argouml.cognitive.AbstractCognitiveTranslator;
14+
+import org.argouml.cognitive.ui.ToDoPane;
15+
+//#endif
16+
+import org.argouml.ui.cmd.InitUiCmdSubsystem;
17+
+import org.argouml.ui.cmd.PrintManager;
18+
+//#if defined(COGNITIVE) and defined(DEPLOYMENTDIAGRAM)
19+
+import org.argouml.uml.diagram.activity.ui.InitActivityDiagram;
20+
+//#endif
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
v 16 NON;IF;(old: -1, diff: -1, new: -1);(old: -1, diff: -1, new: -1);True
2+
v 131 ADD;ARTIFACT;(old: -1, diff: 1, new: 1);(old: -1, diff: 2, new: 2);;package org.argouml.application;
3+
v 195 ADD;ARTIFACT;(old: -1, diff: 2, new: 2);(old: -1, diff: 3, new: 3);;
4+
v 259 ADD;ARTIFACT;(old: -1, diff: 3, new: 3);(old: -1, diff: 4, new: 4);;import javax.swing.UIManager;
5+
v 320 ADD;IF;(old: -1, diff: 4, new: 4);(old: -1, diff: 8, new: 8);DEFINED_LOGGING;//#if defined(LOGGING)
6+
v 387 ADD;ARTIFACT;(old: -1, diff: 5, new: 5);(old: -1, diff: 6, new: 6);;import org.apache.log4j.BasicConfigurator;
7+
v 451 ADD;ARTIFACT;(old: -1, diff: 6, new: 6);(old: -1, diff: 7, new: 7);;import org.apache.log4j.Level;
8+
v 515 ADD;ARTIFACT;(old: -1, diff: 7, new: 7);(old: -1, diff: 8, new: 8);;import org.apache.log4j.Logger;
9+
v 643 ADD;ARTIFACT;(old: -1, diff: 9, new: 9);(old: -1, diff: 10, new: 10);;import org.argouml.application.api.CommandLineInterface;
10+
v 707 ADD;ARTIFACT;(old: -1, diff: 10, new: 10);(old: -1, diff: 11, new: 11);;import org.argouml.application.security.ArgoAwtExceptionHandler;
11+
v 768 ADD;IF;(old: -1, diff: 11, new: 11);(old: -1, diff: 15, new: 15);DEFINED_COGNITIVE;//#if defined(COGNITIVE)
12+
v 835 ADD;ARTIFACT;(old: -1, diff: 12, new: 12);(old: -1, diff: 13, new: 13);;//@#$LPS-COGNITIVE:GranularityType:Import
13+
v 899 ADD;ARTIFACT;(old: -1, diff: 13, new: 13);(old: -1, diff: 14, new: 14);;import org.argouml.cognitive.AbstractCognitiveTranslator;
14+
v 963 ADD;ARTIFACT;(old: -1, diff: 14, new: 14);(old: -1, diff: 15, new: 15);;import org.argouml.cognitive.ui.ToDoPane;
15+
v 1091 ADD;ARTIFACT;(old: -1, diff: 16, new: 16);(old: -1, diff: 17, new: 17);;import org.argouml.ui.cmd.InitUiCmdSubsystem;
16+
v 1155 ADD;ARTIFACT;(old: -1, diff: 17, new: 17);(old: -1, diff: 18, new: 18);;import org.argouml.ui.cmd.PrintManager;
17+
v 1216 ADD;IF;(old: -1, diff: 18, new: 18);(old: -1, diff: 20, new: 20);DEFINED_COGNITIVE & DEFINED_DEPLOYMENTDIAGRAM;//#if defined(COGNITIVE) and defined(DEPLOYMENTDIAGRAM)
18+
v 1283 ADD;ARTIFACT;(old: -1, diff: 19, new: 19);(old: -1, diff: 20, new: 20);;import org.argouml.uml.diagram.activity.ui.InitActivityDiagram;
19+
e 131 16 a;-1,0
20+
e 195 16 a;-1,1
21+
e 259 16 a;-1,2
22+
e 320 16 a;-1,3
23+
e 387 320 a;-1,0
24+
e 451 320 a;-1,1
25+
e 515 320 a;-1,2
26+
e 643 16 a;-1,4
27+
e 707 16 a;-1,5
28+
e 768 16 a;-1,6
29+
e 835 768 a;-1,0
30+
e 899 768 a;-1,1
31+
e 963 768 a;-1,2
32+
e 1091 16 a;-1,7
33+
e 1155 16 a;-1,8
34+
e 1216 16 a;-1,9
35+
e 1283 1216 a;-1,0

0 commit comments

Comments
 (0)