2019-06-08 12:25:15 +00:00
|
|
|
#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());
|
2019-06-15 15:20:27 +00:00
|
|
|
auto variable = script->GetVariable(u"foo");
|
2019-06-08 12:25:15 +00:00
|
|
|
REQUIRE(variable == nullptr);
|
|
|
|
script->Evaluate();
|
2019-06-15 15:20:27 +00:00
|
|
|
variable = script->GetVariable(u"foo");
|
2019-06-08 12:25:15 +00:00
|
|
|
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());
|
2019-06-15 15:20:27 +00:00
|
|
|
auto variable = script->GetVariable(u"foo");
|
2019-06-08 12:25:15 +00:00
|
|
|
REQUIRE(variable == nullptr);
|
|
|
|
script->Evaluate();
|
2019-06-15 15:20:27 +00:00
|
|
|
variable = script->GetVariable(u"foo");
|
2019-06-08 12:25:15 +00:00
|
|
|
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());
|
2019-06-15 15:20:27 +00:00
|
|
|
auto variable = script->GetVariable(u"foo");
|
2019-06-08 12:25:15 +00:00
|
|
|
REQUIRE(variable == nullptr);
|
|
|
|
script->Evaluate();
|
2019-06-15 15:20:27 +00:00
|
|
|
variable = script->GetVariable(u"foo");
|
2019-06-08 12:25:15 +00:00
|
|
|
REQUIRE(variable != nullptr);
|
|
|
|
REQUIRE(variable->EvaluateBool());
|
|
|
|
delete script;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|