forked from Quick/Nimble
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBeLogicalTest.swift
232 lines (191 loc) · 7.12 KB
/
BeLogicalTest.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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
import XCTest
import Nimble
import Foundation
enum ConvertsToBool: ExpressibleByBooleanLiteral, CustomStringConvertible {
case trueLike, falseLike
typealias BooleanLiteralType = Bool
init(booleanLiteral value: Bool) {
switch value {
case true: self = .trueLike
case false: self = .falseLike
}
}
var boolValue: Bool {
switch self {
case .trueLike: return true
case .falseLike: return false
}
}
var description: String {
switch self {
case .trueLike: return "TrueLike"
case .falseLike: return "FalseLike"
}
}
}
final class BeTruthyTest: XCTestCase {
func testShouldMatchNonNilTypes() {
expect(true as Bool?).to(beTruthy())
// Support types conforming to `ExpressibleByBooleanLiteral`
// Nimble extend following types as conforming to `ExpressibleByBooleanLiteral`
expect(1 as Int8?).to(beTruthy())
expect(1 as UInt8?).to(beTruthy())
expect(1 as Int16?).to(beTruthy())
expect(1 as UInt16?).to(beTruthy())
expect(1 as Int32?).to(beTruthy())
expect(1 as UInt32?).to(beTruthy())
expect(1 as Int64?).to(beTruthy())
expect(1 as UInt64?).to(beTruthy())
expect(1 as Float?).to(beTruthy())
expect(1 as Double?).to(beTruthy())
expect(1 as Int?).to(beTruthy())
expect(1 as UInt?).to(beTruthy())
}
func testShouldMatchTrue() {
expect(true).to(beTruthy())
failsWithErrorMessage("expected to not be truthy, got <true>") {
expect(true).toNot(beTruthy())
}
}
func testShouldNotMatchNilTypes() {
expect(false as Bool?).toNot(beTruthy())
// Support types conforming to `ExpressibleByBooleanLiteral`
// Nimble extend following types as conforming to `ExpressibleByBooleanLiteral`
expect(nil as Bool?).toNot(beTruthy())
expect(nil as Int8?).toNot(beTruthy())
expect(nil as UInt8?).toNot(beTruthy())
expect(nil as Int16?).toNot(beTruthy())
expect(nil as UInt16?).toNot(beTruthy())
expect(nil as Int32?).toNot(beTruthy())
expect(nil as UInt32?).toNot(beTruthy())
expect(nil as Int64?).toNot(beTruthy())
expect(nil as UInt64?).toNot(beTruthy())
expect(nil as Float?).toNot(beTruthy())
expect(nil as Double?).toNot(beTruthy())
expect(nil as Int?).toNot(beTruthy())
expect(nil as UInt?).toNot(beTruthy())
}
func testShouldNotMatchFalse() {
expect(false).toNot(beTruthy())
failsWithErrorMessage("expected to be truthy, got <false>") {
expect(false).to(beTruthy())
}
}
func testShouldNotMatchNilBools() {
expect(nil as Bool?).toNot(beTruthy())
failsWithErrorMessage("expected to be truthy, got <nil>") {
expect(nil as Bool?).to(beTruthy())
}
}
func testShouldMatchBoolConvertibleTypesThatConvertToTrue() {
expect(ConvertsToBool.trueLike).to(beTruthy())
failsWithErrorMessage("expected to not be truthy, got <TrueLike>") {
expect(ConvertsToBool.trueLike).toNot(beTruthy())
}
}
func testShouldNotMatchBoolConvertibleTypesThatConvertToFalse() {
expect(ConvertsToBool.falseLike).toNot(beTruthy())
failsWithErrorMessage("expected to be truthy, got <FalseLike>") {
expect(ConvertsToBool.falseLike).to(beTruthy())
}
}
}
final class BeTrueTest: XCTestCase {
func testShouldMatchTrue() {
expect(true).to(beTrue())
failsWithErrorMessage("expected to not be true, got <true>") {
expect(true).toNot(beTrue())
}
}
func testShouldNotMatchFalse() {
expect(false).toNot(beTrue())
failsWithErrorMessage("expected to be true, got <false>") {
expect(false).to(beTrue())
}
}
func testShouldNotMatchNilBools() {
failsWithErrorMessageForNil("expected to not be true, got <nil>") {
expect(nil as Bool?).toNot(beTrue())
}
failsWithErrorMessageForNil("expected to be true, got <nil>") {
expect(nil as Bool?).to(beTrue())
}
}
}
final class BeFalsyTest: XCTestCase {
func testShouldMatchNilTypes() {
expect(false as Bool?).to(beFalsy())
// Support types conforming to `ExpressibleByBooleanLiteral`
// Nimble extend following types as conforming to `ExpressibleByBooleanLiteral`
expect(nil as Bool?).to(beFalsy())
expect(nil as Int8?).to(beFalsy())
expect(nil as UInt8?).to(beFalsy())
expect(nil as Int16?).to(beFalsy())
expect(nil as UInt16?).to(beFalsy())
expect(nil as Int32?).to(beFalsy())
expect(nil as UInt32?).to(beFalsy())
expect(nil as Int64?).to(beFalsy())
expect(nil as UInt64?).to(beFalsy())
expect(nil as Float?).to(beFalsy())
expect(nil as Double?).to(beFalsy())
expect(nil as Int?).to(beFalsy())
expect(nil as UInt?).to(beFalsy())
}
func testShouldNotMatchTrue() {
expect(true).toNot(beFalsy())
failsWithErrorMessage("expected to be falsy, got <true>") {
expect(true).to(beFalsy())
}
}
func testShouldNotMatchNonNilTypes() {
expect(true as Bool?).toNot(beFalsy())
// Support types conforming to `ExpressibleByBooleanLiteral`
// Nimble extend following types as conforming to `ExpressibleByBooleanLiteral`
expect(1 as Int8?).toNot(beFalsy())
expect(1 as UInt8?).toNot(beFalsy())
expect(1 as Int16?).toNot(beFalsy())
expect(1 as UInt16?).toNot(beFalsy())
expect(1 as Int32?).toNot(beFalsy())
expect(1 as UInt32?).toNot(beFalsy())
expect(1 as Int64?).toNot(beFalsy())
expect(1 as UInt64?).toNot(beFalsy())
expect(1 as Float?).toNot(beFalsy())
expect(1 as Double?).toNot(beFalsy())
expect(1 as Int?).toNot(beFalsy())
expect(1 as UInt?).toNot(beFalsy())
}
func testShouldMatchFalse() {
expect(false).to(beFalsy())
failsWithErrorMessage("expected to not be falsy, got <false>") {
expect(false).toNot(beFalsy())
}
}
func testShouldMatchNilBools() {
expect(nil as Bool?).to(beFalsy())
failsWithErrorMessage("expected to not be falsy, got <nil>") {
expect(nil as Bool?).toNot(beFalsy())
}
}
}
final class BeFalseTest: XCTestCase {
func testShouldNotMatchTrue() {
expect(true).toNot(beFalse())
failsWithErrorMessage("expected to be false, got <true>") {
expect(true).to(beFalse())
}
}
func testShouldMatchFalse() {
expect(false).to(beFalse())
failsWithErrorMessage("expected to not be false, got <false>") {
expect(false).toNot(beFalse())
}
}
func testShouldNotMatchNilBools() {
failsWithErrorMessageForNil("expected to be false, got <nil>") {
expect(nil as Bool?).to(beFalse())
}
failsWithErrorMessageForNil("expected to not be false, got <nil>") {
expect(nil as Bool?).toNot(beFalse())
}
}
}