@@ -268,6 +268,60 @@ public void TestJsonDecoderNumeric(string type, object value)
268268 }
269269 }
270270
271+ [ Test ]
272+ [ TestCase ( "float" , "0" , ( float ) 0 ) ]
273+ [ TestCase ( "float" , "1" , ( float ) 1 ) ]
274+ [ TestCase ( "float" , "1.0" , ( float ) 1.0 ) ]
275+ [ TestCase ( "double" , "0" , ( double ) 0 ) ]
276+ [ TestCase ( "double" , "1" , ( double ) 1 ) ]
277+ [ TestCase ( "double" , "1.0" , 1.0 ) ]
278+ [ TestCase ( "float" , "\" NaN\" " , float . NaN ) ]
279+ [ TestCase ( "float" , "\" Infinity\" " , float . PositiveInfinity ) ]
280+ [ TestCase ( "float" , "\" INF\" " , float . PositiveInfinity ) ]
281+ [ TestCase ( "float" , "\" -Infinity\" " , float . NegativeInfinity ) ]
282+ [ TestCase ( "float" , "\" -INF\" " , float . NegativeInfinity ) ]
283+ [ TestCase ( "double" , "\" NaN\" " , double . NaN ) ]
284+ [ TestCase ( "double" , "\" Infinity\" " , double . PositiveInfinity ) ]
285+ [ TestCase ( "double" , "\" INF\" " , double . PositiveInfinity ) ]
286+ [ TestCase ( "double" , "\" -Infinity\" " , double . NegativeInfinity ) ]
287+ [ TestCase ( "double" , "\" -INF\" " , double . NegativeInfinity ) ]
288+ [ TestCase ( "float" , "\" \" " , null ) ]
289+ [ TestCase ( "float" , "\" unknown\" " , null ) ]
290+ [ TestCase ( "float" , "\" nan\" " , null ) ]
291+ [ TestCase ( "float" , "\" infinity\" " , null ) ]
292+ [ TestCase ( "float" , "\" inf\" " , null ) ]
293+ [ TestCase ( "float" , "\" -infinity\" " , null ) ]
294+ [ TestCase ( "float" , "\" -inf\" " , null ) ]
295+ [ TestCase ( "double" , "\" \" " , null ) ]
296+ [ TestCase ( "double" , "\" unknown\" " , null ) ]
297+ [ TestCase ( "double" , "\" nan\" " , null ) ]
298+ [ TestCase ( "double" , "\" infinity\" " , null ) ]
299+ [ TestCase ( "double" , "\" inf\" " , null ) ]
300+ [ TestCase ( "double" , "\" -infinity\" " , null ) ]
301+ [ TestCase ( "double" , "\" -inf\" " , null ) ]
302+ [ TestCase ( "double" , "\" -inf\" " , null ) ]
303+ public void TestJsonDecodeFloatDouble ( string typeStr , string valueStr , object expected )
304+ {
305+ string def = $ "{{\" type\" :\" record\" ,\" name\" :\" X\" ,\" fields\" :[{{\" type\" :\" { typeStr } \" ,\" name\" :\" Value\" }}]}}";
306+ Schema schema = Schema . Parse ( def ) ;
307+ DatumReader < GenericRecord > reader = new GenericDatumReader < GenericRecord > ( schema , schema ) ;
308+
309+ string record = $ "{{\" Value\" :{ valueStr } }}";
310+ Decoder decoder = new JsonDecoder ( schema , record ) ;
311+ try
312+ {
313+ GenericRecord r = reader . Read ( null , decoder ) ;
314+ Assert . AreEqual ( expected , r [ "Value" ] ) ;
315+ }
316+ catch ( AvroTypeException )
317+ {
318+ if ( expected != null )
319+ {
320+ throw ;
321+ }
322+ }
323+ }
324+
271325 [ TestCase ( "{ \" s\" : \" 1900-01-01T00:00:00Z\" }" , "1900-01-01T00:00:00Z" ) ]
272326 [ TestCase ( "{ \" s\" : \" 1900-01-01T00:00:00.0000000Z\" }" , "1900-01-01T00:00:00.0000000Z" ) ]
273327 [ TestCase ( "{ \" s\" : \" 1900-01-01T00:00:00\" }" , "1900-01-01T00:00:00" ) ]
0 commit comments