-
-
Notifications
You must be signed in to change notification settings - Fork 470
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
415 additions
and
93 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
// | ||
// MessageDeleteTimeRangeTest.swift | ||
// BarkTests | ||
// | ||
// Created by huangfeng on 1/8/25. | ||
// Copyright © 2025 Fin. All rights reserved. | ||
// | ||
@testable import Bark | ||
import Testing | ||
|
||
struct MessageDeleteTimeRangeTest { | ||
@Test("检查时间范围区间是否正确", arguments: [ | ||
MessageDeleteTimeRange.lastHour, | ||
MessageDeleteTimeRange.today, | ||
MessageDeleteTimeRange.todayAndYesterday, | ||
MessageDeleteTimeRange.lastMonth, | ||
MessageDeleteTimeRange.allTime, | ||
MessageDeleteTimeRange.beforeOneHour, | ||
MessageDeleteTimeRange.beforeToday, | ||
MessageDeleteTimeRange.beforeYesterday, | ||
MessageDeleteTimeRange.beforeOneMonth | ||
]) | ||
func testRange(range: MessageDeleteTimeRange) async throws { | ||
let now = Date() | ||
let lastHour = Calendar.current.date(byAdding: .hour, value: -1, to: now)! | ||
let today = now.startOfDay | ||
let yesterday = Calendar.current.date(byAdding: .day, value: -1, to: today)!.startOfDay | ||
let lastMonth = Calendar.current.date(byAdding: .month, value: -1, to: now)! | ||
|
||
switch range { | ||
case .lastHour: | ||
let startDate = range.startDate | ||
let endDate = range.endDate | ||
#expect(startDate.timeInterval == lastHour.timeInterval && endDate.timeInterval == now.timeInterval) | ||
case .today: | ||
let startDate = range.startDate | ||
let endDate = range.endDate | ||
#expect(startDate.timeInterval == today.timeInterval && endDate.timeInterval == now.timeInterval) | ||
case .todayAndYesterday: | ||
let startDate = range.startDate | ||
let endDate = range.endDate | ||
#expect(startDate.timeInterval == yesterday.timeInterval && endDate.timeInterval == now.timeInterval) | ||
case .lastMonth: | ||
let startDate = range.startDate | ||
let endDate = range.endDate | ||
#expect(startDate.timeInterval == lastMonth.timeInterval && endDate.timeInterval == now.timeInterval) | ||
case .allTime: | ||
let startDate = range.startDate | ||
let endDate = range.endDate | ||
#expect(startDate.timeInterval == 0 && endDate.timeInterval == now.timeInterval) | ||
case .beforeOneHour: | ||
let startDate = range.startDate | ||
let endDate = range.endDate | ||
#expect(startDate.timeInterval == 0 && endDate.timeInterval == lastHour.timeInterval) | ||
case .beforeToday: | ||
let startDate = range.startDate | ||
let endDate = range.endDate | ||
#expect(startDate.timeInterval == 0 && endDate.timeInterval == today.timeInterval) | ||
case .beforeYesterday: | ||
let startDate = range.startDate | ||
let endDate = range.endDate | ||
#expect(startDate.timeInterval == 0 && endDate.timeInterval == yesterday.timeInterval) | ||
case .beforeOneMonth: | ||
let startDate = range.startDate | ||
let endDate = range.endDate | ||
#expect(startDate.timeInterval == 0 && endDate.timeInterval == lastMonth.timeInterval) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.