
commonMain.io.kotest.matchers.collections.nulls.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.shouldContainOnlyNulls(): Iterable {
toList().shouldContainOnlyNulls()
return this
}
fun Array.shouldContainOnlyNulls(): Array {
asList().shouldContainOnlyNulls()
return this
}
fun Collection.shouldContainOnlyNulls(): Collection {
this should containOnlyNulls()
return this
}
fun Iterable.shouldNotContainOnlyNulls(): Iterable {
toList().shouldNotContainOnlyNulls()
return this
}
fun Array.shouldNotContainOnlyNulls(): Array {
asList().shouldNotContainOnlyNulls()
return this
}
fun Collection.shouldNotContainOnlyNulls(): Collection {
this shouldNot containOnlyNulls()
return this
}
fun containOnlyNulls() = object : Matcher> {
override fun test(value: Collection) =
MatcherResult(
value.all { it == null },
{ "Collection should contain only nulls" },
{
"Collection should not contain only nulls"
})
}
fun Iterable.shouldContainNull(): Iterable {
toList().shouldContainNull()
return this
}
fun Array.shouldContainNull(): Array {
asList().shouldContainNull()
return this
}
fun Collection.shouldContainNull(): Collection {
this should containNull()
return this
}
fun Iterable.shouldNotContainNull(): Iterable {
toList().shouldNotContainNull()
return this
}
fun Array.shouldNotContainNull(): Array {
asList().shouldNotContainNull()
return this
}
fun Collection.shouldNotContainNull(): Collection {
this shouldNot containNull()
return this
}
fun containNull() = object : Matcher> {
override fun test(value: Collection) =
MatcherResult(
value.any { it == null },
{ "Collection should contain at least one null" },
{ "Collection should not contain any nulls" })
}
fun Iterable.shouldContainNoNulls(): Iterable {
toList().shouldContainNoNulls()
return this
}
fun Array.shouldContainNoNulls(): Array {
asList().shouldContainNoNulls()
return this
}
fun Collection.shouldContainNoNulls(): Collection {
this should containNoNulls()
return this
}
fun Iterable.shouldNotContainNoNulls(): Iterable {
toList().shouldNotContainNoNulls()
return this
}
fun Array.shouldNotContainNoNulls(): Array {
asList().shouldNotContainNoNulls()
return this
}
fun Collection.shouldNotContainNoNulls(): Collection {
this shouldNot containNoNulls()
return this
}
fun containNoNulls() = object : Matcher> {
override fun test(value: Collection) =
MatcherResult(
value.all { it != null },
{ "Collection should not contain nulls" },
{ "Collection should have at least one null" }
)
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy