10
10
//
11
11
//===----------------------------------------------------------------------===//
12
12
13
- #if canImport(TestSupport)
14
- import TestSupport
15
- #endif
13
+ import Testing
16
14
17
15
#if FOUNDATION_FRAMEWORK
18
16
@testable import Foundation
@@ -21,15 +19,16 @@ import TestSupport
21
19
@testable import FoundationEssentials
22
20
#endif // FOUNDATION_FRAMEWORK
23
21
24
- final class CalendarRecurrenceRuleTests : XCTestCase {
22
+ @Suite ( " Calendar RecurrenceRule " )
23
+ private struct CalendarRecurrenceRuleTests {
25
24
/// A Gregorian calendar with a time zone set to California
26
25
var gregorian : Calendar = {
27
26
var gregorian = Calendar ( identifier: . gregorian)
28
27
gregorian. timeZone = . init( identifier: " US/Pacific " ) !
29
28
return gregorian
30
29
} ( )
31
30
32
- func testYearlyRecurrenceInLunarCalendar ( ) {
31
+ @ Test func yearlyRecurrenceInLunarCalendar ( ) {
33
32
// Find the first day of the lunar new year
34
33
let start = Date ( timeIntervalSince1970: 1726876800.0 ) // 2024-09-21T00:00:00-0000
35
34
let end = Date ( timeIntervalSince1970: 1855699200.0 ) // 2028-10-21T00:00:00-0000
@@ -50,10 +49,10 @@ final class CalendarRecurrenceRuleTests: XCTestCase {
50
49
Date ( timeIntervalSince1970: 1832508000.0 ) , // 2028-01-26T14:00:00-0000
51
50
]
52
51
53
- XCTAssertEqual ( results, expectedResults)
52
+ #expect ( results == expectedResults)
54
53
}
55
54
56
- func testExpandToLeapMonths ( ) {
55
+ @ Test func expandToLeapMonths ( ) {
57
56
var lunarCalendar = Calendar ( identifier: . chinese)
58
57
lunarCalendar. timeZone = . gmt
59
58
@@ -64,14 +63,14 @@ final class CalendarRecurrenceRuleTests: XCTestCase {
64
63
rule. daysOfTheMonth = [ 1 ]
65
64
var sequence = rule. recurrences ( of: start) . makeIterator ( )
66
65
67
- XCTAssertEqual ( sequence. next ( ) , Date ( timeIntervalSince1970: 1753401600.0 ) ) // 2025-07-25T00:00:00-0000 (Sixth leap month)
68
- XCTAssertEqual ( sequence. next ( ) , Date ( timeIntervalSince1970: 1786579200.0 ) ) // 2026-08-13T00:00:00-0000 (Seventh month)
69
- XCTAssertEqual ( sequence. next ( ) , Date ( timeIntervalSince1970: 1817164800.0 ) ) // 2027-08-02T00:00:00-0000 (Seventh month)
70
- XCTAssertEqual ( sequence. next ( ) , Date ( timeIntervalSince1970: 1850342400.0 ) ) // 2028-08-20T00:00:00-0000 (Seventh month)
71
- XCTAssertEqual ( sequence. next ( ) , Date ( timeIntervalSince1970: 1881014400.0 ) ) // 2029-08-10T00:00:00-0000 (Seventh month)
66
+ #expect ( sequence. next ( ) == Date ( timeIntervalSince1970: 1753401600.0 ) ) // 2025-07-25T00:00:00-0000 (Sixth leap month)
67
+ #expect ( sequence. next ( ) == Date ( timeIntervalSince1970: 1786579200.0 ) ) // 2026-08-13T00:00:00-0000 (Seventh month)
68
+ #expect ( sequence. next ( ) == Date ( timeIntervalSince1970: 1817164800.0 ) ) // 2027-08-02T00:00:00-0000 (Seventh month)
69
+ #expect ( sequence. next ( ) == Date ( timeIntervalSince1970: 1850342400.0 ) ) // 2028-08-20T00:00:00-0000 (Seventh month)
70
+ #expect ( sequence. next ( ) == Date ( timeIntervalSince1970: 1881014400.0 ) ) // 2029-08-10T00:00:00-0000 (Seventh month)
72
71
}
73
72
74
- func testStartFromLeapMonth ( ) {
73
+ @ Test func startFromLeapMonth ( ) {
75
74
var lunarCalendar = Calendar ( identifier: . chinese)
76
75
lunarCalendar. timeZone = . gmt
77
76
@@ -82,29 +81,29 @@ final class CalendarRecurrenceRuleTests: XCTestCase {
82
81
let rule = Calendar . RecurrenceRule ( calendar: lunarCalendar, frequency: . yearly, matchingPolicy: . nextTimePreservingSmallerComponents)
83
82
var sequence = rule. recurrences ( of: start) . makeIterator ( )
84
83
85
- XCTAssertEqual ( sequence. next ( ) , Date ( timeIntervalSince1970: 1753401600.0 ) ) // 2025-07-25T00:00:00-0000 (Sixth leap month)
86
- XCTAssertEqual ( sequence. next ( ) , Date ( timeIntervalSince1970: 1786579200.0 ) ) // 2026-08-13T00:00:00-0000 (Seventh month)
87
- XCTAssertEqual ( sequence. next ( ) , Date ( timeIntervalSince1970: 1817164800.0 ) ) // 2027-08-02T00:00:00-0000 (Seventh month)
88
- XCTAssertEqual ( sequence. next ( ) , Date ( timeIntervalSince1970: 1850342400.0 ) ) // 2028-08-20T00:00:00-0000 (Seventh month)
89
- XCTAssertEqual ( sequence. next ( ) , Date ( timeIntervalSince1970: 1881014400.0 ) ) // 2029-08-10T00:00:00-0000 (Seventh month)
90
- XCTAssertEqual ( sequence. next ( ) , Date ( timeIntervalSince1970: 1911600000.0 ) ) // 2030-07-30T00:00:00-0000 (Seventh month)
91
- XCTAssertEqual ( sequence. next ( ) , Date ( timeIntervalSince1970: 1944777600.0 ) ) // 2031-08-18T00:00:00-0000 (Seventh month)
92
- XCTAssertEqual ( sequence. next ( ) , Date ( timeIntervalSince1970: 1975363200.0 ) ) // 2032-08-06T00:00:00-0000 (Seventh month)
93
- XCTAssertEqual ( sequence. next ( ) , Date ( timeIntervalSince1970: 2005948800.0 ) ) // 2033-07-26T00:00:00-0000 (Seventh month)
94
- XCTAssertEqual ( sequence. next ( ) , Date ( timeIntervalSince1970: 2039126400.0 ) ) // 2034-08-14T00:00:00-0000 (Seventh month)
95
- XCTAssertEqual ( sequence. next ( ) , Date ( timeIntervalSince1970: 2069798400.0 ) ) // 2035-08-04T00:00:00-0000 (Seventh month)
96
- XCTAssertEqual ( sequence. next ( ) , Date ( timeIntervalSince1970: 2100384000.0 ) ) // 2036-07-23T00:00:00-0000 (Sixth leap month)
97
- XCTAssertEqual ( sequence. next ( ) , Date ( timeIntervalSince1970: 2133561600.0 ) ) // 2037-08-11T00:00:00-0000 (Seventh month)
98
- XCTAssertEqual ( sequence. next ( ) , Date ( timeIntervalSince1970: 2164233600.0 ) ) // 2038-08-01T00:00:00-0000 (Seventh month)
84
+ #expect ( sequence. next ( ) == Date ( timeIntervalSince1970: 1753401600.0 ) ) // 2025-07-25T00:00:00-0000 (Sixth leap month)
85
+ #expect ( sequence. next ( ) == Date ( timeIntervalSince1970: 1786579200.0 ) ) // 2026-08-13T00:00:00-0000 (Seventh month)
86
+ #expect ( sequence. next ( ) == Date ( timeIntervalSince1970: 1817164800.0 ) ) // 2027-08-02T00:00:00-0000 (Seventh month)
87
+ #expect ( sequence. next ( ) == Date ( timeIntervalSince1970: 1850342400.0 ) ) // 2028-08-20T00:00:00-0000 (Seventh month)
88
+ #expect ( sequence. next ( ) == Date ( timeIntervalSince1970: 1881014400.0 ) ) // 2029-08-10T00:00:00-0000 (Seventh month)
89
+ #expect ( sequence. next ( ) == Date ( timeIntervalSince1970: 1911600000.0 ) ) // 2030-07-30T00:00:00-0000 (Seventh month)
90
+ #expect ( sequence. next ( ) == Date ( timeIntervalSince1970: 1944777600.0 ) ) // 2031-08-18T00:00:00-0000 (Seventh month)
91
+ #expect ( sequence. next ( ) == Date ( timeIntervalSince1970: 1975363200.0 ) ) // 2032-08-06T00:00:00-0000 (Seventh month)
92
+ #expect ( sequence. next ( ) == Date ( timeIntervalSince1970: 2005948800.0 ) ) // 2033-07-26T00:00:00-0000 (Seventh month)
93
+ #expect ( sequence. next ( ) == Date ( timeIntervalSince1970: 2039126400.0 ) ) // 2034-08-14T00:00:00-0000 (Seventh month)
94
+ #expect ( sequence. next ( ) == Date ( timeIntervalSince1970: 2069798400.0 ) ) // 2035-08-04T00:00:00-0000 (Seventh month)
95
+ #expect ( sequence. next ( ) == Date ( timeIntervalSince1970: 2100384000.0 ) ) // 2036-07-23T00:00:00-0000 (Sixth leap month)
96
+ #expect ( sequence. next ( ) == Date ( timeIntervalSince1970: 2133561600.0 ) ) // 2037-08-11T00:00:00-0000 (Seventh month)
97
+ #expect ( sequence. next ( ) == Date ( timeIntervalSince1970: 2164233600.0 ) ) // 2038-08-01T00:00:00-0000 (Seventh month)
99
98
100
99
// A strict recurrence only matches in years with leap months
101
100
let strictRule = Calendar . RecurrenceRule ( calendar: lunarCalendar, frequency: . yearly, matchingPolicy: . strict)
102
101
var strictSequence = strictRule. recurrences ( of: start) . makeIterator ( )
103
- XCTAssertEqual ( strictSequence. next ( ) , Date ( timeIntervalSince1970: 1753401600.0 ) ) // 2025-07-25T00:00:00-0000 (Sixth leap month)
104
- XCTAssertEqual ( strictSequence. next ( ) , Date ( timeIntervalSince1970: 2100384000.0 ) ) // 2036-07-23T00:00:00-0000 (Sixth leap month)
102
+ #expect ( strictSequence. next ( ) == Date ( timeIntervalSince1970: 1753401600.0 ) ) // 2025-07-25T00:00:00-0000 (Sixth leap month)
103
+ #expect ( strictSequence. next ( ) == Date ( timeIntervalSince1970: 2100384000.0 ) ) // 2036-07-23T00:00:00-0000 (Sixth leap month)
105
104
}
106
105
107
- func testDaylightSavingsRepeatedTimePolicyFirst ( ) {
106
+ @ Test func daylightSavingsRepeatedTimePolicyFirst ( ) {
108
107
let start = Date ( timeIntervalSince1970: 1730535600.0 ) // 2024-11-02T01:20:00-0700
109
108
var rule = Calendar . RecurrenceRule ( calendar: gregorian, frequency: . daily)
110
109
rule. repeatedTimePolicy = . first
@@ -117,10 +116,10 @@ final class CalendarRecurrenceRuleTests: XCTestCase {
117
116
/// 02:00 PDT)
118
117
Date ( timeIntervalSince1970: 1730712000.0 ) , // 2024-11-04T01:20:00-0800
119
118
]
120
- XCTAssertEqual ( results, expectedResults)
119
+ #expect ( results == expectedResults)
121
120
}
122
121
123
- func testDaylightSavingsRepeatedTimePolicyLast ( ) {
122
+ @ Test func daylightSavingsRepeatedTimePolicyLast ( ) {
124
123
let start = Date ( timeIntervalSince1970: 1730535600.0 ) // 2024-11-02T01:20:00-0700
125
124
var rule = Calendar . RecurrenceRule ( calendar: gregorian, frequency: . daily)
126
125
rule. repeatedTimePolicy = . last
@@ -133,6 +132,6 @@ final class CalendarRecurrenceRuleTests: XCTestCase {
133
132
Date ( timeIntervalSince1970: 1730625600.0 ) , // 2024-11-03T01:20:00-0800
134
133
Date ( timeIntervalSince1970: 1730712000.0 ) , // 2024-11-04T01:20:00-0800
135
134
]
136
- XCTAssertEqual ( results, expectedResults)
135
+ #expect ( results == expectedResults)
137
136
}
138
137
}
0 commit comments