add some boolean operations, tests for

Signed-off-by: Ava Hahn <ava@aidanis.online>
This commit is contained in:
Ava Hahn 2023-03-02 09:43:12 -08:00
parent c1d83a6285
commit 28e158f110
Signed by untrusted user who does not match committer: affine
GPG key ID: 3A4645B8CF806069
5 changed files with 292 additions and 4 deletions

144
tests/test_lib_bools.rs Normal file
View file

@ -0,0 +1,144 @@
mod bool_lib_tests {
use relish::ast::{eval, lex, Ctr, SymTable};
use relish::stdlib::{dynamic_stdlib, static_stdlib};
#[test]
fn test_and_true_chain() {
let document = "(and true true true true true)";
let result = true;
let mut syms = SymTable::new();
static_stdlib(&mut syms).unwrap();
dynamic_stdlib(&mut syms).unwrap();
if let Ok(tree) = lex(&document.to_string()) {
if let Ctr::Bool(b) = *eval(&tree, &mut syms).unwrap() {
assert_eq!(b, result);
} else {
assert!(false);
}
} else {
assert!(false);
}
}
#[test]
fn test_and_true_chain_with_false() {
let document = "(and true true false true true)";
let result = false;
let mut syms = SymTable::new();
static_stdlib(&mut syms).unwrap();
dynamic_stdlib(&mut syms).unwrap();
if let Ok(tree) = lex(&document.to_string()) {
if let Ctr::Bool(i) = *eval(&tree, &mut syms).unwrap() {
assert_eq!(i, result);
} else {
assert!(false);
}
} else {
assert!(false);
}
}
#[test]
fn test_and_false_chain() {
let document = "(and false false false false false)";
let result = false;
let mut syms = SymTable::new();
static_stdlib(&mut syms).unwrap();
dynamic_stdlib(&mut syms).unwrap();
if let Ok(tree) = lex(&document.to_string()) {
if let Ctr::Bool(i) = *eval(&tree, &mut syms).unwrap() {
assert_eq!(i, result);
} else {
assert!(false);
}
} else {
assert!(false);
}
}
#[test]
fn test_or_true_chain() {
let document = "(or true true true true true)";
let result = true;
let mut syms = SymTable::new();
static_stdlib(&mut syms).unwrap();
dynamic_stdlib(&mut syms).unwrap();
if let Ok(tree) = lex(&document.to_string()) {
if let Ctr::Bool(b) = *eval(&tree, &mut syms).unwrap() {
assert_eq!(b, result);
} else {
assert!(false);
}
} else {
assert!(false);
}
}
#[test]
fn test_or_true_chain_with_false() {
let document = "(or true true false true true)";
let result = true;
let mut syms = SymTable::new();
static_stdlib(&mut syms).unwrap();
dynamic_stdlib(&mut syms).unwrap();
if let Ok(tree) = lex(&document.to_string()) {
if let Ctr::Bool(i) = *eval(&tree, &mut syms).unwrap() {
assert_eq!(i, result);
} else {
assert!(false);
}
} else {
assert!(false);
}
}
#[test]
fn test_or_false_chain() {
let document = "(or false false false false)";
let result = false;
let mut syms = SymTable::new();
static_stdlib(&mut syms).unwrap();
dynamic_stdlib(&mut syms).unwrap();
if let Ok(tree) = lex(&document.to_string()) {
if let Ctr::Bool(i) = *eval(&tree, &mut syms).unwrap() {
assert_eq!(i, result);
} else {
assert!(false);
}
} else {
assert!(false);
}
}
#[test]
fn test_not() {
let document = "(not true)";
let result = false;
let mut syms = SymTable::new();
static_stdlib(&mut syms).unwrap();
dynamic_stdlib(&mut syms).unwrap();
if let Ok(tree) = lex(&document.to_string()) {
if let Ctr::Bool(i) = *eval(&tree, &mut syms).unwrap() {
assert_eq!(i, result);
} else {
assert!(false);
}
} else {
assert!(false);
}
}
}

View file

@ -108,6 +108,7 @@ mod control_lib_tests {
#[test]
fn test_let_multiphase_local_multibody_evals() {
// prints 'first body' and then returns ('1' '2' '3')
let document = "(let (
(temp '1')
(temp (append () temp '2')))