22import java .nio .file .Files ;
33import java .nio .file .Path ;
44import java .util .stream .Stream ;
5- import org .junit .jupiter .api .Test ;
65import org .junit .jupiter .params .ParameterizedTest ;
76import org .junit .jupiter .params .provider .MethodSource ;
87import org .variantsync .diffdetective .diff .result .DiffParseException ;
1716import static org .variantsync .diffdetective .experiments .thesis_es .UnparseAnalysis .removeWhitespace ;
1817
1918public 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 ));
0 commit comments