implemented tests for each feature (not complete) and added AST Expectation (not complete)

This commit is contained in:
JonathanFleischmann 2024-06-16 21:09:14 +02:00
parent ec5cb4b490
commit bfef8ccff6
72 changed files with 2316 additions and 50 deletions

View File

@ -0,0 +1,32 @@
package testfiles.ASTFeatures;
import de.maishai.ast.records.Block;
import de.maishai.ast.records.Constructor;
import de.maishai.ast.records.Program;
import de.maishai.ast.records.Class;
import java.util.List;
public class AST_Class {
public static Program get() {
return new Program(
List.of(
new Class(
"Class",
List.of(),
List.of(),
List.of(
new Constructor(
"Class",
List.of(),
new Block(
List.of(
)
)
)
)
)
)
);
}
}

View File

@ -0,0 +1,140 @@
package testfiles.ASTFeatures;
import de.maishai.ast.records.*;
import de.maishai.ast.records.Class;
import de.maishai.typedast.Type;
import java.util.List;
public class AST_ClassObjects {
public static Program get() {
return new Program(
List.of(
new Class(
"ClassObjects",
List.of(
new Declaration(
"c",
Type.CHAR
)
),
getMethods(),
getConstructors()
)
)
);
}
private static List<Method> getMethods() {
return List.of(getMethod1());
}
private static Method getMethod1() {
return new Method(
Type.VOID,
"objectsMethod",
List.of(),
new Block(
List.of(
new Assignment(
new FieldVarAccess(
true,
null,
"b"),
new New(
Type.REFERENCE("ClassObjects"),
List.of()
)
),
new Declaration(
"c",
Type.REFERENCE("ClassObjects")
),
new Assignment(
new FieldVarAccess(
false,
null,
"c"),
new New(
Type.REFERENCE("ClassObjects"),
List.of(
new IntLiteral(2)
)
)
),
new Declaration(
"d",
Type.REFERENCE("ClassObjects")
),
new Assignment(
new FieldVarAccess(
false,
null,
"c"),
new FieldVarAccess(
true,
new FieldVarAccess(
true,
new FieldVarAccess(
true,
new FieldVarAccess(
false,
null,
"d"),
"b"),
"b"),
"b")
),
new MethodCall(
new FieldVarAccess(
false,
new FieldVarAccess(
true,
new FieldVarAccess(
true,
new FieldVarAccess(
false,
null,
"c"),
"b"),
"b"),
"objectsMethod"),
List.of()
)
)
)
);
}
private static List<Constructor> getConstructors() {
return List.of(getConstructor1(), getConstructor2());
}
private static Constructor getConstructor1() {
return new Constructor(
"ClassObjects",
List.of(),
new Block(
List.of(
)
)
);
}
private static Constructor getConstructor2() {
return new Constructor(
"ClassObjects",
List.of(
new Parameter(
"a",
Type.INT
)
),
new Block(
List.of(
)
)
);
}
}

View File

@ -0,0 +1,32 @@
package testfiles.ASTFeatures;
import de.maishai.ast.records.Block;
import de.maishai.ast.records.Class;
import de.maishai.ast.records.Constructor;
import de.maishai.ast.records.Program;
import java.util.List;
public class AST_Comment {
public static Program get() {
return new Program(
List.of(
new Class(
"Comment",
List.of(),
List.of(),
List.of(
new Constructor(
"Comment",
List.of(),
new Block(
List.of(
)
)
)
)
)
)
);
}
}

View File

@ -0,0 +1,115 @@
package testfiles.ASTFeatures;
import de.maishai.ast.Operator;
import de.maishai.ast.records.*;
import de.maishai.ast.records.Class;
import de.maishai.typedast.Type;
import java.util.List;
public class AST_Constructor {
public static Program get() {
return new Program(
List.of(
new Class(
"Constructor",
List.of(),
List.of(),
List.of(
new Constructor(
"Constructor",
List.of(),
new Block(
List.of(
new Declaration(
"i",
Type.INT
),
new Assignment(
new FieldVarAccess(
false,
null,
"i"
),
new IntLiteral(1)
)
)
)
),
new Constructor(
"Constructor",
List.of(
new Parameter(
"x",
Type.INT
)
),
new Block(
List.of(
new Declaration(
"i",
Type.INT
),
new Assignment(
new FieldVarAccess(
false,
null,
"i"
),
new FieldVarAccess(
false,
null,
"x"
)
)
)
)
),
new Constructor(
"Constructor",
List.of(
new Parameter(
"x",
Type.INT
),
new Parameter(
"y",
Type.INT
)
),
new Block(
List.of(
new Declaration(
"i",
Type.INT
),
new Assignment(
new FieldVarAccess(
false,
null,
"i"
),
new Binary(
new FieldVarAccess(
false,
null,
"x"
),
Operator.ADD,
new FieldVarAccess(
false,
null,
"y"
)
)
)
)
)
)
)
)
)
);
}
}

View File

