PorygonLang/tests/integration/ConditionalTests.cpp

44 lines
1.3 KiB
C++

#ifdef TESTS_BUILD
#include <catch.hpp>
#include "../src/Script.hpp"
TEST_CASE( "Basic conditional", "[integration]" ) {
Script* script = Script::Create("if true then foo = true end");
REQUIRE(!script->Diagnostics -> HasErrors());
auto variable = script->GetVariable("foo");
REQUIRE(variable == nullptr);
script->Evaluate();
variable = script->GetVariable("foo");
REQUIRE(variable != nullptr);
REQUIRE(variable->EvaluateBool());
delete script;
}
TEST_CASE( "If then, else", "[integration]" ) {
Script* script = Script::Create("if false then foo = false else foo = true end");
REQUIRE(!script->Diagnostics -> HasErrors());
auto variable = script->GetVariable("foo");
REQUIRE(variable == nullptr);
script->Evaluate();
variable = script->GetVariable("foo");
REQUIRE(variable != nullptr);
REQUIRE(variable->EvaluateBool());
delete script;
}
TEST_CASE( "If then, else if", "[integration]" ) {
Script* script = Script::Create("if false then foo = false elseif true then foo = true end");
REQUIRE(!script->Diagnostics -> HasErrors());
auto variable = script->GetVariable("foo");
REQUIRE(variable == nullptr);
script->Evaluate();
variable = script->GetVariable("foo");
REQUIRE(variable != nullptr);
REQUIRE(variable->EvaluateBool());
delete script;
}
#endif