diff --git a/kotest-framework/kotest-framework-datatest/api/kotest-framework-datatest.api b/kotest-framework/kotest-framework-datatest/api/kotest-framework-datatest.api index 42f897651d4..85e8b107d26 100644 --- a/kotest-framework/kotest-framework-datatest/api/kotest-framework-datatest.api +++ b/kotest-framework/kotest-framework-datatest/api/kotest-framework-datatest.api @@ -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 diff --git a/kotest-framework/kotest-framework-datatest/src/commonMain/kotlin/io/kotest/datatest/root.kt b/kotest-framework/kotest-framework-datatest/src/commonMain/kotlin/io/kotest/datatest/root.kt index a0a66c649a1..e5d8cc88589 100644 --- a/kotest-framework/kotest-framework-datatest/src/commonMain/kotlin/io/kotest/datatest/root.kt +++ b/kotest-framework/kotest-framework-datatest/src/commonMain/kotlin/io/kotest/datatest/root.kt @@ -47,7 +47,7 @@ fun RootScope.withData(nameFn: (T) -> String, ts: Sequence, test: suspend * * The test name will be generated from the stable properties of the elements. See [StableIdentifiers]. */ -fun RootScope.withData(ts: Collection, test: suspend ContainerScope.(T) -> Unit) { +fun RootScope.withData(ts: Iterable, test: suspend ContainerScope.(T) -> Unit) { withData({ getStableIdentifier(it) }, ts, test) } @@ -58,7 +58,7 @@ fun RootScope.withData(ts: Collection, test: suspend ContainerScope.(T) - */ fun RootScope.withData( nameFn: (T) -> String, - ts: Collection, + ts: Iterable, test: suspend ContainerScope.(T) -> Unit ) { ts.forEach { t -> diff --git a/kotest-framework/kotest-framework-datatest/src/jvmTest/kotlin/io/kotest/datatest/ContainerDataTestNameFunctionTest.kt b/kotest-framework/kotest-framework-datatest/src/jvmTest/kotlin/io/kotest/datatest/ContainerDataTestNameFunctionTest.kt index 18c9c536fa3..b356bd9d171 100644 --- a/kotest-framework/kotest-framework-datatest/src/jvmTest/kotlin/io/kotest/datatest/ContainerDataTestNameFunctionTest.kt +++ b/kotest-framework/kotest-framework-datatest/src/jvmTest/kotlin/io/kotest/datatest/ContainerDataTestNameFunctionTest.kt @@ -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({ @@ -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), ) {} } @@ -67,6 +66,17 @@ class ContainerDataTestNameFunctionTest : FunSpec({ ) {} } + context("data test with name function and range") { + withData( + { 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) @@ -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", ) } diff --git a/kotest-framework/kotest-framework-datatest/src/jvmTest/kotlin/io/kotest/datatest/RootDataTestNameFunctionTest.kt b/kotest-framework/kotest-framework-datatest/src/jvmTest/kotlin/io/kotest/datatest/RootDataTestNameFunctionTest.kt index a1cdbd024b6..3df399b8d1e 100644 --- a/kotest-framework/kotest-framework-datatest/src/jvmTest/kotlin/io/kotest/datatest/RootDataTestNameFunctionTest.kt +++ b/kotest-framework/kotest-framework-datatest/src/jvmTest/kotlin/io/kotest/datatest/RootDataTestNameFunctionTest.kt @@ -52,6 +52,12 @@ class RootDataTestNameFunctionTest : FunSpec({ ) ) {} + withData( + { 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) @@ -73,6 +79,12 @@ class RootDataTestNameFunctionTest : FunSpec({ "(1) simplea2b2", "(2) simplea1b1", "(2) simplea2b2", + "Test 1", + "Test 2", + "Test 3", + "4", + "2", + "0", ) }