2016-06-27 13:42:28 +02:00
|
|
|
"use strict";
|
|
|
|
|
2016-12-08 08:59:04 +01:00
|
|
|
let chai = require("chai");
|
|
|
|
let helpers = require("./helpers");
|
2016-12-16 13:21:48 +01:00
|
|
|
let pass = require("../../../../lib/compiler/passes/report-duplicate-labels");
|
2016-09-08 13:29:06 +02:00
|
|
|
|
2016-12-08 08:59:04 +01:00
|
|
|
chai.use(helpers);
|
|
|
|
|
|
|
|
let expect = chai.expect;
|
|
|
|
|
2016-06-27 13:42:28 +02:00
|
|
|
describe("compiler pass |reportDuplicateLabels|", function() {
|
|
|
|
describe("in a sequence", function() {
|
|
|
|
it("reports labels duplicate with labels of preceding elements", function() {
|
2016-12-08 08:59:04 +01:00
|
|
|
expect(pass).to.reportError("start = a:'a' a:'a'", {
|
2016-09-22 05:25:09 +02:00
|
|
|
message: "Label \"a\" is already defined at line 1, column 9.",
|
2016-06-27 13:42:28 +02:00
|
|
|
location: {
|
|
|
|
start: { offset: 14, line: 1, column: 15 },
|
2016-09-22 05:25:09 +02:00
|
|
|
end: { offset: 19, line: 1, column: 20 }
|
2016-06-27 13:42:28 +02:00
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it("doesn't report labels duplicate with labels in subexpressions", function() {
|
2016-12-08 08:59:04 +01:00
|
|
|
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'");
|
2016-06-27 13:42:28 +02:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe("in a choice", function() {
|
|
|
|
it("doesn't report labels duplicate with labels of preceding alternatives", function() {
|
2016-12-08 08:59:04 +01:00
|
|
|
expect(pass).to.not.reportError("start = a:'a' / a:'a'");
|
2016-06-27 13:42:28 +02:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe("in outer sequence", function() {
|
|
|
|
it("reports labels duplicate with labels of preceding elements", function() {
|
2016-12-08 08:59:04 +01:00
|
|
|
expect(pass).to.reportError("start = a:'a' (a:'a')", {
|
2016-09-22 05:25:09 +02:00
|
|
|
message: "Label \"a\" is already defined at line 1, column 9.",
|
2016-06-27 13:42:28 +02:00
|
|
|
location: {
|
|
|
|
start: { offset: 15, line: 1, column: 16 },
|
2016-09-22 05:25:09 +02:00
|
|
|
end: { offset: 20, line: 1, column: 21 }
|
2016-06-27 13:42:28 +02:00
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it("doesn't report labels duplicate with the label of the current element", function() {
|
2016-12-08 08:59:04 +01:00
|
|
|
expect(pass).to.not.reportError("start = a:(a:'a')");
|
2016-06-27 13:42:28 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
it("doesn't report labels duplicate with labels of following elements", function() {
|
2016-12-08 08:59:04 +01:00
|
|
|
expect(pass).to.not.reportError("start = (a:'a') a:'a'");
|
2016-06-27 13:42:28 +02:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|