add test for closures
This commit is contained in:
parent
221cd6e149
commit
c77e0703f9
|
|
@ -396,7 +396,7 @@ impl OpenFunction {
|
|||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use crate::ast::*;
|
||||
use crate::{ast::*, types::ValueInner};
|
||||
|
||||
use super::build;
|
||||
|
||||
|
|
@ -459,4 +459,25 @@ mod tests {
|
|||
assert_eq!(ret, Some(42.into()));
|
||||
assert_eq!(env.get("x".into()), Some(666.into()));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_capture() {
|
||||
let remember = Function {
|
||||
name: Some("remember".into()),
|
||||
args: vec!["value".into()],
|
||||
body: vec![],
|
||||
ret: Some(Box::new(Expression::Function(Function {
|
||||
name: None,
|
||||
args: vec![],
|
||||
body: vec![],
|
||||
ret: Some(Box::new(Expression::new_variable("value"))),
|
||||
}))),
|
||||
};
|
||||
let remember = build(&remember);
|
||||
let the_answerer = remember.call(None, &[Some(42.into())]);
|
||||
let Some(ValueInner::Function(f)) = the_answerer else {
|
||||
panic!("a function expected");
|
||||
};
|
||||
assert_eq!(f.call(&[]), Some(42.into()));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user