TEST: tests for safe cast added

This commit is contained in:
Konstantin Anisimov
2016-11-28 12:04:30 +03:00
committed by vvlevchenko
parent c35af302b0
commit 837ae60eaf
2 changed files with 29 additions and 0 deletions
+6
View File
@@ -241,6 +241,12 @@ task check_type(type: UnitKonanTest) {
source = "codegen/basics/check_type.kt"
}
task safe_cast(type: RunKonanTest) {
goldValue = "safe_cast_positive: true\n" +
"safe_cast_negative: true\n"
source = "codegen/basics/safe_cast.kt"
}
task aritmetic(type: UnitKonanTest) {
source = "codegen/function/arithmetic.kt"
}
@@ -0,0 +1,23 @@
open class A
class B : A()
class C
fun foo(a: Any) : A? = a as? A
fun safe_cast_positive(): Boolean {
val b = B()
return foo(b) === b
}
fun safe_cast_negative(): Boolean {
val c = C()
return foo(c) == null
}
fun main(args: Array<String>) {
val safeCastPositive = safe_cast_positive().toString()
val safeCastNegative = safe_cast_negative().toString()
println("safe_cast_positive: " + safeCastPositive)
println("safe_cast_negative: " + safeCastNegative)
}