From ead5e310ac67a41d205ff94a4d58b7e715e3ae38 Mon Sep 17 00:00:00 2001 From: Mikhail Fedotov Date: Wed, 23 Oct 2024 22:26:08 +0300 Subject: [PATCH] Add test to reproduce the github issue https://github.com/KStateMachine/kstatemachine/issues/101 There should be no exception with initalChoiseState inside data state. But data field cannot be accessed there as the state is not activated during choise calculation. --- .../kstatemachine/state/ChoiceStateTest.kt | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/tests/src/commonTest/kotlin/ru/nsk/kstatemachine/state/ChoiceStateTest.kt b/tests/src/commonTest/kotlin/ru/nsk/kstatemachine/state/ChoiceStateTest.kt index 2471f47..5840971 100644 --- a/tests/src/commonTest/kotlin/ru/nsk/kstatemachine/state/ChoiceStateTest.kt +++ b/tests/src/commonTest/kotlin/ru/nsk/kstatemachine/state/ChoiceStateTest.kt @@ -13,6 +13,8 @@ import io.kotest.matchers.shouldBe import io.mockk.verifySequence import ru.nsk.kstatemachine.* import ru.nsk.kstatemachine.event.DataEvent +import ru.nsk.kstatemachine.event.defaultDataExtractor +import ru.nsk.kstatemachine.state.ChoiceStateTestData.IntEvent import ru.nsk.kstatemachine.state.ChoiceStateTestData.State1 import ru.nsk.kstatemachine.state.ChoiceStateTestData.State2 import ru.nsk.kstatemachine.statemachine.StateMachine @@ -22,6 +24,8 @@ import ru.nsk.kstatemachine.statemachine.processEventBlocking private object ChoiceStateTestData { object State1 : DefaultState() object State2 : DefaultState() + + class IntEvent(override val data: Int) : DataEvent } class ChoiceStateTest : StringSpec({ @@ -155,5 +159,21 @@ class ChoiceStateTest : StringSpec({ callbacks.onStateEntry(intState2) } } + + + "Try reproduce https://github.com/KStateMachine/kstatemachine/issues/101" { + lateinit var state3: State + val machine = createTestStateMachine(coroutineStarterType) { + state3 = state("state3") + val state2 = dataState("dataState3") { + initialChoiceState { state3 } + } + initialState("state1") { + dataTransition { targetState = state2 } + } + } + machine.processEvent(IntEvent(42)) + machine.activeStates().shouldContainExactly(state3) + } } }) \ No newline at end of file