From abadaf4d5d9db5fc0c476de51037bd7fadda678d Mon Sep 17 00:00:00 2001 From: Futago-za Ryuu Date: Fri, 20 Oct 2017 19:01:19 +0100 Subject: [PATCH] Add test for empty grammars This add's a test that ensures grammars without any rules are not accepted. --- test/spec/unit/parser.spec.js | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/test/spec/unit/parser.spec.js b/test/spec/unit/parser.spec.js index c794c5f..f4a749c 100644 --- a/test/spec/unit/parser.spec.js +++ b/test/spec/unit/parser.spec.js @@ -226,6 +226,20 @@ describe("PEG.js grammar parser", function() { chai.use(helpers); }); + // Grammars without any rules are not accepted. + it("parses Rule+", function() { + expect("start = a").to.parseAs(ruleRefGrammar("a")); + let grammar = ruleRefGrammar("a"); + grammar.initializer = { + "type": "initializer", + "code": "" + }; + expect("{}\nstart = a").to.parseAs(grammar); + + expect("").to.failToParse(); + expect("{}").to.failToParse(); + }); + // Canonical Grammar is "a = 'abcd'; b = 'efgh'; c = 'ijkl';". it("parses Grammar", function() { expect("\na = 'abcd';\n").to.parseAs(