aboutsummaryrefslogtreecommitdiff
path: root/tests/test_execution.rs
blob: 5aeac1935097d959e85e5452f53913dae8b0cffb (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
use chrysanthemum::ast::*;
use chrysanthemum::simple::*;
use chrysanthemum::util::*;

#[test]
fn test_simple() {
    assert_eq!(execute(Context::new(), Const(0)), Ok(Term(0, Empty)));
    assert_eq!(execute(Context::new(), Const(123)), Ok(Term(123, Empty)));
    assert_eq!(execute(Context::new(), Const(123)), Ok(Term(123, Empty)));
    assert!(execute(Context::new(), Var("x")).is_err());
}

#[test]
fn test_complex() {
    let mut context = Context::new();
    context.insert(String::from("x"), Term(413, Empty));
    context.insert(String::from("y"), Term(1, Empty));
    assert_eq!(execute(context.clone(), Var("x")), Ok(Term(413, Empty)));
    assert_eq!(execute(context.clone(), Cond(Var("y"), Const(612), Var("x"))), Ok(Term(612, Empty)));
    assert_eq!(execute(context.clone(), App(Abs("z", Cond(Const(0), Var("x"), Var("z"))), Const(1025))), Ok(Term(1025, Empty)));
}