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,20 @@ 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
+ #if compiler(>=6.0)
154
+ let ( data, _) = try await URLSession . shared. data ( from: url, delegate: nil )
155
+ #else
156
+ let data = try Data ( contentsOf: url)
157
+ #endif
147
158
let tests = try JSONDecoder ( ) . decode ( [ ComplianceTest ] . self, from: data)
148
159
149
160
if #available( iOS 11 . 0 , tvOS 11 . 0 , watchOS 5 . 0 , * ) {
@@ -153,67 +164,67 @@ final class ComplianceTests: XCTestCase {
153
164
}
154
165
}
155
166
156
- func testBasic( ) throws {
157
- try self . testCompliance ( name: " basic " )
167
+ func testBasic( ) async throws {
168
+ try await self . testCompliance ( name: " basic " )
158
169
}
159
170
160
- func testBenchmarks( ) throws {
161
- try self . testCompliance ( name: " benchmarks " )
171
+ func testBenchmarks( ) async throws {
172
+ try await self . testCompliance ( name: " benchmarks " )
162
173
}
163
174
164
- func testBoolean( ) throws {
165
- try self . testCompliance ( name: " boolean " )
175
+ func testBoolean( ) async throws {
176
+ try await self . testCompliance ( name: " boolean " )
166
177
}
167
178
168
- func testCurrent( ) throws {
169
- try self . testCompliance ( name: " current " )
179
+ func testCurrent( ) async throws {
180
+ try await self . testCompliance ( name: " current " )
170
181
}
171
182
172
- func testEscape( ) throws {
173
- try self . testCompliance ( name: " escape " )
183
+ func testEscape( ) async throws {
184
+ try await self . testCompliance ( name: " escape " )
174
185
}
175
186
176
- func testFilters( ) throws {
177
- try self . testCompliance ( name: " filters " )
187
+ func testFilters( ) async throws {
188
+ try await self . testCompliance ( name: " filters " )
178
189
}
179
190
180
- func testFunctions( ) throws {
181
- try self . testCompliance ( name: " functions " )
191
+ func testFunctions( ) async throws {
192
+ try await self . testCompliance ( name: " functions " )
182
193
}
183
194
184
- func testIdentifiers( ) throws {
185
- try self . testCompliance ( name: " identifiers " )
195
+ func testIdentifiers( ) async throws {
196
+ try await self . testCompliance ( name: " identifiers " )
186
197
}
187
198
188
- func testIndices( ) throws {
189
- try self . testCompliance ( name: " indices " )
199
+ func testIndices( ) async throws {
200
+ try await self . testCompliance ( name: " indices " )
190
201
}
191
202
192
- func testLiteral( ) throws {
193
- try self . testCompliance ( name: " literal " )
203
+ func testLiteral( ) async throws {
204
+ try await self . testCompliance ( name: " literal " )
194
205
}
195
206
196
- func testMultiSelect( ) throws {
197
- try self . testCompliance ( name: " multiselect " )
207
+ func testMultiSelect( ) async throws {
208
+ try await self . testCompliance ( name: " multiselect " )
198
209
}
199
210
200
- func testPipe( ) throws {
201
- try self . testCompliance ( name: " pipe " )
211
+ func testPipe( ) async throws {
212
+ try await self . testCompliance ( name: " pipe " )
202
213
}
203
214
204
- func testSlice( ) throws {
205
- try self . testCompliance ( name: " slice " )
215
+ func testSlice( ) async throws {
216
+ try await self . testCompliance ( name: " slice " )
206
217
}
207
218
208
- func testSyntax( ) throws {
209
- try self . testCompliance ( name: " syntax " )
219
+ func testSyntax( ) async throws {
220
+ try await self . testCompliance ( name: " syntax " )
210
221
}
211
222
212
- func testUnicode( ) throws {
213
- try self . testCompliance ( name: " unicode " )
223
+ func testUnicode( ) async throws {
224
+ try await self . testCompliance ( name: " unicode " )
214
225
}
215
226
216
- func testWildcards( ) throws {
217
- try self . testCompliance ( name: " wildcard " )
227
+ func testWildcards( ) async throws {
228
+ try await self . testCompliance ( name: " wildcard " )
218
229
}
219
230
}
0 commit comments