Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions examples/threads/threads.txs
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
40 changes: 40 additions & 0 deletions stdlib/src/redis.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
}
Loading