Skip to content

Commit 6c3ff7e

Browse files
committed
add 'test_childTypeDecoder' to test 'JSONDecoder.decode(_,from:)'
1 parent cd6b05f commit 6c3ff7e

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

Tests/Foundation/Tests/TestJSONEncoder.swift

+19
Original file line numberDiff line numberDiff line change
@@ -474,6 +474,24 @@ class TestJSONEncoder : XCTestCase {
474474
XCTFail("Caught error during decoding empty super decoder: \(error)")
475475
}
476476
}
477+
478+
func test_childTypeDecoder() {
479+
class BaseTestType: Decodable { }
480+
class ChildTestType: BaseTestType { }
481+
482+
func dynamicTestType() -> BaseTestType.Type {
483+
return ChildTestType.self
484+
}
485+
486+
let decoder = JSONDecoder()
487+
do {
488+
let testType = dynamicTestType()
489+
let instance = try decoder.decode(testType, from: Data(#"{}"#.utf8))
490+
XCTAssertTrue(instance is ChildTestType)
491+
} catch {
492+
XCTFail("Caught error during decoding empty super decoder: \(error)")
493+
}
494+
}
477495

478496
// MARK: - Test encoding and decoding of built-in Codable types
479497
func test_codingOfBool() {
@@ -1562,6 +1580,7 @@ extension TestJSONEncoder {
15621580
("test_nestedContainerCodingPaths", test_nestedContainerCodingPaths),
15631581
("test_superEncoderCodingPaths", test_superEncoderCodingPaths),
15641582
("test_notFoundSuperDecoder", test_notFoundSuperDecoder),
1583+
("test_childTypeDecoder", test_childTypeDecoder),
15651584
("test_codingOfBool", test_codingOfBool),
15661585
("test_codingOfNil", test_codingOfNil),
15671586
("test_codingOfInt8", test_codingOfInt8),

0 commit comments

Comments
 (0)