PorygonLang/tests/integration/LoopTests.cpp

65 lines
1.5 KiB
C++
Raw Normal View History

2019-06-22 15:35:33 +00:00
#ifdef TESTS_BUILD
#include <catch.hpp>
#include "../src/Script.hpp"
using namespace Porygon;
TEST_CASE( "Numerical for loop without step", "[integration]" ) {
auto script = Script::Create(uR"(
result = 0
for i = 0,10 do
result = result + 3
end
)");
REQUIRE(!script->Diagnostics -> HasErrors());
script->Evaluate();
auto var = script->GetVariable(u"result");
REQUIRE(var->EvaluateInteger() == 33);
delete script;
}
TEST_CASE( "Numerical for loop with step", "[integration]" ) {
auto script = Script::Create(uR"(
result = 0
for i = 0,10,3 do
result = result + 3
end
)");
REQUIRE(!script->Diagnostics -> HasErrors());
script->Evaluate();
auto var = script->GetVariable(u"result");
REQUIRE(var->EvaluateInteger() == 12);
delete script;
}
TEST_CASE( "Numerical for loop with negative step", "[integration]" ) {
auto script = Script::Create(uR"(
result = 0
for i = 10,0,-1 do
result = result + 3
end
)");
REQUIRE(!script->Diagnostics -> HasErrors());
script->Evaluate();
auto var = script->GetVariable(u"result");
REQUIRE(var->EvaluateInteger() == 33);
delete script;
}
TEST_CASE( "Numerical for loop creates variable", "[integration]" ) {
auto script = Script::Create(uR"(
result = 0
for i = 0,5 do
result = result + i
end
)");
REQUIRE(!script->Diagnostics -> HasErrors());
script->Evaluate();
auto var = script->GetVariable(u"result");
REQUIRE(var->EvaluateInteger() == 15);
delete script;
}
#endif