diff --git a/Sources/Nimble/Matchers/BeGreaterThan.swift b/Sources/Nimble/Matchers/BeGreaterThan.swift index b86f25dba..6aa36c53a 100644 --- a/Sources/Nimble/Matchers/BeGreaterThan.swift +++ b/Sources/Nimble/Matchers/BeGreaterThan.swift @@ -32,10 +32,10 @@ public func > (lhs: Expectation, rhs: NMBComparable?) { #if os(macOS) || os(iOS) || os(tvOS) || os(watchOS) extension NMBObjCMatcher { - @objc public class func beGreaterThanMatcher(_ expected: NMBComparable?) -> NMBObjCMatcher { - return NMBObjCMatcher(canMatchNil: false) { actualExpression, failureMessage in + @objc public class func beGreaterThanMatcher(_ expected: NMBComparable?) -> NMBMatcher { + return NMBPredicate { actualExpression in let expr = actualExpression.cast { $0 as? NMBComparable } - return try beGreaterThan(expected).matches(expr, failureMessage: failureMessage) + return try beGreaterThan(expected).satisfies(expr).toObjectiveC() } } } diff --git a/Sources/Nimble/Matchers/BeGreaterThanOrEqualTo.swift b/Sources/Nimble/Matchers/BeGreaterThanOrEqualTo.swift index 2a3ca4ae3..2990fa3ff 100644 --- a/Sources/Nimble/Matchers/BeGreaterThanOrEqualTo.swift +++ b/Sources/Nimble/Matchers/BeGreaterThanOrEqualTo.swift @@ -34,10 +34,10 @@ public func >=(lhs: Expectation, rhs: T) { #if os(macOS) || os(iOS) || os(tvOS) || os(watchOS) extension NMBObjCMatcher { - @objc public class func beGreaterThanOrEqualToMatcher(_ expected: NMBComparable?) -> NMBObjCMatcher { - return NMBObjCMatcher(canMatchNil: false) { actualExpression, failureMessage in + @objc public class func beGreaterThanOrEqualToMatcher(_ expected: NMBComparable?) -> NMBMatcher { + return NMBPredicate { actualExpression in let expr = actualExpression.cast { $0 as? NMBComparable } - return try beGreaterThanOrEqualTo(expected).matches(expr, failureMessage: failureMessage) + return try beGreaterThanOrEqualTo(expected).satisfies(expr).toObjectiveC() } } } diff --git a/Sources/Nimble/Matchers/BeIdenticalTo.swift b/Sources/Nimble/Matchers/BeIdenticalTo.swift index 94758c2e6..0b62f99da 100644 --- a/Sources/Nimble/Matchers/BeIdenticalTo.swift +++ b/Sources/Nimble/Matchers/BeIdenticalTo.swift @@ -43,10 +43,10 @@ public func be(_ expected: Any?) -> Predicate { #if os(macOS) || os(iOS) || os(tvOS) || os(watchOS) extension NMBObjCMatcher { - @objc public class func beIdenticalToMatcher(_ expected: NSObject?) -> NMBObjCMatcher { - return NMBObjCMatcher(canMatchNil: false) { actualExpression, failureMessage in + @objc public class func beIdenticalToMatcher(_ expected: NSObject?) -> NMBMatcher { + return NMBPredicate { actualExpression in let aExpr = actualExpression.cast { $0 as Any? } - return try beIdenticalTo(expected).matches(aExpr, failureMessage: failureMessage) + return try beIdenticalTo(expected).satisfies(aExpr).toObjectiveC() } } } diff --git a/Sources/Nimble/Matchers/BeLessThan.swift b/Sources/Nimble/Matchers/BeLessThan.swift index e1fbf1e56..970699a64 100644 --- a/Sources/Nimble/Matchers/BeLessThan.swift +++ b/Sources/Nimble/Matchers/BeLessThan.swift @@ -31,10 +31,10 @@ public func < (lhs: Expectation, rhs: NMBComparable?) { #if os(macOS) || os(iOS) || os(tvOS) || os(watchOS) extension NMBObjCMatcher { - @objc public class func beLessThanMatcher(_ expected: NMBComparable?) -> NMBObjCMatcher { - return NMBObjCMatcher(canMatchNil: false) { actualExpression, failureMessage in + @objc public class func beLessThanMatcher(_ expected: NMBComparable?) -> NMBMatcher { + return NMBPredicate { actualExpression in let expr = actualExpression.cast { $0 as? NMBComparable } - return try beLessThan(expected).matches(expr, failureMessage: failureMessage) + return try beLessThan(expected).satisfies(expr).toObjectiveC() } } } diff --git a/Sources/Nimble/Matchers/BeLessThanOrEqual.swift b/Sources/Nimble/Matchers/BeLessThanOrEqual.swift index c37cb1686..63dc7d9fa 100644 --- a/Sources/Nimble/Matchers/BeLessThanOrEqual.swift +++ b/Sources/Nimble/Matchers/BeLessThanOrEqual.swift @@ -31,10 +31,10 @@ public func <=(lhs: Expectation, rhs: T) { #if os(macOS) || os(iOS) || os(tvOS) || os(watchOS) extension NMBObjCMatcher { - @objc public class func beLessThanOrEqualToMatcher(_ expected: NMBComparable?) -> NMBObjCMatcher { - return NMBObjCMatcher(canMatchNil: false) { actualExpression, failureMessage in + @objc public class func beLessThanOrEqualToMatcher(_ expected: NMBComparable?) -> NMBMatcher { + return NMBPredicate { actualExpression in let expr = actualExpression.cast { $0 as? NMBComparable } - return try beLessThanOrEqualTo(expected).matches(expr, failureMessage: failureMessage) + return try beLessThanOrEqualTo(expected).satisfies(expr).toObjectiveC() } } } diff --git a/Sources/Nimble/Matchers/BeLogical.swift b/Sources/Nimble/Matchers/BeLogical.swift index 6e8d7a1ef..b703846a6 100644 --- a/Sources/Nimble/Matchers/BeLogical.swift +++ b/Sources/Nimble/Matchers/BeLogical.swift @@ -120,24 +120,24 @@ public func beFalsy() -> Predicate NMBObjCMatcher { - return NMBObjCMatcher { actualExpression, failureMessage in + @objc public class func beTruthyMatcher() -> NMBMatcher { + return NMBPredicate { actualExpression in let expr = actualExpression.cast { ($0 as? NSNumber)?.boolValue ?? false } - return try beTruthy().matches(expr, failureMessage: failureMessage) + return try beTruthy().satisfies(expr).toObjectiveC() } } - @objc public class func beFalsyMatcher() -> NMBObjCMatcher { - return NMBObjCMatcher { actualExpression, failureMessage in + @objc public class func beFalsyMatcher() -> NMBMatcher { + return NMBPredicate { actualExpression in let expr = actualExpression.cast { ($0 as? NSNumber)?.boolValue ?? false } - return try beFalsy().matches(expr, failureMessage: failureMessage) + return try beFalsy().satisfies(expr).toObjectiveC() } } - @objc public class func beTrueMatcher() -> NMBObjCMatcher { - return NMBObjCMatcher { actualExpression, failureMessage in + @objc public class func beTrueMatcher() -> NMBMatcher { + return NMBPredicate { actualExpression in let expr = actualExpression.cast { ($0 as? NSNumber)?.boolValue ?? false } - return try beTrue().matches(expr, failureMessage: failureMessage) + return try beTrue().satisfies(expr).toObjectiveC() } } diff --git a/Sources/Nimble/Matchers/BeNil.swift b/Sources/Nimble/Matchers/BeNil.swift index 387420bd5..8dcc66ba2 100644 --- a/Sources/Nimble/Matchers/BeNil.swift +++ b/Sources/Nimble/Matchers/BeNil.swift @@ -10,9 +10,9 @@ public func beNil() -> Predicate { #if os(macOS) || os(iOS) || os(tvOS) || os(watchOS) extension NMBObjCMatcher { - @objc public class func beNilMatcher() -> NMBObjCMatcher { - return NMBObjCMatcher { actualExpression, failureMessage in - return try beNil().matches(actualExpression, failureMessage: failureMessage) + @objc public class func beNilMatcher() -> NMBMatcher { + return NMBPredicate { actualExpression in + return try beNil().satisfies(actualExpression).toObjectiveC() } } } diff --git a/Sources/Nimble/Matchers/BeginWith.swift b/Sources/Nimble/Matchers/BeginWith.swift index db730cdef..678160b53 100644 --- a/Sources/Nimble/Matchers/BeginWith.swift +++ b/Sources/Nimble/Matchers/BeginWith.swift @@ -44,16 +44,16 @@ public func beginWith(_ startingSubstring: String) -> Predicate { #if os(macOS) || os(iOS) || os(tvOS) || os(watchOS) extension NMBObjCMatcher { - @objc public class func beginWithMatcher(_ expected: Any) -> NMBObjCMatcher { - return NMBObjCMatcher(canMatchNil: false) { actualExpression, failureMessage in + @objc public class func beginWithMatcher(_ expected: Any) -> NMBMatcher { + return NMBPredicate { actualExpression in let actual = try actualExpression.evaluate() - if (actual as? String) != nil { + if actual is String { let expr = actualExpression.cast { $0 as? String } // swiftlint:disable:next force_cast - return try beginWith(expected as! String).matches(expr, failureMessage: failureMessage) + return try beginWith(expected as! String).satisfies(expr).toObjectiveC() } else { let expr = actualExpression.cast { $0 as? NMBOrderedCollection } - return try beginWith(expected).matches(expr, failureMessage: failureMessage) + return try beginWith(expected).satisfies(expr).toObjectiveC() } } } diff --git a/Sources/Nimble/Matchers/EndWith.swift b/Sources/Nimble/Matchers/EndWith.swift index d10531877..6a4415f75 100644 --- a/Sources/Nimble/Matchers/EndWith.swift +++ b/Sources/Nimble/Matchers/EndWith.swift @@ -52,16 +52,16 @@ public func endWith(_ endingSubstring: String) -> Predicate { #if os(macOS) || os(iOS) || os(tvOS) || os(watchOS) extension NMBObjCMatcher { - @objc public class func endWithMatcher(_ expected: Any) -> NMBObjCMatcher { - return NMBObjCMatcher(canMatchNil: false) { actualExpression, failureMessage in + @objc public class func endWithMatcher(_ expected: Any) -> NMBMatcher { + return NMBPredicate { actualExpression in let actual = try actualExpression.evaluate() - if (actual as? String) != nil { + if actual is String { let expr = actualExpression.cast { $0 as? String } // swiftlint:disable:next force_cast - return try endWith(expected as! String).matches(expr, failureMessage: failureMessage) + return try endWith(expected as! String).satisfies(expr).toObjectiveC() } else { let expr = actualExpression.cast { $0 as? NMBOrderedCollection } - return try endWith(expected).matches(expr, failureMessage: failureMessage) + return try endWith(expected).satisfies(expr).toObjectiveC() } } }