This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Foundation | |
import XCTest | |
extension XCTestCase { | |
/// Expects that the async code will throw | |
@discardableResult | |
func XCTAssertThrowsErrorAsync( | |
testName: String = #function, | |
file: StaticString = #filePath, | |
line: UInt = #line, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
enum ErrorCode: Equatable, Error { | |
case unknown | |
// Top level server error | |
case serverIssue | |
// Network | |
case noNetworkConnection | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// The code below was inspired by my swift implementation https://gist.github.com/CassiusPacheco/4378d30d69316e4a6ba28a0c3af72628 | |
// and Avdosev's Dart Either https://github.com/avdosev/either_dart/blob/master/lib/src/either.dart | |
import 'package:equatable/equatable.dart'; | |
abstract class Failure extends Equatable implements Exception { | |
@override | |
String toString() => '$runtimeType Exception'; | |
@override |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'package:flutter/material.dart'; | |
extension MaterialX on Color { | |
MaterialColor toMaterial() { | |
return _createMaterialColor(this); | |
} | |
// Taken from https://medium.com/@filipvk/creating-a-custom-color-swatch-in-flutter-554bcdcb27f3 | |
MaterialColor _createMaterialColor(Color color) { | |
final List<double> strengths = [.05]; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'package:logging/logging.dart'; | |
typedef InstanceBuilderCallback<S> = S Function(ServiceLocator); | |
typedef InstanceBuilderCallback1<S, A> = S Function(ServiceLocator, A); | |
/// A service lookup class which allows factories of instances and singletons | |
/// to be registered and resolved as part of a dependency injection system. | |
class ServiceLocator { | |
final Map<String, InstanceBuilderCallback> _factories = {}; | |
final Map<String, dynamic> _factories1 = {}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@available(OSX 10.15, iOS 13.0, tvOS 13.0, watchOS 6.0, *) | |
extension Publisher where Self.Failure == Never { | |
/// Wraps this publisher with a type eraser that updates the expected `Failure` from `Never` to the given type. | |
/// | |
/// Use `eraseToAnyPublisherFailure(to:)` to expose an instance of AnyPublisher to the downstream subscriber, rather than this publisher’s actual type. | |
/// Under the hood it updates the failure type by calling `setFailureType(to:)` applying the given type. | |
public func eraseToAnyPublisherFailure<E>(to failureType: E.Type) -> AnyPublisher<Self.Output, E> where E: Error { | |
return self | |
.setFailureType(to: failureType) | |
.eraseToAnyPublisher() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Foundation | |
public func + (lhs: NSAttributedString, rhs: NSAttributedString) -> NSMutableAttributedString { | |
let mutable = NSMutableAttributedString(attributedString: lhs) | |
mutable.append(rhs) | |
return mutable | |
} | |
extension String { | |
public var attributedString: NSMutableAttributedString { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public final class Assert { | |
public static var shouldCrashOnDebug = true | |
fileprivate static var isUnitTesting = NSClassFromString("XCTest") != nil | |
} | |
public func debugAssertion(_ condition: @autoclosure () -> Bool, message: String = "") { | |
#if DEBUG || STAGE | |
if !condition() { | |
if Assert.shouldCrashOnDebug { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Foundation | |
import RxSwift | |
extension Disposable { | |
/// Adds `self` to `single` | |
/// | |
/// - parameter single: `SingleDisposer` to add `self` to. | |
/// - note: `SingleDisposer` is a wrapper of `DisposeBag` that is recreated | |
/// whenever a disposable object is inserted into it, cancelling any | |
/// previous subscriptions. It keeps at most one subscription at a |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
extension Publisher { | |
func waitForCompletion(timeout: TimeInterval = 1.0, file: StaticString = #file, line: UInt = #line) throws -> [Output] { | |
let expectation = XCTestExpectation(description: "wait for completion") | |
var completion: Subscribers.Completion<Failure>? | |
var output = [Output]() | |
let subscription = self.collect() | |
.sink(receiveCompletion: { receiveCompletion in | |
completion = receiveCompletion | |
expectation.fulfill() |
NewerOlder