Implements return statement
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
2019-06-07 15:23:13 +02:00
parent f143e526ab
commit f4a3918947
12 changed files with 145 additions and 18 deletions

View File

@@ -57,5 +57,32 @@ TEST_CASE( "Define script function and call from extern", "[integration]" ) {
delete script;
}
TEST_CASE( "Define script function and return", "[integration]" ) {
Script* script = Script::Create(
"val = 0\n"
"function add(number a, number b) \n"
"return a + b \n"
"val = val + 1\n"
"end");
REQUIRE(!script->Diagnostics -> HasErrors());
script->Evaluate();
REQUIRE(script->HasFunction("add"));
auto toAddVal = new IntegerEvalValue(5);
auto toAddVal2 = new IntegerEvalValue(6);
auto result = script->CallFunction("add", {toAddVal, toAddVal2});
delete toAddVal;
delete toAddVal2;
REQUIRE(result->GetType()->GetClass() == TypeClass::Number);
REQUIRE(result->EvaluateInteger() == 11);
auto variable = script->GetVariable("val");
REQUIRE(variable->GetType()->GetClass() == TypeClass::Number);
REQUIRE(variable->EvaluateInteger() == 0);
delete script;
}
#endif