Add Contract tests for JS
This commit is contained in:
@@ -0,0 +1,16 @@
|
||||
class Foo(
|
||||
val width: Int,
|
||||
val height: Int,
|
||||
// This function tells the constructor which cells are alive
|
||||
// if init(i, j) is true, the cell (i, j) is alive
|
||||
init: (Int, Int) -> String
|
||||
) {
|
||||
val live: Array<Array<String>> = Array(height) { i -> Array(width) { j -> init(i, j) } }
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
|
||||
val foo = Foo(2, 2) { i, j -> if (i == j) (if (i == 0) "O" else "K") else "Fail@[$i, $j]" }
|
||||
|
||||
return foo.live[0][0] + foo.live[1][1]
|
||||
}
|
||||
+40
@@ -0,0 +1,40 @@
|
||||
// !LANGUAGE: +AllowContractsForCustomFunctions +UseCallsInPlaceEffect +ReadDeserializedContracts
|
||||
// !USE_EXPERIMENTAL: kotlin.contracts.ExperimentalContracts
|
||||
// IGNORE_BACKEND: JVM_IR
|
||||
// IGNORE_BACKEND: NATIVE
|
||||
// FILE: 1.kt
|
||||
package test
|
||||
|
||||
import kotlin.contracts.*
|
||||
|
||||
@Suppress("INVISIBLE_MEMBER", "INVISIBLE_REFERENCE")
|
||||
public inline fun <R> myrun(block: () -> R): R {
|
||||
contract {
|
||||
callsInPlace(block, InvocationKind.EXACTLY_ONCE)
|
||||
}
|
||||
return block()
|
||||
}
|
||||
|
||||
|
||||
// FILE: 2.kt
|
||||
import test.*
|
||||
|
||||
fun test(b: Boolean): Int {
|
||||
val x: Int
|
||||
|
||||
if (b) {
|
||||
x = 1
|
||||
} else {
|
||||
myrun {
|
||||
x = -1
|
||||
}
|
||||
}
|
||||
return x
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
|
||||
if (test(true) != 1) return "Fail 1"
|
||||
if (test(false) != -1) return "Fail 2"
|
||||
return "OK"
|
||||
}
|
||||
+38
@@ -0,0 +1,38 @@
|
||||
// !LANGUAGE: +AllowContractsForCustomFunctions +UseCallsInPlaceEffect +ReadDeserializedContracts
|
||||
// !USE_EXPERIMENTAL: kotlin.contracts.ExperimentalContracts
|
||||
// IGNORE_BACKEND: JVM_IR
|
||||
// IGNORE_BACKEND: NATIVE
|
||||
// NO_CHECK_LAMBDA_INLINING
|
||||
// FILE: 1.kt
|
||||
package test
|
||||
|
||||
import kotlin.contracts.*
|
||||
|
||||
@Suppress("INVISIBLE_MEMBER", "INVISIBLE_REFERENCE")
|
||||
public inline fun <R> myrun(block: () -> R): R {
|
||||
contract {
|
||||
callsInPlace(block, InvocationKind.EXACTLY_ONCE)
|
||||
}
|
||||
return block()
|
||||
}
|
||||
|
||||
|
||||
// FILE: 2.kt
|
||||
import test.*
|
||||
|
||||
class A {
|
||||
val x: String
|
||||
|
||||
constructor() {
|
||||
}
|
||||
|
||||
init {
|
||||
val o: String
|
||||
val k: String = "K"
|
||||
myrun { o = "O" }
|
||||
fun baz() = o + k
|
||||
x = baz()
|
||||
}
|
||||
}
|
||||
|
||||
fun box() = A().x
|
||||
@@ -1,6 +1,7 @@
|
||||
// !LANGUAGE: +AllowContractsForCustomFunctions +UseCallsInPlaceEffect +ReadDeserializedContracts
|
||||
// !USE_EXPERIMENTAL: kotlin.contracts.ExperimentalContracts
|
||||
// IGNORE_BACKEND: JVM_IR
|
||||
// IGNORE_BACKEND: JS_IR
|
||||
// IGNORE_BACKEND: NATIVE
|
||||
// FILE: 1.kt
|
||||
package test
|
||||
|
||||
Reference in New Issue
Block a user