test expression::call
This commit is contained in:
parent
ec3b41809d
commit
d913d8b7a9
22
src/run.rs
22
src/run.rs
|
|
@ -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())
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user