Add ir interpreter tests
This commit is contained in:
committed by
TeamCityServer
parent
cc2d7340dc
commit
e28ab45c51
@@ -0,0 +1,48 @@
|
||||
@CompileTimeCalculation
|
||||
class A
|
||||
|
||||
@CompileTimeCalculation
|
||||
fun notNullAssertion(value: Int?): String {
|
||||
return try {
|
||||
value!!
|
||||
"Value isn't null"
|
||||
} catch (e: NullPointerException) {
|
||||
"Value is null"
|
||||
}
|
||||
}
|
||||
|
||||
@CompileTimeCalculation
|
||||
fun notNullAssertionForObject(value: A?): String {
|
||||
return try {
|
||||
value!!
|
||||
"Value isn't null"
|
||||
} catch (e: NullPointerException) {
|
||||
"Value is null"
|
||||
}
|
||||
}
|
||||
|
||||
@CompileTimeCalculation
|
||||
fun notNullAssertionForSomeWrapper(value: StringBuilder?): String {
|
||||
return try {
|
||||
value!!.toString()
|
||||
} catch (e: NullPointerException) {
|
||||
"Value is null"
|
||||
}
|
||||
}
|
||||
|
||||
@CompileTimeCalculation
|
||||
fun notNullLambda(lambda: (() -> String)?): String {
|
||||
return when {
|
||||
lambda != null -> lambda()
|
||||
else -> "Lambda is null"
|
||||
}
|
||||
}
|
||||
|
||||
const val a1 = <!EVALUATED: `Value isn't null`!>notNullAssertion(1)<!>
|
||||
const val a2 = <!EVALUATED: `Value is null`!>notNullAssertion(null)<!>
|
||||
const val b1 = <!EVALUATED: `Value isn't null`!>notNullAssertionForObject(A())<!>
|
||||
const val b2 = <!EVALUATED: `Value is null`!>notNullAssertionForObject(null)<!>
|
||||
const val c1 = <!EVALUATED: `Some text`!>notNullAssertionForSomeWrapper(StringBuilder("Some text"))<!>
|
||||
const val c2 = <!EVALUATED: `Value is null`!>notNullAssertionForSomeWrapper(null)<!>
|
||||
const val d1 = <!EVALUATED: `Not null lambda`!>notNullLambda { "Not null lambda" }<!>
|
||||
const val d2 = <!EVALUATED: `Lambda is null`!>notNullLambda(null)<!>
|
||||
Reference in New Issue
Block a user