~danielborges93/openlp/ios-new-localization-system

« back to all changes in this revision

Viewing changes to Pods/Nimble/Sources/Nimble/Matchers/BeAKindOf.swift

  • Committer: Daniel Borges
  • Date: 2016-07-03 18:15:32 UTC
  • mfrom: (53.1.3 delete-pods)
  • Revision ID: daniel_borges_93@yahoo.com.br-20160703181532-7n8op16rcl15em5o
DeleteĀ PodsĀ folder.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
import Foundation
2
 
 
3
 
#if _runtime(_ObjC)
4
 
 
5
 
// A Nimble matcher that catches attempts to use beAKindOf with non Objective-C types
6
 
public func beAKindOf(expectedClass: Any) -> NonNilMatcherFunc<Any> {
7
 
    return NonNilMatcherFunc {actualExpression, failureMessage in
8
 
        failureMessage.stringValue = "beAKindOf only works on Objective-C types since"
9
 
            + " the Swift compiler will automatically type check Swift-only types."
10
 
            + " This expectation is redundant."
11
 
        return false
12
 
    }
13
 
}
14
 
 
15
 
/// A Nimble matcher that succeeds when the actual value is an instance of the given class.
16
 
/// @see beAnInstanceOf if you want to match against the exact class
17
 
public func beAKindOf(expectedClass: AnyClass) -> NonNilMatcherFunc<NSObject> {
18
 
    return NonNilMatcherFunc { actualExpression, failureMessage in
19
 
        let instance = try actualExpression.evaluate()
20
 
        if let validInstance = instance {
21
 
            failureMessage.actualValue = "<\(classAsString(validInstance.dynamicType)) instance>"
22
 
        } else {
23
 
            failureMessage.actualValue = "<nil>"
24
 
        }
25
 
        failureMessage.postfixMessage = "be a kind of \(classAsString(expectedClass))"
26
 
        return instance != nil && instance!.isKindOfClass(expectedClass)
27
 
    }
28
 
}
29
 
 
30
 
extension NMBObjCMatcher {
31
 
    public class func beAKindOfMatcher(expected: AnyClass) -> NMBMatcher {
32
 
        return NMBObjCMatcher(canMatchNil: false) { actualExpression, failureMessage in
33
 
            return try! beAKindOf(expected).matches(actualExpression, failureMessage: failureMessage)
34
 
        }
35
 
    }
36
 
}
37
 
 
38
 
#endif