Cleans up basic library handling, implements print function
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:
@@ -1,6 +1,7 @@
|
||||
#ifdef TESTS_BUILD
|
||||
#include <catch.hpp>
|
||||
#include "../src/Script.hpp"
|
||||
#include "../../src/GlobalScriptOptions.hpp"
|
||||
#include <cstring>
|
||||
|
||||
using namespace Porygon;
|
||||
@@ -38,6 +39,30 @@ TEST_CASE( "Assert func does not throw if argument is true", "[integration]" ) {
|
||||
delete script;
|
||||
}
|
||||
|
||||
TEST_CASE( "Assert func works with second argument", "[integration]" ) {
|
||||
Script* script = Script::Create(u"assert(false, 'foobar')");
|
||||
REQUIRE(!script->Diagnostics -> HasErrors());
|
||||
try{
|
||||
script -> Evaluate();
|
||||
throw;
|
||||
} catch (const EvaluationException& e){
|
||||
auto err = e.what();
|
||||
REQUIRE(std::strcmp(err, "An evaluation exception occurred: foobar") == 0);
|
||||
}
|
||||
delete script;
|
||||
}
|
||||
|
||||
TEST_CASE( "Print func works", "[integration]" ) {
|
||||
Script* script = Script::Create(u"print('foobar')");
|
||||
REQUIRE(!script->Diagnostics -> HasErrors());
|
||||
auto stream = new std::stringstream();
|
||||
GlobalScriptOptions::SetPrintStream(stream);
|
||||
script->Evaluate();
|
||||
auto printVal = stream->str();
|
||||
REQUIRE(printVal == "foobar\n");
|
||||
delete script;
|
||||
}
|
||||
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user