[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
@@ -0,0 +1,9 @@
MODULE main
CLASS Lambda1Kt.class
PACKAGE METADATA
PROPERTY getSb()Ljava/lang/StringBuilder;
Property: class.metadata.property.returnType
K1
java/lang/StringBuilder /* = kotlin/text/StringBuilder^ */
K2
java/lang/StringBuilder
+21
View File
@@ -0,0 +1,21 @@
/*
* 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.
*/
// JVM_ABI_K1_K2_DIFF: KT-63864
// WITH_STDLIB
import kotlin.test.*
val sb = StringBuilder()
fun box(): String {
run {
sb.append("OK")
}
return sb.toString()
}
fun run(f: () -> Unit) {
f()
}
@@ -0,0 +1,9 @@
MODULE main
CLASS Lambda10Kt.class
PACKAGE METADATA
PROPERTY getSb()Ljava/lang/StringBuilder;
Property: class.metadata.property.returnType
K1
java/lang/StringBuilder /* = kotlin/text/StringBuilder^ */
K2
java/lang/StringBuilder
+30
View File
@@ -0,0 +1,30 @@
/*
* 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.
*/
// JVM_ABI_K1_K2_DIFF: KT-63864
// WITH_STDLIB
import kotlin.test.*
val sb = StringBuilder()
fun box(): String {
var str = "original"
val lambda = {
sb.appendLine(str)
}
lambda()
str = "changed"
lambda()
assertEquals("""
original
changed
""".trimIndent(), sb.toString())
return "OK"
}
@@ -0,0 +1,9 @@
MODULE main
CLASS Lambda11Kt.class
PACKAGE METADATA
PROPERTY getSb()Ljava/lang/StringBuilder;
Property: class.metadata.property.returnType
K1
java/lang/StringBuilder /* = kotlin/text/StringBuilder^ */
K2
java/lang/StringBuilder
+31
View File
@@ -0,0 +1,31 @@
/*
* 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.
*/
// JVM_ABI_K1_K2_DIFF: KT-63864
// WITH_STDLIB
import kotlin.test.*
val sb = StringBuilder()
fun box(): String {
val first = "first"
val second = "second"
run {
sb.appendLine(first)
sb.appendLine(second)
}
assertEquals("""
first
second
""".trimIndent(), sb.toString())
return "OK"
}
fun run(f: () -> Unit) {
f()
}
@@ -0,0 +1,9 @@
MODULE main
CLASS Lambda12Kt.class
PACKAGE METADATA
PROPERTY getSb()Ljava/lang/StringBuilder;
Property: class.metadata.property.returnType
K1
java/lang/StringBuilder /* = kotlin/text/StringBuilder^ */
K2
java/lang/StringBuilder
+26
View File
@@ -0,0 +1,26 @@
/*
* 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.
*/
// JVM_ABI_K1_K2_DIFF: KT-63864
// WITH_STDLIB
import kotlin.test.*
val sb = StringBuilder()
fun box(): String {
val lambda = { s1: String, s2: String ->
sb.appendLine(s1)
sb.appendLine(s2)
}
lambda("one", "two")
assertEquals("""
one
two
""".trimIndent(), sb.toString())
return "OK"
}
@@ -0,0 +1,9 @@
MODULE main
CLASS Lambda13Kt.class
PACKAGE METADATA
PROPERTY getSb()Ljava/lang/StringBuilder;
Property: class.metadata.property.returnType
K1
java/lang/StringBuilder /* = kotlin/text/StringBuilder^ */
K2
java/lang/StringBuilder
+21
View File
@@ -0,0 +1,21 @@
/*
* 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.
*/
// JVM_ABI_K1_K2_DIFF: KT-63864
// WITH_STDLIB
import kotlin.test.*
val sb = StringBuilder()
fun box(): String {
apply("OK") {
sb.append(this)
}
return sb.toString()
}
fun apply(str: String, block: String.() -> Unit) {
str.block()
}
+22
View File
@@ -0,0 +1,22 @@
/*
* 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.
*/
// WITH_STDLIB
// FILE: 1.kt
import kotlin.test.*
fun box(): String {
assertEquals(foo()(), "foo1")
assertEquals(foo(0)(), "foo2")
return "OK"
}
fun foo() = { "foo1" }
// FILE: 2.kt
fun foo(ignored: Int) = { "foo2" }
@@ -0,0 +1,9 @@
MODULE main
CLASS Lambda2Kt.class
PACKAGE METADATA
PROPERTY getSb()Ljava/lang/StringBuilder;
Property: class.metadata.property.returnType
K1
java/lang/StringBuilder /* = kotlin/text/StringBuilder^ */
K2
java/lang/StringBuilder
+27
View File
@@ -0,0 +1,27 @@
/*
* 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.
*/
// KT-66106: uncaught exception: Wrong box result 'undefined'; Expected "OK"
// IGNORE_BACKEND: WASM
// JVM_ABI_K1_K2_DIFF: KT-63864
// WITH_STDLIB
import kotlin.test.*
val sb = StringBuilder()
fun box(): String {
main(arrayOf("OK"))
return sb.toString()
}
fun main(args : Array<String>) {
run {
sb.append(args[0])
}
}
fun run(f: () -> Unit) {
f()
}
@@ -0,0 +1,9 @@
MODULE main
CLASS Lambda3Kt.class
PACKAGE METADATA
PROPERTY getSb()Ljava/lang/StringBuilder;
Property: class.metadata.property.returnType
K1
java/lang/StringBuilder /* = kotlin/text/StringBuilder^ */
K2
java/lang/StringBuilder
+22
View File
@@ -0,0 +1,22 @@
/*
* 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.
*/
// JVM_ABI_K1_K2_DIFF: KT-63864
// WITH_STDLIB
import kotlin.test.*
val sb = StringBuilder()
fun box(): String {
var str = "OK"
run {
sb.append(str)
}
return sb.toString()
}
fun run(f: () -> Unit) {
f()
}
@@ -0,0 +1,9 @@
MODULE main
CLASS Lambda4Kt.class
PACKAGE METADATA
PROPERTY getSb()Ljava/lang/StringBuilder;
Property: class.metadata.property.returnType
K1
java/lang/StringBuilder /* = kotlin/text/StringBuilder^ */
K2
java/lang/StringBuilder
+49
View File
@@ -0,0 +1,49 @@
/*
* 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.
*/
// JVM_ABI_K1_K2_DIFF: KT-63864
// WITH_STDLIB
import kotlin.test.*
val sb = StringBuilder()
fun box(): String {
val lambda = bar()
lambda()
lambda()
assertEquals("""
1
2
3
3
4
""".trimIndent(), sb.toString())
return "OK"
}
fun bar(): () -> Unit {
var x = Integer(0)
val lambda = {
sb.appendLine(x.toString())
x = x + 1
}
x = x + 1
lambda()
lambda()
sb.appendLine(x.toString())
return lambda
}
class Integer(val value: Int) {
override fun toString() = value.toString()
operator fun plus(other: Int) = Integer(value + other)
}
@@ -0,0 +1,9 @@
MODULE main
CLASS Lambda5Kt.class
PACKAGE METADATA
PROPERTY getSb()Ljava/lang/StringBuilder;
Property: class.metadata.property.returnType
K1
java/lang/StringBuilder /* = kotlin/text/StringBuilder^ */
K2
java/lang/StringBuilder
+23
View File
@@ -0,0 +1,23 @@
/*
* 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.
*/
// JVM_ABI_K1_K2_DIFF: KT-63864
// WITH_STDLIB
import kotlin.test.*
val sb = StringBuilder()
fun box(): String {
foo {
sb.append(it)
}
assertEquals("42", sb.toString())
return "OK"
}
fun foo(f: (Int) -> Unit) {
f(42)
}
@@ -0,0 +1,9 @@
MODULE main
CLASS Lambda6Kt.class
PACKAGE METADATA
PROPERTY getSb()Ljava/lang/StringBuilder;
Property: class.metadata.property.returnType
K1
java/lang/StringBuilder /* = kotlin/text/StringBuilder^ */
K2
java/lang/StringBuilder
+29
View File
@@ -0,0 +1,29 @@
/*
* 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.
*/
// JVM_ABI_K1_K2_DIFF: KT-63864
// WITH_STDLIB
import kotlin.test.*
val sb = StringBuilder()
fun box(): String {
val str = "captured"
foo {
sb.appendLine(it)
sb.appendLine(str)
}
assertEquals("""
42
captured
""".trimIndent(), sb.toString())
return "OK"
}
fun foo(f: (Int) -> Unit) {
f(42)
}
+17
View File
@@ -0,0 +1,17 @@
/*
* 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.
*/
// WITH_STDLIB
import kotlin.test.*
fun box(): String {
val x = foo {
it + 1
}
assertEquals(43, x)
return "OK"
}
fun foo(f: (Int) -> Int) = f(42)
@@ -0,0 +1,9 @@
MODULE main
CLASS Lambda8Kt.class
PACKAGE METADATA
PROPERTY getSb()Ljava/lang/StringBuilder;
Property: class.metadata.property.returnType
K1
java/lang/StringBuilder /* = kotlin/text/StringBuilder^ */
K2
java/lang/StringBuilder
+48
View File
@@ -0,0 +1,48 @@
/*
* 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.
*/
// JVM_ABI_K1_K2_DIFF: KT-63864
// WITH_STDLIB
import kotlin.test.*
val sb = StringBuilder()
fun box(): String {
val lambda1 = bar("first")
val lambda2 = bar("second")
lambda1()
lambda2()
lambda1()
lambda2()
assertEquals("""
first
0
second
0
first
1
second
1
""".trimIndent(), sb.toString())
return "OK"
}
fun bar(str: String): () -> Unit {
var x = Integer(0)
return {
sb.appendLine(str)
sb.appendLine(x.toString())
x = x + 1
}
}
class Integer(val value: Int) {
override fun toString() = value.toString()
operator fun plus(other: Int) = Integer(value + other)
}
@@ -0,0 +1,9 @@
MODULE main
CLASS Lambda9Kt.class
PACKAGE METADATA
PROPERTY getSb()Ljava/lang/StringBuilder;
Property: class.metadata.property.returnType
K1
java/lang/StringBuilder /* = kotlin/text/StringBuilder^ */
K2
java/lang/StringBuilder
+51
View File
@@ -0,0 +1,51 @@
/*
* 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.
*/
// JVM_ABI_K1_K2_DIFF: KT-63864
// WITH_STDLIB
import kotlin.test.*
val sb = StringBuilder()
fun box(): String {
val lambdas = ArrayList<() -> Unit>()
for (i in 0..1) {
var x = Integer(0)
val istr = i.toString()
lambdas.add {
sb.appendLine(istr)
sb.appendLine(x.toString())
x = x + 1
}
}
val lambda1 = lambdas[0]
val lambda2 = lambdas[1]
lambda1()
lambda2()
lambda1()
lambda2()
assertEquals("""
0
0
1
0
0
1
1
1
""".trimIndent(), sb.toString())
return "OK"
}
class Integer(val value: Int) {
override fun toString() = value.toString()
operator fun plus(other: Int) = Integer(value + other)
}
@@ -0,0 +1,19 @@
// WITH_STDLIB
// WITH_COROUTINES
import kotlin.test.*
import kotlin.coroutines.*
// To be tested with -g.
// https://youtrack.jetbrains.com/issue/KT-49360
fun testTrivialCreateBlock(result: Int): () -> Int {
return (if (result == 0) { { 0 } } else null) ?: { result }
}
fun box(): String {
assertEquals(0, testTrivialCreateBlock(0)())
assertEquals(1, testTrivialCreateBlock(1)())
return "OK"
}
@@ -0,0 +1,91 @@
// WITH_STDLIB
// WITH_COROUTINES
import kotlin.test.*
import kotlin.coroutines.*
// To be tested with -g.
// https://youtrack.jetbrains.com/issue/KT-49360
class Block(val block: () -> Int)
// The Flow code below is taken from kotlinx.coroutines (some unrelated details removed).
interface FlowCollector<in T> {
suspend fun emit(value: T)
}
interface Flow<out T> {
suspend fun collect(collector: FlowCollector<T>)
}
suspend inline fun <T> Flow<T>.collect(crossinline action: suspend (value: T) -> Unit): Unit =
collect(object : FlowCollector<T> {
override suspend fun emit(value: T) = action(value)
})
inline fun <T> unsafeFlow(crossinline block: suspend FlowCollector<T>.() -> Unit): Flow<T> {
return object : Flow<T> {
override suspend fun collect(collector: FlowCollector<T>) {
collector.block()
}
}
}
inline fun <T, R> Flow<T>.unsafeTransform(
crossinline transform: suspend FlowCollector<R>.(value: T) -> Unit
): Flow<R> = unsafeFlow {
collect { value ->
return@collect transform(value)
}
}
inline fun <T, R: Any> Flow<T>.mapNotNull(crossinline transform: suspend (value: T) -> R?): Flow<R> = unsafeTransform { value ->
val transformed = transform(value) ?: return@unsafeTransform
return@unsafeTransform emit(transformed)
}
fun <T> flowOf(value: T): Flow<T> = unsafeFlow {
emit(value)
}
suspend fun <T> Flow<T>.toList(): List<T> {
val result = mutableListOf<T>()
collect {
result.add(it)
}
return result
}
// Close to https://youtrack.jetbrains.com/issue/KT-49360:
fun testWithFlowMapNotNull(flow: Flow<Boolean>): Flow<Block> {
return flow.mapNotNull {
if (it) Block({ 333 }) else null
}
}
fun box(): String {
lateinit var list1: List<Block>
lateinit var list2: List<Block>
builder {
list1 = testWithFlowMapNotNull(flowOf(true)).toList()
list2 = testWithFlowMapNotNull(flowOf(false)).toList()
}
assertEquals(1, list1.size)
assertEquals(333, list1.single().block())
assertEquals(0, list2.size)
return "OK"
}
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)
}
@@ -0,0 +1,21 @@
// WITH_STDLIB
// WITH_COROUTINES
import kotlin.test.*
import kotlin.coroutines.*
// To be tested with -g.
// https://youtrack.jetbrains.com/issue/KT-49360
class Block(val block: () -> Int)
fun testWrapBlockCreate(flag: Boolean): Block {
return (if (flag) Block { 11 } else null) ?: Block { 22 }
}
fun box(): String {
assertEquals(11, testWrapBlockCreate(true).block())
assertEquals(22, testWrapBlockCreate(false).block())
return "OK"
}