Fix lint issues.

This commit is contained in:
Brent Simmons 2025-01-22 22:39:38 -08:00
parent b7f82944c7
commit ef4ae1bffe
5 changed files with 64 additions and 81 deletions

View File

@ -13,44 +13,44 @@ import XCTest
@testable import NetNewsWire
class ArticleSorterTests: XCTestCase {
// MARK: sortByDate ascending tests
func testSortByDateAscending() {
let now = Date()
let article1 = TestArticle(sortableName: "Susie's Feed", sortableDate: now.addingTimeInterval(-60.0), sortableArticleID: "1", sortableFeedID: "4")
let article2 = TestArticle(sortableName: "Phil's Feed", sortableDate: now.addingTimeInterval(60.0), sortableArticleID: "2", sortableFeedID: "6")
let article3 = TestArticle(sortableName: "Phil's Feed", sortableDate: now.addingTimeInterval(120.0), sortableArticleID: "3", sortableFeedID: "6")
let article4 = TestArticle(sortableName: "Susie's Feed", sortableDate: now.addingTimeInterval(-120.0), sortableArticleID: "4", sortableFeedID: "5")
let articles = [article1, article2, article3, article4]
let sortedArticles = ArticleSorter.sortedByDate(articles: articles,
sortDirection: .orderedAscending,
groupByFeed: false)
XCTAssertEqual(sortedArticles.count, articles.count)
XCTAssertEqual(sortedArticles.articleAtRow(0), article4)
XCTAssertEqual(sortedArticles.articleAtRow(1), article1)
XCTAssertEqual(sortedArticles.articleAtRow(2), article2)
XCTAssertEqual(sortedArticles.articleAtRow(3), article3)
}
func testSortByDateAscendingWithSameDate() {
let now = Date()
// Articles with the same date should end up being sorted by their article ID
let article1 = TestArticle(sortableName: "Phil's Feed", sortableDate: now, sortableArticleID: "1", sortableFeedID: "1")
let article2 = TestArticle(sortableName: "Matt's Feed", sortableDate: now, sortableArticleID: "2", sortableFeedID: "2")
let article3 = TestArticle(sortableName: "Sally's Feed", sortableDate: now, sortableArticleID: "3", sortableFeedID: "3")
let article4 = TestArticle(sortableName: "Susie's Feed", sortableDate: Date(timeInterval: -60.0, since: now), sortableArticleID: "4", sortableFeedID: "4")
let article5 = TestArticle(sortableName: "Paul's Feed", sortableDate: Date(timeInterval: -120.0, since: now), sortableArticleID: "5", sortableFeedID: "5")
let articles = [article1, article2, article3, article4, article5]
let sortedArticles = ArticleSorter.sortedByDate(articles: articles,
sortDirection: .orderedAscending,
groupByFeed: false)
XCTAssertEqual(sortedArticles.count, articles.count)
XCTAssertEqual(sortedArticles.articleAtRow(0), article5)
XCTAssertEqual(sortedArticles.articleAtRow(1), article4)
@ -58,7 +58,7 @@ class ArticleSorterTests: XCTestCase {
XCTAssertEqual(sortedArticles.articleAtRow(3), article2)
XCTAssertEqual(sortedArticles.articleAtRow(4), article3)
}
func testSortByDateAscendingWithGroupByFeed() {
let now = Date()
@ -71,12 +71,12 @@ class ArticleSorterTests: XCTestCase {
let article7 = TestArticle(sortableName: "Phil's Feed", sortableDate: now, sortableArticleID: "2", sortableFeedID: "1")
let article8 = TestArticle(sortableName: "Zippy's Feed", sortableDate: now, sortableArticleID: "1", sortableFeedID: "0")
let article9 = TestArticle(sortableName: "Zippy's Feed", sortableDate: now, sortableArticleID: "2", sortableFeedID: "0")
let articles = [article1, article2, article3, article4, article5, article6, article7, article8, article9]
let sortedArticles = ArticleSorter.sortedByDate(articles: articles, sortDirection: .orderedAscending, groupByFeed: true)
XCTAssertEqual(sortedArticles.count, 9)
// Gordy's feed articles
XCTAssertEqual(sortedArticles.articleAtRow(0), article4)
XCTAssertEqual(sortedArticles.articleAtRow(1), article5)
@ -93,42 +93,42 @@ class ArticleSorterTests: XCTestCase {
}
// MARK: sortByDate descending tests
func testSortByDateDescending() {
let now = Date()
let article1 = TestArticle(sortableName: "Susie's Feed", sortableDate: now.addingTimeInterval(-60.0), sortableArticleID: "1", sortableFeedID: "4")
let article2 = TestArticle(sortableName: "Phil's Feed", sortableDate: now.addingTimeInterval(60.0), sortableArticleID: "2", sortableFeedID: "6")
let article3 = TestArticle(sortableName: "Phil's Feed", sortableDate: now.addingTimeInterval(120.0), sortableArticleID: "3", sortableFeedID: "6")
let article4 = TestArticle(sortableName: "Susie's Feed", sortableDate: now.addingTimeInterval(-120.0), sortableArticleID: "4", sortableFeedID: "5")
let articles = [article1, article2, article3, article4]
let sortedArticles = ArticleSorter.sortedByDate(articles: articles,
sortDirection: .orderedDescending,
groupByFeed: false)
XCTAssertEqual(sortedArticles.count, articles.count)
XCTAssertEqual(sortedArticles.articleAtRow(0), article3)
XCTAssertEqual(sortedArticles.articleAtRow(1), article2)
XCTAssertEqual(sortedArticles.articleAtRow(2), article1)
XCTAssertEqual(sortedArticles.articleAtRow(3), article4)
}
func testSortByDateDescendingWithSameDate() {
let now = Date()
// Articles with the same date should end up being sorted by their article ID
let article1 = TestArticle(sortableName: "Phil's Feed", sortableDate: now, sortableArticleID: "1", sortableFeedID: "1")
let article2 = TestArticle(sortableName: "Matt's Feed", sortableDate: now, sortableArticleID: "2", sortableFeedID: "2")
let article3 = TestArticle(sortableName: "Sally's Feed", sortableDate: now, sortableArticleID: "3", sortableFeedID: "3")
let article4 = TestArticle(sortableName: "Susie's Feed", sortableDate: Date(timeInterval: -60.0, since: now), sortableArticleID: "4", sortableFeedID: "4")
let article5 = TestArticle(sortableName: "Paul's Feed", sortableDate: Date(timeInterval: -120.0, since: now), sortableArticleID: "5", sortableFeedID: "5")
let articles = [article1, article2, article3, article4, article5]
let sortedArticles = ArticleSorter.sortedByDate(articles: articles,
sortDirection: .orderedDescending,
groupByFeed: false)
XCTAssertEqual(sortedArticles.count, articles.count)
XCTAssertEqual(sortedArticles.articleAtRow(0), article1)
XCTAssertEqual(sortedArticles.articleAtRow(1), article2)
@ -136,7 +136,7 @@ class ArticleSorterTests: XCTestCase {
XCTAssertEqual(sortedArticles.articleAtRow(3), article4)
XCTAssertEqual(sortedArticles.articleAtRow(4), article5)
}
func testSortByDateDescendingWithGroupByFeed() {
let now = Date()
@ -149,12 +149,12 @@ class ArticleSorterTests: XCTestCase {
let article7 = TestArticle(sortableName: "Phil's Feed", sortableDate: now, sortableArticleID: "2", sortableFeedID: "1")
let article8 = TestArticle(sortableName: "Zippy's Feed", sortableDate: now, sortableArticleID: "1", sortableFeedID: "0")
let article9 = TestArticle(sortableName: "Zippy's Feed", sortableDate: now, sortableArticleID: "2", sortableFeedID: "0")
let articles = [article1, article2, article3, article4, article5, article6, article7, article8, article9]
let sortedArticles = ArticleSorter.sortedByDate(articles: articles, sortDirection: .orderedDescending, groupByFeed: true)
XCTAssertEqual(sortedArticles.count, 9)
// Gordy's feed articles
XCTAssertEqual(sortedArticles.articleAtRow(0), article5)
XCTAssertEqual(sortedArticles.articleAtRow(1), article4)
@ -169,12 +169,12 @@ class ArticleSorterTests: XCTestCase {
XCTAssertEqual(sortedArticles.articleAtRow(7), article8)
XCTAssertEqual(sortedArticles.articleAtRow(8), article9)
}
// MARK: Additional group by feed tests
func testGroupByFeedWithCaseInsensitiveFeedNames() {
let now = Date()
let article1 = TestArticle(sortableName: "phil's feed", sortableDate: now, sortableArticleID: "1", sortableFeedID: "1")
let article2 = TestArticle(sortableName: "PhIl's FEed", sortableDate: now, sortableArticleID: "2", sortableFeedID: "1")
let article3 = TestArticle(sortableName: "APPLE's feed", sortableDate: now, sortableArticleID: "3", sortableFeedID: "2")
@ -187,7 +187,7 @@ class ArticleSorterTests: XCTestCase {
groupByFeed: true)
XCTAssertEqual(sortedArticles.count, articles.count)
// Apple's feed articles
XCTAssertEqual(sortedArticles.articleAtRow(0), article3)
XCTAssertEqual(sortedArticles.articleAtRow(1), article5)
@ -196,7 +196,7 @@ class ArticleSorterTests: XCTestCase {
XCTAssertEqual(sortedArticles.articleAtRow(3), article2)
XCTAssertEqual(sortedArticles.articleAtRow(4), article4)
}
func testGroupByFeedWithSameFeedNames() {
let now = Date()
@ -219,7 +219,7 @@ class ArticleSorterTests: XCTestCase {
XCTAssertEqual(sortedArticles.articleAtRow(3), article2)
XCTAssertEqual(sortedArticles.articleAtRow(4), article4)
}
}
private struct TestArticle: SortableArticle, Equatable {
@ -236,5 +236,5 @@ private extension Array where Element == TestArticle {
}
return self[row]
}
}

View File

@ -9,14 +9,6 @@
import XCTest
class AppleScriptXCTestCase: XCTestCase {
override func setUp() {
super.setUp()
}
override func tearDown() {
super.tearDown()
}
/*
@function doIndividualScript
@ -28,39 +20,39 @@ class AppleScriptXCTestCase: XCTestCase {
if the test_result is false or is missing, the test fails
@return the value of script_result, if any
*/
func doIndividualScript(filename:String) -> NSAppleEventDescriptor? {
var errorDict: NSDictionary? = nil
func doIndividualScript(filename: String) -> NSAppleEventDescriptor? {
var errorDict: NSDictionary?
let testBundle = Bundle(for: type(of: self))
let url = testBundle.url(forResource:filename, withExtension:"scpt")
let url = testBundle.url(forResource: filename, withExtension: "scpt")
guard let testScriptUrl = url else {
XCTFail("Failed Getting script URL")
return nil
}
guard let testScript = NSAppleScript(contentsOf: testScriptUrl, error: &errorDict) else {
print ("error is \(String(describing: errorDict))")
print("error is \(String(describing: errorDict))")
XCTFail("Failed initializing NSAppleScript")
return nil
}
let scriptResult = testScript.executeAndReturnError(&errorDict)
if (errorDict != nil) {
print ("error is \(String(describing: errorDict))")
if errorDict != nil {
print("error is \(String(describing: errorDict))")
XCTFail("Failed executing script")
return nil
}
let usrfDictionary = scriptResult.usrfDictionary()
guard let testResult = usrfDictionary["test_result"] else {
XCTFail("test script didn't return test result in usrf")
return nil
}
if (testResult.booleanValue != true) {
if testResult.booleanValue != true {
print("test_result was \(testResult)")
print("script_result was \(String(describing: usrfDictionary["script_result"]))")
}
XCTAssert(testResult.booleanValue == true, "test_result should be true")
return usrfDictionary["script_result"]
}

View File

@ -17,23 +17,23 @@ import Foundation
returns an analogous Swift dictionary
*/
extension NSAppleEventDescriptor {
public func usrfDictionary() -> [String:NSAppleEventDescriptor] {
public func usrfDictionary() -> [String: NSAppleEventDescriptor] {
guard self.isRecordDescriptor else {
print ("error: usrfDictionary() expected input to be a record")
print("error: usrfDictionary() expected input to be a record")
return [:]
}
guard let usrfList = self.forKeyword("usrf".fourCharCode) else {
print ("error: usrfDictionary() couldn't find usrf")
print("error: usrfDictionary() couldn't find usrf")
return [:]
}
let listCount = usrfList.numberOfItems
guard (listCount%2 == 0) else {
print ("error: usrfDictionary() expected even number of items in usrf")
guard listCount%2 == 0 else {
print("error: usrfDictionary() expected even number of items in usrf")
return [:]
}
var usrfDictionary:[String:NSAppleEventDescriptor] = [:]
var usrfDictionary: [String: NSAppleEventDescriptor] = [:]
var processedItems = 0
while (processedItems < listCount) {
while processedItems < listCount {
processedItems = processedItems + 2
guard let nthlabel = usrfList.atIndex(processedItems-1) else {
print("usrfDictionary() couldn't get item \(processedItems+1) in usrf list")
@ -49,6 +49,6 @@ extension NSAppleEventDescriptor {
}
usrfDictionary[nthLabelString] = nthvalue
}
return usrfDictionary;
return usrfDictionary
}
}

View File

@ -10,15 +10,6 @@ import XCTest
class ScriptingTests: AppleScriptXCTestCase {
override func setUp() {
super.setUp()
}
override func tearDown() {
super.tearDown()
}
/*
@function testGenericScript
@brief An example of how a script can be run as part of an XCTest
@ -31,27 +22,27 @@ class ScriptingTests: AppleScriptXCTestCase {
let scriptResult = doIndividualScript(filename: "testGenericScript")
XCTAssert( scriptResult?.stringValue == "Geoducks!")
}
func testGetUrlScript() {
_ = doIndividualScript(filename: "testGetURL")
}
func testNameAndUrlOfEveryFeedScript() {
_ = doIndividualScript(filename: "testNameAndUrlOfEveryFeed")
}
func testNameOfEveryFolderScript() {
_ = doIndividualScript(filename: "testNameOfEveryFolder")
}
func testNameOfAuthorsScript() {
_ = doIndividualScript(filename: "testNameOfAuthors")
}
func testFeedExists() {
_ = doIndividualScript(filename: "testFeedExists")
}
func testFeedOPML() {
_ = doIndividualScript(filename: "testFeedOPML")
}
@ -64,14 +55,14 @@ class ScriptingTests: AppleScriptXCTestCase {
// _ = doIndividualScriptWithExpectation(filename: "testIterativeCreateAndDeleteFeed")
// }
func doIndividualScriptWithExpectation(filename:String) {
let queue = DispatchQueue(label:"testQueue")
func doIndividualScriptWithExpectation(filename: String) {
let queue = DispatchQueue(label: "testQueue")
let scriptExpectation = self.expectation(description: filename+"expectation")
queue.async {
_ = self.doIndividualScript(filename:filename)
_ = self.doIndividualScript(filename: filename)
scriptExpectation.fulfill()
}
self.wait(for:[scriptExpectation], timeout:60)
self.wait(for: [scriptExpectation], timeout: 60)
}
/*
@ -90,7 +81,7 @@ class ScriptingTests: AppleScriptXCTestCase {
this test is disabled.
*/
func disabledTestCurrentArticleScripts() {
doIndividualScriptWithExpectation(filename: "uiScriptingTestSetup")
doIndividualScriptWithExpectation(filename: "establishMainWindowStartingState")
doIndividualScriptWithExpectation(filename: "selectAFeed")

View File

@ -19,7 +19,7 @@ class SharingTests: XCTestCase {
sharingService.delegate = sharingServiceDelegate
sharingService.perform(withItems: [
ArticlePasteboardWriter(article: article(titled: "Immunization")),
ArticlePasteboardWriter(article: article(titled: "Immunization"))
])
XCTAssertEqual("Immunization", sharingService.subject)
@ -32,7 +32,7 @@ class SharingTests: XCTestCase {
sharingService.delegate = sharingServiceDelegate
sharingService.perform(withItems: [
ArticlePasteboardWriter(article: article(titled: "NetNewsWire Status: Almost Beta")),
ArticlePasteboardWriter(article: article(titled: "No Algorithms Follow-Up")),
ArticlePasteboardWriter(article: article(titled: "No Algorithms Follow-Up"))
])
XCTAssertEqual("NetNewsWire Status: Almost Beta, No Algorithms Follow-Up", sharingService.subject)