#include #include "../lib/Lexer.hpp" #include "../lib/Parser.hpp" #include "lib/SrcLoc.hpp" #include "lib/StatusLog.hpp" class ParserTest { public: explicit ParserTest() {} virtual ~ParserTest() {} void test_node(std::string const& oracle, std::string const& source) { roza::SrcLoc loc {"parser_tests"}; roza::StatusLog log; roza::Lexer lexer {log, loc}; roza::Parser parser {lexer, log}; lexer.scan(source); auto node = parser.parse(); REQUIRE(oracle == node->string()); } void test_node_err(std::string const& oracle) { roza::SrcLoc loc {"parser_tests"}; roza::StatusLog log; roza::Lexer lexer {log, loc}; roza::Parser parser {lexer, log}; lexer.scan(oracle); REQUIRE_THROWS(parser.parse()); } protected: }; TEST_CASE_METHOD(ParserTest, "Parser_integers") { test_node("PROG", ""); test_node("PROG(INSTR(INT[27]))", "27"); test_node("PROG(INSTR(INT[27]))", " 27 "); test_node("PROG(INSTR(INT[27])," "INSTR(INT[9])," "INSTR(INT[-99]))", "27 \n 9 \n -99"); test_node_err("32 14 -12"); }