Skip to content

Commit 89b6187

Browse files
PJ FechnerPJ Fechner
PJ Fechner
authored and
PJ Fechner
committed
Testing
1 parent 79d9274 commit 89b6187

File tree

5 files changed

+50
-37
lines changed

5 files changed

+50
-37
lines changed

Package.swift

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ let package = Package(
2727
dependencies: [
2828
.package(url: "https://github.com/Quick/Nimble.git", .upToNextMajor(from: "13.0.0")),
2929
.package(url: "https://github.com/Quick/Quick.git", .upToNextMajor(from: "7.6.0")),
30+
// .package(url: "https://github.com/swiftlang/swift-testing.git", .upToNextMajor(from: "6.0.0")),
3031
// swiftlint is kinda big to pull in and build right now...maybe later
3132
// .package(url: "https://github.com/realm/SwiftLint.git", .upToNextMajor(from: "0.52.0")),
3233
.package(url: "https://github.com/swiftlang/swift-syntax.git", "508.0.0"..."600.0.1"),
@@ -37,11 +38,13 @@ let package = Package(
3738
targets: [
3839
.target(
3940
name: "CodableWrappers",
40-
dependencies: ["CodableWrapperMacros"],
41+
dependencies: ["CodableWrapperMacros",
42+
// .product(name: "Testing", package: "swift-testing"),
43+
],
4144
swiftSettings: [
4245
.enableExperimentalFeature("StrictConcurrency")
4346
]),
44-
// plugins: [.plugin(name: "SwiftLintPlugin", package: "SwiftLint")]),
47+
// plugins: [.plugin(name: "SwiftLintPlugin", package: "SwifutLint")]),
4548

4649
.testTarget(
4750
name: "CodableWrappersTests",

Tests/CodableWrappersTests/Decoder/DecodingTestSpec.swift

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,20 @@ import Foundation
1010
import Quick
1111
import Nimble
1212

13+
protocol CodingTests: DecodingTests, EncodingTests { }
14+
extension CodingTests {
15+
16+
static var emptyJSON: String { "{\n\n}" }
17+
static var emptyPList: String { """
18+
<?xml version="1.0" encoding="UTF-8"?>
19+
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
20+
<plist version="1.0">
21+
<dict/>
22+
</plist>
23+
"""
24+
}
25+
}
26+
1327
protocol CodingTestSpec {
1428

1529
}
@@ -26,12 +40,16 @@ extension CodingTestSpec {
2640
}
2741
}
2842

29-
protocol DecodingTestSpec: CodingTestSpec {
43+
protocol DecodingTests {
3044
static var jsonDecoder: JSONDecoder { get }
3145
static var plistDecoder: PropertyListDecoder { get }
3246
}
3347

34-
extension DecodingTestSpec {
48+
protocol DecodingTestSpec: DecodingTests, CodingTestSpec {
49+
50+
}
51+
52+
extension DecodingTests {
3553
static var jsonDecoder: JSONDecoder {
3654
let decoder = JSONDecoder()
3755
decoder.dateDecodingStrategy = .secondsSince1970

Tests/CodableWrappersTests/Encoder/EncodingTestSpec.swift

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,14 @@
99
import Foundation
1010
import Quick
1111
import Nimble
12-
13-
protocol EncodingTestSpec: CodingTestSpec {
12+
protocol EncodingTests {
1413
static var jsonEncoder: JSONEncoder { get }
1514
static var plistEncoder: PropertyListEncoder { get }
1615
}
1716

18-
extension EncodingTestSpec {
17+
protocol EncodingTestSpec: EncodingTests, CodingTestSpec { }
18+
19+
extension EncodingTests {
1920
static var jsonEncoder: JSONEncoder {
2021
let encoder = JSONEncoder()
2122
// if #available(OSX 10.13, *) {

Tests/CodableWrappersTests/PartialImplementationTests.swift

Lines changed: 20 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -7,36 +7,27 @@
77

88
import CodableWrappers
99
import Foundation
10-
import Quick
11-
import Nimble
10+
//import Quick
11+
//import Nimble
1212

13-
class CompositionTests: QuickSpec, DecodingTestSpec, EncodingTestSpec {
14-
override class func spec() {
15-
describe("StaticCoder") {
16-
context("OnlyCustomDecoding") {
17-
it("EncodesWithDefault") {
18-
let currentDate = Date()
19-
let encodingModel = DecodingModel(time: currentDate)
20-
let encoded = try! self.jsonEncoder.encode(encodingModel)
21-
expect {_ = try self.jsonDecoder.decode(DecodingModel.self, from: encoded)}.toNot(throwError())
22-
let decoded = try? self.jsonDecoder.decode(DecodingModel.self, from: encoded)
23-
expect(decoded).toNot(beNil())
24-
// This means it was decoded using the SecondsSince1970DateDecoding, but encoded using the default
25-
expect(decoded?.time.timeIntervalSince1970) == currentDate.timeIntervalSinceReferenceDate
26-
}
27-
}
28-
context("OnlyCustomEncoding") {
29-
it("DecodesWithDefault") {
30-
let currentDate = Date()
31-
let encodingModel = EncodingModel(time: currentDate)
32-
let encoded = try! self.jsonEncoder.encode(encodingModel)
33-
expect {_ = try self.jsonDecoder.decode(EncodingModel.self, from: encoded)}.toNot(throwError())
34-
let decoded = try? self.jsonDecoder.decode(EncodingModel.self, from: encoded)
35-
expect(decoded).toNot(beNil())
36-
// This means it was decoded using the SecondsSince1970DateDecoding, but encoded using the default
37-
expect(decoded?.time.timeIntervalSinceReferenceDate) == currentDate.timeIntervalSince1970
38-
}
39-
}
13+
import Testing
14+
15+
struct CompositionTest {
16+
struct StaticCoder: CodingTests {
17+
@Test func customDecodingEncodesWithDefaults() async throws {
18+
let currentDate = Date()
19+
let encodingModel = DecodingModel(time: currentDate)
20+
let encoded = try Self.jsonEncoder.encode(encodingModel)
21+
let decoded = try Self.jsonDecoder.decode(DecodingModel.self, from: encoded)
22+
#expect(decoded.time.timeIntervalSince1970 == currentDate.timeIntervalSinceReferenceDate)
23+
}
24+
25+
@Test func customEncodingDecodesWithDefaults() async throws {
26+
let currentDate = Date()
27+
let encodingModel = EncodingModel(time: currentDate)
28+
let encoded = try Self.jsonEncoder.encode(encodingModel)
29+
let decoded = try Self.jsonDecoder.decode(EncodingModel.self, from: encoded)
30+
#expect(decoded.time.timeIntervalSinceReferenceDate == currentDate.timeIntervalSince1970)
4031
}
4132
}
4233
}

Tests/LinuxMain.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ let allTestClasses = [
2525
EmptyDefaultsEncodingTests.self,
2626
NullEncodingTests.self,
2727
OptionalEncodingTests.self,
28-
CompositionTests.self,
28+
// CompositionTests.self,
2929
PartialImplementationTests.self,
3030
]
3131
#if os(Linux)

0 commit comments

Comments
 (0)