Skip to content

Commit b3d9270

Browse files
authored
Correctly show (no state changes) in diff. (#132)
* Correct show (no state changes) in diff. * test for debug operator with no state changes
1 parent 5810032 commit b3d9270

File tree

3 files changed

+21
-12
lines changed

3 files changed

+21
-12
lines changed

Sources/ComposableArchitecture/Debugging/ReducerDebugging.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ extension Reducer {
7575
debugEnvironment.queue.async {
7676
let actionOutput = debugOutput(localAction).indent(by: 2)
7777
let stateOutput =
78-
debugDiff(previousState, nextState).map { "\($0)\n" } ?? " (No state changes)"
78+
debugDiff(previousState, nextState).map { "\($0)\n" } ?? " (No state changes)\n"
7979
debugEnvironment.printer(
8080
"""
8181
\(prefix.isEmpty ? "" : "\(prefix): ")received action:

Sources/ComposableArchitecture/Internal/Diff.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ func diff(_ first: String, _ second: String) -> String? {
7171
first.split(separator: "\n", omittingEmptySubsequences: false)[...],
7272
second.split(separator: "\n", omittingEmptySubsequences: false)[...]
7373
)
74-
guard !differences.isEmpty else { return nil }
74+
if differences.count == 1, case .both = differences[0].which { return nil }
7575
var string = differences.reduce(into: "") { string, diff in
7676
diff.elements.forEach { line in
7777
string += "\(diff.which.prefix) \(line)\n"

Tests/ComposableArchitectureTests/ReducerTests.swift

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -96,22 +96,24 @@ final class ReducerTests: XCTestCase {
9696
}
9797

9898
func testPrint() {
99-
struct Unit: Equatable {}
99+
enum Action: Equatable { case incr, noop }
100100
struct State: Equatable { var count = 0 }
101101

102102
var logs: [String] = []
103103

104-
let expectation = self.expectation(description: "printed")
105-
106-
let reducer = Reducer<State, Unit, Void> { state, _, _ in
107-
state.count += 1
108-
return .none
104+
let reducer = Reducer<State, Action, Void> { state, action, _ in
105+
switch action {
106+
case .incr:
107+
state.count += 1
108+
return .none
109+
case .noop:
110+
return .none
111+
}
109112
}
110113
.debug("[prefix]") { _ in
111114
DebugEnvironment(
112115
printer: {
113116
logs.append($0)
114-
expectation.fulfill()
115117
}
116118
)
117119
}
@@ -122,22 +124,29 @@ final class ReducerTests: XCTestCase {
122124
environment: ()
123125
)
124126
store.assert(
125-
.send(Unit()) { $0.count = 1 }
127+
.send(.incr) { $0.count = 1 },
128+
.send(.noop)
126129
)
127130

128-
self.wait(for: [expectation], timeout: 1)
131+
_ = XCTWaiter.wait(for: [self.expectation(description: "wait")], timeout: 0.1)
129132

130133
XCTAssertEqual(
131134
logs,
132135
[
133136
#"""
134137
[prefix]: received action:
135-
Unit()
138+
Action.incr
136139
  State(
137140
− count: 0
138141
+ count: 1
139142
  )
140143
144+
"""#,
145+
#"""
146+
[prefix]: received action:
147+
Action.noop
148+
(No state changes)
149+
141150
"""#
142151
]
143152
)

0 commit comments

Comments
 (0)