Fix lint issues.

This commit is contained in:
Brent Simmons
2025-01-22 22:13:20 -08:00
parent d210692d7d
commit 72a5e46dcc
115 changed files with 584 additions and 711 deletions

View File

@@ -8,7 +8,7 @@ let package = Package(
products: [
.library(
name: "Parser",
targets: ["Parser"]),
targets: ["Parser"])
],
dependencies: [
.package(path: "../RSCore")
@@ -26,6 +26,6 @@ let package = Package(
"Parser"
],
resources: [.copy("Resources")]
),
)
]
)

View File

@@ -36,7 +36,7 @@ public enum FeedType: Sendable {
return .unknown
}
let cCharPointer = baseAddress.assumingMemoryBound(to: CChar.self)
if isProbablyJSON(cCharPointer, count) {
if isPartialData {

View File

@@ -160,7 +160,7 @@ private extension JSONFeedParser {
let dateModified = parseDate(itemDictionary[Key.dateModified] as? String)
let authors = parseAuthors(itemDictionary)
var tags: Set<String>? = nil
var tags: Set<String>?
if let tagsArray = itemDictionary[Key.tags] as? [String] {
tags = Set(tagsArray)
}

View File

@@ -53,8 +53,7 @@ public struct RSSInJSONParser {
return ParsedFeed(type: .rssInJSON, title: title, homePageURL: homePageURL, feedURL: feedURL, language: feedLanguage, feedDescription: feedDescription, nextURL: nil, iconURL: nil, faviconURL: nil, authors: nil, expired: false, hubs: nil, items: items)
}
catch { throw error }
} catch { throw error }
}
}
@@ -62,7 +61,7 @@ private extension RSSInJSONParser {
static func parseItems(_ itemsObject: JSONArray, _ feedURL: String) -> Set<ParsedItem> {
return Set(itemsObject.compactMap{ (oneItemDictionary) -> ParsedItem? in
return Set(itemsObject.compactMap { (oneItemDictionary) -> ParsedItem? in
return parsedItemWithDictionary(oneItemDictionary, feedURL)
})
@@ -74,7 +73,7 @@ private extension RSSInJSONParser {
let title = itemDictionary["title"] as? String
var contentHTML = itemDictionary["description"] as? String
var contentText: String? = nil
var contentText: String?
if contentHTML != nil && !(contentHTML!.contains("<")) {
contentText = contentHTML
contentHTML = nil
@@ -83,7 +82,7 @@ private extension RSSInJSONParser {
return nil
}
var datePublished: Date? = nil
var datePublished: Date?
if let datePublishedString = itemDictionary["pubDate"] as? String {
datePublished = DateParser.date(string: datePublishedString)
}
@@ -150,9 +149,8 @@ private extension RSSInJSONParser {
return Set([oneTag])
}
return nil
}
else if let categoryArray = itemDictionary["category"] as? JSONArray {
return Set(categoryArray.compactMap{ $0["#value"] as? String })
} else if let categoryArray = itemDictionary["category"] as? JSONArray {
return Set(categoryArray.compactMap { $0["#value"] as? String })
}
return nil
}

View File

@@ -20,7 +20,7 @@ public final class ParsedAttachment: Hashable, Sendable {
if url.isEmpty {
return nil
}
self.url = url
self.mimeType = mimeType
self.title = title

View File

@@ -14,7 +14,7 @@ public final class ParsedAuthor: Hashable, Codable, Sendable {
public let url: String?
public let avatarURL: String?
public let emailAddress: String?
public init(name: String?, url: String?, avatarURL: String?, emailAddress: String?) {
self.name = name
self.url = url
@@ -39,17 +39,13 @@ public final class ParsedAuthor: Hashable, Codable, Sendable {
public func hash(into hasher: inout Hasher) {
if let name {
hasher.combine(name)
}
else if let url {
} else if let url {
hasher.combine(url)
}
else if let emailAddress {
} else if let emailAddress {
hasher.combine(emailAddress)
}
else if let avatarURL{
} else if let avatarURL {
hasher.combine(avatarURL)
}
else {
} else {
hasher.combine("")
}
}

View File

@@ -17,7 +17,7 @@ public final class ParsedHub: Hashable, Sendable {
self.type = type
self.url = url
}
// MARK: - Hashable
public func hash(into hasher: inout Hasher) {

View File

@@ -10,8 +10,8 @@ import Foundation
public final class ParsedItem: Hashable, Sendable {
public let syncServiceID: String? //Nil when not syncing
public let uniqueID: String //RSS guid, for instance; may be calculated
public let syncServiceID: String? // Nil when not syncing
public let uniqueID: String // RSS guid, for instance; may be calculated
public let feedURL: String
public let url: String?
public let externalURL: String?
@@ -27,12 +27,12 @@ public final class ParsedItem: Hashable, Sendable {
public let authors: Set<ParsedAuthor>?
public let tags: Set<String>?
public let attachments: Set<ParsedAttachment>?
public init(syncServiceID: String?, uniqueID: String, feedURL: String, url: String?, externalURL: String?, title: String?,
language: String?, contentHTML: String?, contentText: String?, summary: String?, imageURL: String?,
bannerImageURL: String?,datePublished: Date?, dateModified: Date?, authors: Set<ParsedAuthor>?,
bannerImageURL: String?, datePublished: Date?, dateModified: Date?, authors: Set<ParsedAuthor>?,
tags: Set<String>?, attachments: Set<ParsedAttachment>?) {
self.syncServiceID = syncServiceID
self.uniqueID = uniqueID
self.feedURL = feedURL
@@ -57,8 +57,7 @@ public final class ParsedItem: Hashable, Sendable {
public func hash(into hasher: inout Hasher) {
if let syncServiceID = syncServiceID {
hasher.combine(syncServiceID)
}
else {
} else {
hasher.combine(uniqueID)
hasher.combine(feedURL)
}
@@ -69,4 +68,3 @@ public final class ParsedItem: Hashable, Sendable {
lhs.syncServiceID == rhs.syncServiceID && lhs.uniqueID == rhs.uniqueID && lhs.feedURL == rhs.feedURL && lhs.url == rhs.url && lhs.externalURL == rhs.externalURL && lhs.title == rhs.title && lhs.language == rhs.language && lhs.contentHTML == rhs.contentHTML && lhs.contentText == rhs.contentText && lhs.summary == rhs.summary && lhs.imageURL == rhs.imageURL && lhs.bannerImageURL == rhs.bannerImageURL && lhs.datePublished == rhs.datePublished && lhs.dateModified == rhs.dateModified && lhs.authors == rhs.authors && lhs.tags == rhs.tags && lhs.attachments == rhs.attachments
}
}

View File

@@ -181,29 +181,17 @@ private extension AtomParser {
if SAXEqualTags(localName, XMLName.id) {
currentArticle.guid = currentString(saxParser)
}
else if SAXEqualTags(localName, XMLName.title) {
} else if SAXEqualTags(localName, XMLName.title) {
currentArticle.title = currentString(saxParser)
}
else if SAXEqualTags(localName, XMLName.content) {
} else if SAXEqualTags(localName, XMLName.content) {
addContent(saxParser, currentArticle)
}
else if SAXEqualTags(localName, XMLName.summary) {
} else if SAXEqualTags(localName, XMLName.summary) {
addSummary(saxParser, currentArticle)
}
else if SAXEqualTags(localName, XMLName.link) {
} else if SAXEqualTags(localName, XMLName.link) {
addLink(currentArticle)
}
else if SAXEqualTags(localName, XMLName.published) {
} else if SAXEqualTags(localName, XMLName.published) {
currentArticle.datePublished = currentDate(saxParser)
}
else if SAXEqualTags(localName, XMLName.updated) {
} else if SAXEqualTags(localName, XMLName.updated) {
currentArticle.dateModified = currentDate(saxParser)
}
@@ -212,8 +200,7 @@ private extension AtomParser {
if currentArticle.datePublished == nil {
currentArticle.datePublished = currentDate(saxParser)
}
}
else if SAXEqualTags(localName, XMLName.modified) {
} else if SAXEqualTags(localName, XMLName.modified) {
if currentArticle.dateModified == nil {
currentArticle.dateModified = currentDate(saxParser)
}
@@ -258,13 +245,11 @@ private extension AtomParser {
if article.link == nil {
article.link = resolvedURLString
}
}
else if rel == AttributeValue.alternate {
} else if rel == AttributeValue.alternate {
if article.permalink == nil {
article.permalink = resolvedURLString
}
}
else if rel == AttributeValue.enclosure {
} else if rel == AttributeValue.enclosure {
if let enclosure = enclosure(resolvedURLString, attributes) {
article.addEnclosure(enclosure)
}
@@ -372,7 +357,7 @@ extension AtomParser: SAXParserDelegate {
currentArticle?.language = xmlAttributes["xml:lang"]
}
let contentType = xmlAttributes["type"];
let contentType = xmlAttributes["type"]
if contentType == "xhtml" {
parsingXHTML = true
xhtmlString = ""
@@ -416,9 +401,7 @@ extension AtomParser: SAXParserDelegate {
if isContentTag {
currentArticle?.body = xhtmlString
}
else if isSummaryTag {
} else if isSummaryTag {
if (currentArticle?.body?.count ?? 0) < 1 {
currentArticle?.body = xhtmlString
}
@@ -438,9 +421,7 @@ extension AtomParser: SAXParserDelegate {
} else {
assertionFailure("xhtmlString must not be nil when parsingXHTML in xmlEndElement.")
}
}
else if parsingAuthor {
} else if parsingAuthor {
if SAXEqualTags(localName, XMLName.author) {
parsingAuthor = false
@@ -448,32 +429,21 @@ extension AtomParser: SAXParserDelegate {
currentArticle?.addAuthor(currentAuthor)
}
currentAuthor = nil
}
else if SAXEqualTags(localName, XMLName.name) {
} else if SAXEqualTags(localName, XMLName.name) {
currentAuthor?.name = saxParser.currentStringWithTrimmedWhitespace
}
else if SAXEqualTags(localName, XMLName.email) {
} else if SAXEqualTags(localName, XMLName.email) {
currentAuthor?.emailAddress = saxParser.currentStringWithTrimmedWhitespace
}
else if SAXEqualTags(localName, XMLName.uri) {
} else if SAXEqualTags(localName, XMLName.uri) {
currentAuthor?.url = saxParser.currentStringWithTrimmedWhitespace
}
}
else if SAXEqualTags(localName, XMLName.entry) {
} else if SAXEqualTags(localName, XMLName.entry) {
parsingArticle = false
entryDepth = -1
}
else if parsingArticle && !parsingSource && depth == entryDepth + 1 {
} else if parsingArticle && !parsingSource && depth == entryDepth + 1 {
addArticleElement(saxParser, localName, prefix)
}
else if SAXEqualTags(localName, XMLName.source) {
} else if SAXEqualTags(localName, XMLName.source) {
parsingSource = false
}
else if !parsingArticle && !parsingSource && SAXEqualTags(localName, XMLName.title) {
} else if !parsingArticle && !parsingSource && SAXEqualTags(localName, XMLName.title) {
addFeedTitle(saxParser)
}

View File

@@ -6,7 +6,7 @@
//
import Foundation
//import FoundationExtras
// import FoundationExtras
final class RSSArticle {
@@ -81,28 +81,21 @@ private extension RSSArticle {
if let permalink, !permalink.isEmpty, let datePublishedTimeStampString {
s.append(permalink)
s.append(datePublishedTimeStampString)
}
else if let link, !link.isEmpty, let datePublishedTimeStampString {
} else if let link, !link.isEmpty, let datePublishedTimeStampString {
s.append(link)
s.append(datePublishedTimeStampString)
}
else if let title, !title.isEmpty, let datePublishedTimeStampString {
} else if let title, !title.isEmpty, let datePublishedTimeStampString {
s.append(title)
s.append(datePublishedTimeStampString)
}
else if let datePublishedTimeStampString {
} else if let datePublishedTimeStampString {
s.append(datePublishedTimeStampString)
}
else if let permalink, !permalink.isEmpty {
} else if let permalink, !permalink.isEmpty {
s.append(permalink)
}
else if let link, !link.isEmpty {
} else if let link, !link.isEmpty {
s.append(link)
}
else if let title, !title.isEmpty {
} else if let title, !title.isEmpty {
s.append(title)
}
else if let body, !body.isEmpty {
} else if let body, !body.isEmpty {
s.append(body)
}

View File

@@ -20,7 +20,7 @@ final class RSSAuthor {
self.avatarURL = avatarURL
self.emailAddress = emailAddress
}
/// Use when the actual property is unknown. Guess based on contents of the string. (This is common with RSS.)
convenience init(singleString: String) {

View File

@@ -79,11 +79,9 @@ private extension RSSParser {
if feed.link == nil {
feed.link = saxParser.currentString
}
}
else if SAXEqualTags(localName, XMLName.title) {
} else if SAXEqualTags(localName, XMLName.title) {
feed.title = saxParser.currentString
}
else if SAXEqualTags(localName, XMLName.language) {
} else if SAXEqualTags(localName, XMLName.language) {
feed.language = saxParser.currentString
}
}
@@ -118,26 +116,20 @@ private extension RSSParser {
if let currentString = saxParser.currentString {
if SAXEqualTags(localName, XMLName.guid) {
addGuid(currentString, currentArticle)
}
else if SAXEqualTags(localName, XMLName.author) {
} else if SAXEqualTags(localName, XMLName.author) {
addAuthorWithString(currentString, currentArticle)
}
else if SAXEqualTags(localName, XMLName.link) {
} else if SAXEqualTags(localName, XMLName.link) {
currentArticle.link = urlString(currentString)
}
else if SAXEqualTags(localName, XMLName.description) {
} else if SAXEqualTags(localName, XMLName.description) {
if currentArticle.body == nil {
currentArticle.body = currentString
}
}
else if !parsingAuthor && SAXEqualTags(localName, XMLName.title) {
} else if !parsingAuthor && SAXEqualTags(localName, XMLName.title) {
currentArticle.title = currentString
}
else if SAXEqualTags(localName, XMLName.pubDate) {
} else if SAXEqualTags(localName, XMLName.pubDate) {
currentArticle.datePublished = currentDate(saxParser)
}
}
else if SAXEqualTags(localName, XMLName.enclosure), let currentAttributes {
} else if SAXEqualTags(localName, XMLName.enclosure), let currentAttributes {
addEnclosure(currentAttributes, currentArticle)
}
}
@@ -148,8 +140,7 @@ private extension RSSParser {
if let currentString = saxParser.currentString {
addAuthorWithString(currentString, currentArticle)
}
}
else if SAXEqualTags(localName, XMLName.date) {
} else if SAXEqualTags(localName, XMLName.date) {
currentArticle.datePublished = currentDate(saxParser)
}
}
@@ -298,7 +289,7 @@ extension RSSParser: SAXParserDelegate {
return
}
var xmlAttributes: StringDictionary? = nil
var xmlAttributes: StringDictionary?
if (isRDF && SAXEqualTags(localName, XMLName.item)) || SAXEqualTags(localName, XMLName.guid) || SAXEqualTags(localName, XMLName.enclosure) {
xmlAttributes = saxParser.attributesDictionary(attributes, attributeCount: attributeCount)
}
@@ -314,11 +305,9 @@ extension RSSParser: SAXParserDelegate {
currentArticle.guid = rdfGuid
currentArticle.permalink = rdfGuid
}
}
else if prefix == nil && SAXEqualTags(localName, XMLName.image) {
} else if prefix == nil && SAXEqualTags(localName, XMLName.image) {
parsingChannelImage = true
}
else if prefix == nil && SAXEqualTags(localName, XMLName.author) {
} else if prefix == nil && SAXEqualTags(localName, XMLName.author) {
if parsingArticle {
parsingAuthor = true
}
@@ -337,23 +326,18 @@ extension RSSParser: SAXParserDelegate {
if isRDF && SAXEqualTags(localName, XMLName.uppercaseRDF) {
endRSSFound = true
}
else if SAXEqualTags(localName, XMLName.rss) {
} else if SAXEqualTags(localName, XMLName.rss) {
endRSSFound = true
}
else if SAXEqualTags(localName, XMLName.image) {
} else if SAXEqualTags(localName, XMLName.image) {
parsingChannelImage = false
}
else if SAXEqualTags(localName, XMLName.item) {
} else if SAXEqualTags(localName, XMLName.item) {
parsingArticle = false
}
else if parsingArticle {
} else if parsingArticle {
addArticleElement(saxParser, localName, prefix)
if SAXEqualTags(localName, XMLName.author) {
parsingAuthor = false
}
}
else if !parsingChannelImage {
} else if !parsingChannelImage {
addFeedElement(saxParser, localName, prefix)
}
}
@@ -363,4 +347,3 @@ extension RSSParser: SAXParserDelegate {
// Required method.
}
}

View File

@@ -70,7 +70,7 @@ private func decodedEntities(_ sourceBuffer: UnsafeBufferPointer<UInt8>, _ didDe
resultBuffer.initializeMemory(as: UInt8.self, repeating: 0, count: resultBufferByteCount)
let result = resultBuffer.assumingMemoryBound(to: UInt8.self)
var sourceLocation = 0
var resultLocation = 0
@@ -78,7 +78,7 @@ private func decodedEntities(_ sourceBuffer: UnsafeBufferPointer<UInt8>, _ didDe
let ch = sourceBuffer[sourceLocation]
var decodedEntity: String? = nil
var decodedEntity: String?
if ch == ampersandCharacter {
decodedEntity = decodedEntityValue(sourceBuffer, byteCount, &sourceLocation)
@@ -112,7 +112,7 @@ private func addDecodedEntity(_ decodedEntity: String, _ result: UnsafeMutablePo
}
}
private func decodedEntityValue(_ buffer: UnsafeBufferPointer<UInt8>, _ byteCount: Int, _ sourceLocation: inout Int) -> /*[UInt8]?*/ String? {
private func decodedEntityValue(_ buffer: UnsafeBufferPointer<UInt8>, _ byteCount: Int, _ sourceLocation: inout Int) -> String? {
guard let rawEntity = rawEntityValue(buffer, byteCount, &sourceLocation) else {
return nil
@@ -153,8 +153,7 @@ private func decodedNumericEntity(_ rawEntity: ContiguousArray<UInt8>) -> String
if rawEntity[1] == xCharacter || rawEntity[1] == XCharacter { // Hex?
decodedNumber = decodedHexEntity(rawEntity)
}
else {
} else {
decodedNumber = decodedDecimalEntity(rawEntity)
}
@@ -247,7 +246,7 @@ private func decodedDecimalEntity(_ rawEntity: ContiguousArray<UInt8>) -> UInt32
if number == 0 {
return nil
}
return number
}
@@ -271,7 +270,7 @@ private func rawEntityValue(_ buffer: UnsafeBufferPointer<UInt8>, _ byteCount: I
while true {
sourceLocation += 1
if sourceLocation >= byteCount || entityCharactersIndex >= maxEntityCharacters { // did not parse entity
if sourceLocation >= byteCount || entityCharactersIndex >= maxEntityCharacters { // did not parse entity
sourceLocation = savedSourceLocation
return nil
}

View File

@@ -28,8 +28,7 @@ public final class HTMLMetadata: Sendable {
self.appleTouchIcons = appleTouchIconTags.map { htmlTag in
HTMLMetadataAppleTouchIcon(urlString, htmlTag)
}
}
else {
} else {
self.appleTouchIcons = nil
}
@@ -37,8 +36,7 @@ public final class HTMLMetadata: Sendable {
self.feedLinks = feedLinkTags.map { htmlTag in
HTMLMetadataFeedLink(urlString, htmlTag)
}
}
else {
} else {
self.feedLinks = nil
}
@@ -89,7 +87,7 @@ public final class HTMLMetadata: Sendable {
}
let feedLinkTags = alternateLinkTags.filter { tag in
guard let attributes = tag.attributes, let type = attributes.object(forCaseInsensitiveKey: "type"), typeIsFeedType(type) else {
return false
}
@@ -206,8 +204,7 @@ public final class HTMLMetadataAppleTouchIcon: Sendable {
let sizeComponents = sizes.components(separatedBy: CharacterSet(charactersIn: "x"))
if sizeComponents.count == 2, let width = Double(sizeComponents[0]), let height = Double(sizeComponents[1]) {
self.size = CGSize(width: width, height: height)
}
else {
} else {
self.size = nil
}
}
@@ -313,25 +310,19 @@ private extension HTMLOpenGraphProperties {
if propertyName == OGValue.ogImage {
url = content
}
else if propertyName == OGValue.ogImageURL {
} else if propertyName == OGValue.ogImageURL {
url = content
}
else if propertyName == OGValue.ogImageSecureURL {
} else if propertyName == OGValue.ogImageSecureURL {
secureURL = content
}
else if propertyName == OGValue.ogImageType {
} else if propertyName == OGValue.ogImageType {
mimeType = content
}
else if propertyName == OGValue.ogImageAlt {
} else if propertyName == OGValue.ogImageAlt {
altText = content
}
else if propertyName == OGValue.ogImageWidth {
} else if propertyName == OGValue.ogImageWidth {
if let value = Double(content) {
width = CGFloat(value)
}
}
else if propertyName == OGValue.ogImageHeight {
} else if propertyName == OGValue.ogImageHeight {
if let value = Double(content) {
height = CGFloat(value)
}
@@ -341,14 +332,14 @@ private extension HTMLOpenGraphProperties {
if url == nil && secureURL == nil && mimeType == nil && width == nil && height == nil && altText == nil {
return nil
}
return HTMLOpenGraphImage(url: url, secureURL: secureURL, mimeType: mimeType, width: width, height: height, altText: altText)
}
}
public final class HTMLOpenGraphImage: Sendable {
public let url : String?
public let url: String?
public let secureURL: String?
public let mimeType: String?
public let width: CGFloat?
@@ -434,4 +425,3 @@ private func absoluteURLStringWithRelativeURLString(_ relativeURLString: String,
}
return absoluteURL.absoluteURL.standardized.absoluteString
}

View File

@@ -34,13 +34,13 @@ private extension HTMLMetadataParser {
extension HTMLMetadataParser: SAXHTMLParserDelegate {
private struct HTMLName {
static let link = "link".utf8CString
static let meta = "meta".utf8CString
}
private struct HTMLKey {
static let href = "href"
static let src = "src"
static let rel = "rel"
@@ -81,8 +81,7 @@ extension HTMLMetadataParser: SAXHTMLParserDelegate {
if let d, !d.isEmpty {
handleLinkAttributes(d)
}
}
else if SAXEqualTags(name, HTMLName.meta) {
} else if SAXEqualTags(name, HTMLName.meta) {
let d = saxHTMLParser.attributesDictionary(attributes)
if let d, !d.isEmpty {
handleMetaAttributes(d)

View File

@@ -9,8 +9,8 @@ import Foundation
public final class OPMLDocument: OPMLItem {
public var title: String? = nil
public var url: String? = nil
public var title: String?
public var url: String?
init(url: String?) {
self.url = url

View File

@@ -37,4 +37,3 @@ public struct OPMLFeedSpecifier: Sendable {
self.feedURL = feedURL
}
}

View File

@@ -20,7 +20,7 @@ public class OPMLItem {
(items?.count ?? 0) > 0
}
init(attributes: [String : String]?) {
init(attributes: [String: String]?) {
self.titleFromAttributes = attributes?.opml_title ?? attributes?.opml_text
self.attributes = attributes
@@ -33,7 +33,7 @@ public class OPMLItem {
}
public func add(_ item: OPMLItem) {
if items == nil {
items = [OPMLItem]()
}

View File

@@ -50,7 +50,7 @@ private extension OPMLParser {
}
func canParseData() -> Bool {
data.containsASCIIString("<opml")
}

View File

@@ -14,7 +14,7 @@ public extension Dictionary where Key == String, Value == String {
if let object = self[key] {
return object
}
let lowercaseKey = key.lowercased()
for (oneKey, oneValue) in self {

View File

@@ -103,7 +103,7 @@ public final class SAXHTMLParser {
var dictionary = [String: String]()
var ix = 0
var currentKey: String? = nil
var currentKey: String?
while true {
let oneAttribute = attributes[ix]

View File

@@ -61,7 +61,7 @@ public final class SAXParser {
}
public func parse() {
guard !data.isEmpty else {
return
}
@@ -99,7 +99,7 @@ public final class SAXParser {
}
var dictionary = [String: String]()
let fieldCount = 5
var i = 0, j = 0
while i < attributeCount {
@@ -201,4 +201,3 @@ nonisolated(unsafe) private var saxHandlerStruct: xmlSAXHandler = {
return handler
}()

View File

@@ -10,8 +10,8 @@ import libxml2
public func SAXEqualTags(_ localName: XMLPointer, _ tag: ContiguousArray<Int8>) -> Bool {
return tag.withUnsafeBufferPointer { bufferPointer in
return tag.withUnsafeBufferPointer { _ in
let tagCount = tag.count // includes 0 terminator
for i in 0..<tagCount - 1 {

View File

@@ -14,15 +14,15 @@ final class AtomParserTests: XCTestCase {
func testDaringFireballPerformance() {
// 0.009 sec on my 2012 iMac.
let d = parserData("DaringFireball", "atom", "http://daringfireball.net/") //Its actually an Atom feed
let d = parserData("DaringFireball", "atom", "http://daringfireball.net/") // Its actually an Atom feed
self.measure {
let _ = try! FeedParser.parse(d)
_ = try! FeedParser.parse(d)
}
}
func testDaringFireball() {
let d = parserData("DaringFireball", "atom", "http://daringfireball.net/") //Its actually an Atom feed
let d = parserData("DaringFireball", "atom", "http://daringfireball.net/") // Its actually an Atom feed
let parsedFeed = try! FeedParser.parse(d)!
for article in parsedFeed.items {
@@ -35,8 +35,7 @@ final class AtomParserTests: XCTestCase {
let author = article.authors!.first!
if author.name == "Daring Fireball Department of Commerce" {
XCTAssertNil(author.url)
}
else {
} else {
XCTAssertEqual(author.name, "John Gruber")
XCTAssertEqual(author.url, "http://daringfireball.net/")
}
@@ -78,7 +77,7 @@ final class AtomParserTests: XCTestCase {
guard let attachments = article.attachments else {
continue
}
XCTAssertEqual(attachments.count, 1)
let attachment = attachments.first!

View File

@@ -13,7 +13,7 @@ final class DateParserTests: XCTestCase {
func testDateWithString() {
var expectedDateResult = dateWithValues(2010, 5, 28, 21, 3, 38)
var d = date("Fri, 28 May 2010 21:03:38 +0000")
XCTAssertEqual(d, expectedDateResult)
@@ -78,7 +78,7 @@ final class DateParserTests: XCTestCase {
let d = date("2010-11-17 08:40:07-05:00")
XCTAssertEqual(d, expectedDateResult)
}
func testFeedbinDate() {
let expectedDateResult = dateWithValues(2019, 9, 27, 21, 01, 48)
let d = date("2019-09-27T21:01:48.000000Z")
@@ -106,7 +106,7 @@ final class DateParserTests: XCTestCase {
}
func testPubDateParsingPerformance() {
// 0.0001 seconds on my Mac Studio M1
self.measure {
_ = date("21 May 2010 21:22:53 GMT")

View File

@@ -26,7 +26,7 @@ final class FeedParserTypeTests: XCTestCase {
let type = FeedType.feedType(d.data)
XCTAssertTrue(type == .notAFeed)
}
func testInessentialHTMLType() {
let d = parserData("inessential", "html", "http://inessential.com/")
@@ -40,7 +40,7 @@ final class FeedParserTypeTests: XCTestCase {
let type = FeedType.feedType(d.data)
XCTAssertTrue(type == .notAFeed)
}
// MARK: RSS
func testEMarleyRSSType() {
@@ -56,7 +56,7 @@ final class FeedParserTypeTests: XCTestCase {
let type = FeedType.feedType(d.data)
XCTAssertTrue(type == .rss)
}
func testKatieFloydRSSType() {
let d = parserData("KatieFloyd", "rss", "https://katiefloyd.com/")
@@ -186,21 +186,21 @@ final class FeedParserTypeTests: XCTestCase {
// In the case of this feed, the partial data isnt enough to detect that its a JSON Feed.
// The type detector should return .unknown rather than .notAFeed.
let d = parserData("allthis-partial", "json", "http://leancrew.com/allthis/")
let type = FeedType.feedType(d.data, isPartialData: true)
XCTAssertEqual(type, .unknown)
}
// MARK: Performance
func testFeedTypePerformance() {
// 0.000 on my 2012 iMac.
let d = parserData("EMarley", "rss", "https://medium.com/@emarley")
self.measure {
let _ = FeedType.feedType(d.data)
_ = FeedType.feedType(d.data)
}
}
@@ -210,7 +210,7 @@ final class FeedParserTypeTests: XCTestCase {
let d = parserData("inessential", "json", "http://inessential.com/")
self.measure {
let _ = FeedType.feedType(d.data)
_ = FeedType.feedType(d.data)
}
}
@@ -220,7 +220,7 @@ final class FeedParserTypeTests: XCTestCase {
let d = parserData("DaringFireball", "html", "http://daringfireball.net/")
self.measure {
let _ = FeedType.feedType(d.data)
_ = FeedType.feedType(d.data)
}
}
@@ -230,7 +230,7 @@ final class FeedParserTypeTests: XCTestCase {
let d = parserData("DaringFireball", "rss", "http://daringfireball.net/")
self.measure {
let _ = FeedType.feedType(d.data)
_ = FeedType.feedType(d.data)
}
}
}

View File

@@ -16,7 +16,7 @@ final class HTMLLinkTests: XCTestCase {
// 0.003 sec on my 2012 iMac
let d = parserData("sixcolors", "html", "http://sixcolors.com/")
self.measure {
let _ = HTMLLinkParser.htmlLinks(with: d)
_ = HTMLLinkParser.htmlLinks(with: d)
}
}

View File

@@ -31,7 +31,7 @@ final class HTMLMetadataTests: XCTestCase {
// 0.002 sec on my 2012 iMac
let d = parserData("DaringFireball", "html", "http://daringfireball.net/")
self.measure {
let _ = HTMLMetadataParser.metadata(with: d)
_ = HTMLMetadataParser.metadata(with: d)
}
}
@@ -54,7 +54,7 @@ final class HTMLMetadataTests: XCTestCase {
// 0.001 sec on my 2012 iMac
let d = parserData("furbo", "html", "http://furbo.org/")
self.measure {
let _ = HTMLMetadataParser.metadata(with: d)
_ = HTMLMetadataParser.metadata(with: d)
}
}
@@ -71,7 +71,7 @@ final class HTMLMetadataTests: XCTestCase {
XCTAssertEqual(feedLink.type, "application/rss+xml")
XCTAssertEqual(feedLink.urlString, "http://inessential.com/xml/rss.xml")
XCTAssertEqual(metadata.appleTouchIcons?.count ?? 0, 0);
XCTAssertEqual(metadata.appleTouchIcons?.count ?? 0, 0)
}
func testInessentialPerformance() {
@@ -79,7 +79,7 @@ final class HTMLMetadataTests: XCTestCase {
// 0.001 sec on my 2012 iMac
let d = parserData("inessential", "html", "http://inessential.com/")
self.measure {
let _ = HTMLMetadataParser.metadata(with: d)
_ = HTMLMetadataParser.metadata(with: d)
}
}
@@ -88,7 +88,7 @@ final class HTMLMetadataTests: XCTestCase {
// 0.004 sec on my 2012 iMac
let d = parserData("coco", "html", "https://www.theatlantic.com/entertainment/archive/2017/11/coco-is-among-pixars-best-movies-in-years/546695/")
self.measure {
let _ = HTMLMetadataParser.metadata(with: d)
_ = HTMLMetadataParser.metadata(with: d)
}
}
@@ -99,17 +99,17 @@ final class HTMLMetadataTests: XCTestCase {
XCTAssertEqual(metadata.favicons?.first?.urlString, "https://sixcolors.com/images/favicon.ico")
XCTAssertEqual(metadata.feedLinks?.count, 1);
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(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");
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() {
@@ -117,7 +117,7 @@ final class HTMLMetadataTests: XCTestCase {
// 0.002 sec on my 2012 iMac
let d = parserData("sixcolors", "html", "http://sixcolors.com/")
self.measure {
let _ = HTMLMetadataParser.metadata(with: d)
_ = HTMLMetadataParser.metadata(with: d)
}
}
@@ -144,10 +144,10 @@ final class HTMLMetadataTests: XCTestCase {
let d = parserData("YouTubeTheVolvoRocks", "html", "https://www.youtube.com/user/TheVolvorocks")
let metadata = HTMLMetadataParser.metadata(with: d)
XCTAssertEqual(metadata.feedLinks!.count, 1);
XCTAssertEqual(metadata.feedLinks!.count, 1)
let feedLink = metadata.feedLinks!.first!
XCTAssertEqual(feedLink.title, "RSS");
XCTAssertEqual(feedLink.type, "application/rss+xml");
XCTAssertEqual(feedLink.urlString, "https://www.youtube.com/feeds/videos.xml?channel_id=UCct7QF2jcWRY6dhXWMSq9LQ");
XCTAssertEqual(feedLink.title, "RSS")
XCTAssertEqual(feedLink.type, "application/rss+xml")
XCTAssertEqual(feedLink.urlString, "https://www.youtube.com/feeds/videos.xml?channel_id=UCct7QF2jcWRY6dhXWMSq9LQ")
}
}

View File

@@ -16,7 +16,7 @@ final class JSONFeedParserTests: XCTestCase {
// 0.001 sec on my 2012 iMac.
let d = parserData("inessential", "json", "http://inessential.com/")
self.measure {
let _ = try! FeedParser.parse(d)
_ = try! FeedParser.parse(d)
}
}
@@ -25,7 +25,7 @@ final class JSONFeedParserTests: XCTestCase {
// 0.009 sec on my 2012 iMac.
let d = parserData("DaringFireball", "json", "http://daringfireball.net/")
self.measure {
let _ = try! FeedParser.parse(d)
_ = try! FeedParser.parse(d)
}
}
@@ -83,7 +83,7 @@ final class JSONFeedParserTests: XCTestCase {
let parsedFeed = try! FeedParser.parse(d)!
XCTAssertEqual(parsedFeed.items.count, 20)
XCTAssertEqual(parsedFeed.language, "de-DE")
for item in parsedFeed.items {
XCTAssertEqual(item.language, "de-DE")
}

View File

@@ -17,7 +17,7 @@ final class OPMLTests: XCTestCase {
// 0.003 sec on my M1 Mac Studio 2022
self.measure {
let _ = OPMLParser.document(with: self.subsData)
_ = OPMLParser.document(with: self.subsData)
}
}
@@ -36,7 +36,6 @@ final class OPMLTests: XCTestCase {
recursivelyCheckOPMLStructure(opmlDocument!)
}
func testFindingTitles() {
// https://github.com/brentsimmons/NetNewsWire/issues/527
// Fix a bug where titles arent found when theres no title attribute in the OPML,
@@ -66,8 +65,7 @@ private extension OPMLTests {
if !isFolder {
XCTAssertNotNil(feedSpecifier!.title)
XCTAssertNotNil(feedSpecifier!.feedURL)
}
else {
} else {
XCTAssertNil(feedSpecifier)
}

View File

@@ -16,7 +16,7 @@ final class RSSInJSONParserTests: XCTestCase {
// 0.003 sec on my 2012 iMac.
let d = parserData("ScriptingNews", "json", "http://scripting.com/")
self.measure {
let _ = try! FeedParser.parse(d)
_ = try! FeedParser.parse(d)
}
}

View File

@@ -17,7 +17,7 @@ final class RSSParserTests: XCTestCase {
// 0.002 2022 Mac Studio
let d = parserData("scriptingNews", "rss", "http://scripting.com/")
self.measure {
let _ = try! FeedParser.parse(d)
_ = try! FeedParser.parse(d)
}
}
@@ -27,7 +27,7 @@ final class RSSParserTests: XCTestCase {
// 0.001 2022 Mac Studio
let d = parserData("KatieFloyd", "rss", "http://katiefloyd.com/")
self.measure {
let _ = try! FeedParser.parse(d)
_ = try! FeedParser.parse(d)
}
}
@@ -37,7 +37,7 @@ final class RSSParserTests: XCTestCase {
// 0.0004 2022 Mac Studio
let d = parserData("EMarley", "rss", "https://medium.com/@emarley")
self.measure {
let _ = try! FeedParser.parse(d)
_ = try! FeedParser.parse(d)
}
}
@@ -47,7 +47,7 @@ final class RSSParserTests: XCTestCase {
// 0.0006 2022 Mac Studio
let d = parserData("manton", "rss", "http://manton.org/")
self.measure {
let _ = try! FeedParser.parse(d)
_ = try! FeedParser.parse(d)
}
}
@@ -57,7 +57,7 @@ final class RSSParserTests: XCTestCase {
// 0.002 2022 Mac Studio
let d = parserData("allthis", "rss", "http://leancrew.com/all-this")
self.measure {
let _ = try! FeedParser.parse(d)
_ = try! FeedParser.parse(d)
}
}
@@ -241,8 +241,7 @@ final class RSSParserTests: XCTestCase {
// Tue, 07 Mar 2023 15:15:29 -0500
let expectedDatePublished = dateWithValues(2023, 3, 7, 20, 15, 29)
XCTAssertEqual(article.datePublished, expectedDatePublished)
}
else if article.title == "Venturas System Settings" {
} else if article.title == "Venturas System Settings" {
didFindSecondTestArticle = true
// Sun, 30 Oct 2022 11:58:26 -0500
let expectedDatePublished = dateWithValues(2022, 10, 30, 16, 58, 26)