| 1 | use ron::{ |
| 2 | de::from_str, |
| 3 | ser::{to_string, to_string_pretty, PrettyConfig}, |
| 4 | }; |
| 5 | |
| 6 | #[test] |
| 7 | fn test_inf_and_nan() { |
| 8 | assert_eq!(from_str("inf"), Ok(std::f64::INFINITY)); |
| 9 | assert_eq!(from_str("-inf"), Ok(std::f64::NEG_INFINITY)); |
| 10 | assert_eq!(from_str::<f64>("NaN").map(|n| n.is_nan()), Ok(true)) |
| 11 | } |
| 12 | |
| 13 | #[test] |
| 14 | fn decimal_floats() { |
| 15 | let non_pretty = to_string(&1.0).unwrap(); |
| 16 | assert_eq!(non_pretty, "1.0"); |
| 17 | |
| 18 | let with_pretty = to_string_pretty(&1.0, PrettyConfig::new()).unwrap(); |
| 19 | assert_eq!(with_pretty, "1.0"); |
| 20 | |
| 21 | let tiny_pretty = to_string_pretty(&0.00000000000000005, PrettyConfig::new()).unwrap(); |
| 22 | assert_eq!(tiny_pretty, "0.00000000000000005"); |
| 23 | } |