Skip to content

Commit

Permalink
Code formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
yannxou committed Feb 27, 2023
1 parent e359156 commit 12c0f1a
Showing 1 changed file with 32 additions and 21 deletions.
53 changes: 32 additions & 21 deletions Sources/PublisherExpectations/PublisherExpectations.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//
// File.swift
// PublisherExpectations.swift
//
//
// Created by Joan Duat on 16/2/23.
Expand All @@ -13,9 +13,10 @@ public final class PublisherValueExpectation<P: Publisher>: XCTestExpectation {
private var cancellable: AnyCancellable?

/// Initializes a PublisherValueExpectation that is fulfilled when the publisher emits a value that matches the condition.
public init(_ publisher: P,
condition: @escaping (P.Output) -> Bool,
description expectationDescription: String? = nil)
public init(
_ publisher: P,
condition: @escaping (P.Output) -> Bool,
description expectationDescription: String? = nil)
{
let description = expectationDescription ?? "Publisher expected to emit a value that matches the condition."
super.init(description: description)
Expand All @@ -28,8 +29,10 @@ public final class PublisherValueExpectation<P: Publisher>: XCTestExpectation {
}

/// Initializes a PublisherValueExpectation that is fulfilled when the publisher emits the expected value.
public convenience init(_ publisher: P, expectedValue: P.Output,
description expectationDescription: String? = nil) where P.Output: Equatable
public convenience init(
_ publisher: P, expectedValue: P.Output,
description expectationDescription: String? = nil
) where P.Output: Equatable
{
let description = expectationDescription ?? "Publisher expected to emit the value '\(expectedValue)'"
self.init(publisher, condition: { $0 == expectedValue }, description: description)
Expand All @@ -42,8 +45,9 @@ public final class PublisherFinishedExpectation<P: Publisher>: XCTestExpectation
private var isConditionFulfilled = false

/// Initializes a PublisherFinishedExpectation that is fulfilled when the publisher completes successfully.
public init(_ publisher: P,
description expectationDescription: String = "Publisher expected to finish")
public init(
_ publisher: P,
description expectationDescription: String = "Publisher expected to finish")
{
super.init(description: expectationDescription)
cancellable = publisher.sink(receiveCompletion: { [weak self] completion in
Expand All @@ -57,9 +61,10 @@ public final class PublisherFinishedExpectation<P: Publisher>: XCTestExpectation
}

/// Initializes a PublisherFinishedExpectation that is fulfilled when the publisher completes successfully after emitting a value that matches a certain condition.
public init(_ publisher: P,
condition: @escaping (P.Output) -> Bool,
description expectationDescription: String? = nil)
public init(
_ publisher: P,
condition: @escaping (P.Output) -> Bool,
description expectationDescription: String? = nil)
{
let description = expectationDescription ?? "Publisher expected to finish after matching the condition."
super.init(description: description)
Expand All @@ -81,8 +86,10 @@ public final class PublisherFinishedExpectation<P: Publisher>: XCTestExpectation
}

/// Initializes a PublisherFinishedExpectation that is fulfilled when the publisher completes successfully after emitting a certain value.
public convenience init(_ publisher: P, expectedValue: P.Output,
description expectationDescription: String? = nil) where P.Output: Equatable
public convenience init(
_ publisher: P, expectedValue: P.Output,
description expectationDescription: String? = nil
) where P.Output: Equatable
{
let description = expectationDescription ?? "Publisher expected to finish after emitting the value '\(expectedValue)'"
self.init(publisher, condition: { $0 == expectedValue }, description: description)
Expand All @@ -94,9 +101,10 @@ public final class PublisherFailureExpectation<P: Publisher>: XCTestExpectation
private var cancellable: AnyCancellable?

/// Initializes a PublisherFailureExpectation that is fulfilled when the publisher fails with an error that matches the condition.
public init(_ publisher: P,
condition: @escaping (P.Failure) -> Bool,
description expectationDescription: String = "Failure was expected with an error matching the condition.")
public init(
_ publisher: P,
condition: @escaping (P.Failure) -> Bool,
description expectationDescription: String = "Failure was expected with an error matching the condition.")
{
super.init(description: expectationDescription)
cancellable = publisher.sink(receiveCompletion: { [weak self] completion in
Expand All @@ -112,16 +120,19 @@ public final class PublisherFailureExpectation<P: Publisher>: XCTestExpectation
}

/// Initializes a PublisherFailureExpectation for a publisher with the given description
public convenience init(_ publisher: P,
description expectationDescription: String = "Failure was expected")
public convenience init(
_ publisher: P,
description expectationDescription: String = "Failure was expected")
{
self.init(publisher, condition: { _ in true }, description: expectationDescription)
}

/// Initializes a PublisherFailureExpectation that is fulfilled when the publisher fails with an expected error.
public convenience init(_ publisher: P,
expectedError: P.Failure,
description expectationDescription: String? = nil) where P.Failure: Equatable
public convenience init(
_ publisher: P,
expectedError: P.Failure,
description expectationDescription: String? = nil
) where P.Failure: Equatable
{
let description = expectationDescription ?? "Failure was expected with '\(expectedError)'"
self.init(publisher, condition: { $0 == expectedError }, description: description)
Expand Down

0 comments on commit 12c0f1a

Please sign in to comment.