tests: Update external tests (1.1.2-dev-393)
This commit is contained in:
Vendored
+19
@@ -0,0 +1,19 @@
|
||||
// TODO: muted automatically, investigate should it be ran for JS or not
|
||||
// IGNORE_BACKEND: JS, NATIVE
|
||||
|
||||
// WITH_REFLECT
|
||||
|
||||
import kotlin.test.assertEquals
|
||||
|
||||
@Retention(AnnotationRetention.RUNTIME)
|
||||
annotation class Anno
|
||||
|
||||
fun box(): String {
|
||||
val a = Anno::class.annotations
|
||||
|
||||
if (a.size != 1) return "Fail 1: $a"
|
||||
val ann = a.single() as? Retention ?: return "Fail 2: ${a.single()}"
|
||||
assertEquals(AnnotationRetention.RUNTIME, ann.value)
|
||||
|
||||
return "OK"
|
||||
}
|
||||
Vendored
+32
@@ -0,0 +1,32 @@
|
||||
// TODO: muted automatically, investigate should it be ran for JS or not
|
||||
// IGNORE_BACKEND: JS, NATIVE
|
||||
|
||||
// WITH_REFLECT
|
||||
// FILE: J.java
|
||||
|
||||
@Anno("J")
|
||||
public class J {
|
||||
@Anno("foo")
|
||||
public static int foo = 42;
|
||||
|
||||
@Anno("bar")
|
||||
public static void bar() {}
|
||||
|
||||
@Anno("constructor")
|
||||
public J() {}
|
||||
}
|
||||
|
||||
// FILE: K.kt
|
||||
|
||||
import kotlin.test.assertEquals
|
||||
|
||||
annotation class Anno(val value: String)
|
||||
|
||||
fun box(): String {
|
||||
assertEquals("[@Anno(value=J)]", J::class.annotations.toString())
|
||||
assertEquals("[@Anno(value=foo)]", J::foo.annotations.toString())
|
||||
assertEquals("[@Anno(value=bar)]", J::bar.annotations.toString())
|
||||
assertEquals("[@Anno(value=constructor)]", ::J.annotations.toString())
|
||||
|
||||
return "OK"
|
||||
}
|
||||
+21
@@ -0,0 +1,21 @@
|
||||
// IGNORE_BACKEND: JS, NATIVE
|
||||
// WITH_REFLECT
|
||||
|
||||
import kotlin.reflect.full.findAnnotation
|
||||
import kotlin.test.assertNull
|
||||
|
||||
annotation class Yes(val value: String)
|
||||
annotation class No(val value: String)
|
||||
|
||||
@Yes("OK")
|
||||
@No("Fail")
|
||||
class Foo
|
||||
|
||||
class Bar
|
||||
|
||||
fun box(): String {
|
||||
assertNull(Bar::class.findAnnotation<Yes>())
|
||||
assertNull(Bar::class.findAnnotation<No>())
|
||||
|
||||
return Foo::class.findAnnotation<Yes>()?.value ?: "Fail: no annotation"
|
||||
}
|
||||
+20
@@ -0,0 +1,20 @@
|
||||
// TODO: muted automatically, investigate should it be ran for JS or not
|
||||
// IGNORE_BACKEND: JS, NATIVE
|
||||
|
||||
// WITH_REFLECT
|
||||
|
||||
annotation class Get
|
||||
annotation class Set
|
||||
annotation class SetParam
|
||||
|
||||
var foo: String
|
||||
@Get get() = ""
|
||||
@Set set(@SetParam value) {}
|
||||
|
||||
fun box(): String {
|
||||
assert(::foo.getter.annotations.single() is Get)
|
||||
assert(::foo.setter.annotations.single() is Set)
|
||||
assert(::foo.setter.parameters.single().annotations.single() is SetParam)
|
||||
|
||||
return "OK"
|
||||
}
|
||||
Vendored
+14
@@ -0,0 +1,14 @@
|
||||
// TODO: muted automatically, investigate should it be ran for JS or not
|
||||
// IGNORE_BACKEND: JS, NATIVE
|
||||
|
||||
// WITH_REFLECT
|
||||
|
||||
annotation class Ann(val value: String)
|
||||
|
||||
@Ann("OK")
|
||||
val property: String
|
||||
get() = ""
|
||||
|
||||
fun box(): String {
|
||||
return (::property.annotations.single() as Ann).value
|
||||
}
|
||||
+23
@@ -0,0 +1,23 @@
|
||||
// TODO: muted automatically, investigate should it be ran for JS or not
|
||||
// IGNORE_BACKEND: JS, NATIVE
|
||||
|
||||
// WITH_REFLECT
|
||||
|
||||
import kotlin.test.assertEquals
|
||||
|
||||
@Retention(AnnotationRetention.SOURCE)
|
||||
annotation class SourceAnno
|
||||
|
||||
@Retention(AnnotationRetention.BINARY)
|
||||
annotation class BinaryAnno
|
||||
|
||||
@Retention(AnnotationRetention.RUNTIME)
|
||||
annotation class RuntimeAnno
|
||||
|
||||
@SourceAnno
|
||||
@BinaryAnno
|
||||
@RuntimeAnno
|
||||
fun box(): String {
|
||||
assertEquals(listOf(RuntimeAnno::class.java), ::box.annotations.map { it.annotationClass.java })
|
||||
return "OK"
|
||||
}
|
||||
+14
@@ -0,0 +1,14 @@
|
||||
// TODO: muted automatically, investigate should it be ran for JS or not
|
||||
// IGNORE_BACKEND: JS, NATIVE
|
||||
|
||||
// WITH_REFLECT
|
||||
|
||||
@Retention(AnnotationRetention.RUNTIME)
|
||||
annotation class Simple(val value: String)
|
||||
|
||||
@Simple("OK")
|
||||
class A
|
||||
|
||||
fun box(): String {
|
||||
return (A::class.annotations.single() as Simple).value
|
||||
}
|
||||
Vendored
+18
@@ -0,0 +1,18 @@
|
||||
// TODO: muted automatically, investigate should it be ran for JS or not
|
||||
// IGNORE_BACKEND: JS, NATIVE
|
||||
|
||||
// WITH_REFLECT
|
||||
|
||||
annotation class Primary
|
||||
annotation class Secondary
|
||||
|
||||
class C @Primary constructor() {
|
||||
@Secondary
|
||||
constructor(s: String): this()
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
val ans = C::class.constructors.map { it.annotations.single().annotationClass.java.simpleName }.sorted()
|
||||
if (ans != listOf("Primary", "Secondary")) return "Fail: $ans"
|
||||
return "OK"
|
||||
}
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
// TODO: muted automatically, investigate should it be ran for JS or not
|
||||
// IGNORE_BACKEND: JS, NATIVE
|
||||
|
||||
// WITH_REFLECT
|
||||
|
||||
@Retention(AnnotationRetention.RUNTIME)
|
||||
annotation class Simple(val value: String)
|
||||
|
||||
@Simple("OK")
|
||||
fun box(): String {
|
||||
return (::box.annotations.single() as Simple).value
|
||||
}
|
||||
+13
@@ -0,0 +1,13 @@
|
||||
// TODO: muted automatically, investigate should it be ran for JS or not
|
||||
// IGNORE_BACKEND: JS, NATIVE
|
||||
|
||||
// WITH_REFLECT
|
||||
|
||||
@Retention(AnnotationRetention.RUNTIME)
|
||||
annotation class Simple(val value: String)
|
||||
|
||||
fun test(@Simple("OK") x: Int) {}
|
||||
|
||||
fun box(): String {
|
||||
return (::test.parameters.single().annotations.single() as Simple).value
|
||||
}
|
||||
+14
@@ -0,0 +1,14 @@
|
||||
// TODO: muted automatically, investigate should it be ran for JS or not
|
||||
// IGNORE_BACKEND: JS, NATIVE
|
||||
|
||||
// WITH_REFLECT
|
||||
|
||||
@Retention(AnnotationRetention.RUNTIME)
|
||||
annotation class Simple(val value: String)
|
||||
|
||||
@property:Simple("OK")
|
||||
val foo: Int = 0
|
||||
|
||||
fun box(): String {
|
||||
return (::foo.annotations.single() as Simple).value
|
||||
}
|
||||
Vendored
+53
@@ -0,0 +1,53 @@
|
||||
// TODO: investigate should it be ran for JS or not
|
||||
// IGNORE_BACKEND: JS, NATIVE
|
||||
|
||||
// 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"
|
||||
}
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
// TODO: investigate should it be ran for JS or not
|
||||
// IGNORE_BACKEND: JS, NATIVE
|
||||
|
||||
// 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")
|
||||
Vendored
+45
@@ -0,0 +1,45 @@
|
||||
// TODO: investigate should it be ran for JS or not
|
||||
// IGNORE_BACKEND: JS, NATIVE
|
||||
|
||||
// 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"
|
||||
}
|
||||
+16
@@ -0,0 +1,16 @@
|
||||
// TODO: investigate should it be ran for JS or not
|
||||
// IGNORE_BACKEND: JS, NATIVE
|
||||
|
||||
// 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()
|
||||
}
|
||||
+40
@@ -0,0 +1,40 @@
|
||||
// TODO: investigate should it be ran for JS or not
|
||||
// IGNORE_BACKEND: JS, NATIVE
|
||||
|
||||
// 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"
|
||||
}
|
||||
+35
@@ -0,0 +1,35 @@
|
||||
// TODO: investigate should it be ran for JS or not
|
||||
// IGNORE_BACKEND: JS, NATIVE
|
||||
|
||||
// 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"
|
||||
}
|
||||
+53
@@ -0,0 +1,53 @@
|
||||
// TODO: investigate should it be ran for JS or not
|
||||
// IGNORE_BACKEND: JS, NATIVE
|
||||
|
||||
// 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"
|
||||
}
|
||||
+19
@@ -0,0 +1,19 @@
|
||||
// TODO: investigate should it be ran for JS or not
|
||||
// IGNORE_BACKEND: JS, NATIVE
|
||||
|
||||
// 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")
|
||||
Vendored
+51
@@ -0,0 +1,51 @@
|
||||
// TODO: investigate should it be ran for JS or not
|
||||
// IGNORE_BACKEND: JS, NATIVE
|
||||
|
||||
// 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"
|
||||
}
|
||||
+14
@@ -0,0 +1,14 @@
|
||||
// TODO: investigate should it be ran for JS or not
|
||||
// IGNORE_BACKEND: JS, NATIVE
|
||||
|
||||
// WITH_REFLECT
|
||||
|
||||
import kotlin.reflect.*
|
||||
|
||||
class C(val k: String) {
|
||||
fun foo(s: String) = s + k
|
||||
}
|
||||
|
||||
fun box(): String =
|
||||
C("K")::foo.call("O")
|
||||
|
||||
+50
@@ -0,0 +1,50 @@
|
||||
// TODO: investigate should it be ran for JS or not
|
||||
// IGNORE_BACKEND: JS, NATIVE
|
||||
|
||||
// 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"
|
||||
}
|
||||
+19
@@ -0,0 +1,19 @@
|
||||
// TODO: investigate should it be ran for JS or not
|
||||
// IGNORE_BACKEND: JS, NATIVE
|
||||
|
||||
// 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")
|
||||
+51
@@ -0,0 +1,51 @@
|
||||
// TODO: investigate should it be ran for JS or not
|
||||
// IGNORE_BACKEND: JS, NATIVE
|
||||
|
||||
// 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"
|
||||
}
|
||||
+35
@@ -0,0 +1,35 @@
|
||||
// TODO: muted automatically, investigate should it be ran for JS or not
|
||||
// IGNORE_BACKEND: JS, NATIVE
|
||||
|
||||
// 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"
|
||||
}
|
||||
+40
@@ -0,0 +1,40 @@
|
||||
// TODO: muted automatically, investigate should it be ran for JS or not
|
||||
// IGNORE_BACKEND: JS, NATIVE
|
||||
|
||||
// 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
|
||||
}
|
||||
+26
@@ -0,0 +1,26 @@
|
||||
// TODO: muted automatically, investigate should it be ran for JS or not
|
||||
// IGNORE_BACKEND: JS, NATIVE
|
||||
|
||||
// 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"
|
||||
}
|
||||
+20
@@ -0,0 +1,20 @@
|
||||
// TODO: muted automatically, investigate should it be ran for JS or not
|
||||
// IGNORE_BACKEND: JS, NATIVE
|
||||
|
||||
// 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"
|
||||
}
|
||||
}
|
||||
Vendored
+48
@@ -0,0 +1,48 @@
|
||||
// TODO: muted automatically, investigate should it be ran for JS or not
|
||||
// IGNORE_BACKEND: JS, NATIVE
|
||||
|
||||
// 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"
|
||||
}
|
||||
+30
@@ -0,0 +1,30 @@
|
||||
// TODO: muted automatically, investigate should it be ran for JS or not
|
||||
// IGNORE_BACKEND: JS, NATIVE
|
||||
|
||||
// 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")
|
||||
}
|
||||
+21
@@ -0,0 +1,21 @@
|
||||
// TODO: muted automatically, investigate should it be ran for JS or not
|
||||
// IGNORE_BACKEND: JS, NATIVE
|
||||
|
||||
// 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, NATIVE
|
||||
|
||||
// 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
|
||||
}
|
||||
+15
@@ -0,0 +1,15 @@
|
||||
// TODO: muted automatically, investigate should it be ran for JS or not
|
||||
// IGNORE_BACKEND: JS, NATIVE
|
||||
|
||||
// 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
|
||||
}
|
||||
+108
@@ -0,0 +1,108 @@
|
||||
// TODO: muted automatically, investigate should it be ran for JS or not
|
||||
// IGNORE_BACKEND: JS, NATIVE
|
||||
|
||||
// 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"
|
||||
}
|
||||
+13
@@ -0,0 +1,13 @@
|
||||
// TODO: muted automatically, investigate should it be ran for JS or not
|
||||
// IGNORE_BACKEND: JS, NATIVE
|
||||
|
||||
// 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, NATIVE
|
||||
|
||||
// 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"
|
||||
}
|
||||
Vendored
+47
@@ -0,0 +1,47 @@
|
||||
// TODO: muted automatically, investigate should it be ran for JS or not
|
||||
// IGNORE_BACKEND: JS, NATIVE
|
||||
|
||||
// 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"
|
||||
}
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
// TODO: muted automatically, investigate should it be ran for JS or not
|
||||
// IGNORE_BACKEND: JS, NATIVE
|
||||
|
||||
// WITH_REFLECT
|
||||
|
||||
fun box(): String {
|
||||
class Local {
|
||||
fun result(s: String) = s
|
||||
}
|
||||
|
||||
return Local::result.call(Local(), "OK")
|
||||
}
|
||||
+17
@@ -0,0 +1,17 @@
|
||||
// TODO: muted automatically, investigate should it be ran for JS or not
|
||||
// IGNORE_BACKEND: JS, NATIVE
|
||||
|
||||
// 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, NATIVE
|
||||
|
||||
// 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"
|
||||
}
|
||||
+52
@@ -0,0 +1,52 @@
|
||||
// TODO: muted automatically, investigate should it be ran for JS or not
|
||||
// IGNORE_BACKEND: JS, NATIVE
|
||||
|
||||
// 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"
|
||||
}
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
// TODO: muted automatically, investigate should it be ran for JS or not
|
||||
// IGNORE_BACKEND: JS, NATIVE
|
||||
|
||||
// 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, NATIVE
|
||||
|
||||
// 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"
|
||||
}
|
||||
+11
@@ -0,0 +1,11 @@
|
||||
// TODO: muted automatically, investigate should it be ran for JS or not
|
||||
// IGNORE_BACKEND: JS, NATIVE
|
||||
|
||||
// WITH_REFLECT
|
||||
|
||||
class A(val result: String)
|
||||
|
||||
fun box(): String {
|
||||
val a = (::A).call("OK")
|
||||
return a.result
|
||||
}
|
||||
+21
@@ -0,0 +1,21 @@
|
||||
// TODO: muted automatically, investigate should it be ran for JS or not
|
||||
// IGNORE_BACKEND: JS, NATIVE
|
||||
|
||||
// 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"
|
||||
}
|
||||
+32
@@ -0,0 +1,32 @@
|
||||
// TODO: muted automatically, investigate should it be ran for JS or not
|
||||
// IGNORE_BACKEND: JS, NATIVE
|
||||
|
||||
// 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
|
||||
}
|
||||
+13
@@ -0,0 +1,13 @@
|
||||
// TODO: muted automatically, investigate should it be ran for JS or not
|
||||
// IGNORE_BACKEND: JS, NATIVE
|
||||
|
||||
// WITH_REFLECT
|
||||
|
||||
import kotlin.test.assertEquals
|
||||
|
||||
fun String.extFun(k: String, s: String = "") = this + k + s
|
||||
|
||||
fun box(): String {
|
||||
val sExtFun = "O"::extFun
|
||||
return sExtFun.callBy(mapOf(sExtFun.parameters[0] to "K"))
|
||||
}
|
||||
Vendored
+12
@@ -0,0 +1,12 @@
|
||||
// TODO: muted automatically, investigate should it be ran for JS or not
|
||||
// IGNORE_BACKEND: JS, NATIVE
|
||||
|
||||
// WITH_REFLECT
|
||||
|
||||
import kotlin.test.assertEquals
|
||||
|
||||
val String.plusK: String
|
||||
get() = this + "K"
|
||||
|
||||
fun box(): String =
|
||||
("O"::plusK).getter.callBy(mapOf())
|
||||
+19
@@ -0,0 +1,19 @@
|
||||
// TODO: muted automatically, investigate should it be ran for JS or not
|
||||
// IGNORE_BACKEND: JS, NATIVE
|
||||
|
||||
// WITH_REFLECT
|
||||
|
||||
object Host {
|
||||
@JvmStatic fun concat(s1: String, s2: String, s3: String = "K", s4: String = "x") =
|
||||
s1 + s2 + s3 + s4
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
val concat = Host::concat
|
||||
val concatParams = concat.parameters
|
||||
return concat.callBy(mapOf(
|
||||
concatParams[0] to "",
|
||||
concatParams[1] to "O",
|
||||
concatParams[3] to ""
|
||||
))
|
||||
}
|
||||
+34
@@ -0,0 +1,34 @@
|
||||
// TODO: muted automatically, investigate should it be ran for JS or not
|
||||
// IGNORE_BACKEND: JS, NATIVE
|
||||
|
||||
// WITH_REFLECT
|
||||
|
||||
import kotlin.test.assertEquals
|
||||
|
||||
class C {
|
||||
companion object {
|
||||
fun foo(a: String, b: String = "b") = a + b
|
||||
}
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
val f = C.Companion::class.members.single { it.name == "foo" }
|
||||
|
||||
// Any object method currently requires the object instance passed
|
||||
try {
|
||||
f.callBy(mapOf(
|
||||
f.parameters.single { it.name == "a" } to "a"
|
||||
))
|
||||
return "Fail: IllegalArgumentException should have been thrown"
|
||||
}
|
||||
catch (e: IllegalArgumentException) {
|
||||
// OK
|
||||
}
|
||||
|
||||
assertEquals("ab", f.callBy(mapOf(
|
||||
f.parameters.first() to C,
|
||||
f.parameters.single { it.name == "a" } to "a"
|
||||
)))
|
||||
|
||||
return "OK"
|
||||
}
|
||||
Vendored
+20
@@ -0,0 +1,20 @@
|
||||
// TODO: muted automatically, investigate should it be ran for JS or not
|
||||
// IGNORE_BACKEND: JS, NATIVE
|
||||
|
||||
// WITH_REFLECT
|
||||
|
||||
import kotlin.test.assertEquals
|
||||
|
||||
fun foo(a: String, b: String = "b", c: String, d: String = "d", e: String) =
|
||||
a + b + c + d + e
|
||||
|
||||
fun box(): String {
|
||||
val p = ::foo.parameters
|
||||
assertEquals("abcde", ::foo.callBy(mapOf(
|
||||
p[0] to "a",
|
||||
p[2] to "c",
|
||||
p[4] to "e"
|
||||
)))
|
||||
|
||||
return "OK"
|
||||
}
|
||||
+14
@@ -0,0 +1,14 @@
|
||||
// TODO: muted automatically, investigate should it be ran for JS or not
|
||||
// IGNORE_BACKEND: JS, NATIVE
|
||||
|
||||
// WITH_REFLECT
|
||||
|
||||
import kotlin.test.assertEquals
|
||||
|
||||
fun String.sum(other: String = "b") = this + other
|
||||
|
||||
fun box(): String {
|
||||
val f = String::sum
|
||||
assertEquals("ab", f.callBy(mapOf(f.parameters.first() to "a")))
|
||||
return "OK"
|
||||
}
|
||||
+37
@@ -0,0 +1,37 @@
|
||||
// TODO: muted automatically, investigate should it be ran for JS or not
|
||||
// IGNORE_BACKEND: JS, NATIVE
|
||||
|
||||
// WITH_REFLECT
|
||||
|
||||
// KT-12915 IAE on callBy of JvmStatic function with default arguments
|
||||
|
||||
import kotlin.test.assertEquals
|
||||
|
||||
class C {
|
||||
companion object {
|
||||
@JvmStatic
|
||||
fun foo(a: String, b: String = "b") = a + b
|
||||
}
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
val f = C.Companion::class.members.single { it.name == "foo" }
|
||||
|
||||
// Any object method currently requires the object instance passed
|
||||
try {
|
||||
f.callBy(mapOf(
|
||||
f.parameters.single { it.name == "a" } to "a"
|
||||
))
|
||||
return "Fail: IllegalArgumentException should have been thrown"
|
||||
}
|
||||
catch (e: IllegalArgumentException) {
|
||||
// OK
|
||||
}
|
||||
|
||||
assertEquals("ab", f.callBy(mapOf(
|
||||
f.parameters.first() to C,
|
||||
f.parameters.single { it.name == "a" } to "a"
|
||||
)))
|
||||
|
||||
return "OK"
|
||||
}
|
||||
+33
@@ -0,0 +1,33 @@
|
||||
// TODO: muted automatically, investigate should it be ran for JS or not
|
||||
// IGNORE_BACKEND: JS, NATIVE
|
||||
|
||||
// WITH_REFLECT
|
||||
|
||||
import kotlin.test.assertEquals
|
||||
|
||||
object Obj {
|
||||
@JvmStatic
|
||||
fun foo(a: String, b: String = "b") = a + b
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
val f = Obj::class.members.single { it.name == "foo" }
|
||||
|
||||
// Any object method currently requires the object instance passed
|
||||
try {
|
||||
f.callBy(mapOf(
|
||||
f.parameters.single { it.name == "a" } to "a"
|
||||
))
|
||||
return "Fail: IllegalArgumentException should have been thrown"
|
||||
}
|
||||
catch (e: IllegalArgumentException) {
|
||||
// OK
|
||||
}
|
||||
|
||||
assertEquals("ab", f.callBy(mapOf(
|
||||
f.parameters.first() to Obj,
|
||||
f.parameters.single { it.name == "a" } to "a"
|
||||
)))
|
||||
|
||||
return "OK"
|
||||
}
|
||||
+102
@@ -0,0 +1,102 @@
|
||||
// TODO: muted automatically, investigate should it be ran for JS or not
|
||||
// IGNORE_BACKEND: JS, NATIVE
|
||||
|
||||
// WITH_REFLECT
|
||||
|
||||
import kotlin.test.assertEquals
|
||||
|
||||
// Generate:
|
||||
// (1..70).map { " p${"%02d".format(it)}: Int," }.joinToString("\n")
|
||||
|
||||
class A {
|
||||
fun foo(
|
||||
p01: Int,
|
||||
p02: Int,
|
||||
p03: Int,
|
||||
p04: Int,
|
||||
p05: Int,
|
||||
p06: Int,
|
||||
p07: Int,
|
||||
p08: Int,
|
||||
p09: Int,
|
||||
p10: Int,
|
||||
p11: Int,
|
||||
p12: Int,
|
||||
p13: Int,
|
||||
p14: Int,
|
||||
p15: Int,
|
||||
p16: Int,
|
||||
p17: Int,
|
||||
p18: Int,
|
||||
p19: Int,
|
||||
p20: Int,
|
||||
p21: Int,
|
||||
p22: Int,
|
||||
p23: Int,
|
||||
p24: Int,
|
||||
p25: Int,
|
||||
p26: Int,
|
||||
p27: Int,
|
||||
p28: Int,
|
||||
p29: Int,
|
||||
p30: Int,
|
||||
p31: Int,
|
||||
p32: Int,
|
||||
p33: Int,
|
||||
p34: Int,
|
||||
p35: Int,
|
||||
p36: Int,
|
||||
p37: Int,
|
||||
p38: Int,
|
||||
p39: Int,
|
||||
p40: Int,
|
||||
p41: Int,
|
||||
p42: Int = 239,
|
||||
p43: Int,
|
||||
p44: Int,
|
||||
p45: Int,
|
||||
p46: Int,
|
||||
p47: Int,
|
||||
p48: Int,
|
||||
p49: Int,
|
||||
p50: Int,
|
||||
p51: Int,
|
||||
p52: Int,
|
||||
p53: Int,
|
||||
p54: Int,
|
||||
p55: Int,
|
||||
p56: Int,
|
||||
p57: Int,
|
||||
p58: Int,
|
||||
p59: Int,
|
||||
p60: Int,
|
||||
p61: Int,
|
||||
p62: Int,
|
||||
p63: Int,
|
||||
p64: Int,
|
||||
p65: Int,
|
||||
p66: Int,
|
||||
p67: Int,
|
||||
p68: Int,
|
||||
p69: Int,
|
||||
p70: Int
|
||||
) {
|
||||
assertEquals(1, p01)
|
||||
assertEquals(41, p41)
|
||||
assertEquals(239, p42)
|
||||
assertEquals(43, p43)
|
||||
assertEquals(70, p70)
|
||||
}
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
val f = A::class.members.single { it.name == "foo" }
|
||||
val parameters = f.parameters
|
||||
|
||||
f.callBy(mapOf(
|
||||
parameters.first() to A(),
|
||||
*((1..41) + (43..70)).map { i -> parameters[i] to i }.toTypedArray()
|
||||
))
|
||||
|
||||
return "OK"
|
||||
}
|
||||
+100
@@ -0,0 +1,100 @@
|
||||
// TODO: muted automatically, investigate should it be ran for JS or not
|
||||
// IGNORE_BACKEND: JS, NATIVE
|
||||
|
||||
// WITH_REFLECT
|
||||
|
||||
import kotlin.test.assertEquals
|
||||
|
||||
// Generate:
|
||||
// (1..70).map { " p${"%02d".format(it)}: Int = $it," }.joinToString("\n")
|
||||
|
||||
class A {
|
||||
fun foo(
|
||||
p01: Int = 1,
|
||||
p02: Int = 2,
|
||||
p03: Int = 3,
|
||||
p04: Int = 4,
|
||||
p05: Int = 5,
|
||||
p06: Int = 6,
|
||||
p07: Int = 7,
|
||||
p08: Int = 8,
|
||||
p09: Int = 9,
|
||||
p10: Int = 10,
|
||||
p11: Int = 11,
|
||||
p12: Int = 12,
|
||||
p13: Int = 13,
|
||||
p14: Int = 14,
|
||||
p15: Int = 15,
|
||||
p16: Int = 16,
|
||||
p17: Int = 17,
|
||||
p18: Int = 18,
|
||||
p19: Int = 19,
|
||||
p20: Int = 20,
|
||||
p21: Int = 21,
|
||||
p22: Int = 22,
|
||||
p23: Int = 23,
|
||||
p24: Int = 24,
|
||||
p25: Int = 25,
|
||||
p26: Int = 26,
|
||||
p27: Int = 27,
|
||||
p28: Int = 28,
|
||||
p29: Int = 29,
|
||||
p30: Int = 30,
|
||||
p31: Int = 31,
|
||||
p32: Int = 32,
|
||||
p33: Int = 33,
|
||||
p34: Int = 34,
|
||||
p35: Int = 35,
|
||||
p36: Int = 36,
|
||||
p37: Int = 37,
|
||||
p38: Int = 38,
|
||||
p39: Int = 39,
|
||||
p40: Int = 40,
|
||||
p41: Int = 41,
|
||||
p42: Int,
|
||||
p43: Int = 43,
|
||||
p44: Int = 44,
|
||||
p45: Int = 45,
|
||||
p46: Int = 46,
|
||||
p47: Int = 47,
|
||||
p48: Int = 48,
|
||||
p49: Int = 49,
|
||||
p50: Int = 50,
|
||||
p51: Int = 51,
|
||||
p52: Int = 52,
|
||||
p53: Int = 53,
|
||||
p54: Int = 54,
|
||||
p55: Int = 55,
|
||||
p56: Int = 56,
|
||||
p57: Int = 57,
|
||||
p58: Int = 58,
|
||||
p59: Int = 59,
|
||||
p60: Int = 60,
|
||||
p61: Int = 61,
|
||||
p62: Int = 62,
|
||||
p63: Int = 63,
|
||||
p64: Int = 64,
|
||||
p65: Int = 65,
|
||||
p66: Int = 66,
|
||||
p67: Int = 67,
|
||||
p68: Int = 68,
|
||||
p69: Int = 69,
|
||||
p70: Int = 70
|
||||
) {
|
||||
assertEquals(1, p01)
|
||||
assertEquals(41, p41)
|
||||
assertEquals(239, p42)
|
||||
assertEquals(43, p43)
|
||||
assertEquals(70, p70)
|
||||
}
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
val f = A::class.members.single { it.name == "foo" }
|
||||
val parameters = f.parameters
|
||||
f.callBy(mapOf(
|
||||
parameters.first() to A(),
|
||||
parameters.single { it.name == "p42" } to 239
|
||||
))
|
||||
return "OK"
|
||||
}
|
||||
+26
@@ -0,0 +1,26 @@
|
||||
// TODO: muted automatically, investigate should it be ran for JS or not
|
||||
// IGNORE_BACKEND: JS, NATIVE
|
||||
|
||||
// WITH_REFLECT
|
||||
|
||||
fun foo(x: Int, y: Int = 2) = x + y
|
||||
|
||||
fun box(): String {
|
||||
try {
|
||||
::foo.callBy(mapOf())
|
||||
return "Fail: IllegalArgumentException must have been thrown"
|
||||
}
|
||||
catch (e: IllegalArgumentException) {
|
||||
// OK
|
||||
}
|
||||
|
||||
try {
|
||||
::foo.callBy(mapOf(::foo.parameters.last() to 1))
|
||||
return "Fail: IllegalArgumentException must have been thrown"
|
||||
}
|
||||
catch (e: IllegalArgumentException) {
|
||||
// OK
|
||||
}
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
// TODO: muted automatically, investigate should it be ran for JS or not
|
||||
// IGNORE_BACKEND: JS, NATIVE
|
||||
|
||||
// WITH_REFLECT
|
||||
|
||||
import kotlin.test.assertNull
|
||||
|
||||
fun foo(x: String? = "Fail") {
|
||||
assertNull(x)
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
::foo.callBy(mapOf(::foo.parameters.single() to null))
|
||||
return "OK"
|
||||
}
|
||||
+24
@@ -0,0 +1,24 @@
|
||||
// TODO: muted automatically, investigate should it be ran for JS or not
|
||||
// IGNORE_BACKEND: JS, NATIVE
|
||||
|
||||
// WITH_REFLECT
|
||||
// FULL_JDK
|
||||
|
||||
import kotlin.test.assertEquals
|
||||
|
||||
fun foo(result: String = "foo") {
|
||||
assertEquals("box", result)
|
||||
|
||||
// Check that this function was invoked directly and not through the "foo$default", i.e. there's no "foo$default" in the stack trace
|
||||
val st = Thread.currentThread().stackTrace
|
||||
for (i in 0..5) {
|
||||
if ("foo\$default" in st[i].methodName) {
|
||||
throw AssertionError("KCallable.call should invoke the method directly if all arguments are provided")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
::foo.callBy(mapOf(::foo.parameters.single() to "box"))
|
||||
return "OK"
|
||||
}
|
||||
+31
@@ -0,0 +1,31 @@
|
||||
// TODO: muted automatically, investigate should it be ran for JS or not
|
||||
// IGNORE_BACKEND: JS, NATIVE
|
||||
|
||||
// WITH_REFLECT
|
||||
|
||||
import kotlin.test.assertEquals
|
||||
|
||||
fun primitives(
|
||||
boolean: Boolean = true,
|
||||
character: Char = 'z',
|
||||
byte: Byte = 5.toByte(),
|
||||
short: Short = (-5).toShort(),
|
||||
int: Int = 2000000000,
|
||||
float: Float = -2.72f,
|
||||
long: Long = 1000000000000000000L,
|
||||
double: Double = 3.14159265359
|
||||
) {
|
||||
assertEquals(true, boolean)
|
||||
assertEquals('z', character)
|
||||
assertEquals(5.toByte(), byte)
|
||||
assertEquals((-5).toShort(), short)
|
||||
assertEquals(2000000000, int)
|
||||
assertEquals(-2.72f, float)
|
||||
assertEquals(1000000000000000000L, long)
|
||||
assertEquals(3.14159265359, double)
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
::primitives.callBy(emptyMap())
|
||||
return "OK"
|
||||
}
|
||||
+32
@@ -0,0 +1,32 @@
|
||||
// TODO: muted automatically, investigate should it be ran for JS or not
|
||||
// IGNORE_BACKEND: JS, NATIVE
|
||||
|
||||
// WITH_REFLECT
|
||||
|
||||
import kotlin.reflect.IllegalCallableAccessException
|
||||
import kotlin.reflect.jvm.isAccessible
|
||||
|
||||
class A {
|
||||
private fun foo(default: Any? = this) {
|
||||
}
|
||||
|
||||
fun f() = A::foo
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
val a = A()
|
||||
val f = a.f()
|
||||
|
||||
try {
|
||||
f.callBy(mapOf(f.parameters.first() to a))
|
||||
return "Fail: IllegalCallableAccessException should have been thrown"
|
||||
}
|
||||
catch (e: IllegalCallableAccessException) {
|
||||
// OK
|
||||
}
|
||||
|
||||
f.isAccessible = true
|
||||
f.callBy(mapOf(f.parameters.first() to a))
|
||||
|
||||
return "OK"
|
||||
}
|
||||
+8
@@ -0,0 +1,8 @@
|
||||
// TODO: muted automatically, investigate should it be ran for JS or not
|
||||
// IGNORE_BACKEND: JS, NATIVE
|
||||
|
||||
// WITH_REFLECT
|
||||
|
||||
class A(val result: String = "OK")
|
||||
|
||||
fun box(): String = ::A.callBy(mapOf()).result
|
||||
+13
@@ -0,0 +1,13 @@
|
||||
// TODO: muted automatically, investigate should it be ran for JS or not
|
||||
// IGNORE_BACKEND: JS, NATIVE
|
||||
|
||||
// WITH_REFLECT
|
||||
|
||||
class A(val result: String = "OK") {
|
||||
fun foo(x: Int = 42): String {
|
||||
assert(x == 42) { x }
|
||||
return result
|
||||
}
|
||||
}
|
||||
|
||||
fun box(): String = A::foo.callBy(mapOf(A::foo.parameters.first() to A()))
|
||||
+8
@@ -0,0 +1,8 @@
|
||||
// TODO: muted automatically, investigate should it be ran for JS or not
|
||||
// IGNORE_BACKEND: JS, NATIVE
|
||||
|
||||
// WITH_REFLECT
|
||||
|
||||
fun foo(result: String = "OK") = result
|
||||
|
||||
fun box(): String = ::foo.callBy(mapOf())
|
||||
Vendored
+12
@@ -0,0 +1,12 @@
|
||||
// TODO: muted automatically, investigate should it be ran for JS or not
|
||||
// IGNORE_BACKEND: JS, NATIVE
|
||||
|
||||
// WITH_REFLECT
|
||||
|
||||
import kotlin.test.assertEquals
|
||||
|
||||
fun box(): String {
|
||||
assertEquals("Deprecated", Deprecated::class.simpleName)
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
// TODO: muted automatically, investigate should it be ran for JS or not
|
||||
// IGNORE_BACKEND: JS, NATIVE
|
||||
|
||||
// WITH_REFLECT
|
||||
|
||||
import kotlin.test.*
|
||||
import kotlin.reflect.KClass
|
||||
|
||||
fun box(): String {
|
||||
val any = Array<Any>::class
|
||||
val string = Array<String>::class
|
||||
|
||||
assertNotEquals<KClass<*>>(any, string)
|
||||
assertNotEquals<Class<*>>(any.java, string.java)
|
||||
|
||||
return "OK"
|
||||
}
|
||||
+31
@@ -0,0 +1,31 @@
|
||||
// TODO: muted automatically, investigate should it be ran for JS or not
|
||||
// IGNORE_BACKEND: JS, NATIVE
|
||||
|
||||
// WITH_REFLECT
|
||||
|
||||
import kotlin.test.assertEquals
|
||||
|
||||
fun box(): String {
|
||||
assertEquals("Any", Any::class.simpleName)
|
||||
assertEquals("String", String::class.simpleName)
|
||||
assertEquals("CharSequence", CharSequence::class.simpleName)
|
||||
assertEquals("Number", Number::class.simpleName)
|
||||
assertEquals("Int", Int::class.simpleName)
|
||||
assertEquals("Long", Long::class.simpleName)
|
||||
|
||||
assertEquals("Array", Array<Any>::class.simpleName)
|
||||
assertEquals("Array", Array<IntArray>::class.simpleName)
|
||||
|
||||
assertEquals("Companion", Int.Companion::class.simpleName)
|
||||
assertEquals("Companion", Double.Companion::class.simpleName)
|
||||
assertEquals("Companion", Char.Companion::class.simpleName)
|
||||
|
||||
assertEquals("IntRange", IntRange::class.simpleName)
|
||||
|
||||
assertEquals("List", List::class.simpleName)
|
||||
|
||||
// TODO: this is wrong but should be fixed
|
||||
assertEquals("List", MutableList::class.simpleName)
|
||||
|
||||
return "OK"
|
||||
}
|
||||
+33
@@ -0,0 +1,33 @@
|
||||
// TODO: muted automatically, investigate should it be ran for JS or not
|
||||
// IGNORE_BACKEND: JS, NATIVE
|
||||
|
||||
// WITH_REFLECT
|
||||
|
||||
import kotlin.test.*
|
||||
import kotlin.reflect.*
|
||||
import kotlin.reflect.jvm.*
|
||||
|
||||
class Klass
|
||||
|
||||
inline fun <reified T> arrayClass(): KClass<Array<T>> = Array<T>::class
|
||||
|
||||
fun box(): String {
|
||||
assertEquals("Array", arrayClass<Int>().simpleName)
|
||||
assertEquals("Array", arrayClass<Int?>().simpleName)
|
||||
assertEquals("Array", arrayClass<Array<Int>>().simpleName)
|
||||
assertEquals("Array", arrayClass<Klass>().simpleName)
|
||||
assertEquals("Array", arrayClass<Klass?>().simpleName)
|
||||
assertEquals("Array", arrayClass<Array<Klass>>().simpleName)
|
||||
assertEquals("Array", arrayClass<Array<Klass?>>().simpleName)
|
||||
|
||||
// Should not be that way. Fix this test when backend is fixed.
|
||||
assertEquals("[Ljava.lang.Object;", arrayClass<Int>().jvmName)
|
||||
assertEquals("[Ljava.lang.Object;", arrayClass<Int?>().jvmName)
|
||||
assertEquals("[Ljava.lang.Object;", arrayClass<Array<Int>>().jvmName)
|
||||
assertEquals("[Ljava.lang.Object;", arrayClass<Klass>().jvmName)
|
||||
assertEquals("[Ljava.lang.Object;", arrayClass<Klass?>().jvmName)
|
||||
assertEquals("[Ljava.lang.Object;", arrayClass<Array<Klass>>().jvmName)
|
||||
assertEquals("[Ljava.lang.Object;", arrayClass<Array<Klass?>>().jvmName)
|
||||
|
||||
return "OK"
|
||||
}
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
// IGNORE_BACKEND: NATIVE
|
||||
// WITH_REFLECT
|
||||
|
||||
import kotlin.test.assertEquals
|
||||
|
||||
class Generic<K, V>
|
||||
|
||||
fun box(): String {
|
||||
val g = Generic::class
|
||||
assertEquals("Generic", g.simpleName)
|
||||
return "OK"
|
||||
}
|
||||
Vendored
+33
@@ -0,0 +1,33 @@
|
||||
// TODO: muted automatically, investigate should it be ran for JS or not
|
||||
// IGNORE_BACKEND: JS, NATIVE
|
||||
|
||||
// WITH_REFLECT
|
||||
|
||||
import kotlin.test.*
|
||||
|
||||
class Klass
|
||||
class Other
|
||||
|
||||
inline fun <reified T : Any> simpleName(): String =
|
||||
T::class.simpleName!!
|
||||
|
||||
inline fun <reified T1 : Any, reified T2 : Any> twoReifiedParams(): String =
|
||||
"${T1::class.simpleName!!}, ${T2::class.simpleName!!}"
|
||||
|
||||
inline fun <reified T : Any> myJavaClass(): Class<T> =
|
||||
T::class.java
|
||||
|
||||
fun box(): String {
|
||||
assertEquals("Klass", simpleName<Klass>())
|
||||
assertEquals("Int", simpleName<Int>())
|
||||
assertEquals("Array", simpleName<Array<Int>>())
|
||||
assertEquals("Error", simpleName<Error>())
|
||||
assertEquals("Klass, Other", twoReifiedParams<Klass, Other>())
|
||||
|
||||
assertEquals(String::class.java, myJavaClass<String>())
|
||||
assertEquals(IntArray::class.java, myJavaClass<IntArray>())
|
||||
assertEquals(Klass::class.java, myJavaClass<Klass>())
|
||||
assertEquals(Error::class.java, myJavaClass<Error>())
|
||||
|
||||
return "OK"
|
||||
}
|
||||
+9
@@ -0,0 +1,9 @@
|
||||
// IGNORE_BACKEND: NATIVE
|
||||
// WITH_REFLECT
|
||||
|
||||
class A
|
||||
|
||||
fun box(): String {
|
||||
val klass = A::class
|
||||
return if (klass.toString() == "class A") "OK" else "Fail: $klass"
|
||||
}
|
||||
+17
@@ -0,0 +1,17 @@
|
||||
// TODO: muted automatically, investigate should it be ran for JS or not
|
||||
// IGNORE_BACKEND: JS, NATIVE
|
||||
|
||||
// WITH_REFLECT
|
||||
|
||||
import kotlin.test.assertEquals
|
||||
|
||||
class Klass
|
||||
|
||||
fun box(): String {
|
||||
assertEquals("Klass", Klass::class.simpleName)
|
||||
assertEquals("Date", java.util.Date::class.simpleName)
|
||||
assertEquals("ObjectRef", kotlin.jvm.internal.Ref.ObjectRef::class.simpleName)
|
||||
assertEquals("Void", java.lang.Void::class.simpleName)
|
||||
|
||||
return "OK"
|
||||
}
|
||||
+51
@@ -0,0 +1,51 @@
|
||||
// TODO: muted automatically, investigate should it be ran for JS or not
|
||||
// IGNORE_BACKEND: JS, NATIVE
|
||||
|
||||
// WITH_REFLECT
|
||||
|
||||
import kotlin.reflect.*
|
||||
import kotlin.test.*
|
||||
|
||||
class A {
|
||||
companion object C
|
||||
}
|
||||
|
||||
enum class E {
|
||||
ENTRY;
|
||||
companion object {}
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
val obj = A::class.companionObject
|
||||
assertNotNull(obj)
|
||||
assertEquals("C", obj!!.simpleName)
|
||||
|
||||
assertEquals(A.C, A::class.companionObjectInstance)
|
||||
assertEquals(A.C, obj.objectInstance)
|
||||
|
||||
assertNull(A.C::class.companionObject)
|
||||
assertNull(A.C::class.companionObjectInstance)
|
||||
|
||||
assertEquals(E.Companion, E::class.companionObjectInstance)
|
||||
|
||||
assertEquals(String, String::class.companionObjectInstance)
|
||||
assertEquals(String, String.Companion::class.objectInstance)
|
||||
assertEquals(Enum, Enum::class.companionObjectInstance)
|
||||
assertEquals(Enum, Enum.Companion::class.objectInstance)
|
||||
assertEquals(Double, Double::class.companionObjectInstance)
|
||||
assertEquals(Double, Double.Companion::class.objectInstance)
|
||||
assertEquals(Float, Float::class.companionObjectInstance)
|
||||
assertEquals(Float, Float.Companion::class.objectInstance)
|
||||
assertEquals(Int, Int::class.companionObjectInstance)
|
||||
assertEquals(Int, Int.Companion::class.objectInstance)
|
||||
assertEquals(Long, Long::class.companionObjectInstance)
|
||||
assertEquals(Long, Long.Companion::class.objectInstance)
|
||||
assertEquals(Short, Short::class.companionObjectInstance)
|
||||
assertEquals(Short, Short.Companion::class.objectInstance)
|
||||
assertEquals(Byte, Byte::class.companionObjectInstance)
|
||||
assertEquals(Byte, Byte.Companion::class.objectInstance)
|
||||
assertEquals(Char, Char::class.companionObjectInstance)
|
||||
assertEquals(Char, Char.Companion::class.objectInstance)
|
||||
|
||||
return "OK"
|
||||
}
|
||||
+76
@@ -0,0 +1,76 @@
|
||||
// TODO: muted automatically, investigate should it be ran for JS or not
|
||||
// IGNORE_BACKEND: JS, NATIVE
|
||||
|
||||
// WITH_REFLECT
|
||||
|
||||
import kotlin.reflect.full.createInstance
|
||||
import kotlin.test.assertTrue
|
||||
import kotlin.test.fail
|
||||
|
||||
// Good classes
|
||||
|
||||
class Simple
|
||||
class PrimaryWithDefaults(val d1: String = "d1", val d2: Int = 2)
|
||||
class Secondary(val s: String) {
|
||||
constructor() : this("s")
|
||||
}
|
||||
class SecondaryWithDefaults(val s: String) {
|
||||
constructor(x: Int = 0) : this(x.toString())
|
||||
}
|
||||
class SecondaryWithDefaultsNoPrimary {
|
||||
constructor(x: Int) {}
|
||||
constructor(s: String = "") {}
|
||||
}
|
||||
|
||||
// Bad classes
|
||||
|
||||
class NoNoArgConstructor(val s: String) {
|
||||
constructor(x: Int) : this(x.toString())
|
||||
}
|
||||
class NoArgAndDefault() {
|
||||
constructor(x: Int = 0) : this()
|
||||
}
|
||||
class DefaultPrimaryAndDefaultSecondary(val s: String = "") {
|
||||
constructor(x: Int = 0) : this(x.toString())
|
||||
}
|
||||
class SeveralDefaultSecondaries {
|
||||
constructor(x: Int = 0) {}
|
||||
constructor(s: String = "") {}
|
||||
constructor(d: Double = 3.14) {}
|
||||
}
|
||||
class PrivateConstructor private constructor()
|
||||
object Object
|
||||
|
||||
// -----------
|
||||
|
||||
inline fun <reified T : Any> test() {
|
||||
val instance = T::class.createInstance()
|
||||
assertTrue(instance is T)
|
||||
}
|
||||
|
||||
inline fun <reified T : Any> testFail() {
|
||||
try {
|
||||
T::class.createInstance()
|
||||
fail("createInstance should have failed on ${T::class}")
|
||||
} catch (e: Exception) {
|
||||
// OK
|
||||
}
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
test<Any>()
|
||||
test<Simple>()
|
||||
test<PrimaryWithDefaults>()
|
||||
test<Secondary>()
|
||||
test<SecondaryWithDefaults>()
|
||||
test<SecondaryWithDefaultsNoPrimary>()
|
||||
|
||||
testFail<NoNoArgConstructor>()
|
||||
testFail<NoArgAndDefault>()
|
||||
testFail<DefaultPrimaryAndDefaultSecondary>()
|
||||
testFail<SeveralDefaultSecondaries>()
|
||||
testFail<PrivateConstructor>()
|
||||
testFail<Object>()
|
||||
|
||||
return "OK"
|
||||
}
|
||||
+53
@@ -0,0 +1,53 @@
|
||||
// TODO: muted automatically, investigate should it be ran for JS or not
|
||||
// IGNORE_BACKEND: JS, NATIVE
|
||||
|
||||
// WITH_REFLECT
|
||||
// FILE: I.java
|
||||
|
||||
public class I {
|
||||
public static void publicStaticI() {}
|
||||
public void publicMemberI() {}
|
||||
private static void privateStaticI() {}
|
||||
private void privateMemberI() {}
|
||||
}
|
||||
|
||||
// FILE: J.java
|
||||
|
||||
public class J extends I {
|
||||
public static void publicStaticJ() {}
|
||||
public void publicMemberJ() {}
|
||||
private static void privateStaticJ() {}
|
||||
private void privateMemberJ() {}
|
||||
}
|
||||
|
||||
// FILE: K.kt
|
||||
|
||||
import kotlin.reflect.full.declaredMembers
|
||||
import kotlin.test.assertEquals
|
||||
|
||||
open class K : J() {
|
||||
open fun publicKFun() {}
|
||||
private fun privateKFun() {}
|
||||
var publicKProp = Unit
|
||||
private val privateKProp = Unit
|
||||
}
|
||||
|
||||
class L : K() {
|
||||
fun publicLFun() {}
|
||||
private fun privateLFun() {}
|
||||
val publicLProp = Unit
|
||||
private var privateLProp = Unit
|
||||
}
|
||||
|
||||
inline fun <reified T> test(vararg names: String) {
|
||||
assertEquals(names.toSet(), T::class.declaredMembers.map { it.name }.toSet())
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
test<I>("publicStaticI", "publicMemberI", "privateStaticI", "privateMemberI")
|
||||
test<J>("publicStaticJ", "publicMemberJ", "privateStaticJ", "privateMemberJ")
|
||||
test<K>("publicKFun", "privateKFun", "publicKProp", "privateKProp")
|
||||
test<L>("publicLFun", "privateLFun", "publicLProp", "privateLProp")
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
// TODO: muted automatically, investigate should it be ran for JS or not
|
||||
// IGNORE_BACKEND: JS, NATIVE
|
||||
|
||||
// WITH_REFLECT
|
||||
|
||||
import kotlin.test.assertEquals
|
||||
import kotlin.test.assertTrue
|
||||
import kotlin.reflect.jvm.jvmName
|
||||
|
||||
class Klass {
|
||||
class Nested
|
||||
companion object
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
assertEquals("Klass", Klass::class.jvmName)
|
||||
assertEquals("Klass\$Nested", Klass.Nested::class.jvmName)
|
||||
assertEquals("Klass\$Companion", Klass.Companion::class.jvmName)
|
||||
|
||||
assertEquals("java.lang.Object", Any::class.jvmName)
|
||||
assertEquals("int", Int::class.jvmName)
|
||||
assertEquals("[I", IntArray::class.jvmName)
|
||||
assertEquals("java.util.List", List::class.jvmName)
|
||||
assertEquals("java.util.List", MutableList::class.jvmName)
|
||||
assertEquals("java.lang.String", String::class.jvmName)
|
||||
assertEquals("java.lang.String", java.lang.String::class.jvmName)
|
||||
|
||||
assertEquals("[Ljava.lang.Object;", Array<Any>::class.jvmName)
|
||||
assertEquals("[Ljava.lang.Integer;", Array<Int>::class.jvmName)
|
||||
assertEquals("[[Ljava.lang.String;", Array<Array<String>>::class.jvmName)
|
||||
|
||||
assertEquals("java.util.Date", java.util.Date::class.jvmName)
|
||||
assertEquals("kotlin.jvm.internal.Ref\$ObjectRef", kotlin.jvm.internal.Ref.ObjectRef::class.jvmName)
|
||||
assertEquals("java.lang.Void", java.lang.Void::class.jvmName)
|
||||
|
||||
class Local
|
||||
val l = Local::class.jvmName
|
||||
assertTrue(l != null && l.startsWith("JvmNameKt\$") && "\$box\$" in l && l.endsWith("\$Local"))
|
||||
|
||||
val obj = object {}
|
||||
val o = obj.javaClass.kotlin.jvmName
|
||||
assertTrue(o != null && o.startsWith("JvmNameKt\$") && "\$box\$" in o && o.endsWith("\$1"))
|
||||
|
||||
return "OK"
|
||||
}
|
||||
+42
@@ -0,0 +1,42 @@
|
||||
// IGNORE_BACKEND: NATIVE
|
||||
// WITH_REFLECT
|
||||
|
||||
import kotlin.reflect.KClass
|
||||
import kotlin.test.assertEquals
|
||||
|
||||
fun check(klass: KClass<*>, expectedName: String) {
|
||||
assertEquals(expectedName, klass.simpleName)
|
||||
}
|
||||
|
||||
fun localInMethod() {
|
||||
fun localInMethod(unused: Any?) {
|
||||
class Local
|
||||
check(Local::class, "Local")
|
||||
|
||||
class `Local$With$Dollars`
|
||||
check(`Local$With$Dollars`::class, "Local\$With\$Dollars")
|
||||
}
|
||||
localInMethod(null)
|
||||
|
||||
class Local
|
||||
check(Local::class, "Local")
|
||||
|
||||
class `Local$With$Dollars`
|
||||
check(`Local$With$Dollars`::class, "Local\$With\$Dollars")
|
||||
}
|
||||
|
||||
class LocalInConstructor {
|
||||
init {
|
||||
class Local
|
||||
check(Local::class, "Local")
|
||||
|
||||
class `Local$With$Dollars`
|
||||
check(`Local$With$Dollars`::class, "Local\$With\$Dollars")
|
||||
}
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
localInMethod()
|
||||
LocalInConstructor()
|
||||
return "OK"
|
||||
}
|
||||
+62
@@ -0,0 +1,62 @@
|
||||
// TODO: muted automatically, investigate should it be ran for JS or not
|
||||
// IGNORE_BACKEND: JS, NATIVE
|
||||
|
||||
// WITH_REFLECT
|
||||
// FULL_JDK
|
||||
|
||||
import kotlin.reflect.KClass
|
||||
import kotlin.reflect.jvm.*
|
||||
import kotlin.test.assertEquals
|
||||
|
||||
class A {
|
||||
companion object {}
|
||||
inner class Inner
|
||||
class Nested
|
||||
private class PrivateNested
|
||||
}
|
||||
|
||||
fun nestedNames(c: KClass<*>) = c.nestedClasses.map { it.simpleName ?: throw AssertionError("Unnamed class: ${it.java}") }.sorted()
|
||||
|
||||
fun box(): String {
|
||||
// Kotlin class without nested classes
|
||||
assertEquals(emptyList<String>(), nestedNames(A.Inner::class))
|
||||
// Kotlin class with nested classes
|
||||
assertEquals(listOf("Companion", "Inner", "Nested", "PrivateNested"), nestedNames(A::class))
|
||||
|
||||
// Java class without nested classes
|
||||
assertEquals(emptyList<String>(), nestedNames(Error::class))
|
||||
// Java class with nested classes
|
||||
assertEquals(listOf("State", "UncaughtExceptionHandler"), nestedNames(Thread::class))
|
||||
|
||||
// Built-ins
|
||||
assertEquals(emptyList<String>(), nestedNames(Array<Any>::class))
|
||||
assertEquals(emptyList<String>(), nestedNames(CharSequence::class))
|
||||
assertEquals(listOf("Companion"), nestedNames(String::class))
|
||||
|
||||
assertEquals(emptyList<String>(), nestedNames(Collection::class))
|
||||
assertEquals(emptyList<String>(), nestedNames(MutableCollection::class))
|
||||
assertEquals(emptyList<String>(), nestedNames(List::class))
|
||||
assertEquals(emptyList<String>(), nestedNames(MutableList::class))
|
||||
assertEquals(listOf("Entry"), nestedNames(Map::class))
|
||||
assertEquals(emptyList<String>(), nestedNames(Map.Entry::class))
|
||||
assertEquals(emptyList<String>(), nestedNames(MutableMap.MutableEntry::class))
|
||||
|
||||
// TODO: should be MutableEntry. Currently we do not distinguish between Map and MutableMap.
|
||||
assertEquals(listOf("Entry"), nestedNames(MutableMap::class))
|
||||
|
||||
// Primitives
|
||||
for (primitive in listOf(Byte::class, Double::class, Float::class, Int::class, Long::class, Short::class, Char::class)) {
|
||||
assertEquals(listOf("Companion"), nestedNames(primitive))
|
||||
}
|
||||
assertEquals(emptyList<String>(), nestedNames(Boolean::class))
|
||||
|
||||
// Primitive arrays
|
||||
for (primitiveArray in listOf(
|
||||
ByteArray::class, DoubleArray::class, FloatArray::class, IntArray::class,
|
||||
LongArray::class, ShortArray::class, CharArray::class, BooleanArray::class
|
||||
)) {
|
||||
assertEquals(emptyList<String>(), nestedNames(primitiveArray))
|
||||
}
|
||||
|
||||
return "OK"
|
||||
}
|
||||
+26
@@ -0,0 +1,26 @@
|
||||
// TODO: muted automatically, investigate should it be ran for JS or not
|
||||
// IGNORE_BACKEND: JS, NATIVE
|
||||
|
||||
// WITH_REFLECT
|
||||
// FILE: J.java
|
||||
|
||||
public class J {
|
||||
public class Inner {}
|
||||
|
||||
public static class Nested {}
|
||||
|
||||
private static class PrivateNested {}
|
||||
|
||||
// This anonymous class should not appear in 'nestedClasses'
|
||||
private final Object o = new Object() {};
|
||||
}
|
||||
|
||||
// FILE: K.kt
|
||||
|
||||
import kotlin.test.assertEquals
|
||||
|
||||
fun box(): String {
|
||||
assertEquals(listOf("Inner", "Nested", "PrivateNested"), J::class.nestedClasses.map { it.simpleName!! }.sorted())
|
||||
|
||||
return "OK"
|
||||
}
|
||||
+36
@@ -0,0 +1,36 @@
|
||||
// TODO: muted automatically, investigate should it be ran for JS or not
|
||||
// IGNORE_BACKEND: JS, NATIVE
|
||||
|
||||
// WITH_REFLECT
|
||||
|
||||
import kotlin.test.assertEquals
|
||||
|
||||
object Obj {
|
||||
fun foo() = 1
|
||||
}
|
||||
|
||||
class A {
|
||||
companion object {
|
||||
fun foo() = 2
|
||||
}
|
||||
}
|
||||
|
||||
class B {
|
||||
companion object Factory {
|
||||
fun foo() = 3
|
||||
}
|
||||
}
|
||||
|
||||
class C
|
||||
|
||||
fun box(): String {
|
||||
assertEquals(1, Obj::class.objectInstance!!.foo())
|
||||
assertEquals(2, A.Companion::class.objectInstance!!.foo())
|
||||
assertEquals(3, B.Factory::class.objectInstance!!.foo())
|
||||
|
||||
assertEquals(null, C::class.objectInstance)
|
||||
assertEquals(null, String::class.objectInstance)
|
||||
assertEquals(Unit, Unit::class.objectInstance)
|
||||
|
||||
return "OK"
|
||||
}
|
||||
+18
@@ -0,0 +1,18 @@
|
||||
// TODO: muted automatically, investigate should it be ran for JS or not
|
||||
// IGNORE_BACKEND: JS, NATIVE
|
||||
|
||||
// WITH_REFLECT
|
||||
|
||||
import kotlin.test.assertEquals
|
||||
import kotlin.test.assertFalse
|
||||
|
||||
fun box(): String {
|
||||
val x = Int::class.javaPrimitiveType!!.kotlin
|
||||
val y = Int::class.javaObjectType.kotlin
|
||||
|
||||
assertEquals(x, y)
|
||||
assertEquals(x.hashCode(), y.hashCode())
|
||||
assertFalse(x === y)
|
||||
|
||||
return "OK"
|
||||
}
|
||||
+41
@@ -0,0 +1,41 @@
|
||||
// TODO: muted automatically, investigate should it be ran for JS or not
|
||||
// IGNORE_BACKEND: JS, NATIVE
|
||||
|
||||
// WITH_REFLECT
|
||||
|
||||
import kotlin.test.assertEquals
|
||||
|
||||
class Klass {
|
||||
class Nested
|
||||
companion object
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
assertEquals("Klass", Klass::class.qualifiedName)
|
||||
assertEquals("Klass.Nested", Klass.Nested::class.qualifiedName)
|
||||
assertEquals("Klass.Companion", Klass.Companion::class.qualifiedName)
|
||||
|
||||
assertEquals("kotlin.Any", Any::class.qualifiedName)
|
||||
assertEquals("kotlin.Int", Int::class.qualifiedName)
|
||||
assertEquals("kotlin.Int.Companion", Int.Companion::class.qualifiedName)
|
||||
assertEquals("kotlin.IntArray", IntArray::class.qualifiedName)
|
||||
assertEquals("kotlin.collections.List", List::class.qualifiedName)
|
||||
assertEquals("kotlin.String", String::class.qualifiedName)
|
||||
assertEquals("kotlin.String", java.lang.String::class.qualifiedName)
|
||||
|
||||
assertEquals("kotlin.Array", Array<Any>::class.qualifiedName)
|
||||
assertEquals("kotlin.Array", Array<Int>::class.qualifiedName)
|
||||
assertEquals("kotlin.Array", Array<Array<String>>::class.qualifiedName)
|
||||
|
||||
assertEquals("java.util.Date", java.util.Date::class.qualifiedName)
|
||||
assertEquals("kotlin.jvm.internal.Ref.ObjectRef", kotlin.jvm.internal.Ref.ObjectRef::class.qualifiedName)
|
||||
assertEquals("java.lang.Void", java.lang.Void::class.qualifiedName)
|
||||
|
||||
class Local
|
||||
assertEquals(null, Local::class.qualifiedName)
|
||||
|
||||
val o = object {}
|
||||
assertEquals(null, o.javaClass.kotlin.qualifiedName)
|
||||
|
||||
return "OK"
|
||||
}
|
||||
+26
@@ -0,0 +1,26 @@
|
||||
// TODO: muted automatically, investigate should it be ran for JS or not
|
||||
// IGNORE_BACKEND: JS, NATIVE
|
||||
|
||||
// WITH_REFLECT
|
||||
|
||||
import kotlin.reflect.KTypeProjection
|
||||
import kotlin.reflect.full.createType
|
||||
import kotlin.reflect.full.starProjectedType
|
||||
import kotlin.test.assertEquals
|
||||
|
||||
class Foo<K, V>
|
||||
|
||||
fun box(): String {
|
||||
val foo = Foo::class.starProjectedType
|
||||
assertEquals(Foo::class, foo.classifier)
|
||||
assertEquals(listOf(KTypeProjection.STAR, KTypeProjection.STAR), foo.arguments)
|
||||
assertEquals(foo, Foo::class.createType(listOf(KTypeProjection.STAR, KTypeProjection.STAR)))
|
||||
|
||||
assertEquals(String::class, String::class.starProjectedType.classifier)
|
||||
assertEquals(listOf(), String::class.starProjectedType.arguments)
|
||||
|
||||
val tp = Foo::class.typeParameters.first()
|
||||
assertEquals(tp.createType(), tp.starProjectedType)
|
||||
|
||||
return "OK"
|
||||
}
|
||||
+24
@@ -0,0 +1,24 @@
|
||||
// TODO: muted automatically, investigate should it be ran for JS or not
|
||||
// IGNORE_BACKEND: JS, NATIVE
|
||||
|
||||
// WITH_REFLECT
|
||||
|
||||
import kotlin.reflect.*
|
||||
import kotlin.test.assertEquals
|
||||
|
||||
annotation class A1
|
||||
|
||||
annotation class A2(val k: KClass<*>, val s: A1)
|
||||
|
||||
fun box(): String {
|
||||
assertEquals(1, A1::class.constructors.size)
|
||||
assertEquals(A1::class.primaryConstructor, A1::class.constructors.single())
|
||||
|
||||
val cs = A2::class.constructors
|
||||
assertEquals(1, cs.size)
|
||||
assertEquals(A2::class.primaryConstructor, cs.single())
|
||||
val params = cs.single().parameters
|
||||
assertEquals(listOf("k", "s"), params.map { it.name })
|
||||
|
||||
return "OK"
|
||||
}
|
||||
Vendored
+21
@@ -0,0 +1,21 @@
|
||||
// TODO: muted automatically, investigate should it be ran for JS or not
|
||||
// IGNORE_BACKEND: JS, NATIVE
|
||||
|
||||
// WITH_REFLECT
|
||||
|
||||
import kotlin.test.assertTrue
|
||||
|
||||
interface Interface
|
||||
object Obj
|
||||
|
||||
class C {
|
||||
companion object
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
assertTrue(Interface::class.constructors.isEmpty())
|
||||
assertTrue(Obj::class.constructors.isEmpty())
|
||||
assertTrue(C.Companion::class.constructors.isEmpty())
|
||||
|
||||
return "OK"
|
||||
}
|
||||
+13
@@ -0,0 +1,13 @@
|
||||
// TODO: muted automatically, investigate should it be ran for JS or not
|
||||
// IGNORE_BACKEND: JS, NATIVE
|
||||
|
||||
// WITH_REFLECT
|
||||
|
||||
import kotlin.test.assertEquals
|
||||
|
||||
class A
|
||||
|
||||
fun box(): String {
|
||||
assertEquals("<init>", ::A.name)
|
||||
return "OK"
|
||||
}
|
||||
+57
@@ -0,0 +1,57 @@
|
||||
// TODO: muted automatically, investigate should it be ran for JS or not
|
||||
// IGNORE_BACKEND: JS, NATIVE
|
||||
|
||||
// WITH_REFLECT
|
||||
|
||||
import kotlin.test.assertNull
|
||||
import kotlin.test.assertNotNull
|
||||
import kotlin.reflect.*
|
||||
|
||||
class OnlyPrimary
|
||||
|
||||
class PrimaryWithSecondary(val s: String) {
|
||||
constructor(x: Int) : this(x.toString())
|
||||
|
||||
override fun toString() = s
|
||||
}
|
||||
|
||||
class OnlySecondary {
|
||||
constructor(s: String)
|
||||
}
|
||||
|
||||
class TwoSecondaries {
|
||||
constructor(s: String)
|
||||
constructor(d: Double)
|
||||
}
|
||||
|
||||
enum class En
|
||||
|
||||
interface I
|
||||
object O
|
||||
class C {
|
||||
companion object
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
val p1 = OnlyPrimary::class.primaryConstructor
|
||||
assertNotNull(p1)
|
||||
assert(p1!!.call() is OnlyPrimary)
|
||||
|
||||
val p2 = PrimaryWithSecondary::class.primaryConstructor
|
||||
assertNotNull(p2)
|
||||
assert(p2!!.call("beer").toString() == "beer")
|
||||
|
||||
val p3 = OnlySecondary::class.primaryConstructor
|
||||
assertNull(p3)
|
||||
|
||||
val p4 = TwoSecondaries::class.primaryConstructor
|
||||
assertNull(p4)
|
||||
|
||||
assertNotNull(En::class.primaryConstructor) // TODO: maybe primaryConstructor should be null for enum classes
|
||||
|
||||
assertNull(I::class.primaryConstructor)
|
||||
assertNull(O::class.primaryConstructor)
|
||||
assertNull(C.Companion::class.primaryConstructor)
|
||||
|
||||
return "OK"
|
||||
}
|
||||
+34
@@ -0,0 +1,34 @@
|
||||
// TODO: muted automatically, investigate should it be ran for JS or not
|
||||
// IGNORE_BACKEND: JS, NATIVE
|
||||
|
||||
// WITH_REFLECT
|
||||
|
||||
import java.util.Collections
|
||||
import kotlin.reflect.*
|
||||
import kotlin.test.assertEquals
|
||||
import kotlin.test.assertTrue
|
||||
|
||||
open class A private constructor(x: Int) {
|
||||
public constructor(s: String): this(s.length)
|
||||
constructor(): this("")
|
||||
}
|
||||
|
||||
class B : A("")
|
||||
|
||||
class C {
|
||||
class Nested
|
||||
inner class Inner
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
assertEquals(3, A::class.constructors.size)
|
||||
assertEquals(1, B::class.constructors.size)
|
||||
|
||||
assertTrue(Collections.disjoint(A::class.members, A::class.constructors))
|
||||
assertTrue(Collections.disjoint(B::class.members, B::class.constructors))
|
||||
|
||||
assertEquals(1, C.Nested::class.constructors.size)
|
||||
assertEquals(1, C.Inner::class.constructors.size)
|
||||
|
||||
return "OK"
|
||||
}
|
||||
+14
@@ -0,0 +1,14 @@
|
||||
// TODO: muted automatically, investigate should it be ran for JS or not
|
||||
// IGNORE_BACKEND: JS, NATIVE
|
||||
|
||||
// WITH_REFLECT
|
||||
|
||||
import kotlin.test.assertEquals
|
||||
|
||||
annotation class Foo
|
||||
|
||||
fun box(): String {
|
||||
val foo = Foo::class.constructors.single().call()
|
||||
assertEquals(Foo::class, foo.annotationClass)
|
||||
return "OK"
|
||||
}
|
||||
+16
@@ -0,0 +1,16 @@
|
||||
// TODO: muted automatically, investigate should it be ran for JS or not
|
||||
// IGNORE_BACKEND: JS, NATIVE
|
||||
|
||||
// WITH_REFLECT
|
||||
|
||||
import kotlin.reflect.KClass
|
||||
import kotlin.test.assertEquals
|
||||
|
||||
annotation class Anno(val klasses: Array<KClass<*>> = arrayOf(String::class, Int::class))
|
||||
|
||||
fun box(): String {
|
||||
val anno = Anno::class.constructors.single().callBy(emptyMap())
|
||||
assertEquals(listOf(String::class, Int::class), anno.klasses.toList())
|
||||
assertEquals("@Anno(klasses=[class java.lang.String, int])", anno.toString())
|
||||
return "OK"
|
||||
}
|
||||
+81
@@ -0,0 +1,81 @@
|
||||
// TODO: muted automatically, investigate should it be ran for JS or not
|
||||
// IGNORE_BACKEND: JS, NATIVE
|
||||
|
||||
// WITH_REFLECT
|
||||
// FILE: J.java
|
||||
|
||||
public interface J {
|
||||
@interface NoParams {}
|
||||
|
||||
@interface OneDefault {
|
||||
String s() default "OK";
|
||||
}
|
||||
|
||||
@interface OneNonDefault {
|
||||
String s();
|
||||
}
|
||||
|
||||
@interface TwoParamsOneDefault {
|
||||
String s();
|
||||
int x() default 42;
|
||||
}
|
||||
|
||||
@interface TwoNonDefaults {
|
||||
String string();
|
||||
Class<?> clazz();
|
||||
}
|
||||
|
||||
@interface ManyDefaultParams {
|
||||
int i() default 0;
|
||||
String s() default "";
|
||||
double d() default 3.14;
|
||||
}
|
||||
}
|
||||
|
||||
// FILE: K.kt
|
||||
|
||||
import J.*
|
||||
import kotlin.reflect.KClass
|
||||
import kotlin.reflect.primaryConstructor
|
||||
import kotlin.test.assertEquals
|
||||
import kotlin.test.assertFails
|
||||
|
||||
inline fun <reified T : Annotation> create(args: Map<String, Any?>): T {
|
||||
val ctor = T::class.constructors.single()
|
||||
return ctor.callBy(args.mapKeys { entry -> ctor.parameters.single { it.name == entry.key } })
|
||||
}
|
||||
|
||||
inline fun <reified T : Annotation> create(): T = create(emptyMap())
|
||||
|
||||
fun box(): String {
|
||||
create<NoParams>()
|
||||
|
||||
val t1 = create<OneDefault>()
|
||||
assertEquals("OK", t1.s)
|
||||
assertFails { create<OneDefault>(mapOf("s" to 42)) }
|
||||
|
||||
val t2 = create<OneNonDefault>(mapOf("s" to "OK"))
|
||||
assertEquals("OK", t2.s)
|
||||
assertFails { create<OneNonDefault>() }
|
||||
|
||||
val t3 = create<TwoParamsOneDefault>(mapOf("s" to "OK"))
|
||||
assertEquals("OK", t3.s)
|
||||
assertEquals(42, t3.x)
|
||||
val t4 = create<TwoParamsOneDefault>(mapOf("s" to "OK", "x" to 239))
|
||||
assertEquals(239, t4.x)
|
||||
assertFails { create<TwoParamsOneDefault>(mapOf("s" to "Fail", "x" to "Fail")) }
|
||||
|
||||
assertFails("KClass (not Class) instances should be passed as arguments") {
|
||||
create<TwoNonDefaults>(mapOf("clazz" to String::class.java, "string" to "Fail"))
|
||||
}
|
||||
|
||||
val t5 = create<TwoNonDefaults>(mapOf("clazz" to String::class, "string" to "OK"))
|
||||
assertEquals("OK", t5.string)
|
||||
|
||||
val t6 = create<ManyDefaultParams>()
|
||||
assertEquals(0, t6.i)
|
||||
assertEquals("", t6.s)
|
||||
assertEquals(3.14, t6.d)
|
||||
|
||||
return "OK"
|
||||
}
|
||||
+53
@@ -0,0 +1,53 @@
|
||||
// TODO: muted automatically, investigate should it be ran for JS or not
|
||||
// IGNORE_BACKEND: JS, NATIVE
|
||||
|
||||
// WITH_REFLECT
|
||||
|
||||
import kotlin.reflect.KClass
|
||||
import kotlin.reflect.primaryConstructor
|
||||
import kotlin.test.assertEquals
|
||||
import kotlin.test.assertFails
|
||||
|
||||
annotation class NoParams
|
||||
annotation class OneDefault(val s: String = "OK")
|
||||
annotation class OneNonDefault(val s: String)
|
||||
annotation class TwoParamsOneDefault(val s: String, val x: Int = 42)
|
||||
annotation class TwoParamsOneDefaultKClass(val string: String, val klass: KClass<*> = Number::class)
|
||||
annotation class TwoNonDefaults(val string: String, val klass: KClass<*>)
|
||||
|
||||
|
||||
inline fun <reified T : Annotation> create(args: Map<String, Any?>): T {
|
||||
val ctor = T::class.constructors.single()
|
||||
return ctor.callBy(args.mapKeys { entry -> ctor.parameters.single { it.name == entry.key } })
|
||||
}
|
||||
|
||||
inline fun <reified T : Annotation> create(): T = create(emptyMap())
|
||||
|
||||
fun box(): String {
|
||||
create<NoParams>()
|
||||
|
||||
val t1 = create<OneDefault>()
|
||||
assertEquals("OK", t1.s)
|
||||
assertFails { create<OneDefault>(mapOf("s" to 42)) }
|
||||
|
||||
val t2 = create<OneNonDefault>(mapOf("s" to "OK"))
|
||||
assertEquals("OK", t2.s)
|
||||
assertFails { create<OneNonDefault>() }
|
||||
|
||||
val t3 = create<TwoParamsOneDefault>(mapOf("s" to "OK"))
|
||||
assertEquals("OK", t3.s)
|
||||
assertEquals(42, t3.x)
|
||||
val t4 = create<TwoParamsOneDefault>(mapOf("s" to "OK", "x" to 239))
|
||||
assertEquals(239, t4.x)
|
||||
assertFails { create<TwoParamsOneDefault>(mapOf("s" to "Fail", "x" to "Fail")) }
|
||||
|
||||
val t5 = create<TwoParamsOneDefaultKClass>(mapOf("string" to "OK"))
|
||||
assertEquals(Number::class, t5.klass)
|
||||
|
||||
assertFails("KClass (not Class) instances should be passed as arguments") {
|
||||
create<TwoNonDefaults>(mapOf("klass" to String::class.java, "string" to "Fail"))
|
||||
}
|
||||
|
||||
val t6 = create<TwoNonDefaults>(mapOf("klass" to String::class, "string" to "OK"))
|
||||
return t6.string
|
||||
}
|
||||
+93
@@ -0,0 +1,93 @@
|
||||
// TODO: muted automatically, investigate should it be ran for JS or not
|
||||
// IGNORE_BACKEND: JS, NATIVE
|
||||
|
||||
// WITH_REFLECT
|
||||
// FILE: J.java
|
||||
|
||||
public interface J {
|
||||
@interface NoParams {}
|
||||
|
||||
@interface OneDefault {
|
||||
String foo() default "foo";
|
||||
}
|
||||
|
||||
@interface OneDefaultValue {
|
||||
String value() default "value";
|
||||
}
|
||||
|
||||
@interface OneNonDefault {
|
||||
String foo();
|
||||
}
|
||||
|
||||
@interface OneNonDefaultValue {
|
||||
String value();
|
||||
}
|
||||
|
||||
@interface TwoParamsOneDefault {
|
||||
String string();
|
||||
Class<?> clazz() default Object.class;
|
||||
}
|
||||
|
||||
@interface TwoParamsOneValueOneDefault {
|
||||
String value();
|
||||
Class<?> clazz() default Object.class;
|
||||
}
|
||||
|
||||
@interface TwoNonDefaults {
|
||||
String string();
|
||||
Class<?> clazz();
|
||||
}
|
||||
|
||||
@interface ManyDefaults {
|
||||
int i() default 0;
|
||||
String s() default "";
|
||||
double d() default 3.14;
|
||||
}
|
||||
}
|
||||
|
||||
// FILE: K.kt
|
||||
|
||||
import J.*
|
||||
import kotlin.reflect.KClass
|
||||
import kotlin.reflect.primaryConstructor
|
||||
import kotlin.test.assertEquals
|
||||
import kotlin.test.assertFails
|
||||
|
||||
inline fun <reified T : Annotation> create(vararg args: Any?): T =
|
||||
T::class.constructors.single().call(*args)
|
||||
|
||||
fun box(): String {
|
||||
create<NoParams>()
|
||||
|
||||
assertFails { create<OneDefault>() }
|
||||
assertFails { create<OneDefault>("") }
|
||||
assertFails { create<OneDefault>("", "") }
|
||||
|
||||
assertFails { create<OneDefaultValue>() }
|
||||
create<OneDefaultValue>("")
|
||||
assertFails { create<OneDefaultValue>("", "") }
|
||||
|
||||
assertFails { create<OneNonDefault>() }
|
||||
assertFails { create<OneNonDefault>("") }
|
||||
|
||||
assertFails { create<OneNonDefaultValue>() }
|
||||
create<OneNonDefaultValue>("")
|
||||
|
||||
assertFails { create<TwoParamsOneDefault>() }
|
||||
assertFails { create<TwoParamsOneDefault>("") }
|
||||
assertFails { create<TwoParamsOneDefault>("", Any::class) }
|
||||
assertFails { create<TwoParamsOneDefault>(Any::class, "") }
|
||||
|
||||
assertFails { create<TwoParamsOneValueOneDefault>() }
|
||||
assertFails { create<TwoParamsOneValueOneDefault>("") }
|
||||
assertFails { create<TwoParamsOneValueOneDefault>("", Any::class) }
|
||||
assertFails { create<TwoParamsOneValueOneDefault>(Any::class, "") }
|
||||
|
||||
assertFails { create<TwoNonDefaults>("", Any::class) }
|
||||
assertFails { create<TwoNonDefaults>(Any::class, "") }
|
||||
|
||||
assertFails { create<ManyDefaults>() }
|
||||
assertFails { create<ManyDefaults>(42, "Fail", 2.72) }
|
||||
|
||||
return "OK"
|
||||
}
|
||||
+38
@@ -0,0 +1,38 @@
|
||||
// TODO: muted automatically, investigate should it be ran for JS or not
|
||||
// IGNORE_BACKEND: JS, NATIVE
|
||||
|
||||
// WITH_REFLECT
|
||||
|
||||
import kotlin.reflect.KClass
|
||||
import kotlin.reflect.primaryConstructor
|
||||
import kotlin.test.assertEquals
|
||||
import kotlin.test.assertFails
|
||||
|
||||
annotation class NoParams
|
||||
annotation class OneDefault(val s: String = "Fail")
|
||||
annotation class TwoNonDefaults(val string: String, val klass: KClass<*>)
|
||||
|
||||
inline fun <reified T : Annotation> create(vararg args: Any?): T =
|
||||
T::class.constructors.single().call(*args)
|
||||
|
||||
fun box(): String {
|
||||
create<NoParams>()
|
||||
assertFails { create<NoParams>("Fail") }
|
||||
|
||||
assertFails { create<OneDefault>() }
|
||||
assertFails { create<OneDefault>(42) }
|
||||
val o = create<OneDefault>("OK")
|
||||
assertEquals("OK", o.s)
|
||||
|
||||
assertFails("call() should fail because arguments were passed in an incorrect order") {
|
||||
create<TwoNonDefaults>(Any::class, "Fail")
|
||||
}
|
||||
assertFails("call() should fail because KClass (not Class) instances should be passed as arguments") {
|
||||
create<TwoNonDefaults>("Fail", Any::class.java)
|
||||
}
|
||||
|
||||
val k = create<TwoNonDefaults>("OK", Int::class)
|
||||
assertEquals(Int::class, k.klass)
|
||||
|
||||
return k.string
|
||||
}
|
||||
backend.native/tests/external/codegen/box/reflection/createAnnotation/createJdkAnnotationInstance.kt
Vendored
+18
@@ -0,0 +1,18 @@
|
||||
// TODO: muted automatically, investigate should it be ran for JS or not
|
||||
// IGNORE_BACKEND: JS, NATIVE
|
||||
|
||||
// WITH_REFLECT
|
||||
|
||||
import java.lang.annotation.Retention
|
||||
import java.lang.annotation.RetentionPolicy
|
||||
import kotlin.test.assertEquals
|
||||
|
||||
fun box(): String {
|
||||
val ctor = Retention::class.constructors.single()
|
||||
val r = ctor.callBy(mapOf(
|
||||
ctor.parameters.single { it.name == "value" } to RetentionPolicy.RUNTIME
|
||||
))
|
||||
assertEquals(RetentionPolicy.RUNTIME, r.value as RetentionPolicy)
|
||||
assertEquals(Retention::class.java.classLoader, r.javaClass.classLoader)
|
||||
return "OK"
|
||||
}
|
||||
Vendored
+50
@@ -0,0 +1,50 @@
|
||||
// TODO: muted automatically, investigate should it be ran for JS or not
|
||||
// IGNORE_BACKEND: JS, NATIVE
|
||||
|
||||
// WITH_REFLECT
|
||||
|
||||
import kotlin.reflect.KClass
|
||||
import kotlin.test.assertEquals
|
||||
|
||||
annotation class Foo(val value: String)
|
||||
|
||||
annotation class Anno(
|
||||
val level: DeprecationLevel,
|
||||
val klass: KClass<*>,
|
||||
val foo: Foo,
|
||||
val levels: Array<DeprecationLevel>,
|
||||
val klasses: Array<KClass<*>>,
|
||||
val foos: Array<Foo>
|
||||
)
|
||||
|
||||
@Anno(
|
||||
DeprecationLevel.WARNING,
|
||||
Number::class,
|
||||
Foo("OK"),
|
||||
arrayOf(DeprecationLevel.WARNING),
|
||||
arrayOf(Number::class),
|
||||
arrayOf(Foo("OK"))
|
||||
)
|
||||
fun foo() {}
|
||||
|
||||
fun box(): String {
|
||||
// Construct an annotation with exactly the same parameters, check that the proxy created by Kotlin and by Java reflection are the same and have the same hash code
|
||||
val a1 = Anno::class.constructors.single().call(
|
||||
DeprecationLevel.WARNING,
|
||||
Number::class,
|
||||
Foo::class.constructors.single().call("OK"),
|
||||
arrayOf(DeprecationLevel.WARNING),
|
||||
arrayOf(Number::class),
|
||||
arrayOf(Foo::class.constructors.single().call("OK"))
|
||||
)
|
||||
val a2 = ::foo.annotations.single() as Anno
|
||||
|
||||
assertEquals(a1, a2)
|
||||
assertEquals(a2, a1)
|
||||
assertEquals(a1.hashCode(), a2.hashCode())
|
||||
|
||||
assertEquals("@Anno(level=WARNING, klass=class java.lang.Number, foo=@Foo(value=OK), " +
|
||||
"levels=[WARNING], klasses=[class java.lang.Number], foos=[@Foo(value=OK)])", a1.toString())
|
||||
|
||||
return "OK"
|
||||
}
|
||||
Vendored
+49
@@ -0,0 +1,49 @@
|
||||
// TODO: muted automatically, investigate should it be ran for JS or not
|
||||
// IGNORE_BACKEND: JS, NATIVE
|
||||
|
||||
// WITH_REFLECT
|
||||
|
||||
package test
|
||||
|
||||
annotation class A
|
||||
annotation class B(val s: String)
|
||||
|
||||
@A
|
||||
@B("2")
|
||||
fun javaReflectionAnnotationInstances() {}
|
||||
|
||||
fun box(): String {
|
||||
val createA = A::class.constructors.single()
|
||||
|
||||
val a1 = createA.call()
|
||||
if (a1.toString() != "@test.A()") return "Fail: toString does not correspond to the documentation of java.lang.annotation.Annotation#toString: $a1"
|
||||
|
||||
val a2 = createA.call()
|
||||
if (a1 === a2) return "Fail: instances created by the constructor should be different"
|
||||
if (a1 != a2) return "Fail: any instance of A should be equal to any other instance of A"
|
||||
if (a1.hashCode() != a2.hashCode()) return "Fail: hash codes of equal instances should be equal"
|
||||
if (a1.hashCode() != 0) return "Fail: hashCode does not correspond to the documentation of java.lang.annotation.Annotation#hashCode: ${a1.hashCode()}"
|
||||
|
||||
val createB = B::class.constructors.single()
|
||||
val b1 = createB.call("1")
|
||||
if (b1.toString() != "@test.B(s=1)") return "Fail: toString does not correspond to the documentation of java.lang.annotation.Annotation#toString: $b1"
|
||||
if (b1 != b1) return "Fail: instance should be equal to itself"
|
||||
|
||||
val b2 = createB.call("2")
|
||||
if (b1 == b2) return "Fail: instances with different data should not be equal"
|
||||
if (b1.hashCode() == b2.hashCode()) return "Fail: hash codes of different instances should very likely be also different"
|
||||
|
||||
val a3 = ::javaReflectionAnnotationInstances.annotations.filterIsInstance<A>().single()
|
||||
if (a1 === a3) return "Fail: instance created by the constructor and the one obtained from Java reflection should be different"
|
||||
if (a1 != a3) return "Fail: instance created by the constructor should be equal to the one obtained from Java reflection"
|
||||
if (a3 != a1) return "Fail: instance obtained from Java reflection should be equal to the one created by the constructor"
|
||||
if (a1.hashCode() != a3.hashCode()) return "Fail: hash codes of equal instances should be equal"
|
||||
|
||||
val b3 = ::javaReflectionAnnotationInstances.annotations.filterIsInstance<B>().single()
|
||||
if (b2 === b3) return "Fail: instance created by the constructor and the one obtained from Java reflection should be different"
|
||||
if (b2 != b3) return "Fail: instance created by the constructor should be equal to the one obtained from Java reflection"
|
||||
if (b3 != b2) return "Fail: instance obtained from Java reflection should be equal to the one created by the constructor"
|
||||
if (b2.hashCode() != b3.hashCode()) return "Fail: hash codes of equal instances should be equal"
|
||||
|
||||
return "OK"
|
||||
}
|
||||
Vendored
+66
@@ -0,0 +1,66 @@
|
||||
// TODO: muted automatically, investigate should it be ran for JS or not
|
||||
// IGNORE_BACKEND: JS, NATIVE
|
||||
|
||||
// WITH_REFLECT
|
||||
|
||||
import kotlin.test.assertEquals
|
||||
import kotlin.test.assertNotEquals
|
||||
|
||||
annotation class D(val d: Double)
|
||||
annotation class F(val f: Float)
|
||||
|
||||
/*
|
||||
// TODO: uncomment once KT-13887 is implemented
|
||||
@D(Double.NaN)
|
||||
fun dnan() {}
|
||||
|
||||
@F(Float.NaN)
|
||||
fun fnan() {}
|
||||
*/
|
||||
|
||||
@D(-0.0)
|
||||
fun dMinusZero() {}
|
||||
@D(+0.0)
|
||||
fun dPlusZero() {}
|
||||
|
||||
@F(-0.0f)
|
||||
fun fMinusZero() {}
|
||||
@F(+0.0f)
|
||||
fun fPlusZero() {}
|
||||
|
||||
fun check(x: Any, y: Any) {
|
||||
assertEquals(x, y)
|
||||
assertEquals(y, x)
|
||||
assertEquals(x.hashCode(), y.hashCode())
|
||||
assertEquals(x.toString(), y.toString())
|
||||
}
|
||||
|
||||
fun checkNot(x: Any, y: Any) {
|
||||
assertNotEquals(x, y)
|
||||
assertNotEquals(y, x)
|
||||
assertNotEquals(x.hashCode(), y.hashCode())
|
||||
assertNotEquals(x.toString(), y.toString())
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
/*
|
||||
check(::dnan.annotations.single() as D, D::class.constructors.single().call(Double.NaN))
|
||||
check(::fnan.annotations.single() as F, F::class.constructors.single().call(Float.NaN))
|
||||
*/
|
||||
|
||||
val dmz = D::class.constructors.single().call(-0.0)
|
||||
val dpz = D::class.constructors.single().call(+0.0)
|
||||
val fmz = F::class.constructors.single().call(-0.0f)
|
||||
val fpz = F::class.constructors.single().call(+0.0f)
|
||||
check(::dMinusZero.annotations.single() as D, dmz)
|
||||
check(::dPlusZero.annotations.single() as D, dpz)
|
||||
check(::fMinusZero.annotations.single() as F, fmz)
|
||||
check(::fPlusZero.annotations.single() as F, fpz)
|
||||
|
||||
checkNot(dmz, dpz)
|
||||
checkNot(fmz, fpz)
|
||||
checkNot(dmz, fmz)
|
||||
checkNot(dpz, fpz)
|
||||
|
||||
return "OK"
|
||||
}
|
||||
Vendored
+18
@@ -0,0 +1,18 @@
|
||||
// TODO: muted automatically, investigate should it be ran for JS or not
|
||||
// IGNORE_BACKEND: JS, NATIVE
|
||||
|
||||
// WITH_REFLECT
|
||||
|
||||
import kotlin.test.assertEquals
|
||||
import kotlin.test.assertNotEquals
|
||||
|
||||
annotation class Anno(val equals: Boolean)
|
||||
|
||||
fun box(): String {
|
||||
val t = Anno::class.constructors.single().call(true)
|
||||
val f = Anno::class.constructors.single().call(false)
|
||||
assertEquals(true, t.equals)
|
||||
assertEquals(false, f.equals)
|
||||
assertNotEquals(t, f)
|
||||
return "OK"
|
||||
}
|
||||
Vendored
+85
@@ -0,0 +1,85 @@
|
||||
// TODO: muted automatically, investigate should it be ran for JS or not
|
||||
// IGNORE_BACKEND: JS, NATIVE
|
||||
|
||||
// WITH_REFLECT
|
||||
|
||||
import kotlin.test.assertEquals
|
||||
|
||||
annotation class Anno(
|
||||
val b: Byte,
|
||||
val c: Char,
|
||||
val d: Double,
|
||||
val f: Float,
|
||||
val i: Int,
|
||||
val j: Long,
|
||||
val s: Short,
|
||||
val z: Boolean,
|
||||
val ba: ByteArray,
|
||||
val ca: CharArray,
|
||||
val da: DoubleArray,
|
||||
val fa: FloatArray,
|
||||
val ia: IntArray,
|
||||
val ja: LongArray,
|
||||
val sa: ShortArray,
|
||||
val za: BooleanArray,
|
||||
val str: String,
|
||||
val stra: Array<String>
|
||||
)
|
||||
|
||||
@Anno(
|
||||
1.toByte(),
|
||||
'x',
|
||||
3.14,
|
||||
-2.72f,
|
||||
42424242,
|
||||
239239239239239L,
|
||||
42.toShort(),
|
||||
true,
|
||||
byteArrayOf((-1).toByte()),
|
||||
charArrayOf('y'),
|
||||
doubleArrayOf(-3.14159),
|
||||
floatArrayOf(2.7218f),
|
||||
intArrayOf(424242),
|
||||
longArrayOf(239239239239L),
|
||||
shortArrayOf((-43).toShort()),
|
||||
booleanArrayOf(false, true),
|
||||
"lol",
|
||||
arrayOf("rofl")
|
||||
)
|
||||
fun foo() {}
|
||||
|
||||
fun box(): String {
|
||||
// Construct an annotation with exactly the same parameters, check that the proxy created by Kotlin and by Java reflection are the same and have the same hash code
|
||||
val a1 = Anno::class.constructors.single().call(
|
||||
1.toByte(),
|
||||
'x',
|
||||
3.14,
|
||||
-2.72f,
|
||||
42424242,
|
||||
239239239239239L,
|
||||
42.toShort(),
|
||||
true,
|
||||
byteArrayOf((-1).toByte()),
|
||||
charArrayOf('y'),
|
||||
doubleArrayOf(-3.14159),
|
||||
floatArrayOf(2.7218f),
|
||||
intArrayOf(424242),
|
||||
longArrayOf(239239239239L),
|
||||
shortArrayOf((-43).toShort()),
|
||||
booleanArrayOf(false, true),
|
||||
"lol",
|
||||
arrayOf("rofl")
|
||||
)
|
||||
|
||||
val a2 = ::foo.annotations.single() as Anno
|
||||
|
||||
assertEquals(a1, a2)
|
||||
assertEquals(a2, a1)
|
||||
assertEquals(a1.hashCode(), a2.hashCode())
|
||||
|
||||
assertEquals("@Anno(b=1, c=x, d=3.14, f=-2.72, i=42424242, j=239239239239239, s=42, z=true, " +
|
||||
"ba=[-1], ca=[y], da=[-3.14159], fa=[2.7218], ia=[424242], ja=[239239239239], sa=[-43], za=[false, true], " +
|
||||
"str=lol, stra=[rofl])", a1.toString())
|
||||
|
||||
return "OK"
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user