From 1825dd4a4213680000ec3ba7a78f0617c3bf1d66 Mon Sep 17 00:00:00 2001 From: David Majda Date: Sun, 22 Apr 2012 19:13:25 +0200 Subject: [PATCH] Jasmine: Convert start rule tests --- spec/generated-parser.spec.js | 22 ++++++++++++++++++++++ test/compiler-test.js | 22 ---------------------- 2 files changed, 22 insertions(+), 22 deletions(-) diff --git a/spec/generated-parser.spec.js b/spec/generated-parser.spec.js index 31ff292..a32ddab 100644 --- a/spec/generated-parser.spec.js +++ b/spec/generated-parser.spec.js @@ -91,6 +91,28 @@ describe("generated parser", function() { }); }); + describe("parse", function() { + var parser = PEG.buildParser([ + 'a = "x" { return "a"; }', + 'b = "x" { return "b"; }' + ].join("\n")); + + it("uses the fist rule as a start rule when no |startRule| is specified", function() { + expect(parser.parse("x")).toBe("a"); + }); + + it("uses the specified rule as a start rule when |startRule| is specified", function() { + expect(parser.parse("x", "a")).toBe("a"); + expect(parser.parse("x", "b")).toBe("b"); + }); + + it("throws exception when the specified start rule does not exist", function() { + expect(function() { + parser.parse("x", "c"); + }).toThrow("Invalid rule name: \"c\"."); + }); + }); + describe("initializer code", function() { varyAll(function(options) { it("runs before the parsing begins", function() { diff --git a/test/compiler-test.js b/test/compiler-test.js index d865c8e..2dc6484 100644 --- a/test/compiler-test.js +++ b/test/compiler-test.js @@ -187,26 +187,4 @@ testWithVaryingTrackLineAndColumn("error positions", function(options) { doesNotParseWithPos(digitsParser, "1\u2029x", 2, 2, 1); // paragraph separator }); -testWithVaryingTrackLineAndColumn("start rule", function(options) { - var parser = PEG.buildParser([ - 'a = .* { return "alpha"; }', - 'b = .* { return "beta"; }' - ].join("\n"), options); - - /* Default start rule = the first one */ - parses(parser, "whatever", "alpha"); - - /* Explicit specification of the start rule */ - parsesWithStartRule(parser, "whatever", "a", "alpha"); - parsesWithStartRule(parser, "whatever", "b", "beta"); - - /* Invalid rule name */ - raises( - function() { parser.parse("whatever", "c"); }, - function(e) { - return e instanceof Error && e.message === "Invalid rule name: \"c\"."; - } - ); -}); - })();