Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Swift 3.0: Fix Xcode 8 GM compatibility #201

Merged
merged 1 commit into from
Sep 9, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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