Behavior specs cleanup: Improve simple predicate specs
This commit is contained in:
parent
52144e48cb
commit
548209b48b
|
@ -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() {
|
||||||
var parser = PEG.buildParser('start = &"a" "a"', options);
|
it("returns |undefined|", function() {
|
||||||
|
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("resets parse position", function() {
|
||||||
|
var parser = PEG.buildParser('start = &"a" "a"', options);
|
||||||
|
|
||||||
|
expect(parser).toParse("a");
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it("does not advance position on success", function() {
|
describe("when the expression doesn't match", function() {
|
||||||
var parser = PEG.buildParser('start = &"a" "a"', options);
|
it("reports match failure", function() {
|
||||||
|
var parser = PEG.buildParser('start = &"a"', options);
|
||||||
|
|
||||||
expect(parser).toParse("a", [undefined, "a"]);
|
expect(parser).toFailToParse("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("b", { expected: [] });
|
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() {
|
||||||
var parser = PEG.buildParser('start = !"a" "b"', options);
|
it("reports match failure", function() {
|
||||||
|
var parser = PEG.buildParser('start = !"a"', options);
|
||||||
|
|
||||||
expect(parser).toParse("b", [undefined, "b"]);
|
expect(parser).toFailToParse("a");
|
||||||
expect(parser).toFailToParse("a");
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it("does not advance position on failure", function() {
|
describe("when the expression doesn't match", function() {
|
||||||
var parser = PEG.buildParser('start = !"a" / "a"', options);
|
it("returns |undefined|", function() {
|
||||||
|
var parser = PEG.buildParser('start = !"a" "b"', options);
|
||||||
|
|
||||||
expect(parser).toParse("a", "a");
|
expect(parser).toParse("b", [undefined, "b"]);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("does not influence expected strings on failure", function() {
|
it("resets parse position", function() {
|
||||||
var parser = PEG.buildParser('start = !"a"', options);
|
var parser = PEG.buildParser('start = !"a" "b"', options);
|
||||||
|
|
||||||
expect(parser).toFailToParse("a", { expected: [] });
|
expect(parser).toParse("b");
|
||||||
|
});
|
||||||
|
|
||||||
|
it("discards any expectations recorded when matching the expression", function() {
|
||||||
|
var parser = PEG.buildParser('start = "a" / !"b" / "c"', options);
|
||||||
|
|
||||||
|
expect(parser).toFailToParse("b", {
|
||||||
|
expected: [
|
||||||
|
{ type: "literal", value: "a", description: '"a"' },
|
||||||
|
{ type: "literal", value: "c", description: '"c"' }
|
||||||
|
]
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue