1- import static org .junit .jupiter .api .Assertions .assertEquals ;
2- import static org .junit .jupiter .api .Assertions .assertNotNull ;
3-
1+ import java .io .IOException ;
42import java .nio .file .Files ;
53import java .nio .file .Path ;
64import java .util .stream .Stream ;
7-
8- import org .junit .jupiter .api . Disabled ;
9- import org .junit . jupiter . api . Test ;
5+ import org . junit . jupiter . params . ParameterizedTest ;
6+ import org .junit .jupiter .params . provider . MethodSource ;
7+ import org .variantsync . diffdetective . diff . result . DiffParseException ;
108import org .variantsync .diffdetective .variation .DiffLinesLabel ;
9+ import org .variantsync .diffdetective .variation .diff .Time ;
10+ import org .variantsync .diffdetective .variation .diff .VariationDiff ;
11+ import org .variantsync .diffdetective .variation .diff .parse .VariationDiffParseOptions ;
1112import org .variantsync .diffdetective .variation .tree .VariationTree ;
1213import org .variantsync .diffdetective .variation .VariationUnparser ;
1314
1415public class VariationUnparserTest {
15- private final static Path testDir = Constants .RESOURCE_DIR .resolve ("unparser" );
16+ private final static Path testDirTree = Constants .RESOURCE_DIR .resolve ("unparser" );
1617
17- private final static String testCaseSuffix = ".txt" ;
18+ private final static Path testDirDiff = Constants .RESOURCE_DIR .resolve ("diffs" ).resolve ("parser" );
19+ private final static String testCaseSuffixTree = ".txt" ;
1820
19- protected static Stream <Path > findTestCases (Path dir ) {
21+ private final static String testCaseSuffixDiff = ".diff" ;
22+
23+ protected static Stream <Path > findTestCases (Path dir , String testCaseSuffix ) {
2024 try {
2125 return Files
2226 .list (dir )
@@ -27,51 +31,118 @@ protected static Stream<Path> findTestCases(Path dir) {
2731 return null ;
2832 }
2933
30- @ Disabled
31- @ Test
32- public void tests () {
33- findTestCases (testDir ).forEach (this ::test );
34+ public static Stream <Path > testsTree () throws IOException {
35+ return findTestCases (testDirTree , testCaseSuffixTree );
3436 }
3537
36- @ Test
37- public void teststest () {
38- Path path = testDir .resolve ("test2.txt" );
39- String temp = "b" ;
40- VariationTree <DiffLinesLabel > tree = null ;
38+ public static Stream <Path > testsDiff () throws IOException {
39+ return findTestCases (testDirDiff , testCaseSuffixDiff );
40+ }
41+
42+ @ ParameterizedTest
43+ @ MethodSource ("testsTree" )
44+ public void testTree (Path basename ) throws IOException , DiffParseException {
45+ testCaseTree (basename );
46+ }
47+
48+ @ ParameterizedTest
49+ @ MethodSource ("testsDiff" )
50+ public void testDiff (Path basename ) throws IOException , DiffParseException {
51+ testCaseDiff (basename );
52+ }
53+
54+ public static void testCaseTree (Path testCasePath ) {
55+ String temp = "" ;
4156 try {
42- tree = VariationTree .fromFile (path );
43- temp = VariationUnparser .variationTreeUnparser (tree );
57+ temp = Files .readString (testCasePath );
4458 } catch (Exception e ) {
4559 e .printStackTrace ();
4660 }
47- assertNotNull (tree .root ().getChildren ().get (0 ).getEndIf ());
48- }
49-
50- public void test (Path basename ) {
51- testCase (basename );
61+ System .out .println (testCasePath );
62+ temp = temp .replaceAll ("\\ r\\ n" , "\n " );
63+ String unparse1 = parseUnparseTree (testCasePath , new VariationDiffParseOptions (false , false ));
64+ String unparse2 = parseUnparseTree (testCasePath , new VariationDiffParseOptions (false , true ));
65+ String unparse3 = parseUnparseTree (testCasePath , new VariationDiffParseOptions (true , false ));
66+ String unparse4 = parseUnparseTree (testCasePath , new VariationDiffParseOptions (true , true ));
67+ System .out .println (temp .equals (unparse1 ) + " " + temp .equals (unparse2 ) + " " + temp .equals (unparse3 ) + " "
68+ + temp .equals (unparse4 ));
69+ temp = removeWhitespace (temp );
70+ unparse1 = removeWhitespace (unparse1 );
71+ unparse2 = removeWhitespace (unparse2 );
72+ unparse3 = removeWhitespace (unparse3 );
73+ unparse4 = removeWhitespace (unparse4 );
74+ System .out .println (temp .equals (unparse1 ) + " " + temp .equals (unparse2 ) + " " + temp .equals (unparse3 ) + " "
75+ + temp .equals (unparse4 ));
5276 }
5377
54- public static void testCase (Path testCasePath ) {
78+ public static void testCaseDiff (Path testCasePath ) {
5579 String temp = "" ;
5680 try {
5781 temp = Files .readString (testCasePath );
5882 } catch (Exception e ) {
5983 e .printStackTrace ();
6084 }
85+ System .out .println (testCasePath );
6186 temp = temp .replaceAll ("\\ r\\ n" , "\n " );
62- String unparse = parseUnparse (testCasePath );
63- assertEquals (temp , unparse );
87+ String unparse1 = parseUnparseDiff (testCasePath , new VariationDiffParseOptions (false , false ));
88+ String unparse2 = parseUnparseDiff (testCasePath , new VariationDiffParseOptions (false , true ));
89+ String unparse3 = parseUnparseDiff (testCasePath , new VariationDiffParseOptions (true , false ));
90+ String unparse4 = parseUnparseDiff (testCasePath , new VariationDiffParseOptions (true , true ));
91+ System .out .println (temp .equals (unparse1 ) + " " + temp .equals (unparse2 ) + " " + temp .equals (unparse3 ) + " "
92+ + temp .equals (unparse4 ));
93+ String temp1 = VariationUnparser .undiff (temp , Time .BEFORE );
94+ String temp2 = VariationUnparser .undiff (temp , Time .AFTER );
95+ String unparse11 = VariationUnparser .undiff (unparse1 , Time .BEFORE );
96+ String unparse12 = VariationUnparser .undiff (unparse1 , Time .AFTER );
97+ String unparse21 = VariationUnparser .undiff (unparse2 , Time .BEFORE );
98+ String unparse22 = VariationUnparser .undiff (unparse2 , Time .AFTER );
99+ String unparse31 = VariationUnparser .undiff (unparse3 , Time .BEFORE );
100+ String unparse32 = VariationUnparser .undiff (unparse3 , Time .AFTER );
101+ String unparse41 = VariationUnparser .undiff (unparse1 , Time .BEFORE );
102+ String unparse42 = VariationUnparser .undiff (unparse1 , Time .AFTER );
103+ System .out .println (temp1 .equals (unparse11 ) + " " + temp2 .equals (unparse12 ) + " " + temp1 .equals (unparse21 ) + " "
104+ + temp2 .equals (unparse22 ) + " " + temp1 .equals (unparse31 ) + " " + temp2 .equals (unparse32 ) + " "
105+ + temp1 .equals (unparse41 ) + " " + temp2 .equals (unparse42 ));
106+ System .out .println (removeWhitespace (temp1 ).equals (removeWhitespace (unparse11 )) + " "
107+ + removeWhitespace (temp2 ).equals (removeWhitespace (unparse12 )) + " "
108+ + removeWhitespace (temp1 ).equals (removeWhitespace (unparse21 )) + " "
109+ + removeWhitespace (temp2 ).equals (removeWhitespace (unparse22 )) + " "
110+ + removeWhitespace (temp1 ).equals (removeWhitespace (unparse31 )) + " "
111+ + removeWhitespace (temp2 ).equals (removeWhitespace (unparse32 )) + " "
112+ + removeWhitespace (temp1 ).equals (removeWhitespace (unparse41 )) + " "
113+ + removeWhitespace (temp2 ).equals (removeWhitespace (unparse42 )));
114+ temp = removeWhitespace (temp );
115+ unparse1 = removeWhitespace (unparse1 );
116+ unparse2 = removeWhitespace (unparse2 );
117+ unparse3 = removeWhitespace (unparse3 );
118+ unparse4 = removeWhitespace (unparse4 );
119+ System .out .println (temp .equals (unparse1 ) + " " + temp .equals (unparse2 ) + " " + temp .equals (unparse3 ) + " "
120+ + temp .equals (unparse4 ));
64121 }
65122
66- public static String parseUnparse (Path path ) {
123+ public static String parseUnparseTree (Path path , VariationDiffParseOptions option ) {
67124 String temp = "b" ;
68125 try {
69- VariationTree <DiffLinesLabel > tree = VariationTree .fromFile (path );
126+ VariationTree <DiffLinesLabel > tree = VariationTree .fromFile (path , option );
70127 temp = VariationUnparser .variationTreeUnparser (tree );
71128 } catch (Exception e ) {
72129 e .printStackTrace ();
73130 }
74131 return temp ;
75132 }
76133
134+ public static String parseUnparseDiff (Path path , VariationDiffParseOptions option ) {
135+ String temp = "b" ;
136+ try {
137+ VariationDiff <DiffLinesLabel > diff = VariationDiff .fromFile (path , option );
138+ temp = VariationUnparser .variationDiffUnparser (diff );
139+ } catch (Exception e ) {
140+ e .printStackTrace ();
141+ }
142+ return temp ;
143+ }
144+
145+ public static String removeWhitespace (String string ) {
146+ return string .replaceAll ("\\ s+" , "" );
147+ }
77148}
0 commit comments