implement basic control flow, error handling from functions, many tests
Signed-off-by: Ava Hahn <ava@aidanis.online>
This commit is contained in:
parent
ae365ad63c
commit
09e3546ba6
14 changed files with 315 additions and 488 deletions
64
tests/test_lib_control.rs
Normal file
64
tests/test_lib_control.rs
Normal file
|
|
@ -0,0 +1,64 @@
|
|||
mod control_lib_tests {
|
||||
use relish::ast::{Ctr, eval, lex, SymTable};
|
||||
use relish::stdlib::{static_stdlib, dynamic_stdlib};
|
||||
|
||||
#[test]
|
||||
fn test_if_first_case_singlet() {
|
||||
let document = "(if true 1 2)";
|
||||
let result = 1;
|
||||
|
||||
let mut syms = SymTable::new();
|
||||
static_stdlib(&mut syms).unwrap();
|
||||
dynamic_stdlib(false, &mut syms).unwrap();
|
||||
|
||||
if let Ok(tree) = lex(&document.to_string()) {
|
||||
if let Ctr::Integer(i) = *eval(&tree, &mut syms).unwrap() {
|
||||
assert_eq!(i, result);
|
||||
} else {
|
||||
assert!(false);
|
||||
}
|
||||
} else {
|
||||
assert!(false);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_if_second_case_singlet() {
|
||||
let document = "(if false 1 2)";
|
||||
let result = 2;
|
||||
|
||||
let mut syms = SymTable::new();
|
||||
static_stdlib(&mut syms).unwrap();
|
||||
dynamic_stdlib(false, &mut syms).unwrap();
|
||||
|
||||
if let Ok(tree) = lex(&document.to_string()) {
|
||||
if let Ctr::Integer(i) = *eval(&tree, &mut syms).unwrap() {
|
||||
assert_eq!(i, result);
|
||||
} else {
|
||||
assert!(false);
|
||||
}
|
||||
} else {
|
||||
assert!(false);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_complex_case_call() {
|
||||
let document = "(if true (append () 1) 2)";
|
||||
let result = "(1)";
|
||||
|
||||
let mut syms = SymTable::new();
|
||||
static_stdlib(&mut syms).unwrap();
|
||||
dynamic_stdlib(false, &mut syms).unwrap();
|
||||
|
||||
if let Ok(tree) = lex(&document.to_string()) {
|
||||
if let Ctr::Seg(ref i) = *eval(&tree, &mut syms).unwrap() {
|
||||
assert_eq!(i.to_string(), result);
|
||||
} else {
|
||||
assert!(false);
|
||||
}
|
||||
} else {
|
||||
assert!(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue