Skip to content

Commit

Permalink
Merge pull request #1080 from serde-rs/negativenan
Browse files Browse the repository at this point in the history
Add test of negative NaN and negative infinity
  • Loading branch information
dtolnay committed Oct 25, 2023
2 parents 421a70d + 4e091d5 commit f56053d
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions tests/test.rs
Expand Up @@ -160,17 +160,29 @@ fn test_write_f64() {

#[test]
fn test_encode_nonfinite_float_yields_null() {
let v = to_value(::std::f64::NAN).unwrap();
let v = to_value(::std::f64::NAN.copysign(1.0)).unwrap();
assert!(v.is_null());

let v = to_value(::std::f64::NAN.copysign(-1.0)).unwrap();
assert!(v.is_null());

let v = to_value(::std::f64::INFINITY).unwrap();
assert!(v.is_null());

let v = to_value(::std::f32::NAN).unwrap();
let v = to_value(-::std::f64::INFINITY).unwrap();
assert!(v.is_null());

let v = to_value(::std::f32::NAN.copysign(1.0)).unwrap();
assert!(v.is_null());

let v = to_value(::std::f32::NAN.copysign(-1.0)).unwrap();
assert!(v.is_null());

let v = to_value(::std::f32::INFINITY).unwrap();
assert!(v.is_null());

let v = to_value(-::std::f32::INFINITY).unwrap();
assert!(v.is_null());
}

#[test]
Expand Down

0 comments on commit f56053d

Please sign in to comment.