From 2563edf419074af552fb6af0bb139725dcd830d3 Mon Sep 17 00:00:00 2001 From: Mathew Polzin Date: Fri, 23 Nov 2018 08:49:55 -0800 Subject: [PATCH] Add subscript access to Poly types. Add empty test class for Poly type. Remove unneeded Foundation import. Small README change to read more clearly. --- README.md | 2 +- Sources/JSONAPI/Resource/Poly.swift | 42 +++++++++++++++++++ Tests/JSONAPITests/Poly/PolyTests.swift | 13 ++++++ Tests/JSONAPITests/Poly/stubs/PolyStubs.swift | 6 +++ .../JSONAPITests/Test Helpers/Entity+Id.swift | 1 - 5 files changed, 62 insertions(+), 2 deletions(-) create mode 100644 Tests/JSONAPITests/Poly/PolyTests.swift create mode 100644 Tests/JSONAPITests/Poly/stubs/PolyStubs.swift diff --git a/README.md b/README.md index 47179a3..e555373 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ # JSONAPI [![MIT license](http://img.shields.io/badge/license-MIT-lightgrey.svg)](http://opensource.org/licenses/MIT) [![Swift 4.2](http://img.shields.io/badge/Swift-4.2-blue.svg)](https://swift.org) [![Build Status](https://app.bitrise.io/app/c8295b9589aa401e/status.svg?token=vzcyqWD5bQ4xqQfZsaVzNw&branch=master)](https://app.bitrise.io/app/c8295b9589aa401e) -A Swift package for encoding and decoding to *JSON API* compliant requests and responses. +A Swift package for encoding to- and decoding from *JSON API* compliant requests and responses. See the JSON API Spec here: https://jsonapi.org/format/ diff --git a/Sources/JSONAPI/Resource/Poly.swift b/Sources/JSONAPI/Resource/Poly.swift index 0231d9d..20f64e9 100644 --- a/Sources/JSONAPI/Resource/Poly.swift +++ b/Sources/JSONAPI/Resource/Poly.swift @@ -55,6 +55,13 @@ public protocol _Poly1: _Poly0 { init(_ a: A) } + +public extension _Poly1 { + subscript(_ lookup: A.Type) -> A? { + return a + } +} + public enum Poly1: _Poly1 { case a(A) @@ -101,6 +108,13 @@ public protocol _Poly2: _Poly1 { init(_ b: B) } + +public extension _Poly2 { + subscript(_ lookup: B.Type) -> B? { + return b + } +} + public enum Poly2: _Poly2 { case a(A) case b(B) @@ -173,6 +187,13 @@ public protocol _Poly3: _Poly2 { init(_ c: C) } + +public extension _Poly3 { + subscript(_ lookup: C.Type) -> C? { + return c + } +} + public enum Poly3: _Poly3 { case a(A) case b(B) @@ -260,6 +281,13 @@ public protocol _Poly4: _Poly3 { init(_ d: D) } + +public extension _Poly4 { + subscript(_ lookup: D.Type) -> D? { + return d + } +} + public enum Poly4: _Poly4 { case a(A) case b(B) @@ -362,6 +390,13 @@ public protocol _Poly5: _Poly4 { init(_ e: E) } + +public extension _Poly5 { + subscript(_ lookup: E.Type) -> E? { + return e + } +} + public enum Poly5: _Poly5 { case a(A) case b(B) @@ -479,6 +514,13 @@ public protocol _Poly6: _Poly5 { init(_ f: F) } + +public extension _Poly6 { + subscript(_ lookup: F.Type) -> F? { + return f + } +} + public enum Poly6: _Poly6 { case a(A) case b(B) diff --git a/Tests/JSONAPITests/Poly/PolyTests.swift b/Tests/JSONAPITests/Poly/PolyTests.swift new file mode 100644 index 0000000..87a8eb7 --- /dev/null +++ b/Tests/JSONAPITests/Poly/PolyTests.swift @@ -0,0 +1,13 @@ +// +// PolyTests.swift +// JSONAPITests +// +// Created by Mathew Polzin on 11/23/18. +// + +import XCTest +import JSONAPI + +class PolyTests: XCTestCase { + +} diff --git a/Tests/JSONAPITests/Poly/stubs/PolyStubs.swift b/Tests/JSONAPITests/Poly/stubs/PolyStubs.swift new file mode 100644 index 0000000..0373e59 --- /dev/null +++ b/Tests/JSONAPITests/Poly/stubs/PolyStubs.swift @@ -0,0 +1,6 @@ +// +// PolyStubs.swift +// JSONAPITests +// +// Created by Mathew Polzin on 11/23/18. +// diff --git a/Tests/JSONAPITests/Test Helpers/Entity+Id.swift b/Tests/JSONAPITests/Test Helpers/Entity+Id.swift index a0422ca..47cdbe9 100644 --- a/Tests/JSONAPITests/Test Helpers/Entity+Id.swift +++ b/Tests/JSONAPITests/Test Helpers/Entity+Id.swift @@ -5,7 +5,6 @@ // Created by Mathew Polzin on 11/15/18. // -import Foundation import JSONAPI public typealias Entity = JSONAPI.Entity>