From aa1ff293070319d27822ddea1026fde19853b013 Mon Sep 17 00:00:00 2001 From: Robin Jadoul Date: Wed, 11 Jan 2017 17:24:36 +0100 Subject: [PATCH] Small cleanup for existing test --- tests/lr0_shift-red.cpp | 38 +++++++++++++++++++++++--------------- 1 file changed, 23 insertions(+), 15 deletions(-) diff --git a/tests/lr0_shift-red.cpp b/tests/lr0_shift-red.cpp index 401fdae..08a2423 100644 --- a/tests/lr0_shift-red.cpp +++ b/tests/lr0_shift-red.cpp @@ -15,42 +15,50 @@ TEST(lr0, test0) { pds::Grammar grammar; - grammar.start = "S'"; - grammar.variables = {"S'","S","A","E"}; - grammar.terminals = {"$",";", "id", ":=", "+"}; + grammar.start = "S"; + grammar.variables = {"S","A","E"}; + grammar.terminals = {";", "id", ":=", "+"}; std::shared_ptr rule(new pds::Rule()); - rule->head = "S'"; - rule->tail = {"S","$"}; - grammar.rules.push_back(rule); - rule->head = "S"; rule->tail = {"S",";","A"}; - grammar.rules.push_back(rule); + grammar.rules.push_back(std::make_shared(*rule)); rule->head = "S"; rule->tail = {"A"}; - grammar.rules.push_back(rule); + grammar.rules.push_back(std::make_shared(*rule)); rule->head = "A"; rule->tail = {"E"}; - grammar.rules.push_back(rule); + grammar.rules.push_back(std::make_shared(*rule)); rule->head = "A"; rule->tail = {"id",":=","E"}; - grammar.rules.push_back(rule); + grammar.rules.push_back(std::make_shared(*rule)); rule->head = "E"; rule->tail = {"E","+","id"}; - grammar.rules.push_back(rule); + grammar.rules.push_back(std::make_shared(*rule)); rule->head = "E"; rule->tail = {"id"}; - grammar.rules.push_back(rule); + grammar.rules.push_back(std::make_shared(*rule)); - pds::lr::Generator g(grammar); - auto tbl = g.generate(); // LRTable + { + pds::lr::Generator g(grammar); + ASSERT_THROW(g.generate(), std::runtime_error); + try { + g.generate(); + } catch (std::runtime_error& e) { + ASSERT_EQ(std::string("shift-reduce"), e.what()); + } + } + { + pds::lr::Generator g(grammar); + ASSERT_NO_THROW(g.generate()); + } + // auto tbl = g.generate(); // LRTable // EXPECT_THROW(throw "shift-reduce", std::exception); /*