Skip to content

Commit 727e65d

Browse files
authored
Try to fix compiler crash when running JSONTest (#44)
* refactor JSON * remove Any? on JSON * fix remaining tests * [ci] run builds and test in parallel * simplify testing * try to fix crash in tests
1 parent abad720 commit 727e65d

File tree

3 files changed

+16
-17
lines changed

3 files changed

+16
-17
lines changed

Sources/Converse/ContentBlocks/JSON.swift

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,6 @@ public struct JSON: Codable, Sendable {
177177

178178
public init(from data: Data) throws {
179179
do {
180-
print(String(decoding: data, as: UTF8.self))
181180
self = try JSONDecoder().decode(JSON.self, from: data)
182181
} catch {
183182
throw BedrockLibraryError.decodingError("Failed to decode JSON: \(error)")

Tests/BedrockServiceTests.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@ struct BedrockServiceTests {
2323
let bedrock: BedrockService
2424

2525
init() async throws {
26+
// this is a workaround for issue
27+
// https://github.com/awslabs/aws-sdk-swift/issues/1984
28+
CommonRuntimeKit.initialize()
29+
2630
self.bedrock = try await BedrockService(
2731
bedrockClient: MockBedrockClient(),
2832
bedrockRuntimeClient: MockBedrockRuntimeClient()

Tests/Converse/JSONTests.swift

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,7 @@ struct JSONTests {
2828
#expect(json["name"] == "Jane Doe")
2929
#expect(json["age"] == 30)
3030
#expect(json["isMember"] == true)
31-
let t: String? = json["nonExistentKey"]
32-
#expect(t == nil)
31+
#expect(json["nonExistentKey"] == nil)
3332
}
3433

3534
@Test("JSON getValue from [String:JSONValue]")
@@ -39,8 +38,7 @@ struct JSONTests {
3938
#expect(json["name"] == "Jane Doe")
4039
#expect(json["age"] == 30)
4140
#expect(json["isMember"] == true)
42-
let t: String? = json["nonExistentKey"]
43-
#expect(t == nil)
41+
#expect(json["nonExistentKey"] == nil)
4442
}
4543

4644
@Test("JSON getValue nested")
@@ -50,17 +48,15 @@ struct JSONTests {
5048
#expect(json["name"] == "Jane Doe")
5149
#expect(json["age"] == 30)
5250
#expect(json["isMember"] == true)
53-
let t: String? = json["nonExistentKey"]
54-
#expect(t == nil)
51+
#expect(json["nonExistentKey"] == nil)
5552
#expect(json["address"]?["street"] == "123 Main St")
5653
#expect(json["address"]?["city"] == "Anytown")
5754
#expect(json["address"]?["state"] == "CA")
5855
#expect(json["address"]?["zip"] == 12345)
5956
#expect(json["address"]?["isSomething"] == true)
60-
let t2: String? = json["address"]?["nonExistentKey"]
61-
#expect(t2 == nil)
57+
#expect(json["nonExistentKey"] == nil)
6258
}
63-
//
59+
6460
@Test("JSON Subscript")
6561
func jsonSubscript() async throws {
6662
let json = try JSON(
@@ -92,8 +88,7 @@ struct JSONTests {
9288
#expect(json["address"]?["state"] == "CA")
9389
#expect(json["address"]?["zip"] == 12345)
9490
#expect(json["address"]?["isSomething"] == true)
95-
let t2: String? = json["address"]?["nonExistentKey"]
96-
#expect(t2 == nil)
91+
#expect(json["nonExistentKey"] == nil)
9792
}
9893

9994
@Test("JSON String Initializer with Invalid String")
@@ -103,7 +98,6 @@ struct JSONTests {
10398
"name": "Jane Doe",
10499
"age": 30,
105100
"isMember": true,
106-
107101
""" // Note: trailing comma and no closing brace, making this invalid
108102
#expect(throws: BedrockLibraryError.self) {
109103
let _ = try JSON(from: invalidJSONString)
@@ -114,24 +108,26 @@ struct JSONTests {
114108
func emptyJSON() async throws {
115109
#expect(throws: Never.self) {
116110
let json = try JSON(from: "")
117-
let t: String? = json["nonExistentKey"]
118-
#expect(t == nil)
111+
#expect(json["nonExistentKey"] == nil)
119112
}
120113
}
121114

122115
@Test("Nested JSONValue")
123116
func nestedJSONValue() {
124-
JSON(
117+
let json = JSON(
125118
with: JSONValue([
126119
"name": JSONValue("Jane Doe"),
127120
"age": JSONValue(30),
128121
"isMember": JSONValue(true),
129122
])
130123
)
131-
124+
#expect(json["name"] == "Jane Doe")
125+
#expect(json["age"] == 30)
126+
#expect(json["isMember"] == true)
132127
}
133128
}
134129

130+
// Fixtures
135131
extension JSONTests {
136132
private func jsonFromString() throws -> JSON {
137133
try JSON(

0 commit comments

Comments
 (0)