forked from JavaTX/JavaCompilerCore
Added test case Record(.jav) in TestNewFeatures
This commit is contained in:
parent
24900b8fcc
commit
8b3b07e32c
47
resources/syntaxtreegenerator/Record.ast
Normal file
47
resources/syntaxtreegenerator/Record.ast
Normal 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;
|
||||
}
|
||||
|
||||
}
|
5
resources/syntaxtreegenerator/javFiles/Record.jav
Normal file
5
resources/syntaxtreegenerator/javFiles/Record.jav
Normal file
@ -0,0 +1,5 @@
|
||||
// Simple records
|
||||
record Point(x, y){ }
|
||||
|
||||
//Combination of records
|
||||
record Line(pt1, pt2){}
|
@ -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();
|
||||
|
@ -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 = " ";
|
||||
|
@ -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 {
|
||||
|
Loading…
Reference in New Issue
Block a user