@@ -28,8 +28,7 @@ struct JSONTests {
28
28
#expect( json [ " name " ] == " Jane Doe " )
29
29
#expect( json [ " age " ] == 30 )
30
30
#expect( json [ " isMember " ] == true )
31
- let t : String ? = json [ " nonExistentKey " ]
32
- #expect( t == nil )
31
+ #expect( json [ " nonExistentKey " ] == nil )
33
32
}
34
33
35
34
@Test ( " JSON getValue from [String:JSONValue] " )
@@ -39,8 +38,7 @@ struct JSONTests {
39
38
#expect( json [ " name " ] == " Jane Doe " )
40
39
#expect( json [ " age " ] == 30 )
41
40
#expect( json [ " isMember " ] == true )
42
- let t : String ? = json [ " nonExistentKey " ]
43
- #expect( t == nil )
41
+ #expect( json [ " nonExistentKey " ] == nil )
44
42
}
45
43
46
44
@Test ( " JSON getValue nested " )
@@ -50,17 +48,15 @@ struct JSONTests {
50
48
#expect( json [ " name " ] == " Jane Doe " )
51
49
#expect( json [ " age " ] == 30 )
52
50
#expect( json [ " isMember " ] == true )
53
- let t : String ? = json [ " nonExistentKey " ]
54
- #expect( t == nil )
51
+ #expect( json [ " nonExistentKey " ] == nil )
55
52
#expect( json [ " address " ] ? [ " street " ] == " 123 Main St " )
56
53
#expect( json [ " address " ] ? [ " city " ] == " Anytown " )
57
54
#expect( json [ " address " ] ? [ " state " ] == " CA " )
58
55
#expect( json [ " address " ] ? [ " zip " ] == 12345 )
59
56
#expect( json [ " address " ] ? [ " isSomething " ] == true )
60
- let t2 : String ? = json [ " address " ] ? [ " nonExistentKey " ]
61
- #expect( t2 == nil )
57
+ #expect( json [ " nonExistentKey " ] == nil )
62
58
}
63
- //
59
+
64
60
@Test ( " JSON Subscript " )
65
61
func jsonSubscript( ) async throws {
66
62
let json = try JSON (
@@ -92,8 +88,7 @@ struct JSONTests {
92
88
#expect( json [ " address " ] ? [ " state " ] == " CA " )
93
89
#expect( json [ " address " ] ? [ " zip " ] == 12345 )
94
90
#expect( json [ " address " ] ? [ " isSomething " ] == true )
95
- let t2 : String ? = json [ " address " ] ? [ " nonExistentKey " ]
96
- #expect( t2 == nil )
91
+ #expect( json [ " nonExistentKey " ] == nil )
97
92
}
98
93
99
94
@Test ( " JSON String Initializer with Invalid String " )
@@ -103,7 +98,6 @@ struct JSONTests {
103
98
" name " : " Jane Doe " ,
104
99
" age " : 30,
105
100
" isMember " : true,
106
-
107
101
""" // Note: trailing comma and no closing brace, making this invalid
108
102
#expect( throws: BedrockLibraryError . self) {
109
103
let _ = try JSON ( from: invalidJSONString)
@@ -114,24 +108,26 @@ struct JSONTests {
114
108
func emptyJSON( ) async throws {
115
109
#expect( throws: Never . self) {
116
110
let json = try JSON ( from: " " )
117
- let t : String ? = json [ " nonExistentKey " ]
118
- #expect( t == nil )
111
+ #expect( json [ " nonExistentKey " ] == nil )
119
112
}
120
113
}
121
114
122
115
@Test ( " Nested JSONValue " )
123
116
func nestedJSONValue( ) {
124
- JSON (
117
+ let json = JSON (
125
118
with: JSONValue ( [
126
119
" name " : JSONValue ( " Jane Doe " ) ,
127
120
" age " : JSONValue ( 30 ) ,
128
121
" isMember " : JSONValue ( true ) ,
129
122
] )
130
123
)
131
-
124
+ #expect( json [ " name " ] == " Jane Doe " )
125
+ #expect( json [ " age " ] == 30 )
126
+ #expect( json [ " isMember " ] == true )
132
127
}
133
128
}
134
129
130
+ // Fixtures
135
131
extension JSONTests {
136
132
private func jsonFromString( ) throws -> JSON {
137
133
try JSON (
0 commit comments