Add HTML tests to RSParser.

This commit is contained in:
Brent Simmons 2017-06-25 18:11:38 -07:00
parent a53a0c4697
commit 3bb9887513
4 changed files with 165 additions and 1 deletions

View File

@ -1,6 +1,6 @@
# RSParser
(Note: I havent written tests yet. Its possible that none of this works.)
(Note: Tests are still incomplete. Its possible that none of this works.)
(Also note: this framework is intended to supersede my [RSXML](https://github.com/brentsimmons/RSXML) framework. Use this one instead. Well, once its working, that is.)

View File

@ -69,6 +69,8 @@
849A03DE1F00837A00122600 /* FeedParserTypeTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 849A03DD1F00837A00122600 /* FeedParserTypeTests.swift */; };
849A03E01F0088F600122600 /* OPMLTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 849A03DF1F0088F600122600 /* OPMLTests.swift */; };
849A03E21F00902C00122600 /* RSDateParserTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 849A03E11F00902C00122600 /* RSDateParserTests.m */; };
849A03E41F00912100122600 /* HTMLMetadataTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 849A03E31F00912100122600 /* HTMLMetadataTests.swift */; };
849A03E61F00952400122600 /* HTMLLinkTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 849A03E51F00952400122600 /* HTMLLinkTests.swift */; };
84D81BDC1EFA28E700652332 /* RSParser.h in Headers */ = {isa = PBXBuildFile; fileRef = 84D81BDA1EFA28E700652332 /* RSParser.h */; settings = {ATTRIBUTES = (Public, ); }; };
84D81BDE1EFA2B7D00652332 /* ParsedFeed.swift in Sources */ = {isa = PBXBuildFile; fileRef = 84D81BDD1EFA2B7D00652332 /* ParsedFeed.swift */; };
84D81BE01EFA2BAE00652332 /* FeedType.swift in Sources */ = {isa = PBXBuildFile; fileRef = 84D81BDF1EFA2BAE00652332 /* FeedType.swift */; };
@ -153,6 +155,8 @@
849A03DD1F00837A00122600 /* FeedParserTypeTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = FeedParserTypeTests.swift; sourceTree = "<group>"; };
849A03DF1F0088F600122600 /* OPMLTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = OPMLTests.swift; sourceTree = "<group>"; };
849A03E11F00902C00122600 /* RSDateParserTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RSDateParserTests.m; sourceTree = "<group>"; };
849A03E31F00912100122600 /* HTMLMetadataTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = HTMLMetadataTests.swift; sourceTree = "<group>"; };
849A03E51F00952400122600 /* HTMLLinkTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = HTMLLinkTests.swift; sourceTree = "<group>"; };
84D81BD91EFA28E700652332 /* Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
84D81BDA1EFA28E700652332 /* RSParser.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RSParser.h; sourceTree = "<group>"; };
84D81BDD1EFA2B7D00652332 /* ParsedFeed.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = ParsedFeed.swift; path = Feeds/ParsedFeed.swift; sourceTree = "<group>"; };
@ -357,6 +361,8 @@
849A03DD1F00837A00122600 /* FeedParserTypeTests.swift */,
849A03DF1F0088F600122600 /* OPMLTests.swift */,
849A03E11F00902C00122600 /* RSDateParserTests.m */,
849A03E31F00912100122600 /* HTMLMetadataTests.swift */,
849A03E51F00952400122600 /* HTMLLinkTests.swift */,
849A03C41F0081EA00122600 /* Resources */,
84FF5F941EFA285800C15A01 /* Info.plist */,
);
@ -545,8 +551,10 @@
buildActionMask = 2147483647;
files = (
849A03E01F0088F600122600 /* OPMLTests.swift in Sources */,
849A03E61F00952400122600 /* HTMLLinkTests.swift in Sources */,
849A03E21F00902C00122600 /* RSDateParserTests.m in Sources */,
849A03DE1F00837A00122600 /* FeedParserTypeTests.swift in Sources */,
849A03E41F00912100122600 /* HTMLMetadataTests.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};

View File

@ -0,0 +1,42 @@
//
// HTMLLinkTests.swift
// RSParser
//
// Created by Brent Simmons on 6/25/17.
// Copyright © 2017 Ranchero Software, LLC. All rights reserved.
//
import XCTest
import RSParser
class HTMLLinkTests: XCTestCase {
func testSixColorsPerformance() {
// 0.003 sec on my 2012 iMac
let d = parserData("sixcolors", "html", "http://sixcolors.com/")
self.measure {
let _ = RSHTMLLinkParser.htmlLinks(with: d)
}
}
func testSixColorsLink() {
let d = parserData("sixcolors", "html", "http://sixcolors.com/")
let links = RSHTMLLinkParser.htmlLinks(with: d)!
let linkToFind = "https://www.theincomparable.com/theincomparable/290/index.php"
let textToFind = "this weeks episode of The Incomparable"
var found = false
for oneLink in links {
if let urlString = oneLink.urlString, let text = oneLink.text, urlString == linkToFind, text == textToFind {
found = true
}
}
XCTAssertTrue(found)
XCTAssertEqual(links.count, 131)
}
}

View File

@ -0,0 +1,114 @@
//
// HTMLMetadataTests.swift
// RSParser
//
// Created by Brent Simmons on 6/25/17.
// Copyright © 2017 Ranchero Software, LLC. All rights reserved.
//
import XCTest
import RSParser
class HTMLMetadataTests: XCTestCase {
func testDaringFireball() {
let d = parserData("DaringFireball", "html", "http://daringfireball.net/")
let metadata = RSHTMLMetadataParser.htmlMetadata(with: d)
XCTAssertEqual(metadata.faviconLink, "http://daringfireball.net/graphics/favicon.ico?v=005")
XCTAssertEqual(metadata.feedLinks.count, 1)
let feedLink = metadata.feedLinks.first!
XCTAssertNil(feedLink.title)
XCTAssertEqual(feedLink.type, "application/atom+xml")
XCTAssertEqual(feedLink.urlString, "http://daringfireball.net/feeds/main")
}
func testDaringFireballPerformance() {
// 0.002 sec on my 2012 iMac
let d = parserData("DaringFireball", "html", "http://daringfireball.net/")
self.measure {
let _ = RSHTMLMetadataParser.htmlMetadata(with: d)
}
}
func testFurbo() {
let d = parserData("furbo", "html", "http://furbo.org/")
let metadata = RSHTMLMetadataParser.htmlMetadata(with: d)
XCTAssertEqual(metadata.faviconLink, "http://furbo.org/favicon.ico")
XCTAssertEqual(metadata.feedLinks.count, 1)
let feedLink = metadata.feedLinks.first!
XCTAssertEqual(feedLink.title, "Iconfactory News Feed")
XCTAssertEqual(feedLink.type, "application/rss+xml")
}
func testFurboPerformance() {
// 0.001 sec on my 2012 iMac
let d = parserData("furbo", "html", "http://furbo.org/")
self.measure {
let _ = RSHTMLMetadataParser.htmlMetadata(with: d)
}
}
func testInessential() {
let d = parserData("inessential", "html", "http://inessential.com/")
let metadata = RSHTMLMetadataParser.htmlMetadata(with: d)
XCTAssertNil(metadata.faviconLink)
XCTAssertEqual(metadata.feedLinks.count, 1)
let feedLink = metadata.feedLinks.first!
XCTAssertEqual(feedLink.title, "RSS")
XCTAssertEqual(feedLink.type, "application/rss+xml")
XCTAssertEqual(feedLink.urlString, "http://inessential.com/xml/rss.xml")
XCTAssertEqual(metadata.appleTouchIcons.count, 0);
}
func testInessentialPerformance() {
// 0.001 sec on my 2012 iMac
let d = parserData("inessential", "html", "http://inessential.com/")
self.measure {
let _ = RSHTMLMetadataParser.htmlMetadata(with: d)
}
}
func testSixColors() {
let d = parserData("sixcolors", "html", "http://sixcolors.com/")
let metadata = RSHTMLMetadataParser.htmlMetadata(with: d)
XCTAssertEqual(metadata.faviconLink, "https://sixcolors.com/images/favicon.ico")
XCTAssertEqual(metadata.feedLinks.count, 1);
let feedLink = metadata.feedLinks.first!
XCTAssertEqual(feedLink.title, "RSS");
XCTAssertEqual(feedLink.type, "application/rss+xml");
XCTAssertEqual(feedLink.urlString, "http://feedpress.me/sixcolors");
XCTAssertEqual(metadata.appleTouchIcons.count, 6);
let icon = metadata.appleTouchIcons[3];
XCTAssertEqual(icon.rel, "apple-touch-icon");
XCTAssertEqual(icon.sizes, "120x120");
XCTAssertEqual(icon.urlString, "https://sixcolors.com/apple-touch-icon-120.png");
}
func testSixColorsPerformance() {
// 0.002 sec on my 2012 iMac
let d = parserData("sixcolors", "html", "http://sixcolors.com/")
self.measure {
let _ = RSHTMLMetadataParser.htmlMetadata(with: d)
}
}
}