More tests!
This commit is contained in:
parent
7829d959ce
commit
4ead8e702e
35
src/run.rs
35
src/run.rs
|
|
@ -88,7 +88,7 @@ impl Eval for Expression {
|
|||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use crate::ast;
|
||||
use crate::{ast, types};
|
||||
|
||||
#[test]
|
||||
fn test_consts() {
|
||||
|
|
@ -104,4 +104,37 @@ mod tests {
|
|||
Some("foobar".into())
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_vars() {
|
||||
let mut scope = Scope::default();
|
||||
let foo = ast::Location::Variable { name: "foo".into() };
|
||||
let bar = ast::Location::Variable { name: "bar".into() };
|
||||
assert_eq!(foo.eval(&mut scope), None);
|
||||
assert_eq!(bar.eval(&mut scope), None);
|
||||
scope.variables.insert("bar".into(), 42.into());
|
||||
assert_eq!(foo.eval(&mut scope), None);
|
||||
assert_eq!(bar.eval(&mut scope), Some(42.into()));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_fields() {
|
||||
let mut scope = Scope::default();
|
||||
let loc = ast::Location::Field {
|
||||
table: Box::new(ast::Location::Variable { name: "foo".into() }),
|
||||
index: Box::new(ast::Expression::Constant(ast::Constant::String(
|
||||
"bar".into(),
|
||||
))),
|
||||
};
|
||||
let foo = types::Table::default();
|
||||
let bar = types::Table::default();
|
||||
scope.variables.insert("foo".into(), foo.clone().into());
|
||||
assert_eq!(loc.eval(&mut scope), None);
|
||||
scope.variables.insert("bar".into(), bar.clone().into());
|
||||
assert_eq!(loc.eval(&mut scope), None);
|
||||
bar.set("foo".into(), Some(666.into()));
|
||||
assert_eq!(loc.eval(&mut scope), None);
|
||||
foo.set("bar".into(), Some(42.into()));
|
||||
assert_eq!(loc.eval(&mut scope), Some(42.into()));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user