Sha256: af3a13dedced18fc25cfb957426b9df6ee174efc89b2664d1c8e3855a8837a86

Contents?: true

Size: 1.08 KB

Versions: 19

Compression:

Stored size: 1.08 KB

Contents

use magnus::{rb_assert, StaticSymbol, Symbol, Value};

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

    let sym = ruby.to_symbol("foo");
    // not static by default
    assert!(!sym.is_static());

    rb_assert!(ruby, "sym == :foo", sym);

    ruby.eval::<Value>(":bar").unwrap();
    let sym = ruby.to_symbol("bar");
    // static because there's a previous Ruby symbol literal
    assert!(sym.is_static());

    ruby.sym_new("baz");
    let sym = ruby.to_symbol("baz");
    // static because there's a previous StaticSymbol
    assert!(sym.is_static());

    let sym: Symbol = ruby.sym_new("qux").into();
    assert!(sym.is_static());

    let sym = ruby.to_symbol("example");
    assert!(!sym.is_static());
    sym.to_static();
    assert!(sym.is_static());

    let x = ruby.eval::<Symbol>(r#""xxx".to_sym"#).unwrap();
    assert!(!x.is_static());
    ruby.eval::<StaticSymbol>(":xxx").unwrap();

    let y = ruby.eval::<Symbol>(r#""yyy".to_sym"#).unwrap();
    assert!(!y.is_static());
    StaticSymbol::from_value(ruby.eval::<Value>(":yyy").unwrap()).unwrap();
}

Version data entries

19 entries across 19 versions & 1 rubygems

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