@@ -33,25 +33,28 @@ private func makePersonNameComponents(namePrefix: String? = nil,
33
33
return result
34
34
}
35
35
36
- func expectRoundTripEquality< T : Codable > ( of value: T , encode: ( T ) throws -> Data , decode: ( Data ) throws -> T ) where T : Equatable {
36
+ func expectRoundTripEquality< T : Codable > ( of value: T , encode: ( T ) throws -> Data , decode: ( Data ) throws -> T ) -> Bool where T : Equatable {
37
37
let data : Data
38
38
do {
39
39
data = try encode ( value)
40
40
} catch {
41
- fatalError ( " Unable to encode \( T . self) < \( value) >: \( error) " )
41
+ XCTFail ( " Unable to encode \( T . self) < \( value) >: \( error) " )
42
+ return false
42
43
}
43
44
44
45
let decoded : T
45
46
do {
46
47
decoded = try decode ( data)
47
48
} catch {
48
- fatalError ( " Unable to decode \( T . self) < \( value) >: \( error) " )
49
+ XCTFail ( " Unable to decode \( T . self) < \( value) >: \( error) " )
50
+ return false
49
51
}
50
52
51
53
XCTAssertEqual ( value, decoded, " Decoded \( T . self) < \( decoded) > not equal to original < \( value) > " )
54
+ return value == decoded
52
55
}
53
56
54
- func expectRoundTripEqualityThroughJSON< T : Codable > ( for value: T ) where T : Equatable {
57
+ func expectRoundTripEqualityThroughJSON< T : Codable > ( for value: T ) -> Bool where T : Equatable {
55
58
let inf = " INF " , negInf = " -INF " , nan = " NaN "
56
59
let encode = { ( _ value: T ) throws -> Data in
57
60
let encoder = JSONEncoder ( )
@@ -69,7 +72,7 @@ func expectRoundTripEqualityThroughJSON<T : Codable>(for value: T) where T : Equ
69
72
return try decoder. decode ( T . self, from: data)
70
73
}
71
74
72
- expectRoundTripEquality ( of: value, encode: encode, decode: decode)
75
+ return expectRoundTripEquality ( of: value, encode: encode, decode: decode)
73
76
}
74
77
75
78
// MARK: - Helper Types
@@ -98,7 +101,7 @@ class TestCodable : XCTestCase {
98
101
99
102
func test_PersonNameComponents_JSON( ) {
100
103
for components in personNameComponentsValues {
101
- expectRoundTripEqualityThroughJSON ( for: components)
104
+ XCTAssertTrue ( expectRoundTripEqualityThroughJSON ( for: components) )
102
105
}
103
106
}
104
107
@@ -113,7 +116,7 @@ class TestCodable : XCTestCase {
113
116
func test_UUID_JSON( ) {
114
117
for uuid in uuidValues {
115
118
// We have to wrap the UUID since we cannot have a top-level string.
116
- expectRoundTripEqualityThroughJSON ( for: UUIDCodingWrapper ( uuid) )
119
+ XCTAssertTrue ( expectRoundTripEqualityThroughJSON ( for: UUIDCodingWrapper ( uuid) ) )
117
120
}
118
121
}
119
122
@@ -128,7 +131,7 @@ class TestCodable : XCTestCase {
128
131
129
132
func test_URL_JSON( ) {
130
133
for url in urlValues {
131
- expectRoundTripEqualityThroughJSON ( for: url)
134
+ XCTAssertTrue ( expectRoundTripEqualityThroughJSON ( for: url) )
132
135
}
133
136
}
134
137
@@ -141,7 +144,7 @@ class TestCodable : XCTestCase {
141
144
142
145
func test_NSRange_JSON( ) {
143
146
for range in nsrangeValues {
144
- expectRoundTripEqualityThroughJSON ( for: range)
147
+ XCTAssertTrue ( expectRoundTripEqualityThroughJSON ( for: range) )
145
148
}
146
149
}
147
150
@@ -159,7 +162,7 @@ class TestCodable : XCTestCase {
159
162
160
163
func test_Locale_JSON( ) {
161
164
for locale in localeValues {
162
- expectRoundTripEqualityThroughJSON ( for: locale)
165
+ XCTAssertTrue ( expectRoundTripEqualityThroughJSON ( for: locale) )
163
166
}
164
167
}
165
168
@@ -172,7 +175,7 @@ class TestCodable : XCTestCase {
172
175
173
176
func test_IndexSet_JSON( ) {
174
177
for indexSet in indexSetValues {
175
- expectRoundTripEqualityThroughJSON ( for: indexSet)
178
+ XCTAssertTrue ( expectRoundTripEqualityThroughJSON ( for: indexSet) )
176
179
}
177
180
}
178
181
@@ -186,7 +189,7 @@ class TestCodable : XCTestCase {
186
189
187
190
func test_IndexPath_JSON( ) {
188
191
for indexPath in indexPathValues {
189
- expectRoundTripEqualityThroughJSON ( for: indexPath)
192
+ XCTAssertTrue ( expectRoundTripEqualityThroughJSON ( for: indexPath) )
190
193
}
191
194
}
192
195
@@ -210,7 +213,7 @@ class TestCodable : XCTestCase {
210
213
211
214
func test_AffineTransform_JSON( ) {
212
215
for transform in affineTransformValues {
213
- expectRoundTripEqualityThroughJSON ( for: transform)
216
+ XCTAssertTrue ( expectRoundTripEqualityThroughJSON ( for: transform) )
214
217
}
215
218
}
216
219
@@ -226,7 +229,7 @@ class TestCodable : XCTestCase {
226
229
227
230
func test_Decimal_JSON( ) {
228
231
for decimal in decimalValues {
229
- expectRoundTripEqualityThroughJSON ( for: decimal)
232
+ XCTAssertTrue ( expectRoundTripEqualityThroughJSON ( for: decimal) )
230
233
}
231
234
}
232
235
@@ -242,7 +245,7 @@ class TestCodable : XCTestCase {
242
245
243
246
func test_CGPoint_JSON( ) {
244
247
for point in cgpointValues {
245
- expectRoundTripEqualityThroughJSON ( for: point)
248
+ XCTAssertTrue ( expectRoundTripEqualityThroughJSON ( for: point) )
246
249
}
247
250
}
248
251
@@ -258,7 +261,7 @@ class TestCodable : XCTestCase {
258
261
259
262
func test_CGSize_JSON( ) {
260
263
for size in cgsizeValues {
261
- expectRoundTripEqualityThroughJSON ( for: size)
264
+ XCTAssertTrue ( expectRoundTripEqualityThroughJSON ( for: size) )
262
265
}
263
266
}
264
267
@@ -275,7 +278,7 @@ class TestCodable : XCTestCase {
275
278
276
279
func test_CGRect_JSON( ) {
277
280
for rect in cgrectValues {
278
- expectRoundTripEqualityThroughJSON ( for: rect)
281
+ XCTAssertTrue ( expectRoundTripEqualityThroughJSON ( for: rect) )
279
282
}
280
283
}
281
284
@@ -301,7 +304,7 @@ class TestCodable : XCTestCase {
301
304
302
305
func test_CharacterSet_JSON( ) {
303
306
for characterSet in characterSetValues {
304
- expectRoundTripEqualityThroughJSON ( for: characterSet)
307
+ XCTAssertTrue ( expectRoundTripEqualityThroughJSON ( for: characterSet) )
305
308
}
306
309
}
307
310
@@ -330,7 +333,7 @@ class TestCodable : XCTestCase {
330
333
331
334
func test_TimeZone_JSON( ) {
332
335
for timeZone in timeZoneValues {
333
- expectRoundTripEqualityThroughJSON ( for: timeZone)
336
+ XCTAssertTrue ( expectRoundTripEqualityThroughJSON ( for: timeZone) )
334
337
}
335
338
}
336
339
@@ -366,7 +369,7 @@ class TestCodable : XCTestCase {
366
369
367
370
func test_Calendar_JSON( ) {
368
371
for calendar in calendarValues {
369
- expectRoundTripEqualityThroughJSON ( for: calendar)
372
+ XCTAssertTrue ( expectRoundTripEqualityThroughJSON ( for: calendar) )
370
373
}
371
374
}
372
375
@@ -403,14 +406,14 @@ class TestCodable : XCTestCase {
403
406
#endif
404
407
405
408
let components = calendar. dateComponents ( dateComponents, from: Date ( timeIntervalSince1970: 1501283776 ) )
406
- expectRoundTripEqualityThroughJSON ( for: components)
409
+ XCTAssertTrue ( expectRoundTripEqualityThroughJSON ( for: components) )
407
410
}
408
411
409
412
// MARK: - Measurement
410
413
func test_Measurement_JSON( ) {
411
- expectRoundTripEqualityThroughJSON ( for: Measurement ( value: 42 , unit: UnitAcceleration . metersPerSecondSquared) )
412
- expectRoundTripEqualityThroughJSON ( for: Measurement ( value: 42 , unit: UnitMass . kilograms) )
413
- expectRoundTripEqualityThroughJSON ( for: Measurement ( value: 42 , unit: UnitLength . miles) )
414
+ XCTAssertTrue ( expectRoundTripEqualityThroughJSON ( for: Measurement ( value: 42 , unit: UnitAcceleration . metersPerSecondSquared) ) )
415
+ XCTAssertTrue ( expectRoundTripEqualityThroughJSON ( for: Measurement ( value: 42 , unit: UnitMass . kilograms) ) )
416
+ XCTAssertTrue ( expectRoundTripEqualityThroughJSON ( for: Measurement ( value: 42 , unit: UnitLength . miles) ) )
414
417
}
415
418
}
416
419
0 commit comments