diff --git a/spec/behavior/generated-parser-behavior.spec.js b/spec/behavior/generated-parser-behavior.spec.js index b68b5e6..ed40b02 100644 --- a/spec/behavior/generated-parser-behavior.spec.js +++ b/spec/behavior/generated-parser-behavior.spec.js @@ -445,6 +445,24 @@ describe("generated parser behavior", function() { expect(parser).toParse("a"); }); + + it("cannot access variable defined by labeled predicate element", function() { + var parser = PEG.buildParser( + 'start = "a" b:&{ return b === undefined; } "c"', + options + ); + + expect(parser).toFailToParse("ac"); + }); + + it("cannot access variables defined by following labeled elements", function() { + var parser = PEG.buildParser( + 'start = &{ return a === "a"; } a:"a"', + options + ); + + expect(parser).toFailToParse("a"); + }); }); describe("in outer sequence", function() { @@ -456,6 +474,24 @@ describe("generated parser behavior", function() { expect(parser).toParse("ab"); }); + + it("cannot access variable defined by labeled predicate element", function() { + var parser = PEG.buildParser( + 'start = "a" b:("b" &{ return b === undefined; }) "c"', + options + ); + + expect(parser).toFailToParse("abc"); + }); + + it("cannot access variables defined by following labeled elements", function() { + var parser = PEG.buildParser( + 'start = ("a" &{ return b === "b"; }) b:"b"', + options + ); + + expect(parser).toFailToParse("ab"); + }); }); }); @@ -554,6 +590,24 @@ describe("generated parser behavior", function() { expect(parser).toParse("a"); }); + + it("cannot access variable defined by labeled predicate element", function() { + var parser = PEG.buildParser( + 'start = "a" b:!{ return b !== undefined; } "c"', + options + ); + + expect(parser).toFailToParse("ac"); + }); + + it("cannot access variables defined by following labeled elements", function() { + var parser = PEG.buildParser( + 'start = !{ return a !== "a"; } a:"a"', + options + ); + + expect(parser).toFailToParse("a"); + }); }); describe("in outer sequence", function() { @@ -565,6 +619,24 @@ describe("generated parser behavior", function() { expect(parser).toParse("ab"); }); + + it("cannot access variable defined by labeled predicate element", function() { + var parser = PEG.buildParser( + 'start = "a" b:("b" !{ return b !== undefined; }) "c"', + options + ); + + expect(parser).toFailToParse("abc"); + }); + + it("cannot access variables defined by following labeled elements", function() { + var parser = PEG.buildParser( + 'start = ("a" !{ return b !== "b"; }) b:"b"', + options + ); + + expect(parser).toFailToParse("ab"); + }); }); }); @@ -870,6 +942,24 @@ describe("generated parser behavior", function() { expect(parser).toParse("ab", ["a", "a"]); }); + + it("cannot access variable defined by labeled action element", function() { + var parser = PEG.buildParser( + 'start = "a" b:("b" { return b; }) c:"c"', + options + ); + + expect(parser).toFailToParse("abc"); + }); + + it("cannot access variables defined by following labeled elements", function() { + var parser = PEG.buildParser( + 'start = ("a" { return b; }) b:"b"', + options + ); + + expect(parser).toFailToParse("ab"); + }); }); });