Skip to content

Commit

Permalink
Fix some compilation and test warnings (#2741)
Browse files Browse the repository at this point in the history
* Fix some compilatio and test warnings

* Add missing import

Co-authored-by: wojda <wojda@users.noreply.github.com>
  • Loading branch information
wojda and wojda committed Jun 13, 2022
1 parent 097ceeb commit 5bbb9fc
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 34 deletions.
Expand Up @@ -16,12 +16,10 @@ import io.kotest.assertions.throwables.shouldThrow
import io.kotest.matchers.shouldBe
import io.kotest.property.Arb
import io.kotest.property.arbitrary.boolean
import io.kotest.property.arbitrary.choice
import io.kotest.property.arbitrary.constant
import io.kotest.property.arbitrary.int
import io.kotest.property.arbitrary.long
import io.kotest.property.arbitrary.negativeInts
import io.kotest.property.arbitrary.string
import io.kotest.property.arbitrary.nonPositiveInt

class EitherTest : UnitSpec() {

Expand Down Expand Up @@ -310,7 +308,7 @@ class EitherTest : UnitSpec() {

"replicate should return Right(empty list) when n <= 0" {
checkAll(
Arb.choice(Arb.negativeInts(), Arb.constant(0)),
Arb.nonPositiveInt(),
Arb.int(0..100)
) { n: Int, a: Int ->
val expected: Either<Int, List<Int>> = Right(emptyList())
Expand Down
@@ -1,16 +1,9 @@
package arrow.core

import arrow.core.computations.EvalEffect
import arrow.core.computations.RestrictedEvalEffect
import arrow.core.computations.eval
import arrow.core.test.UnitSpec
import arrow.core.test.concurrency.SideEffect
import arrow.core.test.laws.FxLaws
import arrow.core.test.stackSafeIteration
import io.kotest.property.Arb
import io.kotest.matchers.shouldBe
import io.kotest.property.arbitrary.int
import io.kotest.property.arbitrary.map

class EvalTest : UnitSpec() {

Expand Down
Expand Up @@ -165,7 +165,6 @@ class IterableTest : UnitSpec() {
checkAll(Arb.list(Arb.int())) { ints ->
val evens = ints.map { if (it % 2 == 0) it else null }.sequence()

val expected = ints.takeWhile { it % 2 == 0 }
if (ints.any { it % 2 != 0 }) {
evens.shouldBeNull()
} else {
Expand Down
Expand Up @@ -64,8 +64,7 @@ class OptionTest : UnitSpec() {
"short circuit null" {
option {
val number: Int = "s".length
val x = ensureNotNull(number.takeIf { it > 1 })
x
ensureNotNull(number.takeIf { it > 1 })
throw IllegalStateException("This should not be executed")
} shouldBe None
}
Expand Down Expand Up @@ -120,8 +119,8 @@ class OptionTest : UnitSpec() {
}

"map" {
some.map(String::toUpperCase) shouldBe Some("KOTLIN")
none.map(String::toUpperCase) shouldBe None
some.map(String::uppercase) shouldBe Some("KOTLIN")
none.map(String::uppercase) shouldBe None
}

"zip" {
Expand Down Expand Up @@ -410,17 +409,17 @@ class OptionTest : UnitSpec() {
Option.catch(recover) { 1 } shouldBe Some(1)
}

"catch with default recover should return Some(result) when f does not throw" {
Option.catch { 1 } shouldBe Some(1)
}

"catch should return Some(recoverValue) when f throws" {
val exception = Exception("Boom!")
val recoverValue = 10
val recover: (Throwable) -> Option<Int> = { _ -> Some(recoverValue) }
Option.catch(recover) { throw exception } shouldBe Some(recoverValue)
}

"catch should return Some(result) when f does not throw" {
Option.catch { 1 } shouldBe Some(1)
}

"catch should return None when f throws" {
val exception = Exception("Boom!")
Option.catch { throw exception } shouldBe None
Expand Down
Expand Up @@ -204,7 +204,7 @@ class ValidatedTest : UnitSpec() {
) { a, b -> a + b }
})
else Invalid(
all.filterIsInstance<Invalid<Long?>>().map { it.value }.combineAll(nullableLongSemigroup)
all.filterIsInstance<Invalid<Long?>>().map { it.value }.fold(nullableLongSemigroup)
)

res shouldBe expected
Expand Down Expand Up @@ -458,15 +458,7 @@ class ValidatedTest : UnitSpec() {
}
}

"bitraverseNullable should wrap valid or invalid in a nullable" {
val valid = Valid("Who")
val invalid = Invalid("Nope")

valid.bitraverseNullable({ it }, { it }) shouldBe Valid("Who")
invalid.bitraverseNullable({ it }, { it }) shouldBe Invalid("Nope")
}

"bisequenceOption should yield consistent result with bitraverseOption" {
"bisequenceNullable should yield consistent result with bitraverseNullable" {
checkAll(Arb.string().orNull(), Arb.string().orNull()) { a: String?, b: String? ->
val valid: Validated<String?, String?> = Valid(a)
val invalid: Validated<String?, String?> = Invalid(b)
Expand All @@ -478,6 +470,14 @@ class ValidatedTest : UnitSpec() {
}
}

"bitraverseNullable should wrap valid or invalid in a nullable" {
val valid = Valid("Who")
val invalid = Invalid("Nope")

valid.bitraverseNullable({ it }, { it }) shouldBe Valid("Who")
invalid.bitraverseNullable({ it }, { it }) shouldBe Invalid("Nope")
}

"bitraverseEither should wrap valid or invalid in an either" {
val valid = Valid("Who")
val invalid = Invalid("Nope")
Expand Down
Expand Up @@ -24,8 +24,7 @@ class OptionSpec : StringSpec({
"short circuit option" {
option {
val number: Int = "s".length
val x = ensureNotNull(number.takeIf { it > 1 })
x
ensureNotNull(number.takeIf { it > 1 })
throw IllegalStateException("This should not be executed")
} shouldBe None
}
Expand All @@ -44,8 +43,7 @@ class OptionSpec : StringSpec({
"eager short circuit null" {
option.eager {
val number: Int = "s".length
val x = ensureNotNull(number.takeIf { it > 1 })
x
ensureNotNull(number.takeIf { it > 1 })
throw IllegalStateException("This should not be executed")
} shouldBe None
}
Expand Down

0 comments on commit 5bbb9fc

Please sign in to comment.