2024-04-03 06:43:06 +02:00
//
// J S O N F e e d P a r s e r T e s t s . s w i f t
// R S P a r s e r
//
// C r e a t e d b y B r e n t S i m m o n s o n 6 / 2 6 / 1 7 .
// C o p y r i g h t © 2 0 1 7 R a n c h e r o S o f t w a r e , L L C . A l l r i g h t s r e s e r v e d .
//
import XCTest
import Parser
class JSONFeedParserTests : XCTestCase {
func testInessentialPerformance ( ) {
// 0 . 0 0 1 s e c o n m y 2 0 1 2 i M a c .
let d = parserData ( " inessential " , " json " , " http://inessential.com/ " )
self . measure {
2024-05-19 04:02:36 +02:00
let _ = try ! FeedParser . parseSync ( d )
2024-04-03 06:43:06 +02:00
}
}
func testDaringFireballPerformance ( ) {
// 0 . 0 0 9 s e c o n m y 2 0 1 2 i M a c .
let d = parserData ( " DaringFireball " , " json " , " http://daringfireball.net/ " )
self . measure {
2024-05-19 04:02:36 +02:00
let _ = try ! FeedParser . parseSync ( d )
2024-04-03 06:43:06 +02:00
}
}
2024-05-19 04:02:36 +02:00
func testGettingFaviconAndIconURLs ( ) async {
2024-04-03 06:43:06 +02:00
let d = parserData ( " DaringFireball " , " json " , " http://daringfireball.net/ " )
2024-05-19 04:02:36 +02:00
let parsedFeed = try ! await FeedParser . parse ( d ) !
2024-04-03 06:43:06 +02:00
XCTAssert ( parsedFeed . faviconURL = = " https://daringfireball.net/graphics/favicon-64.png " )
XCTAssert ( parsedFeed . iconURL = = " https://daringfireball.net/graphics/apple-touch-icon.png " )
}
2024-05-19 04:02:36 +02:00
func testAllThis ( ) async {
2024-04-03 06:43:06 +02:00
let d = parserData ( " allthis " , " json " , " http://leancrew.com/allthis/ " )
2024-05-19 04:02:36 +02:00
let parsedFeed = try ! await FeedParser . parse ( d ) !
2024-04-03 06:43:06 +02:00
XCTAssertEqual ( parsedFeed . items . count , 12 )
}
2024-05-19 04:02:36 +02:00
func testCurt ( ) async {
2024-04-03 06:43:06 +02:00
let d = parserData ( " curt " , " json " , " http://curtclifton.net/ " )
2024-05-19 04:02:36 +02:00
let parsedFeed = try ! await FeedParser . parse ( d ) !
2024-04-03 06:43:06 +02:00
XCTAssertEqual ( parsedFeed . items . count , 26 )
var didFindTwitterQuitterArticle = false
for article in parsedFeed . items {
if article . title = = " Twitter Quitter " {
didFindTwitterQuitterArticle = true
XCTAssertTrue ( article . contentHTML ! . hasPrefix ( " <p>I’ve decided to close my Twitter account. William Van Hecke <a href= \" https://tinyletter.com/fet/letters/microcosmographia-xlxi-reasons-to-stay-on-twitter \" >makes a convincing case</a> " ) )
}
}
XCTAssertTrue ( didFindTwitterQuitterArticle )
}
2024-05-19 04:02:36 +02:00
func testPixelEnvy ( ) async {
2024-04-03 06:43:06 +02:00
let d = parserData ( " pxlnv " , " json " , " http://pxlnv.com/ " )
2024-05-19 04:02:36 +02:00
let parsedFeed = try ! await FeedParser . parse ( d ) !
2024-04-03 06:43:06 +02:00
XCTAssertEqual ( parsedFeed . items . count , 20 )
}
2024-05-19 04:02:36 +02:00
func testRose ( ) async {
2024-04-03 06:43:06 +02:00
let d = parserData ( " rose " , " json " , " http://www.rosemaryorchard.com/ " )
2024-05-19 04:02:36 +02:00
let parsedFeed = try ! await FeedParser . parse ( d ) !
2024-04-03 06:43:06 +02:00
XCTAssertEqual ( parsedFeed . items . count , 84 )
}
2024-05-19 04:02:36 +02:00
func test3960 ( ) async {
2024-04-03 06:43:06 +02:00
let d = parserData ( " 3960 " , " json " , " http://journal.3960.org/ " )
2024-05-19 04:02:36 +02:00
let parsedFeed = try ! await FeedParser . parse ( d ) !
2024-04-03 06:43:06 +02:00
XCTAssertEqual ( parsedFeed . items . count , 20 )
XCTAssertEqual ( parsedFeed . language , " de-DE " )
for item in parsedFeed . items {
XCTAssertEqual ( item . language , " de-DE " )
}
}
2024-05-19 04:02:36 +02:00
func testAuthors ( ) async {
2024-04-03 06:43:06 +02:00
let d = parserData ( " authors " , " json " , " https://example.com/ " )
2024-05-19 04:02:36 +02:00
let parsedFeed = try ! await FeedParser . parse ( d ) !
2024-04-03 06:43:06 +02:00
XCTAssertEqual ( parsedFeed . items . count , 4 )
let rootAuthors = Set ( [
ParsedAuthor ( name : " Root Author 1 " , url : nil , avatarURL : nil , emailAddress : nil ) ,
ParsedAuthor ( name : " Root Author 2 " , url : nil , avatarURL : nil , emailAddress : nil )
] )
let itemAuthors = Set ( [
ParsedAuthor ( name : " Item Author 1 " , url : nil , avatarURL : nil , emailAddress : nil ) ,
ParsedAuthor ( name : " Item Author 2 " , url : nil , avatarURL : nil , emailAddress : nil )
] )
let legacyItemAuthors = Set ( [
ParsedAuthor ( name : " Legacy Item Author " , url : nil , avatarURL : nil , emailAddress : nil )
] )
XCTAssertEqual ( parsedFeed . authors ? . count , 2 )
XCTAssertEqual ( parsedFeed . authors , rootAuthors )
let noAuthorsItem = parsedFeed . items . first { $0 . uniqueID = = " Item without authors " } !
XCTAssertEqual ( noAuthorsItem . authors , nil )
let legacyAuthorItem = parsedFeed . items . first { $0 . uniqueID = = " Item with legacy author " } !
XCTAssertEqual ( legacyAuthorItem . authors , legacyItemAuthors )
let modernAuthorsItem = parsedFeed . items . first { $0 . uniqueID = = " Item with modern authors " } !
XCTAssertEqual ( modernAuthorsItem . authors , itemAuthors )
let bothAuthorsItem = parsedFeed . items . first { $0 . uniqueID = = " Item with both " } !
XCTAssertEqual ( bothAuthorsItem . authors , itemAuthors )
}
}