[K/N][Tests] Move codegen test sources cycles..innerClass
^KT-61259
This commit is contained in:
committed by
Space Team
parent
35d2be25b2
commit
71a834b778
@@ -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.
|
||||
*/
|
||||
|
||||
package codegen.enum.companionObject
|
||||
|
||||
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"
|
||||
}
|
||||
|
||||
@Test fun runTest() = println(box())
|
||||
@@ -0,0 +1 @@
|
||||
OK
|
||||
@@ -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.
|
||||
*/
|
||||
|
||||
package codegen.enum.interfaceCallNoEntryClass
|
||||
|
||||
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)"
|
||||
}
|
||||
}
|
||||
|
||||
@Test fun runTest() {
|
||||
println(Zzz.Z3.foo())
|
||||
val a: A = Zzz.Z3
|
||||
println(a.foo())
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
('z3', 3)
|
||||
('z3', 3)
|
||||
@@ -0,0 +1,31 @@
|
||||
/*
|
||||
* 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.enum.interfaceCallWithEntryClass
|
||||
|
||||
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() = ""
|
||||
}
|
||||
|
||||
@Test fun runTest() {
|
||||
println(Zzz.Z1.f() + Zzz.Z2.f())
|
||||
val a1: A = Zzz.Z1
|
||||
val a2: A = Zzz.Z2
|
||||
println(a1.f() + a2.f())
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
z1z2
|
||||
z1z2
|
||||
@@ -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.
|
||||
*/
|
||||
@file:OptIn(FreezingIsDeprecated::class, kotlin.experimental.ExperimentalNativeApi::class)
|
||||
package codegen.enum.isFrozen
|
||||
|
||||
import kotlin.test.*
|
||||
import kotlin.native.concurrent.*
|
||||
|
||||
enum class Zzz(val zzz: String, var value: Int = 0) {
|
||||
Z1("z1"),
|
||||
Z2("z2")
|
||||
}
|
||||
|
||||
@Test fun runTest() {
|
||||
if (Platform.memoryModel == MemoryModel.STRICT) {
|
||||
assertTrue(Zzz.Z1.isFrozen)
|
||||
assertFailsWith<InvalidMutabilityException> {
|
||||
Zzz.Z1.value = 42
|
||||
}
|
||||
assertEquals(0, Zzz.Z1.value)
|
||||
} else {
|
||||
assertFalse(Zzz.Z1.isFrozen)
|
||||
Zzz.Z1.value = 42
|
||||
assertEquals(42, Zzz.Z1.value)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,107 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
package codegen.enum.kt38540
|
||||
|
||||
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
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun runTest() {
|
||||
assertTrue(Node.FIELD_REPORT.dependsOn.contains(Node.AG))
|
||||
assertTrue(Node.FIELD_REPORT.dependsOn.contains(Node.O))
|
||||
assertTrue(Node.FIELD_REPORT.dependsOn.contains(Node.J))
|
||||
}
|
||||
@@ -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.
|
||||
*/
|
||||
|
||||
package codegen.enum.lambdaInDefault
|
||||
|
||||
import kotlin.test.*
|
||||
|
||||
enum class Zzz(val value: String.() -> Int = {
|
||||
length
|
||||
}) {
|
||||
Q()
|
||||
}
|
||||
|
||||
@Test fun runTest() {
|
||||
println(Zzz.Q)
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
Q
|
||||
@@ -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.
|
||||
*/
|
||||
|
||||
package codegen.enum.loop
|
||||
|
||||
import kotlin.test.*
|
||||
|
||||
enum class Zzz {
|
||||
Z {
|
||||
init {
|
||||
println(Z.name)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Test fun runTest() {
|
||||
println(Zzz.Z)
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
Z
|
||||
Z
|
||||
@@ -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.
|
||||
*/
|
||||
|
||||
package codegen.enum.nested
|
||||
|
||||
import kotlin.test.*
|
||||
|
||||
enum class Foo {
|
||||
A;
|
||||
enum class Bar { C }
|
||||
}
|
||||
|
||||
@Test fun runTest() {
|
||||
println(Foo.A)
|
||||
println(Foo.Bar.C)
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
A
|
||||
C
|
||||
@@ -0,0 +1,73 @@
|
||||
/*
|
||||
* 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.enum.reorderedArguments
|
||||
|
||||
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)
|
||||
}
|
||||
|
||||
@Test fun runTest() {
|
||||
|
||||
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)
|
||||
|
||||
}
|
||||
@@ -0,0 +1,91 @@
|
||||
/*
|
||||
* 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.enum.switchLowering
|
||||
|
||||
import kotlin.test.*
|
||||
|
||||
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() {
|
||||
println(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 -> println("fail")
|
||||
else -> println("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 -> println("Should not reach here")
|
||||
else -> println("ok")
|
||||
}
|
||||
}
|
||||
|
||||
fun smoke1() {
|
||||
when (produceEntry()) {
|
||||
EnumA.B -> println("error")
|
||||
EnumA.A -> println("ok")
|
||||
EnumA.C -> println("error")
|
||||
}
|
||||
}
|
||||
|
||||
fun smoke2() {
|
||||
when (produceEntry()) {
|
||||
EnumA.B -> println("error")
|
||||
else -> println("ok")
|
||||
}
|
||||
}
|
||||
|
||||
fun eA() = EnumA.A
|
||||
|
||||
fun eB() = EnumA.B
|
||||
|
||||
|
||||
fun nestedWhen() {
|
||||
println(when (eA()) {
|
||||
EnumA.A, EnumA.C -> when (eB()) {
|
||||
EnumA.B -> "ok"
|
||||
else -> "nope"
|
||||
}
|
||||
else -> "nope"
|
||||
})
|
||||
}
|
||||
|
||||
fun main() {
|
||||
differentEnums()
|
||||
nullable()
|
||||
operatorOverloading()
|
||||
smoke1()
|
||||
smoke2()
|
||||
nestedWhen()
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
EnumA.A
|
||||
ok
|
||||
ok
|
||||
ok
|
||||
ok
|
||||
ok
|
||||
@@ -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.
|
||||
*/
|
||||
|
||||
package codegen.enum.test0
|
||||
|
||||
import kotlin.test.*
|
||||
|
||||
val TOP_LEVEL = 5
|
||||
|
||||
enum class MyEnum(value: Int) {
|
||||
VALUE(TOP_LEVEL)
|
||||
}
|
||||
|
||||
@Test fun runTest() {
|
||||
println(MyEnum.VALUE.toString())
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
VALUE
|
||||
@@ -0,0 +1,17 @@
|
||||
/*
|
||||
* 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.enum.test1
|
||||
|
||||
import kotlin.test.*
|
||||
|
||||
enum class Zzz(val zzz: String, val x: Int) {
|
||||
Z1("z1", 1),
|
||||
Z2("z2", 2)
|
||||
}
|
||||
|
||||
@Test fun runTest() {
|
||||
println(Zzz.Z1.zzz + Zzz.Z2.x)
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
z12
|
||||
@@ -0,0 +1,22 @@
|
||||
/*
|
||||
* 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.enum.vCallNoEntryClass
|
||||
|
||||
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)"
|
||||
}
|
||||
}
|
||||
|
||||
@Test fun runTest() {
|
||||
println(Zzz.Z3.toString())
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
('z3', 3)
|
||||
@@ -0,0 +1,24 @@
|
||||
/*
|
||||
* 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.enum.vCallWithEntryClass
|
||||
|
||||
import kotlin.test.*
|
||||
|
||||
enum class Zzz {
|
||||
Z1 {
|
||||
override fun f() = "z1"
|
||||
},
|
||||
|
||||
Z2 {
|
||||
override fun f() = "z2"
|
||||
};
|
||||
|
||||
open fun f() = ""
|
||||
}
|
||||
|
||||
@Test fun runTest() {
|
||||
println(Zzz.Z1.f() + Zzz.Z2.f())
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
z1z2
|
||||
@@ -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.
|
||||
*/
|
||||
|
||||
package codegen.enum.valueOf
|
||||
|
||||
import kotlin.test.*
|
||||
|
||||
enum class E {
|
||||
E3,
|
||||
E1,
|
||||
E2
|
||||
}
|
||||
|
||||
@Test fun runTest() {
|
||||
println(E.valueOf("E1").toString())
|
||||
println(E.valueOf("E2").toString())
|
||||
println(E.valueOf("E3").toString())
|
||||
println(enumValueOf<E>("E1").toString())
|
||||
println(enumValueOf<E>("E2").toString())
|
||||
println(enumValueOf<E>("E3").toString())
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
E1
|
||||
E2
|
||||
E3
|
||||
E1
|
||||
E2
|
||||
E3
|
||||
@@ -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.
|
||||
*/
|
||||
|
||||
package codegen.enum.values
|
||||
|
||||
import kotlin.test.*
|
||||
|
||||
enum class E {
|
||||
E3,
|
||||
E1,
|
||||
E2
|
||||
}
|
||||
|
||||
@Test fun runTest() {
|
||||
println(E.values()[0].toString())
|
||||
println(E.values()[1].toString())
|
||||
println(E.values()[2].toString())
|
||||
println(enumValues<E>()[0].toString())
|
||||
println(enumValues<E>()[1].toString())
|
||||
println(enumValues<E>()[2].toString())
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
E3
|
||||
E1
|
||||
E2
|
||||
E3
|
||||
E1
|
||||
E2
|
||||
@@ -0,0 +1,16 @@
|
||||
/*
|
||||
* 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.enum.varargParam
|
||||
|
||||
import kotlin.test.*
|
||||
|
||||
enum class Piece(vararg val states: Int) {
|
||||
I(3, 4, 5)
|
||||
}
|
||||
|
||||
@Test fun runTest() {
|
||||
println(Piece.I.states[0])
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
3
|
||||
Reference in New Issue
Block a user