@@ -51,15 +51,17 @@ func expectRoundTripEquality<T : Codable>(of value: T, encode: (T) throws -> Dat
51
51
XCTAssertEqual ( value, decoded, " Decoded \( T . self) < \( decoded) > not equal to original < \( value) > " )
52
52
}
53
53
54
- func expectRoundTripEqualityThroughJSON< T : Codable > ( for value: T ) where T : Equatable {
54
+ func expectRoundTripEqualityThroughJSON< T : Codable > ( for value: T ,
55
+ encoder: JSONEncoder = JSONEncoder ( ) ,
56
+ decoder: JSONDecoder = JSONDecoder ( ) ) where T : Equatable {
55
57
let encode = { ( _ value: T ) throws -> Data in
56
- return try JSONEncoder ( ) . encode ( value)
58
+ return try encoder . encode ( value)
57
59
}
58
-
60
+
59
61
let decode = { ( _ data: Data ) throws -> T in
60
- return try JSONDecoder ( ) . decode ( T . self, from: data)
62
+ return try decoder . decode ( T . self, from: data)
61
63
}
62
-
64
+
63
65
expectRoundTripEquality ( of: value, encode: encode, decode: decode)
64
66
}
65
67
@@ -224,6 +226,7 @@ class TestCodable : XCTestCase {
224
226
// MARK: - CGPoint
225
227
lazy var cgpointValues : [ CGPoint ] = [
226
228
CGPoint ( ) ,
229
+ CGPoint . zero,
227
230
CGPoint ( x: 10 , y: 20 ) ,
228
231
CGPoint ( x: - 10 , y: - 20 ) ,
229
232
// Disabled due to limit on magnitude in JSON. See SR-5346
@@ -239,6 +242,7 @@ class TestCodable : XCTestCase {
239
242
// MARK: - CGSize
240
243
lazy var cgsizeValues : [ CGSize ] = [
241
244
CGSize ( ) ,
245
+ CGSize . zero,
242
246
CGSize ( width: 30 , height: 40 ) ,
243
247
CGSize ( width: - 30 , height: - 40 ) ,
244
248
// Disabled due to limit on magnitude in JSON. See SR-5346
@@ -254,19 +258,31 @@ class TestCodable : XCTestCase {
254
258
// MARK: - CGRect
255
259
lazy var cgrectValues : [ CGRect ] = [
256
260
CGRect ( ) ,
261
+ CGRect . zero,
257
262
CGRect ( origin: CGPoint ( x: 10 , y: 20 ) , size: CGSize ( width: 30 , height: 40 ) ) ,
258
263
CGRect ( origin: CGPoint ( x: - 10 , y: - 20 ) , size: CGSize ( width: - 30 , height: - 40 ) ) ,
259
264
// Disabled due to limit on magnitude in JSON. See SR-5346
260
- // CGRect(origin: CGPoint(x: -.greatestFiniteMagnitude / 2,
261
- // y: -.greatestFiniteMagnitude / 2),
262
- // size: CGSize(width: .greatestFiniteMagnitude,
263
- // height: .greatestFiniteMagnitude)),
265
+ // CGRect.infinite
264
266
]
265
267
266
268
func test_CGRect_JSON( ) {
267
269
for rect in cgrectValues {
268
270
expectRoundTripEqualityThroughJSON ( for: rect)
269
271
}
272
+
273
+ do {
274
+ let rect = CGRect . null
275
+ let encoder = JSONEncoder ( )
276
+ let decoder = JSONDecoder ( )
277
+ let inf = " INF " , negInf = " -INF " , nan = " NaN "
278
+ encoder. nonConformingFloatEncodingStrategy = . convertToString( positiveInfinity: inf,
279
+ negativeInfinity: negInf,
280
+ nan: nan)
281
+ decoder. nonConformingFloatDecodingStrategy = . convertFromString( positiveInfinity: inf,
282
+ negativeInfinity: negInf,
283
+ nan: nan)
284
+ expectRoundTripEqualityThroughJSON ( for: rect, encoder: encoder, decoder: decoder)
285
+ }
270
286
}
271
287
272
288
}
0 commit comments