|
|
@ -682,44 +682,72 @@ describe("generated parser behavior", function() {
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
describe("positive simple predicate", function() {
|
|
|
|
describe("positive simple predicate", function() {
|
|
|
|
it("matches correctly", function() {
|
|
|
|
describe("when the expression matches", function() {
|
|
|
|
|
|
|
|
it("returns |undefined|", function() {
|
|
|
|
var parser = PEG.buildParser('start = &"a" "a"', options);
|
|
|
|
var parser = PEG.buildParser('start = &"a" "a"', options);
|
|
|
|
|
|
|
|
|
|
|
|
expect(parser).toParse("a", [undefined, "a"]);
|
|
|
|
expect(parser).toParse("a", [undefined, "a"]);
|
|
|
|
expect(parser).toFailToParse("b");
|
|
|
|
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
it("does not advance position on success", function() {
|
|
|
|
it("resets parse position", function() {
|
|
|
|
var parser = PEG.buildParser('start = &"a" "a"', options);
|
|
|
|
var parser = PEG.buildParser('start = &"a" "a"', options);
|
|
|
|
|
|
|
|
|
|
|
|
expect(parser).toParse("a", [undefined, "a"]);
|
|
|
|
expect(parser).toParse("a");
|
|
|
|
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
it("does not influence expected strings on failure", function() {
|
|
|
|
describe("when the expression doesn't match", function() {
|
|
|
|
|
|
|
|
it("reports match failure", function() {
|
|
|
|
var parser = PEG.buildParser('start = &"a"', options);
|
|
|
|
var parser = PEG.buildParser('start = &"a"', options);
|
|
|
|
|
|
|
|
|
|
|
|
expect(parser).toFailToParse("b", { expected: [] });
|
|
|
|
expect(parser).toFailToParse("b");
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
it("discards any expectations recorded when matching the expression", function() {
|
|
|
|
|
|
|
|
var parser = PEG.buildParser('start = "a" / &"b" / "c"', options);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
expect(parser).toFailToParse("d", {
|
|
|
|
|
|
|
|
expected: [
|
|
|
|
|
|
|
|
{ type: "literal", value: "a", description: '"a"' },
|
|
|
|
|
|
|
|
{ type: "literal", value: "c", description: '"c"' }
|
|
|
|
|
|
|
|
]
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
describe("negative simple predicate", function() {
|
|
|
|
describe("negative simple predicate", function() {
|
|
|
|
it("matches correctly", function() {
|
|
|
|
describe("when the expression matches", function() {
|
|
|
|
|
|
|
|
it("reports match failure", function() {
|
|
|
|
|
|
|
|
var parser = PEG.buildParser('start = !"a"', options);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
expect(parser).toFailToParse("a");
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
describe("when the expression doesn't match", function() {
|
|
|
|
|
|
|
|
it("returns |undefined|", function() {
|
|
|
|
var parser = PEG.buildParser('start = !"a" "b"', options);
|
|
|
|
var parser = PEG.buildParser('start = !"a" "b"', options);
|
|
|
|
|
|
|
|
|
|
|
|
expect(parser).toParse("b", [undefined, "b"]);
|
|
|
|
expect(parser).toParse("b", [undefined, "b"]);
|
|
|
|
expect(parser).toFailToParse("a");
|
|
|
|
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
it("does not advance position on failure", function() {
|
|
|
|
it("resets parse position", function() {
|
|
|
|
var parser = PEG.buildParser('start = !"a" / "a"', options);
|
|
|
|
var parser = PEG.buildParser('start = !"a" "b"', options);
|
|
|
|
|
|
|
|
|
|
|
|
expect(parser).toParse("a", "a");
|
|
|
|
expect(parser).toParse("b");
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
it("does not influence expected strings on failure", function() {
|
|
|
|
it("discards any expectations recorded when matching the expression", function() {
|
|
|
|
var parser = PEG.buildParser('start = !"a"', options);
|
|
|
|
var parser = PEG.buildParser('start = "a" / !"b" / "c"', options);
|
|
|
|
|
|
|
|
|
|
|
|
expect(parser).toFailToParse("a", { expected: [] });
|
|
|
|
expect(parser).toFailToParse("b", {
|
|
|
|
|
|
|
|
expected: [
|
|
|
|
|
|
|
|
{ type: "literal", value: "a", description: '"a"' },
|
|
|
|
|
|
|
|
{ type: "literal", value: "c", description: '"c"' }
|
|
|
|
|
|
|
|
]
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|