Skip to content

Commit

Permalink
TMP - modified
Browse files Browse the repository at this point in the history
  • Loading branch information
Cypher1 committed Mar 11, 2024
1 parent 0c87f3e commit 7d095b9
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 12 deletions.
13 changes: 12 additions & 1 deletion llamada/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,18 @@ pub trait Expr: Sized {
debug!("as_church - start: {:?}", id);
let inner = match self.get(id) {
Term::Abs(_arg_meta, inner) => inner,
_ => return None,
Term::App(..) => {
debug!("as_church - not abs1: App");
return None
},
Term::Var(..) => {
debug!("as_church - not abs1: Var");
return None
}
Term::Ext(..) => {
debug!("as_church - not abs1: Ext");
return None
}
};
debug!("as_church - unwrap abs1: {:?}", inner);
let mut inner = match self.get(inner) {
Expand Down
34 changes: 23 additions & 11 deletions llamada/src/tests.rs
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
use env_logger;

pub fn setup() {
let env = env_logger::Env::default()
.filter_or("RUST_LOG", "debug")
.write_style_or("RUST_LOG_STYLE", "AUTO");
let mut builder = env_logger::Builder::from_env(env);
let logger = builder.format_timestamp(None);
let _ = logger.is_test(true).try_init();
}

macro_rules! tests {
($ty: ty) => {
fn logger_setup() {
use env_logger;
let env = env_logger::Env::default()
.filter_or("RUST_LOG", "debug")
.write_style_or("RUST_LOG_STYLE", "AUTO");
let mut builder = env_logger::Builder::from_env(env);
let logger = builder.format_timestamp(None);
let _ = logger.is_test(true).try_init();
}

#[test]
fn id_expr() {
logger_setup();
let mut expr = <$ty>::new(Term::Var(1), Empty);
let prev = expr.get_last_id();
let abs = expr.add(Term::abs(prev));
Expand All @@ -37,6 +37,7 @@ macro_rules! tests {

#[test]
fn true_expr() {
logger_setup();
let mut expr = <$ty>::new(Term::Var(2), Empty);
let prev = expr.get_last_id();
let abs1 = expr.add(Term::abs(prev));
Expand All @@ -49,6 +50,7 @@ macro_rules! tests {

#[test]
fn false_expr() {
logger_setup();
let mut expr = <$ty>::new(Term::Var(1), Empty);
let prev = expr.get_last_id();
let abs1 = expr.add(Term::abs(prev));
Expand All @@ -61,6 +63,7 @@ macro_rules! tests {

#[test]
fn id_a_expr() {
logger_setup();
let mut expr = <$ty>::new(Term::Var(1), Empty);
let prev = expr.get_last_id();
let abs1 = expr.add(Term::abs(prev));
Expand All @@ -75,6 +78,7 @@ macro_rules! tests {

#[test]
fn not_expr() {
logger_setup();
let mut expr = <$ty>::new(Term::Var(1), Empty);
let true_case = expr.get_last_id();
let false_case = expr.add(Term::Var(2));
Expand All @@ -92,6 +96,7 @@ macro_rules! tests {

#[test]
fn not_true_false_expr() {
logger_setup();
let mut expr = <$ty>::new(Term::Var(1), Empty);
let inner = {
let true_case = expr.get_last_id();
Expand Down Expand Up @@ -125,6 +130,7 @@ macro_rules! tests {

#[test]
fn zero_expr() {
logger_setup();
let mut church_test = <$ty>::new(Term::Var(1), Empty);
let church = church_test.to_church(0);
*church_test.root_mut() = (church);
Expand All @@ -143,6 +149,7 @@ macro_rules! tests {

#[test]
fn one_expr() {
logger_setup();
let mut church_test = <$ty>::new(Term::Var(1), Empty);
let church = church_test.to_church(1);
*church_test.root_mut() = (church);
Expand All @@ -163,6 +170,7 @@ macro_rules! tests {

#[test]
fn two_expr() {
logger_setup();
let mut church_test = <$ty>::new(Term::Var(1), Empty);
let church = church_test.to_church(2);
*church_test.root_mut() = (church);
Expand All @@ -184,6 +192,7 @@ macro_rules! tests {

#[test]
fn simple_expr_using_macros() {
logger_setup();
let (mut expr, constf) = $crate::new_expr!(
$ty,
constf,
Expand Down Expand Up @@ -214,6 +223,7 @@ macro_rules! tests {

#[test]
fn plus_expr_using_macros() {
logger_setup();
let (mut expr, plus) = $crate::new_expr!(
$ty,
plus,
Expand Down Expand Up @@ -265,6 +275,7 @@ macro_rules! tests {

#[test]
fn plus_expr() {
logger_setup();
let mut expr = <$ty>::new(Term::Var(1), Empty);
let x = expr.get_last_id();

Expand Down Expand Up @@ -322,6 +333,7 @@ macro_rules! tests {

#[test]
fn mul_expr() {
logger_setup();
let mut expr = <$ty>::new(Term::Var(1), Empty);
let x = expr.get_last_id();

Expand Down

0 comments on commit 7d095b9

Please sign in to comment.