Skip to content

Commit

Permalink
Move tests from serialization and functions completely to `kotlin…
Browse files Browse the repository at this point in the history
….test` (#3289)

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
  • Loading branch information
serras and github-actions[bot] authored Nov 8, 2023
1 parent 4ba933e commit a359b79
Show file tree
Hide file tree
Showing 10 changed files with 166 additions and 524 deletions.
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

0 comments on commit a359b79

Please sign in to comment.