0001 public protocol ExpectationType{ 0002 typealias ValueType
Expectation.swift:22 public class Expectation<T> : ExpectationType {Expectation.swift:56 public func == <E: ExpectationType where E.ValueType: Equatable>(lhs: E, rhs: E.ValueType) throws {Expectation.swift:66 public func != <E: ExpectationType where E.ValueType: Equatable>(lhs: E, rhs: E.ValueType) throws {Expectation.swift:75 extension ExpectationType {Expectation.swift:86 extension ExpectationType where ValueType == Bool {Expectation.swift:104 extension ExpectationType {Expectation.swift:144 public func > <E: ExpectationType where E.ValueType: Comparable>(lhs: E, rhs: E.ValueType) throws {Expectation.swift:151 public func >= <E: ExpectationType where E.ValueType: Comparable>(lhs: E, rhs: E.ValueType) throws {Expectation.swift:158 public func < <E: ExpectationType where E.ValueType: Comparable>(lhs: E, rhs: E.ValueType) throws {Expectation.swift:165 public func <= <E: ExpectationType where E.ValueType: Comparable>(lhs: E, rhs: E.ValueType) throws {0003 var expression
Expectation.swift:3 var expression: () throws -> ValueType? { get }Expectation.swift:56 public func == <E: ExpectationType where E.ValueType: Equatable>(lhs: E, rhs: E.ValueType) throws {Expectation.swift:56 public func == <E: ExpectationType where E.ValueType: Equatable>(lhs: E, rhs: E.ValueType) throws {Expectation.swift:66 public func != <E: ExpectationType where E.ValueType: Equatable>(lhs: E, rhs: E.ValueType) throws {Expectation.swift:66 public func != <E: ExpectationType where E.ValueType: Equatable>(lhs: E, rhs: E.ValueType) throws {Expectation.swift:144 public func > <E: ExpectationType where E.ValueType: Comparable>(lhs: E, rhs: E.ValueType) throws {Expectation.swift:144 public func > <E: ExpectationType where E.ValueType: Comparable>(lhs: E, rhs: E.ValueType) throws {Expectation.swift:151 public func >= <E: ExpectationType where E.ValueType: Comparable>(lhs: E, rhs: E.ValueType) throws {Expectation.swift:151 public func >= <E: ExpectationType where E.ValueType: Comparable>(lhs: E, rhs: E.ValueType) throws {Expectation.swift:158 public func < <E: ExpectationType where E.ValueType: Comparable>(lhs: E, rhs: E.ValueType) throws {Expectation.swift:158 public func < <E: ExpectationType where E.ValueType: Comparable>(lhs: E, rhs: E.ValueType) throws {Expectation.swift:165 public func <= <E: ExpectationType where E.ValueType: Comparable>(lhs: E, rhs: E.ValueType) throws {Expectation.swift:165 public func <= <E: ExpectationType where E.ValueType: Comparable>(lhs: E, rhs: E.ValueType) throws {: () throws -> ValueType? { get } 0004 func failure
Expectation.swift:57 if let value = try lhs.expression() {Expectation.swift:67 let value = try lhs.expression()Expectation.swift:77 let value = try expression()Expectation.swift:88 let value = try expression()Expectation.swift:95 let value = try expression()Expectation.swift:109 try expression()Expectation.swift:123 try expression()Expectation.swift:145 let value = try lhs.expression()Expectation.swift:152 let value = try lhs.expression()Expectation.swift:159 let value = try lhs.expression()Expectation.swift:166 let value = try lhs.expression()(reason: String) -> FailureType 0005 } 0006 0007 struct ExpectationFailure
Expectation.swift:59 throw lhs.failure("\(value) is not equal to \(rhs)")Expectation.swift:62 throw lhs.failure("given value is nil")Expectation.swift:69 throw lhs.failure("\(value) is equal to \(rhs)")Expectation.swift:79 throw failure("value is not nil")Expectation.swift:90 throw failure("value is not true")Expectation.swift:97 throw failure("value is not false")Expectation.swift:115 throw failure("expression did not throw an error")Expectation.swift:131 throw failure("\(thrownError) is not \(error)")Expectation.swift:134 throw failure("\(thrownError) is not \(error)")Expectation.swift:137 throw failure("expression did not throw an error")Expectation.swift:147 throw lhs.failure("\(value) is not more than \(rhs)")Expectation.swift:154 throw lhs.failure("\(value) is not more than or equal to \(rhs)")Expectation.swift:161 throw lhs.failure("\(value) is not less than \(rhs)")Expectation.swift:168 throw lhs.failure("\(value) is not less than or equal to \(rhs)"): FailureType { 0008 let file
Expectation.swift:42 return ExpectationFailure(reason: reason, file: file, line: line, function: function): String 0009 let line
Expectation.swift:16 self.file = file: Int 0010 let function
Expectation.swift:17 self.line = line: String 0011 0012 let reason
Expectation.swift:18 self.function = function: String 0013 0014 init
Expectation.swift:15 self.reason = reason(reason: String, file: String, line: Int, function: String) { 0015 self.reason = reason 0016 self.file = file 0017 self.line = line 0018 self.function = function 0019 } 0020 } 0021 0022 public class Expectation
Expectation.swift:42 return ExpectationFailure(reason: reason, file: file, line: line, function: function)<T
Expectation.swift:30 public var to: Expectation<T> {Expectation.swift:46 public func expect<T>(@autoclosure(escaping) expression: () throws -> T?, file: String = __FILE__, line: Int = __LINE__, function: String = __FUNCTION__) -> Expectation<T> {Expectation.swift:47 return Expectation(file: file, line: line, function: function, expression: expression)Expectation.swift:50 public func expect<T>(file: String = __FILE__, line: Int = __LINE__, function: String = __FUNCTION__, expression: () throws -> T?) -> Expectation<T> {Expectation.swift:51 return Expectation(file: file, line: line, function: function, expression: expression)> : ExpectationType { 0023 public typealias ValueType
Expectation.swift:23 public typealias ValueType = TExpectation.swift:30 public var to: Expectation<T> {= T 0024 public let expression
Expectation.swift:24 public let expression: () throws -> ValueType?Expectation.swift:34 init(file: String, line: Int, function: String, expression: () throws -> ValueType?) {: () throws -> ValueType? 0025 0026 let file
Expectation.swift:38 self.expression = expression: String 0027 let line
Expectation.swift:35 self.file = fileExpectation.swift:42 return ExpectationFailure(reason: reason, file: file, line: line, function: function): Int 0028 let function
Expectation.swift:36 self.line = lineExpectation.swift:42 return ExpectationFailure(reason: reason, file: file, line: line, function: function): String 0029 0030 public var to: Expectation<T> { 0031 return self 0032 } 0033 0034 init
Expectation.swift:37 self.function = functionExpectation.swift:42 return ExpectationFailure(reason: reason, file: file, line: line, function: function)(file: String, line: Int, function: String, expression: () throws -> ValueType?) { 0035 self.file = file 0036 self.line = line 0037 self.function = function 0038 self.expression = expression 0039 } 0040 0041 public func failure(reason: String) -> FailureType { 0042 return ExpectationFailure(reason: reason, file: file, line: line, function: function) 0043 } 0044 } 0045 0046 public func expect<T>(@autoclosure(escaping) expression: () throws -> T?, file: String = __FILE__, line: Int = __LINE__, function: String = __FUNCTION__) -> Expectation<T> { 0047 return Expectation(file: file, line: line, function: function, expression: expression) 0048 } 0049 0050 public func expect<T>(file: String = __FILE__, line: Int = __LINE__, function: String = __FUNCTION__, expression: () throws -> T?) -> Expectation<T> { 0051 return Expectation(file: file, line: line, function: function, expression: expression) 0052 } 0053 0054 // MARK: Equatability 0055 0056 public func == <E: ExpectationType where E.ValueType: Equatable>(lhs: E, rhs: E.ValueType) throws { 0057 if let value = try lhs.expression() { 0058 if value != rhs { 0059 throw lhs.failure("\(value) is not equal to \(rhs)") 0060 } 0061 } else { 0062 throw lhs.failure("given value is nil") 0063 } 0064 } 0065 0066 public func != <E: ExpectationType where E.ValueType: Equatable>(lhs: E, rhs: E.ValueType) throws { 0067 let value = try lhs.expression() 0068 if value == rhs { 0069 throw lhs.failure("\(value) is equal to \(rhs)") 0070 } 0071 } 0072 0073 // MARK: Nil 0074 0075 extension ExpectationType { 0076 public func beNil() throws { 0077 let value = try expression() 0078 if value != nil { 0079 throw failure("value is not nil") 0080 } 0081 } 0082 } 0083 0084 // MARK: Boolean 0085 0086 extension ExpectationType where ValueType == Bool { 0087 public func beTrue() throws { 0088 let value = try expression() 0089 if value != true { 0090 throw failure("value is not true") 0091 } 0092 } 0093 0094 public func beFalse() throws { 0095 let value = try expression() 0096 if value != false { 0097 throw failure("value is not false") 0098 } 0099 } 0100 } 0101 0102 // MARK: Error Handling 0103 0104 extension ExpectationType { 0105 public func toThrow() throws { 0106 var didThrow = false 0107 0108 do { 0109 try expression() 0110 } catch { 0111 didThrow = true 0112 } 0113 0114 if !didThrow { 0115 throw failure("expression did not throw an error") 0116 } 0117 } 0118 0119 public func toThrow<T: Equatable>(error: T) throws { 0120 var thrownError: ErrorType? = nil 0121 0122 do { 0123 try expression() 0124 } catch { 0125 thrownError = error 0126 } 0127 0128 if let thrownError = thrownError { 0129 if let thrownError = thrownError as? T { 0130 if error != thrownError { 0131 throw failure("\(thrownError) is not \(error)") 0132 } 0133 } else { 0134 throw failure("\(thrownError) is not \(error)") 0135 } 0136 } else { 0137 throw failure("expression did not throw an error") 0138 } 0139 } 0140 } 0141 0142 // MARK: Comparable 0143 0144 public func > <E: ExpectationType where E.ValueType: Comparable>(lhs: E, rhs: E.ValueType) throws { 0145 let value = try lhs.expression() 0146 guard value > rhs else { 0147 throw lhs.failure("\(value) is not more than \(rhs)") 0148 } 0149 } 0150 0151 public func >= <E: ExpectationType where E.ValueType: Comparable>(lhs: E, rhs: E.ValueType) throws { 0152 let value = try lhs.expression() 0153 guard value >= rhs else { 0154 throw lhs.failure("\(value) is not more than or equal to \(rhs)") 0155 } 0156 } 0157 0158 public func < <E: ExpectationType where E.ValueType: Comparable>(lhs: E, rhs: E.ValueType) throws { 0159 let value = try lhs.expression() 0160 guard value < rhs else { 0161 throw lhs.failure("\(value) is not less than \(rhs)") 0162 } 0163 } 0164 0165 public func <= <E: ExpectationType where E.ValueType: Comparable>(lhs: E, rhs: E.ValueType) throws { 0166 let value = try lhs.expression() 0167 guard value <= rhs else { 0168 throw lhs.failure("\(value) is not less than or equal to \(rhs)") 0169 } 0170 } 0171
Expectation.swift:47 return Expectation(file: file, line: line, function: function, expression: expression)Expectation.swift:51 return Expectation(file: file, line: line, function: function, expression: expression)