mirror of
https://github.com/encounter/JSONAPI.git
synced 2026-03-30 11:18:38 -07:00
Merge pull request #34 from mattpolzin/swift-5.1
Swift 5.1 tools dependency, access to attributes via dynamicMemberLookup
This commit is contained in:
@@ -55,15 +55,11 @@ print("-----")
|
||||
|
||||
// MARK: - Pass successfully parsed body to other parts of the code
|
||||
|
||||
/*
|
||||
---- CRASHING IN XCODE 10.2 PLAYGROUND ----
|
||||
|
||||
if case let .data(bodyData) = peopleResponse.body {
|
||||
print("first person's name: \(bodyData.primary.values[0][\.fullName])")
|
||||
print("first person's name: \(bodyData.primary.values[0].fullName)")
|
||||
} else {
|
||||
print("no body data")
|
||||
}
|
||||
*/
|
||||
|
||||
|
||||
// MARK: - Work in the abstract
|
||||
|
||||
@@ -15,11 +15,11 @@ Please enjoy these examples, but allow me the forced casting and the lack of err
|
||||
********/
|
||||
|
||||
// MARK: - String as CreatableRawIdType
|
||||
var GlobalStringId: Int = 0
|
||||
var globalStringId: Int = 0
|
||||
extension String: CreatableRawIdType {
|
||||
public static func unique() -> String {
|
||||
GlobalStringId += 1
|
||||
return String(GlobalStringId)
|
||||
globalStringId += 1
|
||||
return String(globalStringId)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+2
-2
@@ -16,7 +16,7 @@ Pod::Spec.new do |spec|
|
||||
#
|
||||
|
||||
spec.name = "MP-JSONAPI"
|
||||
spec.version = "1.0.0"
|
||||
spec.version = "2.0.0"
|
||||
spec.summary = "Swift Codable JSON API framework."
|
||||
|
||||
# This description is used to generate tags and improve search results.
|
||||
@@ -131,7 +131,7 @@ See the JSON API Spec here: https://jsonapi.org/format/
|
||||
# where they will only apply to your library. If you depend on other Podspecs
|
||||
# you can include multiple dependencies to ensure it works.
|
||||
|
||||
spec.swift_version = "5.0"
|
||||
spec.swift_version = "5.1"
|
||||
spec.module_name = "JSONAPI"
|
||||
# spec.requires_arc = true
|
||||
|
||||
|
||||
+11
-11
@@ -1,4 +1,4 @@
|
||||
// swift-tools-version:5.0
|
||||
// swift-tools-version:5.1
|
||||
// The swift-tools-version declares the minimum version of Swift required to build this package.
|
||||
|
||||
import PackageDescription
|
||||
@@ -6,27 +6,27 @@ import PackageDescription
|
||||
let package = Package(
|
||||
name: "JSONAPI",
|
||||
platforms: [
|
||||
.macOS(.v10_10),
|
||||
.iOS(.v10)
|
||||
.macOS(.v10_10),
|
||||
.iOS(.v10)
|
||||
],
|
||||
products: [
|
||||
.library(
|
||||
name: "JSONAPI",
|
||||
targets: ["JSONAPI"]),
|
||||
.library(
|
||||
name: "JSONAPITesting",
|
||||
targets: ["JSONAPITesting"])
|
||||
.library(
|
||||
name: "JSONAPITesting",
|
||||
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.0.0")),
|
||||
],
|
||||
targets: [
|
||||
.target(
|
||||
name: "JSONAPI",
|
||||
dependencies: ["Poly"]),
|
||||
.target(
|
||||
name: "JSONAPITesting",
|
||||
dependencies: ["JSONAPI"]),
|
||||
.target(
|
||||
name: "JSONAPITesting",
|
||||
dependencies: ["JSONAPI"]),
|
||||
.testTarget(
|
||||
name: "JSONAPITests",
|
||||
dependencies: ["JSONAPI", "JSONAPITesting"]),
|
||||
@@ -34,5 +34,5 @@ let package = Package(
|
||||
name: "JSONAPITestingTests",
|
||||
dependencies: ["JSONAPI", "JSONAPITesting"])
|
||||
],
|
||||
swiftLanguageVersions: [.v5]
|
||||
swiftLanguageVersions: [.v5]
|
||||
)
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
# JSONAPI
|
||||
[](http://opensource.org/licenses/MIT) [](https://swift.org) [](https://app.bitrise.io/app/c8295b9589aa401e)
|
||||
[](http://opensource.org/licenses/MIT) [](https://swift.org) [](https://app.bitrise.io/app/c8295b9589aa401e)
|
||||
|
||||
A Swift package for encoding to- and decoding from **JSON API** compliant requests and responses.
|
||||
|
||||
@@ -320,11 +320,18 @@ A resource object that does not have attributes can be described by adding the f
|
||||
typealias Attributes = NoAttributes
|
||||
```
|
||||
|
||||
`Attributes` can be accessed via the `subscript` operator of the `ResourceObject` type as follows:
|
||||
As of Swift 5.1, `Attributes` can be accessed via dynamic member keypath lookup as follows:
|
||||
```swift
|
||||
let favoriteColor: String = person.favoriteColor
|
||||
```
|
||||
|
||||
🗒 `Attributes` can also be accessed via the older `subscript` operator as follows:
|
||||
```swift
|
||||
let favoriteColor: String = person[\.favoriteColor]
|
||||
```
|
||||
|
||||
In both cases you retain type-safety, although neither plays particularly nicely with code autocompletion. It is best practice to pick an attribute access syntax and stick with it. At some point in the future the syntax deemed less desirable may be deprecated.
|
||||
|
||||
#### `Transformer`
|
||||
|
||||
Sometimes you need to use a type that does not encode or decode itself in the way you need to represent it as a serialized JSON object. For example, the Swift `Foundation` type `Date` can encode/decode itself to `Double` out of the box, but you might want to represent dates as ISO 8601 compliant `String`s instead. The Foundation library `JSONDecoder` has a setting to make this adjustment, but for the sake of an example, you could create a `Transformer`.
|
||||
@@ -363,7 +370,7 @@ You can also creator `Validators` and `ValidatedAttribute`s. A `Validator` is ju
|
||||
|
||||
#### Computed `Attribute`
|
||||
|
||||
You can add computed properties to your `ResourceObjectDescription.Attributes` struct if you would like to expose attributes that are not explicitly represented by the JSON. These computed properties do not have to be wrapped in `Attribute`, `ValidatedAttribute`, or `TransformedAttribute`. This allows computed attributes to be of types that are not `Codable`. Here's an example of how you might take the `person[\.name]` attribute from the example above and create a `fullName` computed property.
|
||||
You can add computed properties to your `ResourceObjectDescription.Attributes` struct if you would like to expose attributes that are not explicitly represented by the JSON. These computed properties do not have to be wrapped in `Attribute`, `ValidatedAttribute`, or `TransformedAttribute`. This allows computed attributes to be of types that are not `Codable`. Here's an example of how you might take the `person.name` attribute from the example above and create a `fullName` computed property.
|
||||
|
||||
```swift
|
||||
public var fullName: Attribute<String> {
|
||||
@@ -371,7 +378,7 @@ public var fullName: Attribute<String> {
|
||||
}
|
||||
```
|
||||
|
||||
If your computed property is wrapped in a `AttributeType` then you can still use the default subscript operator to access it (as would be the case with the `person[\.fullName]` example above). However, if you add a property to the `Attributes` `struct` that is not wrapped in an `AttributeType`, you must either access it from its full path (`person.attributes.newThing`) or with the "direct" subscript accessor (`person[direct: \.newThing]`). This keeps the subscript access unambiguous enough for the compiler to be helpful prior to explicitly casting, comparing, or storing the result.
|
||||
If your computed property is wrapped in a `AttributeType` then you can still use the default subscript operator to access it (as would be the case with the `person.fullName` example above). However, if you add a property to the `Attributes` `struct` that is not wrapped in an `AttributeType`, you must either access it from its full path (`person.attributes.newThing`) or with the "direct" subscript accessor (`person[direct: \.newThing]`). This keeps the subscript access unambiguous enough for the compiler to be helpful prior to explicitly casting, comparing, or storing the result.
|
||||
|
||||
### Copying/Mutating `ResourceObjects`
|
||||
`ResourceObject` is a value type, so copying is its default behavior. There are two common mutations you might want to make when copying a `ResourceObject`:
|
||||
@@ -633,7 +640,7 @@ typealias User = JSONAPI.ResourceObject<UserDescription, NoMetadata, NoLinks, St
|
||||
Given a value `user` of the above resource object type, you can access the `createdAt` attribute just like you would any other:
|
||||
|
||||
```swift
|
||||
let createdAt = user[\.createdAt]
|
||||
let createdAt = user.createdAt
|
||||
```
|
||||
|
||||
This works because `createdAt` is defined in the form: `var {name}: ({ResourceObject}) -> {Value}` where `{ResourceObject}` is the `JSONAPI.ResourceObject` described by the `ResourceObjectDescription` containing the meta-attribute.
|
||||
@@ -654,7 +661,7 @@ enum UserDescription: ResourceObjectDescription {
|
||||
struct Relationships: JSONAPI.Relationships {
|
||||
public var friend: (User) -> User.Identifier {
|
||||
return { user in
|
||||
return User.Identifier(rawValue: user[\.friend_id])
|
||||
return User.Identifier(rawValue: user.friend_id)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,9 +17,9 @@ public protocol AttributeType: Codable {
|
||||
/// A TransformedAttribute takes a Codable type and attempts to turn it into another type.
|
||||
public struct TransformedAttribute<RawValue: Codable, Transformer: JSONAPI.Transformer>: AttributeType where Transformer.From == RawValue {
|
||||
public let rawValue: RawValue
|
||||
|
||||
|
||||
public let value: Transformer.To
|
||||
|
||||
|
||||
public init(rawValue: RawValue) throws {
|
||||
self.rawValue = rawValue
|
||||
value = try Transformer.transform(rawValue)
|
||||
|
||||
@@ -66,8 +66,9 @@ public protocol ResourceObjectProxyDescription: JSONTyped {
|
||||
public protocol ResourceObjectDescription: ResourceObjectProxyDescription where Attributes: JSONAPI.Attributes, Relationships: JSONAPI.Relationships {}
|
||||
|
||||
/// ResourceObjectProxy is a protocol that can be used to create
|
||||
/// types that _act_ like Entities but cannot be encoded
|
||||
/// or decoded as Entities.
|
||||
/// types that _act_ like ResourceObject but cannot be encoded
|
||||
/// or decoded as ResourceObjects.
|
||||
@dynamicMemberLookup
|
||||
public protocol ResourceObjectProxy: Equatable, JSONTyped {
|
||||
associatedtype Description: ResourceObjectProxyDescription
|
||||
associatedtype EntityRawIdType: JSONAPI.MaybeRawId
|
||||
@@ -91,7 +92,7 @@ public protocol ResourceObjectProxy: Equatable, JSONTyped {
|
||||
}
|
||||
|
||||
extension ResourceObjectProxy {
|
||||
/// The JSON API compliant "type" of this `Entity`.
|
||||
/// The JSON API compliant "type" of this `ResourceObject`.
|
||||
public static var jsonType: String { return Description.jsonType }
|
||||
}
|
||||
|
||||
@@ -151,7 +152,7 @@ extension ResourceObject: CustomStringConvertible {
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: Convenience initializers
|
||||
// MARK: - Convenience initializers
|
||||
extension ResourceObject where EntityRawIdType: CreatableRawIdType {
|
||||
public init(attributes: Description.Attributes, relationships: Description.Relationships, meta: MetaType, links: LinksType) {
|
||||
self.id = ResourceObject.Id()
|
||||
@@ -402,7 +403,7 @@ extension ResourceObject where MetaType == NoMetadata, LinksType == NoLinks, Ent
|
||||
}
|
||||
*/
|
||||
|
||||
// MARK: Pointer for Relationships use.
|
||||
// MARK: - Pointer for Relationships use
|
||||
public extension ResourceObject where EntityRawIdType: JSONAPI.RawIdType {
|
||||
|
||||
/// A `ResourceObject.Pointer` is a `ToOneRelationship` with no metadata or links.
|
||||
@@ -428,7 +429,7 @@ public extension ResourceObject where EntityRawIdType: JSONAPI.RawIdType {
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: Identifying Unidentified Entities
|
||||
// MARK: - Identifying Unidentified Entities
|
||||
public extension ResourceObject where EntityRawIdType == Unidentified {
|
||||
/// Create a new `ResourceObject` from this one with a newly created
|
||||
/// unique Id of the given type.
|
||||
@@ -449,31 +450,55 @@ public extension ResourceObject where EntityRawIdType: CreatableRawIdType {
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: Attribute Access
|
||||
// MARK: - Attribute Access
|
||||
public extension ResourceObjectProxy {
|
||||
// MARK: Keypath Subscript Lookup
|
||||
/// Access the attribute at the given keypath. This just
|
||||
/// allows you to write `resourceObject[\.propertyName]` instead
|
||||
/// of `resourceObject.attributes.propertyName`.
|
||||
/// of `resourceObject.attributes.propertyName.value`.
|
||||
subscript<T: AttributeType>(_ path: KeyPath<Description.Attributes, T>) -> T.ValueType {
|
||||
return attributes[keyPath: path].value
|
||||
}
|
||||
|
||||
/// Access the attribute at the given keypath. This just
|
||||
/// allows you to write `resourceObject[\.propertyName]` instead
|
||||
/// of `resourceObject.attributes.propertyName`.
|
||||
/// of `resourceObject.attributes.propertyName.value`.
|
||||
subscript<T: AttributeType>(_ path: KeyPath<Description.Attributes, T?>) -> T.ValueType? {
|
||||
return attributes[keyPath: path]?.value
|
||||
}
|
||||
|
||||
/// Access the attribute at the given keypath. This just
|
||||
/// allows you to write `resourceObject[\.propertyName]` instead
|
||||
/// of `resourceObject.attributes.propertyName`.
|
||||
/// of `resourceObject.attributes.propertyName.value`.
|
||||
subscript<T: AttributeType, U>(_ path: KeyPath<Description.Attributes, T?>) -> U? where T.ValueType == U? {
|
||||
// Implementation Note: Handles Transform that returns optional
|
||||
// type.
|
||||
return attributes[keyPath: path].flatMap { $0.value }
|
||||
}
|
||||
|
||||
// MARK: Dynaminc Member Keypath Lookup
|
||||
/// Access the attribute at the given keypath. This just
|
||||
/// allows you to write `resourceObject[\.propertyName]` instead
|
||||
/// of `resourceObject.attributes.propertyName.value`.
|
||||
subscript<T: AttributeType>(dynamicMember path: KeyPath<Description.Attributes, T>) -> T.ValueType {
|
||||
return attributes[keyPath: path].value
|
||||
}
|
||||
|
||||
/// Access the attribute at the given keypath. This just
|
||||
/// allows you to write `resourceObject[\.propertyName]` instead
|
||||
/// of `resourceObject.attributes.propertyName.value`.
|
||||
subscript<T: AttributeType>(dynamicMember path: KeyPath<Description.Attributes, T?>) -> T.ValueType? {
|
||||
return attributes[keyPath: path]?.value
|
||||
}
|
||||
|
||||
/// Access the attribute at the given keypath. This just
|
||||
/// allows you to write `resourceObject[\.propertyName]` instead
|
||||
/// of `resourceObject.attributes.propertyName.value`.
|
||||
subscript<T: AttributeType, U>(dynamicMember path: KeyPath<Description.Attributes, T?>) -> U? where T.ValueType == U? {
|
||||
return attributes[keyPath: path].flatMap { $0.value }
|
||||
}
|
||||
|
||||
// MARK: Direct Keypath Subscript Lookup
|
||||
/// Access the storage of the attribute at the given keypath. This just
|
||||
/// allows you to write `resourceObject[direct: \.propertyName]` instead
|
||||
/// of `resourceObject.attributes.propertyName`.
|
||||
@@ -487,16 +512,24 @@ public extension ResourceObjectProxy {
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: Meta-Attribute Access
|
||||
// MARK: - Meta-Attribute Access
|
||||
public extension ResourceObjectProxy {
|
||||
// MARK: Keypath Subscript Lookup
|
||||
/// Access an attribute requiring a transformation on the RawValue _and_
|
||||
/// a secondary transformation on this entity (self).
|
||||
subscript<T>(_ path: KeyPath<Description.Attributes, (Self) -> T>) -> T {
|
||||
return attributes[keyPath: path](self)
|
||||
}
|
||||
|
||||
// MARK: Dynamic Member Keypath Lookup
|
||||
/// Access an attribute requiring a transformation on the RawValue _and_
|
||||
/// a secondary transformation on this entity (self).
|
||||
subscript<T>(dynamicMember path: KeyPath<Description.Attributes, (Self) -> T>) -> T {
|
||||
return attributes[keyPath: path](self)
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: Relationship Access
|
||||
// MARK: - Relationship Access
|
||||
public extension ResourceObjectProxy {
|
||||
/// Access to an Id of a `ToOneRelationship`.
|
||||
/// This allows you to write `resourceObject ~> \.other` instead
|
||||
@@ -538,7 +571,7 @@ public extension ResourceObjectProxy {
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: Meta-Relationship Access
|
||||
// MARK: - Meta-Relationship Access
|
||||
public extension ResourceObjectProxy {
|
||||
/// Access to an Id of a `ToOneRelationship`.
|
||||
/// This allows you to write `resourceObject ~> \.other` instead
|
||||
|
||||
@@ -16,6 +16,7 @@ class Attribute_FunctorTests: XCTestCase {
|
||||
XCTAssertNotNil(entity)
|
||||
|
||||
XCTAssertEqual(entity?[\.computedString], "Frankie2")
|
||||
XCTAssertEqual(entity?.computedString, "Frankie2")
|
||||
}
|
||||
|
||||
func test_mapOptionalSuccess() {
|
||||
@@ -24,6 +25,7 @@ class Attribute_FunctorTests: XCTestCase {
|
||||
XCTAssertNotNil(entity)
|
||||
|
||||
XCTAssertEqual(entity?[\.computedNumber], 22)
|
||||
XCTAssertEqual(entity?.computedNumber, 22)
|
||||
}
|
||||
|
||||
func test_mapOptionalFailure() {
|
||||
@@ -32,6 +34,7 @@ class Attribute_FunctorTests: XCTestCase {
|
||||
XCTAssertNotNil(entity)
|
||||
|
||||
XCTAssertNil(entity?[\.computedNumber])
|
||||
XCTAssertNil(entity?.computedNumber)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -77,12 +77,37 @@ extension AttributeTests {
|
||||
}
|
||||
}
|
||||
|
||||
enum IntToString: Transformer {
|
||||
enum IntToString: ReversibleTransformer {
|
||||
public static func transform(_ from: Int) -> String {
|
||||
return String(from)
|
||||
}
|
||||
|
||||
public static func reverse(_ value: String) throws -> Int {
|
||||
guard let intValue = Int(value) else {
|
||||
fatalError("Reversed IntToString with invalid String value.")
|
||||
}
|
||||
return intValue
|
||||
}
|
||||
}
|
||||
|
||||
enum OptionalIntToOptionalString: ReversibleTransformer {
|
||||
public static func transform(_ from: Int?) -> String? {
|
||||
return from.map(String.init)
|
||||
}
|
||||
|
||||
public static func reverse(_ value: String?) throws -> Int? {
|
||||
guard let stringValue = value else {
|
||||
return nil
|
||||
}
|
||||
|
||||
guard let intValue = Int(stringValue) else {
|
||||
fatalError("Reversed IntToString with invalid String value.")
|
||||
}
|
||||
|
||||
return intValue
|
||||
}
|
||||
}
|
||||
|
||||
enum IntToInt: Transformer {
|
||||
public static func transform(_ from: Int) -> Int {
|
||||
return from + 100
|
||||
|
||||
@@ -15,6 +15,7 @@ class ComputedPropertiesTests: XCTestCase {
|
||||
|
||||
XCTAssertEqual(entity.id, "1234")
|
||||
XCTAssertEqual(entity[\.name], "Sarah")
|
||||
XCTAssertEqual(entity.name, "Sarah")
|
||||
XCTAssertEqual(entity ~> \.other, "5678")
|
||||
XCTAssertNoThrow(try TestType.check(entity))
|
||||
}
|
||||
@@ -27,6 +28,7 @@ class ComputedPropertiesTests: XCTestCase {
|
||||
let entity = decoded(type: TestType.self, data: computed_property_attribute)
|
||||
|
||||
XCTAssertEqual(entity[\.computed], "Sarah2")
|
||||
XCTAssertEqual(entity.computed, "Sarah2")
|
||||
XCTAssertEqual(entity[direct: \.directSecretsOut], "shhhh")
|
||||
}
|
||||
|
||||
|
||||
@@ -14,7 +14,9 @@ class CustomAttributesTests: XCTestCase {
|
||||
let entity = decoded(type: CustomAttributeEntity.self, data: customAttributeEntityData)
|
||||
|
||||
XCTAssertEqual(entity[\.firstName], "Cool")
|
||||
XCTAssertEqual(entity.firstName, "Cool")
|
||||
XCTAssertEqual(entity[\.name], "Cool Name")
|
||||
XCTAssertEqual(entity.name, "Cool Name")
|
||||
XCTAssertNoThrow(try CustomAttributeEntity.check(entity))
|
||||
}
|
||||
|
||||
@@ -27,7 +29,9 @@ class CustomAttributesTests: XCTestCase {
|
||||
let entity = decoded(type: CustomKeysEntity.self, data: customAttributeEntityData)
|
||||
|
||||
XCTAssertEqual(entity[\.firstNameSilly], "Cool")
|
||||
XCTAssertEqual(entity.firstNameSilly, "Cool")
|
||||
XCTAssertEqual(entity[\.lastNameSilly], "Name")
|
||||
XCTAssertEqual(entity.lastNameSilly, "Name")
|
||||
XCTAssertNoThrow(try CustomKeysEntity.check(entity))
|
||||
}
|
||||
|
||||
|
||||
+82
-43
@@ -1,5 +1,5 @@
|
||||
//
|
||||
// EntityTests.swift
|
||||
// ResourceObjectTests.swift
|
||||
// JSONAPITests
|
||||
//
|
||||
// Created by Mathew Polzin on 7/25/18.
|
||||
@@ -9,15 +9,15 @@ import XCTest
|
||||
import JSONAPI
|
||||
import JSONAPITesting
|
||||
|
||||
class EntityTests: XCTestCase {
|
||||
|
||||
class ResourceObjectTests: XCTestCase {
|
||||
|
||||
func test_relationship_access() {
|
||||
let entity1 = TestEntity1(attributes: .none, relationships: .none, meta: .none, links: .none)
|
||||
let entity2 = TestEntity2(attributes: .none, relationships: .init(other: entity1.pointer), meta: .none, links: .none)
|
||||
|
||||
|
||||
XCTAssertEqual(entity2.relationships.other, entity1.pointer)
|
||||
}
|
||||
|
||||
|
||||
func test_relationship_operator_access() {
|
||||
let entity1 = TestEntity1(attributes: .none, relationships: .none, meta: .none, links: .none)
|
||||
let entity2 = TestEntity2(attributes: .none, relationships: .init(other: entity1.pointer), meta: .none, links: .none)
|
||||
@@ -30,7 +30,7 @@ class EntityTests: XCTestCase {
|
||||
let entity = TestEntity9(attributes: .none, relationships: .init(one: entity1.pointer, nullableOne: .init(resourceObject: entity1, meta: .none, links: .none), optionalOne: .init(resourceObject: entity1, meta: .none, links: .none), optionalNullableOne: nil, optionalMany: .init(resourceObjects: [entity1, entity1], meta: .none, links: .none)), meta: .none, links: .none)
|
||||
|
||||
XCTAssertEqual(entity ~> \.optionalOne, Optional(entity1.id))
|
||||
XCTAssertEqual((entity ~> \.optionalOne).rawValue, Optional(entity1.id.rawValue))
|
||||
XCTAssertEqual((entity ~> \.optionalOne).rawValue, Optional(entity1.id.rawValue))
|
||||
}
|
||||
|
||||
func test_toMany_relationship_operator_access() {
|
||||
@@ -48,11 +48,11 @@ class EntityTests: XCTestCase {
|
||||
|
||||
XCTAssertEqual(entity ~> \.optionalMany, [entity1.id, entity1.id])
|
||||
}
|
||||
|
||||
|
||||
func test_relationshipIds() {
|
||||
let entity1 = TestEntity1(attributes: .none, relationships: .none, meta: .none, links: .none)
|
||||
let entity2 = TestEntity2(attributes: .none, relationships: .init(other: entity1.pointer), meta: .none, links: .none)
|
||||
|
||||
|
||||
XCTAssertEqual(entity2.relationships.other.id, entity1.id)
|
||||
}
|
||||
|
||||
@@ -70,6 +70,7 @@ class EntityTests: XCTestCase {
|
||||
let entity = UnidentifiedTestEntity(attributes: .init(me: "hello"), relationships: .none, meta: .none, links: .none)
|
||||
|
||||
XCTAssertEqual(entity[\.me], "hello")
|
||||
XCTAssertEqual(entity.me, "hello")
|
||||
}
|
||||
|
||||
func test_initialization() {
|
||||
@@ -103,7 +104,7 @@ class EntityTests: XCTestCase {
|
||||
}
|
||||
|
||||
// MARK: - Identifying entity copies
|
||||
extension EntityTests {
|
||||
extension ResourceObjectTests {
|
||||
func test_copyIdentifiedByType() {
|
||||
let unidentifiedEntity = UnidentifiedTestEntity(attributes: .init(me: .init(value: "hello")), relationships: .none, meta: .none, links: .none)
|
||||
|
||||
@@ -133,7 +134,7 @@ extension EntityTests {
|
||||
}
|
||||
|
||||
// MARK: - Encode/Decode
|
||||
extension EntityTests {
|
||||
extension ResourceObjectTests {
|
||||
|
||||
func test_EntityNoRelationshipsNoAttributes() {
|
||||
let entity = decoded(type: TestEntity1.self,
|
||||
@@ -158,6 +159,7 @@ extension EntityTests {
|
||||
XCTAssert(type(of: entity.relationships) == NoRelationships.self)
|
||||
|
||||
XCTAssertEqual(entity[\.floater], 123.321)
|
||||
XCTAssertEqual(entity.floater, 123.321)
|
||||
XCTAssertNoThrow(try TestEntity5.check(entity))
|
||||
|
||||
testEncoded(entity: entity)
|
||||
@@ -173,7 +175,7 @@ extension EntityTests {
|
||||
data: entity_some_relationships_no_attributes)
|
||||
|
||||
XCTAssert(type(of: entity.attributes) == NoAttributes.self)
|
||||
|
||||
|
||||
XCTAssertEqual((entity ~> \.others).map { $0.rawValue }, ["364B3B69-4DF1-467F-B52E-B0C9E44F666E"])
|
||||
XCTAssertNoThrow(try TestEntity3.check(entity))
|
||||
|
||||
@@ -184,13 +186,15 @@ extension EntityTests {
|
||||
test_DecodeEncodeEquality(type: TestEntity3.self,
|
||||
data: entity_some_relationships_no_attributes)
|
||||
}
|
||||
|
||||
|
||||
func test_EntitySomeRelationshipsSomeAttributes() {
|
||||
let entity = decoded(type: TestEntity4.self,
|
||||
data: entity_some_relationships_some_attributes)
|
||||
|
||||
|
||||
XCTAssertEqual(entity[\.word], "coolio")
|
||||
XCTAssertEqual(entity.word, "coolio")
|
||||
XCTAssertEqual(entity[\.number], 992299)
|
||||
XCTAssertEqual(entity.number, 992299)
|
||||
XCTAssertEqual((entity ~> \.other).rawValue, "2DF03B69-4B0A-467F-B52E-B0C9E44FCECF")
|
||||
XCTAssertNoThrow(try TestEntity4.check(entity))
|
||||
|
||||
@@ -204,15 +208,18 @@ extension EntityTests {
|
||||
}
|
||||
|
||||
// MARK: Attribute omission and nullification
|
||||
extension EntityTests {
|
||||
|
||||
extension ResourceObjectTests {
|
||||
|
||||
func test_entityOneOmittedAttribute() {
|
||||
let entity = decoded(type: TestEntity6.self,
|
||||
data: entity_one_omitted_attribute)
|
||||
|
||||
|
||||
XCTAssertEqual(entity[\.here], "Hello")
|
||||
XCTAssertEqual(entity.here, "Hello")
|
||||
XCTAssertNil(entity[\.maybeHere])
|
||||
XCTAssertNil(entity.maybeHere)
|
||||
XCTAssertEqual(entity[\.maybeNull], "World")
|
||||
XCTAssertEqual(entity.maybeNull, "World")
|
||||
XCTAssertNoThrow(try TestEntity6.check(entity))
|
||||
|
||||
testEncoded(entity: entity)
|
||||
@@ -222,14 +229,17 @@ extension EntityTests {
|
||||
test_DecodeEncodeEquality(type: TestEntity6.self,
|
||||
data: entity_one_omitted_attribute)
|
||||
}
|
||||
|
||||
|
||||
func test_entityOneNullAttribute() {
|
||||
let entity = decoded(type: TestEntity6.self,
|
||||
data: entity_one_null_attribute)
|
||||
|
||||
|
||||
XCTAssertEqual(entity[\.here], "Hello")
|
||||
XCTAssertEqual(entity.here, "Hello")
|
||||
XCTAssertEqual(entity[\.maybeHere], "World")
|
||||
XCTAssertEqual(entity.maybeHere, "World")
|
||||
XCTAssertNil(entity[\.maybeNull])
|
||||
XCTAssertNil(entity.maybeNull)
|
||||
XCTAssertNoThrow(try TestEntity6.check(entity))
|
||||
|
||||
testEncoded(entity: entity)
|
||||
@@ -239,14 +249,17 @@ extension EntityTests {
|
||||
test_DecodeEncodeEquality(type: TestEntity6.self,
|
||||
data: entity_one_null_attribute)
|
||||
}
|
||||
|
||||
|
||||
func test_entityAllAttribute() {
|
||||
let entity = decoded(type: TestEntity6.self,
|
||||
data: entity_all_attributes)
|
||||
|
||||
|
||||
XCTAssertEqual(entity[\.here], "Hello")
|
||||
XCTAssertEqual(entity.here, "Hello")
|
||||
XCTAssertEqual(entity[\.maybeHere], "World")
|
||||
XCTAssertEqual(entity.maybeHere, "World")
|
||||
XCTAssertEqual(entity[\.maybeNull], "!")
|
||||
XCTAssertEqual(entity.maybeNull, "!")
|
||||
XCTAssertNoThrow(try TestEntity6.check(entity))
|
||||
|
||||
testEncoded(entity: entity)
|
||||
@@ -256,14 +269,17 @@ extension EntityTests {
|
||||
test_DecodeEncodeEquality(type: TestEntity6.self,
|
||||
data: entity_all_attributes)
|
||||
}
|
||||
|
||||
|
||||
func test_entityOneNullAndOneOmittedAttribute() {
|
||||
let entity = decoded(type: TestEntity6.self,
|
||||
data: entity_one_null_and_one_missing_attribute)
|
||||
|
||||
|
||||
XCTAssertEqual(entity[\.here], "Hello")
|
||||
XCTAssertEqual(entity.here, "Hello")
|
||||
XCTAssertNil(entity[\.maybeHere])
|
||||
XCTAssertNil(entity.maybeHere)
|
||||
XCTAssertNil(entity[\.maybeNull])
|
||||
XCTAssertNil(entity.maybeNull)
|
||||
XCTAssertNoThrow(try TestEntity6.check(entity))
|
||||
|
||||
testEncoded(entity: entity)
|
||||
@@ -273,18 +289,20 @@ extension EntityTests {
|
||||
test_DecodeEncodeEquality(type: TestEntity6.self,
|
||||
data: entity_one_null_and_one_missing_attribute)
|
||||
}
|
||||
|
||||
|
||||
func test_entityBrokenNullableOmittedAttribute() {
|
||||
XCTAssertThrowsError(try JSONDecoder().decode(TestEntity6.self,
|
||||
from: entity_broken_missing_nullable_attribute))
|
||||
}
|
||||
|
||||
|
||||
func test_NullOptionalNullableAttribute() {
|
||||
let entity = decoded(type: TestEntity7.self,
|
||||
data: entity_null_optional_nullable_attribute)
|
||||
|
||||
|
||||
XCTAssertEqual(entity[\.here], "Hello")
|
||||
XCTAssertEqual(entity.here, "Hello")
|
||||
XCTAssertNil(entity[\.maybeHereMaybeNull])
|
||||
XCTAssertNil(entity.maybeHereMaybeNull)
|
||||
XCTAssertNoThrow(try TestEntity7.check(entity))
|
||||
|
||||
testEncoded(entity: entity)
|
||||
@@ -294,13 +312,15 @@ extension EntityTests {
|
||||
test_DecodeEncodeEquality(type: TestEntity7.self,
|
||||
data: entity_null_optional_nullable_attribute)
|
||||
}
|
||||
|
||||
|
||||
func test_NonNullOptionalNullableAttribute() {
|
||||
let entity = decoded(type: TestEntity7.self,
|
||||
data: entity_non_null_optional_nullable_attribute)
|
||||
|
||||
XCTAssertEqual(entity[\.here], "Hello")
|
||||
XCTAssertEqual(entity.here, "Hello")
|
||||
XCTAssertEqual(entity[\.maybeHereMaybeNull], "World")
|
||||
XCTAssertEqual(entity.maybeHereMaybeNull, "World")
|
||||
XCTAssertNoThrow(try TestEntity7.check(entity))
|
||||
|
||||
testEncoded(entity: entity)
|
||||
@@ -313,17 +333,23 @@ extension EntityTests {
|
||||
}
|
||||
|
||||
// MARK: Attribute Transformation
|
||||
extension EntityTests {
|
||||
extension ResourceObjectTests {
|
||||
func test_IntToString() {
|
||||
let entity = decoded(type: TestEntity8.self,
|
||||
data: entity_int_to_string_attribute)
|
||||
|
||||
|
||||
XCTAssertEqual(entity[\.string], "22")
|
||||
XCTAssertEqual(entity.string, "22")
|
||||
XCTAssertEqual(entity[\.int], 22)
|
||||
XCTAssertEqual(entity.int, 22)
|
||||
XCTAssertEqual(entity[\.stringFromInt], "22")
|
||||
XCTAssertEqual(entity.stringFromInt, "22")
|
||||
XCTAssertEqual(entity[\.plus], 122)
|
||||
XCTAssertEqual(entity.plus, 122)
|
||||
XCTAssertEqual(entity[\.doubleFromInt], 22.0)
|
||||
XCTAssertEqual(entity.doubleFromInt, 22.0)
|
||||
XCTAssertEqual(entity[\.nullToString], "nil")
|
||||
XCTAssertEqual(entity.nullToString, "nil")
|
||||
XCTAssertNoThrow(try TestEntity8.check(entity))
|
||||
|
||||
testEncoded(entity: entity)
|
||||
@@ -336,7 +362,7 @@ extension EntityTests {
|
||||
}
|
||||
|
||||
// MARK: Attribute Validation
|
||||
extension EntityTests {
|
||||
extension ResourceObjectTests {
|
||||
func test_IntOver10_success() {
|
||||
XCTAssertNoThrow(decoded(type: TestEntity11.self, data: entity_valid_validated_attribute))
|
||||
}
|
||||
@@ -351,7 +377,7 @@ extension EntityTests {
|
||||
}
|
||||
|
||||
// MARK: Relationship omission and nullification
|
||||
extension EntityTests {
|
||||
extension ResourceObjectTests {
|
||||
func test_nullableRelationshipNotNullOrOmitted() {
|
||||
let entity = decoded(type: TestEntity9.self,
|
||||
data: entity_optional_not_omitted_relationship)
|
||||
@@ -453,7 +479,7 @@ extension EntityTests {
|
||||
|
||||
// MARK: Relationships of same type as root entity
|
||||
|
||||
extension EntityTests {
|
||||
extension ResourceObjectTests {
|
||||
func test_RleationshipsOfSameType() {
|
||||
let entity = decoded(type: TestEntity10.self,
|
||||
data: entity_self_ref_relationship)
|
||||
@@ -472,12 +498,13 @@ extension EntityTests {
|
||||
|
||||
// MARK: Unidentified
|
||||
|
||||
extension EntityTests {
|
||||
extension ResourceObjectTests {
|
||||
func test_UnidentifiedEntity() {
|
||||
let entity = decoded(type: UnidentifiedTestEntity.self,
|
||||
data: entity_unidentified)
|
||||
|
||||
XCTAssertNil(entity[\.me])
|
||||
XCTAssertNil(entity.me)
|
||||
XCTAssertEqual(entity.id, .unidentified)
|
||||
XCTAssertNoThrow(try UnidentifiedTestEntity.check(entity))
|
||||
|
||||
@@ -494,6 +521,7 @@ extension EntityTests {
|
||||
data: entity_unidentified_with_attributes)
|
||||
|
||||
XCTAssertEqual(entity[\.me], "unknown")
|
||||
XCTAssertEqual(entity.me, "unknown")
|
||||
XCTAssertEqual(entity.id, .unidentified)
|
||||
XCTAssertNoThrow(try UnidentifiedTestEntity.check(entity))
|
||||
|
||||
@@ -508,12 +536,13 @@ extension EntityTests {
|
||||
|
||||
// MARK: With Meta and/or Links
|
||||
|
||||
extension EntityTests {
|
||||
extension ResourceObjectTests {
|
||||
func test_UnidentifiedEntityWithAttributesAndMeta() {
|
||||
let entity = decoded(type: UnidentifiedTestEntityWithMeta.self,
|
||||
data: entity_unidentified_with_attributes_and_meta)
|
||||
|
||||
XCTAssertEqual(entity[\.me], "unknown")
|
||||
XCTAssertEqual(entity.me, "unknown")
|
||||
XCTAssertEqual(entity.id, .unidentified)
|
||||
XCTAssertEqual(entity.meta.x, "world")
|
||||
XCTAssertEqual(entity.meta.y, 5)
|
||||
@@ -532,6 +561,7 @@ extension EntityTests {
|
||||
data: entity_unidentified_with_attributes_and_links)
|
||||
|
||||
XCTAssertEqual(entity[\.me], "unknown")
|
||||
XCTAssertEqual(entity.me, "unknown")
|
||||
XCTAssertEqual(entity.id, .unidentified)
|
||||
XCTAssertEqual(entity.links.link1, .init(url: "https://image.com/image.png"))
|
||||
XCTAssertNoThrow(try UnidentifiedTestEntityWithLinks.check(entity))
|
||||
@@ -549,6 +579,7 @@ extension EntityTests {
|
||||
data: entity_unidentified_with_attributes_and_meta_and_links)
|
||||
|
||||
XCTAssertEqual(entity[\.me], "unknown")
|
||||
XCTAssertEqual(entity.me, "unknown")
|
||||
XCTAssertEqual(entity.id, .unidentified)
|
||||
XCTAssertEqual(entity.meta.x, "world")
|
||||
XCTAssertEqual(entity.meta.y, 5)
|
||||
@@ -568,7 +599,9 @@ extension EntityTests {
|
||||
data: entity_some_relationships_some_attributes_with_meta)
|
||||
|
||||
XCTAssertEqual(entity[\.word], "coolio")
|
||||
XCTAssertEqual(entity.word, "coolio")
|
||||
XCTAssertEqual(entity[\.number], 992299)
|
||||
XCTAssertEqual(entity.number, 992299)
|
||||
XCTAssertEqual((entity ~> \.other).rawValue, "2DF03B69-4B0A-467F-B52E-B0C9E44FCECF")
|
||||
XCTAssertEqual(entity.meta.x, "world")
|
||||
XCTAssertEqual(entity.meta.y, 5)
|
||||
@@ -587,7 +620,9 @@ extension EntityTests {
|
||||
data: entity_some_relationships_some_attributes_with_links)
|
||||
|
||||
XCTAssertEqual(entity[\.word], "coolio")
|
||||
XCTAssertEqual(entity.word, "coolio")
|
||||
XCTAssertEqual(entity[\.number], 992299)
|
||||
XCTAssertEqual(entity.number, 992299)
|
||||
XCTAssertEqual((entity ~> \.other).rawValue, "2DF03B69-4B0A-467F-B52E-B0C9E44FCECF")
|
||||
XCTAssertEqual(entity.links.link1, .init(url: "https://image.com/image.png"))
|
||||
XCTAssertNoThrow(try TestEntity4WithLinks.check(entity))
|
||||
@@ -605,7 +640,9 @@ extension EntityTests {
|
||||
data: entity_some_relationships_some_attributes_with_meta_and_links)
|
||||
|
||||
XCTAssertEqual(entity[\.word], "coolio")
|
||||
XCTAssertEqual(entity.word, "coolio")
|
||||
XCTAssertEqual(entity[\.number], 992299)
|
||||
XCTAssertEqual(entity.number, 992299)
|
||||
XCTAssertEqual((entity ~> \.other).rawValue, "2DF03B69-4B0A-467F-B52E-B0C9E44FCECF")
|
||||
XCTAssertEqual(entity.meta.x, "world")
|
||||
XCTAssertEqual(entity.meta.y, 5)
|
||||
@@ -623,7 +660,7 @@ extension EntityTests {
|
||||
|
||||
// MARK: With a Meta Attribute
|
||||
|
||||
extension EntityTests {
|
||||
extension ResourceObjectTests {
|
||||
func test_MetaEntityAttributeAccessWorks() {
|
||||
let entity1 = TestEntityWithMetaAttribute(id: "even",
|
||||
attributes: .init(),
|
||||
@@ -637,13 +674,15 @@ extension EntityTests {
|
||||
links: .none)
|
||||
|
||||
XCTAssertEqual(entity1[\.metaAttribute], true)
|
||||
XCTAssertEqual(entity1.metaAttribute, true)
|
||||
XCTAssertEqual(entity2[\.metaAttribute], false)
|
||||
XCTAssertEqual(entity2.metaAttribute, false)
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: With a Meta Relationship
|
||||
|
||||
extension EntityTests {
|
||||
extension ResourceObjectTests {
|
||||
func test_MetaEntityRelationshipAccessWorks() {
|
||||
let entity1 = TestEntityWithMetaRelationship(id: "even",
|
||||
attributes: .none,
|
||||
@@ -666,7 +705,7 @@ extension EntityTests {
|
||||
}
|
||||
|
||||
// MARK: - Test Types
|
||||
extension EntityTests {
|
||||
extension ResourceObjectTests {
|
||||
|
||||
enum TestEntityType1: ResourceObjectDescription {
|
||||
static var jsonType: String { return "test_entities"}
|
||||
@@ -681,7 +720,7 @@ extension EntityTests {
|
||||
static var jsonType: String { return "second_test_entities"}
|
||||
|
||||
typealias Attributes = NoAttributes
|
||||
|
||||
|
||||
struct Relationships: JSONAPI.Relationships {
|
||||
let other: ToOneRelationship<TestEntity1, NoMetadata, NoLinks>
|
||||
}
|
||||
@@ -693,7 +732,7 @@ extension EntityTests {
|
||||
static var jsonType: String { return "third_test_entities"}
|
||||
|
||||
typealias Attributes = NoAttributes
|
||||
|
||||
|
||||
struct Relationships: JSONAPI.Relationships {
|
||||
let others: ToManyRelationship<TestEntity1, NoMetadata, NoLinks>
|
||||
}
|
||||
@@ -766,7 +805,7 @@ extension EntityTests {
|
||||
static var jsonType: String { return "eighth_test_entities" }
|
||||
|
||||
typealias Relationships = NoRelationships
|
||||
|
||||
|
||||
struct Attributes: JSONAPI.Attributes {
|
||||
let string: Attribute<String>
|
||||
let int: Attribute<Int>
|
||||
@@ -777,7 +816,7 @@ extension EntityTests {
|
||||
let nullToString: TransformedAttribute<Int?, OptionalToString<Int>>
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
typealias TestEntity8 = BasicEntity<TestEntityType8>
|
||||
|
||||
enum TestEntityType9: ResourceObjectDescription {
|
||||
@@ -911,19 +950,19 @@ extension EntityTests {
|
||||
return String(from)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
enum IntPlusOneHundred: Transformer {
|
||||
public static func transform(_ from: Int) -> Int {
|
||||
return from + 100
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
enum IntToDouble: Transformer {
|
||||
public static func transform(_ from: Int) -> Double {
|
||||
return Double(from)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
enum OptionalToString<T>: Transformer {
|
||||
public static func transform(_ from: T?) -> String {
|
||||
return String(describing: from)
|
||||
@@ -196,84 +196,6 @@ extension EmptyObjectDecoderTests {
|
||||
]
|
||||
}
|
||||
|
||||
extension EntityTests {
|
||||
// DO NOT MODIFY: This is autogenerated, use:
|
||||
// `swift test --generate-linuxmain`
|
||||
// to regenerate.
|
||||
static let __allTests__EntityTests = [
|
||||
("test_copyIdentifiedByType", test_copyIdentifiedByType),
|
||||
("test_copyIdentifiedByValue", test_copyIdentifiedByValue),
|
||||
("test_copyWithNewId", test_copyWithNewId),
|
||||
("test_entityAllAttribute", test_entityAllAttribute),
|
||||
("test_entityAllAttribute_encode", test_entityAllAttribute_encode),
|
||||
("test_entityBrokenNullableOmittedAttribute", test_entityBrokenNullableOmittedAttribute),
|
||||
("test_EntityNoRelationshipsNoAttributes", test_EntityNoRelationshipsNoAttributes),
|
||||
("test_EntityNoRelationshipsNoAttributes_encode", test_EntityNoRelationshipsNoAttributes_encode),
|
||||
("test_EntityNoRelationshipsSomeAttributes", test_EntityNoRelationshipsSomeAttributes),
|
||||
("test_EntityNoRelationshipsSomeAttributes_encode", test_EntityNoRelationshipsSomeAttributes_encode),
|
||||
("test_entityOneNullAndOneOmittedAttribute", test_entityOneNullAndOneOmittedAttribute),
|
||||
("test_entityOneNullAndOneOmittedAttribute_encode", test_entityOneNullAndOneOmittedAttribute_encode),
|
||||
("test_entityOneNullAttribute", test_entityOneNullAttribute),
|
||||
("test_entityOneNullAttribute_encode", test_entityOneNullAttribute_encode),
|
||||
("test_entityOneOmittedAttribute", test_entityOneOmittedAttribute),
|
||||
("test_entityOneOmittedAttribute_encode", test_entityOneOmittedAttribute_encode),
|
||||
("test_EntitySomeRelationshipsNoAttributes", test_EntitySomeRelationshipsNoAttributes),
|
||||
("test_EntitySomeRelationshipsNoAttributes_encode", test_EntitySomeRelationshipsNoAttributes_encode),
|
||||
("test_EntitySomeRelationshipsSomeAttributes", test_EntitySomeRelationshipsSomeAttributes),
|
||||
("test_EntitySomeRelationshipsSomeAttributes_encode", test_EntitySomeRelationshipsSomeAttributes_encode),
|
||||
("test_EntitySomeRelationshipsSomeAttributesWithLinks", test_EntitySomeRelationshipsSomeAttributesWithLinks),
|
||||
("test_EntitySomeRelationshipsSomeAttributesWithLinks_encode", test_EntitySomeRelationshipsSomeAttributesWithLinks_encode),
|
||||
("test_EntitySomeRelationshipsSomeAttributesWithMeta", test_EntitySomeRelationshipsSomeAttributesWithMeta),
|
||||
("test_EntitySomeRelationshipsSomeAttributesWithMeta_encode", test_EntitySomeRelationshipsSomeAttributesWithMeta_encode),
|
||||
("test_EntitySomeRelationshipsSomeAttributesWithMetaAndLinks", test_EntitySomeRelationshipsSomeAttributesWithMetaAndLinks),
|
||||
("test_EntitySomeRelationshipsSomeAttributesWithMetaAndLinks_encode", test_EntitySomeRelationshipsSomeAttributesWithMetaAndLinks_encode),
|
||||
("test_initialization", test_initialization),
|
||||
("test_IntOver10_encode", test_IntOver10_encode),
|
||||
("test_IntOver10_failure", test_IntOver10_failure),
|
||||
("test_IntOver10_success", test_IntOver10_success),
|
||||
("test_IntToString", test_IntToString),
|
||||
("test_IntToString_encode", test_IntToString_encode),
|
||||
("test_MetaEntityAttributeAccessWorks", test_MetaEntityAttributeAccessWorks),
|
||||
("test_MetaEntityRelationshipAccessWorks", test_MetaEntityRelationshipAccessWorks),
|
||||
("test_NonNullOptionalNullableAttribute", test_NonNullOptionalNullableAttribute),
|
||||
("test_NonNullOptionalNullableAttribute_encode", test_NonNullOptionalNullableAttribute_encode),
|
||||
("test_nullableRelationshipIsNull", test_nullableRelationshipIsNull),
|
||||
("test_nullableRelationshipIsNull_encode", test_nullableRelationshipIsNull_encode),
|
||||
("test_nullableRelationshipNotNull", test_nullableRelationshipNotNull),
|
||||
("test_nullableRelationshipNotNull_encode", test_nullableRelationshipNotNull_encode),
|
||||
("test_nullableRelationshipNotNullOrOmitted", test_nullableRelationshipNotNullOrOmitted),
|
||||
("test_nullableRelationshipNotNullOrOmitted_encode", test_nullableRelationshipNotNullOrOmitted_encode),
|
||||
("test_NullOptionalNullableAttribute", test_NullOptionalNullableAttribute),
|
||||
("test_NullOptionalNullableAttribute_encode", test_NullOptionalNullableAttribute_encode),
|
||||
("test_optional_relationship_operator_access", test_optional_relationship_operator_access),
|
||||
("test_optionalNullableRelationshipNulled", test_optionalNullableRelationshipNulled),
|
||||
("test_optionalNullableRelationshipNulled_encode", test_optionalNullableRelationshipNulled_encode),
|
||||
("test_optionalNullableRelationshipOmitted", test_optionalNullableRelationshipOmitted),
|
||||
("test_optionalToMany_relationship_opeartor_access", test_optionalToMany_relationship_opeartor_access),
|
||||
("test_optionalToManyIsNotOmitted", test_optionalToManyIsNotOmitted),
|
||||
("test_optionalToManyIsNotOmitted_encode", test_optionalToManyIsNotOmitted_encode),
|
||||
("test_pointerWithMetaAndLinks", test_pointerWithMetaAndLinks),
|
||||
("test_relationship_access", test_relationship_access),
|
||||
("test_relationship_operator_access", test_relationship_operator_access),
|
||||
("test_relationshipIds", test_relationshipIds),
|
||||
("test_RleationshipsOfSameType", test_RleationshipsOfSameType),
|
||||
("test_RleationshipsOfSameType_encode", test_RleationshipsOfSameType_encode),
|
||||
("test_toMany_relationship_operator_access", test_toMany_relationship_operator_access),
|
||||
("test_toManyMetaRelationshipAccessWorks", test_toManyMetaRelationshipAccessWorks),
|
||||
("test_UnidentifiedEntity", test_UnidentifiedEntity),
|
||||
("test_UnidentifiedEntity_encode", test_UnidentifiedEntity_encode),
|
||||
("test_unidentifiedEntityAttributeAccess", test_unidentifiedEntityAttributeAccess),
|
||||
("test_UnidentifiedEntityWithAttributes", test_UnidentifiedEntityWithAttributes),
|
||||
("test_UnidentifiedEntityWithAttributes_encode", test_UnidentifiedEntityWithAttributes_encode),
|
||||
("test_UnidentifiedEntityWithAttributesAndLinks", test_UnidentifiedEntityWithAttributesAndLinks),
|
||||
("test_UnidentifiedEntityWithAttributesAndLinks_encode", test_UnidentifiedEntityWithAttributesAndLinks_encode),
|
||||
("test_UnidentifiedEntityWithAttributesAndMeta", test_UnidentifiedEntityWithAttributesAndMeta),
|
||||
("test_UnidentifiedEntityWithAttributesAndMeta_encode", test_UnidentifiedEntityWithAttributesAndMeta_encode),
|
||||
("test_UnidentifiedEntityWithAttributesAndMetaAndLinks", test_UnidentifiedEntityWithAttributesAndMetaAndLinks),
|
||||
("test_UnidentifiedEntityWithAttributesAndMetaAndLinks_encode", test_UnidentifiedEntityWithAttributesAndMetaAndLinks_encode),
|
||||
]
|
||||
}
|
||||
|
||||
extension IncludedTests {
|
||||
// DO NOT MODIFY: This is autogenerated, use:
|
||||
// `swift test --generate-linuxmain`
|
||||
@@ -437,6 +359,84 @@ extension ResourceBodyTests {
|
||||
]
|
||||
}
|
||||
|
||||
extension ResourceObjectTests {
|
||||
// DO NOT MODIFY: This is autogenerated, use:
|
||||
// `swift test --generate-linuxmain`
|
||||
// to regenerate.
|
||||
static let __allTests__ResourceObjectTests = [
|
||||
("test_copyIdentifiedByType", test_copyIdentifiedByType),
|
||||
("test_copyIdentifiedByValue", test_copyIdentifiedByValue),
|
||||
("test_copyWithNewId", test_copyWithNewId),
|
||||
("test_entityAllAttribute", test_entityAllAttribute),
|
||||
("test_entityAllAttribute_encode", test_entityAllAttribute_encode),
|
||||
("test_entityBrokenNullableOmittedAttribute", test_entityBrokenNullableOmittedAttribute),
|
||||
("test_EntityNoRelationshipsNoAttributes", test_EntityNoRelationshipsNoAttributes),
|
||||
("test_EntityNoRelationshipsNoAttributes_encode", test_EntityNoRelationshipsNoAttributes_encode),
|
||||
("test_EntityNoRelationshipsSomeAttributes", test_EntityNoRelationshipsSomeAttributes),
|
||||
("test_EntityNoRelationshipsSomeAttributes_encode", test_EntityNoRelationshipsSomeAttributes_encode),
|
||||
("test_entityOneNullAndOneOmittedAttribute", test_entityOneNullAndOneOmittedAttribute),
|
||||
("test_entityOneNullAndOneOmittedAttribute_encode", test_entityOneNullAndOneOmittedAttribute_encode),
|
||||
("test_entityOneNullAttribute", test_entityOneNullAttribute),
|
||||
("test_entityOneNullAttribute_encode", test_entityOneNullAttribute_encode),
|
||||
("test_entityOneOmittedAttribute", test_entityOneOmittedAttribute),
|
||||
("test_entityOneOmittedAttribute_encode", test_entityOneOmittedAttribute_encode),
|
||||
("test_EntitySomeRelationshipsNoAttributes", test_EntitySomeRelationshipsNoAttributes),
|
||||
("test_EntitySomeRelationshipsNoAttributes_encode", test_EntitySomeRelationshipsNoAttributes_encode),
|
||||
("test_EntitySomeRelationshipsSomeAttributes", test_EntitySomeRelationshipsSomeAttributes),
|
||||
("test_EntitySomeRelationshipsSomeAttributes_encode", test_EntitySomeRelationshipsSomeAttributes_encode),
|
||||
("test_EntitySomeRelationshipsSomeAttributesWithLinks", test_EntitySomeRelationshipsSomeAttributesWithLinks),
|
||||
("test_EntitySomeRelationshipsSomeAttributesWithLinks_encode", test_EntitySomeRelationshipsSomeAttributesWithLinks_encode),
|
||||
("test_EntitySomeRelationshipsSomeAttributesWithMeta", test_EntitySomeRelationshipsSomeAttributesWithMeta),
|
||||
("test_EntitySomeRelationshipsSomeAttributesWithMeta_encode", test_EntitySomeRelationshipsSomeAttributesWithMeta_encode),
|
||||
("test_EntitySomeRelationshipsSomeAttributesWithMetaAndLinks", test_EntitySomeRelationshipsSomeAttributesWithMetaAndLinks),
|
||||
("test_EntitySomeRelationshipsSomeAttributesWithMetaAndLinks_encode", test_EntitySomeRelationshipsSomeAttributesWithMetaAndLinks_encode),
|
||||
("test_initialization", test_initialization),
|
||||
("test_IntOver10_encode", test_IntOver10_encode),
|
||||
("test_IntOver10_failure", test_IntOver10_failure),
|
||||
("test_IntOver10_success", test_IntOver10_success),
|
||||
("test_IntToString", test_IntToString),
|
||||
("test_IntToString_encode", test_IntToString_encode),
|
||||
("test_MetaEntityAttributeAccessWorks", test_MetaEntityAttributeAccessWorks),
|
||||
("test_MetaEntityRelationshipAccessWorks", test_MetaEntityRelationshipAccessWorks),
|
||||
("test_NonNullOptionalNullableAttribute", test_NonNullOptionalNullableAttribute),
|
||||
("test_NonNullOptionalNullableAttribute_encode", test_NonNullOptionalNullableAttribute_encode),
|
||||
("test_nullableRelationshipIsNull", test_nullableRelationshipIsNull),
|
||||
("test_nullableRelationshipIsNull_encode", test_nullableRelationshipIsNull_encode),
|
||||
("test_nullableRelationshipNotNull", test_nullableRelationshipNotNull),
|
||||
("test_nullableRelationshipNotNull_encode", test_nullableRelationshipNotNull_encode),
|
||||
("test_nullableRelationshipNotNullOrOmitted", test_nullableRelationshipNotNullOrOmitted),
|
||||
("test_nullableRelationshipNotNullOrOmitted_encode", test_nullableRelationshipNotNullOrOmitted_encode),
|
||||
("test_NullOptionalNullableAttribute", test_NullOptionalNullableAttribute),
|
||||
("test_NullOptionalNullableAttribute_encode", test_NullOptionalNullableAttribute_encode),
|
||||
("test_optional_relationship_operator_access", test_optional_relationship_operator_access),
|
||||
("test_optionalNullableRelationshipNulled", test_optionalNullableRelationshipNulled),
|
||||
("test_optionalNullableRelationshipNulled_encode", test_optionalNullableRelationshipNulled_encode),
|
||||
("test_optionalNullableRelationshipOmitted", test_optionalNullableRelationshipOmitted),
|
||||
("test_optionalToMany_relationship_opeartor_access", test_optionalToMany_relationship_opeartor_access),
|
||||
("test_optionalToManyIsNotOmitted", test_optionalToManyIsNotOmitted),
|
||||
("test_optionalToManyIsNotOmitted_encode", test_optionalToManyIsNotOmitted_encode),
|
||||
("test_pointerWithMetaAndLinks", test_pointerWithMetaAndLinks),
|
||||
("test_relationship_access", test_relationship_access),
|
||||
("test_relationship_operator_access", test_relationship_operator_access),
|
||||
("test_relationshipIds", test_relationshipIds),
|
||||
("test_RleationshipsOfSameType", test_RleationshipsOfSameType),
|
||||
("test_RleationshipsOfSameType_encode", test_RleationshipsOfSameType_encode),
|
||||
("test_toMany_relationship_operator_access", test_toMany_relationship_operator_access),
|
||||
("test_toManyMetaRelationshipAccessWorks", test_toManyMetaRelationshipAccessWorks),
|
||||
("test_UnidentifiedEntity", test_UnidentifiedEntity),
|
||||
("test_UnidentifiedEntity_encode", test_UnidentifiedEntity_encode),
|
||||
("test_unidentifiedEntityAttributeAccess", test_unidentifiedEntityAttributeAccess),
|
||||
("test_UnidentifiedEntityWithAttributes", test_UnidentifiedEntityWithAttributes),
|
||||
("test_UnidentifiedEntityWithAttributes_encode", test_UnidentifiedEntityWithAttributes_encode),
|
||||
("test_UnidentifiedEntityWithAttributesAndLinks", test_UnidentifiedEntityWithAttributesAndLinks),
|
||||
("test_UnidentifiedEntityWithAttributesAndLinks_encode", test_UnidentifiedEntityWithAttributesAndLinks_encode),
|
||||
("test_UnidentifiedEntityWithAttributesAndMeta", test_UnidentifiedEntityWithAttributesAndMeta),
|
||||
("test_UnidentifiedEntityWithAttributesAndMeta_encode", test_UnidentifiedEntityWithAttributesAndMeta_encode),
|
||||
("test_UnidentifiedEntityWithAttributesAndMetaAndLinks", test_UnidentifiedEntityWithAttributesAndMetaAndLinks),
|
||||
("test_UnidentifiedEntityWithAttributesAndMetaAndLinks_encode", test_UnidentifiedEntityWithAttributesAndMetaAndLinks_encode),
|
||||
]
|
||||
}
|
||||
|
||||
extension SparseFieldEncoderTests {
|
||||
// DO NOT MODIFY: This is autogenerated, use:
|
||||
// `swift test --generate-linuxmain`
|
||||
@@ -482,7 +482,6 @@ public func __allTests() -> [XCTestCaseEntry] {
|
||||
testCase(CustomAttributesTests.__allTests__CustomAttributesTests),
|
||||
testCase(DocumentTests.__allTests__DocumentTests),
|
||||
testCase(EmptyObjectDecoderTests.__allTests__EmptyObjectDecoderTests),
|
||||
testCase(EntityTests.__allTests__EntityTests),
|
||||
testCase(IncludedTests.__allTests__IncludedTests),
|
||||
testCase(LinksTests.__allTests__LinksTests),
|
||||
testCase(NonJSONAPIRelatableTests.__allTests__NonJSONAPIRelatableTests),
|
||||
@@ -490,6 +489,7 @@ public func __allTests() -> [XCTestCaseEntry] {
|
||||
testCase(PolyTests.__allTests__PolyTests),
|
||||
testCase(RelationshipTests.__allTests__RelationshipTests),
|
||||
testCase(ResourceBodyTests.__allTests__ResourceBodyTests),
|
||||
testCase(ResourceObjectTests.__allTests__ResourceObjectTests),
|
||||
testCase(SparseFieldEncoderTests.__allTests__SparseFieldEncoderTests),
|
||||
testCase(SparseFieldsetTests.__allTests__SparseFieldsetTests),
|
||||
testCase(TransformerTests.__allTests__TransformerTests),
|
||||
|
||||
Reference in New Issue
Block a user