Skip to content

Commit 586c395

Browse files
authored
#2 allow JSEN to be initialized from a type-erased JSEN instance
2 parents 35b0e95 + 084f516 commit 586c395

2 files changed

Lines changed: 3 additions & 0 deletions

File tree

Sources/JSEN.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ public enum JSEN : Equatable {
3131
case let dictionary as [String:Any]:
3232
let jsenElements: [String:JSEN] = dictionary.compactMapValues { JSEN(from: $0) }
3333
self = .dictionary(jsenElements)
34+
case let jsen as JSEN: self = jsen
3435
default: return nil
3536
}
3637
}

Tests/JSENTests.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,8 @@ final class JSENTests : XCTestCase {
6161
XCTAssertEqual(JSEN(from: array), .array([42]))
6262
let dictionary: Any? = [ "key" : 42 ]
6363
XCTAssertEqual(JSEN(from: dictionary), .dictionary(["key" : 42]))
64+
let jsen: Any? = JSEN.int(42)
65+
XCTAssertEqual(JSEN(from: jsen), .int(42))
6466
}
6567

6668
func test_initializer_withNestedValues_shouldSucceed() {

0 commit comments

Comments
 (0)