#ifdef TESTS_BUILD
#include <catch.hpp>
#include "../src/Script.hpp"

using namespace Porygon;

TEST_CASE( "Basic conditional", "[integration]" ) {
    Script* script = Script::Create("if true then foo = true end");
    REQUIRE(!script->Diagnostics -> HasErrors());
    auto variable = script->GetVariable(u"foo");
    REQUIRE(variable == nullptr);
    script->Evaluate();
    variable = script->GetVariable(u"foo");
    REQUIRE(variable != nullptr);
    REQUIRE(variable->EvaluateBool());
    delete script;
    delete variable;
}

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(u"foo");
    REQUIRE(variable == nullptr);
    script->Evaluate();
    variable = script->GetVariable(u"foo");
    REQUIRE(variable != nullptr);
    REQUIRE(variable->EvaluateBool());
    delete script;
    delete variable;
}

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(u"foo");
    REQUIRE(variable == nullptr);
    script->Evaluate();
    variable = script->GetVariable(u"foo");
    REQUIRE(variable != nullptr);
    REQUIRE(variable->EvaluateBool());
    delete script;
    delete variable;
}


#endif