@ -0,0 +1,103 @@
package testfiles.ASTFeatures;
import de.maishai.ast.Operator;
import de.maishai.ast.records.*;
import de.maishai.ast.records.Class;
import de.maishai.typedast.Type;
import java.util.List;
public class AST_Continue {
public static Program get() {
return new Program(
List.of(
new Class(
"Continue",
List.of(),
List.of(
new Method(
Type.VOID,
"continueLoop",
List.of(),
new Block(
List.of(
new Declaration(
"i",
Type.INT
),
new For(
new Assignment(
new FieldVarAccess(
false,
null,
"i"
),
new IntLiteral(0)
),
new Binary(
new FieldVarAccess(
false,
null,
"i"
),
Operator.LT,
new IntLiteral(5)
),
new Assignment(
new FieldVarAccess(
false,
null,
"i"
),
new Binary(
new FieldVarAccess(
false,
null,
"i"
),
Operator.ADD,
new IntLiteral(1)
)
),
new Block(
List.of(
new IfElse(
new Binary(
new FieldVarAccess(
false,
null,
"i"
),
Operator.EQ,
new IntLiteral(3)
),
new Block(
List.of(
new Continue()
)
),
null
)
)
)
)
)
)
)
),
List.of(
new Constructor(
"Continue",
List.of(),
new Block(
List.of(
)
)
)
)
)
)
);
}
}

View File

@ -0,0 +1,66 @@
package testfiles.ASTFeatures;
import de.maishai.ast.records.*;
import de.maishai.ast.records.Class;
import de.maishai.typedast.Type;
import java.util.List;
public class AST_Field {
public static Program get() {
return new Program(
List.of(
new Class(
"Field",
List.of(
new Declaration(
"x",
Type.INT
),
new Declaration(
"c",
Type.CHAR
)
),
List.of(
new Method(
Type.VOID,
"fieldAccess",
List.of(),
new Block(
List.of(
new Assignment(
new FieldVarAccess(
true,
null,
"x"
),
new IntLiteral(0)
),
new Assignment(
new FieldVarAccess(
true,
null,
"c"
),
new CharLiteral('a')
)
)
)
)
),
List.of(
new Constructor(
"Field",
List.of(),
new Block(
List.of()
)
)
)
)
)
);
}
}

View File

@ -0,0 +1,127 @@
package testfiles.ASTFeatures;
import de.maishai.ast.Operator;
import de.maishai.ast.records.*;
import de.maishai.ast.records.Class;
import de.maishai.typedast.Type;
import java.util.List;
public class AST_For {
public static Program get() {
return new Program(
List.of(
new Class(
"For",
List.of(),
List.of(
new Method(
Type.VOID,
"testFor",
List.of(),
new Block(
List.of(
new Declaration(
"i",
Type.INT
),
new For(
new Assignment(
new FieldVarAccess(
false,
null,
"i"
),
new IntLiteral(0)
),
new Binary(
new FieldVarAccess(
false,
null,
"i"
),
Operator.LT,
new IntLiteral(10)
),
new Assignment(
new FieldVarAccess(
false,
null,
"i"
),
new Binary(
new FieldVarAccess(
false,
null,
"i"
),
Operator.ADD,
new IntLiteral(1)
)
),
new Block(
List.of()
)
),
new Declaration(
"j",
Type.INT
),
new For(
new Assignment(
new FieldVarAccess(
false,
null,
"j"
),
new IntLiteral(0)
),
new Binary(
new FieldVarAccess(
false,
null,
"j"
),
Operator.LT,
new IntLiteral(10)
),
new Assignment(
new FieldVarAccess(
false,
null,
"j"
),
new Binary(
new FieldVarAccess(
false,
null,
"j"
),
Operator.ADD,
new IntLiteral(1)
)
),
new Block(
List.of()
)
)
)
)
)
),
List.of(
new Constructor(
"For",
List.of(),
new Block(
List.of(
)
)
)
)
)
)
);
}
}

View File

@ -0,0 +1,61 @@
package testfiles.ASTFeatures;
import de.maishai.ast.records.*;
import de.maishai.ast.records.Class;
import de.maishai.typedast.Type;
import java.util.List;
public class AST_If {
public static Program get() {
return new Program(
List.of(
new Class(
"If",
List.of(),
List.of(
new Method(
Type.VOID,
"ifMethod",
List.of(),
new Block(
List.of(
new IfElse(
new BoolLiteral(false),
new Block(
List.of()
),
new Block(
List.of(
new IfElse(
new BoolLiteral(true),
new Block(
List.of()
),
new Block(
List.of()
)
)
)
)
)
)
)
)
),
List.of(
new Constructor(
"If",
List.of(),
new Block(
List.of(
)
)
)
)
)
)
);
}
}

View File

@ -0,0 +1,86 @@
package testfiles.ASTFeatures;
import de.maishai.ast.Operator;
import de.maishai.ast.records.*;
import de.maishai.ast.records.Class;
import de.maishai.typedast.Type;
import java.util.List;
public class AST_IncrDecr {
public static Program get() {
return new Program(
List.of(
new Class(
"IncrDecr",
List.of(),
List.of(
new Method(
Type.INT,
"increment",
List.of(
new Parameter(
"a",
Type.INT
)
),
new Block(
List.of(
new Return(
new Binary(
new FieldVarAccess(
false,
null,
"x"
),
Operator.ADD,
new IntLiteral(
1
)
)
)
)
)
),
new Method(
Type.INT,
"decrement",
List.of(
new Parameter(
"a",
Type.INT
)
),
new Block(
List.of(
new Return(
new Binary(
new FieldVarAccess(
false,
null,
"a"
),
Operator.SUB,
new IntLiteral(
1
)
)
)
)
)
)
),
List.of(
new Constructor(
"IncrDecr",
List.of(),
new Block(
List.of()
)
)
)
)
)
);
}
}

View File

