Skip to content

Commit 7000abd

Browse files
committed
Merge pull request #12 from toco/master
fix JSONEncodable type test for Array and Dictionary
2 parents 651c684 + 683ac9c commit 7000abd

File tree

5 files changed

+254
-3
lines changed

5 files changed

+254
-3
lines changed

Demo/Demo.xcodeproj/project.pbxproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@
5050
9ED87AE61B5A493A001CA154 /* DemoUITests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = DemoUITests.xctest; sourceTree = BUILT_PRODUCTS_DIR; };
5151
9ED87AEA1B5A493A001CA154 /* DemoUITests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DemoUITests.swift; sourceTree = "<group>"; };
5252
9ED87AEC1B5A493A001CA154 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
53-
9ED87AF81B5A4A22001CA154 /* JSONCodable.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = JSONCodable.framework; path = "../../../../Library/Developer/Xcode/DerivedData/JSONCodable-ffvabopizslykkercglcmocrvhlr/Build/Products/Debug/JSONCodable.framework"; sourceTree = "<group>"; };
53+
9ED87AF81B5A4A22001CA154 /* JSONCodable.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; path = JSONCodable.framework; sourceTree = BUILT_PRODUCTS_DIR; };
5454
9ED87AFA1B5A4A6B001CA154 /* Company.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Company.swift; sourceTree = "<group>"; };
5555
9ED87AFC1B5A4B24001CA154 /* User.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = User.swift; sourceTree = "<group>"; };
5656
/* End PBXFileReference section */

JSONCodable.xcodeproj/project.pbxproj

Lines changed: 175 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,20 @@
2121
9EDB394F1B59D0AF00C63019 /* JSONTransformer.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9EDB39421B59D0AF00C63019 /* JSONTransformer.swift */; };
2222
9EDB39501B59D0AF00C63019 /* JSONTransformer.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9EDB39421B59D0AF00C63019 /* JSONTransformer.swift */; };
2323
9EDB39511B59D15400C63019 /* JSONCodable.h in Headers */ = {isa = PBXBuildFile; fileRef = 9EDB39091B59D00B00C63019 /* JSONCodable.h */; settings = {ATTRIBUTES = (Public, ); }; };
24+
DD9AF0A61BCE79AE00AD42D1 /* JSONCodableTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = DD9AF0A51BCE79AE00AD42D1 /* JSONCodableTests.swift */; };
25+
DD9AF0A81BCE79AE00AD42D1 /* JSONCodable.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 9EDB39061B59D00B00C63019 /* JSONCodable.framework */; settings = {ASSET_TAGS = (); }; };
2426
/* End PBXBuildFile section */
2527

28+
/* Begin PBXContainerItemProxy section */
29+
DD9AF0A91BCE79AE00AD42D1 /* PBXContainerItemProxy */ = {
30+
isa = PBXContainerItemProxy;
31+
containerPortal = 9EDF80101B59CFCE00E4A2D6 /* Project object */;
32+
proxyType = 1;
33+
remoteGlobalIDString = 9EDB39051B59D00B00C63019;
34+
remoteInfo = "JSONCodable iOS";
35+
};
36+
/* End PBXContainerItemProxy section */
37+
2638
/* Begin PBXFileReference section */
2739
9EDB39061B59D00B00C63019 /* JSONCodable.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = JSONCodable.framework; sourceTree = BUILT_PRODUCTS_DIR; };
2840
9EDB39091B59D00B00C63019 /* JSONCodable.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = JSONCodable.h; sourceTree = "<group>"; };
@@ -34,6 +46,9 @@
3446
9EDB393F1B59D0AF00C63019 /* JSONHelpers.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = JSONHelpers.swift; sourceTree = "<group>"; };
3547
9EDB39411B59D0AF00C63019 /* JSONString.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = JSONString.swift; sourceTree = "<group>"; };
3648
9EDB39421B59D0AF00C63019 /* JSONTransformer.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = JSONTransformer.swift; sourceTree = "<group>"; };
49+
DD9AF0A31BCE79AE00AD42D1 /* JSONCodableTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = JSONCodableTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; };
50+
DD9AF0A51BCE79AE00AD42D1 /* JSONCodableTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = JSONCodableTests.swift; sourceTree = "<group>"; };
51+
DD9AF0A71BCE79AE00AD42D1 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
3752
/* End PBXFileReference section */
3853

3954
/* Begin PBXFrameworksBuildPhase section */
@@ -51,6 +66,14 @@
5166
);
5267
runOnlyForDeploymentPostprocessing = 0;
5368
};
69+
DD9AF0A01BCE79AE00AD42D1 /* Frameworks */ = {
70+
isa = PBXFrameworksBuildPhase;
71+
buildActionMask = 2147483647;
72+
files = (
73+
DD9AF0A81BCE79AE00AD42D1 /* JSONCodable.framework in Frameworks */,
74+
);
75+
runOnlyForDeploymentPostprocessing = 0;
76+
};
5477
/* End PBXFrameworksBuildPhase section */
5578

5679
/* Begin PBXGroup section */
@@ -59,6 +82,7 @@
5982
children = (
6083
9EDB39061B59D00B00C63019 /* JSONCodable.framework */,
6184
9EDB39231B59D01D00C63019 /* JSONCodable.framework */,
85+
DD9AF0A31BCE79AE00AD42D1 /* JSONCodableTests.xctest */,
6286
);
6387
name = Products;
6488
sourceTree = "<group>";
@@ -90,10 +114,20 @@
90114
children = (
91115
9EDB393B1B59D0AF00C63019 /* JSONCodable */,
92116
9EDB39081B59D00B00C63019 /* Supporting Files */,
117+
DD9AF0A41BCE79AE00AD42D1 /* JSONCodableTests */,
93118
9EDB39071B59D00B00C63019 /* Products */,
94119
);
95120
sourceTree = "<group>";
96121
};
122+
DD9AF0A41BCE79AE00AD42D1 /* JSONCodableTests */ = {
123+
isa = PBXGroup;
124+
children = (
125+
DD9AF0A51BCE79AE00AD42D1 /* JSONCodableTests.swift */,
126+
DD9AF0A71BCE79AE00AD42D1 /* Info.plist */,
127+
);
128+
path = JSONCodableTests;
129+
sourceTree = "<group>";
130+
};
97131
/* End PBXGroup section */
98132

99133
/* Begin PBXHeadersBuildPhase section */
@@ -152,20 +186,42 @@
152186
productReference = 9EDB39231B59D01D00C63019 /* JSONCodable.framework */;
153187
productType = "com.apple.product-type.framework";
154188
};
189+
DD9AF0A21BCE79AE00AD42D1 /* JSONCodableTests */ = {
190+
isa = PBXNativeTarget;
191+
buildConfigurationList = DD9AF0AB1BCE79AE00AD42D1 /* Build configuration list for PBXNativeTarget "JSONCodableTests" */;
192+
buildPhases = (
193+
DD9AF09F1BCE79AE00AD42D1 /* Sources */,
194+
DD9AF0A01BCE79AE00AD42D1 /* Frameworks */,
195+
DD9AF0A11BCE79AE00AD42D1 /* Resources */,
196+
);
197+
buildRules = (
198+
);
199+
dependencies = (
200+
DD9AF0AA1BCE79AE00AD42D1 /* PBXTargetDependency */,
201+
);
202+
name = JSONCodableTests;
203+
productName = JSONCodableTests;
204+
productReference = DD9AF0A31BCE79AE00AD42D1 /* JSONCodableTests.xctest */;
205+
productType = "com.apple.product-type.bundle.unit-test";
206+
};
155207
/* End PBXNativeTarget section */
156208

157209
/* Begin PBXProject section */
158210
9EDF80101B59CFCE00E4A2D6 /* Project object */ = {
159211
isa = PBXProject;
160212
attributes = {
161213
LastUpgradeCheck = 0700;
214+
ORGANIZATIONNAME = matthewcheok;
162215
TargetAttributes = {
163216
9EDB39051B59D00B00C63019 = {
164217
CreatedOnToolsVersion = 7.0;
165218
};
166219
9EDB39221B59D01D00C63019 = {
167220
CreatedOnToolsVersion = 7.0;
168221
};
222+
DD9AF0A21BCE79AE00AD42D1 = {
223+
CreatedOnToolsVersion = 7.0.1;
224+
};
169225
};
170226
};
171227
buildConfigurationList = 9EDF80131B59CFCE00E4A2D6 /* Build configuration list for PBXProject "JSONCodable" */;
@@ -182,6 +238,7 @@
182238
targets = (
183239
9EDB39051B59D00B00C63019 /* JSONCodable iOS */,
184240
9EDB39221B59D01D00C63019 /* JSONCodable OSX */,
241+
DD9AF0A21BCE79AE00AD42D1 /* JSONCodableTests */,
185242
);
186243
};
187244
/* End PBXProject section */
@@ -201,6 +258,13 @@
201258
);
202259
runOnlyForDeploymentPostprocessing = 0;
203260
};
261+
DD9AF0A11BCE79AE00AD42D1 /* Resources */ = {
262+
isa = PBXResourcesBuildPhase;
263+
buildActionMask = 2147483647;
264+
files = (
265+
);
266+
runOnlyForDeploymentPostprocessing = 0;
267+
};
204268
/* End PBXResourcesBuildPhase section */
205269

206270
/* Begin PBXSourcesBuildPhase section */
@@ -230,8 +294,24 @@
230294
);
231295
runOnlyForDeploymentPostprocessing = 0;
232296
};
297+
DD9AF09F1BCE79AE00AD42D1 /* Sources */ = {
298+
isa = PBXSourcesBuildPhase;
299+
buildActionMask = 2147483647;
300+
files = (
301+
DD9AF0A61BCE79AE00AD42D1 /* JSONCodableTests.swift in Sources */,
302+
);
303+
runOnlyForDeploymentPostprocessing = 0;
304+
};
233305
/* End PBXSourcesBuildPhase section */
234306

307+
/* Begin PBXTargetDependency section */
308+
DD9AF0AA1BCE79AE00AD42D1 /* PBXTargetDependency */ = {
309+
isa = PBXTargetDependency;
310+
target = 9EDB39051B59D00B00C63019 /* JSONCodable iOS */;
311+
targetProxy = DD9AF0A91BCE79AE00AD42D1 /* PBXContainerItemProxy */;
312+
};
313+
/* End PBXTargetDependency section */
314+
235315
/* Begin XCBuildConfiguration section */
236316
9EDB39181B59D00B00C63019 /* Debug */ = {
237317
isa = XCBuildConfiguration;
@@ -466,6 +546,93 @@
466546
};
467547
name = Release;
468548
};
549+
DD9AF0AC1BCE79AE00AD42D1 /* Debug */ = {
550+
isa = XCBuildConfiguration;
551+
buildSettings = {
552+
ALWAYS_SEARCH_USER_PATHS = NO;
553+
CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x";
554+
CLANG_CXX_LIBRARY = "libc++";
555+
CLANG_ENABLE_MODULES = YES;
556+
CLANG_ENABLE_OBJC_ARC = YES;
557+
CLANG_WARN_BOOL_CONVERSION = YES;
558+
CLANG_WARN_CONSTANT_CONVERSION = YES;
559+
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
560+
CLANG_WARN_EMPTY_BODY = YES;
561+
CLANG_WARN_ENUM_CONVERSION = YES;
562+
CLANG_WARN_INT_CONVERSION = YES;
563+
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
564+
CLANG_WARN_UNREACHABLE_CODE = YES;
565+
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
566+
COPY_PHASE_STRIP = NO;
567+
DEBUG_INFORMATION_FORMAT = dwarf;
568+
ENABLE_STRICT_OBJC_MSGSEND = YES;
569+
ENABLE_TESTABILITY = YES;
570+
GCC_C_LANGUAGE_STANDARD = gnu99;
571+
GCC_DYNAMIC_NO_PIC = NO;
572+
GCC_NO_COMMON_BLOCKS = YES;
573+
GCC_OPTIMIZATION_LEVEL = 0;
574+
GCC_PREPROCESSOR_DEFINITIONS = (
575+
"DEBUG=1",
576+
"$(inherited)",
577+
);
578+
GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
579+
GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR;
580+
GCC_WARN_UNDECLARED_SELECTOR = YES;
581+
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
582+
GCC_WARN_UNUSED_FUNCTION = YES;
583+
GCC_WARN_UNUSED_VARIABLE = YES;
584+
INFOPLIST_FILE = JSONCodableTests/Info.plist;
585+
IPHONEOS_DEPLOYMENT_TARGET = 9.0;
586+
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
587+
MTL_ENABLE_DEBUG_INFO = YES;
588+
ONLY_ACTIVE_ARCH = YES;
589+
PRODUCT_BUNDLE_IDENTIFIER = com.matthewcheok.JSONCodableTests;
590+
PRODUCT_NAME = "$(TARGET_NAME)";
591+
SDKROOT = iphoneos;
592+
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
593+
};
594+
name = Debug;
595+
};
596+
DD9AF0AD1BCE79AE00AD42D1 /* Release */ = {
597+
isa = XCBuildConfiguration;
598+
buildSettings = {
599+
ALWAYS_SEARCH_USER_PATHS = NO;
600+
CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x";
601+
CLANG_CXX_LIBRARY = "libc++";
602+
CLANG_ENABLE_MODULES = YES;
603+
CLANG_ENABLE_OBJC_ARC = YES;
604+
CLANG_WARN_BOOL_CONVERSION = YES;
605+
CLANG_WARN_CONSTANT_CONVERSION = YES;
606+
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
607+
CLANG_WARN_EMPTY_BODY = YES;
608+
CLANG_WARN_ENUM_CONVERSION = YES;
609+
CLANG_WARN_INT_CONVERSION = YES;
610+
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
611+
CLANG_WARN_UNREACHABLE_CODE = YES;
612+
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
613+
COPY_PHASE_STRIP = NO;
614+
DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
615+
ENABLE_NS_ASSERTIONS = NO;
616+
ENABLE_STRICT_OBJC_MSGSEND = YES;
617+
GCC_C_LANGUAGE_STANDARD = gnu99;
618+
GCC_NO_COMMON_BLOCKS = YES;
619+
GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
620+
GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR;
621+
GCC_WARN_UNDECLARED_SELECTOR = YES;
622+
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
623+
GCC_WARN_UNUSED_FUNCTION = YES;
624+
GCC_WARN_UNUSED_VARIABLE = YES;
625+
INFOPLIST_FILE = JSONCodableTests/Info.plist;
626+
IPHONEOS_DEPLOYMENT_TARGET = 9.0;
627+
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
628+
MTL_ENABLE_DEBUG_INFO = NO;
629+
PRODUCT_BUNDLE_IDENTIFIER = com.matthewcheok.JSONCodableTests;
630+
PRODUCT_NAME = "$(TARGET_NAME)";
631+
SDKROOT = iphoneos;
632+
VALIDATE_PRODUCT = YES;
633+
};
634+
name = Release;
635+
};
469636
/* End XCBuildConfiguration section */
470637

471638
/* Begin XCConfigurationList section */
@@ -496,6 +663,14 @@
496663
defaultConfigurationIsVisible = 0;
497664
defaultConfigurationName = Release;
498665
};
666+
DD9AF0AB1BCE79AE00AD42D1 /* Build configuration list for PBXNativeTarget "JSONCodableTests" */ = {
667+
isa = XCConfigurationList;
668+
buildConfigurations = (
669+
DD9AF0AC1BCE79AE00AD42D1 /* Debug */,
670+
DD9AF0AD1BCE79AE00AD42D1 /* Release */,
671+
);
672+
defaultConfigurationIsVisible = 0;
673+
};
499674
/* End XCConfigurationList section */
500675
};
501676
rootObject = 9EDF80101B59CFCE00E4A2D6 /* Project object */;

JSONCodable/JSONHelpers.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ protocol JSONDictionary {
1515

1616
extension Dictionary : JSONDictionary {
1717
func dictionaryIsJSONEncodable() -> Bool {
18-
return Key.self is String.Type && Value.self is JSONEncodable.Type
18+
return Key.self is String.Type && (Value.self is JSONEncodable.Type || Value.self is JSONEncodable.Protocol)
1919
}
2020

2121
func dictionaryMadeJSONEncodable() -> [String: JSONEncodable] {
@@ -37,7 +37,7 @@ protocol JSONArray {
3737

3838
extension Array: JSONArray {
3939
func elementsAreJSONEncodable() -> Bool {
40-
return Element.self is JSONEncodable.Type
40+
return Element.self is JSONEncodable.Type || Element.self is JSONEncodable.Protocol
4141
}
4242

4343
func elementsMadeJSONEncodable() -> [JSONEncodable] {

JSONCodableTests/Info.plist

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
3+
<plist version="1.0">
4+
<dict>
5+
<key>CFBundleDevelopmentRegion</key>
6+
<string>en</string>
7+
<key>CFBundleExecutable</key>
8+
<string>$(EXECUTABLE_NAME)</string>
9+
<key>CFBundleIdentifier</key>
10+
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
11+
<key>CFBundleInfoDictionaryVersion</key>
12+
<string>6.0</string>
13+
<key>CFBundleName</key>
14+
<string>$(PRODUCT_NAME)</string>
15+
<key>CFBundlePackageType</key>
16+
<string>BNDL</string>
17+
<key>CFBundleShortVersionString</key>
18+
<string>1.0</string>
19+
<key>CFBundleSignature</key>
20+
<string>????</string>
21+
<key>CFBundleVersion</key>
22+
<string>1</string>
23+
</dict>
24+
</plist>
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
//
2+
// JSONCodableTests.swift
3+
// JSONCodableTests
4+
//
5+
// Created by Tobias Conradi on 14.10.15.
6+
// Copyright © 2015 matthewcheok. All rights reserved.
7+
//
8+
9+
import XCTest
10+
@testable import JSONCodable
11+
12+
class JSONCodableTests: XCTestCase {
13+
14+
override func setUp() {
15+
super.setUp()
16+
// Put setup code here. This method is called before the invocation of each test method in the class.
17+
}
18+
19+
override func tearDown() {
20+
// Put teardown code here. This method is called after the invocation of each test method in the class.
21+
super.tearDown()
22+
}
23+
24+
struct NotEncodable {
25+
}
26+
27+
func testArrayElementsAreEncodable() {
28+
let intArray:[Int] = [1,2,3]
29+
XCTAssert(intArray.elementsAreJSONEncodable(), "Array of type [Int] should be encodable")
30+
31+
let encodableArray:[JSONEncodable] = [1,2,3]
32+
XCTAssert(encodableArray.elementsAreJSONEncodable(), "Array of type [JSONEncodable] should be encodable")
33+
34+
let notEncodableArray:[NotEncodable] = [NotEncodable()]
35+
XCTAssert(!notEncodableArray.elementsAreJSONEncodable(), "Array of type [NotEncodable] should not be encodable")
36+
}
37+
38+
func testDictionaryIsEncodable() {
39+
let intDict:[String:Int] = ["a":1,"b":2,"c":3]
40+
XCTAssert(intDict.dictionaryIsJSONEncodable(), "Dictionary of type [String:Int] should be encodable")
41+
42+
let encodableDict:[String:JSONEncodable] = ["a":1,"b":2,"c":3]
43+
XCTAssert(encodableDict.dictionaryIsJSONEncodable(), "Dictionary of type [String:JSONEncodable] should be encodable")
44+
45+
let notEncodableDict:[String:NotEncodable] = ["a":NotEncodable()]
46+
XCTAssert(!notEncodableDict.dictionaryIsJSONEncodable(), "Dictionary of type [String:NotEncodable] should not be encodable")
47+
48+
}
49+
50+
51+
52+
}

0 commit comments

Comments
 (0)