Skip to content

Commit 0023aeb

Browse files
committed
Make work on Swift 5.3
1 parent d165d6b commit 0023aeb

File tree

1 file changed

+73
-6
lines changed

1 file changed

+73
-6
lines changed

Sources/TestingExtensions/UseCaseTests.swift

Lines changed: 73 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,10 @@ import Foundation
1313
@testable import SwiftRex
1414
import XCTest
1515

16+
#if swift(>=5.4)
1617
@resultBuilder public struct StepBuilder<Action, State> {
17-
public static func buildBlock(_ steps: Step<Action, State>...) -> [Step<Action, State>] {
18-
steps
18+
public static func buildBlock(_ steps: [Step<Action, State>]...) -> [Step<Action, State>] {
19+
steps.flatMap { $0 }
1920
}
2021

2122
public static func buildEither(first component: [Step<Action, State>]) -> [Step<Action, State>] {
@@ -38,10 +39,15 @@ import XCTest
3839
components.flatMap { $0 }
3940
}
4041

41-
public static func buildExpression<S: StepProtocol>(_ expression: S) -> Step<Action, State> where S.ActionType == Action, S.StateType == State {
42-
expression.asStep
42+
public static func buildExpression<S: StepProtocol>(_ expression: S) -> [Step<Action, State>] where S.ActionType == Action, S.StateType == State {
43+
[expression.asStep]
44+
}
45+
46+
public static func buildExpression(_ expression: [Step<Action, State>]...) -> [Step<Action, State>] {
47+
expression.flatMap { $0 }
4348
}
4449
}
50+
#endif
4551

4652
public protocol StepProtocol {
4753
associatedtype ActionType
@@ -155,6 +161,7 @@ public enum Step<ActionType, StateType>: StepProtocol {
155161
}
156162

157163
extension XCTestCase {
164+
#if swift(>=5.4)
158165
public func assert<M: Middleware>(
159166
initialValue: M.StateType,
160167
reducer: Reducer<M.InputActionType, M.StateType>,
@@ -167,7 +174,7 @@ extension XCTestCase {
167174
initialValue: initialValue,
168175
reducer: reducer,
169176
middleware: middleware,
170-
steps: steps,
177+
stepsArray: steps(),
171178
stateEquating: ==,
172179
file: file,
173180
line: line
@@ -182,6 +189,66 @@ extension XCTestCase {
182189
stateEquating: (M.StateType, M.StateType) -> Bool,
183190
file: StaticString = #file,
184191
line: UInt = #line
192+
) where M.InputActionType == M.OutputActionType {
193+
assert(
194+
initialValue: initialValue,
195+
reducer: reducer,
196+
middleware: middleware,
197+
stepsArray: steps(),
198+
stateEquating: stateEquating,
199+
file: file,
200+
line: line
201+
)
202+
}
203+
#endif
204+
205+
public func assert<M: Middleware>(
206+
initialValue: M.StateType,
207+
reducer: Reducer<M.InputActionType, M.StateType>,
208+
middleware: M,
209+
steps: Step<M.InputActionType, M.StateType>...,
210+
file: StaticString = #file,
211+
line: UInt = #line
212+
) where M.InputActionType == M.OutputActionType, M.StateType: Equatable {
213+
assert(
214+
initialValue: initialValue,
215+
reducer: reducer,
216+
middleware: middleware,
217+
stepsArray: steps,
218+
stateEquating: ==,
219+
file: file,
220+
line: line
221+
)
222+
}
223+
224+
public func assert<M: Middleware>(
225+
initialValue: M.StateType,
226+
reducer: Reducer<M.InputActionType, M.StateType>,
227+
middleware: M,
228+
steps: Step<M.InputActionType, M.StateType>...,
229+
stateEquating: (M.StateType, M.StateType) -> Bool,
230+
file: StaticString = #file,
231+
line: UInt = #line
232+
) where M.InputActionType == M.OutputActionType {
233+
assert(
234+
initialValue: initialValue,
235+
reducer: reducer,
236+
middleware: middleware,
237+
stepsArray: steps,
238+
stateEquating: stateEquating,
239+
file: file,
240+
line: line
241+
)
242+
}
243+
244+
private func assert<M: Middleware>(
245+
initialValue: M.StateType,
246+
reducer: Reducer<M.InputActionType, M.StateType>,
247+
middleware: M,
248+
stepsArray: [Step<M.InputActionType, M.StateType>],
249+
stateEquating: (M.StateType, M.StateType) -> Bool,
250+
file: StaticString,
251+
line: UInt
185252
) where M.InputActionType == M.OutputActionType {
186253
var state = initialValue
187254
var middlewareResponses: [M.OutputActionType] = []
@@ -193,7 +260,7 @@ extension XCTestCase {
193260
}
194261
middleware.receiveContext(getState: { state }, output: anyActionHandler)
195262

196-
steps().forEach { outerStep in
263+
stepsArray.forEach { outerStep in
197264
var expected = state
198265

199266
switch outerStep {

0 commit comments

Comments
 (0)