d843d432d3
The printer and formatter objects are not trusted code. We moved them to the kernel to be able to provide them as an argument to the trace objects. Another motivation is to eliminate the kernel_exception_formatter hack. With the formatter in the kernel, we can implement the pretty printer for kernel exceptions as a virtual method. Signed-off-by: Leonardo de Moura <leonardo@microsoft.com>
61 lines
1.7 KiB
C++
61 lines
1.7 KiB
C++
/*
|
|
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 "util/test.h"
|
|
#include "kernel/occurs.h"
|
|
#include "kernel/abstract.h"
|
|
#include "kernel/printer.h"
|
|
using namespace lean;
|
|
|
|
static void tst1() {
|
|
expr f = Const("f");
|
|
expr a = Const("a");
|
|
expr b = Const("b");
|
|
expr T = Type();
|
|
lean_assert(occurs(f, f));
|
|
lean_assert(!occurs(a, f));
|
|
lean_assert(occurs(a, f(a)));
|
|
lean_assert(occurs("a", f(a)));
|
|
lean_assert(!occurs("b", f));
|
|
lean_assert(!occurs(a, Fun({a, T}, f(a))));
|
|
context c;
|
|
c = extend(c, name("x"), T);
|
|
lean_assert(!occurs(f, c));
|
|
lean_assert(occurs(f, c, {a, f(a)}));
|
|
lean_assert(occurs(f(a), c, {a, f(a)}));
|
|
lean_assert(!occurs(f(b), c, {a, f(a)}));
|
|
lean_assert(occurs("f", c, {a, f(a)}));
|
|
lean_assert(!occurs(b, c, {a, f(a)}));
|
|
c = extend(c, name("y"), T, f(a));
|
|
lean_assert(!occurs("x", c));
|
|
lean_assert(occurs(f, c));
|
|
lean_assert(occurs("f", c));
|
|
c = extend(c, name("z"), T, f(Const("x")));
|
|
lean_assert(occurs("x", c));
|
|
lean_assert(occurs("a", c));
|
|
lean_assert(occurs(f(Const("x")), c));
|
|
lean_assert(!occurs(f(b), c));
|
|
}
|
|
|
|
static void tst2() {
|
|
expr f = Const("f");
|
|
expr a = Const("a");
|
|
expr b = Const("b");
|
|
context c;
|
|
c = extend(c, "a", Type());
|
|
std::cout << c;
|
|
lean_assert(c.size() == 1);
|
|
lean_assert(lookup(c, 0).get_name() == "a");
|
|
auto p = lookup_ext(c, 0);
|
|
lean_assert(p.first.get_name() == "a");
|
|
lean_assert(p.second.size() == 0);
|
|
}
|
|
|
|
int main() {
|
|
tst1();
|
|
tst2();
|
|
return has_violations() ? 1 : 0;
|
|
}
|