@ -0,0 +1,332 @@
package testfiles.ASTFeatures;
import de.maishai.ast.Operator;
import de.maishai.ast.records.*;
import de.maishai.ast.records.Class;
import de.maishai.typedast.Type;
import java.util.List;
public class AST_LogicExpr {
public static Program get() {
return new Program(
List.of(
new Class(
"LogicExpr",
List.of(),
List.of(
new Method(
Type.BOOL,
"test",
List.of(),
new Block(
List.of(
new Declaration(
"x",
Type.INT
),
new Assignment(
new FieldVarAccess(
false,
null,
"x"
),
new IntLiteral(10)
),
new Declaration(
"y",
Type.INT
),
new Assignment(
new FieldVarAccess(
false,
null,
"y"
),
new IntLiteral(20)
),
new Return(
new Binary(
new FieldVarAccess(
false,
null,
"x"
),
Operator.LT,
new FieldVarAccess(
false,
null,
"y"
)
)
)
)
)
),
new Method(
Type.BOOL,
"test2",
List.of(),
new Block(
List.of(
new Declaration(
"x",
Type.INT
),
new Assignment(
new FieldVarAccess(
false,
null,
"x"
),
new IntLiteral(10)
),
new Declaration(
"y",
Type.INT
),
new Assignment(
new FieldVarAccess(
false,
null,
"y"
),
new IntLiteral(20)
),
new Return(
new Binary(
new FieldVarAccess(
false,
null,
"x"
),
Operator.GT,
new FieldVarAccess(
false,
null,
"y"
)
)
)
)
)
),
new Method(
Type.BOOL,
"test3",
List.of(),
new Block(
List.of(
new Declaration(
"x",
Type.INT
),
new Assignment(
new FieldVarAccess(
false,
null,
"x"
),
new IntLiteral(10)
),
new Declaration(
"y",
Type.INT
),
new Assignment(
new FieldVarAccess(
false,
null,
"y"
),
new IntLiteral(20)
),
new Return(
new Binary(
new FieldVarAccess(
false,
null,
"x"
),
Operator.EQ,
new FieldVarAccess(
false,
null,
"y"
)
)
)
)
)
),
new Method(
Type.BOOL,
"test4",
List.of(),
new Block(
List.of(
new Declaration(
"x",
Type.INT
),
new Assignment(
new FieldVarAccess(
false,
null,
"x"
),
new IntLiteral(10)
),
new Declaration(
"y",
Type.INT
),
new Assignment(
new FieldVarAccess(
false,
null,
"y"
),
new IntLiteral(20)
),
new Return(
new Binary(
new FieldVarAccess(
false,
null,
"x"
),
Operator.NE,
new FieldVarAccess(
false,
null,
"y"
)
)
)
)
)
),
new Method(
Type.BOOL,
"test5",
List.of(),
new Block(
List.of(
new Declaration(
"x",
Type.INT
),
new Assignment(
new FieldVarAccess(
false,
null,
"x"
),
new IntLiteral(10)
),
new Declaration(
"y",
Type.INT
),
new Assignment(
new FieldVarAccess(
false,
null,
"y"
),
new IntLiteral(20)
),
new Return(
new Binary(
new FieldVarAccess(
false,
null,
"x"
),
Operator.LE,
new FieldVarAccess(
false,
null,
"y"
)
)
)
)
)
),
new Method(
Type.BOOL,
"test6",
List.of(),
new Block(
List.of(
new Declaration(
"x",
Type.INT
),
new Assignment(
new FieldVarAccess(
false,
null,
"x"
),
new IntLiteral(10)
),
new Declaration(
"y",
Type.INT
),
new Assignment(
new FieldVarAccess(
false,
null,
"y"
),
new IntLiteral(20)
),
new Return(
new Binary(
new FieldVarAccess(
false,
null,
"x"
),
Operator.GE,
new FieldVarAccess(
false,
null,
"y"
)
)
)
)
)
)
),
List.of(
new Constructor(
"LogicExpr",
List.of(),
new Block(
List.of()
)
)
)
)
)
);
}
}

View File

@ -0,0 +1,39 @@
package testfiles.ASTFeatures;
import de.maishai.ast.records.*;
import de.maishai.ast.records.Class;
import de.maishai.typedast.Type;
import java.util.List;
public class AST_Method {
public static Program get() {
return new Program(
List.of(
new Class(
"Method",
List.of(),
List.of(
new Method(
Type.VOID,
"method",
List.of(),
new Block(
List.of()
)
)
),
List.of(
new Constructor(
"Method",
List.of(),
new Block(
List.of()
)
)
)
)
)
);
}
}

View File

@ -0,0 +1,160 @@
package testfiles.ASTFeatures;
import de.maishai.ast.Operator;
import de.maishai.ast.records.*;
import de.maishai.ast.records.Class;
import de.maishai.typedast.Type;
import java.util.List;
public class AST_MethodCall {
public static Program get() {
return new Program(
List.of(
new Class(
"MethodCall",
List.of(),
List.of(
new Method(
Type.INT,
"methodCall",
List.of(),
new Block(
List.of(
new Return(
new MethodCall(
new FieldVarAccess(
false,
null,
"method"
),
List.of()
)
)
)
)
),
new Method(
Type.INT,
"methodCall1",
List.of(),
new Block(
List.of(
new Return(
new MethodCall(
new FieldVarAccess(
false,
null,
"method1"
),
List.of(
new IntLiteral(1)
)
)
)
)
)
),
new Method(
Type.INT,
"methodCall2",
List.of(),
new Block(
List.of(
new Return(
new MethodCall(
new FieldVarAccess(
false,
null,
"method2"
),
List.of(
new IntLiteral(1),
new IntLiteral(2)
)
)
)
)
)
),
new Method(
Type.INT,
"method",
List.of(),
new Block(
List.of(
new Return(
new IntLiteral(0)
)
)
)
),
new Method(
Type.INT,
"method1",
List.of(
new Parameter(
"x",
Type.INT
)
),
new Block(
List.of(
new Return(
new FieldVarAccess(
false,
null,
"x"
)
)
)
)
),
new Method(
Type.INT,
"method2",
List.of(
new Parameter(
"x",
Type.INT
),
new Parameter(
"y",
Type.INT
)
),
new Block(
List.of(
new Return(
new Binary(
new FieldVarAccess(
false,
null,
"x"
),
Operator.ADD,
new FieldVarAccess(
false,
null,
"y"
)
)
)
)
)
)
),
List.of(
new Constructor(
"MethodCall",
List.of(),
new Block(
List.of()
)
)
)
)
)
);
}
}

