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
|
|
@ -5,146 +5,99 @@ mod bool_lib_tests {
|
|||
#[test]
|
||||
fn test_and_true_chain() {
|
||||
let document = "(and true true true true true)";
|
||||
let result = true;
|
||||
|
||||
let result = "true";
|
||||
let mut syms = SymTable::new();
|
||||
static_stdlib(&mut syms).unwrap();
|
||||
dynamic_stdlib(&mut syms).unwrap();
|
||||
|
||||
if let Ok(tree) = lex(&document.to_string()) {
|
||||
if let Ctr::Bool(b) = *eval(&tree, &mut syms).unwrap() {
|
||||
assert_eq!(b, result);
|
||||
} else {
|
||||
assert!(false);
|
||||
}
|
||||
} else {
|
||||
assert!(false);
|
||||
}
|
||||
assert_eq!(
|
||||
*eval(&lex(&document.to_string()).unwrap(), &mut syms).unwrap().to_string(),
|
||||
result.to_string(),
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_and_true_chain_with_false() {
|
||||
let document = "(and true true false true true)";
|
||||
let result = false;
|
||||
|
||||
let result = "false";
|
||||
let mut syms = SymTable::new();
|
||||
static_stdlib(&mut syms).unwrap();
|
||||
dynamic_stdlib(&mut syms).unwrap();
|
||||
|
||||
if let Ok(tree) = lex(&document.to_string()) {
|
||||
if let Ctr::Bool(i) = *eval(&tree, &mut syms).unwrap() {
|
||||
assert_eq!(i, result);
|
||||
} else {
|
||||
assert!(false);
|
||||
}
|
||||
} else {
|
||||
assert!(false);
|
||||
}
|
||||
assert_eq!(
|
||||
*eval(&lex(&document.to_string()).unwrap(), &mut syms).unwrap().to_string(),
|
||||
result.to_string(),
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_and_false_chain() {
|
||||
let document = "(and false false false false false)";
|
||||
let result = false;
|
||||
|
||||
let result = "false";
|
||||
let mut syms = SymTable::new();
|
||||
static_stdlib(&mut syms).unwrap();
|
||||
dynamic_stdlib(&mut syms).unwrap();
|
||||
|
||||
if let Ok(tree) = lex(&document.to_string()) {
|
||||
if let Ctr::Bool(i) = *eval(&tree, &mut syms).unwrap() {
|
||||
assert_eq!(i, result);
|
||||
} else {
|
||||
assert!(false);
|
||||
}
|
||||
} else {
|
||||
assert!(false);
|
||||
}
|
||||
assert_eq!(
|
||||
*eval(&lex(&document.to_string()).unwrap(), &mut syms).unwrap().to_string(),
|
||||
result.to_string(),
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_or_true_chain() {
|
||||
let document = "(or true true true true true)";
|
||||
let result = true;
|
||||
|
||||
let result = "true";
|
||||
let mut syms = SymTable::new();
|
||||
static_stdlib(&mut syms).unwrap();
|
||||
dynamic_stdlib(&mut syms).unwrap();
|
||||
assert_eq!(
|
||||
*eval(&lex(&document.to_string()).unwrap(), &mut syms).unwrap().to_string(),
|
||||
result.to_string(),
|
||||
);
|
||||
|
||||
if let Ok(tree) = lex(&document.to_string()) {
|
||||
if let Ctr::Bool(b) = *eval(&tree, &mut syms).unwrap() {
|
||||
assert_eq!(b, result);
|
||||
} else {
|
||||
assert!(false);
|
||||
}
|
||||
} else {
|
||||
assert!(false);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_or_true_chain_with_false() {
|
||||
let document = "(or true true false true true)";
|
||||
let result = true;
|
||||
|
||||
let result = "true";
|
||||
let mut syms = SymTable::new();
|
||||
static_stdlib(&mut syms).unwrap();
|
||||
dynamic_stdlib(&mut syms).unwrap();
|
||||
assert_eq!(
|
||||
*eval(&lex(&document.to_string()).unwrap(), &mut syms).unwrap().to_string(),
|
||||
result.to_string(),
|
||||
);
|
||||
|
||||
if let Ok(tree) = lex(&document.to_string()) {
|
||||
if let Ctr::Bool(i) = *eval(&tree, &mut syms).unwrap() {
|
||||
assert_eq!(i, result);
|
||||
} else {
|
||||
assert!(false);
|
||||
}
|
||||
} else {
|
||||
assert!(false);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_or_false_chain() {
|
||||
let document = "(or false false false false)";
|
||||
let result = false;
|
||||
|
||||
let document = "(or false false false false false)";
|
||||
let result = "false";
|
||||
let mut syms = SymTable::new();
|
||||
static_stdlib(&mut syms).unwrap();
|
||||
dynamic_stdlib(&mut syms).unwrap();
|
||||
|
||||
if let Ok(tree) = lex(&document.to_string()) {
|
||||
if let Ctr::Bool(i) = *eval(&tree, &mut syms).unwrap() {
|
||||
assert_eq!(i, result);
|
||||
} else {
|
||||
assert!(false);
|
||||
}
|
||||
} else {
|
||||
assert!(false);
|
||||
}
|
||||
assert_eq!(
|
||||
*eval(&lex(&document.to_string()).unwrap(), &mut syms).unwrap().to_string(),
|
||||
result.to_string(),
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_not() {
|
||||
let document = "(not true)";
|
||||
let result = false;
|
||||
|
||||
let result = "false";
|
||||
let mut syms = SymTable::new();
|
||||
static_stdlib(&mut syms).unwrap();
|
||||
dynamic_stdlib(&mut syms).unwrap();
|
||||
|
||||
if let Ok(tree) = lex(&document.to_string()) {
|
||||
if let Ctr::Bool(i) = *eval(&tree, &mut syms).unwrap() {
|
||||
assert_eq!(i, result);
|
||||
} else {
|
||||
assert!(false);
|
||||
}
|
||||
} else {
|
||||
assert!(false);
|
||||
}
|
||||
assert_eq!(
|
||||
*eval(&lex(&document.to_string()).unwrap(), &mut syms).unwrap().to_string(),
|
||||
result.to_string(),
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_toggle_a_bool() {
|
||||
let document = "(def tester true)";
|
||||
let document = "(def tester '' true)";
|
||||
let change = "(toggle tester)";
|
||||
let check = "(tester)";
|
||||
|
||||
|
|
@ -183,7 +136,7 @@ mod bool_lib_tests {
|
|||
|
||||
#[test]
|
||||
fn test_toggle_errors_dont_lose_vars() {
|
||||
let document = "(def tester 'oops')";
|
||||
let document = "(def tester '' 'oops')";
|
||||
let change = "(toggle tester)";
|
||||
let check = "(tester)";
|
||||
|
||||
|
|
@ -216,7 +169,7 @@ mod bool_lib_tests {
|
|||
|
||||
#[test]
|
||||
fn test_toggle_errors_dont_lose_funcs() {
|
||||
let document = "(def tester (oops) oops)";
|
||||
let document = "(def tester '' (oops) oops)";
|
||||
let change = "(toggle tester)";
|
||||
let check = "(tester '1')";
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue