Skip to content

Commit da7a179

Browse files
committed
Rewrite Kotest integration in Kotlin.
1 parent fbd61c0 commit da7a179

File tree

8 files changed

+202
-264
lines changed

8 files changed

+202
-264
lines changed

build.sbt

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import kotlin.Keys._
2+
13
inThisBuild(
24
Seq(
35
organization := "com.github.simy4.coregex",
@@ -170,17 +172,29 @@ lazy val junitQuickcheck = (project in file("junit-quickcheck"))
170172
.dependsOn(core)
171173

172174
lazy val kotest = (project in file("kotest"))
175+
.enablePlugins(KotlinPlugin)
173176
.settings(
174177
name := "kotest",
175178
moduleName := "coregex-kotest",
176179
description := "Kotest bindings for coregex library.",
177180
libraryDependencies ++= Seq(
178-
"io.kotest" % "kotest-property-jvm" % "6.1.7" % Provided,
179-
"com.github.sbt.junit" % "jupiter-interface" % JupiterKeys.jupiterVersion.value % Test
181+
"io.kotest" % "kotest-property-jvm" % "6.1.7" % Provided,
182+
"io.kotest" % "kotest-runner-junit6" % "6.1.7" % Test,
183+
"com.github.sbt.junit" % "jupiter-interface" % JupiterKeys.jupiterVersion.value % Test
184+
),
185+
crossPaths := false,
186+
autoScalaLibrary := false,
187+
kotlinVersion := "2.2.21",
188+
kotlincOptions ++= Seq(
189+
"-progressive",
190+
"-language-version=2.2",
191+
"-api-version=2.2",
192+
"-Xexplicit-api=strict",
193+
"-Werror"
180194
),
195+
kotlincJvmTarget := "11",
181196
testOptions += Tests.Argument(jupiterTestFramework, "-q", "-v")
182197
)
183-
.settings(javaLibSettings(11))
184198
.settings(jacocoSettings)
185199
.dependsOn(core)
186200

kotest/src/main/java/com/github/simy4/coregex/kotest/CoregexArbitrary.java

Lines changed: 0 additions & 92 deletions
This file was deleted.
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
/*
2+
* Copyright 2021-2026 Alex Simkin
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package com.github.simy4.coregex.kotest
18+
19+
import com.github.simy4.coregex.core.Coregex
20+
import io.kotest.property.Arb
21+
import io.kotest.property.Classifier
22+
import io.kotest.property.RTree
23+
import io.kotest.property.RandomSource
24+
import io.kotest.property.Sample
25+
import java.util.regex.Pattern
26+
import kotlin.streams.toList
27+
28+
public class CoregexArbitrary(private val coregex: Coregex): Arb<String>() {
29+
30+
public companion object {
31+
public fun of(pattern: String, flags: Int = 0): CoregexArbitrary =
32+
CoregexArbitrary(Pattern.compile(pattern, flags))
33+
}
34+
35+
public constructor(pattern: Pattern): this(Coregex.from(pattern))
36+
37+
public constructor(regex: Regex): this(regex.toPattern())
38+
39+
override val classifier: Classifier<out String> = Classifier { string -> "'$string' matching '$coregex'" }
40+
41+
override fun edgecase(rs: RandomSource): Sample<String>? = null
42+
43+
override fun sample(rs: RandomSource): Sample<String> {
44+
val seed = rs.random.nextLong()
45+
val sample = coregex.generate(seed)
46+
return Sample(sample, RTree({ sample }, lazy(CoregexShrinker(coregex, seed))))
47+
}
48+
}
49+
50+
internal class CoregexShrinker(private val coregex: Coregex, private val seed: Long): () -> List<RTree<String>> {
51+
override fun invoke(): List<RTree<String>> =
52+
coregex
53+
.shrink()
54+
.map { coregex ->
55+
val shrink = coregex.generate(seed)
56+
RTree( { shrink }, lazy(CoregexShrinker(coregex, seed)))
57+
}
58+
.toList()
59+
}

kotest/src/test/java/com/github/simy4/coregex/kotest/CoregexArbitraryTest.java

Lines changed: 0 additions & 98 deletions
This file was deleted.

kotest/src/test/java/com/github/simy4/coregex/kotest/KotestTest.java

Lines changed: 0 additions & 71 deletions
This file was deleted.

0 commit comments

Comments
 (0)