use lazy_static::lazy_static;
use crate::eval::EvalContext;
mod bool;
mod num;
mod quote;
mod string;
lazy_static! {
pub static ref STDLIB: EvalContext<'static> = EvalContext::new()
.with_fn("concat", string::concat)
.with_fn("add", num::add)
.with_fn("sub", num::sub)
.with_fn("mul", num::mul)
.with_fn("div", num::div)
.with_fn("pow", num::pow)
.with_fn("if", bool::if_)
.with_fn("not", bool::not)
.with_fn("eq", bool::eq)
.with_fn("gt", bool::gt)
.with_fn("lt", bool::lt)
.with_fn("call", quote::call)
.with_fn("let", quote::let_);
}
#[cfg(test)]
mod tests {
use crate::{eval::EvalResult, eval_str, stdlib::STDLIB};
#[test]
fn test_add() {
assert_eq!(
eval_str("add(1.1, 2.2, 3.3)", STDLIB.clone()).unwrap(),
EvalResult::Number(6.6)
);
}
#[test]
fn test_readme() {
assert_eq!(
eval_str(
r#"
[
let(
{
"myFn": 'add($0, $1)
},
'call(myFn, [2, 2])
), // 4
if(eq(1, 1), 'add(6, 4), 'add(2, 2)) // 10
]
"#,
STDLIB.clone()
)
.unwrap(),
EvalResult::Array(vec![EvalResult::Number(4_f64), EvalResult::Number(10_f64)])
)
}
}