commonMain.com.copperleaf.ballast.test.internal.BallastTestSuiteScopeImpl.kt Maven / Gradle / Ivy
package com.copperleaf.ballast.test.internal
import com.copperleaf.ballast.BallastInterceptor
import com.copperleaf.ballast.BallastLogger
import com.copperleaf.ballast.EventHandler
import com.copperleaf.ballast.InputFilter
import com.copperleaf.ballast.InputHandler
import com.copperleaf.ballast.InputStrategy
import com.copperleaf.ballast.core.LifoInputStrategy
import com.copperleaf.ballast.test.BallastIsolatedScenarioScope
import com.copperleaf.ballast.test.BallastScenarioScope
import com.copperleaf.ballast.test.BallastTestSuiteScope
import com.copperleaf.ballast.test.internal.vm.TestInterceptorWrapper
import com.copperleaf.ballast.test.internal.vm.TestViewModel
import kotlin.time.Duration
import kotlin.time.Duration.Companion.seconds
import kotlin.time.ExperimentalTime
@ExperimentalTime
internal class BallastTestSuiteScopeImpl(
internal val inputHandler: InputHandler,
internal val eventHandler: EventHandler,
internal val filter: InputFilter?,
) : BallastTestSuiteScope {
internal var skip: Boolean = false
internal var suiteLogger: (String) -> BallastLogger = { SimpleTestLogger() }
internal var defaultTimeout: Duration = 30.seconds
internal var inputStrategy: InputStrategy = LifoInputStrategy()
internal val interceptors: MutableList<() -> BallastInterceptor, Events, State>> =
mutableListOf()
internal var defaultInitialStateBlock: (() -> State)? = null
internal val scenarioBlocks = mutableListOf>()
override fun skip() {
this.skip = true
}
override fun logger(logger: (String) -> BallastLogger) {
this.suiteLogger = logger
}
override fun defaultTimeout(timeout: () -> Duration) {
this.defaultTimeout = timeout()
}
override fun addInterceptor(interceptor: () -> BallastInterceptor) {
this.interceptors += { TestInterceptorWrapper(interceptor()) }
}
override fun defaultInputStrategy(inputStrategy: () -> InputStrategy) {
this.inputStrategy = inputStrategy()
}
override fun defaultInitialState(block: () -> State) {
defaultInitialStateBlock = block
}
override fun scenario(name: String, block: BallastScenarioScope.() -> Unit) {
scenarioBlocks += BallastScenarioScopeImpl(name).apply(block)
}
override fun isolatedScenario(
input: Inputs,
name: String,
block: BallastIsolatedScenarioScope.() -> Unit
) {
scenarioBlocks += BallastIsolatedScenarioScopeImpl(
delegate = BallastScenarioScopeImpl(name).apply {
running {
+input
}
}
)
.apply(block)
.delegate
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy