From e64861b602ae8ffec23d91e720e223371e6e1f38 Mon Sep 17 00:00:00 2001 From: greg Date: Mon, 14 May 2018 23:33:11 -0700 Subject: [PATCH] Some eval tests --- schala-lang/src/eval.rs | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/schala-lang/src/eval.rs b/schala-lang/src/eval.rs index 481e250..6581a1e 100644 --- a/schala-lang/src/eval.rs +++ b/schala-lang/src/eval.rs @@ -298,7 +298,6 @@ mod eval_tests { macro_rules! fresh_env { ($string:expr, $correct:expr) => { - let type_context = Rc::new(RefCell::new(TypeContext::new())); let mut state = State::new(type_context); let all_output = state.evaluate(parse(tokenize($string)).0.unwrap().reduce(), true); @@ -315,8 +314,31 @@ mod eval_tests { fresh_env!(r#"("a", 1 + 2)"#, r#"("a", 3)"#); } + #[test] fn function_eval() { fresh_env!("fn oi(x) { x + 1 }; oi(4)", "5"); fresh_env!("fn oi(x) { x + 1 }; oi(1+2)", "4"); } + + #[test] + fn scopes() { + let scope_ok = r#" + const a = 20 + fn haha() { + const a = 10 + a + } + haha() + "#; + fresh_env!(scope_ok, "10"); + let scope_ok = r#" + const a = 20 + fn haha() { + const a = 10 + a + } + a + "#; + fresh_env!(scope_ok, "20"); + } }