backend/tests: Add blackbox tests from Kotlin JVM

Added tests from testData/codegen/box directory. There are blackbox tests
in other directories and they are to be added.
This commit is contained in:
Ilya Matveev
2017-01-12 19:43:20 +07:00
parent d5988297b1
commit 1b553ebfaf
2643 changed files with 66666 additions and 0 deletions
@@ -0,0 +1,53 @@
// TODO: investigate should it be ran for JS or not
// IGNORE_BACKEND: JS
// WITH_REFLECT
import kotlin.reflect.*
import kotlin.test.assertEquals
class Host {
companion object {
val x = 1
var y = 2
val xx: Int
get() = x
var yy: Int
get() = y
set(value) { y = value }
}
}
val c_x = Host.Companion::x
val c_xx = Host.Companion::xx
val c_y = Host.Companion::y
val c_yy = Host.Companion::yy
fun box(): String {
assertEquals(1, c_x.getter())
assertEquals(1, c_x.getter.call())
assertEquals(1, c_xx.getter())
assertEquals(1, c_xx.getter.call())
assertEquals(2, c_y.getter())
assertEquals(2, c_y.getter.call())
assertEquals(2, c_yy.getter())
assertEquals(2, c_yy.getter.call())
c_y.setter(10)
assertEquals(10, c_y.getter())
assertEquals(10, c_yy.getter())
c_yy.setter(20)
assertEquals(20, c_y.getter())
assertEquals(20, c_yy.getter())
c_y.setter.call(100)
assertEquals(100, c_yy.getter.call())
c_yy.setter.call(200)
assertEquals(200, c_y.getter.call())
return "OK"
}
@@ -0,0 +1,12 @@
// TODO: investigate should it be ran for JS or not
// IGNORE_BACKEND: JS
// WITH_REFLECT
import kotlin.reflect.*
fun String.foo(x: String) = this + x
fun String?.bar(x: String) = x
fun box() =
(""::foo).call("O") + (null::bar).call("K")
@@ -0,0 +1,45 @@
// TODO: investigate should it be ran for JS or not
// IGNORE_BACKEND: JS
// WITH_REFLECT
import kotlin.reflect.*
import kotlin.test.assertEquals
class C(val x: Int, var y: Int)
val C.xx: Int
get() = x
var C.yy: Int
get() = y
set(value) { y = value }
val c = C(1, 2)
val c_xx = c::xx
val c_y = c::y
val c_yy = c::yy
fun box(): String {
assertEquals(1, c_xx.getter())
assertEquals(1, c_xx.getter.call())
assertEquals(2, c_yy.getter())
assertEquals(2, c_yy.getter.call())
c_y.setter(10)
assertEquals(10, c_yy.getter())
c_yy.setter(20)
assertEquals(20, c_y.getter())
assertEquals(20, c_yy.getter())
c_y.setter.call(100)
assertEquals(100, c_yy.getter.call())
c_yy.setter.call(200)
assertEquals(200, c_y.getter.call())
return "OK"
}
@@ -0,0 +1,16 @@
// TODO: investigate should it be ran for JS or not
// IGNORE_BACKEND: JS
// WITH_REFLECT
class Outer(val x: String) {
inner class Inner(val y: String) {
fun foo() = x + y
}
}
fun box(): String {
val innerCtor = Outer("O")::Inner
val inner = innerCtor.call("K")
return inner.foo()
}
@@ -0,0 +1,40 @@
// TODO: investigate should it be ran for JS or not
// IGNORE_BACKEND: JS
// WITH_REFLECT
// FILE: J.java
public class J {
public final int finalField;
public String mutableField;
public J(int f, String m) {
this.finalField = f;
this.mutableField = m;
}
}
// FILE: K.kt
import kotlin.reflect.*
import kotlin.reflect.jvm.*
import kotlin.test.assertEquals
fun box(): String {
val j = J(0, "")
val jf = j::finalField
val jm = j::mutableField
assertEquals(0, jf.getter())
assertEquals(0, jf.getter.call())
assertEquals("", jm.getter())
assertEquals("", jm.getter.call())
jm.setter("1")
assertEquals("1", j.mutableField)
jm.setter.call("2")
assertEquals("2", j.mutableField)
return "OK"
}
@@ -0,0 +1,35 @@
// TODO: investigate should it be ran for JS or not
// IGNORE_BACKEND: JS
// WITH_REFLECT
// FILE: J.java
public class J {
private final int param;
public J(int param) {
this.param = param;
}
public String foo(int[] arr, Object[] arr2, Integer y) {
return "" + param + arr[0] + arr2[0] + y;
}
}
// FILE: K.kt
import kotlin.reflect.*
import kotlin.reflect.jvm.*
import kotlin.test.assertEquals
fun box(): String {
val f = J(0)::foo
assertEquals(
listOf(IntArray::class.java, Array<Any>::class.java, Integer::class.java),
f.parameters.map { it.type.javaType }
)
assertEquals(String::class.java, f.returnType.javaType)
assertEquals("01A2", f.call(intArrayOf(1), arrayOf("A"), 2))
return "OK"
}
@@ -0,0 +1,53 @@
// TODO: investigate should it be ran for JS or not
// IGNORE_BACKEND: JS
// WITH_REFLECT
import kotlin.reflect.*
import kotlin.test.assertEquals
class Host {
companion object {
@JvmStatic val x = 1
@JvmStatic var y = 2
@JvmStatic val xx: Int
get() = x
@JvmStatic var yy: Int
get() = y
set(value) { y = value }
}
}
val c_x = Host.Companion::x
val c_xx = Host.Companion::xx
val c_y = Host.Companion::y
val c_yy = Host.Companion::yy
fun box(): String {
assertEquals(1, c_x.getter())
assertEquals(1, c_x.getter.call())
assertEquals(1, c_xx.getter())
assertEquals(1, c_xx.getter.call())
assertEquals(2, c_y.getter())
assertEquals(2, c_y.getter.call())
assertEquals(2, c_yy.getter())
assertEquals(2, c_yy.getter.call())
c_y.setter(10)
assertEquals(10, c_y.getter())
assertEquals(10, c_yy.getter())
c_yy.setter(20)
assertEquals(20, c_y.getter())
assertEquals(20, c_yy.getter())
c_y.setter.call(100)
assertEquals(100, c_yy.getter.call())
c_yy.setter.call(200)
assertEquals(200, c_y.getter.call())
return "OK"
}
@@ -0,0 +1,19 @@
// TODO: investigate should it be ran for JS or not
// IGNORE_BACKEND: JS
// WITH_REFLECT
import kotlin.reflect.*
object Host {
@JvmStatic fun foo(x: String) = x
}
class CompanionOwner {
companion object {
@JvmStatic fun bar(x: String) = x
}
}
fun box(): String =
(Host::foo).call("O") + (CompanionOwner.Companion::bar).call("K")
@@ -0,0 +1,51 @@
// TODO: investigate should it be ran for JS or not
// IGNORE_BACKEND: JS
// WITH_REFLECT
import kotlin.reflect.*
import kotlin.test.assertEquals
object Host {
@JvmStatic val x = 1
@JvmStatic var y = 2
@JvmStatic val xx: Int
get() = x
@JvmStatic var yy: Int
get() = y
set(value) { y = value }
}
val c_x = Host::x
val c_xx = Host::xx
val c_y = Host::y
val c_yy = Host::yy
fun box(): String {
assertEquals(1, c_x.getter())
assertEquals(1, c_x.getter.call())
assertEquals(1, c_xx.getter())
assertEquals(1, c_xx.getter.call())
assertEquals(2, c_y.getter())
assertEquals(2, c_y.getter.call())
assertEquals(2, c_yy.getter())
assertEquals(2, c_yy.getter.call())
c_y.setter(10)
assertEquals(10, c_y.getter())
assertEquals(10, c_yy.getter())
c_yy.setter(20)
assertEquals(20, c_y.getter())
assertEquals(20, c_yy.getter())
c_y.setter.call(100)
assertEquals(100, c_yy.getter.call())
c_yy.setter.call(200)
assertEquals(200, c_y.getter.call())
return "OK"
}
@@ -0,0 +1,14 @@
// TODO: investigate should it be ran for JS or not
// IGNORE_BACKEND: JS
// WITH_REFLECT
import kotlin.reflect.*
class C(val k: String) {
fun foo(s: String) = s + k
}
fun box(): String =
C("K")::foo.call("O")
@@ -0,0 +1,50 @@
// TODO: investigate should it be ran for JS or not
// IGNORE_BACKEND: JS
// WITH_REFLECT
import kotlin.reflect.*
import kotlin.test.assertEquals
class C(val x: Int, var y: Int) {
val xx: Int
get() = x
var yy: Int
get() = y
set(value) { y = value }
}
val c = C(1, 2)
val c_x = c::x
val c_xx = c::xx
val c_y = c::y
val c_yy = c::yy
fun box(): String {
assertEquals(1, c_x.getter())
assertEquals(1, c_x.getter.call())
assertEquals(1, c_xx.getter())
assertEquals(1, c_xx.getter.call())
assertEquals(2, c_y.getter())
assertEquals(2, c_y.getter.call())
assertEquals(2, c_yy.getter())
assertEquals(2, c_yy.getter.call())
c_y.setter(10)
assertEquals(10, c_y.getter())
assertEquals(10, c_yy.getter())
c_yy.setter(20)
assertEquals(20, c_y.getter())
assertEquals(20, c_yy.getter())
c_y.setter.call(100)
assertEquals(100, c_yy.getter.call())
c_yy.setter.call(200)
assertEquals(200, c_y.getter.call())
return "OK"
}
@@ -0,0 +1,19 @@
// TODO: investigate should it be ran for JS or not
// IGNORE_BACKEND: JS
// WITH_REFLECT
import kotlin.reflect.*
object Host {
fun foo(x: String) = x
}
class CompanionOwner {
companion object {
fun bar(x: String) = x
}
}
fun box(): String =
(Host::foo).call("O") + (CompanionOwner.Companion::bar).call("K")
@@ -0,0 +1,51 @@
// TODO: investigate should it be ran for JS or not
// IGNORE_BACKEND: JS
// WITH_REFLECT
import kotlin.reflect.*
import kotlin.test.assertEquals
object Host {
val x = 1
var y = 2
val xx: Int
get() = x
var yy: Int
get() = y
set(value) { y = value }
}
val c_x = Host::x
val c_xx = Host::xx
val c_y = Host::y
val c_yy = Host::yy
fun box(): String {
assertEquals(1, c_x.getter())
assertEquals(1, c_x.getter.call())
assertEquals(1, c_xx.getter())
assertEquals(1, c_xx.getter.call())
assertEquals(2, c_y.getter())
assertEquals(2, c_y.getter.call())
assertEquals(2, c_yy.getter())
assertEquals(2, c_yy.getter.call())
c_y.setter(10)
assertEquals(10, c_y.getter())
assertEquals(10, c_yy.getter())
c_yy.setter(20)
assertEquals(20, c_y.getter())
assertEquals(20, c_yy.getter())
c_y.setter.call(100)
assertEquals(100, c_yy.getter.call())
c_yy.setter.call(200)
assertEquals(200, c_y.getter.call())
return "OK"
}
@@ -0,0 +1,35 @@
// TODO: muted automatically, investigate should it be ran for JS or not
// IGNORE_BACKEND: JS
// WITH_REFLECT
// FILE: J.java
public class J {
private final int param;
public J(int param) {
this.param = param;
}
public String foo(int[] arr, Object[] arr2, Integer y) {
return "" + param + arr[0] + arr2[0] + y;
}
}
// FILE: K.kt
import kotlin.reflect.jvm.*
import kotlin.test.assertEquals
fun box(): String {
val f = J::foo
assertEquals(
listOf(J::class.java, IntArray::class.java, Array<Any>::class.java, Integer::class.java),
f.parameters.map { it.type.javaType }
)
assertEquals(String::class.java, f.returnType.javaType)
assertEquals("01A2", f.call(J(0), intArrayOf(1), arrayOf("A"), 2))
return "OK"
}
@@ -0,0 +1,40 @@
// TODO: muted automatically, investigate should it be ran for JS or not
// IGNORE_BACKEND: JS
// WITH_REFLECT
// FILE: J.java
public class J {
private final String result;
private J(String result) {
this.result = result;
}
private String getResult() {
return result;
}
}
// FILE: K.kt
import kotlin.reflect.*
import kotlin.reflect.jvm.*
import kotlin.test.*
fun box(): String {
val c = J::class.constructors.single()
assertFalse(c.isAccessible)
assertFailsWith(IllegalCallableAccessException::class) { c.call("") }
c.isAccessible = true
assertTrue(c.isAccessible)
val j = c.call("OK")
val m = J::class.members.single { it.name == "getResult" }
assertFalse(m.isAccessible)
assertFailsWith(IllegalCallableAccessException::class) { m.call(j)!! }
m.isAccessible = true
return m.call(j) as String
}
@@ -0,0 +1,26 @@
// TODO: muted automatically, investigate should it be ran for JS or not
// IGNORE_BACKEND: JS
// WITH_REFLECT
// FILE: J.java
public class J {
public static String foo(int x, int[] arr, Object[] arr2) {
return "" + x + arr[0] + arr2[0];
}
}
// FILE: K.kt
import kotlin.reflect.jvm.*
import kotlin.test.assertEquals
fun box(): String {
val f = J::foo
assertEquals(listOf(Integer.TYPE, IntArray::class.java, Array<Any>::class.java), f.parameters.map { it.type.javaType })
assertEquals(String::class.java, f.returnType.javaType)
assertEquals("01A", f.call(0, intArrayOf(1), arrayOf("A")))
return "OK"
}
@@ -0,0 +1,20 @@
// TODO: muted automatically, investigate should it be ran for JS or not
// IGNORE_BACKEND: JS
// WITH_REFLECT
import kotlin.reflect.jvm.*
enum class E
fun box(): String {
try {
val c = E::class.constructors.single()
c.isAccessible = true
c.call()
return "Fail: constructing an enum class should not be allowed"
}
catch (e: Throwable) {
return "OK"
}
}
@@ -0,0 +1,48 @@
// TODO: muted automatically, investigate should it be ran for JS or not
// IGNORE_BACKEND: JS
// WITH_REFLECT
import kotlin.reflect.*
import kotlin.reflect.jvm.*
class A {
private var foo: String = ""
}
object O {
@JvmStatic
private var bar: String = ""
}
class CounterTest<T>(t: T) {
private var baz: String? = ""
private var generic: T = t
}
fun box(): String {
val p = A::class.memberProperties.single() as KMutableProperty1<A, String?>
p.isAccessible = true
try {
p.setter.call(A(), null)
return "Fail: exception should have been thrown"
} catch (e: IllegalArgumentException) {}
val o = O::class.memberProperties.single() as KMutableProperty1<O, String?>
o.isAccessible = true
try {
o.setter.call(O, null)
return "Fail: exception should have been thrown"
} catch (e: IllegalArgumentException) {}
val c = CounterTest::class.memberProperties.single { it.name == "baz" } as KMutableProperty1<CounterTest<*>, String?>
c.isAccessible = true
c.setter.call(CounterTest(""), null) // Should not fail, because CounterTest::baz is nullable
val d = CounterTest::class.memberProperties.single { it.name == "generic" } as KMutableProperty1<CounterTest<*>, String?>
d.isAccessible = true
d.setter.call(CounterTest(""), null) // Also should not fail, because we can't be sure about nullability of 'generic'
return "OK"
}
@@ -0,0 +1,30 @@
// TODO: muted automatically, investigate should it be ran for JS or not
// IGNORE_BACKEND: JS
// WITH_REFLECT
class A
data class D(val s: String)
fun box(): String {
val a = A()
assert(A::equals.call(a, a))
assert(!A::equals.call(a, 0))
assert(A::hashCode.call(a) == A::hashCode.call(a))
assert(A::toString.call(a).startsWith("A@"))
assert(D::equals.call(D("foo"), D("foo")))
assert(!D::equals.call(D("foo"), D("bar")))
assert(D::hashCode.call(D("foo")) == D::hashCode.call(D("foo")))
assert(D::toString.call(D("foo")) == "D(s=foo)")
assert(Int::equals.call(-1, -1))
assert(Int::hashCode.call(0) != Int::hashCode.call(1))
assert(Int::toString.call(42) == "42")
assert(String::equals.call("beer", "beer"))
String::hashCode.call("beer")
return String::toString.call("OK")
}
@@ -0,0 +1,21 @@
// TODO: muted automatically, investigate should it be ran for JS or not
// IGNORE_BACKEND: JS
// WITH_REFLECT
// FULL_JDK
import java.lang.reflect.InvocationTargetException
fun fail(message: String) {
throw AssertionError(message)
}
fun box(): String {
try {
::fail.call("OK")
} catch (e: InvocationTargetException) {
return e.getTargetException().message.toString()
}
return "Fail: no exception was thrown"
}
@@ -0,0 +1,15 @@
// TODO: muted automatically, investigate should it be ran for JS or not
// IGNORE_BACKEND: JS
// WITH_REFLECT
open class A {
fun foo() = "OK"
}
class B : A()
fun box(): String {
val foo = B::class.members.single { it.name == "foo" }
return foo.call(B()) as String
}
@@ -0,0 +1,15 @@
// TODO: muted automatically, investigate should it be ran for JS or not
// IGNORE_BACKEND: JS
// WITH_REFLECT
open class A<T>(val t: T) {
fun foo() = t
}
class B(s: String) : A<String>(s)
fun box(): String {
val foo = B::class.members.single { it.name == "foo" }
return foo.call(B("OK")) as String
}
@@ -0,0 +1,108 @@
// TODO: muted automatically, investigate should it be ran for JS or not
// IGNORE_BACKEND: JS
// WITH_REFLECT
import kotlin.reflect.jvm.isAccessible
import kotlin.reflect.KCallable
import kotlin.reflect.KFunction
import kotlin.reflect.KMutableProperty
var foo: String = ""
class A(private var bar: String = "") {
fun getBar() = A::bar
}
object O {
@JvmStatic
private var baz: String = ""
@JvmStatic
fun getBaz() = (O::class.members.single { it.name == "baz" } as KMutableProperty<*>).apply { isAccessible = true }
fun getGetBaz() = O::class.members.single { it.name == "getBaz" } as KFunction<*>
}
fun check(callable: KCallable<*>, vararg args: Any?) {
val expected = callable.parameters.size
val actual = args.size
if (expected == actual) {
throw AssertionError("Bad test case: expected and actual number of arguments should differ (was $expected vs $actual)")
}
val expectedExceptionMessage = "Callable expects $expected arguments, but $actual were provided."
try {
callable.call(*args)
throw AssertionError("Fail: an IllegalArgumentException should have been thrown")
} catch (e: IllegalArgumentException) {
if (e.message != expectedExceptionMessage) {
// This most probably means that we don't check number of passed arguments in reflection
// and the default check from Java reflection yields an IllegalArgumentException, but with a not that helpful message
throw AssertionError("Fail: an exception with an unrecognized message was thrown: \"${e.message}\"" +
"\nExpected message was: $expectedExceptionMessage")
}
}
}
fun box(): String {
check(::box, null)
check(::box, "")
check(::A)
check(::A, null, "")
check(O.getGetBaz())
check(O.getGetBaz(), null, "")
val f = ::foo
check(f, null)
check(f, null, null)
check(f, arrayOf<Any?>(null))
check(f, "")
check(f.getter, null)
check(f.getter, null, null)
check(f.getter, arrayOf<Any?>(null))
check(f.getter, "")
check(f.setter)
check(f.setter, null, null)
check(f.setter, null, "")
val b = A().getBar()
check(b)
check(b, null, null)
check(b, "", "")
check(b.getter)
check(b.getter, null, null)
check(b.getter, "", "")
check(b.setter)
check(b.setter, null)
check(b.setter, "")
val z = O.getBaz()
check(z)
check(z, null, null)
check(z, "", "")
check(z.getter)
check(z.getter, null, null)
check(z.getter, "", "")
check(z.setter)
check(z.setter, null)
check(z.setter, "")
return "OK"
}
@@ -0,0 +1,13 @@
// TODO: muted automatically, investigate should it be ran for JS or not
// IGNORE_BACKEND: JS
// WITH_REFLECT
class A {
class Nested(val result: String)
inner class Inner(val result: String)
}
fun box(): String {
return (A::Nested).call("O").result + (A::Inner).call((::A).call(), "K").result
}
@@ -0,0 +1,22 @@
// TODO: muted automatically, investigate should it be ran for JS or not
// IGNORE_BACKEND: JS
// WITH_REFLECT
object Obj {
@JvmStatic
fun foo() {}
}
class C {
companion object {
@JvmStatic
fun bar() {}
}
}
fun box(): String {
(Obj::class.members.single { it.name == "foo" }).call(Obj)
(C.Companion::class.members.single { it.name == "bar" }).call(C.Companion)
return "OK"
}
@@ -0,0 +1,47 @@
// TODO: muted automatically, investigate should it be ran for JS or not
// IGNORE_BACKEND: JS
// WITH_REFLECT
object Obj {
@JvmStatic
fun foo(s: String) {}
@JvmStatic
fun bar() {}
@JvmStatic
fun sly(obj: Obj) {}
operator fun get(name: String) = Obj::class.members.single { it.name == name }
}
fun box(): String {
// This should succeed
(Obj["foo"]).call(Obj, "")
(Obj["bar"]).call(Obj)
(Obj["sly"]).call(Obj, Obj)
// This shouldn't: first argument should always be Obj
try {
(Obj["foo"]).call(null, "")
return "Fail foo"
} catch (e: IllegalArgumentException) {}
try {
(Obj["bar"]).call("")
return "Fail bar"
} catch (e: IllegalArgumentException) {}
try {
(Obj["sly"]).call(Obj)
return "Fail sly 1"
} catch (e: IllegalArgumentException) {}
try {
(Obj["sly"]).call(null, Obj)
return "Fail sly 2"
} catch (e: IllegalArgumentException) {}
return "OK"
}
@@ -0,0 +1,12 @@
// TODO: muted automatically, investigate should it be ran for JS or not
// IGNORE_BACKEND: JS
// WITH_REFLECT
fun box(): String {
class Local {
fun result(s: String) = s
}
return Local::result.call(Local(), "OK")
}
@@ -0,0 +1,17 @@
// TODO: muted automatically, investigate should it be ran for JS or not
// IGNORE_BACKEND: JS
// WITH_REFLECT
var result = "Fail"
class A<T> {
fun foo(t: T) {
result = t as String
}
}
fun box(): String {
(A<String>::foo).call(A<String>(), "OK")
return result
}
@@ -0,0 +1,22 @@
// TODO: muted automatically, investigate should it be ran for JS or not
// IGNORE_BACKEND: JS
// WITH_REFLECT
import kotlin.reflect.*
import kotlin.reflect.jvm.*
import kotlin.test.*
class A(private var result: String)
fun box(): String {
val a = A("abc")
val p = A::class.declaredMemberProperties.single() as KMutableProperty1<A, String>
p.isAccessible = true
assertEquals("abc", p.call(a))
assertEquals(Unit, p.setter.call(a, "def"))
assertEquals("def", p.getter.call(a))
return "OK"
}
@@ -0,0 +1,52 @@
// TODO: muted automatically, investigate should it be ran for JS or not
// IGNORE_BACKEND: JS
// WITH_REFLECT
import kotlin.reflect.*
import kotlin.test.assertEquals
val p0 = 1
val Int.p1: Int get() = this
class A {
val Int.p2: Int get() = this
}
var globalCounter = 0
var mp0 = 1
set(value) { globalCounter += value }
var Int.mp1: Int
get() = this
set(value) { globalCounter += value }
class B {
var Int.mp2: Int
get() = this
set(value) { globalCounter += value }
}
fun box(): String {
assertEquals(1, (::p0).call())
assertEquals(1, (::p0).getter.call())
assertEquals(2, (Int::p1).call(2))
assertEquals(2, (Int::p1).getter.call(2))
val p2 = A::class.memberExtensionProperties.single()
assertEquals(3, p2.call(A(), 3))
assertEquals(3, p2.getter.call(A(), 3))
assertEquals(1, (::mp0).call())
assertEquals(1, (::mp0).getter.call())
assertEquals(2, (Int::mp1).call(2))
assertEquals(2, (Int::mp1).getter.call(2))
val mp2 = B::class.memberExtensionProperties.single() as KMutableProperty2
assertEquals(3, mp2.call(B(), 3))
assertEquals(3, mp2.getter.call(B(), 3))
assertEquals(Unit, (::mp0).setter.call(1))
assertEquals(Unit, (Int::mp1).setter.call(0, 3))
assertEquals(Unit, mp2.setter.call(B(), 0, 5))
if (globalCounter != 9) return "Fail: $globalCounter"
return "OK"
}
@@ -0,0 +1,12 @@
// TODO: muted automatically, investigate should it be ran for JS or not
// IGNORE_BACKEND: JS
// WITH_REFLECT
data class Foo(val id: String) {
fun getId() = -42 // Fail
}
fun box(): String {
return Foo::id.call(Foo("OK"))
}
@@ -0,0 +1,29 @@
// TODO: muted automatically, investigate should it be ran for JS or not
// IGNORE_BACKEND: JS
// WITH_REFLECT
import kotlin.test.assertEquals
fun foo() {}
class A {
fun bar() {}
}
object O {
@JvmStatic fun baz() {}
}
fun nullableUnit(unit: Boolean): Unit? = if (unit) Unit else null
fun box(): String {
assertEquals(Unit, ::foo.call())
assertEquals(Unit, A::bar.call(A()))
assertEquals(Unit, O::class.members.single { it.name == "baz" }.call(O))
assertEquals(Unit, (::nullableUnit).call(true))
assertEquals(null, (::nullableUnit).call(false))
return "OK"
}
@@ -0,0 +1,11 @@
// TODO: muted automatically, investigate should it be ran for JS or not
// IGNORE_BACKEND: JS
// WITH_REFLECT
class A(val result: String)
fun box(): String {
val a = (::A).call("OK")
return a.result
}
@@ -0,0 +1,21 @@
// TODO: muted automatically, investigate should it be ran for JS or not
// IGNORE_BACKEND: JS
// WITH_REFLECT
class A {
fun foo(x: Int, y: Int) = x + y
}
fun box(): String {
val x = (A::foo).call(A(), 42, 239)
if (x != 281) return "Fail: $x"
try {
(A::foo).call()
return "Fail: no exception"
}
catch (e: Exception) {}
return "OK"
}
@@ -0,0 +1,32 @@
// TODO: muted automatically, investigate should it be ran for JS or not
// IGNORE_BACKEND: JS
// WITH_REFLECT
fun String.foo(): Int = length
var state = "Fail"
fun bar(result: String) {
state = result
}
fun box(): String {
val f = (String::foo).call("abc")
if (f != 3) return "Fail: $f"
try {
(String::foo).call()
return "Fail: IllegalArgumentException should have been thrown"
}
catch (e: IllegalArgumentException) {}
try {
(String::foo).call(42)
return "Fail: IllegalArgumentException should have been thrown"
}
catch (e: IllegalArgumentException) {}
(::bar).call("OK")
return state
}