2014-05-31 22:40:36 +00:00
|
|
|
local env = environment()
|
2014-06-01 04:44:12 +00:00
|
|
|
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())
|