All Downloads are FREE. Search and download functionalities are using the official Maven repository.

commonMain.io.kotest.datatest.root.kt Maven / Gradle / Ivy

There is a newer version: 5.9.1
Show newest version
package io.kotest.datatest

import io.kotest.core.names.TestName
import io.kotest.core.spec.style.scopes.ContainerScope
import io.kotest.core.spec.style.scopes.RootScope
import io.kotest.core.spec.style.scopes.addTest
import io.kotest.core.test.TestType
import kotlin.jvm.JvmName

/**
 * Registers tests at the root level for each element.
 *
 * The test name will be generated from the stable properties of the elements. See [StableIdentifiers].
 */
fun  RootScope.withData(first: T, second: T, vararg rest: T, test: suspend ContainerScope.(T) -> Unit) {
   withData(listOf(first, second) + rest, test)
}

fun  RootScope.withData(
   nameFn: (T) -> String,
   first: T,
   second: T,
   vararg rest: T,
   test: suspend ContainerScope.(T) -> Unit
) = withData(nameFn, listOf(first, second) + rest, test)

/**
 * Registers tests at the root level for each element of [ts].
 *
 * The test name will be generated from the stable properties of the elements. See [StableIdentifiers].
 */
fun  RootScope.withData(ts: Sequence, test: suspend ContainerScope.(T) -> Unit) {
   withData(ts.toList(), test)
}

/**
 * Registers tests at the root level for each element of [ts].
 *
 * The test name will be generated from the stable properties of the elements. See [StableIdentifiers].
 */
fun  RootScope.withData(nameFn: (T) -> String, ts: Sequence, test: suspend ContainerScope.(T) -> Unit) {
   withData(nameFn, ts.toList(), test)
}

/**
 * Registers tests at the root level for each element of [ts].
 *
 * 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) {
   withData({ getStableIdentifier(it) }, ts, test)
}

/**
 * Registers tests at the root level for each element of [ts].
 *
 * The test name will be generated from the given [nameFn] function.
 */
fun  RootScope.withData(
   nameFn: (T) -> String,
   ts: Collection,
   test: suspend ContainerScope.(T) -> Unit
) {
   ts.forEach { t ->
      addTest(TestName(nameFn(t)), false, null, TestType.Dynamic) { test(t) }
   }
}

/**
 * Registers tests at the root level for each tuple of [data], with the first value of the tuple
 * used as the test name, and the second value passed to the test.
 */
@JvmName("withDataMap")
fun  RootScope.withData(data: Map, test: suspend ContainerScope.(T) -> Unit) {
   data.forEach { (name, t) ->
      addTest(TestName(name), false, null, TestType.Dynamic) { test(t) }
   }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy