diff --git a/stdlib/src/redis.rs b/stdlib/src/redis.rs index 8be06367..022334c2 100644 --- a/stdlib/src/redis.rs +++ b/stdlib/src/redis.rs @@ -30,3 +30,37 @@ impl StdlibRegistry { ); } } + +#[cfg(test)] +mod tests { + use super::*; + use techscript_runtime::context::{RuntimeConfig, RuntimeContext}; + + #[test] + fn test_register_redis() { + let mut registry = StdlibRegistry::new(); + registry.register_redis(); + + assert!(registry.has_module("std.redis")); + let module = registry.get_module("std.redis").unwrap(); + assert_eq!(module.name, "std.redis"); + assert_eq!(module.version, "1.0.0"); + assert!(module.exports.contains_key("connect")); + + let connect_fn = module.exports.get("connect").unwrap(); + assert_eq!(connect_fn.name(), "connect"); + assert_eq!(connect_fn.arity(), 1); + + let mut ctx = RuntimeContext::new(RuntimeConfig::default()); + let res = connect_fn + .call( + &mut ctx, + vec![RuntimeValue::Str("redis://127.0.0.1:6379".to_string())], + ) + .unwrap(); + assert_eq!( + res, + RuntimeValue::Str("Redis not yet available".to_string()) + ); + } +}