
jvmMain.io.kotest.assertions.arrow.eq.matchers.kt Maven / Gradle / Ivy
package io.kotest.assertions.arrow.eq
import arrow.typeclasses.Eq
import io.kotest.assertions.arrow.matcher
import io.kotest.matchers.Matcher
import io.kotest.matchers.should
/**
* Provides assertions for [Eq]
*
* ```kotlin
* EqAssertions(Int.eq()).run {
* 0 shouldBeEqvTo 0
* 0 shouldNotBeEqvTo -1
* }
* ```
*/
interface EqAssertions {
fun EQA(): Eq
infix fun A.shouldBeEqvTo(b: A): Unit =
this should eqv(b)
infix fun A.shouldNotBeEqvTo(b: A): Unit =
this should neqv(b)
private fun A.eqv(b: A): Matcher =
EQA().run { matcher(eqv(b), "value ${this@eqv} != expected $b") }
private fun A.neqv(b: A): Matcher =
EQA().run { matcher(neqv(b), "value ${this@neqv} == expected not equal to $b") }
companion object {
operator fun invoke(EQA: Eq, f: (EqAssertions).() -> Unit): Unit = f(object : EqAssertions {
override fun EQA(): Eq = EQA
})
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy