Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions RxTest/Event+Equatable.swift
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,30 @@ public func == <Element: Equatable>(lhs: Event<Element?>, rhs: Event<Element?>)
}
}

/// Compares two events with Void elements. They are equal always.
///
/// In case `Error` events are being compared, they are equal in case their `NSError` representations are equal (domain and code)
/// and their string representations are equal.
public func == (lhs: Event<Void>, rhs: Event<Void>) -> Bool {
switch (lhs, rhs) {
case (.completed, .completed): return true
case (.error(let e1), .error(let e2)):
#if os(Linux)
return "\(e1)" == "\(e2)"
#else
let error1 = e1 as NSError
let error2 = e2 as NSError

return error1.domain == error2.domain
&& error1.code == error2.code
&& "\(e1)" == "\(e2)"
#endif
case (.next, .next): return true
default: return false
}
}


/// Compares two events. They are equal if they are both the same member of `Event` enumeration.
///
/// In case `Error` events are being compared, they are equal in case their `NSError` representations are equal (domain and code)
Expand Down
11 changes: 11 additions & 0 deletions RxTest/Recorded+Event.swift
Original file line number Diff line number Diff line change
Expand Up @@ -108,3 +108,14 @@ extension Recorded {
}
}

extension Recorded where Value == Void {
/**
Factory method for a `.next` event recorded at a given time.

- parameter time: Recorded virtual time the `.next` event occurs.
- returns: Recorded event in time.
*/
public static func next(_ time: TestTime) -> Recorded<Event<Void>> {
return Recorded<Event<Void>>(time: time, value: .next(()))
}
}
4 changes: 4 additions & 0 deletions RxTest/Recorded.swift
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,7 @@ public func == <T: Equatable>(lhs: Recorded<Event<T>>, rhs: Recorded<Event<T>>)
public func == <T: Equatable>(lhs: Recorded<Event<T?>>, rhs: Recorded<Event<T?>>) -> Bool {
return lhs.time == rhs.time && lhs.value == rhs.value
}

public func == (lhs: Recorded<Event<Void>>, rhs: Recorded<Event<Void>>) -> Bool {
return lhs.time == rhs.time && lhs.value == rhs.value
}
30 changes: 30 additions & 0 deletions RxTest/XCTest+Rx.swift
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,36 @@ public func XCTAssertEqual<T: Equatable>(_ lhs: [Recorded<Event<T?>>], _ rhs: [R
printSequenceDifferences(lhs, rhs, ==)
}

/**
Asserts two lists of Recorded events with Void elements are equal.

Recorded events are equal if times are equal and recoreded events are equal.

Event is considered equal if:
* `Next` events are equal always.
* `Error` events are equal if errors have same domain and code for `NSError` representation and have equal descriptions.
* `Completed` events are always equal.

- parameter lhs: first set of events.
- parameter lhs: second set of events.
*/
public func XCTAssertEqual(_ lhs: [Recorded<Event<Void>>], _ rhs: [Recorded<Event<Void>>], file: StaticString = #file, line: UInt = #line) {
let leftEquatable = lhs.map { AnyEquatable(target: $0, comparer: ==) }
let rightEquatable = rhs.map { AnyEquatable(target: $0, comparer: ==) }
#if os(Linux)
XCTAssertEqual(leftEquatable, rightEquatable)
#else
XCTAssertEqual(leftEquatable, rightEquatable, file: file, line: line)
#endif

if leftEquatable == rightEquatable {
return
}

printSequenceDifferences(lhs, rhs, ==)
}


/**
Assert a list of Recorded events has emitted the provided elements.
This method does not take event times into consideration.
Expand Down