lint
This commit is contained in:
parent
655c716b62
commit
4cd608d123
|
@ -1,10 +1,9 @@
|
|||
included:
|
||||
- Sources
|
||||
- Tests
|
||||
|
||||
disabled_rules:
|
||||
- cyclomatic_complexity
|
||||
- file_length
|
||||
- function_body_length
|
||||
- identifier_name
|
||||
|
||||
line_length: 200
|
||||
|
|
|
@ -64,7 +64,9 @@ extension Plan {
|
|||
/// > "2001-01-01 00:00:03"
|
||||
/// > "2001-01-01 00:00:06"
|
||||
/// ...
|
||||
public static func make<I>(_ makeUnderlyingIterator: @escaping () -> I) -> Plan where I: IteratorProtocol, I.Element == Interval {
|
||||
public static func make<I>(
|
||||
_ 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<I>(_ makeUnderlyingIterator: @escaping () -> I) -> Plan where I: IteratorProtocol, I.Element == Date {
|
||||
public static func make<I>(
|
||||
_ makeUnderlyingIterator: @escaping () -> I
|
||||
) -> Plan where I: IteratorProtocol, I.Element == Date {
|
||||
return Plan.make { () -> AnyIterator<Interval> 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)
|
||||
}
|
||||
|
|
|
@ -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:
|
||||
|
|
|
@ -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)
|
||||
]
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue