How to use testShouldMatchTrue method of BeTruthyTest class

Best Nimble code snippet using BeTruthyTest.testShouldMatchTrue

Run Nimble automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

BeLogicalTest.swift

Source: BeLogicalTest.swift Github

copy
1import XCTest
2import Nimble
3import Foundation
4
5enum ConvertsToBool: ExpressibleByBooleanLiteral, CustomStringConvertible {
6    case trueLike, falseLike
7
8    typealias BooleanLiteralType = Bool
9
10    init(booleanLiteral value: Bool) {
11        switch value {
12        case true: self = .trueLike
13        case false: self = .falseLike
14        }
15    }
16
17    var boolValue: Bool {
18        switch self {
19        case .trueLike: return true
20        case .falseLike: return false
21        }
22    }
23
24    var description: String {
25        switch self {
26        case .trueLike: return "TrueLike"
27        case .falseLike: return "FalseLike"
28        }
29    }
30}
31
32final class BeTruthyTest: XCTestCase, XCTestCaseProvider {
33    static var allTests: [(String, (BeTruthyTest) -> () throws -> Void)] {
34        return [
35            ("testShouldMatchNonNilTypes", testShouldMatchNonNilTypes),
36            ("testShouldMatchTrue", testShouldMatchTrue),
37            ("testShouldNotMatchNilTypes", testShouldNotMatchNilTypes),
38            ("testShouldNotMatchFalse", testShouldNotMatchFalse),
39            ("testShouldNotMatchNilBools", testShouldNotMatchNilBools),
40            ("testShouldMatchBoolConvertibleTypesThatConvertToTrue", testShouldMatchBoolConvertibleTypesThatConvertToTrue),
41            ("testShouldNotMatchBoolConvertibleTypesThatConvertToFalse", testShouldNotMatchBoolConvertibleTypesThatConvertToFalse),
42        ]
43    }
44
45    func testShouldMatchNonNilTypes() {
46        expect(true as Bool?).to(beTruthy())
47
48        // Support types conforming to `ExpressibleByBooleanLiteral`
49        // Nimble extend following types as conforming to `ExpressibleByBooleanLiteral`
50        expect(1 as Int8?).to(beTruthy())
51        expect(1 as UInt8?).to(beTruthy())
52        expect(1 as Int16?).to(beTruthy())
53        expect(1 as UInt16?).to(beTruthy())
54        expect(1 as Int32?).to(beTruthy())
55        expect(1 as UInt32?).to(beTruthy())
56        expect(1 as Int64?).to(beTruthy())
57        expect(1 as UInt64?).to(beTruthy())
58        expect(1 as Float?).to(beTruthy())
59        expect(1 as Double?).to(beTruthy())
60        expect(1 as Int?).to(beTruthy())
61        expect(1 as UInt?).to(beTruthy())
62    }
63
64    func testShouldMatchTrue() {
65        expect(true).to(beTruthy())
66
67        failsWithErrorMessage("expected to not be truthy, got <true>") {
68            expect(true).toNot(beTruthy())
69        }
70    }
71
72    func testShouldNotMatchNilTypes() {
73        expect(false as Bool?).toNot(beTruthy())
74
75        // Support types conforming to `ExpressibleByBooleanLiteral`
76        // Nimble extend following types as conforming to `ExpressibleByBooleanLiteral`
77        expect(nil as Bool?).toNot(beTruthy())
78        expect(nil as Int8?).toNot(beTruthy())
79        expect(nil as UInt8?).toNot(beTruthy())
80        expect(nil as Int16?).toNot(beTruthy())
81        expect(nil as UInt16?).toNot(beTruthy())
82        expect(nil as Int32?).toNot(beTruthy())
83        expect(nil as UInt32?).toNot(beTruthy())
84        expect(nil as Int64?).toNot(beTruthy())
85        expect(nil as UInt64?).toNot(beTruthy())
86        expect(nil as Float?).toNot(beTruthy())
87        expect(nil as Double?).toNot(beTruthy())
88        expect(nil as Int?).toNot(beTruthy())
89        expect(nil as UInt?).toNot(beTruthy())
90    }
91
92    func testShouldNotMatchFalse() {
93        expect(false).toNot(beTruthy())
94
95        failsWithErrorMessage("expected to be truthy, got <false>") {
96            expect(false).to(beTruthy())
97        }
98    }
99
100    func testShouldNotMatchNilBools() {
101        expect(nil as Bool?).toNot(beTruthy())
102
103        failsWithErrorMessage("expected to be truthy, got <nil>") {
104            expect(nil as Bool?).to(beTruthy())
105        }
106    }
107
108    func testShouldMatchBoolConvertibleTypesThatConvertToTrue() {
109        expect(ConvertsToBool.trueLike).to(beTruthy())
110
111        failsWithErrorMessage("expected to not be truthy, got <TrueLike>") {
112            expect(ConvertsToBool.trueLike).toNot(beTruthy())
113        }
114    }
115
116    func testShouldNotMatchBoolConvertibleTypesThatConvertToFalse() {
117        expect(ConvertsToBool.falseLike).toNot(beTruthy())
118
119        failsWithErrorMessage("expected to be truthy, got <FalseLike>") {
120            expect(ConvertsToBool.falseLike).to(beTruthy())
121        }
122    }
123}
124
125final class BeTrueTest: XCTestCase, XCTestCaseProvider {
126    static var allTests: [(String, (BeTrueTest) -> () throws -> Void)] {
127        return [
128            ("testShouldMatchTrue", testShouldMatchTrue),
129            ("testShouldNotMatchFalse", testShouldNotMatchFalse),
130            ("testShouldNotMatchNilBools", testShouldNotMatchNilBools),
131        ]
132    }
133
134    func testShouldMatchTrue() {
135        expect(true).to(beTrue())
136
137        failsWithErrorMessage("expected to not be true, got <true>") {
138            expect(true).toNot(beTrue())
139        }
140    }
141
142    func testShouldNotMatchFalse() {
143        expect(false).toNot(beTrue())
144
145        failsWithErrorMessage("expected to be true, got <false>") {
146            expect(false).to(beTrue())
147        }
148    }
149
150    func testShouldNotMatchNilBools() {
151        failsWithErrorMessageForNil("expected to not be true, got <nil>") {
152            expect(nil as Bool?).toNot(beTrue())
153        }
154
155        failsWithErrorMessageForNil("expected to be true, got <nil>") {
156            expect(nil as Bool?).to(beTrue())
157        }
158    }
159}
160
161final class BeFalsyTest: XCTestCase, XCTestCaseProvider {
162    static var allTests: [(String, (BeFalsyTest) -> () throws -> Void)] {
163        return [
164            ("testShouldMatchNilTypes", testShouldMatchNilTypes),
165            ("testShouldNotMatchTrue", testShouldNotMatchTrue),
166            ("testShouldNotMatchNonNilTypes", testShouldNotMatchNonNilTypes),
167            ("testShouldMatchFalse", testShouldMatchFalse),
168            ("testShouldMatchNilBools", testShouldMatchNilBools),
169        ]
170    }
171
172    func testShouldMatchNilTypes() {
173        expect(false as Bool?).to(beFalsy())
174
175        // Support types conforming to `ExpressibleByBooleanLiteral`
176        // Nimble extend following types as conforming to `ExpressibleByBooleanLiteral`
177        expect(nil as Bool?).to(beFalsy())
178        expect(nil as Int8?).to(beFalsy())
179        expect(nil as UInt8?).to(beFalsy())
180        expect(nil as Int16?).to(beFalsy())
181        expect(nil as UInt16?).to(beFalsy())
182        expect(nil as Int32?).to(beFalsy())
183        expect(nil as UInt32?).to(beFalsy())
184        expect(nil as Int64?).to(beFalsy())
185        expect(nil as UInt64?).to(beFalsy())
186        expect(nil as Float?).to(beFalsy())
187        expect(nil as Double?).to(beFalsy())
188        expect(nil as Int?).to(beFalsy())
189        expect(nil as UInt?).to(beFalsy())
190    }
191
192    func testShouldNotMatchTrue() {
193        expect(true).toNot(beFalsy())
194
195        failsWithErrorMessage("expected to be falsy, got <true>") {
196            expect(true).to(beFalsy())
197        }
198    }
199
200    func testShouldNotMatchNonNilTypes() {
201        expect(true as Bool?).toNot(beFalsy())
202
203        // Support types conforming to `ExpressibleByBooleanLiteral`
204        // Nimble extend following types as conforming to `ExpressibleByBooleanLiteral`
205        expect(1 as Int8?).toNot(beFalsy())
206        expect(1 as UInt8?).toNot(beFalsy())
207        expect(1 as Int16?).toNot(beFalsy())
208        expect(1 as UInt16?).toNot(beFalsy())
209        expect(1 as Int32?).toNot(beFalsy())
210        expect(1 as UInt32?).toNot(beFalsy())
211        expect(1 as Int64?).toNot(beFalsy())
212        expect(1 as UInt64?).toNot(beFalsy())
213        expect(1 as Float?).toNot(beFalsy())
214        expect(1 as Double?).toNot(beFalsy())
215        expect(1 as Int?).toNot(beFalsy())
216        expect(1 as UInt?).toNot(beFalsy())
217    }
218
219    func testShouldMatchFalse() {
220        expect(false).to(beFalsy())
221
222        failsWithErrorMessage("expected to not be falsy, got <false>") {
223            expect(false).toNot(beFalsy())
224        }
225    }
226
227    func testShouldMatchNilBools() {
228        expect(nil as Bool?).to(beFalsy())
229
230        failsWithErrorMessage("expected to not be falsy, got <nil>") {
231            expect(nil as Bool?).toNot(beFalsy())
232        }
233    }
234}
235
236final class BeFalseTest: XCTestCase, XCTestCaseProvider {
237    static var allTests: [(String, (BeFalseTest) -> () throws -> Void)] {
238        return [
239            ("testShouldNotMatchTrue", testShouldNotMatchTrue),
240            ("testShouldMatchFalse", testShouldMatchFalse),
241            ("testShouldNotMatchNilBools", testShouldNotMatchNilBools),
242        ]
243    }
244
245    func testShouldNotMatchTrue() {
246        expect(true).toNot(beFalse())
247
248        failsWithErrorMessage("expected to be false, got <true>") {
249            expect(true).to(beFalse())
250        }
251    }
252
253    func testShouldMatchFalse() {
254        expect(false).to(beFalse())
255
256        failsWithErrorMessage("expected to not be false, got <false>") {
257            expect(false).toNot(beFalse())
258        }
259    }
260
261    func testShouldNotMatchNilBools() {
262        failsWithErrorMessageForNil("expected to be false, got <nil>") {
263            expect(nil as Bool?).to(beFalse())
264        }
265
266        failsWithErrorMessageForNil("expected to not be false, got <nil>") {
267            expect(nil as Bool?).toNot(beFalse())
268        }
269    }
270}
271
Full Screen

Accelerate Your Automation Test Cycles With LambdaTest

Leverage LambdaTest’s cloud-based platform to execute your automation tests in parallel and trim down your test execution time significantly. Your first 100 automation testing minutes are on us.

Try LambdaTest

Trigger testShouldMatchTrue code on LambdaTest Cloud Grid

Execute automation tests with testShouldMatchTrue on a cloud-based Grid of 3000+ real browsers and operating systems for both web and mobile applications.

Test now for Free
LambdaTestX

We use cookies to give you the best experience. Cookies help to provide a more personalized experience and relevant advertising for you, and web analytics for us. Learn More in our Cookies policy, Privacy & Terms of service

Allow Cookie
Sarah

I hope you find the best code examples for your project.

If you want to accelerate automated browser testing, try LambdaTest. Your first 100 automation testing minutes are FREE.

Sarah Elson (Product & Growth Lead)