Skip to content

Commit ef4e11a

Browse files
committed
Infallible test coverage
1 parent ef8b0ab commit ef4e11a

File tree

7 files changed

+405
-2
lines changed

7 files changed

+405
-2
lines changed

Rx.xcodeproj/project.pbxproj

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,10 @@
6363
788DCE6124CB8512005B8F8C /* Observable+DecodeTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 788DCE5E24CB8512005B8F8C /* Observable+DecodeTests.swift */; };
6464
78B6157523B69F49009C2AD9 /* Binder.swift in Sources */ = {isa = PBXBuildFile; fileRef = C8E65EFA1F6E91D1004478C3 /* Binder.swift */; };
6565
78B6157723B6A035009C2AD9 /* Binder+Tests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 78B6157623B6A035009C2AD9 /* Binder+Tests.swift */; };
66+
78C385CE25685076005E39B3 /* Infallible+BindTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 78C385CD25685076005E39B3 /* Infallible+BindTests.swift */; };
67+
78C385CF25685076005E39B3 /* Infallible+BindTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 78C385CD25685076005E39B3 /* Infallible+BindTests.swift */; };
68+
78C385EB256859DC005E39B3 /* Infallible+Tests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 78C385EA256859DC005E39B3 /* Infallible+Tests.swift */; };
69+
78C385EC256859DC005E39B3 /* Infallible+Tests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 78C385EA256859DC005E39B3 /* Infallible+Tests.swift */; };
6670
78F2D93E24C8D35700D13F0C /* RxWKNavigationDelegateProxy.swift in Sources */ = {isa = PBXBuildFile; fileRef = 504540CD2419701D0098665F /* RxWKNavigationDelegateProxy.swift */; };
6771
7EDBAEB41C89B1A6006CBE67 /* UITabBarItem+RxTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7EDBAEAB1C89B1A5006CBE67 /* UITabBarItem+RxTests.swift */; };
6872
7EDBAEC31C89BCB9006CBE67 /* UITabBarItem+RxTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7EDBAEAB1C89B1A5006CBE67 /* UITabBarItem+RxTests.swift */; };
@@ -966,6 +970,8 @@
966970
788DCE5C24CB8249005B8F8C /* Decode.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Decode.swift; sourceTree = "<group>"; };
967971
788DCE5E24CB8512005B8F8C /* Observable+DecodeTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Observable+DecodeTests.swift"; sourceTree = "<group>"; };
968972
78B6157623B6A035009C2AD9 /* Binder+Tests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "Binder+Tests.swift"; sourceTree = "<group>"; };
973+
78C385CD25685076005E39B3 /* Infallible+BindTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Infallible+BindTests.swift"; sourceTree = "<group>"; };
974+
78C385EA256859DC005E39B3 /* Infallible+Tests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Infallible+Tests.swift"; sourceTree = "<group>"; };
969975
7EDBAEAB1C89B1A5006CBE67 /* UITabBarItem+RxTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "UITabBarItem+RxTests.swift"; sourceTree = "<group>"; };
970976
7F600F3D1C5D0C0100535B1D /* UIRefreshControl+Rx.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "UIRefreshControl+Rx.swift"; sourceTree = "<group>"; };
971977
7F600F421C5D0D2D00535B1D /* UIRefreshControl+RxTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "UIRefreshControl+RxTests.swift"; sourceTree = "<group>"; };
@@ -1941,6 +1947,7 @@
19411947
C8F27DB11CE6711600D5FB4F /* UITextView+RxTests.swift */,
19421948
C83508F11C38706D0027C24C /* UIView+RxTests.swift */,
19431949
271A97421CFC99FE00D64125 /* UIViewController+RxTests.swift */,
1950+
78C385CD25685076005E39B3 /* Infallible+BindTests.swift */,
19441951
);
19451952
path = RxCocoaTests;
19461953
sourceTree = "<group>";
@@ -2041,6 +2048,7 @@
20412048
1E9DA0C422006858000EB80A /* Synchronized.swift */,
20422049
C83508F31C38706D0027C24C /* TestImplementations */,
20432050
C835091C1C38706D0027C24C /* VirtualSchedulerTest.swift */,
2051+
78C385EA256859DC005E39B3 /* Infallible+Tests.swift */,
20442052
);
20452053
path = RxSwiftTests;
20462054
sourceTree = "<group>";
@@ -3131,6 +3139,7 @@
31313139
C820A9D21EB50B0900D431BC /* Observable+GroupByTests.swift in Sources */,
31323140
C83509441C38706E0027C24C /* MySubject.swift in Sources */,
31333141
C835095F1C38706E0027C24C /* Observable+SubscriptionTest.swift in Sources */,
3142+
78C385EB256859DC005E39B3 /* Infallible+Tests.swift in Sources */,
31343143
C8C217D71CB710200038A2E6 /* UICollectionView+RxTests.swift in Sources */,
31353144
C83509451C38706E0027C24C /* Observable.Extensions.swift in Sources */,
31363145
C835093B1C38706E0027C24C /* RXObjCRuntime+Testing.m in Sources */,
@@ -3240,6 +3249,7 @@
32403249
C83509321C38706E0027C24C /* DelegateProxyTest.swift in Sources */,
32413250
C8091C531FAA3588001DB32A /* ObservableConvertibleType+SharedSequence.swift in Sources */,
32423251
1E3079AC21FB52330072A7E6 /* AtomicTests.swift in Sources */,
3252+
78C385CE25685076005E39B3 /* Infallible+BindTests.swift in Sources */,
32433253
0BA9496C1E224B9C0036DD06 /* AsyncSubjectTests.swift in Sources */,
32443254
C8F27DC01CE68DA600D5FB4F /* UITextView+RxTests.swift in Sources */,
32453255
C820A9B21EB507D300D431BC /* Observable+TakeWhileTests.swift in Sources */,
@@ -3270,6 +3280,7 @@
32703280
C83509E11C3875500027C24C /* TestVirtualScheduler.swift in Sources */,
32713281
C820A94F1EB4EC3C00D431BC /* Observable+ReduceTests.swift in Sources */,
32723282
C8B2908A1C94D64700E923D0 /* RxTest+Controls.swift in Sources */,
3283+
78C385CF25685076005E39B3 /* Infallible+BindTests.swift in Sources */,
32733284
B44D73EC1EE6D4A300EBFBE8 /* UIViewController+RxTests.swift in Sources */,
32743285
C820A9671EB4F39500D431BC /* Observable+SubscribeOnTests.swift in Sources */,
32753286
C820A9C71EB50A4200D431BC /* Observable+SkipWhileTests.swift in Sources */,
@@ -3383,6 +3394,7 @@
33833394
C83509DC1C38754C0027C24C /* ElementIndexPair.swift in Sources */,
33843395
C8B0F70E1F530A1700548EBE /* SharingSchedulerTests.swift in Sources */,
33853396
C8845ADB1EDB607800B36836 /* Observable+ShareReplayScopeTests.swift in Sources */,
3397+
78C385EC256859DC005E39B3 /* Infallible+Tests.swift in Sources */,
33863398
C8350A171C38756A0027C24C /* SubjectConcurrencyTest.swift in Sources */,
33873399
C83509EA1C3875580027C24C /* BackgroundThreadPrimitiveHotObservable.swift in Sources */,
33883400
C84CB1721C3876B800EB63CC /* UIView+RxTests.swift in Sources */,

