[Tests] Migrate backend-independent tests from native to compiler/testData.

^KT-65979
This commit is contained in:
Vladimir Sukharev
2024-02-25 18:25:58 +01:00
committed by Space Team
parent dd9332d9e1
commit febac0dd5f
640 changed files with 68168 additions and 6313 deletions
@@ -1,52 +0,0 @@
/*
* 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 file.
*/
import kotlin.test.*
import kotlin.coroutines.*
import kotlin.coroutines.intrinsics.*
open class EmptyContinuation(override val context: CoroutineContext = EmptyCoroutineContext) : Continuation<Any?> {
companion object : EmptyContinuation()
override fun resumeWith(result: Result<Any?>) { result.getOrThrow() }
}
suspend fun suspendHere(): Int = suspendCoroutineUninterceptedOrReturn { x ->
x.resume(42)
COROUTINE_SUSPENDED
}
fun builder(c: suspend () -> Unit) {
c.startCoroutine(EmptyContinuation)
}
interface I {
suspend fun foo(lambda: suspend (String) -> Unit)
suspend fun bar(s: String)
}
fun create() = object: I {
var lambda: suspend (String) -> Unit = {}
override suspend fun foo(lambda: suspend (String) -> Unit) {
this.lambda = lambda
}
override suspend fun bar(s: String) {
lambda(s)
}
}
fun box(): String {
val sb = StringBuilder()
builder {
val z = create()
z.foo { suspendHere(); sb.append(it) }
z.bar("zzz")
}
assertEquals("zzz", sb.toString())
return "OK"
}
@@ -1,42 +0,0 @@
/*
* Copyright 2010-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
* that can be found in the LICENSE file.
*/
import kotlin.test.*
import kotlin.coroutines.*
import kotlin.coroutines.intrinsics.*
open class EmptyContinuation(override val context: CoroutineContext = EmptyCoroutineContext) : Continuation<Any?> {
companion object : EmptyContinuation()
override fun resumeWith(result: Result<Any?>) { result.getOrThrow() }
}
suspend fun suspendHere(): Int = suspendCoroutineUninterceptedOrReturn { x ->
x.resume(42)
COROUTINE_SUSPENDED
}
fun builder(c: suspend () -> Unit) {
c.startCoroutine(EmptyContinuation)
}
// See https://github.com/JetBrains/kotlin-native/issues/3476
fun box(): String {
var result = 0
builder {
foo().bar()
result = 1
}
assertEquals(1, result)
return "OK"
}
class Foo {
suspend fun bar() {
suspendHere()
}
}
suspend fun foo() = Foo()
@@ -1,64 +0,0 @@
/*
* 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 file.
*/
import kotlin.test.*
import kotlin.coroutines.*
import kotlin.coroutines.intrinsics.*
val sb = StringBuilder()
open class EmptyContinuation(override val context: CoroutineContext = EmptyCoroutineContext) : Continuation<Any?> {
companion object : EmptyContinuation()
override fun resumeWith(result: Result<Any?>) { result.getOrThrow() }
}
suspend fun s1(): Int = suspendCoroutineUninterceptedOrReturn { x ->
sb.appendLine("s1")
x.resume(42)
COROUTINE_SUSPENDED
}
fun f1(): Int {
sb.appendLine("f1")
return 117
}
fun f2(): Int {
sb.appendLine("f2")
return 1
}
fun f3(x: Int, y: Int): Int {
sb.appendLine("f3")
return x + y
}
fun builder(c: suspend () -> Unit) {
c.startCoroutine(EmptyContinuation)
}
fun box(): String {
var result = 0
builder {
result = try {
f1()
} catch (t: Throwable) {
f2()
} finally {
s1()
}
}
sb.appendLine(result)
assertEquals("""
f1
s1
117
""".trimIndent(), sb.toString())
return "OK"
}
@@ -1,67 +0,0 @@
/*
* 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 file.
*/
import kotlin.test.*
import kotlin.coroutines.*
import kotlin.coroutines.intrinsics.*
val sb = StringBuilder()
open class EmptyContinuation(override val context: CoroutineContext = EmptyCoroutineContext) : Continuation<Any?> {
companion object : EmptyContinuation()
override fun resumeWith(result: Result<Any?>) { result.getOrThrow() }
}
suspend fun s1(): Int = suspendCoroutineUninterceptedOrReturn { x ->
sb.appendLine("s1")
x.resume(42)
COROUTINE_SUSPENDED
}
fun f1(): Int {
sb.appendLine("f1")
return 117
}
fun f2(): Int {
sb.appendLine("f2")
return 1
}
fun f3(x: Int, y: Int): Int {
sb.appendLine("f3")
return x + y
}
fun builder(c: suspend () -> Unit) {
c.startCoroutine(EmptyContinuation)
}
fun box(): String {
var result = 0
builder {
val x = try {
f1()
} catch (t: Throwable) {
f2()
} finally {
s1()
}
result = x
}
sb.appendLine(result)
assertEquals("""
f1
s1
117
""".trimIndent(), sb.toString())
return "OK"
}
@@ -1,66 +0,0 @@
/*
* 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 file.
*/
import kotlin.test.*
import kotlin.coroutines.*
import kotlin.coroutines.intrinsics.*
val sb = StringBuilder()
open class EmptyContinuation(override val context: CoroutineContext = EmptyCoroutineContext) : Continuation<Any?> {
companion object : EmptyContinuation()
override fun resumeWith(result: Result<Any?>) { result.getOrThrow() }
}
suspend fun s1(): Int = suspendCoroutineUninterceptedOrReturn { x ->
sb.appendLine("s1")
x.resume(42)
COROUTINE_SUSPENDED
}
fun f1(): Int {
sb.appendLine("f1")
return 117
}
fun f2(): Int {
sb.appendLine("f2")
return 1
}
fun f3(x: Int, y: Int): Int {
sb.appendLine("f3")
return x + y
}
fun builder(c: suspend () -> Unit) {
c.startCoroutine(EmptyContinuation)
}
fun box(): String {
var result = 0
builder {
try {
result = f1()
} catch (t: Throwable) {
result = f2()
} finally {
s1()
}
}
sb.appendLine(result)
assertEquals("""
f1
s1
117
""".trimIndent(), sb.toString())
return "OK"
}
@@ -1,66 +0,0 @@
/*
* 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 file.
*/
import kotlin.test.*
import kotlin.coroutines.*
import kotlin.coroutines.intrinsics.*
val sb = StringBuilder()
open class EmptyContinuation(override val context: CoroutineContext = EmptyCoroutineContext) : Continuation<Any?> {
companion object : EmptyContinuation()
override fun resumeWith(result: Result<Any?>) { result.getOrThrow() }
}
suspend fun s1(): Int = suspendCoroutineUninterceptedOrReturn { x ->
sb.appendLine("s1")
x.resume(42)
COROUTINE_SUSPENDED
}
fun f1(): Int {
sb.appendLine("f1")
return 117
}
fun f2(): Int {
sb.appendLine("f2")
return 1
}
fun f3(x: Int, y: Int): Int {
sb.appendLine("f3")
return x + y
}
fun builder(c: suspend () -> Unit) {
c.startCoroutine(EmptyContinuation)
}
fun box(): String {
var result = 0
builder {
try {
result = s1()
} catch (t: Throwable) {
result = f2()
} finally {
sb.appendLine("finally")
}
}
sb.appendLine(result)
assertEquals("""
s1
finally
42
""".trimIndent(), sb.toString())
return "OK"
}
@@ -1,67 +0,0 @@
/*
* 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 file.
*/
import kotlin.test.*
import kotlin.coroutines.*
import kotlin.coroutines.intrinsics.*
val sb = StringBuilder()
open class EmptyContinuation(override val context: CoroutineContext = EmptyCoroutineContext) : Continuation<Any?> {
companion object : EmptyContinuation()
override fun resumeWith(result: Result<Any?>) { result.getOrThrow() }
}
suspend fun s1(): Int = suspendCoroutineUninterceptedOrReturn { x ->
sb.appendLine("s1")
x.resumeWithException(Error())
COROUTINE_SUSPENDED
}
fun f1(): Int {
sb.appendLine("f1")
return 117
}
fun f2(): Int {
sb.appendLine("f2")
return 1
}
fun f3(x: Int, y: Int): Int {
sb.appendLine("f3")
return x + y
}
fun builder(c: suspend () -> Unit) {
c.startCoroutine(EmptyContinuation)
}
fun box(): String {
var result = 0
builder {
try {
result = s1()
} catch (t: Throwable) {
result = f2()
} finally {
sb.appendLine("finally")
}
}
sb.appendLine(result)
assertEquals("""
s1
f2
finally
1
""".trimIndent(), sb.toString())
return "OK"
}
@@ -1,72 +0,0 @@
/*
* 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 file.
*/
import kotlin.test.*
import kotlin.coroutines.*
import kotlin.coroutines.intrinsics.*
val sb = StringBuilder()
open class EmptyContinuation(override val context: CoroutineContext = EmptyCoroutineContext) : Continuation<Any?> {
companion object : EmptyContinuation()
override fun resumeWith(result: Result<Any?>) { result.getOrThrow() }
}
suspend fun s1(): Int = suspendCoroutineUninterceptedOrReturn { x ->
sb.appendLine("s1")
x.resumeWithException(Error("error"))
COROUTINE_SUSPENDED
}
fun f1(): Int {
sb.appendLine("f1")
return 117
}
fun f2(): Int {
sb.appendLine("f2")
return 1
}
fun f3(x: Int, y: Int): Int {
sb.appendLine("f3")
return x + y
}
fun builder(c: suspend () -> Unit) {
c.startCoroutine(EmptyContinuation)
}
fun box(): String {
var result = 0
builder {
try {
try {
result = s1()
} catch (t: ClassCastException) {
result = f2()
} finally {
sb.appendLine("finally")
}
}
catch(t: Error) {
sb.appendLine(t.message)
}
}
sb.appendLine(result)
assertEquals("""
s1
finally
error
0
""".trimIndent(), sb.toString())
return "OK"
}
@@ -1,80 +0,0 @@
/*
* 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 file.
*/
import kotlin.test.*
import kotlin.coroutines.*
import kotlin.coroutines.intrinsics.*
val sb = StringBuilder()
open class EmptyContinuation(override val context: CoroutineContext = EmptyCoroutineContext) : Continuation<Any?> {
companion object : EmptyContinuation()
override fun resumeWith(result: Result<Any?>) { result.getOrThrow() }
}
suspend fun s1(): Int = suspendCoroutineUninterceptedOrReturn { x ->
sb.appendLine("s1")
x.resumeWithException(Error())
COROUTINE_SUSPENDED
}
suspend fun s2(): Int = suspendCoroutineUninterceptedOrReturn { x ->
sb.appendLine("s2")
x.resume(42)
COROUTINE_SUSPENDED
}
fun f1(): Int {
sb.appendLine("f1")
return 117
}
fun f2(): Int {
sb.appendLine("f2")
return 1
}
fun f3(x: Int, y: Int): Int {
sb.appendLine("f3")
return x + y
}
fun builder(c: suspend () -> Unit) {
c.startCoroutine(EmptyContinuation)
}
fun box(): String {
var result = 0
builder {
try {
try {
result = s1()
} catch (t: Throwable) {
result = f2()
} finally {
sb.appendLine("finally1")
result = s2()
}
} finally {
sb.appendLine("finally2")
}
}
sb.appendLine(result)
assertEquals("""
s1
f2
finally1
s2
finally2
42
""".trimIndent(), sb.toString())
return "OK"
}
@@ -1,61 +0,0 @@
/*
* 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 file.
*/
import kotlin.test.*
import kotlin.coroutines.*
import kotlin.coroutines.intrinsics.*
val sb = StringBuilder()
open class EmptyContinuation(override val context: CoroutineContext = EmptyCoroutineContext) : Continuation<Any?> {
companion object : EmptyContinuation()
override fun resumeWith(result: Result<Any?>) { result.getOrThrow() }
}
suspend fun s1(): Int = suspendCoroutineUninterceptedOrReturn { x ->
sb.appendLine("s1")
x.resume(42)
COROUTINE_SUSPENDED
}
fun f1(): Int {
sb.appendLine("f1")
return 117
}
fun f2(): Int {
sb.appendLine("f2")
return 1
}
fun f3(x: Int, y: Int): Int {
sb.appendLine("f3")
return x + y
}
fun builder(c: suspend () -> Unit) {
c.startCoroutine(EmptyContinuation)
}
fun box(): String {
var result = 0
builder {
result = f3(if (f1() > 100) s1() else f2(), 42)
}
sb.appendLine(result)
assertEquals("""
f1
s1
f3
84
""".trimIndent(), sb.toString())
return "OK"
}
@@ -1,64 +0,0 @@
/*
* 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 file.
*/
import kotlin.test.*
import kotlin.coroutines.*
import kotlin.coroutines.intrinsics.*
val sb = StringBuilder()
open class EmptyContinuation(override val context: CoroutineContext = EmptyCoroutineContext) : Continuation<Any?> {
companion object : EmptyContinuation()
override fun resumeWith(result: Result<Any?>) { result.getOrThrow() }
}
suspend fun s1(): Int = suspendCoroutineUninterceptedOrReturn { x ->
sb.appendLine("s1")
x.resume(42)
COROUTINE_SUSPENDED
}
fun f1(): Int {
sb.appendLine("f1")
return 117
}
fun f2(): Int {
sb.appendLine("f2")
return 1
}
fun f3(x: Int, y: Int): Int {
sb.appendLine("f3")
return x + y
}
fun builder(c: suspend () -> Unit) {
c.startCoroutine(EmptyContinuation)
}
fun box(): String {
var result = 0
builder {
if (f1() > 100)
result = s1() + f2()
else
result = 42
}
sb.appendLine(result)
assertEquals("""
f1
s1
f2
43
""".trimIndent(), sb.toString())
return "OK"
}
@@ -1,43 +0,0 @@
/*
* 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 file.
*/
import kotlin.test.*
import kotlin.coroutines.*
import kotlin.coroutines.intrinsics.*
val sb = StringBuilder()
open class EmptyContinuation(override val context: CoroutineContext = EmptyCoroutineContext) : Continuation<Any?> {
companion object : EmptyContinuation()
override fun resumeWith(result: Result<Any?>) { result.getOrThrow() }
}
suspend fun s1(): Int = suspendCoroutineUninterceptedOrReturn { x ->
sb.appendLine("s1")
x.resume(42)
COROUTINE_SUSPENDED
}
fun builder(c: suspend () -> Unit) {
c.startCoroutine(EmptyContinuation)
}
inline suspend fun inline_s2(): Int {
return 42
}
fun box(): String {
var result = 0
builder {
result = inline_s2()
}
sb.appendLine(result)
assertEquals("42\n", sb.toString())
return "OK"
}
@@ -1,48 +0,0 @@
/*
* 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 file.
*/
import kotlin.test.*
import kotlin.coroutines.*
import kotlin.coroutines.intrinsics.*
val sb = StringBuilder()
open class EmptyContinuation(override val context: CoroutineContext = EmptyCoroutineContext) : Continuation<Any?> {
companion object : EmptyContinuation()
override fun resumeWith(result: Result<Any?>) { result.getOrThrow() }
}
suspend fun s1(): Int = suspendCoroutineUninterceptedOrReturn { x ->
sb.appendLine("s1")
x.resume(42)
COROUTINE_SUSPENDED
}
fun builder(c: suspend () -> Unit) {
c.startCoroutine(EmptyContinuation)
}
inline suspend fun inline_s2(): Int {
var x = s1()
return x
}
fun box(): String {
var result = 0
builder {
result = inline_s2()
}
sb.appendLine(result)
assertEquals("""
s1
42
""".trimIndent(), sb.toString())
return "OK"
}
@@ -1,62 +0,0 @@
/*
* 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 file.
*/
import kotlin.test.*
import kotlin.coroutines.*
import kotlin.coroutines.intrinsics.*
val sb = StringBuilder()
open class EmptyContinuation(override val context: CoroutineContext = EmptyCoroutineContext) : Continuation<Any?> {
companion object : EmptyContinuation()
override fun resumeWith(result: Result<Any?>) { result.getOrThrow() }
}
suspend fun s1(): Int = suspendCoroutineUninterceptedOrReturn { x ->
sb.appendLine("s1")
x.resume(42)
COROUTINE_SUSPENDED
}
fun builder(c: suspend () -> Unit) {
c.startCoroutine(EmptyContinuation)
}
fun f1(): Int {
sb.appendLine("f1")
return 117
}
fun f2(): Int {
sb.appendLine("f2")
return 1
}
inline suspend fun inline_s2(): Int {
var x = 0
if (f1() > 0)
x = s1()
else x = f2()
return x
}
fun box(): String {
var result = 0
builder {
result = inline_s2()
}
sb.appendLine(result)
assertEquals("""
f1
s1
42
""".trimIndent(), sb.toString())
return "OK"
}
@@ -1,63 +0,0 @@
/*
* 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 file.
*/
import kotlin.test.*
import kotlin.coroutines.*
import kotlin.coroutines.intrinsics.*
val sb = StringBuilder()
open class EmptyContinuation(override val context: CoroutineContext = EmptyCoroutineContext) : Continuation<Any?> {
companion object : EmptyContinuation()
override fun resumeWith(result: Result<Any?>) { result.getOrThrow() }
}
suspend fun s1(): Int = suspendCoroutineUninterceptedOrReturn { x ->
sb.appendLine("s1")
x.resume(42)
COROUTINE_SUSPENDED
}
fun f1(): Int {
sb.appendLine("f1")
return 117
}
fun f2(): Int {
sb.appendLine("f2")
return 1
}
fun f3(x: Int, y: Int): Int {
sb.appendLine("f3")
return x + y
}
fun builder(c: suspend () -> Unit) {
c.startCoroutine(EmptyContinuation)
}
fun box(): String {
var result = 0
builder {
val x = try {
s1()
} catch (t: Throwable) {
f2()
}
result = x
}
sb.appendLine(result)
assertEquals("""
s1
42
""".trimIndent(), sb.toString())
return "OK"
}
@@ -1,62 +0,0 @@
/*
* 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 file.
*/
import kotlin.test.*
import kotlin.coroutines.*
import kotlin.coroutines.intrinsics.*
val sb = StringBuilder()
open class EmptyContinuation(override val context: CoroutineContext = EmptyCoroutineContext) : Continuation<Any?> {
companion object : EmptyContinuation()
override fun resumeWith(result: Result<Any?>) { result.getOrThrow() }
}
suspend fun s1(): Int = suspendCoroutineUninterceptedOrReturn { x ->
sb.appendLine("s1")
x.resume(42)
COROUTINE_SUSPENDED
}
fun f1(): Int {
sb.appendLine("f1")
return 117
}
fun f2(): Int {
sb.appendLine("f2")
return 1
}
fun f3(x: Int, y: Int): Int {
sb.appendLine("f3")
return x + y
}
fun builder(c: suspend () -> Unit) {
c.startCoroutine(EmptyContinuation)
}
fun box(): String {
var result = 0
builder {
result = try {
s1()
} catch (t: Throwable) {
f2()
}
}
sb.appendLine(result)
assertEquals("""
s1
42
""".trimIndent(), sb.toString())
return "OK"
}
@@ -1,69 +0,0 @@
/*
* 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 file.
*/
import kotlin.test.*
import kotlin.coroutines.*
import kotlin.coroutines.intrinsics.*
val sb = StringBuilder()
open class EmptyContinuation(override val context: CoroutineContext = EmptyCoroutineContext) : Continuation<Any?> {
companion object : EmptyContinuation()
override fun resumeWith(result: Result<Any?>) { result.getOrThrow() }
}
suspend fun s1(): Int = suspendCoroutineUninterceptedOrReturn { x ->
sb.appendLine("s1")
x.resume(42)
COROUTINE_SUSPENDED
}
suspend fun s2(): Int = suspendCoroutineUninterceptedOrReturn { x ->
sb.appendLine("s2")
x.resumeWithException(Error())
COROUTINE_SUSPENDED
}
fun f1(): Int {
sb.appendLine("f1")
return 117
}
fun f2(): Int {
sb.appendLine("f2")
return 1
}
fun f3(x: Int, y: Int): Int {
sb.appendLine("f3")
return x + y
}
fun builder(c: suspend () -> Unit) {
c.startCoroutine(EmptyContinuation)
}
fun box(): String {
var result = 0
builder {
result = try {
s2()
} catch (t: Throwable) {
f2()
}
}
sb.appendLine(result)
assertEquals("""
s2
f2
1
""".trimIndent(), sb.toString())
return "OK"
}
@@ -1,70 +0,0 @@
/*
* 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 file.
*/
import kotlin.test.*
import kotlin.coroutines.*
import kotlin.coroutines.intrinsics.*
val sb = StringBuilder()
open class EmptyContinuation(override val context: CoroutineContext = EmptyCoroutineContext) : Continuation<Any?> {
companion object : EmptyContinuation()
override fun resumeWith(result: Result<Any?>) { result.getOrThrow() }
}
suspend fun s1(): Int = suspendCoroutineUninterceptedOrReturn { x ->
sb.appendLine("s1")
x.resume(42)
COROUTINE_SUSPENDED
}
suspend fun s2(): Int = suspendCoroutineUninterceptedOrReturn { x ->
sb.appendLine("s2")
x.resumeWithException(Error())
COROUTINE_SUSPENDED
}
fun f1(): Int {
sb.appendLine("f1")
return 117
}
fun f2(): Int {
sb.appendLine("f2")
return 1
}
fun f3(x: Int, y: Int): Int {
sb.appendLine("f3")
return x + y
}
fun builder(c: suspend () -> Unit) {
c.startCoroutine(EmptyContinuation)
}
fun box(): String {
var result = 0
builder {
val x = try {
s2()
} catch (t: Throwable) {
f2()
}
result = x
}
sb.appendLine(result)
assertEquals("""
s2
f2
1
""".trimIndent(), sb.toString())
return "OK"
}
@@ -1,72 +0,0 @@
/*
* 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 file.
*/
import kotlin.test.*
import kotlin.coroutines.*
import kotlin.coroutines.intrinsics.*
val sb = StringBuilder()
open class EmptyContinuation(override val context: CoroutineContext = EmptyCoroutineContext) : Continuation<Any?> {
companion object : EmptyContinuation()
override fun resumeWith(result: Result<Any?>) { result.getOrThrow() }
}
suspend fun s1(): Int = suspendCoroutineUninterceptedOrReturn { x ->
sb.appendLine("s1")
x.resume(42)
COROUTINE_SUSPENDED
}
suspend fun s2(): Int = suspendCoroutineUninterceptedOrReturn { x ->
sb.appendLine("s2")
x.resumeWithException(Error("Error"))
COROUTINE_SUSPENDED
}
fun f1(): Int {
sb.appendLine("f1")
return 117
}
fun f2(): Int {
sb.appendLine("f2")
return 1
}
fun f3(x: Int, y: Int): Int {
sb.appendLine("f3")
return x + y
}
fun builder(c: suspend () -> Unit) {
c.startCoroutine(EmptyContinuation)
}
fun box(): String {
var result = 0
builder {
result = try {
s2()
} catch (t: Throwable) {
val x = s1()
sb.appendLine(t.message)
x
}
}
sb.appendLine(result)
assertEquals("""
s2
s1
Error
42
""".trimIndent(), sb.toString())
return "OK"
}
@@ -1,74 +0,0 @@
/*
* 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 file.
*/
import kotlin.test.*
import kotlin.coroutines.*
import kotlin.coroutines.intrinsics.*
val sb = StringBuilder()
open class EmptyContinuation(override val context: CoroutineContext = EmptyCoroutineContext) : Continuation<Any?> {
companion object : EmptyContinuation()
override fun resumeWith(result: Result<Any?>) { result.getOrThrow() }
}
suspend fun s1(): Int = suspendCoroutineUninterceptedOrReturn { x ->
sb.appendLine("s1")
x.resume(42)
COROUTINE_SUSPENDED
}
suspend fun s2(): Int = suspendCoroutineUninterceptedOrReturn { x ->
sb.appendLine("s2")
x.resumeWithException(Error("Error"))
COROUTINE_SUSPENDED
}
suspend fun s3(value: Int): Int = suspendCoroutineUninterceptedOrReturn { x ->
sb.appendLine("s3")
x.resume(value)
COROUTINE_SUSPENDED
}
fun f1(): Int {
sb.appendLine("f1")
return 117
}
fun f2(): Int {
sb.appendLine("f2")
return 1
}
fun f3(x: Int, y: Int): Int {
sb.appendLine("f3")
return x + y
}
fun builder(c: suspend () -> Unit) {
c.startCoroutine(EmptyContinuation)
}
fun box(): String {
var result = 0
builder {
while (s3(result) < 3)
++result
}
sb.appendLine(result)
assertEquals("""
s3
s3
s3
s3
3
""".trimIndent(), sb.toString())
return "OK"
}
@@ -1,73 +0,0 @@
/*
* 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 file.
*/
import kotlin.test.*
import kotlin.coroutines.*
import kotlin.coroutines.intrinsics.*
val sb = StringBuilder()
open class EmptyContinuation(override val context: CoroutineContext = EmptyCoroutineContext) : Continuation<Any?> {
companion object : EmptyContinuation()
override fun resumeWith(result: Result<Any?>) { result.getOrThrow() }
}
suspend fun s1(): Int = suspendCoroutineUninterceptedOrReturn { x ->
sb.appendLine("s1")
x.resume(42)
COROUTINE_SUSPENDED
}
suspend fun s2(): Int = suspendCoroutineUninterceptedOrReturn { x ->
sb.appendLine("s2")
x.resumeWithException(Error("Error"))
COROUTINE_SUSPENDED
}
suspend fun s3(value: Int): Int = suspendCoroutineUninterceptedOrReturn { x ->
sb.appendLine("s3")
x.resume(value)
COROUTINE_SUSPENDED
}
fun f1(): Int {
sb.appendLine("f1")
return 117
}
fun f2(): Int {
sb.appendLine("f2")
return 1
}
fun f3(x: Int, y: Int): Int {
sb.appendLine("f3")
return x + y
}
fun builder(c: suspend () -> Unit) {
c.startCoroutine(EmptyContinuation)
}
fun box(): String {
var result = 0
builder {
while (result < 3)
result = s3(result) + 1
}
sb.appendLine(result)
assertEquals("""
s3
s3
s3
3
""".trimIndent(), sb.toString())
return "OK"
}
@@ -1,30 +0,0 @@
/*
* 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 file.
*/
import kotlin.test.*
import kotlin.coroutines.*
import kotlin.coroutines.intrinsics.*
val sb = StringBuilder()
open class EmptyContinuation(override val context: CoroutineContext = EmptyCoroutineContext) : Continuation<Any?> {
companion object : EmptyContinuation()
override fun resumeWith(result: Result<Any?>) { result.getOrThrow() }
}
fun builder(c: suspend () -> Unit) {
c.startCoroutine(EmptyContinuation)
}
fun box(): String {
builder { sb.appendLine(coroutineContext) }
assertEquals("""
EmptyCoroutineContext
""".trimIndent(), sb.toString())
return "OK"
}
@@ -1,32 +0,0 @@
/*
* 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 file.
*/
import kotlin.test.*
import kotlin.coroutines.*
import kotlin.coroutines.intrinsics.*
val sb = StringBuilder()
open class EmptyContinuation(override val context: CoroutineContext = EmptyCoroutineContext) : Continuation<Any?> {
companion object : EmptyContinuation()
override fun resumeWith(result: Result<Any?>) { result.getOrThrow() }
}
fun builder(c: suspend () -> Unit) {
c.startCoroutine(EmptyContinuation)
}
suspend fun foo() = coroutineContext
fun box(): String {
builder { sb.appendLine(foo()) }
assertEquals("""
EmptyCoroutineContext
""".trimIndent(), sb.toString())
return "OK"
}
@@ -1,55 +0,0 @@
/*
* 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 file.
*/
import kotlin.test.*
import kotlin.coroutines.*
import kotlin.coroutines.intrinsics.*
val sb = StringBuilder()
open class EmptyContinuation(override val context: CoroutineContext = EmptyCoroutineContext) : Continuation<Any?> {
companion object : EmptyContinuation()
override fun resumeWith(result: Result<Any?>) { result.getOrThrow() }
}
suspend fun s1(): Int = suspendCoroutineUninterceptedOrReturn { x ->
sb.appendLine("s1")
x.resume(42)
COROUTINE_SUSPENDED
}
fun f1(): Int {
sb.appendLine("f1")
return 117
}
fun f2(): Int {
sb.appendLine("f2")
return 1
}
fun builder(c: suspend () -> Unit) {
c.startCoroutine(EmptyContinuation)
}
fun box(): String {
var result = 0
builder {
result = f1() + s1() + f2()
}
sb.appendLine(result)
assertEquals("""
f1
s1
f2
160
""".trimIndent(), sb.toString())
return "OK"
}
@@ -1,36 +0,0 @@
/*
* 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 file.
*/
import kotlin.test.*
import kotlin.coroutines.*
import kotlin.coroutines.intrinsics.*
val sb = StringBuilder()
open class EmptyContinuation(override val context: CoroutineContext = EmptyCoroutineContext) : Continuation<Any?> {
companion object : EmptyContinuation()
override fun resumeWith(result: Result<Any?>) { result.getOrThrow() }
}
suspend fun s1() {
sb.appendLine("s1")
}
fun builder(c: suspend () -> Unit) {
c.startCoroutine(EmptyContinuation)
}
fun box(): String {
builder {
s1()
}
assertEquals("""
s1
""".trimIndent(), sb.toString())
return "OK"
}
@@ -1,44 +0,0 @@
/*
* 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 file.
*/
import kotlin.test.*
import kotlin.coroutines.*
import kotlin.coroutines.intrinsics.*
val sb = StringBuilder()
open class EmptyContinuation(override val context: CoroutineContext = EmptyCoroutineContext) : Continuation<Any?> {
companion object : EmptyContinuation()
override fun resumeWith(result: Result<Any?>) { result.getOrThrow() }
}
suspend fun s1(): Unit = suspendCoroutineUninterceptedOrReturn { x ->
sb.appendLine("s1")
x.resume(Unit)
COROUTINE_SUSPENDED
}
suspend fun s2() {
sb.appendLine("s2")
s1()
}
fun builder(c: suspend () -> Unit) {
c.startCoroutine(EmptyContinuation)
}
fun box(): String {
builder {
s2()
}
assertEquals("""
s2
s1
""".trimIndent(), sb.toString())
return "OK"
}
@@ -1,34 +0,0 @@
/*
* Copyright 2010-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
* that can be found in the LICENSE file.
*/
import kotlin.test.*
val sb = StringBuilder()
suspend fun foo(x: Int) = x
class Foo(val x: Int) {
suspend fun bar() = x
}
fun box(): String {
val ref1 = ::foo
val rec = Foo(42)
val ref2 = rec::bar
val ref3 = ::foo
val ref4 = Foo(42)::bar
val ref5 = rec::bar
val ref6 = Foo::bar
assertEquals("foo", ref1.name)
assertEquals("bar", ref2.name)
assertEquals("bar", ref6.name)
assertFalse(ref1 == ref2)
assertTrue(ref1 == ref3)
assertFalse(ref2 == ref4)
assertTrue(ref2 == ref5)
assertFalse(ref6 == ref2)
return "OK"
}
@@ -1,34 +0,0 @@
/*
* Copyright 2010-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
* that can be found in the LICENSE file.
*/
import kotlin.test.*
import kotlin.coroutines.*
import kotlin.coroutines.intrinsics.*
val sb = StringBuilder()
open class EmptyContinuation(override val context: CoroutineContext = EmptyCoroutineContext) : Continuation<Any?> {
companion object : EmptyContinuation()
override fun resumeWith(result: Result<Any?>) { result.getOrThrow() }
}
class Foo(val x: Int) {
suspend fun bar(y: Int) = foo(y) + x
}
suspend fun foo(x: Int) = x
fun box(): String {
val ref = Foo(42)::bar
sb.appendLine((ref as Function2<Int, Continuation<Int>, Any?>)(117, EmptyContinuation))
assertEquals("""
159
""".trimIndent(), sb.toString())
return "OK"
}
@@ -1,19 +0,0 @@
/*
* Copyright 2010-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
* that can be found in the LICENSE file.
*/
import kotlin.test.*
import kotlin.coroutines.*
import kotlin.coroutines.intrinsics.*
fun foo(block: (Continuation<Unit>) -> Any?) {
block as (suspend () -> Unit)
}
fun box(): String {
foo {}
return "OK"
}
@@ -1,38 +0,0 @@
/*
* Copyright 2010-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
* that can be found in the LICENSE file.
*/
import kotlin.test.*
import kotlin.coroutines.*
import kotlin.coroutines.intrinsics.*
open class EmptyContinuation(override val context: CoroutineContext = EmptyCoroutineContext) : Continuation<Any?> {
companion object : EmptyContinuation()
override fun resumeWith(result: Result<Any?>) { result.getOrThrow() }
}
suspend fun suspendHere(): Int = suspendCoroutineUninterceptedOrReturn { x ->
x.resume(42)
COROUTINE_SUSPENDED
}
suspend fun foo(x: suspend () -> Int) = x()
fun builder(c: suspend () -> Unit) {
c.startCoroutine(EmptyContinuation)
}
fun box(): String {
var result = 0
val ref = ::suspendHere
builder {
result = foo(ref)
}
assertEquals(42, result)
return "OK"
}
@@ -1,40 +0,0 @@
/*
* 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 file.
*/
import kotlin.test.*
import kotlin.coroutines.*
import kotlin.coroutines.intrinsics.*
open class EmptyContinuation(override val context: CoroutineContext = EmptyCoroutineContext) : Continuation<Any?> {
companion object : EmptyContinuation()
override fun resumeWith(result: Result<Any?>) { result.getOrThrow() }
}
suspend fun suspendHere(): Int = suspendCoroutineUninterceptedOrReturn { x ->
x.resume(42)
COROUTINE_SUSPENDED
}
suspend fun foo(label: String): String {
val x = suspendHere()
return label + x.toString()
}
fun builder(c: suspend () -> Unit) {
c.startCoroutine(EmptyContinuation)
}
fun box(): String {
var result = ""
builder {
result = foo("zzz")
}
assertEquals("zzz42", result)
return "OK"
}
@@ -1,38 +0,0 @@
/*
* Copyright 2010-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
* that can be found in the LICENSE file.
*/
import kotlin.test.*
import kotlin.coroutines.*
import kotlin.coroutines.intrinsics.*
open class EmptyContinuation(override val context: CoroutineContext = EmptyCoroutineContext) : Continuation<Any?> {
companion object : EmptyContinuation()
override fun resumeWith(result: Result<Any?>) { result.getOrThrow() }
}
suspend fun suspendForever(): Int = suspendCoroutineUninterceptedOrReturn {
COROUTINE_SUSPENDED
}
suspend fun foo(): Nothing {
suspendForever()
throw Error()
}
suspend fun bar() {
foo()
}
fun builder(c: suspend () -> Unit) {
c.startCoroutine(EmptyContinuation)
}
fun box(): String {
builder {
bar()
}
return "OK"
}
@@ -1,53 +0,0 @@
/*
* 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 file.
*/
import kotlin.test.*
import kotlin.coroutines.*
import kotlin.coroutines.intrinsics.*
val sb = StringBuilder()
open class EmptyContinuation(override val context: CoroutineContext = EmptyCoroutineContext) : Continuation<Any?> {
companion object : EmptyContinuation()
override fun resumeWith(result: Result<Any?>) { result.getOrThrow() }
}
suspend fun s1(): Unit = suspendCoroutineUninterceptedOrReturn { x ->
sb.appendLine("s1")
x.resume(Unit)
COROUTINE_SUSPENDED
}
fun builder(c: suspend () -> Unit) {
c.startCoroutine(EmptyContinuation)
}
inline suspend fun inline_s2(x: Int): Unit {
sb.appendLine(x)
s1()
}
suspend fun s3(x: Int) {
inline_s2(x)
}
fun box(): String {
var result = 0
builder {
s3(117)
}
sb.appendLine(result)
assertEquals("""
117
s1
0
""".trimIndent(), sb.toString())
return "OK"
}
@@ -1,34 +0,0 @@
/*
* 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 file.
*/
import kotlin.test.*
import kotlin.coroutines.*
import kotlin.coroutines.intrinsics.*
open class EmptyContinuation(override val context: CoroutineContext = EmptyCoroutineContext) : Continuation<Any?> {
companion object : EmptyContinuation()
override fun resumeWith(result: Result<Any?>) { result.getOrThrow() }
}
suspend fun suspendHere(): Int = suspendCoroutineUninterceptedOrReturn { x ->
x.resume(42)
COROUTINE_SUSPENDED
}
fun builder(c: suspend () -> Unit) {
c.startCoroutine(EmptyContinuation)
}
fun box(): String {
var result = 0
builder {
result = suspendHere()
}
assertEquals(42, result)
return "OK"
}
@@ -1,29 +0,0 @@
/*
* 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 file.
*/
import kotlin.test.*
import kotlin.coroutines.*
import kotlin.coroutines.intrinsics.*
open class EmptyContinuation(override val context: CoroutineContext = EmptyCoroutineContext) : Continuation<Any?> {
companion object : EmptyContinuation()
override fun resumeWith(result: Result<Any?>) { result.getOrThrow() }
}
fun builder(c: suspend () -> Unit) {
c.startCoroutine(EmptyContinuation)
}
fun box(): String {
var result = 0
val f: () -> Unit = { result = 42 }
builder(f)
assertEquals(42, result)
return "OK"
}
@@ -1,36 +0,0 @@
/*
* 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 file.
*/
import kotlin.test.*
import kotlin.coroutines.*
import kotlin.coroutines.intrinsics.*
open class EmptyContinuation(override val context: CoroutineContext = EmptyCoroutineContext) : Continuation<Any?> {
companion object : EmptyContinuation()
override fun resumeWith(result: Result<Any?>) { result.getOrThrow() }
}
class Controller {
suspend fun suspendHere(): Int = suspendCoroutineUninterceptedOrReturn { x ->
x.resume(42)
COROUTINE_SUSPENDED
}
}
fun builder(c: suspend Controller.() -> Unit) {
c.startCoroutine(Controller(), EmptyContinuation)
}
fun box(): String {
var result = 0
builder {
result = suspendHere()
}
assertEquals(42, result)
return "OK"
}