diff --git a/stdlib/src/redis.rs b/stdlib/src/redis.rs index 8be06367..aa208342 100644 --- a/stdlib/src/redis.rs +++ b/stdlib/src/redis.rs @@ -30,3 +30,39 @@ impl StdlibRegistry { ); } } + +#[cfg(test)] +mod tests { + use super::*; + use crate::StdlibRegistry; + use techscript_runtime::RuntimeContext; + + #[test] + fn test_register_redis() { + let mut registry = StdlibRegistry { + modules: std::collections::HashMap::new(), + }; + registry.register_redis(); + + assert!(registry.modules.contains_key("std.redis")); + let module = registry.modules.get("std.redis").unwrap(); + assert_eq!(module.name, "std.redis"); + assert_eq!(module.version, "1.0.0"); + assert!(module.exports.contains_key("connect")); + + let connect_func = module.exports.get("connect").unwrap(); + assert_eq!(connect_func.name(), "connect"); + assert_eq!(connect_func.arity(), 1); + + let mut ctx = RuntimeContext::new(techscript_runtime::RuntimeConfig::default()); + let result = connect_func.call( + &mut ctx, + vec![RuntimeValue::Str("redis://localhost".to_string())], + ); + assert!(result.is_ok()); + assert_eq!( + result.unwrap(), + RuntimeValue::Str("Redis not yet available".to_string()) + ); + } +}