Rx.xcodeproj/xcshareddata/xcschemes/AllTests-iOS.xcscheme

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@
1212
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
1313
shouldUseLaunchSchemeArgsEnv = "YES"
1414
enableThreadSanitizer = "YES"
15-
enableUBSanitizer = "YES">
15+
enableUBSanitizer = "YES"
16+
codeCoverageEnabled = "YES">
1617
<Testables>
1718
<TestableReference
1819
skipped = "NO"

RxSwift/Traits/Infallible/Infallible+Operators.swift

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
//
88

99
// MARK: - Static allocation
10-
#warning("Infallible still needs a full test suite")
1110
extension InfallibleType {
1211
/**
1312
Returns an infallible sequence that contains a single element.
@@ -71,6 +70,47 @@ extension InfallibleType {
7170
}
7271
}
7372

73+
// MARK: From & Of
74+
75+
extension Infallible {
76+
/**
77+
This method creates a new Infallible instance with a variable number of elements.
78+
79+
- seealso: [from operator on reactivex.io](http://reactivex.io/documentation/operators/from.html)
80+
81+
- parameter elements: Elements to generate.
82+
- parameter scheduler: Scheduler to send elements on. If `nil`, elements are sent immediately on subscription.
83+
- returns: The Infallible sequence whose elements are pulled from the given arguments.
84+
*/
85+
public static func of(_ elements: Element ..., scheduler: ImmediateSchedulerType = CurrentThreadScheduler.instance) -> Infallible<Element> {
86+
Infallible(Observable.from(elements, scheduler: scheduler))
87+
}
88+
}
89+
90+
extension Infallible {
91+
/**
92+
Converts an array to an Infallible sequence.
93+
94+
- seealso: [from operator on reactivex.io](http://reactivex.io/documentation/operators/from.html)
95+
96+
- returns: The Infallible sequence whose elements are pulled from the given enumerable sequence.
97+
*/
98+
public static func from(_ array: [Element], scheduler: ImmediateSchedulerType = CurrentThreadScheduler.instance) -> Infallible<Element> {
99+
Infallible(Observable.from(array, scheduler: scheduler))
100+
}
101+
102+
/**
103+
Converts a sequence to an Infallible sequence.
104+
105+
- seealso: [from operator on reactivex.io](http://reactivex.io/documentation/operators/from.html)
106+
107+
- returns: The Infallible sequence whose elements are pulled from the given enumerable sequence.
108+
*/
109+
public static func from<Sequence: Swift.Sequence>(_ sequence: Sequence, scheduler: ImmediateSchedulerType = CurrentThreadScheduler.instance) -> Infallible<Element> where Sequence.Element == Element {
110+
Infallible(Observable.from(sequence, scheduler: scheduler))
111+
}
112+
}
113+
74114
// MARK: - Filter
75115
extension InfallibleType {
76116
/**
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../../Tests/RxSwiftTests/Infallible+Tests.swift

Sources/AllTestz/main.swift

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -311,6 +311,23 @@ final class HistoricalSchedulerTest_ : HistoricalSchedulerTest, RxTestCase {
311311
] }
312312
}
313313

314+
final class InfallibleTest_ : InfallibleTest, RxTestCase {
315+
#if os(macOS)
316+
required override init() {
317+
super.init()
318+
}
319+
#endif
320+
321+
static var allTests: [(String, (InfallibleTest_) -> () -> Void)] { return [
322+
("testAsInfallible_OnErrorJustReturn", InfallibleTest.testAsInfallible_OnErrorJustReturn),
323+
("testAsInfallible_OnErrorFallbackTo", InfallibleTest.testAsInfallible_OnErrorFallbackTo),
324+
("testAsInfallible_OnErrorRecover", InfallibleTest.testAsInfallible_OnErrorRecover),
325+
("testAnonymousInfallible_detachesOnDispose", InfallibleTest.testAnonymousInfallible_detachesOnDispose),
326+
("testAnonymousInfallible_detachesOnComplete", InfallibleTest.testAnonymousInfallible_detachesOnComplete),
327+
("testAsInfallible_never", InfallibleTest.testAsInfallible_never),
328+
] }
329+
}
330+
314331
final class MainSchedulerTest_ : MainSchedulerTest, RxTestCase {
315332
#if os(macOS)
316333
required override init() {
@@ -2169,6 +2186,7 @@ func XCTMain(_ tests: [() -> Void]) {
21692186
testCase(DriverTest_.allTests),
21702187
testCase(EventTests_.allTests),
21712188
testCase(HistoricalSchedulerTest_.allTests),
2189+
testCase(InfallibleTest_.allTests),
21722190
testCase(MainSchedulerTest_.allTests),
21732191
testCase(MaybeTest_.allTests),
21742192
testCase(NSNotificationCenterTests_.allTests),
Lines changed: 155 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,155 @@
1+
//
2+
// Infallible+BindTests.swift
3+
// Tests
4+
//
5+
// Created by Shai Mishali on 11/20/20.
6+
// Copyright © 2020 Krunoslav Zaher. All rights reserved.
7+
//
8+
9+
import Foundation
10+
import RxSwift
11+
import RxTest
12+
import XCTest
13+
14+
final class InfallibleBindTest: RxTest {
15+
16+
}
17+
18+
// MARK: bind(to:) observer
19+
20+
extension InfallibleBindTest {
21+
func testBindToObserver() {
22+
var events: [Recorded<Event<Int>>] = []
23+
24+
let observer: AnyObserver<Int> = AnyObserver { event in
25+
events.append(Recorded(time: 0, value: event))
26+
}
27+
28+
_ = Infallible.just(1).bind(to: observer)
29+
30+
XCTAssertEqual(events, [
31+
.next(1),
32+
.completed()
33+
])
34+
}
35+
36+
func testBindToObservers() {
37+
var events1: [Recorded<Event<Int>>] = []
38+
var events2: [Recorded<Event<Int>>] = []
39+
40+
let observer1: AnyObserver<Int> = AnyObserver { event in
41+
events1.append(Recorded(time: 0, value: event))
42+
}
43+
44+
let observer2: AnyObserver<Int> = AnyObserver { event in
45+
events2.append(Recorded(time: 0, value: event))
46+
}
47+
48+
_ = Infallible.just(1).bind(to: observer1, observer2)
49+
50+
XCTAssertEqual(events1, [
51+
.next(1),
52+
.completed()
53+
])
54+
55+
XCTAssertEqual(events2, [
56+
.next(1),
57+
.completed()
58+
])
59+
}
60+
61+
func testBindToOptionalObserver() {
62+
var events: [Recorded<Event<Int?>>] = []
63+
64+
let observer: AnyObserver<Int?> = AnyObserver { event in
65+
events.append(Recorded(time: 0, value: event))
66+
}
67+
68+
_ = (Infallible.just(1) as Infallible<Int>).bind(to: observer)
69+
70+
XCTAssertEqual(events[0].value.element!, 1)
71+
guard case .completed = events[1].value else {
72+
XCTFail("Not completed")
73+
return
74+
}
75+
}
76+
77+
func testBindToOptionalObservers() {
78+
var events1: [Recorded<Event<Int?>>] = []
79+
var events2: [Recorded<Event<Int?>>] = []
80+
81+
let observer1: AnyObserver<Int?> = AnyObserver { event in
82+
events1.append(Recorded(time: 0, value: event))
83+
}
84+
85+
let observer2: AnyObserver<Int?> = AnyObserver { event in
86+
events2.append(Recorded(time: 0, value: event))
87+
}
88+
89+
_ = (Infallible.just(1) as Infallible<Int>).bind(to: observer1, observer2)
90+
91+
XCTAssertEqual(events1, [
92+
.next(1),
93+
.completed()
94+
])
95+
96+
XCTAssertEqual(events2, [
97+
.next(1),
98+
.completed()
99+
])
100+
}
101+
102+
func testBindToOptionalObserverNoAmbiguity() {
103+
var events: [Recorded<Event<Int?>>] = []
104+
105+
let observer: AnyObserver<Int?> = AnyObserver { event in
106+
events.append(Recorded(time: 0, value: event))
107+
}
108+
109+
_ = Infallible.just(1).bind(to: observer)
110+
111+
XCTAssertEqual(events[0].value.element!, 1)
112+
guard case .completed = events[1].value else {
113+
XCTFail("Not completed")
114+
return
115+
}
116+
}
117+
}
118+
119+
// MARK: bind(to:) curried
120+
121+
extension InfallibleBindTest {
122+
func testBindToCurried1() {
123+
var result: Int? = nil
124+
let binder: (Infallible<Int>) -> Disposable = { obs in
125+
return obs.subscribe(onNext: { element in
126+
result = element
127+
})
128+
}
129+
130+
XCTAssertNil(result)
131+
132+
let d: Disposable = Infallible.just(1).bind(to: binder)
133+
134+
XCTAssertEqual(result, 1)
135+
d.dispose()
136+
}
137+
138+
func testBindToCurried2() {
139+
var result: Int? = nil
140+
let binder: (Infallible<Int>) -> (Int) -> Disposable = { obs in
141+
return { other in
142+
return obs.subscribe(onNext: { element in
143+
result = element + other
144+
})
145+
}
146+
}
147+
148+
XCTAssertNil(result)
149+
150+
let d: Disposable = Infallible.just(1).bind(to: binder)(3)
151+
152+
XCTAssertEqual(result, 4)
153+
d.dispose()
154+
}
155+
}

0 commit comments

Comments
 (0)