@@ -37,6 +37,9 @@ final class TypeSafetySourceFileTests: XCTestCase {
37
37
func serviceA(file: StaticString = #fileID, function: StaticString = #function, line: UInt = #line) -> ServiceA {
38
38
knitUnwrap(resolve(ServiceA.self), callsiteFile: file, callsiteFunction: function, callsiteLine: line)
39
39
}
40
+ public func serviceD(file: StaticString = #fileID, function: StaticString = #function, line: UInt = #line) -> ServiceD {
41
+ knitUnwrap(resolve(ServiceD.self), callsiteFile: file, callsiteFunction: function, callsiteLine: line)
42
+ }
40
43
public func serviceDAlias(file: StaticString = #fileID, function: StaticString = #function, line: UInt = #line) -> ServiceD {
41
44
knitUnwrap(resolve(ServiceD.self), callsiteFile: file, callsiteFunction: function, callsiteLine: line)
42
45
}
@@ -75,10 +78,10 @@ final class TypeSafetySourceFileTests: XCTestCase {
75
78
func testRegistrationMultipleArguments( ) {
76
79
let registration = Registration ( service: " A " , accessLevel: . public, arguments: [ . init( type: " String " ) , . init( type: " URL " ) ] )
77
80
XCTAssertEqual (
78
- try TypeSafetySourceFile . makeResolver (
81
+ try TypeSafetySourceFile . makeResolverString (
79
82
registration: registration,
80
83
enumName: nil
81
- ) . formatted ( ) . description ,
84
+ ) ,
82
85
"""
83
86
public func a(string: String, url: URL, file: StaticString = #fileID, function: StaticString = #function, line: UInt = #line) -> A {
84
87
knitUnwrap(resolve(A.self, arguments: string, url), callsiteFile: file, callsiteFunction: function, callsiteLine: line)
@@ -90,10 +93,10 @@ final class TypeSafetySourceFileTests: XCTestCase {
90
93
func testRegistrationSingleArgument( ) {
91
94
let registration = Registration ( service: " A " , accessLevel: . public, arguments: [ . init( type: " String " ) ] )
92
95
XCTAssertEqual (
93
- try TypeSafetySourceFile . makeResolver (
96
+ try TypeSafetySourceFile . makeResolverString (
94
97
registration: registration,
95
98
enumName: nil
96
- ) . formatted ( ) . description ,
99
+ ) ,
97
100
"""
98
101
public func a(string: String, file: StaticString = #fileID, function: StaticString = #function, line: UInt = #line) -> A {
99
102
knitUnwrap(resolve(A.self, argument: string), callsiteFile: file, callsiteFunction: function, callsiteLine: line)
@@ -105,10 +108,10 @@ final class TypeSafetySourceFileTests: XCTestCase {
105
108
func testRegistrationDuplicateParamType( ) {
106
109
let registration = Registration ( service: " A " , accessLevel: . public, arguments: [ . init( type: " String " ) , . init( type: " String " ) ] )
107
110
XCTAssertEqual (
108
- try TypeSafetySourceFile . makeResolver (
111
+ try TypeSafetySourceFile . makeResolverString (
109
112
registration: registration,
110
113
enumName: nil
111
- ) . formatted ( ) . description ,
114
+ ) ,
112
115
"""
113
116
public func a(string1: String, string2: String, file: StaticString = #fileID, function: StaticString = #function, line: UInt = #line) -> A {
114
117
knitUnwrap(resolve(A.self, arguments: string1, string2), callsiteFile: file, callsiteFunction: function, callsiteLine: line)
@@ -120,10 +123,10 @@ final class TypeSafetySourceFileTests: XCTestCase {
120
123
func testRegistrationArgumentAndName( ) {
121
124
let registration = Registration ( service: " A " , name: " test " , accessLevel: . public, arguments: [ . init( type: " String " ) ] )
122
125
XCTAssertEqual (
123
- try TypeSafetySourceFile . makeResolver (
126
+ try TypeSafetySourceFile . makeResolverString (
124
127
registration: registration,
125
128
enumName: " MyAssembly.A_ResolutionKey "
126
- ) . formatted ( ) . description ,
129
+ ) ,
127
130
"""
128
131
public func a(name: MyAssembly.A_ResolutionKey, string: String, file: StaticString = #fileID, function: StaticString = #function, line: UInt = #line) -> A {
129
132
knitUnwrap(resolve(A.self, name: name.rawValue, argument: string), callsiteFile: file, callsiteFunction: function, callsiteLine: line)
@@ -135,10 +138,10 @@ final class TypeSafetySourceFileTests: XCTestCase {
135
138
func testRegistrationWithPrenamedArguments( ) {
136
139
let registration = Registration ( service: " A " , accessLevel: . public, arguments: [ . init( identifier: " arg " , type: " String " ) ] )
137
140
XCTAssertEqual (
138
- try TypeSafetySourceFile . makeResolver (
141
+ try TypeSafetySourceFile . makeResolverString (
139
142
registration: registration,
140
143
enumName: nil
141
- ) . formatted ( ) . description ,
144
+ ) ,
142
145
"""
143
146
public func a(arg: String, file: StaticString = #fileID, function: StaticString = #function, line: UInt = #line) -> A {
144
147
knitUnwrap(resolve(A.self, argument: arg), callsiteFile: file, callsiteFunction: function, callsiteLine: line)
@@ -151,15 +154,36 @@ final class TypeSafetySourceFileTests: XCTestCase {
151
154
var registration = Registration ( service: " A " , accessLevel: . public)
152
155
registration. ifConfigCondition = ExprSyntax ( " SOME_FLAG " )
153
156
XCTAssertEqual (
154
- try TypeSafetySourceFile . makeResolver (
157
+ try TypeSafetySourceFile . makeResolverString (
158
+ registration: registration,
159
+ enumName: nil
160
+ ) ,
161
+ """
162
+ #if SOME_FLAG
163
+ public func a(file: StaticString = #fileID, function: StaticString = #function, line: UInt = #line) -> A {
164
+ knitUnwrap(resolve(A.self), callsiteFile: file, callsiteFunction: function, callsiteLine: line)
165
+ }
166
+ #endif
167
+ """
168
+ )
169
+ }
170
+
171
+ func testRegistrationWithIfConfigAndAlias( ) {
172
+ var registration = Registration ( service: " A " , accessLevel: . public, getterAlias: " fooAlias " )
173
+ registration. ifConfigCondition = ExprSyntax ( " SOME_FLAG " )
174
+ XCTAssertEqual (
175
+ try TypeSafetySourceFile . makeResolverString (
155
176
registration: registration,
156
177
enumName: nil
157
- ) . formatted ( ) . description ,
178
+ ) ,
158
179
"""
159
180
#if SOME_FLAG
160
181
public func a(file: StaticString = #fileID, function: StaticString = #function, line: UInt = #line) -> A {
161
182
knitUnwrap(resolve(A.self), callsiteFile: file, callsiteFunction: function, callsiteLine: line)
162
183
}
184
+ public func fooAlias(file: StaticString = #fileID, function: StaticString = #function, line: UInt = #line) -> A {
185
+ knitUnwrap(resolve(A.self), callsiteFile: file, callsiteFunction: function, callsiteLine: line)
186
+ }
163
187
#endif
164
188
"""
165
189
)
@@ -168,10 +192,10 @@ final class TypeSafetySourceFileTests: XCTestCase {
168
192
func testRegistrationWithSPI( ) {
169
193
let registration = Registration ( service: " A " , accessLevel: . public, spi: " Testing " )
170
194
XCTAssertEqual (
171
- try TypeSafetySourceFile . makeResolver (
195
+ try TypeSafetySourceFile . makeResolverString (
172
196
registration: registration,
173
197
enumName: nil
174
- ) . formatted ( ) . description ,
198
+ ) ,
175
199
"""
176
200
@_spi(Testing) public func a(file: StaticString = #fileID, function: StaticString = #function, line: UInt = #line) -> A {
177
201
knitUnwrap(resolve(A.self), callsiteFile: file, callsiteFunction: function, callsiteLine: line)
@@ -180,6 +204,23 @@ final class TypeSafetySourceFileTests: XCTestCase {
180
204
)
181
205
}
182
206
207
+ func testRegisrationWithGetterAlias( ) {
208
+ let registration = Registration ( service: " A " , accessLevel: . public, getterAlias: " fooAlias " )
209
+ XCTAssertEqual (
210
+ try TypeSafetySourceFile . makeResolverString (
211
+ registration: registration
212
+ ) ,
213
+ """
214
+ public func a(file: StaticString = #fileID, function: StaticString = #function, line: UInt = #line) -> A {
215
+ knitUnwrap(resolve(A.self), callsiteFile: file, callsiteFunction: function, callsiteLine: line)
216
+ }
217
+ public func fooAlias(file: StaticString = #fileID, function: StaticString = #function, line: UInt = #line) -> A {
218
+ knitUnwrap(resolve(A.self), callsiteFile: file, callsiteFunction: function, callsiteLine: line)
219
+ }
220
+ """
221
+ )
222
+ }
223
+
183
224
func testArgumentIdentifiers( ) {
184
225
let registration1 = Registration ( service: " A " , arguments: [ . init( type: " String? " ) ] )
185
226
XCTAssertEqual (
@@ -376,3 +417,20 @@ final class TypeSafetySourceFileTests: XCTestCase {
376
417
}
377
418
378
419
}
420
+
421
+ private extension TypeSafetySourceFile {
422
+
423
+ static func makeResolverString(
424
+ registration: Registration ,
425
+ enumName: String ? = nil
426
+ ) throws -> String {
427
+ try TypeSafetySourceFile . makeResolvers (
428
+ registration: registration,
429
+ enumName: enumName,
430
+ getterAlias: registration. getterAlias
431
+ )
432
+ . map { $0. formatted ( ) . description }
433
+ . joined ( separator: " \n " )
434
+ }
435
+
436
+ }
0 commit comments