6
6
//
7
7
8
8
import Foundation
9
+ import XCTest
10
+
11
+ @testable import JMESPath
9
12
10
- import Foundation
11
13
#if os(Linux)
12
- import FoundationNetworking
14
+ import FoundationNetworking
13
15
#endif
14
- @testable import JMESPath
15
- import XCTest
16
16
17
17
public struct AnyDecodable : Decodable {
18
18
public let value : Any
@@ -22,8 +22,8 @@ public struct AnyDecodable: Decodable {
22
22
}
23
23
}
24
24
25
- public extension AnyDecodable {
26
- init ( from decoder: Decoder ) throws {
25
+ extension AnyDecodable {
26
+ public init ( from decoder: Decoder ) throws {
27
27
let container = try decoder. singleValueContainer ( )
28
28
29
29
if container. decodeNil ( ) {
@@ -43,7 +43,8 @@ public extension AnyDecodable {
43
43
} else if let dictionary = try ? container. decode ( [ String : AnyDecodable ] . self) {
44
44
self . init ( dictionary. mapValues { $0. value } )
45
45
} else {
46
- throw DecodingError . dataCorruptedError ( in: container, debugDescription: " AnyDecodable value cannot be decoded " )
46
+ throw DecodingError . dataCorruptedError (
47
+ in: container, debugDescription: " AnyDecodable value cannot be decoded " )
47
48
}
48
49
}
49
50
}
@@ -67,7 +68,7 @@ final class ComplianceTests: XCTestCase {
67
68
@available ( iOS 11 . 0 , tvOS 11 . 0 , watchOS 5 . 0 , * )
68
69
func run( ) throws {
69
70
for c in self . cases {
70
- if let _ = c. bench {
71
+ if c. bench != nil {
71
72
self . testBenchmark ( c)
72
73
} else if let error = c. error {
73
74
self . testError ( c, error: error)
@@ -106,11 +107,13 @@ final class ComplianceTests: XCTestCase {
106
107
let expression = try JMESExpression . compile ( c. expression)
107
108
108
109
let resultJson : String ? = try result. map {
109
- let data = try JSONSerialization . data ( withJSONObject: $0, options: [ . fragmentsAllowed, . sortedKeys] )
110
+ let data = try JSONSerialization . data (
111
+ withJSONObject: $0, options: [ . fragmentsAllowed, . sortedKeys] )
110
112
return String ( decoding: data, as: Unicode . UTF8. self)
111
113
}
112
114
if let value = try expression. search ( object: self . given. value) {
113
- let valueData = try JSONSerialization . data ( withJSONObject: value, options: [ . fragmentsAllowed, . sortedKeys] )
115
+ let valueData = try JSONSerialization . data (
116
+ withJSONObject: value, options: [ . fragmentsAllowed, . sortedKeys] )
114
117
let valueJson = String ( decoding: valueData, as: Unicode . UTF8. self)
115
118
XCTAssertEqual ( resultJson, valueJson)
116
119
} else {
@@ -124,7 +127,8 @@ final class ComplianceTests: XCTestCase {
124
127
@available ( iOS 11 . 0 , tvOS 11 . 0 , watchOS 5 . 0 , * )
125
128
func output( _ c: Case , expected: String ? , result: String ? ) {
126
129
if expected != result {
127
- let data = try ! JSONSerialization . data ( withJSONObject: self . given. value, options: [ . fragmentsAllowed, . sortedKeys] )
130
+ let data = try ! JSONSerialization . data (
131
+ withJSONObject: self . given. value, options: [ . fragmentsAllowed, . sortedKeys] )
128
132
let givenJson = String ( decoding: data, as: Unicode . UTF8. self)
129
133
if let comment = c. comment {
130
134
print ( " Comment: \( comment) " )
@@ -137,13 +141,16 @@ final class ComplianceTests: XCTestCase {
137
141
}
138
142
}
139
143
140
- func testCompliance( name: String , ignoring: [ String ] = [ ] ) throws {
141
- let url = URL ( string: " https://raw.githubusercontent.com/jmespath/jmespath.test/master/tests/ \( name) .json " ) !
142
- try testCompliance ( url: url, ignoring: ignoring)
144
+ func testCompliance( name: String , ignoring: [ String ] = [ ] ) async throws {
145
+ let url = URL (
146
+ string:
147
+ " https://raw.githubusercontent.com/jmespath/jmespath.test/master/tests/ \( name) .json "
148
+ ) !
149
+ try await testCompliance ( url: url, ignoring: ignoring)
143
150
}
144
151
145
- func testCompliance( url: URL , ignoring: [ String ] = [ ] ) throws {
146
- let data = try Data ( contentsOf : url)
152
+ func testCompliance( url: URL , ignoring: [ String ] = [ ] ) async throws {
153
+ let ( data, _ ) = try await URLSession . shared . data ( from : url, delegate : nil )
147
154
let tests = try JSONDecoder ( ) . decode ( [ ComplianceTest ] . self, from: data)
148
155
149
156
if #available( iOS 11 . 0 , tvOS 11 . 0 , watchOS 5 . 0 , * ) {
@@ -153,67 +160,67 @@ final class ComplianceTests: XCTestCase {
153
160
}
154
161
}
155
162
156
- func testBasic( ) throws {
157
- try self . testCompliance ( name: " basic " )
163
+ func testBasic( ) async throws {
164
+ try await self . testCompliance ( name: " basic " )
158
165
}
159
166
160
- func testBenchmarks( ) throws {
161
- try self . testCompliance ( name: " benchmarks " )
167
+ func testBenchmarks( ) async throws {
168
+ try await self . testCompliance ( name: " benchmarks " )
162
169
}
163
170
164
- func testBoolean( ) throws {
165
- try self . testCompliance ( name: " boolean " )
171
+ func testBoolean( ) async throws {
172
+ try await self . testCompliance ( name: " boolean " )
166
173
}
167
174
168
- func testCurrent( ) throws {
169
- try self . testCompliance ( name: " current " )
175
+ func testCurrent( ) async throws {
176
+ try await self . testCompliance ( name: " current " )
170
177
}
171
178
172
- func testEscape( ) throws {
173
- try self . testCompliance ( name: " escape " )
179
+ func testEscape( ) async throws {
180
+ try await self . testCompliance ( name: " escape " )
174
181
}
175
182
176
- func testFilters( ) throws {
177
- try self . testCompliance ( name: " filters " )
183
+ func testFilters( ) async throws {
184
+ try await self . testCompliance ( name: " filters " )
178
185
}
179
186
180
- func testFunctions( ) throws {
181
- try self . testCompliance ( name: " functions " )
187
+ func testFunctions( ) async throws {
188
+ try await self . testCompliance ( name: " functions " )
182
189
}
183
190
184
- func testIdentifiers( ) throws {
185
- try self . testCompliance ( name: " identifiers " )
191
+ func testIdentifiers( ) async throws {
192
+ try await self . testCompliance ( name: " identifiers " )
186
193
}
187
194
188
- func testIndices( ) throws {
189
- try self . testCompliance ( name: " indices " )
195
+ func testIndices( ) async throws {
196
+ try await self . testCompliance ( name: " indices " )
190
197
}
191
198
192
- func testLiteral( ) throws {
193
- try self . testCompliance ( name: " literal " )
199
+ func testLiteral( ) async throws {
200
+ try await self . testCompliance ( name: " literal " )
194
201
}
195
202
196
- func testMultiSelect( ) throws {
197
- try self . testCompliance ( name: " multiselect " )
203
+ func testMultiSelect( ) async throws {
204
+ try await self . testCompliance ( name: " multiselect " )
198
205
}
199
206
200
- func testPipe( ) throws {
201
- try self . testCompliance ( name: " pipe " )
207
+ func testPipe( ) async throws {
208
+ try await self . testCompliance ( name: " pipe " )
202
209
}
203
210
204
- func testSlice( ) throws {
205
- try self . testCompliance ( name: " slice " )
211
+ func testSlice( ) async throws {
212
+ try await self . testCompliance ( name: " slice " )
206
213
}
207
214
208
- func testSyntax( ) throws {
209
- try self . testCompliance ( name: " syntax " )
215
+ func testSyntax( ) async throws {
216
+ try await self . testCompliance ( name: " syntax " )
210
217
}
211
218
212
- func testUnicode( ) throws {
213
- try self . testCompliance ( name: " unicode " )
219
+ func testUnicode( ) async throws {
220
+ try await self . testCompliance ( name: " unicode " )
214
221
}
215
222
216
- func testWildcards( ) throws {
217
- try self . testCompliance ( name: " wildcard " )
223
+ func testWildcards( ) async throws {
224
+ try await self . testCompliance ( name: " wildcard " )
218
225
}
219
226
}
0 commit comments