@@ -893,27 +893,68 @@ struct KeyValueDecoderTests {
893893 #expect( ( true as NSNumber ) . getDoubleValue ( ) == nil )
894894 }
895895
896+ #if compiler(>=6.1)
897+ @Test ( )
898+ func decodingErrors( ) throws {
899+
900+ var error = #expect( throws: DecodingError . self) {
901+ try KeyValueDecoder . decode ( Seafood . self, from: 10 )
902+ }
903+ #expect( error? . debugDescription == " Expected String at SELF, found Int " )
904+
905+ error = #expect( throws: DecodingError . self) {
906+ try KeyValueDecoder . decode ( Seafood . self, from: 10 )
907+ }
908+ #expect( error? . debugDescription == " Expected String at SELF, found Int " )
909+
910+ error = #expect( throws: DecodingError . self) {
911+ try KeyValueDecoder . decode ( Int . self, from: NSNull ( ) )
912+ }
913+ #expect( error? . debugDescription == " Expected BinaryInteger at SELF, found NSNull " )
914+
915+ error = #expect( throws: DecodingError . self) {
916+ try KeyValueDecoder . decode ( Int . self, from: Optional< Int> . none)
917+ }
918+ #expect( error? . debugDescription == " Expected BinaryInteger at SELF, found nil " )
919+
920+ error = #expect( throws: DecodingError . self) {
921+ try KeyValueDecoder . decode ( [ Int ] . self, from: [ 0 , 1 , true ] as [ Any ] )
922+ }
923+ #expect( error? . debugDescription == " Expected BinaryInteger at SELF[2], found Bool " )
924+
925+ error = #expect( throws: DecodingError . self) {
926+ try KeyValueDecoder . decode ( AllTypes . self, from: [ " tArray " : [ [ " tString " : 0 ] ] ] as [ String : Any ] )
927+ }
928+ #expect( error? . debugDescription == " Expected String at SELF.tArray[0].tString, found Int " )
929+
930+ error = #expect( throws: DecodingError . self) {
931+ try KeyValueDecoder . decode ( AllTypes . self, from: [ " tArray " : [ [ " tString " : 0 ] ] ] as [ String : Any ] )
932+ }
933+ #expect( error? . debugDescription == " Expected String at SELF.tArray[0].tString, found Int " )
934+ }
935+ #else
896936 @Test ( )
897937 func decodingErrors( ) throws {
898938 expectDecodingError ( try KeyValueDecoder . decode ( Seafood . self, from: 10 ) ) { error in
899- // #expect(error.debugDescription == "Expected String at SELF, found Int")
939+ #expect( error. debugDescription == " Expected String at SELF, found Int " )
900940 }
901941 expectDecodingError ( try KeyValueDecoder . decode ( Int . self, from: NSNull ( ) ) ) { error in
902- // #expect(error.debugDescription == "Expected BinaryInteger at SELF, found NSNull")
942+ #expect( error. debugDescription == " Expected BinaryInteger at SELF, found NSNull " )
903943 }
904944 expectDecodingError ( try KeyValueDecoder . decode ( Int . self, from: Optional< Int> . none) ) { error in
905- // #expect(error.debugDescription == "Expected BinaryInteger at SELF, found nil")
945+ #expect( error. debugDescription == " Expected BinaryInteger at SELF, found nil " )
906946 }
907947 expectDecodingError ( try KeyValueDecoder . decode ( [ Int ] . self, from: [ 0 , 1 , true ] as [ Any ] ) ) { error in
908- // #expect(error.debugDescription == "Expected BinaryInteger at SELF[2], found Bool")
948+ #expect( error. debugDescription == " Expected BinaryInteger at SELF[2], found Bool " )
909949 }
910950 expectDecodingError ( try KeyValueDecoder . decode ( AllTypes . self, from: [ " tArray " : [ [ " tString " : 0 ] ] ] as [ String : Any ] ) ) { error in
911- // #expect(error.debugDescription == "Expected String at SELF.tArray[0].tString, found Int")
951+ #expect( error. debugDescription == " Expected String at SELF.tArray[0].tString, found Int " )
912952 }
913953 expectDecodingError ( try KeyValueDecoder . decode ( AllTypes . self, from: [ " tArray " : [ [ " tString " : 0 ] ] ] as [ String : Any ] ) ) { error in
914- // #expect(error.debugDescription == "Expected String at SELF.tArray[0].tString, found Int")
954+ #expect( error. debugDescription == " Expected String at SELF.tArray[0].tString, found Int " )
915955 }
916956 }
957+ #endif
917958
918959 @Test
919960 func int_ClampsDoubles( ) {
@@ -998,6 +1039,7 @@ struct KeyValueDecoderTests {
9981039 #endif
9991040}
10001041
1042+ #if compiler(<6.1)
10011043func expectDecodingError< T> ( _ expression: @autoclosure ( ) throws -> T ,
10021044 file: String = #filePath,
10031045 line: Int = #line,
@@ -1013,6 +1055,7 @@ func expectDecodingError<T>(_ expression: @autoclosure () throws -> T,
10131055 Issue . record ( error, " Expected DecodingError " , sourceLocation: location)
10141056 }
10151057}
1058+ #endif
10161059
10171060extension DecodingError {
10181061
0 commit comments