PorygonLang/tests/integration/Tables.cpp

49 lines
1.4 KiB
C++
Raw Normal View History

2019-06-09 18:15:09 +00:00
#ifdef TESTS_BUILD
#include <catch.hpp>
#include "../src/Script.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;
}
#endif