Simplify property handling; Fix unit tests

This commit is contained in:
Alexander Bock
2023-03-11 15:58:40 +01:00
parent 27aeac0776
commit 3df65ae899
8 changed files with 14 additions and 34 deletions

View File

@@ -199,10 +199,8 @@ public:
* no-op.
*
* \param state The Lua state from which the value will be decoded
* \return `true` if the decoding and setting of the value succeeded, `false`
* otherwise
*/
virtual bool setLuaValue(lua_State* state);
virtual void setLuaValue(lua_State* state);
/**
* Returns the Lua type that will be put onto the stack in the Property::getLua method

View File

@@ -115,7 +115,7 @@ public:
* \param state The Lua state from which the value will be decoded
* \return `true` if the decoding succeeded; `false` otherwise
*/
virtual bool setLuaValue(lua_State* state) override;
virtual void setLuaValue(lua_State* state) override;
/// \see Property::typeLua
virtual int typeLua() const override = 0;

View File

@@ -85,15 +85,9 @@ bool TemplateProperty<T>::getLuaValue(lua_State* state) const {
}
template <typename T>
bool TemplateProperty<T>::setLuaValue(lua_State* state) {
try {
T thisValue = fromLuaConversion(state);
set(std::any(thisValue));
return true;
}
catch (const ghoul::lua::LuaFormatException&) {
return false;
}
void TemplateProperty<T>::setLuaValue(lua_State* state) {
T thisValue = fromLuaConversion(state);
set(std::any(thisValue));
}
template <typename T>

View File

@@ -57,7 +57,7 @@ public:
* \param state The unused Lua state
* \return Returns always `true`
*/
bool setLuaValue(lua_State* state) override;
void setLuaValue(lua_State* state) override;
/**
* Silently ignores any value that is passed into this function and will trigger the

View File

@@ -98,9 +98,7 @@ bool Property::getLuaValue(lua_State*) const {
void Property::set(std::any) {}
bool Property::setLuaValue(lua_State*) {
return false;
}
void Property::setLuaValue(lua_State*) {}
const std::type_info& Property::type() const {
return typeid(void);

View File

@@ -34,9 +34,8 @@ std::string_view TriggerProperty::className() const {
return "TriggerProperty";
}
bool TriggerProperty::setLuaValue(lua_State*) {
void TriggerProperty::setLuaValue(lua_State*) {
notifyChangeListeners();
return true;
}
void TriggerProperty::set(std::any) {

View File

@@ -94,9 +94,7 @@ TEST_CASE("StringListProperty: Invalid Set Lua Value - Not List", "[stringlistpr
ghoul::lua::LuaState L;
ghoul::lua::push(L, 2); // Not a list
bool success = p.setLuaValue(L);
CHECK(!success);
CHECK_THROWS(p.setLuaValue(L));
}
TEST_CASE("StringListProperty: Get Lua Value", "[stringlistproperty]") {
@@ -192,9 +190,7 @@ TEST_CASE("IntListProperty: Set Lua Value - Non-number", "[intlistproperty]") {
ghoul::lua::LuaState L;
ghoul::lua::push(L, std::vector{ "not a number", "oops" });
bool success = p.setLuaValue(L);
CHECK(success == false);
CHECK_THROWS(p.setLuaValue(L));
CHECK(p.value() == std::vector<int>());
}
@@ -204,9 +200,7 @@ TEST_CASE("IntListProperty: Invalid Set Lua Value - Not List", "[intlistproperty
ghoul::lua::LuaState L;
ghoul::lua::push(L, 2); // Not a list
bool success = p.setLuaValue(L);
CHECK(!success);
CHECK_THROWS(p.setLuaValue(L));
}
TEST_CASE("IntListProperty: Get Lua Value", "[intlistproperty]") {
@@ -302,9 +296,7 @@ TEST_CASE("DoubleListProperty: Set Lua Value - Non-number", "[doublelistproperty
ghoul::lua::LuaState L;
ghoul::lua::push(L, std::vector{"not a number", "oops"});
bool success = p.setLuaValue(L);
CHECK(success == false);
CHECK_THROWS(p.setLuaValue(L));
CHECK(p.value() == std::vector<double>());
}
@@ -314,8 +306,7 @@ TEST_CASE("DoubleListProperty: Invalid Set Lua Value - Not List", "[doublelistpr
ghoul::lua::LuaState L;
ghoul::lua::push(L, 2); // Not a list
bool success = p.setLuaValue(L);
CHECK(!success);
CHECK_THROWS(p.setLuaValue(L));
}
TEST_CASE("DoubleListProperty: Get Lua Value", "[doublelistproperty]") {

View File

@@ -167,7 +167,7 @@ TEST_CASE("Minimal", "[profile]") {
Profile ref;
ref.version.major = 1;
ref.version.minor = 1;
ref.version.minor = 2;
CHECK(profile == ref);
}