Big project dir refactor
* split into multi member workspace in preparation for a no_std core * env and posix stuff neatly crammed into a seperate shell project * some pokes at interactive-devel.f * updated ci * removed 'l' shortcut for 'load' and update docs * remove out of date readme content * updated tests * more sensible cond implementation and extra tests * substr stdlib function with tests Signed-off-by: Ava Affine <ava@sunnypup.io>
This commit is contained in:
parent
aa56570d7d
commit
6d2925984f
44 changed files with 967 additions and 779 deletions
|
|
@ -1,113 +0,0 @@
|
|||
mod eval_tests {
|
||||
use flesh::ast::{eval, lex, SymTable};
|
||||
use flesh::ast::{Args, Ctr, Seg, Symbol, UserFn, ValueType};
|
||||
use flesh::stdlib::{dynamic_stdlib, static_stdlib};
|
||||
|
||||
#[test]
|
||||
fn eval_simple() {
|
||||
let test_doc = "(1 2)".to_string();
|
||||
let mut syms = SymTable::new();
|
||||
let doc_tree = lex(&test_doc).unwrap();
|
||||
let reduced = *eval(&doc_tree, &mut syms).unwrap();
|
||||
assert_eq!(reduced.to_string(), test_doc);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn eval_embedded_lists_no_funcs() {
|
||||
let test_doc = "(1 (1 2 3 4 5) 5)".to_string();
|
||||
let mut syms = SymTable::new();
|
||||
let doc_tree = lex(&test_doc).unwrap();
|
||||
let reduced = *eval(&doc_tree, &mut syms).unwrap();
|
||||
assert_eq!(reduced.to_string(), test_doc);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn eval_function_call() {
|
||||
let test_doc = "('one' (echo 'unwrap_me'))".to_string();
|
||||
let output = "('one' 'unwrap_me')";
|
||||
let mut syms = SymTable::new();
|
||||
|
||||
let test_external_func: Symbol = Symbol {
|
||||
name: String::from("echo"),
|
||||
args: Args::Lazy(1),
|
||||
conditional_branches: false,
|
||||
docs: String::new(),
|
||||
value: ValueType::FuncForm(UserFn {
|
||||
arg_syms: vec!["input".to_string()],
|
||||
ast: Box::new(Seg::from(
|
||||
Box::from(Ctr::Symbol("input".to_string())),
|
||||
Box::from(Ctr::None),
|
||||
)),
|
||||
}),
|
||||
..Default::default()
|
||||
};
|
||||
|
||||
syms.insert(String::from("echo"), test_external_func);
|
||||
let doc_tree = lex(&test_doc).unwrap();
|
||||
let reduced = *eval(&doc_tree, &mut syms).unwrap();
|
||||
assert_eq!(reduced.to_string(), output);
|
||||
}
|
||||
|
||||
#[test]
|
||||
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 test_external_func: Symbol = Symbol {
|
||||
name: String::from("echo"),
|
||||
args: Args::Lazy(1),
|
||||
conditional_branches: false,
|
||||
docs: String::new(),
|
||||
value: ValueType::FuncForm(UserFn {
|
||||
arg_syms: vec!["input".to_string()],
|
||||
ast: Box::new(Seg::from(
|
||||
Box::from(Ctr::Symbol("input".to_string())),
|
||||
Box::from(Ctr::None),
|
||||
)),
|
||||
}),
|
||||
..Default::default()
|
||||
};
|
||||
|
||||
syms.insert(String::from("echo"), test_external_func);
|
||||
let doc_tree = lex(&test_doc).unwrap();
|
||||
let reduced = *eval(&doc_tree, &mut syms).unwrap();
|
||||
assert_eq!(reduced.to_string(), output);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn eval_bad_syms() {
|
||||
let test_doc = "(undefined)".to_string();
|
||||
let mut syms = SymTable::new();
|
||||
let doc_tree = lex(&test_doc).unwrap();
|
||||
match eval(&doc_tree, &mut syms) {
|
||||
Err(e) => {
|
||||
assert_eq!(e.0.first().unwrap().message,
|
||||
"(is an undefined symbol)")
|
||||
}
|
||||
|
||||
Ok(reduced) => {
|
||||
println!("Eval succeeded when it shouldnt have");
|
||||
println!("see: {}", reduced);
|
||||
assert!(false)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn func_lambda_equivalency() {
|
||||
let comparator = "(def apply 'applicator' (fn x) (fn x))";
|
||||
let lh_doc = "(apply car (1 2 3))";
|
||||
let rh_doc = "(apply (lambda (x) (car x)) (1 2 3))";
|
||||
|
||||
let mut syms = SymTable::new();
|
||||
static_stdlib(&mut syms);
|
||||
dynamic_stdlib(&mut syms, None);
|
||||
|
||||
eval(&lex(&comparator.to_string()).unwrap(), &mut syms).unwrap();
|
||||
assert_eq!(
|
||||
eval(&lex(&lh_doc.to_string()).unwrap(), &mut syms).unwrap(),
|
||||
eval(&lex(&rh_doc.to_string()).unwrap(), &mut syms).unwrap(),
|
||||
);
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue