File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -80,15 +80,6 @@ extension TransformedAttribute {
8080
8181 public func encode( to encoder: Encoder ) throws {
8282 var container = encoder. singleValueContainer ( )
83-
84- // See note in decode above about the weirdness
85- // going on here.
86- // let anyNil: Any? = nil
87- // let nilRawValue = anyNil as? Transformer.From
88- // guard rawValue != nilRawValue else {
89- // try container.encodeNil()
90- // return
91- // }
9283
9384 try container. encode ( rawValue)
9485 }
Original file line number Diff line number Diff line change @@ -29,6 +29,29 @@ class AttributeTests: XCTestCase {
2929 func test_TransformedAttributeReversNoThrow( ) {
3030 XCTAssertNoThrow ( try TransformedAttribute < String , TestTransformer > ( transformedValue: 10 ) )
3131 }
32+
33+ func test_NullableIsNullIfNil( ) {
34+ struct Wrapper : Codable {
35+ let dummy : Attribute < String ? >
36+ }
37+ let data = encoded ( value: Wrapper ( dummy: . init( value: nil ) ) )
38+ let string = String ( data: data, encoding: . utf8) !
39+
40+ XCTAssertEqual ( string, " { \" dummy \" :null} " )
41+ }
42+
43+ func test_NullableIsEqualToNonNullableIfNotNil( ) {
44+ struct Wrapper1 : Codable {
45+ let dummy : Attribute < String ? >
46+ }
47+ struct Wrapper2 : Codable {
48+ let dummy : Attribute < String >
49+ }
50+ let data1 = encoded ( value: Wrapper1 ( dummy: . init( value: " hello " ) ) )
51+ let data2 = encoded ( value: Wrapper2 ( dummy: . init( value: " hello " ) ) )
52+
53+ XCTAssertEqual ( data1, data2)
54+ }
3255}
3356
3457// MARK: Test types
Original file line number Diff line number Diff line change @@ -207,6 +207,8 @@ extension EntityTests {
207207 XCTAssertNil ( entity [ \. maybeHere] )
208208 XCTAssertNil ( entity [ \. maybeNull] )
209209 XCTAssertNoThrow ( try TestEntity6 . check ( entity) )
210+
211+ print ( encodable: entity)
210212 }
211213
212214 func test_entityOneNullAndOneOmittedAttribute_encode( ) {
You can’t perform that action at this time.
0 commit comments