Extract some codegen tests to black box testData

This commit is contained in:
Alexander Udalov
2013-01-27 20:01:55 +04:00
committed by Alexander Udalov
parent f7e0b06c2f
commit 10c5949199
12 changed files with 103 additions and 136 deletions
@@ -0,0 +1,5 @@
fun StringBuilder.first() = this.charAt(0)
fun foo() = StringBuilder("foo").first()
fun box() = if (foo() == 'f') "OK" else "Fail ${foo()}"
@@ -0,0 +1,24 @@
fun StringBuilder.takeFirst(): Char {
if (this.length() == 0) return 0.toChar()
val c = this.charAt(0)
this.deleteCharAt(0)
return c
}
fun foo(expr: StringBuilder): Int {
val c = expr.takeFirst()
when(c) {
0.toChar() -> throw Exception("zero")
else -> throw Exception("nonzero" + c)
}
}
fun box(): String {
try {
foo(StringBuilder())
return "Fail"
}
catch (e: Exception) {
return "OK"
}
}