Eval test doesn't need to be a macro

Can be a fn
This commit is contained in:
greg 2018-11-05 21:07:06 -08:00
parent 47f7eb1ef6
commit 17e88b33f2

View File

@ -508,24 +508,20 @@ mod eval_tests {
parser.parse() parser.parse()
} }
macro_rules! all_output { fn evaluate_all_outputs(input: &str) -> Vec<Result<String, String>> {
($string:expr) => { let symbol_table = Rc::new(RefCell::new(SymbolTable::new()));
{ let mut state = State::new(symbol_table);
let symbol_table = Rc::new(RefCell::new(SymbolTable::new())); let ast = parse(tokenize(input)).unwrap();
let mut state = State::new(symbol_table); state.symbol_table_handle.borrow_mut().add_top_level_symbols(&ast).unwrap();
let ast = parse(tokenize($string)).unwrap(); let reduced = ast.reduce(&state.symbol_table_handle.borrow());
state.symbol_table_handle.borrow_mut().add_top_level_symbols(&ast).unwrap(); let all_output = state.evaluate(reduced, true);
let reduced = ast.reduce(&state.symbol_table_handle.borrow()); all_output
let all_output = state.evaluate(reduced, true);
all_output
}
}
} }
macro_rules! test_in_fresh_env { macro_rules! test_in_fresh_env {
($string:expr, $correct:expr) => { ($string:expr, $correct:expr) => {
{ {
let all_output = all_output!($string); let all_output = evaluate_all_outputs($string);
let ref output = all_output.last().unwrap(); let ref output = all_output.last().unwrap();
assert_eq!(**output, Ok($correct.to_string())); assert_eq!(**output, Ok($correct.to_string()));
} }