Sha256: db3e5f50996b0ac55336d2b901159b76c9f6ef1c42af2fdcc5e96c9aa307cd4c

Contents?: true

Size: 1.32 KB

Versions: 19

Compression:

Stored size: 1.32 KB

Contents

use magnus::prelude::*;

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

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

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

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

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

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

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

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

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

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

Version data entries

19 entries across 19 versions & 1 rubygems

Version Path
wasmtime-29.0.0 ./ext/cargo-vendor/magnus-0.7.1/tests/float_convert_from_value.rs
wasmtime-28.0.0 ./ext/cargo-vendor/magnus-0.7.1/tests/float_convert_from_value.rs
wasmtime-27.0.0 ./ext/cargo-vendor/magnus-0.7.1/tests/float_convert_from_value.rs
wasmtime-26.0.0 ./ext/cargo-vendor/magnus-0.7.1/tests/float_convert_from_value.rs
wasmtime-25.0.2 ./ext/cargo-vendor/magnus-0.6.4/tests/float_convert_from_value.rs
wasmtime-25.0.1 ./ext/cargo-vendor/magnus-0.6.4/tests/float_convert_from_value.rs
wasmtime-25.0.0 ./ext/cargo-vendor/magnus-0.6.4/tests/float_convert_from_value.rs
wasmtime-24.0.0 ./ext/cargo-vendor/magnus-0.6.4/tests/float_convert_from_value.rs
wasmtime-23.0.2 ./ext/cargo-vendor/magnus-0.6.4/tests/float_convert_from_value.rs
wasmtime-22.0.0 ./ext/cargo-vendor/magnus-0.6.4/tests/float_convert_from_value.rs
wasmtime-21.0.1 ./ext/cargo-vendor/magnus-0.6.4/tests/float_convert_from_value.rs
wasmtime-20.0.2 ./ext/cargo-vendor/magnus-0.6.4/tests/float_convert_from_value.rs
wasmtime-20.0.0 ./ext/cargo-vendor/magnus-0.6.4/tests/float_convert_from_value.rs
wasmtime-18.0.3 ./ext/cargo-vendor/magnus-0.6.2/tests/float_convert_from_value.rs
wasmtime-17.0.1 ./ext/cargo-vendor/magnus-0.6.2/tests/float_convert_from_value.rs
wasmtime-17.0.0 ./ext/cargo-vendor/magnus-0.6.2/tests/float_convert_from_value.rs
wasmtime-16.0.0 ./ext/cargo-vendor/magnus-0.6.2/tests/float_convert_from_value.rs
wasmtime-15.0.1 ./ext/cargo-vendor/magnus-0.6.2/tests/float_convert_from_value.rs
wasmtime-15.0.0 ./ext/cargo-vendor/magnus-0.6.2/tests/float_convert_from_value.rs