mod func_tests { use std::rc::Rc; use std::cell::RefCell; use relish::ast::{Ast, Type, Ctr, new_ast}; use relish::ast::VTable; use relish::ast::{Function, Operation, FTable, Args, func_declare, func_call}; #[test] fn decl_and_call_internal_func() { let test_internal_func: Function = Function{ name: String::from("test_func_in"), loose_syms: false, eval_lazy: true, args: Args::Strict(vec![Type::Bool]), function: Operation::Internal( |a: Ast, _b: Rc>, _c: Rc>| -> Ast { let inner = a.borrow(); let mut is_bool = false; if let Ctr::Bool(_) = &inner.car { is_bool = true; } Ctr::Bool(is_bool) } ) }; let ft = Rc::new(RefCell::new(FTable::new())); let vt = Rc::new(RefCell::new(VTable::new())); let args = new_ast(Ctr::Bool(true), Ctr::None); if let Some(s) = func_declare(ft.clone(), Rc::new(RefCell::new(test_internal_func))) { print!("{}", s); assert!(false); } let func: Rc>; if let Some(f) = ft.borrow().get(&"test_func_in".to_string()) { func = f.clone(); } else { print!("failed to retrieve function!"); assert!(false); return; } if let Ok(ret) = func_call(func, args, vt, ft) { match ret { Ctr::Bool(b) => assert!(b), _ => { print!("invalid return from func!"); assert!(false); } } } else { print!("call to function failed!"); assert!(false); } } }