diff --git a/examples/threads/threads.txs b/examples/threads/threads.txs index 7396bb40..96d5b7db 100644 --- a/examples/threads/threads.txs +++ b/examples/threads/threads.txs @@ -6,12 +6,12 @@ spawn_fn = thread["spawn"] join_fn = thread["join"] do task_a() - time.sleep(100) + time.sleep(200) say "Task A completed on worker thread." end do task_b() - time.sleep(50) + time.sleep(20) say "Task B completed on worker thread." end diff --git a/stdlib/src/redis.rs b/stdlib/src/redis.rs index 8be06367..0d4c40de 100644 --- a/stdlib/src/redis.rs +++ b/stdlib/src/redis.rs @@ -30,3 +30,43 @@ 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.required_capabilities.is_empty()); + 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); + assert!(connect_fn.accepts_arity(1)); + assert!(!connect_fn.accepts_arity(0)); + + 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()) + ); + + let err_res = connect_fn.call(&mut ctx, vec![]); + assert!(err_res.is_err()); + } +}