mirror of
https://github.com/TorqueGameEngines/Torque3D.git
synced 2026-02-13 03:33:48 +00:00
TScript Bugfix
If the statement is a terminating statement on slot assignment (such as %var[%i]++;), the stack has to be popped everytime slot arrays are used regardless of the expression type.
This commit is contained in:
parent
3d4b7b469c
commit
0d743c8bb9
2 changed files with 109 additions and 1 deletions
|
|
@ -983,6 +983,114 @@ TEST_F(ScriptTest, InnerObjectTests)
|
|||
ASSERT_EQ(nestedFuncCall.getInt(), 123);
|
||||
}
|
||||
|
||||
TEST_F(ScriptTest, SlotOperatorTests)
|
||||
{
|
||||
ConsoleValue testSlot1 = RunScript(R"(
|
||||
new SimObject(testObjectSlot1);
|
||||
testObjectSlot1.data[1] = 2;
|
||||
|
||||
function test(%value)
|
||||
{
|
||||
testObjectSlot1.data[%value]++;
|
||||
|
||||
return testObjectSlot1.data[%value];
|
||||
}
|
||||
return test(1);
|
||||
)");
|
||||
|
||||
ASSERT_EQ(testSlot1.getInt(), 3);
|
||||
|
||||
ConsoleValue testSlot2 = RunScript(R"(
|
||||
new SimObject(testObjectSlot2);
|
||||
testObjectSlot2.data[1] = 5;
|
||||
|
||||
function test(%value)
|
||||
{
|
||||
testObjectSlot2.data[%value]--;
|
||||
|
||||
return testObjectSlot2.data[%value];
|
||||
}
|
||||
return test(1);
|
||||
)");
|
||||
|
||||
ASSERT_EQ(testSlot2.getInt(), 4);
|
||||
|
||||
ConsoleValue testSlot3 = RunScript(R"(
|
||||
new SimObject(testObjectSlot3);
|
||||
testObjectSlot3.data[1] = 5;
|
||||
|
||||
function test(%value)
|
||||
{
|
||||
testObjectSlot3.data[1] += 1;
|
||||
|
||||
return testObjectSlot3.data[1];
|
||||
}
|
||||
return test();
|
||||
)");
|
||||
|
||||
ASSERT_EQ(testSlot3.getInt(), 6);
|
||||
|
||||
ConsoleValue testSlot4 = RunScript(R"(
|
||||
new SimObject(testObjectSlot4);
|
||||
testObjectSlot4.data[1] = 5;
|
||||
|
||||
function test(%value)
|
||||
{
|
||||
testObjectSlot4.data[1] -= %value;
|
||||
|
||||
return testObjectSlot4.data[1];
|
||||
}
|
||||
return test(1);
|
||||
)");
|
||||
|
||||
ASSERT_EQ(testSlot4.getInt(), 4);
|
||||
|
||||
ConsoleValue testSlot5 = RunScript(R"(
|
||||
new SimObject(testObjectSlot5);
|
||||
testObjectSlot5.data[1] = 8;
|
||||
|
||||
function test()
|
||||
{
|
||||
testObjectSlot5.data[1] /= 2;
|
||||
|
||||
return testObjectSlot5.data[1];
|
||||
}
|
||||
return test();
|
||||
)");
|
||||
|
||||
ASSERT_EQ(testSlot5.getInt(), 4);
|
||||
|
||||
ConsoleValue testSlot6 = RunScript(R"(
|
||||
new SimObject(testObjectSlot6);
|
||||
testObjectSlot6.data[1] = 8;
|
||||
|
||||
function test()
|
||||
{
|
||||
testObjectSlot6.data[1] *= 2;
|
||||
|
||||
return testObjectSlot6.data[1];
|
||||
}
|
||||
return test();
|
||||
)");
|
||||
|
||||
ASSERT_EQ(testSlot6.getInt(), 16);
|
||||
|
||||
ConsoleValue testSlot7 = RunScript(R"(
|
||||
new SimObject(testObjectSlot7);
|
||||
testObjectSlot7.data[1] = 8;
|
||||
|
||||
function test()
|
||||
{
|
||||
testObjectSlot7.data[1] %= 3;
|
||||
|
||||
return testObjectSlot7.data[1];
|
||||
}
|
||||
return test();
|
||||
)");
|
||||
|
||||
ASSERT_EQ(testSlot7.getInt(), 2);
|
||||
}
|
||||
|
||||
TEST_F(ScriptTest, MiscTesting)
|
||||
{
|
||||
ConsoleValue test1 = RunScript(R"(
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue