fix up def tests

Signed-off-by: Ava Hahn <ava@aidanis.online>
This commit is contained in:
Ava Hahn 2023-02-28 11:20:00 -08:00
parent 870b444505
commit c5e68f25ba
Signed by untrusted user who does not match committer: affine
GPG key ID: 3A4645B8CF806069
2 changed files with 15 additions and 8 deletions

View file

@ -58,9 +58,9 @@ pub fn static_stdlib(syms: &mut SymTable) -> Result<(), String> {
/// callbacks with configuration into a symtable /// callbacks with configuration into a symtable
pub fn dynamic_stdlib(env: bool, syms: &mut SymTable) -> Result<(), String> { pub fn dynamic_stdlib(env: bool, syms: &mut SymTable) -> Result<(), String> {
syms.insert("def".to_string(), Symbol { syms.insert("def".to_string(), Symbol {
name: String::from("export"), name: String::from("define"),
args: Args::Lazy(2), args: Args::Lazy(2),
conditional_branches: false, conditional_branches: true,
value: ValueType::Internal(Rc::new( move |ast: &Seg, syms: &mut SymTable| -> Result<Ctr, String> { value: ValueType::Internal(Rc::new( move |ast: &Seg, syms: &mut SymTable| -> Result<Ctr, String> {
_store_callback(ast, syms, env) _store_callback(ast, syms, env)
}, },

View file

@ -4,31 +4,38 @@ mod var_lib_tests {
#[test] #[test]
fn test_variable_export_and_lookup() { fn test_variable_export_and_lookup() {
let doc1 = "(export test 1)"; let doc1 = "(def test 1)";
let doc2 = "test"; let doc2 = "(test)";
let result = 1; let result = "(1)";
let mut syms = SymTable::new(); let mut syms = SymTable::new();
static_stdlib(&mut syms).unwrap(); static_stdlib(&mut syms).unwrap();
dynamic_stdlib(false, &mut syms).unwrap(); dynamic_stdlib(false, &mut syms).unwrap();
if let Ok(tree) = lex(&doc1.to_string()) { 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 // pass
} else { } else {
eprintln!("bad: {eval_result}");
assert!(false); assert!(false);
} }
} else { } else {
eprintln!("couldn't lex doc1");
assert!(false); assert!(false);
} }
if let Ok(tree) = lex(&doc2.to_string()) { if let Ok(tree) = lex(&doc2.to_string()) {
if let Ctr::Integer(i) = *eval(&tree, &mut syms).unwrap() { println!("tree: {tree}");
assert_eq!(i, result); let eval_result = *eval(&tree, &mut syms).unwrap();
if let Ctr::Seg(ref i) = eval_result {
assert_eq!(i.to_string(), result);
} else { } else {
eprintln!("bad: {eval_result}");
assert!(false); assert!(false);
} }
} else { } else {
eprintln!("couldn't lex doc2");
assert!(false); assert!(false);
} }
} }