diff --git a/src/test/java/testResources/CodeGen/Features/ByteCode_Constructor.java b/src/test/java/testResources/CodeGen/Features/ByteCode_Constructor.java index a77f5d5..48bfaf2 100644 --- a/src/test/java/testResources/CodeGen/Features/ByteCode_Constructor.java +++ b/src/test/java/testResources/CodeGen/Features/ByteCode_Constructor.java @@ -3,157 +3,34 @@ package testResources.CodeGen.Features; import de.maishai.ast.Operator; import de.maishai.typedast.Type; import de.maishai.typedast.typedclass.*; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import testResources.CodeGen.BytecodeTestUtil; import java.util.List; public class ByteCode_Constructor { - public static TypedProgram get() { - return new TypedProgram( - List.of( - new TypedClass( - "Constructor", - List.of(), - List.of(), - List.of( - new TypedConstructor( - "Constructor", - List.of(), - new TypedBlock( - List.of( - new TypedLocalVariable( - "i", - Type.INT - ) - ), - List.of( - new TypedAssignment( - new TypedIntLiteral( - 1, - Type.INT), - new TypedFieldVarAccess( - false, - null, - "i", - Type.INT - ), - Type.INT - ) - ), - Type.VOID - ), - Type.VOID, - List.of() - ), - new TypedConstructor( - "Constructor", - List.of( - new TypedParameter( - "x", - Type.INT - ) - ), - new TypedBlock( - List.of( - new TypedLocalVariable( - "i", - Type.INT - ) - ), - List.of( - new TypedAssignment( - new TypedFieldVarAccess( - false, - null, - "x", - Type.INT - ), - new TypedFieldVarAccess( - false, - null, - "i", - Type.INT - ), - Type.INT - ) - ), - Type.VOID - ), - Type.VOID, - List.of( - new TypedLocalVariable( - "x", - Type.INT - ) - ) - ), - new TypedConstructor( - "Constructor", - List.of( - new TypedParameter( - "x", - Type.INT - ), - new TypedParameter( - "y", - Type.INT - ) - ), - new TypedBlock( - List.of( - new TypedLocalVariable( - "i", - Type.INT - ) - ), - List.of( - new TypedAssignment( - new TypedBinary( - new TypedFieldVarAccess( - false, - null, - "x", - Type.INT - ), - Operator.ADD, - new TypedFieldVarAccess( - false, - null, - "y", - Type.INT - ), - Type.INT - ), - new TypedFieldVarAccess( - false, - null, - "i", - Type.INT - ), - Type.INT - ) - ), - Type.VOID - ), - Type.VOID, - List.of( - new TypedLocalVariable( - "x", - Type.INT - ), - new TypedLocalVariable( - "y", - Type.INT - ) - ) - ) - ), - null, - null, - null, - Type.REFERENCE("Constructor") - ) - ), - null - ); + + private BytecodeTestUtil util; + + @BeforeEach + public void setUp() { + try { + util = new BytecodeTestUtil(List.of("src/test/testFiles/CodeGenFeatures/Constructor.java"), "Constructor"); + } catch (Exception e) { + throw new RuntimeException(e); + } + } + + @Test + public void testConstructorCount() { + Assertions.assertEquals(3, util.getConstructorCount()); + } + + @Test + public void testConstructor1() { + Assertions.assertEquals("Constructor", util.getConstructorNames().get(0)); + Assertions.assertEquals(0, util.getConstructorParameterCount(0)); } } \ No newline at end of file diff --git a/src/test/testFiles/CodeGenFeatures/Constructor.java b/src/test/testFiles/CodeGenFeatures/Constructor.java index 4262853..7b2f7a9 100644 --- a/src/test/testFiles/CodeGenFeatures/Constructor.java +++ b/src/test/testFiles/CodeGenFeatures/Constructor.java @@ -2,17 +2,14 @@ public class Constructor { int i; public Constructor() { - this.i; - i = 1; + this.i = 1; } - public Constructor(this.x) { - this.i; - i= x; + public Constructor(int x) { + this.i= x; } - public Constructor(this.x, this.y) { - this.i; - i= x + y; + public Constructor(int x, int y) { + this.i= x + y; } } \ No newline at end of file