@@ -51,6 +51,38 @@ final class AppStorageTests: XCTestCase {
51
51
XCTAssertEqual ( defaults. url ( forKey: " url " ) , URL ( string: " https://example.com " ) )
52
52
}
53
53
54
+ func testDefaultsReadDate( ) {
55
+ let expectedDate = Date ( )
56
+ @Dependency ( \. defaultAppStorage) var defaults
57
+ defaults. set ( expectedDate, forKey: " date " )
58
+ @Shared ( . appStorage( " date " ) ) var date : Date ?
59
+ XCTAssertEqual ( date, expectedDate)
60
+ }
61
+
62
+ func testDefaultsRegistered_Date( ) {
63
+ let expectedDate = Date ( )
64
+ @Dependency ( \. defaultAppStorage) var defaults
65
+ @Shared ( . appStorage( " date " ) ) var date : Date = expectedDate
66
+ XCTAssertEqual ( defaults. object ( forKey: " date " ) as? Date , expectedDate)
67
+
68
+ let newDate = Date ( ) . addingTimeInterval ( 60 )
69
+ date = newDate
70
+ XCTAssertEqual ( date, newDate)
71
+ XCTAssertEqual ( defaults. object ( forKey: " date " ) as? Date , newDate)
72
+ }
73
+
74
+ func testDefaultsRegistered_Optional_Date( ) {
75
+ let initialDate : Date ? = Date ( )
76
+ @Dependency ( \. defaultAppStorage) var defaults
77
+ @Shared ( . appStorage( " date " ) ) var date : Date ? = initialDate
78
+ XCTAssertEqual ( defaults. object ( forKey: " date " ) as? Date , initialDate)
79
+
80
+ let newDate = Date ( ) . addingTimeInterval ( 60 )
81
+ date = newDate
82
+ XCTAssertEqual ( date, newDate)
83
+ XCTAssertEqual ( defaults. object ( forKey: " date " ) as? Date , newDate)
84
+ }
85
+
54
86
func testDefaultsRegistered_Optional( ) {
55
87
@Dependency ( \. defaultAppStorage) var defaults
56
88
@Shared ( . appStorage( " data " ) ) var data : Data ?
@@ -184,6 +216,13 @@ final class AppStorageTests: XCTestCase {
184
216
XCTAssertEqual ( url2, nil )
185
217
}
186
218
219
+ func testOptionalInitializers_Date( ) {
220
+ @Shared ( . appStorage( " date1 " ) ) var date1 : Date ?
221
+ XCTAssertEqual ( date1, nil )
222
+ @Shared ( . appStorage( " date2 " ) ) var date2 : Date ? = nil
223
+ XCTAssertEqual ( date2, nil )
224
+ }
225
+
187
226
func testRemoveDuplicates( ) {
188
227
@Dependency ( \. defaultAppStorage) var store
189
228
@Shared ( . appStorage( " count " ) ) var count = 0
0 commit comments