forked from Quick/Nimble
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBeAKindOfTest.swift
77 lines (65 loc) · 2.97 KB
/
BeAKindOfTest.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
import Foundation
import XCTest
import Nimble
private class TestNull: NSNull {}
private protocol TestProtocol {}
private class TestClassConformingToProtocol: TestProtocol {}
private struct TestStructConformingToProtocol: TestProtocol {}
final class BeAKindOfSwiftTest: XCTestCase {
enum TestEnum {
case one, two
}
func testPositiveMatch() {
expect(1).to(beAKindOf(Int.self))
expect(1).toNot(beAKindOf(String.self))
expect("turtle string").to(beAKindOf(String.self))
expect("turtle string").toNot(beAKindOf(TestClassConformingToProtocol.self))
expect(TestEnum.one).to(beAKindOf(TestEnum.self))
let testProtocolClass = TestClassConformingToProtocol()
expect(testProtocolClass).to(beAKindOf(TestClassConformingToProtocol.self))
expect(testProtocolClass).to(beAKindOf(TestProtocol.self))
expect(testProtocolClass).toNot(beAKindOf(TestStructConformingToProtocol.self))
let testProtocolStruct = TestStructConformingToProtocol()
expect(testProtocolStruct).to(beAKindOf(TestStructConformingToProtocol.self))
expect(testProtocolStruct).to(beAKindOf(TestProtocol.self))
expect(testProtocolStruct).toNot(beAKindOf(TestClassConformingToProtocol.self))
}
func testFailureMessages() {
failsWithErrorMessage("expected to not be a kind of Int, got <Int instance>") {
expect(1).toNot(beAKindOf(Int.self))
}
let testClass = TestClassConformingToProtocol()
failsWithErrorMessage("expected to not be a kind of \(String(describing: TestProtocol.self)), got <\(String(describing: TestClassConformingToProtocol.self)) instance>") {
expect(testClass).toNot(beAKindOf(TestProtocol.self))
}
failsWithErrorMessage("expected to be a kind of String, got <Int instance>") {
expect(1).to(beAKindOf(String.self))
}
}
}
final class BeAKindOfObjCTest: XCTestCase {
func testPositiveMatch() {
expect(TestNull()).to(beAKindOf(NSNull.self))
expect(NSObject()).to(beAKindOf(NSObject.self))
expect(1 as NSNumber).toNot(beAKindOf(NSDate.self))
}
func testFailureMessages() {
failsWithErrorMessageForNil("expected to not be a kind of NSNull, got <nil>") {
expect(nil as NSNull?).toNot(beAKindOf(NSNull.self))
}
failsWithErrorMessageForNil("expected to be a kind of NSString, got <nil>") {
expect(nil as NSString?).to(beAKindOf(NSString.self))
}
#if canImport(Darwin)
let numberTypeName = "__NSCFNumber"
#else
let numberTypeName = "NSNumber"
#endif
failsWithErrorMessage("expected to be a kind of NSString, got <\(numberTypeName) instance>") {
expect(1 as NSNumber).to(beAKindOf(NSString.self))
}
failsWithErrorMessage("expected to not be a kind of NSNumber, got <\(numberTypeName) instance>") {
expect(1 as NSNumber).toNot(beAKindOf(NSNumber.self))
}
}
}