schala/schala-lang/language/src/tree_walk_eval/test.rs

25 lines
682 B
Rust
Raw Normal View History

2021-10-24 21:54:08 -07:00
#![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", "()");
}