Add test on bytecode text

Test data should be a Kotlin source file with zero or more comments e.g. of
the form: '// 1 INVOKEVIRTUAL'. The test then checks that the generated
bytecode for this file contains exactly one occurrence of the string
'INVOKEVIRTUAL'
This commit is contained in:
Alexander Udalov
2013-02-09 21:44:33 +04:00
parent fe96a0172d
commit 620143ae5b
23 changed files with 259 additions and 169 deletions
@@ -0,0 +1,19 @@
class S(val a: String, val b: String) {
fun component1() : String = a
fun component2() : String = b
}
fun S.component3() = ((a + b) as java.lang.String).substring(2)
class Tester() {
fun box() : String {
val (o,k,ok,ok2) = S("O","K")
return o + k + ok + ok2
}
fun S.component4() = ((a + b) as java.lang.String).substring(2)
}
fun box() = Tester().box()
// 1 NEW S
@@ -0,0 +1,3 @@
fun foo() = 10!!.toString()
// 0 IFNONNULL
@@ -0,0 +1,5 @@
val a : Int? = 10
fun foo() = a!!.toString()
// 1 IFNONNULL
@@ -0,0 +1,5 @@
val a : Int? = 10
fun foo() = a?.toString()
// 1 IFNULL
@@ -0,0 +1,3 @@
fun foo() = 10?.toString()
// 0 IFNULL
@@ -0,0 +1,21 @@
// KT-2202 Wrong instruction for invoke private setter
class A {
private fun f1() {}
fun foo() {
f1()
}
}
class B {
var foo = 1
private set
fun foo() {
foo = 2
}
}
// 0 INVOKEVIRTUAL
// 4 INVOKESPECIAL
@@ -0,0 +1,17 @@
open class Base<T> {
public open fun foo(t: T): T = t
public open fun bar() {}
}
class Child: Base<String>() {
override fun foo(t: String): String {
return super<Base>.foo(t)
}
override fun bar() {
super.bar()
}
}
// 1 bridge
@@ -0,0 +1,16 @@
// Check that this code doesn't contains INVOKEVIRTUAL instruction
class B {
private fun foo(i: Int = 1) {
}
fun f() {
foo(2)
}
}
fun box(): String {
return "OK"
}
// 0 INVOKEVIRTUAL
// 3 INVOKESPECIAL
@@ -0,0 +1,11 @@
fun foo() {
if (0 < 1) {
return
}
if (1 < 2) else {
return
}
}
// 0 GETSTATIC
@@ -0,0 +1,11 @@
fun z(b: Boolean) {}
fun foo(b: Boolean) {
if (b) {
z(b)
} else {
z(b)
}
}
// 0 GETSTATIC
@@ -0,0 +1,7 @@
fun foo(b: Boolean) {
if (b) {
} else {
}
}
// 0 GETSTATIC
@@ -0,0 +1,25 @@
fun z() {}
fun foo() {
try {
z()
} catch (e: Exception) {
z()
}
try {
z()
} finally {
z()
}
try {
z()
} catch (e: Exception) {
z()
} finally {
z()
}
}
// 0 GETSTATIC
@@ -0,0 +1,11 @@
fun z() {}
fun foo(x: Int) {
when {
x == 21 -> z()
x == 42 -> z()
else -> {}
}
}
// 0 GETSTATIC
@@ -0,0 +1,11 @@
fun z() {}
fun foo(x: Int) {
when (x) {
21 -> z()
42 -> z()
else -> {}
}
}
// 0 GETSTATIC