Skip to content

Commit 3796a32

Browse files
authored
Merge pull request #7 from adam-fowler/latest-foundation
Get rid of CoreFoundation import
2 parents 0d9765c + 68ae192 commit 3796a32

File tree

4 files changed

+92
-68
lines changed

4 files changed

+92
-68
lines changed

.github/workflows/ci.yml

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,22 +12,22 @@ on:
1212

1313
jobs:
1414
macos:
15-
runs-on: macOS-latest
15+
runs-on: macOS-13
1616
steps:
1717
- name: Checkout
18-
uses: actions/checkout@v1
18+
uses: actions/checkout@v4
1919
with:
2020
fetch-depth: 1
2121
- name: SPM tests
22-
run: swift test --enable-code-coverage --sanitize=thread
22+
run: swift test --enable-code-coverage
2323
- name: Convert coverage files
2424
run: |
2525
xcrun llvm-cov export -format "lcov" \
2626
.build/debug/jmespath.swiftPackageTests.xctest/Contents/MacOs/jmespath.swiftPackageTests \
2727
-ignore-filename-regex="\/Tests\/" \
2828
-instr-profile=.build/debug/codecov/default.profdata > info.lcov
2929
- name: Upload to codecov.io
30-
uses: codecov/codecov-action@v1
30+
uses: codecov/codecov-action@v4
3131
with:
3232
file: info.lcov
3333

@@ -36,14 +36,15 @@ 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:
4546
- name: Checkout
46-
uses: actions/checkout@v1
47+
uses: actions/checkout@v4
4748
with:
4849
fetch-depth: 1
4950
- name: Test
@@ -55,6 +56,6 @@ jobs:
5556
-ignore-filename-regex="\/Tests\/" \
5657
-instr-profile .build/debug/codecov/default.profdata > info.lcov
5758
- name: Upload to codecov.io
58-
uses: codecov/codecov-action@v1
59+
uses: codecov/codecov-action@v4
5960
with:
6061
file: info.lcov

.gitignore

Lines changed: 1 addition & 0 deletions
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

Lines changed: 23 additions & 12 deletions
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 type(of: number) == Self.nsNumberBoolType {
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
@@ -259,6 +266,8 @@ public enum JMESVariable {
259266
guard let first = mirror.children.first else { return nil }
260267
return first.value
261268
}
269+
270+
fileprivate static var nsNumberBoolType = type(of: NSNumber(value: true))
262271
}
263272

264273
extension JMESVariable: Equatable {
@@ -304,7 +313,9 @@ extension JMESObject {
304313
fileprivate func equalTo(_ rhs: JMESObject) -> Bool {
305314
guard self.count == rhs.count else { return false }
306315
for element in self {
307-
guard let rhsValue = rhs[element.key], JMESVariable(from: rhsValue) == JMESVariable(from: element.value) else {
316+
guard let rhsValue = rhs[element.key],
317+
JMESVariable(from: rhsValue) == JMESVariable(from: element.value)
318+
else {
308319
return false
309320
}
310321
}

Tests/JMESPathTests/ComplianceTests.swift

Lines changed: 59 additions & 48 deletions
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,20 @@ 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+
#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
147158
let tests = try JSONDecoder().decode([ComplianceTest].self, from: data)
148159

149160
if #available(iOS 11.0, tvOS 11.0, watchOS 5.0, *) {
@@ -153,67 +164,67 @@ final class ComplianceTests: XCTestCase {
153164
}
154165
}
155166

156-
func testBasic() throws {
157-
try self.testCompliance(name: "basic")
167+
func testBasic() async throws {
168+
try await self.testCompliance(name: "basic")
158169
}
159170

160-
func testBenchmarks() throws {
161-
try self.testCompliance(name: "benchmarks")
171+
func testBenchmarks() async throws {
172+
try await self.testCompliance(name: "benchmarks")
162173
}
163174

164-
func testBoolean() throws {
165-
try self.testCompliance(name: "boolean")
175+
func testBoolean() async throws {
176+
try await self.testCompliance(name: "boolean")
166177
}
167178

168-
func testCurrent() throws {
169-
try self.testCompliance(name: "current")
179+
func testCurrent() async throws {
180+
try await self.testCompliance(name: "current")
170181
}
171182

172-
func testEscape() throws {
173-
try self.testCompliance(name: "escape")
183+
func testEscape() async throws {
184+
try await self.testCompliance(name: "escape")
174185
}
175186

176-
func testFilters() throws {
177-
try self.testCompliance(name: "filters")
187+
func testFilters() async throws {
188+
try await self.testCompliance(name: "filters")
178189
}
179190

180-
func testFunctions() throws {
181-
try self.testCompliance(name: "functions")
191+
func testFunctions() async throws {
192+
try await self.testCompliance(name: "functions")
182193
}
183194

184-
func testIdentifiers() throws {
185-
try self.testCompliance(name: "identifiers")
195+
func testIdentifiers() async throws {
196+
try await self.testCompliance(name: "identifiers")
186197
}
187198

188-
func testIndices() throws {
189-
try self.testCompliance(name: "indices")
199+
func testIndices() async throws {
200+
try await self.testCompliance(name: "indices")
190201
}
191202

192-
func testLiteral() throws {
193-
try self.testCompliance(name: "literal")
203+
func testLiteral() async throws {
204+
try await self.testCompliance(name: "literal")
194205
}
195206

196-
func testMultiSelect() throws {
197-
try self.testCompliance(name: "multiselect")
207+
func testMultiSelect() async throws {
208+
try await self.testCompliance(name: "multiselect")
198209
}
199210

200-
func testPipe() throws {
201-
try self.testCompliance(name: "pipe")
211+
func testPipe() async throws {
212+
try await self.testCompliance(name: "pipe")
202213
}
203214

204-
func testSlice() throws {
205-
try self.testCompliance(name: "slice")
215+
func testSlice() async throws {
216+
try await self.testCompliance(name: "slice")
206217
}
207218

208-
func testSyntax() throws {
209-
try self.testCompliance(name: "syntax")
219+
func testSyntax() async throws {
220+
try await self.testCompliance(name: "syntax")
210221
}
211222

212-
func testUnicode() throws {
213-
try self.testCompliance(name: "unicode")
223+
func testUnicode() async throws {
224+
try await self.testCompliance(name: "unicode")
214225
}
215226

216-
func testWildcards() throws {
217-
try self.testCompliance(name: "wildcard")
227+
func testWildcards() async throws {
228+
try await self.testCompliance(name: "wildcard")
218229
}
219230
}

0 commit comments

Comments
 (0)