5a833bd982
- Moved benchmark to test/benchmark - Moved tests to test/spec - Removed individual servers - Implemented single test server - Moved server assets to test/server - Updated Gulpfile.js - Moved tools/impact to test/impact This commit move's nearly all code related to testing the PEG.js module into the test directory, and also ensures they run as they did before the move.
100 lines
3.2 KiB
JavaScript
100 lines
3.2 KiB
JavaScript
"use strict";
|
|
|
|
let chai = require("chai");
|
|
let helpers = require("./helpers");
|
|
let pass = require("../../../../../lib/compiler/passes/report-infinite-repetition");
|
|
|
|
chai.use(helpers);
|
|
|
|
let expect = chai.expect;
|
|
|
|
describe("compiler pass |reportInfiniteRepetition|", function() {
|
|
it("reports infinite loops for zero_or_more", function() {
|
|
expect(pass).to.reportError("start = ('')*", {
|
|
message: "Possible infinite loop when parsing (repetition used with an expression that may not consume any input).",
|
|
location: {
|
|
start: { offset: 8, line: 1, column: 9 },
|
|
end: { offset: 13, line: 1, column: 14 }
|
|
}
|
|
});
|
|
});
|
|
|
|
it("reports infinite loops for one_or_more", function() {
|
|
expect(pass).to.reportError("start = ('')+", {
|
|
message: "Possible infinite loop when parsing (repetition used with an expression that may not consume any input).",
|
|
location: {
|
|
start: { offset: 8, line: 1, column: 9 },
|
|
end: { offset: 13, line: 1, column: 14 }
|
|
}
|
|
});
|
|
});
|
|
|
|
it("computes expressions that always consume input on success correctly", function() {
|
|
expect(pass).to.reportError([
|
|
"start = a*",
|
|
"a 'a' = ''"
|
|
].join("\n"));
|
|
expect(pass).to.not.reportError([
|
|
"start = a*",
|
|
"a 'a' = 'a'"
|
|
].join("\n"));
|
|
|
|
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')*");
|
|
|
|
expect(pass).to.reportError("start = ('' { })*");
|
|
expect(pass).to.not.reportError("start = ('a' { })*");
|
|
|
|
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')*");
|
|
|
|
expect(pass).to.reportError("start = (a:'')*");
|
|
expect(pass).to.not.reportError("start = (a:'a')*");
|
|
|
|
expect(pass).to.reportError("start = ($'')*");
|
|
expect(pass).to.not.reportError("start = ($'a')*");
|
|
|
|
expect(pass).to.reportError("start = (&'')*");
|
|
expect(pass).to.reportError("start = (&'a')*");
|
|
|
|
expect(pass).to.reportError("start = (!'')*");
|
|
expect(pass).to.reportError("start = (!'a')*");
|
|
|
|
expect(pass).to.reportError("start = (''?)*");
|
|
expect(pass).to.reportError("start = ('a'?)*");
|
|
|
|
expect(pass).to.reportError("start = (''*)*");
|
|
expect(pass).to.reportError("start = ('a'*)*");
|
|
|
|
expect(pass).to.reportError("start = (''+)*");
|
|
expect(pass).to.not.reportError("start = ('a'+)*");
|
|
|
|
expect(pass).to.reportError("start = ('')*");
|
|
expect(pass).to.not.reportError("start = ('a')*");
|
|
|
|
expect(pass).to.reportError("start = (&{ })*");
|
|
|
|
expect(pass).to.reportError("start = (!{ })*");
|
|
|
|
expect(pass).to.reportError([
|
|
"start = a*",
|
|
"a = ''"
|
|
].join("\n"));
|
|
expect(pass).to.not.reportError([
|
|
"start = a*",
|
|
"a = 'a'"
|
|
].join("\n"));
|
|
|
|
expect(pass).to.reportError("start = ''*");
|
|
expect(pass).to.not.reportError("start = 'a'*");
|
|
|
|
expect(pass).to.not.reportError("start = [a-d]*");
|
|
|
|
expect(pass).to.not.reportError("start = .*");
|
|
});
|
|
});
|