@@ -33,6 +33,12 @@ public void testDouble() throws IOException {
33
33
strategy.readNumber(fromString("1e400"));
34
34
fail();
35
35
} catch (MalformedJsonException expected) {
36
+ assertEquals("JSON forbids NaN and infinities: Infinity at line 1 column 6 path $", expected.getMessage());
37
+ }
38
+ try {
39
+ strategy.readNumber(fromString("\"not-a-number\""));
40
+ fail();
41
+ } catch (NumberFormatException expected) {
36
42
}
37
43
}
38
44
@@ -52,24 +58,35 @@ public void testLongOrDouble() throws IOException {
52
58
strategy.readNumber(fromString("1e400"));
53
59
fail();
54
60
} catch (MalformedJsonException expected) {
61
+ assertEquals("JSON forbids NaN and infinities: Infinity; at path $", expected.getMessage());
62
+ }
63
+ try {
64
+ strategy.readNumber(fromString("\"not-a-number\""));
65
+ fail();
66
+ } catch (JsonParseException expected) {
67
+ assertEquals("Cannot parse not-a-number; at path $", expected.getMessage());
55
68
}
69
+
56
70
assertEquals(Double.NaN, strategy.readNumber(fromStringLenient("NaN")));
57
71
assertEquals(Double.POSITIVE_INFINITY, strategy.readNumber(fromStringLenient("Infinity")));
58
72
assertEquals(Double.NEGATIVE_INFINITY, strategy.readNumber(fromStringLenient("-Infinity")));
59
73
try {
60
74
strategy.readNumber(fromString("NaN"));
61
75
fail();
62
76
} catch (MalformedJsonException expected) {
77
+ assertEquals("Use JsonReader.setLenient(true) to accept malformed JSON at line 1 column 1 path $", expected.getMessage());
63
78
}
64
79
try {
65
80
strategy.readNumber(fromString("Infinity"));
66
81
fail();
67
82
} catch (MalformedJsonException expected) {
83
+ assertEquals("Use JsonReader.setLenient(true) to accept malformed JSON at line 1 column 1 path $", expected.getMessage());
68
84
}
69
85
try {
70
86
strategy.readNumber(fromString("-Infinity"));
71
87
fail();
72
88
} catch (MalformedJsonException expected) {
89
+ assertEquals("Use JsonReader.setLenient(true) to accept malformed JSON at line 1 column 1 path $", expected.getMessage());
73
90
}
74
91
}
75
92
@@ -78,6 +95,13 @@ public void testBigDecimal() throws IOException {
78
95
assertEquals(new BigDecimal("10.1"), strategy.readNumber(fromString("10.1")));
79
96
assertEquals(new BigDecimal("3.141592653589793238462643383279"), strategy.readNumber(fromString("3.141592653589793238462643383279")));
80
97
assertEquals(new BigDecimal("1e400"), strategy.readNumber(fromString("1e400")));
98
+
99
+ try {
100
+ strategy.readNumber(fromString("\"not-a-number\""));
101
+ fail();
102
+ } catch (JsonParseException expected) {
103
+ assertEquals("Cannot parse not-a-number; at path $", expected.getMessage());
104
+ }
81
105
}
82
106
83
107
public void testNullsAreNeverExpected() throws IOException {
0 commit comments