|
| 1 | +import static org.junit.jupiter.api.Assertions.assertEquals; |
| 2 | +import static org.junit.jupiter.api.Assertions.assertNotNull; |
| 3 | + |
| 4 | +import java.nio.file.Files; |
| 5 | +import java.nio.file.Path; |
| 6 | +import java.util.stream.Stream; |
| 7 | + |
| 8 | +import org.junit.jupiter.api.Disabled; |
| 9 | +import org.junit.jupiter.api.Test; |
| 10 | +import org.variantsync.diffdetective.variation.DiffLinesLabel; |
| 11 | +import org.variantsync.diffdetective.variation.tree.VariationTree; |
| 12 | +import org.variantsync.diffdetective.variation.VariationUnparser; |
| 13 | + |
| 14 | +public class VariationUnparserTest { |
| 15 | + private final static Path testDir = Constants.RESOURCE_DIR.resolve("unparser"); |
| 16 | + |
| 17 | + private final static String testCaseSuffix = ".txt"; |
| 18 | + |
| 19 | + protected static Stream<Path> findTestCases(Path dir) { |
| 20 | + try { |
| 21 | + return Files |
| 22 | + .list(dir) |
| 23 | + .filter(filename -> filename.getFileName().toString().endsWith(testCaseSuffix)); |
| 24 | + } catch (Exception e) { |
| 25 | + e.printStackTrace(); |
| 26 | + } |
| 27 | + return null; |
| 28 | + } |
| 29 | + |
| 30 | + @Disabled |
| 31 | + @Test |
| 32 | + public void tests() { |
| 33 | + findTestCases(testDir).forEach(this::test); |
| 34 | + } |
| 35 | + |
| 36 | + @Disabled |
| 37 | + @Test |
| 38 | + public void teststest() { |
| 39 | + Path path = testDir.resolve("test2.txt"); |
| 40 | + String temp = "b"; |
| 41 | + VariationTree<DiffLinesLabel> tree = null; |
| 42 | + try { |
| 43 | + tree = VariationTree.fromFile(path); |
| 44 | + temp = VariationUnparser.variationTreeUnparser(tree); |
| 45 | + } catch (Exception e) { |
| 46 | + e.printStackTrace(); |
| 47 | + } |
| 48 | + assertNotNull(tree.root().getChildren().get(0).getEndIf()); |
| 49 | + } |
| 50 | + |
| 51 | + public void test(Path basename) { |
| 52 | + testCase(basename); |
| 53 | + } |
| 54 | + |
| 55 | + public static void testCase(Path testCasePath) { |
| 56 | + String temp = ""; |
| 57 | + try { |
| 58 | + temp = Files.readString(testCasePath); |
| 59 | + } catch (Exception e) { |
| 60 | + e.printStackTrace(); |
| 61 | + } |
| 62 | + temp = temp.replaceAll("\\r\\n", "\n"); |
| 63 | + String unparse = parseUnparse(testCasePath); |
| 64 | + assertEquals(temp, unparse); |
| 65 | + } |
| 66 | + |
| 67 | + public static String parseUnparse(Path path) { |
| 68 | + String temp = "b"; |
| 69 | + try { |
| 70 | + VariationTree<DiffLinesLabel> tree = VariationTree.fromFile(path); |
| 71 | + temp = VariationUnparser.variationTreeUnparser(tree); |
| 72 | + } catch (Exception e) { |
| 73 | + e.printStackTrace(); |
| 74 | + } |
| 75 | + return temp; |
| 76 | + } |
| 77 | + |
| 78 | +} |
0 commit comments