kotlin-test: make assertIs<T> returning value cast to T KT-45296
This commit is contained in:
@@ -87,9 +87,10 @@ fun <@OnlyInputTypes T> assertNotSame(illegal: T, actual: T, message: String? =
|
|||||||
@SinceKotlin("1.5")
|
@SinceKotlin("1.5")
|
||||||
@InlineOnly
|
@InlineOnly
|
||||||
@OptIn(ExperimentalStdlibApi::class)
|
@OptIn(ExperimentalStdlibApi::class)
|
||||||
inline fun <reified T> assertIs(value: Any?, message: String? = null) {
|
inline fun <reified T> assertIs(value: Any?, message: String? = null): T {
|
||||||
contract { returns() implies (value is T) }
|
contract { returns() implies (value is T) }
|
||||||
assertIsOfType(value, typeOf<T>(), value is T, message)
|
assertIsOfType(value, typeOf<T>(), value is T, message)
|
||||||
|
return value as T
|
||||||
}
|
}
|
||||||
|
|
||||||
@PublishedApi
|
@PublishedApi
|
||||||
|
|||||||
+3
-1
@@ -210,8 +210,10 @@ class BasicAssertionsTest {
|
|||||||
@Test
|
@Test
|
||||||
fun testAssertIsOfType() {
|
fun testAssertIsOfType() {
|
||||||
val s: Any = "test"
|
val s: Any = "test"
|
||||||
assertIs<String>(s)
|
val result = assertIs<String>(s)
|
||||||
assertEquals(4, s.length)
|
assertEquals(4, s.length)
|
||||||
|
assertEquals(s, result)
|
||||||
|
assertEquals(4, result.length)
|
||||||
}
|
}
|
||||||
|
|
||||||
@OptIn(ExperimentalStdlibApi::class)
|
@OptIn(ExperimentalStdlibApi::class)
|
||||||
|
|||||||
Reference in New Issue
Block a user