Skip to content

Commit 9cbe3b6

Browse files
committed
fix windows tests
1 parent f8ddb59 commit 9cbe3b6

File tree

1 file changed

+44
-1
lines changed

1 file changed

+44
-1
lines changed

Tests/KeyValueDecoderTests.swift

Lines changed: 44 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -892,7 +892,47 @@ struct KeyValueDecoderTests {
892892
#expect((true as NSNumber).getDoubleValue() == nil)
893893
}
894894

895-
@Test
895+
#if compiler(>=6.1)
896+
@Test()
897+
func decodingErrors() throws {
898+
899+
var error = #expect(throws: DecodingError.self) {
900+
try KeyValueDecoder.decode(Seafood.self, from: 10)
901+
}
902+
#expect(error?.debugDescription == "Expected String at SELF, found Int")
903+
904+
error = #expect(throws: DecodingError.self) {
905+
try KeyValueDecoder.decode(Seafood.self, from: 10)
906+
}
907+
#expect(error?.debugDescription == "Expected String at SELF, found Int")
908+
909+
error = #expect(throws: DecodingError.self) {
910+
try KeyValueDecoder.decode(Int.self, from: NSNull())
911+
}
912+
#expect(error?.debugDescription == "Expected BinaryInteger at SELF, found NSNull")
913+
914+
error = #expect(throws: DecodingError.self) {
915+
try KeyValueDecoder.decode(Int.self, from: Optional<Int>.none)
916+
}
917+
#expect(error?.debugDescription == "Expected BinaryInteger at SELF, found nil")
918+
919+
error = #expect(throws: DecodingError.self) {
920+
try KeyValueDecoder.decode([Int].self, from: [0, 1, true] as [Any])
921+
}
922+
#expect(error?.debugDescription == "Expected BinaryInteger at SELF[2], found Bool")
923+
924+
error = #expect(throws: DecodingError.self) {
925+
try KeyValueDecoder.decode(AllTypes.self, from: ["tArray": [["tString": 0]]] as [String: Any])
926+
}
927+
#expect(error?.debugDescription == "Expected String at SELF.tArray[0].tString, found Int")
928+
929+
error = #expect(throws: DecodingError.self) {
930+
try KeyValueDecoder.decode(AllTypes.self, from: ["tArray": [["tString": 0]]] as [String: Any])
931+
}
932+
#expect(error?.debugDescription == "Expected String at SELF.tArray[0].tString, found Int")
933+
}
934+
#else
935+
@Test()
896936
func decodingErrors() throws {
897937
expectDecodingError(try KeyValueDecoder.decode(Seafood.self, from: 10)) { error in
898938
#expect(error.debugDescription == "Expected String at SELF, found Int")
@@ -913,6 +953,7 @@ struct KeyValueDecoderTests {
913953
#expect(error.debugDescription == "Expected String at SELF.tArray[0].tString, found Int")
914954
}
915955
}
956+
#endif
916957

917958
@Test
918959
func int_ClampsDoubles() {
@@ -997,6 +1038,7 @@ struct KeyValueDecoderTests {
9971038
#endif
9981039
}
9991040

1041+
#if compiler(<6.1)
10001042
func expectDecodingError<T>(_ expression: @autoclosure () throws -> T,
10011043
file: String = #filePath,
10021044
line: Int = #line,
@@ -1012,6 +1054,7 @@ func expectDecodingError<T>(_ expression: @autoclosure () throws -> T,
10121054
Issue.record(error, "Expected DecodingError", sourceLocation: location)
10131055
}
10141056
}
1057+
#endif
10151058

10161059
extension DecodingError {
10171060

0 commit comments

Comments
 (0)