Add tree walk eval test
This commit is contained in:
parent
b365a3fec7
commit
81859306b3
@ -13,7 +13,7 @@ fn evaluate_all_outputs(input: &str) -> Vec<Result<String, String>> {
|
||||
let reduced = reduce(&ast, &symbol_table);
|
||||
|
||||
let mut state = State::new();
|
||||
|
||||
|
||||
state.evaluate(reduced, true)
|
||||
}
|
||||
|
||||
|
@ -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)]
|
||||
|
24
schala-lang/language/src/tree_walk_eval/test.rs
Normal file
24
schala-lang/language/src/tree_walk_eval/test.rs
Normal 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", "()");
|
||||
}
|
Loading…
Reference in New Issue
Block a user