From 856a0808deaa0f2efd2e2783bdfa4ec8e6a4c5ed Mon Sep 17 00:00:00 2001 From: Greg Shuflin Date: Sun, 24 Oct 2021 22:44:52 -0700 Subject: [PATCH] Start moving over eval tests --- schala-lang/language/src/eval/test.rs | 44 ------------------- .../language/src/tree_walk_eval/test.rs | 43 ++++++++++++++++++ 2 files changed, 43 insertions(+), 44 deletions(-) diff --git a/schala-lang/language/src/eval/test.rs b/schala-lang/language/src/eval/test.rs index 032f184..f89639c 100644 --- a/schala-lang/language/src/eval/test.rs +++ b/schala-lang/language/src/eval/test.rs @@ -27,50 +27,6 @@ macro_rules! test_in_fresh_env { } } -#[test] -fn test_basic_eval() { - test_in_fresh_env!("1 + 2", "3"); - test_in_fresh_env!("let mut a = 1; a = 2", "()"); - /* - test_in_fresh_env!("let mut a = 1; a = 2; a", "2"); - test_in_fresh_env!(r#"("a", 1 + 2)"#, r#"("a", 3)"#); - */ -} - -#[test] -fn op_eval() { - test_in_fresh_env!("- 13", "-13"); - test_in_fresh_env!("10 - 2", "8"); -} - -#[test] -fn function_eval() { - test_in_fresh_env!("fn oi(x) { x + 1 }; oi(4)", "5"); - test_in_fresh_env!("fn oi(x) { x + 1 }; oi(1+2)", "4"); -} - -#[test] -fn scopes() { - let scope_ok = r#" - let a = 20 - fn haha() { - let a = 10 - a - } - haha() - "#; - test_in_fresh_env!(scope_ok, "10"); - let scope_ok = r#" - let a = 20 - fn queque() { - let a = 10 - a - } - a - "#; - test_in_fresh_env!(scope_ok, "20"); -} - #[test] fn if_is_patterns() { let source = r#" diff --git a/schala-lang/language/src/tree_walk_eval/test.rs b/schala-lang/language/src/tree_walk_eval/test.rs index 1eca481..e919e37 100644 --- a/schala-lang/language/src/tree_walk_eval/test.rs +++ b/schala-lang/language/src/tree_walk_eval/test.rs @@ -21,4 +21,47 @@ fn eval_assert(input: &str, expected: &str) { fn test_basic_eval() { eval_assert("1 + 2", "3"); //eval_assert("let mut a = 1; a = 2", "()"); + /* + test_in_fresh_env!("let mut a = 1; a = 2; a", "2"); + test_in_fresh_env!(r#"("a", 1 + 2)"#, r#"("a", 3)"#); + */ } + +#[test] +fn op_eval() { + eval_assert("- 13", "-13"); + eval_assert("10 - 2", "8"); +} + +#[test] +fn function_eval() { + eval_assert("fn oi(x) { x + 1 }; oi(4)", "5"); + eval_assert("fn oi(x) { x + 1 }; oi(1+2)", "4"); +} + +#[test] +fn scopes() { + /* + let scope_ok = r#" + let a = 20 + fn haha() { + let a = 10 + a + } + haha() + "#; + + eval_assert(scope_ok, "10"); + + let scope_ok = r#" + let a = 20 + fn queque() { + let a = 10 + a + } + a + "#; + eval_assert(scope_ok, "20"); + */ +} +