This commit is contained in:
Aidan Hahn 2022-01-16 22:02:40 -08:00
parent f805290a4b
commit be73b0b828
No known key found for this signature in database
GPG key ID: 327711E983899316
17 changed files with 588 additions and 675 deletions

View file

@ -1,9 +1,9 @@
mod eval_tests {
use std::rc::Rc;
use std::cell::RefCell;
use relish::ast::{Ctr, Function, Operation, ExternalOperation};
use relish::ast::{new_ast, lex, eval, VTable, FTable, ast_to_string};
use relish::ast::{ast_to_string, eval, lex, new_ast, FTable, VTable};
use relish::ast::{func_declare, Args};
use relish::ast::{Ctr, ExternalOperation, Function, Operation};
use std::cell::RefCell;
use std::rc::Rc;
// TODO: write generalized testing routine on top of list of inputs
@ -17,22 +17,20 @@ mod eval_tests {
Err(e) => {
println!("Lexing error: {}\n", e);
assert!(false)
},
}
Ok(initial_ast) => {
match eval(initial_ast.clone(), vt.clone(), ft.clone(), false) {
Err(e) => {
println!("Evaluation error: {}\n", e);
assert!(false)
},
Ok(initial_ast) => match eval(initial_ast.clone(), vt.clone(), ft.clone(), false) {
Err(e) => {
println!("Evaluation error: {}\n", e);
assert!(false)
}
Ok(reduced) => {
if let Ctr::Seg(reduced_ast) = reduced {
assert_eq!(ast_to_string(reduced_ast), test_doc)
}
Ok(reduced) => {
if let Ctr::Seg(reduced_ast) = reduced {
assert_eq!(ast_to_string(reduced_ast), test_doc)
}
}
}
},
}
}
@ -46,22 +44,20 @@ mod eval_tests {
Err(e) => {
println!("Lexing error: {}\n", e);
assert!(false)
},
}
Ok(initial_ast) => {
match eval(initial_ast.clone(), vt.clone(), ft.clone(), false) {
Err(e) => {
println!("Evaluation error: {}\n", e);
assert!(false)
},
Ok(initial_ast) => match eval(initial_ast.clone(), vt.clone(), ft.clone(), false) {
Err(e) => {
println!("Evaluation error: {}\n", e);
assert!(false)
}
Ok(reduced) => {
if let Ctr::Seg(reduced_ast) = reduced {
assert_eq!(ast_to_string(reduced_ast), test_doc)
}
Ok(reduced) => {
if let Ctr::Seg(reduced_ast) = reduced {
assert_eq!(ast_to_string(reduced_ast), test_doc)
}
}
}
},
}
}
@ -69,23 +65,23 @@ mod eval_tests {
fn eval_function_call() {
let test_doc = "('one' (echo 'unwrap_me'))".to_string();
let output = "('one' 'unwrap_me')";
let test_external_func: Function = Function{
let test_external_func: Function = Function {
name: String::from("echo"),
loose_syms: false,
eval_lazy: false,
args: Args::Lazy(1),
function: Operation::External(
ExternalOperation{
arg_syms: vec!["input".to_string()],
ast: new_ast(Ctr::Seg(new_ast(Ctr::Symbol("input".to_string()), Ctr::None)), Ctr::None)
}
)
function: Operation::External(ExternalOperation {
arg_syms: vec!["input".to_string()],
ast: new_ast(
Ctr::Seg(new_ast(Ctr::Symbol("input".to_string()), Ctr::None)),
Ctr::None,
),
}),
};
let ft = Rc::new(RefCell::new(FTable::new()));
let vt = Rc::new(RefCell::new(VTable::new()));
if let Some(s) = func_declare(ft.clone(),
Rc::new(RefCell::new(test_external_func))) {
if let Some(s) = func_declare(ft.clone(), Rc::new(RefCell::new(test_external_func))) {
print!("Error declaring external func: {}", s);
assert!(false);
}
@ -94,26 +90,24 @@ mod eval_tests {
Err(e) => {
println!("Lexing error: {}\n", e);
assert!(false)
},
}
Ok(initial_ast) => {
match eval(initial_ast.clone(), vt.clone(), ft.clone(), false) {
Err(e) => {
println!("Evaluation error: {}\n", e);
assert!(false)
},
Ok(initial_ast) => match eval(initial_ast.clone(), vt.clone(), ft.clone(), false) {
Err(e) => {
println!("Evaluation error: {}\n", e);
assert!(false)
}
Ok(reduced) => {
if let Ctr::Seg(reduced_ast) = reduced {
let out_doc = ast_to_string(reduced_ast);
if out_doc != output {
print!("Erroneous output: {}\n", out_doc);
assert!(false)
}
Ok(reduced) => {
if let Ctr::Seg(reduced_ast) = reduced {
let out_doc = ast_to_string(reduced_ast);
if out_doc != output {
print!("Erroneous output: {}\n", out_doc);
assert!(false)
}
}
}
}
},
}
}
@ -121,23 +115,23 @@ mod eval_tests {
fn eval_embedded_func_calls() {
let test_doc = "('one' (echo (echo 'unwrap_me')))".to_string();
let output = "('one' 'unwrap_me')";
let test_external_func: Function = Function{
let test_external_func: Function = Function {
name: String::from("echo"),
loose_syms: false,
eval_lazy: false,
args: Args::Lazy(1),
function: Operation::External(
ExternalOperation{
arg_syms: vec!["input".to_string()],
ast: new_ast(Ctr::Seg(new_ast(Ctr::Symbol("input".to_string()), Ctr::None)), Ctr::None)
}
)
function: Operation::External(ExternalOperation {
arg_syms: vec!["input".to_string()],
ast: new_ast(
Ctr::Seg(new_ast(Ctr::Symbol("input".to_string()), Ctr::None)),
Ctr::None,
),
}),
};
let ft = Rc::new(RefCell::new(FTable::new()));
let vt = Rc::new(RefCell::new(VTable::new()));
if let Some(s) = func_declare(ft.clone(),
Rc::new(RefCell::new(test_external_func))) {
if let Some(s) = func_declare(ft.clone(), Rc::new(RefCell::new(test_external_func))) {
print!("Error declaring external func: {}", s);
assert!(false);
}
@ -146,28 +140,25 @@ mod eval_tests {
Err(e) => {
println!("Lexing error: {}\n", e);
assert!(false)
},
}
Ok(initial_ast) => {
match eval(initial_ast.clone(), vt.clone(), ft.clone(), false) {
Err(e) => {
println!("Evaluation error: {}\n", e);
assert!(false)
},
Ok(initial_ast) => match eval(initial_ast.clone(), vt.clone(), ft.clone(), false) {
Err(e) => {
println!("Evaluation error: {}\n", e);
assert!(false)
}
Ok(reduced) => {
if let Ctr::Seg(reduced_ast) = reduced {
let out_doc = ast_to_string(reduced_ast);
if out_doc != output {
print!("Erroneous output: {}\n", out_doc);
assert!(false)
}
Ok(reduced) => {
if let Ctr::Seg(reduced_ast) = reduced {
let out_doc = ast_to_string(reduced_ast);
if out_doc != output {
print!("Erroneous output: {}\n", out_doc);
assert!(false)
}
}
}
}
},
}
}
/*