From 2d62dda53dbfbbddcc6c29a6e76235ede814d523 Mon Sep 17 00:00:00 2001 From: freak4pc Date: Wed, 10 Apr 2019 23:06:50 +0300 Subject: [PATCH] Added tests for RxRelay and RxCocoa multi-observer bind --- Sources/AllTestz/main.swift | 4 + Tests/RxCocoaTests/Observable+BindTests.swift | 51 ++++++++++++- .../Observable+RelayBindTests.swift | 76 ++++++++++++++++++- 3 files changed, 128 insertions(+), 3 deletions(-) diff --git a/Sources/AllTestz/main.swift b/Sources/AllTestz/main.swift index dd6fe2712..a038efbe8 100644 --- a/Sources/AllTestz/main.swift +++ b/Sources/AllTestz/main.swift @@ -1153,10 +1153,14 @@ final class ObservableRelayBindTest_ : ObservableRelayBindTest, RxTestCase { static var allTests: [(String, (ObservableRelayBindTest_) -> () -> Void)] { return [ ("testBindToPublishRelay", ObservableRelayBindTest.testBindToPublishRelay), + ("testBindToPublishRelays", ObservableRelayBindTest.testBindToPublishRelays), ("testBindToOptionalPublishRelay", ObservableRelayBindTest.testBindToOptionalPublishRelay), + ("testBindToOptionalPublishRelays", ObservableRelayBindTest.testBindToOptionalPublishRelays), ("testBindToPublishRelayNoAmbiguity", ObservableRelayBindTest.testBindToPublishRelayNoAmbiguity), ("testBindToBehaviorRelay", ObservableRelayBindTest.testBindToBehaviorRelay), + ("testBindToBehaviorRelays", ObservableRelayBindTest.testBindToBehaviorRelays), ("testBindToOptionalBehaviorRelay", ObservableRelayBindTest.testBindToOptionalBehaviorRelay), + ("testBindToOptionalBehaviorRelays", ObservableRelayBindTest.testBindToOptionalBehaviorRelays), ("testBindToBehaviorRelayNoAmbiguity", ObservableRelayBindTest.testBindToBehaviorRelayNoAmbiguity), ] } } diff --git a/Tests/RxCocoaTests/Observable+BindTests.swift b/Tests/RxCocoaTests/Observable+BindTests.swift index e957a3cef..80fd49e2c 100644 --- a/Tests/RxCocoaTests/Observable+BindTests.swift +++ b/Tests/RxCocoaTests/Observable+BindTests.swift @@ -33,6 +33,31 @@ extension ObservableBindTest { ]) } + func testBindToObservers() { + var events1: [Recorded>] = [] + var events2: [Recorded>] = [] + + let observer1: AnyObserver = AnyObserver { event in + events1.append(Recorded(time: 0, value: event)) + } + + let observer2: AnyObserver = AnyObserver { event in + events2.append(Recorded(time: 0, value: event)) + } + + _ = Observable.just(1).bind(to: observer1, observer2) + + XCTAssertEqual(events1, [ + .next(1), + .completed() + ]) + + XCTAssertEqual(events2, [ + .next(1), + .completed() + ]) + } + func testBindToOptionalObserver() { var events: [Recorded>] = [] @@ -49,6 +74,31 @@ extension ObservableBindTest { } } + func testBindToOptionalObservers() { + var events1: [Recorded>] = [] + var events2: [Recorded>] = [] + + let observer1: AnyObserver = AnyObserver { event in + events1.append(Recorded(time: 0, value: event)) + } + + let observer2: AnyObserver = AnyObserver { event in + events2.append(Recorded(time: 0, value: event)) + } + + _ = (Observable.just(1) as Observable).bind(to: observer1, observer2) + + XCTAssertEqual(events1, [ + .next(1), + .completed() + ]) + + XCTAssertEqual(events2, [ + .next(1), + .completed() + ]) + } + func testBindToOptionalObserverNoAmbiguity() { var events: [Recorded>] = [] @@ -102,5 +152,4 @@ extension ObservableBindTest { XCTAssertEqual(result, 4) d.dispose() } - } diff --git a/Tests/RxRelayTests/Observable+RelayBindTests.swift b/Tests/RxRelayTests/Observable+RelayBindTests.swift index 7f952f6c7..4038d95fd 100644 --- a/Tests/RxRelayTests/Observable+RelayBindTests.swift +++ b/Tests/RxRelayTests/Observable+RelayBindTests.swift @@ -33,12 +33,38 @@ extension ObservableRelayBindTest { ]) } + func testBindToPublishRelays() { + var events1: [Recorded>] = [] + var events2: [Recorded>] = [] + + let relay1 = PublishRelay() + let relay2 = PublishRelay() + + _ = relay1.subscribe { event in + events1.append(Recorded(time: 0, value: event)) + } + + _ = relay2.subscribe { event in + events2.append(Recorded(time: 0, value: event)) + } + + _ = Observable.just(1).bind(to: relay1, relay2) + + XCTAssertEqual(events1, [ + .next(1) + ]) + + XCTAssertEqual(events2, [ + .next(1) + ]) + } + func testBindToOptionalPublishRelay() { var events: [Recorded>] = [] let relay = PublishRelay() - _ = relay.subscribe{ event in + _ = relay.subscribe { event in events.append(Recorded(time: 0, value: event)) } @@ -49,12 +75,38 @@ extension ObservableRelayBindTest { ]) } + func testBindToOptionalPublishRelays() { + var events1: [Recorded>] = [] + var events2: [Recorded>] = [] + + let relay1 = PublishRelay() + let relay2 = PublishRelay() + + _ = relay1.subscribe { event in + events1.append(Recorded(time: 0, value: event)) + } + + _ = relay2.subscribe { event in + events2.append(Recorded(time: 0, value: event)) + } + + _ = (Observable.just(1) as Observable).bind(to: relay1, relay2) + + XCTAssertEqual(events1, [ + .next(1) + ]) + + XCTAssertEqual(events2, [ + .next(1) + ]) + } + func testBindToPublishRelayNoAmbiguity() { var events: [Recorded>] = [] let relay = PublishRelay() - _ = relay.subscribe{ event in + _ = relay.subscribe { event in events.append(Recorded(time: 0, value: event)) } @@ -76,6 +128,16 @@ extension ObservableRelayBindTest { XCTAssertEqual(relay.value, 1) } + func testBindToBehaviorRelays() { + let relay1 = BehaviorRelay(value: 0) + let relay2 = BehaviorRelay(value: 0) + + _ = Observable.just(1).bind(to: relay1, relay2) + + XCTAssertEqual(relay1.value, 1) + XCTAssertEqual(relay2.value, 1) + } + func testBindToOptionalBehaviorRelay() { let relay = BehaviorRelay(value: 0) @@ -84,6 +146,16 @@ extension ObservableRelayBindTest { XCTAssertEqual(relay.value, 1) } + func testBindToOptionalBehaviorRelays() { + let relay1 = BehaviorRelay(value: 0) + let relay2 = BehaviorRelay(value: 0) + + _ = (Observable.just(1) as Observable).bind(to: relay1, relay2) + + XCTAssertEqual(relay1.value, 1) + XCTAssertEqual(relay2.value, 1) + } + func testBindToBehaviorRelayNoAmbiguity() { let relay = BehaviorRelay(value: 0)