@@ -39,7 +39,8 @@ class JSONDecodableTests: XCTestCase {
39
39
let fourPointFour = 4.4
40
40
let fourPointFourJSON : JSON = 4.4
41
41
let fourJSON : JSON = 4
42
-
42
+ let fourPointFourStringJSON : JSON = " 4.4 "
43
+
43
44
do {
44
45
let decodedFourPointFour = try Double ( json: fourPointFourJSON)
45
46
let decodedFour = try Double ( json: fourJSON)
@@ -48,10 +49,17 @@ class JSONDecodableTests: XCTestCase {
48
49
} catch {
49
50
XCTFail ( " Should be able to instantiate a `Double` with `JSON`: \( error) . " )
50
51
}
51
-
52
+
53
+ do {
54
+ let decodedFourPointFour = try Double ( json: fourPointFourStringJSON)
55
+ XCTAssertEqual ( decodedFourPointFour, fourPointFour, " `fourPointFour` and '4.4' `String` should be equal. " )
56
+ } catch {
57
+ XCTFail ( " Failed for unknown reason: \( error) . " )
58
+ }
59
+
52
60
do {
53
61
_ = try Double ( json: " bad " )
54
- XCTFail ( " Should not be able to instantiate `Double` with `String` `JSON`. " )
62
+ XCTFail ( " Should not be able to instantiate `Double` with `String` not matching a double representation `JSON`. " )
55
63
} catch JSON . Error . ValueNotConvertible( let type) {
56
64
XCTAssert ( true , " \( type) should not be covertible from 'bad' `String`. " )
57
65
} catch {
@@ -63,7 +71,10 @@ class JSONDecodableTests: XCTestCase {
63
71
let four = 4
64
72
let fourJSON : JSON = 4
65
73
let fourPointZeroJSON : JSON = 4.0
66
-
74
+ let fourStringJSON : JSON = " 4 "
75
+ let fourPointZeroStringJSON : JSON = " 4.0 "
76
+ let fourPointFourStringJSON : JSON = " 4.4 "
77
+
67
78
do {
68
79
let decodedFour = try Int ( json: fourJSON)
69
80
let decodedFourPointZero = try Int ( json: fourPointZeroJSON)
@@ -72,10 +83,28 @@ class JSONDecodableTests: XCTestCase {
72
83
} catch {
73
84
XCTFail ( " Should be able to instantiate an `Int` with `JSON`: \( error) . " )
74
85
}
75
-
86
+
87
+ do {
88
+ let decodedFour = try Int ( json: fourStringJSON)
89
+ let decodedFourPointZero = try Int ( json: fourPointZeroStringJSON)
90
+ XCTAssertEqual ( decodedFour, four, " `four` and '4' `String` should be equal. " )
91
+ XCTAssertEqual ( decodedFourPointZero, four, " `decodedFourPointZero` and '4.0' `String` should be equal. " )
92
+ } catch {
93
+ XCTFail ( " Failed for unknown reason: \( error) . " )
94
+ }
95
+
96
+ do {
97
+ _ = try Int ( json: fourPointFourStringJSON)
98
+ XCTFail ( " Should not be able to instantiate `Int` with '4.4' `String` `JSON`. " )
99
+ } catch JSON . Error . ValueNotConvertible( let type) {
100
+ XCTAssert ( true , " \( type) should not be covertible from '4.4' `String`. " )
101
+ } catch {
102
+ XCTFail ( " Failed for unknown reason: \( error) . " )
103
+ }
104
+
76
105
do {
77
106
_ = try Int ( json: " bad " )
78
- XCTFail ( " Should not be able to instantiate `Int` with `String` `JSON`. " )
107
+ XCTFail ( " Should not be able to instantiate `Int` with `String` not matching an integer representation `JSON`. " )
79
108
} catch JSON . Error . ValueNotConvertible( let type) {
80
109
XCTAssert ( true , " \( type) should not be covertible from 'bad' `String`. " )
81
110
} catch {
0 commit comments