Skip to content

Commit

Permalink
Add test to reproduce the github issue
Browse files Browse the repository at this point in the history
#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.
  • Loading branch information
nsk90 committed Oct 23, 2024
1 parent ce20cce commit ead5e31
Showing 1 changed file with 20 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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<Int>
}

class ChoiceStateTest : StringSpec({
Expand Down Expand Up @@ -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<Int>("dataState3") {
initialChoiceState { state3 }
}
initialState("state1") {
dataTransition<IntEvent, Int> { targetState = state2 }
}
}
machine.processEvent(IntEvent(42))
machine.activeStates().shouldContainExactly(state3)
}
}
})

0 comments on commit ead5e31

Please sign in to comment.