You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Add validation to CollectionDifference decoder (#76876)
The `CollectionDifference` type has a few different invariants
that were not being validated when initializing using the type's
`Decodable` conformance, since the type was using the
autogenerated `Codable` implementation. This change provides
manual implementations of the `Encodable` and `Decodable`
requirements, and adds tests that validate the failure when trying
to decode invalid JSON for CollectionDifference (and a few other
types).
@@ -392,6 +427,90 @@ class TestCodable : TestCodableSuper {
392
427
expectEqual(value.upperBound, decoded.upperBound,"\(#file):\(#line): Decoded ClosedRange upperBound <\(debugDescription(decoded))> not equal to original <\(debugDescription(value))>")
393
428
expectEqual(value.lowerBound, decoded.lowerBound,"\(#file):\(#line): Decoded ClosedRange lowerBound <\(debugDescription(decoded))> not equal to original <\(debugDescription(value))>")
@@ -789,6 +908,21 @@ class TestCodable : TestCodableSuper {
789
908
expectEqual(value.upperBound, decoded.upperBound,"\(#file):\(#line): Decoded Range upperBound<\(debugDescription(decoded))> not equal to original <\(debugDescription(value))>")
790
909
expectEqual(value.lowerBound, decoded.lowerBound,"\(#file):\(#line): Decoded Range lowerBound<\(debugDescription(decoded))> not equal to original <\(debugDescription(value))>")
791
910
}
911
+
912
+
func test_Range_JSON_Errors(){
913
+
expectDecodingErrorViaJSON(
914
+
type: Range<Int>.self,
915
+
json:"[5,0]",
916
+
errorKind:.dataCorrupted)
917
+
expectDecodingErrorViaJSON(
918
+
type: Range<Int>.self,
919
+
json:"[5,]",
920
+
errorKind:.valueNotFound)
921
+
expectDecodingErrorViaJSON(
922
+
type: Range<Int>.self,
923
+
json:"[0,Hello]",
924
+
errorKind:.dataCorrupted)
925
+
}
792
926
793
927
// MARK: - TimeZone
794
928
lazy vartimeZoneValues:[Int:TimeZone]=[
@@ -808,7 +942,7 @@ class TestCodable : TestCodableSuper {
0 commit comments