artichoke_backend/extn/stdlib/forwardable/
mod.rs

1use std::ffi::CStr;
2
3use crate::extn::prelude::*;
4
5const FORWARDABLE_CSTR: &CStr = c"Forwardable";
6static FORWARDABLE_RUBY_SOURCE: &[u8] = include_bytes!("vendor/forwardable.rb");
7static FORWARDABLE_IMPL_RUBY_SOURCE: &[u8] = include_bytes!("vendor/forwardable/impl.rb");
8
9pub fn init(interp: &mut Artichoke) -> InitializeResult<()> {
10    let spec = module::Spec::new(interp, "Forwardable", FORWARDABLE_CSTR, None)?;
11    interp.def_module::<Forwardable>(spec)?;
12    interp.def_rb_source_file("forwardable.rb", FORWARDABLE_RUBY_SOURCE)?;
13    interp.def_rb_source_file("forwardable/impl.rb", FORWARDABLE_IMPL_RUBY_SOURCE)?;
14
15    Ok(())
16}
17
18#[derive(Debug, Clone, Copy)]
19pub struct Forwardable;
20
21#[cfg(test)]
22mod tests {
23    use crate::test::prelude::*;
24
25    const SUBJECT: &str = "Forwardable";
26    const FUNCTIONAL_TEST: &[u8] = include_bytes!("forwardable_test.rb");
27
28    #[test]
29    fn functional() {
30        let mut interp = interpreter();
31        let result = interp.eval(FUNCTIONAL_TEST);
32        unwrap_or_panic_with_backtrace(&mut interp, SUBJECT, result);
33        let result = interp.eval(b"spec");
34        unwrap_or_panic_with_backtrace(&mut interp, SUBJECT, result);
35    }
36}