2013-09-21 04:46:32 +00:00
|
|
|
/*
|
|
|
|
Copyright (c) 2013 Microsoft Corporation. All rights reserved.
|
|
|
|
Released under Apache 2.0 license as described in the file LICENSE.
|
|
|
|
|
|
|
|
Author: Leonardo de Moura
|
|
|
|
*/
|
|
|
|
#include <iostream>
|
|
|
|
#include <sstream>
|
|
|
|
#include "util/test.h"
|
|
|
|
#include "kernel/environment.h"
|
|
|
|
#include "kernel/abstract.h"
|
2013-10-01 01:16:13 +00:00
|
|
|
#include "kernel/formatter.h"
|
2013-09-21 04:46:32 +00:00
|
|
|
using namespace lean;
|
|
|
|
|
|
|
|
static void check(format const & f, char const * expected) {
|
|
|
|
std::ostringstream strm;
|
|
|
|
strm << f;
|
|
|
|
std::cout << strm.str() << "\n";
|
2013-10-29 23:20:02 +00:00
|
|
|
lean_assert_eq(strm.str(), expected);
|
2013-09-21 04:46:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void tst1() {
|
|
|
|
environment env;
|
|
|
|
env.add_var("N", Type());
|
|
|
|
formatter fmt = mk_simple_formatter();
|
|
|
|
check(fmt(env), "Variable N : Type\n");
|
|
|
|
expr f = Const("f");
|
|
|
|
expr a = Const("a");
|
|
|
|
expr x = Const("x");
|
|
|
|
expr y = Const("y");
|
|
|
|
expr N = Const("N");
|
|
|
|
expr F = Fun({x, Pi({x, N}, x >> x)}, Let({y, f(a)}, f(Eq(x, f(y, a)))));
|
2013-10-29 23:20:02 +00:00
|
|
|
check(fmt(F), "fun x : (Pi x : N, (x -> x)), (let y := f a in (f (x == (f y a))))");
|
2013-09-21 04:46:32 +00:00
|
|
|
check(fmt(env.get_object("N")), "Variable N : Type");
|
|
|
|
context ctx;
|
|
|
|
ctx = extend(ctx, "x", f(a));
|
|
|
|
ctx = extend(ctx, "y", f(Var(0), N >> N));
|
|
|
|
ctx = extend(ctx, "z", N, Eq(Var(0), Var(1)));
|
2013-10-29 23:20:02 +00:00
|
|
|
check(fmt(ctx), "[x : f a; y : f x (N -> N); z : N := y == x]");
|
2013-09-21 04:46:32 +00:00
|
|
|
check(fmt(ctx, f(Var(0), Var(2))), "f z x");
|
2013-10-29 23:20:02 +00:00
|
|
|
check(fmt(ctx, f(Var(0), Var(2)), true), "[x : f a; y : f x (N -> N); z : N := y == x] |- f z x");
|
2013-09-21 04:46:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int main() {
|
|
|
|
tst1();
|
|
|
|
return has_violations() ? 1 : 0;
|
|
|
|
}
|