added some e2e tests for CodeGenFiles with reflections

This commit is contained in:
JonathanFleischmann 2024-06-27 19:24:27 +02:00
parent 78a34b915e
commit 2029f496ce
2 changed files with 30 additions and 156 deletions

View File

@ -3,157 +3,34 @@ package testResources.CodeGen.Features;
import de.maishai.ast.Operator; import de.maishai.ast.Operator;
import de.maishai.typedast.Type; import de.maishai.typedast.Type;
import de.maishai.typedast.typedclass.*; 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; import java.util.List;
public class ByteCode_Constructor { public class ByteCode_Constructor {
public static TypedProgram get() {
return new TypedProgram( private BytecodeTestUtil util;
List.of(
new TypedClass( @BeforeEach
"Constructor", public void setUp() {
List.of(), try {
List.of(), util = new BytecodeTestUtil(List.of("src/test/testFiles/CodeGenFeatures/Constructor.java"), "Constructor");
List.of( } catch (Exception e) {
new TypedConstructor( throw new RuntimeException(e);
"Constructor", }
List.of(), }
new TypedBlock(
List.of( @Test
new TypedLocalVariable( public void testConstructorCount() {
"i", Assertions.assertEquals(3, util.getConstructorCount());
Type.INT }
)
), @Test
List.of( public void testConstructor1() {
new TypedAssignment( Assertions.assertEquals("Constructor", util.getConstructorNames().get(0));
new TypedIntLiteral( Assertions.assertEquals(0, util.getConstructorParameterCount(0));
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
);
} }
} }

View File

@ -2,17 +2,14 @@ public class Constructor {
int i; int i;
public Constructor() { public Constructor() {
this.i; this.i = 1;
i = 1;
} }
public Constructor(this.x) { public Constructor(int x) {
this.i; this.i= x;
i= x;
} }
public Constructor(this.x, this.y) { public Constructor(int x, int y) {
this.i; this.i= x + y;
i= x + y;
} }
} }