Skip to content

Commit

Permalink
Swift 3.0: Fix Xcode 8 GM compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
ikesyo authored and AliSoftware committed Sep 9, 2016
1 parent d01b524 commit c7c9654
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions OHHTTPStubs/Sources/Swift/OHHTTPStubsSwift.swift
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,15 @@ public func fixture(filePath: String, status: Int32 = 200, headers: [NSObject: A
* - Returns: The opaque `OHHTTPStubsDescriptor` that uniquely identifies the stub
* and can be later used to remove it with `removeStub:`
*/
#if swift(>=3.0)
public func stub(condition: @escaping OHHTTPStubsTestBlock, response: @escaping OHHTTPStubsResponseBlock) -> OHHTTPStubsDescriptor {
return OHHTTPStubs.stubRequests(passingTest: condition, withStubResponse: response)
}
#else
public func stub(condition: OHHTTPStubsTestBlock, response: OHHTTPStubsResponseBlock) -> OHHTTPStubsDescriptor {
return OHHTTPStubs.stubRequests(passingTest: condition, withStubResponse: response)
}
#endif



Expand Down Expand Up @@ -275,9 +281,15 @@ public func hasHeaderNamed(_ name: String, value: String) -> OHHTTPStubsTestBloc
*
* - Returns: a matcher (`OHHTTPStubsTestBlock`) that succeeds if either of the given matchers succeeds
*/
#if swift(>=3.0)
public func || (lhs: @escaping OHHTTPStubsTestBlock, rhs: @escaping OHHTTPStubsTestBlock) -> OHHTTPStubsTestBlock {
return { req in lhs(req) || rhs(req) }
}
#else
public func || (lhs: OHHTTPStubsTestBlock, rhs: OHHTTPStubsTestBlock) -> OHHTTPStubsTestBlock {
return { req in lhs(req) || rhs(req) }
}
#endif

/**
* Combine different `OHHTTPStubsTestBlock` matchers with an 'AND' operation.
Expand All @@ -287,9 +299,15 @@ public func || (lhs: OHHTTPStubsTestBlock, rhs: OHHTTPStubsTestBlock) -> OHHTTPS
*
* - Returns: a matcher (`OHHTTPStubsTestBlock`) that only succeeds if both of the given matchers succeeds
*/
#if swift(>=3.0)
public func && (lhs: @escaping OHHTTPStubsTestBlock, rhs: @escaping OHHTTPStubsTestBlock) -> OHHTTPStubsTestBlock {
return { req in lhs(req) && rhs(req) }
}
#else
public func && (lhs: OHHTTPStubsTestBlock, rhs: OHHTTPStubsTestBlock) -> OHHTTPStubsTestBlock {
return { req in lhs(req) && rhs(req) }
}
#endif

/**
* Create the opposite of a given `OHHTTPStubsTestBlock` matcher.
Expand All @@ -298,6 +316,12 @@ public func && (lhs: OHHTTPStubsTestBlock, rhs: OHHTTPStubsTestBlock) -> OHHTTPS
*
* - Returns: a matcher (OHHTTPStubsTestBlock) that only succeeds if the expr matcher fails
*/
#if swift(>=3.0)
public prefix func ! (expr: @escaping OHHTTPStubsTestBlock) -> OHHTTPStubsTestBlock {
return { req in !expr(req) }
}
#else
public prefix func ! (expr: OHHTTPStubsTestBlock) -> OHHTTPStubsTestBlock {
return { req in !expr(req) }
}
#endif

0 comments on commit c7c9654

Please sign in to comment.