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

Support JS for Arrow Core #2409

Merged
merged 24 commits into from
Jul 5, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
5046b99
Support JS for Arrow Core
nomisRev May 28, 2021
88bb1c8
Fix gradle.build arrow-continuations
nomisRev May 31, 2021
6e48de6
Move JS config to Arrow Core only for multiple PRs
nomisRev May 31, 2021
1247bb6
Add JS target for core
nomisRev May 31, 2021
11a5c15
Revert commented test
nomisRev May 31, 2021
e4665cd
Fix start import
nomisRev May 31, 2021
9928730
Merge branch 'main' into sv-core-js-support
i-walker Jun 1, 2021
1db8fe9
Update FunctionSyntaxTest for MPP
nomisRev Jun 1, 2021
e674740
Remove cyclic dependencies by moving all tests to Arrow Core Test
nomisRev Jun 2, 2021
d9b6bd3
Fix build
nomisRev Jun 2, 2021
1309201
Enable both targets
nomisRev Jun 5, 2021
c04f854
Merge branch 'main' into sv-core-js-support
nomisRev Jun 5, 2021
8183429
Merge branch 'main' into sv-core-js-support
nomisRev Jun 6, 2021
7bd3665
Merge branch 'sv-core-js-support' of github.com:arrow-kt/arrow into s…
nomisRev Jun 8, 2021
bc315e7
Merge branch 'main' into sv-core-js-support
rachelcarmena Jun 10, 2021
2dd1bcc
Fix versions
nomisRev Jun 28, 2021
0f0e617
Merge branch 'sv-core-js-support' of github.com:arrow-kt/arrow into s…
nomisRev Jun 28, 2021
99890d4
Merge branch 'main' into sv-core-js-support
nomisRev Jul 1, 2021
781d9ef
Fix Arrow JS, and add test to verify tests run on CI
nomisRev Jul 5, 2021
45140d9
Revert failing test
nomisRev Jul 5, 2021
7f943d9
Revert "Remove cyclic dependencies by moving all tests to Arrow Core…
nomisRev Jul 5, 2021
4f6694a
Increase karma timeout
nomisRev Jul 5, 2021
07eea27
Comment unusued type tests
nomisRev Jul 5, 2021
7e12dd8
ktlintFormat
nomisRev Jul 5, 2021
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
11 changes: 10 additions & 1 deletion arrow-libs/core/arrow-annotations/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ apply from: "$PUBLICATION_MPP"
apply from: "$ANIMALSNIFFER_MPP"

