Skip to content

Commit e22776f

Browse files
authored
Adds .sequence(Step) to StepType (#387)
1 parent 97c3dab commit e22776f

File tree

2 files changed

+37
-5
lines changed

2 files changed

+37
-5
lines changed

Sources/ComposableArchitecture/TestSupport/TestStore.swift

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,7 @@
259259
store.scope(state: self.toLocalState, action: TestAction.send)
260260
)
261261

262-
for step in steps {
262+
func assert(step: Step) {
263263
var expectedState = toLocalState(snapshotState)
264264

265265
func expectedStateShouldMatch(actualState: LocalState) {
@@ -383,9 +383,14 @@
383383
} catch {
384384
_XCTFail("Threw error: \(error)", file: step.file, line: step.line)
385385
}
386+
387+
case let .sequence(subSteps):
388+
subSteps.forEach(assert(step:))
386389
}
387390
}
388391

392+
steps.forEach(assert(step:))
393+
389394
if !receivedActions.isEmpty {
390395
_XCTFail(
391396
"""
@@ -542,11 +547,36 @@
542547
Step(.do(work), file: file, line: line)
543548
}
544549

545-
fileprivate enum StepType {
550+
/// A step that captures a sub-sequence of steps.
551+
///
552+
/// - Parameter steps: An array of `Step`
553+
/// - Returns: A step that captures a sub-sequence of steps.
554+
public static func sequence(
555+
_ steps: [Step],
556+
file: StaticString = #file,
557+
line: UInt = #line
558+
) -> Step {
559+
Step(.sequence(steps), file: file, line: line)
560+
}
561+
562+
/// A step that captures a sub-sequence of steps.
563+
///
564+
/// - Parameter steps: A variadic list of `Step`
565+
/// - Returns: A step that captures a sub-sequence of steps.
566+
public static func sequence(
567+
_ steps: Step...,
568+
file: StaticString = #file,
569+
line: UInt = #line
570+
) -> Step {
571+
Step(.sequence(steps), file: file, line: line)
572+
}
573+
574+
fileprivate indirect enum StepType {
546575
case send(LocalAction, (inout LocalState) throws -> Void)
547576
case receive(Action, (inout LocalState) throws -> Void)
548577
case environment((inout Environment) throws -> Void)
549578
case `do`(() throws -> Void)
579+
case sequence([Step])
550580
}
551581
}
552582

Tests/ComposableArchitectureTests/TestStoreTests.swift

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,11 @@ class TestStoreTests: XCTestCase {
5454
.receive(.b2),
5555
.receive(.b3),
5656

57-
.receive(.c1),
58-
.receive(.c2),
59-
.receive(.c3),
57+
.sequence([
58+
.receive(.c1),
59+
.receive(.c2),
60+
.receive(.c3),
61+
]),
6062

6163
.send(.d)
6264
)

0 commit comments

Comments
 (0)