Fixed issue where an indexer followed by a binary operator would ignore the binary
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
@@ -20,6 +20,7 @@ using namespace Porygon::Utilities;
|
||||
class UserDataTestObject{
|
||||
public:
|
||||
int foo = 10;
|
||||
int readonly = 5;
|
||||
vector<int> fooVector = {5,10,15,25};
|
||||
int getFoo(){
|
||||
return foo;
|
||||
@@ -41,6 +42,7 @@ private:
|
||||
public:
|
||||
PORYGON_USERDATA(UserDataTestObject,
|
||||
PORYGON_INTEGER_FIELD(foo)
|
||||
PORYGON_READONLY_INTEGER_FIELD(readonly)
|
||||
PORYGON_INTEGER_FUNCTION(getFoo)
|
||||
PORYGON_INTEGER_FUNCTION(Addition, PORYGON_INTEGER_TYPE, PORYGON_INTEGER_TYPE)
|
||||
PORYGON_READONLY_VECTOR_FIELD(fooVector, PORYGON_INTEGER_TYPE)
|
||||
@@ -173,6 +175,52 @@ end
|
||||
UserDataStorage::RemoveType(HashedString::ConstHash("testObject"));
|
||||
}
|
||||
|
||||
TEST_CASE( "returns readonly value + 2", "[integration]" ) {
|
||||
UserDataStorage::RegisterType(HashedString::ConstHash("testObject"), UserDataTestObject::__createUserData());
|
||||
Script* script = Script::Create(R"(
|
||||
function testFunc(testObject obj)
|
||||
return obj.readonly + 2
|
||||
end
|
||||
)");
|
||||
REQUIRE(!script->Diagnostics -> HasErrors());
|
||||
script->Evaluate();
|
||||
auto func = (GenericFunctionEvalValue*)script -> GetVariable(u"testFunc");
|
||||
auto funcType = func -> GetType();
|
||||
auto obj = new UserDataTestObject();
|
||||
auto parameter = new UserDataValue(HashedString::ConstHash("testObject"), obj);
|
||||
auto result = script->CallFunction(u"testFunc", {parameter});
|
||||
REQUIRE(result -> EvaluateInteger() == 7);
|
||||
delete obj;
|
||||
delete parameter;
|
||||
delete script;
|
||||
delete func;
|
||||
delete result;
|
||||
UserDataStorage::RemoveType(HashedString::ConstHash("testObject"));
|
||||
}
|
||||
|
||||
TEST_CASE( "returns negative readonly value", "[integration]" ) {
|
||||
UserDataStorage::RegisterType(HashedString::ConstHash("testObject"), UserDataTestObject::__createUserData());
|
||||
Script* script = Script::Create(R"(
|
||||
function testFunc(testObject obj)
|
||||
return -obj.readonly
|
||||
end
|
||||
)");
|
||||
REQUIRE(!script->Diagnostics -> HasErrors());
|
||||
script->Evaluate();
|
||||
auto func = (GenericFunctionEvalValue*)script -> GetVariable(u"testFunc");
|
||||
auto funcType = func -> GetType();
|
||||
auto obj = new UserDataTestObject();
|
||||
auto parameter = new UserDataValue(HashedString::ConstHash("testObject"), obj);
|
||||
auto result = script->CallFunction(u"testFunc", {parameter});
|
||||
REQUIRE(result -> EvaluateInteger() == -5);
|
||||
delete obj;
|
||||
delete parameter;
|
||||
delete script;
|
||||
delete func;
|
||||
delete result;
|
||||
UserDataStorage::RemoveType(HashedString::ConstHash("testObject"));
|
||||
}
|
||||
|
||||
TEST_CASE( "Iterate over userdata vector keys", "[integration]" ) {
|
||||
UserDataStorage::RegisterType(HashedString::ConstHash("testObject"), UserDataTestObject::__createUserData());
|
||||
Script* script = Script::Create(R"(
|
||||
|
||||
Reference in New Issue
Block a user