#include "bnf.h" #include "cpp.h" #include "cppbnf.h" #include "lexer.h" #include "grammer.h" #include "minicc.h" #include "debug.h" #include #include "gmock/gmock.h" #include "gtest/gtest.h" #include #include #include #include #include #include #include #include using namespace std::string_literals; class GrammerTest: public ::testing::Test { protected: GrammerTest() { //debug = true; } ~GrammerTest() { } // Accessors for friend size_t minimumSymbolsNeeded(Gram::Compiler& compiler, std::vector list) { return compiler.minimumSymbolsNeeded(list); } size_t minimumSymbolsNeeded(Gram::Compiler& compiler, std::string s) { return compiler.minimumSymbolsNeeded(s); } }; TEST_F(GrammerTest, minimumSymbolsNeeded) { auto bnf = SubBNF(CPPBNF::GetCppBNFGram(), "translation-unit"); Gram::Compiler compiler(bnf, "translation-unit"); EXPECT_EQ(minimumSymbolsNeeded(compiler, std::vector{}), size_t(0)); EXPECT_EQ(minimumSymbolsNeeded(compiler, "translation-unit"), 0u); EXPECT_EQ(minimumSymbolsNeeded(compiler, "logical-or-expression"), 1u); EXPECT_EQ(minimumSymbolsNeeded(compiler, "assignment-expression"), 1u); EXPECT_EQ(minimumSymbolsNeeded(compiler, "declaration"), 1u); EXPECT_EQ(minimumSymbolsNeeded(compiler, "block-declaration"), 2u); EXPECT_EQ(minimumSymbolsNeeded(compiler, "simple-declaration"), 2u); EXPECT_EQ(minimumSymbolsNeeded(compiler, "asm-declaration"), 5u); EXPECT_EQ(minimumSymbolsNeeded(compiler, "namespace-alias-definition"), 5u); EXPECT_EQ(minimumSymbolsNeeded(compiler, "using-declaration"), 4u); EXPECT_EQ(minimumSymbolsNeeded(compiler, "using-enum-declaration"), 4u); EXPECT_EQ(minimumSymbolsNeeded(compiler, "using-directive"), 4u); EXPECT_EQ(minimumSymbolsNeeded(compiler, "static_assert-declaration"), 5u); EXPECT_EQ(minimumSymbolsNeeded(compiler, "alias-declaration"), 5u); EXPECT_EQ(minimumSymbolsNeeded(compiler, "opaque-enum-declaration"), 3u); EXPECT_EQ(minimumSymbolsNeeded(compiler, "function-definition"), 3u); }