better use of fixtures for resource allocation and
dealocation
This commit is contained in:
@@ -90,13 +90,6 @@ let y = 10;\
|
|||||||
let foobar = 103213;\
|
let foobar = 103213;\
|
||||||
");
|
");
|
||||||
|
|
||||||
ast::program* program = p->parse_program();
|
|
||||||
check_parser_errors(p->errors);
|
|
||||||
|
|
||||||
REQUIRE_MESSAGE(
|
|
||||||
program != nullptr,
|
|
||||||
"parse_program() returned a null pointer"
|
|
||||||
);
|
|
||||||
REQUIRE(program->statements.size() == 3);
|
REQUIRE(program->statements.size() == 3);
|
||||||
|
|
||||||
struct test {
|
struct test {
|
||||||
@@ -115,7 +108,5 @@ let foobar = 103213;\
|
|||||||
|
|
||||||
test_let_statement(stmt, t.expected_identifier);
|
test_let_statement(stmt, t.expected_identifier);
|
||||||
}
|
}
|
||||||
|
|
||||||
delete program;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -1,5 +1,3 @@
|
|||||||
#include "ast/ast.hpp"
|
|
||||||
#include "parser/parser.hpp"
|
|
||||||
#include "utils.hpp"
|
#include "utils.hpp"
|
||||||
|
|
||||||
#include <doctest.h>
|
#include <doctest.h>
|
||||||
@@ -12,13 +10,6 @@ return 10;\
|
|||||||
return 103213;\
|
return 103213;\
|
||||||
");
|
");
|
||||||
|
|
||||||
ast::program* program = p->parse_program();
|
|
||||||
check_parser_errors(p->errors);
|
|
||||||
|
|
||||||
REQUIRE_MESSAGE(
|
|
||||||
program != nullptr,
|
|
||||||
"parse_program() returned a null pointer"
|
|
||||||
);
|
|
||||||
REQUIRE(program->statements.size() == 3);
|
REQUIRE(program->statements.size() == 3);
|
||||||
|
|
||||||
for (const auto stmt : program->statements) {
|
for (const auto stmt : program->statements) {
|
||||||
@@ -30,7 +21,5 @@ return 103213;\
|
|||||||
"Couldn't cast statement to a return statement"
|
"Couldn't cast statement to a return statement"
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
delete program;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -1,5 +1,6 @@
|
|||||||
#include "utils.hpp"
|
#include "utils.hpp"
|
||||||
|
|
||||||
|
#include <doctest.h>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
void check_parser_errors(const std::vector<ast::error::error*>& errors) {
|
void check_parser_errors(const std::vector<ast::error::error*>& errors) {
|
||||||
@@ -10,6 +11,26 @@ void check_parser_errors(const std::vector<ast::error::error*>& errors) {
|
|||||||
for (const auto& error : errors)
|
for (const auto& error : errors)
|
||||||
std::cerr << '\t' << error->what() << "\n";
|
std::cerr << '\t' << error->what() << "\n";
|
||||||
|
|
||||||
// Use doctest's FAIL macro to immediately stop
|
|
||||||
FAIL_CHECK("Parser had errors. See stderr for details.");
|
FAIL_CHECK("Parser had errors. See stderr for details.");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ParserFixture::setup(std::string source) {
|
||||||
|
input << source;
|
||||||
|
lexer = new lexer::lexer{input};
|
||||||
|
parser = new parser::parser(*lexer);
|
||||||
|
program = parser->parse_program();
|
||||||
|
check_parser_errors(parser->errors);
|
||||||
|
|
||||||
|
CAPTURE(parser);
|
||||||
|
CAPTURE(program);
|
||||||
|
REQUIRE_MESSAGE(
|
||||||
|
program != nullptr,
|
||||||
|
"parse_program() returned a null pointer"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
ParserFixture::~ParserFixture() {
|
||||||
|
delete lexer;
|
||||||
|
delete parser;
|
||||||
|
delete program;
|
||||||
|
}
|
||||||
|
@@ -1,28 +1,19 @@
|
|||||||
#include "ast/errors/error.hpp"
|
|
||||||
#include "lexer/lexer.hpp"
|
#include "lexer/lexer.hpp"
|
||||||
#include "parser/parser.hpp"
|
#include "parser/parser.hpp"
|
||||||
|
|
||||||
#include <doctest.h>
|
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
#include <vector>
|
|
||||||
|
|
||||||
void check_parser_errors(const std::vector<ast::error::error*>& errors);
|
void check_parser_errors(const std::vector<ast::error::error*>& errors);
|
||||||
|
|
||||||
struct ParserFixture {
|
struct ParserFixture {
|
||||||
std::stringstream input;
|
std::stringstream input;
|
||||||
lexer::lexer* l = nullptr;
|
lexer::lexer* lexer = nullptr;
|
||||||
parser::parser* p = nullptr;
|
parser::parser* parser = nullptr;
|
||||||
|
ast::program* program = nullptr;
|
||||||
|
|
||||||
ParserFixture() = default;
|
ParserFixture() = default;
|
||||||
|
|
||||||
void setup(std::string source) {
|
void setup(std::string);
|
||||||
input << source;
|
|
||||||
l = new lexer::lexer{input};
|
|
||||||
p = new parser::parser(*l);
|
|
||||||
}
|
|
||||||
|
|
||||||
~ParserFixture() {
|
~ParserFixture();
|
||||||
delete l;
|
|
||||||
delete p;
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
Reference in New Issue
Block a user