View File

@ -0,0 +1,5 @@
package testfiles.ASTFeatures;
public class AST_MultipleClasses {
}

View File

@ -0,0 +1,198 @@
package testfiles.ASTFeatures;
import de.maishai.ast.Operator;
import de.maishai.ast.records.*;
import de.maishai.ast.records.Class;
import de.maishai.typedast.Type;
import java.util.List;
public class AST_Operators {
public static Program get() {
return new Program(
List.of(
new Class(
"Operators",
List.of(),
List.of(
new Method(
Type.INT,
"add",
List.of(
new Parameter(
"a",
Type.INT
),
new Parameter(
"b",
Type.INT
)
),
new Block(
List.of(
new Return(
new Binary(
new FieldVarAccess(
false,
null,
"a"
),
Operator.ADD,
new FieldVarAccess(
false,
null,
"b"
)
)
)
)
)
),
new Method(
Type.INT,
"sub",
List.of(
new Parameter(
"a",
Type.INT
),
new Parameter(
"b",
Type.INT
)
),
new Block(
List.of(
new Return(
new Binary(
new FieldVarAccess(
false,
null,
"a"
),
Operator.SUB,
new FieldVarAccess(
false,
null,
"b"
)
)
)
)
)
),
new Method(
Type.INT,
"mul",
List.of(
new Parameter(
"a",
Type.INT
),
new Parameter(
"b",
Type.INT
)
),
new Block(
List.of(
new Return(
new Binary(
new FieldVarAccess(
false,
null,
"a"
),
Operator.MUL,
new FieldVarAccess(
false,
null,
"b"
)
)
)
)
)
),
new Method(
Type.INT,
"div",
List.of(
new Parameter(
"a",
Type.INT
),
new Parameter(
"b",
Type.INT
)
),
new Block(
List.of(
new Return(
new Binary(
new FieldVarAccess(
false,
null,
"a"
),
Operator.DIV,
new FieldVarAccess(
false,
null,
"b"
)
)
)
)
)
),
new Method(
Type.INT,
"mod",
List.of(
new Parameter(
"a",
Type.INT
),
new Parameter(
"b",
Type.INT
)
),
new Block(
List.of(
new Return(
new Binary(
new FieldVarAccess(
false,
null,
"a"
),
Operator.MOD,
new FieldVarAccess(
false,
null,
"b"
)
)
)
)
)
)
),
List.of(
new Constructor(
"Operators",
List.of(),
new Block(
List.of()
)
)
)
)
)
);
}
}

View File

@ -0,0 +1,98 @@
package testfiles.ASTFeatures;
import de.maishai.ast.Operator;
import de.maishai.ast.records.*;
import de.maishai.ast.records.Class;
import de.maishai.typedast.Type;
import java.util.List;
public class AST_Overloaded {
public static Program get() {
return new Program(
List.of(
new Class(
"Overloaded",
List.of(),
List.of(
new Method(
Type.INT,
"overloadedMethod",
List.of(),
new Block(
List.of(
new Return(
new IntLiteral(0)
)
)
)
),
new Method(
Type.INT,
"overloadedMethod",
List.of(
new Parameter(
"x",
Type.INT
)
),
new Block(
List.of(
new Return(
new FieldVarAccess(
false,
null,
"x"
)
)
)
)
),
new Method(
Type.INT,
"overloadedMethod",
List.of(
new Parameter(
"x",
Type.INT
),
new Parameter(
"y",
Type.INT
)
),
new Block(
List.of(
new Return(
new Binary(
new FieldVarAccess(
false,
null,
"x"
),
Operator.ADD,
new FieldVarAccess(
false,
null,
"y"
)
)
)
)
)
)
),
List.of(
new Constructor(
"Overloaded",
List.of(),
new Block(
List.of()
)
)
)
)
)
);
}
}

View File

@ -0,0 +1,86 @@
package testfiles.ASTFeatures;
import de.maishai.ast.Operator;
import de.maishai.ast.records.*;
import de.maishai.ast.records.Class;
import de.maishai.typedast.Type;
import java.util.List;
public class AST_Print {
public static Program get() {
return new Program(
List.of(
new Class(
"Print",
List.of(),
List.of(
new Method(
Type.VOID,
"print",
List.of(
new Parameter(
"c",
Type.CHAR
)
),
new Block(
List.of(
new Print(
new FieldVarAccess(
false,
null,
"c"
)
)
)
)
),
new Method(
Type.VOID,
"printMoreComplex",
List.of(
new Parameter(
"x",
Type.INT
),
new Parameter(
"y",
Type.INT
)
),
new Block(
List.of(
new Print(
new Binary(
new FieldVarAccess(
false,
null,
"x"
),
Operator.LT,
new FieldVarAccess(
false,
null,
"y"
)
)
)
)
)
)
),
List.of(
new Constructor(
"Print",
List.of(),
new Block(
List.of()
)
)
)
)
)
);
}
}

