Sha256: 4a572ec1ec6ed66c8010081dc550ec3d1bf24666fa787883b4f2f541b576c91d

Contents?: true

Size: 1.75 KB

Versions: 13

Compression:

Stored size: 1.75 KB

Contents

use toml_edit::DocumentMut;

macro_rules! float_inf_tests {
    ($ty:ty) => {{
        let document = r"
            # infinity
            sf1 = inf  # positive infinity
            sf2 = +inf # positive infinity
            sf3 = -inf # negative infinity

            # not a number
            sf4 = nan  # actual sNaN/qNaN encoding is implementation specific
            sf5 = +nan # same as `nan`
            sf6 = -nan # valid, actual encoding is implementation specific

            # zero
            sf7 = +0.0
            sf8 = -0.0
        ";

        let document = document.parse::<DocumentMut>().unwrap();
        let float = |k| document[k].as_float().unwrap();

        assert!(float("sf1").is_infinite());
        assert!(float("sf1").is_sign_positive());
        assert!(float("sf2").is_infinite());
        assert!(float("sf2").is_sign_positive());
        assert!(float("sf3").is_infinite());
        assert!(float("sf3").is_sign_negative());

        assert!(float("sf4").is_nan());
        assert!(float("sf4").is_sign_positive());
        assert!(float("sf5").is_nan());
        assert!(float("sf5").is_sign_positive());
        assert!(float("sf6").is_nan());
        assert!(float("sf6").is_sign_negative());

        assert_eq!(float("sf7"), 0.0);
        assert!(float("sf7").is_sign_positive());
        assert_eq!(float("sf8"), 0.0);
        assert!(float("sf8").is_sign_negative());

        let mut document = DocumentMut::new();
        document["sf4"] = toml_edit::value(f64::NAN.copysign(1.0));
        document["sf6"] = toml_edit::value(f64::NAN.copysign(-1.0));
        assert_eq!(
            document.to_string(),
            "\
sf4 = nan
sf6 = -nan
"
        );
    }};
}

#[test]
fn test_float() {
    float_inf_tests!(f32);
    float_inf_tests!(f64);
}

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
wasmtime-29.0.0 ./ext/cargo-vendor/toml_edit-0.22.22/tests/testsuite/float.rs
wasmtime-28.0.0 ./ext/cargo-vendor/toml_edit-0.22.22/tests/testsuite/float.rs
wasmtime-27.0.0 ./ext/cargo-vendor/toml_edit-0.22.22/tests/testsuite/float.rs
wasmtime-26.0.0 ./ext/cargo-vendor/toml_edit-0.22.22/tests/testsuite/float.rs
wasmtime-25.0.2 ./ext/cargo-vendor/toml_edit-0.22.20/tests/testsuite/float.rs
wasmtime-25.0.1 ./ext/cargo-vendor/toml_edit-0.22.20/tests/testsuite/float.rs
wasmtime-25.0.0 ./ext/cargo-vendor/toml_edit-0.22.20/tests/testsuite/float.rs
wasmtime-24.0.0 ./ext/cargo-vendor/toml_edit-0.22.20/tests/testsuite/float.rs
wasmtime-23.0.2 ./ext/cargo-vendor/toml_edit-0.22.12/tests/testsuite/float.rs
wasmtime-22.0.0 ./ext/cargo-vendor/toml_edit-0.22.12/tests/testsuite/float.rs
wasmtime-21.0.1 ./ext/cargo-vendor/toml_edit-0.22.12/tests/testsuite/float.rs
wasmtime-20.0.2 ./ext/cargo-vendor/toml_edit-0.22.12/tests/testsuite/float.rs
wasmtime-20.0.0 ./ext/cargo-vendor/toml_edit-0.22.12/tests/testsuite/float.rs