From 72d00a47d2062bb73c393f5be8f1b4f5755cb070 Mon Sep 17 00:00:00 2001 From: Adam Fowler Date: Thu, 3 Jun 2021 09:48:58 +0100 Subject: [PATCH] Variable doesn't convert `.other` to String Also got rid of RawRepresentable searches as they are not valid anymore --- Sources/JMESPath/Expression.swift | 45 --------------------------- Sources/JMESPath/Variable.swift | 2 +- Tests/JMESPathTests/ErrorTests.swift | 6 ---- Tests/JMESPathTests/MirrorTests.swift | 11 ------- 4 files changed, 1 insertion(+), 63 deletions(-) diff --git a/Sources/JMESPath/Expression.swift b/Sources/JMESPath/Expression.swift index 5add72f..7c981b8 100644 --- a/Sources/JMESPath/Expression.swift +++ b/Sources/JMESPath/Expression.swift @@ -38,36 +38,6 @@ public struct Expression { return try self.search(json: json, runtime: runtime) as? Value } - /// Search JSON - /// - /// - Parameters: - /// - any: Swift type to search - /// - as: Swift type to return - /// - runtime: JMES runtime (includes functions) - /// - Throws: JMESPathError - /// - Returns: Search result - public func search(json: Data, as: Value.Type = Value.self, runtime: JMESRuntime = .init()) throws -> Value? { - if let rawValue = try self.search(json: json, runtime: runtime) as? Value.RawValue { - return Value(rawValue: rawValue) - } - return nil - } - - /// Search JSON - /// - /// - Parameters: - /// - any: Swift type to search - /// - as: Swift type to return - /// - runtime: JMES runtime (includes functions) - /// - Throws: JMESPathError - /// - Returns: Search result - public func search(json: String, as: Value.Type = Value.self, runtime: JMESRuntime = .init()) throws -> Value? { - if let rawValue = try self.search(json: json, runtime: runtime) as? Value.RawValue { - return Value(rawValue: rawValue) - } - return nil - } - /// Search Swift type /// /// - Parameters: @@ -80,21 +50,6 @@ public struct Expression { return try self.search(any, runtime: runtime) as? Value } - /// Search Swift type - /// - /// - Parameters: - /// - any: Swift type to search - /// - as: Swift type to return - /// - 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? { - if let rawValue = try self.search(any, runtime: runtime) as? Value.RawValue { - return Value(rawValue: rawValue) - } - return nil - } - /// Search JSON /// /// - Parameters: diff --git a/Sources/JMESPath/Variable.swift b/Sources/JMESPath/Variable.swift index bd71dc2..ce095a8 100644 --- a/Sources/JMESPath/Variable.swift +++ b/Sources/JMESPath/Variable.swift @@ -78,7 +78,7 @@ public enum JMESVariable { case .boolean(let bool): return bool case .array(let array): return array case .object(let map): return map - case .other(let any): return String(describing: any) + case .other(let any): return any case .expRef: return nil } } diff --git a/Tests/JMESPathTests/ErrorTests.swift b/Tests/JMESPathTests/ErrorTests.swift index e256f43..3fae3ae 100644 --- a/Tests/JMESPathTests/ErrorTests.swift +++ b/Tests/JMESPathTests/ErrorTests.swift @@ -11,7 +11,6 @@ final class ErrorTests: XCTestCase { default: XCTFail("\(error)") } - print(error) } } @@ -24,7 +23,6 @@ final class ErrorTests: XCTestCase { default: XCTFail("\(error)") } - print(error) } } @@ -37,7 +35,6 @@ final class ErrorTests: XCTestCase { default: XCTFail("\(error)") } - print(error) } } @@ -50,7 +47,6 @@ final class ErrorTests: XCTestCase { default: XCTFail("\(error)") } - print(error) } } @@ -63,7 +59,6 @@ final class ErrorTests: XCTestCase { default: XCTFail("\(error)") } - print(error) } } @@ -76,7 +71,6 @@ final class ErrorTests: XCTestCase { default: XCTFail("\(error)") } - print(error) } } } diff --git a/Tests/JMESPathTests/MirrorTests.swift b/Tests/JMESPathTests/MirrorTests.swift index 0179e82..083f30a 100644 --- a/Tests/JMESPathTests/MirrorTests.swift +++ b/Tests/JMESPathTests/MirrorTests.swift @@ -12,16 +12,6 @@ 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)) - XCTAssertEqual(value, result) - } catch { - XCTFail("\(error)") - } - } - func testString() { struct TestString { let s: String @@ -84,6 +74,5 @@ final class MirrorTests: XCTestCase { } let test = TestObject(e: .test2) self.testInterpreter("e", data: test, result: TestEnum.test2) - self.testInterpreter("e", data: test, result: "test2") } }