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:
parent
4b587f11ab
commit
dc6342bc74
16 changed files with 575 additions and 677 deletions
|
|
@ -6,46 +6,19 @@ mod eval_tests {
|
|||
fn eval_simple() {
|
||||
let test_doc = "(1 2)".to_string();
|
||||
let mut syms = SymTable::new();
|
||||
match lex(&test_doc) {
|
||||
Err(e) => {
|
||||
println!("Lexing error: {}\n", e);
|
||||
assert!(false)
|
||||
}
|
||||
|
||||
Ok(initial_ast) => match eval(&initial_ast, &mut syms) {
|
||||
Err(e) => {
|
||||
println!("Evaluation error: {}\n", e);
|
||||
assert!(false)
|
||||
}
|
||||
|
||||
Ok(reduced) => {
|
||||
assert_eq!(reduced.to_string(), test_doc)
|
||||
}
|
||||
},
|
||||
}
|
||||
let doc_tree = lex(&test_doc).unwrap();
|
||||
let reduced = *eval(&doc_tree, &mut syms).unwrap();
|
||||
assert_eq!(reduced.to_string(), test_doc);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn eval_embedded_lists_no_funcs() {
|
||||
let test_doc = "(1 (1 2 3 4 5) 5)".to_string();
|
||||
let mut syms = SymTable::new();
|
||||
match lex(&test_doc) {
|
||||
Err(e) => {
|
||||
println!("Lexing error: {}\n", e);
|
||||
assert!(false)
|
||||
}
|
||||
let doc_tree = lex(&test_doc).unwrap();
|
||||
let reduced = *eval(&doc_tree, &mut syms).unwrap();
|
||||
assert_eq!(reduced.to_string(), test_doc);
|
||||
|
||||
Ok(initial_ast) => match eval(&initial_ast, &mut syms) {
|
||||
Err(e) => {
|
||||
println!("Evaluation error: {}\n", e);
|
||||
assert!(false)
|
||||
}
|
||||
|
||||
Ok(reduced) => {
|
||||
assert_eq!(reduced.to_string(), test_doc)
|
||||
}
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
|
@ -58,6 +31,7 @@ mod eval_tests {
|
|||
name: String::from("echo"),
|
||||
args: Args::Lazy(1),
|
||||
conditional_branches: false,
|
||||
docs: String::new(),
|
||||
value: ValueType::FuncForm(UserFn {
|
||||
arg_syms: vec!["input".to_string()],
|
||||
ast: Box::new(Seg::from(
|
||||
|
|
@ -68,24 +42,9 @@ mod eval_tests {
|
|||
};
|
||||
|
||||
syms.insert(String::from("echo"), test_external_func);
|
||||
|
||||
match lex(&test_doc) {
|
||||
Err(e) => {
|
||||
println!("Lexing error: {}\n", e);
|
||||
assert!(false)
|
||||
}
|
||||
|
||||
Ok(initial_ast) => match eval(&initial_ast, &mut syms) {
|
||||
Err(e) => {
|
||||
println!("Evaluation error: {}\n", e);
|
||||
assert!(false)
|
||||
}
|
||||
|
||||
Ok(reduced) => {
|
||||
assert_eq!(reduced.to_string(), output)
|
||||
}
|
||||
},
|
||||
}
|
||||
let doc_tree = lex(&test_doc).unwrap();
|
||||
let reduced = *eval(&doc_tree, &mut syms).unwrap();
|
||||
assert_eq!(reduced.to_string(), output);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
|
@ -98,6 +57,7 @@ mod eval_tests {
|
|||
name: String::from("echo"),
|
||||
args: Args::Lazy(1),
|
||||
conditional_branches: false,
|
||||
docs: String::new(),
|
||||
value: ValueType::FuncForm(UserFn {
|
||||
arg_syms: vec!["input".to_string()],
|
||||
ast: Box::new(Seg::from(
|
||||
|
|
@ -108,46 +68,26 @@ mod eval_tests {
|
|||
};
|
||||
|
||||
syms.insert(String::from("echo"), test_external_func);
|
||||
match lex(&test_doc) {
|
||||
Err(e) => {
|
||||
println!("Lexing error: {}\n", e);
|
||||
assert!(false)
|
||||
}
|
||||
|
||||
Ok(initial_ast) => match eval(&initial_ast, &mut syms) {
|
||||
Err(e) => {
|
||||
println!("Evaluation error: {}\n", e);
|
||||
assert!(false)
|
||||
}
|
||||
|
||||
Ok(reduced) => {
|
||||
assert_eq!(reduced.to_string(), output)
|
||||
}
|
||||
},
|
||||
}
|
||||
let doc_tree = lex(&test_doc).unwrap();
|
||||
let reduced = *eval(&doc_tree, &mut syms).unwrap();
|
||||
assert_eq!(reduced.to_string(), output);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn eval_bad_syms() {
|
||||
let test_doc = "(undefined)".to_string();
|
||||
let mut syms = SymTable::new();
|
||||
match lex(&test_doc) {
|
||||
let doc_tree = lex(&test_doc).unwrap();
|
||||
match eval(&doc_tree, &mut syms) {
|
||||
Err(e) => {
|
||||
println!("Lexing error: {}\n", e);
|
||||
assert!(false)
|
||||
assert_eq!(e, "error in call to undefined: undefined symbol: undefined")
|
||||
}
|
||||
|
||||
Ok(initial_ast) => match eval(&initial_ast, &mut syms) {
|
||||
Err(e) => {
|
||||
assert_eq!(e, "error in call to undefined: undefined symbol: undefined")
|
||||
}
|
||||
|
||||
Ok(reduced) => {
|
||||
println!("Eval succeeded when it shouldnt have");
|
||||
println!("see: {}", reduced);
|
||||
assert!(false)
|
||||
}
|
||||
},
|
||||
Ok(reduced) => {
|
||||
println!("Eval succeeded when it shouldnt have");
|
||||
println!("see: {}", reduced);
|
||||
assert!(false)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue