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.assertions.assertSoftly
import io.kotest.inspectors.forAll
/** Asserts the specified [softAssertions]. */
public inline fun testAll(softAssertions: () -> Unit) {
assertSoftly(softAssertions)
}
/** Asserts the specified [softAssertions] for each of the specified [subjects]. */
public inline fun testAll(subject: T, vararg subjects: T, softAssertions: (T) -> Unit) {
listOf(subject, *subjects).testAll(softAssertions)
}
/** Asserts the specified [softAssertions] for each of this [Array]. */
public inline fun Array.testAll(softAssertions: (T) -> Unit) {
asList().testAll(softAssertions)
}
/** Asserts the specified [softAssertions] for each element of this [Collection]. */
public inline fun Iterable.testAll(softAssertions: (T) -> Unit) {
val subjects = toList()
require(subjects.isNotEmpty()) { "At least one subject must be provided for testing." }
subjects.forAll {
com.bkahlert.kommons.test.testAll { softAssertions(it) }
}
}
/** Asserts the specified [softAssertions] for each element of this [Sequence]. */
public inline fun Sequence.testAll(softAssertions: (T) -> Unit) {
toList().testAll(softAssertions)
}
/** Asserts the specified [softAssertions] for each entry of this [Map]. */
public inline fun Map.testAll(softAssertions: (Map.Entry) -> Unit) {
entries.testAll(softAssertions)
}