How to use testContainNSStringSubstring method of ContainTest class

Best Nimble code snippet using ContainTest.testContainNSStringSubstring

Run Nimble automation tests on LambdaTest cloud grid

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

ContainTest.swift

Source: ContainTest.swift Github

copy
1import Foundation
2import XCTest
3import Nimble
4
5final class ContainTest: XCTestCase {
6    func testContainSequence() {
7        expect([1, 2, 3]).to(contain(1))
8        expect([1, 2, 3]).toNot(contain(4))
9        expect([1, 2, 3] as [CInt]).to(contain(1 as CInt))
10        expect([1, 2, 3] as [CInt]).toNot(contain(4 as CInt))
11        expect(["foo", "bar", "baz"]).to(contain("baz"))
12        expect(["foo", "bar", "baz"]).toNot(contain("ba"))
13#if canImport(Darwin)
14        expect(["a"] as NSArray).to(contain("a" as NSString))
15        expect(["a"] as NSArray).toNot(contain("b" as NSString))
16        expect([1] as NSArray?).to(contain(1))
17#endif
18
19        failsWithErrorMessage("expected to contain <bar>, got <[a, b, c]>") {
20            expect(["a", "b", "c"]).to(contain("bar"))
21        }
22        failsWithErrorMessage("expected to not contain <b>, got <[a, b, c]>") {
23            expect(["a", "b", "c"]).toNot(contain("b"))
24        }
25
26        failsWithErrorMessageForNil("expected to contain <bar>, got <nil>") {
27            expect(nil as [String]?).to(contain("bar"))
28        }
29        failsWithErrorMessageForNil("expected to not contain <b>, got <nil>") {
30            expect(nil as [String]?).toNot(contain("b"))
31        }
32    }
33
34    func testContainSetAlgebra() {
35        expect([.a, .b, .c] as TestOptionSet).to(contain(.a))
36        expect([.a, .b, .c] as TestOptionSet).toNot(contain(.d))
37
38        failsWithErrorMessage("expected to contain <8>, got <7>") {
39            expect([.a, .b, .c] as TestOptionSet).to(contain(.d))
40        }
41        failsWithErrorMessage("expected to not contain <2>, got <7>") {
42            expect([.a, .b, .c] as TestOptionSet).toNot(contain(.b))
43        }
44
45        failsWithErrorMessageForNil("expected to contain <1>, got <nil>") {
46            expect(nil as TestOptionSet?).to(contain(.a))
47        }
48        failsWithErrorMessageForNil("expected to not contain <1>, got <nil>") {
49            expect(nil as TestOptionSet?).toNot(contain(.a))
50        }
51    }
52
53    func testContainSequenceAndSetAlgebra() {
54        let set = [1, 2, 3] as Set<Int>
55
56        expect(set).to(contain(1))
57        expect(set).toNot(contain(4))
58
59        failsWithErrorMessage("expected to contain <4>, got <\(set.debugDescription)>") {
60            expect(set).to(contain(4))
61        }
62        failsWithErrorMessage("expected to not contain <2>, got <\(set.debugDescription)>") {
63            expect(set).toNot(contain(2))
64        }
65
66        failsWithErrorMessageForNil("expected to contain <1>, got <nil>") {
67            expect(nil as Set<Int>?).to(contain(1))
68        }
69        failsWithErrorMessageForNil("expected to not contain <1>, got <nil>") {
70            expect(nil as Set<Int>?).toNot(contain(1))
71        }
72    }
73
74    func testContainSubstring() {
75        expect("foo").to(contain("o"))
76        expect("foo").to(contain("oo"))
77        expect("foo").toNot(contain("z"))
78        expect("foo").toNot(contain("zz"))
79
80        failsWithErrorMessage("expected to contain <bar>, got <foo>") {
81            expect("foo").to(contain("bar"))
82        }
83        failsWithErrorMessage("expected to not contain <oo>, got <foo>") {
84            expect("foo").toNot(contain("oo"))
85        }
86    }
87
88    func testContainNSStringSubstring() {
89        let str = "foo" as NSString
90        expect(str).to(contain("o" as NSString))
91        expect(str).to(contain("oo" as NSString))
92        expect(str).toNot(contain("z" as NSString))
93        expect(str).toNot(contain("zz" as NSString))
94    }
95
96    func testVariadicArguments() {
97        expect([1, 2, 3]).to(contain(1, 2))
98        expect([1, 2, 3]).toNot(contain(1, 4))
99
100        failsWithErrorMessage("expected to contain <a, bar>, got <[a, b, c]>") {
101            expect(["a", "b", "c"]).to(contain("a", "bar"))
102        }
103
104        failsWithErrorMessage("expected to not contain <b, a>, got <[a, b, c]>") {
105            expect(["a", "b", "c"]).toNot(contain("b", "a"))
106        }
107    }
108
109    func testCollectionArguments() {
110        expect([1, 2, 3]).to(contain([1, 2]))
111        expect([1, 2, 3]).toNot(contain([1, 4]))
112
113        let collection = Array(1...10)
114        let slice = Array(collection[3...5])
115        expect(collection).to(contain(slice))
116
117        failsWithErrorMessage("expected to contain <a, bar>, got <[a, b, c]>") {
118            expect(["a", "b", "c"]).to(contain(["a", "bar"]))
119        }
120
121        failsWithErrorMessage("expected to not contain <b, a>, got <[a, b, c]>") {
122            expect(["a", "b", "c"]).toNot(contain(["b", "a"]))
123        }
124    }
125}
126
127private struct TestOptionSet: OptionSet, CustomStringConvertible {
128    let rawValue: Int
129
130    // swiftlint:disable identifier_name
131    static let a = TestOptionSet(rawValue: 1 << 0)
132    static let b = TestOptionSet(rawValue: 1 << 1)
133    static let c = TestOptionSet(rawValue: 1 << 2)
134    static let d = TestOptionSet(rawValue: 1 << 3)
135    static let e = TestOptionSet(rawValue: 1 << 4)
136    // swiftlint:enable identifier_name
137
138    init(rawValue: Int) {
139        self.rawValue = rawValue
140    }
141
142    var description: String {
143        return "\(rawValue)"
144    }
145}
146
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 testContainNSStringSubstring code on LambdaTest Cloud Grid

Execute automation tests with testContainNSStringSubstring 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)