From 4cd608d123ac0b728958ab6ed7825dc38762ad58 Mon Sep 17 00:00:00 2001 From: Quentin Jin Date: Wed, 3 Apr 2019 18:07:25 +0800 Subject: [PATCH] lint --- .swiftlint.yml | 3 +-- Sources/Schedule/Plan.swift | 10 ++++--- Sources/Schedule/Task.swift | 1 - Tests/ScheduleTests/PlanTests.swift | 42 ++++++++++++++--------------- Tests/ScheduleTests/TaskTests.swift | 4 +-- 5 files changed, 31 insertions(+), 29 deletions(-) diff --git a/.swiftlint.yml b/.swiftlint.yml index 002b4b7..07b97ed 100644 --- a/.swiftlint.yml +++ b/.swiftlint.yml @@ -1,10 +1,9 @@ included: - Sources + - Tests disabled_rules: - cyclomatic_complexity - file_length - function_body_length - identifier_name - -line_length: 200 diff --git a/Sources/Schedule/Plan.swift b/Sources/Schedule/Plan.swift index 5523e34..22fca3b 100644 --- a/Sources/Schedule/Plan.swift +++ b/Sources/Schedule/Plan.swift @@ -64,7 +64,9 @@ extension Plan { /// > "2001-01-01 00:00:03" /// > "2001-01-01 00:00:06" /// ... - public static func make(_ makeUnderlyingIterator: @escaping () -> I) -> Plan where I: IteratorProtocol, I.Element == Interval { + public static func make( + _ makeUnderlyingIterator: @escaping () -> I + ) -> Plan where I: IteratorProtocol, I.Element == Interval { return Plan(AnySequence(makeUnderlyingIterator)) } @@ -109,7 +111,9 @@ extension Plan { /// You are not supposed to return `Date()` in making interator. /// If you want to execute a task immediately, /// use `Plan.now` then `concat` another plan instead. - public static func make(_ makeUnderlyingIterator: @escaping () -> I) -> Plan where I: IteratorProtocol, I.Element == Date { + public static func make( + _ makeUnderlyingIterator: @escaping () -> I + ) -> Plan where I: IteratorProtocol, I.Element == Date { return Plan.make { () -> AnyIterator in var iterator = makeUnderlyingIterator() var last: Date! @@ -445,7 +449,7 @@ extension Plan { date = calendar.date(byAdding: .year, value: 1, to: d) } else if Date().is(monthday) { date = Date().startOfToday - } else { + } else { let components = monthday.toDateComponents() date = calendar.nextDate(after: Date(), matching: components, matchingPolicy: .strict) } diff --git a/Sources/Schedule/Task.swift b/Sources/Schedule/Task.swift index 1f5e6a2..0187380 100644 --- a/Sources/Schedule/Task.swift +++ b/Sources/Schedule/Task.swift @@ -51,7 +51,6 @@ open class Task { /// The mutex used to guard task center operations. let taskCenterMutex = NSRecursiveLock() - /// Initializes a normal task with specified plan and dispatch queue. /// /// - Parameters: diff --git a/Tests/ScheduleTests/PlanTests.swift b/Tests/ScheduleTests/PlanTests.swift index 000c847..8854cdc 100644 --- a/Tests/ScheduleTests/PlanTests.swift +++ b/Tests/ScheduleTests/PlanTests.swift @@ -121,89 +121,89 @@ final class PlanTests: XCTestCase { XCTAssertEqual(i.dateComponents.hour, 11) } } - + func testPassingEmptyArrays() { XCTAssertTrue(Plan.of([Interval]()).isNever()) XCTAssertTrue(Plan.of([Date]()).isNever()) - + XCTAssertTrue(Plan.every([Weekday]()).at(11, 11).isNever()) XCTAssertTrue(Plan.every([Monthday]()).at(11, 11).isNever()) - + XCTAssertTrue(Plan.every(.monday).at([]).isNever()) - + XCTAssertTrue(Plan.every([Weekday]()).at("11:11:00").isNever()) } - + func testIntervalOffset() { // Non-offset plan let e1 = expectation(description: "testIntervalOffset_1") let plan1 = Plan.after(1.second) var date1: Date? - + // Offset plan let e2 = expectation(description: "testIntervalOffset_2") let plan2 = plan1.offset(by: 1.second) var date2: Date? - + let task1 = plan1.do { date1 = Date(); e1.fulfill() } let task2 = plan2.do { date2 = Date(); e2.fulfill() } _ = task1 _ = task2 - + waitForExpectations(timeout: 3.5) - + XCTAssertNotNil(date1) XCTAssertNotNil(date2) XCTAssertTrue(date2!.interval(since: date1!).isAlmostEqual(to: 1.second, leeway: 0.1.seconds)) } - + func testNegativeIntervalOffset() { // Non-offset plan let e1 = expectation(description: "testIntervalOffset_1") let plan1 = Plan.after(2.seconds) var date1: Date? - + // Offset plan let e2 = expectation(description: "testIntervalOffset_2") let plan2 = plan1.offset(by: -1.second) var date2: Date? - + let task1 = plan1.do { date1 = Date(); e1.fulfill() } let task2 = plan2.do { date2 = Date(); e2.fulfill() } _ = task1 _ = task2 - + waitForExpectations(timeout: 2.5) - + XCTAssertNotNil(date1) XCTAssertNotNil(date2) XCTAssertTrue(date2!.interval(since: date1!).isAlmostEqual(to: -1.second, leeway: 0.1.seconds)) } - + func testNilIntervalOffset() { // Non-offset plan let e1 = expectation(description: "testIntervalOffset_1") let plan1 = Plan.after(1.second) var date1: Date? - + // Offset plan let e2 = expectation(description: "testIntervalOffset_2") let plan2 = plan1.offset(by: nil) var date2: Date? - + let task1 = plan1.do { date1 = Date(); e1.fulfill() } let task2 = plan2.do { date2 = Date(); e2.fulfill() } _ = task1 _ = task2 - + waitForExpectations(timeout: 1.5) - + XCTAssertNotNil(date1) XCTAssertNotNil(date2) XCTAssertTrue(date2!.interval(since: date1!).isAlmostEqual(to: 0.seconds, leeway: 0.1.seconds)) } - + static var allTests = [ ("testMake", testMake), ("testDates", testDates), @@ -221,6 +221,6 @@ final class PlanTests: XCTestCase { ("testPassingEmptyArrays", testPassingEmptyArrays), ("testIntervalOffset", testIntervalOffset), ("testNegativeIntervalOffset", testNegativeIntervalOffset), - ("testNilIntervalOffset", testNilIntervalOffset), + ("testNilIntervalOffset", testNilIntervalOffset) ] } diff --git a/Tests/ScheduleTests/TaskTests.swift b/Tests/ScheduleTests/TaskTests.swift index eee3467..6b919f0 100644 --- a/Tests/ScheduleTests/TaskTests.swift +++ b/Tests/ScheduleTests/TaskTests.swift @@ -76,7 +76,7 @@ final class TaskTests: XCTestCase { task.removeAction(byKey: key) XCTAssertEqual(task.countOfActions, 1) - + task.cancel() task.removeAllActions() @@ -107,7 +107,7 @@ final class TaskTests: XCTestCase { let fn = { let obj = NSObject() let task = Plan.after(0.1.second).do(queue: .main, onElapse: { - XCTFail() + XCTFail("should never come here") }) task.host(on: obj) }