From d913d8b7a9e93ee468d79719ec003964a956d5ed Mon Sep 17 00:00:00 2001 From: numzero Date: Fri, 11 Apr 2025 20:36:37 +0300 Subject: [PATCH] test expression::call --- src/run.rs | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) 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()) + ); + } }