mirror of
https://github.com/encounter/JSONAPI.git
synced 2026-03-30 11:18:38 -07:00
Add TestLib ability to represent to-one relationships with the values of their IDs.
This commit is contained in:
@@ -0,0 +1,30 @@
|
||||
//
|
||||
// Optional+Literal.swift
|
||||
// JSONAPITestLib
|
||||
//
|
||||
// Created by Mathew Polzin on 11/29/18.
|
||||
//
|
||||
|
||||
extension Optional: ExpressibleByUnicodeScalarLiteral where Wrapped: ExpressibleByUnicodeScalarLiteral {
|
||||
public typealias UnicodeScalarLiteralType = Wrapped.UnicodeScalarLiteralType
|
||||
|
||||
public init(unicodeScalarLiteral value: UnicodeScalarLiteralType) {
|
||||
self = .some(Wrapped(unicodeScalarLiteral: value))
|
||||
}
|
||||
}
|
||||
|
||||
extension Optional: ExpressibleByExtendedGraphemeClusterLiteral where Wrapped: ExpressibleByExtendedGraphemeClusterLiteral {
|
||||
public typealias ExtendedGraphemeClusterLiteralType = Wrapped.ExtendedGraphemeClusterLiteralType
|
||||
|
||||
public init(extendedGraphemeClusterLiteral value: ExtendedGraphemeClusterLiteralType) {
|
||||
self = .some(Wrapped(extendedGraphemeClusterLiteral: value))
|
||||
}
|
||||
}
|
||||
|
||||
extension Optional: ExpressibleByStringLiteral where Wrapped: ExpressibleByStringLiteral {
|
||||
public typealias StringLiteralType = Wrapped.StringLiteralType
|
||||
|
||||
public init(stringLiteral value: StringLiteralType) {
|
||||
self = .some(Wrapped(stringLiteral: value))
|
||||
}
|
||||
}
|
||||
@@ -9,10 +9,35 @@ import JSONAPI
|
||||
|
||||
extension ToOneRelationship: ExpressibleByNilLiteral where Relatable.WrappedIdentifier: ExpressibleByNilLiteral {
|
||||
public init(nilLiteral: ()) {
|
||||
|
||||
self.init(id: Relatable.WrappedIdentifier(nilLiteral: ()))
|
||||
}
|
||||
}
|
||||
|
||||
extension ToOneRelationship: ExpressibleByUnicodeScalarLiteral where Relatable.WrappedIdentifier: ExpressibleByUnicodeScalarLiteral {
|
||||
public typealias UnicodeScalarLiteralType = Relatable.WrappedIdentifier.UnicodeScalarLiteralType
|
||||
|
||||
public init(unicodeScalarLiteral value: UnicodeScalarLiteralType) {
|
||||
self.init(id: Relatable.WrappedIdentifier(unicodeScalarLiteral: value))
|
||||
}
|
||||
}
|
||||
|
||||
extension ToOneRelationship: ExpressibleByExtendedGraphemeClusterLiteral where Relatable.WrappedIdentifier: ExpressibleByExtendedGraphemeClusterLiteral {
|
||||
public typealias ExtendedGraphemeClusterLiteralType = Relatable.WrappedIdentifier.ExtendedGraphemeClusterLiteralType
|
||||
|
||||
public init(extendedGraphemeClusterLiteral value: ExtendedGraphemeClusterLiteralType) {
|
||||
self.init(id: Relatable.WrappedIdentifier(extendedGraphemeClusterLiteral: value))
|
||||
}
|
||||
}
|
||||
|
||||
extension ToOneRelationship: ExpressibleByStringLiteral where Relatable.WrappedIdentifier: ExpressibleByStringLiteral {
|
||||
public typealias StringLiteralType = Relatable.WrappedIdentifier.StringLiteralType
|
||||
|
||||
public init(stringLiteral value: StringLiteralType) {
|
||||
self.init(id: Relatable.WrappedIdentifier(stringLiteral: value))
|
||||
}
|
||||
}
|
||||
|
||||
extension ToManyRelationship: ExpressibleByArrayLiteral {
|
||||
public typealias ArrayLiteralElement = Relatable.Identifier
|
||||
|
||||
|
||||
@@ -18,6 +18,11 @@ class Relationship_LiteralTests: XCTestCase {
|
||||
func test_ArrayLiteral() {
|
||||
XCTAssertEqual(ToManyRelationship<TestEntity>(ids: ["1", "2", "3"]), ["1", "2", "3"])
|
||||
}
|
||||
|
||||
func test_StringLiteral() {
|
||||
XCTAssertEqual(ToOneRelationship<TestEntity>(id: "123"), "123")
|
||||
XCTAssertEqual(ToOneRelationship<TestEntity?>(id: "123"), "123")
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: - Test types
|
||||
|
||||
Reference in New Issue
Block a user