Skip to content

Commit

Permalink
Support Iterable in withData on root level (kotest#3831)
Browse files Browse the repository at this point in the history
  • Loading branch information
obecker committed Jan 18, 2024
1 parent ce6b4fe commit 87ef4a8
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ public abstract interface annotation class io/kotest/datatest/IsStableType : jav
}

public final class io/kotest/datatest/RootKt {
public static final fun withData (Lio/kotest/core/spec/style/scopes/RootScope;Ljava/lang/Iterable;Lkotlin/jvm/functions/Function3;)V
public static final fun withData (Lio/kotest/core/spec/style/scopes/RootScope;Ljava/lang/Object;Ljava/lang/Object;[Ljava/lang/Object;Lkotlin/jvm/functions/Function3;)V
public static final fun withData (Lio/kotest/core/spec/style/scopes/RootScope;Ljava/util/Collection;Lkotlin/jvm/functions/Function3;)V
public static final fun withData (Lio/kotest/core/spec/style/scopes/RootScope;Lkotlin/jvm/functions/Function1;Ljava/lang/Iterable;Lkotlin/jvm/functions/Function3;)V
public static final fun withData (Lio/kotest/core/spec/style/scopes/RootScope;Lkotlin/jvm/functions/Function1;Ljava/lang/Object;Ljava/lang/Object;[Ljava/lang/Object;Lkotlin/jvm/functions/Function3;)V
public static final fun withData (Lio/kotest/core/spec/style/scopes/RootScope;Lkotlin/jvm/functions/Function1;Ljava/util/Collection;Lkotlin/jvm/functions/Function3;)V
public static final fun withData (Lio/kotest/core/spec/style/scopes/RootScope;Lkotlin/jvm/functions/Function1;Lkotlin/sequences/Sequence;Lkotlin/jvm/functions/Function3;)V
public static final fun withData (Lio/kotest/core/spec/style/scopes/RootScope;Lkotlin/sequences/Sequence;Lkotlin/jvm/functions/Function3;)V
public static final fun withDataMap (Lio/kotest/core/spec/style/scopes/RootScope;Ljava/util/Map;Lkotlin/jvm/functions/Function3;)V
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ fun <T> RootScope.withData(nameFn: (T) -> String, ts: Sequence<T>, test: suspend
*
* The test name will be generated from the stable properties of the elements. See [StableIdentifiers].
*/
fun <T> RootScope.withData(ts: Collection<T>, test: suspend ContainerScope.(T) -> Unit) {
fun <T> RootScope.withData(ts: Iterable<T>, test: suspend ContainerScope.(T) -> Unit) {
withData({ getStableIdentifier(it) }, ts, test)
}

Expand All @@ -58,7 +58,7 @@ fun <T> RootScope.withData(ts: Collection<T>, test: suspend ContainerScope.(T) -
*/
fun <T> RootScope.withData(
nameFn: (T) -> String,
ts: Collection<T>,
ts: Iterable<T>,
test: suspend ContainerScope.(T) -> Unit
) {
ts.forEach { t ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import io.kotest.core.spec.style.FunSpec
import io.kotest.core.test.TestCase
import io.kotest.core.test.TestResult
import io.kotest.matchers.shouldBe
import kotlinx.coroutines.delay

@ExperimentalKotest
class ContainerDataTestNameFunctionTest : FunSpec({
Expand All @@ -20,8 +19,8 @@ class ContainerDataTestNameFunctionTest : FunSpec({

context("Data test with triple") {
withData(
Triple(1,2,3),
Triple(3,2,1),
Triple(1, 2, 3),
Triple(3, 2, 1),
) {}
}

Expand Down Expand Up @@ -67,6 +66,17 @@ class ContainerDataTestNameFunctionTest : FunSpec({
) {}
}

context("data test with name function and range") {
withData<Int>(
{ i: Int -> "Test $i" },
1..3
) {}
}

context("data test with progression") {
withData(4 downTo 0 step 2) {}
}

}) {
override suspend fun afterAny(testCase: TestCase, result: TestResult) {
DataTestNamesStore.names.add(testCase.descriptor.id.value)
Expand Down Expand Up @@ -95,6 +105,14 @@ class ContainerDataTestNameFunctionTest : FunSpec({
"simplea1b1",
"simplea2b2",
"data test with name function and collection",
"Test 1",
"Test 2",
"Test 3",
"data test with name function and range",
"4",
"2",
"0",
"data test with progression",
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,12 @@ class RootDataTestNameFunctionTest : FunSpec({
)
) {}

withData<Int>(
{ i: Int -> "Test $i" },
1..3
) {}

withData(4 downTo 0 step 2) {}
}) {
override suspend fun afterAny(testCase: TestCase, result: TestResult) {
DataTestNamesStore.names.add(testCase.descriptor.id.value)
Expand All @@ -73,6 +79,12 @@ class RootDataTestNameFunctionTest : FunSpec({
"(1) simplea2b2",
"(2) simplea1b1",
"(2) simplea2b2",
"Test 1",
"Test 2",
"Test 3",
"4",
"2",
"0",
)
}

Expand Down

0 comments on commit 87ef4a8

Please sign in to comment.