2013-08-14 19:00:11 +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
|
|
|
|
*/
|
2013-09-13 03:04:10 +00:00
|
|
|
#include "util/test.h"
|
|
|
|
#include "kernel/occurs.h"
|
|
|
|
#include "kernel/abstract.h"
|
2013-10-01 01:16:13 +00:00
|
|
|
#include "kernel/printer.h"
|
2013-08-14 19:00:11 +00:00
|
|
|
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));
|
|
|
|
}
|
|
|
|
|
2013-08-14 21:00:30 +00:00
|
|
|
static void tst2() {
|
|
|
|
expr f = Const("f");
|
|
|
|
expr a = Const("a");
|
|
|
|
expr b = Const("b");
|
|
|
|
context c;
|
|
|
|
c = extend(c, "a", Type());
|
2013-08-17 00:11:24 +00:00
|
|
|
std::cout << c;
|
2013-09-07 18:11:45 +00:00
|
|
|
lean_assert(c.size() == 1);
|
2013-08-14 21:42:48 +00:00
|
|
|
lean_assert(lookup(c, 0).get_name() == "a");
|
|
|
|
auto p = lookup_ext(c, 0);
|
|
|
|
lean_assert(p.first.get_name() == "a");
|
2013-09-07 18:11:45 +00:00
|
|
|
lean_assert(p.second.size() == 0);
|
2013-08-14 21:00:30 +00:00
|
|
|
}
|
|
|
|
|
2013-08-14 19:00:11 +00:00
|
|
|
int main() {
|
2013-12-07 22:59:21 +00:00
|
|
|
save_stack_info();
|
2013-08-14 19:00:11 +00:00
|
|
|
tst1();
|
2013-08-14 21:00:30 +00:00
|
|
|
tst2();
|
2013-08-14 19:00:11 +00:00
|
|
|
return has_violations() ? 1 : 0;
|
|
|
|
}
|