diff --git a/Frameworks/RSFeedFinder/RSFeedFinderTests/HTMLFeedFinderTests.swift b/Frameworks/RSFeedFinder/RSFeedFinderTests/HTMLFeedFinderTests.swift index b43851fe0..c6cd586b1 100644 --- a/Frameworks/RSFeedFinder/RSFeedFinderTests/HTMLFeedFinderTests.swift +++ b/Frameworks/RSFeedFinder/RSFeedFinderTests/HTMLFeedFinderTests.swift @@ -12,104 +12,62 @@ import RSParser class HTMLFeedFinderTests: XCTestCase { - private var xmlDataCache = [String: RSXMLData]() + func parserData(_ filename: String, _ fileExtension: String, _ url: String) -> ParserData { - override func setUp() { - super.setUp() - // Put setup code here. This method is called before the invocation of each test method in the class. - } - - override func tearDown() { - // Put teardown code here. This method is called after the invocation of each test method in the class. - super.tearDown() - } - - func testExample() { - // This is an example of a functional test case. - // Use XCTAssert and related functions to verify your tests produce the correct results. - } - - func testPerformanceExample() { - // This is an example of a performance test case. - self.measure { - // Put the code you want to measure the time of here. - } - } - - func xmlDataFor(title: String, urlString: String) -> RSXMLData? { - - if let cachedXMLData = xmlDataCache[title] { - return cachedXMLData - } - - if let s = Bundle(for: self.dynamicType).url(forResource: title, withExtension: "html") { - let d = try! Data(contentsOf: s) - let xmlData = RSXMLData(data: d, urlString: urlString) - xmlDataCache[title] = xmlData - return xmlData - } - return nil + let bundle = Bundle(for: HTMLFeedFinderTests.self) + let path = bundle.path(forResource: filename, ofType: fileExtension)! + let data = try! Data(contentsOf: URL(fileURLWithPath: path)) + return ParserData(url: url, data: data) } - func daringFireballData() -> RSXMLData { + func feedFinder(_ fileName: String, _ fileExtension: String, _ url: String) -> HTMLFeedFinder { - return xmlDataFor(title:"DaringFireball", urlString:"http://daringfireball.net/")! - } - - func furboData() -> RSXMLData { - - return xmlDataFor(title:"furbo", urlString:"http://furbo.org/")! - } - - func inessentialData() -> RSXMLData { - - return xmlDataFor(title:"inessential", urlString:"http://inessential.com/")! - } - - func sixColorsData() -> RSXMLData { - - return xmlDataFor(title:"sixcolors", urlString:"https://sixcolors.com/")! + let d = parserData(fileName, fileExtension, url) + return HTMLFeedFinder(parserData: d) } func testPerformanceWithDaringFireball() { - let xmlData = daringFireballData() + let d = parserData("DaringFireball", "html", "https://daringfireball.net/") self.measure { - let finder = HTMLFeedFinder(xmlData: xmlData) + let finder = HTMLFeedFinder(parserData: d) let _ = finder.feedSpecifiers } } func testHTMLParserWithDaringFireBall() { - let finder = HTMLFeedFinder(xmlData: daringFireballData()) + let finder = feedFinder("DaringFireball", "html", "https://daringfireball.net/") let feedSpecifiers = finder.feedSpecifiers - let bestFeedSpecifier = FeedFinder.bestFeed(in: feedSpecifiers) + let bestFeedSpecifier = FeedSpecifier.bestFeed(in: feedSpecifiers)! print(bestFeedSpecifier) } - func testHTMLParserWithFurbo() { - - let finder = HTMLFeedFinder(xmlData: furboData()) - let feedSpecifiers = finder.feedSpecifiers - let bestFeedSpecifier = FeedFinder.bestFeed(in: feedSpecifiers) - print(bestFeedSpecifier) - } - - func testHTMLParserWithInessential() { - - let finder = HTMLFeedFinder(xmlData: inessentialData()) - let feedSpecifiers = finder.feedSpecifiers - let bestFeedSpecifier = FeedFinder.bestFeed(in: feedSpecifiers) - print(bestFeedSpecifier) - } - - func testHTMLParserWithSixColors() { - - let finder = HTMLFeedFinder(xmlData: sixColorsData()) - let feedSpecifiers = finder.feedSpecifiers - let bestFeedSpecifier = FeedFinder.bestFeed(in: feedSpecifiers) - print(bestFeedSpecifier) - } +// func testHTMLParserWithFurbo() { +// +// let finder = HTMLFeedFinder(xmlData: furboData()) +// let feedSpecifiers = finder.feedSpecifiers +// let bestFeedSpecifier = FeedFinder.bestFeed(in: feedSpecifiers) +// print(bestFeedSpecifier) +// } +// +// func testHTMLParserWithInessential() { +// +// let finder = HTMLFeedFinder(xmlData: inessentialData()) +// let feedSpecifiers = finder.feedSpecifiers +// let bestFeedSpecifier = FeedFinder.bestFeed(in: feedSpecifiers) +// print(bestFeedSpecifier) +// } +// +// func testHTMLParserWithSixColors() { +// +// let finder = HTMLFeedFinder(xmlData: sixColorsData()) +// let feedSpecifiers = finder.feedSpecifiers +// let bestFeedSpecifier = FeedFinder.bestFeed(in: feedSpecifiers) +// print(bestFeedSpecifier) +// } } + + + diff --git a/Frameworks/RSFeedFinder/RSFeedFinderTests/Resources/DaringFireball.html b/Frameworks/RSFeedFinder/RSFeedFinderTests/Resources/DaringFireball.html index 690218708..4bcdf3000 100644 --- a/Frameworks/RSFeedFinder/RSFeedFinderTests/Resources/DaringFireball.html +++ b/Frameworks/RSFeedFinder/RSFeedFinderTests/Resources/DaringFireball.html @@ -1,5 +1,5 @@ - + Daring Fireball @@ -10,18 +10,16 @@ - + + + - +
- - -