[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
+59
View File
@@ -0,0 +1,59 @@
/*
* 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 <T> areSame(arg1: T, arg2: T): Boolean {
return arg1 === arg2
}
fun Boolean.oneIfTrueElseZero(): Int {
return if (this) 1 else 0
}
fun box(): String {
var acc = 0
val range = 1000
for (i in arrayOf(false, true)) {
for (j in arrayOf(false, true)) {
acc += areSame(i, j).oneIfTrueElseZero()
}
}
if (acc != 2) "FAIL 1: $acc"
acc = 0
for (i in Byte.MIN_VALUE..Byte.MAX_VALUE) {
acc += areSame(i, i).oneIfTrueElseZero()
}
if (acc != 256) "FAIL 2: $acc"
acc = 0
for (i in Short.MIN_VALUE..Short.MAX_VALUE) {
acc += areSame(i, i).oneIfTrueElseZero()
}
if (acc != 256) "FAIL 3: $acc"
acc = 0
for (i in 0.toChar()..range.toChar()) {
acc += areSame(i, i).oneIfTrueElseZero()
}
if (acc != 256) "FAIL 4: $acc"
acc = 0
for (i in -range..range) {
acc += areSame(i, i).oneIfTrueElseZero()
}
if (acc != 256) "FAIL 5: $acc"
acc = 0
for (i in -range.toLong()..range.toLong()) {
acc += areSame(i, i).oneIfTrueElseZero()
}
if (acc != 256) "FAIL 6: $acc"
return "OK"
}
+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.
*/
// WITH_STDLIB
import kotlin.test.*
class Box<T>(t: T) {
var value = t
}
fun box(): String {
val box: Box<Int> = Box<Int>(17)
if (box.value != 17) return "FAIL 1: ${box.value}"
val nonConst = 17
val box2: Box<Int> = Box<Int>(nonConst)
if (box2.value != 17) return "FAIL 1: ${box2.value}"
return "OK"
}
@@ -0,0 +1,9 @@
MODULE main
CLASS Boxing1Kt.class
PACKAGE METADATA
PROPERTY getSb()Ljava/lang/StringBuilder;
Property: class.metadata.property.returnType
K1
java/lang/StringBuilder /* = kotlin/text/StringBuilder^ */
K2
java/lang/StringBuilder
+42
View File
@@ -0,0 +1,42 @@
/*
* 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 foo(arg: Any) {
sb.appendLine(arg.toString())
}
fun box(): String {
foo(1)
foo(2u)
foo(false)
foo("Hello")
val nonConstInt = 1
val nonConstUInt = 2u
val nonConstBool = false
val nonConstString = "Hello"
foo(nonConstInt)
foo(nonConstUInt)
foo(nonConstBool)
foo(nonConstString)
assertEquals("""
1
2
false
Hello
1
2
false
Hello
""".trimIndent(), sb.toString())
return "OK"
}
+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.
*/
// WITH_STDLIB
import kotlin.test.*
fun box(): String {
val FALSE: Boolean? = false
if (FALSE != null) {
do {
return "OK"
} while (FALSE)
}
return "FAIL"
}
@@ -0,0 +1,9 @@
MODULE main
CLASS Boxing11Kt.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 printInt(x: Int) = sb.appendLine(x)
class Foo(val value: Int?) {
fun foo() {
printInt(if (value != null) value else 42)
}
}
fun box(): String {
Foo(17).foo()
Foo(null).foo()
assertEquals("17\n42\n", sb.toString())
return "OK"
}
@@ -0,0 +1,9 @@
MODULE main
CLASS Boxing12Kt.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 foo(x: Number) {
sb.appendLine(x.toByte())
}
fun box(): String {
foo(18)
val nonConst = 18
foo(nonConst)
assertEquals("18\n18\n", sb.toString())
return "OK"
}
@@ -0,0 +1,9 @@
MODULE main
CLASS Boxing13Kt.class
PACKAGE METADATA
PROPERTY getSb()Ljava/lang/StringBuilder;
Property: class.metadata.property.returnType
K1
java/lang/StringBuilder /* = kotlin/text/StringBuilder^ */
K2
java/lang/StringBuilder
+44
View File
@@ -0,0 +1,44 @@
/*
* 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 is42(x: Any?) {
sb.appendLine(x == 42)
sb.appendLine(42 == x)
}
fun box(): String {
is42(16)
is42(42)
is42("42")
val nonConst16 = 16
val nonConst42 = 42
val nonConst42String = "42"
is42(nonConst16)
is42(nonConst42)
is42(nonConst42String)
assertEquals("""
false
false
true
true
false
false
false
false
true
true
false
false
""".trimIndent(), sb.toString())
return "OK"
}
@@ -0,0 +1,9 @@
MODULE main
CLASS Boxing14Kt.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 {
42.println()
val nonConst = 42
nonConst.println()
assertEquals("42\n42\n", sb.toString())
return "OK"
}
fun <T> T.println() = sb.appendLine(this)
+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.
*/
// WITH_STDLIB
import kotlin.test.*
fun box(): String {
val res1 = foo(17)
if (res1 != 17) return "FAIL 1: $res1"
val nonConst = 17
val res2 = foo(nonConst)
if (res2 != 17) return "FAIL 2: $res2"
return "OK"
}
fun <T : Int> foo(x: T): Int = x
@@ -0,0 +1,9 @@
MODULE main
CLASS Boxing2Kt.class
PACKAGE METADATA
PROPERTY getSb()Ljava/lang/StringBuilder;
Property: class.metadata.property.returnType
K1
java/lang/StringBuilder /* = kotlin/text/StringBuilder^ */
K2
java/lang/StringBuilder
+53
View File
@@ -0,0 +1,53 @@
/*
* 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 printInt(x: Int) = sb.appendLine(x.toString())
fun printBoolean(x: Boolean) = sb.appendLine(x.toString())
fun printUInt(x: UInt) = sb.appendLine(x.toString())
fun foo(arg: Any) {
if (arg is Int)
printInt(arg)
else if (arg is Boolean)
printBoolean(arg)
else if (arg is UInt)
printUInt(arg)
else
sb.appendLine("other")
}
fun box(): String {
foo(1)
foo(2u)
foo(true)
foo("Hello")
val nonConstInt = 1
val nonConstUInt = 2u
val nonConstBool = true
val nonConstString = "Hello"
foo(nonConstInt)
foo(nonConstUInt)
foo(nonConstBool)
foo(nonConstString)
assertEquals("""
1
2
true
other
1
2
true
other
""".trimIndent(), sb.toString())
return "OK"
}
@@ -0,0 +1,9 @@
MODULE main
CLASS Boxing3Kt.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 printInt(x: Int) = sb.appendLine(x)
fun foo(arg: Int?) {
if (arg != null)
printInt(arg)
}
fun box(): String {
foo(42)
val nonConst = 42
foo(nonConst)
assertEquals("42\n42\n", sb.toString())
return "OK"
}
@@ -0,0 +1,9 @@
MODULE main
CLASS Boxing4Kt.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 printInt(x: Int) = sb.appendLine(x)
fun foo(arg: Any?) {
if (arg is Int? && arg != null)
printInt(arg)
}
fun box(): String {
foo(16)
val nonConst = 16
foo(nonConst)
assertEquals("16\n16\n", sb.toString())
return "OK"
}
@@ -0,0 +1,9 @@
MODULE main
CLASS Boxing5Kt.class
PACKAGE METADATA
PROPERTY getSb()Ljava/lang/StringBuilder;
Property: class.metadata.property.returnType
K1
java/lang/StringBuilder /* = kotlin/text/StringBuilder^ */
K2
java/lang/StringBuilder
+28
View File
@@ -0,0 +1,28 @@
/*
* 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 printInt(x: Int) = sb.appendLine(x)
fun foo(arg: Int?) {
printInt(arg ?: 16)
}
fun box(): String {
foo(null)
foo(42)
val nonConstNull = null
val nonConstInt = 42
foo(nonConstNull)
foo(nonConstInt)
assertEquals("16\n42\n16\n42\n", sb.toString())
return "OK"
}
@@ -0,0 +1,9 @@
MODULE main
CLASS Boxing6Kt.class
PACKAGE METADATA
PROPERTY getSb()Ljava/lang/StringBuilder;
Property: class.metadata.property.returnType
K1
java/lang/StringBuilder /* = kotlin/text/StringBuilder^ */
K2
java/lang/StringBuilder
+28
View File
@@ -0,0 +1,28 @@
/*
* 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 printInt(x: Int) = sb.appendLine(x)
fun foo(arg: Any) {
printInt(arg as? Int ?: 16)
}
fun box(): String {
foo(42)
foo("Hello")
val nonConstInt = 42
val nonConstString = "Hello"
foo(nonConstInt)
foo(nonConstString)
assertEquals("42\n16\n42\n16\n", sb.toString())
return "OK"
}
@@ -0,0 +1,9 @@
MODULE main
CLASS Boxing7Kt.class
PACKAGE METADATA
PROPERTY getSb()Ljava/lang/StringBuilder;
Property: class.metadata.property.returnType
K1
java/lang/StringBuilder /* = kotlin/text/StringBuilder^ */
K2
java/lang/StringBuilder
+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.
*/
// JVM_ABI_K1_K2_DIFF: KT-63864
// WITH_STDLIB
import kotlin.test.*
val sb = StringBuilder()
fun printInt(x: Int) = sb.appendLine(x)
fun foo(arg: Any) {
val argAsInt = try {
arg as Int
} catch (e: ClassCastException) {
0
}
printInt(argAsInt)
}
fun box(): String {
foo(1)
foo("Hello")
val nonConstInt = 1
val nonConstString = "Hello"
foo(nonConstInt)
foo(nonConstString)
assertEquals("1\n0\n1\n0\n", sb.toString())
return "OK"
}
@@ -0,0 +1,9 @@
MODULE main
CLASS Boxing8Kt.class
PACKAGE METADATA
PROPERTY getSb()Ljava/lang/StringBuilder;
Property: class.metadata.property.returnType
K1
java/lang/StringBuilder /* = kotlin/text/StringBuilder^ */
K2
java/lang/StringBuilder
+38
View File
@@ -0,0 +1,38 @@
/*
* 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 foo(vararg args: Any?) {
for (arg in args) {
sb.appendLine(arg.toString())
}
}
fun box(): String {
foo(1, null, true, "Hello")
val nonConstInt = 1
val nonConstNull = null
val nonConstBool = true
val nonConstString = "Hello"
foo(nonConstInt, nonConstNull, nonConstBool, nonConstString)
assertEquals("""
1
null
true
Hello
1
null
true
Hello
""".trimIndent(), sb.toString())
return "OK"
}
@@ -0,0 +1,9 @@
MODULE main
CLASS Boxing9Kt.class
PACKAGE METADATA
PROPERTY getSb()Ljava/lang/StringBuilder;
Property: class.metadata.property.returnType
K1
java/lang/StringBuilder /* = kotlin/text/StringBuilder^ */
K2
java/lang/StringBuilder
+38
View File
@@ -0,0 +1,38 @@
/*
* 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 foo(vararg args: Any?) {
for (arg in args) {
sb.appendLine(arg.toString())
}
}
fun bar(vararg args: Any?) {
foo(1, *args, 2, *args, 3)
}
fun box(): String {
bar(null, true, "Hello")
assertEquals("""
1
null
true
Hello
2
null
true
Hello
3
""".trimIndent(), sb.toString())
return "OK"
}
+30
View File
@@ -0,0 +1,30 @@
/*
* Copyright 2010-2022 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-54635: expected:<[OK]> but was:<[FAIL 1: 0]>
// IGNORE_BACKEND: JS_IR, JS_IR_ES6
// KT-66099: CompileError: WebAssembly.Module(): Compiling function #3415:"box" failed: Invalid types for ref.cast null: local.get of type f64 has to be in the same reference type hierarchy as (ref 686) @+237036
// IGNORE_BACKEND: WASM
// WITH_STDLIB
import kotlin.test.*
// Reproducer is copied from FloatingPointParser.unaryMinus()
inline fun <reified T> unaryMinus(value: T): T {
return when (value) {
is Float -> -value as T
is Double -> -value as T
else -> throw NumberFormatException()
}
}
fun box(): String {
val res1 = unaryMinus(0.0).toString()
if (res1 != "-0.0") return "FAIL 1: $res1"
val res2 = unaryMinus(0.0f).toString()
if (res2 != "-0.0") return "FAIL 2: $res2"
return "OK"
}