View File

@ -0,0 +1,95 @@
package testfiles.ASTFeatures;
import de.maishai.ast.records.*;
import de.maishai.ast.records.Class;
import de.maishai.typedast.Type;
import java.util.List;
public class AST_Return {
public static Program get() {
return new Program(
List.of(
new Class(
"Return",
List.of(),
List.of(
new Method(
Type.INT,
"returnInt",
List.of(),
new Block(
List.of(
new Return(
new IntLiteral(10)
)
)
)
),
new Method(
Type.VOID,
"returnVoid",
List.of(),
new Block(
List.of(
new Return(
null
)
)
)
),
new Method(
Type.BOOL,
"returnBoolean",
List.of(),
new Block(
List.of(
new Return(
new BoolLiteral(true)
)
)
)
),
new Method(
Type.CHAR,
"returnChar",
List.of(),
new Block(
List.of(
new Return(
new CharLiteral('a')
)
)
)
),
new Method(
Type.REFERENCE("AST_Return"),
"returnClass",
List.of(),
new Block(
List.of(
new Return(
new New(
Type.REFERENCE("AST_Return"),
List.of()
)
)
)
)
)
),
List.of(
new Constructor(
"Return",
List.of(),
new Block(
List.of()
)
)
)
)
)
);
}
}

View File

@ -0,0 +1,55 @@
package testfiles.ASTFeatures;
import de.maishai.ast.records.*;
import de.maishai.ast.records.Class;
import de.maishai.typedast.Type;
import java.util.List;
public class AST_VariableDefWithDecl {
public static Program get() {
return new Program(
List.of(
new Class(
"VariableDefWithDecl",
List.of(),
List.of(),
List.of(
new Constructor(
"VariableDefWithDecl",
List.of(),
new Block(
List.of(
new Declaration(
"a",
Type.INT
),
new Assignment(
new FieldVarAccess(
false,
null,
"a"
),
new IntLiteral(10)
),
new Declaration(
"b",
Type.INT
),
new Assignment(
new FieldVarAccess(
false,
null,
"b"
),
new IntLiteral(20)
)
)
)
)
)
)
)
);
}
}

View File

@ -0,0 +1,84 @@
package testfiles.ASTFeatures;
import de.maishai.ast.Operator;
import de.maishai.ast.records.*;
import de.maishai.ast.records.Class;
import de.maishai.typedast.Type;
import java.util.List;
public class AST_While {
public static Program get() {
return new Program(
List.of(
new Class(
"While",
List.of(),
List.of(
new Method(
Type.VOID,
"whileLoop",
List.of(),
new Block(
List.of(
new Declaration(
"i",
Type.INT
),
new Assignment(
new FieldVarAccess(
false,
null,
"i"
),
new IntLiteral(0)
),
new While(
new Binary(
new FieldVarAccess(
false,
null,
"i"
),
Operator.LT,
new IntLiteral(5)
),
new Block(
List.of(
new Assignment(
new FieldVarAccess(
false,
null,
"i"
),
new Binary(
new FieldVarAccess(
false,
null,
"i"
),
Operator.ADD,
new IntLiteral(1)
)
)
)
)
)
)
)
)
),
List.of(
new Constructor(
"While",
List.of(),
new Block(
List.of()
)
)
)
)
)
);
}
}

View File

@ -1,4 +1,4 @@
//public class ClassWithConstructor { package testfiles.ASTMore;//public class ClassWithConstructor {
// int x; // int x;
// public classWithConstructor() { // public classWithConstructor() {
// this.x = 10; // this.x = 10;

View File

@ -1,4 +1,4 @@
//public class ClassWithConstructorAndMethodCall { package testfiles.ASTMore;//public class ClassWithConstructorAndMethodCall {
// int x; // int x;
// //
// public ClassWithConstructorAndMethodCall() { // public ClassWithConstructorAndMethodCall() {

View File

@ -1,4 +1,4 @@
//public class ClassWithConstructorWithCodeInComments { package testfiles.ASTMore;//public class ClassWithConstructorWithCodeInComments {
// int x; // int x;
// public ClassWithConstructorWithCodeInComments() { // public ClassWithConstructorWithCodeInComments() {
// this.x = 10; // this.x = 10;

View File

@ -1,4 +1,4 @@
//public class ClassWithConstructorWithParameters { package testfiles.ASTMore;//public class ClassWithConstructorWithParameters {
// int x; // int x;
// public ClassWithConstructorWithParameters(int startValue, int repetitions) { // public ClassWithConstructorWithParameters(int startValue, int repetitions) {
// this.x = startValue; // this.x = startValue;

View File

@ -1,4 +1,4 @@
//public class ClassWithField { package testfiles.ASTMore;//public class ClassWithField {
// int x; // int x;
//} //}

View File

@ -1,4 +1,4 @@
//public class ClassWithMethod { package testfiles.ASTMore;//public class ClassWithMethod {
// public boolean method() { // public boolean method() {
// return false; // return false;
// } // }

View File

@ -1,4 +1,4 @@
//public class ClassWithMethodAndField { package testfiles.ASTMore;//public class ClassWithMethodAndField {
// char c; // char c;
// //
// public ClassWithMethodAndField(char character) { // public ClassWithMethodAndField(char character) {
@ -10,7 +10,6 @@
// } // }
//} //}
import de.maishai.ast.*;
import de.maishai.ast.records.*; import de.maishai.ast.records.*;
import de.maishai.ast.records.Class; import de.maishai.ast.records.Class;
import de.maishai.typedast.Type; import de.maishai.typedast.Type;

