Fixes and tests for function declaration to string
This commit is contained in:
parent
256969e912
commit
f547715842
|
@ -42,13 +42,14 @@ namespace Porygon::Binder {
|
||||||
}
|
}
|
||||||
|
|
||||||
void GetTreeString(std::stringstream& stream, size_t indents) const override{
|
void GetTreeString(std::stringstream& stream, size_t indents) const override{
|
||||||
for (size_t i = 0; i < indents; i++)
|
DrawIndents(stream, indents);
|
||||||
stream << "\t";
|
|
||||||
stream << "FunctionDeclaration" << endl;
|
stream << "FunctionDeclaration" << endl;
|
||||||
for (size_t i = 0; i < indents; i++)
|
DrawIndents(stream, indents);
|
||||||
stream << "\t";
|
stream << "Key: " << _key->GetIdentifier()->GetDebugString() << endl;
|
||||||
stream << "Key: " << _key->GetIdentifier()->GetString().get() << endl;
|
DrawIndents(stream, indents);
|
||||||
stream << "Type: " << _type->ToString() << endl;
|
stream << "Type: " << _type->ToString() << endl;
|
||||||
|
DrawIndents(stream, indents);
|
||||||
|
stream << "Block:" << endl;
|
||||||
_block->GetTreeString(stream, indents + 1);
|
_block->GetTreeString(stream, indents + 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -2,8 +2,10 @@
|
||||||
#include <catch.hpp>
|
#include <catch.hpp>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
|
|
||||||
|
#include "../src/ScriptTypes/ScriptType.hpp"
|
||||||
#include "../src/Binder/BoundStatements/BoundStatement.hpp"
|
#include "../src/Binder/BoundStatements/BoundStatement.hpp"
|
||||||
#include "../src/Utilities/HashedString.hpp"
|
#include "../src/Utilities/HashedString.hpp"
|
||||||
|
using namespace Porygon;
|
||||||
using namespace Porygon::Binder;
|
using namespace Porygon::Binder;
|
||||||
using namespace Porygon::Utilities;
|
using namespace Porygon::Utilities;
|
||||||
|
|
||||||
|
@ -144,5 +146,23 @@ TEST_CASE( "While To String", "[BoundTreeString]" ) {
|
||||||
delete s;
|
delete s;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST_CASE( "Function Declaration To String", "[BoundTreeString]" ) {
|
||||||
|
std::stringstream stream;
|
||||||
|
auto t = make_shared<const GenericFunctionScriptType>();
|
||||||
|
auto key = new u16string(u"func");
|
||||||
|
const BoundVariableKey *keyObj = new BoundVariableKey(HashedString(key), 0, true);
|
||||||
|
auto s = new BoundFunctionDeclarationStatement(t, keyObj, new BoundBlockStatement({}));
|
||||||
|
s->GetTreeString(stream, 1);
|
||||||
|
REQUIRE(stream.str() ==
|
||||||
|
R"( FunctionDeclaration
|
||||||
|
Key: func
|
||||||
|
Type: function
|
||||||
|
Block:
|
||||||
|
BlockStatement)");
|
||||||
|
delete s;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#endif
|
#endif
|
Loading…
Reference in New Issue