backend/tests: Add blackbox tests from Kotlin JVM
Added tests from testData/codegen/box directory. There are blackbox tests in other directories and they are to be added.
This commit is contained in:
@@ -0,0 +1,8 @@
|
||||
// TODO: muted automatically, investigate should it be ran for JS or not
|
||||
// IGNORE_BACKEND: JS
|
||||
|
||||
fun foo() {}
|
||||
|
||||
fun box(): String {
|
||||
return if (foo() == Unit) "OK" else "Fail"
|
||||
}
|
||||
+8
@@ -0,0 +1,8 @@
|
||||
fun isNull(x: Unit?) = x == null
|
||||
|
||||
fun box(): String {
|
||||
val closure: () -> Unit? = { null }
|
||||
if (!isNull(closure())) return "Fail 1"
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
class A (val p: String, p1: String, p2: String) {
|
||||
|
||||
var cond1: String = ""
|
||||
|
||||
var cond2: String = ""
|
||||
|
||||
val prop1 = if (cond1(p)) p1 else null
|
||||
|
||||
val prop2 = if (cond2(p)) p2 else null;
|
||||
|
||||
|
||||
fun cond1(p: String): Boolean {
|
||||
cond1 = "cond1"
|
||||
return p == "test"
|
||||
}
|
||||
|
||||
fun cond2(p: String): Boolean {
|
||||
cond2 = "cond2"
|
||||
return p == "test"
|
||||
}
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
val a = A("test", "OK", "fail")
|
||||
|
||||
if (a.cond1 != "cond1") return "fail 2 : ${a.cond1}"
|
||||
|
||||
if (a.cond2 != "cond2") return "fail 3 : ${a.cond2}"
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
val c = Unit
|
||||
val d = c
|
||||
|
||||
fun box(): String {
|
||||
c
|
||||
d
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
// TODO: muted automatically, investigate should it be ran for JS or not
|
||||
// IGNORE_BACKEND: JS
|
||||
|
||||
fun foo(): Any? = bar()
|
||||
|
||||
fun bar() {}
|
||||
|
||||
fun baz(): Any? {
|
||||
return bar()
|
||||
}
|
||||
|
||||
fun quux(): Unit? = bar()
|
||||
|
||||
fun box(): String {
|
||||
foo()
|
||||
|
||||
if (foo() != Unit) return "Fail 1"
|
||||
if (foo() != bar()) return "Fail 2"
|
||||
if (bar() != baz()) return "Fail 3"
|
||||
if (baz() != quux()) return "Fail 4"
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
fun <T : Any, R> T.let(f: (T) -> R): R = f(this)
|
||||
|
||||
fun box(): String {
|
||||
val o: String? = null
|
||||
|
||||
var state = 0
|
||||
|
||||
o?.let {
|
||||
state = 1
|
||||
} ?: ({ state = 2 })()
|
||||
|
||||
if (state != 2) return "Fail: $state"
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
fun isNull(x: Unit?) = x == null
|
||||
|
||||
fun <T : Any> isNullGeneric(x: T?) = x == null
|
||||
|
||||
fun deepIsNull0(x: Unit?) = isNull(x)
|
||||
fun deepIsNull(x: Unit?) = deepIsNull0(x)
|
||||
|
||||
fun box(): String {
|
||||
if (!isNull(null)) return "Fail 1"
|
||||
|
||||
val x: Unit? = null
|
||||
if (!isNull(x)) return "Fail 2"
|
||||
|
||||
val y = x
|
||||
if (!isNullGeneric(y)) return "Fail 3"
|
||||
|
||||
if (!deepIsNull(x ?: null)) return "Fail 4"
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
fun foo() {}
|
||||
|
||||
fun box(): String {
|
||||
when ("A") {
|
||||
"B" -> foo()
|
||||
else -> null
|
||||
}
|
||||
|
||||
foo()
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
fun foo() {}
|
||||
|
||||
fun box(): String {
|
||||
when ("A") {
|
||||
"B" -> null
|
||||
else -> foo()
|
||||
}
|
||||
|
||||
foo()
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
fun foo() {}
|
||||
|
||||
fun box(): String {
|
||||
val x = when ("A") {
|
||||
"B" -> foo()
|
||||
else -> null
|
||||
}
|
||||
|
||||
foo()
|
||||
|
||||
return if (x == null) "OK" else "Fail"
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fun box(): String {
|
||||
Unit
|
||||
|
||||
val a = Unit
|
||||
val b = Unit
|
||||
if (a != b) return "Fail a != b"
|
||||
|
||||
if (Unit != Unit) return "Fail Unit != Unit"
|
||||
|
||||
return "OK"
|
||||
}
|
||||
Reference in New Issue
Block a user