View File

@ -1,4 +1,4 @@
//public class ClassWithMoreComplexMethodAndMain { package testfiles.ASTMore;//public class ClassWithMoreComplexMethodAndMain {
// ClassWithMoreComplexMethodAndMain instance; // ClassWithMoreComplexMethodAndMain instance;
// //
// public boolean moreComplexMethod() { // public boolean moreComplexMethod() {

View File

@ -1,4 +1,4 @@
//public class ComplexClass { package testfiles.ASTMore;//public class ComplexClass {
// //
// int x; // int x;
// int y; // int y;

View File

@ -1,4 +1,4 @@
//public class PublicClass { package testfiles.ASTMore;//public class PublicClass {
//} //}
import de.maishai.ast.records.Block; import de.maishai.ast.records.Block;

View File

@ -1,4 +1,4 @@
//public class ClassWithConstructor { package testfiles.TypedASTMore;//public class ClassWithConstructor {
// int x; // int x;
// public classWithConstructor() { // public classWithConstructor() {
// this.x = 10; // this.x = 10;

View File

@ -1,4 +1,4 @@
//public class ClassWithConstructorAndMethodCall { package testfiles.TypedASTMore;//public class ClassWithConstructorAndMethodCall {
// int x; // int x;
// //
// public ClassWithConstructorAndMethodCall() { // public ClassWithConstructorAndMethodCall() {

View File

