Skip to content

Commit

Permalink
Run swift-format
Browse files Browse the repository at this point in the history
  • Loading branch information
p4checo committed Jan 12, 2023
1 parent a393f06 commit 1943aab
Show file tree
Hide file tree
Showing 8 changed files with 1,226 additions and 1,226 deletions.
746 changes: 373 additions & 373 deletions Sources/ComposableArchitecture/Effects/ConcurrencySupport.swift

Large diffs are not rendered by default.

50 changes: 25 additions & 25 deletions Sources/ComposableArchitecture/TestStore.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1167,35 +1167,35 @@ extension TestStore where ScopedState: Equatable, Action: Equatable {
matching: { expectedAction == $0 },
failureMessage: "Expected to receive an action \(expectedAction), but didn't get one.",
onReceive: { receivedAction in
if expectedAction != receivedAction {
let difference = TaskResultDebugging.$emitRuntimeWarnings.withValue(false) {
diff(expectedAction, receivedAction, format: .proportional)
.map { "\($0.indent(by: 4))\n\n(Expected: −, Received: +)" }
?? """
Expected:
\(String(describing: expectedAction).indent(by: 2))
Received:
\(String(describing: receivedAction).indent(by: 2))
"""
}
if expectedAction != receivedAction {
let difference = TaskResultDebugging.$emitRuntimeWarnings.withValue(false) {
diff(expectedAction, receivedAction, format: .proportional)
.map { "\($0.indent(by: 4))\n\n(Expected: −, Received: +)" }
?? """
Expected:
\(String(describing: expectedAction).indent(by: 2))
Received:
\(String(describing: receivedAction).indent(by: 2))
"""
}

XCTFailHelper(
"""
Received unexpected action: …
"""
Received unexpected action: …
\(difference)
""",
\(difference)
""",
file: file,
line: line
)
}
)
}
},
updateStateToExpectedResult,
file: file,
line: line
)
}
file: file,
line: line
)
}

/// Asserts a matching action was received from an effect and asserts how the state changes.
///
Expand Down Expand Up @@ -1243,7 +1243,7 @@ extension TestStore where ScopedState: Equatable, Action: Equatable {
file: file,
line: line
)
}
}

/// Asserts an action was received matching a case path and asserts how the state changes.
///
Expand Down Expand Up @@ -1553,7 +1553,7 @@ extension TestStore where ScopedState: Equatable, Action: Equatable {
_ = {
self.receive(casePath, assert: updateStateToExpectedResult, file: file, line: line)
}()
await Task.megaYield()
await Task.megaYield()
}
#endif

Expand Down Expand Up @@ -1811,7 +1811,7 @@ extension TestStore {
)
self.reducer.state = self.reducer.receivedActions.last!.state
self.reducer.receivedActions = []
}
}

/// Cancels any currently in-flight effects.
///
Expand Down
186 changes: 93 additions & 93 deletions Tests/ComposableArchitectureTests/CompatibilityTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,122 +4,122 @@ import XCTest

