Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix some compilation and test warnings #2741

Merged
merged 2 commits into from Jun 13, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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