Skip to content

Commit

Permalink
Merge pull request #11 from to4iki/swift6
Browse files Browse the repository at this point in the history
Bump up to Swift6
  • Loading branch information
to4iki authored Nov 25, 2024
2 parents b89f044 + c710fdf commit 2a979da
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 34 deletions.
24 changes: 9 additions & 15 deletions Package.swift
Original file line number Diff line number Diff line change
@@ -1,36 +1,30 @@
// swift-tools-version: 5.10
// swift-tools-version: 6.0

import PackageDescription

let debugSwiftSettings: [PackageDescription.SwiftSetting] = [
.enableUpcomingFeature("ConciseMagicFile", .when(configuration: .debug)), // SE-0274
.enableUpcomingFeature("ForwardTrailingClosures", .when(configuration: .debug)), // SE-0286
.enableUpcomingFeature("ExistentialAny", .when(configuration: .debug)), // SE-0335
.enableUpcomingFeature("BareSlashRegexLiterals", .when(configuration: .debug)), // SE-0354
.enableUpcomingFeature("DeprecateApplicationMain", .when(configuration: .debug)), // SE-0383
.enableUpcomingFeature("ImportObjcForwardDeclarations", .when(configuration: .debug)), // SE-0384
.enableUpcomingFeature("DisableOutwardActorInference", .when(configuration: .debug)), // SE-0401
.enableUpcomingFeature("IsolatedDefaultValues", .when(configuration: .debug)), // SE-0411
.enableUpcomingFeature("GlobalConcurrency", .when(configuration: .debug)), // SE-0412
.enableUpcomingFeature("ExistentialAny", .when(configuration: .debug)) // SE-0335
]

let package = Package(
name: "ForcibleValue",
products: [
.library(
name: "ForcibleValue",
targets: ["ForcibleValue"])
targets: ["ForcibleValue"]
)
],
dependencies: [],
targets: [
.target(
name: "ForcibleValue",
dependencies: []),
dependencies: []
),
.testTarget(
name: "ForcibleValueTests",
dependencies: ["ForcibleValue"]),
],
swiftLanguageVersions: [.v5]
dependencies: ["ForcibleValue"]
),
]
)

for target in package.targets {
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 2a979da

Please sign in to comment.