From 94b90a2cb0b4a0e13018cd5ebbf09394abf3b96b Mon Sep 17 00:00:00 2001 From: Vaxry <43317083+vaxerski@users.noreply.github.com> Date: Tue, 28 Apr 2026 18:10:25 +0100 Subject: config/lua: add ExpressionVec2, allow using a table for vec2 rules (#14197) --- tests/config/lua/ConfigValueTypes.cpp | 53 +++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) (limited to 'tests/config/lua') 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 #include #include +#include #include #include #include @@ -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(); -- cgit v1.2.3