Label scope specs: Add negative specs (sequences)

So far, semantic predicate and action specs which verified scope of
labels from containing or outer sequences exercised only cases where
label variables were defined. This commit adds also some negative cases.

The idea comes from @Mingun.
redux
David Majda 8 years ago
parent 7229318671
commit ffd90a8c9e

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

Loading…
Cancel
Save