mirror of
https://github.com/Heretek-AI/GDevelop.git
synced 2026-07-23 18:45:48 -04:00
Fix handling of object parameters in expressions
This commit is contained in:
@@ -47,12 +47,14 @@ TEST_CASE("ExpressionCodeGenerator", "[common][events]") {
|
||||
REQUIRE(expressionCodeGenerator.GetOutput() == "\"hello\" + \"world\"");
|
||||
}
|
||||
{
|
||||
auto node = parser.ParseExpression("string", "\"{\\\"hello\\\": \\\"world \\\\\\\" \\\"}\"");
|
||||
auto node = parser.ParseExpression(
|
||||
"string", "\"{\\\"hello\\\": \\\"world \\\\\\\" \\\"}\"");
|
||||
gd::ExpressionCodeGenerator expressionCodeGenerator(codeGenerator,
|
||||
context);
|
||||
|
||||
node->Visit(expressionCodeGenerator);
|
||||
REQUIRE(expressionCodeGenerator.GetOutput() == "\"{\\\"hello\\\": \\\"world \\\\\\\" \\\"}\"");
|
||||
REQUIRE(expressionCodeGenerator.GetOutput() ==
|
||||
"\"{\\\"hello\\\": \\\"world \\\\\\\" \\\"}\"");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -159,23 +161,6 @@ TEST_CASE("ExpressionCodeGenerator", "[common][events]") {
|
||||
REQUIRE(expressionCodeGenerator.GetOutput() ==
|
||||
"MySpriteObject.getObjectStringWith1Param(getNumber()) ?? \"\"");
|
||||
}
|
||||
{
|
||||
auto node =
|
||||
parser.ParseExpression("string",
|
||||
"MySpriteObject.GetObjectStringWith3Param("
|
||||
"MySpriteObject.GetObjectNumber() / 2.3, "
|
||||
"MySpriteObject.GetObjectStringWith1Param("
|
||||
"MyExtension::GetNumber()), test)");
|
||||
gd::ExpressionCodeGenerator expressionCodeGenerator(codeGenerator,
|
||||
context);
|
||||
|
||||
node->Visit(expressionCodeGenerator);
|
||||
REQUIRE(expressionCodeGenerator.GetOutput() ==
|
||||
"MySpriteObject.getObjectStringWith3Param(MySpriteObject."
|
||||
"getObjectNumber() ?? 0 / 2.3, "
|
||||
"MySpriteObject.getObjectStringWith1Param(getNumber()) ?? \"\", "
|
||||
"\"test\") ?? \"\"");
|
||||
}
|
||||
}
|
||||
SECTION("Valid function calls with optional arguments") {
|
||||
{
|
||||
@@ -216,6 +201,24 @@ TEST_CASE("ExpressionCodeGenerator", "[common][events]") {
|
||||
}
|
||||
}
|
||||
SECTION("Invalid function calls") {
|
||||
{
|
||||
auto node =
|
||||
parser.ParseExpression("string",
|
||||
"MySpriteObject.GetObjectStringWith3Param("
|
||||
"MySpriteObject.GetObjectNumber() / 2.3, "
|
||||
"MySpriteObject.GetObjectStringWith1Param("
|
||||
"MyExtension::GetNumber()), test)");
|
||||
gd::ExpressionCodeGenerator expressionCodeGenerator(codeGenerator,
|
||||
context);
|
||||
|
||||
node->Visit(expressionCodeGenerator);
|
||||
REQUIRE(expressionCodeGenerator.GetOutput() ==
|
||||
"MySpriteObject.getObjectStringWith3Param(MySpriteObject."
|
||||
"getObjectNumber() ?? 0 / 2.3, "
|
||||
"MySpriteObject.getObjectStringWith1Param(getNumber()) ?? \"\", "
|
||||
"/* Error during generation, unrecognized identifier type: "
|
||||
"unknown with value test */ \"test\") ?? \"\"");
|
||||
}
|
||||
{
|
||||
auto node = parser.ParseExpression(
|
||||
"number",
|
||||
@@ -370,6 +373,16 @@ TEST_CASE("ExpressionCodeGenerator", "[common][events]") {
|
||||
}
|
||||
}
|
||||
}
|
||||
SECTION("Objects") {
|
||||
gd::String output = gd::ExpressionCodeGenerator::GenerateExpressionCode(
|
||||
codeGenerator,
|
||||
context,
|
||||
"string",
|
||||
"MySpriteObject.GetObjectStringWith2ObjectParam(Object1, Object2)");
|
||||
REQUIRE(output ==
|
||||
"MySpriteObject.getObjectStringWith2ObjectParam(fakeObjectListOf_"
|
||||
"Object1, fakeObjectListOf_Object2) ?? \"\"");
|
||||
}
|
||||
SECTION("Mixed test (1)") {
|
||||
{
|
||||
auto node = parser.ParseExpression("number", "-+-MyExtension::MouseX(,)");
|
||||
|
||||
Reference in New Issue
Block a user