diff --git a/src/run.rs b/src/run.rs index 550bac5..99556c6 100644 --- a/src/run.rs +++ b/src/run.rs @@ -156,4 +156,26 @@ mod tests { foo.set("bar".into(), 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()) + ); + } }