Implements complex tables
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
2019-06-12 15:19:28 +02:00
parent ba4fe888fa
commit c022c91777
21 changed files with 272 additions and 50 deletions

View File

@@ -1,6 +1,7 @@
#ifdef TESTS_BUILD
#include <catch.hpp>
#include "../src/Script.hpp"
#include "../../src/Evaluator/EvalValues/TableEvalValue.hpp"
TEST_CASE( "Create empty table", "[integration]" ) {
Script* script = Script::Create("table = {}");
@@ -43,6 +44,24 @@ result = table[3]
delete script;
}
TEST_CASE( "Create complex table", "[integration]" ) {
Script* script = Script::Create(
R"(
table = {
foo = 'test'
bar = 100
}
)");
REQUIRE(!script->Diagnostics -> HasErrors());
script->Evaluate();
auto variable = script->GetVariable("table");
REQUIRE(variable != nullptr);
auto table = (TableEvalValue*)variable;
CHECK(*table->IndexValue("foo")->EvaluateString() == "test");
CHECK(table->IndexValue("bar")->EvaluateInteger() == 100);
delete script;
}
#endif

View File

@@ -44,5 +44,22 @@ TEST_CASE( "Create local variable and use", "[integration]" ) {
delete script;
}
TEST_CASE( "Local variables in upmost scope persist", "[integration]" ) {
Script* script = Script::Create(R"(
result = 0
local foo = 0
function bar()
foo = foo + 1
result = foo
end
)");
REQUIRE(!script->Diagnostics -> HasErrors());
script->Evaluate();
script -> CallFunction("bar", {});
script -> CallFunction("bar", {});
auto variable = script->GetVariable("result");
REQUIRE(variable != nullptr);
CHECK(variable->EvaluateInteger() == 2);
delete script;
}
#endif