add some boolean operations, tests for
Signed-off-by: Ava Hahn <ava@aidanis.online>
This commit is contained in:
parent
c1d83a6285
commit
28e158f110
5 changed files with 292 additions and 4 deletions
144
tests/test_lib_bools.rs
Normal file
144
tests/test_lib_bools.rs
Normal 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue