@@ -46,6 +46,26 @@ struct AsyncStateMachine_Tests {
4646 #expect( await receiver. count == 1 )
4747 }
4848
49+ @available ( macOS 15 . 0 , iOS 18 . 0 , watchOS 11 . 0 , tvOS 18 . 0 , visionOS 2 . 0 , * )
50+ @Test
51+ func start_NoContext( ) async {
52+ let lifecycle = AsyncStateMachine < StartableStateMachineState > ( initialState: . stopped)
53+
54+ actor Receiver {
55+ var count : Int = 0
56+ func inc( ) { count += 1 }
57+ init ( ) { }
58+ }
59+
60+ let receiver = Receiver ( )
61+
62+ await lifecycle. withTransition ( to: . started) {
63+ _ = await Task { await receiver. inc ( ) } . value
64+ }
65+ #expect( lifecycle. state == . started)
66+ #expect( await receiver. count == 1 )
67+ }
68+
4969 @available ( macOS 15 . 0 , iOS 18 . 0 , watchOS 11 . 0 , tvOS 18 . 0 , visionOS 2 . 0 , * )
5070 @Test
5171 func stop( ) async {
@@ -209,6 +229,30 @@ struct AsyncStateMachine_Tests {
209229 #expect( lifecycle. state == . stopped) // no change
210230 }
211231
232+ @available ( macOS 15 . 0 , iOS 18 . 0 , watchOS 11 . 0 , tvOS 18 . 0 , visionOS 2 . 0 , * )
233+ @Test
234+ func withState_NoContext( ) async {
235+ let lifecycle = AsyncStateMachine < StartableStateMachineState > ( initialState: . stopped)
236+
237+ await confirmation ( expectedCount: 0b1 ) { confirmation in
238+ await lifecycle. withState ( expecting: [ . stopped, . stoppedPermanently] ) {
239+ confirmation ( count: 0b1 )
240+ } wrongState: {
241+ confirmation ( count: 0b10 )
242+ }
243+ }
244+ #expect( lifecycle. state == . stopped)
245+
246+ await confirmation ( expectedCount: 0b10 ) { confirmation in
247+ await lifecycle. withState ( expecting: . started) {
248+ confirmation ( count: 0b1 )
249+ } wrongState: {
250+ confirmation ( count: 0b10 )
251+ }
252+ }
253+ #expect( lifecycle. state == . stopped) // no change
254+ }
255+
212256 @available ( macOS 15 . 0 , iOS 18 . 0 , watchOS 11 . 0 , tvOS 18 . 0 , visionOS 2 . 0 , * )
213257 @Test
214258 func dummyClass( ) async {
0 commit comments