
commonMain.io.kotest.matchers.collections.containAll.kt Maven / Gradle / Ivy
package io.kotest.matchers.collections
import io.kotest.matchers.Matcher
import io.kotest.matchers.MatcherResult
import io.kotest.matchers.should
import io.kotest.matchers.shouldNot
fun Iterable.shouldContainAll(vararg ts: T) = toList().shouldContainAll(ts)
fun Array.shouldContainAll(vararg ts: T) = asList().shouldContainAll(ts)
fun Collection.shouldContainAll(vararg ts: T) = this should containAll(*ts)
infix fun Iterable.shouldContainAll(ts: Collection) = toList().shouldContainAll(ts)
infix fun Array.shouldContainAll(ts: Collection) = asList().shouldContainAll(ts)
infix fun Collection.shouldContainAll(ts: Collection) = this should containAll(ts)
fun Iterable.shouldNotContainAll(vararg ts: T) = toList().shouldNotContainAll(ts)
fun Array.shouldNotContainAll(vararg ts: T) = asList().shouldNotContainAll(ts)
fun Collection.shouldNotContainAll(vararg ts: T) = this shouldNot containAll(*ts)
infix fun Iterable.shouldNotContainAll(ts: Collection) = toList().shouldNotContainAll(ts)
infix fun Array.shouldNotContainAll(ts: Collection) = asList().shouldNotContainAll(ts)
infix fun Collection.shouldNotContainAll(ts: Collection) = this shouldNot containAll(ts)
fun containAll(vararg ts: T) = containAll(ts.asList())
fun containAll(ts: Collection): Matcher> = object : Matcher> {
override fun test(value: Collection): MatcherResult {
val missing = ts.filterNot { value.contains(it) }
val passed = missing.isEmpty()
val failure =
{ "Collection should contain all of ${ts.printed().value} but was missing ${missing.printed().value}" }
val negFailure = { "Collection should not contain all of ${ts.printed().value}" }
return MatcherResult(passed, failure, negFailure)
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy