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.
96 lines
3.1 KiB
JavaScript
96 lines
3.1 KiB
JavaScript
9 years ago
|
/* global peg */
|
||
10 years ago
|
|
||
|
"use strict";
|
||
|
|
||
8 years ago
|
describe("compiler pass |reportInfiniteRepetition|", function() {
|
||
|
var pass = peg.compiler.passes.check.reportInfiniteRepetition;
|
||
10 years ago
|
|
||
|
it("reports infinite loops for zero_or_more", function() {
|
||
|
expect(pass).toReportError('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: {
|
||
|
start: { offset: 8, line: 1, column: 9 },
|
||
|
end: { offset: 13, line: 1, column: 14 }
|
||
|
}
|
||
10 years ago
|
});
|
||
|
});
|
||
|
|
||
|
it("reports infinite loops for one_or_more", function() {
|
||
|
expect(pass).toReportError('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: {
|
||
|
start: { offset: 8, line: 1, column: 9 },
|
||
|
end: { offset: 13, line: 1, column: 14 }
|
||
|
}
|
||
10 years ago
|
});
|
||
|
});
|
||
|
|
||
9 years ago
|
it("computes expressions that always consume input on success correctly", function() {
|
||
9 years ago
|
expect(pass).toReportError([
|
||
|
'start = a*',
|
||
|
'a "a" = ""'
|
||
|
].join('\n'));
|
||
|
expect(pass).not.toReportError([
|
||
|
'start = a*',
|
||
|
'a "a" = "a"'
|
||
|
].join('\n'));
|
||
|
|
||
10 years ago
|
expect(pass).toReportError('start = ("" / "a" / "b")*');
|
||
|
expect(pass).toReportError('start = ("a" / "" / "b")*');
|
||
|
expect(pass).toReportError('start = ("a" / "b" / "")*');
|
||
|
expect(pass).not.toReportError('start = ("a" / "b" / "c")*');
|
||
|
|
||
|
expect(pass).toReportError('start = ("" { })*');
|
||
|
expect(pass).not.toReportError('start = ("a" { })*');
|
||
|
|
||
|
expect(pass).toReportError('start = ("" "" "")*');
|
||
|
expect(pass).not.toReportError('start = ("a" "" "")*');
|
||
|
expect(pass).not.toReportError('start = ("" "a" "")*');
|
||
|
expect(pass).not.toReportError('start = ("" "" "a")*');
|
||
|
|
||
|
expect(pass).toReportError('start = (a:"")*');
|
||
|
expect(pass).not.toReportError('start = (a:"a")*');
|
||
|
|
||
|
expect(pass).toReportError('start = ($"")*');
|
||
|
expect(pass).not.toReportError('start = ($"a")*');
|
||
|
|
||
|
expect(pass).toReportError('start = (&"")*');
|
||
|
expect(pass).toReportError('start = (&"a")*');
|
||
|
|
||
|
expect(pass).toReportError('start = (!"")*');
|
||
|
expect(pass).toReportError('start = (!"a")*');
|
||
|
|
||
|
expect(pass).toReportError('start = (""?)*');
|
||
|
expect(pass).toReportError('start = ("a"?)*');
|
||
|
|
||
|
expect(pass).toReportError('start = (""*)*');
|
||
|
expect(pass).toReportError('start = ("a"*)*');
|
||
|
|
||
|
expect(pass).toReportError('start = (""+)*');
|
||
|
expect(pass).not.toReportError('start = ("a"+)*');
|
||
|
|
||
9 years ago
|
expect(pass).toReportError('start = ("")*');
|
||
|
expect(pass).not.toReportError('start = ("a")*');
|
||
|
|
||
10 years ago
|
expect(pass).toReportError('start = (&{ })*');
|
||
|
|
||
|
expect(pass).toReportError('start = (!{ })*');
|
||
|
|
||
|
expect(pass).toReportError([
|
||
|
'start = a*',
|
||
|
'a = ""'
|
||
|
].join('\n'));
|
||
|
expect(pass).not.toReportError([
|
||
|
'start = a*',
|
||
|
'a = "a"'
|
||
|
].join('\n'));
|
||
|
|
||
|
expect(pass).toReportError('start = ""*');
|
||
|
expect(pass).not.toReportError('start = "a"*');
|
||
|
|
||
|
expect(pass).not.toReportError('start = [a-d]*');
|
||
|
|
||
9 years ago
|
expect(pass).not.toReportError('start = .*');
|
||
10 years ago
|
});
|
||
|
});
|