Implements if, elseif and else statements
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
43
tests/integration/ConditionalTests.cpp
Normal file
43
tests/integration/ConditionalTests.cpp
Normal file
@@ -0,0 +1,43 @@
|
||||
#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
|
||||
|
||||
Reference in New Issue
Block a user