From 94205ab639d2c9c6d400d088ed932c7ff1f8d96a Mon Sep 17 00:00:00 2001 From: David Majda Date: Sat, 21 Apr 2012 12:48:37 +0200 Subject: [PATCH] Jasmine: Convert tests of parser's "grammar" rule --- spec/parser.spec.js | 26 ++++++++++++++++++++++++++ test/parser-test.js | 28 ---------------------------- 2 files changed, 26 insertions(+), 28 deletions(-) diff --git a/spec/parser.spec.js b/spec/parser.spec.js index 8f7f413..14774dc 100644 --- a/spec/parser.spec.js +++ b/spec/parser.spec.js @@ -157,6 +157,32 @@ describe("PEG.js grammar parser", function() { }); }); + /* Canonical grammar is "a = \"abcd\"; b = \"efgh\"; c = \"ijkl\";". */ + it("parses grammar", function() { + var ruleA = { type: "rule", name: "a", displayName: null, expression: literalAbcd }, + ruleB = { type: "rule", name: "b", displayName: null, expression: literalEfgh }, + ruleC = { type: "rule", name: "c", displayName: null, expression: literalIjkl }; + + expect('a = "abcd"').toParseAs({ + type: "grammar", + initializer: null, + rules: [ruleA], + startRule: "a" + }); + expect('{ code } a = "abcd"').toParseAs({ + type: "grammar", + initializer: { type: "initializer", code: " code " }, + rules: [ruleA], + startRule: "a" + }); + expect('a = "abcd"; b = "efgh"; c = "ijkl"').toParseAs({ + type: "grammar", + initializer: null, + rules: [ruleA, ruleB, ruleC], + startRule: "a" + }); + }); + /* Canonical initializer is "{ code }". */ it("parses initializer", function() { var grammar = oneRuleGrammar(literalAbcd, { diff --git a/test/parser-test.js b/test/parser-test.js index 53391d4..87baba2 100644 --- a/test/parser-test.js +++ b/test/parser-test.js @@ -166,32 +166,4 @@ var namedRuleGrammar = { startRule: "start" }; -/* Canonical grammar is "a: \"abcd\"; b: \"efgh\"; c: \"ijkl\";". */ -test("parses grammar", function() { - parserParses( - 'a = "abcd"', - { - type: "grammar", - initializer: null, - rules: [rule("a", null, literalAbcd)], - startRule: "a" - } - ); - parserParses('{ code }; a = "abcd"', initializerGrammar); - parserParses( - 'a = "abcd"; b = "efgh"; c = "ijkl"', - { - type: "grammar", - initializer: null, - rules: [ - rule("a", null, literalAbcd), - rule("b", null, literalEfgh), - rule("c", null, literalIjkl) - ], - startRule: "a" - } - ); -}); - - })();