Files
kotlin-fork/js/js.translator/testData/patternMatching/cases/ifInWhen.kt
T
Zalim Bashorov 7b503bbe6f Minor in JS backend: added regression tests.
#{KT-2219, KT-2470, KT-2507, KT-2222, KT-2995, KT-2221} Obsolete
2014-03-13 22:57:41 +04:00

25 lines
520 B
Kotlin

// KT-2221 if in when
package foo
fun test(caseId: Int, value: Int, expected: Int) {
val actual: Int
when (caseId) {
0 -> if (value < 0) actual = -value else actual = value
1 -> actual = if (value < 0) -value else value
else -> throw Exception("Unexpected case: $caseId")
}
if (expected != actual) throw Exception("expected = $expected, actual = $actual")
}
fun box(): String {
test(0, 3, 3)
test(0, -13, 13)
test(1, 23, 23)
test(1, -3, 3)
return "OK"
}