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(