[K/N][Tests] Adjust moved codegen tests to new infra
^KT-61259
This commit is contained in:
committed by
Space Team
parent
71a834b778
commit
73032213f0
+5
-5
@@ -3,8 +3,6 @@
|
||||
* that can be found in the LICENSE file.
|
||||
*/
|
||||
|
||||
package codegen.cycles.cycle
|
||||
|
||||
import kotlin.test.*
|
||||
|
||||
fun cycle(cnt: Int): Int {
|
||||
@@ -15,7 +13,9 @@ fun cycle(cnt: Int): Int {
|
||||
return sum
|
||||
}
|
||||
|
||||
@Test fun runTest() {
|
||||
if (cycle(1) != 2) throw Error()
|
||||
if (cycle(0) != 1) throw Error()
|
||||
fun box(): String {
|
||||
assertEquals(2, cycle(1))
|
||||
assertEquals(1, cycle(0))
|
||||
|
||||
return "OK"
|
||||
}
|
||||
|
||||
+5
-5
@@ -3,8 +3,6 @@
|
||||
* that can be found in the LICENSE file.
|
||||
*/
|
||||
|
||||
package codegen.cycles.cycle_do
|
||||
|
||||
import kotlin.test.*
|
||||
|
||||
fun cycle_do(cnt: Int): Int {
|
||||
@@ -15,7 +13,9 @@ fun cycle_do(cnt: Int): Int {
|
||||
return sum
|
||||
}
|
||||
|
||||
@Test fun runTest() {
|
||||
if (cycle_do(3) != 5) throw Error()
|
||||
if (cycle_do(0) != 3) throw Error()
|
||||
fun box(): String {
|
||||
assertEquals(5, cycle_do(3))
|
||||
assertEquals(3, cycle_do(0))
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -3,8 +3,6 @@
|
||||
* that can be found in the LICENSE file.
|
||||
*/
|
||||
|
||||
package codegen.cycles.cycle_for
|
||||
|
||||
import kotlin.test.*
|
||||
|
||||
fun cycle_for(arr: Array<Int>) : Int {
|
||||
@@ -15,6 +13,8 @@ fun cycle_for(arr: Array<Int>) : Int {
|
||||
return sum
|
||||
}
|
||||
|
||||
@Test fun runTest() {
|
||||
if (cycle_for(Array(4, init = { it })) != 6) throw Error()
|
||||
fun box(): String {
|
||||
assertEquals(6, cycle_for(Array(4, init = { it })))
|
||||
|
||||
return "OK"
|
||||
}
|
||||
+3
-4
@@ -3,16 +3,15 @@
|
||||
* that can be found in the LICENSE file.
|
||||
*/
|
||||
|
||||
package codegen.dataflow.scope1
|
||||
|
||||
import kotlin.test.*
|
||||
|
||||
var b = true
|
||||
|
||||
@Test fun runTest() {
|
||||
fun box(): String {
|
||||
var x = 1
|
||||
if (b) {
|
||||
var x = 2
|
||||
}
|
||||
println(x)
|
||||
assertEquals(1, x)
|
||||
return "OK"
|
||||
}
|
||||
|
||||
@@ -1 +0,0 @@
|
||||
1
|
||||
@@ -3,8 +3,6 @@
|
||||
* that can be found in the LICENSE file.
|
||||
*/
|
||||
|
||||
package codegen.dataflow.uninitialized_val
|
||||
|
||||
import kotlin.test.*
|
||||
|
||||
fun foo(b: Boolean): Int {
|
||||
@@ -18,9 +16,11 @@ fun foo(b: Boolean): Int {
|
||||
return x
|
||||
}
|
||||
|
||||
@Test fun runTest() {
|
||||
fun box(): String {
|
||||
val uninitializedUnused: Int
|
||||
|
||||
println(foo(true))
|
||||
println(foo(false))
|
||||
assertEquals(1, foo(true))
|
||||
assertEquals(2, foo(false))
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -1,2 +0,0 @@
|
||||
1
|
||||
2
|
||||
@@ -3,16 +3,24 @@
|
||||
* that can be found in the LICENSE file.
|
||||
*/
|
||||
|
||||
package codegen.delegatedProperty.lazy
|
||||
|
||||
import kotlin.test.*
|
||||
|
||||
val sb = StringBuilder()
|
||||
|
||||
val lazyValue: String by lazy {
|
||||
println("computed!")
|
||||
sb.appendLine("computed!")
|
||||
"Hello"
|
||||
}
|
||||
|
||||
@Test fun runTest() {
|
||||
println(lazyValue)
|
||||
println(lazyValue)
|
||||
fun box(): String {
|
||||
sb.appendLine(lazyValue)
|
||||
sb.appendLine(lazyValue)
|
||||
|
||||
assertEquals("""
|
||||
computed!
|
||||
Hello
|
||||
Hello
|
||||
|
||||
""".trimIndent(), sb.toString())
|
||||
return "OK"
|
||||
}
|
||||
@@ -1,3 +0,0 @@
|
||||
computed!
|
||||
Hello
|
||||
Hello
|
||||
@@ -3,16 +3,15 @@
|
||||
* that can be found in the LICENSE file.
|
||||
*/
|
||||
|
||||
package codegen.delegatedProperty.local
|
||||
|
||||
import kotlin.test.*
|
||||
|
||||
import kotlin.reflect.KProperty
|
||||
|
||||
val sb = StringBuilder()
|
||||
|
||||
fun foo(): Int {
|
||||
class Delegate {
|
||||
operator fun getValue(receiver: Any?, p: KProperty<*>): Int {
|
||||
println(p.name)
|
||||
sb.appendLine(p.name)
|
||||
return 42
|
||||
}
|
||||
}
|
||||
@@ -22,6 +21,13 @@ fun foo(): Int {
|
||||
return x
|
||||
}
|
||||
|
||||
@Test fun runTest() {
|
||||
println(foo())
|
||||
fun box(): String {
|
||||
sb.appendLine(foo())
|
||||
|
||||
assertEquals("""
|
||||
x
|
||||
42
|
||||
|
||||
""".trimIndent(), sb.toString())
|
||||
return "OK"
|
||||
}
|
||||
@@ -1,2 +0,0 @@
|
||||
x
|
||||
42
|
||||
@@ -3,8 +3,6 @@
|
||||
* that can be found in the LICENSE file.
|
||||
*/
|
||||
|
||||
package codegen.delegatedProperty.map
|
||||
|
||||
import kotlin.test.*
|
||||
|
||||
class User(val map: Map<String, Any?>) {
|
||||
@@ -12,11 +10,13 @@ class User(val map: Map<String, Any?>) {
|
||||
val age: Int by map
|
||||
}
|
||||
|
||||
@Test fun runTest() {
|
||||
fun box(): String {
|
||||
val user = User(mapOf(
|
||||
"name" to "John Doe",
|
||||
"age" to 25
|
||||
))
|
||||
println(user.name) // Prints "John Doe"
|
||||
println(user.age) // Prints 25
|
||||
assertEquals("John Doe", user.name)
|
||||
assertEquals(25, user.age)
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -1,2 +0,0 @@
|
||||
John Doe
|
||||
25
|
||||
@@ -3,21 +3,28 @@
|
||||
* that can be found in the LICENSE file.
|
||||
*/
|
||||
|
||||
package codegen.delegatedProperty.observable
|
||||
|
||||
import kotlin.test.*
|
||||
|
||||
import kotlin.properties.Delegates
|
||||
|
||||
val sb = StringBuilder()
|
||||
|
||||
class User {
|
||||
var name: String by Delegates.observable("<no name>") {
|
||||
prop, old, new ->
|
||||
println("$old -> $new")
|
||||
sb.appendLine("$old -> $new")
|
||||
}
|
||||
}
|
||||
|
||||
@Test fun runTest() {
|
||||
fun box(): String {
|
||||
val user = User()
|
||||
user.name = "first"
|
||||
user.name = "second"
|
||||
|
||||
assertEquals("""
|
||||
<no name> -> first
|
||||
first -> second
|
||||
|
||||
""".trimIndent(), sb.toString())
|
||||
return "OK"
|
||||
}
|
||||
@@ -1,2 +0,0 @@
|
||||
<no name> -> first
|
||||
first -> second
|
||||
@@ -3,21 +3,28 @@
|
||||
* that can be found in the LICENSE file.
|
||||
*/
|
||||
|
||||
package codegen.delegatedProperty.packageLevel
|
||||
|
||||
import kotlin.test.*
|
||||
|
||||
import kotlin.reflect.KProperty
|
||||
|
||||
val sb = StringBuilder()
|
||||
|
||||
class Delegate {
|
||||
operator fun getValue(receiver: Any?, p: KProperty<*>): Int {
|
||||
println(p.name)
|
||||
sb.appendLine(p.name)
|
||||
return 42
|
||||
}
|
||||
}
|
||||
|
||||
val x: Int by Delegate()
|
||||
|
||||
@Test fun runTest() {
|
||||
println(x)
|
||||
fun box(): String {
|
||||
sb.appendLine(x)
|
||||
|
||||
assertEquals("""
|
||||
x
|
||||
42
|
||||
|
||||
""".trimIndent(), sb.toString())
|
||||
return "OK"
|
||||
}
|
||||
@@ -1,2 +0,0 @@
|
||||
x
|
||||
42
|
||||
@@ -3,15 +3,15 @@
|
||||
* that can be found in the LICENSE file.
|
||||
*/
|
||||
|
||||
package codegen.delegatedProperty.simpleVal
|
||||
|
||||
import kotlin.test.*
|
||||
|
||||
import kotlin.reflect.KProperty
|
||||
|
||||
val sb = StringBuilder()
|
||||
|
||||
class Delegate {
|
||||
operator fun getValue(receiver: Any?, p: KProperty<*>): Int {
|
||||
println(p.name)
|
||||
sb.appendLine(p.name)
|
||||
return 42
|
||||
}
|
||||
}
|
||||
@@ -20,6 +20,13 @@ class C {
|
||||
val x: Int by Delegate()
|
||||
}
|
||||
|
||||
@Test fun runTest() {
|
||||
println(C().x)
|
||||
fun box(): String {
|
||||
sb.appendLine(C().x)
|
||||
|
||||
assertEquals("""
|
||||
x
|
||||
42
|
||||
|
||||
""".trimIndent(), sb.toString())
|
||||
return "OK"
|
||||
}
|
||||
@@ -1,2 +0,0 @@
|
||||
x
|
||||
42
|
||||
@@ -3,22 +3,22 @@
|
||||
* that can be found in the LICENSE file.
|
||||
*/
|
||||
|
||||
package codegen.delegatedProperty.simpleVar
|
||||
|
||||
import kotlin.test.*
|
||||
|
||||
import kotlin.reflect.KProperty
|
||||
|
||||
val sb = StringBuilder()
|
||||
|
||||
class Delegate {
|
||||
var f: Int = 42
|
||||
|
||||
operator fun getValue(receiver: Any?, p: KProperty<*>): Int {
|
||||
println("get ${p.name}")
|
||||
sb.appendLine("get ${p.name}")
|
||||
return f
|
||||
}
|
||||
|
||||
operator fun setValue(receiver: Any?, p: KProperty<*>, value: Int) {
|
||||
println("set ${p.name}")
|
||||
sb.appendLine("set ${p.name}")
|
||||
f = value
|
||||
}
|
||||
}
|
||||
@@ -27,9 +27,19 @@ class C {
|
||||
var x: Int by Delegate()
|
||||
}
|
||||
|
||||
@Test fun runTest() {
|
||||
fun box(): String {
|
||||
val c = C()
|
||||
println(c.x)
|
||||
sb.appendLine(c.x)
|
||||
c.x = 117
|
||||
println(c.x)
|
||||
sb.appendLine(c.x)
|
||||
|
||||
assertEquals("""
|
||||
get x
|
||||
42
|
||||
set x
|
||||
get x
|
||||
117
|
||||
|
||||
""".trimIndent(), sb.toString())
|
||||
return "OK"
|
||||
}
|
||||
@@ -1,5 +0,0 @@
|
||||
get x
|
||||
42
|
||||
set x
|
||||
get x
|
||||
117
|
||||
@@ -3,13 +3,17 @@
|
||||
* that can be found in the LICENSE file.
|
||||
*/
|
||||
|
||||
import kotlin.test.*
|
||||
|
||||
val sb = StringBuilder()
|
||||
|
||||
interface I {
|
||||
fun foo()
|
||||
}
|
||||
|
||||
fun test() {
|
||||
val impl = object : I {
|
||||
override fun foo() { println("zzz") }
|
||||
override fun foo() { sb.append("zzz") }
|
||||
}
|
||||
|
||||
val delegating = object: I by impl { }
|
||||
@@ -17,6 +21,9 @@ fun test() {
|
||||
delegating.foo()
|
||||
}
|
||||
|
||||
fun main() {
|
||||
fun box(): String {
|
||||
test()
|
||||
assertEquals("zzz", sb.toString())
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -1 +0,0 @@
|
||||
zzz
|
||||
+3
-3
@@ -1,5 +1,5 @@
|
||||
class Foo(val box: String = "box")
|
||||
class Foo(val box: String = "OK")
|
||||
|
||||
fun main() {
|
||||
println(Foo().box)
|
||||
fun box(): String {
|
||||
return Foo().box
|
||||
}
|
||||
-1
@@ -1 +0,0 @@
|
||||
box
|
||||
@@ -1,3 +1,5 @@
|
||||
import kotlin.test.*
|
||||
|
||||
interface Base { val id: Int }
|
||||
|
||||
inline class Child(override val id: Int = 1) : Base
|
||||
@@ -5,9 +7,11 @@ inline class Child(override val id: Int = 1) : Base
|
||||
interface Base2 { val prop: Base }
|
||||
class Child2(override val prop: Child) : Base2
|
||||
|
||||
fun main() {
|
||||
fun box(): String {
|
||||
val x : Base = Child(5)
|
||||
println(x.id)
|
||||
assertEquals(5, x.id)
|
||||
val y : Base2 = Child2(Child(5))
|
||||
println(y.prop)
|
||||
assertEquals("Child(id=5)", y.prop.toString())
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -1,2 +0,0 @@
|
||||
5
|
||||
Child(id=5)
|
||||
@@ -1,3 +1,4 @@
|
||||
import kotlin.test.*
|
||||
interface I {
|
||||
fun foo(): Int
|
||||
}
|
||||
@@ -10,5 +11,10 @@ fun main(args: Array<String>) {
|
||||
lateinit var a: I
|
||||
if (args.size == 0)
|
||||
a = A()
|
||||
println(a.foo())
|
||||
}
|
||||
assertEquals(42, a.foo())
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
main(emptyArray())
|
||||
return "OK"
|
||||
}
|
||||
|
||||
@@ -1 +0,0 @@
|
||||
42
|
||||
@@ -3,8 +3,6 @@
|
||||
* that can be found in the LICENSE file.
|
||||
*/
|
||||
|
||||
package codegen.enum.companionObject
|
||||
|
||||
import kotlin.test.*
|
||||
|
||||
enum class Game {
|
||||
@@ -29,5 +27,3 @@ fun box(): String {
|
||||
if (Game.scissors != Game.SCISSORS) return "Fail 6"
|
||||
return "OK"
|
||||
}
|
||||
|
||||
@Test fun runTest() = println(box())
|
||||
@@ -1 +0,0 @@
|
||||
OK
|
||||
@@ -3,8 +3,6 @@
|
||||
* that can be found in the LICENSE file.
|
||||
*/
|
||||
|
||||
package codegen.enum.interfaceCallNoEntryClass
|
||||
|
||||
import kotlin.test.*
|
||||
|
||||
interface A {
|
||||
@@ -21,8 +19,9 @@ enum class Zzz(val zzz: String, val x: Int) : A {
|
||||
}
|
||||
}
|
||||
|
||||
@Test fun runTest() {
|
||||
println(Zzz.Z3.foo())
|
||||
fun box(): String {
|
||||
assertEquals("('z3', 3)", Zzz.Z3.foo())
|
||||
val a: A = Zzz.Z3
|
||||
println(a.foo())
|
||||
assertEquals("('z3', 3)", a.foo())
|
||||
return "OK"
|
||||
}
|
||||
@@ -1,2 +0,0 @@
|
||||
('z3', 3)
|
||||
('z3', 3)
|
||||
@@ -3,8 +3,6 @@
|
||||
* that can be found in the LICENSE file.
|
||||
*/
|
||||
|
||||
package codegen.enum.interfaceCallWithEntryClass
|
||||
|
||||
import kotlin.test.*
|
||||
|
||||
interface A {
|
||||
@@ -23,9 +21,11 @@ enum class Zzz: A {
|
||||
override fun f() = ""
|
||||
}
|
||||
|
||||
@Test fun runTest() {
|
||||
println(Zzz.Z1.f() + Zzz.Z2.f())
|
||||
fun box(): String {
|
||||
assertEquals("z1z2", Zzz.Z1.f() + Zzz.Z2.f())
|
||||
val a1: A = Zzz.Z1
|
||||
val a2: A = Zzz.Z2
|
||||
println(a1.f() + a2.f())
|
||||
assertEquals("z1z2", a1.f() + a2.f())
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -1,2 +0,0 @@
|
||||
z1z2
|
||||
z1z2
|
||||
+3
-2
@@ -3,7 +3,6 @@
|
||||
* 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.*
|
||||
@@ -13,7 +12,7 @@ enum class Zzz(val zzz: String, var value: Int = 0) {
|
||||
Z2("z2")
|
||||
}
|
||||
|
||||
@Test fun runTest() {
|
||||
fun box(): String {
|
||||
if (Platform.memoryModel == MemoryModel.STRICT) {
|
||||
assertTrue(Zzz.Z1.isFrozen)
|
||||
assertFailsWith<InvalidMutabilityException> {
|
||||
@@ -25,4 +24,6 @@ enum class Zzz(val zzz: String, var value: Int = 0) {
|
||||
Zzz.Z1.value = 42
|
||||
assertEquals(42, Zzz.Z1.value)
|
||||
}
|
||||
|
||||
return "OK"
|
||||
}
|
||||
|
||||
+3
-4
@@ -3,8 +3,6 @@
|
||||
* that can be found in the LICENSE file.
|
||||
*/
|
||||
|
||||
package codegen.enum.kt38540
|
||||
|
||||
import kotlin.test.*
|
||||
|
||||
public enum class Node(
|
||||
@@ -99,9 +97,10 @@ public enum class Node(
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun runTest() {
|
||||
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"
|
||||
}
|
||||
@@ -3,8 +3,6 @@
|
||||
* that can be found in the LICENSE file.
|
||||
*/
|
||||
|
||||
package codegen.enum.lambdaInDefault
|
||||
|
||||
import kotlin.test.*
|
||||
|
||||
enum class Zzz(val value: String.() -> Int = {
|
||||
@@ -13,6 +11,7 @@ enum class Zzz(val value: String.() -> Int = {
|
||||
Q()
|
||||
}
|
||||
|
||||
@Test fun runTest() {
|
||||
println(Zzz.Q)
|
||||
fun box(): String {
|
||||
assertEquals("Q", Zzz.Q.toString())
|
||||
return "OK"
|
||||
}
|
||||
@@ -1 +0,0 @@
|
||||
Q
|
||||
+12
-5
@@ -3,18 +3,25 @@
|
||||
* that can be found in the LICENSE file.
|
||||
*/
|
||||
|
||||
package codegen.enum.loop
|
||||
|
||||
import kotlin.test.*
|
||||
|
||||
val sb = StringBuilder()
|
||||
|
||||
|
||||
enum class Zzz {
|
||||
Z {
|
||||
init {
|
||||
println(Z.name)
|
||||
sb.appendLine(Z.name)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Test fun runTest() {
|
||||
println(Zzz.Z)
|
||||
fun box(): String {
|
||||
sb.appendLine(Zzz.Z)
|
||||
assertEquals("""
|
||||
Z
|
||||
Z
|
||||
|
||||
""".trimIndent(), sb.toString())
|
||||
return "OK"
|
||||
}
|
||||
@@ -1,2 +0,0 @@
|
||||
Z
|
||||
Z
|
||||
+5
-5
@@ -3,8 +3,6 @@
|
||||
* that can be found in the LICENSE file.
|
||||
*/
|
||||
|
||||
package codegen.enum.nested
|
||||
|
||||
import kotlin.test.*
|
||||
|
||||
enum class Foo {
|
||||
@@ -12,7 +10,9 @@ enum class Foo {
|
||||
enum class Bar { C }
|
||||
}
|
||||
|
||||
@Test fun runTest() {
|
||||
println(Foo.A)
|
||||
println(Foo.Bar.C)
|
||||
fun box(): String {
|
||||
assertEquals("A", Foo.A.toString())
|
||||
assertEquals("C", Foo.Bar.C.toString())
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -1,2 +0,0 @@
|
||||
A
|
||||
C
|
||||
@@ -3,8 +3,6 @@
|
||||
* 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
|
||||
@@ -28,7 +26,7 @@ enum class Bar(override val value: Foo) : Base<Foo> {
|
||||
E(Foo.E)
|
||||
}
|
||||
|
||||
@Test fun runTest() {
|
||||
fun box(): String {
|
||||
|
||||
assertEquals(Foo.A.a, 1)
|
||||
assertEquals(Foo.A.b, 0)
|
||||
@@ -70,4 +68,5 @@ enum class Bar(override val value: Foo) : Base<Foo> {
|
||||
assertEquals(Bar.E.value.b, 1)
|
||||
assertEquals(Bar.E.value.c, 1)
|
||||
|
||||
return "OK"
|
||||
}
|
||||
+26
-14
@@ -2,11 +2,12 @@
|
||||
* 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
|
||||
// !LANGUAGE:-ProhibitComparisonOfIncompatibleEnums
|
||||
|
||||
import kotlin.test.*
|
||||
|
||||
val sb = StringBuilder()
|
||||
|
||||
enum class EnumA {
|
||||
A, B, C
|
||||
}
|
||||
@@ -23,7 +24,7 @@ fun produceEntry() = EnumA.A
|
||||
|
||||
// Check that we fail on comparison of different enum types.
|
||||
fun differentEnums() {
|
||||
println(when (produceEntry()) {
|
||||
sb.appendLine(when (produceEntry()) {
|
||||
EnumB.A -> "EnumB.A"
|
||||
EnumA.A -> "EnumA.A"
|
||||
EnumA.B -> "EnumA.B"
|
||||
@@ -35,8 +36,8 @@ fun differentEnums() {
|
||||
fun nullable() {
|
||||
val x: EnumA? = null
|
||||
when(x) {
|
||||
EnumA.A -> println("fail")
|
||||
else -> println("ok")
|
||||
EnumA.A -> sb.appendLine("fail")
|
||||
else -> sb.appendLine("ok")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -46,23 +47,23 @@ fun operatorOverloading() {
|
||||
|
||||
val y = E.ONE
|
||||
when(y) {
|
||||
in E.ONE -> println("Should not reach here")
|
||||
else -> println("ok")
|
||||
in E.ONE -> sb.appendLine("Should not reach here")
|
||||
else -> sb.appendLine("ok")
|
||||
}
|
||||
}
|
||||
|
||||
fun smoke1() {
|
||||
when (produceEntry()) {
|
||||
EnumA.B -> println("error")
|
||||
EnumA.A -> println("ok")
|
||||
EnumA.C -> println("error")
|
||||
EnumA.B -> sb.appendLine("error")
|
||||
EnumA.A -> sb.appendLine("ok")
|
||||
EnumA.C -> sb.appendLine("error")
|
||||
}
|
||||
}
|
||||
|
||||
fun smoke2() {
|
||||
when (produceEntry()) {
|
||||
EnumA.B -> println("error")
|
||||
else -> println("ok")
|
||||
EnumA.B -> sb.appendLine("error")
|
||||
else -> sb.appendLine("ok")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -72,7 +73,7 @@ fun eB() = EnumA.B
|
||||
|
||||
|
||||
fun nestedWhen() {
|
||||
println(when (eA()) {
|
||||
sb.appendLine(when (eA()) {
|
||||
EnumA.A, EnumA.C -> when (eB()) {
|
||||
EnumA.B -> "ok"
|
||||
else -> "nope"
|
||||
@@ -81,11 +82,22 @@ fun nestedWhen() {
|
||||
})
|
||||
}
|
||||
|
||||
fun main() {
|
||||
fun box(): String {
|
||||
differentEnums()
|
||||
nullable()
|
||||
operatorOverloading()
|
||||
smoke1()
|
||||
smoke2()
|
||||
nestedWhen()
|
||||
|
||||
assertEquals("""
|
||||
EnumA.A
|
||||
ok
|
||||
ok
|
||||
ok
|
||||
ok
|
||||
ok
|
||||
|
||||
""".trimIndent(), sb.toString())
|
||||
return "OK"
|
||||
}
|
||||
@@ -1,6 +0,0 @@
|
||||
EnumA.A
|
||||
ok
|
||||
ok
|
||||
ok
|
||||
ok
|
||||
ok
|
||||
+4
-4
@@ -3,8 +3,6 @@
|
||||
* that can be found in the LICENSE file.
|
||||
*/
|
||||
|
||||
package codegen.enum.test0
|
||||
|
||||
import kotlin.test.*
|
||||
|
||||
val TOP_LEVEL = 5
|
||||
@@ -13,6 +11,8 @@ enum class MyEnum(value: Int) {
|
||||
VALUE(TOP_LEVEL)
|
||||
}
|
||||
|
||||
@Test fun runTest() {
|
||||
println(MyEnum.VALUE.toString())
|
||||
fun box(): String {
|
||||
assertEquals("VALUE", MyEnum.VALUE.toString())
|
||||
|
||||
return "OK"
|
||||
}
|
||||
|
||||
@@ -1 +0,0 @@
|
||||
VALUE
|
||||
+4
-4
@@ -3,8 +3,6 @@
|
||||
* that can be found in the LICENSE file.
|
||||
*/
|
||||
|
||||
package codegen.enum.test1
|
||||
|
||||
import kotlin.test.*
|
||||
|
||||
enum class Zzz(val zzz: String, val x: Int) {
|
||||
@@ -12,6 +10,8 @@ enum class Zzz(val zzz: String, val x: Int) {
|
||||
Z2("z2", 2)
|
||||
}
|
||||
|
||||
@Test fun runTest() {
|
||||
println(Zzz.Z1.zzz + Zzz.Z2.x)
|
||||
fun box(): String {
|
||||
assertEquals("z12", Zzz.Z1.zzz + Zzz.Z2.x)
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -1 +0,0 @@
|
||||
z12
|
||||
@@ -3,8 +3,6 @@
|
||||
* that can be found in the LICENSE file.
|
||||
*/
|
||||
|
||||
package codegen.enum.vCallNoEntryClass
|
||||
|
||||
import kotlin.test.*
|
||||
|
||||
enum class Zzz(val zzz: String, val x: Int) {
|
||||
@@ -17,6 +15,7 @@ enum class Zzz(val zzz: String, val x: Int) {
|
||||
}
|
||||
}
|
||||
|
||||
@Test fun runTest() {
|
||||
println(Zzz.Z3.toString())
|
||||
fun box(): String {
|
||||
assertEquals("('z3', 3)", Zzz.Z3.toString())
|
||||
return "OK"
|
||||
}
|
||||
@@ -1 +0,0 @@
|
||||
('z3', 3)
|
||||
@@ -3,8 +3,6 @@
|
||||
* that can be found in the LICENSE file.
|
||||
*/
|
||||
|
||||
package codegen.enum.vCallWithEntryClass
|
||||
|
||||
import kotlin.test.*
|
||||
|
||||
enum class Zzz {
|
||||
@@ -19,6 +17,8 @@ enum class Zzz {
|
||||
open fun f() = ""
|
||||
}
|
||||
|
||||
@Test fun runTest() {
|
||||
println(Zzz.Z1.f() + Zzz.Z2.f())
|
||||
fun box(): String {
|
||||
assertEquals("z1z2", Zzz.Z1.f() + Zzz.Z2.f())
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -1 +0,0 @@
|
||||
z1z2
|
||||
+9
-9
@@ -3,8 +3,6 @@
|
||||
* that can be found in the LICENSE file.
|
||||
*/
|
||||
|
||||
package codegen.enum.valueOf
|
||||
|
||||
import kotlin.test.*
|
||||
|
||||
enum class E {
|
||||
@@ -13,11 +11,13 @@ enum class E {
|
||||
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())
|
||||
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"
|
||||
}
|
||||
@@ -1,6 +0,0 @@
|
||||
E1
|
||||
E2
|
||||
E3
|
||||
E1
|
||||
E2
|
||||
E3
|
||||
+9
-9
@@ -3,8 +3,6 @@
|
||||
* that can be found in the LICENSE file.
|
||||
*/
|
||||
|
||||
package codegen.enum.values
|
||||
|
||||
import kotlin.test.*
|
||||
|
||||
enum class E {
|
||||
@@ -13,11 +11,13 @@ enum class E {
|
||||
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())
|
||||
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,6 +0,0 @@
|
||||
E3
|
||||
E1
|
||||
E2
|
||||
E3
|
||||
E1
|
||||
E2
|
||||
@@ -3,14 +3,13 @@
|
||||
* 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])
|
||||
fun box(): String {
|
||||
assertEquals(3, Piece.I.states[0])
|
||||
return "OK"
|
||||
}
|
||||
@@ -1 +0,0 @@
|
||||
3
|
||||
@@ -3,8 +3,6 @@
|
||||
* that can be found in the LICENSE file.
|
||||
*/
|
||||
|
||||
package codegen.escapeAnalysis.negativeArraySize
|
||||
|
||||
import kotlin.test.*
|
||||
|
||||
const val size = -42
|
||||
@@ -14,6 +12,8 @@ fun foo() {
|
||||
for (x in arr) println(x)
|
||||
}
|
||||
|
||||
@Test fun runTest() {
|
||||
fun box(): String {
|
||||
assertFailsWith<IllegalArgumentException> { foo() }
|
||||
|
||||
return "OK"
|
||||
}
|
||||
|
||||
@@ -3,8 +3,6 @@
|
||||
* that can be found in the LICENSE file.
|
||||
*/
|
||||
|
||||
package codegen.escapeAnalysis.recursion
|
||||
|
||||
import kotlin.test.*
|
||||
|
||||
class A {
|
||||
@@ -19,6 +17,8 @@ fun foo(k: Int, a1: A, a2: A): A {
|
||||
return foo(k - 1, a2, a3)
|
||||
}
|
||||
|
||||
@Test fun runTest() {
|
||||
fun box(): String {
|
||||
foo(3, A(), A()).toString()
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -2,8 +2,8 @@
|
||||
* 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.escapeAnalysis.stackAllocated
|
||||
// IGNORE_NATIVE: optimizationMode=DEBUG
|
||||
// IGNORE_NATIVE: optimizationMode=NO
|
||||
|
||||
import kotlin.test.*
|
||||
import kotlin.native.internal.*
|
||||
@@ -18,6 +18,8 @@ fun f(x: Int): Int {
|
||||
return a.f(x)
|
||||
}
|
||||
|
||||
@Test fun runTest() {
|
||||
fun box(): String {
|
||||
assertEquals(f(42), 55)
|
||||
|
||||
return "OK"
|
||||
}
|
||||
|
||||
+5
-3
@@ -2,13 +2,15 @@
|
||||
* 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.escapeAnalysis.string
|
||||
// IGNORE_NATIVE: optimizationMode=DEBUG
|
||||
// IGNORE_NATIVE: optimizationMode=NO
|
||||
|
||||
import kotlin.test.*
|
||||
import kotlin.native.internal.*
|
||||
|
||||
@Test fun runTest() {
|
||||
fun box(): String {
|
||||
val s = String()
|
||||
assertTrue(s.isLocal())
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
/*
|
||||
* Copyright 2010-2023 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.
|
||||
*/
|
||||
// IGNORE_NATIVE: optimizationMode=OPT
|
||||
|
||||
import kotlin.test.*
|
||||
import kotlin.native.internal.*
|
||||
|
||||
class A {
|
||||
fun f(x: Int) = x + 13
|
||||
}
|
||||
|
||||
fun f(x: Int): Int {
|
||||
val a = A()
|
||||
assertFalse(a.isLocal())
|
||||
return a.f(x)
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
assertEquals(f(42), 55)
|
||||
return "OK"
|
||||
}
|
||||
+15
@@ -0,0 +1,15 @@
|
||||
/*
|
||||
* Copyright 2010-2023 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.
|
||||
*/
|
||||
// IGNORE_NATIVE: optimizationMode=OPT
|
||||
|
||||
import kotlin.test.*
|
||||
import kotlin.native.internal.*
|
||||
|
||||
fun box(): String {
|
||||
val s = String()
|
||||
assertFalse(s.isLocal())
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -3,15 +3,15 @@
|
||||
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||
*/
|
||||
|
||||
package codegen.escapeAnalysis.stack_array
|
||||
|
||||
import kotlin.test.*
|
||||
|
||||
@Test fun runTest() {
|
||||
fun box(): String {
|
||||
val array = IntArray(2)
|
||||
array[0] = 1
|
||||
array[1] = 2
|
||||
val check = array is IntArray
|
||||
println(check)
|
||||
println(array[0] + array[1])
|
||||
assertTrue(check)
|
||||
assertEquals(3, array[0] + array[1])
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -1,2 +0,0 @@
|
||||
true
|
||||
3
|
||||
@@ -2,8 +2,7 @@
|
||||
* 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.
|
||||
*/
|
||||
|
||||
package codegen.escapeAnalysis.test1
|
||||
// TODO: check mentioned debug output of escape analyser
|
||||
|
||||
class A(val s: String)
|
||||
|
||||
@@ -17,4 +16,4 @@ class A(val s: String)
|
||||
// Escapes:
|
||||
fun foo(a: A) = a
|
||||
|
||||
fun main() = println(foo(A("zzz")))
|
||||
fun box(): String = foo(A("OK")).s
|
||||
@@ -2,8 +2,8 @@
|
||||
* 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.
|
||||
*/
|
||||
|
||||
package codegen.escapeAnalysis.test10
|
||||
// TODO: check mentioned debug output of escape analyser
|
||||
import kotlin.test.*
|
||||
|
||||
class G(val x: Int)
|
||||
|
||||
@@ -38,4 +38,7 @@ fun bar(): F {
|
||||
return u
|
||||
}
|
||||
|
||||
fun main() = println(bar().g.x)
|
||||
fun box(): String {
|
||||
assertEquals(42, bar().g.x)
|
||||
return "OK"
|
||||
}
|
||||
@@ -2,8 +2,8 @@
|
||||
* 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.
|
||||
*/
|
||||
|
||||
package codegen.escapeAnalysis.test11
|
||||
// TODO: check mentioned debug output of escape analyser
|
||||
import kotlin.test.*
|
||||
|
||||
class F(val x: Int)
|
||||
|
||||
@@ -28,4 +28,7 @@ fun foo(a: A): F {
|
||||
return a.f
|
||||
}
|
||||
|
||||
fun main() = println(foo(A("zzz")))
|
||||
fun box(): String {
|
||||
assertEquals(0, foo(A("zzz")).x)
|
||||
return "OK"
|
||||
}
|
||||
|
||||
@@ -2,8 +2,7 @@
|
||||
* 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.
|
||||
*/
|
||||
|
||||
package codegen.escapeAnalysis.test12
|
||||
// TODO: check mentioned debug output of escape analyser
|
||||
|
||||
class A(val s: String)
|
||||
|
||||
@@ -17,4 +16,4 @@ class A(val s: String)
|
||||
// Escapes:
|
||||
fun foo(arr: Array<A>) = arr[0]
|
||||
|
||||
fun main() = println(foo(arrayOf(A("zzz"))).s)
|
||||
fun box(): String = foo(arrayOf(A("OK"))).s
|
||||
@@ -2,8 +2,7 @@
|
||||
* 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.
|
||||
*/
|
||||
|
||||
package codegen.escapeAnalysis.test13
|
||||
import kotlin.test.*
|
||||
|
||||
class A {
|
||||
var f: A? = null
|
||||
@@ -13,8 +12,10 @@ fun foo(a: A, k: Int): A {
|
||||
return if (k == 0) a else foo(a.f!!, k - 1)
|
||||
}
|
||||
|
||||
fun main() {
|
||||
fun box(): String {
|
||||
val a = A()
|
||||
a.f = A()
|
||||
println(foo(a, 1))
|
||||
val a2 = A()
|
||||
a.f = a2
|
||||
assertEquals(a2, foo(a, 1))
|
||||
return "OK"
|
||||
}
|
||||
@@ -2,8 +2,7 @@
|
||||
* 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.
|
||||
*/
|
||||
|
||||
package codegen.escapeAnalysis.test2
|
||||
// TODO: check mentioned debug output of escape analyser
|
||||
|
||||
class A(val s: String)
|
||||
|
||||
@@ -17,4 +16,4 @@ class A(val s: String)
|
||||
// Escapes:
|
||||
fun foo(a: A) = a.s
|
||||
|
||||
fun main() = println(foo(A("zzz")))
|
||||
fun box(): String = foo(A("OK"))
|
||||
@@ -2,8 +2,7 @@
|
||||
* 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.
|
||||
*/
|
||||
|
||||
package codegen.escapeAnalysis.test3
|
||||
// TODO: check mentioned debug output of escape analyser
|
||||
|
||||
class A(val s: String)
|
||||
class B {
|
||||
@@ -25,4 +24,4 @@ fun foo(a: A, b: B): String {
|
||||
return a.s
|
||||
}
|
||||
|
||||
fun main() = println(foo(A("zzz"), B()))
|
||||
fun box(): String = foo(A("OK"), B())
|
||||
@@ -2,8 +2,7 @@
|
||||
* 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.
|
||||
*/
|
||||
|
||||
package codegen.escapeAnalysis.test4
|
||||
// TODO: check mentioned debug output of escape analyser
|
||||
|
||||
class A(val s: String)
|
||||
class B {
|
||||
@@ -27,4 +26,7 @@ fun foo(c1: C, c2: C) {
|
||||
c1.g.f = c2.g.f
|
||||
}
|
||||
|
||||
fun main() = println(foo(C(), C()))
|
||||
fun box(): String {
|
||||
foo(C(), C())
|
||||
return "OK"
|
||||
}
|
||||
|
||||
@@ -2,12 +2,11 @@
|
||||
* 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.
|
||||
*/
|
||||
|
||||
package codegen.escapeAnalysis.test5
|
||||
// TODO: check mentioned debug output of escape analyser
|
||||
|
||||
class A(val s: String)
|
||||
class B {
|
||||
var f: A = A("qzz")
|
||||
var f: A = A("OK")
|
||||
}
|
||||
class C {
|
||||
var g: B = B()
|
||||
@@ -32,4 +31,4 @@ fun foo(c1: C, c2: C): B {
|
||||
return b
|
||||
}
|
||||
|
||||
fun main() = println(foo(C(), C()))
|
||||
fun box(): String = foo(C(), C()).f.s
|
||||
@@ -2,8 +2,7 @@
|
||||
* 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.
|
||||
*/
|
||||
|
||||
package codegen.escapeAnalysis.test6
|
||||
// TODO: check mentioned debug output of escape analyser
|
||||
|
||||
class A(val s: String)
|
||||
class B {
|
||||
@@ -37,4 +36,4 @@ fun foo(z: Boolean, c1: C, c2: C, a: A): B {
|
||||
return v
|
||||
}
|
||||
|
||||
fun main() = println(foo(true, C(), C(), A("zzz")))
|
||||
fun box(): String = foo(true, C(), C(), A("OK")).f.s
|
||||
@@ -2,9 +2,9 @@
|
||||
* 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.
|
||||
*/
|
||||
// TODO: check mentioned debug output of escape analyser
|
||||
|
||||
package codegen.escapeAnalysis.test7
|
||||
|
||||
// Note: intentional infinite mutual recursion with `A(String)` and `C()`. Don't try to execute the code.
|
||||
class A(val s: String) {
|
||||
var h: String = ""
|
||||
var p: C = C()
|
||||
@@ -49,4 +49,8 @@ fun foo(z: Boolean, c: C, b: B, s: String, d: D) {
|
||||
u.p = c
|
||||
}
|
||||
|
||||
fun main() = println(foo(true, C(), B(), "zzz", D()))
|
||||
fun box(): String {
|
||||
// When uncommented, execution of the following line would fall into infinite recursion
|
||||
// foo(true, C(), B(), "zzz", D())
|
||||
return "OK"
|
||||
}
|
||||
|
||||
@@ -2,11 +2,11 @@
|
||||
* 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.
|
||||
*/
|
||||
// TODO: check mentioned debug output of escape analyser
|
||||
|
||||
package codegen.escapeAnalysis.test8
|
||||
|
||||
// Note: intentional infinite recursion for F(String). Don't try to execute the code.
|
||||
class F(val s: String) {
|
||||
var g = F("")
|
||||
var g = F("OK")
|
||||
}
|
||||
|
||||
class A {
|
||||
@@ -40,4 +40,8 @@ fun foo(a: A): F {
|
||||
return a.f.g.g
|
||||
}
|
||||
|
||||
fun main() = println(foo(A()).s)
|
||||
fun box(): String {
|
||||
// When uncommented, execution of the following line would fall into infinite recursion
|
||||
// foo(A()).s
|
||||
return "OK"
|
||||
}
|
||||
@@ -2,11 +2,12 @@
|
||||
* 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.
|
||||
*/
|
||||
|
||||
package codegen.escapeAnalysis.test9
|
||||
// TODO: check mentioned debug output of escape analyser
|
||||
import kotlin.test.*
|
||||
|
||||
class H(val x: Int)
|
||||
|
||||
// Note: intentional infinite recursion for F(String). Don't try to execute the code.
|
||||
class F(val s: String) {
|
||||
var g = F("")
|
||||
var h = H(0)
|
||||
@@ -33,4 +34,8 @@ fun foo(a: A, f: F): H {
|
||||
return f.g.h
|
||||
}
|
||||
|
||||
fun main() = println(foo(A(), F("zzz")).x)
|
||||
fun box(): String {
|
||||
// When uncommented, execution of the following line would fall into infinite recursion
|
||||
// assertEquals(0, foo(A(), F("zzz")).x)
|
||||
return "OK"
|
||||
}
|
||||
+3
-3
@@ -3,15 +3,13 @@
|
||||
* that can be found in the LICENSE file.
|
||||
*/
|
||||
|
||||
package codegen.escapeAnalysis.zeroOutObjectOnAlloc
|
||||
|
||||
import kotlin.test.*
|
||||
|
||||
class A {
|
||||
var x = 0
|
||||
}
|
||||
|
||||
@Test fun runTest() {
|
||||
fun box(): String {
|
||||
var sum1 = 0
|
||||
var sum2 = 0
|
||||
for (i in 0 until 10) {
|
||||
@@ -22,4 +20,6 @@ class A {
|
||||
}
|
||||
assertEquals(0, sum1)
|
||||
assertEquals(45, sum2)
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -3,8 +3,6 @@
|
||||
* that can be found in the LICENSE file.
|
||||
*/
|
||||
|
||||
package codegen.funInterface.implIsNotFunction
|
||||
|
||||
import kotlin.test.*
|
||||
|
||||
fun interface Foo {
|
||||
@@ -13,7 +11,7 @@ fun interface Foo {
|
||||
|
||||
fun foo(f: Foo) = f is Function<*>
|
||||
|
||||
@Test
|
||||
fun test() {
|
||||
fun box(): String {
|
||||
assertFalse(foo { "zzz" })
|
||||
return "OK"
|
||||
}
|
||||
@@ -3,7 +3,6 @@
|
||||
* that can be found in the LICENSE file.
|
||||
*/
|
||||
@file:OptIn(kotlinx.cinterop.ExperimentalForeignApi::class)
|
||||
package codegen.funInterface.kt43887
|
||||
|
||||
import kotlin.test.*
|
||||
|
||||
@@ -27,12 +26,14 @@ inline fun CPointer<heap_t>?.free(ptr: CPointer<*>?): Boolean {
|
||||
return heap_free(this, ptr)?.pointed?.value ?: false
|
||||
}
|
||||
|
||||
@Test
|
||||
fun runTest(): Unit = memScoped {
|
||||
fun box(): String {
|
||||
memScoped {
|
||||
val heap = Heap(1024)
|
||||
|
||||
heap.use<IntVar> { ptr ->
|
||||
ptr.pointed.value = 40
|
||||
//println("PTR ${ptr.pointed}")
|
||||
}
|
||||
}
|
||||
return "OK"
|
||||
}
|
||||
|
||||
@@ -3,8 +3,6 @@
|
||||
* that can be found in the LICENSE file.
|
||||
*/
|
||||
|
||||
package codegen.funInterface.kt49384
|
||||
|
||||
import kotlin.test.*
|
||||
|
||||
interface A<T>
|
||||
@@ -17,20 +15,9 @@ class B<T> {
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun test1() {
|
||||
fun box(): String {
|
||||
val b = B<Any>()
|
||||
assertEquals(b, b) // Just to ensure B is not deleted by DCE
|
||||
}
|
||||
|
||||
fun interface Foo<T> {
|
||||
fun same(obj: T): T
|
||||
}
|
||||
|
||||
fun getSame(obj: A<out Any>, foo: Foo<A<out Any>>) = foo.same(obj)
|
||||
|
||||
@Test
|
||||
fun test2() {
|
||||
val obj = object : A<Any> {}
|
||||
assertSame(obj, getSame(obj) { it })
|
||||
return "OK"
|
||||
}
|
||||
|
||||
@@ -0,0 +1,22 @@
|
||||
/*
|
||||
* 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.*
|
||||
|
||||
interface A<T>
|
||||
|
||||
// https://youtrack.jetbrains.com/issue/KT-49384
|
||||
fun interface Foo<T> {
|
||||
fun same(obj: T): T
|
||||
}
|
||||
|
||||
fun getSame(obj: A<out Any>, foo: Foo<A<out Any>>) = foo.same(obj)
|
||||
|
||||
fun box(): String {
|
||||
val obj = object : A<Any> {}
|
||||
assertSame(obj, getSame(obj) { it })
|
||||
|
||||
return "OK"
|
||||
}
|
||||
+2
-4
@@ -3,15 +3,13 @@
|
||||
* that can be found in the LICENSE file.
|
||||
*/
|
||||
|
||||
package codegen.funInterface.nonTrivialProjectionInSuperType
|
||||
|
||||
import kotlin.test.*
|
||||
|
||||
fun <T> foo(comparator: kotlin.Comparator<in T>, a: T, b: T) = comparator.compare(a, b)
|
||||
|
||||
fun bar(x: Int, y: Int) = foo<Int> ({ a, b -> a - b}, x, y)
|
||||
|
||||
@Test
|
||||
fun test() {
|
||||
fun box(): String {
|
||||
assertTrue(bar(42, 117) < 0)
|
||||
return "OK"
|
||||
}
|
||||
@@ -3,20 +3,18 @@
|
||||
* that can be found in the LICENSE file.
|
||||
*/
|
||||
|
||||
package codegen.function.arithmetic
|
||||
|
||||
import kotlin.test.*
|
||||
|
||||
fun square(a:Int):Int = a * a
|
||||
fun sumOfSquares(a:Int, b:Int):Int = square(a) + square(b)
|
||||
fun diffOfSquares(a:Int, b:Int):Int = square(a) - square(b)
|
||||
fun mod(a:Int,b:Int):Int = a / b
|
||||
fun remainder(a:Int, b:Int):Int = a % b
|
||||
|
||||
@Test fun runTest() {
|
||||
fun box(): String {
|
||||
if (square(2) != 4) throw Error()
|
||||
if (sumOfSquares(2, 4) != 20) throw Error()
|
||||
if (diffOfSquares(2, 4) != -12) throw Error()
|
||||
if (mod(5, 2) != 2) throw Error()
|
||||
if (remainder(5, 2) != 1) throw Error()
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -3,12 +3,10 @@
|
||||
* that can be found in the LICENSE file.
|
||||
*/
|
||||
|
||||
package codegen.function.boolean
|
||||
|
||||
import kotlin.test.*
|
||||
|
||||
fun bool_yes(): Boolean = true
|
||||
|
||||
@Test fun runTest() {
|
||||
if (!bool_yes()) throw Error()
|
||||
fun box(): String {
|
||||
if (!bool_yes()) return "FAIL !bool_yes()"
|
||||
|
||||
return "OK"
|
||||
}
|
||||
|
||||
@@ -3,10 +3,6 @@
|
||||
* that can be found in the LICENSE file.
|
||||
*/
|
||||
|
||||
package codegen.function.defaults
|
||||
|
||||
import kotlin.test.*
|
||||
|
||||
/**
|
||||
* Created by minamoto on 12/26/16.
|
||||
*/
|
||||
@@ -48,7 +44,7 @@ fun foo(a: A = A.magic, b:Int = 0xdeadbeef.toInt()) = a.a
|
||||
fun bar(a:A, inc:Int = 0) = A(a.a + inc)
|
||||
|
||||
|
||||
@Test fun runTest() {
|
||||
fun box(): String {
|
||||
|
||||
// if: CALL 'NOT(Boolean): Boolean' type=kotlin.Boolean origin=EXCLEQ
|
||||
// arg0: CALL 'EQEQ(Any?, Any?): Boolean' type=kotlin.Boolean origin=EXCLEQ
|
||||
@@ -98,5 +94,5 @@ fun bar(a:A, inc:Int = 0) = A(a.a + inc)
|
||||
println("A one + 1 failed")
|
||||
throw Error()
|
||||
}
|
||||
println("all tests passed")
|
||||
return "OK"
|
||||
}
|
||||
|
||||
@@ -3,16 +3,15 @@
|
||||
* that can be found in the LICENSE file.
|
||||
*/
|
||||
|
||||
package codegen.function.defaults1
|
||||
|
||||
import kotlin.test.*
|
||||
|
||||
fun foo(x:Int = 0, y:Int = x + 1, z:Int = x + y + 1) = x + y + z
|
||||
|
||||
@Test fun runTest() {
|
||||
fun box(): String {
|
||||
val v = foo()
|
||||
if (v != 3) {
|
||||
println("test failed $v expected 3")
|
||||
throw Error()
|
||||
}
|
||||
return "OK"
|
||||
}
|
||||
@@ -3,14 +3,13 @@
|
||||
* that can be found in the LICENSE file.
|
||||
*/
|
||||
|
||||
package codegen.function.defaults10
|
||||
|
||||
import kotlin.test.*
|
||||
|
||||
enum class A(one: Int, val two: Int = one) {
|
||||
FOO(42)
|
||||
}
|
||||
|
||||
@Test fun runTest() {
|
||||
println(A.FOO.two)
|
||||
fun box(): String {
|
||||
assertEquals(42, (A.FOO.two))
|
||||
return "OK"
|
||||
}
|
||||
@@ -1 +0,0 @@
|
||||
42
|
||||
@@ -3,17 +3,16 @@
|
||||
* that can be found in the LICENSE file.
|
||||
*/
|
||||
|
||||
package codegen.function.defaults2
|
||||
|
||||
import kotlin.test.*
|
||||
|
||||
|
||||
fun Int.foo(inc0:Int, inc:Int = 0) = this + inc0 + inc
|
||||
|
||||
@Test fun runTest() {
|
||||
fun box(): String {
|
||||
val v = 42.foo(0)
|
||||
if (v != 42) {
|
||||
println("test failed v:$v expected:42")
|
||||
throw Error()
|
||||
}
|
||||
return "OK"
|
||||
}
|
||||
|
||||
@@ -3,14 +3,10 @@
|
||||
* that can be found in the LICENSE file.
|
||||
*/
|
||||
|
||||
package codegen.function.defaults3
|
||||
|
||||
import kotlin.test.*
|
||||
|
||||
fun foo(a:Int = 2, b:String = "Hello", c:Int = 4):String = "$b-$c$a"
|
||||
fun foo(a:Int = 3, b:Int = a + 1, c:Int = a + b) = a + b + c
|
||||
|
||||
@Test fun runTest() {
|
||||
fun box(): String {
|
||||
val a = foo(b="Universe")
|
||||
if (a != "Universe-42")
|
||||
throw Error()
|
||||
@@ -18,4 +14,6 @@ fun foo(a:Int = 3, b:Int = a + 1, c:Int = a + b) = a + b + c
|
||||
val b = foo(b = 5)
|
||||
if (b != (/* a = */ 3 + /* b = */ 5 + /* c = */ (3 + 5)))
|
||||
throw Error()
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -3,20 +3,23 @@
|
||||
* that can be found in the LICENSE file.
|
||||
*/
|
||||
|
||||
package codegen.function.defaults4
|
||||
|
||||
import kotlin.test.*
|
||||
|
||||
val sb = StringBuilder()
|
||||
|
||||
open class A {
|
||||
open fun foo(x: Int = 42) = println(x)
|
||||
open fun foo(x: Int = 42) = sb.append(x)
|
||||
}
|
||||
|
||||
open class B : A()
|
||||
|
||||
class C : B() {
|
||||
override fun foo(x: Int) = println(x + 1)
|
||||
override fun foo(x: Int) = sb.append(x + 1)
|
||||
}
|
||||
|
||||
@Test fun runTest() {
|
||||
fun box(): String {
|
||||
C().foo()
|
||||
|
||||
assertEquals("43", sb.toString())
|
||||
return "OK"
|
||||
}
|
||||
@@ -1 +0,0 @@
|
||||
43
|
||||
@@ -3,21 +3,24 @@
|
||||
* that can be found in the LICENSE file.
|
||||
*/
|
||||
|
||||
package codegen.function.defaults5
|
||||
|
||||
import kotlin.test.*
|
||||
|
||||
val sb = StringBuilder()
|
||||
|
||||
class TestClass(val x: Int) {
|
||||
fun foo(y: Int = x) {
|
||||
println(y)
|
||||
sb.appendLine(y)
|
||||
}
|
||||
}
|
||||
|
||||
fun TestClass.bar(y: Int = x) {
|
||||
println(y)
|
||||
sb.appendLine(y)
|
||||
}
|
||||
|
||||
@Test fun runTest() {
|
||||
fun box(): String {
|
||||
TestClass(5).foo()
|
||||
TestClass(6).bar()
|
||||
|
||||
assertEquals("5\n6\n", sb.toString())
|
||||
return "OK"
|
||||
}
|
||||
@@ -1,2 +0,0 @@
|
||||
5
|
||||
6
|
||||
@@ -3,13 +3,12 @@
|
||||
* that can be found in the LICENSE file.
|
||||
*/
|
||||
|
||||
package codegen.function.defaults6
|
||||
|
||||
import kotlin.test.*
|
||||
|
||||
open class Foo(val x: Int = 42)
|
||||
class Bar : Foo()
|
||||
|
||||
@Test fun runTest() {
|
||||
println(Bar().x)
|
||||
fun box(): String {
|
||||
assertEquals(42, Bar().x)
|
||||
return "OK"
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user