Skip to content

Commit 3bf6162

Browse files
stephencelismluisbrown
authored andcommitted
Use modify helper in Tic-Tac-Toe integration test (#687)
* Use `modify` helper * Clean up breakpoint warnings
1 parent 4c625a6 commit 3bf6162

File tree

2 files changed

+25
-33
lines changed

2 files changed

+25
-33
lines changed

Examples/TicTacToe/tic-tac-toe/Tests/AppCoreTests/AppCoreTests.swift

Lines changed: 10 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -19,18 +19,18 @@ class AppCoreTests: XCTestCase {
1919
)
2020

2121
store.send(.login(.emailChanged("[email protected]"))) {
22-
try (/AppState.login).update(&$0) {
22+
try (/AppState.login).modify(&$0) {
2323
$0.email = "[email protected]"
2424
}
2525
}
2626
store.send(.login(.passwordChanged("bl0bbl0b"))) {
27-
try (/AppState.login).update(&$0) {
27+
try (/AppState.login).modify(&$0) {
2828
$0.password = "bl0bbl0b"
2929
$0.isFormValid = true
3030
}
3131
}
3232
store.send(.login(.loginButtonTapped)) {
33-
try (/AppState.login).update(&$0) {
33+
try (/AppState.login).modify(&$0) {
3434
$0.isLoginRequestInFlight = true
3535
}
3636
}
@@ -40,7 +40,7 @@ class AppCoreTests: XCTestCase {
4040
$0 = .newGame(.init())
4141
}
4242
store.send(.newGame(.oPlayerNameChanged("Blob Sr."))) {
43-
try (/AppState.newGame).update(&$0) {
43+
try (/AppState.newGame).modify(&$0) {
4444
$0.oPlayerName = "Blob Sr."
4545
}
4646
}
@@ -67,41 +67,41 @@ class AppCoreTests: XCTestCase {
6767
)
6868

6969
store.send(.login(.emailChanged("[email protected]"))) {
70-
try (/AppState.login).update(&$0) {
70+
try (/AppState.login).modify(&$0) {
7171
$0.email = "[email protected]"
7272
}
7373
}
7474

7575
store.send(.login(.passwordChanged("bl0bbl0b"))) {
76-
try (/AppState.login).update(&$0) {
76+
try (/AppState.login).modify(&$0) {
7777
$0.password = "bl0bbl0b"
7878
$0.isFormValid = true
7979
}
8080
}
8181

8282
store.send(.login(.loginButtonTapped)) {
83-
try (/AppState.login).update(&$0) {
83+
try (/AppState.login).modify(&$0) {
8484
$0.isLoginRequestInFlight = true
8585
}
8686
}
8787
store.receive(
8888
.login(.loginResponse(.success(.init(token: "deadbeef", twoFactorRequired: true))))
8989
) {
90-
try (/AppState.login).update(&$0) {
90+
try (/AppState.login).modify(&$0) {
9191
$0.isLoginRequestInFlight = false
9292
$0.twoFactor = .init(token: "deadbeef")
9393
}
9494
}
9595

9696
store.send(.login(.twoFactor(.codeChanged("1234")))) {
97-
try (/AppState.login).update(&$0) {
97+
try (/AppState.login).modify(&$0) {
9898
$0.twoFactor?.code = "1234"
9999
$0.twoFactor?.isFormValid = true
100100
}
101101
}
102102

103103
store.send(.login(.twoFactor(.submitButtonTapped))) {
104-
try (/AppState.login).update(&$0) {
104+
try (/AppState.login).modify(&$0) {
105105
$0.twoFactor?.isTwoFactorRequestInFlight = true
106106
}
107107
}
@@ -114,11 +114,3 @@ class AppCoreTests: XCTestCase {
114114
}
115115
}
116116
}
117-
118-
extension CasePath {
119-
func update(_ root: inout Root, perform: (inout Value) throws -> Void) throws {
120-
var value = try XCTUnwrap(self.extract(from: root))
121-
try perform(&value)
122-
root = self.embed(value)
123-
}
124-
}

Sources/ComposableArchitecture/Reducer.swift

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -486,12 +486,12 @@ public struct Reducer<State, Action, Environment> {
486486
This ensures that case-specific reducers can handle their actions while their state \
487487
is available.
488488
489-
* An in-flight effect emitted this action when state was unavailable. While it may \
490-
be perfectly reasonable to ignore this action, you may want to cancel the associated \
489+
* An in-flight effect emitted this action when state was unavailable. While it may be \
490+
perfectly reasonable to ignore this action, you may want to cancel the associated \
491491
effect before state is set to another case, especially if it is a long-living effect.
492492
493493
* This action was sent to the store while state was another case. Make sure that \
494-
actions for this reducer can only be sent to a view store when state is non-"nil".
494+
actions for this reducer can only be sent to a view store when state is non-"nil". \
495495
In SwiftUI applications, use "SwitchStore".
496496
---
497497
"""
@@ -691,16 +691,16 @@ public struct Reducer<State, Action, Environment> {
691691
692692
* The optional reducer was combined with or run from another reducer that set \
693693
"\(State.self)" to "nil" before the optional reducer ran. Combine or run optional \
694-
reducers before reducers that can set their state to "nil". This ensures that \
695-
optional reducers can handle their actions while their state is still non-"nil".
694+
reducers before reducers that can set their state to "nil". This ensures that optional \
695+
reducers can handle their actions while their state is still non-"nil".
696696
697697
* An in-flight effect emitted this action while state was "nil". While it may be \
698698
perfectly reasonable to ignore this action, you may want to cancel the associated \
699699
effect before state is set to "nil", especially if it is a long-living effect.
700700
701-
* This action was sent to the store while state was "nil". Make sure that actions \
702-
for this reducer can only be sent to a view store when state is non-"nil". In \
703-
SwiftUI applications, use "IfLetStore".
701+
* This action was sent to the store while state was "nil". Make sure that actions for \
702+
this reducer can only be sent to a view store when state is non-"nil". In SwiftUI \
703+
applications, use "IfLetStore".
704704
---
705705
"""
706706
)
@@ -771,20 +771,20 @@ public struct Reducer<State, Action, Environment> {
771771
---
772772
Warning: Reducer.forEach@\(file):\(line)
773773
774-
"\(debugCaseOutput(localAction))" was received by a "forEach" reducer at id \(id) \
775-
when its state contained no element at this id. This is generally considered an \
776-
application logic error, and can happen for a few reasons:
774+
"\(debugCaseOutput(localAction))" was received by a "forEach" reducer at id \(id) when \
775+
its state contained no element at this id. This is generally considered an application \
776+
logic error, and can happen for a few reasons:
777777
778778
* This "forEach" reducer was combined with or run from another reducer that removed \
779779
the element at this id when it handled this action. To fix this make sure that this \
780780
"forEach" reducer is run before any other reducers that can move or remove elements \
781781
from state. This ensures that "forEach" reducers can handle their actions for the \
782782
element at the intended id.
783783
784-
* An in-flight effect emitted this action while state contained no element at this \
785-
id. It may be perfectly reasonable to ignore this action, but you also may want to \
786-
cancel the effect it originated from when removing an element from the identified \
787-
array, especially if it is a long-living effect.
784+
* An in-flight effect emitted this action while state contained no element at this id. \
785+
It may be perfectly reasonable to ignore this action, but you also may want to cancel \
786+
the effect it originated from when removing an element from the identified array, \
787+
especially if it is a long-living effect.
788788
789789
* This action was sent to the store while its state contained no element at this id. \
790790
To fix this make sure that actions for this reducer can only be sent to a view store \

0 commit comments

Comments
 (0)