side effects!

This commit is contained in:
numzero 2025-04-11 20:48:40 +03:00
parent 380b7b26a3
commit 5f6da6ec60

View File

@ -226,4 +226,31 @@ mod tests {
assert_eq!(scope.get("foo"), Some(42.into())); assert_eq!(scope.get("foo"), Some(42.into()));
assert_eq!(scope.get("bar"), None); assert_eq!(scope.get("bar"), None);
} }
#[test]
fn test_call_statement() {
let mut scope = Scope::default();
scope.add_fn("set", |scope, args| {
let [key, value] = args.as_slice() else {
panic!("exactly two arguments expected");
};
let Some(ValueInner::String(key)) = key else {
panic!("string expected");
};
scope.set(key.clone(), value.clone());
None
});
assert_eq!(scope.get("foo"), None);
assert_eq!(scope.get("bar"), None);
ast::Statement::Call {
callee: "set".into(),
args: vec![
ast::Expression::Constant(ast::Constant::String("foo".into())),
ast::Expression::Constant(ast::Constant::Number(42)),
],
}
.exec(&mut scope);
assert_eq!(scope.get("foo"), Some(42.into()));
assert_eq!(scope.get("bar"), None);
}
} }