From 51b3a21acad89d24fc988949e6ee5afbfea73b60 Mon Sep 17 00:00:00 2001 From: Matthew Rich Date: Thu, 16 May 2024 17:28:49 -0700 Subject: [PATCH] support wildcard source transition --- transition.go | 2 +- transition_test.go | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/transition.go b/transition.go index c5687ab..2c50ce6 100644 --- a/transition.go +++ b/transition.go @@ -25,7 +25,7 @@ func NewTransition(trigger string, source State, dest State) Transitioner { func (r *Transition) Run(m Modeler) error { currentState := m.InspectState() - if currentState == r.source { + if currentState == r.source || r.source == "*" { res := m.ChangeState(r.dest) if res == currentState { r.Notify(EXITSTATEEVENT, currentState, r.dest) diff --git a/transition_test.go b/transition_test.go index ce3b0d5..50da08c 100644 --- a/transition_test.go +++ b/transition_test.go @@ -38,6 +38,14 @@ func TestTransitionExecution(t *testing.T) { } } +func TestTransitionWildcard(t *testing.T) { + tr := NewTransition("open", "*", "opened") + assert.NotNil(t, tr) + m := setupModel("closed") + assert.Nil(t, tr.Run(m)) + assert.Equal(t, "opened", string(m.InspectState())) +} + func TestTransitionSubscribe(t *testing.T) { c := setupSubscriber() s := setupTransition()