How to use testStringExtensions_firstIndexOfNeedle_excludesDefinedCharacterGroupsOnly method of StringExtensionsTests class

Best Mockingbird code snippet using StringExtensionsTests.testStringExtensions_firstIndexOfNeedle_excludesDefinedCharacterGroupsOnly

Run Mockingbird automation tests on LambdaTest cloud grid

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

StringExtensionsTests.swift

Source: StringExtensionsTests.swift Github

copy
1//
2//  StringExtensionsTests.swift
3//  MockingbirdTests
4//
5//  Created by Andrew Chang on 9/2/19.
6//
7
8import XCTest
9@testable import MockingbirdGenerator
10
11class StringExtensionsTests: XCTestCase {
12  
13  // MARK: - Capitalized first
14  
15  func testStringExtensions_capitalizedFirst_capitalizesFirstLowercaseCharacter() {
16    XCTAssertEqual("hello world!".capitalizedFirst, "Hello world!")
17  }
18  
19  func testStringExtensions_capitalizedFirst_handlesFirstUppercaseCharacter() {
20    XCTAssertEqual("Hello world!".capitalizedFirst, "Hello world!")
21  }
22
23  // MARK: Backtick Wrapped
24
25  func testStringExtensions_backtickWrapped_wrapsStringWithBackticks() {
26    XCTAssertEqual("test string".backtickWrapped, "`test string`")
27  }
28  
29  // MARK: - Substring components
30  
31  func testStringExtensions_substringComponents_separatesByDelimiterCharacter() {
32    let expected: [Substring] = ["a", "b", "c", "d"]
33    XCTAssertEqual("a.b.c.d".substringComponents(separatedBy: "."), expected)
34  }
35  
36  func testStringExtensions_substringComponents_separatesStringsWithNoDelimiters() {
37    let expected: [Substring] = ["abcd"]
38    XCTAssertEqual("abcd".substringComponents(separatedBy: "."), expected)
39  }
40  
41  func testStringExtensions_substringComponents_separatesEmptyStrings() {
42    let expected: [Substring] = [""]
43    XCTAssertEqual("".substringComponents(separatedBy: "."), expected)
44  }
45  
46  func testStringExtensions_substringComponents_handlesLeadingDelimiter() {
47    let expected: [Substring] = ["", "a"]
48    XCTAssertEqual(".a".substringComponents(separatedBy: "."), expected)
49  }
50  
51  func testStringExtensions_substringComponents_handlesTrailingDelimiter() {
52    let expected: [Substring] = ["a", ""]
53    XCTAssertEqual("a.".substringComponents(separatedBy: "."), expected)
54  }
55  
56  // MARK: - Indent
57  
58  func testStringExtensions_indent_addsIndentationToSingleLineString() {
59    XCTAssertEqual("foo-bar".indent(by: 2), "    foo-bar")
60  }
61  
62  func testStringExtensions_indent_addsIndentationToMultiLineString() {
63    let actual = """
64    line1
65      line2
66        line3
67    """.indent(by: 2)
68    let expected = """
69        line1
70          line2
71            line3
72    """
73    XCTAssertEqual(actual, expected)
74  }
75  
76  func testStringExtensions_indent_doesNotChangeEmptyStrings() {
77    XCTAssertEqual("".indent(by: 2), "")
78  }
79  
80  func testStringExtensions_indent_ignoresEmptyLines() {
81    let actual = """
82    line1
83    
84    line2
85
86    line3
87    """.indent(by: 2)
88    let expected = """
89        line1
90    
91        line2
92
93        line3
94    """
95    XCTAssertEqual(actual, expected)
96  }
97  
98  // MARK: - Removing parameter attributes
99  
100  func testStringExtensions_removingParameterAttributes_removesFunctionAttributes() {
101    let actual = "@escaping @autoclosure (Int, Bool) -> String".removingParameterAttributes()
102    XCTAssertEqual(actual, "(Int, Bool) -> String")
103  }
104  
105  func testStringExtensions_removingParameterAttributes_removesInoutAttribute() {
106    let actual = "inout String".removingParameterAttributes()
107    XCTAssertEqual(actual, "String")
108  }
109  
110  func testStringExtensions_removingParameterAttributes_removesTopLevelInoutAttribute() {
111    let actual = "inout (inout Int, inout Bool) -> String".removingParameterAttributes()
112    XCTAssertEqual(actual, "(inout Int, inout Bool) -> String")
113  }
114  
115  func testStringExtensions_removingParameterAttributes_removesVariadicAttribute() {
116    let actual = "String...".removingParameterAttributes()
117    XCTAssertEqual(actual, "String")
118  }
119  
120  func testStringExtensions_removingParameterAttributes_removesSpacedVariadicAttribute() {
121    let actual = "String \n\t ...".removingParameterAttributes()
122    XCTAssertEqual(actual, "String")
123  }
124  
125  func testStringExtensions_removingParameterAttributes_removesTopLevelVariadicAttribute() {
126    let actual = "(Int..., Bool ...) -> String".removingParameterAttributes()
127    XCTAssertEqual(actual, "(Int..., Bool...) -> String")
128  }
129  
130  // MARK: - Removing generic typing
131  
132  func testStringExtensions_removingGenericTyping_removesAllGenericTypes() {
133    let actual = "Type1<A, B, C>.Type2.Type3<D, E, F>.Type4".removingGenericTyping()
134    XCTAssertEqual(actual, "Type1.Type2.Type3.Type4")
135  }
136  
137  func testStringExtensions_removingGenericTyping_ignoresNestedGenerics() {
138    let actual = "Type1<A<Int>, B<String>, C<Bool>>.Type2".removingGenericTyping()
139    XCTAssertEqual(actual, "Type1.Type2")
140  }
141  
142  // MARK: - Contains needle
143  
144  func testStringExtensions_containsNeedle_excludesCharacterGroups() {
145    let actual = "abc (d123ef) <gh123i>".contains("123", excluding: ["(": ")", "<": ">"])
146    XCTAssertFalse(actual)
147  }
148  
149  func testStringExtensions_containsNeedle_excludesDefinedCharacterGroupsOnly() {
150    let actual = "abc (d123ef) <gh123i> [jkl123]".contains("123", excluding: ["(": ")", "<": ">"])
151    XCTAssertTrue(actual)
152  }
153  
154  func testStringExtensions_containsNeedle_handlesNeedlesDefinedAsGroupStartCharacter() {
155    let actual = "abc <(def)> [ghi] (jkl)".contains("(", excluding: ["(": ")", "<": ">"])
156    XCTAssertTrue(actual)
157  }
158  
159  // MARK: - First index of needle
160  
161  func testStringExtensions_firstIndexOfNeedle_excludesCharacterGroups() {
162    let actual = "abc (d123ef) <gh123i>".firstIndex(of: "123", excluding: ["(": ")", "<": ">"])
163    XCTAssertNil(actual)
164  }
165  
166  func testStringExtensions_firstIndexOfNeedle_excludesDefinedCharacterGroupsOnly() {
167    let string = "abc (d123ef) <gh123i> [jkl123]"
168    let actual = string.firstIndex(of: "123", excluding: ["(": ")", "<": ">"])
169    XCTAssertEqual(actual, string.index(string.startIndex, offsetBy: 26))
170  }
171  
172  func testStringExtensions_firstIndexOfNeedle_handlesNeedlesDefinedAsGroupStartCharacter() {
173    let string = "abc <(def)> [ghi] (jkl)"
174    let actual = string.firstIndex(of: "(", excluding: ["(": ")", "<": ">"])
175    XCTAssertEqual(actual, string.index(string.startIndex, offsetBy: 18))
176  }
177  
178  // MARK: - Components separated by
179  
180  func testStringExtensions_componentsSeparatedBySingleDelimiter_excludesCharacterGroups() {
181    let actual = "abc.(de.f).<g.hi>".components(separatedBy: ".", excluding: ["(": ")", "<": ">"])
182    XCTAssertEqual(actual, ["abc", "(de.f)", "<g.hi>"])
183  }
184  
185  func testStringExtensions_componentsSeparatedByMultipleDelimiters_excludesCharacterGroups() {
186    let actual = "abc.(d,e.f),<g.h,i>".components(separatedBy: [".", ","],
187                                                  excluding: ["(": ")", "<": ">"])
188    XCTAssertEqual(actual, ["abc", "(d,e.f)", "<g.h,i>"])
189  }
190}
191
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

Most used method in StringExtensionsTests

Trigger testStringExtensions_firstIndexOfNeedle_excludesDefinedCharacterGroupsOnly code on LambdaTest Cloud Grid

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