diff --git a/test/parser.cpp b/test/parser/let.cpp similarity index 88% rename from test/parser.cpp rename to test/parser/let.cpp index 98333af..c10f4f6 100644 --- a/test/parser.cpp +++ b/test/parser/let.cpp @@ -1,11 +1,11 @@ -#include "parser/parser.hpp" +#include "ast/statements/let.hpp" #include "ast/ast.hpp" -#include "ast/statements/let.hpp" #include "lexer/lexer.hpp" +#include "parser/parser.hpp" +#include "utils.hpp" #include -#include #include void test_let_statement(ast::statement* stmt, const std::string name) { @@ -57,18 +57,6 @@ void test_failing_let_parsing( delete program; } -void check_parser_errors(const std::vector& errors) { - if (errors.empty()) - return; - - std::cerr << "parser has " << errors.size() << " errors:\n"; - for (const auto& error : errors) - std::cerr << '\t' << error->what() << "\n"; - - // Use doctest's FAIL macro to immediately stop - FAIL_CHECK("Parser had errors. See stderr for details."); -} - TEST_CASE("Malformed let statement (checking for memory leaks)") { SUBCASE("Second token not identifier") { test_failing_let_parsing("let 5 = 5;", {token::type::IDENTIFIER}); diff --git a/test/parser/utils.cpp b/test/parser/utils.cpp new file mode 100644 index 0000000..90d5253 --- /dev/null +++ b/test/parser/utils.cpp @@ -0,0 +1,15 @@ +#include "utils.hpp" + +#include + +void check_parser_errors(const std::vector& errors) { + if (errors.empty()) + return; + + std::cerr << "parser has " << errors.size() << " errors:\n"; + for (const auto& error : errors) + std::cerr << '\t' << error->what() << "\n"; + + // Use doctest's FAIL macro to immediately stop + FAIL_CHECK("Parser had errors. See stderr for details."); +} diff --git a/test/parser/utils.hpp b/test/parser/utils.hpp new file mode 100644 index 0000000..bf32768 --- /dev/null +++ b/test/parser/utils.hpp @@ -0,0 +1,6 @@ +#include "ast/errors/error.hpp" + +#include +#include + +void check_parser_errors(const std::vector& errors);