Skip to content

Commit

Permalink
Add test of negative NaN and negative infinity
Browse files Browse the repository at this point in the history
  • Loading branch information
dtolnay committed Oct 25, 2023
1 parent 421a70d commit 4e091d5
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions tests/test.rs
Original file line number Diff line number Diff line change
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 4e091d5

Please sign in to comment.