Files
kotlin-fork/compiler/testData/codegen/box/when/stringOptimization/flexibleNullability.kt
T
Ivan Kylchik c7435ba760 Replace all occurrences of WITH_RUNTIME with WITH_STDLIB
We are going to deprecate `WITH_RUNTIME` directive. The main reason
behind this change is that `WITH_STDLIB` directive better describes
its meaning, specifically it will add kotlin stdlib to test's classpath.
2021-11-17 15:26:38 +03:00

72 lines
1.2 KiB
Kotlin
Vendored

// TARGET_BACKEND: JVM
// WITH_STDLIB
// FILE: flexibleNullability.kt
fun testEmpty() {
when (J.nullString()) {
}
}
fun testSingle() {
var q = "other"
when (J.nullString()) {
"a" -> q = "A"
}
if (q != "other") {
throw Exception("Expected 'other', got '$q'")
}
}
fun testElseOnly() {
var q = "other"
when (J.nullString()) {
else -> q = "A"
}
if (q != "A") {
throw Exception("Expected: 'A', got '$q'")
}
}
fun testSmall() {
val q = when (J.nullString()) {
"a" -> "A"
else -> "other"
}
if (q != "other") {
throw Exception("Expected 'other', got '$q'")
}
}
fun testBigger() {
val q = when (J.nullString()) {
"a" -> "A"
"b" -> "B"
"c" -> "C"
"d" -> "D"
"e" -> "E"
"f" -> "F"
"g" -> "G"
"h" -> "H"
else -> "other"
}
if (q != "other") {
throw Exception("Expected 'other', got '$q'")
}
}
fun box(): String {
testEmpty()
testSingle()
testElseOnly()
testSmall()
testBigger()
return "OK"
}
// FILE: J.java
public class J {
public static String nullString() { return null; }
}