commonMain.com.bkahlert.kommons.test.testAll.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of kommons-test Show documentation
Show all versions of kommons-test Show documentation
Kommons Test is a Kotlin Multiplatform Library to ease testing.
package com.bkahlert.kommons.test
import io.kotest.inspectors.forAll
/** Asserts the specified [softAssertions] for each of the specified [subjects]. */
public inline fun testAll(vararg subjects: T, softAssertions: (T) -> R) {
subjects.asList().testAll(softAssertions)
}
/** Asserts the specified [softAssertions] for each element of this [Collection]. */
public inline fun Iterable.testAll(softAssertions: (T) -> R) {
val subjects = toList()
require(subjects.isNotEmpty()) { "At least one subject must be provided for testing." }
subjects.forAll {
test { softAssertions(it) }
}
}
/** Asserts the specified [softAssertions] for each element of this [Sequence]. */
public inline fun Sequence.testAll(softAssertions: (T) -> R) {
toList().testAll(softAssertions)
}
/** Asserts the specified [softAssertions] for each entry of this [Map]. */
public inline fun Map.testAll(softAssertions: (Map.Entry) -> R) {
entries.testAll(softAssertions)
}