Skip to content

Commit

Permalink
Merge pull request #55 from Nirma/smoke_test
Browse files Browse the repository at this point in the history
Add more tests for attribute creation
  • Loading branch information
Nicholas Maccharoli authored Jun 21, 2018
2 parents 5df6bf7 + 0627c72 commit 4520e70
Showing 1 changed file with 68 additions and 3 deletions.
71 changes: 68 additions & 3 deletions AttributedTests/AttributesTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,77 @@ class AttributesTests: XCTestCase {
let attributed = Attributes().font(.systemFont(ofSize: 12.0))
XCTAssert(attributed.dictionary.keys.first!.rawValue == expected.keys.first!, "Font is broken")
}

// NSBaselineOffsetAttributeName


func testBaselineOffset() {
let expected: [String: Any] = [NSAttributedStringKey.baselineOffset.rawValue: NSNumber(value: 1)]
let attributed = Attributes().baselineOffset(1)
XCTAssert(attributed.dictionary.keys.first!.rawValue == expected.keys.first!, "NSBaselineOffsetAttributeName functionality is broken")
}


func testKerning() {
let testText = "Smoke Test"
let smokeTestString = testText.at.attributed { $0.kerning(1.0) }
let baseString = NSAttributedString(string: testText, attributes: [.kern: 1.0])

XCTAssert(smokeTestString == baseString, "Kern functionality is broken")
}

func testStrokeColor() {
let testText = "Smoke Test"
let smokeTestString = testText.at.attributed { $0.strokeColor(.green) }
let baseString = NSAttributedString(string: testText, attributes: [ .strokeColor : UIColor.green])

XCTAssert(smokeTestString == baseString, "StrokeColor functionality is broken")
}

func testStrokeWidth() {
let testText = "Smoke Test"
let smokeTestString = testText.at.attributed { $0.strokeWidth(2.0) }
let baseString = NSAttributedString(string: testText, attributes: [ .strokeWidth : 2.0])

XCTAssert(smokeTestString == baseString, "Stroke width functionality is broken")
}

func testUnderlineStyle() {
let testText = "Smoke Test"
let smokeTestString = testText.at.attributed { $0.underlineStyle(NSUnderlineStyle.byWord) }
let baseString = NSAttributedString(string: testText, attributes: [ .underlineStyle : NSUnderlineStyle.byWord.rawValue])

XCTAssert(smokeTestString == baseString, "Underline style functionality is broken")
}

func testForegroundColor() {
let testText = "Smoke Test"
let smokeTestString = testText.at.attributed { $0.foreground(color: .green) }
let baseString = NSAttributedString(string: testText, attributes: [ .foregroundColor : UIColor.green])

XCTAssert(smokeTestString == baseString, "Foreground color functionality is broken")
}

func testBackgroundColor() {
let testText = "Smoke Test"
let smokeTestString = testText.at.attributed { $0.background(color: .green) }
let baseString = NSAttributedString(string: testText, attributes: [ .backgroundColor : UIColor.green])

XCTAssert(smokeTestString == baseString, "Background color functionality is broken")
}

func testObliqueness() {
let testText = "Smoke Test"
let smokeTestString = testText.at.attributed { $0.obliqueness(1.0) }
let baseString = NSAttributedString(string: testText, attributes: [ .obliqueness : 1.0])

XCTAssert(smokeTestString == baseString, "Obliqueness functionality is broken")
}

func testShadow() {
let testText = "Smoke Test"
let shadow = NSShadow()
shadow.shadowBlurRadius = 0.5
let smokeTestString = testText.at.attributed { $0.shadow(shadow) }
let baseString = NSAttributedString(string: testText, attributes: [ .shadow : shadow])

XCTAssert(smokeTestString == baseString, "Shadow functionality is broken")
}
}

0 comments on commit 4520e70

Please sign in to comment.