From c710fdf245369214ca4885df6de668992ec90217 Mon Sep 17 00:00:00 2001 From: Toshiki Takezawa Date: Tue, 26 Nov 2024 01:29:33 +0900 Subject: [PATCH] Update to Swift6.0 --- Package.swift | 2 +- .../ForcibleBoolTests.swift | 36 +++++++++++++++---- .../ForcibleNumberTests.swift | 11 +++--- .../ForcibleStringTests.swift | 9 +++-- Tests/ForcibleValueTests/TestCase.swift | 2 +- 5 files changed, 40 insertions(+), 20 deletions(-) diff --git a/Package.swift b/Package.swift index 3871f34..24cb69b 100644 --- a/Package.swift +++ b/Package.swift @@ -3,7 +3,7 @@ import PackageDescription let debugSwiftSettings: [PackageDescription.SwiftSetting] = [ - .enableUpcomingFeature("ExistentialAny", .when(configuration: .debug)), // SE-0335 + .enableUpcomingFeature("ExistentialAny", .when(configuration: .debug)) // SE-0335 ] let package = Package( diff --git a/Tests/ForcibleValueTests/ForcibleBoolTests.swift b/Tests/ForcibleValueTests/ForcibleBoolTests.swift index ed4765c..58e0b8c 100644 --- a/Tests/ForcibleValueTests/ForcibleBoolTests.swift +++ b/Tests/ForcibleValueTests/ForcibleBoolTests.swift @@ -18,14 +18,24 @@ struct ForcibleBoolTests { } @Test(arguments: [ - TestCase(input: false, output: false), - TestCase(input: true, output: true), TestCase(input: 0, output: false), TestCase(input: 1, output: true), + ]) + func decodeIntSuccess(testCase: TestCase) throws { + let json = """ + { + "value": \(testCase.input) + } + """.data(using: .utf8) + let target = try JSONDecoder().decode(Target.self, from: json!) + #expect(target.value == testCase.output) + } + + @Test(arguments: [ TestCase(input: "\"false\"", output: false), TestCase(input: "\"true\"", output: true), ]) - func decodeSuccess(testCase: TestCase) throws { + func decodeStringSuccess(testCase: TestCase) throws { let json = """ { "value": \(testCase.input) @@ -38,11 +48,23 @@ struct ForcibleBoolTests { @Test(arguments: [ TestCase(input: -1, output: ()), TestCase(input: 2, output: ()), + ]) + func decodeIntError(testCase: TestCase) throws { + let json = """ + { + "value": \(testCase.input) + } + """.data(using: .utf8) + #expect(throws: (any Error).self) { + try JSONDecoder().decode(Target.self, from: json!) + } + } + + @Test(arguments: [ TestCase(input: "\"f\"", output: ()), TestCase(input: "\"t\"", output: ()), - TestCase(input: 1.1, output: ()), ]) - func decodeError(testCase: TestCase) throws { + func decodeStringError(testCase: TestCase) throws { let json = """ { "value": \(testCase.input) @@ -57,7 +79,7 @@ struct ForcibleBoolTests { TestCase(input: nil, output: nil), TestCase(input: 0, output: false), ]) - func decodeOptionSuccess(testCase: TestCase) throws { + func decodeOptionSuccess(testCase: TestCase) throws { let json: Data? = { if let input = testCase.input { return """ @@ -77,7 +99,7 @@ struct ForcibleBoolTests { TestCase(input: nil, output: false), TestCase(input: 1, output: true), ]) - func decodeDefaultSuccess(testCase: TestCase) throws { + func decodeDefaultSuccess(testCase: TestCase) throws { let json: Data? = { if let input = testCase.input { return """ diff --git a/Tests/ForcibleValueTests/ForcibleNumberTests.swift b/Tests/ForcibleValueTests/ForcibleNumberTests.swift index 6079f32..c0132a6 100644 --- a/Tests/ForcibleValueTests/ForcibleNumberTests.swift +++ b/Tests/ForcibleValueTests/ForcibleNumberTests.swift @@ -18,10 +18,9 @@ struct ForcibleNumberTests { } @Test(arguments: [ - TestCase(input: 1, output: 1), - TestCase(input: "\"1\"", output: 1), + TestCase(input: "\"1\"", output: 1) ]) - func decodeSuccess(testCase: TestCase) throws { + func decodeSuccess(testCase: TestCase) throws { let json = """ { "value": \(testCase.input) @@ -34,7 +33,7 @@ struct ForcibleNumberTests { @Test(arguments: [ TestCase(input: "\"abc\"", output: ()) ]) - func decodeError(testCase: TestCase) throws { + func decodeError(testCase: TestCase) throws { let json = """ { "value": \(testCase.input) @@ -49,7 +48,7 @@ struct ForcibleNumberTests { TestCase(input: nil, output: nil), TestCase(input: "\"1\"", output: 1), ]) - func decodeOptionSuccess(testCase: TestCase) throws { + func decodeOptionSuccess(testCase: TestCase) throws { let json: Data? = { if let input = testCase.input { return """ @@ -69,7 +68,7 @@ struct ForcibleNumberTests { TestCase(input: nil, output: 0), TestCase(input: "\"1\"", output: 1), ]) - func decodeDefaultSuccess(testCase: TestCase) throws { + func decodeDefaultSuccess(testCase: TestCase) throws { let json: Data? = { if let input = testCase.input { return """ diff --git a/Tests/ForcibleValueTests/ForcibleStringTests.swift b/Tests/ForcibleValueTests/ForcibleStringTests.swift index 14fcc3a..948b7e8 100644 --- a/Tests/ForcibleValueTests/ForcibleStringTests.swift +++ b/Tests/ForcibleValueTests/ForcibleStringTests.swift @@ -18,11 +18,10 @@ struct ForcibleStringTests { } @Test(arguments: [ - TestCase(input: "\"string\"", output: "string"), TestCase(input: 1, output: "1"), TestCase(input: 1.1, output: "1.1"), ]) - func decodeSuccess(testCase: TestCase) throws { + func decodeSuccess(testCase: TestCase) throws { let json = """ { "value": \(testCase.input) @@ -36,7 +35,7 @@ struct ForcibleStringTests { TestCase(input: false, output: ()), TestCase(input: true, output: ()), ]) - func decodeError(testCase: TestCase) throws { + func decodeError(testCase: TestCase) throws { let json = """ { "value": \(testCase.input) @@ -51,7 +50,7 @@ struct ForcibleStringTests { TestCase(input: nil, output: nil), TestCase(input: 1, output: "1"), ]) - func decodeOptionSuccess(testCase: TestCase) throws { + func decodeOptionSuccess(testCase: TestCase) throws { let json: Data? = { if let input = testCase.input { return """ @@ -71,7 +70,7 @@ struct ForcibleStringTests { TestCase(input: nil, output: ""), TestCase(input: 1, output: "1"), ]) - func decodeDefaultSuccess(testCase: TestCase) throws { + func decodeDefaultSuccess(testCase: TestCase) throws { let json: Data? = { if let input = testCase.input { return """ diff --git a/Tests/ForcibleValueTests/TestCase.swift b/Tests/ForcibleValueTests/TestCase.swift index 3bd4790..1aa2dbf 100644 --- a/Tests/ForcibleValueTests/TestCase.swift +++ b/Tests/ForcibleValueTests/TestCase.swift @@ -1,4 +1,4 @@ -struct TestCase { +struct TestCase: Sendable { let input: Input let output: Output let description: String