How to use testUniformTupleType method of InferTypeTests class

Best Mockingbird code snippet using InferTypeTests.testUniformTupleType

Run Mockingbird automation tests on LambdaTest cloud grid

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

InferTypeTests.swift

Source: InferTypeTests.swift Github

copy
1//
2//  InferTypeTests.swift
3//  MockingbirdTests
4//
5//  Created by Ryan Meisters on 4/23/20.
6//
7
8import XCTest
9
10@testable import MockingbirdGenerator
11
12class InferTypeTests: XCTestCase {
13  
14  // MARK: - Literals
15  
16  func testBooleanLiteralType() {
17    XCTAssertEqual(inferType(from: "true"), "Bool")
18    XCTAssertEqual(inferType(from: "false"), "Bool")
19  }
20  
21  func testIntegerLiteralType() {
22    XCTAssertEqual(inferType(from: "42"), "Int")
23    XCTAssertEqual(inferType(from: "0"), "Int")
24    XCTAssertEqual(inferType(from: "-42"), "Int")
25  }
26  
27  func testDoubleLiteralType() {
28    XCTAssertEqual(inferType(from: "42.0"), "Double")
29    XCTAssertEqual(inferType(from: "0.0"), "Double")
30    XCTAssertEqual(inferType(from: "000.00"), "Double")
31    XCTAssertEqual(inferType(from: "-42.0"), "Double")
32  }
33  
34  func testStringLiteralType() {
35    XCTAssertEqual(inferType(from: #""foo bar""#), "String")
36    XCTAssertEqual(inferType(from: "#\"foo bar\"#"), "String")
37    XCTAssertEqual(inferType(from: "##\"foo bar\"##"), "String")
38  }
39  
40  // MARK: - Initialized
41  
42  func testImplicitInitializedType() {
43    let input = "Bool(booleanLiteral: true)"
44    XCTAssertEqual(inferType(from: input), "Bool")
45  }
46  
47  func testImplicitInitializedType_method() {
48    let input = "Bool(booleanLiteral: true).map({ true })"
49    XCTAssertNil(inferType(from: input))
50  }
51  
52  func testImplicitInitializedType_capitalizedMethod() {
53    let input = "Bool(booleanLiteral: true).Method(param: true)"
54    XCTAssertNil(inferType(from: input))
55  }
56  
57  func testImplicitInitializedType_trailingClosureMethod() {
58    let input = "Bool(booleanLiteral: true).map { true }"
59    XCTAssertNil(inferType(from: input))
60  }
61  
62  func testImplicitInitializedType_property() {
63    let input = "Bool(booleanLiteral: true).property"
64    XCTAssertNil(inferType(from: input))
65  }
66  
67  func testExplicitInitializedType() {
68    let input = "Bool.init(booleanLiteral: true)"
69    XCTAssertEqual(inferType(from: input), "Bool")
70  }
71  
72  func testExplicitInitializedType_method() {
73    let input = "Bool.init(booleanLiteral: true).map({ true })"
74    XCTAssertNil(inferType(from: input))
75  }
76  
77  func testExplicitInitializedType_capitalizedMethod() {
78    let input = "Bool.init(booleanLiteral: true).Method(param: true)"
79    XCTAssertNil(inferType(from: input))
80  }
81  
82  func testExplicitInitializedType_trailingClosureMethod() {
83    let input = "Bool.init(booleanLiteral: true).map { true }"
84    XCTAssertNil(inferType(from: input))
85  }
86  
87  func testExplicitInitializedType_property() {
88    let input = "Bool.init(booleanLiteral: true).property"
89    XCTAssertNil(inferType(from: input))
90  }
91  
92  // MARK: - Qualified
93  
94  func testImplicitQualifiedInitializedType() {
95    let input = "Swift.Bool(booleanLiteral: true)"
96    XCTAssertEqual(inferType(from: input), "Swift.Bool")
97  }
98  
99  func testImplicitQualifiedInitializedType_method() {
100    let input = "Swift.Bool(booleanLiteral: true).map({ true })"
101    XCTAssertNil(inferType(from: input))
102  }
103  
104  func testImplicitQualifiedInitializedType_trailingClosureMethod() {
105    let input = "Swift.Bool(booleanLiteral: true).map { true }"
106    XCTAssertNil(inferType(from: input))
107  }
108  
109  func testImplicitQualifiedInitializedType_property() {
110    let input = "Swift.Bool(booleanLiteral: true).property"
111    XCTAssertNil(inferType(from: input))
112  }
113  
114  func testExplicitQualifiedInitializedType() {
115    let input = "Swift.Bool.init(booleanLiteral: true)"
116    XCTAssertEqual(inferType(from: input), "Swift.Bool")
117  }
118  
119  func testExplicitQualifiedInitializedType_method() {
120    let input = "Swift.Bool.init(booleanLiteral: true).map({ true })"
121    XCTAssertNil(inferType(from: input))
122  }
123  
124  func testExplicitQualifiedInitializedType_trailingClosureMethod() {
125    let input = "Swift.Bool.init(booleanLiteral: true).map { true }"
126    XCTAssertNil(inferType(from: input))
127  }
128  
129  func testExplicitQualifiedInitializedType_property() {
130    let input = "Swift.Bool.init(booleanLiteral: true).property"
131    XCTAssertNil(inferType(from: input))
132  }
133  
134  // MARK: - Generics
135
136  func testImplicitInitializedGenericType() {
137    let input = #"Array<(String, Int)>(arrayLiteral: ("foo", 1))"#
138    XCTAssertEqual(inferType(from: input), "Array<(String, Int)>")
139  }
140  
141  func testExplicitInitializedGenericType() {
142    let input = #"Array<(String, Int)>.init(arrayLiteral: ("foo", 1))"#
143    XCTAssertEqual(inferType(from: input), "Array<(String, Int)>")
144  }
145  
146  func testImplicitQualifiedInitializedGenericType() {
147    let input = #"Foundation.Array<(String, Int)>(arrayLiteral: ("foo", 1))"#
148    XCTAssertEqual(inferType(from: input), "Foundation.Array<(String, Int)>")
149  }
150  
151  func testExplicitQualifiedInitializedGenericType() {
152    let input = #"Foundation.Array<(String, Int)>.init(arrayLiteral: ("foo", 1))"#
153    XCTAssertEqual(inferType(from: input), "Foundation.Array<(String, Int)>")
154  }
155  
156  // MARK: - Enums
157  
158  func testEnumCase() {
159    let input = "MyEnum.someCase"
160    XCTAssertEqual(inferType(from: input), "MyEnum")
161  }
162  
163  func testQualifiedEnumCase() {
164    let input = "MyModule.MyEnum.someCase"
165    XCTAssertEqual(inferType(from: input), "MyModule.MyEnum")
166  }
167  
168  func testAssociatedTypeEnumCase() {
169    let input = "MyEnum.someCase(success: true)"
170    XCTAssertNil(inferType(from: input))
171  }
172  
173  func testQualifiedAssociatedTypeEnumCase() {
174    let input = "MyModule.MyEnum.someCase(success: true)"
175    XCTAssertNil(inferType(from: input))
176  }
177
178  // MARK: - Tuples
179  
180  func testUniformTupleType() {
181    let input = "(true, false)"
182    XCTAssertEqual(inferType(from: input), "(Bool, Bool)")
183  }
184  
185  func testMixedTupleType() {
186    let input = "(true, 1)"
187    XCTAssertEqual(inferType(from: input), "(Bool, Int)")
188  }
189  
190  func testNamedTupleType() {
191    let input = "(foo: true, bar: 1)"
192    XCTAssertEqual(inferType(from: input), "(foo: Bool, bar: Int)")
193  }
194  
195  func testExplicitUnnamedTupleType() {
196    let input = "(_: true, _: 1)"
197    XCTAssertEqual(inferType(from: input), "(Bool, Int)")
198  }
199  
200  func testMixedNamedTupleType() {
201    let input = #"(foo: true, _: "bar", 1)"#
202    XCTAssertEqual(inferType(from: input), "(foo: Bool, String, Int)")
203  }
204  
205  func testEmptyCollectionType() {
206    let input = "[]"
207    XCTAssertNil(inferType(from: input))
208  }
209  
210  func testSingleElementArrayType() {
211    let input = "[1]"
212    XCTAssertEqual(inferType(from: input), "[Int]")
213  }
214  
215  func testUniformArrayType() {
216    let input = "[1, 2]"
217    XCTAssertEqual(inferType(from: input), "[Int]")
218  }
219  
220  func testMixedArrayType() {
221    let input = #"[1, true]"#
222    XCTAssertNil(inferType(from: input))
223  }
224  
225  func testSingleElementNestedArrayType() {
226    let input = #"[["foo", "bar"]]"#
227    XCTAssertEqual(inferType(from: input), "[[String]]")
228  }
229  
230  func testUniformNestedArrayType() {
231    let input = #"[["foo", "bar"], ["hello"]]"#
232    XCTAssertEqual(inferType(from: input), "[[String]]")
233  }
234  
235  func testSingleItemDictionaryType() {
236    let input = #"["foo": true]"#
237    XCTAssertEqual(inferType(from: input), "[String: Bool]")
238  }
239  
240  func testMultipleItemDictionaryType() {
241    let input = #"["foo": true, "bar": false]"#
242    XCTAssertEqual(inferType(from: input), "[String: Bool]")
243  }
244  
245  func testSingleItemNestedDictionaryType() {
246    let input = #"["foo": ["foo": true]]"#
247    XCTAssertEqual(inferType(from: input), "[String: [String: Bool]]")
248  }
249  
250  func testMultipleItemNestedDictionaryType() {
251    let input = #"["foo": ["foo": true], "bar": ["bar": false]]"#
252    XCTAssertEqual(inferType(from: input), "[String: [String: Bool]]")
253  }
254  
255  func testMappedString() {
256    let input = #""foo".map { $0 }"#
257    XCTAssertNil(inferType(from: input))
258  }
259  
260  func testMappedStringWithParentheses() {
261    let input = #""foo".map({ $0 })"#
262    XCTAssertNil(inferType(from: input))
263  }
264  
265  func testMappedVariable() {
266    let input = #"self.foo.map { $0 }"#
267    XCTAssertNil(inferType(from: input))
268  }
269  
270  func testMappedVariableWithParentheses() {
271    let input = #"self.foo.map({ $0 })"#
272    XCTAssertNil(inferType(from: input))
273  }
274}
275
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 InferTypeTests

Trigger testUniformTupleType code on LambdaTest Cloud Grid

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