Skip to content
Snippets Groups Projects
Commit fba39f1d authored by Stéphane Del Pino's avatar Stéphane Del Pino
Browse files

Begin test for ASTNodeDataTypeBuilder

parent 132301c2
No related branches found
No related tags found
1 merge request!37Feature/language
......@@ -8,6 +8,7 @@ add_executable (unit_tests
test_ASTDotPrinter.cpp
test_ASTBuilder.cpp
test_ASTNodeDataType.cpp
test_ASTNodeDataTypeBuilder.cpp
test_ASTSymbolTableBuilder.cpp
test_ASTSymbolInitializationChecker.cpp
test_ItemType.cpp
......
#include <catch2/catch.hpp>
#include <ASTBuilder.hpp>
#include <ASTNodeDataTypeBuilder.hpp>
#include <ASTSymbolTableBuilder.hpp>
#include <ASTPrinter.hpp>
#define CHECK_AST(data, expected_output) \
{ \
static_assert(std::is_same_v<std::decay_t<decltype(data)>, std::string_view>); \
static_assert(std::is_same_v<std::decay_t<decltype(expected_output)>, std::string_view>); \
\
string_input input{data, "test.pgs"}; \
auto ast = ASTBuilder::build(input); \
\
ASTSymbolTableBuilder{*ast}; \
ASTNodeDataTypeBuilder{*ast}; \
\
std::stringstream ast_output; \
ast_output << '\n' << ASTPrinter{*ast, ASTPrinter::Format::raw, {ASTPrinter::Info::data_type}}; \
\
REQUIRE(ast_output.str() == expected_output); \
}
TEST_CASE("ASTNodeDataTypeBuilder", "[language]")
{
SECTION("integer")
{
std::string_view data = R"(
1;
)";
std::string_view result = R"(
(root:void)
`-(language::integer:1:Z)
)";
CHECK_AST(data, result);
}
SECTION("real")
{
std::string_view data = R"(
1.3;
)";
std::string_view result = R"(
(root:void)
`-(language::real:1.3:R)
)";
CHECK_AST(data, result);
}
SECTION("true")
{
std::string_view data = R"(
true;
)";
std::string_view result = R"(
(root:void)
`-(language::true_kw:B)
)";
CHECK_AST(data, result);
}
SECTION("false")
{
std::string_view data = R"(
false;
)";
std::string_view result = R"(
(root:void)
`-(language::false_kw:B)
)";
CHECK_AST(data, result);
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment