diff --git a/Sources/JMESPath/Expression.swift b/Sources/JMESPath/Expression.swift index 7c981b8..8678e29 100644 --- a/Sources/JMESPath/Expression.swift +++ b/Sources/JMESPath/Expression.swift @@ -46,8 +46,8 @@ public struct Expression { /// - runtime: JMES runtime (includes functions) /// - Throws: JMESPathError /// - Returns: Search result - public func search(_ any: Any, as: Value.Type = Value.self, runtime: JMESRuntime = .init()) throws -> Value? { - return try self.search(any, runtime: runtime) as? Value + public func search(object: Any, as: Value.Type = Value.self, runtime: JMESRuntime = .init()) throws -> Value? { + return try self.search(object: object, runtime: runtime) as? Value } /// Search JSON @@ -81,8 +81,8 @@ public struct Expression { /// - runtime: JMES runtime (includes functions) /// - Throws: JMESPathError /// - Returns: Search result - public func search(_ any: Any, runtime: JMESRuntime = .init()) throws -> Any? { - return try runtime.interpret(JMESVariable(from: any), ast: self.ast).collapse() + public func search(object: Any, runtime: JMESRuntime = .init()) throws -> Any? { + return try runtime.interpret(JMESVariable(from: object), ast: self.ast).collapse() } private init(_ ast: Ast) { diff --git a/Tests/JMESPathTests/ComplianceTests.swift b/Tests/JMESPathTests/ComplianceTests.swift index 014f654..8ca9554 100644 --- a/Tests/JMESPathTests/ComplianceTests.swift +++ b/Tests/JMESPathTests/ComplianceTests.swift @@ -79,7 +79,7 @@ final class ComplianceTests: XCTestCase { func testBenchmark(_ c: Case) { do { let expression = try Expression.compile(c.expression) - _ = try expression.search(self.given.value) + _ = try expression.search(object: self.given.value) } catch { XCTFail("\(error)") } @@ -88,7 +88,7 @@ final class ComplianceTests: XCTestCase { func testError(_ c: Case, error: String) { do { let expression = try Expression.compile(c.expression) - _ = try expression.search(self.given.value) + _ = try expression.search(object: self.given.value) } catch { return } @@ -107,7 +107,7 @@ final class ComplianceTests: XCTestCase { let data = try JSONSerialization.data(withJSONObject: $0, options: [.fragmentsAllowed, .sortedKeys]) return String(decoding: data, as: Unicode.UTF8.self) } - if let value = try expression.search(self.given.value) { + if let value = try expression.search(object: self.given.value) { let valueData = try JSONSerialization.data(withJSONObject: value, options: [.fragmentsAllowed, .sortedKeys]) let valueJson = String(decoding: valueData, as: Unicode.UTF8.self) XCTAssertEqual(resultJson, valueJson) diff --git a/Tests/JMESPathTests/ErrorTests.swift b/Tests/JMESPathTests/ErrorTests.swift index 3fae3ae..cb9c7ab 100644 --- a/Tests/JMESPathTests/ErrorTests.swift +++ b/Tests/JMESPathTests/ErrorTests.swift @@ -4,7 +4,7 @@ import XCTest final class ErrorTests: XCTestCase { func testUnknownFunction() throws { let expression = try Expression.compile("unknown(@)") - XCTAssertThrowsError(try expression.search("test")) { error in + XCTAssertThrowsError(try expression.search(object: "test")) { error in switch error { case let error as JMESPathError where error == .runtime("Unknown function name 'unknown'"): break @@ -16,7 +16,7 @@ final class ErrorTests: XCTestCase { func testWrongNumberOfArgs() throws { let expression = try Expression.compile("reverse(@, @)") - XCTAssertThrowsError(try expression.search("test")) { error in + XCTAssertThrowsError(try expression.search(object: "test")) { error in switch error { case let error as JMESPathError where error == .runtime("Invalid number of arguments, expected 1, got 2"): break @@ -28,7 +28,7 @@ final class ErrorTests: XCTestCase { func testWrongArg() throws { let expression = try Expression.compile("sum(@)") - XCTAssertThrowsError(try expression.search("test")) { error in + XCTAssertThrowsError(try expression.search(object: "test")) { error in switch error { case let error as JMESPathError where error == .runtime("Invalid argument, expected array[number], got string"): break diff --git a/Tests/JMESPathTests/MirrorTests.swift b/Tests/JMESPathTests/MirrorTests.swift index 083f30a..d32c4f9 100644 --- a/Tests/JMESPathTests/MirrorTests.swift +++ b/Tests/JMESPathTests/MirrorTests.swift @@ -5,7 +5,7 @@ final class MirrorTests: XCTestCase { func testInterpreter(_ expression: String, data: Any, result: Value) { do { let expression = try Expression.compile(expression) - let value = try XCTUnwrap(expression.search(data, as: Value.self)) + let value = try XCTUnwrap(expression.search(object: data, as: Value.self)) XCTAssertEqual(value, result) } catch { XCTFail("\(error)")