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.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));
}
}

View File

@ -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;
}
}