tests: Update external tests (1.1.2-dev-393)
This commit is contained in:
+61
@@ -0,0 +1,61 @@
|
||||
// FILE: 1.kt
|
||||
// WITH_RUNTIME
|
||||
package test
|
||||
|
||||
inline public fun String.run(p1: String? = null): String {
|
||||
return this + p1
|
||||
}
|
||||
|
||||
inline public fun String.run(p1: String = "", lambda: (a: String, b: Int) -> String, p2: Int = 0): String {
|
||||
return lambda(p1, p2) + this
|
||||
}
|
||||
|
||||
public class Z(val value: Int = 0) {
|
||||
|
||||
inline public fun String.run(p1: String? = null): String? {
|
||||
return this + p1
|
||||
}
|
||||
|
||||
inline public fun String.run(p1: String = "", lambda: (a: String, b: Int) -> String, p2: Int = 0): String {
|
||||
return lambda(p1, p2) + this
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// FILE: 2.kt
|
||||
|
||||
import test.*
|
||||
|
||||
fun testExtensionInClass() : String {
|
||||
|
||||
var res = with(Z(1)) { "1".run("OK") }
|
||||
if (res != "1OK") return "failed in class 1: $res"
|
||||
|
||||
res = with(Z(1)) { "1".run() }
|
||||
if (res != "1null") return "failed in class 2: $res"
|
||||
|
||||
res = with(Z(2)) { "3".run("OK", { a, b -> a + b + value }, 1) }
|
||||
if (res != "OK123") return "failed in class 3: $res"
|
||||
|
||||
res = with(Z(3)) { "4".run(lambda = { a, b -> a + b + value }) }
|
||||
if (res != "034") return "failed in class 4: $res"
|
||||
|
||||
return "OK"
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
|
||||
var res = "1".run("OK")
|
||||
if (res != "1OK") return "failed 1: $res"
|
||||
|
||||
res = "1".run()
|
||||
if (res != "1null") return "failed 2: $res"
|
||||
|
||||
res = "3".run("OK", { a, b -> a + b}, 1)
|
||||
if (res != "OK13") return "failed 3: $res"
|
||||
|
||||
res = "4".run(lambda = { a, b -> a + b})
|
||||
if (res != "04") return "failed 4: $res"
|
||||
|
||||
return testExtensionInClass()
|
||||
}
|
||||
+38
@@ -0,0 +1,38 @@
|
||||
// FILE: 1.kt
|
||||
|
||||
package test
|
||||
|
||||
|
||||
inline fun <T> simpleFun(arg: String = "O", lambda: (String) -> T): T {
|
||||
return lambda(arg)
|
||||
}
|
||||
|
||||
|
||||
inline fun <T> simpleFunR(lambda: (String) -> T, arg: String = "O"): T {
|
||||
return lambda(arg)
|
||||
}
|
||||
|
||||
// FILE: 2.kt
|
||||
|
||||
import test.*
|
||||
|
||||
fun simple(): String {
|
||||
val k = "K"
|
||||
return simpleFun(lambda = {it + "O"}) + simpleFun("K", {k + it})
|
||||
}
|
||||
|
||||
fun simpleR(): String {
|
||||
val k = "K"
|
||||
return simpleFunR({it + "O"}) + simpleFunR({k + it}, "K")
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
|
||||
var result = simple()
|
||||
if (result != "OOKK") return "fail1: ${result}"
|
||||
|
||||
result = simpleR()
|
||||
if (result != "OOKK") return "fail2: ${result}"
|
||||
|
||||
return "OK"
|
||||
}
|
||||
+31
@@ -0,0 +1,31 @@
|
||||
// FILE: 1.kt
|
||||
|
||||
package test
|
||||
|
||||
public class Z(public val value: Int = 0) {
|
||||
|
||||
inline public fun run(p1: String? = null): String? {
|
||||
return p1 + value
|
||||
}
|
||||
|
||||
|
||||
inline public fun run(p1: String = "", lambda: (a: String, b: Int) -> String, p2: Int = 0): String {
|
||||
return lambda(p1, p2)
|
||||
}
|
||||
}
|
||||
|
||||
// FILE: 2.kt
|
||||
|
||||
import test.*
|
||||
|
||||
fun box(): String {
|
||||
if (Z().run() != "null0") return "fail 1: ${Z().run()}"
|
||||
|
||||
if (Z().run("OK") != "OK0") return "fail 2"
|
||||
|
||||
if (Z().run("OK", { a, b -> a + b }, 1) != "OK1") return "fail 3"
|
||||
|
||||
if (Z().run(lambda = { a: String, b: Int -> a + b }) != "0") return "fail 4"
|
||||
|
||||
return "OK"
|
||||
}
|
||||
+19
@@ -0,0 +1,19 @@
|
||||
// FILE: 1.kt
|
||||
|
||||
package test
|
||||
|
||||
inline fun a(s1: String = "s1", s2: String = "s2", body: (a1: String, a2: String) -> String) = body(s1, s2)
|
||||
|
||||
inline fun String.b(body: (a1: String, a2: String) -> String) = a(s2 = this, body = body)
|
||||
|
||||
// FILE: 2.kt
|
||||
|
||||
import test.*
|
||||
|
||||
fun box(): String {
|
||||
val z = "OK".b { a, b ->
|
||||
a + b
|
||||
}
|
||||
|
||||
return if (z == "s1OK") "OK" else "fail $z"
|
||||
}
|
||||
+36
@@ -0,0 +1,36 @@
|
||||
// FILE: 1.kt
|
||||
|
||||
package test
|
||||
|
||||
inline fun getStringInline(): String {
|
||||
return "OK"
|
||||
}
|
||||
|
||||
// FILE: 2.kt
|
||||
|
||||
import test.*
|
||||
|
||||
fun testCompilation(arg: String = getStringInline()): String {
|
||||
return arg
|
||||
}
|
||||
|
||||
inline fun testCompilationInline(arg: String = getStringInline()): String {
|
||||
return arg
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
var result = testCompilation()
|
||||
if (result != "OK") return "fail1: ${result}"
|
||||
|
||||
result = testCompilation("OKOK")
|
||||
if (result != "OKOK") return "fail2: ${result}"
|
||||
|
||||
|
||||
result = testCompilationInline()
|
||||
if (result != "OK") return "fail3: ${result}"
|
||||
|
||||
result = testCompilationInline("OKOK")
|
||||
if (result != "OKOK") return "fail4: ${result}"
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
// FILE: 1.kt
|
||||
package test
|
||||
|
||||
inline fun log(lazyMessage: () -> Any?) {
|
||||
lazyMessage()
|
||||
}
|
||||
|
||||
// FILE: 2.kt
|
||||
|
||||
import test.*
|
||||
|
||||
inline fun getOrCreate(
|
||||
z : Boolean = false,
|
||||
s: () -> String
|
||||
) {
|
||||
log { s() }
|
||||
}
|
||||
|
||||
|
||||
fun box(): String {
|
||||
var z = "fail"
|
||||
getOrCreate { z = "OK"; z }
|
||||
|
||||
return z
|
||||
}
|
||||
Vendored
+30
@@ -0,0 +1,30 @@
|
||||
// FILE: 1.kt
|
||||
package test
|
||||
|
||||
inline fun log(lazyMessage: () -> Any?) {
|
||||
lazyMessage()
|
||||
}
|
||||
|
||||
inline fun z(): Boolean {
|
||||
"zzz"
|
||||
return true
|
||||
}
|
||||
|
||||
// FILE: 2.kt
|
||||
|
||||
import test.*
|
||||
|
||||
inline fun getOrCreate(
|
||||
z : Boolean = z(),
|
||||
s: () -> String
|
||||
) {
|
||||
log { s() }
|
||||
}
|
||||
|
||||
|
||||
fun box(): String {
|
||||
var z = "fail"
|
||||
getOrCreate { z = "OK"; z }
|
||||
|
||||
return z
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
// FILE: 1.kt
|
||||
|
||||
package test
|
||||
|
||||
class Measurements
|
||||
{
|
||||
inline fun measure(key: String, logEvery: Long = -1, divisor: Int = 1, body: () -> Unit): String {
|
||||
body()
|
||||
return key
|
||||
}
|
||||
}
|
||||
|
||||
// FILE: 2.kt
|
||||
|
||||
import test.*
|
||||
|
||||
fun box(): String {
|
||||
var s1 = ""
|
||||
val s2 = Measurements().measure("K") {
|
||||
s1 = "O"
|
||||
}
|
||||
|
||||
return s1 + s2
|
||||
}
|
||||
+46
@@ -0,0 +1,46 @@
|
||||
// FILE: 1.kt
|
||||
|
||||
package test
|
||||
|
||||
inline fun emptyFun(arg: String = "O") {
|
||||
|
||||
}
|
||||
|
||||
inline fun simpleFun(arg: String = "O"): String {
|
||||
val r = arg;
|
||||
return r;
|
||||
}
|
||||
|
||||
|
||||
inline fun simpleDoubleFun(arg: Double = 1.0): Double {
|
||||
val r = arg + 1;
|
||||
return r;
|
||||
}
|
||||
|
||||
// FILE: 2.kt
|
||||
|
||||
import test.*
|
||||
|
||||
fun testCompilation(): String {
|
||||
emptyFun()
|
||||
emptyFun("K")
|
||||
|
||||
return "OK"
|
||||
}
|
||||
|
||||
fun simple(): String {
|
||||
return simpleFun() + simpleFun("K")
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
var result = testCompilation()
|
||||
if (result != "OK") return "fail1: ${result}"
|
||||
|
||||
result = simple()
|
||||
if (result != "OK") return "fail2: ${result}"
|
||||
|
||||
var result2 = simpleDoubleFun(2.0)
|
||||
if (result2 != 2.0 + 1.0) return "fail3: ${result2}"
|
||||
|
||||
return "OK"
|
||||
}
|
||||
Reference in New Issue
Block a user