From d26cd0c13a86c6c0507cadebce909debdf10156a Mon Sep 17 00:00:00 2001 From: i22035 Date: Tue, 2 Jul 2024 17:57:48 +0200 Subject: [PATCH] For Test --- src/test/java/parser/AstBuilderTest.java | 45 +++++++++++++++++------- 1 file changed, 32 insertions(+), 13 deletions(-) diff --git a/src/test/java/parser/AstBuilderTest.java b/src/test/java/parser/AstBuilderTest.java index b163a2a..0d00bde 100644 --- a/src/test/java/parser/AstBuilderTest.java +++ b/src/test/java/parser/AstBuilderTest.java @@ -5,6 +5,8 @@ import ast.ASTNode; import ast.ClassNode; import ast.ProgramNode; import ast.expressions.IExpressionNode; +import ast.expressions.binaryexpressions.EnumNonCalculationOperator; +import ast.expressions.binaryexpressions.NonCalculationNode; import ast.expressions.unaryexpressions.MemberAccessNode; import ast.expressions.unaryexpressions.UnaryNode; import ast.members.ConstructorNode; @@ -14,10 +16,10 @@ import ast.members.MethodNode; import ast.parameters.ParameterNode; import ast.statementexpressions.AssignNode; import ast.statementexpressions.AssignableNode; +import ast.statementexpressions.crementexpressions.CrementType; +import ast.statementexpressions.crementexpressions.IncrementNode; import ast.statementexpressions.methodcallstatementnexpressions.MethodCallNode; -import ast.statements.BlockNode; -import ast.statements.IStatementNode; -import ast.statements.ReturnNode; +import ast.statements.*; import ast.type.AccessModifierNode; import ast.type.EnumValueNode; import ast.type.ValueNode; @@ -384,21 +386,37 @@ class AstBuilderTest { @Test @DisplayName("For Test") public void forTest(){ + LocalVariableDeclarationNode forDeclaration = new LocalVariableDeclarationNode(new BaseType(TypeEnum.INT), "i", "=", new UnaryNode(new ValueNode(EnumValueNode.INT_VALUE, "0"))); - //assertThat(actual).isEqualToComparingFieldByFieldRecursively(expected); - } + NonCalculationNode condition = new NonCalculationNode(new UnaryNode("i"), "<", new UnaryNode(new ValueNode(EnumValueNode.INT_VALUE, "10"))); + AssignableNode assignable = new AssignableNode("i"); + IncrementNode increment = new IncrementNode(CrementType.SUFFIX, assignable); - //Noch nicht speziell Increment nur zum Development Testen per Debug - @Test - @DisplayName("Increment Test") - public void incrementTest(){ - ClassNode classNode = Helper.generateEmptyClass("TestClass"); - classNode.addMember(new FieldNode(new AccessModifierNode("public"), new BaseType(TypeEnum.INT), "a")); + LocalVariableDeclarationNode declaration = new LocalVariableDeclarationNode(new BaseType(TypeEnum.INT), "a", null, null); + + BlockNode whileBlock = new BlockNode(); + whileBlock.addStatement(declaration); + whileBlock.addStatement(increment); + + WhileNode whileStatement = new WhileNode(condition, whileBlock); + + BlockNode forStatement = new BlockNode(); + forStatement.addStatement(forDeclaration); + forStatement.addStatement(whileStatement); + + BlockNode blockCon = new BlockNode(); + blockCon.addStatement(forStatement); + blockCon.addStatement(new ReturnNode(null)); + ConstructorNode constructor = new ConstructorNode("public", "TestClass", blockCon); + + ClassNode class1 = new ClassNode("public", "TestClass"); + class1.addMember(constructor); ProgramNode expected = new ProgramNode(); - expected.addClass(classNode); + expected.addClass(class1); + + ASTNode actual = Helper.generateAST("src/test/resources/input/javaCases/For.java"); - ASTNode actual = Helper.generateAST("src/test/resources/input/javaCases/Increment.java"); assertThat(actual).isEqualToComparingFieldByFieldRecursively(expected); } @@ -413,4 +431,5 @@ class AstBuilderTest { + } \ No newline at end of file