Merge boxWithStdlib testData into box, delete BoxWithStdlib test

This commit is contained in:
Alexander Udalov
2016-03-07 13:36:14 +03:00
committed by Alexander Udalov
parent 22bfc9786a
commit 06a67e6602
535 changed files with 3520 additions and 3871 deletions
@@ -0,0 +1,13 @@
// WITH_RUNTIME
// See KT-10107: 'Variable must be initialized' for delegate with private set
class My {
var delegate: String by kotlin.properties.Delegates.notNull()
private set
init {
delegate = "OK"
}
}
fun box() = My().delegate
@@ -0,0 +1,14 @@
// WITH_RUNTIME
interface T {
}
fun box(): String {
val a = "OK"
val t = object : T {
val foo by lazy {
a
}
}
return t.foo
}
@@ -0,0 +1,24 @@
// WITH_RUNTIME
import kotlin.properties.Delegates
object X {
public var O: String
by Delegates.observable("O") { prop, old, new -> }
private set
}
open class A {
public var K: String
by Delegates.observable("") { prop, old, new -> }
protected set
}
class B : A() {
init {
K = "K"
}
}
fun box(): String =
X.O + B().K
@@ -0,0 +1,16 @@
// WITH_RUNTIME
import kotlin.properties.Delegates
open class A<T : Any> {
protected var value: T by Delegates.notNull()
private set
}
class B : A<Int>()
fun box(): String {
B()
return "OK"
}
@@ -0,0 +1,53 @@
// WITH_REFLECT
// FULL_JDK
import java.lang.reflect.InvocationTargetException
import kotlin.reflect.*
object Delegate {
operator fun getValue(t: Any?, p: KProperty<*>): String {
(p as? KProperty0<String>)?.get()
(p as? KProperty1<O, String>)?.get(O)
(p as? KProperty2<O, O, String>)?.get(O, O)
return "Fail"
}
operator fun setValue(t: Any?, p: KProperty<*>, v: String) {
(p as? KMutableProperty0<String>)?.set(v)
(p as? KMutableProperty1<O, String>)?.set(O, v)
(p as? KMutableProperty2<O, O, String>)?.set(O, O, v)
}
}
var topLevel: String by Delegate
object O {
var member: String by Delegate
var O.memExt: String by Delegate
}
fun check(lambda: () -> Unit) {
try {
lambda()
} catch (e: Throwable) {
if (e !is InvocationTargetException && e !is StackOverflowError) {
throw AssertionError("The current implementation uses reflection to get the value of the property," +
"so either InvocationTargetException or StackOverflowError should have happened, but was: ${e}")
}
return
}
throw AssertionError("Getting the property value with .get() from getValue() or setting it with .set() in setValue() " +
"is effectively an endless recursion and should fail")
}
fun box(): String {
check { topLevel }
check { topLevel = "" }
check { O.member }
check { O.member = "" }
with (O) {
check { O.memExt }
check { O.memExt = "" }
}
return "OK"
}
@@ -0,0 +1,46 @@
// WITH_REFLECT
// TODO: replace with WITH_RUNTIME once KT-11316 is fixed
import java.util.*
import kotlin.reflect.*
val properties = HashSet<KProperty<*>>()
object Delegate {
operator fun getValue(t: Any?, p: KProperty<*>): String {
properties.add(p)
return ""
}
operator fun setValue(t: Any?, p: KProperty<*>, v: String) {
properties.add(p)
}
}
var topLevel: String by Delegate
object O {
var member: String by Delegate
var O.memExt: String by Delegate
}
fun box(): String {
topLevel = ""
O.member = ""
with (O) {
O.memExt = ""
}
for (p in HashSet(properties)) {
// None of these should fail
(p as? KProperty0<String>)?.get()
(p as? KProperty1<O, String>)?.get(O)
(p as? KProperty2<O, O, String>)?.get(O, O)
(p as? KMutableProperty0<String>)?.set("")
(p as? KMutableProperty1<O, String>)?.set(O, "")
(p as? KMutableProperty2<O, O, String>)?.set(O, O, "")
}
return "OK"
}