File: 337_value_float_roundtrip.rs

package info (click to toggle)
rust-ron 0.12.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,096 kB
  • sloc: makefile: 2
file content (29 lines) | stat: -rw-r--r-- 748 bytes parent folder | download | duplicates (20)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#[test]
fn roundtrip_value_float_with_decimals() {
    let v: ron::Value = ron::from_str("1.0").unwrap();

    assert_eq!(v, ron::Value::Number(1.0_f32.into()));

    let ser = ron::ser::to_string(&v).unwrap();

    let roundtrip = ron::from_str(&ser).unwrap();

    assert_eq!(v, roundtrip);
}

#[test]
#[allow(clippy::float_cmp)]
fn roundtrip_value_float_into() {
    let v: ron::Value = ron::from_str("1.0").unwrap();
    assert_eq!(v, ron::Value::Number(1.0_f32.into()));

    let ser = ron::ser::to_string(&v).unwrap();

    let f1: f64 = ron::from_str(&ser).unwrap();
    assert_eq!(f1, 1.0_f64);

    let roundtrip: ron::Value = ron::from_str(&ser).unwrap();

    let f2: f64 = roundtrip.into_rust().unwrap();
    assert_eq!(f2, 1.0_f64);
}