@@ -97,7 +97,10 @@ final class Test_URICodingRoundtrip: Test_Runtime {
97
97
simpleUnexplode: " " ,
98
98
formDataExplode: " root= " ,
99
99
formDataUnexplode: " root= " ,
100
- deepObjectExplode: " root= "
100
+ deepObjectExplode: . custom(
101
+ " root= " ,
102
+ expectedError: . deepObjectsWithPrimitiveValuesNotSupported
103
+ )
101
104
)
102
105
)
103
106
@@ -112,7 +115,10 @@ final class Test_URICodingRoundtrip: Test_Runtime {
112
115
simpleUnexplode: " Hello%20World%21 " ,
113
116
formDataExplode: " root=Hello+World%21 " ,
114
117
formDataUnexplode: " root=Hello+World%21 " ,
115
- deepObjectExplode: " root=Hello%20World%21 "
118
+ deepObjectExplode: . custom(
119
+ " root=Hello%20World%21 " ,
120
+ expectedError: . deepObjectsWithPrimitiveValuesNotSupported
121
+ )
116
122
)
117
123
)
118
124
@@ -127,7 +133,10 @@ final class Test_URICodingRoundtrip: Test_Runtime {
127
133
simpleUnexplode: " red " ,
128
134
formDataExplode: " root=red " ,
129
135
formDataUnexplode: " root=red " ,
130
- deepObjectExplode: " root=red "
136
+ deepObjectExplode: . custom(
137
+ " root=red " ,
138
+ expectedError: . deepObjectsWithPrimitiveValuesNotSupported
139
+ )
131
140
)
132
141
)
133
142
@@ -142,7 +151,10 @@ final class Test_URICodingRoundtrip: Test_Runtime {
142
151
simpleUnexplode: " 1234 " ,
143
152
formDataExplode: " root=1234 " ,
144
153
formDataUnexplode: " root=1234 " ,
145
- deepObjectExplode: " root=1234 "
154
+ deepObjectExplode: . custom(
155
+ " root=1234 " ,
156
+ expectedError: . deepObjectsWithPrimitiveValuesNotSupported
157
+ )
146
158
)
147
159
)
148
160
@@ -157,7 +169,10 @@ final class Test_URICodingRoundtrip: Test_Runtime {
157
169
simpleUnexplode: " 12.34 " ,
158
170
formDataExplode: " root=12.34 " ,
159
171
formDataUnexplode: " root=12.34 " ,
160
- deepObjectExplode: " root=12.34 "
172
+ deepObjectExplode: . custom(
173
+ " root=12.34 " ,
174
+ expectedError: . deepObjectsWithPrimitiveValuesNotSupported
175
+ )
161
176
)
162
177
)
163
178
@@ -172,7 +187,10 @@ final class Test_URICodingRoundtrip: Test_Runtime {
172
187
simpleUnexplode: " true " ,
173
188
formDataExplode: " root=true " ,
174
189
formDataUnexplode: " root=true " ,
175
- deepObjectExplode: " root=true "
190
+ deepObjectExplode: . custom(
191
+ " root=true " ,
192
+ expectedError: . deepObjectsWithPrimitiveValuesNotSupported
193
+ )
176
194
)
177
195
)
178
196
@@ -187,7 +205,10 @@ final class Test_URICodingRoundtrip: Test_Runtime {
187
205
simpleUnexplode: " 2023-08-25T07%3A34%3A59Z " ,
188
206
formDataExplode: " root=2023-08-25T07%3A34%3A59Z " ,
189
207
formDataUnexplode: " root=2023-08-25T07%3A34%3A59Z " ,
190
- deepObjectExplode: " root=2023-08-25T07%3A34%3A59Z "
208
+ deepObjectExplode: . custom(
209
+ " root=2023-08-25T07%3A34%3A59Z " ,
210
+ expectedError: . deepObjectsWithPrimitiveValuesNotSupported
211
+ )
191
212
)
192
213
)
193
214
@@ -202,7 +223,10 @@ final class Test_URICodingRoundtrip: Test_Runtime {
202
223
simpleUnexplode: " a,b,c " ,
203
224
formDataExplode: " list=a&list=b&list=c " ,
204
225
formDataUnexplode: " list=a,b,c " ,
205
- deepObjectExplode: nil
226
+ deepObjectExplode: . custom(
227
+ " list=a&list=b&list=c " ,
228
+ expectedError: . deepObjectsArrayNotSupported
229
+ )
206
230
)
207
231
)
208
232
@@ -217,7 +241,10 @@ final class Test_URICodingRoundtrip: Test_Runtime {
217
241
simpleUnexplode: " 2023-08-25T07%3A34%3A59Z,2023-08-25T07%3A35%3A01Z " ,
218
242
formDataExplode: " list=2023-08-25T07%3A34%3A59Z&list=2023-08-25T07%3A35%3A01Z " ,
219
243
formDataUnexplode: " list=2023-08-25T07%3A34%3A59Z,2023-08-25T07%3A35%3A01Z " ,
220
- deepObjectExplode: nil
244
+ deepObjectExplode: . custom(
245
+ " list=2023-08-25T07%3A34%3A59Z&list=2023-08-25T07%3A35%3A01Z " ,
246
+ expectedError: . deepObjectsArrayNotSupported
247
+ )
221
248
)
222
249
)
223
250
@@ -232,7 +259,10 @@ final class Test_URICodingRoundtrip: Test_Runtime {
232
259
simpleUnexplode: . custom( " " , value: [ " " ] ) ,
233
260
formDataExplode: " " ,
234
261
formDataUnexplode: " " ,
235
- deepObjectExplode: nil
262
+ deepObjectExplode: . custom(
263
+ " " ,
264
+ expectedError: . deepObjectsArrayNotSupported
265
+ )
236
266
)
237
267
)
238
268
@@ -247,7 +277,10 @@ final class Test_URICodingRoundtrip: Test_Runtime {
247
277
simpleUnexplode: " red,green,blue " ,
248
278
formDataExplode: " list=red&list=green&list=blue " ,
249
279
formDataUnexplode: " list=red,green,blue " ,
250
- deepObjectExplode: nil
280
+ deepObjectExplode: . custom(
281
+ " list=red&list=green&list=blue " ,
282
+ expectedError: . deepObjectsArrayNotSupported
283
+ )
251
284
)
252
285
)
253
286
@@ -278,7 +311,9 @@ final class Test_URICodingRoundtrip: Test_Runtime {
278
311
simpleUnexplode: " 2023-01-18T10%3A04%3A11Z " ,
279
312
formDataExplode: " root=2023-01-18T10%3A04%3A11Z " ,
280
313
formDataUnexplode: " root=2023-01-18T10%3A04%3A11Z " ,
281
- deepObjectExplode: " root=2023-01-18T10%3A04%3A11Z "
314
+ deepObjectExplode: . custom(
315
+ " root=2023-01-18T10%3A04%3A11Z " ,
316
+ expectedError: . deepObjectsWithPrimitiveValuesNotSupported)
282
317
)
283
318
)
284
319
try _test (
@@ -291,7 +326,9 @@ final class Test_URICodingRoundtrip: Test_Runtime {
291
326
simpleUnexplode: " green " ,
292
327
formDataExplode: " root=green " ,
293
328
formDataUnexplode: " root=green " ,
294
- deepObjectExplode: " root=green "
329
+ deepObjectExplode: . custom(
330
+ " root=green " ,
331
+ expectedError: . deepObjectsWithPrimitiveValuesNotSupported)
295
332
)
296
333
)
297
334
try _test (
@@ -372,15 +409,25 @@ final class Test_URICodingRoundtrip: Test_Runtime {
372
409
struct Input : ExpressibleByStringLiteral {
373
410
var string : String
374
411
var customValue : T ?
375
-
376
- init ( string: String , customValue: T ? ) {
412
+ var expectedError : URISerializer . SerializationError ?
413
+
414
+ init ( string: String , customValue: T ? , expectedError: URISerializer . SerializationError ? ) {
377
415
self . string = string
378
416
self . customValue = customValue
417
+ self . expectedError = expectedError
379
418
}
380
419
381
- init ( stringLiteral value: String ) { self . init ( string: value, customValue: nil ) }
420
+ init ( stringLiteral value: String ) {
421
+ self . init ( string: value, customValue: nil , expectedError: nil )
422
+ }
382
423
383
- static func custom( _ string: String , value: T ) -> Self { . init( string: string, customValue: value) }
424
+ static func custom( _ string: String , value: T ) -> Self {
425
+ . init( string: string, customValue: value, expectedError: nil )
426
+ }
427
+
428
+ static func custom( _ string: String , expectedError: URISerializer . SerializationError ) -> Self {
429
+ . init( string: string, customValue: nil , expectedError: expectedError)
430
+ }
384
431
}
385
432
386
433
var formExplode : Input
@@ -389,7 +436,7 @@ final class Test_URICodingRoundtrip: Test_Runtime {
389
436
var simpleUnexplode : Input
390
437
var formDataExplode : Input
391
438
var formDataUnexplode : Input
392
- var deepObjectExplode : Input ?
439
+ var deepObjectExplode : Input
393
440
}
394
441
395
442
func _test< T: Codable & Equatable > (
@@ -401,11 +448,31 @@ final class Test_URICodingRoundtrip: Test_Runtime {
401
448
) throws {
402
449
func testVariant( name: String , configuration: URICoderConfiguration , variant: Variants < T > . Input ) throws {
403
450
let encoder = URIEncoder ( configuration: configuration)
404
- let encodedString = try encoder. encode ( value, forKey: key)
405
- XCTAssertEqual ( encodedString, variant. string, " Variant: \( name) " , file: file, line: line)
406
- let decoder = URIDecoder ( configuration: configuration)
407
- let decodedValue = try decoder. decode ( T . self, forKey: key, from: encodedString [ ... ] )
408
- XCTAssertEqual ( decodedValue, variant. customValue ?? value, " Variant: \( name) " , file: file, line: line)
451
+ do {
452
+ let encodedString = try encoder. encode ( value, forKey: key)
453
+ XCTAssertEqual ( encodedString, variant. string, " Variant: \( name) " , file: file, line: line)
454
+ let decoder = URIDecoder ( configuration: configuration)
455
+ let decodedValue = try decoder. decode ( T . self, forKey: key, from: encodedString [ ... ] )
456
+ XCTAssertEqual ( decodedValue, variant. customValue ?? value, " Variant: \( name) " , file: file, line: line)
457
+ } catch {
458
+ guard let expectedError = variant. expectedError,
459
+ let serializationError = error as? URISerializer . SerializationError else {
460
+ XCTAssert (
461
+ false ,
462
+ " Unexpected error thrown: \( error) " ,
463
+ file: file,
464
+ line: line
465
+ )
466
+ return
467
+ }
468
+ XCTAssertEqual (
469
+ expectedError,
470
+ serializationError,
471
+ " Failed for config: \( variant. string) " ,
472
+ file: file,
473
+ line: line
474
+ )
475
+ }
409
476
}
410
477
try testVariant ( name: " formExplode " , configuration: . formExplode, variant: variants. formExplode)
411
478
try testVariant ( name: " formUnexplode " , configuration: . formUnexplode, variant: variants. formUnexplode)
@@ -418,12 +485,10 @@ final class Test_URICodingRoundtrip: Test_Runtime {
418
485
variant: variants. formDataUnexplode
419
486
)
420
487
421
- if let deepObjectExplode = variants. deepObjectExplode {
422
- try testVariant (
423
- name: " deepObjectExplode " ,
424
- configuration: . deepObjectExplode,
425
- variant: deepObjectExplode
426
- )
427
- }
488
+ try testVariant (
489
+ name: " deepObjectExplode " ,
490
+ configuration: . deepObjectExplode,
491
+ variant: variants. deepObjectExplode
492
+ )
428
493
}
429
494
}
0 commit comments