2019-06-01 10:33:52 +00:00
|
|
|
#ifdef TESTS_BUILD
|
|
|
|
#include <catch.hpp>
|
|
|
|
#include "../src/Script.hpp"
|
|
|
|
|
|
|
|
TEST_CASE( "Define script function", "[integration]" ) {
|
|
|
|
Script* script = Script::Create("function add(number a, number b) a + b end");
|
|
|
|
REQUIRE(!script->Diagnostics -> HasErrors());
|
|
|
|
script->Evaluate();
|
|
|
|
auto variable = script->GetVariable("add");
|
|
|
|
REQUIRE(variable != nullptr);
|
|
|
|
REQUIRE(variable->GetType()->GetClass() == TypeClass::Function);
|
|
|
|
delete script;
|
|
|
|
}
|
|
|
|
|
2019-06-01 17:20:31 +00:00
|
|
|
TEST_CASE( "Define script function and call", "[integration]" ) {
|
|
|
|
Script* script = Script::Create("function add(number a, number b) result = a + b end add(1, 2)");
|
|
|
|
REQUIRE(!script->Diagnostics -> HasErrors());
|
|
|
|
script->Evaluate();
|
|
|
|
auto variable = script->GetVariable("add");
|
|
|
|
REQUIRE(variable != nullptr);
|
|
|
|
REQUIRE(variable->GetType()->GetClass() == TypeClass::Function);
|
|
|
|
auto result = script->GetVariable("result");
|
|
|
|
REQUIRE(result->GetType()->GetClass() == TypeClass::Number);
|
|
|
|
REQUIRE(result->EvaluateInteger() == 3);
|
|
|
|
delete script;
|
|
|
|
}
|
|
|
|
|
2019-06-01 10:33:52 +00:00
|
|
|
#endif
|