Sha256: 8fbf88c58cb9b40defa26d7ef744c3c82b9839f60a4f73fbe7e3e02a36d6b0ee

Contents?: true

Size: 855 Bytes

Versions: 19

Compression:

Stored size: 855 Bytes

Contents

use magnus::{prelude::*, r_struct::RStruct, rb_assert};

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

    let struct_class = ruby.define_struct(Some("Foo"), ("bar", "baz")).unwrap();

    rb_assert!(ruby, r#"val.name == "Struct::Foo""#, val = struct_class);
    rb_assert!(ruby, "val.members == [:bar, :baz]", val = struct_class);

    let obj = struct_class.new_instance((1, 2)).unwrap();

    rb_assert!(ruby, "val.bar == 1", val = obj);
    rb_assert!(ruby, "val.baz == 2", val = obj);

    rb_assert!(
        ruby,
        r#"val.name == nil"#,
        val = ruby.define_struct(None, ("foo",)).unwrap()
    );

    let obj = RStruct::from_value(obj).unwrap();
    assert_eq!(1, obj.get(0).unwrap());
    assert_eq!(2, obj.get(1).unwrap());

    assert_eq!(&["bar", "baz"], obj.members().unwrap().as_slice())
}

Version data entries

19 entries across 19 versions & 1 rubygems

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