diff options
| author | Vaxry <43317083+vaxerski@users.noreply.github.com> | 2026-04-28 18:10:25 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2026-04-28 18:10:25 +0100 |
| commit | 94b90a2cb0b4a0e13018cd5ebbf09394abf3b96b (patch) | |
| tree | 484d32baaab1acdaab7a817c86aa89f117a21059 /tests/config/lua | |
| parent | ab75bbfbecdfb4a0355106f740944c87cb9edd4c (diff) | |
config/lua: add ExpressionVec2, allow using a table for vec2 rules (#14197)
Diffstat (limited to 'tests/config/lua')
| -rw-r--r-- | tests/config/lua/ConfigValueTypes.cpp | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/tests/config/lua/ConfigValueTypes.cpp b/tests/config/lua/ConfigValueTypes.cpp index 90e97520..76de98bf 100644 --- a/tests/config/lua/ConfigValueTypes.cpp +++ b/tests/config/lua/ConfigValueTypes.cpp @@ -1,6 +1,7 @@ #include <config/lua/types/LuaConfigBool.hpp> #include <config/lua/types/LuaConfigColor.hpp> #include <config/lua/types/LuaConfigCssGap.hpp> +#include <config/lua/types/LuaConfigExpressionVec2.hpp> #include <config/lua/types/LuaConfigFloat.hpp> #include <config/lua/types/LuaConfigFontWeight.hpp> #include <config/lua/types/LuaConfigGradient.hpp> @@ -49,6 +50,14 @@ namespace { lua_pushnumber(L, y); lua_rawseti(L, -2, 2); } + + void pushExpressionVec2Table(lua_State* L, const char* x, const char* y) { + lua_createtable(L, 2, 2); + lua_pushstring(L, x); + lua_rawseti(L, -2, 1); + lua_pushstring(L, y); + lua_rawseti(L, -2, 2); + } } TEST(ConfigLuaValueTypes, boolParseAndReset) { @@ -234,6 +243,50 @@ TEST(ConfigLuaValueTypes, vec2ParseValidateAndPush) { EXPECT_EQ(err.errorCode, PARSE_ERROR_BAD_VALUE); } +TEST(ConfigLuaValueTypes, expressionVec2AcceptsStringNumberAndTableForms) { + CLuaState S; + const auto L = S.get(); + + CLuaConfigExpressionVec2 value; + + lua_pushstring(L, "monitor_w*0.5 monitor_h*0.25"); + auto err = value.parse(L); + lua_pop(L, 1); + EXPECT_EQ(err.errorCode, PARSE_ERROR_OK); + EXPECT_EQ(value.parsed().x, "monitor_w*0.5"); + EXPECT_EQ(value.parsed().y, "monitor_h*0.25"); + + pushVec2Table(L, 150, 200); + err = value.parse(L); + lua_pop(L, 1); + EXPECT_EQ(err.errorCode, PARSE_ERROR_OK); + EXPECT_EQ(value.parsed().x, "150"); + EXPECT_EQ(value.parsed().y, "200"); + + pushExpressionVec2Table(L, "monitor_h * 0.5", "monitor_h * 0.25"); + err = value.parse(L); + lua_pop(L, 1); + EXPECT_EQ(err.errorCode, PARSE_ERROR_OK); + EXPECT_EQ(value.parsed().x, "monitor_h * 0.5"); + EXPECT_EQ(value.parsed().y, "monitor_h * 0.25"); + + value.push(L); + ASSERT_TRUE(lua_istable(L, -1)); + lua_rawgeti(L, -1, 1); + EXPECT_STREQ(lua_tostring(L, -1), "monitor_h * 0.5"); + lua_pop(L, 1); + lua_getfield(L, -1, "y"); + EXPECT_STREQ(lua_tostring(L, -1), "monitor_h * 0.25"); + lua_pop(L, 2); + + lua_createtable(L, 1, 0); + lua_pushnumber(L, 1); + lua_rawseti(L, -2, 1); + err = value.parse(L); + lua_pop(L, 1); + EXPECT_EQ(err.errorCode, PARSE_ERROR_BAD_VALUE); +} + TEST(ConfigLuaValueTypes, cssGapParseFormsAndRange) { CLuaState S; const auto L = S.get(); |
