rename SimpleEnv to LazyEnv

This commit is contained in:
falsycat 2023-11-03 19:03:36 +09:00
parent 56b37fad43
commit 0e1dc34937
9 changed files with 49 additions and 49 deletions

View File

@ -29,17 +29,17 @@ class EnvFixture : public ::testing::Test {
protected:
template <typename I>
void Install(SimpleEnv::ObjectOrFactory&& v) {
void Install(LazyEnv::ObjectOrFactory&& v) {
map_.emplace(typeid(I), std::move(v));
}
template <typename I, typename T>
void Install() {
map_.insert(SimpleEnv::MakeItem<I, T>());
map_.insert(LazyEnv::MakeItem<I, T>());
}
protected:
void SetUp() override {
env_ = SimpleEnv::Make(std::move(map_));
env_ = LazyEnv::Make(std::move(map_));
}
void TearDown() override {
env_ = nullptr;
@ -49,8 +49,8 @@ class EnvFixture : public ::testing::Test {
Env& env() noexcept { return *env_; }
private:
SimpleEnv::Map map_;
std::shared_ptr<SimpleEnv> env_;
LazyEnv::Map map_;
std::shared_ptr<LazyEnv> env_;
};
class EnvFixtureWithTasking : public EnvFixture {

View File

@ -76,7 +76,7 @@ class Context::Impl final : public std::enable_shared_from_this<Impl> {
tasq_(std::make_shared<Tasq>()),
tasq_wrap_(std::make_shared<SwitchingTasq>(tasq_, concurrency_)),
ljctx_(luajit::Context::MakeSync(
*SimpleEnv::Make(
*LazyEnv::Make(
{{typeid(subsys::Concurrency), tasq_wrap_}},
env.self()))),
imgui_(ImGui::CreateContext()) { }
@ -100,7 +100,7 @@ class Context::Impl final : public std::enable_shared_from_this<Impl> {
}
std::shared_ptr<Env> MakeDriversEnv(Env& env) {
return SimpleEnv::Make(
return LazyEnv::Make(
{
{typeid(subsys::Concurrency), tasq_wrap_},
{typeid(luajit::Context), ljctx_},

View File

@ -35,7 +35,7 @@ try {
supermaker.get());
auto denv_base = ctx->MakeDriversEnv(env);
auto denv = SimpleEnv::Make(
auto denv = LazyEnv::Make(
{{typeid(subsys::Maker<nf7::Value>), maker}},
denv_base);

View File

@ -33,7 +33,7 @@ TEST_F(ImGuiLuaJITDriver, CompileAndInstall) {
ON_CALL(*logger, Push).WillByDefault(
[](const auto& item) {std::cout << item.contents() << std::endl; });
const auto subenv = nf7::SimpleEnv::Make(
const auto subenv = nf7::LazyEnv::Make(
{{typeid(nf7::subsys::Logger), logger}}, env().self());
auto fu = nf7::core::imgui::LuaJITDriver::CompileAndInstall(

View File

@ -153,7 +153,7 @@ TEST_P(LuaJIT_Lambda, CtxMultiSend) {
TEST_P(LuaJIT_Lambda, CtxSleep) {
const auto clock = std::make_shared<nf7::core::Clock>();
nf7::SimpleEnv env {{
nf7::LazyEnv env {{
{typeid(nf7::subsys::Clock), [&](auto&) { return clock; }},
}, this->env().self()};
@ -194,7 +194,7 @@ TEST_P(LuaJIT_Lambda, CtxLogging) {
EXPECT_EQ(item.contents(), "this is error");
});
nf7::SimpleEnv env {{
nf7::LazyEnv env {{
{typeid(nf7::subsys::Logger), [&](auto&) { return logger; }},
}, this->env().self()};

View File

@ -13,9 +13,9 @@ static inline bool MatchPair(
}
TEST(MetaEnv, FindOrByName) {
const auto a = nf7::SimpleEnv::Make();
const auto b = nf7::SimpleEnv::Make();
const auto c = nf7::SimpleEnv::Make();
const auto a = nf7::LazyEnv::Make();
const auto b = nf7::LazyEnv::Make();
const auto c = nf7::LazyEnv::Make();
nf7::core::MetaEnv sut {
{
@ -33,9 +33,9 @@ TEST(MetaEnv, FindOrByName) {
}
TEST(MetaEnv, FindOrByIndex) {
const auto a = nf7::SimpleEnv::Make();
const auto b = nf7::SimpleEnv::Make();
const auto c = nf7::SimpleEnv::Make();
const auto a = nf7::LazyEnv::Make();
const auto b = nf7::LazyEnv::Make();
const auto c = nf7::LazyEnv::Make();
nf7::core::MetaEnv sut {
{
@ -52,9 +52,9 @@ TEST(MetaEnv, FindOrByIndex) {
}
TEST(MetaEnv, FetchAll) {
const auto a = nf7::SimpleEnv::Make();
const auto b = nf7::SimpleEnv::Make();
const auto c = nf7::SimpleEnv::Make();
const auto a = nf7::LazyEnv::Make();
const auto b = nf7::LazyEnv::Make();
const auto c = nf7::LazyEnv::Make();
nf7::core::MetaEnv sut {
{

View File

@ -82,7 +82,7 @@ class NullContainer : public Container<I> {
};
template <typename I>
class SimpleContainer : public Container<I> {
class LazyContainer : public Container<I> {
public:
using Object = std::shared_ptr<I>;
using Factory = std::function<Object(Container<I>&)>;
@ -119,14 +119,14 @@ class SimpleContainer : public Container<I> {
}
public:
static std::shared_ptr<SimpleContainer<I>> Make(
static std::shared_ptr<LazyContainer<I>> Make(
Map&& m = {},
const std::shared_ptr<Container<I>>& fb = NullContainer<I>::kInstance) {
return std::make_shared<SimpleContainer<I>>(std::move(m), fb);
return std::make_shared<LazyContainer<I>>(std::move(m), fb);
}
public:
SimpleContainer(Map&& m, const std::shared_ptr<Container<I>>& fb) noexcept
LazyContainer(Map&& m, const std::shared_ptr<Container<I>>& fb) noexcept
: map_(std::move(m)), fallback_(fb) { }
public:

View File

@ -10,7 +10,7 @@ class Object {
public:
virtual ~Object() = default;
};
using SUT = nf7::SimpleContainer<Object>;
using Lazy = nf7::LazyContainer<Object>;
class IA : public Object { };
class IB : public Object { };
@ -33,60 +33,60 @@ class BRecursive : public IB {
};
} // namespace
TEST(SimpleContainer, FetchIsolated) {
auto sut = SUT::Make({ SUT::MakeItem<IA, A>(), });
TEST(LazyContainer, FetchIsolated) {
auto sut = Lazy::Make({ Lazy::MakeItem<IA, A>(), });
auto ptr = sut->Get<IA>();
EXPECT_TRUE(std::dynamic_pointer_cast<A>(ptr));
}
TEST(SimpleContainer, FetchDepending) {
auto sut = SUT::Make({
SUT::MakeItem<IA, A>(),
SUT::MakeItem<IB, B>(),
TEST(LazyContainer, FetchDepending) {
auto sut = Lazy::Make({
Lazy::MakeItem<IA, A>(),
Lazy::MakeItem<IB, B>(),
});
auto ptr = sut->Get<IB>();
EXPECT_TRUE(std::dynamic_pointer_cast<B>(ptr));
}
TEST(SimpleContainer, FetchUnknown) {
auto sut = SUT::Make();
TEST(LazyContainer, FetchUnknown) {
auto sut = Lazy::Make();
EXPECT_THROW(sut->Get<IA>(), nf7::Exception);
}
TEST(SimpleContainer, FetchUnknownDepending) {
auto sut = SUT::Make({ SUT::MakeItem<IB, B>(), });
TEST(LazyContainer, FetchUnknownDepending) {
auto sut = Lazy::Make({ Lazy::MakeItem<IB, B>(), });
EXPECT_THROW(sut->Get<IB>(), nf7::Exception);
}
TEST(SimpleContainer, FetchWithFallback) {
auto fb = SUT::Make({ SUT::MakeItem<IA, A>(), });
auto sut = SUT::Make({}, fb);
TEST(LazyContainer, FetchWithFallback) {
auto fb = Lazy::Make({ Lazy::MakeItem<IA, A>(), });
auto sut = Lazy::Make({}, fb);
auto ptr = sut->Get<IA>();
EXPECT_TRUE(std::dynamic_pointer_cast<A>(ptr));
}
TEST(SimpleContainer, FetchUnknownWithFallback) {
auto fb = SUT::Make();
auto sut = SUT::Make({}, fb);
TEST(LazyContainer, FetchUnknownWithFallback) {
auto fb = Lazy::Make();
auto sut = Lazy::Make({}, fb);
EXPECT_THROW(sut->Get<IA>(), nf7::Exception);
}
TEST(SimpleContainer, ConstructWithSharedInstance) {
TEST(LazyContainer, ConstructWithSharedInstance) {
class Ashared : public IA {
public:
Ashared(const std::shared_ptr<nf7::Container<Object>>&) { }
};
auto sut = SUT::Make({ SUT::MakeItem<IA, Ashared>(), });
auto sut = Lazy::Make({ Lazy::MakeItem<IA, Ashared>(), });
EXPECT_TRUE(sut->Get<IA>());
}
TEST(SimpleContainer, ConstructWithNothing) {
TEST(LazyContainer, ConstructWithNothing) {
class Anothing : public IA {
public:
Anothing() { }
};
auto sut = SUT::Make({ SUT::MakeItem<IA, Anothing>(), });
auto sut = Lazy::Make({ Lazy::MakeItem<IA, Anothing>(), });
EXPECT_TRUE(sut->Get<IA>());
}
#if !defined(NDEBUG)
TEST(SimpleContainer, DeathByFetchRecursive) {
auto sut = SUT::Make({ SUT::MakeItem<IB, BRecursive>(), });
TEST(LazyContainer, DeathByFetchRecursive) {
auto sut = Lazy::Make({ Lazy::MakeItem<IB, BRecursive>(), });
ASSERT_DEATH_IF_SUPPORTED(sut->Get<IB>(), "");
}
#endif

View File

@ -6,7 +6,7 @@
namespace nf7 {
using Env = Container<subsys::Interface>;
using SimpleEnv = SimpleContainer<subsys::Interface>;
using Env = Container<subsys::Interface>;
using LazyEnv = LazyContainer<subsys::Interface>;
} // namespace nf7