-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtransition_test.go
62 lines (49 loc) · 1.13 KB
/
transition_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
package gostatechart_test
import (
"context"
"fmt"
"reflect"
"testing"
sc "github.com/enjoypi/gostatechart"
"github.com/stretchr/testify/require"
)
type evTest struct {
}
type st1 struct {
sc.SimpleState
}
func (s *st1) Begin(ctx context.Context, event sc.Event) sc.Event {
panic("implement me")
}
func (s *st1) GetTransitions() sc.Transitions {
panic("implement me")
}
type st2 struct {
sc.SimpleState
}
func (s *st2) Begin(ctx context.Context, event sc.Event) sc.Event {
panic("implement me")
}
func (s *st2) GetTransitions() sc.Transitions {
panic("implement me")
}
func TestTransitions(t *testing.T) {
trans := sc.NewTranstions()
require.NotNil(t, trans)
trans.RegisterTransition((*evTest)(nil), (*st1)(nil))
require.Equal(t,
reflect.TypeOf((*st1)(nil)),
trans[reflect.TypeOf((*evTest)(nil))],
)
trans.RegisterTransition((*evTest)(nil), (*st1)(nil))
require.Equal(t,
reflect.TypeOf((*st1)(nil)),
trans[reflect.TypeOf((*evTest)(nil))],
)
defer func() {
if e := recover(); e != nil {
require.Equal(t, fmt.Errorf("duplicate event evTest"), e)
}
}()
trans.RegisterTransition((*evTest)(nil), (*st2)(nil))
}