You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
66 lines
2.4 KiB
JavaScript
66 lines
2.4 KiB
JavaScript
8 years ago
|
"use strict";
|
||
|
|
||
8 years ago
|
let chai = require("chai");
|
||
|
let helpers = require("./helpers");
|
||
8 years ago
|
let peg = require("../../../../lib/peg");
|
||
8 years ago
|
|
||
8 years ago
|
chai.use(helpers);
|
||
|
|
||
|
let expect = chai.expect;
|
||
|
|
||
8 years ago
|
describe("compiler pass |reportDuplicateLabels|", function() {
|
||
8 years ago
|
let pass = peg.compiler.passes.check.reportDuplicateLabels;
|
||
8 years ago
|
|
||
|
describe("in a sequence", function() {
|
||
|
it("reports labels duplicate with labels of preceding elements", function() {
|
||
8 years ago
|
expect(pass).to.reportError("start = a:'a' a:'a'", {
|
||
8 years ago
|
message: "Label \"a\" is already defined at line 1, column 9.",
|
||
8 years ago
|
location: {
|
||
|
start: { offset: 14, line: 1, column: 15 },
|
||
8 years ago
|
end: { offset: 19, line: 1, column: 20 }
|
||
8 years ago
|
}
|
||
|
});
|
||
|
});
|
||
|
|
||
|
it("doesn't report labels duplicate with labels in subexpressions", function() {
|
||
8 years ago
|
expect(pass).to.not.reportError("start = ('a' / a:'a' / 'a') a:'a'");
|
||
|
expect(pass).to.not.reportError("start = (a:'a' { }) a:'a'");
|
||
|
expect(pass).to.not.reportError("start = ('a' a:'a' 'a') a:'a'");
|
||
|
expect(pass).to.not.reportError("start = b:(a:'a') a:'a'");
|
||
|
expect(pass).to.not.reportError("start = $(a:'a') a:'a'");
|
||
|
expect(pass).to.not.reportError("start = &(a:'a') a:'a'");
|
||
|
expect(pass).to.not.reportError("start = !(a:'a') a:'a'");
|
||
|
expect(pass).to.not.reportError("start = (a:'a')? a:'a'");
|
||
|
expect(pass).to.not.reportError("start = (a:'a')* a:'a'");
|
||
|
expect(pass).to.not.reportError("start = (a:'a')+ a:'a'");
|
||
|
expect(pass).to.not.reportError("start = (a:'a') a:'a'");
|
||
8 years ago
|
});
|
||
|
});
|
||
|
|
||
|
describe("in a choice", function() {
|
||
|
it("doesn't report labels duplicate with labels of preceding alternatives", function() {
|
||
8 years ago
|
expect(pass).to.not.reportError("start = a:'a' / a:'a'");
|
||
8 years ago
|
});
|
||
|
});
|
||
|
|
||
|
describe("in outer sequence", function() {
|
||
|
it("reports labels duplicate with labels of preceding elements", function() {
|
||
8 years ago
|
expect(pass).to.reportError("start = a:'a' (a:'a')", {
|
||
8 years ago
|
message: "Label \"a\" is already defined at line 1, column 9.",
|
||
8 years ago
|
location: {
|
||
|
start: { offset: 15, line: 1, column: 16 },
|
||
8 years ago
|
end: { offset: 20, line: 1, column: 21 }
|
||
8 years ago
|
}
|
||
|
});
|
||
|
});
|
||
|
|
||
|
it("doesn't report labels duplicate with the label of the current element", function() {
|
||
8 years ago
|
expect(pass).to.not.reportError("start = a:(a:'a')");
|
||
8 years ago
|
});
|
||
|
|
||
|
it("doesn't report labels duplicate with labels of following elements", function() {
|
||
8 years ago
|
expect(pass).to.not.reportError("start = (a:'a') a:'a'");
|
||
8 years ago
|
});
|
||
|
});
|
||
|
});
|