Added test case Record(.jav) in TestNewFeatures

This commit is contained in:
luca9913 2023-06-28 22:10:08 +02:00
parent 24900b8fcc
commit 8b3b07e32c
5 changed files with 73 additions and 2 deletions

View File

@ -0,0 +1,47 @@
class Point {
TPH x;
TPH y;
Point(TPH x, TPH y){
super(());
this.x = x;
this.y = y;
}
TPH x(){
return this.x;
}
TPH y(){
return this.y;
}
Point(TPH x, TPH y){
super(());
this.x = x;
this.y = y;
}
}class Line {
TPH pt1;
TPH pt2;
Line(TPH pt1, TPH pt2){
super(());
this.pt1 = pt1;
this.pt2 = pt2;
}
TPH pt1(){
return this.pt1;
}
TPH pt2(){
return this.pt2;
}
Line(TPH pt1, TPH pt2){
super(());
this.pt1 = pt1;
this.pt2 = pt2;
}
}

View File

@ -0,0 +1,5 @@
// Simple records
record Point(x, y){ }
//Combination of records
record Line(pt1, pt2){}

View File

@ -4,7 +4,7 @@ import de.dhbwstuttgart.syntaxtree.*;
public class ASTPrinter {
public static String print(SourceFile toPrint){
public static String print(SourceFile toPrint) {
StringBuilder output = new StringBuilder();
new OutputGenerator(output).visit(toPrint);
return output.toString();

View File

@ -7,7 +7,6 @@ import de.dhbwstuttgart.syntaxtree.type.*;
import java.lang.reflect.Modifier;
import java.util.Iterator;
import java.util.Optional;
public class OutputGenerator implements ASTVisitor {
private static final String TAB = " ";

View File

@ -48,6 +48,26 @@ public class TestNewFeatures {
fail("An error occured while generating the AST for applyLambda.jav");
}
}
@Test
public void recordTest() {
try {
FileInputStream fileIn = new FileInputStream(javFiles.get("Record")[1]);
String expectedAST = new String(fileIn.readAllBytes());
fileIn.close();
expectedAST = expectedAST.replaceAll("TPH [A-Z]+", "TPH");
File srcfile = javFiles.get("Record")[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");
}
}
}
class JavFilter implements FileFilter {