[K/N][Tests] Move some codegen tests to new infra: annotations..coroutines

^KT-61259
This commit is contained in:
Vladimir Sukharev
2023-12-12 13:30:53 +01:00
committed by Space Team
parent a1d13f54cb
commit a5f3d5b737
269 changed files with 2207 additions and 0 deletions
@@ -0,0 +1,47 @@
import kotlin.test.*
import kotlin.contracts.*
open class S
class P(val str: String = "P") : S()
@OptIn(kotlin.contracts.ExperimentalContracts::class)
fun check(actual: Boolean) {
contract { returns() implies actual }
assertTrue(actual)
}
@Test fun testContractForCast() {
val s: S = P()
check(s is P)
assertEquals(s.str, "P")
}
@Test fun testRequire() {
val s: S = P()
require(s is P)
assertEquals(s.str, "P")
}
@Test fun testNonNullSmartCast() {
val i: Int? = 1234
requireNotNull(i)
assertEquals(i, 1234)
}
@Test fun testRunLambdaForVal() {
val x: Int
run {
x = 42
}
assertEquals(x, 42)
}
@Test fun testIsNullString() {
assertEquals("STR", nullableString("str"))
assertEquals("", nullableString(null))
}
private fun nullableString(string: String?): String = if (string.isNullOrBlank()) "" else "STR"