2023-03-06 19:05:34 -08:00
|
|
|
mod math_lib_tests {
|
2024-02-06 22:39:08 +00:00
|
|
|
use flesh::ast::{eval, lex, Ctr, SymTable};
|
2024-07-10 13:22:28 -07:00
|
|
|
use flesh::stdlib::static_stdlib;
|
2023-03-06 19:05:34 -08:00
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
|
fn test_add_chain() {
|
|
|
|
|
let document = "(add 1 2 3 4)";
|
|
|
|
|
let result = "10";
|
|
|
|
|
|
|
|
|
|
let mut syms = SymTable::new();
|
2023-05-26 06:41:18 +00:00
|
|
|
static_stdlib(&mut syms);
|
2023-03-06 19:05:34 -08:00
|
|
|
assert_eq!(
|
|
|
|
|
*eval(&lex(&document.to_string()).unwrap(), &mut syms)
|
|
|
|
|
.unwrap()
|
|
|
|
|
.to_string(),
|
|
|
|
|
result.to_string(),
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
|
fn test_add_chain_mixed() {
|
|
|
|
|
let document = "(add 1 2.2 3 4)";
|
|
|
|
|
let result = "10.2";
|
|
|
|
|
|
|
|
|
|
let mut syms = SymTable::new();
|
2023-05-26 06:41:18 +00:00
|
|
|
static_stdlib(&mut syms);
|
2023-03-06 19:05:34 -08:00
|
|
|
assert_eq!(
|
|
|
|
|
*eval(&lex(&document.to_string()).unwrap(), &mut syms)
|
|
|
|
|
.unwrap()
|
|
|
|
|
.to_string(),
|
|
|
|
|
result.to_string(),
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
|
fn test_mul_chain() {
|
|
|
|
|
let document = "(mul 1 2 3 4)";
|
|
|
|
|
let result = "24";
|
|
|
|
|
|
|
|
|
|
let mut syms = SymTable::new();
|
2023-05-26 06:41:18 +00:00
|
|
|
static_stdlib(&mut syms);
|
2023-03-06 19:05:34 -08:00
|
|
|
assert_eq!(
|
|
|
|
|
*eval(&lex(&document.to_string()).unwrap(), &mut syms)
|
|
|
|
|
.unwrap()
|
|
|
|
|
.to_string(),
|
|
|
|
|
result.to_string(),
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
|
fn test_sub_chain() {
|
|
|
|
|
let document = "(sub 1 2.2 3 4)";
|
|
|
|
|
let result = "-8.2";
|
|
|
|
|
|
|
|
|
|
let mut syms = SymTable::new();
|
2023-05-26 06:41:18 +00:00
|
|
|
static_stdlib(&mut syms);
|
2023-03-06 19:05:34 -08:00
|
|
|
assert_eq!(
|
|
|
|
|
*eval(&lex(&document.to_string()).unwrap(), &mut syms)
|
|
|
|
|
.unwrap()
|
|
|
|
|
.to_string(),
|
|
|
|
|
result.to_string(),
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
|
fn test_div() {
|
|
|
|
|
let document = "(div 10 5)";
|
|
|
|
|
let result = "2";
|
|
|
|
|
|
|
|
|
|
let mut syms = SymTable::new();
|
2023-05-26 06:41:18 +00:00
|
|
|
static_stdlib(&mut syms);
|
2023-03-06 19:05:34 -08:00
|
|
|
assert_eq!(
|
|
|
|
|
*eval(&lex(&document.to_string()).unwrap(), &mut syms)
|
|
|
|
|
.unwrap()
|
|
|
|
|
.to_string(),
|
|
|
|
|
result.to_string(),
|
|
|
|
|
);
|
|
|
|
|
}
|
2023-03-07 13:43:51 -08:00
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
|
fn test_float_to_int() {
|
|
|
|
|
let document = "(int 10.5)";
|
|
|
|
|
let result = "10";
|
|
|
|
|
|
|
|
|
|
let mut syms = SymTable::new();
|
2023-05-26 06:41:18 +00:00
|
|
|
static_stdlib(&mut syms);
|
2023-03-07 13:43:51 -08:00
|
|
|
assert_eq!(
|
|
|
|
|
*eval(&lex(&document.to_string()).unwrap(), &mut syms)
|
|
|
|
|
.unwrap()
|
|
|
|
|
.to_string(),
|
|
|
|
|
result.to_string(),
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
|
fn test_string_to_int() {
|
2024-07-10 13:22:28 -07:00
|
|
|
let document = "(int \"10\")";
|
2023-03-07 13:43:51 -08:00
|
|
|
let result = "10";
|
|
|
|
|
|
|
|
|
|
let mut syms = SymTable::new();
|
2023-05-26 06:41:18 +00:00
|
|
|
static_stdlib(&mut syms);
|
2023-03-07 13:43:51 -08:00
|
|
|
assert_eq!(
|
|
|
|
|
*eval(&lex(&document.to_string()).unwrap(), &mut syms)
|
|
|
|
|
.unwrap()
|
|
|
|
|
.to_string(),
|
|
|
|
|
result.to_string(),
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
|
fn test_int_to_float() {
|
|
|
|
|
let document = "(float 10)";
|
|
|
|
|
let result = "10";
|
|
|
|
|
|
|
|
|
|
let mut syms = SymTable::new();
|
2023-05-26 06:41:18 +00:00
|
|
|
static_stdlib(&mut syms);
|
2023-03-07 13:43:51 -08:00
|
|
|
assert_eq!(
|
|
|
|
|
*eval(&lex(&document.to_string()).unwrap(), &mut syms)
|
|
|
|
|
.unwrap()
|
|
|
|
|
.to_string(),
|
|
|
|
|
result.to_string(),
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
|
fn test_string_to_float() {
|
2024-07-10 13:22:28 -07:00
|
|
|
let document = "(float \"10.3\")";
|
2023-03-07 13:43:51 -08:00
|
|
|
let result = "10.3";
|
|
|
|
|
|
|
|
|
|
let mut syms = SymTable::new();
|
2023-05-26 06:41:18 +00:00
|
|
|
static_stdlib(&mut syms);
|
2023-03-07 13:43:51 -08:00
|
|
|
assert_eq!(
|
|
|
|
|
*eval(&lex(&document.to_string()).unwrap(), &mut syms)
|
|
|
|
|
.unwrap()
|
|
|
|
|
.to_string(),
|
|
|
|
|
result.to_string(),
|
|
|
|
|
);
|
|
|
|
|
}
|
2023-03-07 21:27:45 -08:00
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
|
fn test_ii_exp() {
|
|
|
|
|
let document = "(exp 7 20)";
|
|
|
|
|
let result = 7i128.pow(20);
|
|
|
|
|
|
|
|
|
|
let mut syms = SymTable::new();
|
2023-05-26 06:41:18 +00:00
|
|
|
static_stdlib(&mut syms);
|
2023-03-07 21:27:45 -08:00
|
|
|
assert_eq!(
|
|
|
|
|
*eval(&lex(&document.to_string()).unwrap(), &mut syms)
|
|
|
|
|
.unwrap()
|
|
|
|
|
.to_string(),
|
|
|
|
|
result.to_string(),
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
|
fn test_if_exp() {
|
|
|
|
|
let document = "(exp 1 10.2)";
|
|
|
|
|
let result = f64::powf(1f64, 10.2);
|
|
|
|
|
|
|
|
|
|
let mut syms = SymTable::new();
|
2023-05-26 06:41:18 +00:00
|
|
|
static_stdlib(&mut syms);
|
2023-03-07 21:27:45 -08:00
|
|
|
assert_eq!(
|
|
|
|
|
*eval(&lex(&document.to_string()).unwrap(), &mut syms)
|
|
|
|
|
.unwrap()
|
|
|
|
|
.to_string(),
|
|
|
|
|
result.to_string(),
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
|
fn test_fi_exp() {
|
|
|
|
|
let document = "(exp 1.2 5)";
|
|
|
|
|
let result = f64::powf(1.2, 5f64);
|
|
|
|
|
|
|
|
|
|
let mut syms = SymTable::new();
|
2023-05-26 06:41:18 +00:00
|
|
|
static_stdlib(&mut syms);
|
2023-03-07 21:27:45 -08:00
|
|
|
assert_eq!(
|
|
|
|
|
*eval(&lex(&document.to_string()).unwrap(), &mut syms)
|
|
|
|
|
.unwrap()
|
|
|
|
|
.to_string(),
|
|
|
|
|
format!("{:.5}", result),
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
|
fn test_ff_exp() {
|
|
|
|
|
let document = "(exp 1.3 1.5)";
|
|
|
|
|
let result = f64::powf(1.3, 1.5);
|
|
|
|
|
|
|
|
|
|
let mut syms = SymTable::new();
|
2023-05-26 06:41:18 +00:00
|
|
|
static_stdlib(&mut syms);
|
2023-03-07 21:27:45 -08:00
|
|
|
assert_eq!(
|
|
|
|
|
*eval(&lex(&document.to_string()).unwrap(), &mut syms)
|
|
|
|
|
.unwrap()
|
|
|
|
|
.to_string(),
|
|
|
|
|
result.to_string(),
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
|
fn test_ii_mod() {
|
2024-07-10 13:22:28 -07:00
|
|
|
let document = "(def test \"\" (mod 7 3))";
|
2023-03-07 21:27:45 -08:00
|
|
|
let check1 = "(car test)";
|
|
|
|
|
let result1 = "2";
|
|
|
|
|
let check2 = "(cdr test)";
|
|
|
|
|
let result2 = "1";
|
|
|
|
|
|
|
|
|
|
let mut syms = SymTable::new();
|
2023-05-26 06:41:18 +00:00
|
|
|
static_stdlib(&mut syms);
|
2023-03-07 21:27:45 -08:00
|
|
|
let _ = *eval(&lex(&document.to_string()).unwrap(), &mut syms).unwrap();
|
|
|
|
|
assert_eq!(
|
|
|
|
|
*eval(&lex(&check1.to_string()).unwrap(), &mut syms)
|
|
|
|
|
.unwrap()
|
|
|
|
|
.to_string(),
|
|
|
|
|
result1.to_string(),
|
|
|
|
|
);
|
|
|
|
|
assert_eq!(
|
|
|
|
|
*eval(&lex(&check2.to_string()).unwrap(), &mut syms)
|
|
|
|
|
.unwrap()
|
|
|
|
|
.to_string(),
|
|
|
|
|
result2.to_string(),
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
|
fn test_if_mod() {
|
2024-07-10 13:22:28 -07:00
|
|
|
let document = "(def test \"\" (mod 7 3.3))";
|
2023-03-07 21:27:45 -08:00
|
|
|
let check1 = "(car test)";
|
|
|
|
|
let result1 = "2";
|
|
|
|
|
|
|
|
|
|
let mut syms = SymTable::new();
|
2023-05-26 06:41:18 +00:00
|
|
|
static_stdlib(&mut syms);
|
2023-03-07 21:27:45 -08:00
|
|
|
let _ = *eval(&lex(&document.to_string()).unwrap(), &mut syms).unwrap();
|
|
|
|
|
assert_eq!(
|
|
|
|
|
*eval(&lex(&check1.to_string()).unwrap(), &mut syms)
|
|
|
|
|
.unwrap()
|
|
|
|
|
.to_string(),
|
|
|
|
|
result1.to_string(),
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
|
fn test_fi_mod() {
|
2024-07-10 13:22:28 -07:00
|
|
|
let document = "(def test \"\" (mod 7.2 2))";
|
2023-03-07 21:27:45 -08:00
|
|
|
let check1 = "(car test)";
|
2023-03-07 21:31:54 -08:00
|
|
|
let result1 = "3";
|
|
|
|
|
let mut syms = SymTable::new();
|
2023-05-26 06:41:18 +00:00
|
|
|
static_stdlib(&mut syms);
|
2023-03-07 21:27:45 -08:00
|
|
|
let _ = *eval(&lex(&document.to_string()).unwrap(), &mut syms).unwrap();
|
|
|
|
|
assert_eq!(
|
|
|
|
|
*eval(&lex(&check1.to_string()).unwrap(), &mut syms)
|
|
|
|
|
.unwrap()
|
|
|
|
|
.to_string(),
|
|
|
|
|
result1.to_string(),
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
|
fn test_ff_mod() {
|
2024-07-10 13:22:28 -07:00
|
|
|
let document = "(def test \"\" (mod 7.2 3.3))";
|
2023-03-07 21:27:45 -08:00
|
|
|
let check1 = "(car test)";
|
|
|
|
|
let result1 = "2";
|
|
|
|
|
|
|
|
|
|
let mut syms = SymTable::new();
|
2023-05-26 06:41:18 +00:00
|
|
|
static_stdlib(&mut syms);
|
2023-03-07 21:27:45 -08:00
|
|
|
let _ = *eval(&lex(&document.to_string()).unwrap(), &mut syms).unwrap();
|
|
|
|
|
assert_eq!(
|
|
|
|
|
*eval(&lex(&check1.to_string()).unwrap(), &mut syms)
|
|
|
|
|
.unwrap()
|
|
|
|
|
.to_string(),
|
|
|
|
|
result1.to_string(),
|
|
|
|
|
);
|
|
|
|
|
}
|
2023-03-07 22:01:01 -08:00
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
|
fn test_ii_gt_t() {
|
|
|
|
|
let document = "(gt? 4 3)";
|
|
|
|
|
let result = true;
|
|
|
|
|
|
|
|
|
|
let mut syms = SymTable::new();
|
2023-05-26 06:41:18 +00:00
|
|
|
static_stdlib(&mut syms);
|
2023-03-07 22:01:01 -08:00
|
|
|
assert_eq!(
|
|
|
|
|
*eval(&lex(&document.to_string()).unwrap(), &mut syms)
|
|
|
|
|
.unwrap()
|
|
|
|
|
.to_string(),
|
|
|
|
|
result.to_string(),
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
|
fn test_ii_gt_f() {
|
|
|
|
|
let document = "(gt? 2 3)";
|
|
|
|
|
let result = false;
|
|
|
|
|
|
|
|
|
|
let mut syms = SymTable::new();
|
2023-05-26 06:41:18 +00:00
|
|
|
static_stdlib(&mut syms);
|
2023-03-07 22:01:01 -08:00
|
|
|
assert_eq!(
|
|
|
|
|
*eval(&lex(&document.to_string()).unwrap(), &mut syms)
|
|
|
|
|
.unwrap()
|
|
|
|
|
.to_string(),
|
|
|
|
|
result.to_string(),
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
|
fn test_if_gt_t() {
|
|
|
|
|
let document = "(gt? 4 3.1)";
|
|
|
|
|
let result = true;
|
|
|
|
|
|
|
|
|
|
let mut syms = SymTable::new();
|
2023-05-26 06:41:18 +00:00
|
|
|
static_stdlib(&mut syms);
|
2023-03-07 22:01:01 -08:00
|
|
|
assert_eq!(
|
|
|
|
|
*eval(&lex(&document.to_string()).unwrap(), &mut syms)
|
|
|
|
|
.unwrap()
|
|
|
|
|
.to_string(),
|
|
|
|
|
result.to_string(),
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
|
fn test_if_gt_f() {
|
|
|
|
|
let document = "(gt? 3 3.1)";
|
|
|
|
|
let result = false;
|
|
|
|
|
|
|
|
|
|
let mut syms = SymTable::new();
|
2023-05-26 06:41:18 +00:00
|
|
|
static_stdlib(&mut syms);
|
2023-03-07 22:01:01 -08:00
|
|
|
assert_eq!(
|
|
|
|
|
*eval(&lex(&document.to_string()).unwrap(), &mut syms)
|
|
|
|
|
.unwrap()
|
|
|
|
|
.to_string(),
|
|
|
|
|
result.to_string(),
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
|
fn test_fi_gt_t() {
|
|
|
|
|
let document = "(gt? 4.1 4)";
|
|
|
|
|
let result = true;
|
|
|
|
|
|
|
|
|
|
let mut syms = SymTable::new();
|
2023-05-26 06:41:18 +00:00
|
|
|
static_stdlib(&mut syms);
|
2023-03-07 22:01:01 -08:00
|
|
|
assert_eq!(
|
|
|
|
|
*eval(&lex(&document.to_string()).unwrap(), &mut syms)
|
|
|
|
|
.unwrap()
|
|
|
|
|
.to_string(),
|
|
|
|
|
result.to_string(),
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
|
fn test_fi_gt_f() {
|
|
|
|
|
let document = "(gt? 2.1 3)";
|
|
|
|
|
let result = false;
|
|
|
|
|
|
|
|
|
|
let mut syms = SymTable::new();
|
2023-05-26 06:41:18 +00:00
|
|
|
static_stdlib(&mut syms);
|
2023-03-07 22:01:01 -08:00
|
|
|
assert_eq!(
|
|
|
|
|
*eval(&lex(&document.to_string()).unwrap(), &mut syms)
|
|
|
|
|
.unwrap()
|
|
|
|
|
.to_string(),
|
|
|
|
|
result.to_string(),
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
|
fn test_ff_gt_t() {
|
|
|
|
|
let document = "(gt? 3.2 3.1)";
|
|
|
|
|
let result = true;
|
|
|
|
|
|
|
|
|
|
let mut syms = SymTable::new();
|
2023-05-26 06:41:18 +00:00
|
|
|
static_stdlib(&mut syms);
|
2023-03-07 22:01:01 -08:00
|
|
|
assert_eq!(
|
|
|
|
|
*eval(&lex(&document.to_string()).unwrap(), &mut syms)
|
|
|
|
|
.unwrap()
|
|
|
|
|
.to_string(),
|
|
|
|
|
result.to_string(),
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
|
fn test_ff_gt_f() {
|
|
|
|
|
let document = "(gt? 3.1 3.2)";
|
|
|
|
|
let result = false;
|
|
|
|
|
|
|
|
|
|
let mut syms = SymTable::new();
|
2023-05-26 06:41:18 +00:00
|
|
|
static_stdlib(&mut syms);
|
2023-03-07 22:01:01 -08:00
|
|
|
assert_eq!(
|
|
|
|
|
*eval(&lex(&document.to_string()).unwrap(), &mut syms)
|
|
|
|
|
.unwrap()
|
|
|
|
|
.to_string(),
|
|
|
|
|
result.to_string(),
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
|
fn test_ii_lt_f() {
|
|
|
|
|
let document = "(lt? 4 3)";
|
|
|
|
|
let result = false;
|
|
|
|
|
|
|
|
|
|
let mut syms = SymTable::new();
|
2023-05-26 06:41:18 +00:00
|
|
|
static_stdlib(&mut syms);
|
2023-03-07 22:01:01 -08:00
|
|
|
assert_eq!(
|
|
|
|
|
*eval(&lex(&document.to_string()).unwrap(), &mut syms)
|
|
|
|
|
.unwrap()
|
|
|
|
|
.to_string(),
|
|
|
|
|
result.to_string(),
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
|
fn test_ii_lt_t() {
|
|
|
|
|
let document = "(lt? 2 3)";
|
|
|
|
|
let result = true;
|
|
|
|
|
|
|
|
|
|
let mut syms = SymTable::new();
|
2023-05-26 06:41:18 +00:00
|
|
|
static_stdlib(&mut syms);
|
2023-03-07 22:01:01 -08:00
|
|
|
assert_eq!(
|
|
|
|
|
*eval(&lex(&document.to_string()).unwrap(), &mut syms)
|
|
|
|
|
.unwrap()
|
|
|
|
|
.to_string(),
|
|
|
|
|
result.to_string(),
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
|
fn test_if_lt_f() {
|
|
|
|
|
let document = "(lt? 4 3.1)";
|
|
|
|
|
let result = false;
|
|
|
|
|
|
|
|
|
|
let mut syms = SymTable::new();
|
2023-05-26 06:41:18 +00:00
|
|
|
static_stdlib(&mut syms);
|
2023-03-07 22:01:01 -08:00
|
|
|
assert_eq!(
|
|
|
|
|
*eval(&lex(&document.to_string()).unwrap(), &mut syms)
|
|
|
|
|
.unwrap()
|
|
|
|
|
.to_string(),
|
|
|
|
|
result.to_string(),
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
|
fn test_if_lt_t() {
|
|
|
|
|
let document = "(lt? 3 3.1)";
|
|
|
|
|
let result = true;
|
|
|
|
|
|
|
|
|
|
let mut syms = SymTable::new();
|
2023-05-26 06:41:18 +00:00
|
|
|
static_stdlib(&mut syms);
|
2023-03-07 22:01:01 -08:00
|
|
|
assert_eq!(
|
|
|
|
|
*eval(&lex(&document.to_string()).unwrap(), &mut syms)
|
|
|
|
|
.unwrap()
|
|
|
|
|
.to_string(),
|
|
|
|
|
result.to_string(),
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
|
fn test_fi_lt_f() {
|
|
|
|
|
let document = "(lt? 4.1 4)";
|
|
|
|
|
let result = false;
|
|
|
|
|
|
|
|
|
|
let mut syms = SymTable::new();
|
2023-05-26 06:41:18 +00:00
|
|
|
static_stdlib(&mut syms);
|
2023-03-07 22:01:01 -08:00
|
|
|
assert_eq!(
|
|
|
|
|
*eval(&lex(&document.to_string()).unwrap(), &mut syms)
|
|
|
|
|
.unwrap()
|
|
|
|
|
.to_string(),
|
|
|
|
|
result.to_string(),
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
|
fn test_fi_lt_t() {
|
|
|
|
|
let document = "(lt? 2.1 3)";
|
|
|
|
|
let result = true;
|
|
|
|
|
|
|
|
|
|
let mut syms = SymTable::new();
|
2023-05-26 06:41:18 +00:00
|
|
|
static_stdlib(&mut syms);
|
2023-03-07 22:01:01 -08:00
|
|
|
assert_eq!(
|
|
|
|
|
*eval(&lex(&document.to_string()).unwrap(), &mut syms)
|
|
|
|
|
.unwrap()
|
|
|
|
|
.to_string(),
|
|
|
|
|
result.to_string(),
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
|
fn test_ff_lt_f() {
|
|
|
|
|
let document = "(lt? 3.2 3.1)";
|
|
|
|
|
let result = false;
|
|
|
|
|
|
|
|
|
|
let mut syms = SymTable::new();
|
2023-05-26 06:41:18 +00:00
|
|
|
static_stdlib(&mut syms);
|
2023-03-07 22:01:01 -08:00
|
|
|
assert_eq!(
|
|
|
|
|
*eval(&lex(&document.to_string()).unwrap(), &mut syms)
|
|
|
|
|
.unwrap()
|
|
|
|
|
.to_string(),
|
|
|
|
|
result.to_string(),
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
|
fn test_ff_lt_ft() {
|
|
|
|
|
let document = "(lt? 3.1 3.2)";
|
|
|
|
|
let result = true;
|
|
|
|
|
|
|
|
|
|
let mut syms = SymTable::new();
|
2023-05-26 06:41:18 +00:00
|
|
|
static_stdlib(&mut syms);
|
2023-03-07 22:01:01 -08:00
|
|
|
assert_eq!(
|
|
|
|
|
*eval(&lex(&document.to_string()).unwrap(), &mut syms)
|
|
|
|
|
.unwrap()
|
|
|
|
|
.to_string(),
|
|
|
|
|
result.to_string(),
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
|
fn test_lte() {
|
|
|
|
|
let document = "(lte? 3.2 3.1)";
|
|
|
|
|
let result = false;
|
|
|
|
|
|
|
|
|
|
let mut syms = SymTable::new();
|
2023-05-26 06:41:18 +00:00
|
|
|
static_stdlib(&mut syms);
|
2023-03-07 22:01:01 -08:00
|
|
|
assert_eq!(
|
|
|
|
|
*eval(&lex(&document.to_string()).unwrap(), &mut syms)
|
|
|
|
|
.unwrap()
|
|
|
|
|
.to_string(),
|
|
|
|
|
result.to_string(),
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
|
fn test_lte_e() {
|
|
|
|
|
let document = "(lte? 3.2 3.2)";
|
|
|
|
|
let result = true;
|
|
|
|
|
|
|
|
|
|
let mut syms = SymTable::new();
|
2023-05-26 06:41:18 +00:00
|
|
|
static_stdlib(&mut syms);
|
2023-03-07 22:01:01 -08:00
|
|
|
assert_eq!(
|
|
|
|
|
*eval(&lex(&document.to_string()).unwrap(), &mut syms)
|
|
|
|
|
.unwrap()
|
|
|
|
|
.to_string(),
|
|
|
|
|
result.to_string(),
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
|
fn test_gte() {
|
|
|
|
|
let document = "(gte? 3.1 3.2)";
|
|
|
|
|
let result = false;
|
|
|
|
|
|
|
|
|
|
let mut syms = SymTable::new();
|
2023-05-26 06:41:18 +00:00
|
|
|
static_stdlib(&mut syms);
|
2023-03-07 22:01:01 -08:00
|
|
|
assert_eq!(
|
|
|
|
|
*eval(&lex(&document.to_string()).unwrap(), &mut syms)
|
|
|
|
|
.unwrap()
|
|
|
|
|
.to_string(),
|
|
|
|
|
result.to_string(),
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
|
fn test_gte_e() {
|
|
|
|
|
let document = "(gte? 3.1 3.1)";
|
|
|
|
|
let result = true;
|
|
|
|
|
|
|
|
|
|
let mut syms = SymTable::new();
|
2023-05-26 06:41:18 +00:00
|
|
|
static_stdlib(&mut syms);
|
2023-03-07 22:01:01 -08:00
|
|
|
assert_eq!(
|
|
|
|
|
*eval(&lex(&document.to_string()).unwrap(), &mut syms)
|
|
|
|
|
.unwrap()
|
|
|
|
|
.to_string(),
|
|
|
|
|
result.to_string(),
|
|
|
|
|
);
|
|
|
|
|
}
|
2023-03-07 22:16:57 -08:00
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
|
fn test_inc() {
|
2024-07-10 13:22:28 -07:00
|
|
|
let document = "(def tester \"\" 1)";
|
2023-03-07 22:16:57 -08:00
|
|
|
let change = "(inc tester)";
|
|
|
|
|
let check = "(tester)";
|
|
|
|
|
|
|
|
|
|
let mut syms = SymTable::new();
|
2023-05-26 06:41:18 +00:00
|
|
|
static_stdlib(&mut syms);
|
2023-03-07 22:16:57 -08:00
|
|
|
|
|
|
|
|
let doc_tree = lex(&document.to_string()).unwrap();
|
|
|
|
|
let change_tree = lex(&change.to_string()).unwrap();
|
|
|
|
|
let check_tree = lex(&check.to_string()).unwrap();
|
|
|
|
|
|
|
|
|
|
eval(&doc_tree, &mut syms).unwrap();
|
|
|
|
|
eval(&change_tree, &mut syms).unwrap();
|
|
|
|
|
|
|
|
|
|
if let Ctr::Seg(ref s) = *eval(&check_tree, &mut syms).unwrap() {
|
|
|
|
|
if let Ctr::Integer(ref b) = *s.car {
|
|
|
|
|
assert_eq!(2, *b)
|
|
|
|
|
} else {
|
|
|
|
|
panic!()
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
panic!()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
eval(&change_tree, &mut syms).unwrap();
|
|
|
|
|
if let Ctr::Seg(ref s) = *eval(&check_tree, &mut syms).unwrap() {
|
|
|
|
|
if let Ctr::Integer(ref b) = *s.car {
|
|
|
|
|
assert_eq!(3, *b)
|
|
|
|
|
} else {
|
|
|
|
|
panic!()
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
panic!()
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
|
fn test_inc_errors_dont_lose_vars() {
|
2024-07-10 13:22:28 -07:00
|
|
|
let document = "(def tester \"\" \"oops\")";
|
2023-03-07 22:16:57 -08:00
|
|
|
let change = "(inc tester)";
|
|
|
|
|
let check = "(tester)";
|
|
|
|
|
|
|
|
|
|
let mut syms = SymTable::new();
|
2023-05-26 06:41:18 +00:00
|
|
|
static_stdlib(&mut syms);
|
2023-03-07 22:16:57 -08:00
|
|
|
|
|
|
|
|
let doc_tree = lex(&document.to_string()).unwrap();
|
|
|
|
|
let change_tree = lex(&change.to_string()).unwrap();
|
|
|
|
|
let check_tree = lex(&check.to_string()).unwrap();
|
|
|
|
|
|
|
|
|
|
eval(&doc_tree, &mut syms).unwrap();
|
|
|
|
|
if let Err(s) = eval(&change_tree, &mut syms) {
|
|
|
|
|
assert_eq!(
|
2023-05-23 22:06:11 +00:00
|
|
|
s.0.first().unwrap().message,
|
|
|
|
|
"expected tester to be an integer".to_string()
|
2023-03-07 22:16:57 -08:00
|
|
|
);
|
|
|
|
|
let intermediate = *eval(&check_tree, &mut syms).unwrap();
|
|
|
|
|
if let Ctr::Seg(ref s) = intermediate {
|
2024-07-10 13:22:28 -07:00
|
|
|
assert_eq!(s.to_string(), "(\"oops\")".to_string());
|
2023-03-07 22:16:57 -08:00
|
|
|
} else {
|
|
|
|
|
eprintln!("did not expect: {}", intermediate);
|
|
|
|
|
panic!()
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
eprintln!("shouldn't have succeeded!");
|
|
|
|
|
panic!()
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
|
fn test_inc_errors_dont_lose_funcs() {
|
2024-07-10 13:22:28 -07:00
|
|
|
let document = "(def tester \"\" (oops) oops)";
|
2023-03-07 22:16:57 -08:00
|
|
|
let change = "(inc tester)";
|
2024-07-10 13:22:28 -07:00
|
|
|
let check = "(tester \"1\")";
|
2023-03-07 22:16:57 -08:00
|
|
|
|
|
|
|
|
let mut syms = SymTable::new();
|
2023-05-26 06:41:18 +00:00
|
|
|
static_stdlib(&mut syms);
|
2023-03-07 22:16:57 -08:00
|
|
|
|
|
|
|
|
let doc_tree = lex(&document.to_string()).unwrap();
|
|
|
|
|
let change_tree = lex(&change.to_string()).unwrap();
|
|
|
|
|
let check_tree = lex(&check.to_string()).unwrap();
|
|
|
|
|
|
|
|
|
|
eval(&doc_tree, &mut syms).unwrap();
|
|
|
|
|
if let Err(s) = eval(&change_tree, &mut syms) {
|
|
|
|
|
assert_eq!(
|
2023-05-23 22:06:11 +00:00
|
|
|
s.0.first().unwrap().message,
|
|
|
|
|
"expected tester to be an integer".to_string()
|
2023-03-07 22:16:57 -08:00
|
|
|
);
|
|
|
|
|
if let Ctr::String(ref s) = *eval(&check_tree, &mut syms).unwrap() {
|
|
|
|
|
assert_eq!(*s, "1".to_string());
|
|
|
|
|
} else {
|
|
|
|
|
panic!()
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
eprintln!("shouldn't have succeeded!");
|
|
|
|
|
panic!()
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
|
fn test_dec() {
|
2024-07-10 13:22:28 -07:00
|
|
|
let document = "(def tester \"\" 1)";
|
2023-03-07 22:16:57 -08:00
|
|
|
let change = "(dec tester)";
|
|
|
|
|
let check = "(tester)";
|
|
|
|
|
|
|
|
|
|
let mut syms = SymTable::new();
|
2023-05-26 06:41:18 +00:00
|
|
|
static_stdlib(&mut syms);
|
2023-03-07 22:16:57 -08:00
|
|
|
|
|
|
|
|
let doc_tree = lex(&document.to_string()).unwrap();
|
|
|
|
|
let change_tree = lex(&change.to_string()).unwrap();
|
|
|
|
|
let check_tree = lex(&check.to_string()).unwrap();
|
|
|
|
|
|
|
|
|
|
eval(&doc_tree, &mut syms).unwrap();
|
|
|
|
|
eval(&change_tree, &mut syms).unwrap();
|
|
|
|
|
|
|
|
|
|
if let Ctr::Seg(ref s) = *eval(&check_tree, &mut syms).unwrap() {
|
|
|
|
|
if let Ctr::Integer(ref b) = *s.car {
|
|
|
|
|
assert_eq!(0, *b)
|
|
|
|
|
} else {
|
|
|
|
|
panic!()
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
panic!()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
eval(&change_tree, &mut syms).unwrap();
|
|
|
|
|
if let Ctr::Seg(ref s) = *eval(&check_tree, &mut syms).unwrap() {
|
|
|
|
|
if let Ctr::Integer(ref b) = *s.car {
|
|
|
|
|
assert_eq!(-1, *b)
|
|
|
|
|
} else {
|
|
|
|
|
panic!()
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
panic!()
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
|
fn test_dec_errors_dont_lose_vars() {
|
2024-07-10 13:22:28 -07:00
|
|
|
let document = "(def tester \"\" \"oops\")";
|
2023-03-07 22:16:57 -08:00
|
|
|
let change = "(dec tester)";
|
|
|
|
|
let check = "(tester)";
|
|
|
|
|
|
|
|
|
|
let mut syms = SymTable::new();
|
2023-05-26 06:41:18 +00:00
|
|
|
static_stdlib(&mut syms);
|
2023-03-07 22:16:57 -08:00
|
|
|
|
|
|
|
|
let doc_tree = lex(&document.to_string()).unwrap();
|
|
|
|
|
let change_tree = lex(&change.to_string()).unwrap();
|
|
|
|
|
let check_tree = lex(&check.to_string()).unwrap();
|
|
|
|
|
|
|
|
|
|
eval(&doc_tree, &mut syms).unwrap();
|
|
|
|
|
if let Err(s) = eval(&change_tree, &mut syms) {
|
|
|
|
|
assert_eq!(
|
2023-05-23 22:06:11 +00:00
|
|
|
s.0.first().unwrap().message,
|
|
|
|
|
"expected tester to be an integer".to_string()
|
2023-03-07 22:16:57 -08:00
|
|
|
);
|
|
|
|
|
let intermediate = *eval(&check_tree, &mut syms).unwrap();
|
|
|
|
|
if let Ctr::Seg(ref s) = intermediate {
|
2024-07-10 13:22:28 -07:00
|
|
|
assert_eq!(s.to_string(), "(\"oops\")".to_string());
|
2023-03-07 22:16:57 -08:00
|
|
|
} else {
|
|
|
|
|
eprintln!("did not expect: {}", intermediate);
|
|
|
|
|
panic!()
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
eprintln!("shouldn't have succeeded!");
|
|
|
|
|
panic!()
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
|
fn test_dec_errors_dont_lose_funcs() {
|
2024-07-10 13:22:28 -07:00
|
|
|
let document = "(def tester \"\" (oops) oops)";
|
2023-03-07 22:16:57 -08:00
|
|
|
let change = "(dec tester)";
|
2024-07-10 13:22:28 -07:00
|
|
|
let check = "(tester \"1\")";
|
2023-03-07 22:16:57 -08:00
|
|
|
|
|
|
|
|
let mut syms = SymTable::new();
|
2023-05-26 06:41:18 +00:00
|
|
|
static_stdlib(&mut syms);
|
2023-03-07 22:16:57 -08:00
|
|
|
|
|
|
|
|
let doc_tree = lex(&document.to_string()).unwrap();
|
|
|
|
|
let change_tree = lex(&change.to_string()).unwrap();
|
|
|
|
|
let check_tree = lex(&check.to_string()).unwrap();
|
|
|
|
|
|
|
|
|
|
eval(&doc_tree, &mut syms).unwrap();
|
|
|
|
|
if let Err(s) = eval(&change_tree, &mut syms) {
|
|
|
|
|
assert_eq!(
|
2023-05-23 22:06:11 +00:00
|
|
|
s.0.first().unwrap().message,
|
|
|
|
|
"expected tester to be an integer".to_string()
|
2023-03-07 22:16:57 -08:00
|
|
|
);
|
|
|
|
|
if let Ctr::String(ref s) = *eval(&check_tree, &mut syms).unwrap() {
|
|
|
|
|
assert_eq!(*s, "1".to_string());
|
|
|
|
|
} else {
|
|
|
|
|
panic!()
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
eprintln!("shouldn't have succeeded!");
|
|
|
|
|
panic!()
|
|
|
|
|
}
|
|
|
|
|
}
|
2023-03-06 19:05:34 -08:00
|
|
|
}
|