aboutsummaryrefslogtreecommitdiff
path: root/testApi/src/main/kotlin/org/jetbrains/dokka
diff options
context:
space:
mode:
Diffstat (limited to 'testApi/src/main/kotlin/org/jetbrains/dokka')
-rw-r--r--testApi/src/main/kotlin/org/jetbrains/dokka/testApi/utils/assertIsInstance.kt17
1 files changed, 17 insertions, 0 deletions
diff --git a/testApi/src/main/kotlin/org/jetbrains/dokka/testApi/utils/assertIsInstance.kt b/testApi/src/main/kotlin/org/jetbrains/dokka/testApi/utils/assertIsInstance.kt
new file mode 100644
index 00000000..00c00ebb
--- /dev/null
+++ b/testApi/src/main/kotlin/org/jetbrains/dokka/testApi/utils/assertIsInstance.kt
@@ -0,0 +1,17 @@
+package org.jetbrains.dokka.testApi.utils
+
+import kotlin.contracts.ExperimentalContracts
+import kotlin.contracts.contract
+
+@OptIn(ExperimentalContracts::class)
+inline fun <reified T> assertIsInstance(obj: Any?): T {
+ contract {
+ returns() implies (obj is T)
+ }
+
+ if (obj is T) {
+ return obj
+ }
+
+ throw AssertionError("Expected instance of type ${T::class.qualifiedName} but found $obj")
+}