Add tree walk eval test

This commit is contained in:
Greg Shuflin 2021-10-24 21:54:08 -07:00
parent b365a3fec7
commit 81859306b3
3 changed files with 27 additions and 1 deletions

View File

@ -7,6 +7,8 @@ use std::fmt::Write;
use std::rc::Rc;
use std::convert::From;
mod test;
type EvalResult<T> = Result<T, String>;
#[derive(Debug)]

View File

@ -0,0 +1,24 @@
#![cfg(test)]
use crate::symbol_table::SymbolTable;
use crate::tree_walk_eval::State;
fn evaluate_input(input: &str) -> Result<String, String> {
let ast = crate::util::quick_ast(input);
let mut symbol_table = SymbolTable::new();
symbol_table.process_ast(&ast).unwrap();
let reduced_ir = crate::reduced_ir::reduce(&ast, &symbol_table);
let mut state = State::new();
let mut outputs = state.evaluate(reduced_ir, true);
outputs.pop().unwrap()
}
fn eval_assert(input: &str, expected: &str) {
assert_eq!(evaluate_input(input), Ok(expected.to_string()));
}
#[test]
fn test_basic_eval() {
eval_assert("1 + 2", "3");
//eval_assert("let mut a = 1; a = 2", "()");
}