diff --git a/test/parser/let.cpp b/test/parser/let.cpp index 4794743..282eedd 100644 --- a/test/parser/let.cpp +++ b/test/parser/let.cpp @@ -83,18 +83,15 @@ TEST_SUITE("Parser: let") { } } - TEST_CASE("Parse well formed let statements") { - std::stringstream input("\ + TEST_CASE_FIXTURE(ParserFixture, "Parse well formed let statements") { + setup("\ let x = 5;\ let y = 10;\ let foobar = 103213;\ "); - lexer::lexer l{input}; - parser::parser p{l}; - - ast::program* program = p.parse_program(); - check_parser_errors(p.errors); + ast::program* program = p->parse_program(); + check_parser_errors(p->errors); REQUIRE_MESSAGE( program != nullptr, diff --git a/test/parser/return.cpp b/test/parser/return.cpp index 1ecb606..4862442 100644 --- a/test/parser/return.cpp +++ b/test/parser/return.cpp @@ -1,24 +1,19 @@ #include "ast/ast.hpp" -#include "lexer/lexer.hpp" #include "parser/parser.hpp" #include "utils.hpp" #include -#include TEST_SUITE("Parser: return") { - TEST_CASE("Parse return statement") { - std::stringstream input("\ + TEST_CASE_FIXTURE(ParserFixture, "Parse return statement") { + setup("\ return 5;\ return 10;\ return 103213;\ "); - lexer::lexer l{input}; - parser::parser p{l}; - - ast::program* program = p.parse_program(); - check_parser_errors(p.errors); + ast::program* program = p->parse_program(); + check_parser_errors(p->errors); REQUIRE_MESSAGE( program != nullptr, diff --git a/test/parser/utils.hpp b/test/parser/utils.hpp index bf32768..8905d04 100644 --- a/test/parser/utils.hpp +++ b/test/parser/utils.hpp @@ -1,6 +1,28 @@ #include "ast/errors/error.hpp" +#include "lexer/lexer.hpp" +#include "parser/parser.hpp" #include +#include #include void check_parser_errors(const std::vector& 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; + } +};