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

Add unit tests for AST dotfile generator

parent 85569909
No related branches found
No related tags found
1 merge request!37Feature/language
......@@ -3,12 +3,13 @@ set(EXECUTABLE_OUTPUT_PATH ${PUGS_BINARY_DIR})
add_executable (unit_tests
test_main.cpp
test_ASTSymbolTableBuilder.cpp
test_ASTSymbolInitializationChecker.cpp
test_ASTBuilder.cpp
test_ASTNodeDataType.cpp
test_Array.cpp
test_ArrayUtils.cpp
test_ASTDotPrinter.cpp
test_ASTBuilder.cpp
test_ASTNodeDataType.cpp
test_ASTSymbolTableBuilder.cpp
test_ASTSymbolInitializationChecker.cpp
test_ItemType.cpp
test_PugsAssert.cpp
test_RevisionInfo.cpp
......
#include <catch2/catch.hpp>
#include <ASTBuilder.hpp>
#include <ASTDotPrinter.hpp>
#include <sstream>
#define CHECK_DOT(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); \
\
std::stringstream ast_output; \
ast_output << '\n' << ASTDotPrinter{*ast}; \
\
REQUIRE(ast_output.str() == expected_output); \
}
TEST_CASE("ASTDotPrinter", "[language]")
{
rang::setControlMode(rang::control::Off);
std::string_view data = R"(
N n = 2 + 3;
)";
std::string_view result = R"(
digraph parse_tree
{
x0 [ label="root \nundefined" ]
x0 -> { x1 }
x1 [ label="language::declaration\nN n = 2 + 3\nundefined" ]
x1 -> { x2, x3, x4 }
x2 [ label="language::N_set\nN\nundefined" ]
x3 [ label="language::name\nn\nundefined" ]
x4 [ label="language::plus_op\nundefined" ]
x4 -> { x5, x6 }
x5 [ label="language::integer\n2\nundefined" ]
x6 [ label="language::integer\n3\nundefined" ]
}
)";
CHECK_DOT(data, result);
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment