Merge pull request #35 from mattpolzin/add-include-10

Add include10 Type
This commit is contained in:
Mathew Polzin
2019-09-16 17:13:49 -07:00
committed by GitHub
9 changed files with 137 additions and 727 deletions
+2 -2
View File
@@ -16,7 +16,7 @@ Pod::Spec.new do |spec|
#
spec.name = "MP-JSONAPI"
spec.version = "2.0.0"
spec.version = "2.1.0"
spec.summary = "Swift Codable JSON API framework."
# This description is used to generate tags and improve search results.
@@ -136,6 +136,6 @@ See the JSON API Spec here: https://jsonapi.org/format/
# spec.requires_arc = true
# spec.xcconfig = { "HEADER_SEARCH_PATHS" => "$(SDKROOT)/usr/include/libxml2" }
spec.dependency "Poly", "~> 2.0"
spec.dependency "Poly", "~> 2.1"
end
+2 -2
View File
@@ -6,8 +6,8 @@
"repositoryURL": "https://github.com/mattpolzin/Poly.git",
"state": {
"branch": null,
"revision": "38051821d7ef49e590e26e819a2fe447e50be9ff",
"version": "2.0.1"
"revision": "4a08517b24f8e9f6dd8c02ec7da316aac5c00e2e",
"version": "2.1.0"
}
}
]
+1 -1
View File
@@ -18,7 +18,7 @@ let package = Package(
targets: ["JSONAPITesting"])
],
dependencies: [
.package(url: "https://github.com/mattpolzin/Poly.git", .upToNextMajor(from: "2.0.0")),
.package(url: "https://github.com/mattpolzin/Poly.git", .upToNextMajor(from: "2.1.0")),
],
targets: [
.target(
+8
View File
@@ -161,3 +161,11 @@ extension Includes where I: _Poly9 {
return values.compactMap { $0.i }
}
}
// MARK: - 10 includes
public typealias Include10 = Poly10
extension Includes where I: _Poly10 {
public subscript(_ lookup: I.J.Type) -> [I.J] {
return values.compactMap { $0.j }
}
}
@@ -74,3 +74,8 @@ extension Poly8: PrimaryResource, OptionalPrimaryResource where A: PolyWrapped,
extension Poly9: EncodablePrimaryResource, OptionalEncodablePrimaryResource where A: EncodablePolyWrapped, B: EncodablePolyWrapped, C: EncodablePolyWrapped, D: EncodablePolyWrapped, E: EncodablePolyWrapped, F: EncodablePolyWrapped, G: EncodablePolyWrapped, H: EncodablePolyWrapped, I: EncodablePolyWrapped {}
extension Poly9: PrimaryResource, OptionalPrimaryResource where A: PolyWrapped, B: PolyWrapped, C: PolyWrapped, D: PolyWrapped, E: PolyWrapped, F: PolyWrapped, G: PolyWrapped, H: PolyWrapped, I: PolyWrapped {}
// MARK: - 10 types
extension Poly10: EncodablePrimaryResource, OptionalEncodablePrimaryResource where A: EncodablePolyWrapped, B: EncodablePolyWrapped, C: EncodablePolyWrapped, D: EncodablePolyWrapped, E: EncodablePolyWrapped, F: EncodablePolyWrapped, G: EncodablePolyWrapped, H: EncodablePolyWrapped, I: EncodablePolyWrapped, J: EncodablePolyWrapped {}
extension Poly10: PrimaryResource, OptionalPrimaryResource where A: PolyWrapped, B: PolyWrapped, C: PolyWrapped, D: PolyWrapped, E: PolyWrapped, F: PolyWrapped, G: PolyWrapped, H: PolyWrapped, I: PolyWrapped, J: PolyWrapped {}
@@ -176,6 +176,27 @@ class IncludedTests: XCTestCase {
test_DecodeEncodeEquality(type: Includes<Include9<TestEntity, TestEntity2, TestEntity3, TestEntity4, TestEntity5, TestEntity6, TestEntity7, TestEntity8, TestEntity9>>.self,
data: nine_different_type_includes)
}
func test_TenDifferentIncludes() {
let includes = decoded(type: Includes<Include10<TestEntity, TestEntity2, TestEntity3, TestEntity4, TestEntity5, TestEntity6, TestEntity7, TestEntity8, TestEntity9, TestEntity10>>.self,
data: ten_different_type_includes)
XCTAssertEqual(includes[TestEntity.self].count, 1)
XCTAssertEqual(includes[TestEntity2.self].count, 1)
XCTAssertEqual(includes[TestEntity3.self].count, 1)
XCTAssertEqual(includes[TestEntity4.self].count, 1)
XCTAssertEqual(includes[TestEntity5.self].count, 1)
XCTAssertEqual(includes[TestEntity6.self].count, 1)
XCTAssertEqual(includes[TestEntity7.self].count, 1)
XCTAssertEqual(includes[TestEntity8.self].count, 1)
XCTAssertEqual(includes[TestEntity9.self].count, 1)
XCTAssertEqual(includes[TestEntity10.self].count, 1)
}
func test_TenDifferentIncludes_encode() {
test_DecodeEncodeEquality(type: Includes<Include10<TestEntity, TestEntity2, TestEntity3, TestEntity4, TestEntity5, TestEntity6, TestEntity7, TestEntity8, TestEntity9, TestEntity10>>.self,
data: ten_different_type_includes)
}
}
// MARK: - Appending
@@ -471,4 +492,15 @@ extension IncludedTests {
}
typealias TestEntity9 = BasicEntity<TestEntityType9>
enum TestEntityType10: ResourceObjectDescription {
typealias Attributes = NoAttributes
public static var jsonType: String { return "test_entity10" }
typealias Relationships = NoRelationships
}
typealias TestEntity10 = BasicEntity<TestEntityType10>
}
@@ -512,3 +512,88 @@ let nine_different_type_includes = """
}
]
""".data(using: .utf8)!
let ten_different_type_includes = """
[
{
"type": "test_entity1",
"id": "2DF03B69-4B0A-467F-B52E-B0C9E44FCECF",
"attributes": {
"foo": "Hello",
"bar": 123
}
},
{
"type": "test_entity2",
"id": "90F03B69-4DF1-467F-B52E-B0C9E44FC333",
"attributes": {
"foo": "World",
"bar": 456
},
"relationships": {
"entity1": {
"data": {
"type": "test_entity1",
"id": "2DF03B69-4B0A-467F-B52E-B0C9E44FCECF"
}
}
}
},
{
"type": "test_entity3",
"id": "11223B69-4DF1-467F-B52E-B0C9E44FC443",
"relationships": {
"entity1": {
"data": {
"type": "test_entity1",
"id": "2DF03B69-4B0A-467F-B52E-B0C9E44FCECF"
}
},
"entity2": {
"data": [
{
"type": "test_entity2",
"id": "90F03B69-4DF1-467F-B52E-B0C9E44FC333"
}
]
}
}
},
{
"type": "test_entity6",
"id": "11113B69-4DF1-467F-B52E-B0C9E44FC444",
"relationships": {
"entity4": {
"data": {
"type": "test_entity4",
"id": "364B3B69-4DF1-467F-B52E-B0C9E44F666E"
}
}
}
},
{
"type": "test_entity5",
"id": "A24B3B69-4DF1-467F-B52E-B0C9E44F436A"
},
{
"type": "test_entity4",
"id": "364B3B69-4DF1-467F-B52E-B0C9E44F666E"
},
{
"type": "test_entity7",
"id": "364B3B69-4DF1-222F-B52E-B0C9E44F666E"
},
{
"type": "test_entity8",
"id": "364B3B69-4DF1-222F-B52E-B0C9E44F266F"
},
{
"type": "test_entity9",
"id": "364B3B69-4DF1-218F-B52E-B0C9E44F2661"
},
{
"type": "test_entity10",
"id": "264B3B69-4DF1-212F-B52E-B0C9E44F2660"
}
]
""".data(using: .utf8)!
File diff suppressed because it is too large Load Diff
+2 -39
View File
@@ -218,6 +218,8 @@ extension IncludedTests {
("test_SevenDifferentIncludes_encode", test_SevenDifferentIncludes_encode),
("test_SixDifferentIncludes", test_SixDifferentIncludes),
("test_SixDifferentIncludes_encode", test_SixDifferentIncludes_encode),
("test_TenDifferentIncludes", test_TenDifferentIncludes),
("test_TenDifferentIncludes_encode", test_TenDifferentIncludes_encode),
("test_ThreeDifferentIncludes", test_ThreeDifferentIncludes),
("test_ThreeDifferentIncludes_encode", test_ThreeDifferentIncludes_encode),
("test_TwoDifferentIncludes", test_TwoDifferentIncludes),
@@ -273,44 +275,6 @@ extension PolyProxyTests {
]
}
extension PolyTests {
// DO NOT MODIFY: This is autogenerated, use:
// `swift test --generate-linuxmain`
// to regenerate.
static let __allTests__PolyTests = [
("test_init_Poly0", test_init_Poly0),
("test_init_Poly1", test_init_Poly1),
("test_init_Poly2", test_init_Poly2),
("test_init_Poly3", test_init_Poly3),
("test_init_Poly4", test_init_Poly4),
("test_init_Poly5", test_init_Poly5),
("test_init_Poly6", test_init_Poly6),
("test_init_Poly7", test_init_Poly7),
("test_init_Poly8", test_init_Poly8),
("test_init_Poly9", test_init_Poly9),
("test_Poly0_decode_throws", test_Poly0_decode_throws),
("test_Poly0_encode_throws", test_Poly0_encode_throws),
("test_Poly1_decode_throws_typeNotFound", test_Poly1_decode_throws_typeNotFound),
("test_Poly1_lookup", test_Poly1_lookup),
("test_Poly2_decode_throws_typeNotFound", test_Poly2_decode_throws_typeNotFound),
("test_Poly2_lookup", test_Poly2_lookup),
("test_Poly3_decode_throws_typeNotFound", test_Poly3_decode_throws_typeNotFound),
("test_Poly3_lookup", test_Poly3_lookup),
("test_Poly4_decode_throws_typeNotFound", test_Poly4_decode_throws_typeNotFound),
("test_Poly4_lookup", test_Poly4_lookup),
("test_Poly5_decode_throws_typeNotFound", test_Poly5_decode_throws_typeNotFound),
("test_Poly5_lookup", test_Poly5_lookup),
("test_Poly6_decode_throws_typeNotFound", test_Poly6_decode_throws_typeNotFound),
("test_Poly6_lookup", test_Poly6_lookup),
("test_Poly7_decode_throws_typeNotFound", test_Poly7_decode_throws_typeNotFound),
("test_Poly7_lookup", test_Poly7_lookup),
("test_Poly8_decode_throws_typeNotFound", test_Poly8_decode_throws_typeNotFound),
("test_Poly8_lookup", test_Poly8_lookup),
("test_Poly9_decode_throws_typeNotFound", test_Poly9_decode_throws_typeNotFound),
("test_Poly9_lookup", test_Poly9_lookup),
]
}
extension RelationshipTests {
// DO NOT MODIFY: This is autogenerated, use:
// `swift test --generate-linuxmain`
@@ -486,7 +450,6 @@ public func __allTests() -> [XCTestCaseEntry] {
testCase(LinksTests.__allTests__LinksTests),
testCase(NonJSONAPIRelatableTests.__allTests__NonJSONAPIRelatableTests),
testCase(PolyProxyTests.__allTests__PolyProxyTests),
testCase(PolyTests.__allTests__PolyTests),
testCase(RelationshipTests.__allTests__RelationshipTests),
testCase(ResourceBodyTests.__allTests__ResourceBodyTests),
testCase(ResourceObjectTests.__allTests__ResourceObjectTests),