add a simple test
This commit is contained in:
parent
f6ba112d95
commit
2f08fa0dab
|
|
@ -393,3 +393,40 @@ impl OpenFunction {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use crate::ast::*;
|
||||
|
||||
use super::build;
|
||||
|
||||
#[test]
|
||||
fn test_local() {
|
||||
let testee = Function {
|
||||
name: Some("testee".into()),
|
||||
args: vec![],
|
||||
body: vec![
|
||||
Statement::Assign {
|
||||
target: Location::Variable { name: "x".into() },
|
||||
source: Box::new(Expression::Constant(Constant::Number(1))),
|
||||
},
|
||||
Statement::Local {
|
||||
name: "x".into(),
|
||||
init: Some(Box::new(Expression::Constant(Constant::Number(2)))),
|
||||
},
|
||||
Statement::Assign {
|
||||
target: Location::Variable { name: "x".into() },
|
||||
source: Box::new(Expression::Constant(Constant::Number(3))),
|
||||
},
|
||||
],
|
||||
ret: Some(Box::new(Expression::Variable(Location::Variable {
|
||||
name: "x".into(),
|
||||
}))),
|
||||
};
|
||||
let env = crate::types::Table::default();
|
||||
let testee = build(&testee);
|
||||
let ret = testee.call(Some(env.clone().into()), &[]);
|
||||
assert_eq!(ret, Some(3.into()));
|
||||
assert_eq!(env.get("x".into()), Some(1.into()));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user