diff --git a/.swiftformat b/.swiftformat index 703dc6c..e653653 100644 --- a/.swiftformat +++ b/.swiftformat @@ -5,7 +5,8 @@ --disable redundantType --indent 4 ---allman true +--allman true +--closingparen same-line --elseposition next-line --indentcase true --patternlet inline diff --git a/Examples/KryptonExample/KryptonExample/AlarmService.swift b/Examples/KryptonExample/KryptonExample/AlarmService.swift index 25364c0..b7515d8 100644 --- a/Examples/KryptonExample/KryptonExample/AlarmService.swift +++ b/Examples/KryptonExample/KryptonExample/AlarmService.swift @@ -150,13 +150,11 @@ extension AlarmService will_enter: { context, _ in print("[Will Enter] \(context)") }, did_enter: { context, _ in print("[Did Enter] \(context)") }, will_exit: { context, _ in print("[Will Exit] \(context)") }, - did_exit: { context, _ in print("[Did Exit] \(context)") } - ) + did_exit: { context, _ in print("[Did Exit] \(context)") }) let event_transitions = Event.TransitionContext( will_fire: { context, _ in print("[Will Fire] \(context)") }, - did_fire: { context, _ in print("[Did Fire] \(context)") } - ) + did_fire: { context, _ in print("[Did Fire] \(context)") }) let state_armed = try State(name: "Armed", transition_context: state_transitions) let state_disarmed = try State(name: "Disarmed", transition_context: state_transitions) @@ -171,7 +169,6 @@ extension AlarmService return ( states: [state_armed, state_disarmed, state_alarm], events: [event_arm, event_disarm, event_reset, event_breach, event_panic], - initial: state_disarmed - ) + initial: state_disarmed) } } diff --git a/Package.swift b/Package.swift index 348e04e..cdbf1c4 100644 --- a/Package.swift +++ b/Package.swift @@ -17,6 +17,5 @@ let package = Package( dependencies: [], targets: [ .target(name: "Krypton", dependencies: []), - .testTarget(name: "KryptonTests", - dependencies: ["Krypton"]) + .testTarget(name: "KryptonTests", dependencies: ["Krypton"]) ]) diff --git a/Sources/Krypton/Builders/EventBuilder.swift b/Sources/Krypton/Builders/EventBuilder.swift index da9adfe..d96a646 100644 --- a/Sources/Krypton/Builders/EventBuilder.swift +++ b/Sources/Krypton/Builders/EventBuilder.swift @@ -81,8 +81,6 @@ public final class EventBuilder transition_context: StateMachine.Event.TransitionContext( should_fire: context_action_should_fire, will_fire: context_action_will_fire, - did_fire: context_action_did_fire - ) - ) + did_fire: context_action_did_fire)) } } diff --git a/Sources/Krypton/Builders/StateBuilder.swift b/Sources/Krypton/Builders/StateBuilder.swift index b794df2..e2cf7f3 100644 --- a/Sources/Krypton/Builders/StateBuilder.swift +++ b/Sources/Krypton/Builders/StateBuilder.swift @@ -79,8 +79,6 @@ public final class StateBuilder will_enter: context_action_will_enter, did_enter: context_action_did_enter, will_exit: context_action_will_exit, - did_exit: context_action_did_exit - ) - ) + did_exit: context_action_did_exit)) } } diff --git a/Sources/Krypton/Event.swift b/Sources/Krypton/Event.swift index e6ca639..9fc6042 100644 --- a/Sources/Krypton/Event.swift +++ b/Sources/Krypton/Event.swift @@ -22,8 +22,7 @@ public extension StateMachine public init( should_fire: TransitionTriggerValidation? = nil, will_fire: TransitionContextAction? = nil, - did_fire: TransitionContextAction? = nil - ) + did_fire: TransitionContextAction? = nil) { self.should_fire = should_fire self.will_fire = will_fire @@ -41,8 +40,7 @@ public extension StateMachine name: String, sources: Set, destination: State, - transition_context: TransitionContext = TransitionContext() - ) throws + transition_context: TransitionContext = TransitionContext()) throws { guard !name.isEmpty else diff --git a/Sources/Krypton/State.swift b/Sources/Krypton/State.swift index 926e1a7..4893595 100644 --- a/Sources/Krypton/State.swift +++ b/Sources/Krypton/State.swift @@ -22,8 +22,7 @@ public extension StateMachine will_enter: TransitionContextAction? = nil, did_enter: TransitionContextAction? = nil, will_exit: TransitionContextAction? = nil, - did_exit: TransitionContextAction? = nil - ) + did_exit: TransitionContextAction? = nil) { self.will_enter = will_enter self.did_enter = did_enter @@ -32,8 +31,9 @@ public extension StateMachine } } - let name: String - let user_info: Payload + public let name: String + public let user_info: Payload + let transition_context: Context? public init(name: String, user_info: Payload = [:], transition_context: Context? = nil) throws diff --git a/Tests/KryptonTests/KryptonEventTests.swift b/Tests/KryptonTests/KryptonEventTests.swift index b034b58..cbdbde0 100644 --- a/Tests/KryptonTests/KryptonEventTests.swift +++ b/Tests/KryptonTests/KryptonEventTests.swift @@ -45,8 +45,7 @@ class KryptonEventTests: XCTestCase XCTAssertTrue( actualValue == expectedValue, - "The description, `\(actualValue)`, does not match what was expected, `\(expectedValue)`" - ) + "The description, `\(actualValue)`, does not match what was expected, `\(expectedValue)`") } func testAnEventDescriptionWithMultipleSourceState() throws @@ -60,8 +59,7 @@ class KryptonEventTests: XCTestCase XCTAssertTrue( actualValue == expectedValue, - "The description, `\(actualValue)`, does not match what was expected, `\(expectedValue)`" - ) + "The description, `\(actualValue)`, does not match what was expected, `\(expectedValue)`") } func testEventThatIsDeclined() throws @@ -72,14 +70,12 @@ class KryptonEventTests: XCTestCase let event_transition = StateMachine.Event.TransitionContext( should_fire: disallow_event, will_fire: nil, - did_fire: nil - ) + did_fire: nil) let eventA = try StateMachine.Event( name: "Event-A-to-B", sources: [stateA], destination: stateB, - transition_context: event_transition - ) + transition_context: event_transition) let system = try StateMachine(initial_state: stateA) system.add(states: [stateA, stateB]) @@ -88,8 +84,7 @@ class KryptonEventTests: XCTestCase XCTAssertThrowsError( try system.fire(event: eventA), - "We expected the `declined` error; but no errors were thrown." - ) + "We expected the `declined` error; but no errors were thrown.") } func testEventThatIsExplicitlyAllowedToBeTriggered() throws @@ -100,14 +95,12 @@ class KryptonEventTests: XCTestCase let event_transition = StateMachine.Event.TransitionContext( should_fire: allow_event, will_fire: nil, - did_fire: nil - ) + did_fire: nil) let eventA = try StateMachine.Event( name: "Event-A-to-B", sources: [stateA], destination: stateB, - transition_context: event_transition - ) + transition_context: event_transition) let system = try StateMachine(initial_state: stateA) system.add(states: [stateA, stateB]) @@ -116,7 +109,6 @@ class KryptonEventTests: XCTestCase XCTAssertNoThrow( try system.fire(event: eventA), - "We expected the state machine to allow the event, but it was declined." - ) + "We expected the state machine to allow the event, but it was declined.") } } diff --git a/Tests/KryptonTests/KryptonStateTests.swift b/Tests/KryptonTests/KryptonStateTests.swift index 3c38fae..8c7b9fd 100644 --- a/Tests/KryptonTests/KryptonStateTests.swift +++ b/Tests/KryptonTests/KryptonStateTests.swift @@ -14,8 +14,7 @@ final class KryptonStateTests: XCTestCase { XCTAssertNoThrow( try StateMachine.State(name: "State-A"), - "We expected an state to be created; but it wasn't." - ) + "We expected an state to be created; but it wasn't.") } func testFailureToCreateAState() throws diff --git a/Tests/KryptonTests/KryptonTests.swift b/Tests/KryptonTests/KryptonTests.swift index 9028d5a..7863139 100644 --- a/Tests/KryptonTests/KryptonTests.swift +++ b/Tests/KryptonTests/KryptonTests.swift @@ -223,8 +223,7 @@ final class KryptonTests: XCTestCase XCTAssertTrue( value, - "We expected the state machine to return a `notActivated` error, but did not received any error." - ) + "We expected the state machine to return a `notActivated` error, but did not received any error.") } func testStateMachineInCorrectState() throws @@ -243,8 +242,7 @@ final class KryptonTests: XCTestCase XCTAssertTrue( system.isIn(state: stateB), - "We expected the state machine to be in state `\(stateB.name)`, but it is in `\(system.current_state.name)`." - ) + "We expected the state machine to be in state `\(stateB.name)`, but it is in `\(system.current_state.name)`.") } func testStateMachineCannotFireEventWhenNotActivated() throws @@ -259,8 +257,7 @@ final class KryptonTests: XCTestCase XCTAssertThrowsError( try system.fire(event: eventA), - "We expected the `not_activated` error; but no errors were thrown." - ) + "We expected the `not_activated` error; but no errors were thrown.") } func testTransitionIsNotPermitted() throws @@ -278,7 +275,6 @@ final class KryptonTests: XCTestCase XCTAssertThrowsError( try system.fire(event: eventA), - "We expected the `cannot_fire` error; but no errors were thrown." - ) + "We expected the `cannot_fire` error; but no errors were thrown.") } }