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

Move tests from serialization and functions completely to kotlin.test #3289

Merged
merged 5 commits into from
Nov 8, 2023
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 2 additions & 8 deletions arrow-libs/core/arrow-core-serialization/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ plugins {
id(libs.plugins.kotlin.multiplatform.get().pluginId)
alias(libs.plugins.arrowGradleConfig.kotlin)
alias(libs.plugins.arrowGradleConfig.publish)
alias(libs.plugins.kotest.multiplatform)
alias(libs.plugins.kotlinx.kover)
alias(libs.plugins.spotless)
id(libs.plugins.kotlinx.serialization.get().pluginId)
}

Expand All @@ -25,17 +26,10 @@ kotlin {
implementation(libs.kotlinx.serializationJson)
implementation(libs.kotlin.test)
implementation(libs.coroutines.test)
implementation(libs.kotest.frameworkEngine)
implementation(libs.kotest.assertionsCore)
implementation(libs.kotest.property)
}
}

jvmTest {
dependencies {
runtimeOnly(libs.kotest.runnerJUnit5)
}
}
}

jvm {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,18 @@ import arrow.core.Ior
import arrow.core.NonEmptyList
import arrow.core.NonEmptySet
import arrow.core.Option
import io.kotest.core.spec.style.StringSpec
import io.kotest.matchers.shouldBe
import io.kotest.property.Arb
import io.kotest.property.checkAll
import io.kotest.property.arbitrary.int
import io.kotest.property.arbitrary.map
import io.kotest.property.arbitrary.string
import kotlin.test.Test
import kotlinx.coroutines.test.runTest
import kotlinx.serialization.UseSerializers
import kotlinx.serialization.json.Json
import kotlinx.serialization.json.encodeToJsonElement
import kotlinx.serialization.json.decodeFromJsonElement
import io.kotest.matchers.shouldBe
import io.kotest.property.arbitrary.int
import io.kotest.property.arbitrary.map
import io.kotest.property.arbitrary.string
import kotlinx.serialization.Serializable

/*
Expand All @@ -46,24 +47,28 @@ data class NonEmptyListInside<A>(val thing: NonEmptyList<A>)
@Serializable
data class NonEmptySetInside<A>(val thing: NonEmptySet<A>)

inline fun <reified T> StringSpec.backAgain(generator: Arb<T>) {
"there and back again, ${T::class.simpleName}" {
inline fun <reified T> backAgain(generator: Arb<T>) =
runTest {
checkAll(generator) { e ->
val result = Json.encodeToJsonElement<T>(e)
val back = Json.decodeFromJsonElement<T>(result)
back shouldBe e
}
}
}

/**
* Checks that the result of serializing a value into JSON,
* and then deserializing it, gives back the original.
*/
class BackAgainTest : StringSpec({
backAgain(Arb.either(Arb.string(), Arb.int()).map(::EitherInside))
backAgain(Arb.ior(Arb.string(), Arb.int()).map(::IorInside))
backAgain(Arb.option(Arb.string()).map(::OptionInside))
backAgain(Arb.nonEmptyList(Arb.int()).map(::NonEmptyListInside))
backAgain(Arb.nonEmptySet(Arb.int()).map(::NonEmptySetInside))
})
class BackAgainTest {
@Test fun backAgainEither() =
backAgain(Arb.either(Arb.string(), Arb.int()).map(::EitherInside))
@Test fun backAgainIor() =
backAgain(Arb.ior(Arb.string(), Arb.int()).map(::IorInside))
@Test fun backAgainOption() =
backAgain(Arb.option(Arb.string()).map(::OptionInside))
@Test fun backAgainNonEmptyList() =
backAgain(Arb.nonEmptyList(Arb.int()).map(::NonEmptyListInside))
@Test fun backAgainNonEmptySet() =
backAgain(Arb.nonEmptySet(Arb.int()).map(::NonEmptySetInside))
}
1 change: 0 additions & 1 deletion arrow-libs/core/arrow-core/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ kotlin {
commonTest {
dependencies {
implementation(projects.arrowFxCoroutines)
implementation(projects.arrowFunctions)
implementation(libs.kotlin.test)
implementation(libs.coroutines.test)
implementation(libs.kotest.frameworkEngine)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,15 @@ public typealias EitherNel<E, A> = Either<NonEmptyList<E>, A>
* all becomes even more unwieldy when we try to compose exception-throwing procedures.
*
* ```kotlin
* import arrow.core.andThen
*
* //sampleStart
* val throwsSomeStuff: (Int) -> Double = {x -> x.toDouble()}
* val throwsOtherThings: (Double) -> String = {x -> x.toString()}
* val moreThrowing: (String) -> List<String> = {x -> listOf(x)}
* val magic = throwsSomeStuff.andThen(throwsOtherThings).andThen(moreThrowing)
* val magic: (Int) -> List<String> = { x ->
* val y = throwsSomeStuff(x)
* val z = throwsOtherThings(y)
* moreThrowing(z)
* }
* //sampleEnd
* fun main() {
* println ("magic = $magic")
Expand Down

This file was deleted.

Loading
Loading