Fix bugs with certain properties (and .x .y .z accessors) and add tests.

This commit is contained in:
Jeff Hutchinson 2021-08-16 22:02:24 -04:00
parent a449fadde2
commit 6ec40e86da
4 changed files with 125 additions and 48 deletions

View file

@ -471,6 +471,17 @@ TEST(Script, Basic_SimObject)
ASSERT_STREQ(parentFn.getString(), "FooBar");
ConsoleValue simpleFieldTest = RunScript(R"(
function a()
{
FudgeCollector.field = "A";
return FudgeCollector.field;
}
return a();
)");
ASSERT_STREQ(simpleFieldTest.getString(), "A");
ConsoleValue grp = RunScript(R"(
new SimGroup(FudgeCollectorGroup)
{
@ -587,4 +598,54 @@ TEST(Script, Basic_Package)
ASSERT_EQ(deactivatedValue.getInt(), 3);
}
TEST(Script, Sugar_Syntax)
{
ConsoleValue value = RunScript(R"(
function a()
{
%vector = "1 2 3";
return %vector.y;
}
return a();
)");
ASSERT_EQ(value.getInt(), 2);
ConsoleValue setValue = RunScript(R"(
function a()
{
%vector = "1 2 3";
%vector.y = 4;
return %vector.y;
}
return a();
)");
ASSERT_EQ(setValue.getInt(), 4);
ConsoleValue valueArray = RunScript(R"(
function a()
{
%vector[0] = "1 2 3";
return %vector[0].y;
}
return a();
)");
ASSERT_EQ(valueArray.getInt(), 2);
ConsoleValue valueSetArray = RunScript(R"(
function a()
{
%vector[0] = "1 2 3";
%vector[0].z = 5;
return %vector[0].z;
}
return a();
)");
ASSERT_EQ(valueSetArray.getInt(), 5);
}
#endif