KT-4773: added tests

This commit is contained in:
Alexey Tsvetkov
2014-09-25 17:52:44 +04:00
parent f8968c2f77
commit 3424142b65
5 changed files with 84 additions and 15 deletions
@@ -0,0 +1,39 @@
package foo
class State(var realValue: Int)
fun format(event: String, property: String, value: Int): String
= "${event}: ${property} = ${value}; "
object LoggerDelegate {
var log = ""
fun get(state: State, desc: PropertyMetadataImpl): Int {
log += format("get", desc.name, state.realValue)
return state.realValue
}
fun set(state: State, desc: PropertyMetadataImpl, value: Int) {
log += format("set", desc.name, value)
state.realValue = value
}
}
var State.value by LoggerDelegate
fun box(): String {
val state = State(1)
var expectedLog = ""
assertEquals(1, state.value)
expectedLog += format("get", "value", 1)
state.value = 3
expectedLog += format("set", "value", 3)
assertEquals(3, state.value)
expectedLog += format("get", "value", 3)
assertEquals(expectedLog, LoggerDelegate.log)
return "OK"
}
@@ -1,14 +0,0 @@
package foo
class Delegate {
fun get(t: A, p: PropertyMetadata): Int = 1
}
val A.prop: Int by Delegate()
class A {
}
fun box(): String {
return if (A().prop == 1) "OK" else "fail"
}