From 81859306b388680f3434a2ac3acdb7bf8317b4e7 Mon Sep 17 00:00:00 2001 From: Greg Shuflin Date: Sun, 24 Oct 2021 21:54:08 -0700 Subject: [PATCH] Add tree walk eval test --- schala-lang/language/src/eval/test.rs | 2 +- .../language/src/tree_walk_eval/mod.rs | 2 ++ .../language/src/tree_walk_eval/test.rs | 24 +++++++++++++++++++ 3 files changed, 27 insertions(+), 1 deletion(-) create mode 100644 schala-lang/language/src/tree_walk_eval/test.rs diff --git a/schala-lang/language/src/eval/test.rs b/schala-lang/language/src/eval/test.rs index 185a5f4..032f184 100644 --- a/schala-lang/language/src/eval/test.rs +++ b/schala-lang/language/src/eval/test.rs @@ -13,7 +13,7 @@ fn evaluate_all_outputs(input: &str) -> Vec> { let reduced = reduce(&ast, &symbol_table); let mut state = State::new(); - + state.evaluate(reduced, true) } diff --git a/schala-lang/language/src/tree_walk_eval/mod.rs b/schala-lang/language/src/tree_walk_eval/mod.rs index fbcdd3b..8b4e2b8 100644 --- a/schala-lang/language/src/tree_walk_eval/mod.rs +++ b/schala-lang/language/src/tree_walk_eval/mod.rs @@ -7,6 +7,8 @@ use std::fmt::Write; use std::rc::Rc; use std::convert::From; +mod test; + type EvalResult = Result; #[derive(Debug)] diff --git a/schala-lang/language/src/tree_walk_eval/test.rs b/schala-lang/language/src/tree_walk_eval/test.rs new file mode 100644 index 0000000..1eca481 --- /dev/null +++ b/schala-lang/language/src/tree_walk_eval/test.rs @@ -0,0 +1,24 @@ +#![cfg(test)] + +use crate::symbol_table::SymbolTable; +use crate::tree_walk_eval::State; + +fn evaluate_input(input: &str) -> Result { + 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", "()"); +}