script fixes from latest merge and more tests

This commit is contained in:
Jeff Hutchinson 2021-08-17 20:04:45 -04:00
parent ada1c5a021
commit 838395840d
3 changed files with 58 additions and 4 deletions

View file

@ -647,5 +647,58 @@ TEST(Script, Sugar_Syntax)
ASSERT_EQ(valueSetArray.getInt(), 5);
}
TEST(Script, InnerObjectTests)
{
ConsoleValue theObject = RunScript(R"(
function a()
{
%obj = new SimObject(TheOuterObject)
{
innerObject = new SimObject(TheInnerObject)
{
testField = 123;
position = "1 2 3";
};
};
return %obj;
}
return a();
)");
SimObject* outerObject = Sim::findObject("TheOuterObject");
ASSERT_NE(outerObject, (SimObject*)NULL);
if (outerObject)
{
ASSERT_EQ(theObject.getInt(), Sim::findObject("TheOuterObject")->getId());
}
ASSERT_NE(Sim::findObject("TheInnerObject"), (SimObject*)NULL);
ConsoleValue positionValue = RunScript(R"(
function TheOuterObject::getInnerPosition(%this)
{
return %this.innerObject.position;
}
function a()
{
%position = TheOuterObject.getInnerPosition();
return %position.y;
}
return a();
)");
ASSERT_EQ(positionValue.getInt(), 2);
ConsoleValue nestedFuncCall = RunScript(R"(
function TheInnerObject::test(%this)
{
return %this.testField;
}
return TheOuterObject.innerObject.test();
)");
ASSERT_EQ(nestedFuncCall.getInt(), 123);
}
#endif