Best Kotest code snippet using io.kotest.assertions.print.platformPrint.platformPrint
Print.kt
Source:Print.kt
...42/**43 * Returns a [Print] for this non-null value by delegating to platform specific, or commonly44 * registered typeclasses. If neither matches, then the default [ToStringPrint] is returned.45 */46fun <A : Any> printFor(a: A): Print<A> = platformPrint(a) ?: commonPrintFor(a) ?: ToStringPrint47/**48 * Returns a [Print] instance if one exists in the platform specific [Print]s.49 */50expect fun <A : Any> platformPrint(a: A): Print<A>?51/**52 * Returns a [Print] instance if one exists in the common or registered [Print]s.53 */54fun <A : Any> commonPrintFor(a: A): Print<A>? {55 val key: KClass<*>? = Printers.all().keys.firstOrNull { it.isInstance(a) }56 if (key != null) {57 val print: Print<*>? = Printers.all()[key]58 return print as Print<A>59 }60 return null61 // this won't work in JS or native, so they'll get the boring old toString version62// if (io.kotest.mpp.reflection.isDataClass(a::class) && reflection.isPublic(a::class)) return dataClassPrint()63// return null64}...
platformPrint.kt
Source:platformPrint.kt
...15 * or [FilePrint] if [A] is `java.io.File`,16 * or `null` otherwise.17 */18@Suppress("UNCHECKED_CAST")19actual fun <A : Any> platformPrint(a: A): Print<A>? = when {20 javaNioPathKlass()?.isInstance(a) ?: false -> PathPrint as Print<A>21 javaIoFileKlass()?.isInstance(a) ?: false -> FilePrint as Print<A>22 else -> null23}24private fun javaNioPathKlass(): KClass<*>? = try {25 /*26 * There is no KClass reflection API to find a27 * class by string so the Java Class Reflection28 * API must be used.29 * See https://youtrack.jetbrains.com/issue/KT-1044030 */31 Class.forName("java.nio.file.Path").kotlin32} catch (_: ClassNotFoundException) {33 // ignore Path as it may not exist on Android....
printers.kt
Source:printers.kt
1package io.kotest.assertions.print2// js doesn't support full reflection so we just need to delegate to the instances toString3actual fun <A : Any> dataClassPrint(): Print<A> = ToStringPrint4actual fun <A : Any> platformPrint(a: A): Print<A>? = null...
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!