forked from JavaTX/JavaCompilerCore
Finalized test cases for new jav-files
This commit is contained in:
parent
1df354d5f1
commit
fe6c9858a2
120
resources/syntaxtreegenerator/PatternMatching.ast
Normal file
120
resources/syntaxtreegenerator/PatternMatching.ast
Normal file
@ -0,0 +1,120 @@
|
||||
class Point {
|
||||
|
||||
java.lang.Integer x;
|
||||
java.lang.Integer y;
|
||||
Point(java.lang.Integer x, java.lang.Integer y){
|
||||
super(());
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
}
|
||||
java.lang.Integer x(){
|
||||
return this.x;
|
||||
}
|
||||
|
||||
java.lang.Integer y(){
|
||||
return this.y;
|
||||
}
|
||||
|
||||
Point(java.lang.Integer x, java.lang.Integer y){
|
||||
super(());
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
}
|
||||
|
||||
}class Shape {
|
||||
|
||||
}class ColoredPoint {
|
||||
|
||||
Point pt;
|
||||
java.lang.String color;
|
||||
ColoredPoint(Point pt, java.lang.String color){
|
||||
super(());
|
||||
this.pt = pt;
|
||||
this.color = color;
|
||||
}
|
||||
Point pt(){
|
||||
return this.pt;
|
||||
}
|
||||
|
||||
java.lang.String color(){
|
||||
return this.color;
|
||||
}
|
||||
|
||||
ColoredPoint(Point pt, java.lang.String color){
|
||||
super(());
|
||||
this.pt = pt;
|
||||
this.color = color;
|
||||
}
|
||||
|
||||
}class Rectangle {
|
||||
|
||||
ColoredPoint upperLeft;
|
||||
ColoredPoint lowerRight;
|
||||
Rectangle(ColoredPoint upperLeft, ColoredPoint lowerRight){
|
||||
super(());
|
||||
this.upperLeft = upperLeft;
|
||||
this.lowerRight = lowerRight;
|
||||
}
|
||||
ColoredPoint upperLeft(){
|
||||
return this.upperLeft;
|
||||
}
|
||||
|
||||
ColoredPoint lowerRight(){
|
||||
return this.lowerRight;
|
||||
}
|
||||
|
||||
Rectangle(ColoredPoint upperLeft, ColoredPoint lowerRight){
|
||||
super(());
|
||||
this.upperLeft = upperLeft;
|
||||
this.lowerRight = lowerRight;
|
||||
}
|
||||
|
||||
}class Color {
|
||||
|
||||
Color(){
|
||||
super(());
|
||||
}
|
||||
Color(){
|
||||
super(());
|
||||
}
|
||||
|
||||
}class Blue {
|
||||
|
||||
Blue(){
|
||||
super(());
|
||||
}
|
||||
Blue(){
|
||||
super(());
|
||||
}
|
||||
|
||||
}class Red {
|
||||
|
||||
Red(){
|
||||
super(());
|
||||
}
|
||||
Red(){
|
||||
super(());
|
||||
}
|
||||
|
||||
}class PatternMatching {
|
||||
|
||||
PatternMatching(){
|
||||
super(());
|
||||
}
|
||||
void printColorOfUpperLeftPoint(Shape shape){
|
||||
switch(shape){
|
||||
case Rectangle(ColoredPoint(Point pt, java.lang.String color), ColoredPoint lowerRight):
|
||||
System.out.println Signature: [TPH, TPH](x: op pt.x Signature: [TPH]() op / color: op color op / lowerRight: op lowerRight);
|
||||
|
||||
default:
|
||||
System.out.println Signature: [TPH, TPH](not a rectangle);
|
||||
|
||||
};
|
||||
return;
|
||||
}
|
||||
|
||||
PatternMatching(){
|
||||
super(());
|
||||
}
|
||||
|
||||
}
|
96
resources/syntaxtreegenerator/Switch.ast
Normal file
96
resources/syntaxtreegenerator/Switch.ast
Normal file
@ -0,0 +1,96 @@
|
||||
class SwitchStatement {
|
||||
|
||||
SwitchStatement(){
|
||||
super(());
|
||||
}
|
||||
TPH switchStandard(){
|
||||
str = SwitchMe;
|
||||
switch(str){
|
||||
case java.lang.String s:
|
||||
return true;
|
||||
|
||||
default:
|
||||
return false;
|
||||
|
||||
};
|
||||
}
|
||||
|
||||
TPH switchInteger(){
|
||||
i = 5;
|
||||
switch(i){
|
||||
case java.lang.Integer j:
|
||||
case java.lang.String s:
|
||||
i = 6;
|
||||
break;
|
||||
|
||||
default:
|
||||
i = 0;
|
||||
break;
|
||||
|
||||
};
|
||||
return i op 0;
|
||||
}
|
||||
|
||||
TPH guardedPattern(){
|
||||
TPH i;
|
||||
i = 1;
|
||||
switch(i){
|
||||
case java.lang.Integer j:
|
||||
return true;
|
||||
|
||||
default:
|
||||
return false;
|
||||
|
||||
};
|
||||
}
|
||||
|
||||
TPH recordPattern(java.lang.Object obj){
|
||||
switch(obj){
|
||||
case Coordinates(java.lang.Double lat, java.lang.Double lon):
|
||||
return true;
|
||||
|
||||
default:
|
||||
return false;
|
||||
|
||||
};
|
||||
}
|
||||
|
||||
SwitchStatement(){
|
||||
super(());
|
||||
}
|
||||
|
||||
}class SwitchExpression {
|
||||
|
||||
java.lang.Integer x;
|
||||
java.lang.Integer y;
|
||||
SwitchExpression(java.lang.Integer x, java.lang.Integer y){
|
||||
super(());
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
}
|
||||
java.lang.Integer x(){
|
||||
return this.x;
|
||||
}
|
||||
|
||||
java.lang.Integer y(){
|
||||
return this.y;
|
||||
}
|
||||
|
||||
java.lang.Boolean switchStandard(TPH str){
|
||||
return switch(str){
|
||||
case java.lang.String s:
|
||||
yield true;
|
||||
|
||||
default:
|
||||
yield false;
|
||||
|
||||
};
|
||||
}
|
||||
|
||||
SwitchExpression(java.lang.Integer x, java.lang.Integer y){
|
||||
super(());
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
}
|
||||
|
||||
}
|
@ -42,10 +42,10 @@ public class TestNewFeatures {
|
||||
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);
|
||||
assertEquals("Comparing expected and resulting AST for Instanceof.jav", expectedAST, resultingAST);
|
||||
} catch (Exception exc) {
|
||||
exc.printStackTrace();
|
||||
fail("An error occured while generating the AST for applyLambda.jav");
|
||||
fail("An error occured while generating the AST for Instanceof.jav");
|
||||
}
|
||||
}
|
||||
|
||||
@ -62,45 +62,47 @@ public class TestNewFeatures {
|
||||
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);
|
||||
assertEquals("Comparing expected and resulting AST for Record.jav", expectedAST, resultingAST);
|
||||
} catch (Exception exc) {
|
||||
exc.printStackTrace();
|
||||
fail("An error occured while generating the AST for applyLambda.jav");
|
||||
fail("An error occured while generating the AST for Record.jav");
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void switchTest() {
|
||||
try {
|
||||
/*
|
||||
* FileInputStream fileIn = new FileInputStream(javFiles.get("Record")[1]); String expectedAST = new String(fileIn.readAllBytes()); fileIn.close(); expectedAST = expectedAST.replaceAll("TPH [A-Z]+", "TPH");
|
||||
*/
|
||||
FileInputStream fileIn = new FileInputStream(javFiles.get("Switch")[1]);
|
||||
String expectedAST = new String(fileIn.readAllBytes());
|
||||
fileIn.close();
|
||||
expectedAST = expectedAST.replaceAll("TPH [A-Z]+", "TPH");
|
||||
File srcfile = javFiles.get("Switch")[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("Expected:\n" + new String(expectedAST));
|
||||
System.out.println("Result:\n" + new String(resultingAST));
|
||||
// assertEquals("Comparing expected and resulting AST for applyLambda.jav", expectedAST, resultingAST);
|
||||
assertEquals("Comparing expected and resulting AST for Switch.jav", expectedAST, resultingAST);
|
||||
} catch (Exception exc) {
|
||||
exc.printStackTrace();
|
||||
fail("An error occured while generating the AST for applyLambda.jav");
|
||||
fail("An error occured while generating the AST for Switch.jav");
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void patternMatching() {
|
||||
try {
|
||||
/*
|
||||
* FileInputStream fileIn = new FileInputStream(javFiles.get("PatternMatching")[1]); String expectedAST = new String(fileIn.readAllBytes()); fileIn.close(); expectedAST = expectedAST.replaceAll("TPH [A-Z]+", "TPH");
|
||||
*/
|
||||
FileInputStream fileIn = new FileInputStream(javFiles.get("PatternMatching")[1]);
|
||||
String expectedAST = new String(fileIn.readAllBytes());
|
||||
fileIn.close();
|
||||
expectedAST = expectedAST.replaceAll("TPH [A-Z]+", "TPH");
|
||||
File srcfile = javFiles.get("PatternMatching")[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("Expected:\n" + new String(expectedAST));
|
||||
System.out.println("Result:\n" + new String(resultingAST));
|
||||
// assertEquals("Comparing expected and resulting AST for PatternMatching.jav", expectedAST, resultingAST);
|
||||
assertEquals("Comparing expected and resulting AST for PatternMatching.jav", expectedAST, resultingAST);
|
||||
} catch (Exception exc) {
|
||||
exc.printStackTrace();
|
||||
fail("An error occured while generating the AST for PatternMatching.jav");
|
||||
|
Loading…
Reference in New Issue
Block a user