Skip to content
Closed
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
8 changes: 0 additions & 8 deletions Nimble.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,8 @@
1F1871E11CA89EF600A34BF2 /* NMBExceptionCapture.h in Headers */ = {isa = PBXBuildFile; fileRef = 1F1871BE1CA89EDB00A34BF2 /* NMBExceptionCapture.h */; settings = {ATTRIBUTES = (Public, ); }; };
1F1871E21CA89EF600A34BF2 /* NMBStringify.h in Headers */ = {isa = PBXBuildFile; fileRef = 1F1871C01CA89EDB00A34BF2 /* NMBStringify.h */; settings = {ATTRIBUTES = (Public, ); }; };
1F1871E41CA89FB600A34BF2 /* Async.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1F1871E31CA89FB600A34BF2 /* Async.swift */; };
1F1871E61CA89FCD00A34BF2 /* MatcherFunc.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1F1871E51CA89FCD00A34BF2 /* MatcherFunc.swift */; };
1F1871E71CA8A18400A34BF2 /* Async.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1F1871E31CA89FB600A34BF2 /* Async.swift */; };
1F1871E81CA8A18400A34BF2 /* Async.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1F1871E31CA89FB600A34BF2 /* Async.swift */; };
1F1871E91CA8A18700A34BF2 /* MatcherFunc.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1F1871E51CA89FCD00A34BF2 /* MatcherFunc.swift */; };
1F1871EB1CA8A18800A34BF2 /* MatcherFunc.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1F1871E51CA89FCD00A34BF2 /* MatcherFunc.swift */; };
1F1A742F1940169200FFFC47 /* Nimble.h in Headers */ = {isa = PBXBuildFile; fileRef = 1F1A742E1940169200FFFC47 /* Nimble.h */; settings = {ATTRIBUTES = (Public, ); }; };
1F1A74351940169200FFFC47 /* Nimble.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 1F1A74291940169200FFFC47 /* Nimble.framework */; };
1F1B5AD41963E13900CA8BF9 /* BeAKindOfTest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1F1B5AD31963E13900CA8BF9 /* BeAKindOfTest.swift */; };
Expand Down Expand Up @@ -501,7 +498,6 @@
1F1871C31CA89EDB00A34BF2 /* NMBObjCMatcher.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = NMBObjCMatcher.swift; sourceTree = "<group>"; };
1F1871CD1CA89EE000A34BF2 /* ExceptionCapture.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ExceptionCapture.swift; sourceTree = "<group>"; };
1F1871E31CA89FB600A34BF2 /* Async.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Async.swift; sourceTree = "<group>"; };
1F1871E51CA89FCD00A34BF2 /* MatcherFunc.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MatcherFunc.swift; sourceTree = "<group>"; };
1F1A74291940169200FFFC47 /* Nimble.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Nimble.framework; sourceTree = BUILT_PRODUCTS_DIR; };
1F1A742D1940169200FFFC47 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
1F1A742E1940169200FFFC47 /* Nimble.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = Nimble.h; sourceTree = "<group>"; };
Expand Down Expand Up @@ -864,7 +860,6 @@
B20058C020E92C7500C1264D /* ElementsEqual.swift */,
472FD1341B9E085700C7B8DA /* HaveCount.swift */,
DDB4D5EC19FE43C200E9D9FE /* Match.swift */,
1F1871E51CA89FCD00A34BF2 /* MatcherFunc.swift */,
1FD8CD1D1968AB07008ED995 /* MatcherProtocols.swift */,
AE7ADE441C80BF8000B94CD3 /* MatchError.swift */,
1FCF91521C61C8A400B15DCB /* PostNotification.swift */,
Expand Down Expand Up @@ -1355,7 +1350,6 @@
1FD8CD441968AB07008ED995 /* BeginWith.swift in Sources */,
1FD8CD4A1968AB07008ED995 /* BeIdenticalTo.swift in Sources */,
1FE661581E6574E30035F243 /* ExpectationMessage.swift in Sources */,
1F1871E61CA89FCD00A34BF2 /* MatcherFunc.swift in Sources */,
1FD8CD421968AB07008ED995 /* BeEmpty.swift in Sources */,
1F1871E41CA89FB600A34BF2 /* Async.swift in Sources */,
1F1871CA1CA89EDB00A34BF2 /* NMBStringify.m in Sources */,
Expand Down Expand Up @@ -1493,7 +1487,6 @@
1F5DF16D1BDCA0F500C3A531 /* AdapterProtocols.swift in Sources */,
1F5DF17B1BDCA0F500C3A531 /* BeginWith.swift in Sources */,
1F5DF17E1BDCA0F500C3A531 /* BeIdenticalTo.swift in Sources */,
1F1871E91CA8A18700A34BF2 /* MatcherFunc.swift in Sources */,
1F5DF17A1BDCA0F500C3A531 /* BeEmpty.swift in Sources */,
1F5DF18C1BDCA0F500C3A531 /* Await.swift in Sources */,
1F1871D81CA89EEF00A34BF2 /* NMBStringify.m in Sources */,
Expand Down Expand Up @@ -1632,7 +1625,6 @@
1FD8CD491968AB07008ED995 /* BeGreaterThanOrEqualTo.swift in Sources */,
1FE661571E6574E30035F243 /* ExpectationMessage.swift in Sources */,
1FD8CD451968AB07008ED995 /* BeginWith.swift in Sources */,
1F1871EB1CA8A18800A34BF2 /* MatcherFunc.swift in Sources */,
1FD8CD4B1968AB07008ED995 /* BeIdenticalTo.swift in Sources */,
1FD8CD431968AB07008ED995 /* BeEmpty.swift in Sources */,
1F1871D41CA89EEE00A34BF2 /* NMBStringify.m in Sources */,
Expand Down
160 changes: 46 additions & 114 deletions Sources/Nimble/Adapters/NMBExpectation.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,26 +11,6 @@ private func from(objcPredicate: NMBPredicate) -> Predicate<NSObject> {
}
}

