Skip to content

Commit

Permalink
Variable doesn't convert .other to String
Browse files Browse the repository at this point in the history
Also got rid of RawRepresentable searches as they are not valid anymore
  • Loading branch information
adam-fowler committed Jun 3, 2021
1 parent 0e70044 commit 72d00a4
Show file tree
Hide file tree
Showing 4 changed files with 1 addition and 63 deletions.
45 changes: 0 additions & 45 deletions Sources/JMESPath/Expression.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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<Value: RawRepresentable>(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<Value: RawRepresentable>(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:
Expand All @@ -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<Value: RawRepresentable>(_ 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:
Expand Down
2 changes: 1 addition & 1 deletion Sources/JMESPath/Variable.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
Expand Down
6 changes: 0 additions & 6 deletions Tests/JMESPathTests/ErrorTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ final class ErrorTests: XCTestCase {
default:
XCTFail("\(error)")
}
print(error)
}
}

Expand All @@ -24,7 +23,6 @@ final class ErrorTests: XCTestCase {
default:
XCTFail("\(error)")
}
print(error)
}
}

Expand All @@ -37,7 +35,6 @@ final class ErrorTests: XCTestCase {
default:
XCTFail("\(error)")
}
print(error)
}
}

Expand All @@ -50,7 +47,6 @@ final class ErrorTests: XCTestCase {
default:
XCTFail("\(error)")
}
print(error)
}
}

Expand All @@ -63,7 +59,6 @@ final class ErrorTests: XCTestCase {
default:
XCTFail("\(error)")
}
print(error)
}
}

Expand All @@ -76,7 +71,6 @@ final class ErrorTests: XCTestCase {
default:
XCTFail("\(error)")
}
print(error)
}
}
}
11 changes: 0 additions & 11 deletions Tests/JMESPathTests/MirrorTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,6 @@ final class MirrorTests: XCTestCase {
}
}

func testInterpreter<Value: RawRepresentable & Equatable>(_ 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
Expand Down Expand Up @@ -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")
}
}

0 comments on commit 72d00a4

Please sign in to comment.