JS backend: tests for reflection support
This commit is contained in:
@@ -0,0 +1,40 @@
|
||||
package foo
|
||||
|
||||
native
|
||||
open class A(val value: String) {
|
||||
}
|
||||
|
||||
class B : A("B") {
|
||||
fun bar(): String = "B.bar ${value}"
|
||||
var prop: String = "B prop"
|
||||
}
|
||||
|
||||
native fun A.bar(): String = js.noImpl
|
||||
|
||||
native var A.prop: String
|
||||
get() = js.noImpl
|
||||
set(value) = js.noImpl
|
||||
|
||||
fun box(): String {
|
||||
var a: A = A("A")
|
||||
val b: B = B()
|
||||
|
||||
assertEquals("A.bar A", a.bar())
|
||||
assertEquals("B.bar B", b.bar())
|
||||
|
||||
assertEquals("A.bar A", a.(A::bar)())
|
||||
assertEquals("B.bar B", b.(A::bar)())
|
||||
|
||||
a.prop = "prop"
|
||||
assertEquals("prop", a.prop)
|
||||
assertEquals("prop", (A::prop).get(a))
|
||||
|
||||
a = b
|
||||
assertEquals("B.bar B", a.bar())
|
||||
assertEquals("B.bar B", a.(A::bar)())
|
||||
|
||||
assertEquals("B prop", a.prop)
|
||||
assertEquals("B prop", (A::prop).get(a))
|
||||
|
||||
return "OK";
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
package foo
|
||||
|
||||
native
|
||||
class A(val v: String) {
|
||||
fun m(i:Int, s:String): String = js.noImpl
|
||||
}
|
||||
native
|
||||
fun A.nativeExt(i:Int, s:String): String = js.noImpl
|
||||
|
||||
native("nativeExt2AnotherName")
|
||||
fun A.nativeExt2(i:Int, s:String): String = js.noImpl
|
||||
|
||||
fun bar(a: A, extLambda: A.(Int, String) -> String): String = a.(extLambda)(4, "boo")
|
||||
|
||||
fun box(): String {
|
||||
val a = A("test")
|
||||
|
||||
assertEquals("A.m test 4 boo", a.m(4, "boo"))
|
||||
assertEquals("A.m test 4 boo", bar(a, A::m))
|
||||
|
||||
assertEquals("nativeExt test 4 boo", a.nativeExt(4, "boo"))
|
||||
assertEquals("nativeExt test 4 boo", bar(a, A::nativeExt))
|
||||
|
||||
assertEquals("nativeExt2 test 4 boo", a.nativeExt2(4, "boo"))
|
||||
assertEquals("nativeExt2 test 4 boo", bar(a, A::nativeExt2))
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
package foo
|
||||
|
||||
open class A(val v: String) {
|
||||
open fun m(i:Int, s:String): String = "A.m ${this.v} $i $s"
|
||||
}
|
||||
|
||||
class B(v: String): A(v) {
|
||||
override fun m(i:Int, s:String): String = "B.m ${this.v} $i $s"
|
||||
}
|
||||
|
||||
native
|
||||
fun bar(a: A, extLambda: A.(Int, String) -> String): String = noImpl
|
||||
|
||||
fun A.topLevelExt(i:Int, s:String): String = "A::topLevelExt ${this.v} $i $s"
|
||||
|
||||
fun box(): String {
|
||||
val a = A("test")
|
||||
|
||||
var r = bar(a) { i, s -> "${this.v} $i $s"}
|
||||
if (r != "test 4 boo") return r
|
||||
|
||||
fun A.LocalExt(i:Int, s:String): String = "A::LocalExt ${this.v} $i $s"
|
||||
|
||||
r = bar(a, A::topLevelExt)
|
||||
if (r != "A::topLevelExt test 4 boo") return r
|
||||
|
||||
r = bar(a, A::LocalExt)
|
||||
if (r != "A::LocalExt test 4 boo") return r
|
||||
|
||||
r = bar(a, A::m)
|
||||
if (r != "A.m test 4 boo") return r
|
||||
|
||||
val b = B("test")
|
||||
r = bar(b, A::m)
|
||||
if (r != "B.m test 4 boo") return r
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
package foo
|
||||
|
||||
native
|
||||
fun nativeFun(i:Int, s:String): String = js.noImpl
|
||||
|
||||
fun bar(funRef: (Int, String) -> String): String = funRef(4, "boo")
|
||||
|
||||
fun box(): String {
|
||||
var r = nativeFun(4, "boo")
|
||||
if (r != "nativeFun 4 boo") return r
|
||||
|
||||
r = bar(::nativeFun)
|
||||
if (r != "nativeFun 4 boo") return r
|
||||
|
||||
r = (::nativeFun)(4, "boo")
|
||||
if (r != "nativeFun 4 boo") return r
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
package foo
|
||||
|
||||
native
|
||||
fun run(i:Int, s:String, funRef: (Int, String) -> String): String = noImpl
|
||||
|
||||
fun funTopLevel(i:Int, s:String): String = "funTopLevel $i $s"
|
||||
|
||||
fun box(): String {
|
||||
fun funLocal(i:Int, s:String): String = "funLocal $i $s"
|
||||
|
||||
// Check for lambda
|
||||
var r = run(4, "boo") { i, s -> "$i $s"}
|
||||
if (r != "4 boo") return r
|
||||
|
||||
r = run(4, "boo", ::funTopLevel)
|
||||
if (r != "funTopLevel 4 boo") return r
|
||||
|
||||
r = run(4, "boo", ::funLocal)
|
||||
if (r != "funLocal 4 boo") return r
|
||||
|
||||
return "OK"
|
||||
}
|
||||
Reference in New Issue
Block a user