From 52d682b832afe4c9cf769c060a720bc9b6a89d36 Mon Sep 17 00:00:00 2001 From: Leonardo de Moura Date: Wed, 14 May 2014 14:29:44 -0700 Subject: [PATCH] test(lua): unit tests for let expressions Signed-off-by: Leonardo de Moura --- tests/lua/let1.lua | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 tests/lua/let1.lua diff --git a/tests/lua/let1.lua b/tests/lua/let1.lua new file mode 100644 index 000000000..bbefd06cc --- /dev/null +++ b/tests/lua/let1.lua @@ -0,0 +1,25 @@ +assert(not mk_let("a", Type, Var(0), Var(0)):closed()) +local env = empty_environment() +local A = Const("A") +env = add_decl(env, mk_var_decl("A", Type)) +env = add_decl(env, mk_var_decl("g", mk_arrow(A, mk_arrow(A, A)))) +env = add_decl(env, mk_var_decl("f", mk_arrow(A, Bool))) +env = add_decl(env, mk_var_decl("a", A)) +local a = Const("a") +local b = Const("b") +local x = Const("x") +local y = Const("y") +local g = Const("g") +local f = Const("f") +local tc = type_checker(env) +print(Let(x, A, a, f(x))) +print(Let(x, A, a, y, A, f(f(x)), f(x))) +assert(Let(x, A, a, y, A, f(f(x)), f(x)) == Let({{x, A, a}, {y, A, f(f(x))}}, f(x))) +print(Let({{x, A, a}, {y, A, g(g(x), x, a)}}, f(y))) +local t = Let({{x, A, a}, {y, A, g(g(x), x, a)}}, f(y)) +assert(t:let_name() == name("x")) +assert(t:let_type() == A) +assert(t:let_value() == a) +assert(t:let_body():is_let()) +print(tc:check(Let({{x, A, a}, {y, A, g(g(x, a), x)}}, f(y)))) +