Skip to content

Commit 41157a7

Browse files
committed
Test Binary AST Encoding/Decoding.
1 parent 14e462b commit 41157a7

File tree

3 files changed

+10
-3
lines changed

3 files changed

+10
-3
lines changed

Package.swift

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,10 @@ let package = Package(
116116

117117
.target(
118118
name: "Utils",
119-
dependencies: [.product(name: "BigInt", package: "BigInt")],
119+
dependencies: [
120+
.product(name: "BigInt", package: "BigInt"),
121+
.product(name: "CBORCoding", package: "CBORCoding")
122+
],
120123
swiftSettings: allTargetsSwiftSettings),
121124

122125
.target(

Sources/Utils/StatefulCoder.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import Foundation
2+
import CBORCoding
23

34
/// A key used to access the coding state of encoders/decoders.
45
private let stateKey = CodingUserInfoKey(rawValue: UUID().uuidString)!
@@ -112,6 +113,8 @@ extension JSONEncoder: StatefulEncoder {}
112113
extension JSONDecoder: StatefulDecoder {}
113114
extension PropertyListEncoder: StatefulEncoder {}
114115
extension PropertyListDecoder: StatefulDecoder {}
116+
extension CBOREncoder: StatefulEncoder {}
117+
extension CBORDecoder: StatefulDecoder {}
115118

116119
/// A (thread-unsafe) shared mutable wrapper for a `WrappedType` instance.
117120
///

Tests/HyloTests/ASTTests.swift

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import CBORCoding
12
import Core
23
import FrontEnd
34
import XCTest
@@ -52,11 +53,11 @@ final class ASTTests: XCTestCase {
5253
}
5354

5455
// Serialize the AST.
55-
let encoder = JSONEncoder().forAST
56+
let encoder = CBOREncoder().forAST
5657
let serialized = try encoder.encode(original)
5758

5859
// Deserialize the AST.
59-
let decoder = JSONDecoder().forAST
60+
let decoder = CBORDecoder().forAST
6061
let deserialized = try decoder.decode(AST.self, from: serialized)
6162

6263
// Deserialized AST should contain a `main` function.

0 commit comments

Comments
 (0)