@@ -54,6 +54,41 @@ class DefaultCodableTest_DateStrategy: XCTestCase {
54
54
}
55
55
}
56
56
57
+ // MARK: -
58
+ // MARK: Nested Property Wrapper
59
+
60
+ class DefaultCodableTest_NestedPropertyWrapper : XCTestCase {
61
+ enum DefaultToNowTimeStampDateValue : DefaultCodableStrategy {
62
+ static var defaultValue : DateValue < TimestampStrategy > {
63
+ . init( wrappedValue: Date ( timeIntervalSince1970: 0 ) )
64
+ }
65
+ }
66
+
67
+ struct Fixture : Codable {
68
+ @DefaultCodable < DefaultToNowTimeStampDateValue >
69
+ @DateValue < TimestampStrategy >
70
+ var returnDate : Date
71
+ }
72
+
73
+ func testNestedPropertyWrappersCanMergeDefaultCodableWithDateStrategy( ) throws {
74
+ let _1970 = Date ( timeIntervalSince1970: 0 )
75
+ let _1971 = Date ( timeIntervalSince1970: 31536000 )
76
+
77
+ let jsonData1 = #"{ "returnDate": null }"# . data ( using: . utf8) !
78
+ let jsonData2 = #"{ }"# . data ( using: . utf8) !
79
+ let jsonData3 = #"{ "returnDate": 31536000 }"# . data ( using: . utf8) !
80
+
81
+ let fixture1 = try JSONDecoder ( ) . decode ( Fixture . self, from: jsonData1)
82
+ let fixture2 = try JSONDecoder ( ) . decode ( Fixture . self, from: jsonData2)
83
+ let fixture3 = try JSONDecoder ( ) . decode ( Fixture . self, from: jsonData3)
84
+
85
+ XCTAssertEqual ( fixture1. returnDate, _1970)
86
+ XCTAssertEqual ( fixture2. returnDate, _1970)
87
+ XCTAssertEqual ( fixture3. returnDate, _1971)
88
+ }
89
+ }
90
+
91
+
57
92
// MARK: -
58
93
// MARK: Types with Containers
59
94
0 commit comments