@@ -17,6 +17,9 @@ import XCTest
1717
1818class TencentCloudTests : XCTestCase {
1919 static let allRegions = Set ( TencentCloud . Region. mainland + TencentCloud. Region. overseas)
20+ struct Wrapped < T: Codable > : Codable {
21+ let value : T
22+ }
2023
2124 func testRegionCountEqual( ) {
2225 XCTAssertEqual ( TencentCloud . Region. mainland. count + TencentCloud. Region. overseas. count, TencentCloud . Region. regular. count + TencentCloud. Region. financial. count)
@@ -27,26 +30,28 @@ class TencentCloudTests: XCTestCase {
2730 let encoder = JSONEncoder ( )
2831 let decoder = JSONDecoder ( )
2932 for region in Self . allRegions {
30- let json = " \" \( region. rawValue) \" "
31- let encoded = try encoder. encode ( region)
32- let decoded = try decoder. decode ( TencentCloud . Region. self, from: json. data ( using: . utf8) !)
33+ let wrapped = Wrapped ( value: region)
34+ let json = #"{"value":" \#( region. rawValue) "}"#
35+ let encoded = try encoder. encode ( wrapped)
36+ let decoded = try decoder. decode ( Wrapped< TencentCloud . Region> . self , from: json. data ( using: . utf8) !)
3337 XCTAssertEqual ( String ( data: encoded, encoding: . utf8) , json)
34- XCTAssertEqual ( region, decoded)
38+ XCTAssertEqual ( region, decoded. value )
3539 }
3640 }
3741
3842 func testZoneWithRawAndCodable( ) throws {
39- let number = 23
4043 let encoder = JSONEncoder ( )
4144 let decoder = JSONDecoder ( )
4245 for region in Self . allRegions {
46+ let number = UInt8 . random ( in: UInt8 . min ... UInt8 . max)
4347 let zone = TencentCloud . Zone ( rawValue: " \( region) - \( number) " )
4448 XCTAssertNotNil ( zone)
45- let json = " \" \( zone!) \" "
46- let encoded = try encoder. encode ( zone)
47- let decoded = try decoder. decode ( TencentCloud . Zone. self, from: json. data ( using: . utf8) !)
49+ let wrapped = Wrapped ( value: zone!)
50+ let json = #"{"value":" \#( zone!. rawValue) "}"#
51+ let encoded = try encoder. encode ( wrapped)
52+ let decoded = try decoder. decode ( Wrapped< TencentCloud . Zone> . self , from: json. data ( using: . utf8) !)
4853 XCTAssertEqual ( String ( data: encoded, encoding: . utf8) , json)
49- XCTAssertEqual ( zone, decoded)
54+ XCTAssertEqual ( zone, decoded. value )
5055 }
5156 }
5257}
0 commit comments