summaryrefslogtreecommitdiffstats
path: root/third_party/rust/ron/tests/337_value_float_roundtrip.rs
blob: 66873eaeab497bc5a16b9865ec28d50c01c27865 (plain)
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_f64.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_f64.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);
}