
jvmMain.io.kotest.matchers.reflection.compose.kt Maven / Gradle / Ivy
package io.kotest.matchers.reflection
import io.kotest.matchers.Matcher
import io.kotest.matchers.MatcherResult
import kotlin.reflect.KProperty1
@Suppress("UNCHECKED_CAST")
fun Matcher.Companion.compose(
vararg pairs: Pair, KProperty1>
): Matcher = object : Matcher {
override fun test(value: T): MatcherResult {
val results = pairs.map { (matcher, prop) ->
(matcher as Matcher).test(prop.get(value))
}
return MatcherResult(
results.all { it.passed() },
{
results.map { it.failureMessage() }.fold("") { acc: String, s: String -> acc + s + "\n" }
.trimIndent()
},
{
results.map { it.negatedFailureMessage() }.fold("") { acc: String, s: String -> acc + s + "\n" }
.trimIndent()
},
)
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy