Debian Codegraph @

spec/unit/compiler/passes/report-duplicate-labels.spec.js

raw symbols SCIP
1 /* global peg */
2
3 "use strict";
4
5 describe("compiler pass |reportDuplicateLabels|", function() {
6 var pass = peg.compiler.passes.check.reportDuplicateLabels;
7
8 describe("in a sequence", function() {
9 it("reports labels duplicate with labels of preceding elements", function() {
10 expect(pass).toReportError('start = a:"a" a:"a"', {
11 message: 'Label "a" is already defined at line 1, column 9.',
12 location: {
13 start: { offset: 14, line: 1, column: 15 },
14 end: { offset: 19, line: 1, column: 20 }
15 }
16 });
17 });
18
19 it("doesn't report labels duplicate with labels in subexpressions", function() {
20 expect(pass).not.toReportError('start = ("a" / a:"a" / "a") a:"a"');
21 expect(pass).not.toReportError('start = (a:"a" { }) a:"a"');
22 expect(pass).not.toReportError('start = ("a" a:"a" "a") a:"a"');
23 expect(pass).not.toReportError('start = b:(a:"a") a:"a"');
24 expect(pass).not.toReportError('start = $(a:"a") a:"a"');
25 expect(pass).not.toReportError('start = &(a:"a") a:"a"');
26 expect(pass).not.toReportError('start = !(a:"a") a:"a"');
27 expect(pass).not.toReportError('start = (a:"a")? a:"a"');
28 expect(pass).not.toReportError('start = (a:"a")* a:"a"');
29 expect(pass).not.toReportError('start = (a:"a")+ a:"a"');
30 expect(pass).not.toReportError('start = (a:"a") a:"a"');
31 });
32 });
33
34 describe("in a choice", function() {
35 it("doesn't report labels duplicate with labels of preceding alternatives", function() {
36 expect(pass).not.toReportError('start = a:"a" / a:"a"');
37 });
38 });
39
40 describe("in outer sequence", function() {
41 it("reports labels duplicate with labels of preceding elements", function() {
42 expect(pass).toReportError('start = a:"a" (a:"a")', {
43 message: 'Label "a" is already defined at line 1, column 9.',
44 location: {
45 start: { offset: 15, line: 1, column: 16 },
46 end: { offset: 20, line: 1, column: 21 }
47 }
48 });
49 });
50
51 it("doesn't report labels duplicate with the label of the current element", function() {
52 expect(pass).not.toReportError('start = a:(a:"a")');
53 });
54
55 it("doesn't report labels duplicate with labels of following elements", function() {
56 expect(pass).not.toReportError('start = (a:"a") a:"a"');
57 });
58 });
59 });