fix up def tests
Signed-off-by: Ava Hahn <ava@aidanis.online>
This commit is contained in:
parent
870b444505
commit
c5e68f25ba
2 changed files with 15 additions and 8 deletions
|
|
@ -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<Ctr, String> {
|
||||
_store_callback(ast, syms, env)
|
||||
},
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue