#include #include "../src/Parser.hpp" class ParserTest { public: explicit ParserTest() {} virtual ~ParserTest() {} void test_parse(std::string const& oracle, std::string const& source) { auto node = m_parser.parse(source); REQUIRE(oracle == node->string()); } protected: fk::Loc m_loc {"tests/parser"}; fk::Lexer m_lexer { m_loc }; fk::Parser m_parser { m_lexer }; }; TEST_CASE_METHOD(ParserTest, "Parser_empty") { test_parse("MODULE", ""); } TEST_CASE_METHOD(ParserTest, "Parser_builtins") { test_parse("MODULE(INT[4],FLOAT[3.0],BOOL[false],STRING['salut'])", "4 3. false 'salut'"); } TEST_CASE_METHOD(ParserTest, "Parser_call") { test_parse("MODULE(CALL(IDENT[bim],INT[2],STRING['3'],BOOL[false]))", " (bim 2 '3' false) "); } TEST_CASE_METHOD(ParserTest, "Parser_vardecl") { test_parse("MODULE(VARDECL(IDENT[hello],INT[3]))", " ($ hello 3) "); } TEST_CASE_METHOD(ParserTest, "Parser_lambda") { test_parse("MODULE(LAMBDA(PARAMS,BODY))", " (-> ()) "); test_parse("MODULE(LAMBDA(PARAMS(IDENT[x]),BODY))", " (-> (x)) "); test_parse("MODULE(LAMBDA(PARAMS(IDENT[x],IDENT[y]),BODY(INT[7])))", " (-> (x y) 7) "); } TEST_CASE_METHOD(ParserTest, "Parser_fundecl") { test_parse("MODULE(VARDECL(IDENT[f]," "LAMBDA(PARAMS(IDENT[x]),BODY(INT[7]))))", " ($ (f x) 7) "); } TEST_CASE_METHOD(ParserTest, "Parser_namespace") { test_parse("MODULE(CALL(NS(IDENT[x],IDENT[y]),IDENT[z]))", " (x::y z) "); } TEST_CASE_METHOD(ParserTest, "Parser_import") { test_parse("MODULE(VARDECL(IDENT[x],IMPORT(STRING['y'])))", " ($ x (@ 'y') )"); test_parse("MODULE(VARDECL(IDENT[x],IMPORT(STRING['y'])))", " ($ @x 'y' )"); test_parse("MODULE(VARDECL(IDENT[bim],IMPORT(STRING['bam'])))", " ($ @bim 'bam' )"); test_parse("MODULE(VARDECL(IDENT[example],IMPORT(STRING['example'])))", " ($ @example )"); }