| 1 |
|
| 2 |
|
| 3 |
"use strict"; |
| 4 |
|
| 5 |
describe("compiler pass |removeProxyRules|", function() { |
| 6 |
var pass = peg.compiler.passes.transform.removeProxyRules; |
| 7 |
|
| 8 |
describe("when a proxy rule isn't listed in |allowedStartRules|", function() { |
| 9 |
it("updates references and removes it", function() { |
| 10 |
expect(pass).toChangeAST( |
| 11 |
[ |
| 12 |
'start = proxy', |
| 13 |
'proxy = proxied', |
| 14 |
'proxied = "a"' |
| 15 |
].join("\n"), |
| 16 |
{ |
| 17 |
rules: [ |
| 18 |
{ |
| 19 |
name: "start", |
| 20 |
expression: { type: "rule_ref", name: "proxied" } |
| 21 |
}, |
| 22 |
{ name: "proxied" } |
| 23 |
] |
| 24 |
}, |
| 25 |
{ allowedStartRules: ["start"] } |
| 26 |
); |
| 27 |
}); |
| 28 |
}); |
| 29 |
|
| 30 |
describe("when a proxy rule is listed in |allowedStartRules|", function() { |
| 31 |
it("updates references but doesn't remove it", function() { |
| 32 |
expect(pass).toChangeAST( |
| 33 |
[ |
| 34 |
'start = proxy', |
| 35 |
'proxy = proxied', |
| 36 |
'proxied = "a"' |
| 37 |
].join("\n"), |
| 38 |
{ |
| 39 |
rules: [ |
| 40 |
{ |
| 41 |
name: "start", |
| 42 |
expression: { type: "rule_ref", name: "proxied" } |
| 43 |
}, |
| 44 |
{ |
| 45 |
name: "proxy", |
| 46 |
expression: { type: "rule_ref", name: "proxied" } |
| 47 |
}, |
| 48 |
{ name: "proxied" } |
| 49 |
] |
| 50 |
}, |
| 51 |
{ allowedStartRules: ["start", "proxy"] } |
| 52 |
); |
| 53 |
}); |
| 54 |
}); |
| 55 |
}); |