Skip to content

Commit

Permalink
Expression.search(_:) -> Expression.search(object:)
Browse files Browse the repository at this point in the history
  • Loading branch information
adam-fowler committed Jun 3, 2021
1 parent 72d00a4 commit ddc3ae2
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 11 deletions.
8 changes: 4 additions & 4 deletions Sources/JMESPath/Expression.swift
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ public struct Expression {
/// - runtime: JMES runtime (includes functions)
/// - Throws: JMESPathError
/// - Returns: Search result
public func search<Value>(_ any: Any, as: Value.Type = Value.self, runtime: JMESRuntime = .init()) throws -> Value? {
return try self.search(any, runtime: runtime) as? Value
public func search<Value>(object: Any, as: Value.Type = Value.self, runtime: JMESRuntime = .init()) throws -> Value? {
return try self.search(object: object, runtime: runtime) as? Value
}

/// Search JSON
Expand Down Expand Up @@ -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) {
Expand Down
6 changes: 3 additions & 3 deletions Tests/JMESPathTests/ComplianceTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)")
}
Expand All @@ -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
}
Expand All @@ -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)
Expand Down
6 changes: 3 additions & 3 deletions Tests/JMESPathTests/ErrorTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion Tests/JMESPathTests/MirrorTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ final class MirrorTests: XCTestCase {
func testInterpreter<Value: Equatable>(_ 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)")
Expand Down

0 comments on commit ddc3ae2

Please sign in to comment.