Move ArrowAssertions to simplenotes-domain

This commit is contained in:
2020-10-23 16:30:04 +02:00
parent cd12d1561a
commit 29b024d360
5 changed files with 7 additions and 8 deletions
@@ -1 +0,0 @@
package be.simplenotes.shared
@@ -1,42 +0,0 @@
package be.simplenotes.shared.testutils.assertions
import arrow.core.Either
import com.natpryce.hamkrest.MatchResult
import com.natpryce.hamkrest.Matcher
fun isLeft() = object : Matcher<Either<*, *>> {
override val description: String
get() = "is Either.Left<>"
override fun invoke(actual: Either<*, *>) = when {
actual.isLeft() -> MatchResult.Match
else -> MatchResult.Mismatch("is Either.Right<>")
}
}
fun isRight() = object : Matcher<Either<*, *>> {
override val description: String
get() = "is Either.Right<>"
override fun invoke(actual: Either<*, *>) = when (actual) {
is Either.Right -> MatchResult.Match
is Either.Left -> {
val valueA = actual.a
MatchResult.Mismatch("is Either.Left<${if (valueA == null) "Null" else valueA::class.simpleName}>")
}
}
}
inline fun <reified A> isLeftOfType() = object : Matcher<Either<*, *>> {
override val description: String
get() = "is Either.Left<${A::class.qualifiedName}>"
override fun invoke(actual: Either<*, *>) = when (actual) {
is Either.Right -> MatchResult.Mismatch("was Either.Right<>")
is Either.Left -> {
val valueA = actual.a
if (valueA is A) MatchResult.Match
else MatchResult.Mismatch("was Left<${if (valueA == null) "Null" else valueA::class.simpleName}>")
}
}
}