JavaTXCompilerInJavaTXNoMaven/tests/syntaxtreegenerator/TestComplete.java
2024-05-27 22:38:59 +02:00

871 lines
42 KiB
Java

package syntaxtreegenerator;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import java.io.File;
import java.io.FileFilter;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.ObjectOutputStream;
import java.util.ArrayList;
import java.util.HashMap;
import org.junit.BeforeClass;
import org.junit.Test;
import de.dhbwstuttgart.core.JavaTXCompiler;
import de.dhbwstuttgart.exceptions.NotImplementedException;
import de.dhbwstuttgart.syntaxtree.SourceFile;
import de.dhbwstuttgart.syntaxtree.visual.ASTPrinter;
/**
* Unit-Tests für den 'SyntaxTreeGenerator' aus dem Package 'parser' nach Vorbild der Klasse 'TestComplete' aus dem Test-Package 'targetast'
*/
public class TestComplete {
private static HashMap<String, File[]> javFiles = new HashMap<>();
@BeforeClass
public static void setUp() {
final String testFileDirectory = "resources/bytecode/javFiles/";
final String expectedASTDirectory = "resources/syntaxtreegenerator/";
File dir = new File(testFileDirectory);
for (File f : dir.listFiles(new JavFilter())) {
String basefilename = f.getName().replace(".jav", "");
javFiles.put(basefilename, new File[] { f, new File(expectedASTDirectory + basefilename + ".ast") });
}
}
@Test
public void applyLambdaTest() {
try {
FileInputStream fileIn = new FileInputStream(javFiles.get("applyLambda")[1]);
String expectedAST = new String(fileIn.readAllBytes());
fileIn.close();
expectedAST = expectedAST.replaceAll("TPH [A-Z]+", "TPH");
File srcfile = javFiles.get("applyLambda")[0];
JavaTXCompiler compiler = new JavaTXCompiler(srcfile);
String resultingAST = new String(ASTPrinter.print(compiler.sourceFiles.get(srcfile)));
resultingAST = resultingAST.replaceAll("TPH [A-Z]+", "TPH");
System.out.println("Expected:\n" + new String(expectedAST));
System.out.println("Result:\n" + new String(resultingAST));
assertEquals("Comparing expected and resulting AST for applyLambda.jav", expectedAST, resultingAST);
} catch (Exception exc) {
exc.printStackTrace();
fail("An error occured while generating the AST for applyLambda.jav");
}
}
@Test
public void binaryInMethTest() {
try {
FileInputStream fileIn = new FileInputStream(javFiles.get("BinaryInMeth")[1]);
String expectedAST = new String(fileIn.readAllBytes());
fileIn.close();
expectedAST = expectedAST.replaceAll("TPH [A-Z]+", "TPH");
File srcfile = javFiles.get("BinaryInMeth")[0];
JavaTXCompiler compiler = new JavaTXCompiler(srcfile);
String resultingAST = new String(ASTPrinter.print(compiler.sourceFiles.get(srcfile)));
resultingAST = resultingAST.replaceAll("TPH [A-Z]+", "TPH");
System.out.println("Expected:\n" + new String(expectedAST));
System.out.println("Result:\n" + new String(resultingAST));
assertEquals("Comparing expected and resulting AST for BinaryInMeth.jav", expectedAST, resultingAST);
} catch (Exception exc) {
exc.printStackTrace();
fail("An error occured while generating the AST for BinaryInMeth.jav");
}
}
@Test
public void classGenLamTest() {
try {
FileInputStream fileIn = new FileInputStream(javFiles.get("ClassGenLam")[1]);
String expectedAST = new String(fileIn.readAllBytes());
fileIn.close();
expectedAST = expectedAST.replaceAll("TPH [A-Z]+", "TPH");
File srcfile = javFiles.get("ClassGenLam")[0];
JavaTXCompiler compiler = new JavaTXCompiler(srcfile);
String resultingAST = new String(ASTPrinter.print(compiler.sourceFiles.get(srcfile)));
resultingAST = resultingAST.replaceAll("TPH [A-Z]+", "TPH");
System.out.println("Expected:\n" + new String(expectedAST));
System.out.println("Result:\n" + new String(resultingAST));
assertEquals("Comparing expected and resulting AST for ClassGenLam.jav", expectedAST, resultingAST);
} catch (Exception exc) {
exc.printStackTrace();
fail("An error occured while generating the AST for ClassGenLam.jav");
}
}
@Test
public void facTest() {
try {
FileInputStream fileIn = new FileInputStream(javFiles.get("Fac")[1]);
String expectedAST = new String(fileIn.readAllBytes());
fileIn.close();
expectedAST = expectedAST.replaceAll("TPH [A-Z]+", "TPH");
File srcfile = javFiles.get("Fac")[0];
JavaTXCompiler compiler = new JavaTXCompiler(srcfile);
String resultingAST = new String(ASTPrinter.print(compiler.sourceFiles.get(srcfile)));
resultingAST = resultingAST.replaceAll("TPH [A-Z]+", "TPH");
System.out.println("Expected:\n" + new String(expectedAST));
System.out.println("Result:\n" + new String(resultingAST));
assertEquals("Comparing expected and resulting AST for Fac.jav", expectedAST, resultingAST);
} catch (Exception exc) {
exc.printStackTrace();
fail("An error occured while generating the AST for Fac.jav");
}
}
@Test
public void facultyTest() {
try {
FileInputStream fileIn = new FileInputStream(javFiles.get("Faculty")[1]);
String expectedAST = new String(fileIn.readAllBytes());
fileIn.close();
expectedAST = expectedAST.replaceAll("TPH [A-Z]+", "TPH");
File srcfile = javFiles.get("Faculty")[0];
JavaTXCompiler compiler = new JavaTXCompiler(srcfile);
String resultingAST = new String(ASTPrinter.print(compiler.sourceFiles.get(srcfile)));
resultingAST = resultingAST.replaceAll("TPH [A-Z]+", "TPH");
System.out.println("Expected:\n" + new String(expectedAST));
System.out.println("Result:\n" + new String(resultingAST));
assertEquals("Comparing expected and resulting AST for Faculty.jav", expectedAST, resultingAST);
} catch (Exception exc) {
exc.printStackTrace();
fail("An error occured while generating the AST for Faculty.jav");
}
}
@Test
public void fieldTest() {
try {
FileInputStream fileIn = new FileInputStream(javFiles.get("Field")[1]);
String expectedAST = new String(fileIn.readAllBytes());
fileIn.close();
expectedAST = expectedAST.replaceAll("TPH [A-Z]+", "TPH");
File srcfile = javFiles.get("Field")[0];
JavaTXCompiler compiler = new JavaTXCompiler(srcfile);
String resultingAST = new String(ASTPrinter.print(compiler.sourceFiles.get(srcfile)));
resultingAST = resultingAST.replaceAll("TPH [A-Z]+", "TPH");
System.out.println("Expected:\n" + new String(expectedAST));
System.out.println("Result:\n" + new String(resultingAST));
assertEquals("Comparing expected and resulting AST for Field.jav", expectedAST, resultingAST);
} catch (Exception exc) {
exc.printStackTrace();
fail("An error occured while generating the AST for Field.jav");
}
}
@Test
public void fieldTph2Test() {
try {
FileInputStream fileIn = new FileInputStream(javFiles.get("FieldTph2")[1]);
String expectedAST = new String(fileIn.readAllBytes());
fileIn.close();
expectedAST = expectedAST.replaceAll("TPH [A-Z]+", "TPH");
File srcfile = javFiles.get("FieldTph2")[0];
JavaTXCompiler compiler = new JavaTXCompiler(srcfile);
String resultingAST = new String(ASTPrinter.print(compiler.sourceFiles.get(srcfile)));
resultingAST = resultingAST.replaceAll("TPH [A-Z]+", "TPH");
System.out.println("Expected:\n" + new String(expectedAST));
System.out.println("Result:\n" + new String(resultingAST));
assertEquals("Comparing expected and resulting AST for FieldTph2.jav", expectedAST, resultingAST);
} catch (Exception exc) {
exc.printStackTrace();
fail("An error occured while generating the AST for FieldTph2.jav");
}
}
@Test
public void fieldTphConsMethTest() {
try {
FileInputStream fileIn = new FileInputStream(javFiles.get("FieldTphConsMeth")[1]);
String expectedAST = new String(fileIn.readAllBytes());
fileIn.close();
expectedAST = expectedAST.replaceAll("TPH [A-Z]+", "TPH");
File srcfile = javFiles.get("FieldTphConsMeth")[0];
JavaTXCompiler compiler = new JavaTXCompiler(srcfile);
String resultingAST = new String(ASTPrinter.print(compiler.sourceFiles.get(srcfile)));
resultingAST = resultingAST.replaceAll("TPH [A-Z]+", "TPH");
System.out.println("Expected:\n" + new String(expectedAST));
System.out.println("Result:\n" + new String(resultingAST));
assertEquals("Comparing expected and resulting AST for FieldTphConsMeth.jav", expectedAST, resultingAST);
} catch (Exception exc) {
exc.printStackTrace();
fail("An error occured while generating the AST for FieldTphConsMeth.jav");
}
}
@Test
public void fieldTphMMethTest() {
try {
FileInputStream fileIn = new FileInputStream(javFiles.get("FieldTphMMeth")[1]);
String expectedAST = new String(fileIn.readAllBytes());
fileIn.close();
expectedAST = expectedAST.replaceAll("TPH [A-Z]+", "TPH");
File srcfile = javFiles.get("FieldTphMMeth")[0];
JavaTXCompiler compiler = new JavaTXCompiler(srcfile);
String resultingAST = new String(ASTPrinter.print(compiler.sourceFiles.get(srcfile)));
resultingAST = resultingAST.replaceAll("TPH [A-Z]+", "TPH");
System.out.println("Expected:\n" + new String(expectedAST));
System.out.println("Result:\n" + new String(resultingAST));
assertEquals("Comparing expected and resulting AST for FieldTphMMeth.jav", expectedAST, resultingAST);
} catch (Exception exc) {
exc.printStackTrace();
fail("An error occured while generating the AST for FieldTphMMeth.jav");
}
}
@Test
public void genTest() {
try {
FileInputStream fileIn = new FileInputStream(javFiles.get("Gen")[1]);
String expectedAST = new String(fileIn.readAllBytes());
fileIn.close();
expectedAST = expectedAST.replaceAll("TPH [A-Z]+", "TPH");
File srcfile = javFiles.get("Gen")[0];
JavaTXCompiler compiler = new JavaTXCompiler(srcfile);
String resultingAST = new String(ASTPrinter.print(compiler.sourceFiles.get(srcfile)));
resultingAST = resultingAST.replaceAll("TPH [A-Z]+", "TPH");
System.out.println("Expected:\n" + new String(expectedAST));
System.out.println("Result:\n" + new String(resultingAST));
assertEquals("Comparing expected and resulting AST for Gen.jav", expectedAST, resultingAST);
} catch (Exception exc) {
exc.printStackTrace();
fail("An error occured while generating the AST for Gen.jav");
}
}
@Test
public void idTest() {
try {
FileInputStream fileIn = new FileInputStream(javFiles.get("Id")[1]);
String expectedAST = new String(fileIn.readAllBytes());
fileIn.close();
expectedAST = expectedAST.replaceAll("TPH [A-Z]+", "TPH");
File srcfile = javFiles.get("Id")[0];
JavaTXCompiler compiler = new JavaTXCompiler(srcfile);
String resultingAST = new String(ASTPrinter.print(compiler.sourceFiles.get(srcfile)));
resultingAST = resultingAST.replaceAll("TPH [A-Z]+", "TPH");
System.out.println("Expected:\n" + new String(expectedAST));
System.out.println("Result:\n" + new String(resultingAST));
assertEquals("Comparing expected and resulting AST for Id.jav", expectedAST, resultingAST);
} catch (Exception exc) {
exc.printStackTrace();
fail("An error occured while generating the AST for Id.jav");
}
}
@Test
public void infTest() {
try {
FileInputStream fileIn = new FileInputStream(javFiles.get("Inf")[1]);
String expectedAST = new String(fileIn.readAllBytes());
fileIn.close();
expectedAST = expectedAST.replaceAll("TPH [A-Z]+", "TPH");
File srcfile = javFiles.get("Inf")[0];
JavaTXCompiler compiler = new JavaTXCompiler(srcfile);
String resultingAST = new String(ASTPrinter.print(compiler.sourceFiles.get(srcfile)));
resultingAST = resultingAST.replaceAll("TPH [A-Z]+", "TPH");
System.out.println("Expected:\n" + new String(expectedAST));
System.out.println("Result:\n" + new String(resultingAST));
assertEquals("Comparing expected and resulting AST for Inf.jav", expectedAST, resultingAST);
} catch (Exception exc) {
exc.printStackTrace();
fail("An error occured while generating the AST for Inf.jav");
}
}
@Test
public void kompTphTest() {
try {
FileInputStream fileIn = new FileInputStream(javFiles.get("KompTph")[1]);
String expectedAST = new String(fileIn.readAllBytes());
fileIn.close();
expectedAST = expectedAST.replaceAll("TPH [A-Z]+", "TPH");
File srcfile = javFiles.get("KompTph")[0];
JavaTXCompiler compiler = new JavaTXCompiler(srcfile);
String resultingAST = new String(ASTPrinter.print(compiler.sourceFiles.get(srcfile)));
resultingAST = resultingAST.replaceAll("TPH [A-Z]+", "TPH");
System.out.println("Expected:\n" + new String(expectedAST));
System.out.println("Result:\n" + new String(resultingAST));
assertEquals("Comparing expected and resulting AST for KompTph.jav", expectedAST, resultingAST);
} catch (Exception exc) {
exc.printStackTrace();
fail("An error occured while generating the AST for KompTph.jav");
}
}
@Test
public void lambdaCaptureTest() {
try {
FileInputStream fileIn = new FileInputStream(javFiles.get("LambdaCapture")[1]);
String expectedAST = new String(fileIn.readAllBytes());
fileIn.close();
expectedAST = expectedAST.replaceAll("TPH [A-Z]+", "TPH");
File srcfile = javFiles.get("LambdaCapture")[0];
JavaTXCompiler compiler = new JavaTXCompiler(srcfile);
String resultingAST = new String(ASTPrinter.print(compiler.sourceFiles.get(srcfile)));
resultingAST = resultingAST.replaceAll("TPH [A-Z]+", "TPH");
System.out.println("Expected:\n" + new String(expectedAST));
System.out.println("Result:\n" + new String(resultingAST));
assertEquals("Comparing expected and resulting AST for LambdaCapture.jav", expectedAST, resultingAST);
} catch (Exception exc) {
exc.printStackTrace();
fail("An error occured while generating the AST for LambdaCapture.jav");
}
}
@Test
public void lambdaTest() {
try {
FileInputStream fileIn = new FileInputStream(javFiles.get("Lambda")[1]);
String expectedAST = new String(fileIn.readAllBytes());
fileIn.close();
expectedAST = expectedAST.replaceAll("TPH [A-Z]+", "TPH");
File srcfile = javFiles.get("Lambda")[0];
JavaTXCompiler compiler = new JavaTXCompiler(srcfile);
String resultingAST = new String(ASTPrinter.print(compiler.sourceFiles.get(srcfile)));
resultingAST = resultingAST.replaceAll("TPH [A-Z]+", "TPH");
System.out.println("Expected:\n" + new String(expectedAST));
System.out.println("Result:\n" + new String(resultingAST));
assertEquals("Comparing expected and resulting AST for Lambda.jav", expectedAST, resultingAST);
} catch (Exception exc) {
exc.printStackTrace();
fail("An error occured while generating the AST for Lambda.jav");
}
}
@Test
public void mathStrucIntegerTest() {
try {
FileInputStream fileIn = new FileInputStream(javFiles.get("mathStrucInteger")[1]);
String expectedAST = new String(fileIn.readAllBytes());
fileIn.close();
expectedAST = expectedAST.replaceAll("TPH [A-Z]+", "TPH");
File srcfile = javFiles.get("mathStrucInteger")[0];
JavaTXCompiler compiler = new JavaTXCompiler(srcfile);
String resultingAST = new String(ASTPrinter.print(compiler.sourceFiles.get(srcfile)));
resultingAST = resultingAST.replaceAll("TPH [A-Z]+", "TPH");
System.out.println("Expected:\n" + new String(expectedAST));
System.out.println("Result:\n" + new String(resultingAST));
assertEquals("Comparing expected and resulting AST for mathStrucInteger.jav", expectedAST, resultingAST);
} catch (Exception exc) {
exc.printStackTrace();
assertTrue("An error occured while generating the AST for mathStrucInteger.jav", exc instanceof NotImplementedException);
}
}
@Test
public void mathStrucTest() {
try {
FileInputStream fileIn = new FileInputStream(javFiles.get("mathStruc")[1]);
String expectedAST = new String(fileIn.readAllBytes());
fileIn.close();
expectedAST = expectedAST.replaceAll("TPH [A-Z]+", "TPH");
File srcfile = javFiles.get("mathStruc")[0];
JavaTXCompiler compiler = new JavaTXCompiler(srcfile);
String resultingAST = new String(ASTPrinter.print(compiler.sourceFiles.get(srcfile)));
resultingAST = resultingAST.replaceAll("TPH [A-Z]+", "TPH");
System.out.println("Expected:\n" + new String(expectedAST));
System.out.println("Result:\n" + new String(resultingAST));
assertEquals("Comparing expected and resulting AST for mathStruc.jav", expectedAST, resultingAST);
} catch (Exception exc) {
exc.printStackTrace();
fail("An error occured while generating the AST for mathStruc.jav");
}
}
@Test
public void matrixOPTest() {
try {
FileInputStream fileIn = new FileInputStream(javFiles.get("MatrixOP")[1]);
String expectedAST = new String(fileIn.readAllBytes());
fileIn.close();
expectedAST = expectedAST.replaceAll("TPH [A-Z]+", "TPH");
File srcfile = javFiles.get("MatrixOP")[0];
JavaTXCompiler compiler = new JavaTXCompiler(srcfile);
String resultingAST = new String(ASTPrinter.print(compiler.sourceFiles.get(srcfile)));
resultingAST = resultingAST.replaceAll("TPH [A-Z]+", "TPH");
System.out.println("Expected:\n" + new String(expectedAST));
System.out.println("Result:\n" + new String(resultingAST));
assertEquals("Comparing expected and resulting AST for MatrixOP.jav", expectedAST, resultingAST);
} catch (Exception exc) {
exc.printStackTrace();
fail("An error occured while generating the AST for MatrixOP.jav");
}
}
@Test
public void matrixTest() {
try {
FileInputStream fileIn = new FileInputStream(javFiles.get("Matrix")[1]);
String expectedAST = new String(fileIn.readAllBytes());
fileIn.close();
expectedAST = expectedAST.replaceAll("TPH [A-Z]+", "TPH");
File srcfile = javFiles.get("Matrix")[0];
JavaTXCompiler compiler = new JavaTXCompiler(srcfile);
String resultingAST = new String(ASTPrinter.print(compiler.sourceFiles.get(srcfile)));
resultingAST = resultingAST.replaceAll("TPH [A-Z]+", "TPH");
System.out.println("Expected:\n" + new String(expectedAST));
System.out.println("Result:\n" + new String(resultingAST));
assertEquals("Comparing expected and resulting AST for Matrix.jav", expectedAST, resultingAST);
} catch (Exception exc) {
exc.printStackTrace();
fail("An error occured while generating the AST for Matrix.jav");
}
}
@Test
public void mergeTest() {
try {
FileInputStream fileIn = new FileInputStream(javFiles.get("Merge")[1]);
String expectedAST = new String(fileIn.readAllBytes());
fileIn.close();
expectedAST = expectedAST.replaceAll("TPH [A-Z]+", "TPH");
File srcfile = javFiles.get("Merge")[0];
JavaTXCompiler compiler = new JavaTXCompiler(srcfile);
String resultingAST = new String(ASTPrinter.print(compiler.sourceFiles.get(srcfile)));
resultingAST = resultingAST.replaceAll("TPH [A-Z]+", "TPH");
System.out.println("Expected:\n" + new String(expectedAST));
System.out.println("Result:\n" + new String(resultingAST));
assertEquals("Comparing expected and resulting AST for Merge.jav", expectedAST, resultingAST);
} catch (Exception exc) {
exc.printStackTrace();
fail("An error occured while generating the AST for Merge.jav");
}
}
@Test
public void overloadingSortingTest() {
try {
FileInputStream fileIn = new FileInputStream(javFiles.get("Sorting")[1]);
String expectedAST = new String(fileIn.readAllBytes());
fileIn.close();
expectedAST = expectedAST.replaceAll("TPH [A-Z]+", "TPH");
File srcfile = javFiles.get("Sorting")[0];
JavaTXCompiler compiler = new JavaTXCompiler(srcfile);
String resultingAST = new String(ASTPrinter.print(compiler.sourceFiles.get(srcfile)));
resultingAST = resultingAST.replaceAll("TPH [A-Z]+", "TPH");
System.out.println("Expected:\n" + new String(expectedAST));
System.out.println("Result:\n" + new String(resultingAST));
assertEquals("Comparing expected and resulting AST for Sorting.jav", expectedAST, resultingAST);
} catch (Exception exc) {
exc.printStackTrace();
fail("An error occured while generating the AST for Sorting.jav");
}
}
@Test
public void overloadingTest() {
try {
FileInputStream fileIn = new FileInputStream(javFiles.get("Overloading")[1]);
String expectedAST = new String(fileIn.readAllBytes());
fileIn.close();
expectedAST = expectedAST.replaceAll("TPH [A-Z]+", "TPH");
File srcfile = javFiles.get("Overloading")[0];
JavaTXCompiler compiler = new JavaTXCompiler(srcfile);
String resultingAST = new String(ASTPrinter.print(compiler.sourceFiles.get(srcfile)));
resultingAST = resultingAST.replaceAll("TPH [A-Z]+", "TPH");
System.out.println("Expected:\n" + new String(expectedAST));
System.out.println("Result:\n" + new String(resultingAST));
assertEquals("Comparing expected and resulting AST for Overloading.jav", expectedAST, resultingAST);
} catch (Exception exc) {
exc.printStackTrace();
fail("An error occured while generating the AST for Overloading.jav");
}
}
@Test
public void plusTest() {
try {
FileInputStream fileIn = new FileInputStream(javFiles.get("Plus")[1]);
String expectedAST = new String(fileIn.readAllBytes());
fileIn.close();
expectedAST = expectedAST.replaceAll("TPH [A-Z]+", "TPH");
File srcfile = javFiles.get("Plus")[0];
JavaTXCompiler compiler = new JavaTXCompiler(srcfile);
String resultingAST = new String(ASTPrinter.print(compiler.sourceFiles.get(srcfile)));
resultingAST = resultingAST.replaceAll("TPH [A-Z]+", "TPH");
System.out.println("Expected:\n" + new String(expectedAST));
System.out.println("Result:\n" + new String(resultingAST));
assertEquals("Comparing expected and resulting AST for Plus.jav", expectedAST, resultingAST);
} catch (Exception exc) {
exc.printStackTrace();
fail("An error occured while generating the AST for Plus.jav");
}
}
@Test
public void relOpsTest() {
try {
FileInputStream fileIn = new FileInputStream(javFiles.get("RelOps")[1]);
String expectedAST = new String(fileIn.readAllBytes());
fileIn.close();
expectedAST = expectedAST.replaceAll("TPH [A-Z]+", "TPH");
File srcfile = javFiles.get("RelOps")[0];
JavaTXCompiler compiler = new JavaTXCompiler(srcfile);
String resultingAST = new String(ASTPrinter.print(compiler.sourceFiles.get(srcfile)));
resultingAST = resultingAST.replaceAll("TPH [A-Z]+", "TPH");
System.out.println("Expected:\n" + new String(expectedAST));
System.out.println("Result:\n" + new String(resultingAST));
assertEquals("Comparing expected and resulting AST for RelOps.jav", expectedAST, resultingAST);
} catch (Exception exc) {
exc.printStackTrace();
fail("An error occured while generating the AST for RelOps.jav");
}
}
@Test
public void simpleCycleTest() {
try {
FileInputStream fileIn = new FileInputStream(javFiles.get("SimpleCycle")[1]);
String expectedAST = new String(fileIn.readAllBytes());
fileIn.close();
expectedAST = expectedAST.replaceAll("TPH [A-Z]+", "TPH");
File srcfile = javFiles.get("SimpleCycle")[0];
JavaTXCompiler compiler = new JavaTXCompiler(srcfile);
String resultingAST = new String(ASTPrinter.print(compiler.sourceFiles.get(srcfile)));
resultingAST = resultingAST.replaceAll("TPH [A-Z]+", "TPH");
System.out.println("Expected:\n" + new String(expectedAST));
System.out.println("Result:\n" + new String(resultingAST));
assertEquals("Comparing expected and resulting AST for SimpleCycle.jav", expectedAST, resultingAST);
} catch (Exception exc) {
exc.printStackTrace();
fail("An error occured while generating the AST for SimpleCycle.jav");
}
}
@Test
public void subMatTest() {
try {
FileInputStream fileIn = new FileInputStream(javFiles.get("SubMatrix")[1]);
String expectedAST = new String(fileIn.readAllBytes());
fileIn.close();
expectedAST = expectedAST.replaceAll("TPH [A-Z]+", "TPH");
File srcfile = javFiles.get("SubMatrix")[0];
JavaTXCompiler compiler = new JavaTXCompiler(srcfile);
String resultingAST = new String(ASTPrinter.print(compiler.sourceFiles.get(srcfile)));
resultingAST = resultingAST.replaceAll("TPH [A-Z]+", "TPH");
System.out.println("Expected:\n" + new String(expectedAST));
System.out.println("Result:\n" + new String(resultingAST));
assertEquals("Comparing expected and resulting AST for SubMatrix.jav", expectedAST, resultingAST);
} catch (Exception exc) {
exc.printStackTrace();
fail("An error occured while generating the AST for SubMatrix.jav");
}
}
@Test
public void tphTest() {
try {
FileInputStream fileIn = new FileInputStream(javFiles.get("Tph")[1]);
String expectedAST = new String(fileIn.readAllBytes());
fileIn.close();
expectedAST = expectedAST.replaceAll("TPH [A-Z]+", "TPH");
File srcfile = javFiles.get("Tph")[0];
JavaTXCompiler compiler = new JavaTXCompiler(srcfile);
String resultingAST = new String(ASTPrinter.print(compiler.sourceFiles.get(srcfile)));
resultingAST = resultingAST.replaceAll("TPH [A-Z]+", "TPH");
System.out.println("Expected:\n" + new String(expectedAST));
System.out.println("Result:\n" + new String(resultingAST));
assertEquals("Comparing expected and resulting AST for Tph.jav", expectedAST, resultingAST);
} catch (Exception exc) {
exc.printStackTrace();
fail("An error occured while generating the AST for Tph.jav");
}
}
@Test
public void tph2Test() {
try {
FileInputStream fileIn = new FileInputStream(javFiles.get("Tph2")[1]);
String expectedAST = new String(fileIn.readAllBytes());
fileIn.close();
expectedAST = expectedAST.replaceAll("TPH [A-Z]+", "TPH");
File srcfile = javFiles.get("Tph2")[0];
JavaTXCompiler compiler = new JavaTXCompiler(srcfile);
String resultingAST = new String(ASTPrinter.print(compiler.sourceFiles.get(srcfile)));
resultingAST = resultingAST.replaceAll("TPH [A-Z]+", "TPH");
System.out.println("Expected:\n" + new String(expectedAST));
System.out.println("Result:\n" + new String(resultingAST));
assertEquals("Comparing expected and resulting AST for Tph2.jav", expectedAST, resultingAST);
} catch (Exception exc) {
exc.printStackTrace();
fail("An error occured while generating the AST for Tph2.jav");
}
}
@Test
public void tph3Test() {
try {
FileInputStream fileIn = new FileInputStream(javFiles.get("Tph3")[1]);
String expectedAST = new String(fileIn.readAllBytes());
fileIn.close();
expectedAST = expectedAST.replaceAll("TPH [A-Z]+", "TPH");
File srcfile = javFiles.get("Tph3")[0];
JavaTXCompiler compiler = new JavaTXCompiler(srcfile);
String resultingAST = new String(ASTPrinter.print(compiler.sourceFiles.get(srcfile)));
resultingAST = resultingAST.replaceAll("TPH [A-Z]+", "TPH");
System.out.println("Expected:\n" + new String(expectedAST));
System.out.println("Result:\n" + new String(resultingAST));
assertEquals("Comparing expected and resulting AST for Tph3.jav", expectedAST, resultingAST);
} catch (Exception exc) {
exc.printStackTrace();
fail("An error occured while generating the AST for Tph3.jav");
}
}
@Test
public void tph4Test() {
try {
FileInputStream fileIn = new FileInputStream(javFiles.get("Tph4")[1]);
String expectedAST = new String(fileIn.readAllBytes());
fileIn.close();
expectedAST = expectedAST.replaceAll("TPH [A-Z]+", "TPH");
File srcfile = javFiles.get("Tph4")[0];
JavaTXCompiler compiler = new JavaTXCompiler(srcfile);
String resultingAST = new String(ASTPrinter.print(compiler.sourceFiles.get(srcfile)));
resultingAST = resultingAST.replaceAll("TPH [A-Z]+", "TPH");
System.out.println("Expected:\n" + new String(expectedAST));
System.out.println("Result:\n" + new String(resultingAST));
assertEquals("Comparing expected and resulting AST for Tph4.jav", expectedAST, resultingAST);
} catch (Exception exc) {
exc.printStackTrace();
fail("An error occured while generating the AST for Tph4.jav");
}
}
@Test
public void tph5Test() {
try {
FileInputStream fileIn = new FileInputStream(javFiles.get("Tph5")[1]);
String expectedAST = new String(fileIn.readAllBytes());
fileIn.close();
expectedAST = expectedAST.replaceAll("TPH [A-Z]+", "TPH");
File srcfile = javFiles.get("Tph5")[0];
JavaTXCompiler compiler = new JavaTXCompiler(srcfile);
String resultingAST = new String(ASTPrinter.print(compiler.sourceFiles.get(srcfile)));
resultingAST = resultingAST.replaceAll("TPH [A-Z]+", "TPH");
System.out.println("Expected:\n" + new String(expectedAST));
System.out.println("Result:\n" + new String(resultingAST));
assertEquals("Comparing expected and resulting AST for Tph5.jav", expectedAST, resultingAST);
} catch (Exception exc) {
exc.printStackTrace();
fail("An error occured while generating the AST for Tph5.jav");
}
}
@Test
public void tph6Test() {
try {
FileInputStream fileIn = new FileInputStream(javFiles.get("Tph6")[1]);
String expectedAST = new String(fileIn.readAllBytes());
fileIn.close();
expectedAST = expectedAST.replaceAll("TPH [A-Z]+", "TPH");
File srcfile = javFiles.get("Tph6")[0];
JavaTXCompiler compiler = new JavaTXCompiler(srcfile);
String resultingAST = new String(ASTPrinter.print(compiler.sourceFiles.get(srcfile)));
resultingAST = resultingAST.replaceAll("TPH [A-Z]+", "TPH");
System.out.println("Expected:\n" + new String(expectedAST));
System.out.println("Result:\n" + new String(resultingAST));
assertEquals("Comparing expected and resulting AST for Tph6.jav", expectedAST, resultingAST);
} catch (Exception exc) {
exc.printStackTrace();
fail("An error occured while generating the AST for Tph6.jav");
}
}
@Test
public void tph7Test() {
try {
FileInputStream fileIn = new FileInputStream(javFiles.get("Tph7")[1]);
String expectedAST = new String(fileIn.readAllBytes());
fileIn.close();
expectedAST = expectedAST.replaceAll("TPH [A-Z]+", "TPH");
File srcfile = javFiles.get("Tph7")[0];
JavaTXCompiler compiler = new JavaTXCompiler(srcfile);
String resultingAST = new String(ASTPrinter.print(compiler.sourceFiles.get(srcfile)));
resultingAST = resultingAST.replaceAll("TPH [A-Z]+", "TPH");
System.out.println("Expected:\n" + new String(expectedAST));
System.out.println("Result:\n" + new String(resultingAST));
assertEquals("Comparing expected and resulting AST for Tph7.jav", expectedAST, resultingAST);
} catch (Exception exc) {
exc.printStackTrace();
fail("An error occured while generating the AST for Tph7.jav");
}
}
@Test
public void typedIdTest() {
try {
FileInputStream fileIn = new FileInputStream(javFiles.get("TypedID")[1]);
String expectedAST = new String(fileIn.readAllBytes());
fileIn.close();
expectedAST = expectedAST.replaceAll("TPH [A-Z]+", "TPH");
File srcfile = javFiles.get("TypedID")[0];
JavaTXCompiler compiler = new JavaTXCompiler(srcfile);
String resultingAST = new String(ASTPrinter.print(compiler.sourceFiles.get(srcfile)));
resultingAST = resultingAST.replaceAll("TPH [A-Z]+", "TPH");
System.out.println("Expected:\n" + new String(expectedAST));
System.out.println("Result:\n" + new String(resultingAST));
assertEquals("Comparing expected and resulting AST for TypedID.jav", expectedAST, resultingAST);
} catch (Exception exc) {
exc.printStackTrace();
fail("An error occured while generating the AST for TypedID.jav");
}
}
@Test
public void vectorAddTest() {
try {
FileInputStream fileIn = new FileInputStream(javFiles.get("VectorAdd")[1]);
String expectedAST = new String(fileIn.readAllBytes());
fileIn.close();
expectedAST = expectedAST.replaceAll("TPH [A-Z]+", "TPH");
File srcfile = javFiles.get("VectorAdd")[0];
JavaTXCompiler compiler = new JavaTXCompiler(srcfile);
String resultingAST = new String(ASTPrinter.print(compiler.sourceFiles.get(srcfile)));
resultingAST = resultingAST.replaceAll("TPH [A-Z]+", "TPH");
System.out.println("Expected:\n" + new String(expectedAST));
System.out.println("Result:\n" + new String(resultingAST));
assertEquals("Comparing expected and resulting AST for VectorAdd.jav", expectedAST, resultingAST);
} catch (Exception exc) {
exc.printStackTrace();
fail("An error occured while generating the AST for VectorAdd.jav");
}
}
@Test
public void vectorSuperTest() {
try {
FileInputStream fileIn = new FileInputStream(javFiles.get("VectorSuper")[1]);
String expectedAST = new String(fileIn.readAllBytes());
fileIn.close();
expectedAST = expectedAST.replaceAll("TPH [A-Z]+", "TPH");
File srcfile = javFiles.get("VectorSuper")[0];
JavaTXCompiler compiler = new JavaTXCompiler(srcfile);
String resultingAST = new String(ASTPrinter.print(compiler.sourceFiles.get(srcfile)));
resultingAST = resultingAST.replaceAll("TPH [A-Z]+", "TPH");
System.out.println("Expected:\n" + new String(expectedAST));
System.out.println("Result:\n" + new String(resultingAST));
assertEquals("Comparing expected and resulting AST for VectorSuper.jav", expectedAST, resultingAST);
} catch (Exception exc) {
exc.printStackTrace();
fail("An error occured while generating the AST for VectorSuper.jav");
}
}
@Test
public void yTest() {
try {
FileInputStream fileIn = new FileInputStream(javFiles.get("Y")[1]);
String expectedAST = new String(fileIn.readAllBytes());
fileIn.close();
expectedAST = expectedAST.replaceAll("TPH [A-Z]+", "TPH");
File srcfile = javFiles.get("Y")[0];
JavaTXCompiler compiler = new JavaTXCompiler(srcfile);
String resultingAST = new String(ASTPrinter.print(compiler.sourceFiles.get(srcfile)));
resultingAST = resultingAST.replaceAll("TPH [A-Z]+", "TPH");
System.out.println("Expected:\n" + new String(expectedAST));
System.out.println("Result:\n" + new String(resultingAST));
assertEquals("Comparing expected and resulting AST for Y.jav", expectedAST, resultingAST);
} catch (Exception exc) {
exc.printStackTrace();
fail("An error occured while generating the AST for Y.jav");
}
}
@Test
public void boxTest() {
try {
FileInputStream fileIn = new FileInputStream(javFiles.get("Box")[1]);
String expectedAST = new String(fileIn.readAllBytes());
fileIn.close();
expectedAST = expectedAST.replaceAll("TPH [A-Z]+", "TPH");
File srcfile = javFiles.get("Box")[0];
JavaTXCompiler compiler = new JavaTXCompiler(srcfile);
String resultingAST = new String(ASTPrinter.print(compiler.sourceFiles.get(srcfile)));
resultingAST = resultingAST.replaceAll("TPH [A-Z]+", "TPH");
System.out.println("Expected:\n" + new String(expectedAST));
System.out.println("Result:\n" + new String(resultingAST));
assertEquals("Comparing expected and resulting AST for Box.jav", expectedAST, resultingAST);
} catch (Exception exc) {
exc.printStackTrace();
fail("An error occured while generating the AST for Box.jav");
}
}
@Test
public void cycleTest() {
try {
FileInputStream fileIn = new FileInputStream(javFiles.get("Cycle")[1]);
String expectedAST = new String(fileIn.readAllBytes());
fileIn.close();
expectedAST = expectedAST.replaceAll("TPH [A-Z]+", "TPH");
File srcfile = javFiles.get("Cycle")[0];
JavaTXCompiler compiler = new JavaTXCompiler(srcfile);
String resultingAST = new String(ASTPrinter.print(compiler.sourceFiles.get(srcfile)));
resultingAST = resultingAST.replaceAll("TPH [A-Z]+", "TPH");
System.out.println("Expected:\n" + new String(expectedAST));
System.out.println("Result:\n" + new String(resultingAST));
assertEquals("Comparing expected and resulting AST for Cycle.jav", expectedAST, resultingAST);
} catch (Exception exc) {
exc.printStackTrace();
fail("An error occured while generating the AST for Cycle.jav");
}
}
@Test
public void olFunTest() {
try {
FileInputStream fileIn = new FileInputStream(javFiles.get("OLFun")[1]);
String expectedAST = new String(fileIn.readAllBytes());
fileIn.close();
expectedAST = expectedAST.replaceAll("TPH [A-Z]+", "TPH");
File srcfile = javFiles.get("OLFun")[0];
JavaTXCompiler compiler = new JavaTXCompiler(srcfile);
String resultingAST = new String(ASTPrinter.print(compiler.sourceFiles.get(srcfile)));
resultingAST = resultingAST.replaceAll("TPH [A-Z]+", "TPH");
System.out.println("Expected:\n" + new String(expectedAST));
System.out.println("Result:\n" + new String(resultingAST));
assertEquals("Comparing expected and resulting AST for OLFun.jav", expectedAST, resultingAST);
} catch (Exception exc) {
exc.printStackTrace();
fail("An error occured while generating the AST for OLFun.jav");
}
}
@Test
public void olFun2Test() {
try {
FileInputStream fileIn = new FileInputStream(javFiles.get("OLFun2")[1]);
String expectedAST = new String(fileIn.readAllBytes());
fileIn.close();
expectedAST = expectedAST.replaceAll("TPH [A-Z]+", "TPH");
File srcfile = javFiles.get("OLFun2")[0];
JavaTXCompiler compiler = new JavaTXCompiler(srcfile);
String resultingAST = new String(ASTPrinter.print(compiler.sourceFiles.get(srcfile)));
resultingAST = resultingAST.replaceAll("TPH [A-Z]+", "TPH");
System.out.println("Expected:\n" + new String(expectedAST));
System.out.println("Result:\n" + new String(resultingAST));
assertEquals("Comparing expected and resulting AST for OLFun2.jav", expectedAST, resultingAST);
} catch (Exception exc) {
exc.printStackTrace();
fail("An error occured while generating the AST for OLFun2.jav");
}
}
}
class JavFilter implements FileFilter {
@Override
public boolean accept(File pathname) {
if (pathname.getName().contains(".jav"))
return true;
return false;
}
}