diff options
| author | Vaxry <43317083+vaxerski@users.noreply.github.com> | 2026-04-26 15:16:36 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2026-04-26 15:16:36 +0100 |
| commit | 5ba33f846129f3e6c0505b19f94634b24505e828 (patch) | |
| tree | aaacabe678006040c342935481a86607c66607fd /tests/config/lua/LuaConfigUtils.cpp | |
| parent | 329b2b356dd92ac07f4e2aa69cbce82ee9ba9d19 (diff) | |
config/lua: init lua config manager, use lua if available (#13817)
Adds a new lua config manager, which will automatically be used if there is a lua config present.
Diffstat (limited to 'tests/config/lua/LuaConfigUtils.cpp')
| -rw-r--r-- | tests/config/lua/LuaConfigUtils.cpp | 105 |
1 files changed, 105 insertions, 0 deletions
diff --git a/tests/config/lua/LuaConfigUtils.cpp b/tests/config/lua/LuaConfigUtils.cpp new file mode 100644 index 00000000..a165755e --- /dev/null +++ b/tests/config/lua/LuaConfigUtils.cpp @@ -0,0 +1,105 @@ +#include <config/lua/types/LuaConfigUtils.hpp> + +#include <config/lua/types/LuaConfigBool.hpp> +#include <config/lua/types/LuaConfigColor.hpp> +#include <config/lua/types/LuaConfigCssGap.hpp> +#include <config/lua/types/LuaConfigFloat.hpp> +#include <config/lua/types/LuaConfigFontWeight.hpp> +#include <config/lua/types/LuaConfigGradient.hpp> +#include <config/lua/types/LuaConfigInt.hpp> +#include <config/lua/types/LuaConfigString.hpp> +#include <config/lua/types/LuaConfigVec2.hpp> + +#include <config/values/types/BoolValue.hpp> +#include <config/values/types/ColorValue.hpp> +#include <config/values/types/CssGapValue.hpp> +#include <config/values/types/FloatValue.hpp> +#include <config/values/types/FontWeightValue.hpp> +#include <config/values/types/GradientValue.hpp> +#include <config/values/types/IntValue.hpp> +#include <config/values/types/StringValue.hpp> +#include <config/values/types/Vec2Value.hpp> + +#include <gtest/gtest.h> + +using namespace Config; +using namespace Config::Lua; + +namespace { + class CUnsupportedValue : public Values::IValue { + public: + CUnsupportedValue() : Values::IValue(0) { + m_name = "unsupported"; + m_description = "unsupported"; + } + + const std::type_info* underlying() const override { + return &typeid(void); + } + + void commence() override { + ; + } + }; +} + +TEST(ConfigLuaUtils, fromGenericValueMapsSupportedTypes) { + { + auto out = fromGenericValue(makeShared<Values::CIntValue>("a", "", 1)); + ASSERT_NE(out.get(), nullptr); + EXPECT_NE(dynamic_cast<CLuaConfigInt*>(out.get()), nullptr); + } + { + auto out = fromGenericValue(makeShared<Values::CFloatValue>("a", "", 1.F)); + ASSERT_NE(out.get(), nullptr); + EXPECT_NE(dynamic_cast<CLuaConfigFloat*>(out.get()), nullptr); + } + { + auto out = fromGenericValue(makeShared<Values::CBoolValue>("a", "", true)); + ASSERT_NE(out.get(), nullptr); + EXPECT_NE(dynamic_cast<CLuaConfigBool*>(out.get()), nullptr); + } + { + auto out = fromGenericValue(makeShared<Values::CStringValue>("a", "", "x")); + ASSERT_NE(out.get(), nullptr); + EXPECT_NE(dynamic_cast<CLuaConfigString*>(out.get()), nullptr); + } + { + auto out = fromGenericValue(makeShared<Values::CColorValue>("a", "", 0xFF000000)); + ASSERT_NE(out.get(), nullptr); + EXPECT_NE(dynamic_cast<CLuaConfigColor*>(out.get()), nullptr); + } + { + auto out = fromGenericValue(makeShared<Values::CVec2Value>("a", "", VEC2{1, 2})); + ASSERT_NE(out.get(), nullptr); + EXPECT_NE(dynamic_cast<CLuaConfigVec2*>(out.get()), nullptr); + } + { + auto out = fromGenericValue(makeShared<Values::CCssGapValue>("a", "", 5)); + ASSERT_NE(out.get(), nullptr); + EXPECT_NE(dynamic_cast<CLuaConfigCssGap*>(out.get()), nullptr); + } + { + auto out = fromGenericValue(makeShared<Values::CFontWeightValue>("a", "", 500)); + ASSERT_NE(out.get(), nullptr); + EXPECT_NE(dynamic_cast<CLuaConfigFontWeight*>(out.get()), nullptr); + } + { + auto out = fromGenericValue(makeShared<Values::CGradientValue>("a", "", CHyprColor(0xFF112233))); + ASSERT_NE(out.get(), nullptr); + EXPECT_NE(dynamic_cast<CLuaConfigGradient*>(out.get()), nullptr); + } +} + +TEST(ConfigLuaUtils, fromGenericValueReturnsNullForUnsupportedType) { + auto out = fromGenericValue(makeShared<CUnsupportedValue>()); + EXPECT_EQ(out.get(), nullptr); +} + +TEST(ConfigLuaUtils, fromGenericValueCopiesRefreshBits) { + const auto REFRESH = Config::Supplementary::REFRESH_LAYOUTS | Config::Supplementary::REFRESH_WINDOW_STATES; + + auto out = fromGenericValue(makeShared<Values::CIntValue>("a", "", 1, Values::SIntValueOptions{.refresh = REFRESH})); + ASSERT_NE(out.get(), nullptr); + EXPECT_EQ(out->refreshBits(), REFRESH); +} |
