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.
102 lines
3.2 KiB
JavaScript
102 lines
3.2 KiB
JavaScript
10 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 |reportInfiniteRepetition|", function() {
|
||
8 years ago
|
let pass = peg.compiler.passes.check.reportInfiniteRepetition;
|
||
10 years ago
|
|
||
|
it("reports infinite loops for zero_or_more", function() {
|
||
8 years ago
|
expect(pass).to.reportError("start = ('')*", {
|
||
8 years ago
|
message: "Possible infinite loop when parsing (repetition used with an expression that may not consume any input).",
|
||
10 years ago
|
location: {
|
||
8 years ago
|
start: { offset: 8, line: 1, column: 9 },
|
||
|
end: { offset: 13, line: 1, column: 14 }
|
||
10 years ago
|
}
|
||
10 years ago
|
});
|
||
|
});
|
||
|
|
||
|
it("reports infinite loops for one_or_more", function() {
|
||
8 years ago
|
expect(pass).to.reportError("start = ('')+", {
|
||
8 years ago
|
message: "Possible infinite loop when parsing (repetition used with an expression that may not consume any input).",
|
||
10 years ago
|
location: {
|
||
8 years ago
|
start: { offset: 8, line: 1, column: 9 },
|
||
|
end: { offset: 13, line: 1, column: 14 }
|
||
10 years ago
|
}
|
||
10 years ago
|
});
|
||
|
});
|
||
|
|
||
9 years ago
|
it("computes expressions that always consume input on success correctly", function() {
|
||
8 years ago
|
expect(pass).to.reportError([
|
||
8 years ago
|
"start = a*",
|
||
|
"a 'a' = ''"
|
||
|
].join("\n"));
|
||
8 years ago
|
expect(pass).to.not.reportError([
|
||
8 years ago
|
"start = a*",
|
||
|
"a 'a' = 'a'"
|
||
|
].join("\n"));
|
||
9 years ago
|
|
||
8 years ago
|
expect(pass).to.reportError("start = ('' / 'a' / 'b')*");
|
||
|
expect(pass).to.reportError("start = ('a' / '' / 'b')*");
|
||
|
expect(pass).to.reportError("start = ('a' / 'b' / '')*");
|
||
|
expect(pass).to.not.reportError("start = ('a' / 'b' / 'c')*");
|
||
10 years ago
|
|
||
8 years ago
|
expect(pass).to.reportError("start = ('' { })*");
|
||
|
expect(pass).to.not.reportError("start = ('a' { })*");
|
||
10 years ago
|
|
||
8 years ago
|
expect(pass).to.reportError("start = ('' '' '')*");
|
||
|
expect(pass).to.not.reportError("start = ('a' '' '')*");
|
||
|
expect(pass).to.not.reportError("start = ('' 'a' '')*");
|
||
|
expect(pass).to.not.reportError("start = ('' '' 'a')*");
|
||
10 years ago
|
|
||
8 years ago
|
expect(pass).to.reportError("start = (a:'')*");
|
||
|
expect(pass).to.not.reportError("start = (a:'a')*");
|
||
10 years ago
|
|
||
8 years ago
|
expect(pass).to.reportError("start = ($'')*");
|
||
|
expect(pass).to.not.reportError("start = ($'a')*");
|
||
10 years ago
|
|
||
8 years ago
|
expect(pass).to.reportError("start = (&'')*");
|
||
|
expect(pass).to.reportError("start = (&'a')*");
|
||
10 years ago
|
|
||
8 years ago
|
expect(pass).to.reportError("start = (!'')*");
|
||
|
expect(pass).to.reportError("start = (!'a')*");
|
||
10 years ago
|
|
||
8 years ago
|
expect(pass).to.reportError("start = (''?)*");
|
||
|
expect(pass).to.reportError("start = ('a'?)*");
|
||
10 years ago
|
|
||
8 years ago
|
expect(pass).to.reportError("start = (''*)*");
|
||
|
expect(pass).to.reportError("start = ('a'*)*");
|
||
10 years ago
|
|
||
8 years ago
|
expect(pass).to.reportError("start = (''+)*");
|
||
|
expect(pass).to.not.reportError("start = ('a'+)*");
|
||
10 years ago
|
|
||
8 years ago
|
expect(pass).to.reportError("start = ('')*");
|
||
|
expect(pass).to.not.reportError("start = ('a')*");
|
||
9 years ago
|
|
||
8 years ago
|
expect(pass).to.reportError("start = (&{ })*");
|
||
10 years ago
|
|
||
8 years ago
|
expect(pass).to.reportError("start = (!{ })*");
|
||
10 years ago
|
|
||
8 years ago
|
expect(pass).to.reportError([
|
||
8 years ago
|
"start = a*",
|
||
|
"a = ''"
|
||
|
].join("\n"));
|
||
8 years ago
|
expect(pass).to.not.reportError([
|
||
8 years ago
|
"start = a*",
|
||
|
"a = 'a'"
|
||
|
].join("\n"));
|
||
10 years ago
|
|
||
8 years ago
|
expect(pass).to.reportError("start = ''*");
|
||
|
expect(pass).to.not.reportError("start = 'a'*");
|
||
10 years ago
|
|
||
8 years ago
|
expect(pass).to.not.reportError("start = [a-d]*");
|
||
10 years ago
|
|
||
8 years ago
|
expect(pass).to.not.reportError("start = .*");
|
||
10 years ago
|
});
|
||
|
});
|