Tests for debug strings for many expressions
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
2019-09-05 17:55:00 +02:00
parent f547715842
commit 7b5d03ed74
2 changed files with 142 additions and 28 deletions

View File

@@ -162,6 +162,125 @@ TEST_CASE( "Function Declaration To String", "[BoundTreeString]" ) {
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;
}