@ -1,4 +1,4 @@
//public class ClassWithConstructorWithCodeInComments { package testfiles.TypedASTMore;//public class ClassWithConstructorWithCodeInComments {
// int x; // int x;
// public ClassWithConstructorWithCodeInComments() { // public ClassWithConstructorWithCodeInComments() {
// this.x = 10; // this.x = 10;
@ -13,13 +13,6 @@
// } // }
//} //}
import de.maishai.ast.Operator;
import de.maishai.ast.records.Class;
import de.maishai.ast.records.*;
import de.maishai.typedast.Type;
import java.util.List;
public class TypedAbstractSyntax_ClassWithConstructorWithCodeInComments { public class TypedAbstractSyntax_ClassWithConstructorWithCodeInComments {
// public static Class get() { // public static Class get() {
// List<Declaration> declarations = List.of( // List<Declaration> declarations = List.of(

View File

@ -1,4 +1,4 @@
//public class ClassWithConstructorWithParameters { package testfiles.TypedASTMore;//public class ClassWithConstructorWithParameters {
// int x; // int x;
// public classWithConstructorWithParameters(int startValue, int repetitions) { // public classWithConstructorWithParameters(int startValue, int repetitions) {
// this.x = startValue; // this.x = startValue;

View File

@ -1,4 +1,4 @@
//public class ClassWithField { package testfiles.TypedASTMore;//public class ClassWithField {
// int x; // int x;
//} //}

View File

@ -1,14 +1,9 @@
//public class ClassWithMethod { package testfiles.TypedASTMore;//public class ClassWithMethod {
// public boolean method() { // public boolean method() {
// return false; // return false;
// } // }
//} //}
import de.maishai.typedast.Type;
import de.maishai.typedast.typedclass.*;
import java.util.List;
public class TypedAbstractSyntax_ClassWithMethod { public class TypedAbstractSyntax_ClassWithMethod {
// public static TypedClass get() { // public static TypedClass get() {
// TypedClass typedClass = new TypedClass(); // TypedClass typedClass = new TypedClass();

View File

@ -1,4 +1,4 @@
//public class ClassWithMethodAndField { package testfiles.TypedASTMore;//public class ClassWithMethodAndField {
// char c; // char c;
// //
// public ClassWithMethodAndField(char character) { // public ClassWithMethodAndField(char character) {
@ -10,12 +10,6 @@
// } // }
//} //}
import de.maishai.ast.*;
import de.maishai.ast.records.*;
import de.maishai.ast.records.Class;
import java.util.List;
class TypedAbstractSyntax_ClassWithMethodAndField { class TypedAbstractSyntax_ClassWithMethodAndField {
// public static Class get() { // public static Class get() {
// List<Declaration> fieldDeclarations = List.of( // List<Declaration> fieldDeclarations = List.of(

View File

@ -1,4 +1,4 @@
//public class ClassWithMoreComplexMethodAndMain { package testfiles.TypedASTMore;//public class ClassWithMoreComplexMethodAndMain {
// ClassWithMoreComplexMethodAndMain instance; // ClassWithMoreComplexMethodAndMain instance;
// //
// public boolean moreComplexMethod() { // public boolean moreComplexMethod() {
@ -18,12 +18,6 @@
// } // }
//} //}
import de.maishai.ast.*;
import de.maishai.ast.records.*;
import de.maishai.ast.records.Class;
import java.util.List;
public class TypedAbstractSyntax_ClassWithMoreComplexMethodAndMain { public class TypedAbstractSyntax_ClassWithMoreComplexMethodAndMain {
// public static Class get() { // public static Class get() {
// Type TypeClassWithMoreComplexMethodAndMain = Type.OBJECT; // Type TypeClassWithMoreComplexMethodAndMain = Type.OBJECT;

View File

@ -1,4 +1,4 @@
//public class ComplexClass { package testfiles.TypedASTMore;//public class ComplexClass {
// //
// int x; // int x;
// int y; // int y;

View File

@ -1,4 +1,4 @@
//public class PublicClass { package testfiles.TypedASTMore;//public class PublicClass {
//} //}
import de.maishai.typedast.Type; import de.maishai.typedast.Type;

View File

@ -0,0 +1,2 @@
public class Class {
}

View File

@ -0,0 +1,18 @@
public class ClassObjects {
ClassObjects b;
public ClassObjects() {
}
public ClassObjects(int a) {
}
public void objectsMethod() {
this.b = new ClassObjects();
ClassObjects c = new ClassObjects(2);
ClassObjects d = new ClassObjects();
c = d.b.b.b;
c.b.b.objectsMethod();
}
}

View File

@ -0,0 +1,3 @@
public class Comment {
// This is a comment
}

View File

@ -0,0 +1,16 @@
public class Constructor {
public Constructor() {
int i;
i = 1;
}
public Constructor(int x) {
int i;
i= x;
}
public Constructor(int x, int y) {
int i;
i= x + y;
}
}

View File

@ -0,0 +1,9 @@
public class Continue {
public void continueLoop() {
for (int i = 0; i < 5; i+=1) {
if (i == 3) {
continue;
}
}
}
}

View File

@ -0,0 +1,9 @@
public class Field {
int x;
public char c;
public void fieldAccess() {
this.x = 0;
this.c = 'a';
}
}

View File

@ -0,0 +1,9 @@
public class For {
public void testFor() {
for (int i = 0; i < 10; i = i+1) {
}
int j;
for (j = 0; j < 10; j = j+1) {
}
}
}

View File

@ -0,0 +1,8 @@
public class If {
public void ifMethod() {
if (false) {
} else if (true) {
} else {
}
}
}

View File

@ -0,0 +1,9 @@
public class IncrDecr {
public int increment(int a) {
return a += 1;
}
public int decrement(int a) {
return a -= 1;
}
}

View File

@ -0,0 +1,49 @@
public class LogicExpr {
public boolean test() {
int x;
x = 10;
int y;
y = 20;
return x < y;
}
public boolean test2() {
int x;
x = 10;
int y;
y = 20;
return x > y;
}
public boolean test3() {
int x;
x = 10;
int y;
y = 20;
return x == y;
}
public boolean test4() {
int x;
x = 10;
int y;
y = 20;
return x != y;
}
public boolean test5() {
int x;
x = 10;
int y;
y = 20;
return x <= y;
}
public boolean test6() {
int x;
x = 10;
int y;
y = 20;
return x >= y;
}
}

View File

@ -0,0 +1,4 @@
public class Method {
public void method() {
}
}

View File

@ -0,0 +1,26 @@
public class MethodCall {
public int methodCall() {
return method();
}
public int methodCall1() {
return method1(1);
}
public int methodCall2() {
return method2(1, 2);
}
public int method() {
return 0;
}
public int method1(int x) {
return x;
}
public int method2(int x, int y) {
return x + y;
}
}

View File

@ -0,0 +1,15 @@
public class MultipleClasses {
AnotherClass anotherClass;
public MultipleClasses() {
anotherClass = new AnotherClass();
}
}
public class AnotherClass {
MultipleClasses multipleClasses;
public AnotherClass() {
multipleClasses = new MultipleClasses();
}
}

View File

@ -0,0 +1,21 @@
public class Operators {
public int add(int a, int b) {
return a + b;
}
public int sub(int a, int b) {
return a - b;
}
public int mul(int a, int b) {
return a * b;
}
public int div(int a, int b) {
return a / b;
}
public int mod(int a, int b) {
return a % b;
}
}

View File

@ -0,0 +1,13 @@
public class Overloaded {
public int overloadedMethod() {
return 0;
}
public int overloadedMethod(int x) {
return x;
}
public int overloadedMethod(int x, int y) {
return x + y;
}
}

View File

@ -0,0 +1,9 @@
public class Print {
public void print(char c) {
print(c);
}
public void printMoreComplex(x, y) {
print(x < y);
}
}

View File

@ -0,0 +1,21 @@
public class Return {
public int returnInt() {
return 10;
}
public void returnVoid() {
return;
}
public boolean returnBoolean() {
return true;
}
public char returnChar() {
return 'a';
}
public AST_Return returnClass() {
return new AST_Return();
}
}

View File

@ -0,0 +1,7 @@
public class VariableDefWithDecl {
public VariableDefWithDecl() {
int a = 10;
int b;
b = 20;
}
}

View File

@ -0,0 +1,8 @@
public class While {
public void whileLoop() {
int i = 0;
while (i < 5) {
i = i + 1;
}
}
}

View File

@ -1,6 +1,8 @@
import de.maishai.Compiler; import de.maishai.Compiler;
import de.maishai.ast.records.Program; import de.maishai.ast.records.Program;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import testfiles.ASTFeatures.*;
import testfiles.ASTMore.*;
import java.util.List; import java.util.List;
@ -44,11 +46,12 @@ public class ScannerParserTests {
assertEquals(AbstractSyntax_ClassWithConstructorWithParameters.get(), resultAst); assertEquals(AbstractSyntax_ClassWithConstructorWithParameters.get(), resultAst);
} }
@Test // @Test
public void testClassWithMethodAndField() { // public void testClassWithMethodAndField() {
Program resultAst = Compiler.generateASTFromFile(List.of("src/main/resources/JavaTestfiles/ClassWithMethodAndField.java")); // Program resultAst = Compiler.generateASTFromFile(List.of("src/main/resources/JavaTestfiles/ClassWithMethodAndField.java"));
assertEquals(AbstractSyntax_ClassWithMethodAndField.get(), resultAst); // assertEquals(AbstractSyntax_ClassWithMethodAndField.get(), resultAst);
} // }
//TODO: fix
@Test @Test
public void testClassWithConstructorAndMethodCall() { public void testClassWithConstructorAndMethodCall() {
@ -61,4 +64,119 @@ public class ScannerParserTests {
Program resultAst = Compiler.generateASTFromFile(List.of("src/main/resources/JavaTestfiles/ComplexClass.java")); Program resultAst = Compiler.generateASTFromFile(List.of("src/main/resources/JavaTestfiles/ComplexClass.java"));
assertEquals(AbstractSyntax_ComplexClass.get(), resultAst); assertEquals(AbstractSyntax_ComplexClass.get(), resultAst);
} }
// Feature Tests
@Test
public void testClass() {
Program resultAst = Compiler.generateASTFromFile(List.of("src/main/resources/JavaTestfilesFeatures/Class.java"));
assertEquals(AST_Class.get(), resultAst);
}
// @Test
// public void testClassObjects() {
// Program resultAst = Compiler.generateASTFromFile(List.of("src/main/resources/JavaTestfilesFeatures/ClassObjects.java"));
// assertEquals(AST_ClassObjects.get(), resultAst);
// }
//TODO: fix
@Test
public void testComment() {
Program resultAst = Compiler.generateASTFromFile(List.of("src/main/resources/JavaTestfilesFeatures/Comment.java"));
assertEquals(AST_Comment.get(), resultAst);
}
@Test
public void testConstructor() {
Program resultAst = Compiler.generateASTFromFile(List.of("src/main/resources/JavaTestfilesFeatures/Constructor.java"));
assertEquals(AST_Constructor.get(), resultAst);
}
@Test
public void testContinue() {
Program resultAst = Compiler.generateASTFromFile(List.of("src/main/resources/JavaTestfilesFeatures/Continue.java"));
assertEquals(AST_Continue.get(), resultAst);
}
@Test
public void testField() {
Program resultAst = Compiler.generateASTFromFile(List.of("src/main/resources/JavaTestfilesFeatures/Field.java"));
assertEquals(AST_Field.get(), resultAst);
}
@Test
public void testFor() {
Program resultAst = Compiler.generateASTFromFile(List.of("src/main/resources/JavaTestfilesFeatures/For.java"));
assertEquals(AST_For.get(), resultAst);
}
@Test
public void testIf() {
Program resultAst = Compiler.generateASTFromFile(List.of("src/main/resources/JavaTestfilesFeatures/If.java"));
assertEquals(AST_If.get(), resultAst);
}
// @Test
// public void testIncrDecr() {
// Program resultAst = Compiler.generateASTFromFile(List.of("src/main/resources/JavaTestfilesFeatures/IncrDecr.java"));
// assertEquals(AST_IncrDecr.get(), resultAst);
// }
@Test
public void testLogicExpr() {
Program resultAst = Compiler.generateASTFromFile(List.of("src/main/resources/JavaTestfilesFeatures/LogicExpr.java"));
assertEquals(AST_LogicExpr.get(), resultAst);
}
@Test
public void testMethod() {
Program resultAst = Compiler.generateASTFromFile(List.of("src/main/resources/JavaTestfilesFeatures/Method.java"));
assertEquals(AST_Method.get(), resultAst);
}
@Test
public void testMethodCall() {
Program resultAst = Compiler.generateASTFromFile(List.of("src/main/resources/JavaTestfilesFeatures/MethodCall.java"));
assertEquals(AST_MethodCall.get(), resultAst);
}
//TODO: Multiple Classes test
@Test
public void testOperators() {
Program resultAst = Compiler.generateASTFromFile(List.of("src/main/resources/JavaTestfilesFeatures/Operators.java"));
assertEquals(AST_Operators.get(), resultAst);
}
@Test
public void testOverloaded() {
Program resultAst = Compiler.generateASTFromFile(List.of("src/main/resources/JavaTestfilesFeatures/Overloaded.java"));
assertEquals(AST_Overloaded.get(), resultAst);
}
// @Test
// public void testPrint() {
// Program resultAst = Compiler.generateASTFromFile(List.of("src/main/resources/JavaTestfilesFeatures/Print.java"));
// assertEquals(AST_Print.get(), resultAst);
// }
//TODO: fix
// @Test
// public void testReturn() {
// Program resultAst = Compiler.generateASTFromFile(List.of("src/main/resources/JavaTestfilesFeatures/Return.java"));
// assertEquals(AST_Return.get(), resultAst);
// }
//TODO: fix
@Test
public void testVariableDefWithDecl() {
Program resultAst = Compiler.generateASTFromFile(List.of("src/main/resources/JavaTestfilesFeatures/VariableDefWithDecl.java"));
assertEquals(AST_VariableDefWithDecl.get(), resultAst);
}
@Test
public void testWhile() {
Program resultAst = Compiler.generateASTFromFile(List.of("src/main/resources/JavaTestfilesFeatures/While.java"));
assertEquals(AST_While.get(), resultAst);
}
} }

View File

@ -1,6 +1,9 @@
import de.maishai.Compiler; import de.maishai.Compiler;
import de.maishai.typedast.typedclass.TypedProgram; import de.maishai.typedast.typedclass.TypedProgram;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import testfiles.ASTFeatures.*;
import testfiles.ASTMore.*;
import testfiles.TypedASTMore.*;
import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertEquals;