[K/N][Tests] Move codegen test sources interfaceCallsNCasts..vector

^KT-61259
This commit is contained in:
Vladimir Sukharev
2023-12-15 00:13:04 +01:00
committed by Space Team
parent 56e1c5cbc6
commit 93642020ff
182 changed files with 2023 additions and 686 deletions
+18
View File
@@ -0,0 +1,18 @@
/*
* 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.
*/
package codegen.lambda.lambda1
import kotlin.test.*
@Test fun runTest() {
run {
println("lambda")
}
}
fun run(f: () -> Unit) {
f()
}
@@ -0,0 +1 @@
lambda
+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.
*/
package codegen.lambda.lambda10
import kotlin.test.*
@Test fun runTest() {
var str = "original"
val lambda = {
println(str)
}
lambda()
str = "changed"
lambda()
}
@@ -0,0 +1,2 @@
original
changed
+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.
*/
package codegen.lambda.lambda11
import kotlin.test.*
@Test fun runTest() {
val first = "first"
val second = "second"
run {
println(first)
println(second)
}
}
fun run(f: () -> Unit) {
f()
}
@@ -0,0 +1,2 @@
first
second
+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.
*/
package codegen.lambda.lambda12
import kotlin.test.*
@Test fun runTest() {
val lambda = { s1: String, s2: String ->
println(s1)
println(s2)
}
lambda("one", "two")
}
@@ -0,0 +1,2 @@
one
two
+18
View File
@@ -0,0 +1,18 @@
/*
* 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.
*/
package codegen.lambda.lambda13
import kotlin.test.*
@Test fun runTest() {
apply("foo") {
println(this)
}
}
fun apply(str: String, block: String.() -> Unit) {
str.block()
}
@@ -0,0 +1 @@
foo
+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.
*/
// FILE: 1.kt
package codegen.lambda.lambda14
import kotlin.test.*
@Test fun runTest() {
assertEquals(foo()(), "foo1")
assertEquals(foo(0)(), "foo2")
}
fun foo() = { "foo1" }
// FILE: 2.kt
package codegen.lambda.lambda14
fun foo(ignored: Int) = { "foo2" }
+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.
*/
package codegen.lambda.lambda2
import kotlin.test.*
@Test fun runTest() {
main(arrayOf("arg0"))
}
fun main(args : Array<String>) {
run {
println(args[0])
}
}
fun run(f: () -> Unit) {
f()
}
@@ -0,0 +1 @@
arg0
+19
View File
@@ -0,0 +1,19 @@
/*
* 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.
*/
package codegen.lambda.lambda3
import kotlin.test.*
@Test fun runTest() {
var str = "lambda"
run {
println(str)
}
}
fun run(f: () -> Unit) {
f()
}
@@ -0,0 +1 @@
lambda
+37
View File
@@ -0,0 +1,37 @@
/*
* 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.
*/
package codegen.lambda.lambda4
import kotlin.test.*
@Test fun runTest() {
val lambda = bar()
lambda()
lambda()
}
fun bar(): () -> Unit {
var x = Integer(0)
val lambda = {
println(x.toString())
x = x + 1
}
x = x + 1
lambda()
lambda()
println(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,5 @@
1
2
3
3
4
+18
View File
@@ -0,0 +1,18 @@
/*
* 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.
*/
package codegen.lambda.lambda5
import kotlin.test.*
@Test fun runTest() {
foo {
println(it)
}
}
fun foo(f: (Int) -> Unit) {
f(42)
}
@@ -0,0 +1 @@
42
+20
View File
@@ -0,0 +1,20 @@
/*
* 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.
*/
package codegen.lambda.lambda6
import kotlin.test.*
@Test fun runTest() {
val str = "captured"
foo {
println(it)
println(str)
}
}
fun foo(f: (Int) -> Unit) {
f(42)
}
@@ -0,0 +1,2 @@
42
captured
+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.
*/
package codegen.lambda.lambda7
import kotlin.test.*
@Test fun runTest() {
val x = foo {
it + 1
}
println(x)
}
fun foo(f: (Int) -> Int) = f(42)
@@ -0,0 +1 @@
43
+33
View File
@@ -0,0 +1,33 @@
/*
* 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.
*/
package codegen.lambda.lambda8
import kotlin.test.*
@Test fun runTest() {
val lambda1 = bar("first")
val lambda2 = bar("second")
lambda1()
lambda2()
lambda1()
lambda2()
}
fun bar(str: String): () -> Unit {
var x = Integer(0)
return {
println(str)
println(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,8 @@
first
0
second
0
first
1
second
1
+36
View File
@@ -0,0 +1,36 @@
/*
* 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.
*/
package codegen.lambda.lambda9
import kotlin.test.*
@Test fun runTest() {
val lambdas = ArrayList<() -> Unit>()
for (i in 0..1) {
var x = Integer(0)
val istr = i.toString()
lambdas.add {
println(istr)
println(x.toString())
x = x + 1
}
}
val lambda1 = lambdas[0]
val lambda2 = lambdas[1]
lambda1()
lambda2()
lambda1()
lambda2()
}
class Integer(val value: Int) {
override fun toString() = value.toString()
operator fun plus(other: Int) = Integer(value + other)
}
@@ -0,0 +1,8 @@
0
0
1
0
0
1
1
1
@@ -0,0 +1,17 @@
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,87 @@
import kotlin.test.*
import kotlin.coroutines.*
// To be tested with -g.
// https://youtrack.jetbrains.com/issue/KT-49360
// 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,19 @@
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"
}