Several changes, see commit msg

* clean up all tests
* bugfix for zero value functions, and test
* removed expand function, put in snippets
* added doc strings to Symbol type
* added doc strings to symbol declarations
* implemented display for Args type
* wrote a help function
* wrote docstrings for all builtins and config vars
This commit is contained in:
Ava Hahn 2023-03-05 22:18:49 -08:00
parent 4b587f11ab
commit dc6342bc74
Signed by untrusted user who does not match committer: affine
GPG key ID: 3A4645B8CF806069
16 changed files with 575 additions and 677 deletions

View file

@ -4,7 +4,7 @@ mod var_lib_tests {
#[test]
fn test_variable_def_and_lookup() {
let doc1 = "(def test 1)";
let doc1 = "(def test 'my test var' 1)";
let doc2 = "(test)";
let result = "(1)";
@ -42,7 +42,7 @@ mod var_lib_tests {
#[test]
fn test_func_def_and_lookup() {
let doc1 = "(def test (hello) hello)";
let doc1 = "(def test 'my test func' (hello) hello)";
let doc2 = "(test '1')";
let result = "1";
@ -79,8 +79,8 @@ mod var_lib_tests {
#[test]
fn test_variable_def_redef_and_lookup() {
let doc1 = "(def test 1)";
let doc2 = "(def test '2')";
let doc1 = "(def test 'my test var' 1)";
let doc2 = "(def test 'my test var' '2')";
let doc3 = "(test)";
let result = "('2')";
@ -132,7 +132,7 @@ mod var_lib_tests {
#[test]
fn test_variable_def_undef_and_lookup_fail() {
let doc1 = "(def test 1)";
let doc1 = "(def test 'my test var' 1)";
let doc2 = "(def test)";
let doc3 = "(test)";
@ -185,4 +185,41 @@ mod var_lib_tests {
assert!(false);
}
}
#[test]
fn test_func_def_no_args() {
let doc1 = "(def test 'my test func' () '1')";
let doc2 = "(test)";
let result = "1";
let mut syms = SymTable::new();
static_stdlib(&mut syms).unwrap();
dynamic_stdlib(&mut syms).unwrap();
if let Ok(tree) = lex(&doc1.to_string()) {
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()) {
let eval_result = *eval(&tree, &mut syms).unwrap();
if let Ctr::String(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);
}
}
}