mirror of
https://github.com/jlengrand/kotlin.git
synced 2026-05-09 08:31:29 +00:00
Currently all tests in boxWithStdlib/ run with both runtime and reflection included; eventually they'll be merged into box/ using these directives
69 lines
1.5 KiB
Kotlin
Vendored
69 lines
1.5 KiB
Kotlin
Vendored
// WITH_RUNTIME
|
|
// FILE: 1.kt
|
|
|
|
import test.A
|
|
import kotlin.test.assertEquals
|
|
|
|
open class B : A() {
|
|
fun box(): String {
|
|
val overriddenMethod: () -> String = {
|
|
method()
|
|
}
|
|
assertEquals("C.method", overriddenMethod())
|
|
|
|
val superMethod: () -> String = {
|
|
super.method()
|
|
}
|
|
assertEquals("A.method", superMethod())
|
|
|
|
val overriddenPropertyGetter: () -> String = {
|
|
property
|
|
}
|
|
assertEquals("C.property", overriddenPropertyGetter())
|
|
|
|
val superPropertyGetter: () -> String = {
|
|
super.property
|
|
}
|
|
assertEquals("A.property", superPropertyGetter())
|
|
|
|
val overriddenPropertySetter: () -> Unit = {
|
|
property = ""
|
|
}
|
|
overriddenPropertySetter()
|
|
|
|
val superPropertySetter: () -> Unit = {
|
|
super.property = ""
|
|
}
|
|
superPropertySetter()
|
|
|
|
assertEquals("C.property;A.property;", state)
|
|
|
|
return "OK"
|
|
}
|
|
}
|
|
|
|
class C : B() {
|
|
override fun method() = "C.method"
|
|
override var property: String
|
|
get() = "C.property"
|
|
set(value) { state += "C.property;" }
|
|
}
|
|
|
|
fun box() = C().box()
|
|
|
|
// FILE: 2.kt
|
|
|
|
package test
|
|
|
|
abstract class A {
|
|
public var state = ""
|
|
|
|
// These implementations should not be called, because they are overridden in C
|
|
|
|
protected open fun method(): String = "A.method"
|
|
|
|
protected open var property: String
|
|
get() = "A.property"
|
|
set(value) { state += "A.property;" }
|
|
}
|