Skip to content

Commit

Permalink
Tests for JS
Browse files Browse the repository at this point in the history
  • Loading branch information
serras committed Nov 4, 2023
1 parent 95f9c6a commit a761ab4
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 13 deletions.
1 change: 1 addition & 0 deletions arrow-libs/fx/arrow-collectors/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ plugins {
id(libs.plugins.kotlin.multiplatform.get().pluginId)
alias(libs.plugins.arrowGradleConfig.kotlin)
alias(libs.plugins.arrowGradleConfig.publish)
alias(libs.plugins.spotless)
}

apply(from = property("ANIMALSNIFFER_MPP"))
Expand Down
Original file line number Diff line number Diff line change
@@ -1,22 +1,9 @@
package arrow.collectors

import io.kotest.matchers.shouldBe
import io.kotest.property.Arb
import io.kotest.property.PropertyContext
import io.kotest.property.arbitrary.int
import io.kotest.property.arbitrary.list
import io.kotest.property.checkAll
import kotlinx.coroutines.test.TestResult
import kotlinx.coroutines.test.runTest
import kotlin.test.Test

class CollectorsTest {
fun runTestOverLists(
block: suspend PropertyContext.(List<Int>) -> Unit
): TestResult = runTest {
checkAll(Arb.list(Arb.int()), block)
}

@Test
fun lengthWorks() = runTestOverLists {
it.collect(Collectors.length) shouldBe it.size
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package arrow.collectors

import io.kotest.property.Arb
import io.kotest.property.PropertyContext
import io.kotest.property.arbitrary.int
import io.kotest.property.arbitrary.list
import io.kotest.property.checkAll
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.test.TestResult
import kotlinx.coroutines.test.runTest
import kotlinx.coroutines.withContext

fun runTestWithDelay(testBody: suspend () -> Unit): TestResult = runTest {
withContext(Dispatchers.Default) {
testBody()
}
}

fun runTestOverLists(block: suspend PropertyContext.(List<Int>) -> Unit): TestResult = runTestWithDelay {
checkAll(Arb.list(Arb.int(-1000 .. 1000), range = 0 .. 20), block)
}
1 change: 1 addition & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ dependencies {
kover(projects.arrowOpticsKspPlugin)
kover(projects.arrowOpticsReflect)
kover(projects.arrowResilience)
kover(projects.arrowCollectors)
}

allprojects {
Expand Down

0 comments on commit a761ab4

Please sign in to comment.