[K/N][Tests] Adjust moved tests interfaceCallsNCasts..vector to new infra
^KT-61259
This commit is contained in:
committed by
Space Team
parent
93642020ff
commit
bb8a7b6795
@@ -6,7 +6,6 @@
|
||||
/**
|
||||
* Created by minamoto on 12/26/16.
|
||||
*/
|
||||
//package defaults
|
||||
|
||||
open class A(val a:Int) {
|
||||
override fun equals(other: Any?): Boolean {
|
||||
|
||||
+6
-6
@@ -3,8 +3,6 @@
|
||||
* that can be found in the LICENSE file.
|
||||
*/
|
||||
|
||||
package codegen.interfaceCallsNCasts.conservativeItable
|
||||
|
||||
import kotlin.test.*
|
||||
|
||||
interface I0 {
|
||||
@@ -559,9 +557,9 @@ fun foo(i42: I42, x: Int) = i42.foo42(x)
|
||||
|
||||
fun bar(i_m1: I_M1, x: Int) = i_m1.bar(x)
|
||||
|
||||
@Test fun runTest() {
|
||||
fun box(): String {
|
||||
val y = Bar2()
|
||||
println(bar(y, 1))
|
||||
assertEquals(539, bar(y, 1))
|
||||
val x0 = Bar()
|
||||
var t = 0
|
||||
if (check_is_I0(x0)) t = t + 1
|
||||
@@ -664,7 +662,7 @@ fun bar(i_m1: I_M1, x: Int) = i_m1.bar(x)
|
||||
if (check_is_I97(x0)) t = t + 98
|
||||
if (check_is_I98(x0)) t = t + 99
|
||||
if (check_is_I99(x0)) t = t + 100
|
||||
println(t)
|
||||
assertEquals(5050, t)
|
||||
val x1 = I42_Impl1()
|
||||
val x2 = I42_Impl2()
|
||||
val x3 = I42_Impl3()
|
||||
@@ -682,5 +680,7 @@ fun bar(i_m1: I_M1, x: Int) = i_m1.bar(x)
|
||||
t = foo(x6, t)
|
||||
t = foo(x7, t)
|
||||
t = foo(x8, t)
|
||||
println(t)
|
||||
assertEquals(26551140, t)
|
||||
|
||||
return "OK"
|
||||
}
|
||||
|
||||
-3
@@ -1,3 +0,0 @@
|
||||
539
|
||||
5050
|
||||
26551140
|
||||
@@ -3,8 +3,6 @@
|
||||
* that can be found in the LICENSE file.
|
||||
*/
|
||||
|
||||
package codegen.interfaceCallsNCasts.diamond
|
||||
|
||||
import kotlin.test.*
|
||||
|
||||
interface A<T, U> {
|
||||
@@ -19,8 +17,7 @@ class Z : B<Int>, C<String> {
|
||||
override fun foo(t: String, u: Int) = "Z"
|
||||
}
|
||||
|
||||
@Test
|
||||
fun runTest() {
|
||||
fun box(): String {
|
||||
val z = Z()
|
||||
val c: C<String> = z
|
||||
val b: B<Int> = z
|
||||
@@ -30,4 +27,6 @@ fun runTest() {
|
||||
assertEquals("Z", c.foo("", 0))
|
||||
assertEquals("Z", b.foo("", 0))
|
||||
assertEquals("Z", a.foo("", 0))
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -3,8 +3,6 @@
|
||||
* that can be found in the LICENSE file.
|
||||
*/
|
||||
|
||||
package codegen.interfaceCallsNCasts.finalMethod
|
||||
|
||||
import kotlin.test.*
|
||||
|
||||
interface I1<T> {
|
||||
@@ -21,8 +19,9 @@ class C : I2 {
|
||||
override fun foo(x: Int) = x
|
||||
}
|
||||
|
||||
@Test
|
||||
fun runTest() {
|
||||
fun box(): String {
|
||||
val c: I2 = C()
|
||||
assertEquals(42, c.foo())
|
||||
|
||||
return "OK"
|
||||
}
|
||||
+3
-4
@@ -3,8 +3,6 @@
|
||||
* that can be found in the LICENSE file.
|
||||
*/
|
||||
|
||||
package codegen.interfaceCallsNCasts.functionNameClash
|
||||
|
||||
import kotlin.test.*
|
||||
|
||||
interface I1<T> {
|
||||
@@ -18,11 +16,12 @@ class C : I1<String>, I2<Int> {
|
||||
override fun foo(x: Int) = "I2.foo($x)"
|
||||
}
|
||||
|
||||
@Test
|
||||
fun runTest() {
|
||||
fun box(): String {
|
||||
val c = C()
|
||||
val i1: I1<String> = c
|
||||
assertEquals("I1.foo(str)", i1.foo("str"))
|
||||
val i2: I2<Int> = c
|
||||
assertEquals("I2.foo(42)", i2.foo(42))
|
||||
|
||||
return "OK"
|
||||
}
|
||||
+11
-11
@@ -1,8 +1,6 @@
|
||||
@file:Suppress("INVISIBLE_MEMBER", "INVISIBLE_REFERENCE")
|
||||
@file:OptIn(kotlinx.cinterop.ExperimentalForeignApi::class, kotlin.native.internal.InternalForKotlinNative::class)
|
||||
|
||||
package codegen.intrinsics.interop_sourceCodeStruct
|
||||
|
||||
import kotlinx.cinterop.*
|
||||
import kotlinx.cinterop.internal.*
|
||||
import kotlin.test.*
|
||||
@@ -29,15 +27,17 @@ class S(rawPtr: NativePtr) : CStructVar(rawPtr) {
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun test() = memScoped {
|
||||
val s = alloc<S>()
|
||||
fun box(): String {
|
||||
memScoped {
|
||||
val s = alloc<S>()
|
||||
|
||||
s.x = 123
|
||||
assertEquals(123, s.x)
|
||||
assertEquals(123, s.ptr.reinterpret<IntVar>()[0])
|
||||
s.x = 123
|
||||
assertEquals(123, s.x)
|
||||
assertEquals(123, s.ptr.reinterpret<IntVar>()[0])
|
||||
|
||||
s.y = 321
|
||||
assertEquals(321, s.y)
|
||||
assertEquals(321, s.ptr.reinterpret<IntVar>()[1])
|
||||
s.y = 321
|
||||
assertEquals(321, s.y)
|
||||
assertEquals(321, s.ptr.reinterpret<IntVar>()[1])
|
||||
}
|
||||
return "OK"
|
||||
}
|
||||
|
||||
@@ -7,12 +7,12 @@
|
||||
import kotlin.test.*
|
||||
import kotlin.native.Platform
|
||||
|
||||
@Test
|
||||
@OptIn(kotlin.ExperimentalStdlibApi::class)
|
||||
fun testIsExperimentalMM() {
|
||||
fun box(): String {
|
||||
if (isExperimentalMM()) {
|
||||
assertEquals(Platform.memoryModel, MemoryModel.EXPERIMENTAL)
|
||||
} else {
|
||||
assertNotEquals(Platform.memoryModel, MemoryModel.EXPERIMENTAL)
|
||||
}
|
||||
return "OK"
|
||||
}
|
||||
+46
@@ -0,0 +1,46 @@
|
||||
/*
|
||||
* Copyright 2010-2023 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-64460: When producing cache, anonymous objects are not extracted from inline functions to module scope, so the following happens
|
||||
// kotlin.AssertionError: Expected <class codegen.kclass.kclass0.MainKt$1>, actual <class codegen.kclass.kclass0.box$$inlined$getHasFoo$1>.
|
||||
// IGNORE_NATIVE: cacheMode=STATIC_EVERYWHERE
|
||||
// IGNORE_NATIVE: cacheMode=STATIC_PER_FILE_EVERYWHERE
|
||||
|
||||
package codegen.kclass.kclass0
|
||||
import kotlin.test.*
|
||||
import kotlin.reflect.KClass
|
||||
|
||||
interface HasFoo {
|
||||
fun foo(): String
|
||||
}
|
||||
|
||||
private inline fun getHasFoo(s: String) = object : HasFoo {
|
||||
override fun foo(): String = s
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
val hasFoo = getHasFoo("zzz")
|
||||
checkClass(
|
||||
hasFoo::class,
|
||||
expectedQualifiedName = null,
|
||||
expectedSimpleName = null, // KT-64460: simpleName is explicitly prohibited in NATIVE backend
|
||||
expectedToStringName = "class codegen.kclass.kclass0.MainKt\$1",
|
||||
expectedInstance = hasFoo,
|
||||
expectedNotInstance = Any()
|
||||
)
|
||||
return "OK"
|
||||
}
|
||||
|
||||
private fun checkClass(
|
||||
clazz: KClass<*>,
|
||||
expectedQualifiedName: String?, expectedSimpleName: String?, expectedToStringName: String,
|
||||
expectedInstance: Any, expectedNotInstance: Any?
|
||||
) {
|
||||
assertEquals(expectedQualifiedName, clazz.qualifiedName)
|
||||
assertEquals(expectedSimpleName, clazz.simpleName)
|
||||
assertEquals(expectedToStringName, clazz.toString())
|
||||
|
||||
assertTrue(clazz.isInstance(expectedInstance))
|
||||
if (expectedNotInstance != null) assertTrue(!clazz.isInstance(expectedNotInstance))
|
||||
}
|
||||
+46
@@ -0,0 +1,46 @@
|
||||
/*
|
||||
* Copyright 2010-2023 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-64460: When not producing cache, anonymous objects are extracted from inline functions to module scope, so the following happens
|
||||
// kotlin.AssertionError: Expected <class codegen.kclass.kclass0.checkAnonymousObjects$$inlined$getHasFoo$1>, actual <class codegen.kclass.kclass0.MainKt$1>.
|
||||
// IGNORE_NATIVE: cacheMode=NO
|
||||
// IGNORE_NATIVE: cacheMode=STATIC_ONLY_DIST
|
||||
|
||||
package codegen.kclass.kclass0
|
||||
import kotlin.test.*
|
||||
import kotlin.reflect.KClass
|
||||
|
||||
interface HasFoo {
|
||||
fun foo(): String
|
||||
}
|
||||
|
||||
private inline fun getHasFoo(s: String) = object : HasFoo {
|
||||
override fun foo(): String = s
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
val hasFoo = getHasFoo("zzz")
|
||||
checkClass(
|
||||
hasFoo::class,
|
||||
expectedQualifiedName = null,
|
||||
expectedSimpleName = null, // KT-64460: simpleName is explicitly prohibited in NATIVE backend
|
||||
expectedToStringName = "class codegen.kclass.kclass0.box\$\$inlined\$getHasFoo\$1",
|
||||
expectedInstance = hasFoo,
|
||||
expectedNotInstance = Any()
|
||||
)
|
||||
return "OK"
|
||||
}
|
||||
|
||||
private fun checkClass(
|
||||
clazz: KClass<*>,
|
||||
expectedQualifiedName: String?, expectedSimpleName: String?, expectedToStringName: String,
|
||||
expectedInstance: Any, expectedNotInstance: Any?
|
||||
) {
|
||||
assertEquals(expectedQualifiedName, clazz.qualifiedName)
|
||||
assertEquals(expectedSimpleName, clazz.simpleName)
|
||||
assertEquals(expectedToStringName, clazz.toString())
|
||||
|
||||
assertTrue(clazz.isInstance(expectedInstance))
|
||||
if (expectedNotInstance != null) assertTrue(!clazz.isInstance(expectedNotInstance))
|
||||
}
|
||||
@@ -3,8 +3,6 @@
|
||||
* that can be found in the LICENSE file.
|
||||
*/
|
||||
|
||||
package codegen.kclass.kClassEnumArgument
|
||||
|
||||
import kotlin.test.*
|
||||
import kotlin.reflect.KClass
|
||||
|
||||
@@ -13,6 +11,8 @@ enum class E(val arg: KClass<*>?) {
|
||||
B(String::class);
|
||||
}
|
||||
|
||||
@Test fun runTest() {
|
||||
println(E.B.arg?.simpleName)
|
||||
fun box(): String {
|
||||
assertEquals("String", E.B.arg?.simpleName)
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -1 +0,0 @@
|
||||
String
|
||||
+2
-21
@@ -2,15 +2,14 @@
|
||||
* 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.kclass.kclass0
|
||||
|
||||
import kotlin.test.*
|
||||
import kotlin.coroutines.*
|
||||
import kotlin.reflect.KClass
|
||||
|
||||
@Test fun runTest() {
|
||||
fun box(): String {
|
||||
main(emptyArray<String>())
|
||||
return "OK"
|
||||
}
|
||||
|
||||
fun main(args: Array<String>) {
|
||||
@@ -211,14 +210,6 @@ private fun checkLocalClasses(args: Array<String>) {
|
||||
::suspendFunWithLocalClass.runCoroutine()
|
||||
}
|
||||
|
||||
interface HasFoo {
|
||||
fun foo(): String
|
||||
}
|
||||
|
||||
private inline fun getHasFoo(s: String) = object : HasFoo {
|
||||
override fun foo(): String = s
|
||||
}
|
||||
|
||||
private fun checkAnonymousObjects(args: Array<String>) {
|
||||
// Anonymous object.
|
||||
with(object : Any() {
|
||||
@@ -378,16 +369,6 @@ private fun checkAnonymousObjects(args: Array<String>) {
|
||||
}
|
||||
}
|
||||
::suspendFunWithAnonymousObject.runCoroutine()
|
||||
|
||||
val hasFoo = getHasFoo("zzz")
|
||||
checkClass(
|
||||
hasFoo::class,
|
||||
expectedQualifiedName = null,
|
||||
expectedSimpleName = null,
|
||||
expectedToStringName = "class codegen.kclass.kclass0.Kclass0Kt$1",
|
||||
expectedInstance = hasFoo,
|
||||
expectedNotInstance = Any()
|
||||
)
|
||||
}
|
||||
|
||||
private fun checkAnonymousObjectsAssignedToProperty(args: Array<String>) {
|
||||
|
||||
+6
-6
@@ -7,12 +7,12 @@ package codegen.kclass.kclass1
|
||||
|
||||
import kotlin.test.*
|
||||
|
||||
// FILE: main.kt
|
||||
@Test fun runTest() {
|
||||
App(testQualified = true)
|
||||
}
|
||||
val sb = StringBuilder()
|
||||
|
||||
// FILE: app.kt
|
||||
fun box(): String {
|
||||
App(testQualified = true)
|
||||
return sb.toString()
|
||||
}
|
||||
|
||||
// Taken from:
|
||||
// https://github.com/SalomonBrys/kmffkn/blob/master/shared/main/kotlin/com/github/salomonbrys/kmffkn/app.kt
|
||||
@@ -55,6 +55,6 @@ class App(testQualified: Boolean) {
|
||||
assert(TestClass()::class == TestClass()::class)
|
||||
assert(TestClass()::class == TestClass::class)
|
||||
|
||||
println("OK :D")
|
||||
sb.append("OK")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1 +0,0 @@
|
||||
OK :D
|
||||
+5
-4
@@ -3,14 +3,15 @@
|
||||
* that can be found in the LICENSE file.
|
||||
*/
|
||||
|
||||
package codegen.lambda.lambda1
|
||||
|
||||
import kotlin.test.*
|
||||
|
||||
@Test fun runTest() {
|
||||
val sb = StringBuilder()
|
||||
|
||||
fun box(): String {
|
||||
run {
|
||||
println("lambda")
|
||||
sb.append("OK")
|
||||
}
|
||||
return sb.toString()
|
||||
}
|
||||
|
||||
fun run(f: () -> Unit) {
|
||||
|
||||
@@ -1 +0,0 @@
|
||||
lambda
|
||||
+11
-4
@@ -3,19 +3,26 @@
|
||||
* that can be found in the LICENSE file.
|
||||
*/
|
||||
|
||||
package codegen.lambda.lambda10
|
||||
|
||||
import kotlin.test.*
|
||||
|
||||
@Test fun runTest() {
|
||||
val sb = StringBuilder()
|
||||
|
||||
fun box(): String {
|
||||
var str = "original"
|
||||
|
||||
val lambda = {
|
||||
println(str)
|
||||
sb.appendLine(str)
|
||||
}
|
||||
|
||||
lambda()
|
||||
|
||||
str = "changed"
|
||||
lambda()
|
||||
|
||||
assertEquals("""
|
||||
original
|
||||
changed
|
||||
|
||||
""".trimIndent(), sb.toString())
|
||||
return "OK"
|
||||
}
|
||||
@@ -1,2 +0,0 @@
|
||||
original
|
||||
changed
|
||||
+12
-5
@@ -3,18 +3,25 @@
|
||||
* that can be found in the LICENSE file.
|
||||
*/
|
||||
|
||||
package codegen.lambda.lambda11
|
||||
|
||||
import kotlin.test.*
|
||||
|
||||
@Test fun runTest() {
|
||||
val sb = StringBuilder()
|
||||
|
||||
fun box(): String {
|
||||
val first = "first"
|
||||
val second = "second"
|
||||
|
||||
run {
|
||||
println(first)
|
||||
println(second)
|
||||
sb.appendLine(first)
|
||||
sb.appendLine(second)
|
||||
}
|
||||
|
||||
assertEquals("""
|
||||
first
|
||||
second
|
||||
|
||||
""".trimIndent(), sb.toString())
|
||||
return "OK"
|
||||
}
|
||||
|
||||
fun run(f: () -> Unit) {
|
||||
|
||||
@@ -1,2 +0,0 @@
|
||||
first
|
||||
second
|
||||
+12
-5
@@ -3,15 +3,22 @@
|
||||
* that can be found in the LICENSE file.
|
||||
*/
|
||||
|
||||
package codegen.lambda.lambda12
|
||||
|
||||
import kotlin.test.*
|
||||
|
||||
@Test fun runTest() {
|
||||
val sb = StringBuilder()
|
||||
|
||||
fun box(): String {
|
||||
val lambda = { s1: String, s2: String ->
|
||||
println(s1)
|
||||
println(s2)
|
||||
sb.appendLine(s1)
|
||||
sb.appendLine(s2)
|
||||
}
|
||||
|
||||
lambda("one", "two")
|
||||
|
||||
assertEquals("""
|
||||
one
|
||||
two
|
||||
|
||||
""".trimIndent(), sb.toString())
|
||||
return "OK"
|
||||
}
|
||||
@@ -1,2 +0,0 @@
|
||||
one
|
||||
two
|
||||
+6
-5
@@ -3,14 +3,15 @@
|
||||
* that can be found in the LICENSE file.
|
||||
*/
|
||||
|
||||
package codegen.lambda.lambda13
|
||||
|
||||
import kotlin.test.*
|
||||
|
||||
@Test fun runTest() {
|
||||
apply("foo") {
|
||||
println(this)
|
||||
val sb = StringBuilder()
|
||||
|
||||
fun box(): String {
|
||||
apply("OK") {
|
||||
sb.append(this)
|
||||
}
|
||||
return sb.toString()
|
||||
}
|
||||
|
||||
fun apply(str: String, block: String.() -> Unit) {
|
||||
|
||||
@@ -1 +0,0 @@
|
||||
foo
|
||||
+3
-5
@@ -5,19 +5,17 @@
|
||||
|
||||
// FILE: 1.kt
|
||||
|
||||
package codegen.lambda.lambda14
|
||||
|
||||
import kotlin.test.*
|
||||
|
||||
@Test fun runTest() {
|
||||
fun box(): String {
|
||||
assertEquals(foo()(), "foo1")
|
||||
assertEquals(foo(0)(), "foo2")
|
||||
|
||||
return "OK"
|
||||
}
|
||||
|
||||
fun foo() = { "foo1" }
|
||||
|
||||
// FILE: 2.kt
|
||||
|
||||
package codegen.lambda.lambda14
|
||||
|
||||
fun foo(ignored: Int) = { "foo2" }
|
||||
|
||||
+6
-5
@@ -3,17 +3,18 @@
|
||||
* that can be found in the LICENSE file.
|
||||
*/
|
||||
|
||||
package codegen.lambda.lambda2
|
||||
|
||||
import kotlin.test.*
|
||||
|
||||
@Test fun runTest() {
|
||||
main(arrayOf("arg0"))
|
||||
val sb = StringBuilder()
|
||||
|
||||
fun box(): String {
|
||||
main(arrayOf("OK"))
|
||||
return sb.toString()
|
||||
}
|
||||
|
||||
fun main(args : Array<String>) {
|
||||
run {
|
||||
println(args[0])
|
||||
sb.append(args[0])
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1 +0,0 @@
|
||||
arg0
|
||||
+6
-5
@@ -3,15 +3,16 @@
|
||||
* that can be found in the LICENSE file.
|
||||
*/
|
||||
|
||||
package codegen.lambda.lambda3
|
||||
|
||||
import kotlin.test.*
|
||||
|
||||
@Test fun runTest() {
|
||||
var str = "lambda"
|
||||
val sb = StringBuilder()
|
||||
|
||||
fun box(): String {
|
||||
var str = "OK"
|
||||
run {
|
||||
println(str)
|
||||
sb.append(str)
|
||||
}
|
||||
return sb.toString()
|
||||
}
|
||||
|
||||
fun run(f: () -> Unit) {
|
||||
|
||||
@@ -1 +0,0 @@
|
||||
lambda
|
||||
+15
-5
@@ -3,21 +3,31 @@
|
||||
* that can be found in the LICENSE file.
|
||||
*/
|
||||
|
||||
package codegen.lambda.lambda4
|
||||
|
||||
import kotlin.test.*
|
||||
|
||||
@Test fun runTest() {
|
||||
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 = {
|
||||
println(x.toString())
|
||||
sb.appendLine(x.toString())
|
||||
x = x + 1
|
||||
}
|
||||
|
||||
@@ -26,7 +36,7 @@ fun bar(): () -> Unit {
|
||||
lambda()
|
||||
lambda()
|
||||
|
||||
println(x.toString())
|
||||
sb.appendLine(x.toString())
|
||||
|
||||
return lambda
|
||||
}
|
||||
|
||||
@@ -1,5 +0,0 @@
|
||||
1
|
||||
2
|
||||
3
|
||||
3
|
||||
4
|
||||
+7
-4
@@ -3,14 +3,17 @@
|
||||
* that can be found in the LICENSE file.
|
||||
*/
|
||||
|
||||
package codegen.lambda.lambda5
|
||||
|
||||
import kotlin.test.*
|
||||
|
||||
@Test fun runTest() {
|
||||
val sb = StringBuilder()
|
||||
|
||||
fun box(): String {
|
||||
foo {
|
||||
println(it)
|
||||
sb.append(it)
|
||||
}
|
||||
assertEquals("42", sb.toString())
|
||||
return "OK"
|
||||
|
||||
}
|
||||
|
||||
fun foo(f: (Int) -> Unit) {
|
||||
|
||||
@@ -1 +0,0 @@
|
||||
42
|
||||
+12
-5
@@ -3,16 +3,23 @@
|
||||
* that can be found in the LICENSE file.
|
||||
*/
|
||||
|
||||
package codegen.lambda.lambda6
|
||||
|
||||
import kotlin.test.*
|
||||
|
||||
@Test fun runTest() {
|
||||
val sb = StringBuilder()
|
||||
|
||||
fun box(): String {
|
||||
val str = "captured"
|
||||
foo {
|
||||
println(it)
|
||||
println(str)
|
||||
sb.appendLine(it)
|
||||
sb.appendLine(str)
|
||||
}
|
||||
assertEquals("""
|
||||
42
|
||||
captured
|
||||
|
||||
""".trimIndent(), sb.toString())
|
||||
return "OK"
|
||||
|
||||
}
|
||||
|
||||
fun foo(f: (Int) -> Unit) {
|
||||
|
||||
@@ -1,2 +0,0 @@
|
||||
42
|
||||
captured
|
||||
+3
-4
@@ -3,15 +3,14 @@
|
||||
* that can be found in the LICENSE file.
|
||||
*/
|
||||
|
||||
package codegen.lambda.lambda7
|
||||
|
||||
import kotlin.test.*
|
||||
|
||||
@Test fun runTest() {
|
||||
fun box(): String {
|
||||
val x = foo {
|
||||
it + 1
|
||||
}
|
||||
println(x)
|
||||
assertEquals(43, x)
|
||||
return "OK"
|
||||
}
|
||||
|
||||
fun foo(f: (Int) -> Int) = f(42)
|
||||
@@ -1 +0,0 @@
|
||||
43
|
||||
+18
-5
@@ -3,11 +3,11 @@
|
||||
* that can be found in the LICENSE file.
|
||||
*/
|
||||
|
||||
package codegen.lambda.lambda8
|
||||
|
||||
import kotlin.test.*
|
||||
|
||||
@Test fun runTest() {
|
||||
val sb = StringBuilder()
|
||||
|
||||
fun box(): String {
|
||||
val lambda1 = bar("first")
|
||||
val lambda2 = bar("second")
|
||||
|
||||
@@ -15,14 +15,27 @@ import kotlin.test.*
|
||||
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 {
|
||||
println(str)
|
||||
println(x.toString())
|
||||
sb.appendLine(str)
|
||||
sb.appendLine(x.toString())
|
||||
x = x + 1
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,8 +0,0 @@
|
||||
first
|
||||
0
|
||||
second
|
||||
0
|
||||
first
|
||||
1
|
||||
second
|
||||
1
|
||||
+18
-5
@@ -3,11 +3,11 @@
|
||||
* that can be found in the LICENSE file.
|
||||
*/
|
||||
|
||||
package codegen.lambda.lambda9
|
||||
|
||||
import kotlin.test.*
|
||||
|
||||
@Test fun runTest() {
|
||||
val sb = StringBuilder()
|
||||
|
||||
fun box(): String {
|
||||
val lambdas = ArrayList<() -> Unit>()
|
||||
|
||||
for (i in 0..1) {
|
||||
@@ -15,8 +15,8 @@ import kotlin.test.*
|
||||
val istr = i.toString()
|
||||
|
||||
lambdas.add {
|
||||
println(istr)
|
||||
println(x.toString())
|
||||
sb.appendLine(istr)
|
||||
sb.appendLine(x.toString())
|
||||
x = x + 1
|
||||
}
|
||||
}
|
||||
@@ -28,6 +28,19 @@ import kotlin.test.*
|
||||
lambda2()
|
||||
lambda1()
|
||||
lambda2()
|
||||
|
||||
assertEquals("""
|
||||
0
|
||||
0
|
||||
1
|
||||
0
|
||||
0
|
||||
1
|
||||
1
|
||||
1
|
||||
|
||||
""".trimIndent(), sb.toString())
|
||||
return "OK"
|
||||
}
|
||||
|
||||
class Integer(val value: Int) {
|
||||
|
||||
@@ -1,8 +0,0 @@
|
||||
0
|
||||
0
|
||||
1
|
||||
0
|
||||
0
|
||||
1
|
||||
1
|
||||
1
|
||||
@@ -5,6 +5,8 @@ import kotlin.coroutines.*
|
||||
|
||||
// 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> {
|
||||
|
||||
@@ -3,18 +3,25 @@
|
||||
* that can be found in the LICENSE file.
|
||||
*/
|
||||
|
||||
package codegen.lateinit.globalIsInitialized
|
||||
|
||||
import kotlin.test.*
|
||||
|
||||
val sb = StringBuilder()
|
||||
|
||||
lateinit var s: String
|
||||
|
||||
fun foo() {
|
||||
println(::s.isInitialized)
|
||||
sb.appendLine(::s.isInitialized)
|
||||
}
|
||||
|
||||
@Test fun runTest() {
|
||||
fun box(): String {
|
||||
foo()
|
||||
s = "zzz"
|
||||
foo()
|
||||
|
||||
assertEquals("""
|
||||
false
|
||||
true
|
||||
|
||||
""".trimIndent(), sb.toString())
|
||||
return "OK"
|
||||
}
|
||||
@@ -1,2 +0,0 @@
|
||||
false
|
||||
true
|
||||
@@ -3,8 +3,6 @@
|
||||
* that can be found in the LICENSE file.
|
||||
*/
|
||||
|
||||
package codegen.lateinit.inBaseClass
|
||||
|
||||
import kotlin.test.*
|
||||
|
||||
class A(val a: Int)
|
||||
@@ -17,8 +15,10 @@ class C: B() {
|
||||
fun foo() { a = A(42) }
|
||||
}
|
||||
|
||||
@Test fun runTest() {
|
||||
fun box(): String {
|
||||
val c = C()
|
||||
c.foo()
|
||||
println(c.a.a)
|
||||
assertEquals(42, c.a.a)
|
||||
|
||||
return "OK"
|
||||
}
|
||||
|
||||
@@ -1 +0,0 @@
|
||||
42
|
||||
@@ -3,8 +3,6 @@
|
||||
* that can be found in the LICENSE file.
|
||||
*/
|
||||
|
||||
package codegen.lateinit.initialized
|
||||
|
||||
import kotlin.test.*
|
||||
|
||||
class A {
|
||||
@@ -13,8 +11,8 @@ class A {
|
||||
fun foo() = s
|
||||
}
|
||||
|
||||
@Test fun runTest() {
|
||||
fun box(): String {
|
||||
val a = A()
|
||||
a.s = "zzz"
|
||||
println(a.foo())
|
||||
a.s = "OK"
|
||||
return a.foo()
|
||||
}
|
||||
@@ -1 +0,0 @@
|
||||
zzz
|
||||
@@ -3,8 +3,6 @@
|
||||
* that can be found in the LICENSE file.
|
||||
*/
|
||||
|
||||
package codegen.lateinit.innerIsInitialized
|
||||
|
||||
import kotlin.test.*
|
||||
|
||||
open class Foo {
|
||||
@@ -23,6 +21,6 @@ open class Foo {
|
||||
}
|
||||
}
|
||||
|
||||
@Test fun runTest() {
|
||||
println(Foo().test())
|
||||
fun box(): String {
|
||||
return Foo().test()
|
||||
}
|
||||
|
||||
@@ -1 +0,0 @@
|
||||
OK
|
||||
@@ -3,21 +3,28 @@
|
||||
* that can be found in the LICENSE file.
|
||||
*/
|
||||
|
||||
package codegen.lateinit.isInitialized
|
||||
|
||||
import kotlin.test.*
|
||||
|
||||
val sb = StringBuilder()
|
||||
|
||||
class A {
|
||||
lateinit var s: String
|
||||
|
||||
fun foo() {
|
||||
println(::s.isInitialized)
|
||||
sb.appendLine(::s.isInitialized)
|
||||
}
|
||||
}
|
||||
|
||||
@Test fun runTest() {
|
||||
fun box(): String {
|
||||
val a = A()
|
||||
a.foo()
|
||||
a.s = "zzz"
|
||||
a.foo()
|
||||
|
||||
assertEquals("""
|
||||
false
|
||||
true
|
||||
|
||||
""".trimIndent(), sb.toString())
|
||||
return "OK"
|
||||
}
|
||||
@@ -1,2 +0,0 @@
|
||||
false
|
||||
true
|
||||
@@ -3,15 +3,13 @@
|
||||
* that can be found in the LICENSE file.
|
||||
*/
|
||||
|
||||
package codegen.lateinit.localCapturedInitialized
|
||||
|
||||
import kotlin.test.*
|
||||
|
||||
@Test fun runTest() {
|
||||
fun box(): String {
|
||||
lateinit var s: String
|
||||
|
||||
fun foo() = s
|
||||
|
||||
s = "zzz"
|
||||
println(foo())
|
||||
s = "OK"
|
||||
return foo()
|
||||
}
|
||||
@@ -1 +0,0 @@
|
||||
zzz
|
||||
+7
-7
@@ -3,21 +3,21 @@
|
||||
* that can be found in the LICENSE file.
|
||||
*/
|
||||
|
||||
package codegen.lateinit.localCapturedNotInitialized
|
||||
|
||||
import kotlin.test.*
|
||||
|
||||
@Test fun runTest() {
|
||||
val sb = StringBuilder()
|
||||
|
||||
fun box(): String {
|
||||
lateinit var s: String
|
||||
|
||||
fun foo() = s
|
||||
|
||||
try {
|
||||
println(foo())
|
||||
sb.appendLine(foo())
|
||||
}
|
||||
catch (e: RuntimeException) {
|
||||
println("OK")
|
||||
return
|
||||
sb.append("OK")
|
||||
return sb.toString()
|
||||
}
|
||||
println("Fail")
|
||||
return "Fail"
|
||||
}
|
||||
@@ -1 +0,0 @@
|
||||
OK
|
||||
@@ -3,12 +3,10 @@
|
||||
* that can be found in the LICENSE file.
|
||||
*/
|
||||
|
||||
package codegen.lateinit.localInitialized
|
||||
|
||||
import kotlin.test.*
|
||||
|
||||
@Test fun runTest() {
|
||||
fun box(): String {
|
||||
lateinit var s: String
|
||||
s = "zzz"
|
||||
println(s)
|
||||
s = "OK"
|
||||
return s
|
||||
}
|
||||
@@ -1 +0,0 @@
|
||||
zzz
|
||||
@@ -3,19 +3,19 @@
|
||||
* that can be found in the LICENSE file.
|
||||
*/
|
||||
|
||||
package codegen.lateinit.localNotInitialized
|
||||
|
||||
import kotlin.test.*
|
||||
|
||||
@Test fun runTest() {
|
||||
val sb = StringBuilder()
|
||||
|
||||
fun box(): String {
|
||||
lateinit var s: String
|
||||
|
||||
try {
|
||||
println(s)
|
||||
sb.appendLine(s)
|
||||
}
|
||||
catch (e: RuntimeException) {
|
||||
println("OK")
|
||||
return
|
||||
sb.append("OK")
|
||||
return sb.toString()
|
||||
}
|
||||
println("Fail")
|
||||
return "Fail"
|
||||
}
|
||||
@@ -1 +0,0 @@
|
||||
OK
|
||||
@@ -3,8 +3,6 @@
|
||||
* that can be found in the LICENSE file.
|
||||
*/
|
||||
|
||||
package codegen.lateinit.notInitialized
|
||||
|
||||
import kotlin.test.*
|
||||
|
||||
class A {
|
||||
@@ -13,14 +11,16 @@ class A {
|
||||
fun foo() = s
|
||||
}
|
||||
|
||||
@Test fun runTest() {
|
||||
val sb = StringBuilder()
|
||||
|
||||
fun box(): String {
|
||||
val a = A()
|
||||
try {
|
||||
println(a.foo())
|
||||
sb.appendLine(a.foo())
|
||||
}
|
||||
catch (e: RuntimeException) {
|
||||
println("OK")
|
||||
return
|
||||
sb.append("OK")
|
||||
return sb.toString()
|
||||
}
|
||||
println("Fail")
|
||||
return "Fail"
|
||||
}
|
||||
@@ -1 +0,0 @@
|
||||
OK
|
||||
+11
-8
@@ -3,11 +3,11 @@
|
||||
* that can be found in the LICENSE file.
|
||||
*/
|
||||
|
||||
package codegen.localClass.innerTakesCapturedFromOuter
|
||||
|
||||
import kotlin.test.*
|
||||
|
||||
fun box() {
|
||||
val sb = StringBuilder()
|
||||
|
||||
fun box(): String {
|
||||
var previous: Any? = null
|
||||
for (i in 0 .. 2) {
|
||||
class Outer {
|
||||
@@ -17,11 +17,14 @@ fun box() {
|
||||
|
||||
override fun toString() = Inner().toString()
|
||||
}
|
||||
if (previous != null) println(previous.toString())
|
||||
if (previous != null) sb.appendLine(previous.toString())
|
||||
previous = Outer()
|
||||
}
|
||||
}
|
||||
|
||||
@Test fun runTest() {
|
||||
box()
|
||||
}
|
||||
assertEquals("""
|
||||
0
|
||||
1
|
||||
|
||||
""".trimIndent(), sb.toString())
|
||||
return "OK"
|
||||
}
|
||||
|
||||
-2
@@ -1,2 +0,0 @@
|
||||
0
|
||||
1
|
||||
@@ -3,8 +3,6 @@
|
||||
* that can be found in the LICENSE file.
|
||||
*/
|
||||
|
||||
package codegen.localClass.innerWithCapture
|
||||
|
||||
import kotlin.test.*
|
||||
|
||||
fun box(s: String): String {
|
||||
@@ -17,6 +15,6 @@ fun box(s: String): String {
|
||||
return Local().Inner().result()
|
||||
}
|
||||
|
||||
@Test fun runTest() {
|
||||
println(box("OK"))
|
||||
fun box(): String {
|
||||
return box("OK")
|
||||
}
|
||||
@@ -1 +0,0 @@
|
||||
OK
|
||||
+2
-4
@@ -3,11 +3,9 @@
|
||||
* that can be found in the LICENSE file.
|
||||
*/
|
||||
|
||||
package codegen.localClass.localFunctionCallFromLocalClass
|
||||
|
||||
import kotlin.test.*
|
||||
|
||||
@Test fun runTest() {
|
||||
fun box(): String {
|
||||
var x = 1
|
||||
fun local1() {
|
||||
x++
|
||||
@@ -19,5 +17,5 @@ import kotlin.test.*
|
||||
}
|
||||
}
|
||||
A().bar()
|
||||
println("OK")
|
||||
return "OK"
|
||||
}
|
||||
-1
@@ -1 +0,0 @@
|
||||
OK
|
||||
+2
-4
@@ -3,11 +3,9 @@
|
||||
* that can be found in the LICENSE file.
|
||||
*/
|
||||
|
||||
package codegen.localClass.localFunctionInLocalClass
|
||||
|
||||
import kotlin.test.*
|
||||
|
||||
@Test fun runTest() {
|
||||
fun box(): String {
|
||||
var x = 0
|
||||
class A {
|
||||
fun bar() {
|
||||
@@ -26,5 +24,5 @@ import kotlin.test.*
|
||||
}
|
||||
}
|
||||
A().bar()
|
||||
println("OK")
|
||||
return "OK"
|
||||
}
|
||||
@@ -1 +0,0 @@
|
||||
OK
|
||||
@@ -3,8 +3,6 @@
|
||||
* that can be found in the LICENSE file.
|
||||
*/
|
||||
|
||||
package codegen.localClass.localHierarchy
|
||||
|
||||
import kotlin.test.*
|
||||
|
||||
fun foo(s: String): String {
|
||||
@@ -19,6 +17,6 @@ fun foo(s: String): String {
|
||||
return Derived().g()
|
||||
}
|
||||
|
||||
@Test fun runTest() {
|
||||
println(foo("OK"))
|
||||
fun box(): String {
|
||||
return foo("OK")
|
||||
}
|
||||
@@ -1 +0,0 @@
|
||||
OK
|
||||
@@ -3,8 +3,6 @@
|
||||
* that can be found in the LICENSE file.
|
||||
*/
|
||||
|
||||
package codegen.localClass.noPrimaryConstructor
|
||||
|
||||
import kotlin.test.*
|
||||
|
||||
fun box(s: String): String {
|
||||
@@ -25,6 +23,7 @@ fun box(s: String): String {
|
||||
return Local(42).result() + Local("zzz").result()
|
||||
}
|
||||
|
||||
@Test fun runTest() {
|
||||
println(box("OK"))
|
||||
fun box(): String {
|
||||
assertEquals("OKOK", box("OK"))
|
||||
return "OK"
|
||||
}
|
||||
@@ -1 +0,0 @@
|
||||
OKOK
|
||||
-6
@@ -3,8 +3,6 @@
|
||||
* that can be found in the LICENSE file.
|
||||
*/
|
||||
|
||||
package codegen.localClass.objectExpressionInInitializer
|
||||
|
||||
import kotlin.test.*
|
||||
|
||||
abstract class Father {
|
||||
@@ -28,7 +26,3 @@ class Child : Father() {
|
||||
fun box(): String {
|
||||
return Child().ChildInClass.work()
|
||||
}
|
||||
|
||||
@Test fun runTest() {
|
||||
println(box())
|
||||
}
|
||||
-1
@@ -1 +0,0 @@
|
||||
OK
|
||||
@@ -3,8 +3,6 @@
|
||||
* that can be found in the LICENSE file.
|
||||
*/
|
||||
|
||||
package codegen.localClass.objectExpressionInProperty
|
||||
|
||||
import kotlin.test.*
|
||||
|
||||
abstract class Father {
|
||||
@@ -24,7 +22,3 @@ class Child : Father() {
|
||||
fun box(): String {
|
||||
return Child().ChildInClass.work()
|
||||
}
|
||||
|
||||
@Test fun runTest() {
|
||||
println(box())
|
||||
}
|
||||
-1
@@ -1 +0,0 @@
|
||||
OK
|
||||
@@ -3,23 +3,25 @@
|
||||
* that can be found in the LICENSE file.
|
||||
*/
|
||||
|
||||
package codegen.localClass.tryCatch
|
||||
|
||||
import kotlin.test.*
|
||||
|
||||
val sb = StringBuilder()
|
||||
|
||||
private fun foo() {
|
||||
val local =
|
||||
object {
|
||||
fun bar() {
|
||||
try {
|
||||
} catch (t: Throwable) {
|
||||
println(t)
|
||||
sb.appendLine(t)
|
||||
}
|
||||
}
|
||||
}
|
||||
local.bar()
|
||||
}
|
||||
|
||||
@Test fun runTest() {
|
||||
fun box(): String {
|
||||
sb.append("OK")
|
||||
foo()
|
||||
return sb.toString()
|
||||
}
|
||||
@@ -3,8 +3,6 @@
|
||||
* that can be found in the LICENSE file.
|
||||
*/
|
||||
|
||||
package codegen.localClass.virtualCallFromConstructor
|
||||
|
||||
import kotlin.test.*
|
||||
|
||||
abstract class WaitFor {
|
||||
@@ -28,7 +26,3 @@ fun box(): String {
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@Test fun runTest() {
|
||||
println(box())
|
||||
}
|
||||
-1
@@ -1 +0,0 @@
|
||||
OK
|
||||
+36
-10
@@ -2,6 +2,9 @@
|
||||
* Copyright 2010-2020 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()
|
||||
|
||||
class ArraysConstructor {
|
||||
private val memberArray: IntArray
|
||||
@@ -14,9 +17,9 @@ class ArraysConstructor {
|
||||
memberArray[1] = int2
|
||||
}
|
||||
fun log() {
|
||||
println("Array (constructor init):")
|
||||
println("Size: ${memberArray.size}")
|
||||
println("Contents: ${memberArray.contentToString()}")
|
||||
sb.appendLine("Array (constructor init):")
|
||||
sb.appendLine("Size: ${memberArray.size}")
|
||||
sb.appendLine("Contents: ${memberArray.contentToString()}")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -30,9 +33,9 @@ class ArraysDefault {
|
||||
memberArray[1] = int2
|
||||
}
|
||||
fun log() {
|
||||
println("Array (default value init):")
|
||||
println("Size: ${memberArray.size}")
|
||||
println("Contents: ${memberArray.contentToString()}")
|
||||
sb.appendLine("Array (default value init):")
|
||||
sb.appendLine("Size: ${memberArray.size}")
|
||||
sb.appendLine("Contents: ${memberArray.contentToString()}")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -49,13 +52,13 @@ class ArraysInitBlock {
|
||||
memberArray[1] = int2
|
||||
}
|
||||
fun log() {
|
||||
println("Array (init block):")
|
||||
println("Size: ${memberArray.size}")
|
||||
println("Contents: ${memberArray.contentToString()}")
|
||||
sb.appendLine("Array (init block):")
|
||||
sb.appendLine("Size: ${memberArray.size}")
|
||||
sb.appendLine("Contents: ${memberArray.contentToString()}")
|
||||
}
|
||||
}
|
||||
|
||||
fun main() {
|
||||
fun box(): String {
|
||||
val array1 = (::ArraysConstructor)(1, 2)
|
||||
array1.log()
|
||||
array1.set( 3, 4)
|
||||
@@ -70,4 +73,27 @@ fun main() {
|
||||
array3.log()
|
||||
array3.set( 3, 4)
|
||||
array3.log()
|
||||
|
||||
assertEquals("""
|
||||
Array (constructor init):
|
||||
Size: 2
|
||||
Contents: [1, 2]
|
||||
Array (constructor init):
|
||||
Size: 2
|
||||
Contents: [3, 4]
|
||||
Array (default value init):
|
||||
Size: 2
|
||||
Contents: [1, 2]
|
||||
Array (default value init):
|
||||
Size: 2
|
||||
Contents: [3, 4]
|
||||
Array (init block):
|
||||
Size: 2
|
||||
Contents: [1, 2]
|
||||
Array (init block):
|
||||
Size: 2
|
||||
Contents: [3, 4]
|
||||
|
||||
""".trimIndent(), sb.toString())
|
||||
return "OK"
|
||||
}
|
||||
-18
@@ -1,18 +0,0 @@
|
||||
Array (constructor init):
|
||||
Size: 2
|
||||
Contents: [1, 2]
|
||||
Array (constructor init):
|
||||
Size: 2
|
||||
Contents: [3, 4]
|
||||
Array (default value init):
|
||||
Size: 2
|
||||
Contents: [1, 2]
|
||||
Array (default value init):
|
||||
Size: 2
|
||||
Contents: [3, 4]
|
||||
Array (init block):
|
||||
Size: 2
|
||||
Contents: [1, 2]
|
||||
Array (init block):
|
||||
Size: 2
|
||||
Contents: [3, 4]
|
||||
@@ -3,8 +3,6 @@
|
||||
* that can be found in the LICENSE file.
|
||||
*/
|
||||
|
||||
package codegen.`object`.constructor0
|
||||
|
||||
import kotlin.test.*
|
||||
|
||||
class A {
|
||||
@@ -13,3 +11,8 @@ class A {
|
||||
field0 = arg0
|
||||
}
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
assertEquals(42, A(42).field0)
|
||||
return "OK"
|
||||
}
|
||||
|
||||
+6
-6
@@ -3,8 +3,6 @@
|
||||
* that can be found in the LICENSE file.
|
||||
*/
|
||||
|
||||
package codegen.`object`.fields
|
||||
|
||||
import kotlin.test.*
|
||||
|
||||
private var globalValue = 1
|
||||
@@ -18,8 +16,10 @@ fun globalTest(i:Int):Int {
|
||||
}
|
||||
|
||||
|
||||
@Test fun runTest() {
|
||||
if (global != 1) throw Error()
|
||||
if (globalTest(41) != 42) throw Error()
|
||||
if (global != 42) throw Error()
|
||||
fun box(): String {
|
||||
assertEquals(1, global)
|
||||
assertEquals(42, globalTest(41))
|
||||
assertEquals(42, global)
|
||||
|
||||
return "OK"
|
||||
}
|
||||
+6
-5
@@ -3,8 +3,6 @@
|
||||
* that can be found in the LICENSE file.
|
||||
*/
|
||||
|
||||
package codegen.`object`.fields1
|
||||
|
||||
import kotlin.test.*
|
||||
|
||||
class B(val a:Int, b:Int) {
|
||||
@@ -16,7 +14,10 @@ fun primaryConstructorCall(a:Int, b:Int) = B(a, b).pos
|
||||
|
||||
fun secondaryConstructorCall(a:Int) = B(a).pos
|
||||
|
||||
@Test fun runTest() {
|
||||
if (primaryConstructorCall(0xdeadbeef.toInt(), 41) != 42) throw Error()
|
||||
if (secondaryConstructorCall(41) != 42) throw Error()
|
||||
fun box(): String {
|
||||
assertEquals(42, primaryConstructorCall(0xdeadbeef.toInt(), 41))
|
||||
assertEquals(42, secondaryConstructorCall(41))
|
||||
|
||||
return "OK"
|
||||
|
||||
}
|
||||
+18
-22
@@ -3,33 +3,33 @@
|
||||
* that can be found in the LICENSE file.
|
||||
*/
|
||||
|
||||
package codegen.`object`.fields2
|
||||
|
||||
import kotlin.test.*
|
||||
|
||||
val sb = StringBuilder()
|
||||
|
||||
var global: Int = 0
|
||||
get() {
|
||||
println("Get global = $field")
|
||||
sb.appendLine("Get global = $field")
|
||||
return field
|
||||
}
|
||||
set(value) {
|
||||
println("Set global = $value")
|
||||
sb.appendLine("Set global = $value")
|
||||
field = value
|
||||
}
|
||||
|
||||
class TestClass {
|
||||
var member: Int = 0
|
||||
get() {
|
||||
println("Get member = $field")
|
||||
sb.appendLine("Get member = $field")
|
||||
return field
|
||||
}
|
||||
set(value) {
|
||||
println("Set member = $value")
|
||||
sb.appendLine("Set member = $value")
|
||||
field = value
|
||||
}
|
||||
}
|
||||
|
||||
@Test fun runTest1() {
|
||||
fun box(): String {
|
||||
global = 1
|
||||
|
||||
val test = TestClass()
|
||||
@@ -37,19 +37,15 @@ class TestClass {
|
||||
|
||||
global = test.member
|
||||
test.member = global
|
||||
}
|
||||
|
||||
@ThreadLocal
|
||||
val xInt = 42
|
||||
|
||||
@ThreadLocal
|
||||
val xString = "42"
|
||||
|
||||
@ThreadLocal
|
||||
val xAny = Any()
|
||||
|
||||
@Test fun runTest2() {
|
||||
assertEquals(42, xInt)
|
||||
assertEquals("42", xString)
|
||||
assertTrue(xAny is Any)
|
||||
|
||||
assertEquals("""
|
||||
Set global = 1
|
||||
Set member = 42
|
||||
Get member = 42
|
||||
Set global = 42
|
||||
Get global = 42
|
||||
Set member = 42
|
||||
|
||||
""".trimIndent(), sb.toString())
|
||||
return "OK"
|
||||
}
|
||||
|
||||
@@ -1,6 +0,0 @@
|
||||
Set global = 1
|
||||
Set member = 42
|
||||
Get member = 42
|
||||
Set global = 42
|
||||
Get global = 42
|
||||
Set member = 42
|
||||
@@ -9,4 +9,9 @@ public val z: Any = Z
|
||||
|
||||
private object Z
|
||||
|
||||
fun main(args: Array<String>) { }
|
||||
fun box(): String {
|
||||
if (z is Z)
|
||||
return "OK"
|
||||
else
|
||||
return "FAIL"
|
||||
}
|
||||
|
||||
+7
-2
@@ -3,8 +3,6 @@
|
||||
* that can be found in the LICENSE file.
|
||||
*/
|
||||
|
||||
package codegen.`object`.init0
|
||||
|
||||
import kotlin.test.*
|
||||
|
||||
class A(a:Int) {
|
||||
@@ -12,4 +10,11 @@ class A(a:Int) {
|
||||
init {
|
||||
if (a == 0) i = 1
|
||||
}
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
assertEquals(1, A(0).i)
|
||||
assertEquals(0, A(1).i)
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -3,8 +3,6 @@
|
||||
* that can be found in the LICENSE file.
|
||||
*/
|
||||
|
||||
package codegen.`object`.initialization
|
||||
|
||||
import kotlin.test.*
|
||||
|
||||
open class A(val a:Int, val b:Int)
|
||||
@@ -28,6 +26,7 @@ fun foo(i:Int, j:Int):Int {
|
||||
return c.c
|
||||
}
|
||||
|
||||
@Test fun runTest() {
|
||||
if (foo(2, 3) != 5) throw Error()
|
||||
fun box(): String {
|
||||
assertEquals(5, foo(2, 3))
|
||||
return "OK"
|
||||
}
|
||||
@@ -3,27 +3,39 @@
|
||||
* that can be found in the LICENSE file.
|
||||
*/
|
||||
|
||||
package codegen.`object`.initialization1
|
||||
|
||||
import kotlin.test.*
|
||||
|
||||
val sb = StringBuilder()
|
||||
|
||||
class TestClass {
|
||||
constructor() {
|
||||
println("constructor1")
|
||||
sb.appendLine("constructor1")
|
||||
}
|
||||
|
||||
constructor(x: Int) : this() {
|
||||
println("constructor2")
|
||||
sb.appendLine("constructor2")
|
||||
}
|
||||
|
||||
init {
|
||||
println("init")
|
||||
sb.appendLine("init")
|
||||
}
|
||||
|
||||
val f = println("field")
|
||||
val f = sb.appendLine("field")
|
||||
}
|
||||
|
||||
@Test fun runTest() {
|
||||
fun box(): String {
|
||||
TestClass()
|
||||
TestClass(1)
|
||||
|
||||
assertEquals("""
|
||||
init
|
||||
field
|
||||
constructor1
|
||||
init
|
||||
field
|
||||
constructor1
|
||||
constructor2
|
||||
|
||||
""".trimIndent(), sb.toString())
|
||||
return "OK"
|
||||
}
|
||||
@@ -1,7 +0,0 @@
|
||||
init
|
||||
field
|
||||
constructor1
|
||||
init
|
||||
field
|
||||
constructor1
|
||||
constructor2
|
||||
@@ -3,8 +3,6 @@
|
||||
* that can be found in the LICENSE file.
|
||||
*/
|
||||
|
||||
package codegen.`object`.method_call
|
||||
|
||||
import kotlin.test.*
|
||||
|
||||
class A(val a:Int) {
|
||||
@@ -13,6 +11,7 @@ class A(val a:Int) {
|
||||
|
||||
fun fortyTwo() = A(41).foo(1)
|
||||
|
||||
@Test fun runTest() {
|
||||
if (fortyTwo() != 42) throw Error()
|
||||
fun box(): String {
|
||||
assertEquals(42, fortyTwo())
|
||||
return "OK"
|
||||
}
|
||||
@@ -3,8 +3,8 @@
|
||||
* that can be found in the LICENSE file.
|
||||
*/
|
||||
|
||||
@file:OptIn(FreezingIsDeprecated::class, kotlin.experimental.ExperimentalNativeApi::class)
|
||||
package codegen.objectDeclaration.isFrozen
|
||||
//@file:OptIn(FreezingIsDeprecated::class, kotlin.experimental.ExperimentalNativeApi::class)
|
||||
@file:OptIn(kotlin.experimental.ExperimentalNativeApi::class)
|
||||
|
||||
import kotlin.test.*
|
||||
import kotlin.native.concurrent.*
|
||||
@@ -13,7 +13,7 @@ object X {
|
||||
var value: Int = 0
|
||||
}
|
||||
|
||||
@Test fun runTest() {
|
||||
fun box(): String {
|
||||
if (Platform.memoryModel == MemoryModel.STRICT) {
|
||||
assertTrue(X.isFrozen)
|
||||
assertFailsWith<InvalidMutabilityException> {
|
||||
@@ -25,4 +25,5 @@ object X {
|
||||
X.value = 42
|
||||
assertEquals(42, X.value)
|
||||
}
|
||||
return "OK"
|
||||
}
|
||||
|
||||
@@ -3,11 +3,9 @@
|
||||
* that can be found in the LICENSE file.
|
||||
*/
|
||||
|
||||
package codegen.objectExpression.expr1
|
||||
|
||||
import kotlin.test.*
|
||||
|
||||
@Test fun runTest() {
|
||||
fun box(): String {
|
||||
val a = "a"
|
||||
|
||||
val x = object {
|
||||
@@ -18,5 +16,6 @@ import kotlin.test.*
|
||||
fun foo(s: String) = s + s
|
||||
}
|
||||
|
||||
println(x.toString())
|
||||
assertEquals("aabb", x.toString())
|
||||
return "OK"
|
||||
}
|
||||
@@ -1 +0,0 @@
|
||||
aabb
|
||||
@@ -3,11 +3,10 @@
|
||||
* that can be found in the LICENSE file.
|
||||
*/
|
||||
|
||||
package codegen.objectExpression.expr2
|
||||
import kotlin.test.*
|
||||
|
||||
@Test fun runTest() {
|
||||
val a = "a"
|
||||
fun box(): String {
|
||||
val a = "OK"
|
||||
|
||||
val x = object {
|
||||
override fun toString(): String {
|
||||
@@ -19,7 +18,5 @@ import kotlin.test.*
|
||||
fun foo(lambda: () -> String) = lambda()
|
||||
}
|
||||
|
||||
print(x)
|
||||
return x.toString()
|
||||
}
|
||||
|
||||
fun print(x: Any) = println(x.toString())
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user