artichoke_backend/extn/stdlib/abbrev/
mod.rs

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