From cc6106dffef79a68823571106a06a2bfabe48d81 Mon Sep 17 00:00:00 2001 From: Mikhail Fedotov Date: Fri, 1 Mar 2024 18:08:09 +0700 Subject: [PATCH] [refactoring] Move files into folders (breaking change) This will break existing client code. But I have to store files in more structured way --- .../CoroutinesLibCoroutineAbstraction.kt | 2 +- .../CoroutinesStateMachine.kt | 5 +- .../{ => statemachine}/StateMachineFlow.kt | 7 +- .../ru/nsk/kstatemachine/DefaultState.kt | 67 ------------------- .../ru/nsk/kstatemachine/LibraryUtils.kt | 6 +- .../ru/nsk/kstatemachine/StateMachine.kt | 19 +++++- .../ru/nsk/kstatemachine/TreeAlgorithms.kt | 3 + .../{ => coroutines}/CoroutineAbstraction.kt | 6 +- .../{ => event}/DataExtractor.kt | 5 +- .../{TransitionParams.kt => event/Event.kt} | 34 ++-------- .../kstatemachine/{ => event}/EventMatcher.kt | 5 +- .../kstatemachine/{ => metainfo}/MetaInfo.kt | 5 +- .../{ => state}/BaseStateImpl.kt | 18 +++-- .../{ => state}/DefaultDataState.kt | 6 +- .../nsk/kstatemachine/state/DefaultState.kt | 11 +++ .../nsk/kstatemachine/{ => state}/IState.kt | 16 ++++- .../{ => state}/InternalState.kt | 7 +- .../{ => state}/StateGroupListener.kt | 3 +- .../{ => state}/StateListener.kt | 6 +- .../{ => state}/TransitionStateApi.kt | 9 ++- .../state/pseudo/BasePseudoState.kt | 24 +++++++ .../state/pseudo/DefaultChoiceState.kt | 44 ++++++++++++ .../{ => state/pseudo}/DefaultHistoryState.kt | 6 +- .../{ => state/pseudo}/UndoState.kt | 8 ++- .../{ => statemachine}/PendingEventHandler.kt | 5 +- .../{ => statemachine}/StateMachineImpl.kt | 36 +++++----- .../StateMachineListener.kt | 5 +- .../kstatemachine/{ => testing}/Testing.kt | 11 ++- .../{ => transition}/DefaultTransition.kt | 9 ++- .../{ => transition}/InternalTransition.kt | 5 +- .../{ => transition}/Transition.kt | 11 ++- .../{ => transition}/TransitionBuilder.kt | 14 +++- .../{ => transition}/TransitionDirection.kt | 11 ++- .../{ => transition}/TransitionListener.kt | 7 +- .../transition/TransitionParams.kt | 30 +++++++++ .../visitors/CheckUniqueNamesVisitor.kt | 8 +-- .../kstatemachine/visitors/CleanupVisitor.kt | 7 +- .../visitors/GetActiveStatesVisitor.kt | 6 +- .../visitors/RecursiveVisitor.kt | 2 +- .../ru/nsk/kstatemachine/visitors/Visitor.kt | 8 +-- .../{ => export}/ExportPlantUmlVisitor.kt | 25 +++++-- .../visitors/{ => export}/ExportToMermaid.kt | 6 +- .../ru/nsk/samples/ComplexSyntaxSample.kt | 11 ++- .../nsk/samples/CrossLevelTransitionSample.kt | 10 ++- .../samples/FinishedEventDataStateSample.kt | 9 ++- .../ru/nsk/samples/FinishedEventSample.kt | 6 +- .../ru/nsk/samples/FinishedStateSample.kt | 4 +- .../ru/nsk/samples/GuardedTransitionSample.kt | 5 +- .../nsk/samples/InheritTransitionsSample.kt | 9 ++- .../ru/nsk/samples/MermaidExportSample.kt | 6 +- .../nsk/samples/MinimalSealedClassesSample.kt | 5 +- .../ru/nsk/samples/MinimalSyntaxSample.kt | 5 +- .../ru/nsk/samples/PlantUmlExportSample.kt | 6 +- .../PlantUmlExportWithMetaInfoSample.kt | 11 ++- .../StdLibMinimalSealedClassesSample.kt | 6 +- .../nsk/samples/TypesafeTransitionSample.kt | 5 +- .../ru/nsk/samples/UndoTransitionSample.kt | 8 ++- .../ru/nsk/kstatemachine/CoroutinesTest.kt | 23 ++++++- .../ru/nsk/kstatemachine/IsSubStateOfTest.kt | 4 ++ .../kotlin/ru/nsk/kstatemachine/TestUtils.kt | 14 ++-- .../{ => event}/EventMatcherTest.kt | 13 +++- .../{ => event}/FinishedEventTest.kt | 6 +- .../{ => state}/AccessorsApiTest.kt | 4 +- .../{ => state}/ChoiceStateTest.kt | 11 ++- .../{ => state}/FinishingStateTest.kt | 6 +- .../{ => state}/HistoryStateTest.kt | 5 +- .../{ => state}/ListenersModificationTest.kt | 11 ++- .../{ => state}/NestedStateTest.kt | 6 +- .../{ => state}/ObjectStatesTest.kt | 13 +++- .../{ => state}/ParallelStatesTest.kt | 5 +- .../{ => state}/ParallelTargetStatesTest.kt | 5 +- .../{ => state}/StateCleanupTest.kt | 10 ++- .../{ => state}/StateGroupListenerTest.kt | 11 +-- .../kstatemachine/{ => state}/StateTest.kt | 11 ++- .../nsk/kstatemachine/{ => state}/UndoTest.kt | 12 +++- .../CompositionStateMachinesTest.kt | 4 +- .../FinishingStateMachineTest.kt | 5 +- .../IgnoredEventHandlerTest.kt | 10 ++- .../ListenerExceptionHandlerTest.kt | 6 +- .../PendingEventHandlerTest.kt | 12 +++- .../{ => statemachine}/StateMachineTest.kt | 17 +++-- .../{ => testing}/TestingStartFromTest.kt | 9 ++- .../ConditionalTransitionTest.kt | 12 +++- .../CrossLevelTransitionTest.kt | 6 +- .../{ => transition}/CustomTransitionTest.kt | 16 +++-- .../ExternalTransitionTest.kt | 9 ++- .../{ => transition}/GuardedTransitionTest.kt | 6 +- .../TransitionArgumentTest.kt | 6 +- .../TransitionOverrideTest.kt | 6 +- .../{ => transition}/TransitionTest.kt | 7 +- .../TypesafeTransitionTest.kt | 16 +++-- .../CheckUniqueNamesVisitorTest.kt} | 10 ++- .../GetActiveStatesVisitorTest.kt} | 10 ++- .../export/ExportPlantUmlVisitorTest.kt} | 15 +++-- 94 files changed, 707 insertions(+), 279 deletions(-) rename kstatemachine-coroutines/src/commonMain/kotlin/ru/nsk/kstatemachine/{ => coroutines}/CoroutinesLibCoroutineAbstraction.kt (92%) rename kstatemachine-coroutines/src/commonMain/kotlin/ru/nsk/kstatemachine/{ => statemachine}/CoroutinesStateMachine.kt (89%) rename kstatemachine-coroutines/src/commonMain/kotlin/ru/nsk/kstatemachine/{ => statemachine}/StateMachineFlow.kt (91%) delete mode 100644 kstatemachine/src/commonMain/kotlin/ru/nsk/kstatemachine/DefaultState.kt rename kstatemachine/src/commonMain/kotlin/ru/nsk/kstatemachine/{ => coroutines}/CoroutineAbstraction.kt (89%) rename kstatemachine/src/commonMain/kotlin/ru/nsk/kstatemachine/{ => event}/DataExtractor.kt (84%) rename kstatemachine/src/commonMain/kotlin/ru/nsk/kstatemachine/{TransitionParams.kt => event/Event.kt} (64%) rename kstatemachine/src/commonMain/kotlin/ru/nsk/kstatemachine/{ => event}/EventMatcher.kt (85%) rename kstatemachine/src/commonMain/kotlin/ru/nsk/kstatemachine/{ => metainfo}/MetaInfo.kt (90%) rename kstatemachine/src/commonMain/kotlin/ru/nsk/kstatemachine/{ => state}/BaseStateImpl.kt (96%) rename kstatemachine/src/commonMain/kotlin/ru/nsk/kstatemachine/{ => state}/DefaultDataState.kt (93%) create mode 100644 kstatemachine/src/commonMain/kotlin/ru/nsk/kstatemachine/state/DefaultState.kt rename kstatemachine/src/commonMain/kotlin/ru/nsk/kstatemachine/{ => state}/IState.kt (93%) rename kstatemachine/src/commonMain/kotlin/ru/nsk/kstatemachine/{ => state}/InternalState.kt (93%) rename kstatemachine/src/commonMain/kotlin/ru/nsk/kstatemachine/{ => state}/StateGroupListener.kt (97%) rename kstatemachine/src/commonMain/kotlin/ru/nsk/kstatemachine/{ => state}/StateListener.kt (86%) rename kstatemachine/src/commonMain/kotlin/ru/nsk/kstatemachine/{ => state}/TransitionStateApi.kt (95%) create mode 100644 kstatemachine/src/commonMain/kotlin/ru/nsk/kstatemachine/state/pseudo/BasePseudoState.kt create mode 100644 kstatemachine/src/commonMain/kotlin/ru/nsk/kstatemachine/state/pseudo/DefaultChoiceState.kt rename kstatemachine/src/commonMain/kotlin/ru/nsk/kstatemachine/{ => state/pseudo}/DefaultHistoryState.kt (90%) rename kstatemachine/src/commonMain/kotlin/ru/nsk/kstatemachine/{ => state/pseudo}/UndoState.kt (82%) rename kstatemachine/src/commonMain/kotlin/ru/nsk/kstatemachine/{ => statemachine}/PendingEventHandler.kt (91%) rename kstatemachine/src/commonMain/kotlin/ru/nsk/kstatemachine/{ => statemachine}/StateMachineImpl.kt (96%) rename kstatemachine/src/commonMain/kotlin/ru/nsk/kstatemachine/{ => statemachine}/StateMachineListener.kt (94%) rename kstatemachine/src/commonMain/kotlin/ru/nsk/kstatemachine/{ => testing}/Testing.kt (83%) rename kstatemachine/src/commonMain/kotlin/ru/nsk/kstatemachine/{ => transition}/DefaultTransition.kt (87%) rename kstatemachine/src/commonMain/kotlin/ru/nsk/kstatemachine/{ => transition}/InternalTransition.kt (75%) rename kstatemachine/src/commonMain/kotlin/ru/nsk/kstatemachine/{ => transition}/Transition.kt (84%) rename kstatemachine/src/commonMain/kotlin/ru/nsk/kstatemachine/{ => transition}/TransitionBuilder.kt (92%) rename kstatemachine/src/commonMain/kotlin/ru/nsk/kstatemachine/{ => transition}/TransitionDirection.kt (95%) rename kstatemachine/src/commonMain/kotlin/ru/nsk/kstatemachine/{ => transition}/TransitionListener.kt (80%) create mode 100644 kstatemachine/src/commonMain/kotlin/ru/nsk/kstatemachine/transition/TransitionParams.kt rename kstatemachine/src/commonMain/kotlin/ru/nsk/kstatemachine/visitors/{ => export}/ExportPlantUmlVisitor.kt (89%) rename kstatemachine/src/commonMain/kotlin/ru/nsk/kstatemachine/visitors/{ => export}/ExportToMermaid.kt (84%) rename tests/src/commonTest/kotlin/ru/nsk/kstatemachine/{ => event}/EventMatcherTest.kt (85%) rename tests/src/commonTest/kotlin/ru/nsk/kstatemachine/{ => event}/FinishedEventTest.kt (95%) rename tests/src/commonTest/kotlin/ru/nsk/kstatemachine/{ => state}/AccessorsApiTest.kt (97%) rename tests/src/commonTest/kotlin/ru/nsk/kstatemachine/{ => state}/ChoiceStateTest.kt (92%) rename tests/src/commonTest/kotlin/ru/nsk/kstatemachine/{ => state}/FinishingStateTest.kt (91%) rename tests/src/commonTest/kotlin/ru/nsk/kstatemachine/{ => state}/HistoryStateTest.kt (98%) rename tests/src/commonTest/kotlin/ru/nsk/kstatemachine/{ => state}/ListenersModificationTest.kt (77%) rename tests/src/commonTest/kotlin/ru/nsk/kstatemachine/{ => state}/NestedStateTest.kt (95%) rename tests/src/commonTest/kotlin/ru/nsk/kstatemachine/{ => state}/ObjectStatesTest.kt (81%) rename tests/src/commonTest/kotlin/ru/nsk/kstatemachine/{ => state}/ParallelStatesTest.kt (97%) rename tests/src/commonTest/kotlin/ru/nsk/kstatemachine/{ => state}/ParallelTargetStatesTest.kt (99%) rename tests/src/commonTest/kotlin/ru/nsk/kstatemachine/{ => state}/StateCleanupTest.kt (80%) rename tests/src/commonTest/kotlin/ru/nsk/kstatemachine/{ => state}/StateGroupListenerTest.kt (95%) rename tests/src/commonTest/kotlin/ru/nsk/kstatemachine/{ => state}/StateTest.kt (89%) rename tests/src/commonTest/kotlin/ru/nsk/kstatemachine/{ => state}/UndoTest.kt (97%) rename tests/src/commonTest/kotlin/ru/nsk/kstatemachine/{ => statemachine}/CompositionStateMachinesTest.kt (98%) rename tests/src/commonTest/kotlin/ru/nsk/kstatemachine/{ => statemachine}/FinishingStateMachineTest.kt (98%) rename tests/src/commonTest/kotlin/ru/nsk/kstatemachine/{ => statemachine}/IgnoredEventHandlerTest.kt (86%) rename tests/src/commonTest/kotlin/ru/nsk/kstatemachine/{ => statemachine}/ListenerExceptionHandlerTest.kt (96%) rename tests/src/commonTest/kotlin/ru/nsk/kstatemachine/{ => statemachine}/PendingEventHandlerTest.kt (92%) rename tests/src/commonTest/kotlin/ru/nsk/kstatemachine/{ => statemachine}/StateMachineTest.kt (95%) rename tests/src/commonTest/kotlin/ru/nsk/kstatemachine/{ => testing}/TestingStartFromTest.kt (94%) rename tests/src/commonTest/kotlin/ru/nsk/kstatemachine/{ => transition}/ConditionalTransitionTest.kt (92%) rename tests/src/commonTest/kotlin/ru/nsk/kstatemachine/{ => transition}/CrossLevelTransitionTest.kt (98%) rename tests/src/commonTest/kotlin/ru/nsk/kstatemachine/{ => transition}/CustomTransitionTest.kt (71%) rename tests/src/commonTest/kotlin/ru/nsk/kstatemachine/{ => transition}/ExternalTransitionTest.kt (94%) rename tests/src/commonTest/kotlin/ru/nsk/kstatemachine/{ => transition}/GuardedTransitionTest.kt (93%) rename tests/src/commonTest/kotlin/ru/nsk/kstatemachine/{ => transition}/TransitionArgumentTest.kt (87%) rename tests/src/commonTest/kotlin/ru/nsk/kstatemachine/{ => transition}/TransitionOverrideTest.kt (94%) rename tests/src/commonTest/kotlin/ru/nsk/kstatemachine/{ => transition}/TransitionTest.kt (96%) rename tests/src/commonTest/kotlin/ru/nsk/kstatemachine/{ => transition}/TypesafeTransitionTest.kt (95%) rename tests/src/commonTest/kotlin/ru/nsk/kstatemachine/{UniqueNamesTest.kt => visitors/CheckUniqueNamesVisitorTest.kt} (81%) rename tests/src/commonTest/kotlin/ru/nsk/kstatemachine/{ActiveStatesTest.kt => visitors/GetActiveStatesVisitorTest.kt} (89%) rename tests/src/commonTest/kotlin/ru/nsk/kstatemachine/{ExportToPlantUmlTest.kt => visitors/export/ExportPlantUmlVisitorTest.kt} (96%) diff --git a/kstatemachine-coroutines/src/commonMain/kotlin/ru/nsk/kstatemachine/CoroutinesLibCoroutineAbstraction.kt b/kstatemachine-coroutines/src/commonMain/kotlin/ru/nsk/kstatemachine/coroutines/CoroutinesLibCoroutineAbstraction.kt similarity index 92% rename from kstatemachine-coroutines/src/commonMain/kotlin/ru/nsk/kstatemachine/CoroutinesLibCoroutineAbstraction.kt rename to kstatemachine-coroutines/src/commonMain/kotlin/ru/nsk/kstatemachine/coroutines/CoroutinesLibCoroutineAbstraction.kt index 9a44dc14..52e1fa24 100644 --- a/kstatemachine-coroutines/src/commonMain/kotlin/ru/nsk/kstatemachine/CoroutinesLibCoroutineAbstraction.kt +++ b/kstatemachine-coroutines/src/commonMain/kotlin/ru/nsk/kstatemachine/coroutines/CoroutinesLibCoroutineAbstraction.kt @@ -1,4 +1,4 @@ -package ru.nsk.kstatemachine +package ru.nsk.kstatemachine.coroutines import kotlinx.coroutines.* diff --git a/kstatemachine-coroutines/src/commonMain/kotlin/ru/nsk/kstatemachine/CoroutinesStateMachine.kt b/kstatemachine-coroutines/src/commonMain/kotlin/ru/nsk/kstatemachine/statemachine/CoroutinesStateMachine.kt similarity index 89% rename from kstatemachine-coroutines/src/commonMain/kotlin/ru/nsk/kstatemachine/CoroutinesStateMachine.kt rename to kstatemachine-coroutines/src/commonMain/kotlin/ru/nsk/kstatemachine/statemachine/CoroutinesStateMachine.kt index 74273b72..c46b3100 100644 --- a/kstatemachine-coroutines/src/commonMain/kotlin/ru/nsk/kstatemachine/CoroutinesStateMachine.kt +++ b/kstatemachine-coroutines/src/commonMain/kotlin/ru/nsk/kstatemachine/statemachine/CoroutinesStateMachine.kt @@ -1,6 +1,9 @@ -package ru.nsk.kstatemachine +package ru.nsk.kstatemachine.statemachine import kotlinx.coroutines.CoroutineScope +import ru.nsk.kstatemachine.coroutines.CoroutinesLibCoroutineAbstraction +import ru.nsk.kstatemachine.coroutines.createStateMachine +import ru.nsk.kstatemachine.state.ChildMode /** * Suspendable analog of [createStdLibStateMachine] function, with Kotlin Coroutines support. diff --git a/kstatemachine-coroutines/src/commonMain/kotlin/ru/nsk/kstatemachine/StateMachineFlow.kt b/kstatemachine-coroutines/src/commonMain/kotlin/ru/nsk/kstatemachine/statemachine/StateMachineFlow.kt similarity index 91% rename from kstatemachine-coroutines/src/commonMain/kotlin/ru/nsk/kstatemachine/StateMachineFlow.kt rename to kstatemachine-coroutines/src/commonMain/kotlin/ru/nsk/kstatemachine/statemachine/StateMachineFlow.kt index 64bbfda8..c145ddb1 100644 --- a/kstatemachine-coroutines/src/commonMain/kotlin/ru/nsk/kstatemachine/StateMachineFlow.kt +++ b/kstatemachine-coroutines/src/commonMain/kotlin/ru/nsk/kstatemachine/statemachine/StateMachineFlow.kt @@ -1,7 +1,10 @@ -package ru.nsk.kstatemachine +package ru.nsk.kstatemachine.statemachine import kotlinx.coroutines.flow.* -import ru.nsk.kstatemachine.StateMachineNotification.* +import ru.nsk.kstatemachine.statemachine.StateMachineNotification.* +import ru.nsk.kstatemachine.state.IState +import ru.nsk.kstatemachine.state.activeStates +import ru.nsk.kstatemachine.transition.TransitionParams sealed class StateMachineNotification(val machine: StateMachine) { class Started(machine: StateMachine) : StateMachineNotification(machine) diff --git a/kstatemachine/src/commonMain/kotlin/ru/nsk/kstatemachine/DefaultState.kt b/kstatemachine/src/commonMain/kotlin/ru/nsk/kstatemachine/DefaultState.kt deleted file mode 100644 index 43c92f87..00000000 --- a/kstatemachine/src/commonMain/kotlin/ru/nsk/kstatemachine/DefaultState.kt +++ /dev/null @@ -1,67 +0,0 @@ -package ru.nsk.kstatemachine - -import ru.nsk.kstatemachine.ChildMode.EXCLUSIVE -import ru.nsk.kstatemachine.TransitionDirectionProducerPolicy.* - -/** - * The most common state - */ -open class DefaultState(name: String? = null, childMode: ChildMode = EXCLUSIVE) : - BaseStateImpl(name, childMode), State - -open class DefaultFinalState(name: String? = null) : DefaultState(name), FinalState - -open class DefaultChoiceState( - name: String? = null, - private val choiceAction: suspend EventAndArgument<*>.() -> State -) : BasePseudoState(name), RedirectPseudoState { - - override suspend fun resolveTargetState(policy: TransitionDirectionProducerPolicy<*>): TransitionDirection { - return internalResolveTargetState(policy, choiceAction) - } -} - -open class DefaultChoiceDataState( - name: String? = null, - private val choiceAction: suspend EventAndArgument<*>.() -> DataState, -) : DataState, BasePseudoState(name), RedirectPseudoState { - - override suspend fun resolveTargetState(policy: TransitionDirectionProducerPolicy<*>): TransitionDirection { - return internalResolveTargetState(policy, choiceAction) - } - - override val defaultData: D? = null - override val data: D get() = error("PseudoState $this can not have data") - override val lastData: D get() = error("PseudoState $this can not have lastData") -} - -private suspend fun IState.internalResolveTargetState( - policy: TransitionDirectionProducerPolicy<*>, - choiceAction: suspend EventAndArgument<*>.() -> IState -): TransitionDirection { - return when (policy) { - is DefaultPolicy -> policy.targetState( - policy.eventAndArgument.choiceAction().also { log { "$this resolved to $it" } } - ) - is CollectTargetStatesPolicy -> noTransition() - is UnsafeCollectTargetStatesPolicy -> policy.targetState(policy.eventAndArgument.choiceAction()) - } -} - -open class BasePseudoState(name: String?) : BaseStateImpl(name, EXCLUSIVE), PseudoState { - override suspend fun doEnter(transitionParams: TransitionParams<*>) = internalError() - override suspend fun doExit(transitionParams: TransitionParams<*>) = internalError() - - override fun addListener(listener: L) = - throw UnsupportedOperationException("PseudoState $this can not have listeners") - - override fun addState(state: S, init: StateBlock?) = - throw UnsupportedOperationException("PseudoState $this can not have child states") - - - override fun addTransition(transition: Transition) = - throw UnsupportedOperationException("PseudoState $this can not have transitions") - - private fun internalError(): Nothing = - error("Internal error, PseudoState $this can not be entered or exited, looks that machine is purely configured") -} \ No newline at end of file diff --git a/kstatemachine/src/commonMain/kotlin/ru/nsk/kstatemachine/LibraryUtils.kt b/kstatemachine/src/commonMain/kotlin/ru/nsk/kstatemachine/LibraryUtils.kt index 9ef809a2..d762f8bc 100644 --- a/kstatemachine/src/commonMain/kotlin/ru/nsk/kstatemachine/LibraryUtils.kt +++ b/kstatemachine/src/commonMain/kotlin/ru/nsk/kstatemachine/LibraryUtils.kt @@ -1,7 +1,11 @@ package ru.nsk.kstatemachine +import ru.nsk.kstatemachine.state.IState +import ru.nsk.kstatemachine.state.InternalState +import ru.nsk.kstatemachine.statemachine.StateMachine + /** - * [forEach] analog which ignores internal state machines + * [forEach] analog which ignores internal [StateMachine]s */ internal suspend fun Iterable.forEachState(block: suspend (InternalState) -> Unit) { forEach { if (it !is StateMachine) block(it) } diff --git a/kstatemachine/src/commonMain/kotlin/ru/nsk/kstatemachine/StateMachine.kt b/kstatemachine/src/commonMain/kotlin/ru/nsk/kstatemachine/StateMachine.kt index 3f733997..9473fa36 100644 --- a/kstatemachine/src/commonMain/kotlin/ru/nsk/kstatemachine/StateMachine.kt +++ b/kstatemachine/src/commonMain/kotlin/ru/nsk/kstatemachine/StateMachine.kt @@ -1,6 +1,19 @@ -package ru.nsk.kstatemachine - -import ru.nsk.kstatemachine.StateMachine.PendingEventHandler +package ru.nsk.kstatemachine.statemachine + +import ru.nsk.kstatemachine.coroutines.CoroutineAbstraction +import ru.nsk.kstatemachine.coroutines.StdLibCoroutineAbstraction +import ru.nsk.kstatemachine.coroutines.createStateMachine +import ru.nsk.kstatemachine.event.DestroyEvent +import ru.nsk.kstatemachine.event.Event +import ru.nsk.kstatemachine.event.StopEvent +import ru.nsk.kstatemachine.event.UndoEvent +import ru.nsk.kstatemachine.state.ChildMode +import ru.nsk.kstatemachine.state.IState +import ru.nsk.kstatemachine.state.State +import ru.nsk.kstatemachine.statemachine.StateMachine.PendingEventHandler +import ru.nsk.kstatemachine.transition.EventAndArgument +import ru.nsk.kstatemachine.transition.Transition +import ru.nsk.kstatemachine.transition.TransitionParams import ru.nsk.kstatemachine.visitors.CoVisitor import ru.nsk.kstatemachine.visitors.Visitor diff --git a/kstatemachine/src/commonMain/kotlin/ru/nsk/kstatemachine/TreeAlgorithms.kt b/kstatemachine/src/commonMain/kotlin/ru/nsk/kstatemachine/TreeAlgorithms.kt index 74d130a0..796868ca 100644 --- a/kstatemachine/src/commonMain/kotlin/ru/nsk/kstatemachine/TreeAlgorithms.kt +++ b/kstatemachine/src/commonMain/kotlin/ru/nsk/kstatemachine/TreeAlgorithms.kt @@ -1,5 +1,8 @@ package ru.nsk.kstatemachine +import ru.nsk.kstatemachine.state.InternalNode +import ru.nsk.kstatemachine.state.requireParentNode + /** * @return Path from [targetState] to the lowest common ancestor (lca). * Path order: Lca and its parent if [addLcaParent] is true are last elements in resulting list. diff --git a/kstatemachine/src/commonMain/kotlin/ru/nsk/kstatemachine/CoroutineAbstraction.kt b/kstatemachine/src/commonMain/kotlin/ru/nsk/kstatemachine/coroutines/CoroutineAbstraction.kt similarity index 89% rename from kstatemachine/src/commonMain/kotlin/ru/nsk/kstatemachine/CoroutineAbstraction.kt rename to kstatemachine/src/commonMain/kotlin/ru/nsk/kstatemachine/coroutines/CoroutineAbstraction.kt index 3d19adff..0e19f653 100644 --- a/kstatemachine/src/commonMain/kotlin/ru/nsk/kstatemachine/CoroutineAbstraction.kt +++ b/kstatemachine/src/commonMain/kotlin/ru/nsk/kstatemachine/coroutines/CoroutineAbstraction.kt @@ -1,5 +1,9 @@ -package ru.nsk.kstatemachine +package ru.nsk.kstatemachine.coroutines +import ru.nsk.kstatemachine.state.ChildMode +import ru.nsk.kstatemachine.statemachine.BuildingStateMachine +import ru.nsk.kstatemachine.statemachine.StateMachine +import ru.nsk.kstatemachine.statemachine.StateMachineImpl import kotlin.coroutines.Continuation import kotlin.coroutines.EmptyCoroutineContext import kotlin.coroutines.startCoroutine diff --git a/kstatemachine/src/commonMain/kotlin/ru/nsk/kstatemachine/DataExtractor.kt b/kstatemachine/src/commonMain/kotlin/ru/nsk/kstatemachine/event/DataExtractor.kt similarity index 84% rename from kstatemachine/src/commonMain/kotlin/ru/nsk/kstatemachine/DataExtractor.kt rename to kstatemachine/src/commonMain/kotlin/ru/nsk/kstatemachine/event/DataExtractor.kt index 27196f69..890461ee 100644 --- a/kstatemachine/src/commonMain/kotlin/ru/nsk/kstatemachine/DataExtractor.kt +++ b/kstatemachine/src/commonMain/kotlin/ru/nsk/kstatemachine/event/DataExtractor.kt @@ -1,4 +1,7 @@ -package ru.nsk.kstatemachine +package ru.nsk.kstatemachine.event + +import ru.nsk.kstatemachine.state.DataState +import ru.nsk.kstatemachine.transition.TransitionParams /** * Allows to extract data for [DataState] from any [Event] diff --git a/kstatemachine/src/commonMain/kotlin/ru/nsk/kstatemachine/TransitionParams.kt b/kstatemachine/src/commonMain/kotlin/ru/nsk/kstatemachine/event/Event.kt similarity index 64% rename from kstatemachine/src/commonMain/kotlin/ru/nsk/kstatemachine/TransitionParams.kt rename to kstatemachine/src/commonMain/kotlin/ru/nsk/kstatemachine/event/Event.kt index 0270a9bb..b49f7488 100644 --- a/kstatemachine/src/commonMain/kotlin/ru/nsk/kstatemachine/TransitionParams.kt +++ b/kstatemachine/src/commonMain/kotlin/ru/nsk/kstatemachine/event/Event.kt @@ -1,4 +1,8 @@ -package ru.nsk.kstatemachine +package ru.nsk.kstatemachine.event + +import ru.nsk.kstatemachine.state.* +import ru.nsk.kstatemachine.statemachine.StateMachine +import ru.nsk.kstatemachine.statemachine.processEventBlocking /** * Base interface for events which may trigger transitions of [StateMachine] @@ -64,29 +68,5 @@ internal class DestroyEvent(val stop: Boolean) : GeneratedEvent * @param event original event * @param argument original argument */ -class WrappedEvent(val event: Event, val argument: Any?) : Event - -@StateMachineDslMarker -data class TransitionParams( - val transition: Transition, - val direction: TransitionDirection, - val event: E, - /** - * This parameter may be used to pass arbitrary data with the event, - * so there is no need to define [Event] subclasses every time. - * Subclassing should be preferred if the event always contains data of some type. - */ - val argument: Any? = null, -) - -/** - * Convenience property for unwrapping original event. - * If the event is not [WrappedEvent] this is same as [TransitionParams.event] property - */ -val TransitionParams<*>.unwrappedEvent get() = if (event is WrappedEvent) event.event else event - -/** - * Convenience property for unwrapping original argument. - * If the event is not [WrappedEvent] this is same as [TransitionParams.argument] property - */ -val TransitionParams<*>.unwrappedArgument get() = if (event is WrappedEvent) event.argument else argument \ No newline at end of file +class WrappedEvent(val event: Event, val argument: Any?) : + Event \ No newline at end of file diff --git a/kstatemachine/src/commonMain/kotlin/ru/nsk/kstatemachine/EventMatcher.kt b/kstatemachine/src/commonMain/kotlin/ru/nsk/kstatemachine/event/EventMatcher.kt similarity index 85% rename from kstatemachine/src/commonMain/kotlin/ru/nsk/kstatemachine/EventMatcher.kt rename to kstatemachine/src/commonMain/kotlin/ru/nsk/kstatemachine/event/EventMatcher.kt index 5d44661b..d5a571af 100644 --- a/kstatemachine/src/commonMain/kotlin/ru/nsk/kstatemachine/EventMatcher.kt +++ b/kstatemachine/src/commonMain/kotlin/ru/nsk/kstatemachine/event/EventMatcher.kt @@ -1,5 +1,8 @@ -package ru.nsk.kstatemachine +package ru.nsk.kstatemachine.event +import ru.nsk.kstatemachine.state.IState +import ru.nsk.kstatemachine.transition.Transition +import ru.nsk.kstatemachine.transition.TransitionBuilder import kotlin.reflect.KClass /** diff --git a/kstatemachine/src/commonMain/kotlin/ru/nsk/kstatemachine/MetaInfo.kt b/kstatemachine/src/commonMain/kotlin/ru/nsk/kstatemachine/metainfo/MetaInfo.kt similarity index 90% rename from kstatemachine/src/commonMain/kotlin/ru/nsk/kstatemachine/MetaInfo.kt rename to kstatemachine/src/commonMain/kotlin/ru/nsk/kstatemachine/metainfo/MetaInfo.kt index f7577287..4dabad45 100644 --- a/kstatemachine/src/commonMain/kotlin/ru/nsk/kstatemachine/MetaInfo.kt +++ b/kstatemachine/src/commonMain/kotlin/ru/nsk/kstatemachine/metainfo/MetaInfo.kt @@ -1,4 +1,7 @@ -package ru.nsk.kstatemachine +package ru.nsk.kstatemachine.metainfo + +import ru.nsk.kstatemachine.state.IState +import ru.nsk.kstatemachine.transition.Transition /** * Additional static (designed to be immutable) info for library primitives like [IState] [Transition] etc. diff --git a/kstatemachine/src/commonMain/kotlin/ru/nsk/kstatemachine/BaseStateImpl.kt b/kstatemachine/src/commonMain/kotlin/ru/nsk/kstatemachine/state/BaseStateImpl.kt similarity index 96% rename from kstatemachine/src/commonMain/kotlin/ru/nsk/kstatemachine/BaseStateImpl.kt rename to kstatemachine/src/commonMain/kotlin/ru/nsk/kstatemachine/state/BaseStateImpl.kt index 70651cb7..7d99594a 100644 --- a/kstatemachine/src/commonMain/kotlin/ru/nsk/kstatemachine/BaseStateImpl.kt +++ b/kstatemachine/src/commonMain/kotlin/ru/nsk/kstatemachine/state/BaseStateImpl.kt @@ -1,8 +1,16 @@ -package ru.nsk.kstatemachine - -import ru.nsk.kstatemachine.ChildMode.EXCLUSIVE -import ru.nsk.kstatemachine.ChildMode.PARALLEL -import ru.nsk.kstatemachine.TransitionType.EXTERNAL +package ru.nsk.kstatemachine.state + +import ru.nsk.kstatemachine.* +import ru.nsk.kstatemachine.event.Event +import ru.nsk.kstatemachine.event.FinishedEvent +import ru.nsk.kstatemachine.metainfo.MetaInfo +import ru.nsk.kstatemachine.state.ChildMode.EXCLUSIVE +import ru.nsk.kstatemachine.state.ChildMode.PARALLEL +import ru.nsk.kstatemachine.statemachine.StateMachine +import ru.nsk.kstatemachine.statemachine.destroyBlocking +import ru.nsk.kstatemachine.statemachine.machineNotify +import ru.nsk.kstatemachine.transition.* +import ru.nsk.kstatemachine.transition.TransitionType.EXTERNAL /** * Base [IState] implementation for all states diff --git a/kstatemachine/src/commonMain/kotlin/ru/nsk/kstatemachine/DefaultDataState.kt b/kstatemachine/src/commonMain/kotlin/ru/nsk/kstatemachine/state/DefaultDataState.kt similarity index 93% rename from kstatemachine/src/commonMain/kotlin/ru/nsk/kstatemachine/DefaultDataState.kt rename to kstatemachine/src/commonMain/kotlin/ru/nsk/kstatemachine/state/DefaultDataState.kt index 7a8f9ddb..55e38777 100644 --- a/kstatemachine/src/commonMain/kotlin/ru/nsk/kstatemachine/DefaultDataState.kt +++ b/kstatemachine/src/commonMain/kotlin/ru/nsk/kstatemachine/state/DefaultDataState.kt @@ -1,6 +1,8 @@ -package ru.nsk.kstatemachine +package ru.nsk.kstatemachine.state -import ru.nsk.kstatemachine.ChildMode.EXCLUSIVE +import ru.nsk.kstatemachine.event.* +import ru.nsk.kstatemachine.state.ChildMode.EXCLUSIVE +import ru.nsk.kstatemachine.transition.TransitionParams /** inline constructor function */ inline fun defaultDataState( diff --git a/kstatemachine/src/commonMain/kotlin/ru/nsk/kstatemachine/state/DefaultState.kt b/kstatemachine/src/commonMain/kotlin/ru/nsk/kstatemachine/state/DefaultState.kt new file mode 100644 index 00000000..a80b6e06 --- /dev/null +++ b/kstatemachine/src/commonMain/kotlin/ru/nsk/kstatemachine/state/DefaultState.kt @@ -0,0 +1,11 @@ +package ru.nsk.kstatemachine.state + +import ru.nsk.kstatemachine.state.ChildMode.EXCLUSIVE + +/** + * The most common state + */ +open class DefaultState(name: String? = null, childMode: ChildMode = EXCLUSIVE) : + BaseStateImpl(name, childMode), State + +open class DefaultFinalState(name: String? = null) : DefaultState(name), FinalState \ No newline at end of file diff --git a/kstatemachine/src/commonMain/kotlin/ru/nsk/kstatemachine/IState.kt b/kstatemachine/src/commonMain/kotlin/ru/nsk/kstatemachine/state/IState.kt similarity index 93% rename from kstatemachine/src/commonMain/kotlin/ru/nsk/kstatemachine/IState.kt rename to kstatemachine/src/commonMain/kotlin/ru/nsk/kstatemachine/state/IState.kt index e5125117..a3bb9a0e 100644 --- a/kstatemachine/src/commonMain/kotlin/ru/nsk/kstatemachine/IState.kt +++ b/kstatemachine/src/commonMain/kotlin/ru/nsk/kstatemachine/state/IState.kt @@ -1,5 +1,17 @@ -package ru.nsk.kstatemachine - +package ru.nsk.kstatemachine.state + +import ru.nsk.kstatemachine.event.DataExtractor +import ru.nsk.kstatemachine.event.defaultDataExtractor +import ru.nsk.kstatemachine.metainfo.MetaInfo +import ru.nsk.kstatemachine.state.pseudo.DefaultChoiceDataState +import ru.nsk.kstatemachine.state.pseudo.DefaultChoiceState +import ru.nsk.kstatemachine.state.pseudo.DefaultHistoryState +import ru.nsk.kstatemachine.statemachine.StateMachine +import ru.nsk.kstatemachine.statemachine.StateMachineDslMarker +import ru.nsk.kstatemachine.transition.EventAndArgument +import ru.nsk.kstatemachine.transition.TransitionDirection +import ru.nsk.kstatemachine.transition.TransitionDirectionProducerPolicy +import ru.nsk.kstatemachine.transition.TransitionParams import ru.nsk.kstatemachine.visitors.CoVisitor import ru.nsk.kstatemachine.visitors.GetActiveStatesVisitor import ru.nsk.kstatemachine.visitors.Visitor diff --git a/kstatemachine/src/commonMain/kotlin/ru/nsk/kstatemachine/InternalState.kt b/kstatemachine/src/commonMain/kotlin/ru/nsk/kstatemachine/state/InternalState.kt similarity index 93% rename from kstatemachine/src/commonMain/kotlin/ru/nsk/kstatemachine/InternalState.kt rename to kstatemachine/src/commonMain/kotlin/ru/nsk/kstatemachine/state/InternalState.kt index 17d3faec..45b8189a 100644 --- a/kstatemachine/src/commonMain/kotlin/ru/nsk/kstatemachine/InternalState.kt +++ b/kstatemachine/src/commonMain/kotlin/ru/nsk/kstatemachine/state/InternalState.kt @@ -1,6 +1,9 @@ -package ru.nsk.kstatemachine +package ru.nsk.kstatemachine.state -import ru.nsk.kstatemachine.TransitionDirectionProducerPolicy.DefaultPolicy +import ru.nsk.kstatemachine.PathNode +import ru.nsk.kstatemachine.event.Event +import ru.nsk.kstatemachine.transition.* +import ru.nsk.kstatemachine.transition.TransitionDirectionProducerPolicy.DefaultPolicy /** * Contains tree composition api for [InternalState]. diff --git a/kstatemachine/src/commonMain/kotlin/ru/nsk/kstatemachine/StateGroupListener.kt b/kstatemachine/src/commonMain/kotlin/ru/nsk/kstatemachine/state/StateGroupListener.kt similarity index 97% rename from kstatemachine/src/commonMain/kotlin/ru/nsk/kstatemachine/StateGroupListener.kt rename to kstatemachine/src/commonMain/kotlin/ru/nsk/kstatemachine/state/StateGroupListener.kt index 1da4f894..6d1a42c1 100644 --- a/kstatemachine/src/commonMain/kotlin/ru/nsk/kstatemachine/StateGroupListener.kt +++ b/kstatemachine/src/commonMain/kotlin/ru/nsk/kstatemachine/state/StateGroupListener.kt @@ -1,5 +1,6 @@ -package ru.nsk.kstatemachine +package ru.nsk.kstatemachine.state +import ru.nsk.kstatemachine.transition.TransitionParams import kotlin.properties.Delegates.observable interface GroupListener { diff --git a/kstatemachine/src/commonMain/kotlin/ru/nsk/kstatemachine/StateListener.kt b/kstatemachine/src/commonMain/kotlin/ru/nsk/kstatemachine/state/StateListener.kt similarity index 86% rename from kstatemachine/src/commonMain/kotlin/ru/nsk/kstatemachine/StateListener.kt rename to kstatemachine/src/commonMain/kotlin/ru/nsk/kstatemachine/state/StateListener.kt index b772bbf7..c10b451f 100644 --- a/kstatemachine/src/commonMain/kotlin/ru/nsk/kstatemachine/StateListener.kt +++ b/kstatemachine/src/commonMain/kotlin/ru/nsk/kstatemachine/state/StateListener.kt @@ -1,4 +1,8 @@ -package ru.nsk.kstatemachine +package ru.nsk.kstatemachine.state + +import ru.nsk.kstatemachine.statemachine.InternalStateMachine +import ru.nsk.kstatemachine.statemachine.runDelayingException +import ru.nsk.kstatemachine.transition.TransitionParams internal suspend inline fun InternalState.stateNotify(crossinline block: suspend IState.Listener.() -> Unit) { val machine = machine as InternalStateMachine diff --git a/kstatemachine/src/commonMain/kotlin/ru/nsk/kstatemachine/TransitionStateApi.kt b/kstatemachine/src/commonMain/kotlin/ru/nsk/kstatemachine/state/TransitionStateApi.kt similarity index 95% rename from kstatemachine/src/commonMain/kotlin/ru/nsk/kstatemachine/TransitionStateApi.kt rename to kstatemachine/src/commonMain/kotlin/ru/nsk/kstatemachine/state/TransitionStateApi.kt index aafd75bf..50177dc8 100644 --- a/kstatemachine/src/commonMain/kotlin/ru/nsk/kstatemachine/TransitionStateApi.kt +++ b/kstatemachine/src/commonMain/kotlin/ru/nsk/kstatemachine/state/TransitionStateApi.kt @@ -1,7 +1,10 @@ -package ru.nsk.kstatemachine +package ru.nsk.kstatemachine.state -import ru.nsk.kstatemachine.EventMatcher.Companion.isInstanceOf -import ru.nsk.kstatemachine.TransitionType.LOCAL +import ru.nsk.kstatemachine.event.* +import ru.nsk.kstatemachine.event.EventMatcher.Companion.isInstanceOf +import ru.nsk.kstatemachine.metainfo.MetaInfo +import ru.nsk.kstatemachine.transition.* +import ru.nsk.kstatemachine.transition.TransitionType.LOCAL /** * Helper interface for [IState] to keep transitions logic separately. diff --git a/kstatemachine/src/commonMain/kotlin/ru/nsk/kstatemachine/state/pseudo/BasePseudoState.kt b/kstatemachine/src/commonMain/kotlin/ru/nsk/kstatemachine/state/pseudo/BasePseudoState.kt new file mode 100644 index 00000000..e2b059a2 --- /dev/null +++ b/kstatemachine/src/commonMain/kotlin/ru/nsk/kstatemachine/state/pseudo/BasePseudoState.kt @@ -0,0 +1,24 @@ +package ru.nsk.kstatemachine.state.pseudo + +import ru.nsk.kstatemachine.event.Event +import ru.nsk.kstatemachine.state.* +import ru.nsk.kstatemachine.transition.Transition +import ru.nsk.kstatemachine.transition.TransitionParams + +open class BasePseudoState(name: String?) : BaseStateImpl(name, ChildMode.EXCLUSIVE), PseudoState { + override suspend fun doEnter(transitionParams: TransitionParams<*>) = internalError() + override suspend fun doExit(transitionParams: TransitionParams<*>) = internalError() + + override fun addListener(listener: L) = + throw UnsupportedOperationException("PseudoState $this can not have listeners") + + override fun addState(state: S, init: StateBlock?) = + throw UnsupportedOperationException("PseudoState $this can not have child states") + + + override fun addTransition(transition: Transition) = + throw UnsupportedOperationException("PseudoState $this can not have transitions") + + private fun internalError(): Nothing = + error("Internal error, PseudoState $this can not be entered or exited, looks that machine is purely configured") +} \ No newline at end of file diff --git a/kstatemachine/src/commonMain/kotlin/ru/nsk/kstatemachine/state/pseudo/DefaultChoiceState.kt b/kstatemachine/src/commonMain/kotlin/ru/nsk/kstatemachine/state/pseudo/DefaultChoiceState.kt new file mode 100644 index 00000000..298ca2c5 --- /dev/null +++ b/kstatemachine/src/commonMain/kotlin/ru/nsk/kstatemachine/state/pseudo/DefaultChoiceState.kt @@ -0,0 +1,44 @@ +package ru.nsk.kstatemachine.state.pseudo + +import ru.nsk.kstatemachine.state.* +import ru.nsk.kstatemachine.transition.EventAndArgument +import ru.nsk.kstatemachine.transition.TransitionDirection +import ru.nsk.kstatemachine.transition.TransitionDirectionProducerPolicy +import ru.nsk.kstatemachine.transition.noTransition + +open class DefaultChoiceState( + name: String? = null, + private val choiceAction: suspend EventAndArgument<*>.() -> State +) : BasePseudoState(name), RedirectPseudoState { + + override suspend fun resolveTargetState(policy: TransitionDirectionProducerPolicy<*>): TransitionDirection { + return internalResolveTargetState(policy, choiceAction) + } +} + +open class DefaultChoiceDataState( + name: String? = null, + private val choiceAction: suspend EventAndArgument<*>.() -> DataState, +) : DataState, BasePseudoState(name), RedirectPseudoState { + + override suspend fun resolveTargetState(policy: TransitionDirectionProducerPolicy<*>): TransitionDirection { + return internalResolveTargetState(policy, choiceAction) + } + + override val defaultData: D? = null + override val data: D get() = error("PseudoState $this can not have data") + override val lastData: D get() = error("PseudoState $this can not have lastData") +} + +private suspend fun IState.internalResolveTargetState( + policy: TransitionDirectionProducerPolicy<*>, + choiceAction: suspend EventAndArgument<*>.() -> IState +): TransitionDirection { + return when (policy) { + is TransitionDirectionProducerPolicy.DefaultPolicy -> policy.targetState( + policy.eventAndArgument.choiceAction().also { log { "$this resolved to $it" } } + ) + is TransitionDirectionProducerPolicy.CollectTargetStatesPolicy -> noTransition() + is TransitionDirectionProducerPolicy.UnsafeCollectTargetStatesPolicy -> policy.targetState(policy.eventAndArgument.choiceAction()) + } +} \ No newline at end of file diff --git a/kstatemachine/src/commonMain/kotlin/ru/nsk/kstatemachine/DefaultHistoryState.kt b/kstatemachine/src/commonMain/kotlin/ru/nsk/kstatemachine/state/pseudo/DefaultHistoryState.kt similarity index 90% rename from kstatemachine/src/commonMain/kotlin/ru/nsk/kstatemachine/DefaultHistoryState.kt rename to kstatemachine/src/commonMain/kotlin/ru/nsk/kstatemachine/state/pseudo/DefaultHistoryState.kt index b5d7504c..294b224c 100644 --- a/kstatemachine/src/commonMain/kotlin/ru/nsk/kstatemachine/DefaultHistoryState.kt +++ b/kstatemachine/src/commonMain/kotlin/ru/nsk/kstatemachine/state/pseudo/DefaultHistoryState.kt @@ -1,4 +1,8 @@ -package ru.nsk.kstatemachine +package ru.nsk.kstatemachine.state.pseudo + +import ru.nsk.kstatemachine.isSubStateOf +import ru.nsk.kstatemachine.state.* +import ru.nsk.kstatemachine.transition.TransitionParams /** * It is open for subclassing as all other [State] implementations, but I do not know real use cases for it. diff --git a/kstatemachine/src/commonMain/kotlin/ru/nsk/kstatemachine/UndoState.kt b/kstatemachine/src/commonMain/kotlin/ru/nsk/kstatemachine/state/pseudo/UndoState.kt similarity index 82% rename from kstatemachine/src/commonMain/kotlin/ru/nsk/kstatemachine/UndoState.kt rename to kstatemachine/src/commonMain/kotlin/ru/nsk/kstatemachine/state/pseudo/UndoState.kt index f7032437..dc9f8755 100644 --- a/kstatemachine/src/commonMain/kotlin/ru/nsk/kstatemachine/UndoState.kt +++ b/kstatemachine/src/commonMain/kotlin/ru/nsk/kstatemachine/state/pseudo/UndoState.kt @@ -1,4 +1,10 @@ -package ru.nsk.kstatemachine +package ru.nsk.kstatemachine.state.pseudo + +import ru.nsk.kstatemachine.event.UndoEvent +import ru.nsk.kstatemachine.event.WrappedEvent +import ru.nsk.kstatemachine.state.IState +import ru.nsk.kstatemachine.transition.EventAndArgument +import ru.nsk.kstatemachine.transition.TransitionParams private data class StateAndEvent(val state: IState, val eventAndArgument: EventAndArgument<*>) diff --git a/kstatemachine/src/commonMain/kotlin/ru/nsk/kstatemachine/PendingEventHandler.kt b/kstatemachine/src/commonMain/kotlin/ru/nsk/kstatemachine/statemachine/PendingEventHandler.kt similarity index 91% rename from kstatemachine/src/commonMain/kotlin/ru/nsk/kstatemachine/PendingEventHandler.kt rename to kstatemachine/src/commonMain/kotlin/ru/nsk/kstatemachine/statemachine/PendingEventHandler.kt index 00cb6466..ec25694e 100644 --- a/kstatemachine/src/commonMain/kotlin/ru/nsk/kstatemachine/PendingEventHandler.kt +++ b/kstatemachine/src/commonMain/kotlin/ru/nsk/kstatemachine/statemachine/PendingEventHandler.kt @@ -1,4 +1,7 @@ -package ru.nsk.kstatemachine +package ru.nsk.kstatemachine.statemachine + +import ru.nsk.kstatemachine.state.log +import ru.nsk.kstatemachine.transition.EventAndArgument /** * Returns [StateMachine.PendingEventHandler] implementation that throws exception. This is an old default behaviour. diff --git a/kstatemachine/src/commonMain/kotlin/ru/nsk/kstatemachine/StateMachineImpl.kt b/kstatemachine/src/commonMain/kotlin/ru/nsk/kstatemachine/statemachine/StateMachineImpl.kt similarity index 96% rename from kstatemachine/src/commonMain/kotlin/ru/nsk/kstatemachine/StateMachineImpl.kt rename to kstatemachine/src/commonMain/kotlin/ru/nsk/kstatemachine/statemachine/StateMachineImpl.kt index 9b3758c6..9714350e 100644 --- a/kstatemachine/src/commonMain/kotlin/ru/nsk/kstatemachine/StateMachineImpl.kt +++ b/kstatemachine/src/commonMain/kotlin/ru/nsk/kstatemachine/statemachine/StateMachineImpl.kt @@ -1,13 +1,19 @@ -package ru.nsk.kstatemachine - -import ru.nsk.kstatemachine.TransitionDirectionProducerPolicy.DefaultPolicy +package ru.nsk.kstatemachine.statemachine + +import ru.nsk.kstatemachine.coroutines.CoroutineAbstraction +import ru.nsk.kstatemachine.event.* +import ru.nsk.kstatemachine.isSubStateOf +import ru.nsk.kstatemachine.state.* +import ru.nsk.kstatemachine.state.pseudo.UndoState +import ru.nsk.kstatemachine.transition.* +import ru.nsk.kstatemachine.transition.TransitionDirectionProducerPolicy.DefaultPolicy import ru.nsk.kstatemachine.visitors.CheckUniqueNamesVisitor import ru.nsk.kstatemachine.visitors.CleanupVisitor /** * Defines state machine API for internal library usage. */ -abstract class InternalStateMachine(name: String?, childMode: ChildMode) : +internal abstract class InternalStateMachine(name: String?, childMode: ChildMode) : BuildingStateMachine, DefaultState(name, childMode) { internal abstract suspend fun startFrom(states: Set, argument: Any?) internal abstract suspend fun startFrom(state: DataState, data: D, argument: Any?) @@ -31,6 +37,17 @@ internal class StateMachineImpl( private var _isDestroyed: Boolean = false override val isDestroyed get() = _isDestroyed + /** + * Flag for event processing mechanism, which takes place in [processEventBlocking] and during [startBlocking]/[startFrom]. + * It is not possible to process new event while previous processing is incomplete. + */ + private var isProcessingEvent = false + + private var _isRunning = false + override val isRunning get() = _isRunning + + private var delayedListenerException: Exception? = null + init { transitionConditionally("start transition") { direction = { @@ -52,17 +69,6 @@ internal class StateMachineImpl( } } - /** - * Flag for event processing mechanism, which takes place in [processEventBlocking] and during [startBlocking]/[startFrom]. - * It is not possible to process new event while previous processing is incomplete. - */ - private var isProcessingEvent = false - - private var _isRunning = false - override val isRunning get() = _isRunning - - private var delayedListenerException: Exception? = null - override fun delayListenerException(exception: Exception) { if (delayedListenerException == null) delayedListenerException = exception diff --git a/kstatemachine/src/commonMain/kotlin/ru/nsk/kstatemachine/StateMachineListener.kt b/kstatemachine/src/commonMain/kotlin/ru/nsk/kstatemachine/statemachine/StateMachineListener.kt similarity index 94% rename from kstatemachine/src/commonMain/kotlin/ru/nsk/kstatemachine/StateMachineListener.kt rename to kstatemachine/src/commonMain/kotlin/ru/nsk/kstatemachine/statemachine/StateMachineListener.kt index 965505cd..667c2e98 100644 --- a/kstatemachine/src/commonMain/kotlin/ru/nsk/kstatemachine/StateMachineListener.kt +++ b/kstatemachine/src/commonMain/kotlin/ru/nsk/kstatemachine/statemachine/StateMachineListener.kt @@ -1,4 +1,7 @@ -package ru.nsk.kstatemachine +package ru.nsk.kstatemachine.statemachine + +import ru.nsk.kstatemachine.state.IState +import ru.nsk.kstatemachine.transition.TransitionParams internal suspend inline fun StateMachine.machineNotify(crossinline block: suspend StateMachine.Listener.() -> Unit) { this as InternalStateMachine diff --git a/kstatemachine/src/commonMain/kotlin/ru/nsk/kstatemachine/Testing.kt b/kstatemachine/src/commonMain/kotlin/ru/nsk/kstatemachine/testing/Testing.kt similarity index 83% rename from kstatemachine/src/commonMain/kotlin/ru/nsk/kstatemachine/Testing.kt rename to kstatemachine/src/commonMain/kotlin/ru/nsk/kstatemachine/testing/Testing.kt index b02624a3..bff71812 100644 --- a/kstatemachine/src/commonMain/kotlin/ru/nsk/kstatemachine/Testing.kt +++ b/kstatemachine/src/commonMain/kotlin/ru/nsk/kstatemachine/testing/Testing.kt @@ -1,7 +1,14 @@ -package ru.nsk.kstatemachine +package ru.nsk.kstatemachine.testing + +import ru.nsk.kstatemachine.state.DataState +import ru.nsk.kstatemachine.state.IState +import ru.nsk.kstatemachine.state.requireState +import ru.nsk.kstatemachine.statemachine.InternalStateMachine +import ru.nsk.kstatemachine.statemachine.StateMachine +import ru.nsk.kstatemachine.transition.targetParallelStates /** - * Method for testing purpose. + * Methods for testing purpose */ object Testing { /** diff --git a/kstatemachine/src/commonMain/kotlin/ru/nsk/kstatemachine/DefaultTransition.kt b/kstatemachine/src/commonMain/kotlin/ru/nsk/kstatemachine/transition/DefaultTransition.kt similarity index 87% rename from kstatemachine/src/commonMain/kotlin/ru/nsk/kstatemachine/DefaultTransition.kt rename to kstatemachine/src/commonMain/kotlin/ru/nsk/kstatemachine/transition/DefaultTransition.kt index 75450c61..cfd60526 100644 --- a/kstatemachine/src/commonMain/kotlin/ru/nsk/kstatemachine/DefaultTransition.kt +++ b/kstatemachine/src/commonMain/kotlin/ru/nsk/kstatemachine/transition/DefaultTransition.kt @@ -1,4 +1,11 @@ -package ru.nsk.kstatemachine +package ru.nsk.kstatemachine.transition + +import ru.nsk.kstatemachine.event.Event +import ru.nsk.kstatemachine.event.EventMatcher +import ru.nsk.kstatemachine.metainfo.MetaInfo +import ru.nsk.kstatemachine.state.IState +import ru.nsk.kstatemachine.state.InternalState +import ru.nsk.kstatemachine.statemachine.StateMachine open class DefaultTransition( override val name: String?, diff --git a/kstatemachine/src/commonMain/kotlin/ru/nsk/kstatemachine/InternalTransition.kt b/kstatemachine/src/commonMain/kotlin/ru/nsk/kstatemachine/transition/InternalTransition.kt similarity index 75% rename from kstatemachine/src/commonMain/kotlin/ru/nsk/kstatemachine/InternalTransition.kt rename to kstatemachine/src/commonMain/kotlin/ru/nsk/kstatemachine/transition/InternalTransition.kt index ffa3cb3c..4fdc5bb6 100644 --- a/kstatemachine/src/commonMain/kotlin/ru/nsk/kstatemachine/InternalTransition.kt +++ b/kstatemachine/src/commonMain/kotlin/ru/nsk/kstatemachine/transition/InternalTransition.kt @@ -1,4 +1,7 @@ -package ru.nsk.kstatemachine +package ru.nsk.kstatemachine.transition + +import ru.nsk.kstatemachine.event.Event +import ru.nsk.kstatemachine.state.InternalState /** * Defines transition API for internal library usage. All transitions must implement this interface. diff --git a/kstatemachine/src/commonMain/kotlin/ru/nsk/kstatemachine/Transition.kt b/kstatemachine/src/commonMain/kotlin/ru/nsk/kstatemachine/transition/Transition.kt similarity index 84% rename from kstatemachine/src/commonMain/kotlin/ru/nsk/kstatemachine/Transition.kt rename to kstatemachine/src/commonMain/kotlin/ru/nsk/kstatemachine/transition/Transition.kt index d33763b4..06ece18b 100644 --- a/kstatemachine/src/commonMain/kotlin/ru/nsk/kstatemachine/Transition.kt +++ b/kstatemachine/src/commonMain/kotlin/ru/nsk/kstatemachine/transition/Transition.kt @@ -1,7 +1,12 @@ -package ru.nsk.kstatemachine +package ru.nsk.kstatemachine.transition -import ru.nsk.kstatemachine.TransitionType.EXTERNAL -import ru.nsk.kstatemachine.TransitionType.LOCAL +import ru.nsk.kstatemachine.event.Event +import ru.nsk.kstatemachine.event.EventMatcher +import ru.nsk.kstatemachine.metainfo.MetaInfo +import ru.nsk.kstatemachine.state.IState +import ru.nsk.kstatemachine.statemachine.StateMachine +import ru.nsk.kstatemachine.transition.TransitionType.EXTERNAL +import ru.nsk.kstatemachine.transition.TransitionType.LOCAL import ru.nsk.kstatemachine.visitors.CoVisitor import ru.nsk.kstatemachine.visitors.Visitor import ru.nsk.kstatemachine.visitors.VisitorAcceptor diff --git a/kstatemachine/src/commonMain/kotlin/ru/nsk/kstatemachine/TransitionBuilder.kt b/kstatemachine/src/commonMain/kotlin/ru/nsk/kstatemachine/transition/TransitionBuilder.kt similarity index 92% rename from kstatemachine/src/commonMain/kotlin/ru/nsk/kstatemachine/TransitionBuilder.kt rename to kstatemachine/src/commonMain/kotlin/ru/nsk/kstatemachine/transition/TransitionBuilder.kt index 198557eb..4d433dbe 100644 --- a/kstatemachine/src/commonMain/kotlin/ru/nsk/kstatemachine/TransitionBuilder.kt +++ b/kstatemachine/src/commonMain/kotlin/ru/nsk/kstatemachine/transition/TransitionBuilder.kt @@ -1,6 +1,14 @@ -package ru.nsk.kstatemachine - -import ru.nsk.kstatemachine.TransitionDirectionProducerPolicy.* +package ru.nsk.kstatemachine.transition + +import ru.nsk.kstatemachine.event.DataEvent +import ru.nsk.kstatemachine.event.Event +import ru.nsk.kstatemachine.event.EventMatcher +import ru.nsk.kstatemachine.metainfo.MetaInfo +import ru.nsk.kstatemachine.state.DataState +import ru.nsk.kstatemachine.state.IState +import ru.nsk.kstatemachine.state.State +import ru.nsk.kstatemachine.statemachine.StateMachineDslMarker +import ru.nsk.kstatemachine.transition.TransitionDirectionProducerPolicy.* @StateMachineDslMarker abstract class TransitionBuilder(protected val name: String?, protected val sourceState: IState) { diff --git a/kstatemachine/src/commonMain/kotlin/ru/nsk/kstatemachine/TransitionDirection.kt b/kstatemachine/src/commonMain/kotlin/ru/nsk/kstatemachine/transition/TransitionDirection.kt similarity index 95% rename from kstatemachine/src/commonMain/kotlin/ru/nsk/kstatemachine/TransitionDirection.kt rename to kstatemachine/src/commonMain/kotlin/ru/nsk/kstatemachine/transition/TransitionDirection.kt index af61872e..122deaed 100644 --- a/kstatemachine/src/commonMain/kotlin/ru/nsk/kstatemachine/TransitionDirection.kt +++ b/kstatemachine/src/commonMain/kotlin/ru/nsk/kstatemachine/transition/TransitionDirection.kt @@ -1,6 +1,11 @@ -package ru.nsk.kstatemachine - -import ru.nsk.kstatemachine.TransitionDirectionProducerPolicy.DefaultPolicy +package ru.nsk.kstatemachine.transition + +import ru.nsk.kstatemachine.event.Event +import ru.nsk.kstatemachine.findLca +import ru.nsk.kstatemachine.state.* +import ru.nsk.kstatemachine.state.pseudo.UndoState +import ru.nsk.kstatemachine.statemachine.StateMachine +import ru.nsk.kstatemachine.transition.TransitionDirectionProducerPolicy.DefaultPolicy sealed interface TransitionDirection { /** diff --git a/kstatemachine/src/commonMain/kotlin/ru/nsk/kstatemachine/TransitionListener.kt b/kstatemachine/src/commonMain/kotlin/ru/nsk/kstatemachine/transition/TransitionListener.kt similarity index 80% rename from kstatemachine/src/commonMain/kotlin/ru/nsk/kstatemachine/TransitionListener.kt rename to kstatemachine/src/commonMain/kotlin/ru/nsk/kstatemachine/transition/TransitionListener.kt index 4c8876e1..d64973ac 100644 --- a/kstatemachine/src/commonMain/kotlin/ru/nsk/kstatemachine/TransitionListener.kt +++ b/kstatemachine/src/commonMain/kotlin/ru/nsk/kstatemachine/transition/TransitionListener.kt @@ -1,4 +1,9 @@ -package ru.nsk.kstatemachine +package ru.nsk.kstatemachine.transition + +import ru.nsk.kstatemachine.event.Event +import ru.nsk.kstatemachine.state.IState +import ru.nsk.kstatemachine.statemachine.InternalStateMachine +import ru.nsk.kstatemachine.statemachine.runDelayingException internal suspend inline fun InternalTransition<*>.transitionNotify( crossinline block: suspend Transition.Listener.() -> Unit diff --git a/kstatemachine/src/commonMain/kotlin/ru/nsk/kstatemachine/transition/TransitionParams.kt b/kstatemachine/src/commonMain/kotlin/ru/nsk/kstatemachine/transition/TransitionParams.kt new file mode 100644 index 00000000..26151412 --- /dev/null +++ b/kstatemachine/src/commonMain/kotlin/ru/nsk/kstatemachine/transition/TransitionParams.kt @@ -0,0 +1,30 @@ +package ru.nsk.kstatemachine.transition + +import ru.nsk.kstatemachine.event.Event +import ru.nsk.kstatemachine.event.WrappedEvent +import ru.nsk.kstatemachine.statemachine.StateMachineDslMarker + +@StateMachineDslMarker +data class TransitionParams( + val transition: Transition, + val direction: TransitionDirection, + val event: E, + /** + * This parameter may be used to pass arbitrary data with the event, + * so there is no need to define [Event] subclasses every time. + * Subclassing should be preferred if the event always contains data of some type. + */ + val argument: Any? = null, +) + +/** + * Convenience property for unwrapping original event. + * If the event is not [WrappedEvent] this is same as [TransitionParams.event] property + */ +val TransitionParams<*>.unwrappedEvent get() = if (event is WrappedEvent) event.event else event + +/** + * Convenience property for unwrapping original argument. + * If the event is not [WrappedEvent] this is same as [TransitionParams.argument] property + */ +val TransitionParams<*>.unwrappedArgument get() = if (event is WrappedEvent) event.argument else argument \ No newline at end of file diff --git a/kstatemachine/src/commonMain/kotlin/ru/nsk/kstatemachine/visitors/CheckUniqueNamesVisitor.kt b/kstatemachine/src/commonMain/kotlin/ru/nsk/kstatemachine/visitors/CheckUniqueNamesVisitor.kt index 4329e646..e4cdfc91 100644 --- a/kstatemachine/src/commonMain/kotlin/ru/nsk/kstatemachine/visitors/CheckUniqueNamesVisitor.kt +++ b/kstatemachine/src/commonMain/kotlin/ru/nsk/kstatemachine/visitors/CheckUniqueNamesVisitor.kt @@ -1,9 +1,9 @@ package ru.nsk.kstatemachine.visitors -import ru.nsk.kstatemachine.Event -import ru.nsk.kstatemachine.IState -import ru.nsk.kstatemachine.StateMachine -import ru.nsk.kstatemachine.Transition +import ru.nsk.kstatemachine.event.Event +import ru.nsk.kstatemachine.state.IState +import ru.nsk.kstatemachine.statemachine.StateMachine +import ru.nsk.kstatemachine.transition.Transition internal class CheckUniqueNamesVisitor : RecursiveVisitor { private val stateNames = mutableSetOf() diff --git a/kstatemachine/src/commonMain/kotlin/ru/nsk/kstatemachine/visitors/CleanupVisitor.kt b/kstatemachine/src/commonMain/kotlin/ru/nsk/kstatemachine/visitors/CleanupVisitor.kt index 41749c81..3064c037 100644 --- a/kstatemachine/src/commonMain/kotlin/ru/nsk/kstatemachine/visitors/CleanupVisitor.kt +++ b/kstatemachine/src/commonMain/kotlin/ru/nsk/kstatemachine/visitors/CleanupVisitor.kt @@ -1,6 +1,11 @@ package ru.nsk.kstatemachine.visitors -import ru.nsk.kstatemachine.* +import ru.nsk.kstatemachine.event.Event +import ru.nsk.kstatemachine.state.IState +import ru.nsk.kstatemachine.state.InternalState +import ru.nsk.kstatemachine.statemachine.InternalStateMachine +import ru.nsk.kstatemachine.statemachine.StateMachine +import ru.nsk.kstatemachine.transition.Transition internal class CleanupVisitor : RecursiveCoVisitor { override suspend fun visit(machine: StateMachine) { diff --git a/kstatemachine/src/commonMain/kotlin/ru/nsk/kstatemachine/visitors/GetActiveStatesVisitor.kt b/kstatemachine/src/commonMain/kotlin/ru/nsk/kstatemachine/visitors/GetActiveStatesVisitor.kt index 2a78ed60..12409a7a 100644 --- a/kstatemachine/src/commonMain/kotlin/ru/nsk/kstatemachine/visitors/GetActiveStatesVisitor.kt +++ b/kstatemachine/src/commonMain/kotlin/ru/nsk/kstatemachine/visitors/GetActiveStatesVisitor.kt @@ -1,6 +1,10 @@ package ru.nsk.kstatemachine.visitors -import ru.nsk.kstatemachine.* +import ru.nsk.kstatemachine.event.Event +import ru.nsk.kstatemachine.state.IState +import ru.nsk.kstatemachine.state.InternalState +import ru.nsk.kstatemachine.statemachine.StateMachine +import ru.nsk.kstatemachine.transition.Transition internal class GetActiveStatesVisitor(private val selfIncluding: Boolean) : Visitor { private val _activeStates = mutableSetOf() diff --git a/kstatemachine/src/commonMain/kotlin/ru/nsk/kstatemachine/visitors/RecursiveVisitor.kt b/kstatemachine/src/commonMain/kotlin/ru/nsk/kstatemachine/visitors/RecursiveVisitor.kt index 5b8521a3..ed94bb4b 100644 --- a/kstatemachine/src/commonMain/kotlin/ru/nsk/kstatemachine/visitors/RecursiveVisitor.kt +++ b/kstatemachine/src/commonMain/kotlin/ru/nsk/kstatemachine/visitors/RecursiveVisitor.kt @@ -1,6 +1,6 @@ package ru.nsk.kstatemachine.visitors -import ru.nsk.kstatemachine.IState +import ru.nsk.kstatemachine.state.IState internal interface RecursiveVisitor : Visitor { fun IState.visitChildren() { diff --git a/kstatemachine/src/commonMain/kotlin/ru/nsk/kstatemachine/visitors/Visitor.kt b/kstatemachine/src/commonMain/kotlin/ru/nsk/kstatemachine/visitors/Visitor.kt index ed58c945..b4dd21e0 100644 --- a/kstatemachine/src/commonMain/kotlin/ru/nsk/kstatemachine/visitors/Visitor.kt +++ b/kstatemachine/src/commonMain/kotlin/ru/nsk/kstatemachine/visitors/Visitor.kt @@ -1,9 +1,9 @@ package ru.nsk.kstatemachine.visitors -import ru.nsk.kstatemachine.Event -import ru.nsk.kstatemachine.IState -import ru.nsk.kstatemachine.StateMachine -import ru.nsk.kstatemachine.Transition +import ru.nsk.kstatemachine.event.Event +import ru.nsk.kstatemachine.state.IState +import ru.nsk.kstatemachine.statemachine.StateMachine +import ru.nsk.kstatemachine.transition.Transition /** * Suspendable interface for visiting state machine components diff --git a/kstatemachine/src/commonMain/kotlin/ru/nsk/kstatemachine/visitors/ExportPlantUmlVisitor.kt b/kstatemachine/src/commonMain/kotlin/ru/nsk/kstatemachine/visitors/export/ExportPlantUmlVisitor.kt similarity index 89% rename from kstatemachine/src/commonMain/kotlin/ru/nsk/kstatemachine/visitors/ExportPlantUmlVisitor.kt rename to kstatemachine/src/commonMain/kotlin/ru/nsk/kstatemachine/visitors/export/ExportPlantUmlVisitor.kt index 394c76ee..a4a6efd4 100644 --- a/kstatemachine/src/commonMain/kotlin/ru/nsk/kstatemachine/visitors/ExportPlantUmlVisitor.kt +++ b/kstatemachine/src/commonMain/kotlin/ru/nsk/kstatemachine/visitors/export/ExportPlantUmlVisitor.kt @@ -1,10 +1,21 @@ -package ru.nsk.kstatemachine.visitors - -import ru.nsk.kstatemachine.* -import ru.nsk.kstatemachine.TransitionDirectionProducerPolicy.CollectTargetStatesPolicy -import ru.nsk.kstatemachine.TransitionDirectionProducerPolicy.UnsafeCollectTargetStatesPolicy -import ru.nsk.kstatemachine.visitors.CompatibilityFormat.MERMAID -import ru.nsk.kstatemachine.visitors.CompatibilityFormat.PLANT_UML +package ru.nsk.kstatemachine.visitors.export + +import ru.nsk.kstatemachine.event.Event +import ru.nsk.kstatemachine.isNeighbor +import ru.nsk.kstatemachine.metainfo.IUmlMetaInfo +import ru.nsk.kstatemachine.metainfo.MetaInfo +import ru.nsk.kstatemachine.state.* +import ru.nsk.kstatemachine.state.pseudo.UndoState +import ru.nsk.kstatemachine.statemachine.StateMachine +import ru.nsk.kstatemachine.transition.EventAndArgument +import ru.nsk.kstatemachine.transition.InternalTransition +import ru.nsk.kstatemachine.transition.Transition +import ru.nsk.kstatemachine.transition.TransitionDirectionProducerPolicy +import ru.nsk.kstatemachine.transition.TransitionDirectionProducerPolicy.CollectTargetStatesPolicy +import ru.nsk.kstatemachine.transition.TransitionDirectionProducerPolicy.UnsafeCollectTargetStatesPolicy +import ru.nsk.kstatemachine.visitors.CoVisitor +import ru.nsk.kstatemachine.visitors.export.CompatibilityFormat.MERMAID +import ru.nsk.kstatemachine.visitors.export.CompatibilityFormat.PLANT_UML private const val STAR = "[*]" private const val SINGLE_INDENT = " " diff --git a/kstatemachine/src/commonMain/kotlin/ru/nsk/kstatemachine/visitors/ExportToMermaid.kt b/kstatemachine/src/commonMain/kotlin/ru/nsk/kstatemachine/visitors/export/ExportToMermaid.kt similarity index 84% rename from kstatemachine/src/commonMain/kotlin/ru/nsk/kstatemachine/visitors/ExportToMermaid.kt rename to kstatemachine/src/commonMain/kotlin/ru/nsk/kstatemachine/visitors/export/ExportToMermaid.kt index d6bca2fd..c63aa71b 100644 --- a/kstatemachine/src/commonMain/kotlin/ru/nsk/kstatemachine/visitors/ExportToMermaid.kt +++ b/kstatemachine/src/commonMain/kotlin/ru/nsk/kstatemachine/visitors/export/ExportToMermaid.kt @@ -1,7 +1,7 @@ -package ru.nsk.kstatemachine.visitors +package ru.nsk.kstatemachine.visitors.export -import ru.nsk.kstatemachine.StateMachine -import ru.nsk.kstatemachine.visitors.CompatibilityFormat.MERMAID +import ru.nsk.kstatemachine.statemachine.StateMachine +import ru.nsk.kstatemachine.visitors.export.CompatibilityFormat.MERMAID /** * Export [StateMachine] to Mermaid state diagram diff --git a/samples/src/commonMain/kotlin/ru/nsk/samples/ComplexSyntaxSample.kt b/samples/src/commonMain/kotlin/ru/nsk/samples/ComplexSyntaxSample.kt index dfa94596..c1170539 100644 --- a/samples/src/commonMain/kotlin/ru/nsk/samples/ComplexSyntaxSample.kt +++ b/samples/src/commonMain/kotlin/ru/nsk/samples/ComplexSyntaxSample.kt @@ -1,7 +1,10 @@ package ru.nsk.samples import kotlinx.coroutines.runBlocking -import ru.nsk.kstatemachine.* +import ru.nsk.kstatemachine.event.Event +import ru.nsk.kstatemachine.state.* +import ru.nsk.kstatemachine.statemachine.* +import ru.nsk.kstatemachine.transition.* import ru.nsk.samples.ComplexSyntaxSample.SwitchRedEvent import ru.nsk.samples.ComplexSyntaxSample.SwitchYellowEvent import ru.nsk.samples.ComplexSyntaxSample.YellowState @@ -17,7 +20,7 @@ private object ComplexSyntaxSample { class YellowState(val info: Int) : DefaultState("Yellow") } -fun main() = runBlocking { +fun main(): Unit = runBlocking { val machine = createStateMachine( this, // coroutine scope used for this machine "Traffic lights" // StateMachine name is optional @@ -139,4 +142,8 @@ fun main() = runBlocking { // get list of currently active states val states = machine.activeStates() + + states.apply { + // do something with states + } } \ No newline at end of file diff --git a/samples/src/commonMain/kotlin/ru/nsk/samples/CrossLevelTransitionSample.kt b/samples/src/commonMain/kotlin/ru/nsk/samples/CrossLevelTransitionSample.kt index 32bd389b..6c7a4e70 100644 --- a/samples/src/commonMain/kotlin/ru/nsk/samples/CrossLevelTransitionSample.kt +++ b/samples/src/commonMain/kotlin/ru/nsk/samples/CrossLevelTransitionSample.kt @@ -1,8 +1,14 @@ package ru.nsk.samples import kotlinx.coroutines.runBlocking -import ru.nsk.kstatemachine.* -import ru.nsk.kstatemachine.visitors.exportToPlantUml +import ru.nsk.kstatemachine.event.Event +import ru.nsk.kstatemachine.state.State +import ru.nsk.kstatemachine.state.initialState +import ru.nsk.kstatemachine.state.state +import ru.nsk.kstatemachine.state.transitionOn +import ru.nsk.kstatemachine.statemachine.StateMachine +import ru.nsk.kstatemachine.statemachine.createStateMachine +import ru.nsk.kstatemachine.visitors.export.exportToPlantUml import ru.nsk.samples.CrossLevelTransitionSample.SwitchEvent private object CrossLevelTransitionSample { diff --git a/samples/src/commonMain/kotlin/ru/nsk/samples/FinishedEventDataStateSample.kt b/samples/src/commonMain/kotlin/ru/nsk/samples/FinishedEventDataStateSample.kt index 9ff4c2cf..15f3cfcd 100644 --- a/samples/src/commonMain/kotlin/ru/nsk/samples/FinishedEventDataStateSample.kt +++ b/samples/src/commonMain/kotlin/ru/nsk/samples/FinishedEventDataStateSample.kt @@ -1,7 +1,14 @@ package ru.nsk.samples import kotlinx.coroutines.runBlocking -import ru.nsk.kstatemachine.* +import ru.nsk.kstatemachine.event.DataEvent +import ru.nsk.kstatemachine.event.FinishedEvent +import ru.nsk.kstatemachine.event.defaultDataExtractor +import ru.nsk.kstatemachine.state.* +import ru.nsk.kstatemachine.statemachine.StateMachine +import ru.nsk.kstatemachine.statemachine.createStateMachine +import ru.nsk.kstatemachine.transition.onTriggered +import ru.nsk.kstatemachine.transition.targetState import ru.nsk.samples.FinishedEventDataStateSample.IntEvent import ru.nsk.samples.FinishedEventDataStateSample.States.* diff --git a/samples/src/commonMain/kotlin/ru/nsk/samples/FinishedEventSample.kt b/samples/src/commonMain/kotlin/ru/nsk/samples/FinishedEventSample.kt index 05fe08fc..9addf242 100644 --- a/samples/src/commonMain/kotlin/ru/nsk/samples/FinishedEventSample.kt +++ b/samples/src/commonMain/kotlin/ru/nsk/samples/FinishedEventSample.kt @@ -1,7 +1,11 @@ package ru.nsk.samples import kotlinx.coroutines.runBlocking -import ru.nsk.kstatemachine.* +import ru.nsk.kstatemachine.event.Event +import ru.nsk.kstatemachine.event.FinishedEvent +import ru.nsk.kstatemachine.state.* +import ru.nsk.kstatemachine.statemachine.StateMachine +import ru.nsk.kstatemachine.statemachine.createStateMachine import ru.nsk.samples.FinishedEventSample.States.* import ru.nsk.samples.FinishedEventSample.SwitchEvent diff --git a/samples/src/commonMain/kotlin/ru/nsk/samples/FinishedStateSample.kt b/samples/src/commonMain/kotlin/ru/nsk/samples/FinishedStateSample.kt index 49319686..63cce1c9 100644 --- a/samples/src/commonMain/kotlin/ru/nsk/samples/FinishedStateSample.kt +++ b/samples/src/commonMain/kotlin/ru/nsk/samples/FinishedStateSample.kt @@ -1,7 +1,9 @@ package ru.nsk.samples import kotlinx.coroutines.runBlocking -import ru.nsk.kstatemachine.* +import ru.nsk.kstatemachine.event.Event +import ru.nsk.kstatemachine.state.* +import ru.nsk.kstatemachine.statemachine.createStateMachine import ru.nsk.samples.FinishedStateSample.SwitchEvent private object FinishedStateSample { diff --git a/samples/src/commonMain/kotlin/ru/nsk/samples/GuardedTransitionSample.kt b/samples/src/commonMain/kotlin/ru/nsk/samples/GuardedTransitionSample.kt index bc41c700..d108be9c 100644 --- a/samples/src/commonMain/kotlin/ru/nsk/samples/GuardedTransitionSample.kt +++ b/samples/src/commonMain/kotlin/ru/nsk/samples/GuardedTransitionSample.kt @@ -1,7 +1,10 @@ package ru.nsk.samples import kotlinx.coroutines.runBlocking -import ru.nsk.kstatemachine.* +import ru.nsk.kstatemachine.event.Event +import ru.nsk.kstatemachine.state.* +import ru.nsk.kstatemachine.statemachine.StateMachine +import ru.nsk.kstatemachine.statemachine.createStateMachine import ru.nsk.samples.GuardedTransitionSample.States.State1 import ru.nsk.samples.GuardedTransitionSample.States.State2 import ru.nsk.samples.GuardedTransitionSample.SwitchEvent diff --git a/samples/src/commonMain/kotlin/ru/nsk/samples/InheritTransitionsSample.kt b/samples/src/commonMain/kotlin/ru/nsk/samples/InheritTransitionsSample.kt index 0a27dc97..fa6cbb8b 100644 --- a/samples/src/commonMain/kotlin/ru/nsk/samples/InheritTransitionsSample.kt +++ b/samples/src/commonMain/kotlin/ru/nsk/samples/InheritTransitionsSample.kt @@ -1,14 +1,17 @@ package ru.nsk.samples import kotlinx.coroutines.runBlocking -import ru.nsk.kstatemachine.* +import ru.nsk.kstatemachine.event.Event +import ru.nsk.kstatemachine.state.* +import ru.nsk.kstatemachine.statemachine.StateMachine +import ru.nsk.kstatemachine.statemachine.createStateMachine import ru.nsk.samples.InheritTransitionsSample.Events.ExitEvent import ru.nsk.samples.InheritTransitionsSample.Events.SwitchEvent private object InheritTransitionsSample { sealed interface Events : Event { - object ExitEvent : Events - object SwitchEvent : Events + data object ExitEvent : Events + data object SwitchEvent : Events } } diff --git a/samples/src/commonMain/kotlin/ru/nsk/samples/MermaidExportSample.kt b/samples/src/commonMain/kotlin/ru/nsk/samples/MermaidExportSample.kt index 42c1cf87..34be4a2b 100644 --- a/samples/src/commonMain/kotlin/ru/nsk/samples/MermaidExportSample.kt +++ b/samples/src/commonMain/kotlin/ru/nsk/samples/MermaidExportSample.kt @@ -1,8 +1,10 @@ package ru.nsk.samples import kotlinx.coroutines.runBlocking -import ru.nsk.kstatemachine.* -import ru.nsk.kstatemachine.visitors.exportToMermaid +import ru.nsk.kstatemachine.event.Event +import ru.nsk.kstatemachine.state.* +import ru.nsk.kstatemachine.statemachine.createStateMachine +import ru.nsk.kstatemachine.visitors.export.exportToMermaid import ru.nsk.samples.MermaidExportSample.SwitchEvent private object MermaidExportSample { diff --git a/samples/src/commonMain/kotlin/ru/nsk/samples/MinimalSealedClassesSample.kt b/samples/src/commonMain/kotlin/ru/nsk/samples/MinimalSealedClassesSample.kt index 5b8a133e..b46b3e53 100644 --- a/samples/src/commonMain/kotlin/ru/nsk/samples/MinimalSealedClassesSample.kt +++ b/samples/src/commonMain/kotlin/ru/nsk/samples/MinimalSealedClassesSample.kt @@ -1,7 +1,10 @@ package ru.nsk.samples import kotlinx.coroutines.runBlocking -import ru.nsk.kstatemachine.* +import ru.nsk.kstatemachine.event.Event +import ru.nsk.kstatemachine.state.* +import ru.nsk.kstatemachine.statemachine.createStateMachine +import ru.nsk.kstatemachine.transition.onTriggered import ru.nsk.samples.MinimalSealedClassesSample.States.* import ru.nsk.samples.MinimalSealedClassesSample.SwitchEvent diff --git a/samples/src/commonMain/kotlin/ru/nsk/samples/MinimalSyntaxSample.kt b/samples/src/commonMain/kotlin/ru/nsk/samples/MinimalSyntaxSample.kt index db2127c5..50a2fd5d 100644 --- a/samples/src/commonMain/kotlin/ru/nsk/samples/MinimalSyntaxSample.kt +++ b/samples/src/commonMain/kotlin/ru/nsk/samples/MinimalSyntaxSample.kt @@ -1,7 +1,10 @@ package ru.nsk.samples import kotlinx.coroutines.runBlocking -import ru.nsk.kstatemachine.* +import ru.nsk.kstatemachine.event.Event +import ru.nsk.kstatemachine.state.* +import ru.nsk.kstatemachine.statemachine.createStateMachine +import ru.nsk.kstatemachine.transition.onTriggered import ru.nsk.samples.MinimalSyntaxSample.SwitchEvent private object MinimalSyntaxSample { diff --git a/samples/src/commonMain/kotlin/ru/nsk/samples/PlantUmlExportSample.kt b/samples/src/commonMain/kotlin/ru/nsk/samples/PlantUmlExportSample.kt index d4583edc..ec941988 100644 --- a/samples/src/commonMain/kotlin/ru/nsk/samples/PlantUmlExportSample.kt +++ b/samples/src/commonMain/kotlin/ru/nsk/samples/PlantUmlExportSample.kt @@ -1,8 +1,10 @@ package ru.nsk.samples import kotlinx.coroutines.runBlocking -import ru.nsk.kstatemachine.* -import ru.nsk.kstatemachine.visitors.exportToPlantUml +import ru.nsk.kstatemachine.event.Event +import ru.nsk.kstatemachine.state.* +import ru.nsk.kstatemachine.statemachine.createStateMachine +import ru.nsk.kstatemachine.visitors.export.exportToPlantUml import ru.nsk.samples.PlantUmlExportSample.SwitchEvent private object PlantUmlExportSample { diff --git a/samples/src/commonMain/kotlin/ru/nsk/samples/PlantUmlExportWithMetaInfoSample.kt b/samples/src/commonMain/kotlin/ru/nsk/samples/PlantUmlExportWithMetaInfoSample.kt index 9a9cf98c..33fda7b2 100644 --- a/samples/src/commonMain/kotlin/ru/nsk/samples/PlantUmlExportWithMetaInfoSample.kt +++ b/samples/src/commonMain/kotlin/ru/nsk/samples/PlantUmlExportWithMetaInfoSample.kt @@ -1,8 +1,15 @@ package ru.nsk.samples import kotlinx.coroutines.runBlocking -import ru.nsk.kstatemachine.* -import ru.nsk.kstatemachine.visitors.exportToPlantUml +import ru.nsk.kstatemachine.event.Event +import ru.nsk.kstatemachine.metainfo.MetaInfo +import ru.nsk.kstatemachine.metainfo.UmlMetaInfo +import ru.nsk.kstatemachine.state.State +import ru.nsk.kstatemachine.state.finalState +import ru.nsk.kstatemachine.state.initialState +import ru.nsk.kstatemachine.state.transitionOn +import ru.nsk.kstatemachine.statemachine.createStateMachine +import ru.nsk.kstatemachine.visitors.export.exportToPlantUml import ru.nsk.samples.PlantUmlExportWithMetaInfoSample.SwitchEvent private object PlantUmlExportWithMetaInfoSample { diff --git a/samples/src/commonMain/kotlin/ru/nsk/samples/StdLibMinimalSealedClassesSample.kt b/samples/src/commonMain/kotlin/ru/nsk/samples/StdLibMinimalSealedClassesSample.kt index a4c08597..711d5b57 100644 --- a/samples/src/commonMain/kotlin/ru/nsk/samples/StdLibMinimalSealedClassesSample.kt +++ b/samples/src/commonMain/kotlin/ru/nsk/samples/StdLibMinimalSealedClassesSample.kt @@ -1,6 +1,10 @@ package ru.nsk.samples -import ru.nsk.kstatemachine.* +import ru.nsk.kstatemachine.event.Event +import ru.nsk.kstatemachine.state.* +import ru.nsk.kstatemachine.statemachine.createStdLibStateMachine +import ru.nsk.kstatemachine.statemachine.processEventBlocking +import ru.nsk.kstatemachine.transition.onTriggered import ru.nsk.samples.StdLibMinimalSealedClassesSample.States.* import ru.nsk.samples.StdLibMinimalSealedClassesSample.SwitchEvent diff --git a/samples/src/commonMain/kotlin/ru/nsk/samples/TypesafeTransitionSample.kt b/samples/src/commonMain/kotlin/ru/nsk/samples/TypesafeTransitionSample.kt index e11d1852..46003288 100644 --- a/samples/src/commonMain/kotlin/ru/nsk/samples/TypesafeTransitionSample.kt +++ b/samples/src/commonMain/kotlin/ru/nsk/samples/TypesafeTransitionSample.kt @@ -1,7 +1,10 @@ package ru.nsk.samples import kotlinx.coroutines.runBlocking -import ru.nsk.kstatemachine.* +import ru.nsk.kstatemachine.event.DataEvent +import ru.nsk.kstatemachine.state.* +import ru.nsk.kstatemachine.statemachine.StateMachine +import ru.nsk.kstatemachine.statemachine.createStateMachine import ru.nsk.samples.TypesafeTransitionSample.LoginData import ru.nsk.samples.TypesafeTransitionSample.LoginEvent import ru.nsk.samples.TypesafeTransitionSample.checkUserPassword diff --git a/samples/src/commonMain/kotlin/ru/nsk/samples/UndoTransitionSample.kt b/samples/src/commonMain/kotlin/ru/nsk/samples/UndoTransitionSample.kt index b300cd0e..742512b3 100644 --- a/samples/src/commonMain/kotlin/ru/nsk/samples/UndoTransitionSample.kt +++ b/samples/src/commonMain/kotlin/ru/nsk/samples/UndoTransitionSample.kt @@ -1,7 +1,13 @@ package ru.nsk.samples import kotlinx.coroutines.runBlocking -import ru.nsk.kstatemachine.* +import ru.nsk.kstatemachine.event.Event +import ru.nsk.kstatemachine.event.UndoEvent +import ru.nsk.kstatemachine.state.* +import ru.nsk.kstatemachine.statemachine.StateMachine +import ru.nsk.kstatemachine.statemachine.createStateMachine +import ru.nsk.kstatemachine.statemachine.undo +import ru.nsk.kstatemachine.transition.unwrappedEvent import ru.nsk.samples.UndoTransitionSample.SwitchEvent private object UndoTransitionSample { diff --git a/tests/src/commonTest/kotlin/ru/nsk/kstatemachine/CoroutinesTest.kt b/tests/src/commonTest/kotlin/ru/nsk/kstatemachine/CoroutinesTest.kt index df1bf648..f2353d89 100644 --- a/tests/src/commonTest/kotlin/ru/nsk/kstatemachine/CoroutinesTest.kt +++ b/tests/src/commonTest/kotlin/ru/nsk/kstatemachine/CoroutinesTest.kt @@ -8,7 +8,12 @@ import io.mockk.verifySequence import kotlinx.coroutines.* import kotlinx.coroutines.flow.first import kotlinx.coroutines.flow.take -import ru.nsk.kstatemachine.StateMachineNotification.* +import ru.nsk.kstatemachine.statemachine.StateMachineNotification.* +import ru.nsk.kstatemachine.event.StartEvent +import ru.nsk.kstatemachine.state.* +import ru.nsk.kstatemachine.statemachine.* +import ru.nsk.kstatemachine.transition.onTriggered +import ru.nsk.kstatemachine.transition.stay import kotlin.coroutines.EmptyCoroutineContext class CoroutinesTest : StringSpec({ @@ -286,4 +291,20 @@ class CoroutinesTest : StringSpec({ machine.processEvent(SwitchEvent) statesFlow.first().shouldContainExactlyInAnyOrder(state2) } + + "f:context switching" { + println(""+ Thread.currentThread() + Thread.currentThread().hashCode() ) + val scope = CoroutineScope(EmptyCoroutineContext) + val scope1 = CoroutineScope(Dispatchers.Default) + val scope2 = CoroutineScope(Dispatchers.IO) + scope.launch { + println("EmptyCoroutineContext ${this.coroutineContext} " + Thread.currentThread() + Thread.currentThread().hashCode() ) + } + scope1.launch { + println("Default ${this.coroutineContext} " + Thread.currentThread() + Thread.currentThread().hashCode() ) + } + scope2.launch { + println("IO ${this.coroutineContext} " + Thread.currentThread() + Thread.currentThread().hashCode() ) + } + } }) \ No newline at end of file diff --git a/tests/src/commonTest/kotlin/ru/nsk/kstatemachine/IsSubStateOfTest.kt b/tests/src/commonTest/kotlin/ru/nsk/kstatemachine/IsSubStateOfTest.kt index 91fd5cb4..d354baf9 100644 --- a/tests/src/commonTest/kotlin/ru/nsk/kstatemachine/IsSubStateOfTest.kt +++ b/tests/src/commonTest/kotlin/ru/nsk/kstatemachine/IsSubStateOfTest.kt @@ -2,6 +2,10 @@ package ru.nsk.kstatemachine import io.kotest.core.spec.style.StringSpec import io.kotest.matchers.shouldBe +import ru.nsk.kstatemachine.state.IState +import ru.nsk.kstatemachine.state.addInitialState +import ru.nsk.kstatemachine.state.initialState +import ru.nsk.kstatemachine.state.state class IsSubStateOfTest : StringSpec({ CoroutineStarterType.entries.forEach { coroutineStarterType -> diff --git a/tests/src/commonTest/kotlin/ru/nsk/kstatemachine/TestUtils.kt b/tests/src/commonTest/kotlin/ru/nsk/kstatemachine/TestUtils.kt index 741a45ab..6609d2f2 100644 --- a/tests/src/commonTest/kotlin/ru/nsk/kstatemachine/TestUtils.kt +++ b/tests/src/commonTest/kotlin/ru/nsk/kstatemachine/TestUtils.kt @@ -5,11 +5,15 @@ import io.mockk.MockKVerificationScope import io.mockk.clearMocks import io.mockk.mockk import io.mockk.verifySequence -import kotlinx.coroutines.CoroutineScope -import kotlinx.coroutines.DelicateCoroutinesApi -import kotlinx.coroutines.Dispatchers -import kotlinx.coroutines.ExperimentalCoroutinesApi -import kotlinx.coroutines.newSingleThreadContext +import kotlinx.coroutines.* +import ru.nsk.kstatemachine.event.Event +import ru.nsk.kstatemachine.state.* +import ru.nsk.kstatemachine.statemachine.BuildingStateMachine +import ru.nsk.kstatemachine.statemachine.StateMachine +import ru.nsk.kstatemachine.statemachine.createStateMachineBlocking +import ru.nsk.kstatemachine.statemachine.createStdLibStateMachine +import ru.nsk.kstatemachine.transition.TransitionBuilder +import ru.nsk.kstatemachine.transition.onTriggered import kotlin.coroutines.EmptyCoroutineContext typealias Callback = (T) -> Unit diff --git a/tests/src/commonTest/kotlin/ru/nsk/kstatemachine/EventMatcherTest.kt b/tests/src/commonTest/kotlin/ru/nsk/kstatemachine/event/EventMatcherTest.kt similarity index 85% rename from tests/src/commonTest/kotlin/ru/nsk/kstatemachine/EventMatcherTest.kt rename to tests/src/commonTest/kotlin/ru/nsk/kstatemachine/event/EventMatcherTest.kt index 62c9316f..afb2f5b6 100644 --- a/tests/src/commonTest/kotlin/ru/nsk/kstatemachine/EventMatcherTest.kt +++ b/tests/src/commonTest/kotlin/ru/nsk/kstatemachine/event/EventMatcherTest.kt @@ -1,12 +1,19 @@ -package ru.nsk.kstatemachine +package ru.nsk.kstatemachine.event import io.kotest.assertions.throwables.shouldThrow import io.kotest.core.spec.style.StringSpec import io.mockk.called import io.mockk.verify import io.mockk.verifySequence -import ru.nsk.kstatemachine.EventMatcherTestData.HierarchyEventL1 -import ru.nsk.kstatemachine.EventMatcherTestData.HierarchyEventL2 +import ru.nsk.kstatemachine.CoroutineStarterType +import ru.nsk.kstatemachine.createTestStateMachine +import ru.nsk.kstatemachine.event.EventMatcherTestData.HierarchyEventL1 +import ru.nsk.kstatemachine.event.EventMatcherTestData.HierarchyEventL2 +import ru.nsk.kstatemachine.listen +import ru.nsk.kstatemachine.mockkCallbacks +import ru.nsk.kstatemachine.state.initialState +import ru.nsk.kstatemachine.state.transition +import ru.nsk.kstatemachine.statemachine.processEventBlocking private object EventMatcherTestData { open class HierarchyEventL1 : Event diff --git a/tests/src/commonTest/kotlin/ru/nsk/kstatemachine/FinishedEventTest.kt b/tests/src/commonTest/kotlin/ru/nsk/kstatemachine/event/FinishedEventTest.kt similarity index 95% rename from tests/src/commonTest/kotlin/ru/nsk/kstatemachine/FinishedEventTest.kt rename to tests/src/commonTest/kotlin/ru/nsk/kstatemachine/event/FinishedEventTest.kt index e838629c..379b61e6 100644 --- a/tests/src/commonTest/kotlin/ru/nsk/kstatemachine/FinishedEventTest.kt +++ b/tests/src/commonTest/kotlin/ru/nsk/kstatemachine/event/FinishedEventTest.kt @@ -1,8 +1,12 @@ -package ru.nsk.kstatemachine +package ru.nsk.kstatemachine.event import io.kotest.core.spec.style.StringSpec import io.kotest.matchers.shouldBe import io.mockk.verifySequence +import ru.nsk.kstatemachine.* +import ru.nsk.kstatemachine.state.* +import ru.nsk.kstatemachine.statemachine.processEventBlocking +import ru.nsk.kstatemachine.transition.onTriggered class FinishedEventTest : StringSpec({ CoroutineStarterType.entries.forEach { coroutineStarterType -> diff --git a/tests/src/commonTest/kotlin/ru/nsk/kstatemachine/AccessorsApiTest.kt b/tests/src/commonTest/kotlin/ru/nsk/kstatemachine/state/AccessorsApiTest.kt similarity index 97% rename from tests/src/commonTest/kotlin/ru/nsk/kstatemachine/AccessorsApiTest.kt rename to tests/src/commonTest/kotlin/ru/nsk/kstatemachine/state/AccessorsApiTest.kt index a27810c9..dd95847d 100644 --- a/tests/src/commonTest/kotlin/ru/nsk/kstatemachine/AccessorsApiTest.kt +++ b/tests/src/commonTest/kotlin/ru/nsk/kstatemachine/state/AccessorsApiTest.kt @@ -1,9 +1,11 @@ -package ru.nsk.kstatemachine +package ru.nsk.kstatemachine.state import io.kotest.assertions.throwables.shouldThrow import io.kotest.core.spec.style.StringSpec import io.kotest.matchers.shouldBe import io.kotest.matchers.types.shouldBeSameInstanceAs +import ru.nsk.kstatemachine.* +import ru.nsk.kstatemachine.transition.Transition class AccessorsApiTest : StringSpec({ CoroutineStarterType.entries.forEach { coroutineStarterType -> diff --git a/tests/src/commonTest/kotlin/ru/nsk/kstatemachine/ChoiceStateTest.kt b/tests/src/commonTest/kotlin/ru/nsk/kstatemachine/state/ChoiceStateTest.kt similarity index 92% rename from tests/src/commonTest/kotlin/ru/nsk/kstatemachine/ChoiceStateTest.kt rename to tests/src/commonTest/kotlin/ru/nsk/kstatemachine/state/ChoiceStateTest.kt index babb1501..1fb55179 100644 --- a/tests/src/commonTest/kotlin/ru/nsk/kstatemachine/ChoiceStateTest.kt +++ b/tests/src/commonTest/kotlin/ru/nsk/kstatemachine/state/ChoiceStateTest.kt @@ -1,10 +1,15 @@ -package ru.nsk.kstatemachine +package ru.nsk.kstatemachine.state import io.kotest.core.spec.style.StringSpec import io.kotest.matchers.collections.shouldContainExactly import io.mockk.verifySequence -import ru.nsk.kstatemachine.ChoiceStateTestData.State1 -import ru.nsk.kstatemachine.ChoiceStateTestData.State2 +import ru.nsk.kstatemachine.* +import ru.nsk.kstatemachine.event.DataEvent +import ru.nsk.kstatemachine.state.ChoiceStateTestData.State1 +import ru.nsk.kstatemachine.state.ChoiceStateTestData.State2 +import ru.nsk.kstatemachine.statemachine.StateMachine +import ru.nsk.kstatemachine.statemachine.onTransitionTriggered +import ru.nsk.kstatemachine.statemachine.processEventBlocking private object ChoiceStateTestData { object State1 : DefaultState() diff --git a/tests/src/commonTest/kotlin/ru/nsk/kstatemachine/FinishingStateTest.kt b/tests/src/commonTest/kotlin/ru/nsk/kstatemachine/state/FinishingStateTest.kt similarity index 91% rename from tests/src/commonTest/kotlin/ru/nsk/kstatemachine/FinishingStateTest.kt rename to tests/src/commonTest/kotlin/ru/nsk/kstatemachine/state/FinishingStateTest.kt index 3d1b1247..ed4e8aca 100644 --- a/tests/src/commonTest/kotlin/ru/nsk/kstatemachine/FinishingStateTest.kt +++ b/tests/src/commonTest/kotlin/ru/nsk/kstatemachine/state/FinishingStateTest.kt @@ -1,7 +1,11 @@ -package ru.nsk.kstatemachine +package ru.nsk.kstatemachine.state import io.kotest.core.spec.style.StringSpec import io.kotest.matchers.shouldBe +import ru.nsk.kstatemachine.CoroutineStarterType +import ru.nsk.kstatemachine.SwitchEvent +import ru.nsk.kstatemachine.createTestStateMachine +import ru.nsk.kstatemachine.statemachine.processEventBlocking class FinishingStateTest : StringSpec({ CoroutineStarterType.entries.forEach { coroutineStarterType -> diff --git a/tests/src/commonTest/kotlin/ru/nsk/kstatemachine/HistoryStateTest.kt b/tests/src/commonTest/kotlin/ru/nsk/kstatemachine/state/HistoryStateTest.kt similarity index 98% rename from tests/src/commonTest/kotlin/ru/nsk/kstatemachine/HistoryStateTest.kt rename to tests/src/commonTest/kotlin/ru/nsk/kstatemachine/state/HistoryStateTest.kt index dcc837f0..a4bdbabf 100644 --- a/tests/src/commonTest/kotlin/ru/nsk/kstatemachine/HistoryStateTest.kt +++ b/tests/src/commonTest/kotlin/ru/nsk/kstatemachine/state/HistoryStateTest.kt @@ -1,4 +1,4 @@ -package ru.nsk.kstatemachine +package ru.nsk.kstatemachine.state import io.kotest.assertions.throwables.shouldThrow import io.kotest.core.spec.style.StringSpec @@ -7,6 +7,9 @@ import io.kotest.matchers.collections.shouldContainExactly import io.kotest.matchers.shouldBe import io.mockk.called import io.mockk.verify +import ru.nsk.kstatemachine.* +import ru.nsk.kstatemachine.statemachine.StateMachine +import ru.nsk.kstatemachine.statemachine.processEventBlocking class HistoryStateTest : StringSpec({ CoroutineStarterType.entries.forEach { coroutineStarterType -> diff --git a/tests/src/commonTest/kotlin/ru/nsk/kstatemachine/ListenersModificationTest.kt b/tests/src/commonTest/kotlin/ru/nsk/kstatemachine/state/ListenersModificationTest.kt similarity index 77% rename from tests/src/commonTest/kotlin/ru/nsk/kstatemachine/ListenersModificationTest.kt rename to tests/src/commonTest/kotlin/ru/nsk/kstatemachine/state/ListenersModificationTest.kt index 6dccf317..388ecff6 100644 --- a/tests/src/commonTest/kotlin/ru/nsk/kstatemachine/ListenersModificationTest.kt +++ b/tests/src/commonTest/kotlin/ru/nsk/kstatemachine/state/ListenersModificationTest.kt @@ -1,6 +1,15 @@ -package ru.nsk.kstatemachine +package ru.nsk.kstatemachine.state import io.kotest.core.spec.style.StringSpec +import ru.nsk.kstatemachine.CoroutineStarterType +import ru.nsk.kstatemachine.SwitchEvent +import ru.nsk.kstatemachine.createTestStateMachine +import ru.nsk.kstatemachine.statemachine.StateMachine +import ru.nsk.kstatemachine.statemachine.onStarted +import ru.nsk.kstatemachine.statemachine.processEventBlocking +import ru.nsk.kstatemachine.transition.Transition +import ru.nsk.kstatemachine.transition.TransitionParams +import ru.nsk.kstatemachine.transition.onTriggered class ListenersModificationTest : StringSpec({ CoroutineStarterType.entries.forEach { coroutineStarterType -> diff --git a/tests/src/commonTest/kotlin/ru/nsk/kstatemachine/NestedStateTest.kt b/tests/src/commonTest/kotlin/ru/nsk/kstatemachine/state/NestedStateTest.kt similarity index 95% rename from tests/src/commonTest/kotlin/ru/nsk/kstatemachine/NestedStateTest.kt rename to tests/src/commonTest/kotlin/ru/nsk/kstatemachine/state/NestedStateTest.kt index 2b20795f..14f0e918 100644 --- a/tests/src/commonTest/kotlin/ru/nsk/kstatemachine/NestedStateTest.kt +++ b/tests/src/commonTest/kotlin/ru/nsk/kstatemachine/state/NestedStateTest.kt @@ -1,8 +1,12 @@ -package ru.nsk.kstatemachine +package ru.nsk.kstatemachine.state import io.kotest.assertions.throwables.shouldThrow import io.kotest.core.spec.style.StringSpec import io.mockk.verifySequence +import ru.nsk.kstatemachine.* +import ru.nsk.kstatemachine.statemachine.StateMachine +import ru.nsk.kstatemachine.statemachine.processEventBlocking +import ru.nsk.kstatemachine.statemachine.startBlocking class NestedStateTest : StringSpec({ CoroutineStarterType.entries.forEach { coroutineStarterType -> diff --git a/tests/src/commonTest/kotlin/ru/nsk/kstatemachine/ObjectStatesTest.kt b/tests/src/commonTest/kotlin/ru/nsk/kstatemachine/state/ObjectStatesTest.kt similarity index 81% rename from tests/src/commonTest/kotlin/ru/nsk/kstatemachine/ObjectStatesTest.kt rename to tests/src/commonTest/kotlin/ru/nsk/kstatemachine/state/ObjectStatesTest.kt index 4471ede1..7ac0541e 100644 --- a/tests/src/commonTest/kotlin/ru/nsk/kstatemachine/ObjectStatesTest.kt +++ b/tests/src/commonTest/kotlin/ru/nsk/kstatemachine/state/ObjectStatesTest.kt @@ -1,9 +1,16 @@ -package ru.nsk.kstatemachine +package ru.nsk.kstatemachine.state import io.kotest.assertions.throwables.shouldThrow import io.kotest.core.spec.style.StringSpec -import ru.nsk.kstatemachine.ObjectStatesTestData.State1 -import ru.nsk.kstatemachine.ObjectStatesTestData.State2 +import ru.nsk.kstatemachine.CoroutineStarterType +import ru.nsk.kstatemachine.SwitchEvent +import ru.nsk.kstatemachine.createTestStateMachine +import ru.nsk.kstatemachine.state.ObjectStatesTestData.State1 +import ru.nsk.kstatemachine.state.ObjectStatesTestData.State2 +import ru.nsk.kstatemachine.statemachine.StateMachine +import ru.nsk.kstatemachine.statemachine.destroyBlocking +import ru.nsk.kstatemachine.statemachine.processEventBlocking +import ru.nsk.kstatemachine.statemachine.stop private object ObjectStatesTestData { object State1 : DefaultState("state1") diff --git a/tests/src/commonTest/kotlin/ru/nsk/kstatemachine/ParallelStatesTest.kt b/tests/src/commonTest/kotlin/ru/nsk/kstatemachine/state/ParallelStatesTest.kt similarity index 97% rename from tests/src/commonTest/kotlin/ru/nsk/kstatemachine/ParallelStatesTest.kt rename to tests/src/commonTest/kotlin/ru/nsk/kstatemachine/state/ParallelStatesTest.kt index 79e079a6..9ffa3ab0 100644 --- a/tests/src/commonTest/kotlin/ru/nsk/kstatemachine/ParallelStatesTest.kt +++ b/tests/src/commonTest/kotlin/ru/nsk/kstatemachine/state/ParallelStatesTest.kt @@ -1,4 +1,4 @@ -package ru.nsk.kstatemachine +package ru.nsk.kstatemachine.state import io.kotest.assertions.throwables.shouldThrow import io.kotest.core.spec.style.StringSpec @@ -7,6 +7,9 @@ import io.kotest.matchers.collections.containExactlyInAnyOrder import io.kotest.matchers.should import io.mockk.verify import io.mockk.verifySequence +import ru.nsk.kstatemachine.* +import ru.nsk.kstatemachine.statemachine.processEventBlocking +import ru.nsk.kstatemachine.transition.onTriggered class ParallelStatesTest : StringSpec({ CoroutineStarterType.entries.forEach { coroutineStarterType -> diff --git a/tests/src/commonTest/kotlin/ru/nsk/kstatemachine/ParallelTargetStatesTest.kt b/tests/src/commonTest/kotlin/ru/nsk/kstatemachine/state/ParallelTargetStatesTest.kt similarity index 99% rename from tests/src/commonTest/kotlin/ru/nsk/kstatemachine/ParallelTargetStatesTest.kt rename to tests/src/commonTest/kotlin/ru/nsk/kstatemachine/state/ParallelTargetStatesTest.kt index ad24d85f..d5a51a88 100644 --- a/tests/src/commonTest/kotlin/ru/nsk/kstatemachine/ParallelTargetStatesTest.kt +++ b/tests/src/commonTest/kotlin/ru/nsk/kstatemachine/state/ParallelTargetStatesTest.kt @@ -1,4 +1,4 @@ -package ru.nsk.kstatemachine +package ru.nsk.kstatemachine.state import io.kotest.assertions.throwables.shouldThrow import io.kotest.assertions.throwables.shouldThrowWithMessage @@ -7,7 +7,8 @@ import io.kotest.matchers.collections.shouldContainExactly import io.kotest.matchers.shouldBe import io.kotest.matchers.string.shouldStartWith import io.mockk.verifySequence -import ru.nsk.kstatemachine.Testing.startFrom +import ru.nsk.kstatemachine.* +import ru.nsk.kstatemachine.transition.targetParallelStates class ParallelTargetStatesTest : StringSpec({ CoroutineStarterType.entries.forEach { coroutineStarterType -> diff --git a/tests/src/commonTest/kotlin/ru/nsk/kstatemachine/StateCleanupTest.kt b/tests/src/commonTest/kotlin/ru/nsk/kstatemachine/state/StateCleanupTest.kt similarity index 80% rename from tests/src/commonTest/kotlin/ru/nsk/kstatemachine/StateCleanupTest.kt rename to tests/src/commonTest/kotlin/ru/nsk/kstatemachine/state/StateCleanupTest.kt index 378e7ca0..c27fce9f 100644 --- a/tests/src/commonTest/kotlin/ru/nsk/kstatemachine/StateCleanupTest.kt +++ b/tests/src/commonTest/kotlin/ru/nsk/kstatemachine/state/StateCleanupTest.kt @@ -1,9 +1,13 @@ -package ru.nsk.kstatemachine +package ru.nsk.kstatemachine.state import io.kotest.core.spec.style.StringSpec import io.kotest.matchers.shouldBe -import io.mockk.* -import ru.nsk.kstatemachine.StateCleanupTestData.State1 +import io.mockk.coVerify +import io.mockk.spyk +import ru.nsk.kstatemachine.CoroutineStarterType +import ru.nsk.kstatemachine.createTestStateMachine +import ru.nsk.kstatemachine.state.StateCleanupTestData.State1 +import ru.nsk.kstatemachine.statemachine.destroyBlocking private object StateCleanupTestData { class State1 : DefaultState("state1") diff --git a/tests/src/commonTest/kotlin/ru/nsk/kstatemachine/StateGroupListenerTest.kt b/tests/src/commonTest/kotlin/ru/nsk/kstatemachine/state/StateGroupListenerTest.kt similarity index 95% rename from tests/src/commonTest/kotlin/ru/nsk/kstatemachine/StateGroupListenerTest.kt rename to tests/src/commonTest/kotlin/ru/nsk/kstatemachine/state/StateGroupListenerTest.kt index baa47d5d..104d3a71 100644 --- a/tests/src/commonTest/kotlin/ru/nsk/kstatemachine/StateGroupListenerTest.kt +++ b/tests/src/commonTest/kotlin/ru/nsk/kstatemachine/state/StateGroupListenerTest.kt @@ -1,4 +1,4 @@ -package ru.nsk.kstatemachine +package ru.nsk.kstatemachine.state import io.kotest.assertions.throwables.shouldThrow import io.kotest.core.spec.style.FreeSpec @@ -7,9 +7,12 @@ import io.mockk.called import io.mockk.mockk import io.mockk.verify import io.mockk.verifySequence -import ru.nsk.kstatemachine.StateGroupListenerTestData.State1 -import ru.nsk.kstatemachine.StateGroupListenerTestData.State2 -import ru.nsk.kstatemachine.StateGroupListenerTestData.State3 +import ru.nsk.kstatemachine.* +import ru.nsk.kstatemachine.state.StateGroupListenerTestData.State1 +import ru.nsk.kstatemachine.state.StateGroupListenerTestData.State2 +import ru.nsk.kstatemachine.state.StateGroupListenerTestData.State3 +import ru.nsk.kstatemachine.statemachine.processEventBlocking +import ru.nsk.kstatemachine.statemachine.startBlocking private object StateGroupListenerTestData { object State1 : DefaultState() diff --git a/tests/src/commonTest/kotlin/ru/nsk/kstatemachine/StateTest.kt b/tests/src/commonTest/kotlin/ru/nsk/kstatemachine/state/StateTest.kt similarity index 89% rename from tests/src/commonTest/kotlin/ru/nsk/kstatemachine/StateTest.kt rename to tests/src/commonTest/kotlin/ru/nsk/kstatemachine/state/StateTest.kt index f98ac4e0..782ad025 100644 --- a/tests/src/commonTest/kotlin/ru/nsk/kstatemachine/StateTest.kt +++ b/tests/src/commonTest/kotlin/ru/nsk/kstatemachine/state/StateTest.kt @@ -1,9 +1,16 @@ -package ru.nsk.kstatemachine +package ru.nsk.kstatemachine.state import io.kotest.assertions.throwables.shouldThrowUnitWithMessage import io.kotest.core.spec.style.StringSpec import io.kotest.matchers.shouldBe -import ru.nsk.kstatemachine.StateTestData.SubclassState +import ru.nsk.kstatemachine.CoroutineStarterType +import ru.nsk.kstatemachine.SwitchEvent +import ru.nsk.kstatemachine.createTestStateMachine +import ru.nsk.kstatemachine.metainfo.UmlMetaInfo +import ru.nsk.kstatemachine.state.StateTestData.SubclassState +import ru.nsk.kstatemachine.statemachine.destroy +import ru.nsk.kstatemachine.statemachine.processEventBlocking +import ru.nsk.kstatemachine.transition.onTriggered private object StateTestData { class SubclassState : DefaultState() { diff --git a/tests/src/commonTest/kotlin/ru/nsk/kstatemachine/UndoTest.kt b/tests/src/commonTest/kotlin/ru/nsk/kstatemachine/state/UndoTest.kt similarity index 97% rename from tests/src/commonTest/kotlin/ru/nsk/kstatemachine/UndoTest.kt rename to tests/src/commonTest/kotlin/ru/nsk/kstatemachine/state/UndoTest.kt index bc5c670d..87bbe8ff 100644 --- a/tests/src/commonTest/kotlin/ru/nsk/kstatemachine/UndoTest.kt +++ b/tests/src/commonTest/kotlin/ru/nsk/kstatemachine/state/UndoTest.kt @@ -1,11 +1,19 @@ -package ru.nsk.kstatemachine +package ru.nsk.kstatemachine.state import io.kotest.assertions.throwables.shouldThrow import io.kotest.core.spec.style.StringSpec import io.kotest.matchers.collections.shouldContain import io.kotest.matchers.shouldBe import io.kotest.matchers.types.shouldBeInstanceOf -import ru.nsk.kstatemachine.UndoTestData.SwitchDataEvent +import ru.nsk.kstatemachine.* +import ru.nsk.kstatemachine.event.DataEvent +import ru.nsk.kstatemachine.event.StartEvent +import ru.nsk.kstatemachine.event.UndoEvent +import ru.nsk.kstatemachine.event.WrappedEvent +import ru.nsk.kstatemachine.state.UndoTestData.SwitchDataEvent +import ru.nsk.kstatemachine.statemachine.* +import ru.nsk.kstatemachine.transition.unwrappedArgument +import ru.nsk.kstatemachine.transition.unwrappedEvent private object UndoTestData { class SwitchDataEvent(override val data: Int) : DataEvent diff --git a/tests/src/commonTest/kotlin/ru/nsk/kstatemachine/CompositionStateMachinesTest.kt b/tests/src/commonTest/kotlin/ru/nsk/kstatemachine/statemachine/CompositionStateMachinesTest.kt similarity index 98% rename from tests/src/commonTest/kotlin/ru/nsk/kstatemachine/CompositionStateMachinesTest.kt rename to tests/src/commonTest/kotlin/ru/nsk/kstatemachine/statemachine/CompositionStateMachinesTest.kt index adae77a0..705b6603 100644 --- a/tests/src/commonTest/kotlin/ru/nsk/kstatemachine/CompositionStateMachinesTest.kt +++ b/tests/src/commonTest/kotlin/ru/nsk/kstatemachine/statemachine/CompositionStateMachinesTest.kt @@ -1,4 +1,4 @@ -package ru.nsk.kstatemachine +package ru.nsk.kstatemachine.statemachine import io.kotest.assertions.throwables.shouldThrow import io.kotest.core.spec.style.StringSpec @@ -8,6 +8,8 @@ import io.mockk.clearMocks import io.mockk.verify import io.mockk.verifyOrder import io.mockk.verifySequence +import ru.nsk.kstatemachine.* +import ru.nsk.kstatemachine.state.* /** * In a parent state machine it is not possible to use as transitions targets states from inner machine and vise versa. diff --git a/tests/src/commonTest/kotlin/ru/nsk/kstatemachine/FinishingStateMachineTest.kt b/tests/src/commonTest/kotlin/ru/nsk/kstatemachine/statemachine/FinishingStateMachineTest.kt similarity index 98% rename from tests/src/commonTest/kotlin/ru/nsk/kstatemachine/FinishingStateMachineTest.kt rename to tests/src/commonTest/kotlin/ru/nsk/kstatemachine/statemachine/FinishingStateMachineTest.kt index ba156b9c..17e62271 100644 --- a/tests/src/commonTest/kotlin/ru/nsk/kstatemachine/FinishingStateMachineTest.kt +++ b/tests/src/commonTest/kotlin/ru/nsk/kstatemachine/statemachine/FinishingStateMachineTest.kt @@ -1,4 +1,4 @@ -package ru.nsk.kstatemachine +package ru.nsk.kstatemachine.statemachine import io.kotest.assertions.throwables.shouldThrow import io.kotest.core.spec.style.StringSpec @@ -7,6 +7,9 @@ import io.mockk.called import io.mockk.confirmVerified import io.mockk.verify import io.mockk.verifySequence +import ru.nsk.kstatemachine.* +import ru.nsk.kstatemachine.state.* +import ru.nsk.kstatemachine.transition.onTriggered class FinishingStateMachineTest : StringSpec({ CoroutineStarterType.entries.forEach { coroutineStarterType -> diff --git a/tests/src/commonTest/kotlin/ru/nsk/kstatemachine/IgnoredEventHandlerTest.kt b/tests/src/commonTest/kotlin/ru/nsk/kstatemachine/statemachine/IgnoredEventHandlerTest.kt similarity index 86% rename from tests/src/commonTest/kotlin/ru/nsk/kstatemachine/IgnoredEventHandlerTest.kt rename to tests/src/commonTest/kotlin/ru/nsk/kstatemachine/statemachine/IgnoredEventHandlerTest.kt index d538743b..ec5daa3b 100644 --- a/tests/src/commonTest/kotlin/ru/nsk/kstatemachine/IgnoredEventHandlerTest.kt +++ b/tests/src/commonTest/kotlin/ru/nsk/kstatemachine/statemachine/IgnoredEventHandlerTest.kt @@ -1,11 +1,17 @@ -package ru.nsk.kstatemachine +package ru.nsk.kstatemachine.statemachine import io.kotest.assertions.throwables.shouldThrow import io.kotest.core.spec.style.StringSpec import io.kotest.matchers.shouldBe import io.mockk.verify import io.mockk.verifySequence -import ru.nsk.kstatemachine.ProcessingResult.IGNORED +import ru.nsk.kstatemachine.* +import ru.nsk.kstatemachine.state.initialFinalState +import ru.nsk.kstatemachine.state.initialState +import ru.nsk.kstatemachine.state.onFinished +import ru.nsk.kstatemachine.state.transitionConditionally +import ru.nsk.kstatemachine.statemachine.ProcessingResult.IGNORED +import ru.nsk.kstatemachine.transition.noTransition class IgnoredEventHandlerTest : StringSpec({ CoroutineStarterType.entries.forEach { coroutineStarterType -> diff --git a/tests/src/commonTest/kotlin/ru/nsk/kstatemachine/ListenerExceptionHandlerTest.kt b/tests/src/commonTest/kotlin/ru/nsk/kstatemachine/statemachine/ListenerExceptionHandlerTest.kt similarity index 96% rename from tests/src/commonTest/kotlin/ru/nsk/kstatemachine/ListenerExceptionHandlerTest.kt rename to tests/src/commonTest/kotlin/ru/nsk/kstatemachine/statemachine/ListenerExceptionHandlerTest.kt index 5f6282d9..54972ebc 100644 --- a/tests/src/commonTest/kotlin/ru/nsk/kstatemachine/ListenerExceptionHandlerTest.kt +++ b/tests/src/commonTest/kotlin/ru/nsk/kstatemachine/statemachine/ListenerExceptionHandlerTest.kt @@ -1,10 +1,12 @@ -package ru.nsk.kstatemachine +package ru.nsk.kstatemachine.statemachine import io.kotest.assertions.throwables.shouldThrow import io.kotest.core.spec.style.StringSpec import io.kotest.matchers.shouldBe import io.mockk.* -import ru.nsk.kstatemachine.Testing.startFromBlocking +import ru.nsk.kstatemachine.* +import ru.nsk.kstatemachine.state.* +import ru.nsk.kstatemachine.testing.Testing.startFromBlocking class ListenerExceptionHandlerTest : StringSpec({ CoroutineStarterType.entries.forEach { coroutineStarterType -> diff --git a/tests/src/commonTest/kotlin/ru/nsk/kstatemachine/PendingEventHandlerTest.kt b/tests/src/commonTest/kotlin/ru/nsk/kstatemachine/statemachine/PendingEventHandlerTest.kt similarity index 92% rename from tests/src/commonTest/kotlin/ru/nsk/kstatemachine/PendingEventHandlerTest.kt rename to tests/src/commonTest/kotlin/ru/nsk/kstatemachine/statemachine/PendingEventHandlerTest.kt index 3b5405b3..44705a4e 100644 --- a/tests/src/commonTest/kotlin/ru/nsk/kstatemachine/PendingEventHandlerTest.kt +++ b/tests/src/commonTest/kotlin/ru/nsk/kstatemachine/statemachine/PendingEventHandlerTest.kt @@ -1,11 +1,17 @@ -package ru.nsk.kstatemachine +package ru.nsk.kstatemachine.statemachine import io.kotest.assertions.throwables.shouldThrow import io.kotest.core.spec.style.StringSpec import io.kotest.matchers.shouldBe import io.mockk.verifySequence -import ru.nsk.kstatemachine.ProcessingResult.PENDING -import ru.nsk.kstatemachine.ProcessingResult.PROCESSED +import ru.nsk.kstatemachine.* +import ru.nsk.kstatemachine.state.initialState +import ru.nsk.kstatemachine.state.onEntry +import ru.nsk.kstatemachine.state.state +import ru.nsk.kstatemachine.state.transition +import ru.nsk.kstatemachine.statemachine.ProcessingResult.PENDING +import ru.nsk.kstatemachine.statemachine.ProcessingResult.PROCESSED +import ru.nsk.kstatemachine.transition.onTriggered class PendingEventHandlerTest : StringSpec({ CoroutineStarterType.entries.forEach { coroutineStarterType -> diff --git a/tests/src/commonTest/kotlin/ru/nsk/kstatemachine/StateMachineTest.kt b/tests/src/commonTest/kotlin/ru/nsk/kstatemachine/statemachine/StateMachineTest.kt similarity index 95% rename from tests/src/commonTest/kotlin/ru/nsk/kstatemachine/StateMachineTest.kt rename to tests/src/commonTest/kotlin/ru/nsk/kstatemachine/statemachine/StateMachineTest.kt index d0ffe201..19ed6e79 100644 --- a/tests/src/commonTest/kotlin/ru/nsk/kstatemachine/StateMachineTest.kt +++ b/tests/src/commonTest/kotlin/ru/nsk/kstatemachine/statemachine/StateMachineTest.kt @@ -1,4 +1,4 @@ -package ru.nsk.kstatemachine +package ru.nsk.kstatemachine.statemachine import io.kotest.assertions.throwables.shouldThrow import io.kotest.assertions.throwables.shouldThrowUnit @@ -12,9 +12,18 @@ import io.kotest.matchers.shouldBe import io.mockk.called import io.mockk.verify import io.mockk.verifySequence -import ru.nsk.kstatemachine.StateMachineTestData.OffEvent -import ru.nsk.kstatemachine.StateMachineTestData.OnEvent -import ru.nsk.kstatemachine.Testing.startFromBlocking +import ru.nsk.kstatemachine.* +import ru.nsk.kstatemachine.event.Event +import ru.nsk.kstatemachine.event.EventMatcher +import ru.nsk.kstatemachine.event.StartEvent +import ru.nsk.kstatemachine.state.* +import ru.nsk.kstatemachine.statemachine.StateMachineTestData.OffEvent +import ru.nsk.kstatemachine.statemachine.StateMachineTestData.OnEvent +import ru.nsk.kstatemachine.testing.Testing.startFromBlocking +import ru.nsk.kstatemachine.transition.DefaultTransition +import ru.nsk.kstatemachine.transition.Transition +import ru.nsk.kstatemachine.transition.TransitionType +import ru.nsk.kstatemachine.transition.onTriggered private object StateMachineTestData { object OnEvent : Event diff --git a/tests/src/commonTest/kotlin/ru/nsk/kstatemachine/TestingStartFromTest.kt b/tests/src/commonTest/kotlin/ru/nsk/kstatemachine/testing/TestingStartFromTest.kt similarity index 94% rename from tests/src/commonTest/kotlin/ru/nsk/kstatemachine/TestingStartFromTest.kt rename to tests/src/commonTest/kotlin/ru/nsk/kstatemachine/testing/TestingStartFromTest.kt index 69447c57..69a14574 100644 --- a/tests/src/commonTest/kotlin/ru/nsk/kstatemachine/TestingStartFromTest.kt +++ b/tests/src/commonTest/kotlin/ru/nsk/kstatemachine/testing/TestingStartFromTest.kt @@ -1,10 +1,13 @@ -package ru.nsk.kstatemachine +package ru.nsk.kstatemachine.testing import io.kotest.core.spec.style.StringSpec import io.kotest.matchers.collections.shouldContainExactly import io.kotest.matchers.shouldBe -import ru.nsk.kstatemachine.Testing.startFrom -import ru.nsk.kstatemachine.Testing.startFromBlocking +import ru.nsk.kstatemachine.* +import ru.nsk.kstatemachine.state.* +import ru.nsk.kstatemachine.statemachine.onStarted +import ru.nsk.kstatemachine.testing.Testing.startFrom +import ru.nsk.kstatemachine.testing.Testing.startFromBlocking enum class ApiType { StateByReference, StateByName } diff --git a/tests/src/commonTest/kotlin/ru/nsk/kstatemachine/ConditionalTransitionTest.kt b/tests/src/commonTest/kotlin/ru/nsk/kstatemachine/transition/ConditionalTransitionTest.kt similarity index 92% rename from tests/src/commonTest/kotlin/ru/nsk/kstatemachine/ConditionalTransitionTest.kt rename to tests/src/commonTest/kotlin/ru/nsk/kstatemachine/transition/ConditionalTransitionTest.kt index de554d80..db5d5476 100644 --- a/tests/src/commonTest/kotlin/ru/nsk/kstatemachine/ConditionalTransitionTest.kt +++ b/tests/src/commonTest/kotlin/ru/nsk/kstatemachine/transition/ConditionalTransitionTest.kt @@ -1,10 +1,18 @@ -package ru.nsk.kstatemachine +package ru.nsk.kstatemachine.transition import io.kotest.core.spec.style.StringSpec import io.mockk.called import io.mockk.verify import io.mockk.verifySequence -import ru.nsk.kstatemachine.ConditionalTransitionTestData.ConditionEvent +import ru.nsk.kstatemachine.* +import ru.nsk.kstatemachine.event.Event +import ru.nsk.kstatemachine.event.StartEvent +import ru.nsk.kstatemachine.state.DefaultState +import ru.nsk.kstatemachine.state.addInitialState +import ru.nsk.kstatemachine.state.transitionConditionally +import ru.nsk.kstatemachine.statemachine.onTransitionTriggered +import ru.nsk.kstatemachine.statemachine.processEventBlocking +import ru.nsk.kstatemachine.transition.ConditionalTransitionTestData.ConditionEvent private object ConditionalTransitionTestData { class ConditionEvent(val data: Boolean) : Event diff --git a/tests/src/commonTest/kotlin/ru/nsk/kstatemachine/CrossLevelTransitionTest.kt b/tests/src/commonTest/kotlin/ru/nsk/kstatemachine/transition/CrossLevelTransitionTest.kt similarity index 98% rename from tests/src/commonTest/kotlin/ru/nsk/kstatemachine/CrossLevelTransitionTest.kt rename to tests/src/commonTest/kotlin/ru/nsk/kstatemachine/transition/CrossLevelTransitionTest.kt index 2a1e5f3f..55d4e3cd 100644 --- a/tests/src/commonTest/kotlin/ru/nsk/kstatemachine/CrossLevelTransitionTest.kt +++ b/tests/src/commonTest/kotlin/ru/nsk/kstatemachine/transition/CrossLevelTransitionTest.kt @@ -1,9 +1,13 @@ -package ru.nsk.kstatemachine +package ru.nsk.kstatemachine.transition import io.kotest.assertions.throwables.shouldThrow import io.kotest.core.spec.style.StringSpec import io.kotest.matchers.collections.shouldContainExactly import io.mockk.verifySequence +import ru.nsk.kstatemachine.* +import ru.nsk.kstatemachine.state.* +import ru.nsk.kstatemachine.statemachine.StateMachine +import ru.nsk.kstatemachine.statemachine.processEventBlocking class CrossLevelTransitionTest : StringSpec({ CoroutineStarterType.entries.forEach { coroutineStarterType -> diff --git a/tests/src/commonTest/kotlin/ru/nsk/kstatemachine/CustomTransitionTest.kt b/tests/src/commonTest/kotlin/ru/nsk/kstatemachine/transition/CustomTransitionTest.kt similarity index 71% rename from tests/src/commonTest/kotlin/ru/nsk/kstatemachine/CustomTransitionTest.kt rename to tests/src/commonTest/kotlin/ru/nsk/kstatemachine/transition/CustomTransitionTest.kt index cdb9ba32..0be36a48 100644 --- a/tests/src/commonTest/kotlin/ru/nsk/kstatemachine/CustomTransitionTest.kt +++ b/tests/src/commonTest/kotlin/ru/nsk/kstatemachine/transition/CustomTransitionTest.kt @@ -1,10 +1,18 @@ -package ru.nsk.kstatemachine +package ru.nsk.kstatemachine.transition import io.kotest.core.spec.style.StringSpec import io.mockk.verifySequence -import ru.nsk.kstatemachine.CustomTransitionTestData.CustomEvent -import ru.nsk.kstatemachine.CustomTransitionTestData.CustomTransition -import ru.nsk.kstatemachine.EventMatcher.Companion.isInstanceOf +import ru.nsk.kstatemachine.CoroutineStarterType +import ru.nsk.kstatemachine.createTestStateMachine +import ru.nsk.kstatemachine.event.Event +import ru.nsk.kstatemachine.event.EventMatcher.Companion.isInstanceOf +import ru.nsk.kstatemachine.mockkCallbacks +import ru.nsk.kstatemachine.state.IState +import ru.nsk.kstatemachine.state.initialState +import ru.nsk.kstatemachine.state.state +import ru.nsk.kstatemachine.statemachine.processEventBlocking +import ru.nsk.kstatemachine.transition.CustomTransitionTestData.CustomEvent +import ru.nsk.kstatemachine.transition.CustomTransitionTestData.CustomTransition private object CustomTransitionTestData { class CustomEvent(val value: Int) : Event diff --git a/tests/src/commonTest/kotlin/ru/nsk/kstatemachine/ExternalTransitionTest.kt b/tests/src/commonTest/kotlin/ru/nsk/kstatemachine/transition/ExternalTransitionTest.kt similarity index 94% rename from tests/src/commonTest/kotlin/ru/nsk/kstatemachine/ExternalTransitionTest.kt rename to tests/src/commonTest/kotlin/ru/nsk/kstatemachine/transition/ExternalTransitionTest.kt index 4d6021c3..3078e46c 100644 --- a/tests/src/commonTest/kotlin/ru/nsk/kstatemachine/ExternalTransitionTest.kt +++ b/tests/src/commonTest/kotlin/ru/nsk/kstatemachine/transition/ExternalTransitionTest.kt @@ -1,8 +1,11 @@ -package ru.nsk.kstatemachine +package ru.nsk.kstatemachine.transition import io.kotest.core.spec.style.StringSpec -import ru.nsk.kstatemachine.TransitionType.EXTERNAL -import ru.nsk.kstatemachine.TransitionType.LOCAL +import ru.nsk.kstatemachine.* +import ru.nsk.kstatemachine.state.* +import ru.nsk.kstatemachine.statemachine.processEventBlocking +import ru.nsk.kstatemachine.transition.TransitionType.EXTERNAL +import ru.nsk.kstatemachine.transition.TransitionType.LOCAL class ExternalTransitionTest : StringSpec({ CoroutineStarterType.entries.forEach { coroutineStarterType -> diff --git a/tests/src/commonTest/kotlin/ru/nsk/kstatemachine/GuardedTransitionTest.kt b/tests/src/commonTest/kotlin/ru/nsk/kstatemachine/transition/GuardedTransitionTest.kt similarity index 93% rename from tests/src/commonTest/kotlin/ru/nsk/kstatemachine/GuardedTransitionTest.kt rename to tests/src/commonTest/kotlin/ru/nsk/kstatemachine/transition/GuardedTransitionTest.kt index db5564dd..564743c9 100644 --- a/tests/src/commonTest/kotlin/ru/nsk/kstatemachine/GuardedTransitionTest.kt +++ b/tests/src/commonTest/kotlin/ru/nsk/kstatemachine/transition/GuardedTransitionTest.kt @@ -1,9 +1,13 @@ -package ru.nsk.kstatemachine +package ru.nsk.kstatemachine.transition import io.kotest.core.spec.style.StringSpec import io.mockk.called import io.mockk.verify import io.mockk.verifySequence +import ru.nsk.kstatemachine.* +import ru.nsk.kstatemachine.state.* +import ru.nsk.kstatemachine.statemachine.StateMachine +import ru.nsk.kstatemachine.statemachine.processEventBlocking class GuardedTransitionTest : StringSpec({ CoroutineStarterType.entries.forEach { coroutineStarterType -> diff --git a/tests/src/commonTest/kotlin/ru/nsk/kstatemachine/TransitionArgumentTest.kt b/tests/src/commonTest/kotlin/ru/nsk/kstatemachine/transition/TransitionArgumentTest.kt similarity index 87% rename from tests/src/commonTest/kotlin/ru/nsk/kstatemachine/TransitionArgumentTest.kt rename to tests/src/commonTest/kotlin/ru/nsk/kstatemachine/transition/TransitionArgumentTest.kt index 872fd6c3..ec6e334a 100644 --- a/tests/src/commonTest/kotlin/ru/nsk/kstatemachine/TransitionArgumentTest.kt +++ b/tests/src/commonTest/kotlin/ru/nsk/kstatemachine/transition/TransitionArgumentTest.kt @@ -1,8 +1,12 @@ -package ru.nsk.kstatemachine +package ru.nsk.kstatemachine.transition import io.kotest.core.spec.style.StringSpec import io.kotest.matchers.shouldBe import io.mockk.verifySequence +import ru.nsk.kstatemachine.* +import ru.nsk.kstatemachine.state.* +import ru.nsk.kstatemachine.statemachine.processEventBlocking +import ru.nsk.kstatemachine.statemachine.startBlocking private const val ARGUMENT = 1 diff --git a/tests/src/commonTest/kotlin/ru/nsk/kstatemachine/TransitionOverrideTest.kt b/tests/src/commonTest/kotlin/ru/nsk/kstatemachine/transition/TransitionOverrideTest.kt similarity index 94% rename from tests/src/commonTest/kotlin/ru/nsk/kstatemachine/TransitionOverrideTest.kt rename to tests/src/commonTest/kotlin/ru/nsk/kstatemachine/transition/TransitionOverrideTest.kt index c0c34fd7..cd0d292b 100644 --- a/tests/src/commonTest/kotlin/ru/nsk/kstatemachine/TransitionOverrideTest.kt +++ b/tests/src/commonTest/kotlin/ru/nsk/kstatemachine/transition/TransitionOverrideTest.kt @@ -1,7 +1,11 @@ -package ru.nsk.kstatemachine +package ru.nsk.kstatemachine.transition import io.kotest.core.spec.style.StringSpec import io.mockk.verifySequence +import ru.nsk.kstatemachine.* +import ru.nsk.kstatemachine.event.Event +import ru.nsk.kstatemachine.state.* +import ru.nsk.kstatemachine.statemachine.processEventBlocking class TransitionOverrideTest : StringSpec({ CoroutineStarterType.entries.forEach { coroutineStarterType -> diff --git a/tests/src/commonTest/kotlin/ru/nsk/kstatemachine/TransitionTest.kt b/tests/src/commonTest/kotlin/ru/nsk/kstatemachine/transition/TransitionTest.kt similarity index 96% rename from tests/src/commonTest/kotlin/ru/nsk/kstatemachine/TransitionTest.kt rename to tests/src/commonTest/kotlin/ru/nsk/kstatemachine/transition/TransitionTest.kt index a0fe6f82..3c73c759 100644 --- a/tests/src/commonTest/kotlin/ru/nsk/kstatemachine/TransitionTest.kt +++ b/tests/src/commonTest/kotlin/ru/nsk/kstatemachine/transition/TransitionTest.kt @@ -1,4 +1,4 @@ -package ru.nsk.kstatemachine +package ru.nsk.kstatemachine.transition import io.kotest.assertions.throwables.shouldThrow import io.kotest.core.spec.style.StringSpec @@ -8,7 +8,10 @@ import io.mockk.confirmVerified import io.mockk.verify import io.mockk.verifySequence import org.junit.jupiter.api.fail -import ru.nsk.kstatemachine.ProcessingResult.PROCESSED +import ru.nsk.kstatemachine.* +import ru.nsk.kstatemachine.state.* +import ru.nsk.kstatemachine.statemachine.ProcessingResult.PROCESSED +import ru.nsk.kstatemachine.statemachine.processEventBlocking class TransitionTest : StringSpec({ CoroutineStarterType.entries.forEach { coroutineStarterType -> diff --git a/tests/src/commonTest/kotlin/ru/nsk/kstatemachine/TypesafeTransitionTest.kt b/tests/src/commonTest/kotlin/ru/nsk/kstatemachine/transition/TypesafeTransitionTest.kt similarity index 95% rename from tests/src/commonTest/kotlin/ru/nsk/kstatemachine/TypesafeTransitionTest.kt rename to tests/src/commonTest/kotlin/ru/nsk/kstatemachine/transition/TypesafeTransitionTest.kt index 820d2359..11e49654 100644 --- a/tests/src/commonTest/kotlin/ru/nsk/kstatemachine/TypesafeTransitionTest.kt +++ b/tests/src/commonTest/kotlin/ru/nsk/kstatemachine/transition/TypesafeTransitionTest.kt @@ -1,4 +1,4 @@ -package ru.nsk.kstatemachine +package ru.nsk.kstatemachine.transition import io.kotest.assertions.throwables.shouldThrow import io.kotest.core.spec.style.StringSpec @@ -6,9 +6,17 @@ import io.kotest.matchers.collections.shouldContainExactly import io.kotest.matchers.shouldBe import io.mockk.verify import io.mockk.verifySequence -import ru.nsk.kstatemachine.TypesafeTransitionTestData.CustomDataEvent -import ru.nsk.kstatemachine.TypesafeTransitionTestData.IdEvent -import ru.nsk.kstatemachine.TypesafeTransitionTestData.NameEvent +import ru.nsk.kstatemachine.* +import ru.nsk.kstatemachine.event.DataEvent +import ru.nsk.kstatemachine.event.DataExtractor +import ru.nsk.kstatemachine.event.Event +import ru.nsk.kstatemachine.event.FinishedEvent +import ru.nsk.kstatemachine.state.* +import ru.nsk.kstatemachine.statemachine.StateMachine +import ru.nsk.kstatemachine.statemachine.processEventBlocking +import ru.nsk.kstatemachine.transition.TypesafeTransitionTestData.CustomDataEvent +import ru.nsk.kstatemachine.transition.TypesafeTransitionTestData.IdEvent +import ru.nsk.kstatemachine.transition.TypesafeTransitionTestData.NameEvent private object TypesafeTransitionTestData { class CustomDataEvent(val value: Int) : Event diff --git a/tests/src/commonTest/kotlin/ru/nsk/kstatemachine/UniqueNamesTest.kt b/tests/src/commonTest/kotlin/ru/nsk/kstatemachine/visitors/CheckUniqueNamesVisitorTest.kt similarity index 81% rename from tests/src/commonTest/kotlin/ru/nsk/kstatemachine/UniqueNamesTest.kt rename to tests/src/commonTest/kotlin/ru/nsk/kstatemachine/visitors/CheckUniqueNamesVisitorTest.kt index e90f876b..fc8f56ec 100644 --- a/tests/src/commonTest/kotlin/ru/nsk/kstatemachine/UniqueNamesTest.kt +++ b/tests/src/commonTest/kotlin/ru/nsk/kstatemachine/visitors/CheckUniqueNamesVisitorTest.kt @@ -1,9 +1,15 @@ -package ru.nsk.kstatemachine +package ru.nsk.kstatemachine.visitors import io.kotest.assertions.throwables.shouldThrow import io.kotest.core.spec.style.StringSpec +import ru.nsk.kstatemachine.CoroutineStarterType +import ru.nsk.kstatemachine.SwitchEvent +import ru.nsk.kstatemachine.createTestStateMachine +import ru.nsk.kstatemachine.state.addInitialState +import ru.nsk.kstatemachine.state.initialState +import ru.nsk.kstatemachine.state.transition -class UniqueNamesTest : StringSpec({ +class CheckUniqueNamesVisitorTest : StringSpec({ CoroutineStarterType.entries.forEach { coroutineStarterType -> "do not allow transitions with same name" { shouldThrow { diff --git a/tests/src/commonTest/kotlin/ru/nsk/kstatemachine/ActiveStatesTest.kt b/tests/src/commonTest/kotlin/ru/nsk/kstatemachine/visitors/GetActiveStatesVisitorTest.kt similarity index 89% rename from tests/src/commonTest/kotlin/ru/nsk/kstatemachine/ActiveStatesTest.kt rename to tests/src/commonTest/kotlin/ru/nsk/kstatemachine/visitors/GetActiveStatesVisitorTest.kt index fb7c006c..69e257ff 100644 --- a/tests/src/commonTest/kotlin/ru/nsk/kstatemachine/ActiveStatesTest.kt +++ b/tests/src/commonTest/kotlin/ru/nsk/kstatemachine/visitors/GetActiveStatesVisitorTest.kt @@ -1,11 +1,15 @@ -package ru.nsk.kstatemachine +package ru.nsk.kstatemachine.visitors import io.kotest.core.spec.style.StringSpec import io.kotest.matchers.collections.containExactly -import io.kotest.matchers.collections.shouldContainExactly import io.kotest.matchers.should +import ru.nsk.kstatemachine.CoroutineStarterType +import ru.nsk.kstatemachine.SwitchEvent +import ru.nsk.kstatemachine.createTestStateMachine +import ru.nsk.kstatemachine.state.* +import ru.nsk.kstatemachine.statemachine.processEventBlocking -class ActiveStatesTest : StringSpec({ +class GetActiveStatesVisitorTest : StringSpec({ CoroutineStarterType.entries.forEach { coroutineStarterType -> "activeStates()" { lateinit var state1: State diff --git a/tests/src/commonTest/kotlin/ru/nsk/kstatemachine/ExportToPlantUmlTest.kt b/tests/src/commonTest/kotlin/ru/nsk/kstatemachine/visitors/export/ExportPlantUmlVisitorTest.kt similarity index 96% rename from tests/src/commonTest/kotlin/ru/nsk/kstatemachine/ExportToPlantUmlTest.kt rename to tests/src/commonTest/kotlin/ru/nsk/kstatemachine/visitors/export/ExportPlantUmlVisitorTest.kt index 84c5acaf..93f904ad 100644 --- a/tests/src/commonTest/kotlin/ru/nsk/kstatemachine/ExportToPlantUmlTest.kt +++ b/tests/src/commonTest/kotlin/ru/nsk/kstatemachine/visitors/export/ExportPlantUmlVisitorTest.kt @@ -1,4 +1,4 @@ -package ru.nsk.kstatemachine +package ru.nsk.kstatemachine.visitors.export import io.kotest.core.spec.style.StringSpec import io.kotest.data.forAll @@ -7,9 +7,12 @@ import io.kotest.data.row import io.kotest.data.table import io.kotest.matchers.shouldBe import io.kotest.matchers.types.shouldNotBeInstanceOf -import ru.nsk.kstatemachine.HistoryType.DEEP -import ru.nsk.kstatemachine.visitors.exportToMermaid -import ru.nsk.kstatemachine.visitors.exportToPlantUml +import ru.nsk.kstatemachine.* +import ru.nsk.kstatemachine.metainfo.UmlMetaInfo +import ru.nsk.kstatemachine.state.* +import ru.nsk.kstatemachine.statemachine.StateMachine +import ru.nsk.kstatemachine.statemachine.createStateMachine +import ru.nsk.kstatemachine.transition.targetParallelStates private const val PLANTUML_NESTED_STATES_RESULT = """@startuml hide empty description @@ -260,7 +263,7 @@ private fun makeChoiceMachine(coroutineStarterType: CoroutineStarterType): State state("state22") } val shallowHistory = state2.historyState("shallow history") - val deepHistory = state2.historyState("deep history", historyType = DEEP) + val deepHistory = state2.historyState("deep history", historyType = HistoryType.DEEP) state("state3") { transition(targetState = shallowHistory) @@ -271,7 +274,7 @@ private fun makeChoiceMachine(coroutineStarterType: CoroutineStarterType): State } } -class ExportToPlantUmlTest : StringSpec({ +class ExportPlantUmlVisitorTest : StringSpec({ CoroutineStarterType.entries.forEach { coroutineStarterType -> table( headers("showEventLabels", "result"),