Files
kotlin/compiler/testData/codegen/boxWithStdlib/whenStringOptimization/statement.kt
Denis Zharkov d4cb822ee8 When by String constants:
Generate TABLESWITCH/LOOKUPSWITCH bytecode operation for when operator by String constants
2014-07-21 17:13:56 +04:00

39 lines
831 B
Kotlin

import kotlin.test.assertEquals
fun foo1(x : String) : String {
when (x) {
"abc", "cde" -> return "abc_cde"
"efg", "ghi" -> return "efg_ghi"
}
return "other"
}
fun foo2(x : String) : String {
when (x) {
"abc", "cde" -> return "abc_cde"
"efg", "ghi" -> return "efg_ghi"
else -> return "other"
}
}
fun box() : String {
//foo1
assertEquals("abc_cde", foo1("abc"))
assertEquals("abc_cde", foo1("cde"))
assertEquals("efg_ghi", foo1("efg"))
assertEquals("efg_ghi", foo1("ghi"))
assertEquals("other", foo1("xyz"))
//foo2
assertEquals("abc_cde", foo2("abc"))
assertEquals("abc_cde", foo2("cde"))
assertEquals("efg_ghi", foo2("efg"))
assertEquals("efg_ghi", foo2("ghi"))
assertEquals("other", foo2("xyz"))
return "OK"
}