Added some tests
This commit is contained in:
parent
c535d7a231
commit
e2c874937c
2 changed files with 37 additions and 4 deletions
|
|
@ -0,0 +1,13 @@
|
|||
package nl.sander.beejava;
|
||||
|
||||
import nl.sander.beejava.api.BeeClass;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
public class ConstantPoolUniquenessTests {
|
||||
@Test
|
||||
public void test(){
|
||||
BeeClass someClass = TestData.createClassWithTwoReferencesToSomeClass();
|
||||
CompiledClass compiledClass = Compiler.compile(someClass);
|
||||
BytecodeGenerator.generate(compiledClass);
|
||||
}
|
||||
}
|
||||
|
|
@ -34,6 +34,26 @@ public class TestData {
|
|||
.build();
|
||||
}
|
||||
|
||||
public static BeeClass createClassWithTwoReferencesToSomeClass() {
|
||||
BeeMethod print1 = BeeMethod.builder()
|
||||
.withAccessFlags(MethodAccessFlag.PUBLIC)
|
||||
.withCode(
|
||||
line(0, GET, "java.lang.System","out"),
|
||||
line(1, LD_CONST, "1"),
|
||||
line(2, INVOKE, "java.io.PrintStream", "println", "(java.lang.String)"),
|
||||
line(3, RETURN))
|
||||
.build();
|
||||
|
||||
return BeeClass.builder()
|
||||
.withClassFileVersion(Version.V14)
|
||||
.withPackage("nl.sander.beejava.test")
|
||||
.withAccessFlags(PUBLIC)
|
||||
.withSimpleName("ClassWithReferences")
|
||||
.withConstructors(createConstructor()) // There's no default constructor in beejava. The user must always add them
|
||||
.withMethods(print1)
|
||||
.build();
|
||||
}
|
||||
|
||||
public static BeeClass createClassWithIntField() {
|
||||
BeeField intField = BeeField.builder()
|
||||
.withAccessFlags(FieldAccessFlag.PRIVATE)
|
||||
|
|
@ -47,10 +67,10 @@ public class TestData {
|
|||
.withAccessFlags(MethodAccessFlag.PUBLIC)
|
||||
.withFormalParameters(intValueParameter)
|
||||
.withCode(
|
||||
line(0, LOAD, Ref.THIS),
|
||||
line(0, LD_VAR, Ref.THIS),
|
||||
line(1, INVOKE, Ref.SUPER, "<init>", "()"),
|
||||
line(2, LOAD, Ref.THIS),
|
||||
line(3, LOAD, intValueParameter),
|
||||
line(2, LD_VAR, Ref.THIS),
|
||||
line(3, LD_VAR, intValueParameter),
|
||||
line(4, PUT, intField),
|
||||
line(5, RETURN))
|
||||
.build();
|
||||
|
|
@ -70,7 +90,7 @@ public class TestData {
|
|||
return BeeConstructor.builder()
|
||||
.withAccessFlags(MethodAccessFlag.PUBLIC)
|
||||
.withCode(
|
||||
line(0, LOAD, Ref.THIS),
|
||||
line(0, LD_VAR, Ref.THIS),
|
||||
line(1, INVOKE, Ref.SUPER, "<init>", "()"),
|
||||
line(5, RETURN))
|
||||
.build();
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue