From d13e2ef32e75852f3b083ba9fedb7eabb9457ecd Mon Sep 17 00:00:00 2001 From: Ilmir Usmanov Date: Fri, 6 Jul 2018 15:33:18 +0300 Subject: [PATCH] Add tests --- .../coroutines/builder.kt | 25 ++++++++++++--- .../coroutines/lambda.kt | 26 +++++++++++++++ .../coroutines/receiver.kt | 32 +++++++++++++++++++ .../coroutines/simple.kt | 12 +++++-- ...mpileKotlinAgainstKotlinTestGenerated.java | 10 ++++++ 5 files changed, 99 insertions(+), 6 deletions(-) create mode 100644 compiler/testData/compileKotlinAgainstKotlin/coroutines/lambda.kt create mode 100644 compiler/testData/compileKotlinAgainstKotlin/coroutines/receiver.kt diff --git a/compiler/testData/compileKotlinAgainstKotlin/coroutines/builder.kt b/compiler/testData/compileKotlinAgainstKotlin/coroutines/builder.kt index 573fa7b5838..346435428ce 100644 --- a/compiler/testData/compileKotlinAgainstKotlin/coroutines/builder.kt +++ b/compiler/testData/compileKotlinAgainstKotlin/coroutines/builder.kt @@ -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 { 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 { + 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): Any? { } fun box(): String { - if (builder(::ok) != "OK") return "FAIL 1" - if (builder { cont: Continuation -> "OK" } != "OK") return "FAIL 2" - if (builder(fun (cont: Continuation): Any? = "OK") != "OK") return "FAIL 2" + if (builder1(::ok) != "OK") return "FAIL 1" + if (builder1 { cont: Continuation -> "OK" } != "OK") return "FAIL 2" + if (builder1(fun (cont: Continuation): Any? = "OK") != "OK") return "FAIL 3" + + if (builder2 { cont: Continuation -> this + "K" } != "OK") return "FAIL 5" + if (builder2(fun String.(cont: Continuation): Any? = this + "K") != "OK") return "FAIL 6" return "OK" } diff --git a/compiler/testData/compileKotlinAgainstKotlin/coroutines/lambda.kt b/compiler/testData/compileKotlinAgainstKotlin/coroutines/lambda.kt new file mode 100644 index 00000000000..ce058b232fa --- /dev/null +++ b/compiler/testData/compileKotlinAgainstKotlin/coroutines/lambda.kt @@ -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 { + 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" +} diff --git a/compiler/testData/compileKotlinAgainstKotlin/coroutines/receiver.kt b/compiler/testData/compileKotlinAgainstKotlin/coroutines/receiver.kt new file mode 100644 index 00000000000..8447df2674b --- /dev/null +++ b/compiler/testData/compileKotlinAgainstKotlin/coroutines/receiver.kt @@ -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 { + 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): Any? { + return "OK" +} + +fun box(): String { + if ((::ok).builder() != "OK") return "FAIL 1" + if (({ cont: Continuation -> "OK" }).builder() != "OK") return "FAIL 2" + if ((fun (cont: Continuation): Any? = "OK").builder() != "OK") return "FAIL 2" + return "OK" +} diff --git a/compiler/testData/compileKotlinAgainstKotlin/coroutines/simple.kt b/compiler/testData/compileKotlinAgainstKotlin/coroutines/simple.kt index d7af9ddfc31..9cba8fc10b8 100644 --- a/compiler/testData/compileKotlinAgainstKotlin/coroutines/simple.kt +++ b/compiler/testData/compileKotlinAgainstKotlin/coroutines/simple.kt @@ -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 { + val continuation = object : Continuation { 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" } diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/CompileKotlinAgainstKotlinTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/codegen/CompileKotlinAgainstKotlinTestGenerated.java index 7486a610f5b..ce23000b247 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/CompileKotlinAgainstKotlinTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/CompileKotlinAgainstKotlinTestGenerated.java @@ -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");