pegjs/spec/unit/compiler/passes/remove-proxy-rules.spec.js
David Majda 850ddf5889 Specs cleanup: Simplify compiler passes specs
After 898a7b5a2d the specs mostly tested
the visitor implementation, not actual code in the passes.
2014-06-07 10:50:55 +02:00

52 lines
1.4 KiB
JavaScript

describe("compiler pass |removeProxyRules|", function() {
var pass = PEG.compiler.passes.transform.removeProxyRules;
describe("when a proxy rule isn't listed in |allowedStartRules|", function() {
it("updates references and removes it", function() {
expect(pass).toChangeAST(
[
'start = proxy',
'proxy = proxied',
'proxied = "a"'
].join("\n"),
{ allowedStartRules: ["start"] },
{
rules: [
{
name: "start",
expression: { type: "rule_ref", name: "proxied" }
},
{ name: "proxied" }
]
}
);
});
});
describe("when a proxy rule is listed in |allowedStartRules|", function() {
it("updates references but doesn't remove it", function() {
expect(pass).toChangeAST(
[
'start = proxy',
'proxy = proxied',
'proxied = "a"'
].join("\n"),
{ allowedStartRules: ["start", "proxy"] },
{
rules: [
{
name: "start",
expression: { type: "rule_ref", name: "proxied" }
},
{
name: "proxy",
expression: { type: "rule_ref", name: "proxied" }
},
{ name: "proxied" }
]
}
);
});
});
});