From 6a6709d2c85704fa55f9bb172bb1dc44b5f1ea47 Mon Sep 17 00:00:00 2001 From: Paul Beckingham Date: Wed, 23 Dec 2015 00:22:17 -0500 Subject: [PATCH] Tests: Added Grammar metadata tests --- test/grammar.t.cpp | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/test/grammar.t.cpp b/test/grammar.t.cpp index ddf8a26c..670dacb8 100644 --- a/test/grammar.t.cpp +++ b/test/grammar.t.cpp @@ -63,7 +63,7 @@ void testBadGrammar (UnitTest& t, const std::string& bnf) //////////////////////////////////////////////////////////////////////////////// int main (int, char**) { - UnitTest t (6); + UnitTest t (14); // Test loading from a missing file. File missing ("/tmp/does/not/exist"); @@ -88,6 +88,26 @@ int main (int, char**) "\n" "two: \"foo\"\n"); + // Test metadata access. + Grammar g; + g.loadFromString ("one: two\n" + "\n" + "two: three \"literal\"\n" + " /regex/\n" + "\n" + "three: \"literal2\"\n"); + auto start = g.start (); + auto rules = g.rules (); + auto terminals = g.terminals (); + t.is (start, "one", "Located start rule"); + t.is ((int)rules.size (), 3, "Found three rules"); + t.ok (rules.find ("one") != rules.end (), "Found rule 'one'"); + t.ok (rules.find ("two") != rules.end (), "Found rule 'two'"); + t.ok (rules.find ("three") != rules.end (), "Found rule 'three'"); + t.ok (terminals.find ("\"literal\"") != terminals.end (), "Found terminal '\"literal\"'"); + t.ok (terminals.find ("/regex/") != terminals.end (), "Found terminal '/regex/'"); + t.ok (terminals.find ("\"literal2\"") != terminals.end (), "Found terminal '\"literal2\"'"); + return 0; }