
commonMain.io.kotest.matchers.collections.empty.kt Maven / Gradle / Ivy
package io.kotest.matchers.collections
import io.kotest.assertions.show.show
import io.kotest.matchers.Matcher
import io.kotest.matchers.MatcherResult
import io.kotest.matchers.invokeMatcher
import io.kotest.matchers.should
import io.kotest.matchers.shouldNot
fun Iterable?.shouldBeEmpty(): Iterable {
if (this == null) fail()
toList().shouldBeEmpty()
return this
}
fun Array?.shouldBeEmpty(): Array {
if (this == null) fail()
asList().shouldBeEmpty()
return this
}
fun Collection?.shouldBeEmpty(): Collection {
if (this == null) fail()
this should beEmpty()
return this
}
fun Iterable?.shouldNotBeEmpty(): Iterable {
if (this == null) fail()
toList().shouldNotBeEmpty()
return this
}
fun Array?.shouldNotBeEmpty(): Array {
if (this == null) fail()
asList().shouldNotBeEmpty()
return this
}
fun Collection?.shouldNotBeEmpty(): Collection {
if (this == null) fail()
this shouldNot beEmpty()
return this
}
fun beEmpty(): Matcher> = object : Matcher> {
override fun test(value: Collection): MatcherResult = MatcherResult(
value.isEmpty(),
{ "Collection should be empty but contained ${value.show().value}" },
{ "Collection should not be empty" }
)
}
private fun fail(): Nothing {
invokeMatcher(null, Matcher.failure("Should be empty but was null"))
throw NotImplementedError()
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy