Merge boxWithStdlib testData into box, delete BoxWithStdlib test
This commit is contained in:
committed by
Alexander Udalov
parent
22bfc9786a
commit
06a67e6602
@@ -0,0 +1,36 @@
|
||||
// WITH_RUNTIME
|
||||
|
||||
fun fn0() {}
|
||||
fun fn1(x: Any) {}
|
||||
|
||||
inline fun safeAsReturnsNull(operation: String, cast: () -> Any?) {
|
||||
try {
|
||||
val x = cast()
|
||||
assert(x == null) { "$operation: should return null, got $x" }
|
||||
}
|
||||
catch (e: Throwable) {
|
||||
throw AssertionError("$operation: should not throw exceptions, got $e")
|
||||
}
|
||||
}
|
||||
|
||||
inline fun safeAsReturnsNonNull(operation: String, cast: () -> Any?) {
|
||||
try {
|
||||
val x = cast()
|
||||
assert(x != null) { "$operation: should return non-null" }
|
||||
}
|
||||
catch (e: Throwable) {
|
||||
throw AssertionError("$operation: should not throw exceptions, got $e")
|
||||
}
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
val f0 = ::fn0 as Any
|
||||
val f1 = ::fn1 as Any
|
||||
|
||||
safeAsReturnsNonNull("f0 as? Function0<*>") { f0 as? Function0<*> }
|
||||
safeAsReturnsNull("f0 as? Function1<*, *>") { f0 as? Function1<*, *> }
|
||||
safeAsReturnsNull("f1 as? Function0<*>") { f1 as? Function0<*> }
|
||||
safeAsReturnsNonNull("f1 as? Function1<*, *>") { f1 as? Function1<*, *> }
|
||||
|
||||
return "OK"
|
||||
}
|
||||
Reference in New Issue
Block a user