Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
XCTAssert to easy assert heterogenous dictionaries are equal
/// Makes testings dictionaries berable in Swift. It correctly tests heterogenous dictionaries
///
/// E.g.:
/// let expected: [String: Any] = ["p": true]
/// let actual = doSomething() // returns [String: Any]
/// XCTAssertEqual(actual, expected)
///
public func XCTAssertEqual<K, V>(_ expression1: @autoclosure () throws -> [K: V], _ expression2: @autoclosure () throws -> [K: V], _ message: @autoclosure () -> String? = nil, file: StaticString = #file, line: UInt = #line) {
do {
let lhs = try expression1() as NSDictionary
let rhs = try expression2() as NSDictionary
if let msg = message() {
XCTAssertEqual(lhs, rhs, msg, file: file, line: line)
} else {
XCTAssertEqual(lhs, rhs, file: file, line: line)
}
} catch let error {
XCTFail("\(error)", file: file, line: line)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment