-
Notifications
You must be signed in to change notification settings - Fork 380
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
<Description> : Adding NSAttributed string data extension.
<Type> : feature/test
- Loading branch information
Showing
4 changed files
with
79 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
// | ||
// DataTests.swift | ||
// EZSwiftExtensions | ||
// | ||
// Created by Sanyal, Arunav on 2/12/17. | ||
// Copyright © 2017 Goktug Yilmaz. All rights reserved. | ||
// | ||
|
||
import XCTest | ||
import EZSwiftExtensions | ||
|
||
class DataTests: XCTestCase { | ||
|
||
override func setUp() { | ||
super.setUp() | ||
} | ||
|
||
override func tearDown() { | ||
super.tearDown() | ||
} | ||
|
||
func testNSAttributedStringSanityTest() { | ||
let data = Data() | ||
XCTAssertEqual(data.attributedString, NSAttributedString()) | ||
} | ||
|
||
func testNSAttributedStringTest() { | ||
|
||
// We can alternatively store the existing google.com contents on a file | ||
// to stabilize this test case. | ||
let url = URL(string:"http://www.google.com") | ||
do { | ||
let data = try Data(contentsOf: url!) | ||
XCTAssertEqual(data.attributedString?.length, 217) | ||
|
||
// TODO : Write additional tests on attrs, e.g. the font family | ||
} catch _ { | ||
XCTFail() | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
// | ||
// DataExtensions.swift | ||
// EZSwiftExtensions | ||
// | ||
// Created by Sanyal, Arunav on 2/12/17. | ||
// Copyright © 2017 Goktug Yilmaz. All rights reserved. | ||
// | ||
|
||
import Foundation | ||
|
||
extension Data { | ||
|
||
/// EZSE : Attributed string from data | ||
/// Found it here : http://stackoverflow.com/questions/39248092/nsattributedstring-extension-in-swift-3 | ||
public var attributedString: NSAttributedString? { | ||
do { | ||
return try NSAttributedString(data: self, options:[NSDocumentTypeDocumentAttribute:NSHTMLTextDocumentType, NSCharacterEncodingDocumentAttribute: String.Encoding.utf8.rawValue], documentAttributes: nil) | ||
} catch let error { | ||
NSLog(error.localizedDescription) | ||
} | ||
return nil | ||
} | ||
} |