[K/N][Tests] Adjust moved codegen tests to new infra

^KT-61259
This commit is contained in:
Vladimir Sukharev
2023-12-14 20:14:47 +01:00
committed by Space Team
parent 71a834b778
commit 73032213f0
295 changed files with 1362 additions and 1145 deletions
@@ -3,8 +3,6 @@
* that can be found in the LICENSE file.
*/
package codegen.initializers.correctOrder1
import kotlin.test.*
class TestClass {
@@ -17,6 +15,7 @@ class TestClass {
val y = x
}
@Test fun runTest() {
println(TestClass().y)
fun box(): String {
assertEquals(42, TestClass().y)
return "OK"
}
@@ -1 +0,0 @@
42
@@ -3,8 +3,6 @@
* that can be found in the LICENSE file.
*/
package codegen.initializers.correctOrder2
import kotlin.test.*
class TestClass {
@@ -17,6 +15,7 @@ class TestClass {
}
}
@Test fun runTest() {
println(TestClass().x)
fun box(): String {
assertEquals(42, TestClass().x)
return "OK"
}
@@ -1 +0,0 @@
42
@@ -14,6 +14,9 @@ class Z(val x: Int)
val z2 = Z(x.s.length)
// FILE: main.kt
fun main() {
println(z2.x)
import kotlin.test.*
fun box(): String {
assertEquals(3, z2.x)
return "OK"
}
@@ -1 +0,0 @@
3
@@ -2,6 +2,8 @@
* Copyright 2010-2021 JetBrains s.r.o. and Kotlin Programming Language contributors.
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/
// KT-64408: when undisabled (by removing next line), the compiled .kexe wrongly contains no tests
// DISABLE_NATIVE: cacheMode=STATIC_PER_FILE_EVERYWHERE
// FILE: lib.kt
var z1 = false
@@ -25,7 +27,9 @@ val y = run { z2 = true; 117 }
// FILE: main.kt
import kotlin.test.*
fun main() {
fun box(): String {
assertTrue(z1)
assertTrue(z2)
return "OK"
}
@@ -2,6 +2,8 @@
* Copyright 2010-2021 JetBrains s.r.o. and Kotlin Programming Language contributors.
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/
// KT-64408: when undisabled (by removing next line), the compiled .kexe wrongly contains no tests
// DISABLE_NATIVE: cacheMode=STATIC_PER_FILE_EVERYWHERE
// FILE: lib.kt
var z1 = false
@@ -20,7 +22,9 @@ val y = run { z2 = true; 117 }
// FILE: main.kt
import kotlin.test.*
fun main() {
fun box(): String {
assertTrue(z1)
assertFalse(z2)
return "OK"
}
@@ -2,6 +2,8 @@
* Copyright 2010-2021 JetBrains s.r.o. and Kotlin Programming Language contributors.
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/
// KT-64408: when undisabled (by removing next line), the compiled .kexe wrongly contains no tests
// DISABLE_NATIVE: cacheMode=STATIC_PER_FILE_EVERYWHERE
// FILE: lib.kt
@ThreadLocal
@@ -32,8 +34,10 @@ val y2 = run { z3 = true; 117 }
// FILE: main.kt
import kotlin.test.*
fun main() {
fun box(): String {
assertTrue(z1)
assertTrue(z2)
assertTrue(z3)
return "OK"
}
@@ -2,6 +2,8 @@
* Copyright 2010-2021 JetBrains s.r.o. and Kotlin Programming Language contributors.
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/
// KT-64408: when undisabled (by removing next line), the compiled .kexe wrongly contains no tests
// DISABLE_NATIVE: cacheMode=STATIC_PER_FILE_EVERYWHERE
// FILE: lib.kt
@ThreadLocal
@@ -27,8 +29,10 @@ val y2 = run { z3 = true; 117 }
// FILE: main.kt
import kotlin.test.*
fun main() {
fun box(): String {
assertTrue(z1)
assertFalse(z2)
assertFalse(z3)
return "OK"
}
@@ -21,7 +21,9 @@ fun bar() = 117
// FILE: main.kt
import kotlin.test.*
fun main() {
fun box(): String {
bar()
assertTrue(z)
return "OK"
}
@@ -21,6 +21,7 @@ private fun bar(): Int {
// FILE: main.kt
import kotlin.test.*
fun main() {
fun box(): String {
assertEquals(y, 117)
return "OK"
}
@@ -23,7 +23,9 @@ class C {
// FILE: main.kt
import kotlin.test.*
fun main() {
fun box(): String {
C().bar()
assertFalse(z)
return "OK"
}
@@ -22,9 +22,11 @@ object Z {
// FILE: main.kt
import kotlin.test.*
fun main() {
fun box(): String {
Z.bar()
assertFalse(z)
assertEquals(42, Z.baz())
assertTrue(z)
return "OK"
}
@@ -11,12 +11,15 @@ private fun getY() = 42
fun bar(x: Int) = x == 0
// FILE: main.kt
import kotlin.test.*
fun foo(x: Int) {
if (x <= 0) return
bar(x)
}
fun main() {
fun box(): String {
foo(0)
println(y)
assertEquals(42, y)
return "OK"
}
@@ -1 +0,0 @@
42
@@ -11,12 +11,15 @@ private fun getY() = 42
fun bar(x: Int) = x == 0
// FILE: main.kt
import kotlin.test.*
inline fun foo(x: Int) {
if (x <= 0) return
bar(x)
}
fun main() {
fun box(): String {
foo(0)
println(y)
assertEquals(42, y)
return "OK"
}
@@ -1 +0,0 @@
42
@@ -1,211 +0,0 @@
/*
* Copyright 2010-2021 JetBrains s.r.o. and Kotlin Programming Language contributors.
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/
@file:OptIn(kotlin.ExperimentalStdlibApi::class, kotlin.experimental.ExperimentalNativeApi::class)
package codegen.initializers.static
import kotlin.test.*
import kotlin.native.internal.*
import kotlin.reflect.*
import kotlin.native.Platform
import kotlin.native.OsFamily
class Delegate {
operator fun getValue(thisRef: Any?, property: KProperty<*>) : String {
assertTrue(property.isPermanent());
assertTrue(property.returnType.isPermanent())
return property.name
}
}
class A {
val z by Delegate()
}
fun f() = 5
@Test fun testPermanent() {
val x = typeOf<Map<String, Int>>()
assertTrue(x.isPermanent())
val a = A()
assertTrue(a.z.isPermanent())
assertEquals("z", a.z)
val t = ::f
assertTrue(t.isPermanent())
assertEquals(5, t())
val z = { 6 }
assertTrue(z.isPermanent())
assertEquals(6, z())
}
@Test fun testVarargChange() {
fun varargGetter(position:Int, vararg x: Int): Int {
x[position] *= 5;
return x[position]
}
repeat(3) {
assertEquals(10, varargGetter(0, 2, 3, 4))
assertEquals(10, varargGetter(0, 2, 3, 4))
assertEquals(15, varargGetter(1, 2, 3, 4))
assertEquals(15, varargGetter(1, 2, 3, 4))
assertEquals(20, varargGetter(2, 2, 3, 4))
assertEquals(20, varargGetter(2, 2, 3, 4))
if (Platform.osFamily != OsFamily.WASM) {
assertFailsWith<IndexOutOfBoundsException> { varargGetter(3, 2, 3, 4) }
}
}
}
@Test fun testArrays() {
assertEquals("1, 2, 3", intArrayOf(1, 2, 3).joinToString())
assertEquals("4, 5, 6", longArrayOf(4.toLong(), 5.toLong(), 6.toLong()).joinToString())
assertEquals("7, 8, 9", shortArrayOf(7.toShort(), 8.toShort(), 9.toShort()).joinToString())
assertEquals("10, 11, 12", byteArrayOf(10.toByte(), 11.toByte(), 12.toByte()).joinToString())
assertEquals("abc", charArrayOf('a', 'b', 'c').joinToString(""))
assertEquals("1.5, 2.5, -3.5", floatArrayOf(1.5f, 2.5f, -3.5f).joinToString())
assertEquals("4.5, 5.5, -6.5", doubleArrayOf(4.5, 5.5, -6.5).joinToString())
assertEquals("13, 14, 4294967295", uintArrayOf(13u, 14u, 4294967295u).joinToString())
assertEquals("15, 16, 17", ulongArrayOf(15.toULong(), 16.toULong(), 17.toULong()).joinToString())
assertEquals("18, 19, 40000", ushortArrayOf(18.toUShort(), 19.toUShort(), 40000.toUShort()).joinToString())
assertEquals("20, 21, 200", ubyteArrayOf(20.toUByte(), 21.toUByte(), 200.toUByte()).joinToString())
assertEquals("abc, def, ghi", arrayOf("abc", "def", "ghi").joinToString())
assertEquals("1, 2, 3", arrayOf(1, 2, 3).joinToString())
assertEquals("4, 5, 6", arrayOf(4.toLong(), 5.toLong(), 6.toLong()).joinToString())
assertEquals("7, 8, 9", arrayOf(7.toShort(), 8.toShort(), 9.toShort()).joinToString())
assertEquals("10, 11, 12", arrayOf(10.toByte(), 11.toByte(), 12.toByte()).joinToString())
assertEquals("abc", arrayOf('a', 'b', 'c').joinToString(""))
assertEquals("1.5, 2.5, -3.5", arrayOf(1.5f, 2.5f, -3.5f).joinToString())
assertEquals("4.5, 5.5, -6.5", arrayOf(4.5, 5.5, -6.5).joinToString())
assertEquals("13, 14, 4294967295", arrayOf(13u, 14u, 4294967295u).joinToString())
assertEquals("15, 16, 17", arrayOf(15.toULong(), 16.toULong(), 17.toULong()).joinToString())
assertEquals("18, 19, 40000", arrayOf(18.toUShort(), 19.toUShort(), 40000.toUShort()).joinToString())
assertEquals("20, 21, 200", arrayOf(20.toUByte(), 21.toUByte(), 200.toUByte()).joinToString())
assertEquals("abc, 1, 2, 3, 4, a, 1.5, 2.5, 5, 6, 7, 8",
arrayOf("abc", 1, 2.toLong(), 3.toShort(), 4.toByte(), 'a', 1.5f, 2.5, 5u, 6.toULong(), 7.toUShort(), 8.toUByte()).joinToString())
}
@Test fun testList() {
assertEquals("abc, def, ghi", listOf("abc", "def", "ghi").joinToString())
assertEquals("1, 2, 3", listOf(1, 2, 3).joinToString())
assertEquals("4, 5, 6", listOf(4.toLong(), 5.toLong(), 6.toLong()).joinToString())
assertEquals("7, 8, 9", listOf(7.toShort(), 8.toShort(), 9.toShort()).joinToString())
assertEquals("10, 11, 12", listOf(10.toByte(), 11.toByte(), 12.toByte()).joinToString())
assertEquals("abc", listOf('a', 'b', 'c').joinToString(""))
assertEquals("1.5, 2.5, -3.5", listOf(1.5f, 2.5f, -3.5f).joinToString())
assertEquals("4.5, 5.5, -6.5", listOf(4.5, 5.5, -6.5).joinToString())
assertEquals("13, 14, 4294967295", listOf(13u, 14u, 4294967295u).joinToString())
assertEquals("15, 16, 17", listOf(15.toULong(), 16.toULong(), 17.toULong()).joinToString())
assertEquals("18, 19, 40000", listOf(18.toUShort(), 19.toUShort(), 40000.toUShort()).joinToString())
assertEquals("20, 21, 200", listOf(20.toUByte(), 21.toUByte(), 200.toUByte()).joinToString())
assertEquals("abc, 1, 2, 3, 4, a, 1.5, 2.5, 5, 6, 7, 8",
listOf("abc", 1, 2.toLong(), 3.toShort(), 4.toByte(), 'a', 1.5f, 2.5, 5u, 6.toULong(), 7.toUShort(), 8.toUByte()).joinToString())
}
@Test fun testKType() {
val ktype = typeOf<Map<in String?, out List<*>>?>()
assertTrue(ktype.isPermanent())
assertEquals("Map", (ktype.classifier as? KClass<*>)?.simpleName)
assertSame(Map::class, ktype.classifier)
assertTrue(ktype.isMarkedNullable)
assertTrue(ktype.arguments.isPermanent())
assertEquals(2, ktype.arguments.size)
assertSame(KVariance.IN, ktype.arguments[0].variance)
assertSame(KVariance.OUT, ktype.arguments[1].variance)
val arg0type = ktype.arguments[0].type!!
assertTrue(arg0type.isPermanent())
assertEquals("String", (arg0type.classifier as? KClass<*>)?.simpleName)
assertSame(String::class, arg0type.classifier)
assertTrue(arg0type.isMarkedNullable)
assertTrue(arg0type.arguments.isPermanent())
assertTrue(arg0type.arguments.isEmpty())
val arg1type = ktype.arguments[1].type!!
assertTrue(arg1type.isPermanent())
assertEquals("List", (arg1type.classifier as? KClass<*>)?.simpleName)
assertSame(List::class, arg1type.classifier)
assertFalse(arg1type.isMarkedNullable)
assertTrue(arg1type.arguments.isPermanent())
assertTrue(arg1type.arguments.size == 1)
assertSame(null, arg1type.arguments[0].variance)
assertSame(null, arg1type.arguments[0].type)
}
class R<T, U, V, X>
interface S
@Test fun testReifiedKType() {
inline fun <reified T, U, V> kTypeOf() where V : List<Int>, V : S, U : T = typeOf<R<T, in U, out V, *>>()
class XX(val x:List<Int>) : List<Int> by x, S
val type = kTypeOf<List<Int>, ArrayList<Int>, XX>()
assertEquals("codegen.initializers.static.R<kotlin.collections.List<kotlin.Int>, in U, out V, *>", type.toString())
assertEquals("[T]", (type.arguments[1].type!!.classifier as KTypeParameter).upperBounds.toString())
assertEquals("[kotlin.collections.List<kotlin.Int>, codegen.initializers.static.S]",
(type.arguments[2].type!!.classifier as KTypeParameter).upperBounds.toString())
}
inline fun invokeAndReturnKClass(block: ()->Boolean) : KClass<*> {
try {
if (block()) {
return Double::class
}
} catch (e: Exception) {
return String::class
} finally {
return Int::class
}
}
@Test fun testConstantObjectInFinally() {
for (i in 0..2) {
val clazz = invokeAndReturnKClass {
when (i) {
0 -> true
1 -> false
else -> TODO("test")
}
}
assertTrue(clazz.isPermanent())
assertEquals("kotlin.Int", clazz.qualifiedName)
}
}
@Test fun testSmallIntIdentity() {
val xBool = true
val xBoolStatic : Any = false
val xBoolDyanmic : Any = !xBool
assertSame(xBoolStatic, xBoolDyanmic)
val xByte = 1.toByte()
val xByteStatic : Any = 2.toByte()
val xByteDyanmic : Any = (xByte + xByte).toByte()
assertSame(xByteStatic, xByteDyanmic)
val xShort = 1.toShort()
val xShortStatic : Any = 2.toShort()
val xShortDyanmic : Any = (xShort + xShort).toShort()
assertSame(xShortStatic, xShortDyanmic)
val xInt = 1.toInt()
val xIntStatic : Any = 2.toInt()
val xIntDyanmic : Any = xInt + xInt
assertSame(xIntStatic, xIntDyanmic)
val xChar = 1.toChar()
val xCharStatic : Any = 2.toChar()
val xCharDyanmic : Any = (xChar.code + xChar.code).toChar()
assertSame(xCharStatic, xCharDyanmic)
val xLong = 1.toLong()
val xLongStatic = 2.toLong()
val xLongDyanmic = xLong + xLong
assertSame(xLongStatic, xLongDyanmic)
}
@@ -0,0 +1,38 @@
/*
* Copyright 2010-2021 JetBrains s.r.o. and Kotlin Programming Language contributors.
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/
import kotlin.test.*
fun box(): String {
assertEquals("1, 2, 3", intArrayOf(1, 2, 3).joinToString())
assertEquals("4, 5, 6", longArrayOf(4.toLong(), 5.toLong(), 6.toLong()).joinToString())
assertEquals("7, 8, 9", shortArrayOf(7.toShort(), 8.toShort(), 9.toShort()).joinToString())
assertEquals("10, 11, 12", byteArrayOf(10.toByte(), 11.toByte(), 12.toByte()).joinToString())
assertEquals("abc", charArrayOf('a', 'b', 'c').joinToString(""))
assertEquals("1.5, 2.5, -3.5", floatArrayOf(1.5f, 2.5f, -3.5f).joinToString())
assertEquals("4.5, 5.5, -6.5", doubleArrayOf(4.5, 5.5, -6.5).joinToString())
assertEquals("13, 14, 4294967295", uintArrayOf(13u, 14u, 4294967295u).joinToString())
assertEquals("15, 16, 17", ulongArrayOf(15.toULong(), 16.toULong(), 17.toULong()).joinToString())
assertEquals("18, 19, 40000", ushortArrayOf(18.toUShort(), 19.toUShort(), 40000.toUShort()).joinToString())
assertEquals("20, 21, 200", ubyteArrayOf(20.toUByte(), 21.toUByte(), 200.toUByte()).joinToString())
assertEquals("abc, def, ghi", arrayOf("abc", "def", "ghi").joinToString())
assertEquals("1, 2, 3", arrayOf(1, 2, 3).joinToString())
assertEquals("4, 5, 6", arrayOf(4.toLong(), 5.toLong(), 6.toLong()).joinToString())
assertEquals("7, 8, 9", arrayOf(7.toShort(), 8.toShort(), 9.toShort()).joinToString())
assertEquals("10, 11, 12", arrayOf(10.toByte(), 11.toByte(), 12.toByte()).joinToString())
assertEquals("abc", arrayOf('a', 'b', 'c').joinToString(""))
assertEquals("1.5, 2.5, -3.5", arrayOf(1.5f, 2.5f, -3.5f).joinToString())
assertEquals("4.5, 5.5, -6.5", arrayOf(4.5, 5.5, -6.5).joinToString())
assertEquals("13, 14, 4294967295", arrayOf(13u, 14u, 4294967295u).joinToString())
assertEquals("15, 16, 17", arrayOf(15.toULong(), 16.toULong(), 17.toULong()).joinToString())
assertEquals("18, 19, 40000", arrayOf(18.toUShort(), 19.toUShort(), 40000.toUShort()).joinToString())
assertEquals("20, 21, 200", arrayOf(20.toUByte(), 21.toUByte(), 200.toUByte()).joinToString())
assertEquals("abc, 1, 2, 3, 4, a, 1.5, 2.5, 5, 6, 7, 8",
arrayOf("abc", 1, 2.toLong(), 3.toShort(), 4.toByte(), 'a', 1.5f, 2.5, 5u, 6.toULong(), 7.toUShort(), 8.toUByte()).joinToString())
return "OK"
}
@@ -0,0 +1,36 @@
/*
* Copyright 2010-2021 JetBrains s.r.o. and Kotlin Programming Language contributors.
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/
import kotlin.test.*
import kotlin.native.internal.*
import kotlin.reflect.*
inline fun invokeAndReturnKClass(block: ()->Boolean) : KClass<*> {
try {
if (block()) {
return Double::class
}
} catch (e: Exception) {
return String::class
} finally {
return Int::class
}
}
fun box(): String {
for (i in 0..2) {
val clazz = invokeAndReturnKClass {
when (i) {
0 -> true
1 -> false
else -> TODO("test")
}
}
assertTrue(clazz.isPermanent())
assertEquals("kotlin.Int", clazz.qualifiedName)
}
return "OK"
}
@@ -0,0 +1,40 @@
/*
* Copyright 2010-2021 JetBrains s.r.o. and Kotlin Programming Language contributors.
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/
import kotlin.test.*
import kotlin.native.internal.*
import kotlin.reflect.*
fun box(): String {
val ktype = typeOf<Map<in String?, out List<*>>?>()
assertTrue(ktype.isPermanent())
assertEquals("Map", (ktype.classifier as? KClass<*>)?.simpleName)
assertSame(Map::class, ktype.classifier)
assertTrue(ktype.isMarkedNullable)
assertTrue(ktype.arguments.isPermanent())
assertEquals(2, ktype.arguments.size)
assertSame(KVariance.IN, ktype.arguments[0].variance)
assertSame(KVariance.OUT, ktype.arguments[1].variance)
val arg0type = ktype.arguments[0].type!!
assertTrue(arg0type.isPermanent())
assertEquals("String", (arg0type.classifier as? KClass<*>)?.simpleName)
assertSame(String::class, arg0type.classifier)
assertTrue(arg0type.isMarkedNullable)
assertTrue(arg0type.arguments.isPermanent())
assertTrue(arg0type.arguments.isEmpty())
val arg1type = ktype.arguments[1].type!!
assertTrue(arg1type.isPermanent())
assertEquals("List", (arg1type.classifier as? KClass<*>)?.simpleName)
assertSame(List::class, arg1type.classifier)
assertFalse(arg1type.isMarkedNullable)
assertTrue(arg1type.arguments.isPermanent())
assertTrue(arg1type.arguments.size == 1)
assertSame(null, arg1type.arguments[0].variance)
assertSame(null, arg1type.arguments[0].type)
return "OK"
}
@@ -0,0 +1,26 @@
/*
* Copyright 2010-2021 JetBrains s.r.o. and Kotlin Programming Language contributors.
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/
import kotlin.test.*
fun box(): String {
assertEquals("abc, def, ghi", listOf("abc", "def", "ghi").joinToString())
assertEquals("1, 2, 3", listOf(1, 2, 3).joinToString())
assertEquals("4, 5, 6", listOf(4.toLong(), 5.toLong(), 6.toLong()).joinToString())
assertEquals("7, 8, 9", listOf(7.toShort(), 8.toShort(), 9.toShort()).joinToString())
assertEquals("10, 11, 12", listOf(10.toByte(), 11.toByte(), 12.toByte()).joinToString())
assertEquals("abc", listOf('a', 'b', 'c').joinToString(""))
assertEquals("1.5, 2.5, -3.5", listOf(1.5f, 2.5f, -3.5f).joinToString())
assertEquals("4.5, 5.5, -6.5", listOf(4.5, 5.5, -6.5).joinToString())
assertEquals("13, 14, 4294967295", listOf(13u, 14u, 4294967295u).joinToString())
assertEquals("15, 16, 17", listOf(15.toULong(), 16.toULong(), 17.toULong()).joinToString())
assertEquals("18, 19, 40000", listOf(18.toUShort(), 19.toUShort(), 40000.toUShort()).joinToString())
assertEquals("20, 21, 200", listOf(20.toUByte(), 21.toUByte(), 200.toUByte()).joinToString())
assertEquals("abc, 1, 2, 3, 4, a, 1.5, 2.5, 5, 6, 7, 8",
listOf("abc", 1, 2.toLong(), 3.toShort(), 4.toByte(), 'a', 1.5f, 2.5, 5u, 6.toULong(), 7.toUShort(), 8.toUByte()).joinToString())
return "OK"
}
@@ -0,0 +1,38 @@
/*
* Copyright 2010-2021 JetBrains s.r.o. and Kotlin Programming Language contributors.
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/
import kotlin.test.*
import kotlin.native.internal.*
import kotlin.reflect.*
class Delegate {
operator fun getValue(thisRef: Any?, property: KProperty<*>) : String {
assertTrue(property.isPermanent());
assertTrue(property.returnType.isPermanent())
return property.name
}
}
class A {
val z by Delegate()
}
fun f() = 5
fun box(): String {
val x = typeOf<Map<String, Int>>()
assertTrue(x.isPermanent())
val a = A()
assertTrue(a.z.isPermanent())
assertEquals("z", a.z)
val t = ::f
assertTrue(t.isPermanent())
assertEquals(5, t())
val z = { 6 }
assertTrue(z.isPermanent())
assertEquals(6, z())
return "OK"
}
@@ -0,0 +1,24 @@
/*
* Copyright 2010-2021 JetBrains s.r.o. and Kotlin Programming Language contributors.
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/
import kotlin.test.*
import kotlin.reflect.*
class R<T, U, V, X>
interface S
fun box(): String {
inline fun <reified T, U, V> kTypeOf() where V : List<Int>, V : S, U : T = typeOf<R<T, in U, out V, *>>()
class XX(val x:List<Int>) : List<Int> by x, S
val type = kTypeOf<List<Int>, ArrayList<Int>, XX>()
assertEquals("R<kotlin.collections.List<kotlin.Int>, in U, out V, *>", type.toString())
assertEquals("[T]", (type.arguments[1].type!!.classifier as KTypeParameter).upperBounds.toString())
assertEquals("[kotlin.collections.List<kotlin.Int>, S]",
(type.arguments[2].type!!.classifier as KTypeParameter).upperBounds.toString())
return "OK"
}
@@ -0,0 +1,40 @@
/*
* Copyright 2010-2021 JetBrains s.r.o. and Kotlin Programming Language contributors.
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/
import kotlin.test.*
fun box(): String {
val xBool = true
val xBoolStatic : Any = false
val xBoolDyanmic : Any = !xBool
assertSame(xBoolStatic, xBoolDyanmic)
val xByte = 1.toByte()
val xByteStatic : Any = 2.toByte()
val xByteDyanmic : Any = (xByte + xByte).toByte()
assertSame(xByteStatic, xByteDyanmic)
val xShort = 1.toShort()
val xShortStatic : Any = 2.toShort()
val xShortDyanmic : Any = (xShort + xShort).toShort()
assertSame(xShortStatic, xShortDyanmic)
val xInt = 1.toInt()
val xIntStatic : Any = 2.toInt()
val xIntDyanmic : Any = xInt + xInt
assertSame(xIntStatic, xIntDyanmic)
val xChar = 1.toChar()
val xCharStatic : Any = 2.toChar()
val xCharDyanmic : Any = (xChar.code + xChar.code).toChar()
assertSame(xCharStatic, xCharDyanmic)
val xLong = 1.toLong()
val xLongStatic = 2.toLong()
val xLongDyanmic = xLong + xLong
assertSame(xLongStatic, xLongDyanmic)
return "OK"
}
@@ -0,0 +1,26 @@
/*
* Copyright 2010-2021 JetBrains s.r.o. and Kotlin Programming Language contributors.
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/
import kotlin.test.*
fun box(): String {
fun varargGetter(position:Int, vararg x: Int): Int {
x[position] *= 5;
return x[position]
}
repeat(3) {
assertEquals(10, varargGetter(0, 2, 3, 4))
assertEquals(10, varargGetter(0, 2, 3, 4))
assertEquals(15, varargGetter(1, 2, 3, 4))
assertEquals(15, varargGetter(1, 2, 3, 4))
assertEquals(20, varargGetter(2, 2, 3, 4))
assertEquals(20, varargGetter(2, 2, 3, 4))
// the following assert might fail on Kotlin/WASM
assertFailsWith<IndexOutOfBoundsException> { varargGetter(3, 2, 3, 4) }
}
return "OK"
}
@@ -13,6 +13,8 @@ fun baz1() { }
fun baz2() { }
// FILE: main.kt
import kotlin.test.*
fun bar(x: Int) = if (x == 0) error("") else x
fun foo(x: Int) {
@@ -22,7 +24,8 @@ fun foo(x: Int) {
} catch (t: Throwable) { }
}
fun main() {
fun box(): String {
foo(0)
println(x)
assertEquals(42, x)
return "OK"
}
@@ -1 +0,0 @@
42
@@ -13,17 +13,24 @@ fun baz1() { }
fun baz2() { }
// FILE: main.kt
import kotlin.test.*
fun bar(x: Int) = if (x == 0) error("") else x
val sb = StringBuilder()
fun foo(x: Int) {
try {
bar(x)
baz1()
} catch (t: Throwable) {
println(y)
sb.appendLine(y)
}
}
fun main() {
fun box(): String {
foo(0)
assertEquals("42\n", sb.toString())
return "OK"
}
@@ -1 +0,0 @@
42
+5 -2
View File
@@ -11,13 +11,16 @@ private fun getY() = 42
fun bar(x: Int) = x == 0
// FILE: main.kt
import kotlin.test.*
fun foo(x: Int) = when {
x > 0 -> 42
bar(x) -> 117
else -> -1
}
fun main() {
fun box(): String {
foo(123)
println(y)
assertEquals(42, y)
return "OK"
}
@@ -1 +0,0 @@
42
+5 -2
View File
@@ -11,11 +11,14 @@ private fun getY() = 42
fun bar(x: Int) = x == 0
// FILE: main.kt
import kotlin.test.*
fun foo(x: Int) {
if (x > 0) bar(x)
}
fun main() {
fun box(): String {
foo(-1)
println(y)
assertEquals(42, y)
return "OK"
}
@@ -1 +0,0 @@
42
@@ -11,6 +11,8 @@ private fun getY() = 42
fun bar(x: Int) = x == 0
// FILE: main.kt
import kotlin.test.*
fun foo(x: Int) {
var i = 0
while (i < x) {
@@ -19,7 +21,8 @@ fun foo(x: Int) {
}
}
fun main() {
fun box(): String {
foo(0)
println(y)
assertEquals(42, y)
return "OK"
}
@@ -1 +0,0 @@
42
@@ -11,6 +11,8 @@ private fun getY() = 42
fun bar(x: Int) = x == 0
// FILE: main.kt
import kotlin.test.*
fun foo(x: Int) {
var i = 0
do {
@@ -19,7 +21,8 @@ fun foo(x: Int) {
} while (bar(i))
}
fun main() {
fun box(): String {
foo(0)
println(y)
assertEquals(42, y)
return "OK"
}
@@ -1 +0,0 @@
42
@@ -11,6 +11,8 @@ private fun getY() = 42
fun bar(x: Int) = x == 0
// FILE: main.kt
import kotlin.test.*
fun foo(x: Int) {
var i = 0
do {
@@ -20,7 +22,8 @@ fun foo(x: Int) {
} while (i < x)
}
fun main() {
fun box(): String {
foo(0)
println(y)
assertEquals(42, y)
return "OK"
}
@@ -1 +0,0 @@
42
@@ -21,15 +21,25 @@ val z2 = Z(x.s.length)
// FILE: main.kt
@file:OptIn(ObsoleteWorkersApi::class)
import kotlin.native.concurrent.*
import kotlin.test.*
val sb = StringBuilder()
fun foo() {
val worker = Worker.start()
worker.execute(TransferMode.SAFE, { -> }, {
it -> println(z1.x)
it -> sb.appendLine(z1.x)
}).consume { }
}
fun main() {
fun box(): String {
foo()
println(z2.x)
sb.appendLine(z2.x)
assertEquals("""
42
3
""".trimIndent(), sb.toString())
return "OK"
}
@@ -1,2 +0,0 @@
42
3
@@ -14,11 +14,21 @@ val z = Z(42)
// FILE: main.kt
@file:OptIn(ObsoleteWorkersApi::class)
import kotlin.native.concurrent.*
import kotlin.test.*
fun main() {
println(z.x)
val sb = StringBuilder()
fun box(): String {
sb.appendLine(z.x)
val worker = Worker.start()
worker.execute(TransferMode.SAFE, { -> }, {
it -> println(z.x)
it -> sb.appendLine(z.x)
}).consume { }
assertEquals("""
42
42
""".trimIndent(), sb.toString())
return "OK"
}
@@ -1,2 +0,0 @@
42
42