Skip to content

Commit

Permalink
Support String Literal expressions
Browse files Browse the repository at this point in the history
  • Loading branch information
BasThomas committed Jan 10, 2017
1 parent b8dee91 commit 94cd2d9
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
17 changes: 17 additions & 0 deletions Analysis/Classes/Analysis.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
7 changes: 7 additions & 0 deletions Example/Tests/AnalysisTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
Expand Down Expand Up @@ -221,4 +224,8 @@ class AnalysisTests: XCTestCase {
XCTAssertEqual(a.hashValue, a.input.hashValue)
XCTAssertEqual(z.hashValue, z.input.hashValue)
}

func testExpressibleByStringLiteral() {
XCTAssertEqual(literal, nonLiteral)
}
}

0 comments on commit 94cd2d9

Please sign in to comment.