Skip to content

Commit

Permalink
Add formatting test for #3
Browse files Browse the repository at this point in the history
  • Loading branch information
kean committed Apr 29, 2021
1 parent 2c3b700 commit ab2800b
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions Tests/FormattingTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,25 @@ class FormattingsTests: XCTestCase {
XCTAssertEqual(font.pointSize, 20)
}
}

func testEmoji() throws {
// GIVEN
let style = FormattedStringStyle(attributes: [
"t": [.foregroundColor: UIColor.red]
])

// WHEN
let input = "⚠ Text with <t>emoji</t>"
let output = NSAttributedString(formatting: input, style: style)

// THEN
let allAttributes = output.attributes
XCTAssertEqual(allAttributes.count, 2)

let colorAttribute = try XCTUnwrap(allAttributes.first { $0.attributes.first?.key == NSAttributedString.Key.foregroundColor })
let range = colorAttribute.range
XCTAssertEqual((output.string as NSString).substring(with: range), "emoji")
}
}

private extension NSAttributedString {
Expand Down

0 comments on commit ab2800b

Please sign in to comment.