How to use testVariadicArguments method of ContainTest class

Best Nimble code snippet using ContainTest.testVariadicArguments

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, XCTestCaseProvider {
6    static var allTests: [(String, (ContainTest) -> () throws -> Void)] {
7        return [
8            ("testContain", testContain),
9            ("testContainSubstring", testContainSubstring),
10            ("testContainObjCSubstring", testContainObjCSubstring),
11            ("testVariadicArguments", testVariadicArguments),
12            ("testCollectionArguments", testCollectionArguments),
13        ]
14    }
15
16    func testContain() {
17        expect([1, 2, 3]).to(contain(1))
18        expect([1, 2, 3] as [CInt]).to(contain(1 as CInt))
19        expect([1, 2, 3] as Array<CInt>).to(contain(1 as CInt))
20        expect(["foo", "bar", "baz"]).to(contain("baz"))
21        expect([1, 2, 3]).toNot(contain(4))
22        expect(["foo", "bar", "baz"]).toNot(contain("ba"))
23#if _runtime(_ObjC)
24        expect(NSArray(array: ["a"])).to(contain(NSString(string: "a")))
25        expect(NSArray(array: ["a"])).toNot(contain(NSString(string:"b")))
26        expect(NSArray(object: 1) as NSArray?).to(contain(1))
27#endif
28
29        failsWithErrorMessage("expected to contain <bar>, got <[a, b, c]>") {
30            expect(["a", "b", "c"]).to(contain("bar"))
31        }
32        failsWithErrorMessage("expected to not contain <b>, got <[a, b, c]>") {
33            expect(["a", "b", "c"]).toNot(contain("b"))
34        }
35
36        failsWithErrorMessageForNil("expected to contain <bar>, got <nil>") {
37            expect(nil as [String]?).to(contain("bar"))
38        }
39        failsWithErrorMessageForNil("expected to not contain <b>, got <nil>") {
40            expect(nil as [String]?).toNot(contain("b"))
41        }
42    }
43
44    func testContainSubstring() {
45        expect("foo").to(contain("o"))
46        expect("foo").to(contain("oo"))
47        expect("foo").toNot(contain("z"))
48        expect("foo").toNot(contain("zz"))
49
50        failsWithErrorMessage("expected to contain <bar>, got <foo>") {
51            expect("foo").to(contain("bar"))
52        }
53        failsWithErrorMessage("expected to not contain <oo>, got <foo>") {
54            expect("foo").toNot(contain("oo"))
55        }
56    }
57
58    func testContainObjCSubstring() {
59        let str = NSString(string: "foo")
60        expect(str).to(contain(NSString(string: "o")))
61        expect(str).to(contain(NSString(string: "oo")))
62        expect(str).toNot(contain(NSString(string: "z")))
63        expect(str).toNot(contain(NSString(string: "zz")))
64    }
65
66    func testVariadicArguments() {
67        expect([1, 2, 3]).to(contain(1, 2))
68        expect([1, 2, 3]).toNot(contain(1, 4))
69
70        failsWithErrorMessage("expected to contain <a, bar>, got <[a, b, c]>") {
71            expect(["a", "b", "c"]).to(contain("a", "bar"))
72        }
73
74        failsWithErrorMessage("expected to not contain <bar, b>, got <[a, b, c]>") {
75            expect(["a", "b", "c"]).toNot(contain("bar", "b"))
76        }
77    }
78
79    func testCollectionArguments() {
80        expect([1, 2, 3]).to(contain([1, 2]))
81        expect([1, 2, 3]).toNot(contain([1, 4]))
82
83        let collection = Array(1...10)
84        let slice = Array(collection[3...5])
85        expect(collection).to(contain(slice))
86
87        failsWithErrorMessage("expected to contain <a, bar>, got <[a, b, c]>") {
88            expect(["a", "b", "c"]).to(contain(["a", "bar"]))
89        }
90
91        failsWithErrorMessage("expected to not contain <bar, b>, got <[a, b, c]>") {
92            expect(["a", "b", "c"]).toNot(contain(["bar", "b"]))
93        }
94    }
95}
96
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 testVariadicArguments code on LambdaTest Cloud Grid

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