tests: Update box tests (1050294:id)

This commit is contained in:
Ilya Matveev
2017-04-24 17:17:41 +07:00
committed by ilmat192
parent 569ceff5f9
commit 8df15dca5a
96 changed files with 1165 additions and 145 deletions
@@ -0,0 +1,54 @@
// MODULE: lib
// FILE: lib.kt
package utils
inline fun foo(a: Int) {
bar(a)
}
inline fun bar(a: Int) {
try {
if (a > 0) throw Exception()
log("foo($a) #1")
}
catch (e: Exception) {
myRun {
log("foo($a) #2")
if (a > 1) return
log("foo($a) #3")
}
}
log("foo($a) #4")
}
var LOG: String = ""
fun log(s: String): String {
LOG += s + ";"
return LOG
}
inline fun myRun(f: () -> Unit) = f()
// MODULE: main(lib)
// FILE: main.kt
import utils.*
fun box(): String {
foo(0)
if (LOG != "foo(0) #1;foo(0) #4;") return "fail1: $LOG"
LOG = ""
foo(1)
if (LOG != "foo(1) #2;foo(1) #3;foo(1) #4;") return "fail2: $LOG"
LOG = ""
foo(2)
if (LOG != "foo(2) #2;") return "fail3: $LOG"
LOG = ""
return "OK"
}
@@ -0,0 +1,51 @@
// MODULE: lib
// FILE: lib.kt
package utils
inline fun foo(a: Int) {
try {
if (a > 0) throw Exception()
log("foo($a)")
}
catch (e: Exception) {
bar(a)
}
}
inline fun bar(a: Int) {
myRun {
log("bar($a) #1")
if (a == 2) return
log("bar($a) #2")
}
}
var LOG: String = ""
fun log(s: String): String {
LOG += s + ";"
return LOG
}
inline fun myRun(f: () -> Unit) = f()
// MODULE: main(lib)
// FILE: main.kt
import utils.*
fun box(): String {
foo(0)
if (LOG != "foo(0);") return "fail1: $LOG"
LOG = ""
foo(1)
if (LOG != "bar(1) #1;bar(1) #2;") return "fail2: $LOG"
LOG = ""
foo(2)
if (LOG != "bar(2) #1;") return "fail3: $LOG"
return "OK"
}
@@ -0,0 +1,27 @@
// FILE: 1.kt
// FULL_JDK
// WITH_REFLECT
package test
import kotlin.properties.Delegates
import kotlin.properties.ReadWriteProperty
var result = "fail"
inline fun <reified T : Any> crashMe(): ReadWriteProperty<Any?, Unit> {
return Delegates.observable(Unit, { a, b, c -> result = T::class.java.simpleName })
}
// FILE: 2.kt
import test.*
class OK {
var value by crashMe<OK>()
}
fun box(): String {
OK().value = Unit
return result
}
@@ -0,0 +1,36 @@
// FILE: 1.kt
// FULL_JDK
// WITH_REFLECT
package test
import kotlin.properties.Delegates
import kotlin.properties.ReadWriteProperty
import kotlin.properties.ObservableProperty
import kotlin.reflect.KProperty
var result = "fail"
public inline fun <reified T> myObservable(initialValue: T, crossinline onChange: (property: KProperty<*>, oldValue: T, newValue: T) -> Unit):
ReadWriteProperty<Any?, T> = object : ObservableProperty<T>(initialValue) {
override fun afterChange(property: KProperty<*>, oldValue: T, newValue: T) = onChange(property, oldValue, newValue)
}
//samely named reified parameter (T) as in myObservable
inline fun <reified T : Any> crashMe(): ReadWriteProperty<Any?, Unit> {
return myObservable(Unit, { a, b, c -> result = T::class.java.simpleName })
}
// FILE: 2.kt
import test.*
class OK {
var value by crashMe<OK>()
}
fun box(): String {
OK().value = Unit
return result
}