68 lines
1.9 KiB
C++
68 lines
1.9 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'}
|
|
result = table[3]
|
|
)");
|
|
REQUIRE(!script->Diagnostics -> HasErrors());
|
|
script->Evaluate();
|
|
auto variable = script->GetVariable("result");
|
|
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;
|
|
}
|
|
|
|
|
|
#endif
|
|
|