Skip to content

Commit cea80fe

Browse files
fdiazmartijnwalraven
authored andcommitted
Fix JSONDecodingError Matchable implementation (#367)
wrongType was missing from the implementation
1 parent e7201c0 commit cea80fe

3 files changed

Lines changed: 53 additions & 8 deletions

File tree

Apollo.xcodeproj/project.pbxproj

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@
9494
9FF90A6F1DDDEB420034C3B6 /* InputValueEncodingTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9FF90A6A1DDDEB420034C3B6 /* InputValueEncodingTests.swift */; };
9595
9FF90A711DDDEB420034C3B6 /* ReadFieldValueTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9FF90A6B1DDDEB420034C3B6 /* ReadFieldValueTests.swift */; };
9696
9FF90A731DDDEB420034C3B6 /* ParseQueryResponseTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9FF90A6C1DDDEB420034C3B6 /* ParseQueryResponseTests.swift */; };
97+
E86D8E05214B32FD0028EFE1 /* JSONTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = E86D8E03214B32DA0028EFE1 /* JSONTests.swift */; };
9798
/* End PBXBuildFile section */
9899

99100
/* Begin PBXContainerItemProxy section */
@@ -331,6 +332,7 @@
331332
9FF90A6A1DDDEB420034C3B6 /* InputValueEncodingTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = InputValueEncodingTests.swift; sourceTree = "<group>"; };
332333
9FF90A6B1DDDEB420034C3B6 /* ReadFieldValueTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ReadFieldValueTests.swift; sourceTree = "<group>"; };
333334
9FF90A6C1DDDEB420034C3B6 /* ParseQueryResponseTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ParseQueryResponseTests.swift; sourceTree = "<group>"; };
335+
E86D8E03214B32DA0028EFE1 /* JSONTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = JSONTests.swift; sourceTree = "<group>"; };
334336
/* End PBXFileReference section */
335337

336338
/* Begin PBXFrameworksBuildPhase section */
@@ -547,18 +549,19 @@
547549
9FC750521D2A532D00458D91 /* ApolloTests */ = {
548550
isa = PBXGroup;
549551
children = (
550-
9FF90A6C1DDDEB420034C3B6 /* ParseQueryResponseTests.swift */,
551-
9F295E301E27534800A24949 /* NormalizeQueryResults.swift */,
552552
9F438D0B1E6C494C007BDC1A /* BatchedLoadTests.swift */,
553-
9FF90A6A1DDDEB420034C3B6 /* InputValueEncodingTests.swift */,
554-
9FF90A6B1DDDEB420034C3B6 /* ReadFieldValueTests.swift */,
553+
9FC9A9C71E2EFE6E0023C4D5 /* CacheKeyForFieldTests.swift */,
554+
9FADC8531E6B86D900C677E6 /* DataLoaderTests.swift */,
555555
9F8622F91EC2117C00C38162 /* FragmentConstructionAndConversionTests.swift */,
556+
9FC750551D2A532D00458D91 /* Info.plist */,
557+
9FF90A6A1DDDEB420034C3B6 /* InputValueEncodingTests.swift */,
558+
E86D8E03214B32DA0028EFE1 /* JSONTests.swift */,
556559
9F91CF8E1F6C0DB2008DD0BE /* MutatingResultsTests.swift */,
557-
9FC9A9C71E2EFE6E0023C4D5 /* CacheKeyForFieldTests.swift */,
560+
9F295E301E27534800A24949 /* NormalizeQueryResults.swift */,
561+
9FF90A6C1DDDEB420034C3B6 /* ParseQueryResponseTests.swift */,
558562
9FE1C6E61E634C8D00C02284 /* PromiseTests.swift */,
563+
9FF90A6B1DDDEB420034C3B6 /* ReadFieldValueTests.swift */,
559564
9F19D8451EED8D3B00C57247 /* ResultOrPromiseTests.swift */,
560-
9FADC8531E6B86D900C677E6 /* DataLoaderTests.swift */,
561-
9FC750551D2A532D00458D91 /* Info.plist */,
562565
);
563566
path = ApolloTests;
564567
sourceTree = "<group>";
@@ -1120,6 +1123,7 @@
11201123
9FF90A6F1DDDEB420034C3B6 /* InputValueEncodingTests.swift in Sources */,
11211124
9FE1C6E71E634C8D00C02284 /* PromiseTests.swift in Sources */,
11221125
9FADC8541E6B86D900C677E6 /* DataLoaderTests.swift in Sources */,
1126+
E86D8E05214B32FD0028EFE1 /* JSONTests.swift in Sources */,
11231127
9F8622FA1EC2117C00C38162 /* FragmentConstructionAndConversionTests.swift in Sources */,
11241128
9FF90A711DDDEB420034C3B6 /* ReadFieldValueTests.swift in Sources */,
11251129
9F295E311E27534800A24949 /* NormalizeQueryResults.swift in Sources */,

Sources/Apollo/JSON.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ extension JSONDecodingError: Matchable {
4040
}
4141

4242
switch (value, pattern) {
43-
case (.missingValue, .missingValue), (.nullValue, .nullValue), (.couldNotConvert, .couldNotConvert):
43+
case (.missingValue, .missingValue), (.nullValue, .nullValue), (.wrongType, .wrongType), (.couldNotConvert, .couldNotConvert):
4444
return true
4545
default:
4646
return false

Tests/ApolloTests/JSONTests.swift

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import XCTest
2+
@testable import Apollo
3+
4+
class JSONTests: XCTestCase {
5+
func testMissingValueMatchable() {
6+
let value = JSONDecodingError.missingValue
7+
8+
XCTAssertTrue(value ~= JSONDecodingError.missingValue)
9+
XCTAssertFalse(value ~= JSONDecodingError.nullValue)
10+
XCTAssertFalse(value ~= JSONDecodingError.wrongType)
11+
XCTAssertFalse(value ~= JSONDecodingError.couldNotConvert(value: 123, to: Int.self))
12+
}
13+
14+
func testNullValueMatchable() {
15+
let value = JSONDecodingError.nullValue
16+
17+
XCTAssertTrue(value ~= JSONDecodingError.nullValue)
18+
XCTAssertFalse(value ~= JSONDecodingError.missingValue)
19+
XCTAssertFalse(value ~= JSONDecodingError.wrongType)
20+
XCTAssertFalse(value ~= JSONDecodingError.couldNotConvert(value: 123, to: Int.self))
21+
}
22+
23+
func testWrongTypeMatchable() {
24+
let value = JSONDecodingError.wrongType
25+
26+
XCTAssertTrue(value ~= JSONDecodingError.wrongType)
27+
XCTAssertFalse(value ~= JSONDecodingError.nullValue)
28+
XCTAssertFalse(value ~= JSONDecodingError.missingValue)
29+
XCTAssertFalse(value ~= JSONDecodingError.couldNotConvert(value: 123, to: Int.self))
30+
}
31+
32+
func testCouldNotConvertMatchable() {
33+
let value = JSONDecodingError.couldNotConvert(value: 123, to: Int.self)
34+
35+
XCTAssertTrue(value ~= JSONDecodingError.couldNotConvert(value: 123, to: Int.self))
36+
XCTAssertTrue(value ~= JSONDecodingError.couldNotConvert(value: "abc", to: String.self))
37+
XCTAssertFalse(value ~= JSONDecodingError.wrongType)
38+
XCTAssertFalse(value ~= JSONDecodingError.nullValue)
39+
XCTAssertFalse(value ~= JSONDecodingError.missingValue)
40+
}
41+
}

0 commit comments

Comments
 (0)