created the parser dir test to avoid having a
bunch of "unrelated" tests in one file
This commit is contained in:
@@ -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 <doctest.h>
|
||||
#include <iostream>
|
||||
#include <sstream>
|
||||
|
||||
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<ast::error::error*>& 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});
|
15
test/parser/utils.cpp
Normal file
15
test/parser/utils.cpp
Normal file
@@ -0,0 +1,15 @@
|
||||
#include "utils.hpp"
|
||||
|
||||
#include <iostream>
|
||||
|
||||
void check_parser_errors(const std::vector<ast::error::error*>& 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.");
|
||||
}
|
6
test/parser/utils.hpp
Normal file
6
test/parser/utils.hpp
Normal file
@@ -0,0 +1,6 @@
|
||||
#include "ast/errors/error.hpp"
|
||||
|
||||
#include <doctest.h>
|
||||
#include <vector>
|
||||
|
||||
void check_parser_errors(const std::vector<ast::error::error*>& errors);
|
Reference in New Issue
Block a user