// `@MainActor` introduces issues gathering tests on Linux
#if !os(Linux)
@MainActor
final class CompatibilityTests: XCTestCase {
// Actions can be re-entrantly sent into the store if an action is sent that holds an object
// which sends an action on deinit. In order to prevent a simultaneous access exception for this
// case we need to use `withExtendedLifetime` on the buffered actions when clearing them out.
func testCaseStudy_ActionReentranceFromClearedBufferCausingDeinitAction() {
let cancelID = UUID()

struct State: Equatable {}
enum Action: Equatable {
case start
case kickOffAction
case actionSender(OnDeinit)
case stop

var description: String {
switch self {
case .start:
return "start"
case .kickOffAction:
return "kickOffAction"
case .actionSender:
return "actionSender"
case .stop:
return "stop"
@MainActor
final class CompatibilityTests: XCTestCase {
// Actions can be re-entrantly sent into the store if an action is sent that holds an object
// which sends an action on deinit. In order to prevent a simultaneous access exception for this
// case we need to use `withExtendedLifetime` on the buffered actions when clearing them out.
func testCaseStudy_ActionReentranceFromClearedBufferCausingDeinitAction() {
let cancelID = UUID()

struct State: Equatable {}
enum Action: Equatable {
case start
case kickOffAction
case actionSender(OnDeinit)
case stop

var description: String {
switch self {
case .start:
return "start"
case .kickOffAction:
return "kickOffAction"
case .actionSender:
return "actionSender"
case .stop:
return "stop"
}
}
}
}
let (signal, observer) = Signal<Action, Never>.pipe()

var handledActions: [String] = []
var handledActions: [String] = []

let reducer = AnyReducer<State, Action, Void> { state, action, env in
handledActions.append(action.description)
let reducer = AnyReducer<State, Action, Void> { state, action, env in
handledActions.append(action.description)

switch action {
case .start:
switch action {
case .start:
return signal.producer
.eraseToEffect()
.cancellable(id: cancelID)
.eraseToEffect()
.cancellable(id: cancelID)

case .kickOffAction:
case .kickOffAction:
return EffectTask(value: .actionSender(OnDeinit { observer.send(value: .stop) }))

case .actionSender:
return .none
case .actionSender:
return .none

case .stop:
return .cancel(id: cancelID)
case .stop:
return .cancel(id: cancelID)
}
}
}

let store = Store(
initialState: .init(),
reducer: reducer,
environment: ()
)

let viewStore = ViewStore(store)

viewStore.send(.start)
viewStore.send(.kickOffAction)

XCTAssertEqual(
handledActions,
[
"start",
"kickOffAction",
"actionSender",
"stop",
]
)
}
let store = Store(
initialState: .init(),
reducer: reducer,
environment: ()
)

let viewStore = ViewStore(store)

viewStore.send(.start)
viewStore.send(.kickOffAction)

XCTAssertEqual(
handledActions,
[
"start",
"kickOffAction",
"actionSender",
"stop",
]
)
}

// Actions can be re-entrantly sent into the store while observing changes to the store's state.
// In such cases we need to take special care that those re-entrant actions are handled _after_
// the original action.
//
// In particular, this means that in the implementation of `Store.send` we need to flip
// `isSending` to false _after_ the store's state mutation is made so that re-entrant actions
// are buffered rather than immediately handled.
func testCaseStudy_ActionReentranceFromStateObservation() {
let store = Store<Int, Int>(
initialState: 0,
reducer: .init { state, action, _ in
state = action
return .none
},
environment: ()
)

let viewStore = ViewStore(store)
// Actions can be re-entrantly sent into the store while observing changes to the store's state.
// In such cases we need to take special care that those re-entrant actions are handled _after_
// the original action.
//
// In particular, this means that in the implementation of `Store.send` we need to flip
// `isSending` to false _after_ the store's state mutation is made so that re-entrant actions
// are buffered rather than immediately handled.
func testCaseStudy_ActionReentranceFromStateObservation() {
let store = Store<Int, Int>(
initialState: 0,
reducer: .init { state, action, _ in
state = action
return .none
},
environment: ()
)

let viewStore = ViewStore(store)

viewStore.produced.producer
.startWithValues { value in
if value == 1 {
viewStore.send(0)
if value == 1 {
viewStore.send(0)
}
}
}

var stateChanges: [Int] = []
var stateChanges: [Int] = []
viewStore.produced.producer
.startWithValues { stateChanges.append($0) }

XCTAssertEqual(stateChanges, [0])
viewStore.send(1)
XCTAssertEqual(stateChanges, [0, 1, 0])
XCTAssertEqual(stateChanges, [0])
viewStore.send(1)
XCTAssertEqual(stateChanges, [0, 1, 0])
}
}
}

private final class OnDeinit: Equatable {
private let onDeinit: () -> Void
init(onDeinit: @escaping () -> Void) {
self.onDeinit = onDeinit
private final class OnDeinit: Equatable {
private let onDeinit: () -> Void
init(onDeinit: @escaping () -> Void) {
self.onDeinit = onDeinit
}
deinit { self.onDeinit() }
static func == (lhs: OnDeinit, rhs: OnDeinit) -> Bool { true }
}
deinit { self.onDeinit() }
static func == (lhs: OnDeinit, rhs: OnDeinit) -> Bool { true }
}
#endif
Loading

0 comments on commit 1943aab

Please sign in to comment.