Label scope specs: Don't exercise all expression types

Semantic predicate and action specs which verified scope of labels from
outer sequences exercised all relevant expression types. This is not
needed as the behavior is common for all expression types and no extra
code needs to be written to make it work for each of them.

This commit changes the specs to verify scope of labels from outer
sequences using only one expression type.
redux
David Majda 9 years ago
parent a20d04edf4
commit 7229318671

@ -449,58 +449,12 @@ describe("generated parser behavior", function() {
describe("in outer sequence", function() {
it("can access variables defined by preceding labeled elements", function() {
var testcases = [
{
grammar: 'start = a:"a" ("b" &{ return a === "a"; })',
input: "ab"
},
{
grammar: 'start = a:"a" ("b" &{ return a === "a"; })?',
input: "ab"
},
{
grammar: 'start = a:"a" ("b" &{ return a === "a"; })*',
input: "ab"
},
{
grammar: 'start = a:"a" ("b" &{ return a === "a"; })+',
input: "ab"
},
{
grammar: 'start = a:"a" $("b" &{ return a === "a"; })',
input: "ab"
},
{
grammar: 'start = a:"a" &("b" &{ return a === "a"; }) "b"',
input: "ab"
},
{
grammar: 'start = a:"a" !("b" &{ return a === "a"; }) "c"',
input: "ac"
},
{
grammar: 'start = a:"a" b:("b" &{ return a === "a"; })',
input: "ab"
},
{
grammar: 'start = a:"a" ("b" ("c" &{ return a === "a"; }) "d")',
input: "abcd"
},
{
grammar: 'start = a:"a" (b:("b" &{ return a === "a"; }) { return b; })',
input: "ab"
},
{
grammar: 'start = a:"a" ("b" / "c" &{ return a === "a"; } / "d")',
input: "ac"
}
],
parser, i;
var parser = PEG.buildParser(
'start = a:"a" ("b" &{ return a === "a"; })',
options
);
for (i = 0; i < testcases.length; i++) {
parser = PEG.buildParser(testcases[i].grammar, options);
expect(parser).toParse(testcases[i].input);
}
expect(parser).toParse("ab");
});
});
});
@ -604,58 +558,12 @@ describe("generated parser behavior", function() {
describe("in outer sequence", function() {
it("can access variables defined by preceding labeled elements", function() {
var testcases = [
{
grammar: 'start = a:"a" ("b" !{ return a !== "a"; })',
input: "ab"
},
{
grammar: 'start = a:"a" ("b" !{ return a !== "a"; })?',
input: "ab"
},
{
grammar: 'start = a:"a" ("b" !{ return a !== "a"; })*',
input: "ab"
},
{
grammar: 'start = a:"a" ("b" !{ return a !== "a"; })+',
input: "ab"
},
{
grammar: 'start = a:"a" $("b" !{ return a !== "a"; })',
input: "ab"
},
{
grammar: 'start = a:"a" &("b" !{ return a !== "a"; }) "b"',
input: "ab"
},
{
grammar: 'start = a:"a" !("b" !{ return a !== "a"; }) "c"',
input: "ac"
},
{
grammar: 'start = a:"a" b:("b" !{ return a !== "a"; })',
input: "ab"
},
{
grammar: 'start = a:"a" ("b" ("c" !{ return a !== "a"; }) "d")',
input: "abcd"
},
{
grammar: 'start = a:"a" (b:("b" !{ return a !== "a"; }) { return b; })',
input: "ab"
},
{
grammar: 'start = a:"a" ("b" / "c" !{ return a !== "a"; } / "d")',
input: "ac"
}
],
parser, i;
var parser = PEG.buildParser(
'start = a:"a" ("b" !{ return a !== "a"; })',
options
);
for (i = 0; i < testcases.length; i++) {
parser = PEG.buildParser(testcases[i].grammar, options);
expect(parser).toParse(testcases[i].input);
}
expect(parser).toParse("ab");
});
});
});
@ -955,69 +863,12 @@ describe("generated parser behavior", function() {
describe("in outer sequence", function() {
it("can access variables defined by preceding labeled elements", function() {
var testcases = [
{
grammar: 'start = a:"a" ("b" { return a; })',
input: "ab",
result: ["a", "a"]
},
{
grammar: 'start = a:"a" ("b" { return a; })?',
input: "ab",
result: ["a", "a"]
},
{
grammar: 'start = a:"a" ("b" { return a; })*',
input: "ab",
result: ["a", ["a"]]
},
{
grammar: 'start = a:"a" ("b" { return a; })+',
input: "ab",
result: ["a", ["a"]]
},
{
grammar: 'start = a:"a" $("b" { return a; })',
input: "ab",
result: ["a", "b"]
},
{
grammar: 'start = a:"a" &("b" { return a; }) "b"',
input: "ab",
result: ["a", undefined, "b"]
},
{
grammar: 'start = a:"a" !("b" { return a; }) "c"',
input: "ac",
result: ["a", undefined, "c"]
},
{
grammar: 'start = a:"a" b:("b" { return a; })',
input: "ab",
result: ["a", "a"]
},
{
grammar: 'start = a:"a" ("b" ("c" { return a; }) "d")',
input: "abcd",
result: ["a", ["b", "a", "d"]]
},
{
grammar: 'start = a:"a" (b:("b" { return a; }) { return b; })',
input: "ab",
result: ["a", "a"]
},
{
grammar: 'start = a:"a" ("b" / "c" { return a; } / "d")',
input: "ac",
result: ["a", "a"]
}
],
parser, i;
for (i = 0; i < testcases.length; i++) {
parser = PEG.buildParser(testcases[i].grammar, options);
expect(parser).toParse(testcases[i].input, testcases[i].result);
}
var parser = PEG.buildParser(
'start = a:"a" ("b" { return a; })',
options
);
expect(parser).toParse("ab", ["a", "a"]);
});
});
});

Loading…
Cancel
Save