using fixtures (not super necessary, but nice)
This commit is contained in:
@@ -83,18 +83,15 @@ TEST_SUITE("Parser: let") {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_CASE("Parse well formed let statements") {
|
TEST_CASE_FIXTURE(ParserFixture, "Parse well formed let statements") {
|
||||||
std::stringstream input("\
|
setup("\
|
||||||
let x = 5;\
|
let x = 5;\
|
||||||
let y = 10;\
|
let y = 10;\
|
||||||
let foobar = 103213;\
|
let foobar = 103213;\
|
||||||
");
|
");
|
||||||
|
|
||||||
lexer::lexer l{input};
|
ast::program* program = p->parse_program();
|
||||||
parser::parser p{l};
|
check_parser_errors(p->errors);
|
||||||
|
|
||||||
ast::program* program = p.parse_program();
|
|
||||||
check_parser_errors(p.errors);
|
|
||||||
|
|
||||||
REQUIRE_MESSAGE(
|
REQUIRE_MESSAGE(
|
||||||
program != nullptr,
|
program != nullptr,
|
||||||
|
@@ -1,24 +1,19 @@
|
|||||||
#include "ast/ast.hpp"
|
#include "ast/ast.hpp"
|
||||||
#include "lexer/lexer.hpp"
|
|
||||||
#include "parser/parser.hpp"
|
#include "parser/parser.hpp"
|
||||||
#include "utils.hpp"
|
#include "utils.hpp"
|
||||||
|
|
||||||
#include <doctest.h>
|
#include <doctest.h>
|
||||||
#include <sstream>
|
|
||||||
|
|
||||||
TEST_SUITE("Parser: return") {
|
TEST_SUITE("Parser: return") {
|
||||||
TEST_CASE("Parse return statement") {
|
TEST_CASE_FIXTURE(ParserFixture, "Parse return statement") {
|
||||||
std::stringstream input("\
|
setup("\
|
||||||
return 5;\
|
return 5;\
|
||||||
return 10;\
|
return 10;\
|
||||||
return 103213;\
|
return 103213;\
|
||||||
");
|
");
|
||||||
|
|
||||||
lexer::lexer l{input};
|
ast::program* program = p->parse_program();
|
||||||
parser::parser p{l};
|
check_parser_errors(p->errors);
|
||||||
|
|
||||||
ast::program* program = p.parse_program();
|
|
||||||
check_parser_errors(p.errors);
|
|
||||||
|
|
||||||
REQUIRE_MESSAGE(
|
REQUIRE_MESSAGE(
|
||||||
program != nullptr,
|
program != nullptr,
|
||||||
|
@@ -1,6 +1,28 @@
|
|||||||
#include "ast/errors/error.hpp"
|
#include "ast/errors/error.hpp"
|
||||||
|
#include "lexer/lexer.hpp"
|
||||||
|
#include "parser/parser.hpp"
|
||||||
|
|
||||||
#include <doctest.h>
|
#include <doctest.h>
|
||||||
|
#include <sstream>
|
||||||
#include <vector>
|
#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 {
|
||||||
|
std::stringstream input;
|
||||||
|
lexer::lexer* l = nullptr;
|
||||||
|
parser::parser* p = nullptr;
|
||||||
|
|
||||||
|
ParserFixture() = default;
|
||||||
|
|
||||||
|
void setup(std::string source) {
|
||||||
|
input << source;
|
||||||
|
l = new lexer::lexer{input};
|
||||||
|
p = new parser::parser(*l);
|
||||||
|
}
|
||||||
|
|
||||||
|
~ParserFixture() {
|
||||||
|
delete l;
|
||||||
|
delete p;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
Reference in New Issue
Block a user