Removed LastValue variable, as it can be better emulated with basic return values
This commit is contained in:
parent
8b80b5789d
commit
268f6b59fb
|
@ -63,11 +63,10 @@ TEST_CASE( "Evaluate String", "[integration]" ) {
|
||||||
auto sc = new u16string(u"\"foo bar\"");
|
auto sc = new u16string(u"\"foo bar\"");
|
||||||
auto script = Porygon::Script::Create(*sc);
|
auto script = Porygon::Script::Create(*sc);
|
||||||
REQUIRE(!script->Diagnostics -> HasErrors());
|
REQUIRE(!script->Diagnostics -> HasErrors());
|
||||||
script->Evaluate();
|
auto result = script->Evaluate();
|
||||||
auto lastValue = script->GetLastValue();
|
size_t size = GetEvalValueStringLength(result.get());
|
||||||
size_t size = GetEvalValueStringLength(lastValue);
|
|
||||||
auto dst = new char16_t[size + 1]{'\0'};
|
auto dst = new char16_t[size + 1]{'\0'};
|
||||||
EvaluateEvalValueString(lastValue, dst, size);
|
EvaluateEvalValueString(result.get(), dst, size);
|
||||||
auto s = u16string(dst);
|
auto s = u16string(dst);
|
||||||
REQUIRE(s == u"foo bar");
|
REQUIRE(s == u"foo bar");
|
||||||
delete[] dst;
|
delete[] dst;
|
||||||
|
|
|
@ -10,16 +10,20 @@
|
||||||
#include "../TableScriptType.hpp"
|
#include "../TableScriptType.hpp"
|
||||||
#include "../UserData/UserDataFunction.hpp"
|
#include "../UserData/UserDataFunction.hpp"
|
||||||
#include "EvalValues/NumericalTableEvalValue.hpp"
|
#include "EvalValues/NumericalTableEvalValue.hpp"
|
||||||
#include "../Utilities/Random.hpp"
|
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
using namespace Porygon::Binder;
|
using namespace Porygon::Binder;
|
||||||
|
|
||||||
namespace Porygon::Evaluation {
|
namespace Porygon::Evaluation {
|
||||||
const EvalValue *Evaluator::Evaluate(const BoundScriptStatement *statement) {
|
shared_ptr<const EvalValue> Evaluator::Evaluate(const BoundScriptStatement *statement) {
|
||||||
this->_evaluationScope = make_shared<EvaluationScope>(this->_scriptVariables);
|
this->_evaluationScope = make_shared<EvaluationScope>(this->_scriptVariables);
|
||||||
|
auto statements = statement->GetStatements();
|
||||||
|
if (statements -> size() == 1 && statements->at(0)->GetKind() == BoundStatementKind::Expression){
|
||||||
|
auto expStatement = (BoundExpressionStatement*) statements -> at(0);
|
||||||
|
return this -> EvaluateExpression(expStatement -> GetExpression());
|
||||||
|
}
|
||||||
EvaluateBlockStatement(statement);
|
EvaluateBlockStatement(statement);
|
||||||
return this->_returnValue.get();
|
return this->_returnValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Evaluator::EvaluateStatement(const BoundStatement *statement) {
|
void Evaluator::EvaluateStatement(const BoundStatement *statement) {
|
||||||
|
@ -67,8 +71,7 @@ namespace Porygon::Evaluation {
|
||||||
}
|
}
|
||||||
|
|
||||||
void Evaluator::EvaluateExpressionStatement(const BoundExpressionStatement *statement) {
|
void Evaluator::EvaluateExpressionStatement(const BoundExpressionStatement *statement) {
|
||||||
// Save new value
|
this->EvaluateExpression(statement->GetExpression());
|
||||||
this->_lastValue = this->EvaluateExpression(statement->GetExpression());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Evaluator::EvaluateAssignmentStatement(const BoundAssignmentStatement *statement) {
|
void Evaluator::EvaluateAssignmentStatement(const BoundAssignmentStatement *statement) {
|
||||||
|
|
|
@ -19,7 +19,6 @@ namespace Porygon::Evaluation{
|
||||||
map<Utilities::HashedString, shared_ptr<const EvalValue>>* _scriptVariables;
|
map<Utilities::HashedString, shared_ptr<const EvalValue>>* _scriptVariables;
|
||||||
bool _hasReturned;
|
bool _hasReturned;
|
||||||
bool _hasBroken;
|
bool _hasBroken;
|
||||||
shared_ptr<const EvalValue> _lastValue;
|
|
||||||
|
|
||||||
//Porygon::Script* _scriptData;
|
//Porygon::Script* _scriptData;
|
||||||
shared_ptr<EvaluationScope> _evaluationScope;
|
shared_ptr<EvaluationScope> _evaluationScope;
|
||||||
|
@ -64,14 +63,10 @@ namespace Porygon::Evaluation{
|
||||||
_evaluationScope(nullptr){
|
_evaluationScope(nullptr){
|
||||||
}
|
}
|
||||||
|
|
||||||
const EvalValue* Evaluate(const BoundScriptStatement* statement);
|
shared_ptr<const EvalValue> Evaluate(const BoundScriptStatement* statement);
|
||||||
shared_ptr<const EvalValue> EvaluateFunction(const GenericFunctionEvalValue *function,
|
shared_ptr<const EvalValue> EvaluateFunction(const GenericFunctionEvalValue *function,
|
||||||
const vector<EvalValue *> ¶meters);
|
const vector<EvalValue *> ¶meters);
|
||||||
|
|
||||||
inline const EvalValue* GetLastValue(){
|
|
||||||
return _lastValue.get();
|
|
||||||
}
|
|
||||||
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -30,7 +30,7 @@ Porygon::Script::Script(const u16string& s)
|
||||||
this -> Parse(s);
|
this -> Parse(s);
|
||||||
}
|
}
|
||||||
|
|
||||||
const EvalValue* Porygon::Script::Evaluate() {
|
shared_ptr<const EvalValue> Porygon::Script::Evaluate() {
|
||||||
return _evaluator->Evaluate(_boundScript.get());
|
return _evaluator->Evaluate(_boundScript.get());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -71,9 +71,9 @@ bool Porygon::Script::HasVariable(const u16string &key) {
|
||||||
return f != _scriptVariables->end();
|
return f != _scriptVariables->end();
|
||||||
}
|
}
|
||||||
|
|
||||||
const EvalValue *Porygon::Script::GetLastValue() {
|
/*const EvalValue *Porygon::Script::GetLastValue() {
|
||||||
return _evaluator->GetLastValue();
|
return _evaluator->GetLastValue();
|
||||||
}
|
}*/
|
||||||
|
|
||||||
bool Porygon::Script::HasFunction(const u16string &key) {
|
bool Porygon::Script::HasFunction(const u16string &key) {
|
||||||
auto f = _scriptVariables->find(HashedString::CreateLookup(key));
|
auto f = _scriptVariables->find(HashedString::CreateLookup(key));
|
||||||
|
@ -109,12 +109,10 @@ extern "C" {
|
||||||
return Porygon::Script::Create(s);
|
return Porygon::Script::Create(s);
|
||||||
}
|
}
|
||||||
|
|
||||||
void EvaluateScript(Porygon::Script* script){
|
const EvalValue* EvaluateScript(Porygon::Script* script){
|
||||||
script->Evaluate();
|
auto result = script -> Evaluate();
|
||||||
}
|
auto resultPtr = result.get();
|
||||||
|
return resultPtr;
|
||||||
const EvalValue* GetLastValue(Porygon::Script* script){
|
|
||||||
return script->GetLastValue();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool HasVariable(Porygon::Script* script, const char16_t* key){
|
bool HasVariable(Porygon::Script* script, const char16_t* key){
|
||||||
|
|
|
@ -41,9 +41,9 @@ namespace Porygon{
|
||||||
_returnType = t;
|
_returnType = t;
|
||||||
}
|
}
|
||||||
|
|
||||||
const EvalValue* Evaluate();
|
shared_ptr<const EvalValue> Evaluate();
|
||||||
|
|
||||||
const EvalValue* GetLastValue();
|
//const EvalValue* GetLastValue();
|
||||||
|
|
||||||
const EvalValue* GetVariable(const u16string& key);
|
const EvalValue* GetVariable(const u16string& key);
|
||||||
bool HasVariable(const u16string& key);
|
bool HasVariable(const u16string& key);
|
||||||
|
|
|
@ -7,33 +7,29 @@ using namespace Porygon;
|
||||||
TEST_CASE( "True Equals True", "[integration]" ) {
|
TEST_CASE( "True Equals True", "[integration]" ) {
|
||||||
auto script = Script::Create("true == true");
|
auto script = Script::Create("true == true");
|
||||||
REQUIRE(!script->Diagnostics -> HasErrors());
|
REQUIRE(!script->Diagnostics -> HasErrors());
|
||||||
script->Evaluate();
|
auto result = script->Evaluate();
|
||||||
auto lastValue = script->GetLastValue();
|
REQUIRE(result->EvaluateBool());
|
||||||
REQUIRE(lastValue->EvaluateBool());
|
|
||||||
delete script;
|
delete script;
|
||||||
}
|
}
|
||||||
TEST_CASE( "True Not Equals True", "[integration]" ) {
|
TEST_CASE( "True Not Equals True", "[integration]" ) {
|
||||||
auto script = Script::Create("true == false");
|
auto script = Script::Create("true == false");
|
||||||
REQUIRE(!script->Diagnostics -> HasErrors());
|
REQUIRE(!script->Diagnostics -> HasErrors());
|
||||||
script->Evaluate();
|
auto result = script->Evaluate();
|
||||||
auto lastValue = script->GetLastValue();
|
REQUIRE(!result->EvaluateBool());
|
||||||
REQUIRE(!lastValue->EvaluateBool());
|
|
||||||
delete script;
|
delete script;
|
||||||
}
|
}
|
||||||
TEST_CASE( "True Nequals False", "[integration]" ) {
|
TEST_CASE( "True Nequals False", "[integration]" ) {
|
||||||
auto script = Script::Create("true ~= false");
|
auto script = Script::Create("true ~= false");
|
||||||
REQUIRE(!script->Diagnostics -> HasErrors());
|
REQUIRE(!script->Diagnostics -> HasErrors());
|
||||||
script->Evaluate();
|
auto result = script->Evaluate();
|
||||||
auto lastValue = script->GetLastValue();
|
REQUIRE(result->EvaluateBool());
|
||||||
REQUIRE(lastValue->EvaluateBool());
|
|
||||||
delete script;
|
delete script;
|
||||||
}
|
}
|
||||||
TEST_CASE( "True Not Nequals True", "[integration]" ) {
|
TEST_CASE( "True Not Nequals True", "[integration]" ) {
|
||||||
auto script = Script::Create("true ~= true");
|
auto script = Script::Create("true ~= true");
|
||||||
REQUIRE(!script->Diagnostics -> HasErrors());
|
REQUIRE(!script->Diagnostics -> HasErrors());
|
||||||
script->Evaluate();
|
auto result = script->Evaluate();
|
||||||
auto lastValue = script->GetLastValue();
|
REQUIRE(!result->EvaluateBool());
|
||||||
REQUIRE(!lastValue->EvaluateBool());
|
|
||||||
delete script;
|
delete script;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -41,134 +37,119 @@ TEST_CASE( "True Not Nequals True", "[integration]" ) {
|
||||||
TEST_CASE( "False Equals False", "[integration]" ) {
|
TEST_CASE( "False Equals False", "[integration]" ) {
|
||||||
auto script = Script::Create("false == false");
|
auto script = Script::Create("false == false");
|
||||||
REQUIRE(!script->Diagnostics -> HasErrors());
|
REQUIRE(!script->Diagnostics -> HasErrors());
|
||||||
script->Evaluate();
|
auto result = script->Evaluate();
|
||||||
auto lastValue = script->GetLastValue();
|
REQUIRE(result->EvaluateBool());
|
||||||
REQUIRE(lastValue->EvaluateBool());
|
|
||||||
delete script;
|
delete script;
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_CASE( "10 Equals 10", "[integration]" ) {
|
TEST_CASE( "10 Equals 10", "[integration]" ) {
|
||||||
auto script = Script::Create("10 == 10");
|
auto script = Script::Create("10 == 10");
|
||||||
REQUIRE(!script->Diagnostics -> HasErrors());
|
REQUIRE(!script->Diagnostics -> HasErrors());
|
||||||
script->Evaluate();
|
auto result = script->Evaluate();
|
||||||
auto lastValue = script->GetLastValue();
|
REQUIRE(result->EvaluateBool());
|
||||||
REQUIRE(lastValue->EvaluateBool());
|
|
||||||
delete script;
|
delete script;
|
||||||
}
|
}
|
||||||
TEST_CASE( "10 Not Equals 5", "[integration]" ) {
|
TEST_CASE( "10 Not Equals 5", "[integration]" ) {
|
||||||
auto script = Script::Create("10 == 5");
|
auto script = Script::Create("10 == 5");
|
||||||
REQUIRE(!script->Diagnostics -> HasErrors());
|
REQUIRE(!script->Diagnostics -> HasErrors());
|
||||||
script->Evaluate();
|
auto result = script->Evaluate();
|
||||||
auto lastValue = script->GetLastValue();
|
REQUIRE(!result->EvaluateBool());
|
||||||
REQUIRE(!lastValue->EvaluateBool());
|
|
||||||
delete script;
|
delete script;
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_CASE( "10 < 5 == false", "[integration]" ) {
|
TEST_CASE( "10 < 5 == false", "[integration]" ) {
|
||||||
auto script = Script::Create("10 < 5");
|
auto script = Script::Create("10 < 5");
|
||||||
REQUIRE(!script->Diagnostics -> HasErrors());
|
REQUIRE(!script->Diagnostics -> HasErrors());
|
||||||
script->Evaluate();
|
auto result = script->Evaluate();
|
||||||
auto lastValue = script->GetLastValue();
|
REQUIRE_FALSE(result->EvaluateBool());
|
||||||
REQUIRE_FALSE(lastValue->EvaluateBool());
|
|
||||||
delete script;
|
delete script;
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_CASE( "2 < 60 == true", "[integration]" ) {
|
TEST_CASE( "2 < 60 == true", "[integration]" ) {
|
||||||
auto script = Script::Create("2 < 60");
|
auto script = Script::Create("2 < 60");
|
||||||
REQUIRE(!script->Diagnostics -> HasErrors());
|
REQUIRE(!script->Diagnostics -> HasErrors());
|
||||||
script->Evaluate();
|
auto result = script->Evaluate();
|
||||||
auto lastValue = script->GetLastValue();
|
REQUIRE(result->EvaluateBool());
|
||||||
REQUIRE(lastValue->EvaluateBool());
|
|
||||||
delete script;
|
delete script;
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_CASE( "5 < 5 == false", "[integration]" ) {
|
TEST_CASE( "5 < 5 == false", "[integration]" ) {
|
||||||
auto script = Script::Create("5 < 5");
|
auto script = Script::Create("5 < 5");
|
||||||
REQUIRE(!script->Diagnostics -> HasErrors());
|
REQUIRE(!script->Diagnostics -> HasErrors());
|
||||||
script->Evaluate();
|
auto result = script->Evaluate();
|
||||||
auto lastValue = script->GetLastValue();
|
REQUIRE_FALSE(result->EvaluateBool());
|
||||||
REQUIRE_FALSE(lastValue->EvaluateBool());
|
|
||||||
delete script;
|
delete script;
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_CASE( "10 <= 5 == false", "[integration]" ) {
|
TEST_CASE( "10 <= 5 == false", "[integration]" ) {
|
||||||
auto script = Script::Create("10 <= 5");
|
auto script = Script::Create("10 <= 5");
|
||||||
REQUIRE(!script->Diagnostics -> HasErrors());
|
REQUIRE(!script->Diagnostics -> HasErrors());
|
||||||
script->Evaluate();
|
auto result = script->Evaluate();
|
||||||
auto lastValue = script->GetLastValue();
|
REQUIRE_FALSE(result->EvaluateBool());
|
||||||
REQUIRE_FALSE(lastValue->EvaluateBool());
|
|
||||||
delete script;
|
delete script;
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_CASE( "2 <= 60 == true", "[integration]" ) {
|
TEST_CASE( "2 <= 60 == true", "[integration]" ) {
|
||||||
auto script = Script::Create("2 <= 60");
|
auto script = Script::Create("2 <= 60");
|
||||||
REQUIRE(!script->Diagnostics -> HasErrors());
|
REQUIRE(!script->Diagnostics -> HasErrors());
|
||||||
script->Evaluate();
|
auto result = script->Evaluate();
|
||||||
auto lastValue = script->GetLastValue();
|
REQUIRE(result->EvaluateBool());
|
||||||
REQUIRE(lastValue->EvaluateBool());
|
|
||||||
delete script;
|
delete script;
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_CASE( "5 <= 5 == true", "[integration]" ) {
|
TEST_CASE( "5 <= 5 == true", "[integration]" ) {
|
||||||
auto script = Script::Create("5 <= 5");
|
auto script = Script::Create("5 <= 5");
|
||||||
REQUIRE(!script->Diagnostics -> HasErrors());
|
REQUIRE(!script->Diagnostics -> HasErrors());
|
||||||
script->Evaluate();
|
auto result = script->Evaluate();
|
||||||
auto lastValue = script->GetLastValue();
|
REQUIRE(result->EvaluateBool());
|
||||||
REQUIRE(lastValue->EvaluateBool());
|
|
||||||
delete script;
|
delete script;
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_CASE( "10 > 5 == true", "[integration]" ) {
|
TEST_CASE( "10 > 5 == true", "[integration]" ) {
|
||||||
auto script = Script::Create("10 > 5");
|
auto script = Script::Create("10 > 5");
|
||||||
REQUIRE(!script->Diagnostics -> HasErrors());
|
REQUIRE(!script->Diagnostics -> HasErrors());
|
||||||
script->Evaluate();
|
auto result = script->Evaluate();
|
||||||
auto lastValue = script->GetLastValue();
|
REQUIRE(result->EvaluateBool());
|
||||||
REQUIRE(lastValue->EvaluateBool());
|
|
||||||
delete script;
|
delete script;
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_CASE( "2 > 60 == false", "[integration]" ) {
|
TEST_CASE( "2 > 60 == false", "[integration]" ) {
|
||||||
auto script = Script::Create("2 > 60");
|
auto script = Script::Create("2 > 60");
|
||||||
REQUIRE(!script->Diagnostics -> HasErrors());
|
REQUIRE(!script->Diagnostics -> HasErrors());
|
||||||
script->Evaluate();
|
auto result = script->Evaluate();
|
||||||
auto lastValue = script->GetLastValue();
|
REQUIRE_FALSE(result->EvaluateBool());
|
||||||
REQUIRE_FALSE(lastValue->EvaluateBool());
|
|
||||||
delete script;
|
delete script;
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_CASE( "5 > 5 == false", "[integration]" ) {
|
TEST_CASE( "5 > 5 == false", "[integration]" ) {
|
||||||
auto script = Script::Create("5 > 5");
|
auto script = Script::Create("5 > 5");
|
||||||
REQUIRE(!script->Diagnostics -> HasErrors());
|
REQUIRE(!script->Diagnostics -> HasErrors());
|
||||||
script->Evaluate();
|
auto result = script->Evaluate();
|
||||||
auto lastValue = script->GetLastValue();
|
REQUIRE_FALSE(result->EvaluateBool());
|
||||||
REQUIRE_FALSE(lastValue->EvaluateBool());
|
|
||||||
delete script;
|
delete script;
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_CASE( "10 >= 5 == true", "[integration]" ) {
|
TEST_CASE( "10 >= 5 == true", "[integration]" ) {
|
||||||
auto script = Script::Create("10 >= 5");
|
auto script = Script::Create("10 >= 5");
|
||||||
REQUIRE(!script->Diagnostics -> HasErrors());
|
REQUIRE(!script->Diagnostics -> HasErrors());
|
||||||
script->Evaluate();
|
auto result = script->Evaluate();
|
||||||
auto lastValue = script->GetLastValue();
|
REQUIRE(result->EvaluateBool());
|
||||||
REQUIRE(lastValue->EvaluateBool());
|
|
||||||
delete script;
|
delete script;
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_CASE( "2 >= 60 == false", "[integration]" ) {
|
TEST_CASE( "2 >= 60 == false", "[integration]" ) {
|
||||||
auto script = Script::Create("2 >= 60");
|
auto script = Script::Create("2 >= 60");
|
||||||
REQUIRE(!script->Diagnostics -> HasErrors());
|
REQUIRE(!script->Diagnostics -> HasErrors());
|
||||||
script->Evaluate();
|
auto result = script->Evaluate();
|
||||||
auto lastValue = script->GetLastValue();
|
REQUIRE_FALSE(result->EvaluateBool());
|
||||||
REQUIRE_FALSE(lastValue->EvaluateBool());
|
|
||||||
delete script;
|
delete script;
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_CASE( "5 >= 5 == true", "[integration]" ) {
|
TEST_CASE( "5 >= 5 == true", "[integration]" ) {
|
||||||
auto script = Script::Create("5 >= 5");
|
auto script = Script::Create("5 >= 5");
|
||||||
REQUIRE(!script->Diagnostics -> HasErrors());
|
REQUIRE(!script->Diagnostics -> HasErrors());
|
||||||
script->Evaluate();
|
auto result = script->Evaluate();
|
||||||
auto lastValue = script->GetLastValue();
|
REQUIRE(result->EvaluateBool());
|
||||||
REQUIRE(lastValue->EvaluateBool());
|
|
||||||
delete script;
|
delete script;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -6,9 +6,8 @@ using namespace Porygon;
|
||||||
TEST_CASE( "String indexing", "[integration]" ) {
|
TEST_CASE( "String indexing", "[integration]" ) {
|
||||||
auto script = Script::Create("'foobar'[4]");
|
auto script = Script::Create("'foobar'[4]");
|
||||||
REQUIRE(!script->Diagnostics -> HasErrors());
|
REQUIRE(!script->Diagnostics -> HasErrors());
|
||||||
script->Evaluate();
|
auto result = script->Evaluate();
|
||||||
auto lastValue = script->GetLastValue();
|
REQUIRE(result->EvaluateString() == u"b");
|
||||||
REQUIRE(lastValue->EvaluateString() == u"b");
|
|
||||||
delete script;
|
delete script;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -6,102 +6,90 @@ using namespace Porygon;
|
||||||
TEST_CASE( "Basic True", "[integration]" ) {
|
TEST_CASE( "Basic True", "[integration]" ) {
|
||||||
auto script = Script::Create("true");
|
auto script = Script::Create("true");
|
||||||
REQUIRE(!script->Diagnostics -> HasErrors());
|
REQUIRE(!script->Diagnostics -> HasErrors());
|
||||||
script->Evaluate();
|
auto result = script->Evaluate();
|
||||||
auto lastValue = script->GetLastValue();
|
REQUIRE(result->EvaluateBool());
|
||||||
REQUIRE(lastValue->EvaluateBool());
|
|
||||||
delete script;
|
delete script;
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_CASE( "Basic False", "[integration]" ) {
|
TEST_CASE( "Basic False", "[integration]" ) {
|
||||||
auto script = Script::Create("false");
|
auto script = Script::Create("false");
|
||||||
REQUIRE(!script->Diagnostics -> HasErrors());
|
REQUIRE(!script->Diagnostics -> HasErrors());
|
||||||
script->Evaluate();
|
auto result = script->Evaluate();
|
||||||
auto lastValue = script->GetLastValue();
|
REQUIRE(!result->EvaluateBool());
|
||||||
REQUIRE(!lastValue->EvaluateBool());
|
|
||||||
delete script;
|
delete script;
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_CASE( "True and True", "[integration]" ) {
|
TEST_CASE( "True and True", "[integration]" ) {
|
||||||
auto script = Script::Create("true and true");
|
auto script = Script::Create("true and true");
|
||||||
REQUIRE(!script->Diagnostics -> HasErrors());
|
REQUIRE(!script->Diagnostics -> HasErrors());
|
||||||
script->Evaluate();
|
auto result = script->Evaluate();
|
||||||
auto lastValue = script->GetLastValue();
|
REQUIRE(result->EvaluateBool());
|
||||||
REQUIRE(lastValue->EvaluateBool());
|
|
||||||
delete script;
|
delete script;
|
||||||
}
|
}
|
||||||
TEST_CASE( "True and False", "[integration]" ) {
|
TEST_CASE( "True and False", "[integration]" ) {
|
||||||
auto script = Script::Create("true and false");
|
auto script = Script::Create("true and false");
|
||||||
REQUIRE(!script->Diagnostics -> HasErrors());
|
REQUIRE(!script->Diagnostics -> HasErrors());
|
||||||
script->Evaluate();
|
auto result = script->Evaluate();
|
||||||
auto lastValue = script->GetLastValue();
|
REQUIRE(!result->EvaluateBool());
|
||||||
REQUIRE(!lastValue->EvaluateBool());
|
|
||||||
delete script;
|
delete script;
|
||||||
}
|
}
|
||||||
TEST_CASE( "False and True", "[integration]" ) {
|
TEST_CASE( "False and True", "[integration]" ) {
|
||||||
auto script = Script::Create("false and true");
|
auto script = Script::Create("false and true");
|
||||||
REQUIRE(!script->Diagnostics -> HasErrors());
|
REQUIRE(!script->Diagnostics -> HasErrors());
|
||||||
script->Evaluate();
|
auto result = script->Evaluate();
|
||||||
auto lastValue = script->GetLastValue();
|
REQUIRE(!result->EvaluateBool());
|
||||||
REQUIRE(!lastValue->EvaluateBool());
|
|
||||||
delete script;
|
delete script;
|
||||||
}
|
}
|
||||||
TEST_CASE( "False and False", "[integration]" ) {
|
TEST_CASE( "False and False", "[integration]" ) {
|
||||||
auto script = Script::Create("false and false");
|
auto script = Script::Create("false and false");
|
||||||
REQUIRE(!script->Diagnostics -> HasErrors());
|
REQUIRE(!script->Diagnostics -> HasErrors());
|
||||||
script->Evaluate();
|
auto result = script->Evaluate();
|
||||||
auto lastValue = script->GetLastValue();
|
REQUIRE(!result->EvaluateBool());
|
||||||
REQUIRE(!lastValue->EvaluateBool());
|
|
||||||
delete script;
|
delete script;
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_CASE( "True or True", "[integration]" ) {
|
TEST_CASE( "True or True", "[integration]" ) {
|
||||||
auto script = Script::Create("true or true");
|
auto script = Script::Create("true or true");
|
||||||
REQUIRE(!script->Diagnostics -> HasErrors());
|
REQUIRE(!script->Diagnostics -> HasErrors());
|
||||||
script->Evaluate();
|
auto result = script->Evaluate();
|
||||||
auto lastValue = script->GetLastValue();
|
REQUIRE(result->EvaluateBool());
|
||||||
REQUIRE(lastValue->EvaluateBool());
|
|
||||||
delete script;
|
delete script;
|
||||||
}
|
}
|
||||||
TEST_CASE( "True or False", "[integration]" ) {
|
TEST_CASE( "True or False", "[integration]" ) {
|
||||||
auto script = Script::Create("true or false");
|
auto script = Script::Create("true or false");
|
||||||
REQUIRE(!script->Diagnostics -> HasErrors());
|
REQUIRE(!script->Diagnostics -> HasErrors());
|
||||||
script->Evaluate();
|
auto result = script->Evaluate();
|
||||||
auto lastValue = script->GetLastValue();
|
REQUIRE(result->EvaluateBool());
|
||||||
REQUIRE(lastValue->EvaluateBool());
|
|
||||||
delete script;
|
delete script;
|
||||||
}
|
}
|
||||||
TEST_CASE( "False or True", "[integration]" ) {
|
TEST_CASE( "False or True", "[integration]" ) {
|
||||||
auto script = Script::Create("false or true");
|
auto script = Script::Create("false or true");
|
||||||
REQUIRE(!script->Diagnostics -> HasErrors());
|
REQUIRE(!script->Diagnostics -> HasErrors());
|
||||||
script->Evaluate();
|
auto result = script->Evaluate();
|
||||||
auto lastValue = script->GetLastValue();
|
REQUIRE(result->EvaluateBool());
|
||||||
REQUIRE(lastValue->EvaluateBool());
|
|
||||||
delete script;
|
delete script;
|
||||||
}
|
}
|
||||||
TEST_CASE( "False or False", "[integration]" ) {
|
TEST_CASE( "False or False", "[integration]" ) {
|
||||||
auto script = Script::Create("false or false");
|
auto script = Script::Create("false or false");
|
||||||
REQUIRE(!script->Diagnostics -> HasErrors());
|
REQUIRE(!script->Diagnostics -> HasErrors());
|
||||||
script->Evaluate();
|
auto result = script->Evaluate();
|
||||||
auto lastValue = script->GetLastValue();
|
REQUIRE(!result->EvaluateBool());
|
||||||
REQUIRE(!lastValue->EvaluateBool());
|
|
||||||
delete script;
|
delete script;
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_CASE( "Not True", "[integration]" ) {
|
TEST_CASE( "Not True", "[integration]" ) {
|
||||||
auto script = Script::Create("not true");
|
auto script = Script::Create("not true");
|
||||||
REQUIRE(!script->Diagnostics -> HasErrors());
|
REQUIRE(!script->Diagnostics -> HasErrors());
|
||||||
script->Evaluate();
|
auto result = script->Evaluate();
|
||||||
auto lastValue = script->GetLastValue();
|
REQUIRE(!result->EvaluateBool());
|
||||||
REQUIRE(!lastValue->EvaluateBool());
|
|
||||||
delete script;
|
delete script;
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_CASE( "Not False", "[integration]" ) {
|
TEST_CASE( "Not False", "[integration]" ) {
|
||||||
auto script = Script::Create("not false");
|
auto script = Script::Create("not false");
|
||||||
REQUIRE(!script->Diagnostics -> HasErrors());
|
REQUIRE(!script->Diagnostics -> HasErrors());
|
||||||
script->Evaluate();
|
auto result = script->Evaluate();
|
||||||
auto lastValue = script->GetLastValue();
|
REQUIRE(result->EvaluateBool());
|
||||||
REQUIRE(lastValue->EvaluateBool());
|
|
||||||
delete script;
|
delete script;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -6,83 +6,73 @@ using namespace Porygon;
|
||||||
TEST_CASE( "Integer Negation", "[integration]" ) {
|
TEST_CASE( "Integer Negation", "[integration]" ) {
|
||||||
auto script = Script::Create("-60");
|
auto script = Script::Create("-60");
|
||||||
REQUIRE(!script->Diagnostics -> HasErrors());
|
REQUIRE(!script->Diagnostics -> HasErrors());
|
||||||
script->Evaluate();
|
auto result = script->Evaluate();
|
||||||
auto lastValue = script->GetLastValue();
|
REQUIRE(result->EvaluateInteger() == -60);
|
||||||
REQUIRE(lastValue->EvaluateInteger() == -60);
|
|
||||||
delete script;
|
delete script;
|
||||||
}
|
}
|
||||||
TEST_CASE( "Float Negation", "[integration]" ) {
|
TEST_CASE( "Float Negation", "[integration]" ) {
|
||||||
auto script = Script::Create("-5.65");
|
auto script = Script::Create("-5.65");
|
||||||
REQUIRE(!script->Diagnostics -> HasErrors());
|
REQUIRE(!script->Diagnostics -> HasErrors());
|
||||||
script->Evaluate();
|
auto result = script->Evaluate();
|
||||||
auto lastValue = script->GetLastValue();
|
REQUIRE(result->EvaluateFloat() == Approx(-5.65));
|
||||||
REQUIRE(lastValue->EvaluateFloat() == Approx(-5.65));
|
|
||||||
delete script;
|
delete script;
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_CASE( "Integer Addition", "[integration]" ) {
|
TEST_CASE( "Integer Addition", "[integration]" ) {
|
||||||
auto script = Script::Create("1 + 5");
|
auto script = Script::Create("1 + 5");
|
||||||
REQUIRE(!script->Diagnostics -> HasErrors());
|
REQUIRE(!script->Diagnostics -> HasErrors());
|
||||||
script->Evaluate();
|
auto result = script->Evaluate();
|
||||||
auto lastValue = script->GetLastValue();
|
REQUIRE(result->EvaluateInteger() == 6);
|
||||||
REQUIRE(lastValue->EvaluateInteger() == 6);
|
|
||||||
delete script;
|
delete script;
|
||||||
}
|
}
|
||||||
TEST_CASE( "Integer Subtraction", "[integration]" ) {
|
TEST_CASE( "Integer Subtraction", "[integration]" ) {
|
||||||
auto script = Script::Create("1 - 5");
|
auto script = Script::Create("1 - 5");
|
||||||
REQUIRE(!script->Diagnostics -> HasErrors());
|
REQUIRE(!script->Diagnostics -> HasErrors());
|
||||||
script->Evaluate();
|
auto result = script->Evaluate();
|
||||||
auto lastValue = script->GetLastValue();
|
REQUIRE(result->EvaluateInteger() == -4);
|
||||||
REQUIRE(lastValue->EvaluateInteger() == -4);
|
|
||||||
delete script;
|
delete script;
|
||||||
}
|
}
|
||||||
TEST_CASE( "Integer Multiplication", "[integration]" ) {
|
TEST_CASE( "Integer Multiplication", "[integration]" ) {
|
||||||
auto script = Script::Create("5 * 8");
|
auto script = Script::Create("5 * 8");
|
||||||
REQUIRE(!script->Diagnostics -> HasErrors());
|
REQUIRE(!script->Diagnostics -> HasErrors());
|
||||||
script->Evaluate();
|
auto result = script->Evaluate();
|
||||||
auto lastValue = script->GetLastValue();
|
REQUIRE(result->EvaluateInteger() == 40);
|
||||||
REQUIRE(lastValue->EvaluateInteger() == 40);
|
|
||||||
delete script;
|
delete script;
|
||||||
}
|
}
|
||||||
TEST_CASE( "Integer Division", "[integration]" ) {
|
TEST_CASE( "Integer Division", "[integration]" ) {
|
||||||
auto script = Script::Create("40 / 8");
|
auto script = Script::Create("40 / 8");
|
||||||
REQUIRE(!script->Diagnostics -> HasErrors());
|
REQUIRE(!script->Diagnostics -> HasErrors());
|
||||||
script->Evaluate();
|
auto result = script->Evaluate();
|
||||||
auto lastValue = script->GetLastValue();
|
REQUIRE(result->EvaluateInteger() == 5);
|
||||||
REQUIRE(lastValue->EvaluateInteger() == 5);
|
|
||||||
delete script;
|
delete script;
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_CASE( "Float Addition", "[integration]" ) {
|
TEST_CASE( "Float Addition", "[integration]" ) {
|
||||||
auto script = Script::Create("1.2 + 5.34");
|
auto script = Script::Create("1.2 + 5.34");
|
||||||
REQUIRE(!script->Diagnostics -> HasErrors());
|
REQUIRE(!script->Diagnostics -> HasErrors());
|
||||||
script->Evaluate();
|
auto result = script->Evaluate();
|
||||||
auto lastValue = script->GetLastValue();
|
REQUIRE(result->EvaluateFloat() == 6.54);
|
||||||
REQUIRE(lastValue->EvaluateFloat() == 6.54);
|
|
||||||
delete script;
|
delete script;
|
||||||
}
|
}
|
||||||
TEST_CASE( "Float Subtraction", "[integration]" ) {
|
TEST_CASE( "Float Subtraction", "[integration]" ) {
|
||||||
auto script = Script::Create("1.8 - 5.14");
|
auto script = Script::Create("1.8 - 5.14");
|
||||||
REQUIRE(!script->Diagnostics -> HasErrors());
|
REQUIRE(!script->Diagnostics -> HasErrors());
|
||||||
script->Evaluate();
|
auto result = script->Evaluate();
|
||||||
auto lastValue = script->GetLastValue();
|
REQUIRE(result->EvaluateFloat() == -3.34);
|
||||||
REQUIRE(lastValue->EvaluateFloat() == -3.34);
|
|
||||||
delete script;
|
delete script;
|
||||||
}
|
}
|
||||||
TEST_CASE( "Float Multiplication", "[integration]" ) {
|
TEST_CASE( "Float Multiplication", "[integration]" ) {
|
||||||
auto script = Script::Create("5.2 * 8.9");
|
auto script = Script::Create("5.2 * 8.9");
|
||||||
REQUIRE(!script->Diagnostics -> HasErrors());
|
REQUIRE(!script->Diagnostics -> HasErrors());
|
||||||
script->Evaluate();
|
auto result = script->Evaluate();
|
||||||
auto lastValue = script->GetLastValue();
|
REQUIRE(result->EvaluateFloat() == 46.28);
|
||||||
REQUIRE(lastValue->EvaluateFloat() == 46.28);
|
|
||||||
delete script;
|
delete script;
|
||||||
}
|
}
|
||||||
TEST_CASE( "Float Division", "[integration]" ) {
|
TEST_CASE( "Float Division", "[integration]" ) {
|
||||||
auto script = Script::Create("95.18 / 8.87");
|
auto script = Script::Create("95.18 / 8.87");
|
||||||
REQUIRE(!script->Diagnostics -> HasErrors());
|
REQUIRE(!script->Diagnostics -> HasErrors());
|
||||||
script->Evaluate();
|
auto result = script->Evaluate();
|
||||||
auto lastValue = script->GetLastValue();
|
REQUIRE(result->EvaluateFloat() == Approx(10.7305524239));
|
||||||
REQUIRE(lastValue->EvaluateFloat() == Approx(10.7305524239));
|
|
||||||
delete script;
|
delete script;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -8,27 +8,24 @@ using namespace Porygon;
|
||||||
TEST_CASE( "Simple String", "[integration]" ) {
|
TEST_CASE( "Simple String", "[integration]" ) {
|
||||||
auto script = Script::Create("\"foo bar\"");
|
auto script = Script::Create("\"foo bar\"");
|
||||||
REQUIRE(!script->Diagnostics -> HasErrors());
|
REQUIRE(!script->Diagnostics -> HasErrors());
|
||||||
script->Evaluate();
|
auto result = script->Evaluate();
|
||||||
auto lastValue = script->GetLastValue();
|
REQUIRE(result->EvaluateString() == u"foo bar");
|
||||||
REQUIRE(lastValue->EvaluateString() == u"foo bar");
|
|
||||||
delete script;
|
delete script;
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_CASE( "String Concat", "[integration]" ) {
|
TEST_CASE( "String Concat", "[integration]" ) {
|
||||||
auto script = Script::Create(R"("foo" + "bar")");
|
auto script = Script::Create(R"("foo" + "bar")");
|
||||||
REQUIRE(!script->Diagnostics -> HasErrors());
|
REQUIRE(!script->Diagnostics -> HasErrors());
|
||||||
script->Evaluate();
|
auto result = script->Evaluate();
|
||||||
auto lastValue = script->GetLastValue();
|
REQUIRE(result->EvaluateString() == u"foobar");
|
||||||
REQUIRE(lastValue->EvaluateString() == u"foobar");
|
|
||||||
delete script;
|
delete script;
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_CASE( "String Concat 2", "[integration]" ) {
|
TEST_CASE( "String Concat 2", "[integration]" ) {
|
||||||
auto script = Script::Create("'foo' + 'bar'");
|
auto script = Script::Create("'foo' + 'bar'");
|
||||||
REQUIRE(!script->Diagnostics -> HasErrors());
|
REQUIRE(!script->Diagnostics -> HasErrors());
|
||||||
script->Evaluate();
|
auto result = script->Evaluate();
|
||||||
auto lastValue = script->GetLastValue();
|
REQUIRE(result->EvaluateString() == u"foobar");
|
||||||
REQUIRE(lastValue->EvaluateString() == u"foobar");
|
|
||||||
delete script;
|
delete script;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue