Adding Test Cases
This commit is contained in:
parent
dcd20a2394
commit
f414e278bb
@ -14,29 +14,21 @@ import ast.members.MethodNode;
|
||||
import ast.parameters.ParameterNode;
|
||||
import ast.statementexpressions.AssignNode;
|
||||
import ast.statementexpressions.AssignableNode;
|
||||
import ast.statementexpressions.NewDeclarationNode;
|
||||
import ast.statementexpressions.methodcallstatementnexpressions.MethodCallNode;
|
||||
import ast.statementexpressions.methodcallstatementnexpressions.TargetNode;
|
||||
import ast.statements.BlockNode;
|
||||
import ast.statements.IStatementNode;
|
||||
import ast.statements.LocalVariableDeclarationNode;
|
||||
import ast.statements.ReturnNode;
|
||||
import ast.type.AccessModifierNode;
|
||||
import ast.type.EnumValueNode;
|
||||
import ast.type.ValueNode;
|
||||
import ast.type.type.BaseType;
|
||||
import ast.type.type.ITypeNode;
|
||||
import ast.type.type.ReferenceType;
|
||||
import ast.type.type.TypeEnum;
|
||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||
import org.antlr.v4.runtime.CharStream;
|
||||
import org.antlr.v4.runtime.CharStreams;
|
||||
import org.antlr.v4.runtime.CommonTokenStream;
|
||||
import org.antlr.v4.runtime.tree.ParseTree;
|
||||
|
||||
import org.junit.jupiter.api.DisplayName;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import parser.astBuilder.ASTBuilder;
|
||||
import parser.generated.SimpleJavaLexer;
|
||||
import parser.generated.SimpleJavaParser;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.lang.reflect.Member;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
@ -343,7 +335,38 @@ class AstBuilderTest {
|
||||
@DisplayName("Self Reference Test")
|
||||
public void selfReferneceTest(){
|
||||
|
||||
//assertThat(actual).isEqualToComparingFieldByFieldRecursively(expected);
|
||||
ClassNode testClass = Helper.generateEmptyClass("TestClass");
|
||||
|
||||
MemberNode testClassObject = new FieldNode(new AccessModifierNode("public"), new ReferenceType("TestClass"),"testClass");
|
||||
|
||||
BlockNode testMethod1Block = new BlockNode();
|
||||
testMethod1Block.addStatement(new ReturnNode(new UnaryNode(new MethodCallNode(new TargetNode(true), "testMethod2"))));
|
||||
MethodNode testMethod1 = new MethodNode("public", new BaseType(TypeEnum.INT), false, "testMethod1", testMethod1Block);
|
||||
|
||||
BlockNode testMethod2Block = new BlockNode();
|
||||
testMethod2Block.addStatement(new ReturnNode(new UnaryNode(new ValueNode(EnumValueNode.INT_VALUE,"1"))));
|
||||
MethodNode testMethod2 = new MethodNode("public", new BaseType(TypeEnum.INT), false, "testMethod2", testMethod2Block);
|
||||
|
||||
BlockNode testMethod3Block = new BlockNode();
|
||||
testMethod3Block.addStatement(new LocalVariableDeclarationNode(new ReferenceType("TestClass"),"testClass1", "=", new UnaryNode(new NewDeclarationNode("TestClass")))); // Assing einfach "=" ?
|
||||
MemberAccessNode methodAccess = new MemberAccessNode(false);
|
||||
methodAccess.addIdentifier("testClass1");
|
||||
methodAccess.addIdentifier("testClass");
|
||||
TargetNode methodTarget = new TargetNode(methodAccess);
|
||||
testMethod3Block.addStatement(new ReturnNode(new UnaryNode(new MethodCallNode(methodTarget,"testMethod1"))));
|
||||
MethodNode testMethod3 = new MethodNode("public", new BaseType(TypeEnum.INT), false, "testMethod3", testMethod3Block);
|
||||
|
||||
testClass.addMember(testClassObject);
|
||||
testClass.addMember(testMethod1);
|
||||
testClass.addMember(testMethod2);
|
||||
testClass.addMember(testMethod3);
|
||||
|
||||
ProgramNode expected = new ProgramNode();
|
||||
expected.addClass(testClass);
|
||||
|
||||
ASTNode actual = Helper.generateAST("src/test/resources/input/javaCases/SelfReference.java");
|
||||
|
||||
assertThat(actual).isEqualToComparingFieldByFieldRecursively(expected);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -3,14 +3,14 @@ class TestClass{
|
||||
TestClass testClass;
|
||||
|
||||
int testMethod1() {
|
||||
return this.testMethod2()
|
||||
return this.testMethod2();
|
||||
}
|
||||
|
||||
int testMethod2() {
|
||||
return 1;
|
||||
}
|
||||
|
||||
int testMehtod3(){
|
||||
int testMethod3(){
|
||||
TestClass testClass1 = new TestClass();
|
||||
return testClass1.testClass.testMethod1();
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user