Jasmine: Convert start rule tests

redux
David Majda 13 years ago
parent 68bfeac134
commit 1825dd4a42

@ -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() {

@ -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\".";
}
);
});
})();

Loading…
Cancel
Save