File tree 2 files changed +13
-1
lines changed
Sources/Segment/Utilities 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 {
59
59
self = . string( string)
60
60
case let bool as Bool :
61
61
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 > :
63
65
self = . array( try array. map ( JSON . init) )
64
66
case let object as [ String : Any ] :
65
67
self = . object( try object. mapValues ( JSON . init) )
Original file line number Diff line number Diff line change @@ -52,6 +52,16 @@ class JSONTests: XCTestCase {
52
52
}
53
53
}
54
54
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
+
55
65
func testJSONNil( ) throws {
56
66
let traits = try JSON ( [ " type " : NSNull ( ) , " preferences " : [ " bwack " ] , " key " : nil ] )
57
67
let encoder = JSONEncoder ( )
You can’t perform that action at this time.
0 commit comments