From 9dcaa4b333db437b0fbfaf453fad29069044a8b4 Mon Sep 17 00:00:00 2001 From: Hal Lee Date: Fri, 12 May 2023 00:02:28 -0500 Subject: [PATCH] Fix Infallible CombineLatest arity helpers (#2520) --- .../Infallible+CombineLatest+arity.swift | 14 +- .../Infallible+CombineLatestTests+arity.swift | 1 + Sources/AllTestz/main.swift | 19 ++ .../Infallible+CombineLatestTests+arity.swift | 246 ++++++++++++++++++ 4 files changed, 273 insertions(+), 7 deletions(-) create mode 120000 Sources/AllTestz/Infallible+CombineLatestTests+arity.swift create mode 100644 Tests/RxSwiftTests/Infallible+CombineLatestTests+arity.swift diff --git a/RxSwift/Traits/Infallible/Infallible+CombineLatest+arity.swift b/RxSwift/Traits/Infallible/Infallible+CombineLatest+arity.swift index 18fbc2d75..4bcc7656f 100644 --- a/RxSwift/Traits/Infallible/Infallible+CombineLatest+arity.swift +++ b/RxSwift/Traits/Infallible/Infallible+CombineLatest+arity.swift @@ -29,7 +29,7 @@ extension Infallible { } } -extension InfallibleType { +extension InfallibleType where Element == Any { /** Merges the specified observable sequences into one observable sequence of tuples whenever any of the observable sequences produces an element. @@ -67,7 +67,7 @@ extension Infallible { } } -extension InfallibleType { +extension InfallibleType where Element == Any { /** Merges the specified observable sequences into one observable sequence of tuples whenever any of the observable sequences produces an element. @@ -105,7 +105,7 @@ extension Infallible { } } -extension InfallibleType { +extension InfallibleType where Element == Any { /** Merges the specified observable sequences into one observable sequence of tuples whenever any of the observable sequences produces an element. @@ -143,7 +143,7 @@ extension Infallible { } } -extension InfallibleType { +extension InfallibleType where Element == Any { /** Merges the specified observable sequences into one observable sequence of tuples whenever any of the observable sequences produces an element. @@ -181,7 +181,7 @@ extension Infallible { } } -extension InfallibleType { +extension InfallibleType where Element == Any { /** Merges the specified observable sequences into one observable sequence of tuples whenever any of the observable sequences produces an element. @@ -219,7 +219,7 @@ extension Infallible { } } -extension InfallibleType { +extension InfallibleType where Element == Any { /** Merges the specified observable sequences into one observable sequence of tuples whenever any of the observable sequences produces an element. @@ -257,7 +257,7 @@ extension Infallible { } } -extension InfallibleType { +extension InfallibleType where Element == Any { /** Merges the specified observable sequences into one observable sequence of tuples whenever any of the observable sequences produces an element. diff --git a/Sources/AllTestz/Infallible+CombineLatestTests+arity.swift b/Sources/AllTestz/Infallible+CombineLatestTests+arity.swift new file mode 120000 index 000000000..d34c5affd --- /dev/null +++ b/Sources/AllTestz/Infallible+CombineLatestTests+arity.swift @@ -0,0 +1 @@ +../../Tests/RxSwiftTests/Infallible+CombineLatestTests+arity.swift \ No newline at end of file diff --git a/Sources/AllTestz/main.swift b/Sources/AllTestz/main.swift index c9e732e8c..ccbe4be16 100644 --- a/Sources/AllTestz/main.swift +++ b/Sources/AllTestz/main.swift @@ -315,6 +315,24 @@ final class HistoricalSchedulerTest_ : HistoricalSchedulerTest, RxTestCase { ] } } +final class InfallibleCombineLatestTest_ : InfallibleCombineLatestTest, RxTestCase { + #if os(macOS) + required override init() { + super.init() + } + #endif + + static var allTests: [(String, (InfallibleCombineLatestTest_) -> () -> Void)] { return [ + ("testCombineLatest_Arity", InfallibleCombineLatestTest.testCombineLatest_Arity), + ("testCombineLatest_3_Arity", InfallibleCombineLatestTest.testCombineLatest_3_Arity), + ("testCombineLatest_4_Arity", InfallibleCombineLatestTest.testCombineLatest_4_Arity), + ("testCombineLatest_5_Arity", InfallibleCombineLatestTest.testCombineLatest_5_Arity), + ("testCombineLatest_6_Arity", InfallibleCombineLatestTest.testCombineLatest_6_Arity), + ("testCombineLatest_7_Arity", InfallibleCombineLatestTest.testCombineLatest_7_Arity), + ("testCombineLatest_8_Arity", InfallibleCombineLatestTest.testCombineLatest_8_Arity), + ] } +} + final class InfallibleTest_ : InfallibleTest, RxTestCase { #if os(macOS) required override init() { @@ -2217,6 +2235,7 @@ func XCTMain(_ tests: [() -> Void]) { testCase(DriverTest_.allTests), testCase(EventTests_.allTests), testCase(HistoricalSchedulerTest_.allTests), + testCase(InfallibleCombineLatestTest_.allTests), testCase(InfallibleTest_.allTests), testCase(MainSchedulerTest_.allTests), testCase(MaybeTest_.allTests), diff --git a/Tests/RxSwiftTests/Infallible+CombineLatestTests+arity.swift b/Tests/RxSwiftTests/Infallible+CombineLatestTests+arity.swift new file mode 100644 index 000000000..fae39f56b --- /dev/null +++ b/Tests/RxSwiftTests/Infallible+CombineLatestTests+arity.swift @@ -0,0 +1,246 @@ +// +// Infallible+CombineLatestTests+arity.swift +// Tests +// +// Created by Hal Lee on 5/11/23. +// Copyright © 2023 Krunoslav Zaher. All rights reserved. +// + +import XCTest +import RxSwift +import RxTest + +class InfallibleCombineLatestTest: RxTest { + + func testCombineLatest_Arity() { + let scheduler = TestScheduler(initialClock: 0) + let firstStream = scheduler.createColdObservable([ + .next(1, 1) + ]).asInfallible(onErrorFallbackTo: .never()) + + let secondStream = scheduler.createColdObservable([ + .next(1, 1) + ]).asInfallible(onErrorFallbackTo: .never()) + + let observer = scheduler.start(created: 0, subscribed: 0, disposed: 100) { + return Infallible + .combineLatest(firstStream, secondStream) + .map { $0 + $1 } + } + + XCTAssertEqual(observer.events, [ + .next(1, 2), + ]) + } + + func testCombineLatest_3_Arity() { + let scheduler = TestScheduler(initialClock: 0) + let firstStream = scheduler.createColdObservable([ + .next(1, 1) + ]).asInfallible(onErrorFallbackTo: .never()) + + let secondStream = scheduler.createColdObservable([ + .next(1, 1) + ]).asInfallible(onErrorFallbackTo: .never()) + + let thirdStream = scheduler.createColdObservable([ + .next(1, 1) + ]).asInfallible(onErrorFallbackTo: .never()) + + let observer = scheduler.start(created: 0, subscribed: 0, disposed: 100) { + return Infallible + .combineLatest(firstStream, secondStream, thirdStream) + .map { $0 + $1 + $2 } + } + + XCTAssertEqual(observer.events, [ + .next(1, 3), + ]) + } + + func testCombineLatest_4_Arity() { + let scheduler = TestScheduler(initialClock: 0) + let firstStream = scheduler.createColdObservable([ + .next(1, 1) + ]).asInfallible(onErrorFallbackTo: .never()) + + let secondStream = scheduler.createColdObservable([ + .next(1, 1) + ]).asInfallible(onErrorFallbackTo: .never()) + + let thirdStream = scheduler.createColdObservable([ + .next(1, 1) + ]).asInfallible(onErrorFallbackTo: .never()) + + let fourthStream = scheduler.createColdObservable([ + .next(1, 1) + ]).asInfallible(onErrorFallbackTo: .never()) + + let observer = scheduler.start(created: 0, subscribed: 0, disposed: 100) { + return Infallible + .combineLatest(firstStream, secondStream, thirdStream, fourthStream) + .map { (a: Int, b: Int, c: Int, d: Int) -> Int in a + b + c + d } + } + + XCTAssertEqual(observer.events, [ + .next(1, 4), + ]) + } + + func testCombineLatest_5_Arity() { + let scheduler = TestScheduler(initialClock: 0) + let firstStream = scheduler.createColdObservable([ + .next(1, 1) + ]).asInfallible(onErrorFallbackTo: .never()) + + let secondStream = scheduler.createColdObservable([ + .next(1, 1) + ]).asInfallible(onErrorFallbackTo: .never()) + + let thirdStream = scheduler.createColdObservable([ + .next(1, 1) + ]).asInfallible(onErrorFallbackTo: .never()) + + let fourthStream = scheduler.createColdObservable([ + .next(1, 1) + ]).asInfallible(onErrorFallbackTo: .never()) + + let fifthStream = scheduler.createColdObservable([ + .next(1, 1) + ]).asInfallible(onErrorFallbackTo: .never()) + + let observer = scheduler.start(created: 0, subscribed: 0, disposed: 100) { + return Infallible + .combineLatest(firstStream, secondStream, thirdStream, fourthStream, fifthStream) + .map { (a: Int, b: Int, c: Int, d: Int, e: Int) -> Int in a + b + c + d + e } + } + + XCTAssertEqual(observer.events, [ + .next(1, 5), + ]) + } + + func testCombineLatest_6_Arity() { + let scheduler = TestScheduler(initialClock: 0) + let firstStream = scheduler.createColdObservable([ + .next(1, 1) + ]).asInfallible(onErrorFallbackTo: .never()) + + let secondStream = scheduler.createColdObservable([ + .next(1, 1) + ]).asInfallible(onErrorFallbackTo: .never()) + + let thirdStream = scheduler.createColdObservable([ + .next(1, 1) + ]).asInfallible(onErrorFallbackTo: .never()) + + let fourthStream = scheduler.createColdObservable([ + .next(1, 1) + ]).asInfallible(onErrorFallbackTo: .never()) + + let fifthStream = scheduler.createColdObservable([ + .next(1, 1) + ]).asInfallible(onErrorFallbackTo: .never()) + + let sixthStream = scheduler.createColdObservable([ + .next(1, 1) + ]).asInfallible(onErrorFallbackTo: .never()) + + let observer = scheduler.start(created: 0, subscribed: 0, disposed: 100) { + return Infallible + .combineLatest(firstStream, secondStream, thirdStream, fourthStream, fifthStream, sixthStream) + .map { (a: Int, b: Int, c: Int, d: Int, e: Int, f: Int) -> Int in a + b + c + d + e + f } + } + + XCTAssertEqual(observer.events, [ + .next(1, 6), + ]) + } + + func testCombineLatest_7_Arity() { + let scheduler = TestScheduler(initialClock: 0) + let firstStream = scheduler.createColdObservable([ + .next(1, 1) + ]).asInfallible(onErrorFallbackTo: .never()) + + let secondStream = scheduler.createColdObservable([ + .next(1, 1) + ]).asInfallible(onErrorFallbackTo: .never()) + + let thirdStream = scheduler.createColdObservable([ + .next(1, 1) + ]).asInfallible(onErrorFallbackTo: .never()) + + let fourthStream = scheduler.createColdObservable([ + .next(1, 1) + ]).asInfallible(onErrorFallbackTo: .never()) + + let fifthStream = scheduler.createColdObservable([ + .next(1, 1) + ]).asInfallible(onErrorFallbackTo: .never()) + + let sixthStream = scheduler.createColdObservable([ + .next(1, 1) + ]).asInfallible(onErrorFallbackTo: .never()) + + let seventhStream = scheduler.createColdObservable([ + .next(1, 1) + ]).asInfallible(onErrorFallbackTo: .never()) + + let observer = scheduler.start(created: 0, subscribed: 0, disposed: 100) { + return Infallible + .combineLatest(firstStream, secondStream, thirdStream, fourthStream, fifthStream, sixthStream, seventhStream) + .map { (a: Int, b: Int, c: Int, d: Int, e: Int, f: Int, g: Int) -> Int in a + b + c + d + e + f + g } + } + + XCTAssertEqual(observer.events, [ + .next(1, 7), + ]) + } + + func testCombineLatest_8_Arity() { + let scheduler = TestScheduler(initialClock: 0) + let firstStream = scheduler.createColdObservable([ + .next(1, 1) + ]).asInfallible(onErrorFallbackTo: .never()) + + let secondStream = scheduler.createColdObservable([ + .next(1, 1) + ]).asInfallible(onErrorFallbackTo: .never()) + + let thirdStream = scheduler.createColdObservable([ + .next(1, 1) + ]).asInfallible(onErrorFallbackTo: .never()) + + let fourthStream = scheduler.createColdObservable([ + .next(1, 1) + ]).asInfallible(onErrorFallbackTo: .never()) + + let fifthStream = scheduler.createColdObservable([ + .next(1, 1) + ]).asInfallible(onErrorFallbackTo: .never()) + + let sixthStream = scheduler.createColdObservable([ + .next(1, 1) + ]).asInfallible(onErrorFallbackTo: .never()) + + let seventhStream = scheduler.createColdObservable([ + .next(1, 1) + ]).asInfallible(onErrorFallbackTo: .never()) + + let eighthStream = scheduler.createColdObservable([ + .next(1, 1) + ]).asInfallible(onErrorFallbackTo: .never()) + + let observer = scheduler.start(created: 0, subscribed: 0, disposed: 100) { + return Infallible + .combineLatest(firstStream, secondStream, thirdStream, fourthStream, fifthStream, sixthStream, seventhStream, eighthStream) + .map { (a: Int, b: Int, c: Int, d: Int, e: Int, f: Int, g: Int, h: Int) -> Int in a + b + c + d + e + f + g + h } + } + + XCTAssertEqual(observer.events, [ + .next(1, 8), + ]) + } + +}