File tree Expand file tree Collapse file tree 2 files changed +13
-1
lines changed
Sources/Segment/Utilities Expand file tree Collapse file tree 2 files changed +13
-1
lines changed Original file line number Diff line number Diff line change @@ -59,7 +59,9 @@ public enum JSON: Equatable {
5959 self = . string( string)
6060 case let bool as Bool :
6161 self = . bool( bool)
62- case let array as [ Any ] :
62+ case let aSet as Set < AnyHashable > :
63+ self = . array( try aSet. map ( JSON . init) )
64+ case let array as Array < Any > :
6365 self = . array( try array. map ( JSON . init) )
6466 case let object as [ String : Any ] :
6567 self = . object( try object. mapValues ( JSON . init) )
Original file line number Diff line number Diff line change @@ -52,6 +52,16 @@ class JSONTests: XCTestCase {
5252 }
5353 }
5454
55+ func testJSONCollectionTypes( ) throws {
56+ let testSet : Set = [ " 1 " , " 2 " , " 3 " ]
57+ let traits = try ! JSON ( [ " type " : NSNull ( ) , " preferences " : [ " bwack " ] , " key " : testSet] )
58+ let jsonSet = traits [ " key " ]
59+ XCTAssertNotNil ( jsonSet)
60+ let array = jsonSet!. arrayValue!
61+ XCTAssertNotNil ( array)
62+ XCTAssertEqual ( array. count, 3 )
63+ }
64+
5565 func testJSONNil( ) throws {
5666 let traits = try JSON ( [ " type " : NSNull ( ) , " preferences " : [ " bwack " ] , " key " : nil ] )
5767 let encoder = JSONEncoder ( )
You can’t perform that action at this time.
0 commit comments