77import com .fasterxml .jackson .core .json .JsonReadFeature ;
88import com .fasterxml .jackson .core .testsupport .AsyncReaderWrapper ;
99
10- public class AsyncNumberLeadingZeroesTest extends AsyncTestBase
10+ public class AsyncNonStdNumberHandlingTest extends AsyncTestBase
1111{
1212 @ SuppressWarnings ("deprecation" )
1313 public void testDefaultsForAsync () throws Exception {
@@ -77,7 +77,7 @@ public void testLeadingZeroesFloat() throws Exception
7777 _testLeadingZeroesFloat ("-000.5 " , -0.5 );
7878 }
7979
80- public void _testLeadingZeroesFloat (String valueStr , double value ) throws Exception
80+ private void _testLeadingZeroesFloat (String valueStr , double value ) throws Exception
8181 {
8282 // first: verify that we get an exception
8383 JsonFactory f = new JsonFactory ();
@@ -104,8 +104,58 @@ public void _testLeadingZeroesFloat(String valueStr, double value) throws Except
104104 p .close ();
105105 }
106106
107+ public void testLeadingPeriodFloat () throws Exception
108+ {
109+ _testLeadingPeriodFloat (".25" , 0.25 , 1 );
110+ _testLeadingPeriodFloat (".25" , 0.25 , 100 );
111+ _testLeadingPeriodFloat (" .25 " , 0.25 , 1 );
112+ _testLeadingPeriodFloat (" .25 " , 0.25 , 100 );
113+
114+ _testLeadingPeriodFloat (".1" , 0.1 , 1 );
115+ _testLeadingPeriodFloat (".1" , 0.1 , 100 );
116+
117+ _testLeadingPeriodFloat (".6125 " , 0.6125 , 1 );
118+ _testLeadingPeriodFloat (".6125 " , 0.6125 , 100 );
119+ }
120+
121+ private void _testLeadingPeriodFloat (String valueStr , double value , int bytesPerRead )
122+ throws Exception
123+ {
124+ // first: verify that we get an exception
125+
126+ JsonFactory f = new JsonFactory ();
127+ String JSON = valueStr ;
128+ AsyncReaderWrapper p = createParser (f , JSON , bytesPerRead );
129+ try {
130+ p .nextToken ();
131+ p .currentText ();
132+ fail ("Should have thrown an exception for doc <" +JSON +">" );
133+ } catch (JsonParseException e ) {
134+ verifyException (e , "Unexpected character ('.'" );
135+ verifyException (e , "expected a valid value" );
136+ } finally {
137+ p .close ();
138+ }
139+
140+ // and then verify it's ok when enabled
141+ f = JsonFactory .builder ()
142+ .enable (JsonReadFeature .ALLOW_LEADING_DECIMAL_POINT_FOR_NUMBERS )
143+ .build ();
144+ p = createParser (f , JSON , bytesPerRead );
145+ assertToken (JsonToken .VALUE_NUMBER_FLOAT , p .nextToken ());
146+ assertEquals (value , p .getDoubleValue ());
147+ assertEquals (valueStr .trim (), p .currentText ());
148+ p .close ();
149+ }
150+
107151 private AsyncReaderWrapper createParser (JsonFactory f , String doc ) throws IOException
108152 {
109- return asyncForBytes (f , 1 , _jsonDoc (doc ), 1 );
153+ return createParser (f , doc , 1 );
154+ }
155+
156+ private AsyncReaderWrapper createParser (JsonFactory f , String doc , int bytesPerRead )
157+ throws IOException
158+ {
159+ return asyncForBytes (f , bytesPerRead , _jsonDoc (doc ), 1 );
110160 }
111161}
0 commit comments