undid eval tweaks, made tests for weird def cases

This commit is contained in:
Ava Apples Affine 2023-03-17 12:21:42 -07:00
parent 2dfe73de6b
commit a01df6b7b2
Signed by: affine
GPG key ID: 3A4645B8CF806069
2 changed files with 60 additions and 11 deletions

View file

@ -88,6 +88,46 @@ mod decl_lib_tests {
}
}
#[test]
fn test_variable_def_redef_via_reference_and_lookup() {
let doc1 = "(def test 'my test var' 1)";
let doc2 = "(def ref 'references test' (quote test))";
let doc3 = "(def (eval ref) 'my test var' '2')";
let doc4 = "(test)";
let result = "('2')";
let mut syms = SymTable::new();
static_stdlib(&mut syms).unwrap();
dynamic_stdlib(&mut syms).unwrap();
eval(&lex(&doc1.to_string()).unwrap(), &mut syms).unwrap();
eval(&lex(&doc2.to_string()).unwrap(), &mut syms).unwrap();
eval(&lex(&doc3.to_string()).unwrap(), &mut syms).unwrap();
let res = *eval(&lex(&doc4.to_string()).unwrap(), &mut syms).unwrap();
assert_eq!(res.to_string(), result);
}
#[test]
fn test_variable_doc_dynamic() {
let doc1 = "(def test-doc 'docs for test' 'test tests tests test')";
let doc2 = "(def test test-doc 'one')";
let doc3 = "(eq? (and
(eq? (get-doc test) test-doc)
(eq? test 'one')))";
let mut syms = SymTable::new();
static_stdlib(&mut syms).unwrap();
dynamic_stdlib(&mut syms).unwrap();
eval(&lex(&doc1.to_string()).unwrap(), &mut syms).unwrap();
eval(&lex(&doc2.to_string()).unwrap(), &mut syms).unwrap();
if let Ctr::Bool(b) = *eval(&lex(&doc3.to_string()).unwrap(), &mut syms).unwrap() {
assert!(b);
} else {
assert!(false);
}
}
#[test]
fn test_func_def_no_args() {
let doc1 = "(def test 'my test func' () 1)";
@ -195,6 +235,8 @@ mod decl_lib_tests {
);
}
/* THIS TEST REMOVED BECAUSE EVAL SHOULDNT ARBITRARILY DO THINGS TWICE
* KEPT FOR REFERENCE PURPOSES JUST IN CASE
#[test]
fn test_eval_var_deref() {
let def1 = "(def one '' 1)";
@ -212,7 +254,7 @@ mod decl_lib_tests {
.to_string(),
result.to_string(),
);
}
}*/
#[test]
fn test_lambda_str_equivalency_list() {