Minor. Move helpers for coroutines tests to kt-file

This commit is contained in:
Denis Zharkov
2018-06-22 12:33:12 +03:00
parent 3aa76c58fc
commit 1ced127660
2 changed files with 40 additions and 25 deletions
@@ -0,0 +1,38 @@
/*
* Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
* that can be found in the license/LICENSE.txt file.
*/
package org.jetbrains.kotlin
fun createTextForHelpers(coroutinesPackage: String): String {
return """
|package helpers
|import $coroutinesPackage.*
|
|fun <T> handleResultContinuation(x: (T) -> Unit): Continuation<T> = object: Continuation<T> {
| override val context = EmptyCoroutineContext
| override fun resumeWithException(exception: Throwable) {
| throw exception
| }
|
| override fun resume(data: T) = x(data)
|}
|
|
|fun handleExceptionContinuation(x: (Throwable) -> Unit): Continuation<Any?> = object: Continuation<Any?> {
| override val context = EmptyCoroutineContext
| override fun resumeWithException(exception: Throwable) {
| x(exception)
| }
|
| override fun resume(data: Any?) { }
|}
|
|open class EmptyContinuation(override val context: CoroutineContext = EmptyCoroutineContext) : Continuation<Any?> {
| companion object : EmptyContinuation()
| override fun resume(data: Any?) {}
| override fun resumeWithException(exception: Throwable) { throw exception }
|}
""".trimMargin()
}
@@ -35,6 +35,7 @@ import org.jetbrains.annotations.NonNls;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.annotations.TestOnly;
import org.jetbrains.kotlin.CoroutineTestUtilKt;
import org.jetbrains.kotlin.analyzer.AnalysisResult;
import org.jetbrains.kotlin.builtins.DefaultBuiltIns;
import org.jetbrains.kotlin.builtins.KotlinBuiltIns;
@@ -787,31 +788,7 @@ public class KotlinTestUtils {
}
testFiles.add(factory.createFile(supportModule,
"CoroutineUtil.kt",
"package helpers\n" +
"import " + coroutinesPackage + ".*\n" +
"fun <T> handleResultContinuation(x: (T) -> Unit): Continuation<T> = object: Continuation<T> {\n" +
" override val context = EmptyCoroutineContext\n" +
" override fun resumeWithException(exception: Throwable) {\n" +
" throw exception\n" +
" }\n" +
"\n" +
" override fun resume(data: T) = x(data)\n" +
"}\n" +
"\n" +
"fun handleExceptionContinuation(x: (Throwable) -> Unit): Continuation<Any?> = object: Continuation<Any?> {\n" +
" override val context = EmptyCoroutineContext\n" +
" override fun resumeWithException(exception: Throwable) {\n" +
" x(exception)\n" +
" }\n" +
"\n" +
" override fun resume(data: Any?) { }\n" +
"}\n" +
"\n" +
"open class EmptyContinuation(override val context: CoroutineContext = EmptyCoroutineContext) : Continuation<Any?> {\n" +
" companion object : EmptyContinuation()\n" +
" override fun resume(data: Any?) {}\n" +
" override fun resumeWithException(exception: Throwable) { throw exception }\n" +
"}",
CoroutineTestUtilKt.createTextForHelpers(coroutinesPackage),
directives
));
}