artichoke_backend/extn/stdlib/strscan/
mod.rs1use std::ffi::CStr;
2
3use crate::extn::prelude::*;
4
5const STRING_SCANNER_CSTR: &CStr = c"StringScanner";
6static STRING_SCANNER_RUBY_SOURCE: &[u8] = include_bytes!("strscan.rb");
7
8pub fn init(interp: &mut Artichoke) -> InitializeResult<()> {
9 let spec = class::Spec::new("StringScanner", STRING_SCANNER_CSTR, None, None)?;
10 interp.def_class::<StringScanner>(spec)?;
11 interp.def_rb_source_file("strscan.rb", STRING_SCANNER_RUBY_SOURCE)?;
12
13 Ok(())
14}
15
16#[derive(Debug, Clone, Copy)]
17pub struct StringScanner;
18
19#[cfg(test)]
20mod tests {
21 use crate::test::prelude::*;
22
23 const SUBJECT: &str = "StringScanner";
24 const FUNCTIONAL_TEST: &[u8] = include_bytes!("strscan_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}