NetNewsWire/Frameworks/RSFeedFinder/RSFeedFinderTests/HTMLFeedFinderTests.swift

67 lines
1.9 KiB
Swift
Raw Normal View History

2017-05-22 22:27:54 +02:00
//
// HTMLFeedFinderTests.swift
// RSFeedFinder
//
// Created by Brent Simmons on 8/7/16.
// Copyright © 2016 Ranchero Software, LLC. All rights reserved.
2017-05-22 22:27:54 +02:00
//
import XCTest
@testable import RSFeedFinder
import RSParser
2017-05-22 22:27:54 +02:00
class HTMLFeedFinderTests: XCTestCase {
2017-11-26 01:34:40 +01:00
func parserData(_ filename: String, _ fileExtension: String, _ url: String) -> ParserData {
2017-05-22 22:27:54 +02:00
2017-11-26 01:34:40 +01:00
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)
2017-05-22 22:27:54 +02:00
}
2017-11-26 01:34:40 +01:00
func feedFinder(_ fileName: String, _ fileExtension: String, _ url: String) -> HTMLFeedFinder {
2017-05-22 22:27:54 +02:00
2017-11-26 01:34:40 +01:00
let d = parserData(fileName, fileExtension, url)
return HTMLFeedFinder(parserData: d)
2017-05-22 22:27:54 +02:00
}
func testPerformanceWithDaringFireball() {
2017-11-26 01:34:40 +01:00
let d = parserData("DaringFireball", "html", "https://daringfireball.net/")
2017-05-22 22:27:54 +02:00
self.measure {
2017-11-26 01:34:40 +01:00
let finder = HTMLFeedFinder(parserData: d)
2017-05-22 22:27:54 +02:00
let _ = finder.feedSpecifiers
}
}
func testFindingBestFeedWithDaringFireBall() {
2017-05-22 22:27:54 +02:00
2017-11-26 01:34:40 +01:00
let finder = feedFinder("DaringFireball", "html", "https://daringfireball.net/")
2017-05-22 22:27:54 +02:00
let feedSpecifiers = finder.feedSpecifiers
2017-11-26 01:34:40 +01:00
let bestFeedSpecifier = FeedSpecifier.bestFeed(in: feedSpecifiers)!
XCTAssert(bestFeedSpecifier.urlString == "https://daringfireball.net/feeds/json")
}
func testFindingBestFeedWithFurbo() {
let finder = feedFinder("furbo", "html", "http://furbo.org")
let feedSpecifiers = finder.feedSpecifiers
let bestFeedSpecifier = FeedSpecifier.bestFeed(in: feedSpecifiers)!
XCTAssert(bestFeedSpecifier.urlString == "http://furbo.org/feed/")
}
func testFindingBestFeedWithIndieStack() {
let finder = feedFinder("indiestack", "html", "http://indiestack.com/")
let feedSpecifiers = finder.feedSpecifiers
let bestFeedSpecifier = FeedSpecifier.bestFeed(in: feedSpecifiers)!
XCTAssert(bestFeedSpecifier.urlString == "http://indiestack.com/feed/json/")
2017-05-22 22:27:54 +02:00
}
2017-11-26 01:34:40 +01:00
}
2017-05-22 22:27:54 +02:00