1+ import org .apache .commons .io .IOUtils ;
12import org .junit .jupiter .params .ParameterizedTest ;
23import org .junit .jupiter .params .provider .MethodSource ;
4+ import org .variantsync .diffdetective .diff .result .DiffParseException ;
35import org .variantsync .diffdetective .error .UnparseableFormulaException ;
6+ import org .variantsync .diffdetective .feature .PreprocessorAnnotationParser ;
47import 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 ;
621import java .util .List ;
722
823import static org .junit .jupiter .api .Assertions .assertEquals ;
924import 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/
1228public 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}
0 commit comments