Skip to content

Commit 53553d0

Browse files
committedAug 1, 2024·
Get rid of CoreFoundation import
1 parent 0d9765c commit 53553d0

File tree

4 files changed

+80
-62
lines changed

4 files changed

+80
-62
lines changed
 

‎.github/workflows/ci.yml

+3-2
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,10 @@ jobs:
3636
strategy:
3737
matrix:
3838
tag:
39-
- swift:5.6
40-
- swift:5.7
4139
- swift:5.8
40+
- swift:5.9
41+
- swift:5.10
42+
- swiftlang/swift:nightly-6.0-jammy
4243
container:
4344
image: ${{ matrix.tag }}
4445
steps:

‎.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
/.build
33
/.swiftpm
44
/.vscode
5+
/.devcontainer
56
/Packages
67
/*.xcodeproj
78
/docs

‎Sources/JMESPath/Variable.swift

+21-12
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import CoreFoundation
21
import Foundation
32

43
public typealias JMESArray = [Any]
@@ -27,7 +26,7 @@ public enum JMESVariable {
2726
case let number as NSNumber:
2827
// both booleans and integer/float point types can be converted to a `NSNumber`
2928
// We have to check to see the type id to see if it is a boolean
30-
if CFGetTypeID(number) == CFBooleanGetTypeID() {
29+
if UInt8(number.objCType[0]) == UInt8(ascii: "c") {
3130
self = .boolean(number.boolValue)
3231
} else {
3332
self = .number(number)
@@ -56,7 +55,9 @@ public enum JMESVariable {
5655
case .dictionary:
5756
var object: JMESObject = [:]
5857
var index: Int = 0
59-
while let key = mirror.descendant(index, "key") as? String, let value = mirror.descendant(index, "value") {
58+
while let key = mirror.descendant(index, "key") as? String,
59+
let value = mirror.descendant(index, "value")
60+
{
6061
object[key] = Self.unwrap(value) ?? NSNull()
6162
index += 1
6263
}
@@ -115,12 +116,18 @@ public enum JMESVariable {
115116
case .boolean(let bool):
116117
return String(describing: bool)
117118
case .array(let array):
118-
guard let jsonData = try? JSONSerialization.data(withJSONObject: array, options: [.fragmentsAllowed]) else {
119+
guard
120+
let jsonData = try? JSONSerialization.data(
121+
withJSONObject: array, options: [.fragmentsAllowed])
122+
else {
119123
return nil
120124
}
121125
return String(decoding: jsonData, as: Unicode.UTF8.self)
122126
case .object(let object):
123-
guard let jsonData = try? JSONSerialization.data(withJSONObject: object, options: [.fragmentsAllowed]) else {
127+
guard
128+
let jsonData = try? JSONSerialization.data(
129+
withJSONObject: object, options: [.fragmentsAllowed])
130+
else {
124131
return nil
125132
}
126133
return String(decoding: jsonData, as: Unicode.UTF8.self)
@@ -148,12 +155,12 @@ public enum JMESVariable {
148155
public func isSameType(as variable: JMESVariable) -> Bool {
149156
switch (self, variable) {
150157
case (.null, .null),
151-
(.string, .string),
152-
(.boolean, .boolean),
153-
(.number, .number),
154-
(.array, .array),
155-
(.object, .object),
156-
(.expRef, .expRef):
158+
(.string, .string),
159+
(.boolean, .boolean),
160+
(.number, .number),
161+
(.array, .array),
162+
(.object, .object),
163+
(.expRef, .expRef):
157164
return true
158165
default:
159166
return false
@@ -304,7 +311,9 @@ extension JMESObject {
304311
fileprivate func equalTo(_ rhs: JMESObject) -> Bool {
305312
guard self.count == rhs.count else { return false }
306313
for element in self {
307-
guard let rhsValue = rhs[element.key], JMESVariable(from: rhsValue) == JMESVariable(from: element.value) else {
314+
guard let rhsValue = rhs[element.key],
315+
JMESVariable(from: rhsValue) == JMESVariable(from: element.value)
316+
else {
308317
return false
309318
}
310319
}

‎Tests/JMESPathTests/ComplianceTests.swift

+55-48
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,13 @@
66
//
77

88
import Foundation
9+
import XCTest
10+
11+
@testable import JMESPath
912

10-
import Foundation
1113
#if os(Linux)
12-
import FoundationNetworking
14+
import FoundationNetworking
1315
#endif
14-
@testable import JMESPath
15-
import XCTest
1616

1717
public struct AnyDecodable: Decodable {
1818
public let value: Any
@@ -22,8 +22,8 @@ public struct AnyDecodable: Decodable {
2222
}
2323
}
2424

25-
public extension AnyDecodable {
26-
init(from decoder: Decoder) throws {
25+
extension AnyDecodable {
26+
public init(from decoder: Decoder) throws {
2727
let container = try decoder.singleValueContainer()
2828

2929
if container.decodeNil() {
@@ -43,7 +43,8 @@ public extension AnyDecodable {
4343
} else if let dictionary = try? container.decode([String: AnyDecodable].self) {
4444
self.init(dictionary.mapValues { $0.value })
4545
} 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")
4748
}
4849
}
4950
}
@@ -67,7 +68,7 @@ final class ComplianceTests: XCTestCase {
6768
@available(iOS 11.0, tvOS 11.0, watchOS 5.0, *)
6869
func run() throws {
6970
for c in self.cases {
70-
if let _ = c.bench {
71+
if c.bench != nil {
7172
self.testBenchmark(c)
7273
} else if let error = c.error {
7374
self.testError(c, error: error)
@@ -106,11 +107,13 @@ final class ComplianceTests: XCTestCase {
106107
let expression = try JMESExpression.compile(c.expression)
107108

108109
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])
110112
return String(decoding: data, as: Unicode.UTF8.self)
111113
}
112114
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])
114117
let valueJson = String(decoding: valueData, as: Unicode.UTF8.self)
115118
XCTAssertEqual(resultJson, valueJson)
116119
} else {
@@ -124,7 +127,8 @@ final class ComplianceTests: XCTestCase {
124127
@available(iOS 11.0, tvOS 11.0, watchOS 5.0, *)
125128
func output(_ c: Case, expected: String?, result: String?) {
126129
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])
128132
let givenJson = String(decoding: data, as: Unicode.UTF8.self)
129133
if let comment = c.comment {
130134
print("Comment: \(comment)")
@@ -137,13 +141,16 @@ final class ComplianceTests: XCTestCase {
137141
}
138142
}
139143

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)
143150
}
144151

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)
147154
let tests = try JSONDecoder().decode([ComplianceTest].self, from: data)
148155

149156
if #available(iOS 11.0, tvOS 11.0, watchOS 5.0, *) {
@@ -153,67 +160,67 @@ final class ComplianceTests: XCTestCase {
153160
}
154161
}
155162

156-
func testBasic() throws {
157-
try self.testCompliance(name: "basic")
163+
func testBasic() async throws {
164+
try await self.testCompliance(name: "basic")
158165
}
159166

160-
func testBenchmarks() throws {
161-
try self.testCompliance(name: "benchmarks")
167+
func testBenchmarks() async throws {
168+
try await self.testCompliance(name: "benchmarks")
162169
}
163170

164-
func testBoolean() throws {
165-
try self.testCompliance(name: "boolean")
171+
func testBoolean() async throws {
172+
try await self.testCompliance(name: "boolean")
166173
}
167174

168-
func testCurrent() throws {
169-
try self.testCompliance(name: "current")
175+
func testCurrent() async throws {
176+
try await self.testCompliance(name: "current")
170177
}
171178

172-
func testEscape() throws {
173-
try self.testCompliance(name: "escape")
179+
func testEscape() async throws {
180+
try await self.testCompliance(name: "escape")
174181
}
175182

176-
func testFilters() throws {
177-
try self.testCompliance(name: "filters")
183+
func testFilters() async throws {
184+
try await self.testCompliance(name: "filters")
178185
}
179186

180-
func testFunctions() throws {
181-
try self.testCompliance(name: "functions")
187+
func testFunctions() async throws {
188+
try await self.testCompliance(name: "functions")
182189
}
183190

184-
func testIdentifiers() throws {
185-
try self.testCompliance(name: "identifiers")
191+
func testIdentifiers() async throws {
192+
try await self.testCompliance(name: "identifiers")
186193
}
187194

188-
func testIndices() throws {
189-
try self.testCompliance(name: "indices")
195+
func testIndices() async throws {
196+
try await self.testCompliance(name: "indices")
190197
}
191198

192-
func testLiteral() throws {
193-
try self.testCompliance(name: "literal")
199+
func testLiteral() async throws {
200+
try await self.testCompliance(name: "literal")
194201
}
195202

196-
func testMultiSelect() throws {
197-
try self.testCompliance(name: "multiselect")
203+
func testMultiSelect() async throws {
204+
try await self.testCompliance(name: "multiselect")
198205
}
199206

200-
func testPipe() throws {
201-
try self.testCompliance(name: "pipe")
207+
func testPipe() async throws {
208+
try await self.testCompliance(name: "pipe")
202209
}
203210

204-
func testSlice() throws {
205-
try self.testCompliance(name: "slice")
211+
func testSlice() async throws {
212+
try await self.testCompliance(name: "slice")
206213
}
207214

208-
func testSyntax() throws {
209-
try self.testCompliance(name: "syntax")
215+
func testSyntax() async throws {
216+
try await self.testCompliance(name: "syntax")
210217
}
211218

212-
func testUnicode() throws {
213-
try self.testCompliance(name: "unicode")
219+
func testUnicode() async throws {
220+
try await self.testCompliance(name: "unicode")
214221
}
215222

216-
func testWildcards() throws {
217-
try self.testCompliance(name: "wildcard")
223+
func testWildcards() async throws {
224+
try await self.testCompliance(name: "wildcard")
218225
}
219226
}

0 commit comments

Comments
 (0)
Please sign in to comment.