Add gd::ExpressionCodeGenerator::GenerateExpressionCode

This commit is contained in:
Florian Rival
2018-12-09 20:45:33 +00:00
parent b14238c692
commit a9e1120f00
4 changed files with 76 additions and 18 deletions
+27 -8
View File
@@ -166,29 +166,33 @@ TEST_CASE("ExpressionCodeGenerator", "[common][events]") {
context);
node->Visit(expressionCodeGenerator);
REQUIRE(expressionCodeGenerator.GetOutput() == "getMouseX(\"\", \"layer1\", 0)");
REQUIRE(expressionCodeGenerator.GetOutput() ==
"getMouseX(\"\", \"layer1\", 0)");
// (first argument is the currentScene)
}
{
auto node =
parser.ParseExpression("number", "MyExtension::MouseX(\"layer1\",2+2)");
auto node = parser.ParseExpression("number",
"MyExtension::MouseX(\"layer1\",2+2)");
gd::ExpressionCodeGenerator expressionCodeGenerator(codeGenerator,
context);
node->Visit(expressionCodeGenerator);
REQUIRE(expressionCodeGenerator.GetOutput() == "getMouseX(\"\", \"layer1\", 2 + 2)");
REQUIRE(expressionCodeGenerator.GetOutput() ==
"getMouseX(\"\", \"layer1\", 2 + 2)");
// (first argument is the currentScene)
}
}
SECTION("Valid function calls (deprecated way of specifying optional arguments)") {
SECTION(
"Valid function calls (deprecated way of specifying optional "
"arguments)") {
{
auto node =
parser.ParseExpression("number", "MyExtension::MouseX(,)");
auto node = parser.ParseExpression("number", "MyExtension::MouseX(,)");
gd::ExpressionCodeGenerator expressionCodeGenerator(codeGenerator,
context);
node->Visit(expressionCodeGenerator);
REQUIRE(expressionCodeGenerator.GetOutput() == "getMouseX(\"\", \"\", 0)");
REQUIRE(expressionCodeGenerator.GetOutput() ==
"getMouseX(\"\", \"\", 0)");
// (first argument is the currentScene)
}
}
@@ -297,4 +301,19 @@ TEST_CASE("ExpressionCodeGenerator", "[common][events]") {
}
}
}
SECTION("Helper for code generation") {
gd::String output = gd::ExpressionCodeGenerator::GenerateExpressionCode(
codeGenerator,
context,
"number",
"MyExtension::GetVariableAsNumber(myVariable[ \"hello\" + "
"MySpriteObject.GetObjectStringWith1Param(MyOtherSpriteObject."
"GetObjectVariableAsNumber(mySecondVariable)) ].child2)");
REQUIRE(output ==
"returnVariable(getLayoutVariable(myVariable).getChild(\"hello\" + "
"MySpriteObject.getObjectStringWith1Param(MyOtherSpriteObject."
"returnVariable"
"(getVariableForObject(MyOtherSpriteObject, mySecondVariable)) ?? "
"0) ?? \"\").getChild(\"child2\"))");
}
}