bdf91b5941
This is purely a mechanical change, not taking advantage of block scope of "let" and "const". Minimizing variable scope will come in the next commit. In general, "var" is converted into "let" and "const" is used only for immutable variables of permanent character (generally spelled in ALL_CAPS). Using it for any immutable variable regardless on its permanence would feel confusing. Any code which is not transpiled and needs to run in ES6 environment (examples, code in grammars embedded in specs, ...) is kept unchanged. This is also true for code generated by PEG.js. See #442.
60 lines
2.3 KiB
JavaScript
60 lines
2.3 KiB
JavaScript
"use strict";
|
|
|
|
let peg = require("../../../../lib/peg");
|
|
|
|
describe("compiler pass |reportDuplicateLabels|", function() {
|
|
let pass = peg.compiler.passes.check.reportDuplicateLabels;
|
|
|
|
describe("in a sequence", function() {
|
|
it("reports labels duplicate with labels of preceding elements", function() {
|
|
expect(pass).toReportError('start = a:"a" a:"a"', {
|
|
message: 'Label "a" is already defined at line 1, column 9.',
|
|
location: {
|
|
start: { offset: 14, line: 1, column: 15 },
|
|
end: { offset: 19, line: 1, column: 20 }
|
|
}
|
|
});
|
|
});
|
|
|
|
it("doesn't report labels duplicate with labels in subexpressions", function() {
|
|
expect(pass).not.toReportError('start = ("a" / a:"a" / "a") a:"a"');
|
|
expect(pass).not.toReportError('start = (a:"a" { }) a:"a"');
|
|
expect(pass).not.toReportError('start = ("a" a:"a" "a") a:"a"');
|
|
expect(pass).not.toReportError('start = b:(a:"a") a:"a"');
|
|
expect(pass).not.toReportError('start = $(a:"a") a:"a"');
|
|
expect(pass).not.toReportError('start = &(a:"a") a:"a"');
|
|
expect(pass).not.toReportError('start = !(a:"a") a:"a"');
|
|
expect(pass).not.toReportError('start = (a:"a")? a:"a"');
|
|
expect(pass).not.toReportError('start = (a:"a")* a:"a"');
|
|
expect(pass).not.toReportError('start = (a:"a")+ a:"a"');
|
|
expect(pass).not.toReportError('start = (a:"a") a:"a"');
|
|
});
|
|
});
|
|
|
|
describe("in a choice", function() {
|
|
it("doesn't report labels duplicate with labels of preceding alternatives", function() {
|
|
expect(pass).not.toReportError('start = a:"a" / a:"a"');
|
|
});
|
|
});
|
|
|
|
describe("in outer sequence", function() {
|
|
it("reports labels duplicate with labels of preceding elements", function() {
|
|
expect(pass).toReportError('start = a:"a" (a:"a")', {
|
|
message: 'Label "a" is already defined at line 1, column 9.',
|
|
location: {
|
|
start: { offset: 15, line: 1, column: 16 },
|
|
end: { offset: 20, line: 1, column: 21 }
|
|
}
|
|
});
|
|
});
|
|
|
|
it("doesn't report labels duplicate with the label of the current element", function() {
|
|
expect(pass).not.toReportError('start = a:(a:"a")');
|
|
});
|
|
|
|
it("doesn't report labels duplicate with labels of following elements", function() {
|
|
expect(pass).not.toReportError('start = (a:"a") a:"a"');
|
|
});
|
|
});
|
|
});
|