File tree Expand file tree Collapse file tree 3 files changed +18
-4
lines changed Expand file tree Collapse file tree 3 files changed +18
-4
lines changed Original file line number Diff line number Diff line change @@ -24,6 +24,7 @@ fn value_bool() {
24
24
25
25
#[ test]
26
26
fn value_number ( ) {
27
+ assert_eq ! ( format!( "{:?}" , json!( :: std:: f64 :: NAN ) ) , "Number(NaN)" ) ;
27
28
assert_eq ! ( format!( "{:?}" , json!( 1 ) ) , "Number(1)" ) ;
28
29
assert_eq ! ( format!( "{:?}" , json!( -1 ) ) , "Number(-1)" ) ;
29
30
assert_eq ! ( format!( "{:?}" , json!( 1.0 ) ) , "Number(1.0)" ) ;
Original file line number Diff line number Diff line change @@ -31,7 +31,7 @@ macro_rules! test_stream {
31
31
32
32
#[ test]
33
33
fn test_json_stream_newlines ( ) {
34
- let data = "{\" x\" :39} {\" x\" :40}{\" x\" :41}\n {\" x\" :42}" ;
34
+ let data = "{\" x\" :39} {\" x\" :40}{\" x\" :41}\n {\" x\" :42}{ \" x \" :nan} " ;
35
35
36
36
test_stream ! ( data, Value , |stream| {
37
37
assert_eq!( stream. next( ) . unwrap( ) . unwrap( ) [ "x" ] , 39 ) ;
@@ -45,9 +45,11 @@ fn test_json_stream_newlines() {
45
45
46
46
assert_eq!( stream. next( ) . unwrap( ) . unwrap( ) [ "x" ] , 42 ) ;
47
47
assert_eq!( stream. byte_offset( ) , 34 ) ;
48
+ assert!( stream. next( ) . unwrap( ) . unwrap( ) [ "x" ] . as_f64( ) . unwrap( ) . is_nan( ) ) ;
49
+ assert_eq!( stream. byte_offset( ) , 43 ) ;
48
50
49
51
assert!( stream. next( ) . is_none( ) ) ;
50
- assert_eq!( stream. byte_offset( ) , 34 ) ;
52
+ assert_eq!( stream. byte_offset( ) , 43 ) ;
51
53
} ) ;
52
54
}
53
55
Original file line number Diff line number Diff line change @@ -161,13 +161,13 @@ fn test_write_f64() {
161
161
#[ test]
162
162
fn test_encode_nonfinite_float_yields_null ( ) {
163
163
let v = to_value ( :: std:: f64:: NAN ) . unwrap ( ) ;
164
- assert ! ( v. is_null ( ) ) ;
164
+ assert ! ( v. is_f64 ( ) ) ;
165
165
166
166
let v = to_value ( :: std:: f64:: INFINITY ) . unwrap ( ) ;
167
167
assert ! ( v. is_null( ) ) ;
168
168
169
169
let v = to_value ( :: std:: f32:: NAN ) . unwrap ( ) ;
170
- assert ! ( v. is_null ( ) ) ;
170
+ assert ! ( v. is_f64 ( ) ) ;
171
171
172
172
let v = to_value ( :: std:: f32:: INFINITY ) . unwrap ( ) ;
173
173
assert ! ( v. is_null( ) ) ;
@@ -693,6 +693,17 @@ fn test_parse_null() {
693
693
test_parse_ok ( vec ! [ ( "null" , ( ) ) ] ) ;
694
694
}
695
695
696
+ #[ test]
697
+ fn test_parse_nan ( ) {
698
+ test_parse_err :: < ( ) > ( & [
699
+ ( "n" , "EOF while parsing a value at line 1 column 1" ) ,
700
+ ( "na" , "expected ident at line 1 column 2" ) ,
701
+ ( "nana" , "expected ident at line 1 column 2" ) ,
702
+ ] ) ;
703
+
704
+ assert ! ( from_str:: <f64 >( "nan" ) . unwrap( ) . is_nan( ) ) ;
705
+ }
706
+
696
707
#[ test]
697
708
fn test_parse_bool ( ) {
698
709
test_parse_err :: < bool > ( & [
You can’t perform that action at this time.
0 commit comments