Skip to content

Commit

Permalink
#2 allow JSEN to be initialized from a type-erased JSEN instance
Browse files Browse the repository at this point in the history
  • Loading branch information
rogerluan committed Feb 9, 2022
2 parents 35b0e95 + 084f516 commit 586c395
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 0 deletions.
1 change: 1 addition & 0 deletions Sources/JSEN.swift
Expand Up @@ -31,6 +31,7 @@ public enum JSEN : Equatable {
case let dictionary as [String:Any]:
let jsenElements: [String:JSEN] = dictionary.compactMapValues { JSEN(from: $0) }
self = .dictionary(jsenElements)
case let jsen as JSEN: self = jsen
default: return nil
}
}
Expand Down
2 changes: 2 additions & 0 deletions Tests/JSENTests.swift
Expand Up @@ -61,6 +61,8 @@ final class JSENTests : XCTestCase {
XCTAssertEqual(JSEN(from: array), .array([42]))
let dictionary: Any? = [ "key" : 42 ]
XCTAssertEqual(JSEN(from: dictionary), .dictionary(["key" : 42]))
let jsen: Any? = JSEN.int(42)
XCTAssertEqual(JSEN(from: jsen), .int(42))
}

func test_initializer_withNestedValues_shouldSucceed() {
Expand Down

0 comments on commit 586c395

Please sign in to comment.