Skip to content

Commit

Permalink
Merge pull request #15 from kazuhiro4949/swift4Test
Browse files Browse the repository at this point in the history
Supporting Swift4 to Unit Test
  • Loading branch information
kazuhiro4949 committed Sep 30, 2017
2 parents 85e3f92 + 5246298 commit d8936d5
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 32 deletions.
4 changes: 2 additions & 2 deletions StringStylizer.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -377,7 +377,7 @@
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = kazuhiro.hayashi.StringStylizerTests;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 3.0;
SWIFT_VERSION = 4.0;
};
name = Debug;
};
Expand All @@ -388,7 +388,7 @@
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = kazuhiro.hayashi.StringStylizerTests;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 3.0;
SWIFT_VERSION = 4.0;
};
name = Release;
};
Expand Down
59 changes: 29 additions & 30 deletions StringStylizerTests/StringStylizerTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -52,63 +52,62 @@ class StringStylizerTests: XCTestCase {

func testColor() {
let str = "StringStylizer".stylize().color(.white).attr
let expected = NSAttributedString(string: "StringStylizer", attributes: [NSForegroundColorAttributeName: UIColor.white])
let expected = NSAttributedString(string: "StringStylizer", attributes: [.foregroundColor: UIColor.white])
XCTAssert(str.isEqual(to: expected), "has color attributed")
}

func testFontAndSize() {
let str = "StringStylizer".stylize().font(.Helvetica).size(17).attr
let expected = NSAttributedString(string: "StringStylizer", attributes: [NSFontAttributeName: UIFont(name: "Helvetica", size: 17)!])
let expected = NSAttributedString(string: "StringStylizer", attributes: [.font: UIFont(name: "Helvetica", size: 17)!])
XCTAssert(str.isEqual(to: expected), "has font and size attributed")
}

func testBackground() {
let str = "StringStylizer".stylize().background(0x000000).attr
let expected = NSAttributedString(string: "StringStylizer", attributes: [NSBackgroundColorAttributeName: rgb(0x000000, alpha: 1.0)])
let expected = NSAttributedString(string: "StringStylizer", attributes: [.backgroundColor: rgb(0x000000, alpha: 1.0)])
XCTAssert(str.isEqual(to: expected), "has background attributed")
}

func testKarn() {
let str = "StringStylizer".stylize().karn(1).attr
let expected = NSAttributedString(string: "StringStylizer", attributes: [NSKernAttributeName: 1])
let expected = NSAttributedString(string: "StringStylizer", attributes: [.kern: 1])
XCTAssert(str.isEqual(to: expected), "has karn attributed")
}

func testUnderline() {
let str = "StringStylizer".stylize().underline(.styleSingle).attr
let expected = NSAttributedString(string: "StringStylizer", attributes: [NSUnderlineStyleAttributeName: NSUnderlineStyle.styleSingle.rawValue])
let expected = NSAttributedString(string: "StringStylizer", attributes: [.underlineStyle: NSUnderlineStyle.styleSingle.rawValue])
XCTAssert(str.isEqual(to: expected), "has underline attributed")
}

func testUnderlineNoneParam() {
let str = "StringStylizer".stylize().underline().attr
let expected = NSAttributedString(string: "StringStylizer", attributes: [NSUnderlineStyleAttributeName: NSUnderlineStyle.styleSingle.rawValue])
let expected = NSAttributedString(string: "StringStylizer", attributes: [.underlineStyle: NSUnderlineStyle.styleSingle.rawValue])
XCTAssert(str.isEqual(to: expected), "has underline attributed")
}

func testStrokeParam() {
let str = "StringStylizer".stylize().stroke(color: .white).attr
let expected = NSAttributedString(string: "StringStylizer", attributes: [NSStrokeColorAttributeName: UIColor.white,
NSStrokeWidthAttributeName: 1.0])
let expected = NSAttributedString(string: "StringStylizer", attributes: [.strokeColor: UIColor.white, .strokeWidth: 1.0])
XCTAssert(str.isEqual(to: expected), "has stroke attributed")
}

func testStrokeThroghParam() {
let str = "StringStylizer".stylize().strokeThrogh(.styleDouble).attr
let expected = NSAttributedString(string: "StringStylizer", attributes: [NSStrikethroughStyleAttributeName: NSUnderlineStyle.styleDouble.rawValue])
let expected = NSAttributedString(string: "StringStylizer", attributes: [.strikethroughStyle: NSUnderlineStyle.styleDouble.rawValue])
XCTAssert(str.isEqual(to: expected), "has strokeThrogh attributed")
}

func testStrokeThroghBlankParam() {
let str = "StringStylizer".stylize().strokeThrogh().attr
let expected = NSAttributedString(string: "StringStylizer", attributes: [NSStrikethroughStyleAttributeName: NSUnderlineStyle.styleSingle.rawValue])
let expected = NSAttributedString(string: "StringStylizer", attributes: [.strikethroughStyle: NSUnderlineStyle.styleSingle.rawValue])
XCTAssert(str.isEqual(to: expected), "has strokeThrogh attributed")
}

func testShadowParam() {
let shadow = NSShadow()
let str = "StringStylizer".stylize().shadow(shadow).attr
let expected = NSAttributedString(string: "StringStylizer", attributes: [NSShadowAttributeName: shadow])
let expected = NSAttributedString(string: "StringStylizer", attributes: [.shadow: shadow])
XCTAssert(str.isEqual(to: expected), "has shadow attributed")
}

Expand All @@ -118,7 +117,7 @@ class StringStylizerTests: XCTestCase {
shadow.shadowOffset = CGSize(width: 10, height: 10)
shadow.shadowColor = UIColor.red
shadow.shadowBlurRadius = 1.0
let expected = NSAttributedString(string: "StringStylizer", attributes: [NSShadowAttributeName: shadow])
let expected = NSAttributedString(string: "StringStylizer", attributes: [.shadow: shadow])
XCTAssert(str.isEqual(to: expected), "has shadow attributed")
}

Expand All @@ -128,57 +127,57 @@ class StringStylizerTests: XCTestCase {
let shadow = NSShadow()
shadow.shadowOffset = CGSize(width: 10, height: 10)
shadow.shadowColor = UIColor.red
let expected = NSAttributedString(string: "StringStylizer", attributes: [NSShadowAttributeName: shadow])
let expected = NSAttributedString(string: "StringStylizer", attributes: [.shadow: shadow])
XCTAssert(str.isEqual(to: expected), "has shadow attributed")
}

func testShadowPropertyParamNoAplphaAndBlurRadiusAndColor() {
let str = "StringStylizer".stylize().shadow(offset: (10, 10)).attr
let shadow = NSShadow()
shadow.shadowOffset = CGSize(width: 10, height: 10)
let expected = NSAttributedString(string: "StringStylizer", attributes: [NSShadowAttributeName: shadow])
let expected = NSAttributedString(string: "StringStylizer", attributes: [.shadow: shadow])
XCTAssert(str.isEqual(to: expected), "has shadow attributed")
}

func testLigetureParam() {
let str = "StringStylizer".stylize().ligeture(1).attr
let expected = NSAttributedString(string: "StringStylizer", attributes: [NSLigatureAttributeName: 1])
let expected = NSAttributedString(string: "StringStylizer", attributes: [.ligature: 1])
XCTAssert(str.isEqual(to: expected), "has ligeture attributed")
}

func testBaselineParam() {
let str = "StringStylizer".stylize().baselineOffset(1).attr
let expected = NSAttributedString(string: "StringStylizer", attributes: [NSBaselineOffsetAttributeName: 1])
let expected = NSAttributedString(string: "StringStylizer", attributes: [.baselineOffset: 1])
XCTAssert(str.isEqual(to: expected), "has baselineOffset attributed")
}

func testLinkParam() {
let url = URL(string: "http://test.com")!
let str = "StringStylizer".stylize().link(url).attr
let expected = NSAttributedString(string: "StringStylizer", attributes: [NSLinkAttributeName: url])
let expected = NSAttributedString(string: "StringStylizer", attributes: [.link: url])
XCTAssert(str.isEqual(to: expected), "has link attribute")
}

func testParagraphParam() {
let paragraph = NSParagraphStyle()
let str = "StringStylizer".stylize().paragraph(paragraph).attr
let expected = NSAttributedString(string: "StringStylizer", attributes: [NSParagraphStyleAttributeName: paragraph])
let expected = NSAttributedString(string: "StringStylizer", attributes: [.paragraphStyle: paragraph])
XCTAssert(str.isEqual(to: expected), "has color attributed")
}

func testPartialRange() {
let str = "StringStylizer".stylize().range(5..<UInt.max).color(.white).attr

let expected = NSMutableAttributedString(string: "StringStylizer")
expected.addAttributes([NSForegroundColorAttributeName: UIColor.white], range: NSRange(5..<str.length))
expected.addAttributes([.foregroundColor: UIColor.white], range: NSRange(5..<str.length))
XCTAssert(str.isEqual(to: expected), "has correct partial range")
}

func testPartialSearch() {
let str = "StringStylizer".stylize().search("ring").color(.white).attr

let expected = NSMutableAttributedString(string: "StringStylizer")
expected.addAttributes([NSForegroundColorAttributeName: UIColor.white], range: NSRange(2..<6))
expected.addAttributes([.foregroundColor: UIColor.white], range: NSRange(2..<6))
XCTAssert(str.isEqual(to: expected), "has correct partial range")
}

Expand All @@ -189,11 +188,11 @@ class StringStylizerTests: XCTestCase {

let expected = NSMutableAttributedString(string: "StringStylizer")
expected.addAttributes(
[NSForegroundColorAttributeName: UIColor.white],
[.foregroundColor: UIColor.white],
range: NSRange(5..<str.length)
)
expected.addAttributes(
[NSFontAttributeName: UIFont.systemFont(ofSize: 14)],
[.font: UIFont.systemFont(ofSize: 14)],
range: NSRange(1..<4)
)

Expand All @@ -206,12 +205,12 @@ class StringStylizerTests: XCTestCase {

let expectedHead = NSMutableAttributedString(string: "String")
expectedHead.addAttributes(
[NSForegroundColorAttributeName: UIColor.white],
[.foregroundColor: UIColor.white],
range: NSRange(5..<"String".characters.count)
)
let expectedTail = NSMutableAttributedString(string: "Stylizer")
expectedTail.addAttributes(
[NSFontAttributeName: UIFont.systemFont(ofSize: 14)],
[.font: UIFont.systemFont(ofSize: 14)],
range: NSRange(1..<4)
)
expectedHead.append(expectedTail)
Expand All @@ -224,7 +223,7 @@ class StringStylizerTests: XCTestCase {

let style = NSMutableParagraphStyle()
style.alignment = .right
let expcted = NSMutableAttributedString(string: "StringStylizer", attributes: [NSParagraphStyleAttributeName: style])
let expcted = NSMutableAttributedString(string: "StringStylizer", attributes: [.paragraphStyle: style])

XCTAssert(str.isEqual(to: expcted), "has paragraph Alinment")
}
Expand All @@ -236,7 +235,7 @@ class StringStylizerTests: XCTestCase {
style.firstLineHeadIndent = 10
style.headIndent = 10
style.tailIndent = 10
let expcted = NSMutableAttributedString(string: "StringStylizer", attributes: [NSParagraphStyleAttributeName: style])
let expcted = NSMutableAttributedString(string: "StringStylizer", attributes: [.paragraphStyle: style])
XCTAssert(str.isEqual(to: expcted), "has paragraph Indent")
}

Expand All @@ -245,7 +244,7 @@ class StringStylizerTests: XCTestCase {

let style = NSMutableParagraphStyle()
style.lineBreakMode = .byCharWrapping
let expcted = NSMutableAttributedString(string: "StringStylizer", attributes: [NSParagraphStyleAttributeName: style])
let expcted = NSMutableAttributedString(string: "StringStylizer", attributes: [.paragraphStyle: style])
XCTAssert(str.isEqual(to: expcted), "has paragraph line break")
}

Expand All @@ -256,7 +255,7 @@ class StringStylizerTests: XCTestCase {
style.maximumLineHeight = 10
style.minimumLineHeight = 10
style.lineHeightMultiple = 1.0
let expcted = NSMutableAttributedString(string: "StringStylizer", attributes: [NSParagraphStyleAttributeName: style])
let expcted = NSMutableAttributedString(string: "StringStylizer", attributes: [.paragraphStyle: style])
XCTAssert(str.isEqual(to: expcted), "has paragraph line height")
}

Expand All @@ -266,7 +265,7 @@ class StringStylizerTests: XCTestCase {
let style = NSMutableParagraphStyle()
style.lineSpacing = 10
style.paragraphSpacingBefore = 10
let expcted = NSMutableAttributedString(string: "StringStylizer", attributes: [NSParagraphStyleAttributeName: style])
let expcted = NSMutableAttributedString(string: "StringStylizer", attributes: [.paragraphStyle: style])
XCTAssert(str.isEqual(to: expcted), "has paragraph spacing before")
}

Expand All @@ -275,7 +274,7 @@ class StringStylizerTests: XCTestCase {

let style = NSMutableParagraphStyle()
style.baseWritingDirection = .rightToLeft
let expcted = NSMutableAttributedString(string: "StringStylizer", attributes: [NSParagraphStyleAttributeName: style])
let expcted = NSMutableAttributedString(string: "StringStylizer", attributes: [.paragraphStyle: style])
XCTAssert(str.isEqual(to: expcted), "has paragraph Indent")
}

Expand Down

0 comments on commit d8936d5

Please sign in to comment.