2017-06-27 04:51:01 +02:00
|
|
|
|
//
|
|
|
|
|
// RSSParserTests.swift
|
|
|
|
|
// RSParser
|
|
|
|
|
//
|
|
|
|
|
// Created by Brent Simmons on 6/26/17.
|
|
|
|
|
// Copyright © 2017 Ranchero Software, LLC. All rights reserved.
|
|
|
|
|
//
|
|
|
|
|
|
|
|
|
|
import XCTest
|
|
|
|
|
import RSParser
|
|
|
|
|
|
|
|
|
|
class RSSParserTests: XCTestCase {
|
|
|
|
|
|
|
|
|
|
func testScriptingNewsPerformance() {
|
|
|
|
|
|
|
|
|
|
// 0.004 sec on my 2012 iMac.
|
|
|
|
|
let d = parserData("scriptingNews", "rss", "http://scripting.com/")
|
|
|
|
|
self.measure {
|
|
|
|
|
let _ = try! FeedParser.parse(d)
|
|
|
|
|
}
|
|
|
|
|
}
|
2017-06-27 15:56:03 +02:00
|
|
|
|
|
|
|
|
|
func testKatieFloydPerformance() {
|
|
|
|
|
|
|
|
|
|
// 0.004 sec on my 2012 iMac.
|
|
|
|
|
let d = parserData("KatieFloyd", "rss", "http://katiefloyd.com/")
|
|
|
|
|
self.measure {
|
|
|
|
|
let _ = try! FeedParser.parse(d)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func testEMarleyPerformance() {
|
|
|
|
|
|
|
|
|
|
// 0.001 sec on my 2012 iMac.
|
|
|
|
|
let d = parserData("EMarley", "rss", "https://medium.com/@emarley")
|
|
|
|
|
self.measure {
|
|
|
|
|
let _ = try! FeedParser.parse(d)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func testMantonPerformance() {
|
|
|
|
|
|
|
|
|
|
// 0.002 sec on my 2012 iMac.
|
|
|
|
|
let d = parserData("manton", "rss", "http://manton.org/")
|
|
|
|
|
self.measure {
|
|
|
|
|
let _ = try! FeedParser.parse(d)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-12-08 05:05:58 +01:00
|
|
|
|
func testNatashaTheRobot() {
|
|
|
|
|
|
|
|
|
|
let d = parserData("natasha", "xml", "https://www.natashatherobot.com/")
|
|
|
|
|
let parsedFeed = try! FeedParser.parse(d)!
|
|
|
|
|
XCTAssertEqual(parsedFeed.items.count, 10)
|
|
|
|
|
}
|
|
|
|
|
|
2017-12-19 00:35:50 +01:00
|
|
|
|
func testTheOmniShowAttachments() {
|
|
|
|
|
|
|
|
|
|
let d = parserData("theomnishow", "rss", "https://theomnishow.omnigroup.com/")
|
|
|
|
|
let parsedFeed = try! FeedParser.parse(d)!
|
|
|
|
|
|
|
|
|
|
for article in parsedFeed.items {
|
|
|
|
|
XCTAssertNotNil(article.attachments)
|
|
|
|
|
XCTAssertEqual(article.attachments!.count, 1)
|
|
|
|
|
let attachment = Array(article.attachments!).first!
|
|
|
|
|
XCTAssertNotNil(attachment.mimeType)
|
|
|
|
|
XCTAssertNotNil(attachment.sizeInBytes)
|
|
|
|
|
XCTAssert(attachment.url.contains("cloudfront"))
|
|
|
|
|
XCTAssertGreaterThanOrEqual(attachment.sizeInBytes!, 22275279)
|
|
|
|
|
XCTAssertEqual(attachment.mimeType, "audio/mpeg")
|
|
|
|
|
}
|
|
|
|
|
}
|
2017-12-19 20:02:05 +01:00
|
|
|
|
|
2017-12-19 20:20:40 +01:00
|
|
|
|
func testTheOmniShowUniqueIDs() {
|
2017-12-19 20:02:05 +01:00
|
|
|
|
|
|
|
|
|
let d = parserData("theomnishow", "rss", "https://theomnishow.omnigroup.com/")
|
|
|
|
|
let parsedFeed = try! FeedParser.parse(d)!
|
|
|
|
|
|
|
|
|
|
for article in parsedFeed.items {
|
|
|
|
|
XCTAssertNotNil(article.uniqueID)
|
|
|
|
|
XCTAssertTrue(article.uniqueID.hasPrefix("https://theomnishow.omnigroup.com/episode/"))
|
|
|
|
|
}
|
|
|
|
|
}
|
2017-12-19 20:20:40 +01:00
|
|
|
|
|
|
|
|
|
func testMacworldUniqueIDs() {
|
|
|
|
|
|
|
|
|
|
// Macworld’s feed doesn’t have guids, so they should be calculated unique IDs.
|
|
|
|
|
|
|
|
|
|
let d = parserData("macworld", "rss", "https://www.macworld.com/")
|
|
|
|
|
let parsedFeed = try! FeedParser.parse(d)!
|
|
|
|
|
|
|
|
|
|
for article in parsedFeed.items {
|
|
|
|
|
XCTAssertNotNil(article.uniqueID)
|
|
|
|
|
XCTAssertEqual(article.uniqueID.count, 32) // calculated unique IDs are MD5 hashes
|
|
|
|
|
}
|
2017-12-19 22:28:33 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func testMacworldAuthors() {
|
|
|
|
|
|
|
|
|
|
// Macworld uses names instead of email addresses (despite the RSS spec saying they should be email addresses).
|
2017-12-19 20:20:40 +01:00
|
|
|
|
|
2017-12-19 22:28:33 +01:00
|
|
|
|
let d = parserData("macworld", "rss", "https://www.macworld.com/")
|
|
|
|
|
let parsedFeed = try! FeedParser.parse(d)!
|
|
|
|
|
|
|
|
|
|
for article in parsedFeed.items {
|
|
|
|
|
|
|
|
|
|
let author = article.authors!.first!
|
|
|
|
|
XCTAssertNil(author.emailAddress)
|
|
|
|
|
XCTAssertNil(author.url)
|
|
|
|
|
XCTAssertNotNil(author.name)
|
|
|
|
|
}
|
2017-12-19 20:20:40 +01:00
|
|
|
|
}
|
2017-06-27 04:51:01 +02:00
|
|
|
|
}
|