Skip to content

Commit

Permalink
Update OptionSpec.kt (#3271)
Browse files Browse the repository at this point in the history
Co-authored-by: Simon Vergauwen <[email protected]>
  • Loading branch information
Tejas Mate and nomisRev authored Nov 2, 2023
1 parent 40fcd76 commit 4e0846e
Showing 1 changed file with 8 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,18 @@ import arrow.core.None
import arrow.core.Some
import arrow.core.some
import arrow.core.toOption
import io.kotest.core.spec.style.StringSpec
import io.kotest.matchers.shouldBe
import io.kotest.property.Arb
import io.kotest.property.arbitrary.boolean
import io.kotest.property.arbitrary.int
import io.kotest.property.arbitrary.orNull
import io.kotest.property.checkAll
import kotlin.test.Test
import kotlinx.coroutines.test.runTest

class OptionSpec : StringSpec({
class OptionSpec {

"ensure" {
@Test fun ensure() = runTest {
checkAll(Arb.boolean(), Arb.int()) { b, i ->
option {
ensure(b)
Expand All @@ -23,7 +24,7 @@ class OptionSpec : StringSpec({
}
}

"ensureNotNull in option computation" {
@Test fun ensureNotNullInOptionComputation() = runTest {
fun square(i: Int): Int = i * i
checkAll(Arb.int().orNull()) { i: Int? ->
option {
Expand All @@ -33,19 +34,19 @@ class OptionSpec : StringSpec({
}
}

"short circuit option" {
@Test fun shortCircuitOption() = runTest {
@Suppress("UNREACHABLE_CODE")
option {
ensureNotNull<Int>(null)
throw IllegalStateException("This should not be executed")
} shouldBe None
}

"Recover works as expected" {
@Test fun RecoverWorksAsExpected() = runTest {
option {
val one: Int = recover({ None.bind<Int>() }) { 1 }
val two = Some(2).bind()
one + two
} shouldBe Some(3)
}
})
}

0 comments on commit 4e0846e

Please sign in to comment.