Skip to content

Commit

Permalink
Added tests for RxRelay and RxCocoa multi-observer bind
Browse files Browse the repository at this point in the history
  • Loading branch information
freak4pc authored and kzaher committed Apr 11, 2019
1 parent a06cd3e commit 2d62dda
Show file tree
Hide file tree
Showing 3 changed files with 128 additions and 3 deletions.
4 changes: 4 additions & 0 deletions Sources/AllTestz/main.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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),
] }
}
Expand Down
51 changes: 50 additions & 1 deletion Tests/RxCocoaTests/Observable+BindTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,31 @@ extension ObservableBindTest {
])
}

func testBindToObservers() {
var events1: [Recorded<Event<Int>>] = []
var events2: [Recorded<Event<Int>>] = []

let observer1: AnyObserver<Int> = AnyObserver { event in
events1.append(Recorded(time: 0, value: event))
}

let observer2: AnyObserver<Int> = 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<Event<Int?>>] = []

Expand All @@ -49,6 +74,31 @@ extension ObservableBindTest {
}
}

func testBindToOptionalObservers() {
var events1: [Recorded<Event<Int?>>] = []
var events2: [Recorded<Event<Int?>>] = []

let observer1: AnyObserver<Int?> = AnyObserver { event in
events1.append(Recorded(time: 0, value: event))
}

let observer2: AnyObserver<Int?> = AnyObserver { event in
events2.append(Recorded(time: 0, value: event))
}

_ = (Observable.just(1) as Observable<Int>).bind(to: observer1, observer2)

XCTAssertEqual(events1, [
.next(1),
.completed()
])

XCTAssertEqual(events2, [
.next(1),
.completed()
])
}

func testBindToOptionalObserverNoAmbiguity() {
var events: [Recorded<Event<Int?>>] = []

Expand Down Expand Up @@ -102,5 +152,4 @@ extension ObservableBindTest {
XCTAssertEqual(result, 4)
d.dispose()
}

}
76 changes: 74 additions & 2 deletions Tests/RxRelayTests/Observable+RelayBindTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,38 @@ extension ObservableRelayBindTest {
])
}

func testBindToPublishRelays() {
var events1: [Recorded<Event<Int>>] = []
var events2: [Recorded<Event<Int>>] = []

let relay1 = PublishRelay<Int>()
let relay2 = PublishRelay<Int>()

_ = 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<Event<Int?>>] = []

let relay = PublishRelay<Int?>()

_ = relay.subscribe{ event in
_ = relay.subscribe { event in
events.append(Recorded(time: 0, value: event))
}

Expand All @@ -49,12 +75,38 @@ extension ObservableRelayBindTest {
])
}

func testBindToOptionalPublishRelays() {
var events1: [Recorded<Event<Int?>>] = []
var events2: [Recorded<Event<Int?>>] = []

let relay1 = PublishRelay<Int?>()
let relay2 = PublishRelay<Int?>()

_ = 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<Int>).bind(to: relay1, relay2)

XCTAssertEqual(events1, [
.next(1)
])

XCTAssertEqual(events2, [
.next(1)
])
}

func testBindToPublishRelayNoAmbiguity() {
var events: [Recorded<Event<Int?>>] = []

let relay = PublishRelay<Int?>()

_ = relay.subscribe{ event in
_ = relay.subscribe { event in
events.append(Recorded(time: 0, value: event))
}

Expand All @@ -76,6 +128,16 @@ extension ObservableRelayBindTest {
XCTAssertEqual(relay.value, 1)
}

func testBindToBehaviorRelays() {
let relay1 = BehaviorRelay<Int>(value: 0)
let relay2 = BehaviorRelay<Int>(value: 0)

_ = Observable.just(1).bind(to: relay1, relay2)

XCTAssertEqual(relay1.value, 1)
XCTAssertEqual(relay2.value, 1)
}

func testBindToOptionalBehaviorRelay() {
let relay = BehaviorRelay<Int?>(value: 0)

Expand All @@ -84,6 +146,16 @@ extension ObservableRelayBindTest {
XCTAssertEqual(relay.value, 1)
}

func testBindToOptionalBehaviorRelays() {
let relay1 = BehaviorRelay<Int?>(value: 0)
let relay2 = BehaviorRelay<Int?>(value: 0)

_ = (Observable.just(1) as Observable<Int>).bind(to: relay1, relay2)

XCTAssertEqual(relay1.value, 1)
XCTAssertEqual(relay2.value, 1)
}

func testBindToBehaviorRelayNoAmbiguity() {
let relay = BehaviorRelay<Int?>(value: 0)

Expand Down

0 comments on commit 2d62dda

Please sign in to comment.