kotlin {
js(BOTH) {
browser()
nodejs()
}
sourceSets {
commonMain {
dependencies {
Expand All @@ -17,7 +21,12 @@ kotlin {
}
jvmMain {
dependencies {
compileOnly "org.jetbrains.kotlin:kotlin-stdlib:$KOTLIN_VERSION"
compileOnly "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$KOTLIN_VERSION"
}
}
jsMain {
dependencies {
compileOnly "org.jetbrains.kotlin:kotlin-stdlib-js:$KOTLIN_VERSION"
}
}
}
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import kotlin.annotation.AnnotationTarget.CLASS
/**
* Empty arrays means "Everything that matches annotated class"
*/
annotation class optics(val targets: Array<OpticsTarget> = [])
annotation class optics(val targets: Array<OpticsTarget> = emptyArray())

enum class OpticsTarget {
ISO, LENS, PRISM, OPTIONAL, DSL
Expand Down
35 changes: 33 additions & 2 deletions arrow-libs/core/arrow-continuations/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -11,21 +11,52 @@ apply from: "$ANIMALSNIFFER_MPP"
apply plugin: 'kotlinx-atomicfu'

kotlin {
js(BOTH) {
browser {
testTask {
useKarma {
useChromeHeadless()
useConfigDirectory("${project.rootDir}/karma")
}
}
}
nodejs {
testTask {
useMocha {
timeout = "10000000000"
}
}
}
}
sourceSets {
commonMain {
dependencies {
compileOnly "org.jetbrains.kotlin:kotlin-stdlib-common:$KOTLIN_VERSION"
}
}
commonTest {
dependencies {
implementation project(":arrow-core-test")
}
}
jvmMain {
dependencies {
compileOnly "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$KOTLIN_VERSION"
}
}
jvmTest {
dependencies {
runtimeOnly "org.junit.vintage:junit-vintage-engine:$JUNIT_VINTAGE_VERSION"
implementation project(":arrow-core-test")
runtimeOnly "io.kotest:kotest-runner-junit5:$KOTEST_VERSION"
}
}
jsMain {
dependencies {
compileOnly "org.jetbrains.kotlin:kotlin-stdlib-js:$KOTLIN_VERSION"
}
}
jsTest {
dependencies {
implementation "io.kotest:kotest-framework-engine:$KOTEST_VERSION"
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
package generic
package arrow.continuations

import arrow.core.Either
import arrow.core.computations.either
import arrow.core.Either.Right
import arrow.core.Either.Left
import arrow.core.Eval
import arrow.core.computations.eval
import io.kotest.assertions.fail
import io.kotest.matchers.shouldBe
import io.kotest.assertions.throwables.shouldThrow
import io.kotest.core.spec.style.StringSpec
import kotlinx.coroutines.CompletableDeferred
import kotlinx.coroutines.CoroutineScope
Expand Down Expand Up @@ -49,29 +51,29 @@ class SuspendingComputationTest : StringSpec({

"Rethrows immediate exceptions" {
val e = RuntimeException("test")
shouldThrow<RuntimeException> {
Either.catch {
either<String, Int> {
Right(1).bind()
Right(1).suspend().bind()
throw e
}
} shouldBe e
} shouldBe Left(e)
}

"Rethrows suspended exceptions" {
val e = RuntimeException("test")
shouldThrow<RuntimeException> {
Either.catch {
either<String, Int> {
Right(1).bind()
Right(1).suspend().bind()
e.suspend()
}
} shouldBe e
} shouldBe Either.Left(e)
}

"Can short-circuit immediately from nested blocks" {
either<String, Int> {
val x = maybeEff {
val x = eval {
Left("test").bind()
5L
}
Expand All @@ -83,7 +85,7 @@ class SuspendingComputationTest : StringSpec({

"Can short-circuit suspended from nested blocks" {
either<String, Int> {
val x = maybeEff {
val x = eval {
Left("test").suspend().bind()
5L
}
Expand All @@ -95,8 +97,8 @@ class SuspendingComputationTest : StringSpec({

"Can short-circuit immediately after suspending from nested blocks" {
either<String, Int> {
val x = maybeEff {
Just(1L).suspend().bind()
val x = eval {
Eval.Now(1L).suspend().bind()
Left("test").suspend().bind()
5L
}
Expand All @@ -108,8 +110,8 @@ class SuspendingComputationTest : StringSpec({

"Can short-circuit suspended after suspending from nested blocks" {
either<String, Int> {
val x = maybeEff {
Just(1L).suspend().bind()
val x = eval {
Eval.Now(1L).suspend().bind()
Left("test").suspend().bind()
5L
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package generic

import arrow.continuations.Reset
import arrow.continuations.generic.MultiShotDelimContScope
import arrow.continuations.generic.RestrictedScope
import arrow.core.Either
import arrow.core.Either.Left
Expand Down Expand Up @@ -93,9 +92,9 @@ class SingleShotContTestSuite : ContTestSuite() {
override fun capabilities(): Set<ScopeCapabilities> = emptySet()
}

class MultiShotContTestSuite : ContTestSuite() {
override suspend fun <A> runScope(func: (suspend RestrictedScope<A>.() -> A)): A =
MultiShotDelimContScope.reset { func(this) }

override fun capabilities(): Set<ScopeCapabilities> = setOf(ScopeCapabilities.MultiShot)
}
// class MultiShotContTestSuite : ContTestSuite() {
// override suspend fun <A> runScope(func: (suspend RestrictedScope<A>.() -> A)): A =
// MultiShotDelimContScope.reset { func(this) }
//
// override fun capabilities(): Set<ScopeCapabilities> = setOf(ScopeCapabilities.MultiShot)
// }
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package arrow.continuations.generic

/**
* A [Throwable] class intended for control flow.
* Instance of [ControlThrowable.kt] should **not** be caught,
* and `arrow.core.NonFatal` does not catch this [Throwable].
* Thus by extension `Either.catch` and `Validated.catch` also don't catch [ControlThrowable.kt].
*/
actual open class ControlThrowable : Throwable()
28 changes: 28 additions & 0 deletions arrow-libs/core/arrow-core-test/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,13 @@ plugins {
apply from: "$SUB_PROJECT_MPP"
apply from: "$PUBLICATION_MPP"
apply from: "$ANIMALSNIFFER_MPP"
apply plugin: 'kotlinx-atomicfu'

kotlin {
js(BOTH) {
browser()
nodejs()
}
sourceSets {
commonMain {
dependencies {
Expand All @@ -20,10 +25,33 @@ kotlin {
api "io.kotest:kotest-assertions-core:$KOTEST_VERSION"
}
}
commonTest {
dependencies {
implementation project(":arrow-core-test")
}
}
jvmMain {
dependencies {
compileOnly "org.jetbrains.kotlin:kotlin-stdlib:$KOTLIN_VERSION"
}
}
jvmTest {
dependencies {
runtimeOnly "io.kotest:kotest-runner-junit5:$KOTEST_VERSION"
implementation project(":arrow-core-retrofit")
implementation "com.squareup.retrofit2:converter-gson:$RETROFIT_VERSION"
implementation "com.squareup.okhttp3:mockwebserver:$MOCKWEBSERVER_VERSION"
}
}
jsMain {
dependencies {
compileOnly "org.jetbrains.kotlin:kotlin-stdlib-js:$KOTLIN_VERSION"
}
}
jsTest {
dependencies {
implementation "io.kotest:kotest-framework-engine:$KOTEST_VERSION"
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package arrow.core.test

expect fun isJvm(): Boolean
expect fun isJs(): Boolean

fun stackSafeIteration(): Int =
if (isJvm()) 500_000 else 1000
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,19 @@ import arrow.core.Tuple8
import arrow.core.Tuple9
import arrow.core.Validated
import arrow.core.left
import arrow.core.prependTo
import arrow.core.right
import arrow.core.toOption
import io.kotest.property.Arb
import io.kotest.property.arbitrary.arb
import io.kotest.property.arbitrary.bind
import io.kotest.property.arbitrary.bool
import io.kotest.property.arbitrary.byte
import io.kotest.property.arbitrary.choice
import io.kotest.property.arbitrary.constant
import io.kotest.property.arbitrary.double
import io.kotest.property.arbitrary.edgecases
import io.kotest.property.arbitrary.filter
import io.kotest.property.arbitrary.flatMap
import io.kotest.property.arbitrary.float
import io.kotest.property.arbitrary.int
import io.kotest.property.arbitrary.list
import io.kotest.property.arbitrary.long
Expand All @@ -39,7 +40,9 @@ import io.kotest.property.arbitrary.of
import io.kotest.property.arbitrary.orNull
import io.kotest.property.arbitrary.short
import io.kotest.property.arbitrary.string
import kotlin.jvm.JvmOverloads
import kotlin.math.abs
import kotlin.random.nextInt

fun <A, B> Arb.Companion.functionAToB(arb: Arb<B>): Arb<(A) -> B> =
arb.map { b: B -> { _: A -> b } }
Expand Down Expand Up @@ -239,9 +242,32 @@ fun Arb.Companion.any(): Arb<Any> =
Arb.string() as Arb<Any>,
Arb.int() as Arb<Any>,
Arb.long() as Arb<Any>,
Arb.float() as Arb<Any>,
Arb.double() as Arb<Any>,
// Arb.float() as Arb<Any>,
// Arb.double() as Arb<Any>,
Arb.bool() as Arb<Any>,
Arb.throwable() as Arb<Any>,
Arb.unit() as Arb<Any>
)

@JvmOverloads
inline fun <reified A> Arb.Companion.array(
gen: Arb<A>,
range: IntRange = 0..100
): Arb<Array<A>> {
check(!range.isEmpty())
check(range.first >= 0)
return arb(edgecases = emptyArray<A>() prependTo gen.edgecases().map { arrayOf(it) }) {
sequence {
val genIter = gen.generate(it).iterator()
while (true) {
val targetSize = it.random.nextInt(range)
val list = ArrayList<A>(targetSize)
while (list.size < targetSize && genIter.hasNext()) {
list.add(genIter.next().value)
}
check(list.size == targetSize)
yield(list.toTypedArray())
}
}
}
}
Loading