summaryrefslogtreecommitdiffhomepage
path: root/test-grammer.cpp
diff options
context:
space:
mode:
authorRoland Reichwein <mail@reichwein.it>2020-03-23 22:02:40 +0100
committerRoland Reichwein <mail@reichwein.it>2020-03-23 22:02:40 +0100
commitfce1c18103f208857af477ca47af9aa908bd69b6 (patch)
tree3d0affeca1328825e81be8950f19e956f39ab213 /test-grammer.cpp
parent365183e243d164185bca6ad9fa4e0d75664800f4 (diff)
Helper functions for grammer
Diffstat (limited to 'test-grammer.cpp')
-rw-r--r--test-grammer.cpp65
1 files changed, 65 insertions, 0 deletions
diff --git a/test-grammer.cpp b/test-grammer.cpp
new file mode 100644
index 0000000..1734da2
--- /dev/null
+++ b/test-grammer.cpp
@@ -0,0 +1,65 @@
+#include "bnf.h"
+#include "cpp.h"
+#include "cppbnf.h"
+#include "lexer.h"
+#include "grammer.h"
+#include "minicc.h"
+#include "debug.h"
+
+#include <boost/algorithm/string.hpp>
+
+#include "gmock/gmock.h"
+#include "gtest/gtest.h"
+
+#include <algorithm>
+#include <cctype>
+#include <deque>
+#include <map>
+#include <memory>
+#include <string>
+#include <utility>
+#include <vector>
+
+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<std::string> 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<std::string>{}), 0);
+ EXPECT_EQ(minimumSymbolsNeeded(compiler, "translation-unit"), 0);
+ EXPECT_EQ(minimumSymbolsNeeded(compiler, "logical-or-expression"), 1);
+ EXPECT_EQ(minimumSymbolsNeeded(compiler, "assignment-expression"), 1);
+ EXPECT_EQ(minimumSymbolsNeeded(compiler, "declaration"), 1);
+ EXPECT_EQ(minimumSymbolsNeeded(compiler, "block-declaration"), 3);
+ EXPECT_EQ(minimumSymbolsNeeded(compiler, "simple-declaration"), 2);
+ EXPECT_EQ(minimumSymbolsNeeded(compiler, "asm-declaration"), 5);
+ EXPECT_EQ(minimumSymbolsNeeded(compiler, "namespace-alias-definition"), 5);
+ EXPECT_EQ(minimumSymbolsNeeded(compiler, "using-declaration"), 4);
+ EXPECT_EQ(minimumSymbolsNeeded(compiler, "using-enum-declaration"), 4);
+ EXPECT_EQ(minimumSymbolsNeeded(compiler, "using-directive"), 4);
+ EXPECT_EQ(minimumSymbolsNeeded(compiler, "static_assert-declaration"), 5);
+ EXPECT_EQ(minimumSymbolsNeeded(compiler, "alias-declaration"), 7);
+ EXPECT_EQ(minimumSymbolsNeeded(compiler, "opaque-enum-declaration"), 3);
+ EXPECT_EQ(minimumSymbolsNeeded(compiler, "function-definition"), 4);
+}
+