Skip to content

Commit

Permalink
(WIP) add unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Godin committed Dec 15, 2023
1 parent d553db6 commit b653a9b
Showing 1 changed file with 109 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -219,4 +219,113 @@ public void should_filter_methods_with_parameters_that_consume_two_slots() {
assertIgnored(new Range(m.instructions.get(3), m.instructions.get(3)));
}

/**
* <pre>
* class C(
* p1: Int,
* ...
* p31: Int,
* p32: Int = 42,
* p33: Int,
* )
* </pre>
*
* This constructor will have 2 additional parameters containing the mask.
*/
@Test
public void should_filter_methods_with_more_than_32_parameters() {
final StringBuilder paramTypes = new StringBuilder();
for (int i = 1; i <= 33; i++) {
paramTypes.append("I");
}
final MethodNode m = new MethodNode(InstrSupport.ASM_API_VERSION,
Opcodes.ACC_SYNTHETIC, "<init>",
"(" + paramTypes
+ "IILkotlin/jvm/internal/DefaultConstructorMarker;)V",
null, null);
context.classAnnotations
.add(KotlinGeneratedFilter.KOTLIN_METADATA_DESC);

m.visitVarInsn(Opcodes.ILOAD, 34);
m.visitLdcInsn(1 << 31);
m.visitInsn(Opcodes.IAND);
final Label label = new Label();
m.visitJumpInsn(Opcodes.IFEQ, label);
// default argument
m.visitLdcInsn(Integer.valueOf(42));
m.visitVarInsn(Opcodes.ISTORE, 32);
m.visitLabel(label);

m.visitVarInsn(Opcodes.ALOAD, 0);
for (int i = 1; i <= 33; i++) {
m.visitVarInsn(Opcodes.ILOAD, i);
}
m.visitMethodInsn(Opcodes.INVOKESPECIAL, "Owner", "<init>",
"(" + paramTypes + ")V", false);
m.visitInsn(Opcodes.RETURN);

filter.filter(m, context, output);

assertIgnored(new Range(m.instructions.get(3), m.instructions.get(3)));
}

/**
* <pre>
* class C(
* p1: Int = 42,
* ...
* p225: Int,
* )
* </pre>
*
* This constructor will have 8 additional parameters containing the mask.
*
* 9 additional parameters will be required for methods with more than 256
* parameters, but according to Java Virtual Machine Specification <a href=
* "https://docs.oracle.com/javase/specs/jvms/se8/html/jvms-4.html#jvms-4.11">
* §4.11</a>:
*
* <blockquote>
* <p>
* The number of method parameters is limited to 255
* </p>
* </blockquote>
*/
@Test
public void should_filter_methods_with_more_than_224_parameters() {
final StringBuilder paramTypes = new StringBuilder();
for (int i = 1; i <= 225; i++) {
paramTypes.append("I");
}
final MethodNode m = new MethodNode(InstrSupport.ASM_API_VERSION,
Opcodes.ACC_SYNTHETIC, "<init>",
"(" + paramTypes
+ "IIIIIIIILkotlin/jvm/internal/DefaultConstructorMarker;)V",
null, null);
context.classAnnotations
.add(KotlinGeneratedFilter.KOTLIN_METADATA_DESC);

m.visitVarInsn(Opcodes.ILOAD, 226);
m.visitInsn(Opcodes.ICONST_1);
m.visitInsn(Opcodes.IAND);
final Label label = new Label();
m.visitJumpInsn(Opcodes.IFEQ, label);
// default argument
m.visitLdcInsn(Integer.valueOf(42));
m.visitVarInsn(Opcodes.ISTORE, 1);
m.visitLabel(label);

m.visitVarInsn(Opcodes.ALOAD, 0);
for (int i = 1; i <= 225; i++) {
m.visitVarInsn(Opcodes.ILOAD, i);
}
m.visitMethodInsn(Opcodes.INVOKESPECIAL, "Owner", "<init>",
"(" + paramTypes + ")V", false);
m.visitInsn(Opcodes.RETURN);

filter.filter(m, context, output);

assertIgnored(new Range(m.instructions.get(3), m.instructions.get(3)));
}

}

0 comments on commit b653a9b

Please sign in to comment.