Skip to content

Commit

Permalink
Update to Swift6.0
Browse files Browse the repository at this point in the history
  • Loading branch information
to4iki committed Nov 25, 2024
1 parent c58e172 commit c710fdf
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 20 deletions.
2 changes: 1 addition & 1 deletion Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
36 changes: 29 additions & 7 deletions Tests/ForcibleValueTests/ForcibleBoolTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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<Int, Bool>) 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<Any, Bool>) throws {
func decodeStringSuccess(testCase: TestCase<String, Bool>) throws {
let json = """
{
"value": \(testCase.input)
Expand All @@ -38,11 +48,23 @@ struct ForcibleBoolTests {
@Test(arguments: [
TestCase(input: -1, output: ()),
TestCase(input: 2, output: ()),
])
func decodeIntError(testCase: TestCase<Int, Void>) 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<Any, Void>) throws {
func decodeStringError(testCase: TestCase<String, Void>) throws {
let json = """
{
"value": \(testCase.input)
Expand All @@ -57,7 +79,7 @@ struct ForcibleBoolTests {
TestCase(input: nil, output: nil),
TestCase(input: 0, output: false),
])
func decodeOptionSuccess(testCase: TestCase<Any?, Bool?>) throws {
func decodeOptionSuccess(testCase: TestCase<Int?, Bool?>) throws {
let json: Data? = {
if let input = testCase.input {
return """
Expand All @@ -77,7 +99,7 @@ struct ForcibleBoolTests {
TestCase(input: nil, output: false),
TestCase(input: 1, output: true),
])
func decodeDefaultSuccess(testCase: TestCase<Any?, Bool>) throws {
func decodeDefaultSuccess(testCase: TestCase<Int?, Bool>) throws {
let json: Data? = {
if let input = testCase.input {
return """
Expand Down
11 changes: 5 additions & 6 deletions Tests/ForcibleValueTests/ForcibleNumberTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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<Any, Int>) throws {
func decodeSuccess(testCase: TestCase<String, Int>) throws {
let json = """
{
"value": \(testCase.input)
Expand All @@ -34,7 +33,7 @@ struct ForcibleNumberTests {
@Test(arguments: [
TestCase(input: "\"abc\"", output: ())
])
func decodeError(testCase: TestCase<Any, Void>) throws {
func decodeError(testCase: TestCase<String, Void>) throws {
let json = """
{
"value": \(testCase.input)
Expand All @@ -49,7 +48,7 @@ struct ForcibleNumberTests {
TestCase(input: nil, output: nil),
TestCase(input: "\"1\"", output: 1),
])
func decodeOptionSuccess(testCase: TestCase<Any?, Int?>) throws {
func decodeOptionSuccess(testCase: TestCase<String?, Int?>) throws {
let json: Data? = {
if let input = testCase.input {
return """
Expand All @@ -69,7 +68,7 @@ struct ForcibleNumberTests {
TestCase(input: nil, output: 0),
TestCase(input: "\"1\"", output: 1),
])
func decodeDefaultSuccess(testCase: TestCase<Any?, Int>) throws {
func decodeDefaultSuccess(testCase: TestCase<String?, Int>) throws {
let json: Data? = {
if let input = testCase.input {
return """
Expand Down
9 changes: 4 additions & 5 deletions Tests/ForcibleValueTests/ForcibleStringTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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<Any, String>) throws {
func decodeSuccess(testCase: TestCase<Double, String>) throws {
let json = """
{
"value": \(testCase.input)
Expand All @@ -36,7 +35,7 @@ struct ForcibleStringTests {
TestCase(input: false, output: ()),
TestCase(input: true, output: ()),
])
func decodeError(testCase: TestCase<Any, Void>) throws {
func decodeError(testCase: TestCase<Bool, Void>) throws {
let json = """
{
"value": \(testCase.input)
Expand All @@ -51,7 +50,7 @@ struct ForcibleStringTests {
TestCase(input: nil, output: nil),
TestCase(input: 1, output: "1"),
])
func decodeOptionSuccess(testCase: TestCase<Any?, String?>) throws {
func decodeOptionSuccess(testCase: TestCase<Int?, String?>) throws {
let json: Data? = {
if let input = testCase.input {
return """
Expand All @@ -71,7 +70,7 @@ struct ForcibleStringTests {
TestCase(input: nil, output: ""),
TestCase(input: 1, output: "1"),
])
func decodeDefaultSuccess(testCase: TestCase<Any?, String>) throws {
func decodeDefaultSuccess(testCase: TestCase<Int?, String>) throws {
let json: Data? = {
if let input = testCase.input {
return """
Expand Down
2 changes: 1 addition & 1 deletion Tests/ForcibleValueTests/TestCase.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
struct TestCase<Input, Output> {
struct TestCase<Input: Sendable, Output: Sendable>: Sendable {
let input: Input
let output: Output
let description: String
Expand Down

0 comments on commit c710fdf

Please sign in to comment.