@@ -128,7 +128,6 @@ class TestPropertyListEncoder : TestPropertyListEncoderSuper {
128
128
_testRoundTrip ( of: TopLevelWrapper ( EnhancedBool . fileNotFound) , in: . xml)
129
129
}
130
130
131
- // MARK: - Multiple Nested Keys with the same top-level key Encoding Tests
132
131
func testEncodingMultipleNestedContainersWithTheSameTopLevelKey( ) {
133
132
struct Model : Codable , Equatable {
134
133
let first : String
@@ -180,39 +179,27 @@ class TestPropertyListEncoder : TestPropertyListEncoderSuper {
180
179
_testRoundTrip ( of: model, in: . xml, expectedPlist: expectedXML)
181
180
}
182
181
183
- func testEncodingConfilictedTypeNestedContainersWithTheSameTopLevelKey ( ) {
184
- struct Model : Codable , Equatable {
182
+ func testEncodingConflictedTypeNestedContainersWithTheSameTopLevelKey ( ) {
183
+ struct Model : Encodable , Equatable {
185
184
let first : String
186
- let second : String
187
-
188
- init ( from coder: Decoder ) throws {
189
- let container = try coder. container ( keyedBy: TopLevelCodingKeys . self)
190
-
191
- let firstNestedContainer = try container. nestedContainer ( keyedBy: FirstNestedCodingKeys . self, forKey: . top)
192
- self . first = try firstNestedContainer. decode ( String . self, forKey: . first)
193
-
194
- let secondNestedContainer = try container. nestedContainer ( keyedBy: SecondNestedCodingKeys . self, forKey: . top)
195
- self . second = try secondNestedContainer. decode ( String . self, forKey: . second)
196
- }
197
185
198
186
func encode( to encoder: Encoder ) throws {
199
187
var container = encoder. container ( keyedBy: TopLevelCodingKeys . self)
200
188
201
189
var firstNestedContainer = container. nestedContainer ( keyedBy: FirstNestedCodingKeys . self, forKey: . top)
202
190
try firstNestedContainer. encode ( self . first, forKey: . first)
203
191
192
+ // The following line would fail as it attempts to re-encode into already encoded container is invalid. This will always fail
204
193
var secondNestedContainer = container. nestedUnkeyedContainer ( forKey: . top)
205
- try secondNestedContainer. encode ( self . second)
194
+ try secondNestedContainer. encode ( " second " )
206
195
}
207
196
208
- init ( first: String , second : String ) {
197
+ init ( first: String ) {
209
198
self . first = first
210
- self . second = second
211
199
}
212
200
213
201
static var testValue : Model {
214
- return Model ( first: " Johnny Appleseed " ,
215
-
202
+ return Model ( first: " Johnny Appleseed " )
216
203
}
217
204
enum TopLevelCodingKeys : String , CodingKey {
218
205
case top
@@ -221,14 +208,11 @@ class TestPropertyListEncoder : TestPropertyListEncoderSuper {
221
208
enum FirstNestedCodingKeys : String , CodingKey {
222
209
case first
223
210
}
224
- enum SecondNestedCodingKeys : String , CodingKey {
225
- case second
226
- }
227
211
}
228
212
229
213
let model = Model . testValue
230
- let expectedXML = " <?xml version= \" 1.0 \" encoding= \" UTF-8 \" ?> \n <!DOCTYPE plist PUBLIC \" -//Apple//DTD PLIST 1.0//EN \" \" http://www.apple.com/DTDs/PropertyList-1.0.dtd \" > \n <plist version= \" 1.0 \" > \n <dict> \n \t <key>top</key> \n \t <dict> \n \t \t <key>first</key> \n \t \t <string>Johnny Appleseed</string> \n \t \t <key>second</key> \n \t \t <string>[email protected] </string> \n \t </dict> \n </dict> \n </plist> \n " . data ( using : . utf8 ) !
231
- _testRoundTrip ( of: model, in: . xml, expectedPlist : expectedXML )
214
+ // This following test would fail as it attempts to re-encode into already encoded container is invalid. This will always fail
215
+ _testEncodeFailure ( of: model, in: . xml)
232
216
}
233
217
234
218
// MARK: - Encoder Features
@@ -890,10 +874,10 @@ PropertyListEncoderTests.test("testEncodingTopLevelDeepStructuredType") { TestPr
890
874
PropertyListEncoderTests . test ( " testEncodingClassWhichSharesEncoderWithSuper " ) { TestPropertyListEncoder ( ) . testEncodingClassWhichSharesEncoderWithSuper ( ) }
891
875
PropertyListEncoderTests . test ( " testEncodingTopLevelNullableType " ) { TestPropertyListEncoder ( ) . testEncodingTopLevelNullableType ( ) }
892
876
PropertyListEncoderTests . test ( " testEncodingMultipleNestedContainersWithTheSameTopLevelKey " ) { TestPropertyListEncoder ( ) . testEncodingMultipleNestedContainersWithTheSameTopLevelKey ( ) }
893
- PropertyListEncoderTests . test ( " testEncodingConfilictedTypeNestedContainersWithTheSameTopLevelKey " )
877
+ PropertyListEncoderTests . test ( " testEncodingConflictedTypeNestedContainersWithTheSameTopLevelKey " )
894
878
. xfail ( . always( " Attempt to re-encode into already encoded container is invalid. This will always fail " ) )
895
879
. code {
896
- TestPropertyListEncoder ( ) . testEncodingConfilictedTypeNestedContainersWithTheSameTopLevelKey ( )
880
+ TestPropertyListEncoder ( ) . testEncodingConflictedTypeNestedContainersWithTheSameTopLevelKey ( )
897
881
}
898
882
PropertyListEncoderTests . test ( " testNestedContainerCodingPaths " ) { TestPropertyListEncoder ( ) . testNestedContainerCodingPaths ( ) }
899
883
PropertyListEncoderTests . test ( " testSuperEncoderCodingPaths " ) { TestPropertyListEncoder ( ) . testSuperEncoderCodingPaths ( ) }
0 commit comments