@@ -11,17 +11,17 @@ final class StateMachineTests: XCTestCase, StateMachineBuilder {
11
11
12
12
enum State : StateMachineHashable {
13
13
14
- case stateOne, stateTwo
14
+ case stateOne, stateTwo, stateThree
15
15
}
16
16
17
17
enum Event : StateMachineHashable {
18
18
19
- case eventOne, eventTwo
19
+ case eventOne, eventTwo, eventThree
20
20
}
21
21
22
- enum SideEffect {
22
+ enum SideEffect : Equatable {
23
23
24
- case commandOne, commandTwo, commandThree
24
+ case commandOne, commandTwo, commandThree, commandFour ( Int )
25
25
}
26
26
27
27
typealias TestStateMachine = StateMachine < State , Event , SideEffect >
@@ -33,7 +33,7 @@ final class StateMachineTests: XCTestCase, StateMachineBuilder {
33
33
initialState ( _state)
34
34
state ( . stateOne) {
35
35
on ( . eventOne) {
36
- dontTransition ( emit: . commandOne)
36
+ dontTransition ( emit: . commandOne, . commandTwo )
37
37
}
38
38
on ( . eventTwo) {
39
39
transition ( to: . stateTwo, emit: . commandTwo)
@@ -43,7 +43,11 @@ final class StateMachineTests: XCTestCase, StateMachineBuilder {
43
43
on ( . eventTwo) {
44
44
dontTransition ( emit: . commandThree)
45
45
}
46
+ on ( . eventThree) { _, event in
47
+ transition ( to: . stateThree, emit: . commandFour( try event. string ( ) ) )
48
+ }
46
49
}
50
+ state ( . stateThree)
47
51
}
48
52
}
49
53
@@ -66,7 +70,7 @@ final class StateMachineTests: XCTestCase, StateMachineBuilder {
66
70
expect ( transition) . to ( equal ( ValidTransition ( fromState: . stateOne,
67
71
event: . eventOne,
68
72
toState: . stateOne,
69
- sideEffects: [ . commandOne] ) ) )
73
+ sideEffects: [ . commandOne, . commandTwo ] ) ) )
70
74
}
71
75
72
76
func testTransition( ) throws {
@@ -131,7 +135,7 @@ final class StateMachineTests: XCTestCase, StateMachineBuilder {
131
135
. success( ValidTransition ( fromState: . stateOne,
132
136
event: . eventOne,
133
137
toState: . stateOne,
134
- sideEffects: [ . commandOne] ) ) ,
138
+ sideEffects: [ . commandOne, . commandTwo ] ) ) ,
135
139
. success( ValidTransition ( fromState: . stateOne,
136
140
event: . eventTwo,
137
141
toState: . stateTwo,
@@ -191,6 +195,14 @@ final class StateMachineTests: XCTestCase, StateMachineBuilder {
191
195
// Then
192
196
expect ( error) . to ( equal ( . recursionDetected) )
193
197
}
198
+
199
+ func testGettingNonExistingValue( ) throws {
200
+ // Given
201
+ let stateMachine : TestStateMachine = givenState ( is: . stateTwo)
202
+
203
+ // Then
204
+ XCTAssertThrowsError ( try stateMachine. transition ( . eventThree) )
205
+ }
194
206
}
195
207
196
208
final class Logger {
0 commit comments