@@ -110,7 +110,10 @@ final class Test_URISerializer: Test_Runtime {
110
110
simpleUnexplode: " red,green,blue " ,
111
111
formDataExplode: " list=red&list=green&list=blue " ,
112
112
formDataUnexplode: " list=red,green,blue " ,
113
- deepObjectExplode: nil
113
+ deepObjectExplode: . custom(
114
+ " list=red&list=green&list=blue " ,
115
+ expectedError: . deepObjectsArrayNotSupported
116
+ )
114
117
)
115
118
) ,
116
119
makeCase (
@@ -131,26 +134,36 @@ final class Test_URISerializer: Test_Runtime {
131
134
) ,
132
135
]
133
136
for testCase in cases {
134
- func testVariant( _ variant: Case . Variant , _ expectedString : String ) throws {
137
+ func testVariant( _ variant: Case . Variant , _ input : Case . Variants . Input ) throws {
135
138
var serializer = URISerializer ( configuration: variant. config)
136
- let encodedString = try serializer. serializeNode ( testCase. value, forKey: testCase. key)
137
- XCTAssertEqual (
138
- encodedString,
139
- expectedString,
140
- " Failed for config: \( variant. name) " ,
141
- file: testCase. file,
142
- line: testCase. line
143
- )
139
+ do {
140
+ let encodedString = try serializer. serializeNode ( testCase. value, forKey: testCase. key)
141
+ XCTAssertEqual (
142
+ encodedString,
143
+ input. string,
144
+ " Failed for config: \( variant. name) " ,
145
+ file: testCase. file,
146
+ line: testCase. line
147
+ )
148
+ } catch {
149
+ guard let expectedError = input. expectedError,
150
+ let serializationError = error as? URISerializer . SerializationError else { throw error }
151
+ XCTAssertEqual (
152
+ expectedError,
153
+ serializationError,
154
+ " Failed for config: \( variant. name) " ,
155
+ file: testCase. file,
156
+ line: testCase. line
157
+ )
158
+ }
144
159
}
145
160
try testVariant ( . formExplode, testCase. variants. formExplode)
146
161
try testVariant ( . formUnexplode, testCase. variants. formUnexplode)
147
162
try testVariant ( . simpleExplode, testCase. variants. simpleExplode)
148
163
try testVariant ( . simpleUnexplode, testCase. variants. simpleUnexplode)
149
164
try testVariant ( . formDataExplode, testCase. variants. formDataExplode)
150
165
try testVariant ( . formDataUnexplode, testCase. variants. formDataUnexplode)
151
- if let deepObjectExplode = testCase. variants. deepObjectExplode {
152
- try testVariant ( . deepObjectExplode, deepObjectExplode)
153
- }
166
+ try testVariant ( . deepObjectExplode, testCase. variants. deepObjectExplode)
154
167
}
155
168
}
156
169
}
@@ -170,13 +183,33 @@ extension Test_URISerializer {
170
183
static let deepObjectExplode : Self = . init( name: " deepObjectExplode " , config: . deepObjectExplode)
171
184
}
172
185
struct Variants {
173
- var formExplode : String
174
- var formUnexplode : String
175
- var simpleExplode : String
176
- var simpleUnexplode : String
177
- var formDataExplode : String
178
- var formDataUnexplode : String
179
- var deepObjectExplode : String ?
186
+
187
+ struct Input : ExpressibleByStringLiteral {
188
+ var string : String
189
+ var expectedError : URISerializer . SerializationError ?
190
+
191
+ init ( string: String , expectedError: URISerializer . SerializationError ? = nil ) {
192
+ self . string = string
193
+ self . expectedError = expectedError
194
+ }
195
+
196
+ static func custom( _ string: String , expectedError: URISerializer . SerializationError ) -> Self {
197
+ . init( string: string, expectedError: expectedError)
198
+ }
199
+
200
+ init ( stringLiteral value: String ) {
201
+ self . string = value
202
+ self . expectedError = nil
203
+ }
204
+ }
205
+
206
+ var formExplode : Input
207
+ var formUnexplode : Input
208
+ var simpleExplode : Input
209
+ var simpleUnexplode : Input
210
+ var formDataExplode : Input
211
+ var formDataUnexplode : Input
212
+ var deepObjectExplode : Input
180
213
}
181
214
var value : URIEncodedNode
182
215
var key : String
0 commit comments