Sha256: a3008268817e527fb4f0ca177a183472a365aedbf6fca00a9d2921d7ff505de2

Contents?: true

Size: 792 Bytes

Versions: 19

Compression:

Stored size: 792 Bytes

Contents

use magnus::{eval, method, rb_assert, Error, Ruby, Value};

fn flipflop(ruby: &Ruby, _rb_self: Value, mut val: bool) -> Result<(), Error> {
    val = ruby.yield_value(val)?;
    loop {
        val = ruby.yield_value(!val)?;
    }
}

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

    ruby.define_global_function("flipflop", method!(flipflop, 1));

    let values = ruby.ary_new();
    let i: Value = eval!(
        ruby,
        "
        i = 0
        flipflop(true) do |val|
          values << val
          i += 1 if val
          break if i > 5
          val
        end
        i
        ",
        values
    )
    .unwrap();

    rb_assert!(ruby, "i == 6 && values == [true, false, true, false, true, false, true, false, true, false, true]", i, values);
}

Version data entries

19 entries across 19 versions & 1 rubygems

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