PorygonLang/tests/standardLibraries/BasicLibrary.cpp

45 lines
1.2 KiB
C++

#ifdef TESTS_BUILD
#include <catch.hpp>
#include "../src/Script.hpp"
#include <cstring>
using namespace Porygon;
TEST_CASE( "Error func throws error", "[integration]" ) {
Script* script = Script::Create(u"error('foo bar')");
REQUIRE(!script->Diagnostics -> HasErrors());
try{
script -> Evaluate();
throw;
} catch (const EvaluationException& e){
auto err = e.what();
REQUIRE(std::strcmp(err, "An evaluation exception occurred: foo bar") == 0);
}
delete script;
}
TEST_CASE( "Assert func throws error if argument is false", "[integration]" ) {
Script* script = Script::Create(u"assert(false)");
REQUIRE(!script->Diagnostics -> HasErrors());
try{
script -> Evaluate();
throw;
} catch (const EvaluationException& e){
auto err = e.what();
REQUIRE(std::strcmp(err, "An evaluation exception occurred: assertion failed!") == 0);
}
delete script;
}
TEST_CASE( "Assert func does not throw if argument is true", "[integration]" ) {
Script* script = Script::Create(u"assert(true)");
REQUIRE(!script->Diagnostics -> HasErrors());
script -> Evaluate();
delete script;
}
#endif