Files
kotlin-fork/compiler/testData/codegen/boxInline/suspend/defaultParameter/defaultValueCrossinline.kt
T
Ilmir Usmanov f60787d57c Move coroutines to kotlin.coroutines package: tests
Introduce COMMON_COROUTINES_TEST directive.
Every test with this directive is run twice: one time with
language version 1.2 and kotlin.coroutines.experimental package
and the other time with language version 1.3 and kotlin.coroutines
package. Each run is a separate method: with suffixes _1_2 and _1_3
respectively.
However, since codegen of release coroutines is not supported in JS
backend, we generate only one method: with suffix _1_2.
 #KT-23362
2018-04-23 21:51:59 +03:00

103 lines
2.3 KiB
Kotlin
Vendored

// FILE: test.kt
// COMMON_COROUTINES_TEST
// WITH_RUNTIME
// NO_CHECK_LAMBDA_INLINING
import COROUTINES_PACKAGE.*
class Controller {
var res = "FAIL 1"
}
val defaultController = Controller()
suspend inline fun test1(controller: Controller = defaultController, crossinline c: suspend Controller.() -> Unit) {
controller.c()
}
suspend inline fun test2(controller: Controller = defaultController, crossinline c: suspend Controller.() -> Unit) {
val l : suspend () -> Unit = {
controller.c()
}
l()
}
interface SuspendRunnable {
suspend fun run()
}
suspend inline fun test3(controller: Controller = defaultController, crossinline c: suspend Controller.() -> Unit) {
val sr = object: SuspendRunnable {
override suspend fun run() {
controller.c()
}
}
sr.run()
}
// FILE: box.kt
// COMMON_COROUTINES_TEST
import COROUTINES_PACKAGE.*
fun builder(c: suspend () -> Unit) {
c.startCoroutine(object: Continuation<Unit> {
override val context: CoroutineContext
get() = EmptyCoroutineContext
override fun resume(value: Unit) {
}
override fun resumeWithException(exception: Throwable) {
throw exception
}
})
}
suspend fun calculate() = "OK"
fun box() : String {
builder {
test1 {
res = calculate()
}
}
if (defaultController.res != "OK") return defaultController.res
defaultController.res = "FAIL 2"
builder {
test2 {
res = calculate()
}
}
if (defaultController.res != "OK") return defaultController.res
defaultController.res = "FAIL 3"
builder {
test3 {
res = calculate()
}
}
if (defaultController.res != "OK") return defaultController.res
val controller = Controller()
controller.res = "FAIL 4"
builder {
test1(controller) {
res = calculate()
}
}
if (controller.res != "OK") return controller.res
controller.res = "FAIL 5"
builder {
test2(controller) {
res = calculate()
}
}
if (controller.res != "OK") return controller.res
controller.res = "FAIL 6"
builder {
test3(controller) {
res = calculate()
}
}
return controller.res
}