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
|
|
@ -1,46 +1,22 @@
|
|||
mod append_lib_tests {
|
||||
use relish::ast::{ast_to_string, eval, lex, Ctr, FTable, VTable};
|
||||
use relish::stdlib::get_stdlib;
|
||||
use std::cell::RefCell;
|
||||
use std::rc::Rc;
|
||||
use relish::ast::{Ctr, eval, lex, SymTable};
|
||||
use relish::stdlib::{static_stdlib, dynamic_stdlib};
|
||||
|
||||
#[test]
|
||||
fn test_append_to_empty_list() {
|
||||
let document = "(append () 1 2 3)";
|
||||
let result = "(1 2 3)";
|
||||
let vt = Rc::new(RefCell::new(VTable::new()));
|
||||
let ft: Rc<RefCell<FTable>>;
|
||||
match get_stdlib(vt.clone()) {
|
||||
Ok(f) => ft = f,
|
||||
Err(s) => {
|
||||
ft = Rc::new(RefCell::new(FTable::new()));
|
||||
println!("Couldnt get stdlib: {}!", s);
|
||||
assert!(false)
|
||||
let document = "(append () 1)";
|
||||
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 s) = *eval(&tree, &mut syms).unwrap() {
|
||||
assert_eq!(s.to_string(), result);
|
||||
}
|
||||
}
|
||||
|
||||
match lex(document.to_string()) {
|
||||
Err(s) => {
|
||||
println!("Couldnt lex {}: {}\n", document, s);
|
||||
assert!(false);
|
||||
}
|
||||
|
||||
Ok(tree) => match eval(tree, vt.clone(), ft.clone(), false) {
|
||||
Err(s) => {
|
||||
println!("Couldnt eval {}: {}\n", document, s);
|
||||
assert!(false);
|
||||
}
|
||||
|
||||
Ok(ctr) => match ctr {
|
||||
Ctr::Symbol(_) => assert!(false),
|
||||
Ctr::String(_) => assert!(false),
|
||||
Ctr::Integer(_) => assert!(false),
|
||||
Ctr::Float(_) => assert!(false),
|
||||
Ctr::Bool(_) => assert!(false),
|
||||
Ctr::Seg(s) => assert_eq!(ast_to_string(s), result),
|
||||
Ctr::None => assert!(false),
|
||||
},
|
||||
},
|
||||
} else {
|
||||
assert!(false)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -48,79 +24,35 @@ mod append_lib_tests {
|
|||
fn test_append_to_full_list() {
|
||||
let document = "(append (1 2) 3)";
|
||||
let result = "(1 2 3)";
|
||||
let vt = Rc::new(RefCell::new(VTable::new()));
|
||||
let ft: Rc<RefCell<FTable>>;
|
||||
match get_stdlib(vt.clone()) {
|
||||
Ok(f) => ft = f,
|
||||
Err(s) => {
|
||||
ft = Rc::new(RefCell::new(FTable::new()));
|
||||
println!("Couldnt get stdlib: {}!", s);
|
||||
assert!(false)
|
||||
|
||||
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 s) = *eval(&tree, &mut syms).unwrap() {
|
||||
assert_eq!(s.to_string(), result);
|
||||
}
|
||||
}
|
||||
|
||||
match lex(document.to_string()) {
|
||||
Err(s) => {
|
||||
println!("Couldnt lex {}: {}\n", document, s);
|
||||
assert!(false);
|
||||
}
|
||||
|
||||
Ok(tree) => match eval(tree, vt.clone(), ft.clone(), false) {
|
||||
Err(s) => {
|
||||
println!("Couldnt eval {}: {}\n", document, s);
|
||||
assert!(false);
|
||||
}
|
||||
|
||||
Ok(ctr) => match ctr {
|
||||
Ctr::Symbol(_) => assert!(false),
|
||||
Ctr::String(_) => assert!(false),
|
||||
Ctr::Integer(_) => assert!(false),
|
||||
Ctr::Float(_) => assert!(false),
|
||||
Ctr::Bool(_) => assert!(false),
|
||||
Ctr::Seg(s) => assert_eq!(ast_to_string(s), result),
|
||||
Ctr::None => assert!(false),
|
||||
},
|
||||
},
|
||||
} else {
|
||||
assert!(false);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_mono_append() {
|
||||
let document = "(append)";
|
||||
let result = "()";
|
||||
let vt = Rc::new(RefCell::new(VTable::new()));
|
||||
let ft: Rc<RefCell<FTable>>;
|
||||
match get_stdlib(vt.clone()) {
|
||||
Ok(f) => ft = f,
|
||||
Err(s) => {
|
||||
ft = Rc::new(RefCell::new(FTable::new()));
|
||||
println!("Couldnt get stdlib: {}!", s);
|
||||
assert!(false)
|
||||
let result = "(<nil>)";
|
||||
|
||||
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 s) = *eval(&tree, &mut syms).unwrap() {
|
||||
assert_eq!(s.to_string(), result);
|
||||
}
|
||||
}
|
||||
|
||||
match lex(document.to_string()) {
|
||||
Err(s) => {
|
||||
println!("Couldnt lex {}: {}\n", document, s);
|
||||
assert!(false);
|
||||
}
|
||||
|
||||
Ok(tree) => match eval(tree, vt.clone(), ft.clone(), false) {
|
||||
Err(s) => {
|
||||
println!("Couldnt eval {}: {}\n", document, s);
|
||||
assert!(false);
|
||||
}
|
||||
|
||||
Ok(ctr) => match ctr {
|
||||
Ctr::Symbol(_) => assert!(false),
|
||||
Ctr::String(_) => assert!(false),
|
||||
Ctr::Integer(_) => assert!(false),
|
||||
Ctr::Float(_) => assert!(false),
|
||||
Ctr::Bool(_) => assert!(false),
|
||||
Ctr::Seg(s) => assert_eq!(ast_to_string(s), result),
|
||||
Ctr::None => assert!(false),
|
||||
},
|
||||
},
|
||||
} else {
|
||||
assert!(false);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -128,39 +60,17 @@ mod append_lib_tests {
|
|||
fn test_append_no_list() {
|
||||
let document = "(append 'test' 1 2 3)";
|
||||
let result = "('test' 1 2 3)";
|
||||
let vt = Rc::new(RefCell::new(VTable::new()));
|
||||
let ft: Rc<RefCell<FTable>>;
|
||||
match get_stdlib(vt.clone()) {
|
||||
Ok(f) => ft = f,
|
||||
Err(s) => {
|
||||
ft = Rc::new(RefCell::new(FTable::new()));
|
||||
println!("Couldnt get stdlib: {}!", s);
|
||||
assert!(false)
|
||||
|
||||
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 s) = *eval(&tree, &mut syms).unwrap() {
|
||||
assert_eq!(s.to_string(), result);
|
||||
}
|
||||
}
|
||||
|
||||
match lex(document.to_string()) {
|
||||
Err(s) => {
|
||||
println!("Couldnt lex {}: {}\n", document, s);
|
||||
assert!(false);
|
||||
}
|
||||
|
||||
Ok(tree) => match eval(tree, vt.clone(), ft.clone(), false) {
|
||||
Err(s) => {
|
||||
println!("Couldnt eval {}: {}\n", document, s);
|
||||
assert!(false);
|
||||
}
|
||||
|
||||
Ok(ctr) => match ctr {
|
||||
Ctr::Symbol(_) => assert!(false),
|
||||
Ctr::String(_) => assert!(false),
|
||||
Ctr::Integer(_) => assert!(false),
|
||||
Ctr::Float(_) => assert!(false),
|
||||
Ctr::Bool(_) => assert!(false),
|
||||
Ctr::Seg(s) => assert_eq!(ast_to_string(s), result),
|
||||
Ctr::None => assert!(false),
|
||||
},
|
||||
},
|
||||
} else {
|
||||
assert!(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue