test expression::call

This commit is contained in:
numzero 2025-04-11 20:36:37 +03:00
parent ec3b41809d
commit d913d8b7a9

View File

@ -156,4 +156,26 @@ mod tests {
foo.set("bar".into(), Some(42.into())); foo.set("bar".into(), Some(42.into()));
assert_eq!(loc.eval(&mut scope), Some(42.into())); assert_eq!(loc.eval(&mut scope), Some(42.into()));
} }
#[test]
fn test_call() {
let mut scope = Scope::default();
scope.add_fn("sqr", |args| {
let [arg] = args.as_slice() else {
panic!("exactly one argument expected");
};
let Some(ValueInner::Number(arg)) = arg else {
panic!("number expected");
};
Some(ValueInner::Number(arg * arg))
});
assert_eq!(
ast::Expression::Call {
callee: "sqr".into(),
args: vec![ast::Expression::Constant(ast::Constant::Number(7))],
}
.eval(&mut scope),
Some(49.into())
);
}
} }