[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,21 +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.*
class TestClass {
val x: Int
init {
x = 42
}
val y = x
}
fun box(): String {
assertEquals(42, TestClass().y)
return "OK"
}
@@ -1,21 +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.*
class TestClass {
val x: Int
val y = 42
init {
x = y
}
}
fun box(): String {
assertEquals(42, TestClass().x)
return "OK"
}
@@ -1,29 +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: lib.kt
var z = false
// FILE: lib2.kt
import kotlin.test.*
val x = foo()
private fun foo(): Int {
z = true
return 42
}
fun bar() = 117
// FILE: main.kt
import kotlin.test.*
fun box(): String {
bar()
assertTrue(z)
return "OK"
}
@@ -1,31 +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: lib.kt
var z = false
// FILE: lib2.kt
import kotlin.test.*
val x = foo()
private fun foo(): Int {
z = true
return 42
}
class C {
fun bar() = 117
}
// FILE: main.kt
import kotlin.test.*
fun box(): String {
C().bar()
assertFalse(z)
return "OK"
}
@@ -1,22 +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.
*/
// FILE: lib.kt
class X(val s: String)
val x = X("zzz")
// FILE: lib2.kt
class Z(val x: Int)
val z2 = Z(x.s.length)
// FILE: main.kt
import kotlin.test.*
fun box(): String {
assertEquals(3, z2.x)
return "OK"
}
@@ -1,25 +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.
*/
// MODULE: lib
// FILE: lib.kt
class X(val s: String)
val x = X("zzz")
// MODULE: lib2(lib)
// FILE: lib2.kt
class Z(val x: Int)
val z2 = Z(x.s.length)
// MODULE: main(lib2)
// FILE: main.kt
import kotlin.test.*
fun box(): String {
assertEquals(3, z2.x)
return "OK"
}
@@ -1,68 +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.*
val sb = StringBuilder()
class A {
init{
sb.appendLine ("A::init")
}
val a = 1
companion object :B(1) {
init {
sb.appendLine ("A::companion")
}
fun foo() {
sb.appendLine("A::companion::foo")
}
}
object AObj : B(){
init {
sb.appendLine("A::Obj")
}
fun foo() {
sb.appendLine("A::AObj::foo")
}
}
}
fun box(): String {
sb.appendLine("main")
A.foo()
A.foo()
A.AObj.foo()
A.AObj.foo()
assertEquals("""
main
B::constructor(1)
A::companion
A::companion::foo
A::companion::foo
B::constructor(0)
B::constructor()
A::Obj
A::AObj::foo
A::AObj::foo
""".trimIndent(), sb.toString())
return "OK"
}
open class B(val a:Int, val b:Int) {
constructor(a:Int):this (a, 0) {
sb.appendLine("B::constructor(" + a.toString()+ ")")
}
constructor():this(0) {
sb.appendLine("B::constructor()")
}
}
@@ -1,22 +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.*
val sb = StringBuilder()
class TestClass {
companion object {
init {
sb.append("OK")
}
}
}
fun box(): String {
val t1 = TestClass()
val t2 = TestClass()
return sb.toString()
}
@@ -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.*
val sb = StringBuilder()
class A(val msg: String) {
init {
sb.appendLine("init $msg")
}
override fun toString(): String = msg
}
val globalValue1 = 1
val globalValue2 = A("globalValue2")
val globalValue3 = A("globalValue3")
fun box(): String {
sb.appendLine(globalValue1.toString())
sb.appendLine(globalValue2.toString())
sb.appendLine(globalValue3.toString())
assertEquals("""
init globalValue2
init globalValue3
1
globalValue2
globalValue3
""".trimIndent(), sb.toString())
return "OK"
}
@@ -1,14 +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.*
class Foo(val bar: Int)
var x = Foo(42)
fun box(): String {
assertEquals(42, x.bar)
return "OK"
}
@@ -1,15 +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.*
const val INT_MAX_POWER_OF_TWO: Int = Int.MAX_VALUE / 2 + 1
val DOUBLE = Double.MAX_VALUE - 1.0
fun box(): String {
assertEquals(1073741824, INT_MAX_POWER_OF_TWO)
assertTrue(DOUBLE > 0.0)
return "OK"
}
@@ -1,16 +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.*
object A {
val a = 42
val b = A.a
}
fun box(): String {
assertEquals(42, A.b)
return "OK"
}
@@ -1,59 +0,0 @@
/*
* 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.*
object A {
init {
assertAUninitialized()
}
val a1 = 7
val a2 = 12
}
// Check that A is initialized dynamically.
fun assertAUninitialized() {
assertEquals(0, A.a1)
assertEquals(0, A.a2)
}
object B {
init {
assertBUninitialized()
}
val b1 = A.a2
val b2 = C.c1
}
// Check that B is initialized dynamically.
fun assertBUninitialized() {
assertEquals(0, B.b1)
assertEquals(0, B.b2)
}
object C {
init {
assertCUninitialized()
}
val c1 = 42
val c2 = A.a1
val c3 = B.b1
val c4 = B.b2
}
// Check that C is initialized dynamically.
fun assertCUninitialized() {
assertEquals(0, C.c1)
assertEquals(0, C.c2)
assertEquals(0, C.c3)
assertEquals(0, C.c4)
}
fun box(): String {
assertEquals(A.a1, C.c2)
assertEquals(A.a2, C.c3)
assertEquals(C.c1, C.c4)
return "OK"
}
@@ -1,11 +0,0 @@
/*
* Copyright 2010-2021 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.*
var globalString = "OK"
fun box(): String {
return globalString
}
@@ -1,16 +0,0 @@
// MODULE: lib
// FILE: lib.kt
val a = 10
val b = a * 6
val c = a * b * 2
// MODULE: main(lib)
// FILE: main.kt
import kotlin.test.*
fun box(): String {
assertEquals(1200, c)
return "OK"
}
@@ -1,32 +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: lib.kt
var z = false
// FILE: lib2.kt
val x = foo()
fun foo(): Int {
z = true
return 42
}
object Z {
fun bar() { }
fun baz() = x
}
// FILE: main.kt
import kotlin.test.*
fun box(): String {
Z.bar()
assertFalse(z)
assertEquals(42, Z.baz())
assertTrue(z)
return "OK"
}
@@ -1,21 +0,0 @@
// MODULE: lib
// FILE: lib.kt
class A {
val x: String
init {
var y = "FAIL"
fun foo() { y = "OK" }
foo()
x = y
}
}
// MODULE: main(lib)
// FILE: main.kt
fun box() = A().x
@@ -1,38 +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.
*/
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"
}
@@ -1,26 +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.
*/
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"
}
@@ -1,40 +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.
*/
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"
}
@@ -1,26 +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.
*/
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"
}
@@ -1,31 +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: lib.kt
val x = computeX()
private fun computeX() = 42
fun baz1() { }
fun baz2() { }
// FILE: main.kt
import kotlin.test.*
fun bar(x: Int) = if (x == 0) error("") else x
fun foo(x: Int) {
try {
bar(x)
baz1()
} catch (t: Throwable) { }
}
fun box(): String {
foo(0)
assertEquals(42, x)
return "OK"
}
@@ -1,36 +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: lib.kt
val y = computeY()
private fun computeY() = 42
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) {
sb.appendLine(y)
}
}
fun box(): String {
foo(0)
assertEquals("42\n", sb.toString())
return "OK"
}