Skip to content
Merged
Show file tree
Hide file tree
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
6 changes: 2 additions & 4 deletions Sources/Nimble/Matchers/BeGreaterThan.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import Foundation

/// A Nimble matcher that succeeds when the actual value is greater than the expected value.
public func beGreaterThan<T: Comparable>(_ expectedValue: T?) -> Predicate<T> {
let errorMessage = "be greater than <\(stringify(expectedValue))>"
Expand All @@ -15,6 +13,8 @@ public func ><T: Comparable>(lhs: Expectation<T>, 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<NMBComparable> {
let errorMessage = "be greater than <\(stringify(expectedValue))>"
Expand All @@ -29,9 +29,7 @@ public func beGreaterThan(_ expectedValue: NMBComparable?) -> Predicate<NMBCompa
public func > (lhs: Expectation<NMBComparable>, rhs: NMBComparable?) {
lhs.to(beGreaterThan(rhs))
}
#endif

#if canImport(Darwin)
extension NMBPredicate {
@objc public class func beGreaterThanMatcher(_ expected: NMBComparable?) -> NMBPredicate {
return NMBPredicate { actualExpression in
Expand Down
6 changes: 2 additions & 4 deletions Sources/Nimble/Matchers/BeGreaterThanOrEqualTo.swift
Original file line number Diff line number Diff line change
@@ -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<T: Comparable>(_ expectedValue: T?) -> Predicate<T> {
Expand All @@ -16,6 +14,8 @@ public func >=<T: Comparable>(lhs: Expectation<T>, 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<T: NMBComparable>(_ expectedValue: T?) -> Predicate<T> {
Expand All @@ -30,9 +30,7 @@ public func beGreaterThanOrEqualTo<T: NMBComparable>(_ expectedValue: T?) -> Pre
public func >=<T: NMBComparable>(lhs: Expectation<T>, rhs: T) {
lhs.to(beGreaterThanOrEqualTo(rhs))
}
#endif

#if canImport(Darwin)
extension NMBPredicate {
@objc public class func beGreaterThanOrEqualToMatcher(_ expected: NMBComparable?) -> NMBPredicate {
return NMBPredicate { actualExpression in
Expand Down
8 changes: 2 additions & 6 deletions Sources/Nimble/Matchers/BeLessThan.swift
Original file line number Diff line number Diff line change
@@ -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<T: Comparable>(_ expectedValue: T?) -> Predicate<T> {
let message = "be less than <\(stringify(expectedValue))>"
Expand All @@ -17,6 +13,8 @@ public func <<T: Comparable>(lhs: Expectation<T>, 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<NMBComparable> {
let message = "be less than <\(stringify(expectedValue))>"
Expand All @@ -30,9 +28,7 @@ public func beLessThan(_ expectedValue: NMBComparable?) -> Predicate<NMBComparab
public func < (lhs: Expectation<NMBComparable>, rhs: NMBComparable?) {
lhs.to(beLessThan(rhs))
}
#endif

#if canImport(Darwin)
extension NMBPredicate {
@objc public class func beLessThanMatcher(_ expected: NMBComparable?) -> NMBPredicate {
return NMBPredicate { actualExpression in
Expand Down
8 changes: 2 additions & 6 deletions Sources/Nimble/Matchers/BeLessThanOrEqual.swift
Original file line number Diff line number Diff line change
@@ -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<T: Comparable>(_ expectedValue: T?) -> Predicate<T> {
Expand All @@ -17,6 +13,8 @@ public func <=<T: Comparable>(lhs: Expectation<T>, 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<T: NMBComparable>(_ expectedValue: T?) -> Predicate<T> {
Expand All @@ -30,9 +28,7 @@ public func beLessThanOrEqualTo<T: NMBComparable>(_ expectedValue: T?) -> Predic
public func <=<T: NMBComparable>(lhs: Expectation<T>, rhs: T) {
lhs.to(beLessThanOrEqualTo(rhs))
}
#endif

#if canImport(Darwin)
extension NMBPredicate {
@objc public class func beLessThanOrEqualToMatcher(_ expected: NMBComparable?) -> NMBPredicate {
return NMBPredicate { actualExpression in
Expand Down
4 changes: 1 addition & 3 deletions Sources/Nimble/Matchers/MatcherProtocols.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down