[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,29 +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.*
enum class Game {
ROCK,
PAPER,
SCISSORS;
companion object {
fun foo() = ROCK
val bar = PAPER
val values2 = values()
val scissors = valueOf("SCISSORS")
}
}
fun box(): String {
if (Game.foo() != Game.ROCK) return "Fail 1"
if (Game.bar != Game.PAPER) return "Fail 2: ${Game.bar}"
if (Game.values().size != 3) return "Fail 3"
if (Game.valueOf("SCISSORS") != Game.SCISSORS) return "Fail 4"
if (Game.values2.size != 3) return "Fail 5"
if (Game.scissors != Game.SCISSORS) return "Fail 6"
return "OK"
}
@@ -1,26 +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.
*/
// !LANGUAGE: -ProhibitComparisonOfIncompatibleEnums
import kotlin.test.*
enum class EnumA {
A, B
}
enum class EnumB {
B
}
fun box(): String {
if (!(EnumA.A == EnumA.A))
return "FAIL: A must equal A"
if (EnumA.A == EnumA.B)
return "FAIL: A.A must not equal A.B"
if (EnumA.A == EnumB.B)
return "FAIL: A.A must not equal B.B"
return "OK"
}
@@ -1,27 +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.*
interface A {
fun foo(): String
}
enum class Zzz(val zzz: String, val x: Int) : A {
Z1("z1", 1),
Z2("z2", 2),
Z3("z3", 3);
override fun foo(): String{
return "('$zzz', $x)"
}
}
fun box(): String {
assertEquals("('z3', 3)", Zzz.Z3.foo())
val a: A = Zzz.Z3
assertEquals("('z3', 3)", a.foo())
return "OK"
}
@@ -1,31 +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.*
interface A {
fun f(): String
}
enum class Zzz: A {
Z1 {
override fun f() = "z1"
},
Z2 {
override fun f() = "z2"
};
override fun f() = ""
}
fun box(): String {
assertEquals("z1z2", Zzz.Z1.f() + Zzz.Z2.f())
val a1: A = Zzz.Z1
val a2: A = Zzz.Z2
assertEquals("z1z2", a1.f() + a2.f())
return "OK"
}
-106
View File
@@ -1,106 +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.*
public enum class Node(
public val external: Boolean,
public val dependsOn: Set<Node>,
public val required: Boolean
) {
A(
external = false,
dependsOn = emptySet(),
required = true
),
B(
external = false,
dependsOn = emptySet(),
required = true
),
C(
external = true,
dependsOn = emptySet(),
required = true
),
D(
external = true,
dependsOn = emptySet(),
required = true
),
E(
external = true,
dependsOn = emptySet(),
required = true
),
F(
external = true,
dependsOn = emptySet(),
required = true
),
G(
external = true,
dependsOn = emptySet(),
required = false
),
H(
external = true,
dependsOn = emptySet(),
required = true
),
I(
external = true,
dependsOn = emptySet(),
required = true
),
J(
external = true,
dependsOn = emptySet(),
required = true
),
K(
external = true,
dependsOn = setOf(I),
required = true
),
L(
external = true,
dependsOn = setOf(I),
required = true
),
M(
external = true,
dependsOn = setOf(I),
required = true
),
N(
external = true,
dependsOn = emptySet(),
required = true
),
O(
external = true,
dependsOn = emptySet(),
required = true
),
AG(
external = true,
dependsOn = emptySet(),
required = true
),
FIELD_REPORT(
external = true,
dependsOn = setOf(AG, O, J),
required = true
)
}
fun box(): String {
assertTrue(Node.FIELD_REPORT.dependsOn.contains(Node.AG))
assertTrue(Node.FIELD_REPORT.dependsOn.contains(Node.O))
assertTrue(Node.FIELD_REPORT.dependsOn.contains(Node.J))
return "OK"
}
@@ -1,17 +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.*
enum class Zzz(val value: String.() -> Int = {
length
}) {
Q()
}
fun box(): String {
assertEquals("Q", Zzz.Q.toString())
return "OK"
}
-27
View File
@@ -1,27 +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()
enum class Zzz {
Z {
init {
sb.appendLine(Z.name)
}
}
}
fun box(): String {
sb.appendLine(Zzz.Z)
assertEquals("""
Z
Z
""".trimIndent(), sb.toString())
return "OK"
}
@@ -1,23 +0,0 @@
// MODULE: lib
// FILE: lib.kt
package a
enum class A(val x: Int) {
Z1(42),
Z2(117),
Z3(-1)
}
// MODULE: main(lib)
// FILE: main.kt
import a.*
import kotlin.test.*
fun box(): String {
assertEquals(42, A.Z1.x)
assertEquals(117, A.valueOf("Z2").x)
assertEquals(-1, A.values()[2].x)
return "OK"
}
-18
View File
@@ -1,18 +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.*
enum class Foo {
A;
enum class Bar { C }
}
fun box(): String {
assertEquals("A", Foo.A.toString())
assertEquals("C", Foo.Bar.C.toString())
return "OK"
}
@@ -1,13 +0,0 @@
// MODULE: lib
// FILE: lib.kt
enum class Foo {
Z;
open fun bar() = "OK"
}
// MODULE: main(lib)
// FILE: main.kt
fun box() = Foo.Z.bar()
@@ -1,72 +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.*
// Regression test for https://github.com/JetBrains/kotlin-native/issues/1779
enum class Foo(val a: Int, val b: Int, val c: Int = 0) {
A(a = 1, b = 0),
B(b = 1, a = 0),
C(c = 1, b = 0, a = 0),
D(0, 0),
E(1, 1, 1)
}
interface Base<T> {
val value: T
}
enum class Bar(override val value: Foo) : Base<Foo> {
A(Foo.A),
B(Foo.B),
C(Foo.C),
D(Foo.D),
E(Foo.E)
}
fun box(): String {
assertEquals(Foo.A.a, 1)
assertEquals(Foo.A.b, 0)
assertEquals(Foo.A.c, 0)
assertEquals(Foo.B.a, 0)
assertEquals(Foo.B.b, 1)
assertEquals(Foo.B.c, 0)
assertEquals(Foo.C.a, 0)
assertEquals(Foo.C.b, 0)
assertEquals(Foo.C.c, 1)
assertEquals(Foo.D.a, 0)
assertEquals(Foo.D.b, 0)
assertEquals(Foo.D.c, 0)
assertEquals(Foo.E.a, 1)
assertEquals(Foo.E.b, 1)
assertEquals(Foo.E.c, 1)
assertEquals(Bar.A.value.a, 1)
assertEquals(Bar.A.value.b, 0)
assertEquals(Bar.A.value.c, 0)
assertEquals(Bar.B.value.a, 0)
assertEquals(Bar.B.value.b, 1)
assertEquals(Bar.B.value.c, 0)
assertEquals(Bar.C.value.a, 0)
assertEquals(Bar.C.value.b, 0)
assertEquals(Bar.C.value.c, 1)
assertEquals(Bar.D.value.a, 0)
assertEquals(Bar.D.value.b, 0)
assertEquals(Bar.D.value.c, 0)
assertEquals(Bar.E.value.a, 1)
assertEquals(Bar.E.value.b, 1)
assertEquals(Bar.E.value.c, 1)
return "OK"
}
@@ -1,103 +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.
*/
// !LANGUAGE:-ProhibitComparisonOfIncompatibleEnums
import kotlin.test.*
val sb = StringBuilder()
enum class EnumA {
A, B, C
}
enum class EnumB {
A, B
}
enum class E {
ONE, TWO, THREE
}
fun produceEntry() = EnumA.A
// Check that we fail on comparison of different enum types.
fun differentEnums() {
sb.appendLine(when (produceEntry()) {
EnumB.A -> "EnumB.A"
EnumA.A -> "EnumA.A"
EnumA.B -> "EnumA.B"
else -> "nah"
})
}
// Nullable subject shouldn't be lowered.
fun nullable() {
val x: EnumA? = null
when(x) {
EnumA.A -> sb.appendLine("fail")
else -> sb.appendLine("ok")
}
}
// Operator overloading won't trick us!
fun operatorOverloading() {
operator fun E.contains(other: E): Boolean = false
val y = E.ONE
when(y) {
in E.ONE -> sb.appendLine("Should not reach here")
else -> sb.appendLine("ok")
}
}
fun smoke1() {
when (produceEntry()) {
EnumA.B -> sb.appendLine("error")
EnumA.A -> sb.appendLine("ok")
EnumA.C -> sb.appendLine("error")
}
}
fun smoke2() {
when (produceEntry()) {
EnumA.B -> sb.appendLine("error")
else -> sb.appendLine("ok")
}
}
fun eA() = EnumA.A
fun eB() = EnumA.B
fun nestedWhen() {
sb.appendLine(when (eA()) {
EnumA.A, EnumA.C -> when (eB()) {
EnumA.B -> "ok"
else -> "nope"
}
else -> "nope"
})
}
fun box(): String {
differentEnums()
nullable()
operatorOverloading()
smoke1()
smoke2()
nestedWhen()
assertEquals("""
EnumA.A
ok
ok
ok
ok
ok
""".trimIndent(), sb.toString())
return "OK"
}
-18
View File
@@ -1,18 +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 TOP_LEVEL = 5
enum class MyEnum(value: Int) {
VALUE(TOP_LEVEL)
}
fun box(): String {
assertEquals("VALUE", MyEnum.VALUE.toString())
return "OK"
}
-17
View File
@@ -1,17 +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.*
enum class Zzz(val zzz: String, val x: Int) {
Z1("z1", 1),
Z2("z2", 2)
}
fun box(): String {
assertEquals("z12", Zzz.Z1.zzz + Zzz.Z2.x)
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.*
enum class Zzz(val zzz: String, val x: Int) {
Z1("z1", 1),
Z2("z2", 2),
Z3("z3", 3);
override fun toString(): String{
return "('$zzz', $x)"
}
}
fun box(): String {
assertEquals("('z3', 3)", Zzz.Z3.toString())
return "OK"
}
@@ -1,24 +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.*
enum class Zzz {
Z1 {
override fun f() = "z1"
},
Z2 {
override fun f() = "z2"
};
open fun f() = ""
}
fun box(): String {
assertEquals("z1z2", Zzz.Z1.f() + Zzz.Z2.f())
return "OK"
}
-23
View File
@@ -1,23 +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.*
enum class E {
E3,
E1,
E2
}
fun box(): String {
assertEquals("E1", E.valueOf("E1").toString())
assertEquals("E2", E.valueOf("E2").toString())
assertEquals("E3", E.valueOf("E3").toString())
assertEquals("E1", enumValueOf<E>("E1").toString())
assertEquals("E2", enumValueOf<E>("E2").toString())
assertEquals("E3", enumValueOf<E>("E3").toString())
return "OK"
}
-23
View File
@@ -1,23 +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.*
enum class E {
E3,
E1,
E2
}
fun box(): String {
assertEquals("E3", E.values()[0].toString())
assertEquals("E1", E.values()[1].toString())
assertEquals("E2", E.values()[2].toString())
assertEquals("E3", enumValues<E>()[0].toString())
assertEquals("E1", enumValues<E>()[1].toString())
assertEquals("E2", enumValues<E>()[2].toString())
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.*
enum class Piece(vararg val states: Int) {
I(3, 4, 5)
}
fun box(): String {
assertEquals(3, Piece.I.states[0])
return "OK"
}