internal struct ObjCMatcherWrapper: Matcher {
let matcher: NMBMatcher

func matches(_ actualExpression: Expression<NSObject>, failureMessage: FailureMessage) -> Bool {
return matcher.matches(
// swiftlint:disable:next force_try
({ try! actualExpression.evaluate() }),
failureMessage: failureMessage,
location: actualExpression.location)
}

func doesNotMatch(_ actualExpression: Expression<NSObject>, failureMessage: FailureMessage) -> Bool {
return matcher.doesNotMatch(
// swiftlint:disable:next force_try
({ try! actualExpression.evaluate() }),
failureMessage: failureMessage,
location: actualExpression.location)
}
}

// Equivalent to Expectation, but for Nimble's Objective-C interface
public class NMBExpectation: NSObject {
// swiftlint:disable identifier_name
Expand Down Expand Up @@ -60,127 +40,79 @@ public class NMBExpectation: NSObject {
}
}

@objc public var to: (NMBMatcher) -> Void {
return { matcher in
if let pred = matcher as? NMBPredicate {
self.expectValue.to(from(objcPredicate: pred))
} else {
self.expectValue.to(ObjCMatcherWrapper(matcher: matcher))
}
@objc public var to: (NMBPredicate) -> Void {
return { pred in
self.expectValue.to(from(objcPredicate: pred))
}
}

@objc public var toWithDescription: (NMBMatcher, String) -> Void {
return { matcher, description in
if let pred = matcher as? NMBPredicate {
self.expectValue.to(from(objcPredicate: pred), description: description)
} else {
self.expectValue.to(ObjCMatcherWrapper(matcher: matcher), description: description)
}
@objc public var toWithDescription: (NMBPredicate, String) -> Void {
return { pred, description in
self.expectValue.to(from(objcPredicate: pred), description: description)
}
}

@objc public var toNot: (NMBMatcher) -> Void {
return { matcher in
if let pred = matcher as? NMBPredicate {
self.expectValue.toNot(from(objcPredicate: pred))
} else {
self.expectValue.toNot(ObjCMatcherWrapper(matcher: matcher))
}
@objc public var toNot: (NMBPredicate) -> Void {
return { pred in
self.expectValue.toNot(from(objcPredicate: pred))
}
}

@objc public var toNotWithDescription: (NMBMatcher, String) -> Void {
return { matcher, description in
if let pred = matcher as? NMBPredicate {
self.expectValue.toNot(from(objcPredicate: pred), description: description)
} else {
self.expectValue.toNot(ObjCMatcherWrapper(matcher: matcher), description: description)
}
@objc public var toNotWithDescription: (NMBPredicate, String) -> Void {
return { pred, description in
self.expectValue.toNot(from(objcPredicate: pred), description: description)
}
}

@objc public var notTo: (NMBMatcher) -> Void { return toNot }

@objc public var notToWithDescription: (NMBMatcher, String) -> Void { return toNotWithDescription }

@objc public var toEventually: (NMBMatcher) -> Void {
return { matcher in
if let pred = matcher as? NMBPredicate {
self.expectValue.toEventually(
from(objcPredicate: pred),
timeout: self._timeout,
description: nil
)
} else {
self.expectValue.toEventually(
ObjCMatcherWrapper(matcher: matcher),
timeout: self._timeout,
description: nil
)
}
@objc public var notTo: (NMBPredicate) -> Void { return toNot }

@objc public var notToWithDescription: (NMBPredicate, String) -> Void { return toNotWithDescription }

@objc public var toEventually: (NMBPredicate) -> Void {
return { pred in
self.expectValue.toEventually(
from(objcPredicate: pred),
timeout: self._timeout,
description: nil
)
}
}

@objc public var toEventuallyWithDescription: (NMBMatcher, String) -> Void {
return { matcher, description in
if let pred = matcher as? NMBPredicate {
self.expectValue.toEventually(
from(objcPredicate: pred),
timeout: self._timeout,
description: description
)
} else {
self.expectValue.toEventually(
ObjCMatcherWrapper(matcher: matcher),
timeout: self._timeout,
description: description
)
}
@objc public var toEventuallyWithDescription: (NMBPredicate, String) -> Void {
return { pred, description in
self.expectValue.toEventually(
from(objcPredicate: pred),
timeout: self._timeout,
description: description
)
}
}

@objc public var toEventuallyNot: (NMBMatcher) -> Void {
return { matcher in
if let pred = matcher as? NMBPredicate {
self.expectValue.toEventuallyNot(
from(objcPredicate: pred),
timeout: self._timeout,
description: nil
)
} else {
self.expectValue.toEventuallyNot(
ObjCMatcherWrapper(matcher: matcher),
timeout: self._timeout,
description: nil
)
}
@objc public var toEventuallyNot: (NMBPredicate) -> Void {
return { pred in
self.expectValue.toEventuallyNot(
from(objcPredicate: pred),
timeout: self._timeout,
description: nil
)
}
}

@objc public var toEventuallyNotWithDescription: (NMBMatcher, String) -> Void {
return { matcher, description in
if let pred = matcher as? NMBPredicate {
self.expectValue.toEventuallyNot(
from(objcPredicate: pred),
timeout: self._timeout,
description: description
)
} else {
self.expectValue.toEventuallyNot(
ObjCMatcherWrapper(matcher: matcher),
timeout: self._timeout,
description: description
)
}
@objc public var toEventuallyNotWithDescription: (NMBPredicate, String) -> Void {
return { pred, description in
self.expectValue.toEventuallyNot(
from(objcPredicate: pred),
timeout: self._timeout,
description: description
)
}
}

@objc public var toNotEventually: (NMBMatcher) -> Void {
@objc public var toNotEventually: (NMBPredicate) -> Void {
return toEventuallyNot
}

@objc public var toNotEventuallyWithDescription: (NMBMatcher, String) -> Void {
@objc public var toNotEventuallyWithDescription: (NMBPredicate, String) -> Void {
return toEventuallyNotWithDescription
}

Expand Down
52 changes: 0 additions & 52 deletions Sources/Nimble/Expectation.swift
Original file line number Diff line number Diff line change
@@ -1,23 +1,5 @@
import Foundation

// Deprecated
internal func expressionDoesNotMatch<T, U>(_ expression: Expression<T>, matcher: U, toNot: String, description: String?) -> (Bool, FailureMessage)
where U: Matcher, U.ValueType == T {
let msg = FailureMessage()
msg.userDescription = description
msg.to = toNot
do {
let pass = try matcher.doesNotMatch(expression, failureMessage: msg)
if msg.actualValue == "" {
msg.actualValue = "<\(stringify(try expression.evaluate()))>"
}
return (pass, msg)
} catch let error {
msg.stringValue = "unexpected error thrown: <\(error)>"
return (false, msg)
}
}

internal func execute<T>(_ expression: Expression<T>, _ style: ExpectationStyle, _ predicate: Predicate<T>, to: String, description: String?, captureExceptions: Bool = true) -> (Bool, FailureMessage) {
func run() -> (Bool, FailureMessage) {
let msg = FailureMessage()
Expand Down Expand Up @@ -66,40 +48,6 @@ public struct Expectation<T> {
handler.assert(pass, message: message, location: expression.location)
}

////////////////// OLD API /////////////////////

/// DEPRECATED: Tests the actual value using a matcher to match.
public func to<U>(_ matcher: U, description: String? = nil)
where U: Matcher, U.ValueType == T {
let (pass, msg) = execute(
expression,
.toMatch,
matcher.predicate,
to: "to",
description: description,
captureExceptions: false
)
verify(pass, msg)
}

/// DEPRECATED: Tests the actual value using a matcher to not match.
public func toNot<U>(_ matcher: U, description: String? = nil)
where U: Matcher, U.ValueType == T {
// swiftlint:disable:next line_length
let (pass, msg) = expressionDoesNotMatch(expression, matcher: matcher, toNot: "to not", description: description)
verify(pass, msg)
}

/// DEPRECATED: Tests the actual value using a matcher to not match.
///
/// Alias to toNot().
public func notTo<U>(_ matcher: U, description: String? = nil)
where U: Matcher, U.ValueType == T {
toNot(matcher, description: description)
}

////////////////// NEW API /////////////////////

/// Tests the actual value using a matcher to match.
public func to(_ predicate: Predicate<T>, description: String? = nil) {
let (pass, msg) = execute(expression, .toMatch, predicate, to: "to", description: description)
Expand Down
5 changes: 0 additions & 5 deletions Sources/Nimble/Matchers/AllPass.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,6 @@ public func allPass<T, U>
return createPredicate(matcher)
}

public func allPass<S, M>(_ elementMatcher: M) -> Predicate<S>
where S: Sequence, M: Matcher, S.Iterator.Element == M.ValueType {
return createPredicate(elementMatcher.predicate)
}

public func allPass<S>(_ elementPredicate: Predicate<S.Iterator.Element>) -> Predicate<S>
where S: Sequence {
return createPredicate(elementPredicate)
Expand Down
Loading