From 580eacc3257adf69f2d5cf0bbbf58b939ccf4c60 Mon Sep 17 00:00:00 2001 From: Sho Ikeda Date: Fri, 22 May 2020 17:27:48 +0900 Subject: [PATCH] Unify some `#if canImport(Darwin)` conditional compilations --- Sources/Nimble/Matchers/BeGreaterThan.swift | 6 ++---- Sources/Nimble/Matchers/BeGreaterThanOrEqualTo.swift | 6 ++---- Sources/Nimble/Matchers/BeLessThan.swift | 8 ++------ Sources/Nimble/Matchers/BeLessThanOrEqual.swift | 8 ++------ Sources/Nimble/Matchers/MatcherProtocols.swift | 4 +--- 5 files changed, 9 insertions(+), 23 deletions(-) diff --git a/Sources/Nimble/Matchers/BeGreaterThan.swift b/Sources/Nimble/Matchers/BeGreaterThan.swift index 5f4f67ad2..a8d12125e 100644 --- a/Sources/Nimble/Matchers/BeGreaterThan.swift +++ b/Sources/Nimble/Matchers/BeGreaterThan.swift @@ -1,5 +1,3 @@ -import Foundation - /// A Nimble matcher that succeeds when the actual value is greater than the expected value. public func beGreaterThan(_ expectedValue: T?) -> Predicate { let errorMessage = "be greater than <\(stringify(expectedValue))>" @@ -15,6 +13,8 @@ public func >(lhs: Expectation, rhs: T) { } #if canImport(Darwin) +import enum Foundation.ComparisonResult + /// A Nimble matcher that succeeds when the actual value is greater than the expected value. public func beGreaterThan(_ expectedValue: NMBComparable?) -> Predicate { let errorMessage = "be greater than <\(stringify(expectedValue))>" @@ -29,9 +29,7 @@ public func beGreaterThan(_ expectedValue: NMBComparable?) -> Predicate (lhs: Expectation, rhs: NMBComparable?) { lhs.to(beGreaterThan(rhs)) } -#endif -#if canImport(Darwin) extension NMBPredicate { @objc public class func beGreaterThanMatcher(_ expected: NMBComparable?) -> NMBPredicate { return NMBPredicate { actualExpression in diff --git a/Sources/Nimble/Matchers/BeGreaterThanOrEqualTo.swift b/Sources/Nimble/Matchers/BeGreaterThanOrEqualTo.swift index cbf97a9e4..affa58cf8 100644 --- a/Sources/Nimble/Matchers/BeGreaterThanOrEqualTo.swift +++ b/Sources/Nimble/Matchers/BeGreaterThanOrEqualTo.swift @@ -1,5 +1,3 @@ -import Foundation - /// A Nimble matcher that succeeds when the actual value is greater than /// or equal to the expected value. public func beGreaterThanOrEqualTo(_ expectedValue: T?) -> Predicate { @@ -16,6 +14,8 @@ public func >=(lhs: Expectation, rhs: T) { } #if canImport(Darwin) +import enum Foundation.ComparisonResult + /// A Nimble matcher that succeeds when the actual value is greater than /// or equal to the expected value. public func beGreaterThanOrEqualTo(_ expectedValue: T?) -> Predicate { @@ -30,9 +30,7 @@ public func beGreaterThanOrEqualTo(_ expectedValue: T?) -> Pre public func >=(lhs: Expectation, rhs: T) { lhs.to(beGreaterThanOrEqualTo(rhs)) } -#endif -#if canImport(Darwin) extension NMBPredicate { @objc public class func beGreaterThanOrEqualToMatcher(_ expected: NMBComparable?) -> NMBPredicate { return NMBPredicate { actualExpression in diff --git a/Sources/Nimble/Matchers/BeLessThan.swift b/Sources/Nimble/Matchers/BeLessThan.swift index d82cf1937..256f3a625 100644 --- a/Sources/Nimble/Matchers/BeLessThan.swift +++ b/Sources/Nimble/Matchers/BeLessThan.swift @@ -1,7 +1,3 @@ -#if canImport(Foundation) -import enum Foundation.ComparisonResult -#endif - /// A Nimble matcher that succeeds when the actual value is less than the expected value. public func beLessThan(_ expectedValue: T?) -> Predicate { let message = "be less than <\(stringify(expectedValue))>" @@ -17,6 +13,8 @@ public func <(lhs: Expectation, rhs: T) { } #if canImport(Darwin) +import enum Foundation.ComparisonResult + /// A Nimble matcher that succeeds when the actual value is less than the expected value. public func beLessThan(_ expectedValue: NMBComparable?) -> Predicate { let message = "be less than <\(stringify(expectedValue))>" @@ -30,9 +28,7 @@ public func beLessThan(_ expectedValue: NMBComparable?) -> Predicate, rhs: NMBComparable?) { lhs.to(beLessThan(rhs)) } -#endif -#if canImport(Darwin) extension NMBPredicate { @objc public class func beLessThanMatcher(_ expected: NMBComparable?) -> NMBPredicate { return NMBPredicate { actualExpression in diff --git a/Sources/Nimble/Matchers/BeLessThanOrEqual.swift b/Sources/Nimble/Matchers/BeLessThanOrEqual.swift index 6278f77ad..6174be5af 100644 --- a/Sources/Nimble/Matchers/BeLessThanOrEqual.swift +++ b/Sources/Nimble/Matchers/BeLessThanOrEqual.swift @@ -1,7 +1,3 @@ -#if canImport(Foundation) -import enum Foundation.ComparisonResult -#endif - /// A Nimble matcher that succeeds when the actual value is less than /// or equal to the expected value. public func beLessThanOrEqualTo(_ expectedValue: T?) -> Predicate { @@ -17,6 +13,8 @@ public func <=(lhs: Expectation, rhs: T) { } #if canImport(Darwin) +import enum Foundation.ComparisonResult + /// A Nimble matcher that succeeds when the actual value is less than /// or equal to the expected value. public func beLessThanOrEqualTo(_ expectedValue: T?) -> Predicate { @@ -30,9 +28,7 @@ public func beLessThanOrEqualTo(_ expectedValue: T?) -> Predic public func <=(lhs: Expectation, rhs: T) { lhs.to(beLessThanOrEqualTo(rhs)) } -#endif -#if canImport(Darwin) extension NMBPredicate { @objc public class func beLessThanOrEqualToMatcher(_ expected: NMBComparable?) -> NMBPredicate { return NMBPredicate { actualExpression in diff --git a/Sources/Nimble/Matchers/MatcherProtocols.swift b/Sources/Nimble/Matchers/MatcherProtocols.swift index fea8a1ccf..720ced01c 100644 --- a/Sources/Nimble/Matchers/MatcherProtocols.swift +++ b/Sources/Nimble/Matchers/MatcherProtocols.swift @@ -129,17 +129,15 @@ extension NSDate: TestOutputStringConvertible { } } +#if canImport(Darwin) /// Protocol for types to support beLessThan(), beLessThanOrEqualTo(), /// beGreaterThan(), beGreaterThanOrEqualTo(), and equal() matchers. /// /// Types that conform to Swift's Comparable protocol will work implicitly too -#if canImport(Darwin) @objc public protocol NMBComparable { func NMB_compare(_ otherObject: NMBComparable!) -> ComparisonResult } -#endif -#if canImport(Darwin) extension NSNumber: NMBComparable { public func NMB_compare(_ otherObject: NMBComparable!) -> ComparisonResult { // swiftlint:disable:next force_cast