artichoke_backend/extn/core/hash/
mod.rs1use std::ffi::CStr;
2
3use crate::extn::prelude::*;
4
5const HASH_CSTR: &CStr = c"Hash";
6static HASH_RUBY_SOURCE: &[u8] = include_bytes!("hash.rb");
7
8pub fn init(interp: &mut Artichoke) -> InitializeResult<()> {
9 if interp.is_class_defined::<Hash>() {
10 return Ok(());
11 }
12
13 let spec = class::Spec::new("Hash", HASH_CSTR, None, None)?;
14 interp.def_class::<Hash>(spec)?;
15 interp.eval(HASH_RUBY_SOURCE)?;
16
17 Ok(())
18}
19
20#[derive(Debug, Clone, Copy)]
21pub struct Hash;
22
23#[cfg(test)]
24mod tests {
25 use crate::test::prelude::*;
26
27 const SUBJECT: &str = "Hash";
28 const FUNCTIONAL_TEST: &[u8] = include_bytes!("hash_functional_test.rb");
29
30 #[test]
31 fn functional() {
32 let mut interp = interpreter();
33 let result = interp.eval(FUNCTIONAL_TEST);
34 unwrap_or_panic_with_backtrace(&mut interp, SUBJECT, result);
35 let result = interp.eval(b"spec");
36 unwrap_or_panic_with_backtrace(&mut interp, SUBJECT, result);
37 }
38
39 #[test]
40 fn regression_github_1099() {
41 let mut interp = interpreter();
42 let inspect = interp.eval(b"{ a: 'GH-1099' }.inspect").unwrap();
43 let inspect = inspect.try_convert_into_mut::<&str>(&mut interp).unwrap();
44 assert_eq!(inspect, r#"{:a=>"GH-1099"}"#);
45 }
46}