Implements return statement
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user