Rewritten previous enviroment tests to new implementation

This commit is contained in:
Robert Bendun 2022-05-22 03:42:17 +02:00
parent 6bc2a1cd38
commit c1493a75c2

View File

@ -1,4 +1,3 @@
#if 0
#include <boost/ut.hpp>
#include <musique.hh>
@ -16,67 +15,47 @@ static void equals(
suite environment_test = [] {
"Global enviroment exists"_test = [] {
Interpreter i;
expect(eq(&i.env_pool.front(), &Env::global()));
expect(not bool(Env::global)) << "Before interpreter global environment does not exists";
{
Interpreter i;
expect(bool(Env::global)) << "When interpreter exists global environment exists";
}
expect(not bool(Env::global)) << "After interpreter destruction, global environment does not exists";
};
"Environment scoping"_test = [] {
should("nested scoping preserve outer scope") = [] {
Interpreter i;
i.env().force_define("x", Value::number(Number(10)));
i.env().force_define("y", Value::number(Number(20)));
i.env->force_define("x", Value::number(Number(10)));
i.env->force_define("y", Value::number(Number(20)));
equals(i.env().find("x"), Value::number(Number(10)));
equals(i.env().find("y"), Value::number(Number(20)));
equals(i.env->find("x"), Value::number(Number(10)));
equals(i.env->find("y"), Value::number(Number(20)));
i.current_env = ++i.env();
i.env().force_define("x", Value::number(Number(30)));
equals(i.env().find("x"), Value::number(Number(30)));
equals(i.env().find("y"), Value::number(Number(20)));
i.enter_scope();
{
i.env->force_define("x", Value::number(Number(30)));
equals(i.env->find("x"), Value::number(Number(30)));
equals(i.env->find("y"), Value::number(Number(20)));
}
i.leave_scope();
i.current_env = --i.env();
equals(i.env().find("x"), Value::number(Number(10)));
equals(i.env().find("y"), Value::number(Number(20)));
equals(i.env->find("x"), Value::number(Number(10)));
equals(i.env->find("y"), Value::number(Number(20)));
};
should("nested variables missing from outer scope") = [] {
Interpreter i;
i.current_env = ++i.env();
i.env().force_define("x", Value::number(Number(30)));
equals(i.env().find("x"), Value::number(Number(30)));
i.enter_scope();
{
i.env->force_define("x", Value::number(Number(30)));
equals(i.env->find("x"), Value::number(Number(30)));
}
i.leave_scope();
i.current_env = --i.env();
expect(eq(i.env().find("x"), nullptr));
};
should("stay at global scope when too much end of scope is applied") = [] {
Interpreter i;
i.current_env = --i.env();
expect(eq(&i.env(), &Env::global()));
};
should("reuse already allocated enviroments") = [] {
Interpreter i;
i.current_env = ++i.env();
auto const first_env = &i.env();
i.env().force_define("x", Value::number(Number(30)));
equals(i.env().find("x"), Value::number(Number(30)));
i.current_env = --i.env();
expect(eq(i.env().find("x"), nullptr));
i.current_env = ++i.env();
expect(eq(first_env, &i.env()));
expect(eq(i.env().find("x"), nullptr));
i.env().force_define("x", Value::number(Number(30)));
equals(i.env().find("x"), Value::number(Number(30)));
i.current_env = --i.env();
expect(eq(i.env().find("x"), nullptr));
expect(eq(i.env->find("x"), nullptr));
};
};
};
#endif