NetNewsWire/Frameworks/RSParser/RSParserTests/OPMLTests.swift

67 lines
1.6 KiB
Swift
Raw Normal View History

2017-06-26 02:15:47 +02:00
//
// OPMLTests.swift
// RSParser
//
// Created by Brent Simmons on 6/25/17.
// Copyright © 2017 Ranchero Software, LLC. All rights reserved.
//
import XCTest
import RSParser
class OPMLTests: XCTestCase {
2017-06-26 02:34:48 +02:00
let subsData = parserData("Subs", "opml", "http://example.org/")
2017-06-26 02:15:47 +02:00
func testOPMLParsingPerformance() {
2017-06-26 02:34:48 +02:00
// 0.002 sec on my 2012 iMac.
2017-06-26 02:15:47 +02:00
self.measure {
2017-06-26 02:34:48 +02:00
let _ = try! RSOPMLParser.parseOPML(with: self.subsData)
2017-06-26 02:15:47 +02:00
}
}
2017-06-26 02:34:48 +02:00
func testNotOPML() {
let d = parserData("DaringFireball", "rss", "http://daringfireball.net/")
XCTAssertThrowsError(try RSOPMLParser.parseOPML(with: d))
}
func testSubsStructure() {
let opmlDocument = try! RSOPMLParser.parseOPML(with: subsData)
recursivelyCheckOPMLStructure(opmlDocument)
}
func recursivelyCheckOPMLStructure(_ item: RSOPMLItem) {
let feedSpecifier = item.feedSpecifier
2017-06-26 02:34:48 +02:00
if !(item is RSOPMLDocument) {
XCTAssertNotNil((item.attributes! as NSDictionary).opml_text)
2017-06-26 02:34:48 +02:00
}
// If it has no children, it should have a feed specifier. The converse is also true.
var isFolder = item.children != nil && item.children!.count > 0
if !isFolder && (item.attributes! as NSDictionary).opml_title == "Skip" {
2017-06-26 02:34:48 +02:00
isFolder = true
}
if !isFolder {
XCTAssertNotNil(feedSpecifier!.title)
XCTAssertNotNil(feedSpecifier!.feedURL)
}
else {
XCTAssertNil(feedSpecifier)
if !(item is RSOPMLDocument) {
XCTAssertNotNil((item.attributes! as NSDictionary).opml_title)
2017-06-26 02:34:48 +02:00
}
}
if item.children != nil && item.children!.count > 0 {
for oneItem in item.children! {
2017-06-26 02:34:48 +02:00
recursivelyCheckOPMLStructure(oneItem)
}
}
}
2017-06-26 02:15:47 +02:00
}