Add tests
This commit is contained in:
@@ -2,7 +2,7 @@
|
||||
// LANGUAGE_VERSION: 1.2
|
||||
import kotlin.coroutines.experimental.*
|
||||
|
||||
fun builder(c: suspend () -> String): String {
|
||||
fun builder1(c: suspend () -> String): String {
|
||||
var res = "FAIL"
|
||||
c.startCoroutine(object : Continuation<String> {
|
||||
override val context = EmptyCoroutineContext
|
||||
@@ -16,6 +16,20 @@ fun builder(c: suspend () -> String): String {
|
||||
return res
|
||||
}
|
||||
|
||||
fun builder2(c: suspend String.() -> String): String {
|
||||
var res = "FAIL"
|
||||
c.startCoroutine("O", object : Continuation<String> {
|
||||
override val context = EmptyCoroutineContext
|
||||
override fun resume(value: String) {
|
||||
res = value
|
||||
}
|
||||
override fun resumeWithException(exception: Throwable) {
|
||||
throw exception
|
||||
}
|
||||
})
|
||||
return res
|
||||
}
|
||||
|
||||
// FILE: B.kt
|
||||
// LANGUAGE_VERSION: 1.3
|
||||
import kotlin.coroutines.experimental.*
|
||||
@@ -25,8 +39,11 @@ fun ok(continuation: Continuation<String>): Any? {
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
if (builder(::ok) != "OK") return "FAIL 1"
|
||||
if (builder { cont: Continuation<String> -> "OK" } != "OK") return "FAIL 2"
|
||||
if (builder(fun (cont: Continuation<String>): Any? = "OK") != "OK") return "FAIL 2"
|
||||
if (builder1(::ok) != "OK") return "FAIL 1"
|
||||
if (builder1 { cont: Continuation<String> -> "OK" } != "OK") return "FAIL 2"
|
||||
if (builder1(fun (cont: Continuation<String>): Any? = "OK") != "OK") return "FAIL 3"
|
||||
|
||||
if (builder2 { cont: Continuation<String> -> this + "K" } != "OK") return "FAIL 5"
|
||||
if (builder2(fun String.(cont: Continuation<String>): Any? = this + "K") != "OK") return "FAIL 6"
|
||||
return "OK"
|
||||
}
|
||||
|
||||
@@ -0,0 +1,26 @@
|
||||
// FILE: A.kt
|
||||
// LANGUAGE_VERSION: 1.2
|
||||
|
||||
val dummy1: suspend () -> String = { "OK" }
|
||||
val dummy2: suspend String.() -> String = { this + "K" }
|
||||
val dummy3: suspend String.(String) -> String = { s -> this + s }
|
||||
|
||||
// FILE: B.kt
|
||||
// LANGUAGE_VERSION: 1.3
|
||||
import kotlin.coroutines.experimental.*
|
||||
|
||||
fun box(): String {
|
||||
val continuation = object : Continuation<String> {
|
||||
override val context = EmptyCoroutineContext
|
||||
override fun resume(value: String) {
|
||||
}
|
||||
|
||||
override fun resumeWithException(exception: Throwable) {
|
||||
throw exception
|
||||
}
|
||||
}
|
||||
if (dummy1(continuation) != "OK") return "FAIL 1"
|
||||
if ("O".dummy2(continuation) != "OK") return "FAIL 2"
|
||||
if ("O".dummy3("K", continuation) != "OK") return "FAIL 3"
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
// FILE: A.kt
|
||||
// LANGUAGE_VERSION: 1.2
|
||||
import kotlin.coroutines.experimental.*
|
||||
|
||||
fun (suspend () -> String).builder(): String {
|
||||
var res = "FAIL"
|
||||
startCoroutine(object : Continuation<String> {
|
||||
override val context = EmptyCoroutineContext
|
||||
override fun resume(value: String) {
|
||||
res = value
|
||||
}
|
||||
override fun resumeWithException(exception: Throwable) {
|
||||
throw exception
|
||||
}
|
||||
})
|
||||
return res
|
||||
}
|
||||
|
||||
// FILE: B.kt
|
||||
// LANGUAGE_VERSION: 1.3
|
||||
import kotlin.coroutines.experimental.*
|
||||
|
||||
fun ok(continuation: Continuation<String>): Any? {
|
||||
return "OK"
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
if ((::ok).builder() != "OK") return "FAIL 1"
|
||||
if (({ cont: Continuation<String> -> "OK" }).builder() != "OK") return "FAIL 2"
|
||||
if ((fun (cont: Continuation<String>): Any? = "OK").builder() != "OK") return "FAIL 2"
|
||||
return "OK"
|
||||
}
|
||||
@@ -3,17 +3,25 @@
|
||||
|
||||
suspend fun dummy() = "OK"
|
||||
|
||||
suspend fun String.dummy() = this + "K"
|
||||
|
||||
suspend fun String.dummy(s: String) = this + s
|
||||
|
||||
// FILE: B.kt
|
||||
// LANGUAGE_VERSION: 1.3
|
||||
import kotlin.coroutines.experimental.*
|
||||
|
||||
fun box(): String {
|
||||
return dummy(object : Continuation<String> {
|
||||
val continuation = object : Continuation<String> {
|
||||
override val context = EmptyCoroutineContext
|
||||
override fun resume(value: String) {
|
||||
}
|
||||
override fun resumeWithException(exception: Throwable) {
|
||||
throw exception
|
||||
}
|
||||
}) as String
|
||||
}
|
||||
if (dummy(continuation) != "OK") return "FAIL 1"
|
||||
if ("O".dummy(continuation) != "OK") return "FAIL 2"
|
||||
if ("O".dummy("K", continuation) != "OK") return "FAIL 3"
|
||||
return "OK"
|
||||
}
|
||||
|
||||
+10
@@ -295,6 +295,16 @@ public class CompileKotlinAgainstKotlinTestGenerated extends AbstractCompileKotl
|
||||
runTest("compiler/testData/compileKotlinAgainstKotlin/coroutines/builder.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("lambda.kt")
|
||||
public void testLambda() throws Exception {
|
||||
runTest("compiler/testData/compileKotlinAgainstKotlin/coroutines/lambda.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("receiver.kt")
|
||||
public void testReceiver() throws Exception {
|
||||
runTest("compiler/testData/compileKotlinAgainstKotlin/coroutines/receiver.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("simple.kt")
|
||||
public void testSimple() throws Exception {
|
||||
runTest("compiler/testData/compileKotlinAgainstKotlin/coroutines/simple.kt");
|
||||
|
||||
Reference in New Issue
Block a user