From 94cd2d93807f8cf2fbbd5a7d0fb910da81fb1440 Mon Sep 17 00:00:00 2001 From: Bas Broek Date: Tue, 10 Jan 2017 11:30:22 +0100 Subject: [PATCH] Support String Literal expressions --- Analysis/Classes/Analysis.swift | 17 +++++++++++++++++ Example/Tests/AnalysisTests.swift | 7 +++++++ 2 files changed, 24 insertions(+) diff --git a/Analysis/Classes/Analysis.swift b/Analysis/Classes/Analysis.swift index 19df910..a4599a5 100644 --- a/Analysis/Classes/Analysis.swift +++ b/Analysis/Classes/Analysis.swift @@ -253,3 +253,20 @@ extension Analysis: CustomStringConvertible, CustomDebugStringConvertible { return dump(description) } } + +extension Analysis: ExpressibleByStringLiteral { + public typealias UnicodeScalarLiteralType = StringLiteralType + public typealias ExtendedGraphemeClusterLiteralType = StringLiteralType + + public init(stringLiteral value: StringLiteralType) { + self.init(of: value) + } + + public init(extendedGraphemeClusterLiteral value: ExtendedGraphemeClusterLiteralType) { + self.init(of: value) + } + + public init(unicodeScalarLiteral value: UnicodeScalarLiteralType) { + self.init(of: value) + } +} diff --git a/Example/Tests/AnalysisTests.swift b/Example/Tests/AnalysisTests.swift index a97c32f..6e7cec3 100644 --- a/Example/Tests/AnalysisTests.swift +++ b/Example/Tests/AnalysisTests.swift @@ -22,6 +22,9 @@ class AnalysisTests: XCTestCase { let spaces = "Hi. How are you doing? ".analysed() let face = "Can't feel my face".analysed() + let literal: Analysis = "How are you doing?" + let nonLiteral = Analysis(of: "How are you doing?") + override func setUp() { super.setUp() } @@ -221,4 +224,8 @@ class AnalysisTests: XCTestCase { XCTAssertEqual(a.hashValue, a.input.hashValue) XCTAssertEqual(z.hashValue, z.input.hashValue) } + + func testExpressibleByStringLiteral() { + XCTAssertEqual(literal, nonLiteral) + } }