Skip to content

Commit

Permalink
Add test to avoid breaking code generation in the future
Browse files Browse the repository at this point in the history
  • Loading branch information
4ian committed Nov 27, 2023
1 parent 90fd3a0 commit eea3d4a
Showing 1 changed file with 43 additions and 0 deletions.
43 changes: 43 additions & 0 deletions Core/tests/ExpressionCodeGenerator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1252,6 +1252,49 @@ TEST_CASE("ExpressionCodeGenerator", "[common][events]") {
"MySpriteObject.getObjectStringWith2ObjectParam(fakeObjectListOf_"
"Object1, fakeObjectListOf_Object2) ?? \"\"");
}
SECTION("Edge cases (variables with object name in objectvar parameter)") {
SECTION("Simple case") {
gd::String output = gd::ExpressionCodeGenerator::GenerateExpressionCode(
codeGenerator,
context,
"objectvar", // We suppose we generate an "objectvar" parameter.
"MyOtherSpriteObject", // This "variable name" is the same as an object name (but this is valid).
"MySpriteObject" // The object owning the variable: MySpriteObject.
);

// This seems "obvious", but we had cases where MyOtherSpriteObject could have been interpreted as an object
// when the code generation is not properly recognizing "objectvar".
REQUIRE(output == "getVariableForObject(MySpriteObject, MyOtherSpriteObject)");
}

SECTION("With child variable") {
gd::String output = gd::ExpressionCodeGenerator::GenerateExpressionCode(
codeGenerator,
context,
"objectvar", // We suppose we generate an "objectvar" parameter.
"MyOtherSpriteObject.Child", // This "variable name" is the same as an object name (but this is valid).
"MySpriteObject" // The object owning the variable: MySpriteObject.
);

// This seems "obvious", but we had cases where MyOtherSpriteObject could have been interpreted as an object
// when the code generation is not properly recognizing "objectvar".
REQUIRE(output == "getVariableForObject(MySpriteObject, MyOtherSpriteObject).getChild(\"Child\")");
}

SECTION("With child and grandchild variable") {
gd::String output = gd::ExpressionCodeGenerator::GenerateExpressionCode(
codeGenerator,
context,
"objectvar", // We suppose we generate an "objectvar" parameter.
"MyOtherSpriteObject.Child.Grandchild", // This "variable name" is the same as an object name (but this is valid).
"MySpriteObject" // The object owning the variable: MySpriteObject.
);

// This seems "obvious", but we had cases where MyOtherSpriteObject could have been interpreted as an object
// when the code generation is not properly recognizing "objectvar".
REQUIRE(output == "getVariableForObject(MySpriteObject, MyOtherSpriteObject).getChild(\"Child\").getChild(\"Grandchild\")");
}
}
SECTION("Mixed test (1)") {
{
auto node = parser.ParseExpression("-+-MyExtension::MouseX(,)");
Expand Down

0 comments on commit eea3d4a

Please sign in to comment.