Skip to content

Commit 414b359

Browse files
committed
Changed TestableSubscriber recorded property names
1 parent 3ede883 commit 414b359

20 files changed

+169
-89
lines changed

Assets/EntwineTest/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ func testMap() {
182182
// uses the method described above (schedules a subscription at 200, to be cancelled at 900)
183183
let results = testScheduler.start { subjectUnderTest }
184184

185-
XCTAssertEqual(results.sequence, [
185+
XCTAssertEqual(results.recordedOutput, [
186186
(200, .subscription), // subscribed at 200
187187
(300, .input("A")), // received uppercased input @ 100 + subscription time
188188
(400, .input("B")), // received uppercased input @ 200 + subscription time

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ func testMap() {
8282
// schedules a subscription at 200, to be cancelled at 900
8383
let results = testScheduler.start { subjectUnderTest }
8484

85-
XCTAssertEqual(results.sequence, [
85+
XCTAssertEqual(results.recordedOutput, [
8686
(200, .subscription), // subscribed at 200
8787
(300, .input("A")), // received uppercased input @ 100 + subscription time
8888
(400, .input("B")), // received uppercased input @ 200 + subscription time

Sources/Entwine/Deprecations.swift

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,26 @@
11
//
2-
// File.swift
3-
//
2+
// Entwine
3+
// https://github.com/tcldr/Entwine
44
//
5-
// Created by Tristan Celder on 01/07/2019.
5+
// Copyright © 2019 Tristan Celder. All rights reserved.
66
//
7+
// Permission is hereby granted, free of charge, to any person obtaining a copy
8+
// of this software and associated documentation files (the "Software"), to deal
9+
// in the Software without restriction, including without limitation the rights
10+
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11+
// copies of the Software, and to permit persons to whom the Software is
12+
// furnished to do so, subject to the following conditions:
13+
//
14+
// The above copyright notice and this permission notice shall be included in
15+
// all copies or substantial portions of the Software.
16+
//
17+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18+
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19+
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20+
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21+
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22+
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23+
// THE SOFTWARE.
724

825
@available(*, deprecated, renamed: "CancellableBag")
926
public typealias CancellationBag = CancellableBag

Sources/Entwine/Operators/Dematerialize.swift

Lines changed: 23 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -24,21 +24,10 @@
2424

2525
import Combine
2626

27-
/// Represents an error for a dematerialized sequence
28-
///
29-
/// Consumers of publishers with a `Failure` of this type can opt-in to force unwrapping
30-
/// the error using the `assertNoDematerializationFailure()` operator
31-
public enum DematerializationError<SourceError: Error>: Error {
32-
/// Sequencing error during dematerialization. e.g. an `.input` arriving after a `.completion`
33-
case outOfSequence
34-
/// A wrapped error of the represented material sequence
35-
case sourceError(SourceError)
36-
}
37-
38-
extension DematerializationError: Equatable where SourceError: Equatable {}
39-
4027
extension Publishers {
4128

29+
// MARK: - Publisher
30+
4231
/// Converts a materialized publisher of `Signal`s into the represented sequence. Fails on a malformed
4332
/// source sequence.
4433
///
@@ -70,6 +59,8 @@ extension Publishers {
7059
}
7160
}
7261

62+
// MARK: - Subscription
63+
7364
fileprivate class DematerializeSubscription<Upstream: Publisher, Downstream: Subscriber>: Subscription
7465
where
7566
Upstream.Output: SignalConvertible,
@@ -102,6 +93,8 @@ extension Publishers {
10293
}
10394
}
10495

96+
// MARK: - Sink
97+
10598
fileprivate class DematerializeSink<Upstream: Publisher, Downstream: Subscriber>: Subscriber
10699
where
107100
Upstream.Output: SignalConvertible,
@@ -194,6 +187,8 @@ extension Publishers {
194187
}
195188
}
196189

190+
// MARK: - Operators
191+
197192
extension Publisher where Output: SignalConvertible, Failure == Never {
198193

199194
private func dematerializedValuesPublisherSequence() -> Publishers.Dematerialize<Self> {
@@ -247,6 +242,21 @@ extension Publisher where Failure: DematerializationErrorConvertible {
247242
}
248243
}
249244

245+
// MARK: - Errors
246+
247+
/// Represents an error for a dematerialized sequence
248+
///
249+
/// Consumers of publishers with a `Failure` of this type can opt-in to force unwrapping
250+
/// the error using the `assertNoDematerializationFailure()` operator
251+
public enum DematerializationError<SourceError: Error>: Error {
252+
/// Sequencing error during dematerialization. e.g. an `.input` arriving after a `.completion`
253+
case outOfSequence
254+
/// A wrapped error of the represented material sequence
255+
case sourceError(SourceError)
256+
}
257+
258+
extension DematerializationError: Equatable where SourceError: Equatable {}
259+
250260
/// A type which can be converted into a `DematerializationError`
251261
public protocol DematerializationErrorConvertible {
252262

Sources/Entwine/Operators/Materialize.swift

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ import Combine
2626

2727
extension Publishers {
2828

29+
// MARK: - Publisher
30+
2931
/// Wraps all the elements as well as the subscription and completion events of an upstream publisher
3032
/// into a stream of `Signal` elements
3133
public struct Materialize<Upstream: Publisher>: Publisher {
@@ -44,6 +46,8 @@ extension Publishers {
4446
}
4547
}
4648

49+
// MARK: - Subscription
50+
4751
// Owned by the downstream subscriber
4852
fileprivate class MaterializeSubscription<Upstream: Publisher, Downstream: Subscriber>: Subscription
4953
where Never == Downstream.Failure, Signal<Upstream.Output, Upstream.Failure> == Downstream.Input
@@ -72,6 +76,8 @@ extension Publishers {
7276
}
7377
}
7478

79+
// MARK: - Sink
80+
7581
fileprivate class MaterializeSink<Upstream: Publisher, Downstream: Subscriber>: Subscriber
7682
where Never == Downstream.Failure, Signal<Upstream.Output, Upstream.Failure> == Downstream.Input
7783
{
@@ -130,6 +136,8 @@ extension Publishers {
130136
}
131137
}
132138

139+
// MARK: - Operator
140+
133141
public extension Publisher {
134142

135143
/// Wraps each element from the upstream publisher, as well as its subscription and completion events,

Sources/Entwine/Operators/ReplaySubject.swift

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,9 +78,12 @@ extension ReplaySubject: Publisher {
7878
subscriptions.append(subscription)
7979

8080
subscription.cleanupHandler = { [weak self] in
81-
if let index = self?.subscriptions.firstIndex(where: { subscriberIdentifier == $0.subscriberIdentifier }) {
82-
self?.subscriberIdentifiers.remove(subscriberIdentifier)
83-
self?.subscriptions.remove(at: index)
81+
82+
guard let self = self else { return }
83+
84+
if let index = self.subscriptions.firstIndex(where: { subscriberIdentifier == $0.subscriberIdentifier }) {
85+
self.subscriberIdentifiers.remove(subscriberIdentifier)
86+
self.subscriptions.remove(at: index)
8487
}
8588
}
8689
subscriber.receive(subscription: subscription)

Sources/Entwine/Signal.swift

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,16 @@ public enum Signal <Input, Failure: Error> {
4444
case completion(Subscribers.Completion<Failure>)
4545
}
4646

47+
// MARK: - Signal extensions
48+
49+
public extension Signal {
50+
/// Whether the signal indicates sequence completion
51+
var isCompletion: Bool {
52+
guard case .completion(_) = self else { return false }
53+
return true
54+
}
55+
}
56+
4757
// MARK: - Equatable conformance
4858

4959
extension Signal: Equatable where Input: Equatable, Failure: Equatable {
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
//
2+
// Entwine
3+
// https://github.com/tcldr/Entwine
4+
//
5+
// Copyright © 2019 Tristan Celder. All rights reserved.
6+
//
7+
// Permission is hereby granted, free of charge, to any person obtaining a copy
8+
// of this software and associated documentation files (the "Software"), to deal
9+
// in the Software without restriction, including without limitation the rights
10+
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11+
// copies of the Software, and to permit persons to whom the Software is
12+
// furnished to do so, subject to the following conditions:
13+
//
14+
// The above copyright notice and this permission notice shall be included in
15+
// all copies or substantial portions of the Software.
16+
//
17+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18+
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19+
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20+
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21+
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22+
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23+
// THE SOFTWARE.
24+
25+
public extension TestableSubscriber {
26+
27+
@available(*, deprecated, renamed: "recordedOutput")
28+
var sequence: TestSequence<Input, Failure>{ recordedOutput }
29+
30+
@available(*, deprecated, renamed: "recordedDemandLog")
31+
var demands: DemandLedger<VirtualTime>{ recordedDemandLog }
32+
}

Sources/EntwineTest/TestableSubscriber/TestableSubscriber.swift

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -61,10 +61,10 @@ public final class TestableSubscriber<Input, Failure: Error> {
6161
public typealias Sequence = TestSequence<Input, Failure>
6262

6363
/// A time-stamped log of `Signal`s produced during the lifetime of a subscription to a publisher.
64-
public internal(set) var sequence = TestSequence<Input, Failure>()
64+
public internal(set) var recordedOutput = TestSequence<Input, Failure>()
6565
/// A time-stamped account of `Subscribers.Demand`s issued upstream, and incoming elements
6666
/// downstream, during the lifetime of a subscription to a publisher.
67-
public internal(set) var demands = DemandLedger<VirtualTime>()
67+
public internal(set) var recordedDemandLog = DemandLedger<VirtualTime>()
6868

6969
private let scheduler: TestScheduler
7070
private let options: TestableSubscriberOptions
@@ -85,7 +85,7 @@ public final class TestableSubscriber<Input, Failure: Error> {
8585
func issueDemandCredit(_ demand: Subscribers.Demand) {
8686

8787
demandBalance += demand
88-
demands.append((scheduler.now, demandBalance, .credit(amount: demand)))
88+
recordedDemandLog.append((scheduler.now, demandBalance, .credit(amount: demand)))
8989

9090
subscription?.request(demand)
9191
}
@@ -94,7 +94,7 @@ public final class TestableSubscriber<Input, Failure: Error> {
9494

9595
let authorized = (demandBalance > .none)
9696
demandBalance -= authorized ? demand : .none
97-
demands.append((scheduler.now, demandBalance, .debit(authorized: authorized)))
97+
recordedDemandLog.append((scheduler.now, demandBalance, .debit(authorized: authorized)))
9898
if !authorized {
9999
signalNegativeBalance()
100100
}
@@ -147,14 +147,14 @@ extension TestableSubscriber: Subscriber {
147147
self.demandBalance = .none
148148
self.subscription = subscription
149149

150-
sequence.append((scheduler.now, .subscription))
150+
recordedOutput.append((scheduler.now, .subscription))
151151

152152
issueDemandCredit(options.initialDemand)
153153
delayedReplenishDemandIfNeeded()
154154
}
155155

156156
public func receive(_ input: Input) -> Subscribers.Demand {
157-
sequence.append((scheduler.now, .input(input)))
157+
recordedOutput.append((scheduler.now, .input(input)))
158158

159159
debitDemand(.max(1))
160160
delayedReplenishDemandIfNeeded()
@@ -163,7 +163,7 @@ extension TestableSubscriber: Subscriber {
163163
}
164164

165165
public func receive(completion: Subscribers.Completion<Failure>) {
166-
sequence.append((scheduler.now, .completion(completion)))
166+
recordedOutput.append((scheduler.now, .completion(completion)))
167167
}
168168
}
169169

Tests/EntwineTestTests/TestSchedulerTests.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ final class TestSchedulerTests: XCTestCase {
153153
(310, .input(2)),
154154
]
155155

156-
XCTAssertEqual(expected, results.sequence)
156+
XCTAssertEqual(expected, results.recordedOutput)
157157
}
158158

159159
func testFiresEventsScheduledBeforeStartCalled() {
@@ -175,7 +175,7 @@ final class TestSchedulerTests: XCTestCase {
175175
(500, .input(2)),
176176
]
177177

178-
XCTAssertEqual(expected, testableSubscriber.sequence)
178+
XCTAssertEqual(expected, testableSubscriber.recordedOutput)
179179
}
180180

181181
func testTrampolinesImmediatelyScheduledTasks() {
@@ -206,7 +206,7 @@ final class TestSchedulerTests: XCTestCase {
206206
(200, .input(2)),
207207
]
208208

209-
XCTAssertEqual(expected, results.sequence)
209+
XCTAssertEqual(expected, results.recordedOutput)
210210
}
211211

212212
static var allTests = [

0 commit comments

Comments
 (0)