[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.
|
* that can be found in the LICENSE file.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package codegen.cycles.cycle
|
|
||||||
|
|
||||||
import kotlin.test.*
|
import kotlin.test.*
|
||||||
|
|
||||||
fun cycle(cnt: Int): Int {
|
fun cycle(cnt: Int): Int {
|
||||||
@@ -15,7 +13,9 @@ fun cycle(cnt: Int): Int {
|
|||||||
return sum
|
return sum
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test fun runTest() {
|
fun box(): String {
|
||||||
if (cycle(1) != 2) throw Error()
|
assertEquals(2, cycle(1))
|
||||||
if (cycle(0) != 1) throw Error()
|
assertEquals(1, cycle(0))
|
||||||
|
|
||||||
|
return "OK"
|
||||||
}
|
}
|
||||||
|
|||||||
+5
-5
@@ -3,8 +3,6 @@
|
|||||||
* that can be found in the LICENSE file.
|
* that can be found in the LICENSE file.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package codegen.cycles.cycle_do
|
|
||||||
|
|
||||||
import kotlin.test.*
|
import kotlin.test.*
|
||||||
|
|
||||||
fun cycle_do(cnt: Int): Int {
|
fun cycle_do(cnt: Int): Int {
|
||||||
@@ -15,7 +13,9 @@ fun cycle_do(cnt: Int): Int {
|
|||||||
return sum
|
return sum
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test fun runTest() {
|
fun box(): String {
|
||||||
if (cycle_do(3) != 5) throw Error()
|
assertEquals(5, cycle_do(3))
|
||||||
if (cycle_do(0) != 3) throw Error()
|
assertEquals(3, cycle_do(0))
|
||||||
|
|
||||||
|
return "OK"
|
||||||
}
|
}
|
||||||
@@ -3,8 +3,6 @@
|
|||||||
* that can be found in the LICENSE file.
|
* that can be found in the LICENSE file.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package codegen.cycles.cycle_for
|
|
||||||
|
|
||||||
import kotlin.test.*
|
import kotlin.test.*
|
||||||
|
|
||||||
fun cycle_for(arr: Array<Int>) : Int {
|
fun cycle_for(arr: Array<Int>) : Int {
|
||||||
@@ -15,6 +13,8 @@ fun cycle_for(arr: Array<Int>) : Int {
|
|||||||
return sum
|
return sum
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test fun runTest() {
|
fun box(): String {
|
||||||
if (cycle_for(Array(4, init = { it })) != 6) throw Error()
|
assertEquals(6, cycle_for(Array(4, init = { it })))
|
||||||
|
|
||||||
|
return "OK"
|
||||||
}
|
}
|
||||||
+3
-4
@@ -3,16 +3,15 @@
|
|||||||
* that can be found in the LICENSE file.
|
* that can be found in the LICENSE file.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package codegen.dataflow.scope1
|
|
||||||
|
|
||||||
import kotlin.test.*
|
import kotlin.test.*
|
||||||
|
|
||||||
var b = true
|
var b = true
|
||||||
|
|
||||||
@Test fun runTest() {
|
fun box(): String {
|
||||||
var x = 1
|
var x = 1
|
||||||
if (b) {
|
if (b) {
|
||||||
var x = 2
|
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.
|
* that can be found in the LICENSE file.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package codegen.dataflow.uninitialized_val
|
|
||||||
|
|
||||||
import kotlin.test.*
|
import kotlin.test.*
|
||||||
|
|
||||||
fun foo(b: Boolean): Int {
|
fun foo(b: Boolean): Int {
|
||||||
@@ -18,9 +16,11 @@ fun foo(b: Boolean): Int {
|
|||||||
return x
|
return x
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test fun runTest() {
|
fun box(): String {
|
||||||
val uninitializedUnused: Int
|
val uninitializedUnused: Int
|
||||||
|
|
||||||
println(foo(true))
|
assertEquals(1, foo(true))
|
||||||
println(foo(false))
|
assertEquals(2, foo(false))
|
||||||
|
|
||||||
|
return "OK"
|
||||||
}
|
}
|
||||||
@@ -1,2 +0,0 @@
|
|||||||
1
|
|
||||||
2
|
|
||||||
@@ -3,16 +3,24 @@
|
|||||||
* that can be found in the LICENSE file.
|
* that can be found in the LICENSE file.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package codegen.delegatedProperty.lazy
|
|
||||||
|
|
||||||
import kotlin.test.*
|
import kotlin.test.*
|
||||||
|
|
||||||
|
val sb = StringBuilder()
|
||||||
|
|
||||||
val lazyValue: String by lazy {
|
val lazyValue: String by lazy {
|
||||||
println("computed!")
|
sb.appendLine("computed!")
|
||||||
"Hello"
|
"Hello"
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test fun runTest() {
|
fun box(): String {
|
||||||
println(lazyValue)
|
sb.appendLine(lazyValue)
|
||||||
println(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.
|
* that can be found in the LICENSE file.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package codegen.delegatedProperty.local
|
|
||||||
|
|
||||||
import kotlin.test.*
|
import kotlin.test.*
|
||||||
|
|
||||||
import kotlin.reflect.KProperty
|
import kotlin.reflect.KProperty
|
||||||
|
|
||||||
|
val sb = StringBuilder()
|
||||||
|
|
||||||
fun foo(): Int {
|
fun foo(): Int {
|
||||||
class Delegate {
|
class Delegate {
|
||||||
operator fun getValue(receiver: Any?, p: KProperty<*>): Int {
|
operator fun getValue(receiver: Any?, p: KProperty<*>): Int {
|
||||||
println(p.name)
|
sb.appendLine(p.name)
|
||||||
return 42
|
return 42
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -22,6 +21,13 @@ fun foo(): Int {
|
|||||||
return x
|
return x
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test fun runTest() {
|
fun box(): String {
|
||||||
println(foo())
|
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.
|
* that can be found in the LICENSE file.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package codegen.delegatedProperty.map
|
|
||||||
|
|
||||||
import kotlin.test.*
|
import kotlin.test.*
|
||||||
|
|
||||||
class User(val map: Map<String, Any?>) {
|
class User(val map: Map<String, Any?>) {
|
||||||
@@ -12,11 +10,13 @@ class User(val map: Map<String, Any?>) {
|
|||||||
val age: Int by map
|
val age: Int by map
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test fun runTest() {
|
fun box(): String {
|
||||||
val user = User(mapOf(
|
val user = User(mapOf(
|
||||||
"name" to "John Doe",
|
"name" to "John Doe",
|
||||||
"age" to 25
|
"age" to 25
|
||||||
))
|
))
|
||||||
println(user.name) // Prints "John Doe"
|
assertEquals("John Doe", user.name)
|
||||||
println(user.age) // Prints 25
|
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.
|
* that can be found in the LICENSE file.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package codegen.delegatedProperty.observable
|
|
||||||
|
|
||||||
import kotlin.test.*
|
import kotlin.test.*
|
||||||
|
|
||||||
import kotlin.properties.Delegates
|
import kotlin.properties.Delegates
|
||||||
|
|
||||||
|
val sb = StringBuilder()
|
||||||
|
|
||||||
class User {
|
class User {
|
||||||
var name: String by Delegates.observable("<no name>") {
|
var name: String by Delegates.observable("<no name>") {
|
||||||
prop, old, new ->
|
prop, old, new ->
|
||||||
println("$old -> $new")
|
sb.appendLine("$old -> $new")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test fun runTest() {
|
fun box(): String {
|
||||||
val user = User()
|
val user = User()
|
||||||
user.name = "first"
|
user.name = "first"
|
||||||
user.name = "second"
|
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.
|
* that can be found in the LICENSE file.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package codegen.delegatedProperty.packageLevel
|
|
||||||
|
|
||||||
import kotlin.test.*
|
import kotlin.test.*
|
||||||
|
|
||||||
import kotlin.reflect.KProperty
|
import kotlin.reflect.KProperty
|
||||||
|
|
||||||
|
val sb = StringBuilder()
|
||||||
|
|
||||||
class Delegate {
|
class Delegate {
|
||||||
operator fun getValue(receiver: Any?, p: KProperty<*>): Int {
|
operator fun getValue(receiver: Any?, p: KProperty<*>): Int {
|
||||||
println(p.name)
|
sb.appendLine(p.name)
|
||||||
return 42
|
return 42
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
val x: Int by Delegate()
|
val x: Int by Delegate()
|
||||||
|
|
||||||
@Test fun runTest() {
|
fun box(): String {
|
||||||
println(x)
|
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.
|
* that can be found in the LICENSE file.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package codegen.delegatedProperty.simpleVal
|
|
||||||
|
|
||||||
import kotlin.test.*
|
import kotlin.test.*
|
||||||
|
|
||||||
import kotlin.reflect.KProperty
|
import kotlin.reflect.KProperty
|
||||||
|
|
||||||
|
val sb = StringBuilder()
|
||||||
|
|
||||||
class Delegate {
|
class Delegate {
|
||||||
operator fun getValue(receiver: Any?, p: KProperty<*>): Int {
|
operator fun getValue(receiver: Any?, p: KProperty<*>): Int {
|
||||||
println(p.name)
|
sb.appendLine(p.name)
|
||||||
return 42
|
return 42
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -20,6 +20,13 @@ class C {
|
|||||||
val x: Int by Delegate()
|
val x: Int by Delegate()
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test fun runTest() {
|
fun box(): String {
|
||||||
println(C().x)
|
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.
|
* that can be found in the LICENSE file.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package codegen.delegatedProperty.simpleVar
|
|
||||||
|
|
||||||
import kotlin.test.*
|
import kotlin.test.*
|
||||||
|
|
||||||
import kotlin.reflect.KProperty
|
import kotlin.reflect.KProperty
|
||||||
|
|
||||||
|
val sb = StringBuilder()
|
||||||
|
|
||||||
class Delegate {
|
class Delegate {
|
||||||
var f: Int = 42
|
var f: Int = 42
|
||||||
|
|
||||||
operator fun getValue(receiver: Any?, p: KProperty<*>): Int {
|
operator fun getValue(receiver: Any?, p: KProperty<*>): Int {
|
||||||
println("get ${p.name}")
|
sb.appendLine("get ${p.name}")
|
||||||
return f
|
return f
|
||||||
}
|
}
|
||||||
|
|
||||||
operator fun setValue(receiver: Any?, p: KProperty<*>, value: Int) {
|
operator fun setValue(receiver: Any?, p: KProperty<*>, value: Int) {
|
||||||
println("set ${p.name}")
|
sb.appendLine("set ${p.name}")
|
||||||
f = value
|
f = value
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -27,9 +27,19 @@ class C {
|
|||||||
var x: Int by Delegate()
|
var x: Int by Delegate()
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test fun runTest() {
|
fun box(): String {
|
||||||
val c = C()
|
val c = C()
|
||||||
println(c.x)
|
sb.appendLine(c.x)
|
||||||
c.x = 117
|
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.
|
* that can be found in the LICENSE file.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
import kotlin.test.*
|
||||||
|
|
||||||
|
val sb = StringBuilder()
|
||||||
|
|
||||||
interface I {
|
interface I {
|
||||||
fun foo()
|
fun foo()
|
||||||
}
|
}
|
||||||
|
|
||||||
fun test() {
|
fun test() {
|
||||||
val impl = object : I {
|
val impl = object : I {
|
||||||
override fun foo() { println("zzz") }
|
override fun foo() { sb.append("zzz") }
|
||||||
}
|
}
|
||||||
|
|
||||||
val delegating = object: I by impl { }
|
val delegating = object: I by impl { }
|
||||||
@@ -17,6 +21,9 @@ fun test() {
|
|||||||
delegating.foo()
|
delegating.foo()
|
||||||
}
|
}
|
||||||
|
|
||||||
fun main() {
|
fun box(): String {
|
||||||
test()
|
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() {
|
fun box(): String {
|
||||||
println(Foo().box)
|
return Foo().box
|
||||||
}
|
}
|
||||||
-1
@@ -1 +0,0 @@
|
|||||||
box
|
|
||||||
@@ -1,3 +1,5 @@
|
|||||||
|
import kotlin.test.*
|
||||||
|
|
||||||
interface Base { val id: Int }
|
interface Base { val id: Int }
|
||||||
|
|
||||||
inline class Child(override val id: Int = 1) : Base
|
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 }
|
interface Base2 { val prop: Base }
|
||||||
class Child2(override val prop: Child) : Base2
|
class Child2(override val prop: Child) : Base2
|
||||||
|
|
||||||
fun main() {
|
fun box(): String {
|
||||||
val x : Base = Child(5)
|
val x : Base = Child(5)
|
||||||
println(x.id)
|
assertEquals(5, x.id)
|
||||||
val y : Base2 = Child2(Child(5))
|
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 {
|
interface I {
|
||||||
fun foo(): Int
|
fun foo(): Int
|
||||||
}
|
}
|
||||||
@@ -10,5 +11,10 @@ fun main(args: Array<String>) {
|
|||||||
lateinit var a: I
|
lateinit var a: I
|
||||||
if (args.size == 0)
|
if (args.size == 0)
|
||||||
a = A()
|
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.
|
* that can be found in the LICENSE file.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package codegen.enum.companionObject
|
|
||||||
|
|
||||||
import kotlin.test.*
|
import kotlin.test.*
|
||||||
|
|
||||||
enum class Game {
|
enum class Game {
|
||||||
@@ -29,5 +27,3 @@ fun box(): String {
|
|||||||
if (Game.scissors != Game.SCISSORS) return "Fail 6"
|
if (Game.scissors != Game.SCISSORS) return "Fail 6"
|
||||||
return "OK"
|
return "OK"
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test fun runTest() = println(box())
|
|
||||||
@@ -1 +0,0 @@
|
|||||||
OK
|
|
||||||
@@ -3,8 +3,6 @@
|
|||||||
* that can be found in the LICENSE file.
|
* that can be found in the LICENSE file.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package codegen.enum.interfaceCallNoEntryClass
|
|
||||||
|
|
||||||
import kotlin.test.*
|
import kotlin.test.*
|
||||||
|
|
||||||
interface A {
|
interface A {
|
||||||
@@ -21,8 +19,9 @@ enum class Zzz(val zzz: String, val x: Int) : A {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test fun runTest() {
|
fun box(): String {
|
||||||
println(Zzz.Z3.foo())
|
assertEquals("('z3', 3)", Zzz.Z3.foo())
|
||||||
val a: A = Zzz.Z3
|
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.
|
* that can be found in the LICENSE file.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package codegen.enum.interfaceCallWithEntryClass
|
|
||||||
|
|
||||||
import kotlin.test.*
|
import kotlin.test.*
|
||||||
|
|
||||||
interface A {
|
interface A {
|
||||||
@@ -23,9 +21,11 @@ enum class Zzz: A {
|
|||||||
override fun f() = ""
|
override fun f() = ""
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test fun runTest() {
|
fun box(): String {
|
||||||
println(Zzz.Z1.f() + Zzz.Z2.f())
|
assertEquals("z1z2", Zzz.Z1.f() + Zzz.Z2.f())
|
||||||
val a1: A = Zzz.Z1
|
val a1: A = Zzz.Z1
|
||||||
val a2: A = Zzz.Z2
|
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.
|
* that can be found in the LICENSE file.
|
||||||
*/
|
*/
|
||||||
@file:OptIn(FreezingIsDeprecated::class, kotlin.experimental.ExperimentalNativeApi::class)
|
@file:OptIn(FreezingIsDeprecated::class, kotlin.experimental.ExperimentalNativeApi::class)
|
||||||
package codegen.enum.isFrozen
|
|
||||||
|
|
||||||
import kotlin.test.*
|
import kotlin.test.*
|
||||||
import kotlin.native.concurrent.*
|
import kotlin.native.concurrent.*
|
||||||
@@ -13,7 +12,7 @@ enum class Zzz(val zzz: String, var value: Int = 0) {
|
|||||||
Z2("z2")
|
Z2("z2")
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test fun runTest() {
|
fun box(): String {
|
||||||
if (Platform.memoryModel == MemoryModel.STRICT) {
|
if (Platform.memoryModel == MemoryModel.STRICT) {
|
||||||
assertTrue(Zzz.Z1.isFrozen)
|
assertTrue(Zzz.Z1.isFrozen)
|
||||||
assertFailsWith<InvalidMutabilityException> {
|
assertFailsWith<InvalidMutabilityException> {
|
||||||
@@ -25,4 +24,6 @@ enum class Zzz(val zzz: String, var value: Int = 0) {
|
|||||||
Zzz.Z1.value = 42
|
Zzz.Z1.value = 42
|
||||||
assertEquals(42, Zzz.Z1.value)
|
assertEquals(42, Zzz.Z1.value)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return "OK"
|
||||||
}
|
}
|
||||||
|
|||||||
+3
-4
@@ -3,8 +3,6 @@
|
|||||||
* that can be found in the LICENSE file.
|
* that can be found in the LICENSE file.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package codegen.enum.kt38540
|
|
||||||
|
|
||||||
import kotlin.test.*
|
import kotlin.test.*
|
||||||
|
|
||||||
public enum class Node(
|
public enum class Node(
|
||||||
@@ -99,9 +97,10 @@ public enum class Node(
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
fun box(): String {
|
||||||
fun runTest() {
|
|
||||||
assertTrue(Node.FIELD_REPORT.dependsOn.contains(Node.AG))
|
assertTrue(Node.FIELD_REPORT.dependsOn.contains(Node.AG))
|
||||||
assertTrue(Node.FIELD_REPORT.dependsOn.contains(Node.O))
|
assertTrue(Node.FIELD_REPORT.dependsOn.contains(Node.O))
|
||||||
assertTrue(Node.FIELD_REPORT.dependsOn.contains(Node.J))
|
assertTrue(Node.FIELD_REPORT.dependsOn.contains(Node.J))
|
||||||
|
|
||||||
|
return "OK"
|
||||||
}
|
}
|
||||||
@@ -3,8 +3,6 @@
|
|||||||
* that can be found in the LICENSE file.
|
* that can be found in the LICENSE file.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package codegen.enum.lambdaInDefault
|
|
||||||
|
|
||||||
import kotlin.test.*
|
import kotlin.test.*
|
||||||
|
|
||||||
enum class Zzz(val value: String.() -> Int = {
|
enum class Zzz(val value: String.() -> Int = {
|
||||||
@@ -13,6 +11,7 @@ enum class Zzz(val value: String.() -> Int = {
|
|||||||
Q()
|
Q()
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test fun runTest() {
|
fun box(): String {
|
||||||
println(Zzz.Q)
|
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.
|
* that can be found in the LICENSE file.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package codegen.enum.loop
|
|
||||||
|
|
||||||
import kotlin.test.*
|
import kotlin.test.*
|
||||||
|
|
||||||
|
val sb = StringBuilder()
|
||||||
|
|
||||||
|
|
||||||
enum class Zzz {
|
enum class Zzz {
|
||||||
Z {
|
Z {
|
||||||
init {
|
init {
|
||||||
println(Z.name)
|
sb.appendLine(Z.name)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test fun runTest() {
|
fun box(): String {
|
||||||
println(Zzz.Z)
|
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.
|
* that can be found in the LICENSE file.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package codegen.enum.nested
|
|
||||||
|
|
||||||
import kotlin.test.*
|
import kotlin.test.*
|
||||||
|
|
||||||
enum class Foo {
|
enum class Foo {
|
||||||
@@ -12,7 +10,9 @@ enum class Foo {
|
|||||||
enum class Bar { C }
|
enum class Bar { C }
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test fun runTest() {
|
fun box(): String {
|
||||||
println(Foo.A)
|
assertEquals("A", Foo.A.toString())
|
||||||
println(Foo.Bar.C)
|
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.
|
* that can be found in the LICENSE file.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package codegen.enum.reorderedArguments
|
|
||||||
|
|
||||||
import kotlin.test.*
|
import kotlin.test.*
|
||||||
|
|
||||||
// Regression test for https://github.com/JetBrains/kotlin-native/issues/1779
|
// 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)
|
E(Foo.E)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test fun runTest() {
|
fun box(): String {
|
||||||
|
|
||||||
assertEquals(Foo.A.a, 1)
|
assertEquals(Foo.A.a, 1)
|
||||||
assertEquals(Foo.A.b, 0)
|
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.b, 1)
|
||||||
assertEquals(Bar.E.value.c, 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
|
* 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.
|
* that can be found in the LICENSE file.
|
||||||
*/
|
*/
|
||||||
|
// !LANGUAGE:-ProhibitComparisonOfIncompatibleEnums
|
||||||
package codegen.enum.switchLowering
|
|
||||||
|
|
||||||
import kotlin.test.*
|
import kotlin.test.*
|
||||||
|
|
||||||
|
val sb = StringBuilder()
|
||||||
|
|
||||||
enum class EnumA {
|
enum class EnumA {
|
||||||
A, B, C
|
A, B, C
|
||||||
}
|
}
|
||||||
@@ -23,7 +24,7 @@ fun produceEntry() = EnumA.A
|
|||||||
|
|
||||||
// Check that we fail on comparison of different enum types.
|
// Check that we fail on comparison of different enum types.
|
||||||
fun differentEnums() {
|
fun differentEnums() {
|
||||||
println(when (produceEntry()) {
|
sb.appendLine(when (produceEntry()) {
|
||||||
EnumB.A -> "EnumB.A"
|
EnumB.A -> "EnumB.A"
|
||||||
EnumA.A -> "EnumA.A"
|
EnumA.A -> "EnumA.A"
|
||||||
EnumA.B -> "EnumA.B"
|
EnumA.B -> "EnumA.B"
|
||||||
@@ -35,8 +36,8 @@ fun differentEnums() {
|
|||||||
fun nullable() {
|
fun nullable() {
|
||||||
val x: EnumA? = null
|
val x: EnumA? = null
|
||||||
when(x) {
|
when(x) {
|
||||||
EnumA.A -> println("fail")
|
EnumA.A -> sb.appendLine("fail")
|
||||||
else -> println("ok")
|
else -> sb.appendLine("ok")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -46,23 +47,23 @@ fun operatorOverloading() {
|
|||||||
|
|
||||||
val y = E.ONE
|
val y = E.ONE
|
||||||
when(y) {
|
when(y) {
|
||||||
in E.ONE -> println("Should not reach here")
|
in E.ONE -> sb.appendLine("Should not reach here")
|
||||||
else -> println("ok")
|
else -> sb.appendLine("ok")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun smoke1() {
|
fun smoke1() {
|
||||||
when (produceEntry()) {
|
when (produceEntry()) {
|
||||||
EnumA.B -> println("error")
|
EnumA.B -> sb.appendLine("error")
|
||||||
EnumA.A -> println("ok")
|
EnumA.A -> sb.appendLine("ok")
|
||||||
EnumA.C -> println("error")
|
EnumA.C -> sb.appendLine("error")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun smoke2() {
|
fun smoke2() {
|
||||||
when (produceEntry()) {
|
when (produceEntry()) {
|
||||||
EnumA.B -> println("error")
|
EnumA.B -> sb.appendLine("error")
|
||||||
else -> println("ok")
|
else -> sb.appendLine("ok")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -72,7 +73,7 @@ fun eB() = EnumA.B
|
|||||||
|
|
||||||
|
|
||||||
fun nestedWhen() {
|
fun nestedWhen() {
|
||||||
println(when (eA()) {
|
sb.appendLine(when (eA()) {
|
||||||
EnumA.A, EnumA.C -> when (eB()) {
|
EnumA.A, EnumA.C -> when (eB()) {
|
||||||
EnumA.B -> "ok"
|
EnumA.B -> "ok"
|
||||||
else -> "nope"
|
else -> "nope"
|
||||||
@@ -81,11 +82,22 @@ fun nestedWhen() {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
fun main() {
|
fun box(): String {
|
||||||
differentEnums()
|
differentEnums()
|
||||||
nullable()
|
nullable()
|
||||||
operatorOverloading()
|
operatorOverloading()
|
||||||
smoke1()
|
smoke1()
|
||||||
smoke2()
|
smoke2()
|
||||||
nestedWhen()
|
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.
|
* that can be found in the LICENSE file.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package codegen.enum.test0
|
|
||||||
|
|
||||||
import kotlin.test.*
|
import kotlin.test.*
|
||||||
|
|
||||||
val TOP_LEVEL = 5
|
val TOP_LEVEL = 5
|
||||||
@@ -13,6 +11,8 @@ enum class MyEnum(value: Int) {
|
|||||||
VALUE(TOP_LEVEL)
|
VALUE(TOP_LEVEL)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test fun runTest() {
|
fun box(): String {
|
||||||
println(MyEnum.VALUE.toString())
|
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.
|
* that can be found in the LICENSE file.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package codegen.enum.test1
|
|
||||||
|
|
||||||
import kotlin.test.*
|
import kotlin.test.*
|
||||||
|
|
||||||
enum class Zzz(val zzz: String, val x: Int) {
|
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)
|
Z2("z2", 2)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test fun runTest() {
|
fun box(): String {
|
||||||
println(Zzz.Z1.zzz + Zzz.Z2.x)
|
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.
|
* that can be found in the LICENSE file.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package codegen.enum.vCallNoEntryClass
|
|
||||||
|
|
||||||
import kotlin.test.*
|
import kotlin.test.*
|
||||||
|
|
||||||
enum class Zzz(val zzz: String, val x: Int) {
|
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() {
|
fun box(): String {
|
||||||
println(Zzz.Z3.toString())
|
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.
|
* that can be found in the LICENSE file.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package codegen.enum.vCallWithEntryClass
|
|
||||||
|
|
||||||
import kotlin.test.*
|
import kotlin.test.*
|
||||||
|
|
||||||
enum class Zzz {
|
enum class Zzz {
|
||||||
@@ -19,6 +17,8 @@ enum class Zzz {
|
|||||||
open fun f() = ""
|
open fun f() = ""
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test fun runTest() {
|
fun box(): String {
|
||||||
println(Zzz.Z1.f() + Zzz.Z2.f())
|
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.
|
* that can be found in the LICENSE file.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package codegen.enum.valueOf
|
|
||||||
|
|
||||||
import kotlin.test.*
|
import kotlin.test.*
|
||||||
|
|
||||||
enum class E {
|
enum class E {
|
||||||
@@ -13,11 +11,13 @@ enum class E {
|
|||||||
E2
|
E2
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test fun runTest() {
|
fun box(): String {
|
||||||
println(E.valueOf("E1").toString())
|
assertEquals("E1", E.valueOf("E1").toString())
|
||||||
println(E.valueOf("E2").toString())
|
assertEquals("E2", E.valueOf("E2").toString())
|
||||||
println(E.valueOf("E3").toString())
|
assertEquals("E3", E.valueOf("E3").toString())
|
||||||
println(enumValueOf<E>("E1").toString())
|
assertEquals("E1", enumValueOf<E>("E1").toString())
|
||||||
println(enumValueOf<E>("E2").toString())
|
assertEquals("E2", enumValueOf<E>("E2").toString())
|
||||||
println(enumValueOf<E>("E3").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.
|
* that can be found in the LICENSE file.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package codegen.enum.values
|
|
||||||
|
|
||||||
import kotlin.test.*
|
import kotlin.test.*
|
||||||
|
|
||||||
enum class E {
|
enum class E {
|
||||||
@@ -13,11 +11,13 @@ enum class E {
|
|||||||
E2
|
E2
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test fun runTest() {
|
fun box(): String {
|
||||||
println(E.values()[0].toString())
|
assertEquals("E3", E.values()[0].toString())
|
||||||
println(E.values()[1].toString())
|
assertEquals("E1", E.values()[1].toString())
|
||||||
println(E.values()[2].toString())
|
assertEquals("E2", E.values()[2].toString())
|
||||||
println(enumValues<E>()[0].toString())
|
assertEquals("E3", enumValues<E>()[0].toString())
|
||||||
println(enumValues<E>()[1].toString())
|
assertEquals("E1", enumValues<E>()[1].toString())
|
||||||
println(enumValues<E>()[2].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.
|
* that can be found in the LICENSE file.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package codegen.enum.varargParam
|
|
||||||
|
|
||||||
import kotlin.test.*
|
import kotlin.test.*
|
||||||
|
|
||||||
enum class Piece(vararg val states: Int) {
|
enum class Piece(vararg val states: Int) {
|
||||||
I(3, 4, 5)
|
I(3, 4, 5)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test fun runTest() {
|
fun box(): String {
|
||||||
println(Piece.I.states[0])
|
assertEquals(3, Piece.I.states[0])
|
||||||
|
return "OK"
|
||||||
}
|
}
|
||||||
@@ -1 +0,0 @@
|
|||||||
3
|
|
||||||
@@ -3,8 +3,6 @@
|
|||||||
* that can be found in the LICENSE file.
|
* that can be found in the LICENSE file.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package codegen.escapeAnalysis.negativeArraySize
|
|
||||||
|
|
||||||
import kotlin.test.*
|
import kotlin.test.*
|
||||||
|
|
||||||
const val size = -42
|
const val size = -42
|
||||||
@@ -14,6 +12,8 @@ fun foo() {
|
|||||||
for (x in arr) println(x)
|
for (x in arr) println(x)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test fun runTest() {
|
fun box(): String {
|
||||||
assertFailsWith<IllegalArgumentException> { foo() }
|
assertFailsWith<IllegalArgumentException> { foo() }
|
||||||
|
|
||||||
|
return "OK"
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,8 +3,6 @@
|
|||||||
* that can be found in the LICENSE file.
|
* that can be found in the LICENSE file.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package codegen.escapeAnalysis.recursion
|
|
||||||
|
|
||||||
import kotlin.test.*
|
import kotlin.test.*
|
||||||
|
|
||||||
class A {
|
class A {
|
||||||
@@ -19,6 +17,8 @@ fun foo(k: Int, a1: A, a2: A): A {
|
|||||||
return foo(k - 1, a2, a3)
|
return foo(k - 1, a2, a3)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test fun runTest() {
|
fun box(): String {
|
||||||
foo(3, A(), A()).toString()
|
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
|
* 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.
|
* that can be found in the LICENSE file.
|
||||||
*/
|
*/
|
||||||
|
// IGNORE_NATIVE: optimizationMode=DEBUG
|
||||||
package codegen.escapeAnalysis.stackAllocated
|
// IGNORE_NATIVE: optimizationMode=NO
|
||||||
|
|
||||||
import kotlin.test.*
|
import kotlin.test.*
|
||||||
import kotlin.native.internal.*
|
import kotlin.native.internal.*
|
||||||
@@ -18,6 +18,8 @@ fun f(x: Int): Int {
|
|||||||
return a.f(x)
|
return a.f(x)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test fun runTest() {
|
fun box(): String {
|
||||||
assertEquals(f(42), 55)
|
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
|
* 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.
|
* that can be found in the LICENSE file.
|
||||||
*/
|
*/
|
||||||
|
// IGNORE_NATIVE: optimizationMode=DEBUG
|
||||||
package codegen.escapeAnalysis.string
|
// IGNORE_NATIVE: optimizationMode=NO
|
||||||
|
|
||||||
import kotlin.test.*
|
import kotlin.test.*
|
||||||
import kotlin.native.internal.*
|
import kotlin.native.internal.*
|
||||||
|
|
||||||
@Test fun runTest() {
|
fun box(): String {
|
||||||
val s = String()
|
val s = String()
|
||||||
assertTrue(s.isLocal())
|
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.
|
* 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.*
|
import kotlin.test.*
|
||||||
|
|
||||||
@Test fun runTest() {
|
fun box(): String {
|
||||||
val array = IntArray(2)
|
val array = IntArray(2)
|
||||||
array[0] = 1
|
array[0] = 1
|
||||||
array[1] = 2
|
array[1] = 2
|
||||||
val check = array is IntArray
|
val check = array is IntArray
|
||||||
println(check)
|
assertTrue(check)
|
||||||
println(array[0] + array[1])
|
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
|
* 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.
|
* that can be found in the LICENSE file.
|
||||||
*/
|
*/
|
||||||
|
// TODO: check mentioned debug output of escape analyser
|
||||||
package codegen.escapeAnalysis.test1
|
|
||||||
|
|
||||||
class A(val s: String)
|
class A(val s: String)
|
||||||
|
|
||||||
@@ -17,4 +16,4 @@ class A(val s: String)
|
|||||||
// Escapes:
|
// Escapes:
|
||||||
fun foo(a: A) = a
|
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
|
* 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.
|
* that can be found in the LICENSE file.
|
||||||
*/
|
*/
|
||||||
|
// TODO: check mentioned debug output of escape analyser
|
||||||
package codegen.escapeAnalysis.test10
|
import kotlin.test.*
|
||||||
|
|
||||||
class G(val x: Int)
|
class G(val x: Int)
|
||||||
|
|
||||||
@@ -38,4 +38,7 @@ fun bar(): F {
|
|||||||
return u
|
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
|
* 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.
|
* that can be found in the LICENSE file.
|
||||||
*/
|
*/
|
||||||
|
// TODO: check mentioned debug output of escape analyser
|
||||||
package codegen.escapeAnalysis.test11
|
import kotlin.test.*
|
||||||
|
|
||||||
class F(val x: Int)
|
class F(val x: Int)
|
||||||
|
|
||||||
@@ -28,4 +28,7 @@ fun foo(a: A): F {
|
|||||||
return 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
|
* 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.
|
* that can be found in the LICENSE file.
|
||||||
*/
|
*/
|
||||||
|
// TODO: check mentioned debug output of escape analyser
|
||||||
package codegen.escapeAnalysis.test12
|
|
||||||
|
|
||||||
class A(val s: String)
|
class A(val s: String)
|
||||||
|
|
||||||
@@ -17,4 +16,4 @@ class A(val s: String)
|
|||||||
// Escapes:
|
// Escapes:
|
||||||
fun foo(arr: Array<A>) = arr[0]
|
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
|
* 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.
|
* that can be found in the LICENSE file.
|
||||||
*/
|
*/
|
||||||
|
import kotlin.test.*
|
||||||
package codegen.escapeAnalysis.test13
|
|
||||||
|
|
||||||
class A {
|
class A {
|
||||||
var f: A? = null
|
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)
|
return if (k == 0) a else foo(a.f!!, k - 1)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun main() {
|
fun box(): String {
|
||||||
val a = A()
|
val a = A()
|
||||||
a.f = A()
|
val a2 = A()
|
||||||
println(foo(a, 1))
|
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
|
* 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.
|
* that can be found in the LICENSE file.
|
||||||
*/
|
*/
|
||||||
|
// TODO: check mentioned debug output of escape analyser
|
||||||
package codegen.escapeAnalysis.test2
|
|
||||||
|
|
||||||
class A(val s: String)
|
class A(val s: String)
|
||||||
|
|
||||||
@@ -17,4 +16,4 @@ class A(val s: String)
|
|||||||
// Escapes:
|
// Escapes:
|
||||||
fun foo(a: A) = a.s
|
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
|
* 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.
|
* that can be found in the LICENSE file.
|
||||||
*/
|
*/
|
||||||
|
// TODO: check mentioned debug output of escape analyser
|
||||||
package codegen.escapeAnalysis.test3
|
|
||||||
|
|
||||||
class A(val s: String)
|
class A(val s: String)
|
||||||
class B {
|
class B {
|
||||||
@@ -25,4 +24,4 @@ fun foo(a: A, b: B): String {
|
|||||||
return a.s
|
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
|
* 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.
|
* that can be found in the LICENSE file.
|
||||||
*/
|
*/
|
||||||
|
// TODO: check mentioned debug output of escape analyser
|
||||||
package codegen.escapeAnalysis.test4
|
|
||||||
|
|
||||||
class A(val s: String)
|
class A(val s: String)
|
||||||
class B {
|
class B {
|
||||||
@@ -27,4 +26,7 @@ fun foo(c1: C, c2: C) {
|
|||||||
c1.g.f = c2.g.f
|
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
|
* 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.
|
* that can be found in the LICENSE file.
|
||||||
*/
|
*/
|
||||||
|
// TODO: check mentioned debug output of escape analyser
|
||||||
package codegen.escapeAnalysis.test5
|
|
||||||
|
|
||||||
class A(val s: String)
|
class A(val s: String)
|
||||||
class B {
|
class B {
|
||||||
var f: A = A("qzz")
|
var f: A = A("OK")
|
||||||
}
|
}
|
||||||
class C {
|
class C {
|
||||||
var g: B = B()
|
var g: B = B()
|
||||||
@@ -32,4 +31,4 @@ fun foo(c1: C, c2: C): B {
|
|||||||
return 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
|
* 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.
|
* that can be found in the LICENSE file.
|
||||||
*/
|
*/
|
||||||
|
// TODO: check mentioned debug output of escape analyser
|
||||||
package codegen.escapeAnalysis.test6
|
|
||||||
|
|
||||||
class A(val s: String)
|
class A(val s: String)
|
||||||
class B {
|
class B {
|
||||||
@@ -37,4 +36,4 @@ fun foo(z: Boolean, c1: C, c2: C, a: A): B {
|
|||||||
return v
|
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
|
* 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.
|
* 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) {
|
class A(val s: String) {
|
||||||
var h: String = ""
|
var h: String = ""
|
||||||
var p: C = C()
|
var p: C = C()
|
||||||
@@ -49,4 +49,8 @@ fun foo(z: Boolean, c: C, b: B, s: String, d: D) {
|
|||||||
u.p = c
|
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
|
* 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.
|
* 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) {
|
class F(val s: String) {
|
||||||
var g = F("")
|
var g = F("OK")
|
||||||
}
|
}
|
||||||
|
|
||||||
class A {
|
class A {
|
||||||
@@ -40,4 +40,8 @@ fun foo(a: A): F {
|
|||||||
return a.f.g.g
|
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
|
* 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.
|
* that can be found in the LICENSE file.
|
||||||
*/
|
*/
|
||||||
|
// TODO: check mentioned debug output of escape analyser
|
||||||
package codegen.escapeAnalysis.test9
|
import kotlin.test.*
|
||||||
|
|
||||||
class H(val x: Int)
|
class H(val x: Int)
|
||||||
|
|
||||||
|
// Note: intentional infinite recursion for F(String). Don't try to execute the code.
|
||||||
class F(val s: String) {
|
class F(val s: String) {
|
||||||
var g = F("")
|
var g = F("")
|
||||||
var h = H(0)
|
var h = H(0)
|
||||||
@@ -33,4 +34,8 @@ fun foo(a: A, f: F): H {
|
|||||||
return f.g.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.
|
* that can be found in the LICENSE file.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package codegen.escapeAnalysis.zeroOutObjectOnAlloc
|
|
||||||
|
|
||||||
import kotlin.test.*
|
import kotlin.test.*
|
||||||
|
|
||||||
class A {
|
class A {
|
||||||
var x = 0
|
var x = 0
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test fun runTest() {
|
fun box(): String {
|
||||||
var sum1 = 0
|
var sum1 = 0
|
||||||
var sum2 = 0
|
var sum2 = 0
|
||||||
for (i in 0 until 10) {
|
for (i in 0 until 10) {
|
||||||
@@ -22,4 +20,6 @@ class A {
|
|||||||
}
|
}
|
||||||
assertEquals(0, sum1)
|
assertEquals(0, sum1)
|
||||||
assertEquals(45, sum2)
|
assertEquals(45, sum2)
|
||||||
|
|
||||||
|
return "OK"
|
||||||
}
|
}
|
||||||
@@ -3,8 +3,6 @@
|
|||||||
* that can be found in the LICENSE file.
|
* that can be found in the LICENSE file.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package codegen.funInterface.implIsNotFunction
|
|
||||||
|
|
||||||
import kotlin.test.*
|
import kotlin.test.*
|
||||||
|
|
||||||
fun interface Foo {
|
fun interface Foo {
|
||||||
@@ -13,7 +11,7 @@ fun interface Foo {
|
|||||||
|
|
||||||
fun foo(f: Foo) = f is Function<*>
|
fun foo(f: Foo) = f is Function<*>
|
||||||
|
|
||||||
@Test
|
fun box(): String {
|
||||||
fun test() {
|
|
||||||
assertFalse(foo { "zzz" })
|
assertFalse(foo { "zzz" })
|
||||||
|
return "OK"
|
||||||
}
|
}
|
||||||
@@ -3,7 +3,6 @@
|
|||||||
* that can be found in the LICENSE file.
|
* that can be found in the LICENSE file.
|
||||||
*/
|
*/
|
||||||
@file:OptIn(kotlinx.cinterop.ExperimentalForeignApi::class)
|
@file:OptIn(kotlinx.cinterop.ExperimentalForeignApi::class)
|
||||||
package codegen.funInterface.kt43887
|
|
||||||
|
|
||||||
import kotlin.test.*
|
import kotlin.test.*
|
||||||
|
|
||||||
@@ -27,12 +26,14 @@ inline fun CPointer<heap_t>?.free(ptr: CPointer<*>?): Boolean {
|
|||||||
return heap_free(this, ptr)?.pointed?.value ?: false
|
return heap_free(this, ptr)?.pointed?.value ?: false
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
fun box(): String {
|
||||||
fun runTest(): Unit = memScoped {
|
memScoped {
|
||||||
val heap = Heap(1024)
|
val heap = Heap(1024)
|
||||||
|
|
||||||
heap.use<IntVar> { ptr ->
|
heap.use<IntVar> { ptr ->
|
||||||
ptr.pointed.value = 40
|
ptr.pointed.value = 40
|
||||||
//println("PTR ${ptr.pointed}")
|
//println("PTR ${ptr.pointed}")
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
return "OK"
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,8 +3,6 @@
|
|||||||
* that can be found in the LICENSE file.
|
* that can be found in the LICENSE file.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package codegen.funInterface.kt49384
|
|
||||||
|
|
||||||
import kotlin.test.*
|
import kotlin.test.*
|
||||||
|
|
||||||
interface A<T>
|
interface A<T>
|
||||||
@@ -17,20 +15,9 @@ class B<T> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
fun box(): String {
|
||||||
fun test1() {
|
|
||||||
val b = B<Any>()
|
val b = B<Any>()
|
||||||
assertEquals(b, b) // Just to ensure B is not deleted by DCE
|
assertEquals(b, b) // Just to ensure B is not deleted by DCE
|
||||||
}
|
|
||||||
|
|
||||||
fun interface Foo<T> {
|
return "OK"
|
||||||
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 })
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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.
|
* that can be found in the LICENSE file.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package codegen.funInterface.nonTrivialProjectionInSuperType
|
|
||||||
|
|
||||||
import kotlin.test.*
|
import kotlin.test.*
|
||||||
|
|
||||||
fun <T> foo(comparator: kotlin.Comparator<in T>, a: T, b: T) = comparator.compare(a, b)
|
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)
|
fun bar(x: Int, y: Int) = foo<Int> ({ a, b -> a - b}, x, y)
|
||||||
|
|
||||||
@Test
|
fun box(): String {
|
||||||
fun test() {
|
|
||||||
assertTrue(bar(42, 117) < 0)
|
assertTrue(bar(42, 117) < 0)
|
||||||
|
return "OK"
|
||||||
}
|
}
|
||||||
@@ -3,20 +3,18 @@
|
|||||||
* that can be found in the LICENSE file.
|
* that can be found in the LICENSE file.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package codegen.function.arithmetic
|
|
||||||
|
|
||||||
import kotlin.test.*
|
|
||||||
|
|
||||||
fun square(a:Int):Int = a * a
|
fun square(a:Int):Int = a * a
|
||||||
fun sumOfSquares(a:Int, b:Int):Int = square(a) + square(b)
|
fun sumOfSquares(a:Int, b:Int):Int = square(a) + square(b)
|
||||||
fun diffOfSquares(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 mod(a:Int,b:Int):Int = a / b
|
||||||
fun remainder(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 (square(2) != 4) throw Error()
|
||||||
if (sumOfSquares(2, 4) != 20) throw Error()
|
if (sumOfSquares(2, 4) != 20) throw Error()
|
||||||
if (diffOfSquares(2, 4) != -12) throw Error()
|
if (diffOfSquares(2, 4) != -12) throw Error()
|
||||||
if (mod(5, 2) != 2) throw Error()
|
if (mod(5, 2) != 2) throw Error()
|
||||||
if (remainder(5, 2) != 1) throw Error()
|
if (remainder(5, 2) != 1) throw Error()
|
||||||
|
|
||||||
|
return "OK"
|
||||||
}
|
}
|
||||||
@@ -3,12 +3,10 @@
|
|||||||
* that can be found in the LICENSE file.
|
* that can be found in the LICENSE file.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package codegen.function.boolean
|
|
||||||
|
|
||||||
import kotlin.test.*
|
|
||||||
|
|
||||||
fun bool_yes(): Boolean = true
|
fun bool_yes(): Boolean = true
|
||||||
|
|
||||||
@Test fun runTest() {
|
fun box(): String {
|
||||||
if (!bool_yes()) throw Error()
|
if (!bool_yes()) return "FAIL !bool_yes()"
|
||||||
|
|
||||||
|
return "OK"
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,10 +3,6 @@
|
|||||||
* that can be found in the LICENSE file.
|
* that can be found in the LICENSE file.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package codegen.function.defaults
|
|
||||||
|
|
||||||
import kotlin.test.*
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by minamoto on 12/26/16.
|
* 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)
|
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
|
// if: CALL 'NOT(Boolean): Boolean' type=kotlin.Boolean origin=EXCLEQ
|
||||||
// arg0: CALL 'EQEQ(Any?, Any?): 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")
|
println("A one + 1 failed")
|
||||||
throw Error()
|
throw Error()
|
||||||
}
|
}
|
||||||
println("all tests passed")
|
return "OK"
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,16 +3,15 @@
|
|||||||
* that can be found in the LICENSE file.
|
* that can be found in the LICENSE file.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package codegen.function.defaults1
|
|
||||||
|
|
||||||
import kotlin.test.*
|
import kotlin.test.*
|
||||||
|
|
||||||
fun foo(x:Int = 0, y:Int = x + 1, z:Int = x + y + 1) = x + y + z
|
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()
|
val v = foo()
|
||||||
if (v != 3) {
|
if (v != 3) {
|
||||||
println("test failed $v expected 3")
|
println("test failed $v expected 3")
|
||||||
throw Error()
|
throw Error()
|
||||||
}
|
}
|
||||||
|
return "OK"
|
||||||
}
|
}
|
||||||
@@ -3,14 +3,13 @@
|
|||||||
* that can be found in the LICENSE file.
|
* that can be found in the LICENSE file.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package codegen.function.defaults10
|
|
||||||
|
|
||||||
import kotlin.test.*
|
import kotlin.test.*
|
||||||
|
|
||||||
enum class A(one: Int, val two: Int = one) {
|
enum class A(one: Int, val two: Int = one) {
|
||||||
FOO(42)
|
FOO(42)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test fun runTest() {
|
fun box(): String {
|
||||||
println(A.FOO.two)
|
assertEquals(42, (A.FOO.two))
|
||||||
|
return "OK"
|
||||||
}
|
}
|
||||||
@@ -1 +0,0 @@
|
|||||||
42
|
|
||||||
@@ -3,17 +3,16 @@
|
|||||||
* that can be found in the LICENSE file.
|
* that can be found in the LICENSE file.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package codegen.function.defaults2
|
|
||||||
|
|
||||||
import kotlin.test.*
|
import kotlin.test.*
|
||||||
|
|
||||||
|
|
||||||
fun Int.foo(inc0:Int, inc:Int = 0) = this + inc0 + inc
|
fun Int.foo(inc0:Int, inc:Int = 0) = this + inc0 + inc
|
||||||
|
|
||||||
@Test fun runTest() {
|
fun box(): String {
|
||||||
val v = 42.foo(0)
|
val v = 42.foo(0)
|
||||||
if (v != 42) {
|
if (v != 42) {
|
||||||
println("test failed v:$v expected:42")
|
println("test failed v:$v expected:42")
|
||||||
throw Error()
|
throw Error()
|
||||||
}
|
}
|
||||||
|
return "OK"
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,14 +3,10 @@
|
|||||||
* that can be found in the LICENSE file.
|
* 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 = 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
|
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")
|
val a = foo(b="Universe")
|
||||||
if (a != "Universe-42")
|
if (a != "Universe-42")
|
||||||
throw Error()
|
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)
|
val b = foo(b = 5)
|
||||||
if (b != (/* a = */ 3 + /* b = */ 5 + /* c = */ (3 + 5)))
|
if (b != (/* a = */ 3 + /* b = */ 5 + /* c = */ (3 + 5)))
|
||||||
throw Error()
|
throw Error()
|
||||||
|
|
||||||
|
return "OK"
|
||||||
}
|
}
|
||||||
@@ -3,20 +3,23 @@
|
|||||||
* that can be found in the LICENSE file.
|
* that can be found in the LICENSE file.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package codegen.function.defaults4
|
|
||||||
|
|
||||||
import kotlin.test.*
|
import kotlin.test.*
|
||||||
|
|
||||||
|
val sb = StringBuilder()
|
||||||
|
|
||||||
open class A {
|
open class A {
|
||||||
open fun foo(x: Int = 42) = println(x)
|
open fun foo(x: Int = 42) = sb.append(x)
|
||||||
}
|
}
|
||||||
|
|
||||||
open class B : A()
|
open class B : A()
|
||||||
|
|
||||||
class C : B() {
|
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()
|
C().foo()
|
||||||
|
|
||||||
|
assertEquals("43", sb.toString())
|
||||||
|
return "OK"
|
||||||
}
|
}
|
||||||
@@ -1 +0,0 @@
|
|||||||
43
|
|
||||||
@@ -3,21 +3,24 @@
|
|||||||
* that can be found in the LICENSE file.
|
* that can be found in the LICENSE file.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package codegen.function.defaults5
|
|
||||||
|
|
||||||
import kotlin.test.*
|
import kotlin.test.*
|
||||||
|
|
||||||
|
val sb = StringBuilder()
|
||||||
|
|
||||||
class TestClass(val x: Int) {
|
class TestClass(val x: Int) {
|
||||||
fun foo(y: Int = x) {
|
fun foo(y: Int = x) {
|
||||||
println(y)
|
sb.appendLine(y)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun TestClass.bar(y: Int = x) {
|
fun TestClass.bar(y: Int = x) {
|
||||||
println(y)
|
sb.appendLine(y)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test fun runTest() {
|
fun box(): String {
|
||||||
TestClass(5).foo()
|
TestClass(5).foo()
|
||||||
TestClass(6).bar()
|
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.
|
* that can be found in the LICENSE file.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package codegen.function.defaults6
|
|
||||||
|
|
||||||
import kotlin.test.*
|
import kotlin.test.*
|
||||||
|
|
||||||
open class Foo(val x: Int = 42)
|
open class Foo(val x: Int = 42)
|
||||||
class Bar : Foo()
|
class Bar : Foo()
|
||||||
|
|
||||||
@Test fun runTest() {
|
fun box(): String {
|
||||||
println(Bar().x)
|
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