JS backend: tests for reflection support
This commit is contained in:
@@ -0,0 +1,12 @@
|
||||
// This test was adapted from compiler/testData/codegen/boxWithStdlib/callableReference/function/.
|
||||
package foo
|
||||
|
||||
abstract class A {
|
||||
abstract fun foo(): String
|
||||
}
|
||||
|
||||
class B : A() {
|
||||
override fun foo() = "OK"
|
||||
}
|
||||
|
||||
fun box(): String = B().(A::foo)()
|
||||
@@ -0,0 +1,8 @@
|
||||
// This test was adapted from compiler/testData/codegen/boxWithStdlib/callableReference/function/.
|
||||
package foo
|
||||
|
||||
fun box(): String {
|
||||
if (true.(Boolean::not)() != false) return "Fail 1"
|
||||
if (false.(Boolean::not)() != true) return "Fail 2"
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
package foo
|
||||
|
||||
class A {
|
||||
val s = "sA"
|
||||
fun memBar(other: String): String = s +":memBar:" + other
|
||||
}
|
||||
|
||||
fun A.extBar(other: String):String = s + ":extBar:" + other
|
||||
|
||||
fun box():String {
|
||||
fun A.locExtBar(other: String):String = s + ":locExtBar:" + other
|
||||
|
||||
val a = A()
|
||||
|
||||
var r = a.(A::memBar)("!!")
|
||||
if (r != "sA:memBar:!!") return r
|
||||
|
||||
r = a.(A::extBar)("!!")
|
||||
if (r != "sA:extBar:!!") return r
|
||||
|
||||
r = a.(A::locExtBar)("!!")
|
||||
if (r != "sA:locExtBar:!!") return r
|
||||
|
||||
return "OK"
|
||||
}
|
||||
+32
@@ -0,0 +1,32 @@
|
||||
package foo
|
||||
|
||||
fun run(a: A, arg: String, funRef:A.(String) -> String): String {
|
||||
return a.(funRef)(arg)
|
||||
}
|
||||
|
||||
class A {
|
||||
val s = "sA"
|
||||
fun memBar(other: String): String = s +":memBar:" + other
|
||||
}
|
||||
|
||||
fun A.extBar(other: String):String = s + ":extBar:" + other
|
||||
|
||||
fun box():String {
|
||||
fun A.locExtBar(other: String):String = s + ":locExtBar:" + other
|
||||
|
||||
val a = A()
|
||||
|
||||
var r = run(a, "!!", A::memBar)
|
||||
if (r != "sA:memBar:!!") return r
|
||||
|
||||
r = run(a, "!!", A::extBar)
|
||||
if (r != "sA:extBar:!!") return r
|
||||
|
||||
r = run(a, "!!", A::locExtBar)
|
||||
if (r != "sA:locExtBar:!!") return r
|
||||
|
||||
r = run(a, "!!") {A.(other:String):String -> s + ":literal:" + other }
|
||||
if (r != "sA:literal:!!") return r
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
// This test was adapted from compiler/testData/codegen/boxWithStdlib/callableReference/function/.
|
||||
package foo
|
||||
|
||||
class A {
|
||||
fun bar(k: Int) = k
|
||||
|
||||
fun result() = this.(::bar)(111)
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
val result = A().result()
|
||||
if (result != 111) return "Fail $result"
|
||||
return "OK"
|
||||
}
|
||||
+15
@@ -0,0 +1,15 @@
|
||||
// This test was adapted from compiler/testData/codegen/boxWithStdlib/callableReference/function/.
|
||||
package foo
|
||||
|
||||
class A {
|
||||
fun o() = 111
|
||||
fun k(k: Int) = k
|
||||
}
|
||||
|
||||
fun A.bar() = this.(::o)() + this.(A::k)(222)
|
||||
|
||||
fun box(): String {
|
||||
val result = A().bar()
|
||||
if (result != 333) return "Fail $result"
|
||||
return "OK"
|
||||
}
|
||||
+22
@@ -0,0 +1,22 @@
|
||||
// This test was adapted from compiler/testData/codegen/boxWithStdlib/callableReference/function/.
|
||||
package foo
|
||||
|
||||
fun run(arg1: A, funRef:A.() -> String): String {
|
||||
return arg1.funRef()
|
||||
}
|
||||
|
||||
class A {
|
||||
fun foo() = "OK"
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
val x = A::foo
|
||||
var r = A().x()
|
||||
if (r != "OK") return r
|
||||
|
||||
r = run(A(), A::foo)
|
||||
if (r != "OK") return r
|
||||
|
||||
return "OK"
|
||||
}
|
||||
|
||||
+21
@@ -0,0 +1,21 @@
|
||||
// This test was adapted from compiler/testData/codegen/boxWithStdlib/callableReference/function/.
|
||||
package foo
|
||||
|
||||
fun run(arg1: A, arg2: String, funRef:A.(String) -> String): String {
|
||||
return arg1.funRef(arg2)
|
||||
}
|
||||
|
||||
class A {
|
||||
fun foo(result: String):String = result
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
val x = A::foo
|
||||
var r = A().x("OK")
|
||||
|
||||
if (r != "OK") return r
|
||||
|
||||
r = run(A(), "OK", A::foo)
|
||||
if (r != "OK") return r
|
||||
return "OK"
|
||||
}
|
||||
+29
@@ -0,0 +1,29 @@
|
||||
// This test was adapted from compiler/testData/codegen/boxWithStdlib/callableReference/function/.
|
||||
package foo
|
||||
|
||||
fun run(arg1: A, funRef:A.() -> Unit): Unit {
|
||||
return arg1.funRef()
|
||||
}
|
||||
|
||||
class A {
|
||||
var result = "Fail"
|
||||
|
||||
fun foo() {
|
||||
result = "OK"
|
||||
}
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
val a = A()
|
||||
val x = A::foo
|
||||
a.x()
|
||||
var r = a.result
|
||||
if (r != "OK") return r
|
||||
|
||||
val a1 = A()
|
||||
run(a1, A::foo)
|
||||
r = a.result
|
||||
if (r != "OK") return r
|
||||
|
||||
return "OK"
|
||||
}
|
||||
+29
@@ -0,0 +1,29 @@
|
||||
// This test was adapted from compiler/testData/codegen/boxWithStdlib/callableReference/function/.
|
||||
package foo
|
||||
|
||||
fun run(arg1: A, arg2: String, funRef:A.(String) -> Unit): Unit {
|
||||
return arg1.funRef(arg2)
|
||||
}
|
||||
|
||||
class A {
|
||||
var result = "Fail"
|
||||
|
||||
fun foo(newResult: String) {
|
||||
result = newResult
|
||||
}
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
val a = A()
|
||||
val x = A::foo
|
||||
a.x("OK")
|
||||
var r = a.result
|
||||
if (r != "OK") return r
|
||||
|
||||
val a1 = A()
|
||||
run(a1, "OK", A::foo)
|
||||
r = a1.result
|
||||
if (r != "OK") return r
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
package foo
|
||||
|
||||
open class A {
|
||||
open fun foo(a:String,b:String): String = "fooA:" + a + b
|
||||
}
|
||||
|
||||
class B : A() {
|
||||
override fun foo(a:String,b:String): String = "fooB:" + a + b
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
val b = B()
|
||||
var ref = A::foo
|
||||
val result = b.(ref)("1", "2")
|
||||
return (if (result == "fooB:12") "OK" else result)
|
||||
}
|
||||
+15
@@ -0,0 +1,15 @@
|
||||
package foo
|
||||
|
||||
open class A {
|
||||
open fun foo(a:String,b:String): String = "fooA:" + a + b
|
||||
}
|
||||
|
||||
object B : A() {
|
||||
override fun foo(a:String,b:String): String = "fooB:" + a + b
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
var ref = B::foo
|
||||
val result = B.(ref)("1", "2")
|
||||
return (if (result == "fooB:12") "OK" else result)
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
// This test was adapted from compiler/testData/codegen/boxWithStdlib/callableReference/function/local/.
|
||||
package foo
|
||||
|
||||
fun box(): String {
|
||||
var result = "Fail"
|
||||
|
||||
fun changeToOK() { result = "OK" }
|
||||
|
||||
val ok = ::changeToOK
|
||||
ok()
|
||||
return result
|
||||
}
|
||||
+8
@@ -0,0 +1,8 @@
|
||||
// This test was adapted from compiler/testData/codegen/boxWithStdlib/callableReference/function/.
|
||||
package foo
|
||||
|
||||
class A {
|
||||
var result = "OK"
|
||||
}
|
||||
|
||||
fun box() = (::A)().result
|
||||
+6
@@ -0,0 +1,6 @@
|
||||
// This test was adapted from compiler/testData/codegen/boxWithStdlib/callableReference/function/.
|
||||
package foo
|
||||
|
||||
class A(val result: String)
|
||||
|
||||
fun box() = (::A)("OK").result
|
||||
@@ -0,0 +1,21 @@
|
||||
package foo
|
||||
|
||||
class A(val x:Int) {
|
||||
var s = "sA"
|
||||
{
|
||||
s += ":init:" + x
|
||||
}
|
||||
}
|
||||
|
||||
class B(val arg1:String, val arg2:String) {
|
||||
var msg = ""
|
||||
{
|
||||
msg = arg1 + arg2
|
||||
}
|
||||
}
|
||||
|
||||
fun box():String {
|
||||
val ref = ::A
|
||||
var result = ref(1).s + (::B)("23", "45").msg
|
||||
return (if (result == "sA:init:12345") "OK" else result)
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
// This test was adapted from compiler/testData/codegen/boxWithStdlib/callableReference/function/local/.
|
||||
package foo
|
||||
|
||||
class A
|
||||
|
||||
fun box(): String {
|
||||
fun A.foo() = "OK"
|
||||
return A().(A::foo)()
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
// This test was adapted from compiler/testData/codegen/boxWithStdlib/callableReference/function/.
|
||||
package foo
|
||||
|
||||
class A {
|
||||
fun result() = this.(::bar)("OK")
|
||||
}
|
||||
|
||||
fun A.bar(x: String) = x
|
||||
|
||||
fun box() = A().result()
|
||||
@@ -0,0 +1,10 @@
|
||||
// This test was adapted from compiler/testData/codegen/boxWithStdlib/callableReference/function/.
|
||||
package foo
|
||||
|
||||
class A
|
||||
|
||||
fun A.foo() = this.(A::bar)("OK")
|
||||
|
||||
fun A.bar(x: String) = x
|
||||
|
||||
fun box() = A().foo()
|
||||
@@ -0,0 +1,25 @@
|
||||
// This test was adapted from compiler/testData/codegen/boxWithStdlib/callableReference/function/.
|
||||
package foo
|
||||
|
||||
fun <T> run(arg1: A, arg2: T, funRef:A.(T) -> T): T {
|
||||
return arg1.funRef(arg2)
|
||||
}
|
||||
|
||||
class A {
|
||||
var xx: Int = 100
|
||||
}
|
||||
|
||||
fun A.bar(x: Int): Int {
|
||||
this.xx = this.xx * 2
|
||||
return x
|
||||
}
|
||||
|
||||
fun box(): Boolean {
|
||||
val funRef = A::bar
|
||||
val obj = A()
|
||||
var result = obj.(funRef)(25)
|
||||
if (result != 25 || obj.xx != 200) return false
|
||||
|
||||
result = run(A(), 25, funRef)
|
||||
return result == 25 && obj.xx == 200
|
||||
}
|
||||
+21
@@ -0,0 +1,21 @@
|
||||
// This test was adapted from compiler/testData/codegen/boxWithStdlib/callableReference/function/.
|
||||
package foo
|
||||
|
||||
fun run(arg1: A, funRef:A.() -> String): String {
|
||||
return arg1.funRef()
|
||||
}
|
||||
|
||||
class A
|
||||
|
||||
fun A.foo() = "OK"
|
||||
|
||||
fun box(): String {
|
||||
val x = A::foo
|
||||
var r = A().x()
|
||||
if (r != "OK") return r
|
||||
|
||||
r = run(A(), A::foo)
|
||||
if (r != "OK") return r
|
||||
|
||||
return "OK"
|
||||
}
|
||||
+19
@@ -0,0 +1,19 @@
|
||||
// This test was adapted from compiler/testData/codegen/boxWithStdlib/callableReference/function/.
|
||||
package foo
|
||||
|
||||
fun run(arg1: A, arg2: String, funRef:A.(String) -> String): String {
|
||||
return arg1.funRef(arg2)
|
||||
}
|
||||
|
||||
class A
|
||||
|
||||
fun A.foo(result: String) = result
|
||||
|
||||
fun box(): String {
|
||||
val x = A::foo
|
||||
var r = A().x("OK")
|
||||
if (r != "OK") return r
|
||||
|
||||
r = run(A(), "OK", A::foo)
|
||||
return "OK"
|
||||
}
|
||||
+26
@@ -0,0 +1,26 @@
|
||||
// This test was adapted from compiler/testData/codegen/boxWithStdlib/callableReference/function/.
|
||||
package foo
|
||||
|
||||
fun run(arg1: A, funRef:A.() -> Unit): Unit {
|
||||
return arg1.funRef()
|
||||
}
|
||||
|
||||
class A {
|
||||
var result = "Fail"
|
||||
}
|
||||
|
||||
fun A.foo() {
|
||||
result = "OK"
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
val a = A()
|
||||
val x = A::foo
|
||||
a.x()
|
||||
|
||||
if (a.result != "OK") return a.result
|
||||
|
||||
val a1 = A()
|
||||
run(a1, A::foo)
|
||||
return a.result
|
||||
}
|
||||
+26
@@ -0,0 +1,26 @@
|
||||
// This test was adapted from compiler/testData/codegen/boxWithStdlib/callableReference/function/.
|
||||
package foo
|
||||
|
||||
fun run(arg1: A, arg2: String, funRef:A.(String) -> Unit): Unit {
|
||||
return arg1.funRef(arg2)
|
||||
}
|
||||
|
||||
class A {
|
||||
var result = "Fail"
|
||||
}
|
||||
|
||||
fun A.foo(newResult: String) {
|
||||
result = newResult
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
val a = A()
|
||||
val x = A::foo
|
||||
a.x("OK")
|
||||
|
||||
if (a.result != "OK") return a.result
|
||||
|
||||
val a1 = A()
|
||||
run(a1, "OK", A::foo)
|
||||
return a.result
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
// This test was adapted from compiler/testData/codegen/boxWithStdlib/callableReference/function/local/.
|
||||
package foo
|
||||
|
||||
fun box(): String {
|
||||
fun Int.is42With(that: Int) = this + 2 * that == 42
|
||||
return if (16.(Int::is42With)(13)) "OK" else "Fail"
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
// This test was adapted from compiler/testData/codegen/boxWithStdlib/callableReference/function/local/.
|
||||
package foo
|
||||
|
||||
class A
|
||||
|
||||
fun box(): String {
|
||||
var result = "Fail"
|
||||
|
||||
fun A.ext() { result = "OK" }
|
||||
|
||||
val f = A::ext
|
||||
A().f()
|
||||
return result
|
||||
}
|
||||
+22
@@ -0,0 +1,22 @@
|
||||
package foo
|
||||
|
||||
fun Int.sum0(other: Int): Int = this + other;
|
||||
|
||||
fun box(): String {
|
||||
fun Int.sum1(other: Int): Int = this + other
|
||||
|
||||
val sum2 = {Int.(other : Int) : Int -> this + other}
|
||||
|
||||
var x = 10
|
||||
x = x.sum0(5)
|
||||
x = x.sum1(5)
|
||||
x = x.sum2(5)
|
||||
|
||||
var y = 10
|
||||
y = y.(Int::sum0)(5)
|
||||
y = y.(Int::sum1)(5)
|
||||
y = y.sum2(5)
|
||||
|
||||
var result:String = (if (x == y && x == 25) "OK" else "x=${x} y=${y}")
|
||||
return result
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
// This test was adapted from compiler/testData/codegen/boxWithStdlib/callableReference/function/local/.
|
||||
package foo
|
||||
|
||||
fun box(): String {
|
||||
fun foo(): String {
|
||||
fun bar() = "OK"
|
||||
val ref = ::bar
|
||||
return ref()
|
||||
}
|
||||
|
||||
val ref = ::foo
|
||||
return ref()
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
// This test was adapted from compiler/testData/codegen/boxWithStdlib/callableReference/function/local/.
|
||||
package foo
|
||||
|
||||
fun foo(until: Int): String {
|
||||
fun bar(x: Int): String =
|
||||
if (x == until) "OK" else bar(x + 1)
|
||||
return (::bar)(0)
|
||||
}
|
||||
|
||||
fun box() = foo(10)
|
||||
@@ -0,0 +1,7 @@
|
||||
// This test was adapted from compiler/testData/codegen/boxWithStdlib/callableReference/function/local/.
|
||||
package foo
|
||||
|
||||
fun box(): String {
|
||||
fun foo() = "OK"
|
||||
return (::foo)()
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
// This test was adapted from compiler/testData/codegen/boxWithStdlib/callableReference/function/local/.
|
||||
package foo
|
||||
|
||||
fun box(): String {
|
||||
val result = "OK"
|
||||
|
||||
fun foo() = result
|
||||
|
||||
return (::foo)()
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
// This test was adapted from compiler/testData/codegen/boxWithStdlib/callableReference/function/local/.
|
||||
package foo
|
||||
|
||||
fun box(): String {
|
||||
fun foo(s: String) = s
|
||||
return (::foo)("OK")
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
package foo
|
||||
|
||||
fun box(): String {
|
||||
var s = "abc"
|
||||
assertEquals("ABC", s.(String::toUpperCase)())
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
// This test was adapted from compiler/testData/codegen/boxWithStdlib/callableReference/function/.
|
||||
package foo
|
||||
|
||||
fun <T> run(arg1: T, arg2: T, funRef:(T,T) -> T): T {
|
||||
return funRef(arg1, arg2)
|
||||
}
|
||||
|
||||
fun tmp(o: Int, k: Int) = o + k
|
||||
|
||||
class A {
|
||||
fun bar() = (::tmp)(111, 222)
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
val result = A().bar()
|
||||
if (result != 333) return "Fail $result"
|
||||
|
||||
var r = run(111, 222, ::tmp)
|
||||
if (result != 333) return "Fail $result"
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
// This test was adapted from compiler/testData/codegen/boxWithStdlib/callableReference/function/.
|
||||
package foo
|
||||
|
||||
fun <T> run(arg1: T, arg2: T, funRef:(T,T) -> T): T {
|
||||
return funRef(arg1, arg2)
|
||||
}
|
||||
|
||||
fun tmp(o: Int, k: Int) = o + k
|
||||
|
||||
class A
|
||||
|
||||
fun A.bar() = (::tmp)(111, 222)
|
||||
|
||||
fun box(): String {
|
||||
val result = A().bar()
|
||||
if (result != 333) return "Fail $result"
|
||||
|
||||
var r = run(111, 222, ::tmp)
|
||||
if (result != 333) return "Fail $result"
|
||||
|
||||
return "OK"
|
||||
}
|
||||
+20
@@ -0,0 +1,20 @@
|
||||
// This test was adapted from compiler/testData/codegen/boxWithStdlib/callableReference/function/.
|
||||
package foo
|
||||
|
||||
fun run(funRef:() -> String): String {
|
||||
return funRef()
|
||||
}
|
||||
|
||||
fun bar() = "OK"
|
||||
|
||||
fun box(): String {
|
||||
val x = ::bar
|
||||
|
||||
var r = x()
|
||||
if (r != "OK") return r
|
||||
|
||||
r = run(::bar)
|
||||
if (r != "OK") return r
|
||||
|
||||
return "OK"
|
||||
}
|
||||
+20
@@ -0,0 +1,20 @@
|
||||
// This test was adapted from compiler/testData/codegen/boxWithStdlib/callableReference/function/.
|
||||
package foo
|
||||
|
||||
fun run(arg: Int, funRef:(Int) -> Int): Int {
|
||||
return funRef(arg)
|
||||
}
|
||||
|
||||
fun inc(x: Int) = x + 1
|
||||
|
||||
fun tmp():Function1<Int, Int> {
|
||||
return ::inc
|
||||
}
|
||||
|
||||
fun box(): Boolean {
|
||||
if (tmp()(5) != 6) return false
|
||||
|
||||
if (run(5, tmp()) != 6) return false
|
||||
|
||||
return true
|
||||
}
|
||||
+18
@@ -0,0 +1,18 @@
|
||||
// This test was adapted from compiler/testData/codegen/boxWithStdlib/callableReference/function/.
|
||||
package foo
|
||||
|
||||
fun run(arg: Int, funRef:(Int) -> Int): Int {
|
||||
return funRef(arg)
|
||||
}
|
||||
fun inc(x: Int) = x + 1
|
||||
|
||||
fun box(): Boolean {
|
||||
val funRef = ::inc
|
||||
if (funRef(5) != 6) return false
|
||||
|
||||
if (run(5, funRef) != 6) return false
|
||||
|
||||
if (run(5) {x -> x + 1} != 6) return false
|
||||
|
||||
return true
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
// This test was adapted from compiler/testData/codegen/boxWithStdlib/callableReference/function/local/.
|
||||
package foo
|
||||
|
||||
var state = 23
|
||||
|
||||
fun box(): String {
|
||||
fun incrementState(inc: Int) {
|
||||
state += inc
|
||||
}
|
||||
|
||||
val inc = ::incrementState
|
||||
inc(12)
|
||||
inc(-5)
|
||||
inc(27)
|
||||
inc(-15)
|
||||
|
||||
return if (state == 42) "OK" else "Fail $state"
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
// This test was adapted from compiler/testData/codegen/boxWithStdlib/callableReference/property/.
|
||||
package foo
|
||||
|
||||
abstract class Base {
|
||||
val result = "OK"
|
||||
}
|
||||
|
||||
class Derived : Base()
|
||||
|
||||
fun box(): String {
|
||||
return (Base::result).get(Derived())
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
// This test was adapted from compiler/testData/codegen/boxWithStdlib/callableReference/property/.
|
||||
package foo
|
||||
|
||||
object NumberDecrypter {
|
||||
fun get(instance: Any?, data: PropertyMetadata) = when (data.name) {
|
||||
"four" -> 4
|
||||
"two" -> 2
|
||||
else -> throw Exception()
|
||||
}
|
||||
}
|
||||
|
||||
val four: Int by NumberDecrypter
|
||||
|
||||
class A {
|
||||
val two: Int by NumberDecrypter
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
val x = ::four.get()
|
||||
if (x != 4) return "Fail x: $x"
|
||||
val a = A()
|
||||
val y = A::two.get(a)
|
||||
if (y != 2) return "Fail y: $y"
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
// This test was adapted from compiler/testData/codegen/boxWithStdlib/callableReference/property/.
|
||||
package foo
|
||||
|
||||
object Delegate {
|
||||
var value = "lol"
|
||||
|
||||
fun get(instance: Any?, data: PropertyMetadata): String {
|
||||
return value
|
||||
}
|
||||
|
||||
fun set(instance: Any?, data: PropertyMetadata, newValue: String) {
|
||||
value = newValue
|
||||
}
|
||||
}
|
||||
|
||||
var result: String by Delegate
|
||||
|
||||
fun box(): String {
|
||||
val f = ::result
|
||||
if (f.get() != "lol") return "Fail 1: {$f.get()}"
|
||||
Delegate.value = "rofl"
|
||||
if (f.get() != "rofl") return "Fail 2: {$f.get()}"
|
||||
f.set("OK")
|
||||
return f.get()
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
package foo
|
||||
|
||||
|
||||
open class A(var msg:String) {
|
||||
}
|
||||
|
||||
class B:A("FromB") {
|
||||
}
|
||||
|
||||
var global:String = ""
|
||||
|
||||
var A.ext:String
|
||||
get() = ":A.ext ${this.msg}:"
|
||||
set(value) { global = ":A.ext ${value}" }
|
||||
|
||||
var B.ext:String
|
||||
get() = ":B.ext ${this.msg}:"
|
||||
set(value) { global = ":B.ext ${value}" }
|
||||
|
||||
fun box(): String {
|
||||
val a = A("Test")
|
||||
|
||||
var refAExt = A::ext
|
||||
var refBExt = B::ext
|
||||
|
||||
assertEquals("ext", refAExt.name)
|
||||
assertEquals("ext", refBExt.name)
|
||||
|
||||
assertEquals(":A.ext Test:", refAExt.get(a))
|
||||
assertEquals(":B.ext FromB:", refBExt.get(B()))
|
||||
|
||||
refAExt.set(a, "newA")
|
||||
assertEquals(":A.ext newA", global)
|
||||
|
||||
global = ""
|
||||
refBExt.set(B(), "newB")
|
||||
assertEquals(":B.ext newB", global)
|
||||
|
||||
return "OK"
|
||||
}
|
||||
+16
@@ -0,0 +1,16 @@
|
||||
// This test was adapted from compiler/testData/codegen/boxWithStdlib/callableReference/property/.
|
||||
package foo
|
||||
|
||||
import kotlin.reflect.KMemberProperty
|
||||
|
||||
class A {
|
||||
class object {
|
||||
val ref: KMemberProperty<A, String> = A::foo
|
||||
}
|
||||
|
||||
val foo: String = "OK"
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
return A.ref.get(A())
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
package foo
|
||||
|
||||
open class A(var msg:String) {
|
||||
open var prop:String = "initA"
|
||||
}
|
||||
|
||||
class B:A("FromB") {
|
||||
override var prop:String = "initB"
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
var refAProp = A::prop
|
||||
var refBProp = B::prop
|
||||
|
||||
assertEquals("prop", refAProp.name)
|
||||
assertEquals("prop", refBProp.name)
|
||||
|
||||
val a = A("Test")
|
||||
assertEquals("initA", refAProp.get(a))
|
||||
|
||||
refAProp.set(a, "newPropA")
|
||||
assertEquals("newPropA", a.prop)
|
||||
|
||||
val a1 = B()
|
||||
assertEquals("initB", refAProp.get(a1))
|
||||
|
||||
refAProp.set(a1, "newPropB")
|
||||
assertEquals("newPropB", a1.prop)
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
// This test was adapted from compiler/testData/codegen/boxWithStdlib/callableReference/property/.
|
||||
package foo
|
||||
|
||||
open class Base {
|
||||
open val foo = "Base"
|
||||
}
|
||||
|
||||
class Derived : Base() {
|
||||
override val foo = "OK"
|
||||
}
|
||||
|
||||
fun box() = (Base::foo).get(Derived())
|
||||
@@ -0,0 +1,15 @@
|
||||
// This test was adapted from compiler/testData/codegen/boxWithStdlib/callableReference/property/.
|
||||
package foo
|
||||
|
||||
val String.id: String
|
||||
get() = this
|
||||
|
||||
fun box(): String {
|
||||
val pr = String::id
|
||||
|
||||
if (pr["123"] != "123") return "Fail value: ${pr["123"]}"
|
||||
|
||||
if (pr.name != "id") return "Fail name: ${pr.name}"
|
||||
|
||||
return pr.get("OK")
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
// This test was adapted from compiler/testData/codegen/boxWithStdlib/callableReference/property/.
|
||||
package foo
|
||||
|
||||
class A(val x: Int)
|
||||
|
||||
fun box(): String {
|
||||
val p = A::x
|
||||
if (p.get(A(42)) != 42) return "Fail 1"
|
||||
if (p.get(A(-1)) != -1) return "Fail 2"
|
||||
if (p.name != "x") return "Fail 3"
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
// This test was adapted from compiler/testData/codegen/boxWithStdlib/callableReference/property/.
|
||||
package foo
|
||||
|
||||
var storage = 0
|
||||
|
||||
var Int.foo: Int
|
||||
get() {
|
||||
return this + storage
|
||||
}
|
||||
set(value) {
|
||||
storage = this + value
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
val pr = Int::foo
|
||||
if (pr.get(42) != 42) return "Fail 1: ${pr[42]}"
|
||||
pr.set(200, 39)
|
||||
if (pr.get(-239) != 0) return "Fail 2: ${pr[-239]}"
|
||||
if (storage != 239) return "Fail 3: $storage"
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
// This test was adapted from compiler/testData/codegen/boxWithStdlib/callableReference/property/.
|
||||
package foo
|
||||
|
||||
data class Box(var value: String)
|
||||
|
||||
fun box(): String {
|
||||
val o = Box("lorem")
|
||||
val prop = Box::value
|
||||
|
||||
if (prop.get(o) != "lorem") return "Fail 1: ${prop[o]}"
|
||||
prop.set(o, "ipsum")
|
||||
if (prop.get(o) != "ipsum") return "Fail 2: ${prop[o]}"
|
||||
if (o.value != "ipsum") return "Fail 3: ${o.value}"
|
||||
o.value = "dolor"
|
||||
if (prop.get(o) != "dolor") return "Fail 4: ${prop.get(o)}"
|
||||
if ("$o" != "Box(value=dolor)") return "Fail 5: $o"
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
// This test was adapted from compiler/testData/codegen/boxWithStdlib/callableReference/property/.
|
||||
package foo
|
||||
|
||||
data class Box(val value: String)
|
||||
|
||||
var pr = Box("first")
|
||||
|
||||
fun box(): String {
|
||||
val property = ::pr
|
||||
if (property.get() != Box("first")) return "Fail value: ${property.get()}"
|
||||
if (property.name != "pr") return "Fail name: ${property.name}"
|
||||
property.set(Box("second"))
|
||||
if (property.get().value != "second") return "Fail value 2: ${property.get()}"
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
// This test was adapted from compiler/testData/codegen/boxWithStdlib/callableReference/property/.
|
||||
package foo
|
||||
|
||||
data class Box(val value: String)
|
||||
|
||||
val foo = Box("lol")
|
||||
|
||||
fun box(): String {
|
||||
val property = ::foo
|
||||
if (property.get() != Box("lol")) return "Fail value: ${property.get()}"
|
||||
if (property.name != "foo") return "Fail name: ${property.name}"
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
package foo
|
||||
|
||||
var x = 1
|
||||
|
||||
val y = 2
|
||||
|
||||
fun box(): String {
|
||||
var refX = ::x
|
||||
assertEquals(1, refX.get())
|
||||
assertEquals("x", refX.name)
|
||||
|
||||
refX.set(100)
|
||||
assertEquals(100, x)
|
||||
|
||||
var refY = ::y
|
||||
assertEquals(2, refY.get())
|
||||
assertEquals("y", refY.name)
|
||||
|
||||
return "OK"
|
||||
}
|
||||
Reference in New Issue
Block a user