Created
April 14, 2015 20:49
-
-
Save jarsen/fd25c3c00b1f484b80ef to your computer and use it in GitHub Desktop.
cool swift unit test expectation syntax
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
func expect<T: Equatable>(value: T, file: String = __FILE__, line: Int = __LINE__) -> (T, String, Int) { | |
return (value, file, line) | |
} | |
func ==<T: Equatable>(lhs: (T, String, Int), rhs: T) { | |
if lhs.0 != rhs { | |
XCTFail("Expected \(rhs), but got \(lhs.0) instead", file: lhs.1, line: UInt(lhs.2)) | |
} | |
} | |
func !=<T: Equatable>(lhs: (T, String, Int), rhs: T) { | |
if lhs.0 == rhs { | |
XCTFail("Expected \(rhs), but got \(lhs.0) instead", file: lhs.1, line: UInt(lhs.2)) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
example test:
expect(foo.bar) == 2