diff --git a/Sources/JSONAPITestLib/Optional+Literal.swift b/Sources/JSONAPITestLib/Optional+Literal.swift new file mode 100644 index 0000000..7c9087f --- /dev/null +++ b/Sources/JSONAPITestLib/Optional+Literal.swift @@ -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)) + } +} diff --git a/Sources/JSONAPITestLib/Relationship+Literal.swift b/Sources/JSONAPITestLib/Relationship+Literal.swift index 42fdc6d..0dc586e 100644 --- a/Sources/JSONAPITestLib/Relationship+Literal.swift +++ b/Sources/JSONAPITestLib/Relationship+Literal.swift @@ -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 diff --git a/Tests/JSONAPITests/JSONAPITestLib/Relationship+LiteralTests.swift b/Tests/JSONAPITests/JSONAPITestLib/Relationship+LiteralTests.swift index 896535e..42ec030 100644 --- a/Tests/JSONAPITests/JSONAPITestLib/Relationship+LiteralTests.swift +++ b/Tests/JSONAPITests/JSONAPITestLib/Relationship+LiteralTests.swift @@ -18,6 +18,11 @@ class Relationship_LiteralTests: XCTestCase { func test_ArrayLiteral() { XCTAssertEqual(ToManyRelationship(ids: ["1", "2", "3"]), ["1", "2", "3"]) } + + func test_StringLiteral() { + XCTAssertEqual(ToOneRelationship(id: "123"), "123") + XCTAssertEqual(ToOneRelationship(id: "123"), "123") + } } // MARK: - Test types