Tests for debug strings for many expressions
continuous-integration/drone/push Build is passing
Details
continuous-integration/drone/push Build is passing
Details
This commit is contained in:
parent
f547715842
commit
7b5d03ed74
|
@ -34,9 +34,15 @@ namespace Porygon::Binder {
|
||||||
};
|
};
|
||||||
|
|
||||||
class BoundExpression {
|
class BoundExpression {
|
||||||
|
private:
|
||||||
const unsigned int _start;
|
const unsigned int _start;
|
||||||
const unsigned int _length;
|
const unsigned int _length;
|
||||||
const shared_ptr<const ScriptType> _type;
|
const shared_ptr<const ScriptType> _type;
|
||||||
|
protected:
|
||||||
|
inline void DrawIndents(std::stringstream& stream, size_t indents) const{
|
||||||
|
for (size_t i = 0; i < indents; i++)
|
||||||
|
stream << "\t";
|
||||||
|
}
|
||||||
public:
|
public:
|
||||||
BoundExpression(unsigned int start, unsigned int length, shared_ptr<const ScriptType> type)
|
BoundExpression(unsigned int start, unsigned int length, shared_ptr<const ScriptType> type)
|
||||||
: _start(start),
|
: _start(start),
|
||||||
|
@ -79,8 +85,7 @@ namespace Porygon::Binder {
|
||||||
}
|
}
|
||||||
|
|
||||||
void GetTreeString(std::stringstream& stream, size_t indents) const final{
|
void GetTreeString(std::stringstream& stream, size_t indents) const final{
|
||||||
for (size_t i = 0; i < indents; i++)
|
DrawIndents(stream, indents);
|
||||||
stream << "\t";
|
|
||||||
stream << "BadExpression";
|
stream << "BadExpression";
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -104,8 +109,7 @@ namespace Porygon::Binder {
|
||||||
}
|
}
|
||||||
|
|
||||||
void GetTreeString(std::stringstream& stream, size_t indents) const final{
|
void GetTreeString(std::stringstream& stream, size_t indents) const final{
|
||||||
for (size_t i = 0; i < indents; i++)
|
DrawIndents(stream, indents);
|
||||||
stream << "\t";
|
|
||||||
stream << "LiteralInteger: " << _value << " (" << GetType()->ToString() << ")";
|
stream << "LiteralInteger: " << _value << " (" << GetType()->ToString() << ")";
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -129,8 +133,7 @@ namespace Porygon::Binder {
|
||||||
}
|
}
|
||||||
|
|
||||||
void GetTreeString(std::stringstream& stream, size_t indents) const final{
|
void GetTreeString(std::stringstream& stream, size_t indents) const final{
|
||||||
for (size_t i = 0; i < indents; i++)
|
DrawIndents(stream, indents);
|
||||||
stream << "\t";
|
|
||||||
stream << "LiteralFloat: " << _value << " (" << GetType()->ToString() << ")";
|
stream << "LiteralFloat: " << _value << " (" << GetType()->ToString() << ")";
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -155,10 +158,9 @@ namespace Porygon::Binder {
|
||||||
}
|
}
|
||||||
|
|
||||||
void GetTreeString(std::stringstream& stream, size_t indents) const final{
|
void GetTreeString(std::stringstream& stream, size_t indents) const final{
|
||||||
for (size_t i = 0; i < indents; i++)
|
DrawIndents(stream, indents);
|
||||||
stream << "\t";
|
stream << "LiteralString: \"" << Utilities::StringUtils::FromUTF8(_value)
|
||||||
stream << "LiteralString: " << Utilities::StringUtils::FromUTF8(_value)
|
<< "\" (" << GetType()->ToString() << ")";
|
||||||
<< " (" << GetType()->ToString() << ")";
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -181,8 +183,7 @@ namespace Porygon::Binder {
|
||||||
}
|
}
|
||||||
|
|
||||||
void GetTreeString(std::stringstream& stream, size_t indents) const final{
|
void GetTreeString(std::stringstream& stream, size_t indents) const final{
|
||||||
for (size_t i = 0; i < indents; i++)
|
DrawIndents(stream, indents);
|
||||||
stream << "\t";
|
|
||||||
stream << "LiteralBool: " << _value << " (" << GetType()->ToString() << ")";
|
stream << "LiteralBool: " << _value << " (" << GetType()->ToString() << ")";
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -199,8 +200,7 @@ namespace Porygon::Binder {
|
||||||
}
|
}
|
||||||
|
|
||||||
void GetTreeString(std::stringstream& stream, size_t indents) const final{
|
void GetTreeString(std::stringstream& stream, size_t indents) const final{
|
||||||
for (size_t i = 0; i < indents; i++)
|
DrawIndents(stream, indents);
|
||||||
stream << "\t";
|
|
||||||
stream << "NilExpression" << " (" << GetType()->ToString() << ")";
|
stream << "NilExpression" << " (" << GetType()->ToString() << ")";
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -229,9 +229,8 @@ namespace Porygon::Binder {
|
||||||
}
|
}
|
||||||
|
|
||||||
void GetTreeString(std::stringstream& stream, size_t indents) const final{
|
void GetTreeString(std::stringstream& stream, size_t indents) const final{
|
||||||
for (size_t i = 0; i < indents; i++)
|
DrawIndents(stream, indents);
|
||||||
stream << "\t";
|
stream << "VariableExpression: " << _key->GetIdentifier()->GetDebugString()
|
||||||
stream << "VariableExpression: " << _key->GetIdentifier()->GetString().get()
|
|
||||||
<< " (" << GetType()->ToString() << ")";
|
<< " (" << GetType()->ToString() << ")";
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -296,11 +295,11 @@ namespace Porygon::Binder {
|
||||||
}
|
}
|
||||||
|
|
||||||
void GetTreeString(std::stringstream& stream, size_t indents) const final{
|
void GetTreeString(std::stringstream& stream, size_t indents) const final{
|
||||||
for (size_t i = 0; i < indents; i++)
|
DrawIndents(stream, indents);
|
||||||
stream << "\t";
|
|
||||||
stream << "BinaryExpression: " << GetOperationString(_operation)
|
stream << "BinaryExpression: " << GetOperationString(_operation)
|
||||||
<< " (" << GetType()->ToString() << ")" << endl;
|
<< " (" << GetType()->ToString() << ")" << endl;
|
||||||
_left->GetTreeString(stream, indents + 1);
|
_left->GetTreeString(stream, indents + 1);
|
||||||
|
stream << endl;
|
||||||
_right->GetTreeString(stream, indents + 1);
|
_right->GetTreeString(stream, indents + 1);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -344,8 +343,7 @@ namespace Porygon::Binder {
|
||||||
}
|
}
|
||||||
|
|
||||||
void GetTreeString(std::stringstream& stream, size_t indents) const final{
|
void GetTreeString(std::stringstream& stream, size_t indents) const final{
|
||||||
for (size_t i = 0; i < indents; i++)
|
DrawIndents(stream, indents);
|
||||||
stream << "\t";
|
|
||||||
stream << "UnaryExpression: " << GetOperationString(_operation)
|
stream << "UnaryExpression: " << GetOperationString(_operation)
|
||||||
<< " (" << GetType()->ToString() << ")" << endl;
|
<< " (" << GetType()->ToString() << ")" << endl;
|
||||||
_operand->GetTreeString(stream, indents + 1);
|
_operand->GetTreeString(stream, indents + 1);
|
||||||
|
@ -383,8 +381,7 @@ namespace Porygon::Binder {
|
||||||
}
|
}
|
||||||
|
|
||||||
void GetTreeString(std::stringstream& stream, size_t indents) const final{
|
void GetTreeString(std::stringstream& stream, size_t indents) const final{
|
||||||
for (size_t i = 0; i < indents; i++)
|
DrawIndents(stream, indents);
|
||||||
stream << "\t";
|
|
||||||
stream << "IndexExpression" << " (" << GetType()->ToString() << ")" << endl;
|
stream << "IndexExpression" << " (" << GetType()->ToString() << ")" << endl;
|
||||||
_indexableExpression->GetTreeString(stream, indents + 1);
|
_indexableExpression->GetTreeString(stream, indents + 1);
|
||||||
stream << endl;
|
stream << endl;
|
||||||
|
@ -423,10 +420,8 @@ namespace Porygon::Binder {
|
||||||
}
|
}
|
||||||
|
|
||||||
void GetTreeString(std::stringstream& stream, size_t indents) const final{
|
void GetTreeString(std::stringstream& stream, size_t indents) const final{
|
||||||
for (size_t i = 0; i < indents; i++)
|
DrawIndents(stream, indents);
|
||||||
stream << "\t";
|
stream << "PeriodIndex: " << _index.GetDebugString() << " (" << GetType()->ToString() << ")" << endl;
|
||||||
stream << "PeriodIndex: " << _index.GetString().get() << " (" << GetType()->ToString() << ")" << endl;
|
|
||||||
stream << endl;
|
|
||||||
_indexableExpression->GetTreeString(stream, indents + 1);
|
_indexableExpression->GetTreeString(stream, indents + 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -476,7 +471,7 @@ namespace Porygon::Binder {
|
||||||
_expression(expression)
|
_expression(expression)
|
||||||
{}
|
{}
|
||||||
|
|
||||||
const BoundExpression* GetExpression() const{
|
[[nodiscard]] const BoundExpression* GetExpression() const{
|
||||||
return _expression;
|
return _expression;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -162,6 +162,125 @@ TEST_CASE( "Function Declaration To String", "[BoundTreeString]" ) {
|
||||||
delete s;
|
delete s;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST_CASE( "Bad Expression To String", "[BoundTreeString]" ) {
|
||||||
|
std::stringstream stream;
|
||||||
|
auto s = new BoundBadExpression(0,0);
|
||||||
|
s->GetTreeString(stream, 1);
|
||||||
|
REQUIRE(stream.str() == "\tBadExpression");
|
||||||
|
delete s;
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_CASE( "Literal Integer Expression To String", "[BoundTreeString]" ) {
|
||||||
|
std::stringstream stream;
|
||||||
|
auto s = new BoundLiteralIntegerExpression(684,0,0);
|
||||||
|
s->GetTreeString(stream, 1);
|
||||||
|
REQUIRE(stream.str() == "\tLiteralInteger: 684 (number)");
|
||||||
|
delete s;
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_CASE( "Literal Float Expression To String", "[BoundTreeString]" ) {
|
||||||
|
std::stringstream stream;
|
||||||
|
auto s = new BoundLiteralFloatExpression(5.5,0,0);
|
||||||
|
s->GetTreeString(stream, 1);
|
||||||
|
REQUIRE(stream.str() == "\tLiteralFloat: 5.5 (number)");
|
||||||
|
delete s;
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_CASE( "Literal String Expression To String", "[BoundTreeString]" ) {
|
||||||
|
std::stringstream stream;
|
||||||
|
auto s = new BoundLiteralStringExpression(u"foobar",0,0);
|
||||||
|
s->GetTreeString(stream, 1);
|
||||||
|
REQUIRE(stream.str() == "\tLiteralString: \"foobar\" (string)");
|
||||||
|
delete s;
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_CASE( "Literal Bool Expression To String", "[BoundTreeString]" ) {
|
||||||
|
std::stringstream stream;
|
||||||
|
auto s = new BoundLiteralBoolExpression(true, 0,0);
|
||||||
|
s->GetTreeString(stream, 1);
|
||||||
|
REQUIRE(stream.str() == "\tLiteralBool: 1 (bool)");
|
||||||
|
delete s;
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_CASE( "Nil Expression To String", "[BoundTreeString]" ) {
|
||||||
|
std::stringstream stream;
|
||||||
|
auto s = new BoundNilExpression(0,0);
|
||||||
|
s->GetTreeString(stream, 1);
|
||||||
|
REQUIRE(stream.str() == "\tNilExpression (nil)");
|
||||||
|
delete s;
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_CASE( "Variable Expression To String", "[BoundTreeString]" ) {
|
||||||
|
std::stringstream stream;
|
||||||
|
auto type = ScriptType::BoolType;
|
||||||
|
auto key = new BoundVariableKey(HashedString(new u16string(u"var")), 0, false);
|
||||||
|
auto s = new BoundVariableExpression(key, type,0,0);
|
||||||
|
s->GetTreeString(stream, 1);
|
||||||
|
REQUIRE(stream.str() == "\tVariableExpression: var (bool)");
|
||||||
|
delete s;
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_CASE( "Binary Expression To String", "[BoundTreeString]" ) {
|
||||||
|
std::stringstream stream;
|
||||||
|
auto s = new BoundBinaryExpression(
|
||||||
|
new BoundLiteralIntegerExpression(5,0,0),
|
||||||
|
new BoundLiteralIntegerExpression(200,0,0),
|
||||||
|
BoundBinaryOperation ::Addition,
|
||||||
|
NumericScriptType::AwareInt, 0,0
|
||||||
|
);
|
||||||
|
s->GetTreeString(stream, 1);
|
||||||
|
REQUIRE(stream.str() == "\tBinaryExpression: addition (number)\n\t\tLiteralInteger: 5 (number)\n\t\tLiteralInteger: 200 (number)");
|
||||||
|
delete s;
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_CASE( "Unary Expression To String", "[BoundTreeString]" ) {
|
||||||
|
std::stringstream stream;
|
||||||
|
auto s = new BoundUnaryExpression(
|
||||||
|
new BoundLiteralIntegerExpression(5,0,0),
|
||||||
|
BoundUnaryOperation ::Negation,
|
||||||
|
NumericScriptType::AwareInt, 0,0
|
||||||
|
);
|
||||||
|
s->GetTreeString(stream, 1);
|
||||||
|
REQUIRE(stream.str() == "\tUnaryExpression: negation (number)\n\t\tLiteralInteger: 5 (number)");
|
||||||
|
delete s;
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_CASE( "Index Expression To String", "[BoundTreeString]" ) {
|
||||||
|
std::stringstream stream;
|
||||||
|
auto s = new BoundIndexExpression(
|
||||||
|
new BoundBadExpression(0,0),
|
||||||
|
new BoundBadExpression(0,0),
|
||||||
|
ScriptType::NilType,
|
||||||
|
0,0
|
||||||
|
);
|
||||||
|
s->GetTreeString(stream, 1);
|
||||||
|
REQUIRE(stream.str() == "\tIndexExpression (nil)\n\t\tBadExpression\n\t\tBadExpression");
|
||||||
|
delete s;
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_CASE( "Period Index Expression To String", "[BoundTreeString]" ) {
|
||||||
|
std::stringstream stream;
|
||||||
|
auto s = new BoundPeriodIndexExpression(
|
||||||
|
new BoundBadExpression(0,0),
|
||||||
|
HashedString(new u16string(u"key")),
|
||||||
|
ScriptType::NilType,
|
||||||
|
0,0
|
||||||
|
);
|
||||||
|
s->GetTreeString(stream, 1);
|
||||||
|
REQUIRE(stream.str() == "\tPeriodIndex: key (nil)\n\t\tBadExpression");
|
||||||
|
delete s;
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_CASE( "Cast Expression To String", "[BoundTreeString]" ) {
|
||||||
|
std::stringstream stream;
|
||||||
|
auto s = new BoundCastExpression(
|
||||||
|
new BoundBadExpression(0,0),
|
||||||
|
ScriptType::BoolType
|
||||||
|
);
|
||||||
|
s->GetTreeString(stream, 1);
|
||||||
|
REQUIRE(stream.str() == "\tCastExpression (bool)\n\t\tBadExpression");
|
||||||
|
delete s;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue