From c5e68f25ba2fb6cd316a431d0225959b5ce833bc Mon Sep 17 00:00:00 2001 From: Ava Hahn Date: Tue, 28 Feb 2023 11:20:00 -0800 Subject: [PATCH] fix up def tests Signed-off-by: Ava Hahn --- src/stl.rs | 4 ++-- tests/test_vars.rs | 19 +++++++++++++------ 2 files changed, 15 insertions(+), 8 deletions(-) diff --git a/src/stl.rs b/src/stl.rs index e63d0f1..741d7e0 100644 --- a/src/stl.rs +++ b/src/stl.rs @@ -58,9 +58,9 @@ pub fn static_stdlib(syms: &mut SymTable) -> Result<(), String> { /// callbacks with configuration into a symtable pub fn dynamic_stdlib(env: bool, syms: &mut SymTable) -> Result<(), String> { syms.insert("def".to_string(), Symbol { - name: String::from("export"), + name: String::from("define"), args: Args::Lazy(2), - conditional_branches: false, + conditional_branches: true, value: ValueType::Internal(Rc::new( move |ast: &Seg, syms: &mut SymTable| -> Result { _store_callback(ast, syms, env) }, diff --git a/tests/test_vars.rs b/tests/test_vars.rs index f412c06..431ef4c 100644 --- a/tests/test_vars.rs +++ b/tests/test_vars.rs @@ -4,31 +4,38 @@ mod var_lib_tests { #[test] fn test_variable_export_and_lookup() { - let doc1 = "(export test 1)"; - let doc2 = "test"; - let result = 1; + let doc1 = "(def test 1)"; + let doc2 = "(test)"; + let result = "(1)"; let mut syms = SymTable::new(); static_stdlib(&mut syms).unwrap(); dynamic_stdlib(false, &mut syms).unwrap(); if let Ok(tree) = lex(&doc1.to_string()) { - if let Ctr::None = *eval(&tree, &mut syms).unwrap() { + let eval_result = *eval(&tree, &mut syms).unwrap(); + if let Ctr::None = eval_result { // pass } else { + eprintln!("bad: {eval_result}"); assert!(false); } } else { + eprintln!("couldn't lex doc1"); assert!(false); } if let Ok(tree) = lex(&doc2.to_string()) { - if let Ctr::Integer(i) = *eval(&tree, &mut syms).unwrap() { - assert_eq!(i, result); + println!("tree: {tree}"); + let eval_result = *eval(&tree, &mut syms).unwrap(); + if let Ctr::Seg(ref i) = eval_result { + assert_eq!(i.to_string(), result); } else { + eprintln!("bad: {eval_result}"); assert!(false); } } else { + eprintln!("couldn't lex doc2"); assert!(false); } }