diff --git a/CHANGELOG.md b/CHANGELOG.md index 805e8cfcb..757103580 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,7 +6,27 @@ All notable changes to this project will be documented in this file. ## Master * Adds `materialize()` operator for RxBlocking's `BlockingObservable`. #1383 -* Adds `first` operator to ObservableType. +* Adds `first` operator to `ObservableType`. + +#### Anomalies + +* Call `controlTextDidChange(…)` as an optional method. #1406 +* Fixed issue with `NSControl.rx.value` regarding multiple observers. #1399 + +## [4.0.0-beta.0](https://github.com/ReactiveX/RxSwift/releases/tag/4.0.0-beta.0) + +* Adds `materialize()` operator for RxBlocking's `BlockingObservable`. #1383 +* Adds `first` operator to `ObservableType`. +* Deprecates `UIBindingObserver` in favor of `Binder`. #1411 +* Adds another specialization of `SharedSequence` called `Signal`. +* Refactors `DelegateProxy` to be type safe. +* Changes nested `SharedSequence` strategy to use inner sharing strategy for result. + +#### Anomalies + +* Call `controlTextDidChange(…)` as an optional method. #1406 +* Fixed issue with `NSControl.rx.value` regarding multiple observers. #1399 +* Removes useless extensions from `PrimitiveSequence`. #1248 ## [4.0.0-alpha.1](https://github.com/ReactiveX/RxSwift/releases/tag/4.0.0-alpha.1) diff --git a/RxBlocking.podspec b/RxBlocking.podspec index 31504c16f..40e28b207 100644 --- a/RxBlocking.podspec +++ b/RxBlocking.podspec @@ -1,6 +1,6 @@ Pod::Spec.new do |s| s.name = "RxBlocking" - s.version = "4.0.0-alpha.1" + s.version = "4.0.0-beta.0" s.summary = "RxSwift Blocking operatos" s.description = <<-DESC Set of blocking operators for RxSwift. These operators are mostly intended for unit/integration tests @@ -25,5 +25,5 @@ Waiting for observable sequence to complete before exiting command line applicat s.source_files = 'RxBlocking/**/*.swift', 'Platform/**/*.swift' s.exclude_files = 'RxBlocking/Platform/**/*.swift' - s.dependency 'RxSwift', '~> 4.0.0-alpha.1' + s.dependency 'RxSwift', '~> 4.0.0-beta.0' end diff --git a/RxBlocking/Info.plist b/RxBlocking/Info.plist index a8342d759..07aca14b2 100644 Binary files a/RxBlocking/Info.plist and b/RxBlocking/Info.plist differ diff --git a/RxCocoa.podspec b/RxCocoa.podspec index 8bfeed808..73526e1e6 100644 --- a/RxCocoa.podspec +++ b/RxCocoa.podspec @@ -1,6 +1,6 @@ Pod::Spec.new do |s| s.name = "RxCocoa" - s.version = "4.0.0-alpha.1" + s.version = "4.0.0-beta.0" s.summary = "RxSwift Cocoa extensions" s.description = <<-DESC * UI extensions @@ -27,5 +27,5 @@ Pod::Spec.new do |s| s.watchos.source_files = 'RxCocoa/iOS/**/*.swift' s.tvos.source_files = 'RxCocoa/iOS/**/*.swift' - s.dependency 'RxSwift', '~> 4.0.0-alpha.1' + s.dependency 'RxSwift', '~> 4.0.0-beta.0' end diff --git a/RxCocoa/Info.plist b/RxCocoa/Info.plist index a8342d759..07aca14b2 100644 Binary files a/RxCocoa/Info.plist and b/RxCocoa/Info.plist differ diff --git a/RxExample/Extensions/RxCLLocationManagerDelegateProxy.swift b/RxExample/Extensions/RxCLLocationManagerDelegateProxy.swift index c64315df6..89e42b568 100644 --- a/RxExample/Extensions/RxCLLocationManagerDelegateProxy.swift +++ b/RxExample/Extensions/RxCLLocationManagerDelegateProxy.swift @@ -12,19 +12,27 @@ import CoreLocation import RxCocoa #endif -class RxCLLocationManagerDelegateProxy +public class RxCLLocationManagerDelegateProxy : DelegateProxy , DelegateProxyType , CLLocationManagerDelegate { + public init(parentObject: CLLocationManager) { + super.init(parentObject: parentObject, delegateProxy: RxCLLocationManagerDelegateProxy.self) + } + + public static func registerKnownImplementations() { + self.register { RxCLLocationManagerDelegateProxy(parentObject: $0) } + } + internal lazy var didUpdateLocationsSubject = PublishSubject<[CLLocation]>() internal lazy var didFailWithErrorSubject = PublishSubject() - override class func currentDelegate(for object: ParentObject) -> CLLocationManagerDelegate? { + public class func currentDelegate(for object: ParentObject) -> CLLocationManagerDelegate? { return object.delegate } - override class func setCurrentDelegate(_ delegate: CLLocationManagerDelegate?, toObject object: ParentObject) { + public class func setCurrentDelegate(_ delegate: CLLocationManagerDelegate?, to object: ParentObject) { object.delegate = delegate } diff --git a/RxExample/Extensions/RxImagePickerDelegateProxy.swift b/RxExample/Extensions/RxImagePickerDelegateProxy.swift index e448747e1..1846907b0 100644 --- a/RxExample/Extensions/RxImagePickerDelegateProxy.swift +++ b/RxExample/Extensions/RxImagePickerDelegateProxy.swift @@ -16,7 +16,11 @@ open class RxImagePickerDelegateProxy : RxNavigationControllerDelegateProxy, UIImagePickerControllerDelegate { - + + public init(parentObject: UIImagePickerController) { + super.init(parentObject: parentObject) + } + } #endif diff --git a/RxExample/RxDataSources/DataSources+Rx/RxCollectionViewSectionedAnimatedDataSource.swift b/RxExample/RxDataSources/DataSources+Rx/RxCollectionViewSectionedAnimatedDataSource.swift index 33328afaf..88d3644df 100644 --- a/RxExample/RxDataSources/DataSources+Rx/RxCollectionViewSectionedAnimatedDataSource.swift +++ b/RxExample/RxDataSources/DataSources+Rx/RxCollectionViewSectionedAnimatedDataSource.swift @@ -54,7 +54,7 @@ open class RxCollectionViewSectionedAnimatedDataSource) { - UIBindingObserver(UIElement: self) { dataSource, newSections in + Binder(self) { dataSource, newSections in let oldSections = dataSource.sectionModels do { let differences = try differencesForSectionedView(oldSections, finalSections: newSections) @@ -77,7 +77,7 @@ open class RxCollectionViewSectionedAnimatedDataSource) { - UIBindingObserver(UIElement: self) { dataSource, newSections in + Binder(self) { dataSource, newSections in #if DEBUG self._dataSourceBound = true #endif diff --git a/RxExample/RxDataSources/DataSources+Rx/RxCollectionViewSectionedReloadDataSource.swift b/RxExample/RxDataSources/DataSources+Rx/RxCollectionViewSectionedReloadDataSource.swift index 1b422ad09..956369afa 100644 --- a/RxExample/RxDataSources/DataSources+Rx/RxCollectionViewSectionedReloadDataSource.swift +++ b/RxExample/RxDataSources/DataSources+Rx/RxCollectionViewSectionedReloadDataSource.swift @@ -24,7 +24,7 @@ open class RxCollectionViewSectionedReloadDataSource } open func collectionView(_ collectionView: UICollectionView, observedEvent: Event) { - UIBindingObserver(UIElement: self) { dataSource, element in + Binder(self) { dataSource, element in #if DEBUG self._dataSourceBound = true #endif diff --git a/RxExample/RxDataSources/DataSources+Rx/RxTableViewSectionedAnimatedDataSource.swift b/RxExample/RxDataSources/DataSources+Rx/RxTableViewSectionedAnimatedDataSource.swift index 96366c979..b893d3877 100644 --- a/RxExample/RxDataSources/DataSources+Rx/RxTableViewSectionedAnimatedDataSource.swift +++ b/RxExample/RxDataSources/DataSources+Rx/RxTableViewSectionedAnimatedDataSource.swift @@ -27,7 +27,7 @@ open class RxTableViewSectionedAnimatedDataSource } open func tableView(_ tableView: UITableView, observedEvent: Event) { - UIBindingObserver(UIElement: self) { dataSource, newSections in + Binder(self) { dataSource, newSections in #if DEBUG self._dataSourceBound = true #endif diff --git a/RxExample/RxDataSources/DataSources+Rx/RxTableViewSectionedReloadDataSource.swift b/RxExample/RxDataSources/DataSources+Rx/RxTableViewSectionedReloadDataSource.swift index e8bdb76bf..45af0a863 100644 --- a/RxExample/RxDataSources/DataSources+Rx/RxTableViewSectionedReloadDataSource.swift +++ b/RxExample/RxDataSources/DataSources+Rx/RxTableViewSectionedReloadDataSource.swift @@ -23,7 +23,7 @@ open class RxTableViewSectionedReloadDataSource } open func tableView(_ tableView: UITableView, observedEvent: Event) { - UIBindingObserver(UIElement: self) { dataSource, element in + Binder(self) { dataSource, element in #if DEBUG self._dataSourceBound = true #endif diff --git a/RxExample/RxExample-iOSTests/CLLocationManager+RxTests.swift b/RxExample/RxExample-iOSTests/CLLocationManager+RxTests.swift index bec261b85..33d09c0bd 100644 --- a/RxExample/RxExample-iOSTests/CLLocationManager+RxTests.swift +++ b/RxExample/RxExample-iOSTests/CLLocationManager+RxTests.swift @@ -10,6 +10,7 @@ import RxSwift import RxCocoa import XCTest import CoreLocation +import RxExample_iOS class CLLocationManagerTests : RxTest { diff --git a/RxExample/RxExample-iOSTests/Info.plist b/RxExample/RxExample-iOSTests/Info.plist index ba72822e8..e4b5a84ca 100644 --- a/RxExample/RxExample-iOSTests/Info.plist +++ b/RxExample/RxExample-iOSTests/Info.plist @@ -2,6 +2,10 @@ + NSLocationAlwaysAndWhenInUseUsageDescription + We use it + NSLocationWhenInUseUsageDescription + We use it CFBundleDevelopmentRegion en CFBundleExecutable diff --git a/RxExample/RxExample-iOSTests/RxExample_iOSTests.swift b/RxExample/RxExample-iOSTests/RxExample_iOSTests.swift index d3e3351fc..bd8890469 100644 --- a/RxExample/RxExample-iOSTests/RxExample_iOSTests.swift +++ b/RxExample/RxExample-iOSTests/RxExample_iOSTests.swift @@ -140,7 +140,7 @@ class RxExample_iOSTests This method enables using mock schedulers for while testing drivers. */ - driveOnScheduler(scheduler) { + SharingScheduler.mock(scheduler: scheduler) { let viewModel = GithubSignupViewModel2( input: ( diff --git a/RxExample/RxExample-iOSTests/UIImagePickerController+RxTests.swift b/RxExample/RxExample-iOSTests/UIImagePickerController+RxTests.swift index 3a393c138..d5dad3da7 100644 --- a/RxExample/RxExample-iOSTests/UIImagePickerController+RxTests.swift +++ b/RxExample/RxExample-iOSTests/UIImagePickerController+RxTests.swift @@ -14,6 +14,7 @@ import RxSwift import RxCocoa import XCTest import UIKit +import RxExample_iOS class UIImagePickerControllerTests: RxTest { diff --git a/RxExample/RxExample.xcodeproj/project.pbxproj b/RxExample/RxExample.xcodeproj/project.pbxproj index 8ac25ec21..6e7476fbe 100644 --- a/RxExample/RxExample.xcodeproj/project.pbxproj +++ b/RxExample/RxExample.xcodeproj/project.pbxproj @@ -122,9 +122,6 @@ C886A6911D85AD7E00653EE4 /* CLLocationManager+RxTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = C886A6901D85AD7E00653EE4 /* CLLocationManager+RxTests.swift */; }; C886A6931D85ADA100653EE4 /* UIImagePickerController+RxTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = C886A6921D85ADA100653EE4 /* UIImagePickerController+RxTests.swift */; }; C886A6951D85AEA300653EE4 /* RxTest.swift in Sources */ = {isa = PBXBuildFile; fileRef = C886A6941D85AEA300653EE4 /* RxTest.swift */; }; - C886A6991D85B0E400653EE4 /* CLLocationManager+Rx.swift in Sources */ = {isa = PBXBuildFile; fileRef = C886A68C1D85AD2000653EE4 /* CLLocationManager+Rx.swift */; }; - C886A69A1D85B0E400653EE4 /* RxCLLocationManagerDelegateProxy.swift in Sources */ = {isa = PBXBuildFile; fileRef = C886A68D1D85AD2000653EE4 /* RxCLLocationManagerDelegateProxy.swift */; }; - C886A69B1D85B0E500653EE4 /* UIImagePickerController+Rx.swift in Sources */ = {isa = PBXBuildFile; fileRef = C886A68A1D85AC9400653EE4 /* UIImagePickerController+Rx.swift */; }; C88BB8BB1B07E6C90064D411 /* SearchResultViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = C86E2F321AE5A0CA00C31024 /* SearchResultViewModel.swift */; }; C88BB8BC1B07E6C90064D411 /* HtmlParsing.swift in Sources */ = {isa = PBXBuildFile; fileRef = C83367111AD029AE00C668A7 /* HtmlParsing.swift */; }; C88BB8BE1B07E6C90064D411 /* ImageService.swift in Sources */ = {isa = PBXBuildFile; fileRef = C83367121AD029AE00C668A7 /* ImageService.swift */; }; @@ -136,7 +133,6 @@ C88BB8CC1B07E6C90064D411 /* WikipediaPage.swift in Sources */ = {isa = PBXBuildFile; fileRef = C86E2F3C1AE5A0CA00C31024 /* WikipediaPage.swift */; }; C88C2B2A1D67EC5200B01A98 /* FlowTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = C88C2B291D67EC5200B01A98 /* FlowTests.swift */; }; C88CB7261D8F253D0021D83F /* RxImagePickerDelegateProxy.swift in Sources */ = {isa = PBXBuildFile; fileRef = C88CB7251D8F253D0021D83F /* RxImagePickerDelegateProxy.swift */; }; - C88CB73B1D8F25440021D83F /* RxImagePickerDelegateProxy.swift in Sources */ = {isa = PBXBuildFile; fileRef = C88CB7251D8F253D0021D83F /* RxImagePickerDelegateProxy.swift */; }; C890A65D1AEC084100AFF7E6 /* ViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = C890A65C1AEC084100AFF7E6 /* ViewController.swift */; }; C89634081B95BE50002AE38C /* RxBlocking.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = C8A468EF1B8A8BD000BF917B /* RxBlocking.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; }; C89634091B95BE50002AE38C /* RxCocoa.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = C8A468ED1B8A8BCC00BF917B /* RxCocoa.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; }; @@ -1558,13 +1554,10 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( - C886A6991D85B0E400653EE4 /* CLLocationManager+Rx.swift in Sources */, C89C2BD61C321DA200EBC99C /* TestScheduler+MarbleTests.swift in Sources */, C886A6951D85AEA300653EE4 /* RxTest.swift in Sources */, C849EF901C319E9A0048AC4A /* GithubSignupViewModel1.swift in Sources */, C849EF641C3190360048AC4A /* RxExample_iOSTests.swift in Sources */, - C886A69B1D85B0E500653EE4 /* UIImagePickerController+Rx.swift in Sources */, - C88CB73B1D8F25440021D83F /* RxImagePickerDelegateProxy.swift in Sources */, C886A6911D85AD7E00653EE4 /* CLLocationManager+RxTests.swift in Sources */, C849EF921C319E9A0048AC4A /* DefaultImplementations.swift in Sources */, C849EF991C31A63C0048AC4A /* Wireframe.swift in Sources */, @@ -1573,7 +1566,6 @@ C849EF9A1C31A7680048AC4A /* ActivityIndicator.swift in Sources */, C849EF951C319E9D0048AC4A /* GithubSignupViewModel2.swift in Sources */, C886A6931D85ADA100653EE4 /* UIImagePickerController+RxTests.swift in Sources */, - C886A69A1D85B0E400653EE4 /* RxCLLocationManagerDelegateProxy.swift in Sources */, C89C2BDD1C32231A00EBC99C /* MockWireframe.swift in Sources */, C89C2BDF1C32231A00EBC99C /* ValidationResult+Equatable.swift in Sources */, C849EF911C319E9A0048AC4A /* Protocols.swift in Sources */, diff --git a/RxExample/RxExample.xcodeproj/xcshareddata/xcschemes/RxExample-iOSTests.xcscheme b/RxExample/RxExample.xcodeproj/xcshareddata/xcschemes/RxExample-iOSTests.xcscheme index 2235c4bd9..41f6f34f9 100644 --- a/RxExample/RxExample.xcodeproj/xcshareddata/xcschemes/RxExample-iOSTests.xcscheme +++ b/RxExample/RxExample.xcodeproj/xcshareddata/xcschemes/RxExample-iOSTests.xcscheme @@ -10,6 +10,7 @@ buildConfiguration = "Debug" selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB" selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB" + language = "" shouldUseLaunchSchemeArgsEnv = "YES"> { - return UIBindingObserver(UIElement: base) { label, location in + var coordinates: Binder { + return Binder(base) { label, location in label.text = "Lat: \(location.latitude)\nLon: \(location.longitude)" } } diff --git a/RxExample/RxExample/Examples/GitHubSearchRepositories/UINavigationController+Extensions.swift b/RxExample/RxExample/Examples/GitHubSearchRepositories/UINavigationController+Extensions.swift index 4abc4e197..aefdf3915 100644 --- a/RxExample/RxExample/Examples/GitHubSearchRepositories/UINavigationController+Extensions.swift +++ b/RxExample/RxExample/Examples/GitHubSearchRepositories/UINavigationController+Extensions.swift @@ -16,8 +16,8 @@ struct Colors { } extension Reactive where Base: UINavigationController { - var isOffline: UIBindingObserver { - return UIBindingObserver(UIElement: base) { navigationController, isOffline in + var isOffline: Binder { + return Binder(base) { navigationController, isOffline in navigationController.navigationBar.barTintColor = isOffline ? Colors.offlineColor : Colors.onlineColor diff --git a/RxExample/RxExample/Examples/GitHubSignup/BindingExtensions.swift b/RxExample/RxExample/Examples/GitHubSignup/BindingExtensions.swift index 0cfefe534..03568c58a 100644 --- a/RxExample/RxExample/Examples/GitHubSignup/BindingExtensions.swift +++ b/RxExample/RxExample/Examples/GitHubSignup/BindingExtensions.swift @@ -48,8 +48,8 @@ extension ValidationResult { } extension Reactive where Base: UILabel { - var validationResult: UIBindingObserver { - return UIBindingObserver(UIElement: base) { label, result in + var validationResult: Binder { + return Binder(base) { label, result in label.textColor = result.textColor label.text = result.description } diff --git a/RxExample/RxExample/Examples/UIPickerViewExample/CustomPickerViewAdapterExampleViewController.swift b/RxExample/RxExample/Examples/UIPickerViewExample/CustomPickerViewAdapterExampleViewController.swift index ffae0c442..5a39ce063 100644 --- a/RxExample/RxExample/Examples/UIPickerViewExample/CustomPickerViewAdapterExampleViewController.swift +++ b/RxExample/RxExample/Examples/UIPickerViewExample/CustomPickerViewAdapterExampleViewController.swift @@ -61,10 +61,10 @@ final class PickerViewViewAdapter } func pickerView(_ pickerView: UIPickerView, observedEvent: Event) { - UIBindingObserver(UIElement: self) { (adapter, items) in + Binder(self) { (adapter, items) in adapter.items = items pickerView.reloadAllComponents() - }.on(observedEvent) + }.on(observedEvent) } } diff --git a/RxExample/RxExample/Info-iOS.plist b/RxExample/RxExample/Info-iOS.plist index 0e6f54c99..061288de6 100644 --- a/RxExample/RxExample/Info-iOS.plist +++ b/RxExample/RxExample/Info-iOS.plist @@ -2,6 +2,8 @@ + NSLocationWhenInUseUsageDescription + We need location CFBundleDevelopmentRegion en CFBundleExecutable diff --git a/RxExample/RxExample/Services/UIImageView+DownloadableImage.swift b/RxExample/RxExample/Services/UIImageView+DownloadableImage.swift index c8daa0387..9f9abb123 100644 --- a/RxExample/RxExample/Services/UIImageView+DownloadableImage.swift +++ b/RxExample/RxExample/Services/UIImageView+DownloadableImage.swift @@ -15,12 +15,12 @@ import UIKit extension Reactive where Base: UIImageView { - var downloadableImage: UIBindingObserver{ + var downloadableImage: Binder{ return downloadableImageAnimated(nil) } - func downloadableImageAnimated(_ transitionType:String?) -> UIBindingObserver { - return UIBindingObserver(UIElement: base) { imageView, image in + func downloadableImageAnimated(_ transitionType:String?) -> Binder { + return Binder(base) { imageView, image in for subview in imageView.subviews { subview.removeFromSuperview() } diff --git a/RxExample/RxExample/iOS/AppDelegate.swift b/RxExample/RxExample/iOS/AppDelegate.swift index f2c5c2651..068a0c7a4 100644 --- a/RxExample/RxExample/iOS/AppDelegate.swift +++ b/RxExample/RxExample/iOS/AppDelegate.swift @@ -18,9 +18,8 @@ class AppDelegate: UIResponder, UIApplicationDelegate { if UIApplication.isInUITest { UIView.setAnimationsEnabled(false) } - - // Install delegate proxy - RxImagePickerDelegateProxy.register(for: UIImagePickerController.self) + + RxImagePickerDelegateProxy.register { RxImagePickerDelegateProxy(parentObject: $0) } #if DEBUG _ = Observable.interval(1, scheduler: MainScheduler.instance) diff --git a/RxSwift.podspec b/RxSwift.podspec index 34c133dec..e15575631 100644 --- a/RxSwift.podspec +++ b/RxSwift.podspec @@ -1,6 +1,6 @@ Pod::Spec.new do |s| s.name = "RxSwift" - s.version = "4.0.0-alpha.1" + s.version = "4.0.0-beta.0" s.summary = "RxSwift is a Swift implementation of Reactive Extensions" s.description = <<-DESC This is a Swift port of [ReactiveX.io](https://github.com/ReactiveX) diff --git a/RxSwift/Info.plist b/RxSwift/Info.plist index 8b2195f93..07aca14b2 100644 --- a/RxSwift/Info.plist +++ b/RxSwift/Info.plist @@ -15,7 +15,7 @@ CFBundlePackageType FMWK CFBundleShortVersionString - 4.0.0-alpha.1 + 4.0.0-beta.0 CFBundleSignature ???? CFBundleVersion diff --git a/RxTest.podspec b/RxTest.podspec index 2bd0958ed..15a7ed3e2 100644 --- a/RxTest.podspec +++ b/RxTest.podspec @@ -1,6 +1,6 @@ Pod::Spec.new do |s| s.name = "RxTest" - s.version = "4.0.0-alpha.1" + s.version = "4.0.0-beta.0" s.summary = "RxSwift Testing extensions" s.description = <<-DESC Unit testing extensions for RxSwift. This library contains mock schedulers, observables, and observers @@ -56,7 +56,7 @@ func testMap() { s.framework = 'XCTest' - s.dependency 'RxSwift', '~> 4.0.0-alpha.1' + s.dependency 'RxSwift', '~> 4.0.0-beta.0' s.pod_target_xcconfig = { 'ENABLE_BITCODE' => 'NO' } end diff --git a/RxTest/Info.plist b/RxTest/Info.plist index a8342d759..07aca14b2 100644 Binary files a/RxTest/Info.plist and b/RxTest/Info.plist differ diff --git a/Sources/AllTestz/PrimitiveSequenceTest.swift b/Sources/AllTestz/PrimitiveSequenceTest.swift deleted file mode 120000 index ad2f1901c..000000000 --- a/Sources/AllTestz/PrimitiveSequenceTest.swift +++ /dev/null @@ -1 +0,0 @@ -../../Tests/RxSwiftTests/PrimitiveSequenceTest.swift \ No newline at end of file diff --git a/Sources/AllTestz/main.swift b/Sources/AllTestz/main.swift index 7c79c4eff..0367a0d03 100644 --- a/Sources/AllTestz/main.swift +++ b/Sources/AllTestz/main.swift @@ -81,88 +81,6 @@ final class ObservableTakeLastTest_ : ObservableTakeLastTest, RxTestCase { ] } } -final class PrimitiveSequenceTest_ : PrimitiveSequenceTest, RxTestCase { - #if os(macOS) - required override init() { - super.init() - } - #endif - - static var allTests: [(String, (PrimitiveSequenceTest_) -> () -> ())] { return [ - ("testSingle_Subscription_success", PrimitiveSequenceTest.testSingle_Subscription_success), - ("testSingle_Subscription_error", PrimitiveSequenceTest.testSingle_Subscription_error), - ("testSingle_create_success", PrimitiveSequenceTest.testSingle_create_success), - ("testSingle_create_error", PrimitiveSequenceTest.testSingle_create_error), - ("testSingle_create_disposing", PrimitiveSequenceTest.testSingle_create_disposing), - ("testMaybe_Subscription_success", PrimitiveSequenceTest.testMaybe_Subscription_success), - ("testMaybe_Subscription_completed", PrimitiveSequenceTest.testMaybe_Subscription_completed), - ("testMaybe_Subscription_error", PrimitiveSequenceTest.testMaybe_Subscription_error), - ("testMaybe_create_success", PrimitiveSequenceTest.testMaybe_create_success), - ("testMaybe_create_completed", PrimitiveSequenceTest.testMaybe_create_completed), - ("testMaybe_create_error", PrimitiveSequenceTest.testMaybe_create_error), - ("testMaybe_create_disposing", PrimitiveSequenceTest.testMaybe_create_disposing), - ("testCompletable_Subscription_completed", PrimitiveSequenceTest.testCompletable_Subscription_completed), - ("testCompletable_Subscription_error", PrimitiveSequenceTest.testCompletable_Subscription_error), - ("testCompletable_create_completed", PrimitiveSequenceTest.testCompletable_create_completed), - ("testCompletable_create_error", PrimitiveSequenceTest.testCompletable_create_error), - ("testCompletable_create_disposing", PrimitiveSequenceTest.testCompletable_create_disposing), - ("testSingle_deferred_producesSingleElement", PrimitiveSequenceTest.testSingle_deferred_producesSingleElement), - ("testSingle_just_producesSingleElement", PrimitiveSequenceTest.testSingle_just_producesSingleElement), - ("testSingle_just2_producesSingleElement", PrimitiveSequenceTest.testSingle_just2_producesSingleElement), - ("testSingle_error_fails", PrimitiveSequenceTest.testSingle_error_fails), - ("testSingle_never_producesSingleElement", PrimitiveSequenceTest.testSingle_never_producesSingleElement), - ("testSingle_delaySubscription_producesSingleElement", PrimitiveSequenceTest.testSingle_delaySubscription_producesSingleElement), - ("testSingle_delay_producesSingleElement", PrimitiveSequenceTest.testSingle_delay_producesSingleElement), - ("testSingle_do_producesSingleElement", PrimitiveSequenceTest.testSingle_do_producesSingleElement), - ("testSingle_filter_resultIsMaybe", PrimitiveSequenceTest.testSingle_filter_resultIsMaybe), - ("testSingle_map_producesSingleElement", PrimitiveSequenceTest.testSingle_map_producesSingleElement), - ("testSingle_flatMap_producesSingleElement", PrimitiveSequenceTest.testSingle_flatMap_producesSingleElement), - ("testSingle_observeOn_producesSingleElement", PrimitiveSequenceTest.testSingle_observeOn_producesSingleElement), - ("testSingle_subscribeOn_producesSingleElement", PrimitiveSequenceTest.testSingle_subscribeOn_producesSingleElement), - ("testSingle_catchError_producesSingleElement", PrimitiveSequenceTest.testSingle_catchError_producesSingleElement), - ("testSingle_retry_producesSingleElement", PrimitiveSequenceTest.testSingle_retry_producesSingleElement), - ("testSingle_retryWhen1_producesSingleElement", PrimitiveSequenceTest.testSingle_retryWhen1_producesSingleElement), - ("testSingle_retryWhen2_producesSingleElement", PrimitiveSequenceTest.testSingle_retryWhen2_producesSingleElement), - ("testSingle_timer_producesSingleElement", PrimitiveSequenceTest.testSingle_timer_producesSingleElement), - ("testSingle_using_producesSingleElement", PrimitiveSequenceTest.testSingle_using_producesSingleElement), - ("testSingle_timeout", PrimitiveSequenceTest.testSingle_timeout), - ("testSingle_timeout_other", PrimitiveSequenceTest.testSingle_timeout_other), - ("testMaybe_timeout", PrimitiveSequenceTest.testMaybe_timeout), - ("testMaybe_timeout_other", PrimitiveSequenceTest.testMaybe_timeout_other), - ("testCompletable_timeout", PrimitiveSequenceTest.testCompletable_timeout), - ("testCompletable_timeout_other", PrimitiveSequenceTest.testCompletable_timeout_other), - ("testCompletable_timeout_succeeds", PrimitiveSequenceTest.testCompletable_timeout_succeeds), - ("testCompletable_timeout_other_succeeds", PrimitiveSequenceTest.testCompletable_timeout_other_succeeds), - ("testAsSingle_Empty", PrimitiveSequenceTest.testAsSingle_Empty), - ("testAsSingle_One", PrimitiveSequenceTest.testAsSingle_One), - ("testAsSingle_Many", PrimitiveSequenceTest.testAsSingle_Many), - ("testAsSingle_Error", PrimitiveSequenceTest.testAsSingle_Error), - ("testAsSingle_Error2", PrimitiveSequenceTest.testAsSingle_Error2), - ("testAsSingle_subscribeOnSuccess", PrimitiveSequenceTest.testAsSingle_subscribeOnSuccess), - ("testAsSingle_subscribeOnError", PrimitiveSequenceTest.testAsSingle_subscribeOnError), - ("testFirst_Empty", PrimitiveSequenceTest.testFirst_Empty), - ("testFirst_One", PrimitiveSequenceTest.testFirst_One), - ("testFirst_Many", PrimitiveSequenceTest.testFirst_Many), - ("testFirst_ManyWithoutCompletion", PrimitiveSequenceTest.testFirst_ManyWithoutCompletion), - ("testFirst_Error", PrimitiveSequenceTest.testFirst_Error), - ("testAsMaybe_Empty", PrimitiveSequenceTest.testAsMaybe_Empty), - ("testAsMaybe_One", PrimitiveSequenceTest.testAsMaybe_One), - ("testAsMaybe_Many", PrimitiveSequenceTest.testAsMaybe_Many), - ("testAsMaybe_Error", PrimitiveSequenceTest.testAsMaybe_Error), - ("testAsMaybe_Error2", PrimitiveSequenceTest.testAsMaybe_Error2), - ("testAsMaybe_subscribeOnSuccess", PrimitiveSequenceTest.testAsMaybe_subscribeOnSuccess), - ("testAsMaybe_subscribeOnError", PrimitiveSequenceTest.testAsMaybe_subscribeOnError), - ("testAsMaybe_subscribeOnCompleted", PrimitiveSequenceTest.testAsMaybe_subscribeOnCompleted), - ("testAsCompletable_Empty", PrimitiveSequenceTest.testAsCompletable_Empty), - ("testAsCompletable_Error", PrimitiveSequenceTest.testAsCompletable_Error), - ("testAsCompletable_subscribeOnCompleted", PrimitiveSequenceTest.testAsCompletable_subscribeOnCompleted), - ("testAsCompletable_subscribeOnError", PrimitiveSequenceTest.testAsCompletable_subscribeOnError), - ("testCompletable_merge", PrimitiveSequenceTest.testCompletable_merge), - ("testCompletable_concat", PrimitiveSequenceTest.testCompletable_concat), - ("testDebug_producesSingleElement", PrimitiveSequenceTest.testDebug_producesSingleElement), - ] } -} - final class VirtualSchedulerTest_ : VirtualSchedulerTest, RxTestCase { #if os(macOS) required override init() { @@ -2050,7 +1968,6 @@ func XCTMain(_ tests: [() -> ()]) { testCase(ObservableOptionalTest_.allTests), testCase(AnomaliesTest_.allTests), testCase(ObservableTakeLastTest_.allTests), - testCase(PrimitiveSequenceTest_.allTests), testCase(VirtualSchedulerTest_.allTests), testCase(ObservableBlockingTest_.allTests), testCase(ObservableRetryWhenTest_.allTests), diff --git a/Tests/RxCocoaTests/NSButton+RxTests.swift b/Tests/RxCocoaTests/NSButton+RxTests.swift index 28989a3f1..56c916d38 100644 --- a/Tests/RxCocoaTests/NSButton+RxTests.swift +++ b/Tests/RxCocoaTests/NSButton+RxTests.swift @@ -75,40 +75,4 @@ extension NSButtonTests { XCTAssertEqual(value1, NSControl.StateValue.on) XCTAssertEqual(value2, NSControl.StateValue.on) } - - func testButton_multipleObservers() { - let button = NSButton(frame: CGRect(x: 0, y: 0, width: 1, height: 1)) - var value1: Int? = nil - var value2: Int? = nil - - var numberOfTimesReceivedValue = 0 - - _ = Observable.just(NSOffState).bind(to: button.rx.state) - let d1 = button.rx.state.subscribe(onNext: { numberOfTimesReceivedValue += 1; value1 = $0 }) - let d2 = button.rx.state.subscribe(onNext: { numberOfTimesReceivedValue += 1; value2 = $0 }) - _ = Observable.just(NSOnState).bind(to: button.rx.state) - - if let target = button.target, let action = button.action { - _ = target.perform(action, with: button) - } - - - XCTAssertEqual(button.state, NSOnState) - XCTAssertEqual(value1, NSOnState) - XCTAssertEqual(value2, NSOnState) - - XCTAssertEqual(numberOfTimesReceivedValue, 4) - - d1.dispose() - d2.dispose() - - _ = button.rx.state.subscribe(onNext: { numberOfTimesReceivedValue += 1; value1 = $0 }) - _ = button.rx.state.subscribe(onNext: { numberOfTimesReceivedValue += 1; value2 = $0 }) - - XCTAssertEqual(numberOfTimesReceivedValue, 6) - - XCTAssertEqual(button.state, NSOnState) - XCTAssertEqual(value1, NSOnState) - XCTAssertEqual(value2, NSOnState) - } } diff --git a/Tests/RxSwiftTests/PrimitiveSequenceTest.swift b/Tests/RxSwiftTests/PrimitiveSequenceTest.swift deleted file mode 100644 index 5bc9a154e..000000000 --- a/Tests/RxSwiftTests/PrimitiveSequenceTest.swift +++ /dev/null @@ -1,1538 +0,0 @@ -// -// PrimitiveSequenceTest.swift -// Tests -// -// Created by Krunoslav Zaher on 3/11/17. -// Copyright © 2017 Krunoslav Zaher. All rights reserved. -// - -import XCTest -import RxSwift -import RxTest - -class PrimitiveSequenceTest : RxTest { - -} - -// single -extension PrimitiveSequenceTest { - func testSingle_Subscription_success() { - let xs = Single.just(1) - - var events: [SingleEvent] = [] - - _ = xs.subscribe { event in - events.append(event) - } - - XCTAssertEqual(events, [.success(1)]) - } - - func testSingle_Subscription_error() { - let xs = Single.error(testError) - - var events: [SingleEvent] = [] - - _ = xs.subscribe { event in - events.append(event) - } - - XCTAssertEqual(events, [.error(testError)]) - } - - func testSingle_create_success() { - let scheduler = TestScheduler(initialClock: 0) - - var observer: ((SingleEvent) -> ())! = nil - - var disposedTime: Int? = nil - - scheduler.scheduleAt(201, action: { - observer(.success(1)) - }) - scheduler.scheduleAt(202, action: { - observer(.success(1)) - }) - scheduler.scheduleAt(203, action: { - observer(.error(testError)) - }) - - let res = scheduler.start { - Single.create { _observer in - observer = _observer - return Disposables.create { - disposedTime = scheduler.clock - } - }.asObservable() - } - - XCTAssertEqual(res.events, [ - next(201, 1), - completed(201) - ]) - - XCTAssertEqual(disposedTime, 201) - } - - func testSingle_create_error() { - let scheduler = TestScheduler(initialClock: 0) - - var observer: ((SingleEvent) -> ())! = nil - - var disposedTime: Int? = nil - - scheduler.scheduleAt(201, action: { - observer(.error(testError)) - }) - scheduler.scheduleAt(202, action: { - observer(.success(1)) - }) - scheduler.scheduleAt(203, action: { - observer(.error(testError)) - }) - - let res = scheduler.start { - Single.create { _observer in - observer = _observer - return Disposables.create { - disposedTime = scheduler.clock - } - }.asObservable() - } - - XCTAssertEqual(res.events, [ - error(201, testError) - ]) - - XCTAssertEqual(disposedTime, 201) - } - - func testSingle_create_disposing() { - let scheduler = TestScheduler(initialClock: 0) - - var observer: ((SingleEvent) -> ())! = nil - var disposedTime: Int? = nil - var subscription: Disposable! = nil - let res = scheduler.createObserver(Int.self) - - scheduler.scheduleAt(201, action: { - subscription = Single.create { _observer in - observer = _observer - return Disposables.create { - disposedTime = scheduler.clock - } - } - .asObservable() - .subscribe(res) - }) - scheduler.scheduleAt(202, action: { - subscription.dispose() - }) - scheduler.scheduleAt(203, action: { - observer(.success(1)) - }) - scheduler.scheduleAt(204, action: { - observer(.error(testError)) - }) - - scheduler.start() - - XCTAssertEqual(res.events, [ - ]) - - XCTAssertEqual(disposedTime, 202) - } -} - -// maybe -extension PrimitiveSequenceTest { - func testMaybe_Subscription_success() { - let xs = Maybe.just(1) - - var events: [MaybeEvent] = [] - - _ = xs.subscribe { event in - events.append(event) - } - - XCTAssertEqual(events, [.success(1)]) - } - - func testMaybe_Subscription_completed() { - let xs = Maybe.empty() - - var events: [MaybeEvent] = [] - - _ = xs.subscribe { event in - events.append(event) - } - - XCTAssertEqual(events, [.completed]) - } - - func testMaybe_Subscription_error() { - let xs = Maybe.error(testError) - - var events: [MaybeEvent] = [] - - _ = xs.subscribe { event in - events.append(event) - } - - XCTAssertEqual(events, [.error(testError)]) - } - - func testMaybe_create_success() { - let scheduler = TestScheduler(initialClock: 0) - - var observer: ((MaybeEvent) -> ())! = nil - - var disposedTime: Int? = nil - - scheduler.scheduleAt(201, action: { - observer(.success(1)) - }) - scheduler.scheduleAt(202, action: { - observer(.success(1)) - }) - scheduler.scheduleAt(203, action: { - observer(.error(testError)) - }) - scheduler.scheduleAt(204, action: { - observer(.completed) - }) - - let res = scheduler.start { - Maybe.create { _observer in - observer = _observer - return Disposables.create { - disposedTime = scheduler.clock - } - }.asObservable() - } - - XCTAssertEqual(res.events, [ - next(201, 1), - completed(201) - ]) - - XCTAssertEqual(disposedTime, 201) - } - - func testMaybe_create_completed() { - let scheduler = TestScheduler(initialClock: 0) - - var observer: ((MaybeEvent) -> ())! = nil - - var disposedTime: Int? = nil - - scheduler.scheduleAt(201, action: { - observer(.completed) - }) - scheduler.scheduleAt(202, action: { - observer(.success(1)) - }) - scheduler.scheduleAt(203, action: { - observer(.error(testError)) - }) - scheduler.scheduleAt(204, action: { - observer(.completed) - }) - - let res = scheduler.start { - Maybe.create { _observer in - observer = _observer - return Disposables.create { - disposedTime = scheduler.clock - } - }.asObservable() - } - - XCTAssertEqual(res.events, [ - completed(201) - ]) - - XCTAssertEqual(disposedTime, 201) - } - - func testMaybe_create_error() { - let scheduler = TestScheduler(initialClock: 0) - - var observer: ((MaybeEvent) -> ())! = nil - - var disposedTime: Int? = nil - - scheduler.scheduleAt(201, action: { - observer(.error(testError)) - }) - scheduler.scheduleAt(202, action: { - observer(.success(1)) - }) - scheduler.scheduleAt(203, action: { - observer(.error(testError)) - }) - - let res = scheduler.start { - Maybe.create { _observer in - observer = _observer - return Disposables.create { - disposedTime = scheduler.clock - } - }.asObservable() - } - - XCTAssertEqual(res.events, [ - error(201, testError) - ]) - - XCTAssertEqual(disposedTime, 201) - } - - func testMaybe_create_disposing() { - let scheduler = TestScheduler(initialClock: 0) - - var observer: ((MaybeEvent) -> ())! = nil - var disposedTime: Int? = nil - var subscription: Disposable! = nil - let res = scheduler.createObserver(Int.self) - - scheduler.scheduleAt(201, action: { - subscription = Maybe.create { _observer in - observer = _observer - return Disposables.create { - disposedTime = scheduler.clock - } - } - .asObservable() - .subscribe(res) - }) - scheduler.scheduleAt(202, action: { - subscription.dispose() - }) - scheduler.scheduleAt(203, action: { - observer(.success(1)) - }) - scheduler.scheduleAt(204, action: { - observer(.error(testError)) - }) - - scheduler.start() - - XCTAssertEqual(res.events, [ - ]) - - XCTAssertEqual(disposedTime, 202) - } -} - -// completable -extension PrimitiveSequenceTest { - func testCompletable_Subscription_completed() { - let xs = Completable.empty() - - var events: [CompletableEvent] = [] - - _ = xs.subscribe { event in - events.append(event) - } - - XCTAssertEqual(events, [.completed]) - } - - func testCompletable_Subscription_error() { - let xs = Completable.error(testError) - - var events: [CompletableEvent] = [] - - _ = xs.subscribe { event in - events.append(event) - } - - XCTAssertEqual(events, [.error(testError)]) - } - - func testCompletable_create_completed() { - let scheduler = TestScheduler(initialClock: 0) - - var observer: ((CompletableEvent) -> ())! = nil - - var disposedTime: Int? = nil - - scheduler.scheduleAt(201, action: { - observer(.completed) - }) - scheduler.scheduleAt(203, action: { - observer(.error(testError)) - }) - scheduler.scheduleAt(204, action: { - observer(.completed) - }) - - let res = scheduler.start { - Completable.create { _observer in - observer = _observer - return Disposables.create { - disposedTime = scheduler.clock - } - }.asObservable() - } - - XCTAssertEqual(res.events, [ - completed(201, Never.self) - ]) - - XCTAssertEqual(disposedTime, 201) - } - - func testCompletable_create_error() { - let scheduler = TestScheduler(initialClock: 0) - - var observer: ((CompletableEvent) -> ())! = nil - - var disposedTime: Int? = nil - - scheduler.scheduleAt(201, action: { - observer(.error(testError)) - }) - scheduler.scheduleAt(202, action: { - observer(.completed) - }) - scheduler.scheduleAt(203, action: { - observer(.error(testError)) - }) - - let res = scheduler.start { - Completable.create { _observer in - observer = _observer - return Disposables.create { - disposedTime = scheduler.clock - } - }.asObservable() - } - - XCTAssertEqual(res.events, [ - error(201, testError) - ]) - - XCTAssertEqual(disposedTime, 201) - } - - func testCompletable_create_disposing() { - let scheduler = TestScheduler(initialClock: 0) - - var observer: ((CompletableEvent) -> ())! = nil - var disposedTime: Int? = nil - var subscription: Disposable! = nil - let res = scheduler.createObserver(Never.self) - - scheduler.scheduleAt(201, action: { - subscription = Completable.create { _observer in - observer = _observer - return Disposables.create { - disposedTime = scheduler.clock - } - } - .asObservable() - .subscribe(res) - }) - scheduler.scheduleAt(202, action: { - subscription.dispose() - }) - scheduler.scheduleAt(203, action: { - observer(.completed) - }) - scheduler.scheduleAt(204, action: { - observer(.error(testError)) - }) - - scheduler.start() - - XCTAssertEqual(res.events, [ - ]) - - XCTAssertEqual(disposedTime, 202) - } -} - -// single operators -extension PrimitiveSequenceTest { - func testSingle_deferred_producesSingleElement() { - let result = try! (Single.deferred { Single.just(1) } as Single).toBlocking().first()! - XCTAssertEqual(result, 1) - } - - func testSingle_just_producesSingleElement() { - let result = try! (Single.just(1) as Single).toBlocking().first()! - XCTAssertEqual(result, 1) - } - - func testSingle_just2_producesSingleElement() { - let result = try! (Single.just(1, scheduler: CurrentThreadScheduler.instance) as Single).toBlocking().first()! - XCTAssertEqual(result, 1) - } - - func testSingle_error_fails() { - do { - _ = try (Single.error(testError) as Single).toBlocking().first() - XCTFail() - } - catch let e { - XCTAssertEqual(e as! TestError, testError) - } - } - - func testSingle_never_producesSingleElement() { - var event: SingleEvent? = nil - let subscription = (Single.never() as Single).subscribe { _event in - event = _event - } - - XCTAssertNil(event) - subscription.dispose() - } - - func testSingle_delaySubscription_producesSingleElement() { - let scheduler = TestScheduler(initialClock: 0) - - let res = scheduler.start { - (Single.just(1).delaySubscription(1.0, scheduler: scheduler) as Single).asObservable() - } - - XCTAssertEqual(res.events, [ - next(201, 1), - completed(201) - ]) - } - - func testSingle_delay_producesSingleElement() { - let scheduler = TestScheduler(initialClock: 0) - - let res = scheduler.start { - (Single.just(1) - .delay(1.0, scheduler: scheduler) as Single).asObservable() - } - - XCTAssertEqual(res.events, [ - next(201, 1), - completed(202) - ]) - } - - func testSingle_do_producesSingleElement() { - let singleResult: Single = Single.just(1) - .do() - - let result = try! singleResult - .toBlocking().first()! - XCTAssertEqual(result, 1) - } - - func testSingle_filter_resultIsMaybe() { - let filterResult: Maybe = Single.just(1) - .filter { _ in false } - - XCTAssertNil(try! filterResult.toBlocking().first()) - } - - func testSingle_map_producesSingleElement() { - let singleResult: Single = Single.just(1) - .map { $0 * 2 } - - let result = try! singleResult - .toBlocking().first()! - XCTAssertEqual(result, 2) - } - - func testSingle_flatMap_producesSingleElement() { - let singleResult: Single = Single.just(1) - .flatMap { Single.just($0 * 2) } - - let result = try! singleResult - .toBlocking().first()! - XCTAssertEqual(result, 2) - } - - func testSingle_observeOn_producesSingleElement() { - let scheduler = TestScheduler(initialClock: 0) - - let res = scheduler.start { () -> Observable in - let singleResult: Single = Single.just(1) - .observeOn(scheduler) - - return singleResult.asObservable() - } - - XCTAssertEqual(res.events, [ - next(201, 1), - completed(202) - ]) - } - - func testSingle_subscribeOn_producesSingleElement() { - let scheduler = TestScheduler(initialClock: 0) - - let res = scheduler.start { () -> Observable in - let singleResult: Single = Single.just(1) - .subscribeOn(scheduler) - - return singleResult.asObservable() - } - - XCTAssertEqual(res.events, [ - next(201, 1), - completed(201) - ]) - } - - func testSingle_catchError_producesSingleElement() { - let singleResult: Single = Single.error(testError) - .catchError { _ in Single.just(2) } - - let result = try! singleResult - .toBlocking().first()! - XCTAssertEqual(result, 2) - } - - func testSingle_retry_producesSingleElement() { - var isFirst = true - let singleResult: Single = Single.error(testError) - .catchError { e in - defer { - isFirst = false - } - if isFirst { - return Single.error(e) - } - - return Single.just(2) - } - .retry(2) - - let result = try! singleResult - .toBlocking().first()! - XCTAssertEqual(result, 2) - } - - func testSingle_retryWhen1_producesSingleElement() { - var isFirst = true - let singleResult: Single = Single.error(testError) - .catchError { e in - defer { - isFirst = false - } - if isFirst { - return Single.error(e) - } - - return Single.just(2) - } - .retryWhen { (e: Observable) in - return e - } - - let result = try! singleResult - .toBlocking().first()! - XCTAssertEqual(result, 2) - } - - func testSingle_retryWhen2_producesSingleElement() { - var isFirst = true - let singleResult: Single = Single.error(testError) - .catchError { e in - defer { - isFirst = false - } - if isFirst { - return Single.error(e) - } - - return Single.just(2) - } - .retryWhen { (e: Observable) in - return e - } - - let result = try! singleResult - .toBlocking().first()! - XCTAssertEqual(result, 2) - } - - func testSingle_timer_producesSingleElement() { - let scheduler = TestScheduler(initialClock: 0) - - let res = scheduler.start { () -> Observable in - let singleResult: Single = Single.timer(2, scheduler: scheduler) - - return singleResult.asObservable() - } - - XCTAssertEqual(res.events, [ - next(202, 0), - completed(202) - ]) - } - - func testSingle_using_producesSingleElement() { - let scheduler = TestScheduler(initialClock: 0) - - var disposeInvoked = 0 - var createInvoked = 0 - - var disposable: MockDisposable! - var xs: TestableObservable! - var _d: MockDisposable! - - let res = scheduler.start { - Single.using({ () -> MockDisposable in - disposeInvoked += 1 - disposable = MockDisposable(scheduler: scheduler) - return disposable - }, primitiveSequenceFactory: { (d: MockDisposable) -> Single in - _d = d - createInvoked += 1 - xs = scheduler.createColdObservable([ - next(100, scheduler.clock), - completed(100) - ]) - return xs.asObservable().asSingle() - }).asObservable() - } - - XCTAssert(disposable === _d) - - XCTAssertEqual(1, createInvoked) - XCTAssertEqual(1, disposeInvoked) - - XCTAssertEqual(res.events, [ - next(300, 200), - completed(300) - ]) - - XCTAssertEqual(xs.subscriptions, [ - Subscription(200, 300) - ]) - - XCTAssertEqual(disposable.ticks, [ - 200, - 300 - ]) - } - - func testSingle_timeout() { - let scheduler = TestScheduler(initialClock: 0) - - let xs = scheduler.createColdObservable([ - next(10, 1), - completed(20) - ]).asSingle() - - let res = scheduler.start { () -> Observable in - let singleResult: Single = xs.timeout(5.0, scheduler: scheduler) - - return singleResult.asObservable() - } - - XCTAssertEqual(res.events, [ - error(205, RxError.timeout) - ]) - } - - func testSingle_timeout_other() { - let scheduler = TestScheduler(initialClock: 0) - - let xs = scheduler.createColdObservable([ - next(10, 1), - completed(20) - ]).asSingle() - - let xs2 = scheduler.createColdObservable([ - next(20, 1), - completed(20) - ]).asSingle() - - let res = scheduler.start { () -> Observable in - let singleResult: Single = xs.timeout(5.0, other: xs2, scheduler: scheduler) - - return singleResult.asObservable() - } - - XCTAssertEqual(res.events, [ - next(225, 1), - completed(225) - ]) - } - - func testMaybe_timeout() { - let scheduler = TestScheduler(initialClock: 0) - - let xs = scheduler.createColdObservable([ - next(10, 1), - completed(20) - ]).asMaybe() - - let res = scheduler.start { () -> Observable in - let result: Maybe = xs.timeout(5.0, scheduler: scheduler) - - return result.asObservable() - } - - XCTAssertEqual(res.events, [ - error(205, RxError.timeout) - ]) - } - - func testMaybe_timeout_other() { - let scheduler = TestScheduler(initialClock: 0) - - let xs = scheduler.createColdObservable([ - next(10, 1), - completed(20) - ]).asMaybe() - - let xs2 = scheduler.createColdObservable([ - next(20, 1), - completed(20) - ]).asMaybe() - - let res = scheduler.start { () -> Observable in - let result: Maybe = xs.timeout(5.0, other: xs2, scheduler: scheduler) - - return result.asObservable() - } - - XCTAssertEqual(res.events, [ - next(225, 1), - completed(225) - ]) - } - - func testCompletable_timeout() { - let scheduler = TestScheduler(initialClock: 0) - - let xs = scheduler.createColdObservable([ - completed(20, Never.self) - ]).asCompletable() - - let res = scheduler.start { () -> Observable in - let result: Completable = xs.timeout(5.0, scheduler: scheduler) - - return result.asObservable() - } - - XCTAssertEqual(res.events, [ - error(205, RxError.timeout) - ]) - } - - func testCompletable_timeout_other() { - let scheduler = TestScheduler(initialClock: 0) - - let xs = scheduler.createColdObservable([ - completed(20, Never.self) - ]).asCompletable() - - let xs2 = scheduler.createColdObservable([ - completed(20, Never.self) - ]).asCompletable() - - let res = scheduler.start { () -> Observable in - let result: Completable = xs.timeout(5.0, other: xs2, scheduler: scheduler) - - return result.asObservable() - } - - XCTAssertEqual(res.events, [ - completed(225) - ]) - } - - func testCompletable_timeout_succeeds() { - let scheduler = TestScheduler(initialClock: 0) - - let xs = scheduler.createColdObservable([ - completed(2, Never.self) - ]).asCompletable() - - let res = scheduler.start { () -> Observable in - let result: Completable = xs.timeout(5.0, scheduler: scheduler) - - return result.asObservable() - } - - XCTAssertEqual(res.events, [ - completed(202) - ]) - } - - func testCompletable_timeout_other_succeeds() { - let scheduler = TestScheduler(initialClock: 0) - - let xs = scheduler.createColdObservable([ - completed(2, Never.self) - ]).asCompletable() - - let xs2 = scheduler.createColdObservable([ - completed(20, Never.self) - ]).asCompletable() - - let res = scheduler.start { () -> Observable in - let result: Completable = xs.timeout(5.0, other: xs2, scheduler: scheduler) - - return result.asObservable() - } - - XCTAssertEqual(res.events, [ - completed(202) - ]) - } -} - -extension PrimitiveSequenceTest { - func testAsSingle_Empty() { - let scheduler = TestScheduler(initialClock: 0) - - let xs = scheduler.createHotObservable([ - next(150, 1), - completed(250), - error(260, testError) - ]) - - let res = scheduler.start { () -> Observable in - let single: Single = xs.asSingle() - return single.asObservable() - } - - XCTAssertEqual(res.events, [ - error(250, RxError.noElements) - ]) - - XCTAssertEqual(xs.subscriptions, [ - Subscription(200, 250) - ]) - } - - func testAsSingle_One() { - let scheduler = TestScheduler(initialClock: 0) - - let xs = scheduler.createHotObservable([ - next(150, 1), - next(210, 2), - completed(250), - error(260, testError) - ]) - - let res = scheduler.start { () -> Observable in - let single: Single = xs.asSingle() - return single.asObservable() - } - - XCTAssertEqual(res.events, [ - next(250, 2), - completed(250) - ]) - - XCTAssertEqual(xs.subscriptions, [ - Subscription(200, 250) - ]) - } - - func testAsSingle_Many() { - let scheduler = TestScheduler(initialClock: 0) - - let xs = scheduler.createHotObservable([ - next(150, 1), - next(210, 2), - next(220, 3), - completed(250), - error(260, testError) - ]) - - let res = scheduler.start { () -> Observable in - let single: Single = xs.asSingle() - return single.asObservable() - } - - XCTAssertEqual(res.events, [ - error(220, RxError.moreThanOneElement) - ]) - - XCTAssertEqual(xs.subscriptions, [ - Subscription(200, 220) - ]) - } - - func testAsSingle_Error() { - let scheduler = TestScheduler(initialClock: 0) - - let xs = scheduler.createHotObservable([ - next(150, 1), - error(210, testError) - ]) - - let res = scheduler.start { () -> Observable in - let single: Single = xs.asSingle() - return single.asObservable() - } - - XCTAssertEqual(res.events, [ - error(210, testError) - ]) - - XCTAssertEqual(xs.subscriptions, [ - Subscription(200, 210) - ]) - } - - func testAsSingle_Error2() { - let scheduler = TestScheduler(initialClock: 0) - - let xs = scheduler.createHotObservable([ - next(150, 1), - next(205, 2), - error(210, testError) - ]) - - let res = scheduler.start { () -> Observable in - let single: Single = xs.asSingle() - return single.asObservable() - } - - XCTAssertEqual(res.events, [ - error(210, testError) - ]) - - XCTAssertEqual(xs.subscriptions, [ - Subscription(200, 210) - ]) - } - - func testAsSingle_subscribeOnSuccess() { - var events: [SingleEvent] = [] - - _ = Single.just(1).subscribe(onSuccess: { element in - events.append(.success(element)) - }, onError: { error in - events.append(.error(error)) - }) - - XCTAssertEqual(events, [.success(1)]) - } - - func testAsSingle_subscribeOnError() { - var events: [SingleEvent] = [] - - _ = Single.error(testError).subscribe(onSuccess: { element in - events.append(.success(element)) - }, onError: { error in - events.append(.error(error)) - }) - - XCTAssertEqual(events, [.error(testError)]) - } - - #if TRACE_RESOURCES - func testAsSingleReleasesResourcesOnComplete() { - _ = Observable.just(1).asSingle().subscribe({ _ in }) - } - - func testAsSingleReleasesResourcesOnError1() { - _ = Observable.error(testError).asSingle().subscribe({ _ in }) - } - - func testAsSingleReleasesResourcesOnError2() { - _ = Observable.of(1, 2).asSingle().subscribe({ _ in }) - } - #endif -} - -extension PrimitiveSequenceTest { - func testFirst_Empty() { - let scheduler = TestScheduler(initialClock: 0) - - let xs = scheduler.createHotObservable([ - next(150, 1), - completed(250), - error(260, testError) - ]) - - let res: TestableObserver = scheduler.start { () -> Observable in - let single: Single = xs.first() - return single.asObservable() - } - - XCTAssertEqual(res.events, [ - next(250, nil), - completed(250) - ]) - - XCTAssertEqual(xs.subscriptions, [ - Subscription(200, 250) - ]) - } - - func testFirst_One() { - let scheduler = TestScheduler(initialClock: 0) - - let xs = scheduler.createHotObservable([ - next(150, 1), - next(210, 2), - completed(250), - error(260, testError) - ]) - - let res = scheduler.start { () -> Observable in - let single: Single = xs.first() - return single.asObservable() - } - - XCTAssertEqual(res.events, [ - next(210, 2), - completed(210) - ]) - - XCTAssertEqual(xs.subscriptions, [ - Subscription(200, 210) - ]) - } - - func testFirst_Many() { - let scheduler = TestScheduler(initialClock: 0) - - let xs = scheduler.createHotObservable([ - next(150, 1), - next(210, 2), - next(220, 3), - completed(250), - error(260, testError) - ]) - - let res = scheduler.start { () -> Observable in - let single: Single = xs.first() - return single.asObservable() - } - - XCTAssertEqual(res.events, [ - next(210, 2), - completed(210) - ]) - - XCTAssertEqual(xs.subscriptions, [ - Subscription(200, 210) - ]) - } - - func testFirst_ManyWithoutCompletion() { - let scheduler = TestScheduler(initialClock: 0) - - let xs = scheduler.createHotObservable([ - next(150, 1), - next(160, 2), - next(280, 3), - next(250, 4), - next(300, 5) - ]) - - let res = scheduler.start { () -> Observable in - let single: Single = xs.first() - return single.asObservable() - } - - XCTAssertEqual(res.events, [ - next(250, 4), - completed(250) - ]) - - XCTAssertEqual(xs.subscriptions, [ - Subscription(200, 250) - ]) - } - - func testFirst_Error() { - let scheduler = TestScheduler(initialClock: 0) - - let xs = scheduler.createHotObservable([ - next(150, 1), - error(210, testError) - ]) - - let res = scheduler.start { () -> Observable in - let single: Single = xs.first() - return single.asObservable() - } - - XCTAssertEqual(res.events, [ - error(210, testError) - ]) - - XCTAssertEqual(xs.subscriptions, [ - Subscription(200, 210) - ]) - } - - #if TRACE_RESOURCES - func testFirstReleasesResourcesOnComplete() { - _ = Observable.just(1).first().subscribe({ _ in }) - } - - func testFirstReleasesResourcesOnError1() { - _ = Observable.error(testError).first().subscribe({ _ in }) - } - #endif -} - -extension PrimitiveSequenceTest { - func testAsMaybe_Empty() { - let scheduler = TestScheduler(initialClock: 0) - - let xs = scheduler.createHotObservable([ - next(150, 1), - completed(250), - error(260, testError) - ]) - - let res = scheduler.start { () -> Observable in - let maybe: Maybe = xs.asMaybe() - return maybe.asObservable() - } - - XCTAssertEqual(res.events, [ - completed(250) - ]) - - XCTAssertEqual(xs.subscriptions, [ - Subscription(200, 250) - ]) - } - - func testAsMaybe_One() { - let scheduler = TestScheduler(initialClock: 0) - - let xs = scheduler.createHotObservable([ - next(150, 1), - next(210, 2), - completed(250), - error(260, testError) - ]) - - let res = scheduler.start { () -> Observable in - let maybe: Maybe = xs.asMaybe() - return maybe.asObservable() - } - - XCTAssertEqual(res.events, [ - next(250, 2), - completed(250) - ]) - - XCTAssertEqual(xs.subscriptions, [ - Subscription(200, 250) - ]) - } - - func testAsMaybe_Many() { - let scheduler = TestScheduler(initialClock: 0) - - let xs = scheduler.createHotObservable([ - next(150, 1), - next(210, 2), - next(220, 3), - completed(250), - error(260, testError) - ]) - - let res = scheduler.start { () -> Observable in - let maybe: Maybe = xs.asMaybe() - return maybe.asObservable() - } - - XCTAssertEqual(res.events, [ - error(220, RxError.moreThanOneElement) - ]) - - XCTAssertEqual(xs.subscriptions, [ - Subscription(200, 220) - ]) - } - - func testAsMaybe_Error() { - let scheduler = TestScheduler(initialClock: 0) - - let xs = scheduler.createHotObservable([ - next(150, 1), - error(210, testError) - ]) - - let res = scheduler.start { () -> Observable in - let maybe: Maybe = xs.asMaybe() - return maybe.asObservable() - } - - XCTAssertEqual(res.events, [ - error(210, testError) - ]) - - XCTAssertEqual(xs.subscriptions, [ - Subscription(200, 210) - ]) - } - - func testAsMaybe_Error2() { - let scheduler = TestScheduler(initialClock: 0) - - let xs = scheduler.createHotObservable([ - next(150, 1), - next(205, 2), - error(210, testError) - ]) - - let res = scheduler.start { () -> Observable in - let maybe: Maybe = xs.asMaybe() - return maybe.asObservable() - } - - XCTAssertEqual(res.events, [ - error(210, testError) - ]) - - XCTAssertEqual(xs.subscriptions, [ - Subscription(200, 210) - ]) - } - - func testAsMaybe_subscribeOnSuccess() { - var events: [MaybeEvent] = [] - - _ = Maybe.just(1).subscribe(onSuccess: { element in - events.append(.success(element)) - }, onError: { error in - events.append(.error(error)) - }, onCompleted: { - events.append(.completed) - }) - - XCTAssertEqual(events, [.success(1)]) - } - - func testAsMaybe_subscribeOnError() { - var events: [MaybeEvent] = [] - - _ = Maybe.error(testError).subscribe(onSuccess: { element in - events.append(.success(element)) - }, onError: { error in - events.append(.error(error)) - }, onCompleted: { - events.append(.completed) - }) - - XCTAssertEqual(events, [.error(testError)]) - } - - func testAsMaybe_subscribeOnCompleted() { - var events: [MaybeEvent] = [] - - _ = Maybe.empty().subscribe(onSuccess: { element in - events.append(.success(element)) - }, onError: { error in - events.append(.error(error)) - }, onCompleted: { - events.append(.completed) - }) - - XCTAssertEqual(events, [.completed]) - } - - #if TRACE_RESOURCES - func testAsMaybeReleasesResourcesOnComplete1() { - _ = Observable.empty().asMaybe().subscribe({ _ in }) - } - - func testAsMaybeReleasesResourcesOnComplete2() { - _ = Observable.just(1).asMaybe().subscribe({ _ in }) - } - - func testAsMaybeReleasesResourcesOnError1() { - _ = Observable.error(testError).asMaybe().subscribe({ _ in }) - } - - func testAsMaybeReleasesResourcesOnError2() { - _ = Observable.of(1, 2).asMaybe().subscribe({ _ in }) - } - #endif -} - -extension PrimitiveSequenceTest { - func testAsCompletable_Empty() { - let scheduler = TestScheduler(initialClock: 0) - - let xs = scheduler.createHotObservable([ - completed(250, Never.self), - error(260, testError) - ]) - - let res = scheduler.start { () -> Observable in - let completable: Completable = xs.asCompletable() - return completable.asObservable() - } - - XCTAssertEqual(res.events, [ - completed(250) - ]) - - XCTAssertEqual(xs.subscriptions, [ - Subscription(200, 250) - ]) - } - - func testAsCompletable_Error() { - let scheduler = TestScheduler(initialClock: 0) - - let xs = scheduler.createHotObservable([ - error(210, testError, Never.self) - ]) - - let res = scheduler.start { () -> Observable in - let completable: Completable = xs.asCompletable() - return completable.asObservable() - } - - XCTAssertEqual(res.events, [ - error(210, testError) - ]) - - XCTAssertEqual(xs.subscriptions, [ - Subscription(200, 210) - ]) - } - - func testAsCompletable_subscribeOnCompleted() { - var events: [CompletableEvent] = [] - - _ = Completable.empty().subscribe(onCompleted: { - events.append(.completed) - }, onError: { error in - events.append(.error(error)) - }) - - XCTAssertEqual(events, [.completed]) - } - - func testAsCompletable_subscribeOnError() { - var events: [CompletableEvent] = [] - - _ = Completable.error(testError).subscribe(onCompleted: { - events.append(.completed) - }, onError: { error in - events.append(.error(error)) - }) - - XCTAssertEqual(events, [.error(testError)]) - } - - #if TRACE_RESOURCES - func testAsCompletableReleasesResourcesOnComplete() { - _ = Observable.empty().asCompletable().subscribe({ _ in }) - } - - func testAsCompletableReleasesResourcesOnError() { - _ = Observable.error(testError).asCompletable().subscribe({ _ in }) - } - #endif - - func testCompletable_merge() { - let factories: [(Completable, Completable) -> Completable] = - [ - { ys1, ys2 in Completable.merge(ys1, ys2) }, - { ys1, ys2 in Completable.merge([ys1, ys2]) }, - { ys1, ys2 in Completable.merge(AnyCollection([ys1, ys2])) }, - ] - - for factory in factories { - let scheduler = TestScheduler(initialClock: 0) - - let ys1 = scheduler.createHotObservable([ - completed(250, Never.self), - error(260, testError) - ]) - - let ys2 = scheduler.createHotObservable([ - completed(300, Never.self) - ]) - - let res = scheduler.start { () -> Observable in - let completable: Completable = factory(ys1.asCompletable(), ys2.asCompletable()) - return completable.asObservable() - } - - XCTAssertEqual(res.events, [ - completed(300) - ]) - - XCTAssertEqual(ys1.subscriptions, [ - Subscription(200, 250), - ]) - - XCTAssertEqual(ys2.subscriptions, [ - Subscription(200, 300), - ]) - } - } - - func testCompletable_concat() { - let factories: [(Completable, Completable) -> Completable] = - [ - { ys1, ys2 in Completable.concat(ys1, ys2) }, - { ys1, ys2 in Completable.concat([ys1, ys2]) }, - { ys1, ys2 in Completable.concat(AnyCollection([ys1, ys2])) }, - { ys1, ys2 in ys1.concat(ys2) } - ] - - for factory in factories { - let scheduler = TestScheduler(initialClock: 0) - - let ys1 = scheduler.createHotObservable([ - completed(250, Never.self), - error(260, testError) - ]) - - let ys2 = scheduler.createHotObservable([ - completed(300, Never.self) - ]) - - let res = scheduler.start { () -> Observable in - let completable: Completable = factory(ys1.asCompletable(), ys2.asCompletable()) - return completable.asObservable() - } - - XCTAssertEqual(res.events, [ - completed(300) - ]) - - XCTAssertEqual(ys1.subscriptions, [ - Subscription(200, 250), - ]) - - XCTAssertEqual(ys2.subscriptions, [ - Subscription(250, 300), - ]) - } - } -} - -extension PrimitiveSequenceTest { - func testDebug_producesSingleElement() { - let singleResult: Single = Single.just(1) - .debug("a", trimOutput: false) - - let result = try! singleResult - .toBlocking().first()! - XCTAssertEqual(result, 1) - } -} - -extension Never: Equatable { - -} - -public func == (lhs: Never, rhs: Never) -> Bool { - fatalError() -} diff --git a/default.profraw b/default.profraw index b91f3c00b..56d1b28d7 100644 Binary files a/default.profraw and b/default.profraw differ