lean2/tests/lua/namespace1.lua

24 lines
1.3 KiB
Lua
Raw Normal View History

local env = environment()
env = env:begin_namespace_scope("foo")
assert(env:get_namespace() == name("foo"))
env = add_decl(env, mk_var_decl(name(env:get_namespace(), "nat"), Type))
env = add_decl(env, mk_var_decl(name(env:get_namespace(), "int"), Type))
env = env:begin_namespace_scope("bar")
assert(env:get_namespace() == name("foo", "bar"))
assert(env:namespace_find("int"):name() == name("foo", "int"))
assert(env:namespace_find("nat"):name() == name("foo", "nat"))
env = add_decl(env, mk_var_decl(name(env:get_namespace(), "int"), Type))
assert(env:namespace_find("int"):name() == name("foo", "bar", "int"))
assert(env:get_name_in_namespace(name("foo", "bar", "int")) == name("int"))
assert(env:get_name_in_namespace(name("foo", "int")) == name("foo", "int")) -- it was shadowed by foo.bar.int
assert(env:get_name_in_namespace(name("foo", "nat")) == name("nat"))
env = env:end_scope()
assert(env:get_namespace() == name("foo"))
assert(env:get_name_in_namespace(name("foo", "bar", "int")) == name("bar", "int"))
assert(env:get_name_in_namespace(name("foo", "nat")) == name("nat"))
env = env:end_scope()
assert(env:get_name_in_namespace(name("foo", "bar", "int")) == name("foo", "bar", "int"))
assert(env:get_name_in_namespace(name("foo", "nat")) == name("foo", "nat"))
check_error(function() env = env:end_scope() end)
assert(env:get_namespace() == name())