From 8148c41179afb8f97a02cf6f7a0172e8a10def7b Mon Sep 17 00:00:00 2001 From: Robin Jadoul Date: Tue, 17 Jan 2017 17:54:05 +0100 Subject: [PATCH] Complete LR(1) but not LALR(1) test --- tests/lr1_only.cpp | 57 ++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 55 insertions(+), 2 deletions(-) diff --git a/tests/lr1_only.cpp b/tests/lr1_only.cpp index eb68a57..74302ae 100644 --- a/tests/lr1_only.cpp +++ b/tests/lr1_only.cpp @@ -1,12 +1,14 @@ #include "Parsodus/lrtables/generator.h" #include "Parsodus/lrtables/LR1Itemset.h" #include "Parsodus/lrtables/LALR1Itemset.h" +#include "Parsodus/util/symbols.h" #include "gtest/gtest.h" #include TEST(lr1, only) { using namespace pds; + using namespace pds::lr; Grammar grammar; grammar.start = "s"; @@ -28,8 +30,59 @@ TEST(lr1, only) { } { - pds::lr::Generator g(grammar); - ASSERT_NO_THROW(g.generate()); + Generator g(grammar); + LRTable table; + ASSERT_NO_THROW(table = g.generate()); + std::vector>> act = { + { + {"A", {Action::SHIFT, 1}}, + {"B", {Action::SHIFT, 2}} + }, { + {util::EOF_PLACEHOLDER, {Action::REDUCE, 4}}, + {"A", {Action::REDUCE, 5}} + }, { + {"A", {Action::SHIFT, 6}} + }, { + {util::EOF_PLACEHOLDER, {Action::REDUCE, 2}} + }, { + {"A", {Action::SHIFT, 9}} + }, { + {util::EOF_PLACEHOLDER, {Action::ACCEPT, 0}} + }, { + {util::EOF_PLACEHOLDER, {Action::REDUCE, 5}}, + {"A", {Action::REDUCE, 4}} + }, { + {"A", {Action::SHIFT, 10}} + }, { + {util::EOF_PLACEHOLDER, {Action::REDUCE, 3}} + }, { + {util::EOF_PLACEHOLDER, {Action::REDUCE, 1}} + }, { + {util::EOF_PLACEHOLDER, {Action::REDUCE, 0}} + } + }; + ASSERT_EQ(act.size(), table.act.size()); + for (std::size_t i = 0; i < act.size(); i++) { + EXPECT_EQ(act[i], table.act[i]); + } + + std::vector> got = { + { {"s", 5}, {"a", 3}, {"b", 4} }, + {}, + { {"a", 7}, {"b", 8} }, + {}, + {}, + {}, + {}, + {}, + {}, + {}, + {} + }; + ASSERT_EQ(got.size(), table.goto_.size()); + for (std::size_t i = 0; i < got.size(); i++) { + EXPECT_EQ(got[i], table.goto_[i]); + } } {