tests function now
Signed-off-by: Ava Hahn <ava@aidanis.online>
This commit is contained in:
parent
c70cbc701d
commit
8e13b5b87f
2 changed files with 61 additions and 112 deletions
|
|
@ -1,5 +1,5 @@
|
|||
mod eval_tests {
|
||||
use relish::ast::{eval, lex, SYM_TABLE};
|
||||
use relish::ast::{eval, lex, SymTable};
|
||||
use relish::ast::{Args, Symbol, Ctr, Seg, ValueType, UserFn};
|
||||
|
||||
// TODO: write generalized testing routine on top of list of inputs
|
||||
|
|
@ -7,13 +7,14 @@ mod eval_tests {
|
|||
#[test]
|
||||
fn eval_singlet() {
|
||||
let test_doc = "(1)".to_string();
|
||||
let mut syms = SymTable::new();
|
||||
match lex(&test_doc) {
|
||||
Err(e) => {
|
||||
println!("Lexing error: {}\n", e);
|
||||
assert!(false)
|
||||
}
|
||||
|
||||
Ok(ref initial_ast) => match eval(initial_ast, true, true) {
|
||||
Ok(ref initial_ast) => match eval(initial_ast, &mut syms) {
|
||||
Err(e) => {
|
||||
println!("Evaluation error: {}\n", e);
|
||||
assert!(false)
|
||||
|
|
@ -29,14 +30,14 @@ mod eval_tests {
|
|||
#[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)
|
||||
}
|
||||
|
||||
Ok(initial_ast) => match eval(&initial_ast, true, true) {
|
||||
Ok(initial_ast) => match eval(&initial_ast, &mut syms) {
|
||||
Err(e) => {
|
||||
println!("Evaluation error: {}\n", e);
|
||||
assert!(false)
|
||||
|
|
@ -53,33 +54,32 @@ mod eval_tests {
|
|||
fn eval_function_call() {
|
||||
let test_doc = "('one' (echo 'unwrap_me'))".to_string();
|
||||
let output = "('one' 'unwrap_me')";
|
||||
let mut syms = SymTable::new();
|
||||
|
||||
{ // we want the write lock to expire before eval
|
||||
let mut table_handle = SYM_TABLE.write().unwrap();
|
||||
let test_external_func: Symbol = Symbol {
|
||||
name: String::from("echo"),
|
||||
args: Args::Lazy(1),
|
||||
has_undefined_symbols: false,
|
||||
value: ValueType::FuncForm( UserFn {
|
||||
arg_syms: vec!["input".to_string()],
|
||||
ast: Box::new(Seg::from(
|
||||
Box::new(Ctr::Seg(Seg::from(
|
||||
Box::from(Ctr::Symbol("input".to_string())),
|
||||
Box::from(Ctr::None)))),
|
||||
Box::new(Ctr::None),
|
||||
)),
|
||||
}),
|
||||
};
|
||||
let test_external_func: Symbol = Symbol {
|
||||
name: String::from("echo"),
|
||||
args: Args::Lazy(1),
|
||||
conditional_branches: false,
|
||||
value: ValueType::FuncForm( UserFn {
|
||||
arg_syms: vec!["input".to_string()],
|
||||
ast: Box::new(Seg::from(
|
||||
Box::new(Ctr::Seg(Seg::from(
|
||||
Box::from(Ctr::Symbol("input".to_string())),
|
||||
Box::from(Ctr::None)))),
|
||||
Box::new(Ctr::None),
|
||||
)),
|
||||
}),
|
||||
};
|
||||
|
||||
syms.insert(String::from("echo"), test_external_func);
|
||||
|
||||
table_handle.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, true, true) {
|
||||
Ok(initial_ast) => match eval(&initial_ast, &mut syms) {
|
||||
Err(e) => {
|
||||
println!("Evaluation error: {}\n", e);
|
||||
assert!(false)
|
||||
|
|
@ -96,33 +96,31 @@ mod eval_tests {
|
|||
fn eval_embedded_func_calls() {
|
||||
let test_doc = "('one' (echo (echo 'unwrap_me')))".to_string();
|
||||
let output = "('one' 'unwrap_me')";
|
||||
let mut syms = SymTable::new();
|
||||
|
||||
{
|
||||
let mut table_handle = SYM_TABLE.write().unwrap();
|
||||
let test_external_func: Symbol = Symbol{
|
||||
name: String::from("echo"),
|
||||
args: Args::Lazy(1),
|
||||
has_undefined_symbols: false,
|
||||
value: ValueType::FuncForm( UserFn {
|
||||
arg_syms: vec!["input".to_string()],
|
||||
ast: Box::new(Seg::from(
|
||||
Box::new(Ctr::Seg(Seg::from(
|
||||
Box::from(Ctr::Symbol("input".to_string())),
|
||||
Box::from(Ctr::None)))),
|
||||
Box::new(Ctr::None),
|
||||
)),
|
||||
}),
|
||||
};
|
||||
let test_external_func: Symbol = Symbol{
|
||||
name: String::from("echo"),
|
||||
args: Args::Lazy(1),
|
||||
conditional_branches: false,
|
||||
value: ValueType::FuncForm( UserFn {
|
||||
arg_syms: vec!["input".to_string()],
|
||||
ast: Box::new(Seg::from(
|
||||
Box::new(Ctr::Seg(Seg::from(
|
||||
Box::from(Ctr::Symbol("input".to_string())),
|
||||
Box::from(Ctr::None)))),
|
||||
Box::new(Ctr::None),
|
||||
)),
|
||||
}),
|
||||
};
|
||||
|
||||
table_handle.insert(String::from("echo"), test_external_func);
|
||||
}
|
||||
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, true, true) {
|
||||
Ok(initial_ast) => match eval(&initial_ast, &mut syms) {
|
||||
Err(e) => {
|
||||
println!("Evaluation error: {}\n", e);
|
||||
assert!(false)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue