Created
February 21, 2018 22:17
-
-
Save fcy/cbdc044bc64233028f766d6e03335a91 to your computer and use it in GitHub Desktop.
XCTAssert to easy assert heterogenous dictionaries are equal
This file contains 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
/// 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