1010//
1111//===----------------------------------------------------------------------===//
1212
13- #if canImport(TestSupport)
14- import TestSupport
15- #endif
13+ import Testing
1614
1715#if canImport(FoundationEssentials)
18- @testable import FoundationEssentials
16+ import FoundationEssentials
17+ #elseif FOUNDATION_FRAMEWORK
18+ import Foundation
1919#endif
2020
21- final class DateTests : XCTestCase {
21+ @Suite ( " Date " )
22+ private struct DateTests {
2223
23- func testDateComparison ( ) {
24+ @ Test func comparison ( ) {
2425 let d1 = Date ( )
2526 let d2 = d1 + 1
2627
27- XCTAssertGreaterThan ( d2, d1)
28- XCTAssertLessThan ( d1, d2)
28+ #expect ( d2 > d1)
29+ #expect ( d1 < d2)
2930
3031 let d3 = Date ( timeIntervalSince1970: 12345 )
3132 let d4 = Date ( timeIntervalSince1970: 12345 )
3233
33- XCTAssertEqual ( d3, d4)
34- XCTAssertLessThanOrEqual ( d3, d4)
35- XCTAssertGreaterThanOrEqual ( d4, d3)
34+ #expect ( d3 == d4)
35+ #expect ( d3 <= d4)
36+ #expect ( d4 >= d3)
3637 }
3738
38- func testDateMutation ( ) {
39+ @ Test func mutation ( ) {
3940 let d0 = Date ( )
4041 var d1 = Date ( )
4142 d1 = d1 + 1.0
4243 let d2 = Date ( timeIntervalSinceNow: 10 )
4344
44- XCTAssertGreaterThan ( d2, d1)
45- XCTAssertNotEqual ( d1, d0)
45+ #expect ( d2 > d1)
46+ #expect ( d1 != d0)
4647
4748 let d3 = d1
4849 d1 += 10
4950
50- XCTAssertGreaterThan ( d1, d3)
51+ #expect ( d1 > d3)
5152 }
5253
53- func testDistantPast ( ) {
54+ @ Test func distantPast ( ) {
5455 let distantPast = Date . distantPast
5556 let currentDate = Date ( )
5657
57- XCTAssertLessThan ( distantPast, currentDate)
58- XCTAssertGreaterThan ( currentDate, distantPast)
59- XCTAssertLessThan ( distantPast. timeIntervalSince ( currentDate) ,
58+ #expect ( distantPast < currentDate)
59+ #expect ( currentDate > distantPast)
60+ #expect ( distantPast. timeIntervalSince ( currentDate) <
6061 3600.0 * 24 * 365 * 100 ) /* ~1 century in seconds */
6162 }
6263
63- func testDistantFuture ( ) {
64+ @ Test func distantFuture ( ) {
6465 let distantFuture = Date . distantFuture
6566 let currentDate = Date ( )
6667
67- XCTAssertLessThan ( currentDate, distantFuture)
68- XCTAssertGreaterThan ( distantFuture, currentDate)
69- XCTAssertGreaterThan ( distantFuture. timeIntervalSince ( currentDate) ,
68+ #expect ( currentDate < distantFuture)
69+ #expect ( distantFuture > currentDate)
70+ #expect ( distantFuture. timeIntervalSince ( currentDate) >
7071 3600.0 * 24 * 365 * 100 ) /* ~1 century in seconds */
7172 }
7273
73- func test_now ( ) {
74+ @ Test func now ( ) {
7475 let date1 : Date = . now
7576 let date2 : Date = . now
7677
77- XCTAssertLessThanOrEqual ( date1, date2)
78+ #expect ( date1 <= date2)
7879 }
7980
80- func testDescriptionReferenceDate ( ) {
81+ @ Test func descriptionReferenceDate ( ) {
8182 let date = Date ( timeIntervalSinceReferenceDate: TimeInterval ( 0 ) )
8283
83- XCTAssertEqual ( " 2001-01-01 00:00:00 +0000 " , date. description)
84+ #expect ( " 2001-01-01 00:00:00 +0000 " == date. description)
8485 }
8586
86- func testDescription1970 ( ) {
87+ @ Test func description1970 ( ) {
8788 let date = Date ( timeIntervalSince1970: TimeInterval ( 0 ) )
8889
89- XCTAssertEqual ( " 1970-01-01 00:00:00 +0000 " , date. description)
90+ #expect ( " 1970-01-01 00:00:00 +0000 " == date. description)
9091 }
9192
92- func testDescriptionDistantPast( ) throws {
93- #if os(Windows)
94- throw XCTSkip ( " ucrt does not support distant past " )
95- #else
93+ #if os(Windows)
94+ @Test ( . disabled( " ucrt does not support distant past " ) )
95+ #else
96+ @Test
97+ #endif
98+ func descriptionDistantPast( ) throws {
9699#if FOUNDATION_FRAMEWORK
97- XCTAssertEqual ( " 0001-01-01 00:00:00 +0000 " , Date . distantPast. description)
100+ #expect ( " 0001-01-01 00:00:00 +0000 " == Date . distantPast. description)
98101#else
99- XCTAssertEqual ( " 0000-12-30 00:00:00 +0000 " , Date . distantPast. description)
100- #endif
102+ #expect( " 0000-12-30 00:00:00 +0000 " == Date . distantPast. description)
101103#endif
102104 }
103105
104- func testDescriptionDistantFuture( ) throws {
105- #if os(Windows)
106- throw XCTSkip ( " ucrt does not support distant future " )
107- #else
108- XCTAssertEqual ( " 4001-01-01 00:00:00 +0000 " , Date . distantFuture. description)
109- #endif
106+ #if os(Windows)
107+ @Test ( . disabled( " ucrt does not support distant past " ) )
108+ #else
109+ @Test
110+ #endif
111+ func descriptionDistantFuture( ) throws {
112+ #expect( " 4001-01-01 00:00:00 +0000 " == Date . distantFuture. description)
110113 }
111114
112- func testDescriptionBeyondDistantPast ( ) {
115+ @ Test func descriptionBeyondDistantPast ( ) {
113116 let date = Date . distantPast. addingTimeInterval ( TimeInterval ( - 1 ) )
114117#if FOUNDATION_FRAMEWORK
115- XCTAssertEqual ( " 0000-12-31 23:59:59 +0000 " , date. description)
118+ #expect ( " 0000-12-31 23:59:59 +0000 " == date. description)
116119#else
117- XCTAssertEqual ( " <description unavailable> " , date. description)
120+ #expect ( " <description unavailable> " == date. description)
118121#endif
119122 }
120123
121- func testDescriptionBeyondDistantFuture ( ) {
124+ @ Test func descriptionBeyondDistantFuture ( ) {
122125 let date = Date . distantFuture. addingTimeInterval ( TimeInterval ( 1 ) )
123126#if FOUNDATION_FRAMEWORK
124- XCTAssertEqual ( " 4001-01-01 00:00:01 +0000 " , date. description)
127+ #expect ( " 4001-01-01 00:00:01 +0000 " == date. description)
125128#else
126- XCTAssertEqual ( " <description unavailable> " , date. description)
129+ #expect ( " <description unavailable> " == date. description)
127130#endif
128131 }
129132
130- func testNowIsAfterReasonableDate ( ) {
133+ @ Test func nowIsAfterReasonableDate ( ) {
131134 let date = Date . now
132- XCTAssert ( date. timeIntervalSinceReferenceDate > 742100000.0 ) // "2024-07-08T02:53:20Z"
133- XCTAssert ( date. timeIntervalSinceReferenceDate < 3896300000.0 ) // "2124-06-21T01:33:20Z"
135+ #expect ( date. timeIntervalSinceReferenceDate > 742100000.0 ) // "2024-07-08T02:53:20Z"
136+ #expect ( date. timeIntervalSinceReferenceDate < 3896300000.0 ) // "2124-06-21T01:33:20Z"
134137 }
135138}
136139
137140// MARK: - Bridging
138141#if FOUNDATION_FRAMEWORK
139- final class DateBridgingTests : XCTestCase {
140- func testCast( ) {
142+ @Suite ( " Date Bridging " )
143+ private struct DateBridgingTests {
144+ @Test func cast( ) {
141145 let d0 = NSDate ( )
142146 let d1 = d0 as Date
143- XCTAssertEqual ( d0. timeIntervalSinceReferenceDate, d1. timeIntervalSinceReferenceDate)
147+ #expect ( d0. timeIntervalSinceReferenceDate == d1. timeIntervalSinceReferenceDate)
144148 }
145149
146- func test_AnyHashableCreatedFromNSDate ( ) {
150+ @ Test func anyHashableCreatedFromNSDate ( ) {
147151 let values : [ NSDate ] = [
148152 NSDate ( timeIntervalSince1970: 1000000000 ) ,
149153 NSDate ( timeIntervalSince1970: 1000000001 ) ,
150154 NSDate ( timeIntervalSince1970: 1000000001 ) ,
151155 ]
152156 let anyHashables = values. map ( AnyHashable . init)
153- expectEqual ( Date . self, type ( of: anyHashables [ 0 ] . base) )
154- expectEqual ( Date . self, type ( of: anyHashables [ 1 ] . base) )
155- expectEqual ( Date . self, type ( of: anyHashables [ 2 ] . base) )
156- XCTAssertNotEqual ( anyHashables [ 0 ] , anyHashables [ 1 ] )
157- XCTAssertEqual ( anyHashables [ 1 ] , anyHashables [ 2 ] )
157+ #expect ( Date . self == type ( of: anyHashables [ 0 ] . base) )
158+ #expect ( Date . self == type ( of: anyHashables [ 1 ] . base) )
159+ #expect ( Date . self == type ( of: anyHashables [ 2 ] . base) )
160+ #expect ( anyHashables [ 0 ] != anyHashables [ 1 ] )
161+ #expect ( anyHashables [ 1 ] == anyHashables [ 2 ] )
158162 }
159163
160- func test_AnyHashableCreatedFromNSDateComponents ( ) {
164+ @ Test func anyHashableCreatedFromNSDateComponents ( ) {
161165 func makeNSDateComponents( year: Int ) -> NSDateComponents {
162166 let result = NSDateComponents ( )
163167 result. year = year
@@ -169,15 +173,15 @@ final class DateBridgingTests : XCTestCase {
169173 makeNSDateComponents ( year: 1995 ) ,
170174 ]
171175 let anyHashables = values. map ( AnyHashable . init)
172- expectEqual ( DateComponents . self, type ( of: anyHashables [ 0 ] . base) )
173- expectEqual ( DateComponents . self, type ( of: anyHashables [ 1 ] . base) )
174- expectEqual ( DateComponents . self, type ( of: anyHashables [ 2 ] . base) )
175- XCTAssertNotEqual ( anyHashables [ 0 ] , anyHashables [ 1 ] )
176- XCTAssertEqual ( anyHashables [ 1 ] , anyHashables [ 2 ] )
176+ #expect ( DateComponents . self == type ( of: anyHashables [ 0 ] . base) )
177+ #expect ( DateComponents . self == type ( of: anyHashables [ 1 ] . base) )
178+ #expect ( DateComponents . self == type ( of: anyHashables [ 2 ] . base) )
179+ #expect ( anyHashables [ 0 ] != anyHashables [ 1 ] )
180+ #expect ( anyHashables [ 1 ] == anyHashables [ 2 ] )
177181 }
178182
179- func test_dateComponents_unconditionallyBridgeFromObjectiveC ( ) {
180- XCTAssertEqual ( DateComponents ( ) , DateComponents . _unconditionallyBridgeFromObjectiveC ( nil ) )
183+ @ Test func dateComponents_unconditionallyBridgeFromObjectiveC ( ) {
184+ #expect ( DateComponents ( ) == DateComponents . _unconditionallyBridgeFromObjectiveC ( nil ) )
181185 }
182186}
183187#endif // FOUNDATION_FRAMEWORK
0 commit comments