84 lines
2.3 KiB
C++
84 lines
2.3 KiB
C++
#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 = {}");
|
|
REQUIRE(!script->Diagnostics -> HasErrors());
|
|
script->Evaluate();
|
|
auto variable = script->GetVariable("table");
|
|
REQUIRE(variable != nullptr);
|
|
delete script;
|
|
}
|
|
|
|
TEST_CASE( "Create simple integer table", "[integration]" ) {
|
|
Script* script = Script::Create("table = {100, 50, 20, 5, -100, 50+50}");
|
|
REQUIRE(!script->Diagnostics -> HasErrors());
|
|
script->Evaluate();
|
|
auto variable = script->GetVariable("table");
|
|
REQUIRE(variable != nullptr);
|
|
delete script;
|
|
}
|
|
|
|
TEST_CASE( "Create simple string table", "[integration]" ) {
|
|
Script* script = Script::Create("table = {'bla', 'test', 'foo', 'bar'}");
|
|
REQUIRE(!script->Diagnostics -> HasErrors());
|
|
script->Evaluate();
|
|
auto variable = script->GetVariable("table");
|
|
REQUIRE(variable != nullptr);
|
|
delete script;
|
|
}
|
|
|
|
TEST_CASE( "Index string table", "[integration]" ) {
|
|
Script* script = Script::Create(
|
|
R"(
|
|
table = {'bla', 'test', 'foo', 'bar'}
|
|
return table[3]
|
|
)");
|
|
REQUIRE(!script->Diagnostics -> HasErrors());
|
|
auto variable = script->Evaluate();
|
|
REQUIRE(variable != nullptr);
|
|
REQUIRE(*variable->EvaluateString() == "foo");
|
|
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;
|
|
}
|
|
|
|
TEST_CASE( "Complex table with function", "[integration]" ) {
|
|
Script* script = Script::Create(
|
|
R"(
|
|
table = {
|
|
local foo = 'test'
|
|
function getFoo()
|
|
return foo
|
|
end
|
|
}
|
|
return table["getFoo"]()
|
|
)");
|
|
REQUIRE(!script->Diagnostics -> HasErrors());
|
|
auto variable = script->Evaluate();
|
|
REQUIRE(variable != nullptr);
|
|
delete script;
|
|
}
|
|
|
|
|
|
#endif
|
|
|