Add OPMLTests to RSParser.

This commit is contained in:
Brent Simmons 2017-06-25 17:34:48 -07:00
parent c56f887ab4
commit 53574284dc
2 changed files with 47 additions and 3 deletions

View File

@ -14,7 +14,7 @@
@interface RSOPMLItem : NSObject @interface RSOPMLItem : NSObject
@property (nonatomic) NSDictionary *attributes; @property (nonatomic) NSDictionary *attributes;
@property (nonatomic) NSArray *children; @property (nonatomic) NSArray <RSOPMLItem *> *children;
- (void)addChild:(RSOPMLItem *)child; - (void)addChild:(RSOPMLItem *)child;

View File

@ -11,12 +11,56 @@ import RSParser
class OPMLTests: XCTestCase { class OPMLTests: XCTestCase {
let subsData = parserData("Subs", "opml", "http://example.org/")
func testOPMLParsingPerformance() { func testOPMLParsingPerformance() {
let d = parserData("Subs", "opml", "http://example.org/") // 0.002 sec on my 2012 iMac.
self.measure { self.measure {
let _ = try! RSOPMLParser.parseOPML(with: d) let _ = try! RSOPMLParser.parseOPML(with: self.subsData)
} }
} }
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.opmlFeedSpecifier
if !(item is RSOPMLDocument) {
XCTAssertNotNil((item.attributes as NSDictionary).opml_text)
}
// 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" {
isFolder = true
}
if !isFolder {
XCTAssertNotNil(feedSpecifier!.title)
XCTAssertNotNil(feedSpecifier!.feedURL)
}
else {
XCTAssertNil(feedSpecifier)
if !(item is RSOPMLDocument) {
XCTAssertNotNil((item.attributes as NSDictionary).opml_title)
}
}
if item.children != nil && item.children.count > 0 {
for oneItem in item.children {
recursivelyCheckOPMLStructure(oneItem)
}
}
}
} }