@@ -107,6 +107,14 @@ fn default_value_examples() -> &'static Vec<(&'static str, &'static str, Value)>
107107 ( r#""long""# , "5" , Value :: Long ( 5 ) ) ,
108108 ( r#""float""# , "1.1" , Value :: Float ( 1.1 ) ) ,
109109 ( r#""double""# , "1.1" , Value :: Double ( 1.1 ) ) ,
110+ ( r#""float""# , r#"" +inf ""# , Value :: Float ( f32 :: INFINITY ) ) ,
111+ (
112+ r#""double""# ,
113+ r#""-Infinity""# ,
114+ Value :: Double ( f64 :: NEG_INFINITY ) ,
115+ ) ,
116+ ( r#""float""# , r#""-NAN""# , Value :: Float ( f32 :: NAN ) ) ,
117+ ( r#""double""# , r#""-NAN""# , Value :: Double ( f64 :: NAN ) ) ,
110118 (
111119 r#"{"type": "fixed", "name": "F", "size": 2}"# ,
112120 r#""a""# ,
@@ -312,11 +320,41 @@ fn test_default_value() -> TestResult {
312320 & mut Cursor :: new ( encoded) ,
313321 Some ( & reader_schema) ,
314322 ) ?;
315- assert_eq ! (
316- datum_read, datum_to_read,
317- "{} -> {}" ,
318- * field_type, * default_json
319- ) ;
323+
324+ match default_datum {
325+ // For float/double, NaN != NaN, so we check specially here.
326+ Value :: Double ( f) if f. is_nan ( ) => {
327+ let Value :: Record ( fields) = datum_read else {
328+ unreachable ! ( "the test always constructs top level as record" )
329+ } ;
330+ let Value :: Double ( f) = fields[ 0 ] . 1 else {
331+ panic ! ( "double expected" )
332+ } ;
333+ assert ! (
334+ f. is_nan( ) ,
335+ "{field_type} -> {default_json} is parsed as {f} rather than NaN"
336+ ) ;
337+ }
338+ Value :: Float ( f) if f. is_nan ( ) => {
339+ let Value :: Record ( fields) = datum_read else {
340+ unreachable ! ( "the test always constructs top level as record" )
341+ } ;
342+ let Value :: Float ( f) = fields[ 0 ] . 1 else {
343+ panic ! ( "double expected" )
344+ } ;
345+ assert ! (
346+ f. is_nan( ) ,
347+ "{field_type} -> {default_json} is parsed as {f} rather than NaN"
348+ ) ;
349+ }
350+ _ => {
351+ assert_eq ! (
352+ datum_read, datum_to_read,
353+ "{} -> {}" ,
354+ * field_type, * default_json
355+ ) ;
356+ }
357+ }
320358 }
321359
322360 Ok ( ( ) )
0 commit comments