Sha256: aa8738bf49a7126d0c384c3a39764ab7c7e6bdf538360babc069b60bba41cfcc

Contents?: true

Size: 1.35 KB

Versions: 19

Compression:

Stored size: 1.35 KB

Contents

#[test]
fn it_converts_floats_from_value() {
    let _cleanup = unsafe { magnus::embed::init() };

    let val = magnus::eval::<magnus::Value>("1.0").unwrap();
    let res = val.try_convert::<f64>();
    assert_eq!(res.unwrap(), 1.0);

    let val = magnus::eval::<magnus::Value>("1").unwrap();
    let res = val.try_convert::<f64>();
    assert_eq!(res.unwrap(), 1.0);

    let val = magnus::eval::<magnus::Value>("1/2r").unwrap();
    let res = val.try_convert::<f64>();
    assert_eq!(res.unwrap(), 0.5);

    let val = magnus::eval::<magnus::Value>("18446744073709551615").unwrap();
    let res = val.try_convert::<f64>();
    assert_eq!(res.unwrap(), 18446744073709552000.0);

    let val = magnus::eval::<magnus::Value>(r#""1.0""#).unwrap();
    let res = val.try_convert::<f64>();
    assert!(res.is_err());

    let val = magnus::eval::<magnus::Value>("Object.new").unwrap();
    let res = val.try_convert::<f64>();
    assert!(res.is_err());

    let val = magnus::eval::<magnus::Value>("nil").unwrap();
    let res = val.try_convert::<f64>();
    assert!(res.is_err());

    let val = magnus::eval::<magnus::Value>("Float::INFINITY").unwrap();
    let res = val.try_convert::<f64>();
    assert_eq!(res.unwrap(), f64::INFINITY);

    let val = magnus::eval::<magnus::Value>("Float::NAN").unwrap();
    let res = val.try_convert::<f64>();
    assert!(res.unwrap().is_nan());
}

Version data entries

19 entries across 19 versions & 1 rubygems

Version Path
wasmtime-14.0.4 ./ext/cargo-vendor/magnus-0.5.5/tests/float_convert_from_value.rs
wasmtime-14.0.3 ./ext/cargo-vendor/magnus-0.5.5/tests/float_convert_from_value.rs
wasmtime-14.0.1 ./ext/cargo-vendor/magnus-0.5.5/tests/float_convert_from_value.rs
wasmtime-14.0.0 ./ext/cargo-vendor/magnus-0.5.5/tests/float_convert_from_value.rs
wasmtime-13.0.0 ./ext/cargo-vendor/magnus-0.5.5/tests/float_convert_from_value.rs
wasmtime-12.0.1 ./ext/cargo-vendor/magnus-0.5.5/tests/float_convert_from_value.rs
wasmtime-12.0.0 ./ext/cargo-vendor/magnus-0.5.5/tests/float_convert_from_value.rs
wasmtime-11.0.0 ./ext/cargo-vendor/magnus-0.5.5/tests/float_convert_from_value.rs
wasmtime-10.0.1 ./ext/cargo-vendor/magnus-0.5.5/tests/float_convert_from_value.rs
wasmtime-10.0.0 ./ext/cargo-vendor/magnus-0.5.5/tests/float_convert_from_value.rs
wasmtime-9.0.4 ./ext/cargo-vendor/magnus-0.5.5/tests/float_convert_from_value.rs
wasmtime-9.0.1 ./ext/cargo-vendor/magnus-0.5.3/tests/float_convert_from_value.rs
wasmtime-8.0.0 ./ext/cargo-vendor/magnus-0.5.3/tests/float_convert_from_value.rs
wasmtime-7.0.0 ./ext/cargo-vendor/magnus-0.5.2/tests/float_convert_from_value.rs
wasmtime-6.0.1 ./ext/cargo-vendor/magnus-0.5.1/tests/float_convert_from_value.rs
wasmtime-6.0.0 ./ext/cargo-vendor/magnus-0.5.1/tests/float_convert_from_value.rs
wasmtime-5.0.0 ./ext/cargo-vendor/magnus-0.4.4/tests/float_convert_from_value.rs
wasmtime-0.4.1 ./ext/cargo-vendor/magnus-0.4.4/tests/float_convert_from_value.rs
wasmtime-0.4.0 ./ext/cargo-vendor/magnus-0.4.3/tests/float_convert_from_value.rs