Added delegated property through map support + tests.

This commit is contained in:
Igor Chevdar
2017-02-28 15:44:06 +03:00
parent 889b28ee87
commit e2f2e31dc1
6 changed files with 183 additions and 0 deletions
+14
View File
@@ -619,6 +619,20 @@ task delegatedProperty_delegatedOverride(type: LinkKonanTest) {
lib = "codegen/delegatedProperty/delegatedOverride_lib.kt"
}
task delegatedProperty_lazy(type: RunKonanTest) {
goldValue = "computed!\nHello\nHello\n"
source = "codegen/delegatedProperty/lazy.kt"
}
task delegatedProperty_observable(type: RunKonanTest) {
goldValue = "<no name> -> first\nfirst -> second\n"
source = "codegen/delegatedProperty/observable.kt"
}
task delegatedProperty_map(type: RunKonanTest) {
goldValue = "John Doe\n25\n"
source = "codegen/delegatedProperty/map.kt"
}
task array0(type: RunKonanTest) {
goldValue = "5\n6\n7\n8\n9\n10\n11\n12\n13\n"
@@ -0,0 +1,9 @@
val lazyValue: String by lazy {
println("computed!")
"Hello"
}
fun main(args: Array<String>) {
println(lazyValue)
println(lazyValue)
}
@@ -0,0 +1,13 @@
class User(val map: Map<String, Any?>) {
val name: String by map
val age: Int by map
}
fun main(args: Array<String>) {
val user = User(mapOf(
"name" to "John Doe",
"age" to 25
))
println(user.name) // Prints "John Doe"
println(user.age) // Prints 25
}
@@ -0,0 +1,14 @@
import kotlin.properties.Delegates
class User {
var name: String by Delegates.observable("<no name>") {
prop, old, new ->
println("$old -> $new")
}
}
fun main(args: Array<String>) {
val user = User()
user.name = "first"
user.name = "second"
}