Skip to content

Commit

Permalink
Merge pull request #10 from noppoMan/kludgey-decimal-cast
Browse files Browse the repository at this point in the history
kludgey decimal cast for Linux platforms
  • Loading branch information
noppoMan authored Oct 8, 2017
2 parents 11a6cbc + e9a3893 commit 11d4a97
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 7 deletions.
14 changes: 11 additions & 3 deletions Sources/AWSSDKSwiftCore/Decoder/DictionaryDecoder.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1115,17 +1115,25 @@ extension _DictionaryDecoder {
return Float(number)
}

if let number = value as? Int {
return Float(number)
}

throw DecodingError._typeMismatch(at: self.codingPath, expectation: type, reality: value)
}

fileprivate func unbox(_ value: Any, as type: Double.Type) throws -> Double? {
guard !(value is NSNull) else { return nil }

guard let number = value as? Double else {
throw DecodingError._typeMismatch(at: self.codingPath, expectation: type, reality: value)
if let number = value as? Double {
return number
}

return number
if let number = value as? Int {
return Double(number)
}

throw DecodingError._typeMismatch(at: self.codingPath, expectation: type, reality: value)
}

fileprivate func unbox(_ value: Any, as type: String.Type) throws -> String? {
Expand Down
8 changes: 4 additions & 4 deletions Tests/AWSSDKSwiftCoreTests/DictionaryDecoderTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ class DictionaryDecoderTests: XCTestCase {
"uint16": UInt16.max,
"uint32": UInt32.max,
"uint64": UInt64.max,
"double": 2.0,
"float": 3.0,
"double": Double.greatestFiniteMagnitude,
"float": Float.greatestFiniteMagnitude,
"string": "hello",
"data": "hello".data(using: .utf8)!,
"bool": true,
Expand All @@ -73,8 +73,8 @@ class DictionaryDecoderTests: XCTestCase {
XCTAssertEqual(a.b.uint16, 65535)
XCTAssertEqual(a.b.uint32, 4294967295)
XCTAssertEqual(a.b.uint64, 18446744073709551615)
XCTAssertEqual(a.b.double, 2.0)
XCTAssertEqual(a.b.float, 3.0)
XCTAssertEqual(a.b.double, 1.7976931348623157E+308)
XCTAssertEqual(a.b.float, 3.40282347E+38)
XCTAssertEqual(a.b.string, "hello")
XCTAssertEqual(a.b.data, "hello".data(using: .utf8))
XCTAssertEqual(a.b.bool, true)
Expand Down

0 comments on commit 11d4a97

Please sign in to comment.