forked from JavaTX/JavaCompilerCore
Added test for Sealed classe and interface ASTs
This commit is contained in:
parent
fe6c9858a2
commit
951d741d90
144
resources/syntaxtreegenerator/Sealed.ast
Normal file
144
resources/syntaxtreegenerator/Sealed.ast
Normal file
@ -0,0 +1,144 @@
|
|||||||
|
class Shape {
|
||||||
|
|
||||||
|
Shape(){
|
||||||
|
super(());
|
||||||
|
}
|
||||||
|
Shape(){
|
||||||
|
super(());
|
||||||
|
}
|
||||||
|
|
||||||
|
}class Circle {
|
||||||
|
|
||||||
|
Circle(){
|
||||||
|
super(());
|
||||||
|
}
|
||||||
|
Circle(){
|
||||||
|
super(());
|
||||||
|
}
|
||||||
|
|
||||||
|
}class Rectangle {
|
||||||
|
|
||||||
|
Rectangle(){
|
||||||
|
super(());
|
||||||
|
}
|
||||||
|
Rectangle(){
|
||||||
|
super(());
|
||||||
|
}
|
||||||
|
|
||||||
|
}class TransparentRectangle {
|
||||||
|
|
||||||
|
TransparentRectangle(){
|
||||||
|
super(());
|
||||||
|
}
|
||||||
|
TransparentRectangle(){
|
||||||
|
super(());
|
||||||
|
}
|
||||||
|
|
||||||
|
}class FilledRectangle {
|
||||||
|
|
||||||
|
FilledRectangle(){
|
||||||
|
super(());
|
||||||
|
}
|
||||||
|
FilledRectangle(){
|
||||||
|
super(());
|
||||||
|
}
|
||||||
|
|
||||||
|
}class Square {
|
||||||
|
|
||||||
|
Square(){
|
||||||
|
super(());
|
||||||
|
}
|
||||||
|
Square(){
|
||||||
|
super(());
|
||||||
|
}
|
||||||
|
|
||||||
|
}class WeirdShape {
|
||||||
|
|
||||||
|
WeirdShape(){
|
||||||
|
super(());
|
||||||
|
}
|
||||||
|
WeirdShape(){
|
||||||
|
super(());
|
||||||
|
}
|
||||||
|
|
||||||
|
}class Expr {
|
||||||
|
|
||||||
|
}class ConstantExpr {
|
||||||
|
|
||||||
|
java.lang.Integer i;
|
||||||
|
ConstantExpr(java.lang.Integer i){
|
||||||
|
super(());
|
||||||
|
this.i = i;
|
||||||
|
}
|
||||||
|
java.lang.Integer i(){
|
||||||
|
return this.i;
|
||||||
|
}
|
||||||
|
|
||||||
|
ConstantExpr(java.lang.Integer i){
|
||||||
|
super(());
|
||||||
|
this.i = i;
|
||||||
|
}
|
||||||
|
|
||||||
|
}class PlusExpr {
|
||||||
|
|
||||||
|
Expr a;
|
||||||
|
Expr b;
|
||||||
|
PlusExpr(Expr a, Expr b){
|
||||||
|
super(());
|
||||||
|
this.a = a;
|
||||||
|
this.b = b;
|
||||||
|
}
|
||||||
|
Expr a(){
|
||||||
|
return this.a;
|
||||||
|
}
|
||||||
|
|
||||||
|
Expr b(){
|
||||||
|
return this.b;
|
||||||
|
}
|
||||||
|
|
||||||
|
PlusExpr(Expr a, Expr b){
|
||||||
|
super(());
|
||||||
|
this.a = a;
|
||||||
|
this.b = b;
|
||||||
|
}
|
||||||
|
|
||||||
|
}class TimesExpr {
|
||||||
|
|
||||||
|
Expr a;
|
||||||
|
Expr b;
|
||||||
|
TimesExpr(Expr a, Expr b){
|
||||||
|
super(());
|
||||||
|
this.a = a;
|
||||||
|
this.b = b;
|
||||||
|
}
|
||||||
|
Expr a(){
|
||||||
|
return this.a;
|
||||||
|
}
|
||||||
|
|
||||||
|
Expr b(){
|
||||||
|
return this.b;
|
||||||
|
}
|
||||||
|
|
||||||
|
TimesExpr(Expr a, Expr b){
|
||||||
|
super(());
|
||||||
|
this.a = a;
|
||||||
|
this.b = b;
|
||||||
|
}
|
||||||
|
|
||||||
|
}class NegExpr {
|
||||||
|
|
||||||
|
Expr e;
|
||||||
|
NegExpr(Expr e){
|
||||||
|
super(());
|
||||||
|
this.e = e;
|
||||||
|
}
|
||||||
|
Expr e(){
|
||||||
|
return this.e;
|
||||||
|
}
|
||||||
|
|
||||||
|
NegExpr(Expr e){
|
||||||
|
super(());
|
||||||
|
this.e = e;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
21
resources/syntaxtreegenerator/javFiles/Sealed.jav
Normal file
21
resources/syntaxtreegenerator/javFiles/Sealed.jav
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
public abstract sealed class Shape
|
||||||
|
permits Circle, Rectangle, Square, WeirdShape { }
|
||||||
|
|
||||||
|
public final class Circle extends Shape { }
|
||||||
|
|
||||||
|
public sealed class Rectangle extends Shape
|
||||||
|
permits TransparentRectangle, FilledRectangle { }
|
||||||
|
public final class TransparentRectangle extends Rectangle { }
|
||||||
|
public final class FilledRectangle extends Rectangle { }
|
||||||
|
|
||||||
|
public final class Square extends Shape { }
|
||||||
|
|
||||||
|
public non-sealed class WeirdShape extends Shape { }
|
||||||
|
|
||||||
|
public sealed interface Expr
|
||||||
|
permits ConstantExpr, PlusExpr, TimesExpr, NegExpr { }
|
||||||
|
|
||||||
|
public record ConstantExpr(int i) implements Expr { }
|
||||||
|
public record PlusExpr(Expr a, Expr b) implements Expr { }
|
||||||
|
public record TimesExpr(Expr a, Expr b) implements Expr { }
|
||||||
|
public record NegExpr(Expr e) implements Expr { }
|
@ -69,6 +69,26 @@ public class TestNewFeatures {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void sealedTest() {
|
||||||
|
try {
|
||||||
|
FileInputStream fileIn = new FileInputStream(javFiles.get("Sealed")[1]);
|
||||||
|
String expectedAST = new String(fileIn.readAllBytes());
|
||||||
|
fileIn.close();
|
||||||
|
expectedAST = expectedAST.replaceAll("TPH [A-Z]+", "TPH");
|
||||||
|
File srcfile = javFiles.get("Sealed")[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 Sealed.jav", expectedAST, resultingAST);
|
||||||
|
} catch (Exception exc) {
|
||||||
|
exc.printStackTrace();
|
||||||
|
fail("An error occured while generating the AST for Sealed.jav");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void switchTest() {
|
public void switchTest() {
|
||||||
try {
|
try {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user